[PC-BSD Commits] r7207 - pcbsd/current/SystemUpdaterTray

svn at pcbsd.org svn at pcbsd.org
Wed Jul 14 10:25:57 PDT 2010


Author: kris
Date: 2010-07-14 10:25:57 -0700 (Wed, 14 Jul 2010)
New Revision: 7207

Modified:
   pcbsd/current/SystemUpdaterTray/SystemUpdaterTray.pro
   pcbsd/current/SystemUpdaterTray/UpdaterTray.cpp
   pcbsd/current/SystemUpdaterTray/UpdaterTray.h
   pcbsd/current/SystemUpdaterTray/main.cpp
Log:

Refactor SystemUpdaterTray to be 100% QT4 only, no KDE4 libs usage anymore



Modified: pcbsd/current/SystemUpdaterTray/SystemUpdaterTray.pro
===================================================================
--- pcbsd/current/SystemUpdaterTray/SystemUpdaterTray.pro	2010-07-14 14:48:33 UTC (rev 7206)
+++ pcbsd/current/SystemUpdaterTray/SystemUpdaterTray.pro	2010-07-14 17:25:57 UTC (rev 7207)
@@ -3,8 +3,6 @@
 
 CONFIG	+= qt warn_on release
 
-LIBS	+= -lkdecore -lkdeui -lkio -Ikdelibs
-
 HEADERS	+= UpdaterTray.h
 
 SOURCES	+= main.cpp UpdaterTray.cpp
@@ -13,10 +11,8 @@
 
 RESOURCES += SystemUpdaterTray.qrc
 
-INCLUDEPATH += /usr/local/kde4/include /usr/local/kde4/include
+INCLUDEPATH += /usr/local/include
 
-LIBS += -L/usr/local/kde4/lib -L/usr/local/kde4/lib
-
 TRANSLATIONS =  i18n/SystemUpdaterTray_af.ts \
 		i18n/SystemUpdaterTray_ar.ts \
 		i18n/SystemUpdaterTray_az.ts \
@@ -79,15 +75,17 @@
 		i18n/SystemUpdaterTray_zh_TW.ts \
 		i18n/SystemUpdaterTray_zu.ts
 
-dotrans.path=/usr/local/kde4/share/apps/pcbsd/i18n/
-dotrans.extra=cd i18n && lrelease-qt4 *.ts && cp *.qm /usr/local/kde4/share/apps/pcbsd/i18n/
+dotrans.path=/usr/local/share/apps/pcbsd/i18n/
+dotrans.extra=cd i18n && lrelease-qt4 *.ts && cp *.qm /usr/local/share/apps/pcbsd/i18n/
 
-desktop.path=/usr/local/kde4/share/applications/kde4/
+desktop.path=/usr/local/share/applications/
 desktop.files=pcbsdpbu.desktop
 
 INSTALLS += dotrans desktop
 
-QMAKE_LIBDIR = /usr/local/kde4/lib /usr/local/lib/qt4 /usr/local/lib /usr/local/kde4/lib /usr/local/lib/qt4 /usr/local/lib
+QMAKE_LIBDIR = /usr/local/lib/qt4 /usr/local/lib
 
-TARGET  = SystemUpdaterTray
-DESTDIR = /usr/PCBSD/SystemUpdater/bin/
+TARGET  = pc-systemupdatertray
+DESTDIR = /usr/local/bin/
+
+QT +=  network

Modified: pcbsd/current/SystemUpdaterTray/UpdaterTray.cpp
===================================================================
--- pcbsd/current/SystemUpdaterTray/UpdaterTray.cpp	2010-07-14 14:48:33 UTC (rev 7206)
+++ pcbsd/current/SystemUpdaterTray/UpdaterTray.cpp	2010-07-14 17:25:57 UTC (rev 7207)
@@ -11,19 +11,11 @@
 #include <QFile>
 #include <QProcess>
 #include <QDebug>
+#include <QMessageBox>
+#include <QNetworkRequest>
 #include <qmenu.h>
+#include <QDebug>
 
-/* KDE */
-#include <kiconloader.h>
-#include <kpassivepopup.h>
-#include <kmessagebox.h>
-#include <kpassivepopup.h>
-#include <iostream>
-#include <unistd.h>
-#include <kjob.h>
-#include <kio/job.h>
-#include <kio/copyjob.h>
-
 #include "UpdaterTray.h"
 
 /* Update interval in ms  - Every 6 hours */
@@ -104,7 +96,6 @@
   connect( sysTimer, SIGNAL(timeout()), this, SLOT(slotScheduledSystemCheck()) );
   connect( pbiTimer, SIGNAL(timeout()), this, SLOT(slotScheduledPBICheck()) );
 
-  connect( this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(slotTrayActivated(QSystemTrayIcon::ActivationReason) ) );
 
   // Get the username of the person running X
   username = getlogin();
@@ -112,20 +103,31 @@
   // Setup our Context Menu
   QIcon contextIcon;
   contextIcon.addFile("/PCBSD/SystemUpdater/images/updated.png");
-  contextMenu()->setIcon(contextIcon);
-  contextMenu()->addSeparator();
-  contextMenu()->addAction( tr("Start the Update Manager"), this, SLOT(slotOpenUpdateManager()));
-  contextMenu()->addAction( tr("Check for updates"), this, SLOT(slotCheckAllUpdates()));
-  contextMenu()->addSeparator();
-  runAction = contextMenu()->addAction( tr("Run at startup"), this, SLOT(slotChangeRunStartup()) );
+
+
+  trayIconMenu = new QMenu(this);
+  trayIconMenu->setIcon(contextIcon);
+  trayIconMenu->addSeparator();
+  trayIconMenu->addAction( tr("Start the Update Manager"), this, SLOT(slotOpenUpdateManager()));
+  trayIconMenu->addAction( tr("Check for updates"), this, SLOT(slotCheckAllUpdates()));
+  trayIconMenu->addSeparator();
+  runAction = trayIconMenu->addAction( tr("Run at startup"), this, SLOT(slotChangeRunStartup()) );
   runAction->setCheckable( TRUE );
   runAction->setChecked( TRUE );
+  trayIconMenu->addSeparator();
+  trayIconMenu->addAction( tr("Quit"), this, SLOT(slotQuitTray()) );
   
+  trayIcon = new QSystemTrayIcon(this);
+  trayIcon->setContextMenu(trayIconMenu);
+  trayIcon->show();
+
   // Set the tray icon that we are checking for updates
   QIcon Icon;
   Icon.addFile("/PCBSD/SystemUpdater/images/working.png");
-  setIcon(Icon);
+  trayIcon->setIcon(Icon);
 
+  connect( trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(slotTrayActivated(QSystemTrayIcon::ActivationReason) ) );
+
   // Load the program preferences
   loadUpdaterPrefs();
 
@@ -145,10 +147,12 @@
      streamTrig << QDateTime::currentDateTime().toString("hhmmss");
      sysTrig.close();
   }
-  fileWatcherAutoUpdate = KDirWatch::self();
-  fileWatcherAutoUpdate->addFile(SYSTRIGGER);
-  connect(fileWatcherAutoUpdate, SIGNAL(dirty(const QString&)), this, SLOT(slotSetTimerReadAutoStatus() ));
 
+  // Start our file watchers
+  fileWatcherAutoUpdate = new QFileSystemWatcher();
+  fileWatcherAutoUpdate->addPath(SYSTRIGGER);
+  connect(fileWatcherAutoUpdate, SIGNAL(fileChanged(const QString&)), this, SLOT(slotSetTimerReadAutoStatus() ));
+
   // Watch for PBI updates and refresh
   QFile pbiTrig( PBITRIGGER );
   if ( pbiTrig.open( QIODevice::WriteOnly ) ) {
@@ -156,14 +160,14 @@
      streamTrig1 << QDateTime::currentDateTime().toString("hhmmss");
      pbiTrig.close();
   }
-  pbiWatcherAutoUpdate = KDirWatch::self();
-  pbiWatcherAutoUpdate->addFile(PBITRIGGER);
-  connect(pbiWatcherAutoUpdate, SIGNAL(dirty(const QString&)), this, SLOT(slotScheduledPBICheck() ));
+  pbiWatcherAutoUpdate = new QFileSystemWatcher();
+  pbiWatcherAutoUpdate->addPath(PBITRIGGER);
+  connect(pbiWatcherAutoUpdate, SIGNAL(fileChanged(const QString&)), this, SLOT(slotScheduledPBICheck() ));
 
   // Watch our trigger file, to see if any automated updates are being downloaded
-  fileWatcherSys = KDirWatch::self();
-  fileWatcherSys->addFile("/PCBSD/SystemUpdater/conf/sysupdate.conf");
-  connect(fileWatcherSys, SIGNAL(dirty(const QString&)), this, SLOT(slotScheduledSystemCheck() ));
+  fileWatcherSys = new QFileSystemWatcher();
+  fileWatcherSys->addPath("/PCBSD/SystemUpdater/conf/sysupdate.conf");
+  connect(fileWatcherSys, SIGNAL(fileChanged(const QString&)), this, SLOT(slotScheduledSystemCheck() ));
 }
 
 // Slot that watches for any config changes
@@ -246,7 +250,6 @@
           if ( line.indexOf("REQUIRESREBOOT: " ) == 0)
           {
               line.replace("REQUIRESREBOOT: ", "");
-              KPassivePopup::message(tr("Requires Reboot") , tr("An installed patch requires a reboot to complete. Please restart your system as soon as possible."),  QPixmap(), this);
           }
       } 
 
@@ -309,7 +312,7 @@
   // Set the tray icon that we are checking for updates
   QIcon Icon;
   Icon.addFile("/PCBSD/SystemUpdater/images/working.png");
-  setIcon(Icon);
+  trayIcon->setIcon(Icon);
 
   // Set the status to checking for system updates
   programstatus = SYSTEM_CHECKING4UPDATES;
@@ -317,8 +320,6 @@
   // Create the tooltip popup now
   displayTooltip();
 
-  // Run our KIO Job to fetch the system-update patch data for this version of PC-BSD
-
   // First, get some variables to figure out the full patch URL
   QFile file( "/PCBSD/SystemUpdater/conf/sysupdate.conf" );
   if ( file.open( QIODevice::ReadOnly ) ) {
@@ -366,26 +367,43 @@
   sysPatchsetTmpFile = "/home/" + username + "/.pcbsdupcheck/" + patchfile;
   QString patchurl = SysUrl + "/" + patchfile;
 
-  // Start our KIO copy now
-  sysFetchJob = KIO::file_copy( patchurl, sysPatchsetTmpFile, -1, KIO::HideProgressInfo | KIO::Overwrite);
-  connect(sysFetchJob, SIGNAL(result(KJob *)), this, SLOT(slotSysUpdateCheckFinished() ) );
+  // Remove the old file
+  if ( QFile::exists(sysPatchsetTmpFile) )
+	QFile::remove(sysPatchsetTmpFile);
+
+  // Start our QNetworkManager Download now
+  checkSysJob = new QNetworkAccessManager(this);
   
+  QNetworkRequest netRequest;
+  netRequest.setUrl(QUrl(patchurl));
+   
+  sysReply = checkSysJob->get(netRequest);
+  
+  connect(checkSysJob, SIGNAL(finished(QNetworkReply *)), this, SLOT(slotSysUpdateCheckFinished() ) );
+  connect(sysReply, SIGNAL(readyRead()), this, SLOT(slotRecieveSysData() ) );
+  qDebug() << "Starting System Update Check";
 }
 
 
+void UpdaterTray::slotRecieveSysData()
+{
+  //qDebug() << "Saving Downloaded Data" << sysPatchsetTmpFile;
+  QFile sysSaveFile(sysPatchsetTmpFile);
+  if (!sysSaveFile.open(QIODevice::WriteOnly | QIODevice::Append)) {
+         return;
+  }
+  sysSaveFile.write(sysReply->readAll());
+  sysSaveFile.close();
+}
 
 
-
-
-
 void UpdaterTray::slotSysUpdateCheckFinished() {
 
   QString command = "pbreg get /PC-BSD/Version";
   QString Version = getLineFromCommandOutput(command);
 
-
   // Check to see if the update download was successful and warn if not
-  if ( sysFetchJob->error() != 0 && sysFetchJob->error() != 101 )
+  if ( ! QFile::exists(sysPatchsetTmpFile) )
   {
      // We couldn't fetch any updates, set the status and update the icon
      programstatus = CHECK_FAILED;
@@ -397,6 +415,9 @@
     QStringList args;
     args << "/PCBSD/SystemUpdater/bin/readSysUpdatesUser.sh" << Version << sysPatchsetTmpFile << username;
 
+    //qDebug() << "System Fetch Finished:" << sysPatchsetTmpFile;
+    qDebug() << "Finished System Update Check";
+
     // Connect the exited signal and start the process
     readSysUpdates = new QProcess( this );
     connect( readSysUpdates, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotReadSystemUpdates() ) );
@@ -405,12 +426,6 @@
 
 }
 
