[PC-BSD Commits] r3710 - in pcbsd/trunk: SystemUpdaterTray kcmPBMsource

svn at pcbsd.org svn at pcbsd.org
Tue Mar 31 11:12:30 PST 2009


Author: kris
Date: 2009-03-31 12:12:29 -0700 (Tue, 31 Mar 2009)
New Revision: 3710

Modified:
   pcbsd/trunk/SystemUpdaterTray/UpdaterTray.cpp
   pcbsd/trunk/SystemUpdaterTray/UpdaterTray.h
   pcbsd/trunk/kcmPBMsource/pbm.cpp
   pcbsd/trunk/kcmPBMsource/pbm.h
Log:

Large update to the PBI updater and tray updater, fixed bugs with checking for updates not showing all the updates properly, due to buffering problems when getting the data back from server. Also added feature which will check the PBI's "made date", and not try to have the user install an older PBI on top of a newer copy. This is helpful when the user is running PBI's which are not yet in the online-update service



Modified: pcbsd/trunk/SystemUpdaterTray/UpdaterTray.cpp
===================================================================
--- pcbsd/trunk/SystemUpdaterTray/UpdaterTray.cpp	2009-03-31 18:29:02 UTC (rev 3709)
+++ pcbsd/trunk/SystemUpdaterTray/UpdaterTray.cpp	2009-03-31 19:12:29 UTC (rev 3710)
@@ -71,9 +71,12 @@
 QString PBIProgURL2[900];
 QString PBIProgURL3[900];
 QString PBIProgMD5[900];
+QString PBIProgMdate[900];
 QString PBIProgLoc[900];
 int     PBIProgUpdate[900];
 int     PBIProgFailed[900];
