source: src-qt4/pc-systemupdatertray/UpdaterTray.cpp @ a071509

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3
Last change on this file since a071509 was a071509, checked in by Kris Moore <kris@…>, 17 months ago

Fix the updater tray to show the new Package Manager when right-clicked, and
when new package updates are available, show the correct bubble popup

  • Property mode set to 100644
File size: 23.1 KB
Line 
1/* Qt */
2#include <QApplication>
3#include <QDateTime>
4#include <QDebug>
5#include <QFile>
6#include <QImage>
7#include <QMenu>
8#include <QMessageBox>
9#include <QProcess>
10#include <QSettings>
11#include <QTimer>
12#include <QToolTip>
13#include <QTranslator>
14#include <QTextStream>
15
16#include "UpdaterTray.h"
17#include "../config.h"
18
19/* Update interval in ms  - Every 24 hours */
20#define  UPDATE_MSEC 1000 * 60 * 60 * 24
21
22/* Change this to switch the default patch tmpdir */
23const QString PATCHTMPDIR_DEFAULT( PREFIX + "/tmp" );
24
25/* The Update STATUS Flags */
26#define SYSTEM_UP2DATE 0
27#define SYSTEM_UPDATE_AVAIL 1
28#define PACKAGE_UPDATE_AVAIL 2
29#define SYSTEM_CHECKING4UPDATES 4
30#define SYSTEM_UPDATING 5
31#define CHECK_FAILED 6
32#define SYSTEM_RESTART_NEEDED 7
33
34#define WARDEN_UP2DATE 0
35#define WARDEN_UPDATE_AVAIL 1
36
37#define PBI_UPDATED 0
38#define PBI_UPDATES_AVAIL 1
39#define PBI_CHECKING4UPDATES 2
40#define PBI_UPDATING 3
41
42// Public Variables
43QString username;
44int programstatus = SYSTEM_UP2DATE;
45int wardenstatus = WARDEN_UP2DATE;
46int pbistatus = PBI_UPDATED;
47bool checkSysUpdatesFrequently = TRUE;
48bool checkPBIUpdatesFrequently = TRUE;
49int currentSysWorkingItem;
50
51// Define our processes
52QProcess *getUpdatesDir;
53QProcess *readSysUpdates;
54QProcess *listingProc;
55QProcess *checkPBIProc;
56QProcess *launchAdminProc;
57 
58QTimer *sysTimer;
59QTimer *pbiTimer;
60
61QString PBIProgName[900];
62QString PBIProgVer[900];
63QString PBIProgNewVer[900];
64QString PBIProgIcon[900];
65QString PBIProgURL1[900];
66QString PBIProgURL2[900];
67QString PBIProgURL3[900];
68QString PBIProgMD5[900];
69QString PBIProgMdate[900];
70QString PBIProgLoc[900];
71int     PBIProgUpdate[900];
72int     PBIProgFailed[900];
73QString PBIBuffer;
74QString updatePBITextList;
75
76// Updater frequency supplied by user
77qlonglong       updateFrequency;
78
79#define AUTOINACTIVE 0
80#define AUTODOWNLOAD 1
81#define AUTOFINISHED 2
82#define AUTOFINISHEDDL 3
83#define AUTOINSTALLING 4
84#define AUTOFAILED 5
85
86void UpdaterTray::programInit()
87{
88  QString tmp, command;
89  autoStatus = AUTOINACTIVE;
90  doingCheck=false;
91  shownPopup=false;
92
93  // Use built-in frequency until we load another
94  updateFrequency = -1;
95
96  sysTimer = new QTimer(this);
97  pbiTimer = new QTimer(this);
98
99  connect( sysTimer, SIGNAL(timeout()), this, SLOT(slotScheduledSystemCheck()) );
100  connect( pbiTimer, SIGNAL(timeout()), this, SLOT(slotScheduledPBICheck()) );
101
102  // Get the username of the person running X
103  username = getlogin();
104
105  // Setup our Context Menu
106  QIcon contextIcon;
107  contextIcon.addFile(PREFIX + "/share/pcbsd/pc-sysmanager/images/updated.png");
108
109
110  trayIconMenu = new QMenu(this);
111  trayIconMenu->setIcon(contextIcon);
112  trayIconMenu->addSeparator();
113  trayIconMenu->addAction( tr("Start the Update Manager"), this, SLOT(slotOpenUpdateManager()));
114  trayIconMenu->addAction( tr("Start the Package Manager"), this, SLOT(slotOpenPackageManager()));
115  trayIconMenu->addSeparator();
116  trayIconMenu->addAction( tr("Start the AppCafe"), this, SLOT(slotOpenSoftwareManager()));
117  trayIconMenu->addAction( tr("Start the Warden"), this, SLOT(slotOpenJailManager()));
118  trayIconMenu->addSeparator();
119  trayIconMenu->addAction( tr("Check for updates"), this, SLOT(slotCheckAllUpdates()));
120  trayIconMenu->addSeparator();
121  runAction = trayIconMenu->addAction( tr("Run at startup"), this, SLOT(slotChangeRunStartup()) );
122  runAction->setCheckable( TRUE );
123  runAction->setChecked( TRUE );
124  popAction = trayIconMenu->addAction( tr("Display notifications"), this, SLOT(slotChangePopup()) );
125  popAction->setCheckable( TRUE );
126  popAction->setChecked( TRUE );
127  trayIconMenu->addSeparator();
128  trayIconMenu->addAction( tr("Quit"), this, SLOT(slotQuitTray()) );
129 
130  // Init the tray icon
131  trayIcon = new QSystemTrayIcon(this);
132  trayIcon->setContextMenu(trayIconMenu);
133  QIcon Icon;
134  Icon.addFile(PREFIX + "/share/pcbsd/pc-sysmanager/images/working.png");
135  trayIcon->setIcon(Icon);
136  trayIcon->show();
137  connect( trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(slotTrayActivated(QSystemTrayIcon::ActivationReason) ) );
138
139  // Load the program preferences
140  loadUpdaterPrefs();
141
142  // Start the monitor service for system updates
143  QTimer::singleShot(1000, this, SLOT(slotScheduledSystemCheck()));
144
145  // Start the monitor service for PBI updates
146  QTimer::singleShot(60000, this, SLOT(slotScheduledPBICheck()));
147
148  // Monitor if we need to start any update checks
149  QTimer::singleShot(500, this, SLOT(slotMonitorForChanges()));
150
151  // Watch our trigger file, to see if any automated updates are being downloaded
152  QFile sysTrig( SYSTRIGGER );
153  if ( sysTrig.open( QIODevice::WriteOnly ) ) {
154    QTextStream streamTrig( &sysTrig );
155     streamTrig << QDateTime::currentDateTime().toString("hhmmss");
156  }
157  sysTrig.close();
158
159  // Start our file watchers
160  fileWatcherAutoUpdate = new QFileSystemWatcher();
161  fileWatcherAutoUpdate->addPath(SYSTRIGGER);
162  connect(fileWatcherAutoUpdate, SIGNAL(fileChanged(const QString&)), this, SLOT(slotSetTimerReadAutoStatus() ));
163
164  // Watch for PBI updates and refresh
165  QFile pbiTrig( PBITRIGGER );
166  if ( pbiTrig.open( QIODevice::WriteOnly ) ) {
167    QTextStream streamTrig1( &pbiTrig );
168     streamTrig1 << QDateTime::currentDateTime().toString("hhmmss");
169     pbiTrig.close();
170  }
171  pbiWatcherAutoUpdate = new QFileSystemWatcher();
172  pbiWatcherAutoUpdate->addPath(PBITRIGGER);
173  connect(pbiWatcherAutoUpdate, SIGNAL(fileChanged(const QString&)), this, SLOT(slotScheduledPBICheck() ));
174
175  // Watch our trigger file, to see if any automated updates are being downloaded
176  fileWatcherSys = new QFileSystemWatcher();
177  fileWatcherSys->addPath(PREFIX + "/share/pcbsd/pc-updatemanager/conf/sysupdate.conf");
178  connect(fileWatcherSys, SIGNAL(fileChanged(const QString&)), this, SLOT(slotScheduledSystemCheck() ));
179}
180
181// Slot that watches for any config changes
182void UpdaterTray::slotMonitorForChanges()
183{
184  QString upstamp, userupstamp;
185  qlonglong oldfrequency;
186  bool needRescan = false;
187
188  QSettings settings("PCBSD");
189
190  // Load the update frequency
191  oldfrequency = updateFrequency;
192  updateFrequency = settings.value("/PC-BSD/SystemUpdater/checkUpdateFrequency", updateFrequency).toLongLong();
193  if ( oldfrequency != updateFrequency)
194    needRescan = true;
195
196
197  // Check if we need to re-scan for PBI / system updates
198  upstamp = settings.value( "/PC-BSD/SystemUpdater/updateStatusTimeStamp", QString() ).toString();
199  userupstamp = settings.value( "/PC-BSD/SystemUpdater/updateStatusUserTimeStamp", QString() ).toString();
200  if ( upstamp != userupstamp ) {
201    settings.setValue( "/PC-BSD/SystemUpdater/updateStatusUserTimeStamp", upstamp );
202    needRescan = true;
203  }
204
205  if ( needRescan ) {
206    slotScheduledSystemCheck();
207    slotScheduledPBICheck();
208  }
209
210  QTimer::singleShot(5000, this, SLOT(slotMonitorForChanges()));
211}
212
213void UpdaterTray::slotSetTimerReadAutoStatus()
214{
215  QTimer::singleShot(1000, this, SLOT(slotAutoUpdateStatusChanged()));
216}
217
218void UpdaterTray::slotAutoUpdateStatusChanged()
219{
220  QString line;
221  QFile file( SYSTRIGGER );
222  if ( file.open( QIODevice::ReadOnly ) ) {
223      QTextStream stream( &file );
224      while ( !stream.atEnd() ) {
225          line = stream.readLine(); // line of text excluding '\n'
226          if ( line.indexOf("DOWNLOADING: " ) == 0)
227          {
228              line.replace("DOWNLOADING: ", "");
229              autoStatus = AUTODOWNLOAD;
230              autoCurrentUpdate = line;
231          }
232          if ( line.indexOf("INSTALLFAILED: " ) == 0)
233          {
234              autoStatus = AUTOFINISHED;
235              QTimer::singleShot(2000, this, SLOT(slotStartUpdateCheck()));
236              qDebug() << "FAILED INSTALLING UPDATES";
237          }
238          if ( line.indexOf("INSTALLFINISHED: " ) == 0)
239          {
240              autoStatus = AUTOFINISHED;
241              QTimer::singleShot(2000, this, SLOT(slotStartUpdateCheck()));
242              qDebug() << "DONE INSTALLING UPDATES";
243          }
244      } 
245
246      contextMenuRefresh();
247   }
248   file.close();
249
250   if ( ! file.exists() ) {
251     QFile sysTrig( SYSTRIGGER );
252     if ( sysTrig.open( QIODevice::WriteOnly ) ) {
253       QTextStream streamTrig( &sysTrig );
254       streamTrig << QDateTime::currentDateTime().toString("hhmmss");
255     }
256     sysTrig.close();
257
258     // Start our file watchers
259     fileWatcherAutoUpdate = new QFileSystemWatcher();
260     fileWatcherAutoUpdate->addPath(SYSTRIGGER);
261     connect(fileWatcherAutoUpdate, SIGNAL(fileChanged(const QString&)), this, SLOT(slotSetTimerReadAutoStatus() ));
262   }
263
264}
265
266void UpdaterTray::slotCheckAllUpdates()
267{
268   // Start the monitor service for system updates
269  QTimer::singleShot(300, this, SLOT(slotScheduledSystemCheck()));
270
271  // Start the monitor service for PBI updates
272  QTimer::singleShot(400, this, SLOT(slotScheduledPBICheck()));
273
274}
275
276void UpdaterTray::slotChangeRunStartup() {
277
278  // Save & reLoad the program preferences
279  slotSaveUpdaterPrefs();
280  QSettings settings("PCBSD");
281  settings.setValue( "/PC-BSD/SystemUpdater/runAtStartup", runAction->isChecked() );
282  loadUpdaterPrefs();
283
284}
285
286void UpdaterTray::slotChangePopup() {
287
288  // Save & reLoad the program preferences
289  QSettings settings("PCBSD");
290  settings.setValue( "/PC-BSD/SystemUpdater/displayPopup", popAction->isChecked() );
291  loadUpdaterPrefs();
292
293}
294
295void UpdaterTray::slotScheduledSystemCheck() {
296
297   
298   // Set our timer to check again in 24 hours.
299   if ( checkSysUpdatesFrequently == TRUE)
300     sysTimer->start( updateFrequency ); 
301
302   slotStartUpdateCheck();
303}
304
305
306
307
308void UpdaterTray::slotStartUpdateCheck()
309{
310  QString SysUrl;
311  QString PatchSet;
312  QString Version;
313  QString Arch, line;
314
315  // Block here if check already taking place
316  if ( doingCheck )
317     return;
318  doingCheck=true;
319
320  // Check if the system is doing updates right now, if it is, ignore the request
321  if ( programstatus == SYSTEM_CHECKING4UPDATES)
322    return;
323
324  // Set the tray icon that we are checking for updates
325  QIcon Icon;
326  Icon.addFile(PREFIX + "/share/pcbsd/pc-systemupdatertray/images/working.png");
327  trayIcon->setIcon(Icon);
328
329  // Set the status to checking for system updates
330  programstatus = SYSTEM_CHECKING4UPDATES;
331  wardenstatus = WARDEN_UP2DATE;
332
333  // Create the tooltip popup now
334  displayTooltip();
335
336  qDebug() << "Starting System Update Check";
337
338  //Check for installed system updates needing computer to restart to finish
339  bool needRestart = false;
340  if( QFile::exists("/usr/local/tmp/update-stagedir/doupdate.sh") ){
341    needRestart = true;
342  }
343
344  bool haveUp = false;
345  bool haveNGUp = false;
346  bool haveUpWarden = false;
347 
348  // Check for PC-BSD updates
349  /////////////////////////////////////////////
350  QProcess p;
351  p.start(QString("sudo"), QStringList() << "pc-updatemanager" << "check");
352  while(p.state() == QProcess::Starting || p.state() == QProcess::Running) {
353     p.waitForFinished(200);
354     QCoreApplication::processEvents();
355  }
356
357  while (p.canReadLine()) {
358    line = p.readLine().simplified();
359    if ( line.indexOf("The following updates are available") == 0 ) {
360      haveUp = true;
361      break;
362    } 
363  }
364  /////////////////////////////////////////////
365
366  // Check for meta-pkg updates
367  /////////////////////////////////////////////
368  QProcess m;
369  m.start(QString("sudo"), QStringList() << "pc-updatemanager" << "pkgcheck");
370  while(m.state() == QProcess::Starting || m.state() == QProcess::Running) {
371     m.waitForFinished(200);
372     QCoreApplication::processEvents();
373  }
374
375  while (m.canReadLine()) {
376    line = m.readLine().simplified();
377    if ( line.indexOf("To start the upgrade") == 0 ) {
378      haveNGUp = true;
379      break;
380    } 
381  }
382  /////////////////////////////////////////////
383
384  // Now check if there are freebsd-updates to install
385  /////////////////////////////////////////////
386  QProcess f;
387  f.start(QString("sudo"), QStringList() << "pc-fbsdupdatecheck");
388  while(f.state() == QProcess::Starting || f.state() == QProcess::Running) {
389     f.waitForFinished(200);
390     QCoreApplication::processEvents();
391  }
392  while (f.canReadLine()) {
393    line = f.readLine().simplified();
394    if ( line.indexOf("The following files will be updated ") == 0) {
395       haveUp = true;
396       break;
397    }
398  }
399  /////////////////////////////////////////////
400
401  // Check for warden updates
402  /////////////////////////////////////////////
403  QProcess w;
404  w.start(QString("warden"), QStringList() << "checkup" << "all");
405  while(w.state() == QProcess::Starting || w.state() == QProcess::Running) {
406     w.waitForFinished(200);
407     QCoreApplication::processEvents();
408  }
409
410  while (w.canReadLine()) {
411    line = w.readLine().simplified();
412    if ( line.indexOf("The following package updates") == 0 ) {
413      haveUpWarden = true;
414      wardenstatus = WARDEN_UPDATE_AVAIL;
415      break;
416    } 
417    if ( line.indexOf("The following files will be updates ") == 0 ) {
418      haveUpWarden = true;
419      wardenstatus = WARDEN_UPDATE_AVAIL;
420      break;
421    } 
422  }
423  /////////////////////////////////////////////
424
425  if ( needRestart ) {
426    programstatus = SYSTEM_RESTART_NEEDED;
427  } else if ( haveUp ) {
428    programstatus = SYSTEM_UPDATE_AVAIL;
429  } else if ( haveNGUp ) {
430    programstatus = PACKAGE_UPDATE_AVAIL;
431  } else {
432    // We have no updates available, indicate that now.
433    programstatus = SYSTEM_UP2DATE;
434  }
435 
436  //Display the info based on the program status
437  contextMenuRefresh();
438  displayTooltip();
439
440  // Ready to check again later
441  doingCheck=false;
442
443}
444
445/* This function is called to repaint the context menu based on program status */
446void UpdaterTray::contextMenuRefresh() {
447
448  QIcon Icon;
449
450  // If the program is completely updated!
451  if ( programstatus == SYSTEM_UP2DATE ) 
452     Icon.addFile(PREFIX + "/share/pcbsd/pc-systemupdatertray/images/updated.png");
453
454  // If the program couldn't get a list of updates from the server
455  if ( programstatus == CHECK_FAILED ) 
456     Icon.addFile(PREFIX + "/share/pcbsd/pc-systemupdatertray/images/connecterror.png");
457
458  // If the program has a PBI update
459  if ( pbistatus == PBI_UPDATES_AVAIL ) 
460     Icon.addFile(PREFIX + "/share/pcbsd/pc-systemupdatertray/images/pbiupdates.png");
461
462  /* Start checking the system - updater status now, which superceedes the PBI stuff */
463
464  // If the program is checking updates right now
465  if ( programstatus == SYSTEM_CHECKING4UPDATES ) 
466     Icon.addFile(PREFIX + "/share/pcbsd/pc-systemupdatertray/images/working.png");
467
468  if ( programstatus == PACKAGE_UPDATE_AVAIL ) 
469     Icon.addFile(PREFIX + "/share/pcbsd/pc-systemupdatertray/images/pbiupdates.png");
470
471  // If the program shows system updates available
472  if ( programstatus == SYSTEM_UPDATE_AVAIL || wardenstatus == WARDEN_UPDATE_AVAIL ) 
473     Icon.addFile(PREFIX + "/share/pcbsd/pc-systemupdatertray/images/sysupdates.png");
474 
475  if ( programstatus == SYSTEM_UPDATING)
476     Icon.addFile(PREFIX + "/share/pcbsd/pc-systemupdatertray/images/updating.png");
477
478  if ( programstatus == SYSTEM_RESTART_NEEDED)
479     Icon.addFile(PREFIX + "/share/pcbsd/pc-systemupdatertray/images/restart.png");
480 
481  // Check if we are downloading a system update in the background
482  if ( autoStatus == AUTODOWNLOAD)
483     Icon.addFile(PREFIX + "/share/pcbsd/pc-systemupdatertray/images/go-down.png");
484
485  // Set the status that we are installing updates
486  if ( autoStatus == AUTOINSTALLING)
487     Icon.addFile(PREFIX + "/share/pcbsd/pc-systemupdatertray/images/updating.png");
488
489  // Check if we are downloading a system update in the background
490  if ( autoStatus == AUTOFAILED)
491     Icon.addFile(PREFIX + "/share/pcbsd/pc-systemupdatertray/images/connecterror.png");
492
493  trayIcon->setIcon(Icon);
494
495  // Update the tooltip to what we are doing now
496  displayTooltip();
497 
498}
499
500
501void UpdaterTray::slotOpenConfigDlg() {
502}
503
504
505QString UpdaterTray::getLineFromCommandOutput( QString command )
506{
507        FILE *file = popen(command.toLatin1(),"r"); 
508       
509        char buffer[100];
510       
511        QString line = ""; 
512        char firstChar;
513       
514        if ((firstChar = fgetc(file)) != -1){
515                line += firstChar;
516                line += fgets(buffer,100,file);
517        }
518       
519       
520        pclose(file);
521       
522       
523        return line;
524}
525
526
527void UpdaterTray::slotTrayActivated(QSystemTrayIcon::ActivationReason reason) {
528   if(reason == QSystemTrayIcon::Context)
529     return;
530
531   if(reason == QSystemTrayIcon::Trigger) {
532       if ( (programstatus != SYSTEM_UPDATE_AVAIL && programstatus != PACKAGE_UPDATE_AVAIL) && (pbistatus == PBI_UPDATES_AVAIL) )
533       {
534            slotOpenSoftwareManagerInstalled();
535            return;
536       }
537       else
538       {
539           if ( programstatus == SYSTEM_UPDATE_AVAIL ) {
540              slotOpenUpdateManager();
541              return;
542           }
543           if ( programstatus == PACKAGE_UPDATE_AVAIL ) {
544              slotOpenPackageManager();
545              return;
546           }
547           if ( wardenstatus == WARDEN_UPDATE_AVAIL ) {
548              slotOpenJailManager();
549              return;
550           }
551       }//else
552   }
553
554   slotOpenSoftwareManager();
555}
556
557void UpdaterTray::slotOpenJailManager(void)
558{   
559   system ("(pc-su warden gui) &"); 
560}
561
562void UpdaterTray::slotOpenPackageManager(void)
563{   
564   system ("(sudo pc-pkgmanager) &"); 
565}
566
567void UpdaterTray::slotOpenUpdateManager(void)
568{   
569   if ( programstatus == SYSTEM_RESTART_NEEDED ){
570     qDebug() << "System restart required: Do not open update manager";
571     QMessageBox::warning(this, tr("Restart Required"), tr("Please restart your computer to complete the pending updates") );
572   }else{
573     system ("(sudo pc-updategui) &"); 
574   }
575}
576
577void UpdaterTray::slotOpenSoftwareManager(void)
578{   
579    system ("(pc-softwaremanager) &"); 
580}
581
582void UpdaterTray::slotOpenSoftwareManagerInstalled(void)
583{   
584    system ("(pc-softwaremanager -installed) &"); 
585}
586
587// The user wants to quit the application
588void UpdaterTray::slotQuitTray() {
589 exit(0);
590}
591
592
593
594void UpdaterTray::displayTooltip() {
595
596   QString  tooltipStr;
597
598   tooltipStr = QString(tr("PC-BSD Update Manager"));
599
600   tooltipStr += "<br><hr>";
601
602   if (programstatus == SYSTEM_UP2DATE && wardenstatus == WARDEN_UP2DATE ) {
603      tooltipStr += "<br>" + tr("Your system is fully updated");
604   }
605   
606   if (programstatus == CHECK_FAILED ) {
607      tooltipStr += "<br>" + tr("Failed to contact the update server!");
608   }
609
610   if (programstatus == SYSTEM_CHECKING4UPDATES ) {
611      tooltipStr += "<br>" + tr("Checking for updates...");
612   }
613   
614   if (programstatus == SYSTEM_UPDATE_AVAIL) {
615      tooltipStr += "<br>" + tr("System updates available");
616      if ( !shownPopup && popAction->isChecked() ) {
617        shownPopup=true;
618        QTimer::singleShot(15000, this, SLOT(slotShowSysUpdatePopup()));
619      }
620   }
621
622   if (programstatus == PACKAGE_UPDATE_AVAIL) {
623      tooltipStr += "<br>" + tr("Package updates available");
624      if ( !shownPopup && popAction->isChecked() ) {
625        shownPopup=true;
626        QTimer::singleShot(15000, this, SLOT(slotShowPkgUpdatePopup()));
627      }
628   }
629
630   if (wardenstatus == WARDEN_UPDATE_AVAIL) {
631      tooltipStr += "<br>" + tr("Jail updates available");
632      if ( !shownPopup && popAction->isChecked() ) {
633        shownPopup=true;
634        QTimer::singleShot(15000, this, SLOT(slotShowJailUpdatePopup()));
635      }
636   }
637   
638   if (programstatus == SYSTEM_RESTART_NEEDED) {
639     tooltipStr += "<br>" + tr("System restart required to finish updates");
640   }
641
642   // If the program has a PBI update
643   if ( pbistatus == PBI_UPDATES_AVAIL ) 
644   {
645      tooltipStr += "<br><br>" + tr("PBI updates available") + "<br><br>";
646      tooltipStr += updatePBITextList;
647      if ( !shownPopup && popAction->isChecked() ) {
648        shownPopup=true;
649        QTimer::singleShot(15000, this, SLOT(slotShowPBIUpdatePopup()));
650      }
651   }
652   
653   trayIcon->setToolTip(tooltipStr);
654
655}
656
657void UpdaterTray::slotSaveUpdaterPrefs() {
658  if (runAction->isChecked() )
659    system("pbreg set /PC-BSD/SystemUpdater/runAtStartup true");
660  else
661    system("pbreg set /PC-BSD/SystemUpdater/runAtStartup false");
662
663
664}
665
666void UpdaterTray::loadUpdaterPrefs() {
667  // Load the user preferences for the System Updater
668  QSettings settings("PCBSD");
669 
670  bool enableStartup = settings.value( "/PC-BSD/SystemUpdater/runAtStartup", TRUE ).toBool();
671  runAction->setChecked( enableStartup );
672
673  bool enablePopupNotify = settings.value( "/PC-BSD/SystemUpdater/displayPopup", TRUE ).toBool();
674  popAction->setChecked( enablePopupNotify );
675
676  // Load a custom tmpdir
677  customTmpDir = PATCHTMPDIR_DEFAULT;
678  customTmpDir = settings.value("/PC-BSD/SystemUpdater/customTmpDir", customTmpDir).toString();
679
680  // Load a custom tmpdir
681  updateFrequency = UPDATE_MSEC;
682  updateFrequency = settings.value("/PC-BSD/SystemUpdater/checkUpdateFrequency", updateFrequency).toLongLong();
683
684}
685
686void UpdaterTray::slotSysUpdateTimer() {
687  slotScheduledSystemCheck();
688}
689
690
691
692
693/**********************************************************************
694Code for the PBI update checking functionality of the system updater
695***********************************************************************/
696
697void UpdaterTray::slotScheduledPBICheck()
698{
699   // Set our timer to check again in 24 hours.
700   if ( checkPBIUpdatesFrequently == TRUE)
701     pbiTimer->start( updateFrequency); 
702
703   slotStartPBIUpdateCheck();
704
705}
706
707void UpdaterTray::slotStartPBIUpdateCheck()
708{
709
710  if ( pbistatus == PBI_CHECKING4UPDATES || pbistatus == PBI_UPDATING )
711     return;
712
713  qDebug() << "Starting PBI update check...";
714
715  slotPBICheckUpdate();
716
717} 
718
719// Start checking our list of PBIs which may be updatable
720void UpdaterTray::slotPBICheckUpdate()
721{
722  // Empty out our PBI buffer
723  PBIBuffer="";
724  updatePBITextList = "";
725
726  qDebug() << "Checking For PBI Updates...";
727  checkPBIProc = new QProcess();
728  checkPBIProc->setProcessChannelMode(QProcess::MergedChannels);
729  connect(checkPBIProc, SIGNAL(readyReadStandardOutput()), this, SLOT(slotReadPBIBuffer()));
730  connect(checkPBIProc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotPopulatePBIList()) );
731  checkPBIProc->start(QString("pbi_update"), QStringList() << "--check-all" );
732}
733
734void UpdaterTray::slotReadPBIBuffer()
735{
736    while( checkPBIProc->canReadLine() )
737        PBIBuffer += checkPBIProc->readLine();
738}
739
740// The update checking is finished
741void UpdaterTray::slotPopulatePBIList()
742{
743        if ( PBIBuffer.indexOf("- Available:") != -1 ) {
744                updatePBITextList = PBIBuffer;
745                pbistatus = PBI_UPDATES_AVAIL;
746        } else {
747                // No PBI updates found right now!
748                pbistatus = PBI_UPDATED;
749        }
750
751        contextMenuRefresh();
752}
753
754void UpdaterTray::slotShowPkgUpdatePopup()
755{
756        disconnect(trayIcon, SIGNAL(messageClicked()), 0, 0 );
757        trayIcon->showMessage(tr("Package Updates Available"), tr("Important package updates are available. Click here to install them!"), QSystemTrayIcon::Critical);
758        connect( trayIcon, SIGNAL(messageClicked()), this, SLOT(slotOpenPackageManager()) );
759}
760
761
762void UpdaterTray::slotShowSysUpdatePopup()
763{
764        disconnect(trayIcon, SIGNAL(messageClicked()), 0, 0 );
765        trayIcon->showMessage(tr("System Updates Available"), tr("Important system updates are available. Click here to install them!"), QSystemTrayIcon::Critical);
766        connect( trayIcon, SIGNAL(messageClicked()), this, SLOT(slotOpenUpdateManager()) );
767}
768
769void UpdaterTray::slotShowJailUpdatePopup()
770{
771        disconnect(trayIcon, SIGNAL(messageClicked()), 0, 0 );
772        trayIcon->showMessage(tr("Jail Updates Available"), tr("Important jail updates are available. Click here to launch the Warden!"), QSystemTrayIcon::Critical);
773        connect( trayIcon, SIGNAL(messageClicked()), this, SLOT(slotOpenJailManager()) );
774}
775
776void UpdaterTray::slotShowPBIUpdatePopup()
777{
778        disconnect(trayIcon, SIGNAL(messageClicked()), 0, 0 );
779        trayIcon->showMessage(tr("Software Updates Available"), tr("Software updates are available. Click here to install them!"), QSystemTrayIcon::Warning);
780        connect( trayIcon, SIGNAL(messageClicked()), this, SLOT(slotOpenSoftwareManagerInstalled()) );
781}
782
783void UpdaterTray::slotSingleInstance()
784{
785  trayIcon->show();
786}
Note: See TracBrowser for help on using the repository browser.