[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    kdesupport/kdewin-installer
From:       Ralf Habacker <Ralf.Habacker () freenet ! de>
Date:       2008-04-10 12:38:36
Message-ID: 1207831116.504969.12510.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 795479 by habacker:

- added new class MirrorsConfig which is used in class Mirror
- set www.winkde.org as default mirror list server 
- set sourceforge as fallback mirror list server


 M  +41 -14    gui/mirrorsettingspage.cpp  
 M  +20 -20    shared/mirrors.cpp  
 M  +92 -7     shared/mirrors.h  


--- trunk/kdesupport/kdewin-installer/gui/mirrorsettingspage.cpp #795478:795479
@@ -27,20 +27,45 @@
 #include "mirrorsettingspage.h"
 #include "installerdialogs.h"
 
+Mirrors::Config winkde_org_mirrorConfig(
+    "http://www.winkde.org/pub/kde/ports/win32/mirrors.lst",
+    Mirrors::KDE,
+    "",
+    ""
+);
+
+Mirrors::Config sourceforge_mirrorConfig(
+    "http://downloads.sourceforge.net/kde-windows/mirrors.lst",
+    Mirrors::Cygwin,
+    "",
+    ""
+);
+
 #if 0
-QUrl mirrorListURL("http://www.kde.org/mirrors/kdemirrors.list");
-Mirrors::Type mirrorListType = Mirrors::KDE;
-QString mirrorReleasePath = "unstable/4.0.61/win32";
-#else
-QUrl mirrorListURL("http://downloads.sourceforge.net/kde-windows/mirrors.lst");
-Mirrors::Type mirrorListType = Mirrors::Cygwin;
-QString mirrorReleasePath = "";
+// sourceforge mirror could only be added manually 
+Mirrors::Config download_kde_org_mirrorConfig(
+    "http://download.kde.org/download.php?url=unstable/4.0.67/win32",
+    Mirrors::KDE_HTML,
+    "",
+    ""
+);
 #endif
 
-QUrl fallBackMirrorURL("http://webdev.cegit.de/snapshots/kde-windows/mirrors.lst");
-Mirrors::Type fallBackMirrorType = Mirrors::Cygwin;
-QString fallBackMirrorReleasePath = "";
 
+Mirrors::Config webdev_cegit_de_mirrorConfig(
+    "http://webdev.cegit.de/snapshots/kde-windows/mirrors.lst",
+    Mirrors::Cygwin,
+    "",
+    ""
+);
+
+/// main mirror list server 
+#define mirrorConfig winkde_org_mirrorConfig
+
+/// fall back server when main mirror list server could not be contacted
+#define fallBackConfig sourceforge_mirrorConfig
+
+
 MirrorSettingsPage::MirrorSettingsPage() : InstallWizardPage(0)
 {
     ui.setupUi(this);
@@ -53,18 +78,20 @@
     Settings &s = Settings::instance();
     s.setSkipBasicSettings(true);
     Mirrors &mirrors = Mirrors::instance();
+    mirrors.setConfig(mirrorConfig);
     InstallerDialogs::instance().downloadProgressDialog(this,true,tr("Downloading \
Mirror List"));  
     if (mirrors.mirrors().size() == 0)
     {
         /// @TODO add vivible progress bar
-        if ( !mirrors.fetch(mirrorListType, mirrorListURL, mirrorReleasePath) ) 
+        if ( !mirrors.fetch() ) 
         {
-            qCritical() << "could not load mirrors from" << mirrorListURL;
+            qCritical() << "could not load mirrors from" << mirrorConfig.url;
             /// @TODO add vivible progress bar
-            if ( !mirrors.fetch(fallBackMirrorType, fallBackMirrorURL, \
fallBackMirrorReleasePath) ) +            mirrors.setConfig(fallBackConfig);
+            if ( !mirrors.fetch() )
             {
-                qCritical() << "could not load fallback mirror list from" << \
fallBackMirrorURL; +                qCritical() << "could not load fallback mirror \
list from" << fallBackConfig.url;  // display warning box
             }
         }
--- trunk/kdesupport/kdewin-installer/shared/mirrors.cpp #795478:795479
@@ -38,20 +38,18 @@
 
 
 Mirrors::Mirrors()
-: m_type(Cygwin)
 {
-    m_releasePath="";
     initCountries();
 }
 
-/**
- get the list of mirrors
- @return list of mirrors
-*/
-bool Mirrors::fetch(Type type, QUrl url, const QString &releasePath)
+Mirrors::Mirrors(const Config &config)
+: m_config(config)
 {
-    m_releasePath = releasePath;
-    m_type = type;
+    initCountries();
+}
+
+bool Mirrors::fetch()
+{
 #ifdef DEBUG
     QString out = "mirrors.html";
 #else
@@ -78,18 +76,11 @@
         }
 #endif
      }   
-     else if (!Downloader::instance()->start(url,out))
+     else if (!Downloader::instance()->start(m_config.url,out))
         return false;
     return parse(out);
 }
 
-/**
- parse mirror list from a local file
-
- @param filename
- @return true if parse was performed successfully, false otherwise
-*/
-
 bool Mirrors::parse(const QString &fileName)
 {
     QFile file(fileName);
@@ -113,7 +104,7 @@
 bool Mirrors::parse(QIODevice *ioDev)
 {
     m_mirrors.clear();
-    switch (m_type) {
+    switch (m_config.type) {
     case KDE:
         {
             while (!ioDev->atEnd())
@@ -125,7 +116,10 @@
                 if (parts.size() >= 3) 
                 {
                     MirrorType mirror;
-                    mirror.url = QUrl(parts[2] + m_releasePath);
+                    if (parts[2].contains(m_config.excludePattern))
+                        mirror.url = QUrl(parts[2]);
+                    else
+                        mirror.url = QUrl(parts[2] + m_config.releasePath);
                     mirror.name = parts[0] + "://" + mirror.url.host();
                     if (m_countries.contains(parts[1])) 
                     {
@@ -164,7 +158,11 @@
                     continue; 
                 }
                 MirrorType mirror;
-                mirror.url = a[0];
+                if (a[0].contains(m_config.excludePattern.toLatin1()))
+                    mirror.url = a[0];
+                else
+                    mirror.url = QUrl(a[2] + m_config.releasePath);
+
                 mirror.name = a[1];
                 mirror.continent = a[2];
                 mirror.country = a[3];
@@ -446,6 +444,7 @@
     m_countries["za"] = "South Africa";
     m_countries["zm"] = "Zambia";
     m_countries["zw"] = "Zimbabwe";
+    m_countries["--"] = "";
 
     // setup countryGroups hash table 
     QHash<QString,QString> countryGroups;
@@ -459,6 +458,7 @@
     countryGroups["Northern Europe"] = "dk:ee:is:fi:no:se";
     countryGroups["Southern Europe"] = "ba:cy:gr:hr:it:mk:mt:va:yu:tr";
     countryGroups["Western Europe"] = "be:es:fr:ie:lu:nl:pt:uk";
+    countryGroups["World Wide"] = "--";
 
     // setup m_continents hash table 
     // which is accessable by using QString continent = m_continents[<countrycode>];
--- trunk/kdesupport/kdewin-installer/shared/mirrors.h #795478:795479
@@ -30,49 +30,134 @@
 class QByteArray;
 class QFile;
 
-//http://webdev.cegit.de/snapshots/kde-windows;webdev.cegit.de;Europe;Germany,Essen
+/**
+ holds all attributes for a single mirror 
+*/
 
 class MirrorType
 {
     public:
+        typedef enum URLType {Unspecified, Local, Other } ;
+        MirrorType(const QUrl &_url=QUrl(), const QString _name=QString(), const \
QString &_continent=QString(), const QString &_country=QString(), URLType \
_type=Unspecified) +        {
+            url = _url;
+            name = _name;
+            continent = _continent;
+            country   = _country;  
+            type      = _type;     
+        }                
+
         QUrl url;
         QString name;
         QString continent;
         QString country;
+        URLType type;
 
         friend QDebug &operator<<(QDebug &,const MirrorType &);
         QString toString() const
         {
-            return continent + "," + country + " (" + name + ")";
+            QString result;
+            if (type == Local)
+                result += "Local ";
+            else if (type == Other)
+                result += "Other ";
+            if ( continent.isEmpty() )
+                return result + name;
+            else 
+                return result + continent + "," + country + " (" + name + ")";
         }
 };
 
 typedef QList<MirrorType> MirrorTypeList;
 
+/**
+  This class provides access to a list of download mirror locations, which could be \
fetched from a  +  remote http or ftp site. The mirror locations are accessable as a \
list of MirrorType instances. +  Currently there are three formats of mirror list \
files supported.  +    KDE - mirrors defined in this format are containing one mirror \
on each line in the form  +    
+          <protocol> <2-digit country code> <url><eol>
+
+    cygwin - this format is used by the cygwin setup application with one mirror on \
each line  +             using the following form
+
+              <url>;<name>;<continent>;<country><eol>
+
+    KDE_HTML - this format is platin html text where the urls are extracted from the \
href attribut  +               of an <a> tag 
+*/
+
 class Mirrors /* : public QObject */
 {
     //Q_OBJECT
     public:
-        enum Type { KDE = 1 ,Cygwin= 2 };
+        enum Type { KDE = 1, KDE_HTML = 2, Cygwin= 3 };
 
+    /** 
+     holds several options required by Mirrors::fetch()
+    */
+    class Config {
+        public:
+            Config() {}
+            Config(const QUrl &url, Type type, const QString &releasePath, const \
QString &exclude) +                : url(url), type(type), releasePath(releasePath), \
excludePattern(exclude)  +            {}
+            Config(const QString &url, Type type, const QString &releasePath, const \
QString &exclude) +                : url(QUrl(url)), type(type), \
releasePath(releasePath), excludePattern(exclude)  +            {}
+            QUrl url;
+            Type type;
+            QString releasePath;
+            /// contains exclude pattern of hosts to which the release Path isn't \
appended  +            QString excludePattern; 
+    };
+
+    public:
         Mirrors();
-        // fetch mirror list; releasePath will be appended to each mirror url 
-        bool fetch(Type type, QUrl url, const QString &releasePath=QString());
+        Mirrors(const Config &config);
+        void setConfig(const Config &config) { m_config = config; }
+
+        // fetch mirror list 
+        bool fetch();
+        void clear() { m_mirrors.clear(); }
+        void add(const MirrorType &mirror) { m_mirrors.append(mirror); }
         MirrorTypeList &mirrors() { return m_mirrors; }
         static Mirrors &instance();
     protected:
+
+        /**
+         parse mirror list from a local file. The mirror list is accessable 
+         by the mirrors() method. 
+        
+         @param filename
+         @return true if parse was performed successfully, false otherwise
+        */
         bool parse(const QString &fileName);
+        /**
+         parse mirror list from a QByteArray. The mirror list is accessable 
+         by the mirrors() method. 
+         
+         @param data - QByteArry instance 
+         @return true if parse was performed successfully, false otherwise
+        */
         bool parse(const QByteArray &data);
+        /**
+         parse mirror list from an QIODevice instance. The mirror list is accessable \
 +         by the mirrors() method. 
+         
+         @param data - QIODevice instance 
+         @return true if parse was performed successfully, false otherwise
+        */
         bool parse(QIODevice *ioDev);
         void initCountries();
 
-        Type m_type;
         QList<MirrorType> m_mirrors;
-        QString m_releasePath;
         static QHash<QString,QString> m_countries;
         static QHash<QString,QString> m_continents;
+        Config m_config;
 };
 
+
 QDebug &operator<<(QDebug &,const MirrorTypeList &);
 
 #endif


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic