[PC-BSD Commits] r18359 - pcbsd/current/src-qt4/libpcbsd

svn at pcbsd.org svn at pcbsd.org
Wed Aug 8 14:17:31 PDT 2012


Author: kris
Date: 2012-08-08 21:17:31 +0000 (Wed, 08 Aug 2012)
New Revision: 18359

Modified:
   pcbsd/current/src-qt4/libpcbsd/dialogMetaProgress.cpp
   pcbsd/current/src-qt4/libpcbsd/dialogMetaProgress.h
   pcbsd/current/src-qt4/libpcbsd/dialogMetaProgress.ui
   pcbsd/current/src-qt4/libpcbsd/metaWidget.cpp
   pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h
   pcbsd/current/src-qt4/libpcbsd/utils.cpp
Log:

Enhance the metaWidget to parse the new download data, so we can show
package download speeds, better progress, etc. 



Modified: pcbsd/current/src-qt4/libpcbsd/dialogMetaProgress.cpp
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/dialogMetaProgress.cpp	2012-08-08 20:16:10 UTC (rev 18358)
+++ pcbsd/current/src-qt4/libpcbsd/dialogMetaProgress.cpp	2012-08-08 21:17:31 UTC (rev 18359)
@@ -22,6 +22,9 @@
     progressTotal->setValue(0);
     progressSub->setRange(0,0);
     progressSub->setValue(0);
+    progressDownload->setRange(0,0);
+    progressDownload->setValue(0);
+    setDLVisible(false);
 }
 
 void dialogMetaProgress::setTotalDesc( QString desc )
@@ -82,3 +85,29 @@
 
    event->ignore();
 }
+
+void dialogMetaProgress::setDLVisible( bool isVis)
+{
+   labelDownload->setVisible(isVis);
+   progressDownload->setVisible(isVis);
+}
+
+void dialogMetaProgress::setDLDesc( QString desc )
+{
+    labelDownload->setText(desc);
+}
+
+void dialogMetaProgress::setDLRange( int min, int max )
+{
+    progressDownload->setRange(min, max);
+}
+
+void dialogMetaProgress::setDLVal( int val )
+{
+    progressDownload->setValue(val);
+}
+
+int dialogMetaProgress::getDLVal( )
+{
+    return progressDownload->value();
+}

Modified: pcbsd/current/src-qt4/libpcbsd/dialogMetaProgress.h
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/dialogMetaProgress.h	2012-08-08 20:16:10 UTC (rev 18358)
+++ pcbsd/current/src-qt4/libpcbsd/dialogMetaProgress.h	2012-08-08 21:17:31 UTC (rev 18359)
@@ -28,14 +28,20 @@
 
     void programInit(QString desc);
     void setTotalDesc(QString desc);
-    void setSubDesc(QString desc);
     void setTotalRange(int min, int max);
     void setTotalVal(int val);
     int  getTotalVal();
+    void setSubDesc(QString desc);
     void setSubRange(int min, int max);
     void setSubVal(int val);
     int  getSubVal();
 
+    void setDLVisible(bool);
+    void setDLDesc(QString desc);
+    void setDLRange(int min, int max);
+    void setDLVal(int val);
+    int  getDLVal();
+
 public slots:
 
 protected:

Modified: pcbsd/current/src-qt4/libpcbsd/dialogMetaProgress.ui
===================================================================
(Binary files differ)

Modified: pcbsd/current/src-qt4/libpcbsd/metaWidget.cpp
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/metaWidget.cpp	2012-08-08 20:16:10 UTC (rev 18358)
+++ pcbsd/current/src-qt4/libpcbsd/metaWidget.cpp	2012-08-08 21:17:31 UTC (rev 18359)
@@ -368,6 +368,11 @@
 
 		addMetaProc = new QProcess();
 		addMetaProc->setProcessChannelMode(QProcess::MergedChannels);
