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

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1
Last change on this file since 6ed8c50 was 6ed8c50, checked in by yurkis <yurkis@…>, 17 months ago

Rework system update tray app: use icons from resources but not from file system. Please remove icons installing rule from project file if noone else uses them

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