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

9.1-release9.2-releaseenter/10releng/10.0releng/10.0.1releng/10.0.2releng/10.0.3releng/10.1releng/10.1.1releng/10.1.2releng/10.2
Last change on this file since 1620346 was 1620346, checked in by Kris Moore <kris@…>, 2 years ago

Initial import of PC-BSD /current/ SVN repo

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