+QString PBIBuffer;
+QString updatePBITextList;
 
 void UpdaterTray::programInit()
 {
@@ -479,7 +482,8 @@
    // If the program has a PBI update
    if ( pbistatus == PBI_UPDATES_AVAIL ) 
    {
-      tooltipStr += "<br>" + tr("PBI updates available!");
+      tooltipStr += "<br><br>" + tr("PBI updates available!") + "<br><br>";
+      tooltipStr += updatePBITextList;
    }
    
 
@@ -648,7 +652,15 @@
 // Start checking our list of PBIs which may be updatable
 void UpdaterTray::slotPBICheckUpdate()
 {
+  // Read the buffer from the last PBI check
+  if (currentWorkingPBI != -1 )
+  {
+    slotReadPBIBuffer();
+  }
 
+  // Empty out our PBI buffer
+  PBIBuffer="";
+
     QString tmp, line;
     QString progName, Arch, Version, PBIUrl;
 
@@ -714,17 +726,25 @@
   QString postData = "PBIName=" + progName + "&PBIVer=" + PBIProgVer[currentWorkingPBI] + "&PCBSDVER=" + Version + "&OSARCH=" + Arch;
   
   checkPBIJob = KIO::http_post( PBIUrl, postData.utf8(), KIO::HideProgressInfo);
+  connect(checkPBIJob, SIGNAL(result(KJob *)), this, SLOT(slotPBICheckUpdate() ) );
+  connect(checkPBIJob, SIGNAL(data(KIO::Job *, const QByteArray&)), this, SLOT(slotRecieveData(KIO::Job *, const QByteArray& ) ) );
   checkPBIJob->addMetaData("content-type", "Content-type: application/x-www-form-urlencoded" );
 
 
-  connect(checkPBIJob, SIGNAL(result(KJob *)), this, SLOT(slotPBICheckUpdate() ) );
-  connect(checkPBIJob, SIGNAL(data(KIO::Job *, const QByteArray&)), this, SLOT(slotRecieveData(KIO::Job *, const QByteArray& ) ) );
 
 }
 
 void UpdaterTray::slotRecieveData(KIO::Job*, const QByteArray& data)
 {
-    QString output(data), line;
+    QString output(data);
+    PBIBuffer = PBIBuffer + output;
+}
+
+void UpdaterTray::slotReadPBIBuffer()
+{
+    QString output = PBIBuffer;
+    QString line;
+
     QStringList outputList;
     if ( output.indexOf("Up2Date") == -1  && ! output.isEmpty())
     {
@@ -758,6 +778,10 @@
              {
                  PBIProgMD5[currentWorkingPBI] = line.replace("MD5: ", "");
              } 
+             if ( line.find("MDATE:") == 0)
+             {
+                 PBIProgMdate[currentWorkingPBI] = line.replace("MDATE: ", "");
+             } 
         } // End of For loop reading line-by-line our data
 
         // Check to ensure we have found all our variables
@@ -776,6 +800,7 @@
 {
   int i = 0, foundUpdates = 0;
   QString text, tmp, newMsg, ProgDirName, iconPath;
+  bool updateAvail;
 
     while (! PBIProgName[i].isEmpty() )
     {
@@ -791,31 +816,83 @@
    	  tmp.replace(" ", "");
   	  ProgDirName = ProgDirName + tmp;
           iconPath = "/Programs/" + ProgDirName + "/" + PBIProgIcon[i];
-          foundUpdates++;
+          updateAvail=true;
+
+          // Now check if we have a *newer* PBI installed here, than is in the updater
+          QFile mdatefile( "/Programs/" + ProgDirName + "/.mdate");
+          if ( mdatefile.exists() && ! PBIProgMdate[i].isEmpty() )
+          {
+	     if ( mdatefile.open( QIODevice::ReadOnly ) ) {
+               QTextStream stream( &mdatefile );
+               QString line;
+               line = stream.readLine(); // line of text excluding '\n'
+               if ( ! line.isEmpty() ) {
+
+                 // Sort the dates from the .mdate file
+                 QString tmp2 = line;
+                 tmp2.truncate( tmp2.indexOf(" ") );
+                 QString date1 = tmp2;
+	         tmp2 = line;
+                 QString date2 = tmp2.remove( 0, tmp2.indexOf(" ") );
+
+                 // Sort the dates from the updater
+                 tmp2 = PBIProgMdate[i];
+                 tmp2.truncate( tmp2.indexOf(" ") );
+                 QString PBIdate1 = tmp2;
+                 tmp2 = PBIProgMdate[i];
+                 QString PBIdate2 = tmp2.remove( 0, tmp2.indexOf(" ") );
+
+		 // Check if the installed PBI is created later than the online update
+		 int ldate, odate;
+ 		 bool ok;
+                 ldate = date1.toInt(&ok);
+                 if ( ok )
+                 {
+                   odate = PBIdate1.toInt(&ok);
+                   if ( ok )
+                   {
+		     if ( ldate > odate )
+		     {
+                       updateAvail = false;
+		     } else if (ldate == odate) {
+                        // We checked the year / day, now check the hours seconds
+                        ldate = date2.toInt(&ok);
+                        if ( ok )
+                        {
+                           odate = PBIdate2.toInt(&ok);
+                           if ( ok )
+                           {
+		             if ( ldate > odate )
+		             {
+                               updateAvail = false;
+			     }
+                           }
+                        }
+                     }
+                   }
+                 }
+               
+                 /* QMessageBox::critical( 0, tr("Online Update"), "date1: " + date1, QMessageBox::Ok );
+                 QMessageBox::critical( 0, tr("Online Update"), "date2: " + date2, QMessageBox::Ok );
+                 QMessageBox::critical( 0, tr("Online Update"), "PBIdate1: " + PBIdate1, QMessageBox::Ok );
+                 QMessageBox::critical( 0, tr("Online Update"), "PBIdate2: " + PBIdate2, QMessageBox::Ok ); */
+               }
+             }
+
+              
+          }
+
+          // If this is a valid update, go ahead and increment our update counter
+          if ( updateAvail ) {
+  	    updatePBITextList = updatePBITextList + PBIProgName[i] + " " +  PBIProgNewVer[i] + "<br>";
+            foundUpdates++;
+          }
        }
        i++;
     }
 
   if ( foundUpdates != 0 ) {
-  // Update our dialog that we are looking for PBI updates right now
-    if (foundUpdates == 1 ) {
-       newMsg = "<font color=\"#ff0000\">" + tmp.setNum(foundUpdates) + " " + tr("PBI Update available!") + "</font>";
-       QImage Icon2;
-       Icon2.load("/PCBSD/SystemUpdater/images/pbiupdates.png");
-       QPixmap PixmapIcon2;
-       PixmapIcon2.convertFromImage(Icon2.scaled(22,22));
-
-       KPassivePopup::message(tr("System Update") , tr("A PBI update is available!"),  PixmapIcon2,  this);
-    } else {
-       newMsg = "<font color=\"#ff0000\">" + tmp.setNum(foundUpdates) + " " + tr("PBI Updates available!") + "</font>";
-       QImage Icon2;
-       Icon2.load("/PCBSD/SystemUpdater/images/pbiupdates.png");
-       QPixmap PixmapIcon2;
-       PixmapIcon2.convertFromImage(Icon2.scaled(22,22));
-
-       KPassivePopup::message(tr("System Update") , tr("PBI updates are available!"),  PixmapIcon2,  this);
-    }
-
+    // Set the status that we have new PBIs
     pbistatus = PBI_UPDATES_AVAIL;
   } else {
      // No PBI updates found right now!

Modified: pcbsd/trunk/SystemUpdaterTray/UpdaterTray.h
===================================================================
--- pcbsd/trunk/SystemUpdaterTray/UpdaterTray.h	2009-03-31 18:29:02 UTC (rev 3709)
+++ pcbsd/trunk/SystemUpdaterTray/UpdaterTray.h	2009-03-31 19:12:29 UTC (rev 3710)
@@ -39,6 +39,7 @@
    void slotTrayActivated(QSystemTrayIcon::ActivationReason reason);
    void slotRecieveData(KIO::Job*, const QByteArray& data);
    void slotCheckAllUpdates();
+   void slotReadPBIBuffer();
    
 protected:
    

Modified: pcbsd/trunk/kcmPBMsource/pbm.cpp
===================================================================
--- pcbsd/trunk/kcmPBMsource/pbm.cpp	2009-03-31 18:29:02 UTC (rev 3709)
+++ pcbsd/trunk/kcmPBMsource/pbm.cpp	2009-03-31 19:12:29 UTC (rev 3710)
@@ -2066,10 +2066,19 @@
 void PBM::slotPBICheckUpdate()
 {
 
-    QString tmp, line;
-    QString progName, Arch, Version, PBIUrl;
+  // Read the buffer from the last PBI check
+  if (currentWorkingPBI != -1 )
+  {
+    slotReadPBIBuffer();
+  }
+  
+  // Empty out our PBI buffer
+  PBIBuffer="";
 
+  QString tmp, line;
+  QString progName, Arch, Version, PBIUrl;
 
+
     // Jump to the next PBI in our list
     currentWorkingPBI++;
 
@@ -2128,28 +2137,41 @@
    }
 
   QString postData = "PBIName=" + progName + "&PBIVer=" + PBIProgVer[currentWorkingPBI] + "&PCBSDVER=" + Version + "&OSARCH=" + Arch;
+
   
+
   checkPBIJob = KIO::http_post( PBIUrl, postData.utf8(), KIO::HideProgressInfo);
+  connect(checkPBIJob, SIGNAL(result(KJob *)), this, SLOT(slotPBICheckUpdate() ) );
+  connect(checkPBIJob, SIGNAL(data(KIO::Job *, const QByteArray&)), this, SLOT(slotRecieveData(KIO::Job *, const QByteArray& ) ) );
+
   checkPBIJob->addMetaData("content-type", "Content-type: application/x-www-form-urlencoded" );
   
   textPBIStatus->setText(tr("<font color=\"#ff0000\">Checking %1 for updates...</font>").arg(progName) );
 
-  connect(checkPBIJob, SIGNAL(result(KJob *)), this, SLOT(slotPBICheckUpdate() ) );
-  connect(checkPBIJob, SIGNAL(data(KIO::Job *, const QByteArray&)), this, SLOT(slotRecieveData(KIO::Job *, const QByteArray& ) ) );
 
 }
 
 void PBM::slotRecieveData(KIO::Job*, const QByteArray& data)
 {
-    QString output(data), line;
+    QString output(data);
+
+    PBIBuffer = PBIBuffer + output;
+}
+
+void PBM::slotReadPBIBuffer()
+{
+    QString output = PBIBuffer;
+    QString line;
     QStringList outputList;
     if ( output.indexOf("Up2Date") == -1  && ! output.isEmpty())
     {
+        //QMessageBox::critical( 0, tr("Online Update"), "line: " + output, QMessageBox::Ok );
+
         outputList = QStringList::split("\n", output);
         for ( int i = 0; i < outputList.size(); i++)
         {
             line = outputList.at(i);
-           
+
              if (line.find("NewVer:" ) ==  0 )
              {
                PBIProgNewVer[currentWorkingPBI] = line.replace("NewVer: ", "");
@@ -2175,6 +2197,10 @@
              {
                  PBIProgMD5[currentWorkingPBI] = line.replace("MD5: ", "");
              } 
+             if ( line.find("MDATE:") == 0)
+             {
+                 PBIProgMdate[currentWorkingPBI] = line.replace("MDATE: ", "");
+             } 
         } // End of For loop reading line-by-line our data
 
         // Check to ensure we have found all our variables
@@ -2193,6 +2219,7 @@
 {
   int i = 0, foundUpdates = 0;
   QString text, tmp, newMsg, ProgDirName, iconPath;
+  bool updateAvail;
 
     while (! PBIProgName[i].isEmpty() )
     {
@@ -2208,17 +2235,84 @@
    	  tmp.replace(" ", "");
   	  ProgDirName = ProgDirName + tmp;
           iconPath = "/Programs/" + ProgDirName + "/" + PBIProgIcon[i];
+          updateAvail = true;
 
-          QPixmap defaultIcon;
-          Q3CheckListItem *item = new Q3CheckListItem ( listViewPBIUpdates, text, Q3CheckListItem::CheckBox  ) ;
-          item->setText(1, tmp.setNum(i));
+          // Now check if we have a *newer* PBI installed here, than is in the updater
+          QFile mdatefile( "/Programs/" + ProgDirName + "/.mdate");
+          if ( mdatefile.exists() && ! PBIProgMdate[i].isEmpty() )
+          {
+	     if ( mdatefile.open( QIODevice::ReadOnly ) ) {
+               Q3TextStream stream( &mdatefile );
+               QString line;
+               line = stream.readLine(); // line of text excluding '\n'
+               if ( ! line.isEmpty() ) {
 
-          defaultIcon.convertFromImage(QImage(iconPath).smoothScale(32,32));
+                 // Sort the dates from the .mdate file
+                 QString tmp2 = line;
+                 tmp2.truncate( tmp2.indexOf(" ") );
+                 QString date1 = tmp2;
+	         tmp2 = line;
+                 QString date2 = tmp2.remove( 0, tmp2.indexOf(" ") );
 
-          item->setPixmap ( 0, defaultIcon ) ;
-          listViewPBIUpdates->setColumnAlignment ( 0, Qt::AlignVCenter);
+                 // Sort the dates from the updater
+                 tmp2 = PBIProgMdate[i];
+                 tmp2.truncate( tmp2.indexOf(" ") );
+                 QString PBIdate1 = tmp2;
+                 tmp2 = PBIProgMdate[i];
+                 QString PBIdate2 = tmp2.remove( 0, tmp2.indexOf(" ") );
 
-          foundUpdates++;
+		 // Check if the installed PBI is created later than the online update
+		 int ldate, odate;
+ 		 bool ok;
+                 ldate = date1.toInt(&ok);
+                 if ( ok )
+                 {
+                   odate = PBIdate1.toInt(&ok);
+                   if ( ok )
+                   {
+		     if ( ldate > odate )
+		     {
+                       updateAvail = false;
+		     } else if (ldate == odate) {
+                        // We checked the year / day, now check the hours seconds
+                        ldate = date2.toInt(&ok);
+                        if ( ok )
+                        {
+                           odate = PBIdate2.toInt(&ok);
+                           if ( ok )
+                           {
+		             if ( ldate > odate )
+		             {
+                               updateAvail = false;
+			     }
+                           }
+                        }
+                     }
+                   }
+                 }
+               
+                 /* QMessageBox::critical( 0, tr("Online Update"), "date1: " + date1, QMessageBox::Ok );
+                 QMessageBox::critical( 0, tr("Online Update"), "date2: " + date2, QMessageBox::Ok );
+                 QMessageBox::critical( 0, tr("Online Update"), "PBIdate1: " + PBIdate1, QMessageBox::Ok );
+                 QMessageBox::critical( 0, tr("Online Update"), "PBIdate2: " + PBIdate2, QMessageBox::Ok ); */
+               }
+             }
+
+              
+          }
+
+          if ( updateAvail ) {
+           QPixmap defaultIcon;
+           Q3CheckListItem *item = new Q3CheckListItem ( listViewPBIUpdates, text, Q3CheckListItem::CheckBox  ) ;
+           item->setText(1, tmp.setNum(i));
+
+           defaultIcon.convertFromImage(QImage(iconPath).smoothScale(32,32));
+
+           item->setPixmap ( 0, defaultIcon ) ;
+           listViewPBIUpdates->setColumnAlignment ( 0, Qt::AlignVCenter);
+
+           foundUpdates++;
+          }
        }
        i++;
     }

Modified: pcbsd/trunk/kcmPBMsource/pbm.h
===================================================================
--- pcbsd/trunk/kcmPBMsource/pbm.h	2009-03-31 18:29:02 UTC (rev 3709)
+++ pcbsd/trunk/kcmPBMsource/pbm.h	2009-03-31 19:12:29 UTC (rev 3710)
@@ -86,6 +86,7 @@
     void slotSelectCustomTmp();
     void slotInstallUpdatesClicked();
     void slotCheckSysUpdatesFlags();
+    void slotReadPBIBuffer();
 private:
     void RemoveFiles( PBI * pbi );
     void loadComponents();
@@ -167,9 +168,11 @@
     QString PBIProgURL2[900];
     QString PBIProgURL3[900];
     QString PBIProgMD5[900];
+    QString PBIProgMdate[900];
     QString PBIProgLoc[900];
     int     PBIProgUpdate[900];
     int     PBIProgFailed[900];
+    QString PBIBuffer;
 signals:
 
 } ;



More information about the Commits mailing list