[PC-BSD Commits] r1482 - pcbsd/trunk/SystemUpdater

svn at pcbsd.org svn at pcbsd.org
Thu Feb 28 16:07:16 PST 2008


Author: tim
Date: 2008-02-28 16:07:16 -0800 (Thu, 28 Feb 2008)
New Revision: 1482

Modified:
   pcbsd/trunk/SystemUpdater/SystemUpdater.pro
   pcbsd/trunk/SystemUpdater/UpdaterTray.cpp
   pcbsd/trunk/SystemUpdater/UpdaterTray.h
   pcbsd/trunk/SystemUpdater/updaterDialog.ui
   pcbsd/trunk/SystemUpdater/updaterDialog.ui.h
Log:
Altered the method SystemUpdater uses to retrieve files from the update site.

SystemUpdater now uses KIO::file_copy to transfer the file. This allows for better status reporting to the user, and removes instances where the output of 'fetch' might not correctly be parsed for display.



Modified: pcbsd/trunk/SystemUpdater/SystemUpdater.pro
===================================================================
--- pcbsd/trunk/SystemUpdater/SystemUpdater.pro	2008-02-28 23:34:47 UTC (rev 1481)
+++ pcbsd/trunk/SystemUpdater/SystemUpdater.pro	2008-02-29 00:07:16 UTC (rev 1482)
@@ -2,18 +2,23 @@
 LANGUAGE	= C++
 
 CONFIG	+= qt warn_on release
+
+LIBS	+= -lkdeui -lkdeinit_kcmshell
+
+HEADERS	+= UpdaterTray.h
+
+SOURCES	+= main.cpp \
+	UpdaterTray.cpp
+
+FORMS	= SystemUpdater.ui \
+	updaterDialog.ui
+
 TARGET  = SystemUpdater
 DESTDIR = /PCBSD/SystemUpdater/bin/
 
-FORMS	= SystemUpdater.ui \
-          updaterDialog.ui	
 
-LIBS    += -lkdeui -lkdeinit_kcmshell
 
-HEADERS += UpdaterTray.h
 
