Permalink
Browse files

Clean up the new SystemFlags calss so that only a pre-defined set of …

…messages can be sent. This ensures that the watchers do not need to do custom parsing to figure out what the message is based upon the application that set the flag.
  • Loading branch information...
1 parent e93d2a0 commit 15c3f293c878c88765d8812ae1a9a1c2de82e411 Ken Moore committed Mar 26, 2014
Showing with 42 additions and 21 deletions.
  1. +11 −5 src-qt4/libpcbsd/utils/pcbsd-sysFlags.cpp
  2. +31 −16 src-qt4/libpcbsd/utils/pcbsd-sysFlags.h
@@ -42,16 +42,22 @@ void SystemFlagWatcher::watcherNotification(){
QFileInfoList flags = dir.entryInfoList( QDir::Files | QDir::NoDotAndDotDot, QDir::Time);
for(int i=0; i<flags.length(); i++){
if(CDT < flags[i].lastModified()){
- QString contents = quickRead(flags[i].absoluteFilePath()); //add this later
+ QString contents = quickRead(flags[i].absoluteFilePath());
+ SystemFlags::SYSMESSAGE msg;
+ if(contents==MWORKING){ msg = SystemFlags::Working; }
+ else if(contents==MERROR){ msg = SystemFlags::Error; }
+ else if(contents==MSUCCESS){ msg = SystemFlags::Success; }
+ else if(contents==MUPDATE){ msg = SystemFlags::UpdateAvailable; }
+ else{ continue; } //invalid message - skip this flag
//New flag - check which one and emit the proper signal
if(flags[i].fileName().startsWith(NETWORKRESTARTED) ){
- emit FlagChanged(SystemFlags::NetRestart, contents);
+ emit FlagChanged(SystemFlags::NetRestart, msg);
}else if(flags[i].fileName().startsWith(PKGUPDATEAVAILABLE) ){
- emit FlagChanged(SystemFlags::PkgUpdate, contents);
+ emit FlagChanged(SystemFlags::PkgUpdate, msg);
}else if(flags[i].fileName().startsWith(SYSUPDATEAVAILABLE) ){
- emit FlagChanged(SystemFlags::SysUpdate, contents);
+ emit FlagChanged(SystemFlags::SysUpdate, msg);
}else if(flags[i].fileName().startsWith(PBIUPDATEAVAILABLE) ){
- emit FlagChanged(SystemFlags::PbiUpdate, contents);
+ emit FlagChanged(SystemFlags::PbiUpdate, msg);
}
}
}
@@ -22,37 +22,52 @@
#define SYSUPDATEAVAILABLE QString("sys-update-available")
#define PBIUPDATEAVAILABLE QString("pbi-update-available")
+// DEFINE THE SIMPLE MESSAGES
+#define MWORKING QString("working")
+#define MERROR QString("error")
+#define MSUCCESS QString("success")
+#define MUPDATE QString("updateavailable")
+
class SystemFlags{
public:
enum SYSFLAG{ NetRestart, PkgUpdate, SysUpdate, PbiUpdate};
-
- static void setFlag( SYSFLAG flag, QString contents = ""){
+ enum SYSMESSAGE{ Working, Error, Success, UpdateAvailable};
+ static void setFlag( SYSFLAG flag, SYSMESSAGE msg){
if(!QFile::exists(FLAGDIR)){
pcbsd::Utils::runShellCommand("mkdir -p -m 777 "+FLAGDIR);
if( !QFile::exists(FLAGDIR) ){ return; }
}
- QString cmd;
- if(contents.isEmpty()){ cmd = "touch %1"; }
- else{ cmd = "echo '%2' > %1"; cmd = cmd.arg("%1", contents); }
+ QString cmd = "echo '%2' > %1";
+ //Get the Message Type
+ QString contents;
+ switch(msg){
+ case Working:
+ contents = MWORKING; break;
+ case Error:
+ contents = MERROR; break;
+ case Success:
+ contents = MSUCCESS; break;
+ case UpdateAvailable:
+ contents = MUPDATE; break;
+ default:
+ return; //invalid message
+ }
//Now get the flag type
- cmd = cmd.arg(FLAGDIR+"/");
QString user = "-"+QString( getlogin() );
+ QString file;
switch(flag){
case NetRestart:
- cmd = cmd.arg(NETWORKRESTARTED+user);
- break;
+ file = NETWORKRESTARTED+user; break;
case PkgUpdate:
- cmd = cmd.arg(PKGUPDATEAVAILABLE+user);
- break;
+ file = PKGUPDATEAVAILABLE+user; break;
case SysUpdate:
- cmd = cmd.arg(SYSUPDATEAVAILABLE+user);
- break;
+ file = SYSUPDATEAVAILABLE+user; break;
case PbiUpdate:
- cmd = cmd.arg(PBIUPDATEAVAILABLE+user);
- break;
+ file = PBIUPDATEAVAILABLE+user; break;
default:
- return;
+ return; //invalid flag
}
+ cmd = cmd.arg(file, contents);
pcbsd::Utils::runShellCommand(cmd);
}
@@ -76,7 +91,7 @@ private slots:
QString quickRead(QString filepath);
signals:
- void FlagChanged(SystemFlags::SYSFLAG, QString);
+ void FlagChanged(SystemFlags::SYSFLAG, SystemFlags::SYSMESSAGE);
};
#endif

0 comments on commit 15c3f29

Please sign in to comment.