Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on Mar 26, 2014
@beanpole135 beanpole135 Make sure that the sysFlag watcher can properly read the flag content…
…s as text.
e93d2a0
@beanpole135 beanpole135 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.
15c3f29
View
22 src-qt4/libpcbsd/utils/pcbsd-sysFlags.cpp
@@ -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);
}
}
}
@@ -63,8 +69,10 @@ QString SystemFlagWatcher::quickRead(QString filepath){
QFile file(filepath);
if( !file.open(QIODevice::ReadOnly | QIODevice::Text) ){ return ""; }
QStringList ret;
- while( !file.atEnd() ){
- ret << QString( file.readLine() );
+ QTextStream in(&file);
+ while( !in.atEnd() ){
+ ret << QString( in.readLine() );
}
+ file.close();
return ret.join("\n");
}
View
48 src-qt4/libpcbsd/utils/pcbsd-sysFlags.h
@@ -9,6 +9,7 @@
#include <QFile>
#include <QDir>
#include <QTimer>
+#include <QTextStream>
#include <unistd.h>
@@ -21,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);
}
@@ -75,7 +91,7 @@ private slots:
QString quickRead(QString filepath);
signals:
- void FlagChanged(SystemFlags::SYSFLAG, QString);
+ void FlagChanged(SystemFlags::SYSFLAG, SystemFlags::SYSMESSAGE);
};
#endif

No commit comments for this range

Something went wrong with that request. Please try again.