summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2018-11-05 10:12:54 +0100
committerSimon Rettberg2018-11-05 10:12:54 +0100
commit827f27462e84e1ebc1c94ec50efa0dfaf5d944b1 (patch)
treec764148272feae27c331526463d00a047352dbc7 /src
parentRead messages from external files (diff)
downloadbwlp-screensaver-827f27462e84e1ebc1c94ec50efa0dfaf5d944b1.tar.gz
bwlp-screensaver-827f27462e84e1ebc1c94ec50efa0dfaf5d944b1.tar.xz
bwlp-screensaver-827f27462e84e1ebc1c94ec50efa0dfaf5d944b1.zip
Make QSS customizable as well
Diffstat (limited to 'src')
-rw-r--r--src/config.cpp20
-rw-r--r--src/config.h5
-rw-r--r--src/deadlinetype.cpp25
-rw-r--r--src/saverwidget.cpp5
-rw-r--r--src/ui/saver.ui3
5 files changed, 39 insertions, 19 deletions
diff --git a/src/config.cpp b/src/config.cpp
index 7dfb6b1..450c8db 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -1,5 +1,8 @@
#include "config.h"
+#include <QFile>
+#include <QTextStream>
+
const QString CONFIG_DIR("/opt/openslx/xscreensaver");
const QString CONFIG_QSS(CONFIG_DIR + "/style.qss");
@@ -7,3 +10,20 @@ Config::Config()
{
}
+
+QString Config::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;
+}
+
+QString Config::getMainQss()
+{
+ return loadFileToString(CONFIG_QSS);
+}
diff --git a/src/config.h b/src/config.h
index 9e3af29..25da6b6 100644
--- a/src/config.h
+++ b/src/config.h
@@ -8,8 +8,11 @@ extern const QString CONFIG_QSS;
class Config
{
+private:
+ Config();
public:
- Config();
+ static QString loadFileToString(const QString &fileName);
+ static QString getMainQss();
};
#endif // CONFIG_H
diff --git a/src/deadlinetype.cpp b/src/deadlinetype.cpp
index e539d65..b14a572 100644
--- a/src/deadlinetype.cpp
+++ b/src/deadlinetype.cpp
@@ -1,9 +1,8 @@
#include "deadlinetype.h"
#include "config.h"
-#include <QFile>
#include <QSettings>
-#include <QTextStream>
+#include <QDebug>
static const QString FILE_SHUTDOWN("shutdown");
static const QString FILE_IDLE_KILL("idle-kill");
@@ -20,8 +19,6 @@ 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())
@@ -29,7 +26,7 @@ DeadlineType::DeadlineType(const QString &name)
MESSAGES.setIniCodec("UTF-8");
QString nameLocked = name + CONFIG_LOCKED_SUFFIX;
_headerLine[0] = MESSAGES.value(name).toString();
- _bodyText[0] = loadFileToString(CONFIG_DIR + "/text-" + name);
+ _bodyText[0] = Config::loadFileToString(CONFIG_DIR + "/text-" + name);
if (_headerLine[0].isEmpty()) {
_headerLine[0] = CONFIG_MESSAGES_PATH + " missing key " + name;
}
@@ -37,23 +34,15 @@ DeadlineType::DeadlineType(const QString &name)
_bodyText[0] = CONFIG_DIR + "/text-" + name + " missing";
}
_headerLine[1] = MESSAGES.value(nameLocked).toString();
- _bodyText[1] = loadFileToString(CONFIG_DIR + "/text-" + nameLocked);
+ qDebug() << "From" << nameLocked << "got:" << _headerLine[1];
+ _bodyText[1] = Config::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;
+ qDebug() << name;
+ qDebug() << " locked headline:" << headerLine(true);
+ qDebug() << "unlocked headline:" << headerLine(false);
}
diff --git a/src/saverwidget.cpp b/src/saverwidget.cpp
index 17353d6..d7f3a74 100644
--- a/src/saverwidget.cpp
+++ b/src/saverwidget.cpp
@@ -2,6 +2,7 @@
#include "ui_saver.h"
#include "screensaver.h"
#include "deadlinetype.h"
+#include "config.h"
#include <QTimer>
#include <QX11Info>
@@ -36,6 +37,10 @@ SaverWidget::SaverWidget(WId parentWinId, QWidget *parent) :
_isLocked(false)
{
ui->setupUi(this);
+ QString qss = Config::getMainQss();
+ if (!qss.isEmpty()) {
+ this->setStyleSheet(qss);
+ }
QTimer *t = new QTimer(this);
t->setInterval(1000);
connect(t, &QTimer::timeout, [=]() {
diff --git a/src/ui/saver.ui b/src/ui/saver.ui
index 8f1dc93..a9f4e70 100644
--- a/src/ui/saver.ui
+++ b/src/ui/saver.ui
@@ -43,6 +43,9 @@ QLabel {
<property name="text">
<string notr="true">¯\_(ツ)_/¯</string>
</property>
+ <property name="textFormat">
+ <enum>Qt::PlainText</enum>
+ </property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>