source: src-qt4/libpcbsd/utils/pcbsd-sysFlags.cpp @ cab198c

releng/10.0.2releng/10.0.3
Last change on this file since cab198c was cab198c, checked in by Ken Moore <ken@…>, 6 months ago

Add a new file/classes to libpcbsd - utils.
1) SystemFlags? : public enumeration of different flag types, and a static function to set a particular system flag (SystemFlags::setFlat(SYSFLAG, QString contents) )
2) SystemFlagWatcher? : Class that can be used in Qt utilites for alerting when a new system flag is available (as well as a public function to look for new flags within the last X minutes - for when a utility just started up)

Still needs testing in an actual utility.
One known restriction: setFlag() needs to be run by a root-permissions utility after computer startup before non-root utilities can successfully set flags. This is because the /tmp/pcbsdflags dir needs to be initially created first with 666 permissions.

  • Property mode set to 100644
File size: 2.0 KB
Line 
1#include "pcbsd-sysFlags.h"
2
3SystemFlagWatcher::SystemFlagWatcher(){
4  CDT = QDateTime::currentDateTime();
5  watcher = new QFileSystemWatcher(this);
6  connect(watcher, SIGNAL(directoryChanged(QString)), this, SLOT(watcherNotification()) );
7  connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT(watcherNotification()) );
8  QTimer::singleShot(1, this, SLOT(watchFlagDir()) ); 
9}
10
11SystemFlagWatcher::~SystemFlagWatcher(){
12       
13}
14
15//========
16//   PUBLIC
17//========
18void SystemFlagWatcher::checkForRecent(int minutes){
19  CDT = QDateTime::currentDateTime();
20        CDT = CDT.addMSecs( -(minutes*60000) );
21  watcherNotification(); //Now manually check for flags since then
22}
23
24//=========
25//    PRIVATE
26//=========
27void SystemFlagWatcher::watchFlagDir(){
28  watcher->addPath(FLAGDIR);
29  //Now manually run the detection routine
30  watcherNotification();
31  //Now check that the directory is being watched
32  if(watcher->directories().isEmpty()){
33    //flag dir does not exist yet, try again in 2 minutes
34    QTimer::singleShot(120000, this, SLOT(watchFlagDir()) );
35  }
36}
37
38void SystemFlagWatcher::watcherNotification(){
39  //Does not specify the contents of a flag just yet - KenMoore 3/12/14
40  QDir dir(FLAGDIR);
41  if(!dir.exists()){ return; } //flag directory does not exist yet - do nothing
42  QFileInfoList flags = dir.entryInfoList( QDir::Files | QDir::NoDotAndDotDot, QDir::Time);
43  for(int i=0; i<flags.length(); i++){
44     if(CDT < flags[i].lastModified()){
45       //New flag - check which one and emit the proper signal
46       if(flags[i].fileName() == NETWORKRESTARTED){
47         emit FlagChanged(SystemFlags::NetRestart, "");
48       }else if(flags[i].fileName() == PKGUPDATEAVAILABLE){
49         emit FlagChanged(SystemFlags::PkgUpdate, "");
50       }else if(flags[i].fileName() == SYSUPDATEAVAILABLE){
51         emit FlagChanged(SystemFlags::SysUpdate, "");
52       }else if(flags[i].fileName() == PBIUPDATEAVAILABLE){
53         emit FlagChanged(SystemFlags::PbiUpdate, "");
54       }
55     }
56  }
57  CDT = QDateTime::currentDateTime(); //Now update the last time flags were checked
58}
Note: See TracBrowser for help on using the repository browser.