+		// Set the process environment flag for parsing download status
+  		QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
+  		env.insert("GUI_FETCH_PARSING", "YES");
+  		addMetaProc->setProcessEnvironment(env);
+
 		connect( addMetaProc, SIGNAL(readyReadStandardOutput()), this, SLOT(slotMetaAddRead()) );
 		connect( addMetaProc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotMetaAddDone()) );
      		addMetaProc->start("pc-metapkgmanager", QStringList() << chrootArg1 << chrootArg2 <<"add" << addPkgs << rDir);
@@ -379,7 +384,7 @@
 
 void metaWidget::slotMetaAddRead()
 {
-	bool ok;
+	bool ok, ok2;
 
 	// This functionality needs to be re-written to not loop, uses to much CPU
 	while ( addMetaProc->canReadLine() ) {
@@ -407,12 +412,61 @@
 			line = line.replace("Pending package changes: ", "");
 			line.toInt(&ok);
 			if ( ok ) {
-				metaProgressAdd->setSubRange(0, line.toInt(&ok) + 1 );
+				metaProgressAdd->setSubRange(0, (line.toInt(&ok) * 2) + 1 );
 				metaProgressAdd->setSubVal(0);
 			}
-			
-		} else {
+			continue;	
+		}
+
+		if ( line.indexOf("Downloading package: ") != -1 ) {
+			line = line.replace("Downloading package: ", "");
+			metaProgressAdd->setDLVisible(true);
+			metaProgressAdd->setDLRange(0, 10);
+			metaProgressAdd->setDLVal(0);
+			metaProgressAdd->setDLDesc("");
+
+			// Increment the sub-bar
 			metaProgressAdd->setSubVal(metaProgressAdd->getSubVal() + 1);
+			metaProgressAdd->setSubDesc(tr("Downloading: %1").arg(line) );
+			continue;	
+		}
+
+ 	    	if ( line.indexOf("SIZE: ") == 0 ) {
+       			line.replace("SIZE: ", "");
+        		line.replace("DOWNLOADED: ", "");
+        		line.replace("SPEED: ", "");
+        		line.section(" ", 0, 0).toInt(&ok);
+        		line.section(" ", 1, 1).toInt(&ok2);
+   
+			qDebug() << line;
+        		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);
+			   metaProgressAdd->setDLDesc(ProgressString);
+			   metaProgressAdd->setDLRange(0, tot);
+			   metaProgressAdd->setDLVal(cur);
+     			   QCoreApplication::processEvents();
+			}
+			continue;
+		}
+
+		if ( line.indexOf("Installing package: ") != -1 ) {
+			metaProgressAdd->setDLVisible(false);
+			metaProgressAdd->setSubVal(metaProgressAdd->getSubVal() + 1);
 			metaProgressAdd->setSubDesc(line);
 		}
 	}

Modified: pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h	2012-08-08 20:16:10 UTC (rev 18358)
+++ pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h	2012-08-08 21:17:31 UTC (rev 18359)
@@ -90,6 +90,11 @@
   void setSubRange(int min, int max);
   void setSubVal(int val);
   int  getSubVal();
+  void setDLVisible(bool);
+  void setDLDesc(QString desc);
+  void setDLRange(int min, int max);
+  void setDLVal(int val);
+  int  getDLVal();
   void show();
   void close();
   void hide();

Modified: pcbsd/current/src-qt4/libpcbsd/utils.cpp
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/utils.cpp	2012-08-08 20:16:10 UTC (rev 18358)
+++ pcbsd/current/src-qt4/libpcbsd/utils.cpp	2012-08-08 21:17:31 UTC (rev 18359)
@@ -896,6 +896,26 @@
   return d_p->getSubVal();
 }
 
+int metaProgressDialog::getDLVal() {
+  return d_p->getDLVal();
+}
+
+void metaProgressDialog::setDLVisible(bool vis) {
+  d_p->setDLVisible(vis);
+}
+
+void metaProgressDialog::setDLVal(int val) {
+  d_p->setDLVal(val);
+}
+
+void metaProgressDialog::setDLRange(int min, int max) {
+  d_p->setDLRange(min, max);
+}
+
+void metaProgressDialog::setDLDesc(QString desc) {
+  d_p->setDLDesc(desc);
+}
+
 void metaProgressDialog::show() {
   d_p->show();
 }



More information about the Commits mailing list