-SOURCES += main.cpp \
-        UpdaterTray.cpp
 
 unix {
   UI_DIR = .ui

Modified: pcbsd/trunk/SystemUpdater/UpdaterTray.cpp
===================================================================
--- pcbsd/trunk/SystemUpdater/UpdaterTray.cpp	2008-02-28 23:34:47 UTC (rev 1481)
+++ pcbsd/trunk/SystemUpdater/UpdaterTray.cpp	2008-02-29 00:07:16 UTC (rev 1482)
@@ -17,6 +17,7 @@
 #include <kmessagebox.h>
 #include <kpassivepopup.h>
 #include <iostream>
+#include <kio/job.h>
 
 #include "UpdaterTray.h"
 #include "SystemUpdater.h"
@@ -55,7 +56,6 @@
 int firstDownload = 0;
 long totalSeconds = 0;
 long downloadSize = 0;
-int stopReadListing = 0;
 int totalSteps = 0;
 int attemptedRedownload = 0;
 int firstInstall = 0;
@@ -68,8 +68,6 @@
 updaterStatus *UpdaterStatusDialog;
 QProcess *getUpdatesDir;
 QProcess *readSysUpdates;
-QProcess *fetchSizeProc;
-QProcess *fetchProc;
 QProcess *listingProc;
 QProcess *checksumProc;
 QProcess *extractProc;
@@ -106,9 +104,6 @@
 int     PBIProgUpdate[900];
 int     PBIProgFailed[900];
 
-
-
-
 UpdaterTray::UpdaterTray() {
 
 }
@@ -1066,175 +1061,24 @@
    status = tr("Downloading updates...");
    UpdaterStatusDialog->setLabelSysUpdateStatus(status);
 
-    // Flag that we can start listing file data again
-    stopReadListing = 0;
-
-    // Start process to get filesize and update progressbar
-    fetchSizeProc = new QProcess( this );
-    fetchSizeProc->addArgument( "fetch" );
-    fetchSizeProc->addArgument( "-s" );
-    fetchSizeProc->addArgument( SysUpdateURL[currentSysWorkingItem]  );
-
-    connect( fetchSizeProc, SIGNAL(readyReadStdout()), this, SLOT(slotReadFetchSize() ) );
-
-    if ( !fetchSizeProc->start() ) {
-
-    }
-
-
-        // Start download process
-    fetchProc = new QProcess( this );
-    fetchProc->addArgument( "fetch" );
-    fetchProc->addArgument( "-o" );
-    fetchProc->addArgument( "/PCBSD/tmp/patch" + tmp.setNum(currentSysWorkingItem) + ".lzma" );
-    fetchProc->addArgument( SysUpdateURL[currentSysWorkingItem] );
-	
-    connect( fetchProc, SIGNAL(processExited()), this, SLOT(slotStartCheckSysMD5() ) );
+    UpdaterStatusDialog->setProgressTotalSteps(100);
     
-	    if ( ! fetchProc->start() ) {
-                QMessageBox::critical( 0, tr("Online Update"), tr("An error occured while downloading. Please try again later.") );
-			
-	    } 
-
-
-}
-
-
-
-
-
-
-
-// Read the fetch size of the file we are downloading
-void UpdaterTray::slotReadFetchSize()
-{
-    QString tmp;
-    long size;
-    bool ok;
+    copyJob = KIO::file_copy(SysUpdateURL[currentSysWorkingItem], "/PCBSD/tmp/patch" + tmp.setNum(currentSysWorkingItem) + ".lzma", -1, true, false, false);
     
-    totalSeconds=0;
-    
-     if(fetchSizeProc->canReadLineStdout() )
-     {	// Read the line,  getting filesize
-	
-	 tmp = fetchSizeProc->readLineStdout();
-	 size = tmp.toLong(&ok);
-	 // We have a good number now
-	 if ( ok)
-	 {
-	     // Setup the progressbar
-	     UpdaterStatusDialog->setProgressTotalSteps(size);
-	     totalSteps = size;
-	     UpdaterStatusDialog->setProgressSteps(0);
-	     downloadSize = size;
-                QTimer::singleShot( 1000, this, SLOT(slotGetFetchProgress()) );
-	     
-	 }
-     }
+    connect(copyJob, SIGNAL(totalSize(KIO::Job*, KIO::filesize_t)), UpdaterStatusDialog, SLOT(slotJobUpdateTotalSize( KIO::Job*, KIO::filesize_t)));
+    connect(copyJob, SIGNAL(percent(KIO::Job*, unsigned long)), UpdaterStatusDialog, SLOT(slotJobSetPercent(KIO::Job*, unsigned long)));
+    connect(copyJob, SIGNAL(speed(KIO::Job*, unsigned long)), UpdaterStatusDialog, SLOT(slotJobUpdateSpeed( KIO::Job*, unsigned long)));
+    connect(copyJob, SIGNAL(processedSize(KIO::Job*, KIO::filesize_t)), UpdaterStatusDialog, SLOT(slotJobUpdateProcessedSize( KIO::Job*, KIO::filesize_t)));
+    connect(copyJob, SIGNAL(result(KIO::Job*)), this, SLOT(slotStartCheckSysMD5()));
 
-}
 
-
-
-
-
-
-
-
-void UpdaterTray::slotGetFetchProgress()
-{
-    QString tmp;
-
-    if ( fetchProc->isRunning() )
-    {
-          if ( pbistatus == PBI_UPDATING ) {
-            // Do a listing of the PBI file
-            listingProc = new QProcess( this );
-            listingProc->addArgument( "ls" ); 
-            listingProc->addArgument( "-l" );
-            listingProc->addArgument( "/PCBSD/tmp/" + tmp.setNum(currentWorkingPBI) + ".pbi");
-        
-            connect( listingProc, SIGNAL(readyReadStdout()), this, SLOT(slotReadFetchProgress() ) );
-    
-            if ( ! listingProc->start() ) {
-            }
-          } else {
-
-            // Do a listing of the patch file
-            listingProc = new QProcess( this );
-            listingProc->addArgument( "ls" ); 
-            listingProc->addArgument( "-l" );
-            listingProc->addArgument( "/PCBSD/tmp/patch" + tmp.setNum(currentSysWorkingItem) + ".lzma");
-        
-            connect( listingProc, SIGNAL(readyReadStdout()), this, SLOT(slotReadFetchProgress() ) );
-    
-            if ( ! listingProc->start() ) {
-            }
-
-          }
-         
-    } 
-
 }
 
