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

9.1-release9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1
Last change on this file since 304095c was 304095c, checked in by Kris Moore <kris@…>, 20 months ago

Make system update tray aware of pc-pkgmanager

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