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

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

Fix up all the last bits of clang / HEAD fussiness

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