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

svn at pcbsd.org svn at pcbsd.org
Wed Jan 30 12:35:40 PST 2013


Author: kris
Date: 2013-01-30 20:35:40 +0000 (Wed, 30 Jan 2013)
New Revision: 21257

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

Improve pc-updategui, now it will read the EVENT_PIPE file from pkgng,
and use it to display download progress. 



Modified: pcbsd/current/src-qt4/pc-updategui/mainWin.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-updategui/mainWin.cpp	2013-01-30 20:31:54 UTC (rev 21256)
+++ pcbsd/current/src-qt4/pc-updategui/mainWin.cpp	2013-01-30 20:35:40 UTC (rev 21257)
@@ -9,10 +9,12 @@
 ** These will automatically be called by the form's constructor and
 ** destructor.
 *****************************************************************************/
+#include <fcntl.h>
 #include <QDebug>
 #include <QDir>
 #include <QProcess>
 #include <QProgressDialog>
+#include <QSocketNotifier>
 #include <QString>
 #include <QTextStream>
 #include <pcbsd-utils.h>
@@ -613,29 +615,15 @@
   else
     uProc->start("chroot", QStringList() << wDir << "pc-updatemanager" << "pkgupdate");
 
+  textLabel->setText(tr("Starting package updates..."));
+
   progressUpdate->setRange(0, listViewUpdatesPkgs->topLevelItemCount() );
   progressUpdate->setValue(0);
 }
 
 void mainWin::slotReadPkgUpdateOutput() {
-   QString line, tmp;
-   if ( dPackages )
-   {
-     line = uProc->readAll();
-     qDebug() << "Read my dline:" <<  line;
-     if ( line.indexOf("Checking integrity") == 0 ) {
-       textLabel->setText(line);
-       uPackages = true;
-       dPackages = false;
-       curUpdate = 0;
-       progressUpdate->setValue(0);
-     }
+   QString line, tmp, cur, tot, fname;
 
-     progressUpdate->setValue( progressUpdate->value() + line.count("Downloading"));
-     return;
-   }
-
-
    while (uProc->canReadLine()) {
      line = uProc->readLine().simplified();
      qDebug() << "Normal Line:" << line;
@@ -649,6 +637,22 @@
        slotReadPkgUpdateOutput(); 
        return;
      }
+     if ( line.indexOf("Checking integrity") == 0 ) {
+       textLabel->setText(line);
+       uPackages = true;
+       dPackages = false;
+       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 ( dPackages ) {
        curUpdate++;
        progressUpdate->setValue(curUpdate);
@@ -666,6 +670,44 @@
    } // end of while
 }
 
+// Function to read output of pipefile
+void mainWin::slotReadEventPipe(int fd) {
+  QString tmp, fname, cur, tot;
+  bool ok, ok2;
+  char buff[4028];
+  int totread = read(fd, buff, 4020);
+  buff[totread]='\0';
+  QString line = buff;
+  line = line.simplified();
+  //qDebug() << "Found line:" << line;
+  
+  if ( line.indexOf("INFO_FETCH") != -1  && dPackages ) {
+     tmp = line;
+     fname = tmp.section(":", 4, 4);
+     fname.remove(0, fname.lastIndexOf('/') + 1);
+     fname  = fname.section('"', 0, 0);
+     cur = tmp.section(":", 5, 5);
+     cur = cur.remove(',');
+     cur = cur.section(" ", 1, 1);
+     cur = cur.simplified();
+     tot = tmp.section(":", 6, 6);
+     tot = tot.simplified();
+     tot = tot.remove(',');
+     tot = tot.section("}", 0, 0);
+
+     textLabel->setText(tr("Downloading %1").arg(fname));
+     tot.toInt(&ok);
+     cur.toInt(&ok2);
+     if ( ok && ok2 )
+     { 
+       progressUpdate->setRange(0, tot.toInt(&ok2));
+       progressUpdate->setValue(cur.toInt(&ok2));
+     }
+     
+     //qDebug() << "File:" << fname << "cur" << cur << "tot" << tot;
+  }
+}
+
 void mainWin::slotUpdatePkgDone() {
   progressUpdate->setHidden(true);
   checkMPKGUpdates();

Modified: pcbsd/current/src-qt4/pc-updategui/mainWin.h
===================================================================
--- pcbsd/current/src-qt4/pc-updategui/mainWin.h	2013-01-30 20:31:54 UTC (rev 21256)
+++ pcbsd/current/src-qt4/pc-updategui/mainWin.h	2013-01-30 20:35:40 UTC (rev 21257)
@@ -7,6 +7,7 @@
 #include <QMessageBox>
 #include <QProcess>
 #include <QProgressDialog>
+#include <QSocketNotifier>
 #include <QStringList>
 #include <QTextStream>
 #include <QTimer>
@@ -52,6 +53,7 @@
     void slotUpdatePkgsClicked();
     void slotReadPkgUpdateOutput();
     void slotUpdatePkgDone();
+    void slotReadEventPipe(int fd);
 
 private:
     void doUpdates();
@@ -68,6 +70,7 @@
     QList<QStringList> listUpdates;
     QString wDir, wIP;
     QString lastError;
+    QSocketNotifier *eSock;
 
 signals:
 

Modified: pcbsd/current/src-qt4/pc-updategui/pc-updategui.pro
===================================================================
--- pcbsd/current/src-qt4/pc-updategui/pc-updategui.pro	2013-01-30 20:31:54 UTC (rev 21256)
+++ pcbsd/current/src-qt4/pc-updategui/pc-updategui.pro	2013-01-30 20:35:40 UTC (rev 21257)
@@ -1,6 +1,5 @@
 TEMPLATE	= app
 LANGUAGE	= C++
-
 CONFIG	+= qt warn_on release
 
 LIBS	+= -L../libpcbsd -L/usr/local/lib -lpcbsd -lQtSolutions_SingleApplication-head



More information about the Commits mailing list