-
-
-
-
-
-
 // Read in the available system updates
 void UpdaterTray::slotReadSystemUpdates() {
   
@@ -506,12 +521,12 @@
      Icon.addFile("/PCBSD/SystemUpdater/images/connecterror.png");
   }
 
-  setIcon(Icon);
+  trayIcon->setIcon(Icon);
 
   // Update the tooltip to what we are doing now
   displayTooltip();
  
-  show();
+  //show();
 
 }
 
@@ -606,7 +621,7 @@
       tooltipStr += updatePBITextList;
    }
    
-   setToolTip(tooltipStr);
+   trayIcon->setToolTip(tooltipStr);
 
 }
 
@@ -688,7 +703,7 @@
      return;
   }
 
-  //qDebug() << "Starting PBI update check...";
+  qDebug() << "Starting PBI update check...";
 
   int i = -1;
   QString tmp, ProgDirName;
@@ -797,7 +812,7 @@
     }
 
 
-  // qDebug() << "Checking PBI: " << PBIProgName[currentWorkingPBI];
+  qDebug() << "Checking PBI: " << PBIProgName[currentWorkingPBI];
 
   tmp = PBIProgName[currentWorkingPBI];
   tmp.replace(" ", "");
@@ -847,18 +862,22 @@
 
   QString postData = "PBIName=" + progName + "&PBIVer=" + PBIProgVer[currentWorkingPBI] + "&PCBSDVER=" + Version + "&OSARCH=" + Arch;
   
-  checkPBIJob = KIO::http_post( PBIUrl, postData.toUtf8(), KIO::HideProgressInfo);
-  connect(checkPBIJob, SIGNAL(result(KJob *)), this, SLOT(slotPBICheckUpdate() ) );
-  connect(checkPBIJob, SIGNAL(data(KIO::Job *, const QByteArray&)), this, SLOT(slotRecieveData(KIO::Job *, const QByteArray& ) ) );
-  checkPBIJob->addMetaData("content-type", "Content-type: application/x-www-form-urlencoded" );
+  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(KIO::Job*, const QByteArray& data)
+void UpdaterTray::slotRecieveData()
 {
-    QString output(data);
+    QString output(pbiReply->readAll());
     PBIBuffer = PBIBuffer + output;
 }
 
@@ -867,6 +886,7 @@
     QString output = PBIBuffer;
     QString line;
 
