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

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

Add a better system of locking when GUIs can run freebsd-update, this will prevent
some messed up situations where a current freebsd-update is being screwed up by another
running process.

  • Property mode set to 100644
File size: 23.0 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
386  // KPM Lets skip this if pc-fbsdupdatecheck is open, having two freebsd-updates running at same time
387  // Cause *bad* things to happen
388  if ( ! QFile::exists("/tmp/.fbsdup-lock") ) {
389    qDebug() << "Checking for freebsd-updates!";
390
391    QProcess f;
392    f.start(QString("sudo"), QStringList() << "pc-fbsdupdatecheck");
393    while(f.state() == QProcess::Starting || f.state() == QProcess::Running) {
394       f.waitForFinished(200);
395       QCoreApplication::processEvents();
396    }
397    while (f.canReadLine()) {
398      line = f.readLine().simplified();
399      if ( line.indexOf("The following files will be updated ") == 0) {
400         haveUp = true;
401         break;
402      }
403    }
404  } else {
405    qDebug() << "pc-updategui is open, skip freebsd-update for now";
406  }
407  /////////////////////////////////////////////
408
409  // Check for warden updates
410  /////////////////////////////////////////////
411  QProcess w;
412  w.start(QString("warden"), QStringList() << "checkup" << "all");
413  while(w.state() == QProcess::Starting || w.state() == QProcess::Running) {
414     w.waitForFinished(200);
415     QCoreApplication::processEvents();
416  }
417
418  while (w.canReadLine()) {
419    line = w.readLine().simplified();
420    if ( line.indexOf("The following package updates") == 0 ) {
421      haveUpWarden = true;
422      wardenstatus = WARDEN_UPDATE_AVAIL;
423      break;
424    } 
425    if ( line.indexOf("The following files will be updates ") == 0 ) {
426      haveUpWarden = true;
427      wardenstatus = WARDEN_UPDATE_AVAIL;
428      break;
429    } 
430  }
431  /////////////////////////////////////////////
432
433  if ( needRestart ) {
434    programstatus = SYSTEM_RESTART_NEEDED;
435  } else if ( haveUp ) {
436    programstatus = SYSTEM_UPDATE_AVAIL;
437  } else if ( haveNGUp ) {
438    programstatus = PACKAGE_UPDATE_AVAIL;
439  } else {
440    // We have no updates available, indicate that now.
441    programstatus = SYSTEM_UP2DATE;
442  }
443 
444  //Display the info based on the program status
445  contextMenuRefresh();
446  displayTooltip();
447
448  // Ready to check again later
449  doingCheck=false;
450
451}
452
453/* This function is called to repaint the context menu based on program status */
454void UpdaterTray::contextMenuRefresh() {
455
456  QIcon Icon;
457
458  // If the program is completely updated!
459  if ( programstatus == SYSTEM_UP2DATE ) 
460     Icon.addFile(":/images/updated.png");
461
462  // If the program couldn't get a list of updates from the server
463  if ( programstatus == CHECK_FAILED ) 
464     Icon.addFile(":/images/connecterror.png");
465
466  // If the program has a PBI update
467  if ( pbistatus == PBI_UPDATES_AVAIL ) 
468     Icon.addFile(":/images/pbiupdates.png");
469
470  /* Start checking the system - updater status now, which superceedes the PBI stuff */
471
472  // If the program is checking updates right now
473  if ( programstatus == SYSTEM_CHECKING4UPDATES ) 
474     Icon.addFile(":/images/working.png");
475
476  if ( programstatus == PACKAGE_UPDATE_AVAIL ) 
477     Icon.addFile(":/images/pkgupdates.png");
478
479  // If the program shows system updates available
480  if ( programstatus == SYSTEM_UPDATE_AVAIL || wardenstatus == WARDEN_UPDATE_AVAIL ) 
481     Icon.addFile(":/images/sysupdates.png");
482 
483  if ( programstatus == SYSTEM_UPDATING)
484     Icon.addFile(":/images/updating.png");
485
486  if ( programstatus == SYSTEM_RESTART_NEEDED)
487     Icon.addFile(":/images/restart.png");
488 
489  // Check if we are downloading a system update in the background
490  if ( autoStatus == AUTODOWNLOAD)
491     Icon.addFile(":/images/go-down.png");
492
493  // Set the status that we are installing updates
494  if ( autoStatus == AUTOINSTALLING)
495     Icon.addFile(":/images/updating.png");
496
497  // Check if we are downloading a system update in the background
498  if ( autoStatus == AUTOFAILED)
499     Icon.addFile(":/images/connecterror.png");
500
501  trayIcon->setIcon(Icon);
502
503  // Update the tooltip to what we are doing now
504  displayTooltip();
505 
506}
507
508
509void UpdaterTray::slotOpenConfigDlg() {
510}
511
512
513QString UpdaterTray::getLineFromCommandOutput( QString command )
514{
515        FILE *file = popen(command.toLatin1(),"r"); 
516       
517        char buffer[100];
518       
519        QString line = ""; 
520        char firstChar;
521       
522        if ((firstChar = fgetc(file)) != -1){
523                line += firstChar;
524                line += fgets(buffer,100,file);
525        }
526       
527       
528        pclose(file);
529       
530       
531        return line;
532}
533
534
535void UpdaterTray::slotTrayActivated(QSystemTrayIcon::ActivationReason reason) {
536   if(reason == QSystemTrayIcon::Context)
537     return;
538
539   if(reason == QSystemTrayIcon::Trigger) {
540       if ( (programstatus != SYSTEM_UPDATE_AVAIL && programstatus != PACKAGE_UPDATE_AVAIL) && (pbistatus == PBI_UPDATES_AVAIL) )
541       {
542            slotOpenSoftwareManagerInstalled();
543            return;
544       }
545       else
546       {
547           if ( programstatus == SYSTEM_UPDATE_AVAIL ) {
548              slotOpenUpdateManager();
549              return;
550           }
551           if ( programstatus == PACKAGE_UPDATE_AVAIL ) {
552              slotOpenPackageManager();
553              return;
554           }
555           if ( wardenstatus == WARDEN_UPDATE_AVAIL ) {
556              slotOpenJailManager();
557              return;
558           }
559       }//else
560   }
561
562   slotOpenSoftwareManager();
563}
564
565void UpdaterTray::slotOpenJailManager(void)
566{   
567   system ("(pc-su warden gui) &"); 
568}
569
570void UpdaterTray::slotOpenPackageManager(void)
571{   
572   system ("(pc-su pc-pkgmanager) &"); 
573}
574
575void UpdaterTray::slotOpenUpdateManager(void)
576{   
577   if ( programstatus == SYSTEM_RESTART_NEEDED ){
578     qDebug() << "System restart required: Do not open update manager";
579     QMessageBox::warning(this, tr("Restart Required"), tr("Please restart your computer to complete the pending updates") );
580   }else{
581     system ("(sudo pc-updategui) &"); 
582   }
583}
584
585void UpdaterTray::slotOpenSoftwareManager(void)
586{   
587    system ("(pc-softwaremanager) &"); 
588}
589
590void UpdaterTray::slotOpenSoftwareManagerInstalled(void)
591{   
592    system ("(pc-softwaremanager -installed) &"); 
593}
594
595// The user wants to quit the application
596void UpdaterTray::slotQuitTray() {
597 exit(0);
598}
599
600
601
602void UpdaterTray::displayTooltip() {
603
604   QString  tooltipStr;
605
606   tooltipStr = QString(tr("PC-BSD Update Manager"));
607
608   tooltipStr += "<br><hr>";
609
610   if (programstatus == SYSTEM_UP2DATE && wardenstatus == WARDEN_UP2DATE ) {
611      tooltipStr += "<br>" + tr("Your system is fully updated");
612   }
613   
614   if (programstatus == CHECK_FAILED ) {
615      tooltipStr += "<br>" + tr("Failed to contact the update server!");
616   }
617
618   if (programstatus == SYSTEM_CHECKING4UPDATES ) {
619      tooltipStr += "<br>" + tr("Checking for updates...");
620   }
621   
622   if (programstatus == SYSTEM_UPDATE_AVAIL) {
623      tooltipStr += "<br>" + tr("System updates available");
624      if ( !shownPopup && popAction->isChecked() ) {
625        shownPopup=true;
626        QTimer::singleShot(15000, this, SLOT(slotShowSysUpdatePopup()));
627      }
628   }
629
630   if (programstatus == PACKAGE_UPDATE_AVAIL) {
631      tooltipStr += "<br>" + tr("Package updates available");
632      if ( !shownPopup && popAction->isChecked() ) {
633        shownPopup=true;
634        QTimer::singleShot(15000, this, SLOT(slotShowPkgUpdatePopup()));
635      }
636   }
637
638   if (wardenstatus == WARDEN_UPDATE_AVAIL) {
639      tooltipStr += "<br>" + tr("Jail updates available");
640      if ( !shownPopup && popAction->isChecked() ) {
641        shownPopup=true;
642        QTimer::singleShot(15000, this, SLOT(slotShowJailUpdatePopup()));
643      }
644   }
645   
646   if (programstatus == SYSTEM_RESTART_NEEDED) {
647     tooltipStr += "<br>" + tr("System restart required to finish updates");
648   }
649
650   // If the program has a PBI update
651   if ( pbistatus == PBI_UPDATES_AVAIL ) 
652   {
653      tooltipStr += "<br><br>" + tr("PBI updates available") + "<br><br>";
654      tooltipStr += updatePBITextList;
655      if ( !shownPopup && popAction->isChecked() ) {
656        shownPopup=true;
657        QTimer::singleShot(15000, this, SLOT(slotShowPBIUpdatePopup()));
658      }
659   }
660   
661   trayIcon->setToolTip(tooltipStr);
662
663}
664
665void UpdaterTray::slotSaveUpdaterPrefs() {
666  if (runAction->isChecked() )
667    system("pbreg set /PC-BSD/SystemUpdater/runAtStartup true");
668  else
669    system("pbreg set /PC-BSD/SystemUpdater/runAtStartup false");
670
671
672}
673
674void UpdaterTray::loadUpdaterPrefs() {
675  // Load the user preferences for the System Updater
676  QSettings settings("PCBSD");
677 
678  bool enableStartup = settings.value( "/PC-BSD/SystemUpdater/runAtStartup", TRUE ).toBool();
679  runAction->setChecked( enableStartup );
680
681  bool enablePopupNotify = settings.value( "/PC-BSD/SystemUpdater/displayPopup", TRUE ).toBool();
682  popAction->setChecked( enablePopupNotify );
683
684  // Load a custom tmpdir
685  customTmpDir = PATCHTMPDIR_DEFAULT;
686  customTmpDir = settings.value("/PC-BSD/SystemUpdater/customTmpDir", customTmpDir).toString();
687
688  // Load a custom tmpdir
689  updateFrequency = UPDATE_MSEC;
690  updateFrequency = settings.value("/PC-BSD/SystemUpdater/checkUpdateFrequency", updateFrequency).toLongLong();
691
692}
693
694void UpdaterTray::slotSysUpdateTimer() {
695  slotScheduledSystemCheck();
696}
697
698
699
700
701/**********************************************************************
702Code for the PBI update checking functionality of the system updater
703***********************************************************************/
704
705void UpdaterTray::slotScheduledPBICheck()
706{
707   // Set our timer to check again in 24 hours.
708   if ( checkPBIUpdatesFrequently == TRUE)
709     pbiTimer->start( updateFrequency); 
710
711   slotStartPBIUpdateCheck();
712
713}
714
715void UpdaterTray::slotStartPBIUpdateCheck()
716{
717
718  if ( pbistatus == PBI_CHECKING4UPDATES || pbistatus == PBI_UPDATING )
719     return;
720
721  qDebug() << "Starting PBI update check...";
722
723  slotPBICheckUpdate();
724
725} 
726
727// Start checking our list of PBIs which may be updatable
728void UpdaterTray::slotPBICheckUpdate()
729{
730  // Empty out our PBI buffer
731  PBIBuffer="";
732  updatePBITextList = "";
733
734  qDebug() << "Checking For PBI Updates...";
735  checkPBIProc = new QProcess();
736  checkPBIProc->setProcessChannelMode(QProcess::MergedChannels);
737  connect(checkPBIProc, SIGNAL(readyReadStandardOutput()), this, SLOT(slotReadPBIBuffer()));
738  connect(checkPBIProc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotPopulatePBIList()) );
739  checkPBIProc->start(QString("pbi_update"), QStringList() << "--check-all" );
740}
741
742void UpdaterTray::slotReadPBIBuffer()
743{
744    while( checkPBIProc->canReadLine() )
745        PBIBuffer += checkPBIProc->readLine();
746}
747
748// The update checking is finished
749void UpdaterTray::slotPopulatePBIList()
750{
751        if ( PBIBuffer.indexOf("- Available:") != -1 ) {
752                updatePBITextList = PBIBuffer;
753                pbistatus = PBI_UPDATES_AVAIL;
754        } else {
755                // No PBI updates found right now!
756                pbistatus = PBI_UPDATED;
757        }
758
759        contextMenuRefresh();
760}
761
762void UpdaterTray::slotShowPkgUpdatePopup()
763{
764        disconnect(trayIcon, SIGNAL(messageClicked()), 0, 0 );
765        trayIcon->showMessage(tr("Package Updates Available"), tr("Important package updates are available. Click here to install them!"), QSystemTrayIcon::Critical);
766        connect( trayIcon, SIGNAL(messageClicked()), this, SLOT(slotOpenPackageManager()) );
767}
768
769
770void UpdaterTray::slotShowSysUpdatePopup()
771{
772        disconnect(trayIcon, SIGNAL(messageClicked()), 0, 0 );
773        trayIcon->showMessage(tr("System Updates Available"), tr("Important system updates are available. Click here to install them!"), QSystemTrayIcon::Critical);
774        connect( trayIcon, SIGNAL(messageClicked()), this, SLOT(slotOpenUpdateManager()) );
775}
776
777void UpdaterTray::slotShowJailUpdatePopup()
778{
779        disconnect(trayIcon, SIGNAL(messageClicked()), 0, 0 );
780        trayIcon->showMessage(tr("Jail Updates Available"), tr("Important jail updates are available. Click here to launch the Warden!"), QSystemTrayIcon::Critical);
781        connect( trayIcon, SIGNAL(messageClicked()), this, SLOT(slotOpenJailManager()) );
782}
783
784void UpdaterTray::slotShowPBIUpdatePopup()
785{
786        disconnect(trayIcon, SIGNAL(messageClicked()), 0, 0 );
787        trayIcon->showMessage(tr("Software Updates Available"), tr("Software updates are available. Click here to install them!"), QSystemTrayIcon::Warning);
788        connect( trayIcon, SIGNAL(messageClicked()), this, SLOT(slotOpenSoftwareManagerInstalled()) );
789}
790
791void UpdaterTray::slotSingleInstance()
792{
793  trayIcon->show();
794}
Note: See TracBrowser for help on using the repository browser.