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

List:       kde-commits
Subject:    KDE/kdenetwork/kget/ui
From:       Matthias Fuchs <mat69 () gmx ! net>
Date:       2009-11-30 23:13:23
Message-ID: 1259622803.447082.12121.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 1056822 by mfuchs:

Changes the priority of Url and Metaurl (min 1, max 255) to conform with the most \
recent draft of Metalink 4.0.

 M  +26 -17    metalinkcreator/metalinker.cpp  
 M  +12 -7     metalinkcreator/metalinker.h  
 M  +1 -1      mirror/mirrormodel.cpp  


--- trunk/KDE/kdenetwork/kget/ui/metalinkcreator/metalinker.cpp #1056821:1056822
@@ -33,6 +33,7 @@
 #endif //HAVE_NEPOMUK
 
 const QString KGetMetalink::Metalink::KGET_DESCRIPTION = QString(QString("KGet ") + \
"2." + QString::number(KDE_VERSION_MINOR) + '.' + \
QString::number(KDE_VERSION_RELEASE)); +const uint \
KGetMetalink::Metalink::MAX_PRIORITY = 255;  
 namespace KGetMetalink
 {
@@ -276,13 +277,16 @@
 
 bool KGetMetalink::Metaurl::operator<(const KGetMetalink::Metaurl &other) const
 {
-     return this->priority > other.priority;
+     return (this->priority > other.priority) || (this->priority == 0);
 }
 
 void KGetMetalink::Metaurl::load(const QDomElement &e)
 {
     type = e.attribute("type").toLower();
-    priority = e.attribute("priority").toInt();
+    priority = e.attribute("priority").toUInt();
+    if (priority > Metalink::MAX_PRIORITY) {
+        priority = Metalink::MAX_PRIORITY;
+    }
     name = e.attribute("name");
     url = KUrl(e.text());
 }
@@ -322,7 +326,7 @@
 
 bool KGetMetalink::Url::operator<(const KGetMetalink::Url &other) const
 {
-    bool smaller = this->priority > other.priority;
+    bool smaller = (this->priority > other.priority) || ((this->priority == 0) && \
(other.priority != 0));  
     if (!smaller && (this->priority == other.priority)) {
         QString countryCode = KGlobal::locale()->country();
@@ -336,7 +340,10 @@
 void KGetMetalink::Url::load(const QDomElement &e)
 {
     location = e.attribute("location").toLower();
-    priority = e.attribute("priority").toInt();
+    priority = e.attribute("priority").toUInt();
+    if (priority > Metalink::MAX_PRIORITY) {
+        priority = Metalink::MAX_PRIORITY;
+    }
     url = KUrl(e.text());
 }
 
@@ -704,6 +711,8 @@
     files.clear();
 }
 
+const uint KGetMetalink::Metalink_v3::MAX_PREFERENCE = 100;//as defined in Metalink \
specification 3.0 2nd edition +
 KGetMetalink::Metalink_v3::Metalink_v3()
 {
 }
@@ -844,12 +853,12 @@
     for (QDomElement elemRes = res.firstChildElement("url"); !elemRes.isNull(); \
elemRes = elemRes.nextSiblingElement("url")) {  const QString location = \
elemRes.attribute("location").toLower();  
-        int preference = elemRes.attribute("preference").toInt();
-        //the maximum preference we use is 100
-        if (preference > 100) {
-            preference = 100;
+        uint preference = elemRes.attribute("preference").toUInt();
+        //the maximum preference we use is MAX_PREFERENCE
+        if (preference > MAX_PREFERENCE) {
+            preference = MAX_PREFERENCE;
         }
-        const int priority = 100 - preference + 1;//convert old preference to new \
priority +        const int priority = MAX_PREFERENCE - preference + 1;//convert old \
preference to new priority  
         const KUrl link = KUrl(elemRes.text());
         QString type;
@@ -1027,11 +1036,11 @@
 
     foreach (const Url &url, resources.urls) {
         QDomElement elem = doc.createElement("url");
-        if (url.priority) {
-            const int priority = url.priority;
-            int preference = 100 - priority + 1;
+        const uint priority = url.priority;
+        if (priority) {
+            int preference = MAX_PREFERENCE - priority + 1;
             if (preference <= 0) {
-                preference = 1;//HACK if priority is larger 100 makes it 1
+                preference = 1;//HACK if priority is larger MAX_PREFERENCE makes it \
1  }
             elem.setAttribute("preference", preference);
         }
@@ -1049,11 +1058,11 @@
         if (metaurl.type == "torrent") {
             QDomElement elem = doc.createElement("url");
             elem.setAttribute("type", "bittorrent");
-            if (metaurl.priority) {
-                const int priority = metaurl.priority;
-                int preference = 100 - priority + 1;
+            const uint priority = metaurl.priority;
+            if (priority) {
+                int preference = MAX_PREFERENCE - priority + 1;
                 if (preference <= 0) {
-                    preference = 1;//HACK if priority is larger 100 makes it 1
+                    preference = 1;//HACK if priority is larger MAX_PREFERENCE makes \
it 1  }
                 elem.setAttribute("preference", preference);
             }
--- trunk/KDE/kdenetwork/kget/ui/metalinkcreator/metalinker.h #1056821:1056822
@@ -117,7 +117,10 @@
 class Metaurl
 {
     public:
-        Metaurl() {}
+        Metaurl()
+          : priority(0)
+        {
+        }
 
         /**
          * "smaller" urls are less important than larger, larger urls should be \
preffered @@ -134,10 +137,10 @@
         QString type;
 
         /**
-         * the priority of the urls, 1 is highest priority, higher numbers mean
-         * a lower priority
+         * the priority of the urls, 1 is highest priority, 255 lowest
+         * default is 0 as in not set and thus is ranked even behind 255
          */
-        int priority;
+        uint priority;
 
         /**
          * Optional the name of a file that should be get of that metaurl
@@ -168,10 +171,10 @@
         void clear();
 
         /**
-         * the preference of the urls, 100 is highest priority, 1 lowest
-         * default is 0 as in not set
+         * the priority of the urls, 1 is highest priority, 255 lowest
+         * default is 0 as in not set and thus is ranked even behind 255
          */
-        int priority;
+        uint priority;
 
         /**
          * the location of the server eg. "uk"
@@ -316,6 +319,7 @@
         Files files;
 
         static const QString KGET_DESCRIPTION;
+        static const uint MAX_PRIORITY; //maximum pirority a Metalink 4.0 Url or \
Metaurl can have, not to be mixed up with the highest priority  };
 
 /**
@@ -359,6 +363,7 @@
 
     private:
         Metalink m_metalink;
+        static const uint MAX_PREFERENCE;
 };
 
 /**
--- trunk/KDE/kdenetwork/kget/ui/mirror/mirrormodel.cpp #1056821:1056822
@@ -64,7 +64,7 @@
         else if (index.column() == MirrorItem::Priority)
         {
             QSpinBox *preference = new QSpinBox(parent);
-            preference->setRange(0, 100);
+            preference->setRange(0, 255);
 
             return preference;
         }


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

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