[PC-BSD Commits] r21839 - pcbsd/current/src-qt4/pc-updategui

svn at pcbsd.org svn at pcbsd.org
Wed Mar 13 04:42:01 PDT 2013


Author: kris
Date: 2013-03-13 11:42:00 +0000 (Wed, 13 Mar 2013)
New Revision: 21839

Modified:
   pcbsd/current/src-qt4/pc-updategui/mainWin.cpp
   pcbsd/current/src-qt4/pc-updategui/mainWin.h
Log:

Fix the GUI to show proper download status now

Also fix a bug where the main widget was re-enabled while an update
is in process



Modified: pcbsd/current/src-qt4/pc-updategui/mainWin.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-updategui/mainWin.cpp	2013-03-13 10:54:27 UTC (rev 21838)
+++ pcbsd/current/src-qt4/pc-updategui/mainWin.cpp	2013-03-13 11:42:00 UTC (rev 21839)
@@ -25,6 +25,7 @@
 void mainWin::ProgramInit(QString ch, QString ip)
 {
   // Set any warden directories
+  doingUpdate=false;
   lastError="";
   wDir = ch;
   wIP = ip;
@@ -320,6 +321,8 @@
 
 void mainWin::slotRescanUpdates()
 {
+  if ( doingUpdate )
+     return;
   groupUpdates->setEnabled(false);
   listUpdates.clear();
   textLabel->setText(tr("Checking for updates... Please Wait..."));
@@ -331,12 +334,14 @@
     checkAll->setEnabled(false);
   }
   pushInstallUpdates->setEnabled(false); //disable the button until an update is selected
-  groupUpdates->setEnabled(true);
+  if ( ! doingUpdate )
+    groupUpdates->setEnabled(true);
 }
 
 void mainWin::slotDisplayUpdates()
 {
-  tabUpdates->setEnabled(true);
+  if ( ! doingUpdate )
+    tabUpdates->setEnabled(true);
   listViewUpdates->clear();
 
   // Check if the system has an upgrade available
@@ -517,6 +522,8 @@
 }
 
 void mainWin::checkMPKGUpdates() {
+  if ( doingUpdate )
+     return;
 
   QString line, tmp, name, pkgname, pkgover, pkgnver;
   QStringList up, listPkgs;
@@ -630,6 +637,7 @@
 
   dPackages = false;
   uPackages = false;
+  doingUpdate=true;
   curUpdate = 0;
 
   // Setup the upgrade process
@@ -664,11 +672,9 @@
      tmp.truncate(50);
      if ( line.indexOf("to be downloaded") != -1 ) {
        textLabel->setText(tr("Downloading packages..."));
-       dPackages = true;
        curUpdate = 0;
        progressUpdate->setValue(0);
-       slotReadPkgUpdateOutput(); 
-       return;
+       continue;
      }
      if ( line.indexOf("Checking integrity") == 0 ) {
        textLabel->setText(line);
@@ -677,20 +683,44 @@
        curUpdate = 0;
        progressUpdate->setValue(0);
      }
-     if ( line.indexOf("EVENT_PIPE:") != -1 ) {
-        tmp = line;
-        tmp = tmp.section(" ", 1, 1);
-	int fd = ::open(tmp.toLatin1(), O_RDONLY | O_NONBLOCK);
-        eSock = new QSocketNotifier(fd, QSocketNotifier::Read);
-        connect( eSock, SIGNAL(activated(int)), this, SLOT(slotReadEventPipe(int)) );
-        if ( ! eSock->isEnabled() )
-           qDebug() << "Could not connect to socket";
+     if ( line.indexOf("FETCH: ") == 0 ) { 
+	progressUpdate->setValue(progressUpdate->value() + 1); 
+	tmp = line; 
+	tmp = tmp.remove(0, tmp.lastIndexOf("/") + 1); 
+	textLabel->setText(tr("Downloading: %1").arg(tmp)); 
+        continue;
+     } 
+     
+     if ( line.indexOf("SIZE: ") == 0 ) {
+          bool ok, ok2;
+     	  line.replace("SIZE: ", "");
+          line.replace("DOWNLOADED: ", "");
+          line.replace("SPEED: ", "");
+          line.section(" ", 0, 0).toInt(&ok);
+          line.section(" ", 1, 1).toInt(&ok2);
+   
+          if ( ok && ok2 ) {
+	    QString unit;
+            int tot = line.section(" ", 0, 0).toInt(&ok);
+            int cur = line.section(" ", 1, 1).toInt(&ok2);
+            QString percent = QString::number( (float)(cur * 100)/tot );
+            QString speed = line.section(" ", 2, 3);
+
+  	    // Get the MB downloaded / total
+	    if ( tot > 2048 ) {
+	      unit="MB";
+	      tot = tot / 1024;
+       	      cur = cur / 1024;
+	    } else {
+	      unit="KB";
+            }
+
+            QString ProgressString=QString("%1" + unit + " of %2" + unit + " at %3").arg(cur).arg(tot).arg(speed);
+            progressUpdate->setRange(0, tot);
+            progressUpdate->setValue(cur);
+         }
      }
-     if ( dPackages ) {
-       curUpdate++;
-       progressUpdate->setValue(curUpdate);
-       continue;
-     }
+
      if ( uPackages ) {
        if ( line.indexOf("Upgrading") == 0 ) {
          textLabel->setText(line);
@@ -748,5 +778,10 @@
     QTextStream streamTrig( &sysTrig );
      streamTrig << "INSTALLFINISHED: ";
   }
+
+  if ( uProc->exitCode() != 0 )
+    QMessageBox::warning(this, tr("Failed package update"), tr("The package update failed! If this persists, you may need to manually run: pc-updatemanager pkgupdate"));
+
+  doingUpdate=false;
   checkMPKGUpdates();
 }

Modified: pcbsd/current/src-qt4/pc-updategui/mainWin.h
===================================================================
--- pcbsd/current/src-qt4/pc-updategui/mainWin.h	2013-03-13 10:54:27 UTC (rev 21838)
+++ pcbsd/current/src-qt4/pc-updategui/mainWin.h	2013-03-13 11:42:00 UTC (rev 21839)
@@ -67,6 +67,7 @@
     int totUpdate;
     bool dPackages;
     bool uPackages;
+    bool doingUpdate;
     QProcess *uProc;
     QList<QStringList> listUpdates;
     QString wDir, wIP;



More information about the Commits mailing list