[PC-BSD Commits] r7934 - pcbsd/current/src-qt4/pc-systemupdatertray
svn at pcbsd.org
svn at pcbsd.org
Thu Oct 28 12:05:50 PDT 2010
Author: kris
Date: 2010-10-28 12:05:50 -0700 (Thu, 28 Oct 2010)
New Revision: 7934
Modified:
pcbsd/current/src-qt4/pc-systemupdatertray/UpdaterTray.cpp
pcbsd/current/src-qt4/pc-systemupdatertray/UpdaterTray.h
Log:
Add support for checking for PBI updates via "pbi_update --check-all"
Modified: pcbsd/current/src-qt4/pc-systemupdatertray/UpdaterTray.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-systemupdatertray/UpdaterTray.cpp 2010-10-28 16:50:21 UTC (rev 7933)
+++ pcbsd/current/src-qt4/pc-systemupdatertray/UpdaterTray.cpp 2010-10-28 19:05:50 UTC (rev 7934)
@@ -46,7 +46,6 @@
bool checkSysUpdatesFrequently = TRUE;
bool checkPBIUpdatesFrequently = TRUE;
int currentSysWorkingItem;
-int currentWorkingPBI = -1;
// Define our processes
QProcess *getUpdatesDir;
@@ -706,340 +705,46 @@
qDebug() << "Starting PBI update check...";
- int i = -1;
- QString tmp, ProgDirName;
+ slotPBICheckUpdate();
-
- // Load all the PBIs from our list and only keep the ones with update URLs.
- QFile file( "/Programs/.config/ProgList" );
- if ( file.open( QIODevice::ReadOnly ) ) {
- QTextStream stream( &file );
- QString line;
-
- while ( !stream.atEnd() ) {
- line = stream.readLine(); // line of text excluding '\n'
- if (line.indexOf("#" ) != 0)
- {
- if (line.indexOf("ProgName:" ) == 0 )
- {
- i++;
- PBIProgName[i] = line.replace("ProgName: ", "");
- }
- if ( line.indexOf("ProgVer:") == 0)
- {
- PBIProgVer[i] = line.replace("ProgVer: ", "");
- }
- if ( line.indexOf("DefaultIcon:") == 0)
- {
- PBIProgIcon[i] = line.replace("DefaultIcon: ", "");
-
- tmp = PBIProgName[i];
- tmp.replace(" ", "");
- ProgDirName = tmp;
-
- QFile file2( "/Programs/" + ProgDirName + "/PBI.UpdateURL.sh" );
- if ( ! file2.exists() ) {
- PBIProgName[i]="";
- PBIProgVer[i]="";
- PBIProgIcon[i]="";
- PBIProgUpdate[i] = 0;
- i--;
- } else {
- // Set our status to 0, that we don't need to update this PBI so far
- PBIProgUpdate[i] = 0;
-
- }
-
- }
-
- }
-
- }
- file.close();
-
- }
-
-
-
- // Now start checking if these PBIs are up to date!
- if ( ! PBIProgName[0].isEmpty() )
- {
- currentWorkingPBI = -1;
- pbistatus = PBI_CHECKING4UPDATES;
- QTimer::singleShot( 500, this, SLOT(slotPBICheckUpdate()) );
- contextMenuRefresh();
- } else {
- // Indicate that no new PBIs are available
- pbistatus = PBI_UPDATED;
- }
-
-
-
-
}
-
-
-
// 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="";
updatePBITextList = "";
-
- QString tmp, line;
- QString progName, Arch, Version, PBIUrl;
+ qDebug() << "Checking For PBI Updates...";
+ checkPBIProc = new QProcess();
+ checkPBIProc->setProcessChannelMode(QProcess::MergedChannels);
+ connect(checkPBIProc, SIGNAL(readyReadStandardOutput()), this, SLOT(slotReadPBIBuffer()));
+ connect(checkPBIProc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotPopulatePBIList()) );
+ checkPBIProc->start(QString("pbi_update"), QStringList() << "--check-all" );
- // Jump to the next PBI in our list
- currentWorkingPBI++;
-
- // Check if we are done with checking for updates
- if ( PBIProgName[currentWorkingPBI].isEmpty() )
- {
- // Go ahead and finish up the PBI update check now
- slotPopulatePBIList();
- return;
- }
-
-
- qDebug() << "Checking PBI: " << PBIProgName[currentWorkingPBI];
-
- tmp = PBIProgName[currentWorkingPBI];
- tmp.replace(" ", "");
- progName = tmp;
-
-
-
- // First, get some variables to figure out the full patch URL
- QFile file( "/Programs/" + progName + "/PBI.UpdateURL.sh" );
- if ( file.open( QIODevice::ReadOnly ) ) {
- QTextStream stream( &file );
- while ( !stream.atEnd() ) {
- line = stream.readLine(); // line of text excluding '\n'
- if ( line.indexOf("PBIUpdateURL=\"" ) == 0)
- {
- line.replace("PBIUpdateURL=\"", "");
- line.truncate(line.indexOf("\""));
- PBIUrl = line;
- //QMessageBox::critical( 0, tr("Online Update"), PBIUrl, QMessageBox::Ok );
- }
-
- }
- file.close();
- }
-
- if ( PBIUrl.isEmpty() )
- {
- // No PBI update file for this program, jump to next program
- QTimer::singleShot(1000, this, SLOT(slotPBICheckUpdate() ) );
- return;
- }
-
-
- QString command = "pbreg get /PC-BSD/Version";
- Version = getLineFromCommandOutput(command);
-
- command = "uname -p";
- Arch = getLineFromCommandOutput(command);
- if ( Arch.indexOf("i386") != -1 )
- {
- Arch = "i386";
- }
- if ( Arch.indexOf("amd64") != -1 )
- {
- Arch = "amd64";
- }
-
- QString postData = "PBIName=" + progName + "&PBIVer=" + PBIProgVer[currentWorkingPBI] + "&PCBSDVER=" + Version + "&OSARCH=" + Arch;
-
- checkPBIJob = new QNetworkAccessManager(this);
-
- QNetworkRequest netRequest;
- netRequest.setUrl(QUrl(PBIUrl));
- netRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded" );
-
- pbiReply = checkPBIJob->post(netRequest, postData.toAscii());
-
- connect(checkPBIJob, SIGNAL(finished(QNetworkReply *)), this, SLOT(slotPBICheckUpdate() ) );
- connect(pbiReply, SIGNAL(readyRead()), this, SLOT(slotRecieveData() ) );
-
}
-void UpdaterTray::slotRecieveData()
-{
- QString output(pbiReply->readAll());
- PBIBuffer = PBIBuffer + output;
-}
-
void UpdaterTray::slotReadPBIBuffer()
{
- QString output = PBIBuffer;
- QString line;
-
- //qDebug() << "PBI Return:" << output;
- QStringList outputList;
- if ( output.indexOf("Up2Date") == -1 && ! output.isEmpty())
- {
- outputList = output.split("\n");
- for ( int i = 0; i < outputList.size(); i++)
- {
- line = outputList.at(i);
-
- if (line.indexOf("NewVer:" ) == 0 )
- {
- PBIProgNewVer[currentWorkingPBI] = line.replace("NewVer: ", "");
- }
- if ( line.indexOf("Mirror1:") == 0)
- {
- PBIProgURL1[currentWorkingPBI] = line.replace("Mirror1: ", "");
- }
- // Check for our other file locations
- if ( line.indexOf("Mirror2:") == 0)
- {
- PBIProgURL2[currentWorkingPBI] = line.replace("Mirror2: ", "");
- }
- if ( line.indexOf("Mirror3:") == 0)
- {
- PBIProgURL3[currentWorkingPBI] = line.replace("Mirror3: ", "");
- }
- if ( line.indexOf("FileLoc:") == 0)
- {
- PBIProgLoc[currentWorkingPBI] = line.replace("FileLoc: ", "");
- }
- if ( line.indexOf("MD5:") == 0)
- {
- PBIProgMD5[currentWorkingPBI] = line.replace("MD5: ", "");
- }
- if ( line.indexOf("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
- if ( ! PBIProgNewVer[currentWorkingPBI].isEmpty() && ! PBIProgURL1[currentWorkingPBI].isEmpty() && ! PBIProgURL2[currentWorkingPBI].isEmpty() && ! PBIProgURL3[currentWorkingPBI].isEmpty() && ! PBIProgLoc[currentWorkingPBI].isEmpty() && ! PBIProgMD5[currentWorkingPBI].isEmpty() )
- {
- // We have valid data! Set the flag that this PBI is in need of an update
- PBIProgUpdate[currentWorkingPBI] = 1;
- }
- } // End of IF statement to find if this string has update data
+ while( checkPBIProc->canReadLine() )
+ PBIBuffer += checkPBIProc->readLine();
}
-
-
-// The update checking is finished, now see if we have any PBIs which need an update
+// The update checking is finished
void UpdaterTray::slotPopulatePBIList()
{
- int i = 0, foundUpdates = 0;
- QString text, tmp, newMsg, ProgDirName, iconPath;
- bool updateAvail;
+ if ( PBIBuffer.indexOf("- Available:") != -1 ) {
+ updatePBITextList = PBIBuffer;
+ pbistatus = PBI_UPDATES_AVAIL;
+ } else {
+ // No PBI updates found right now!
+ pbistatus = PBI_UPDATED;
+ }
- while (! PBIProgName[i].isEmpty() )
- {
- // Add the PBI info to the GUI
- if ( PBIProgUpdate[i] == 1 )
- {
- text=PBIProgName[i] + " " + PBIProgNewVer[i];
-
- tmp = PBIProgName[i];
- tmp.replace(" ", "");
- ProgDirName = tmp;
- iconPath = "/Programs/" + ProgDirName + "/" + PBIProgIcon[i];
- 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 ) {
- // Set the status that we have new PBIs
- pbistatus = PBI_UPDATES_AVAIL;
- } else {
- // No PBI updates found right now!
- pbistatus = PBI_UPDATED;
- }
-
- contextMenuRefresh();
-
+ contextMenuRefresh();
}
Modified: pcbsd/current/src-qt4/pc-systemupdatertray/UpdaterTray.h
===================================================================
--- pcbsd/current/src-qt4/pc-systemupdatertray/UpdaterTray.h 2010-10-28 16:50:21 UTC (rev 7933)
+++ pcbsd/current/src-qt4/pc-systemupdatertray/UpdaterTray.h 2010-10-28 19:05:50 UTC (rev 7934)
@@ -1,15 +1,15 @@
-
-#include <qpair.h>
-#include <qstring.h>
-#include <QSystemTrayIcon>
-#include <QMenu>
+#include <QAction>
+#include <QDialog>
#include <QFileSystemWatcher>
#include <QFtp>
#include <QFile>
+#include <QMenu>
#include <QNetworkAccessManager>
-#include <QAction>
#include <QNetworkReply>
-#include <QDialog>
+#include <QPair>
+#include <QProcess>
+#include <QString>
+#include <QSystemTrayIcon>
#define SYSTRIGGER "/tmp/.sysupdatetraytrigger"
#define PBITRIGGER "/tmp/.pbiupdatetraytrigger"
@@ -45,7 +45,6 @@
void slotPopulatePBIList();
void slotChangeRunStartup();
void slotTrayActivated(QSystemTrayIcon::ActivationReason reason);
- void slotRecieveData();
void slotRecieveSysData();
void slotAutoUpdateStatusChanged();
void slotSetTimerReadAutoStatus();
@@ -59,10 +58,9 @@
void displayTooltip();
QString getLineFromCommandOutput( QString command );
void loadUpdaterPrefs();
- QNetworkAccessManager *checkPBIJob;
- QNetworkReply *pbiReply;
QNetworkAccessManager *checkSysJob;
QNetworkReply *sysReply;
+ QProcess *checkPBIProc;
QFileSystemWatcher *fileWatcher;
QFileSystemWatcher *fileWatcherSys;
QFileSystemWatcher *fileWatcherAutoUpdate;
More information about the Commits
mailing list