This repository has been archived by the owner on Dec 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
/
pcbsd-sysFlags.h
97 lines (84 loc) · 2.3 KB
/
pcbsd-sysFlags.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef _PCBSD_SYSTEM_FLAGS_H
#define _PCBSD_SYSTEM_FLAGS_H
#include <QObject>
#include <QFileSystemWatcher>
#include <QString>
#include <QDateTime>
#include <QFileInfo>
#include <QFile>
#include <QDir>
#include <QTimer>
#include <QTextStream>
#include <unistd.h>
#include "pcbsd-utils.h"
// DEFINE THE FLAG FILES
#define FLAGDIR QString("/tmp/.pcbsdflags")
#define NETWORKRESTARTED QString("network-restarted")
#define PKGUPDATEAVAILABLE QString("pkg-update-available")
#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};
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 = "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
QString user = "-"+QString( getlogin() );
QString file;
switch(flag){
case NetRestart:
file = NETWORKRESTARTED+user; break;
case PkgUpdate:
file = PKGUPDATEAVAILABLE+user; break;
case SysUpdate:
file = SYSUPDATEAVAILABLE+user; break;
case PbiUpdate:
file = PBIUPDATEAVAILABLE+user; break;
default:
return; //invalid flag
}
cmd = cmd.arg(file, contents);
pcbsd::Utils::runShellCommand(cmd);
}
};
class SystemFlagWatcher : public QObject{
Q_OBJECT
public:
SystemFlagWatcher();
~SystemFlagWatcher();
void checkForRecent(int minutes);
private:
QDateTime CDT; //current date time
QFileSystemWatcher *watcher;
private slots:
void watchFlagDir();
void watcherNotification();
QString quickRead(QString filepath);
signals:
void FlagChanged(SystemFlags::SYSFLAG, SystemFlags::SYSMESSAGE);
};
#endif