summaryrefslogtreecommitdiffstats
path: root/src/deadlinetype.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/deadlinetype.cpp')
-rw-r--r--src/deadlinetype.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/deadlinetype.cpp b/src/deadlinetype.cpp
new file mode 100644
index 0000000..e539d65
--- /dev/null
+++ b/src/deadlinetype.cpp
@@ -0,0 +1,59 @@
+#include "deadlinetype.h"
+#include "config.h"
+
+#include <QFile>
+#include <QSettings>
+#include <QTextStream>
+
+static const QString FILE_SHUTDOWN("shutdown");
+static const QString FILE_IDLE_KILL("idle-kill");
+static const QString FILE_NO_TIMEOUT("no-timeout");
+
+static const QString CONFIG_LOCKED_SUFFIX("-locked");
+
+static const QString CONFIG_MESSAGES_PATH(CONFIG_DIR + "/messages.ini");
+
+static QSettings MESSAGES(CONFIG_MESSAGES_PATH, QSettings::IniFormat);
+
+const DeadlineType *DeadlineType::Unknown = new DeadlineType("");
+const DeadlineType *DeadlineType::Shutdown = new DeadlineType(FILE_SHUTDOWN);
+const DeadlineType *DeadlineType::IdleKill = new DeadlineType(FILE_IDLE_KILL);
+const DeadlineType *DeadlineType::NoTimeout = new DeadlineType(FILE_NO_TIMEOUT);
+
+static QString loadFileToString(const QString &fileName);
+
+DeadlineType::DeadlineType(const QString &name)
+{
+ if (name.isEmpty())
+ return;
+ MESSAGES.setIniCodec("UTF-8");
+ QString nameLocked = name + CONFIG_LOCKED_SUFFIX;
+ _headerLine[0] = MESSAGES.value(name).toString();
+ _bodyText[0] = loadFileToString(CONFIG_DIR + "/text-" + name);
+ if (_headerLine[0].isEmpty()) {
+ _headerLine[0] = CONFIG_MESSAGES_PATH + " missing key " + name;
+ }
+ if (_bodyText[0].isEmpty()) {
+ _bodyText[0] = CONFIG_DIR + "/text-" + name + " missing";
+ }
+ _headerLine[1] = MESSAGES.value(nameLocked).toString();
+ _bodyText[1] = loadFileToString(CONFIG_DIR + "/text-" + nameLocked);
+ if (_headerLine[1].isEmpty()) {
+ _headerLine[1] = _headerLine[0];
+ }
+ if (_bodyText[1].isEmpty()) {
+ _bodyText[1] = _bodyText[0];
+ }
+}
+
+static QString loadFileToString(const QString &fileName)
+{
+ QFile f(fileName);
+ QString str;
+ if (f.open(QFile::ReadOnly | QFile::Text)) {
+ QTextStream s(&f);
+ s.setCodec("UTF-8");
+ str = s.readAll();
+ }
+ return str;
+}