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

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

Fix some bugs doing freebsd-update / major updates via the GUI.

When an update is going to require a reboot, we must ensure the GUI
does NOT check for updates again, possibly trampling the freebsd-update
cache directories / files

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