-
-
-
-
-
-
-void UpdaterTray::slotReadFetchProgress()
-{
-    QString tmp, tmp2;
-    long size; 
-    long diffBytes;    
-    bool ok;
-    int Average = 0;
-
-
-    if ( listingProc->canReadLineStdout() )
-    {
-          tmp = listingProc->readLineStdout();
-          tmp = tmp.section( " ", 4, 4, QString::SectionSkipEmpty);
-          size = tmp.toLong(&ok);
-	  
-          diffBytes = size - downloadSize;	  
-	  
-          UpdaterStatusDialog->setProgressSteps(size);
-
-	  // Calculate the KB/s and display the details for the user
-          totalSeconds++;
-          Average = size / totalSeconds;
-
-	  tmp2 = tmp.setNum(size / 1000) + "KB of " + tmp.setNum(totalSteps / 1000) + "KB (" + tmp.setNum(Average / 1000) + "KB/s Average)";
-	  UpdaterStatusDialog->setLabelSysUpdateStatus( tmp2 );
-
-
-          if ( stopReadListing == 0) {	  
-              QTimer::singleShot( 1000, this, SLOT(slotGetFetchProgress()) );
-          } else {
-	      stopReadListing = 0;  
-          }
-	  
-	  
-    }
-
-}
-
-
-
-
-
-
-
 void UpdaterTray::slotStartCheckSysMD5()
 {
 
     QString tmp;
 
-    // Set the flag to stop reading the file size listing
-    stopReadListing = 1;
-
     // This function starts the internal checksum to ensure the PBI is intact
 
     tmp = tr("Checking data integrity...");
@@ -1994,35 +1838,16 @@
    status = tr("Downloading PBI upgrades...");
    UpdaterStatusDialog->setLabelSysUpdateStatus(status);
 
-    // Flag that we can start listing file data again
-    stopReadListing = 0;
-
-    // Start process to get filesize and update progressbar
-    fetchSizeProc = new QProcess( this );
-    fetchSizeProc->addArgument( "fetch" );
-    fetchSizeProc->addArgument( "-s" );
-    fetchSizeProc->addArgument( URL  );
-
-    connect( fetchSizeProc, SIGNAL(readyReadStdout()), this, SLOT(slotReadFetchSize() ) );
-
-    if ( !fetchSizeProc->start() ) {
-
-    }
-
-
-        // Start download process
-    fetchProc = new QProcess( this );
-    fetchProc->addArgument( "fetch" );
-    fetchProc->addArgument( "-o" );
-    fetchProc->addArgument( "/PCBSD/tmp/" + tmp.setNum(currentWorkingPBI) + ".pbi" );
-    fetchProc->addArgument( URL );
-	
-    connect( fetchProc, SIGNAL(processExited()), this, SLOT(slotDownloadPBIDone() ) );
+    UpdaterStatusDialog->setProgressTotalSteps(100);
     
-	    if ( ! fetchProc->start() ) {
-                QMessageBox::critical( 0, tr("Online Update"), tr("An error occured while downloading. Please try again later.") );
-			
-	    } 
+    copyJob = KIO::file_copy(URL, "/PCBSD/tmp/" + tmp.setNum(currentWorkingPBI) + ".pbi", -1, true, false, false);
+    
+    connect(copyJob, SIGNAL(totalSize(KIO::Job*, KIO::filesize_t)), UpdaterStatusDialog, SLOT(slotJobUpdateTotalSize( KIO::Job*, KIO::filesize_t)));
+    connect(copyJob, SIGNAL(percent(KIO::Job*, unsigned long)), UpdaterStatusDialog, SLOT(slotJobSetPercent(KIO::Job*, unsigned long)));
+    connect(copyJob, SIGNAL(speed(KIO::Job*, unsigned long)), UpdaterStatusDialog, SLOT(slotJobUpdateSpeed( KIO::Job*, unsigned long)));
+    connect(copyJob, SIGNAL(processedSize(KIO::Job*, KIO::filesize_t)), UpdaterStatusDialog, SLOT(slotJobUpdateProcessedSize( KIO::Job*, KIO::filesize_t)));
+    connect(copyJob, SIGNAL(result(KIO::Job*)), this, SLOT(slotDownloadPBIDone()));
+    
 }
 
 