+    //qDebug() << "PBI Return:" << output;
     QStringList outputList;
     if ( output.indexOf("Up2Date") == -1  && ! output.isEmpty())
     {

Modified: pcbsd/current/SystemUpdaterTray/UpdaterTray.h
===================================================================
--- pcbsd/current/SystemUpdaterTray/UpdaterTray.h	2010-07-14 14:48:33 UTC (rev 7206)
+++ pcbsd/current/SystemUpdaterTray/UpdaterTray.h	2010-07-14 17:25:57 UTC (rev 7207)
@@ -1,9 +1,15 @@
 
 #include <qpair.h>
 #include <qstring.h>
-#include <ksystemtrayicon.h>
-#include <kio/jobclasses.h>
-#include <kdirwatch.h>
+#include <QSystemTrayIcon>
+#include <QMenu>
+#include <QFileSystemWatcher>
+#include <QFtp>
+#include <QFile>
+#include <QNetworkAccessManager>
+#include <QAction>
+#include <QNetworkReply>
+#include <QDialog>
 
 #define SYSTRIGGER "/tmp/.sysupdatetraytrigger"
 #define PBITRIGGER "/tmp/.pbiupdatetraytrigger"
@@ -11,11 +17,11 @@
 class QString;
 class QPixmap;
 
-class UpdaterTray : public KSystemTrayIcon {
+class UpdaterTray : public QDialog {
    Q_OBJECT
    
 public:
-   UpdaterTray() : KSystemTrayIcon()
+   UpdaterTray() : QDialog()
    {
    }
    void programInit();
@@ -39,7 +45,8 @@
    void slotPopulatePBIList();
    void slotChangeRunStartup();
    void slotTrayActivated(QSystemTrayIcon::ActivationReason reason);
-   void slotRecieveData(KIO::Job*, const QByteArray& data);
+   void slotRecieveData();
+   void slotRecieveSysData();
    void slotAutoUpdateStatusChanged();
    void slotSetTimerReadAutoStatus();
    void slotCheckAllUpdates();
@@ -52,13 +59,14 @@
    void displayTooltip();
    QString getLineFromCommandOutput( QString command );
    void loadUpdaterPrefs();
-   KJob *copyJob;
-   KJob *sysFetchJob;
-   KIO::TransferJob *checkPBIJob;
-   KDirWatch *fileWatcher;
-   KDirWatch *fileWatcherSys;
-   KDirWatch *fileWatcherAutoUpdate;
-   KDirWatch *pbiWatcherAutoUpdate;
+   QNetworkAccessManager *checkPBIJob;
+   QNetworkReply *pbiReply;
+   QNetworkAccessManager *checkSysJob;
+   QNetworkReply *sysReply;
+   QFileSystemWatcher *fileWatcher;
+   QFileSystemWatcher *fileWatcherSys;
+   QFileSystemWatcher *fileWatcherAutoUpdate;
+   QFileSystemWatcher *pbiWatcherAutoUpdate;
    QString sysPatchsetTmpFile;
    bool useCustomTmpDir;
    QString customTmpDir;
@@ -68,4 +76,6 @@
    QString autoCurrentUpdate;
    QStringList autoUpdatesFailed;
    QStringList autoUpdatesInstalled;
+   QSystemTrayIcon *trayIcon;
+   QMenu *trayIconMenu;
 };

Modified: pcbsd/current/SystemUpdaterTray/main.cpp
===================================================================
--- pcbsd/current/SystemUpdaterTray/main.cpp	2010-07-14 14:48:33 UTC (rev 7206)
+++ pcbsd/current/SystemUpdaterTray/main.cpp	2010-07-14 17:25:57 UTC (rev 7207)
@@ -4,49 +4,40 @@
 #include <qlocale.h>
 #include <QDebug>
 #include <QFile>
-#include <kuniqueapplication.h>
-#include <kaboutdata.h>
-#include <kcmdlineargs.h>
+#include <QSystemTrayIcon>
+#include <QApplication>
+#include <QMessageBox>
+#include <QtGui>
 
 
 #include "UpdaterTray.h"
 
-static const char description[] = I18N_NOOP("PC-BSD System Updater Tray");
-
 int  main(int argc, char ** argv)
 {
+   QApplication a(argc, argv);
 
-    KAboutData aboutData("SystemUpdaterTray", 0, ki18n("SystemUpdaterTray"),
-                            "1.0", ki18n(description),
-                            KAboutData::License_BSD,
-                            ki18n("(c) 2008, Kris Moore(c)"));
-
-    aboutData.addAuthor(ki18n("Kris Moore"), ki18n("Current maintainer"), "kris at pcbsd.org");
-
-   KCmdLineArgs::init(argc, argv, &aboutData);
-
-   KCmdLineOptions options;
-
-    // Tell which options are supported
-   KCmdLineArgs::addCmdLineOptions( options );
-
-   KUniqueApplication a;
-
    QTranslator translator;
    QLocale mylocale;
    QString langCode = mylocale.name();
-   if ( ! QFile::exists("/usr/local/kde4/share/apps/pcbsd/i18n/SystemUpdaterTray_" + langCode + ".qm" ) )
+   if ( ! QFile::exists("/usr/local/share/apps/pcbsd/i18n/SystemUpdaterTray_" + langCode + ".qm" ) )
      langCode.truncate(langCode.indexOf("_"));
-   translator.load( QString("SystemUpdaterTray_") + langCode, "/usr/local/kde4/share/apps/pcbsd/i18n/" );
+   translator.load( QString("SystemUpdaterTray_") + langCode, "/usr/local/share/apps/pcbsd/i18n/" );
    a.installTranslator( &translator );
    qDebug() << "Locale:" << langCode;
 
+   if (!QSystemTrayIcon::isSystemTrayAvailable()) {
+         QMessageBox::critical(0, QObject::tr("Systray"),
+                               QObject::tr("I couldn't detect any system tray "
+                                           "on this system."));
+         return 1;
+   }
+
+   qDebug() << "Starting Tray Application";
+
    UpdaterTray tray;
-   //a.setMainWidget(tray.contextMenu());
-   a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
+   QApplication::setQuitOnLastWindowClosed(false);
 
    // Init our program
    tray.programInit();
-   tray.show();
    return  a.exec();
 }



More information about the Commits mailing list