@@ -2034,7 +1859,7 @@
 {
    QString id, tmp;
 
-   if (fetchProc->exitStatus() != 0 )
+   if (copyJob->error() != 0)
    {
       // If the download didn't complete, set the status and try again with the next URL
       firstDownload = 1;

Modified: pcbsd/trunk/SystemUpdater/UpdaterTray.h
===================================================================
--- pcbsd/trunk/SystemUpdater/UpdaterTray.h	2008-02-28 23:34:47 UTC (rev 1481)
+++ pcbsd/trunk/SystemUpdater/UpdaterTray.h	2008-02-29 00:07:16 UTC (rev 1482)
@@ -1,12 +1,12 @@
 
 #include <qpair.h>
 #include <qptrlist.h>
-#include <ksystemtray.h>
 #include <qstring.h>
 
+#include <ksystemtray.h>
+#include <kio/jobclasses.h>
 
 
-
 class QString;
 class QPixmap;
 
@@ -34,9 +34,6 @@
    void slotOpenSysDetails(int id);
    void slotStartSystemUpdate();
    void slotDownloadSysUpdate();
-   void slotReadFetchSize();
-   void slotGetFetchProgress();
-   void slotReadFetchProgress();
    void slotStartCheckSysMD5();
    void slotReadSysMD5();
    void slotStartSysInstall();
@@ -63,6 +60,8 @@
    QString getLineFromCommandOutput( QString command );
    void loadUpdaterPrefs();
    void loadPatchData(QString patchFile, int patchNum);
+
+   KIO::FileCopyJob *copyJob;
 };
 
 

Modified: pcbsd/trunk/SystemUpdater/updaterDialog.ui
===================================================================
--- pcbsd/trunk/SystemUpdater/updaterDialog.ui	2008-02-28 23:34:47 UTC (rev 1481)
+++ pcbsd/trunk/SystemUpdater/updaterDialog.ui	2008-02-29 00:07:16 UTC (rev 1482)
@@ -159,14 +159,24 @@
     </connection>
 </connections>
 <includes>
+    <include location="global" impldecl="in declaration">kio/job.h</include>
     <include location="local" impldecl="in implementation">updaterDialog.ui.h</include>
 </includes>
+<variables>
+    <variable access="private">KIO::filesize_t totalSize;</variable>
+    <variable access="private">KIO::filesize_t processedSize;</variable>
+    <variable access="private">unsigned long speed;</variable>
+</variables>
 <signals>
     <signal>buttonClosedPressed()</signal>
 </signals>
 <slots>
     <slot access="private">slotPushClose()</slot>
     <slot access="private">closeEvent( QCloseEvent * e )</slot>
+    <slot>slotJobSetPercent(KIO::Job*, unsigned long percent)</slot>
+    <slot>slotJobUpdateTotalSize(KIO::Job*, KIO::filesize_t size)</slot>
+    <slot>slotJobUpdateProcessedSize(KIO::Job*, KIO::filesize_t size)</slot>
+    <slot>slotJobUpdateSpeed(KIO::Job*, unsigned long speed)</slot>
 </slots>
 <functions>
     <function>programInit()</function>
@@ -179,6 +189,7 @@
     <function>updateSizeListBoxItem( QString &amp; itemSize, QString &amp; id )</function>
     <function>setUpdatingPBI()</function>
     <function>setUpdatingSystem()</function>
+    <function access="private">generateCopyLabel()</function>
 </functions>
 <layoutdefaults spacing="6" margin="11"/>
 </UI>

Modified: pcbsd/trunk/SystemUpdater/updaterDialog.ui.h
===================================================================
--- pcbsd/trunk/SystemUpdater/updaterDialog.ui.h	2008-02-28 23:34:47 UTC (rev 1481)
+++ pcbsd/trunk/SystemUpdater/updaterDialog.ui.h	2008-02-29 00:07:16 UTC (rev 1482)
@@ -99,3 +99,39 @@
 {
    listInstallView->setColumnText(1, tr("Size") );
 }
+
+
+void updaterStatus::slotJobSetPercent( KIO::Job*, unsigned long percent )
+{
+   progressInstall->setProgress(percent);
+}
+
+
+void updaterStatus::slotJobUpdateTotalSize( KIO::Job *, KIO::filesize_t size )
+{
+   totalSize = size;
+   generateCopyLabel();
+}
+
+
+void updaterStatus::slotJobUpdateProcessedSize( KIO::Job *, KIO::filesize_t size )
+{
+   processedSize = size;
+   generateCopyLabel();
+}
+
+
+void updaterStatus::slotJobUpdateSpeed( KIO::Job *, unsigned long speed )
+{
+   this->speed = speed;
+   generateCopyLabel();
+}
+
+
+void updaterStatus::generateCopyLabel()
+{
+   QString totalSize = QString::number(this->totalSize / 1048576) + "MB";
+   QString processedSize = QString::number(this->processedSize / 1048576) + "MB";
+   QString speed = QString::number(this->speed / 1024) + "KB/s";
+   textInstallStatusLabel->setText(processedSize + tr(" of ") + totalSize + " (" + speed + ")");
+}



More information about the Commits mailing list