-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitializer.cpp
110 lines (89 loc) · 3.02 KB
/
initializer.cpp
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
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "initializer.h"
#include <QWidget>
#include <QFile>
#include <QJsonDocument>
#include <QJsonObject>
#include <QSettings>
#include <QProcess>
#include "dbusintegration.h"
#include "panel.h"
#include "configman.h"
QList<Panel*> panels;
void Initializer::autostart() {
QString homeDir = QDir::homePath();
QString path = QString("%1/.config/autostart").arg(homeDir);
QDir autostartDir(path);
QStringList autostartEntries = autostartDir.entryList(QDir::Files | QDir::NoDotAndDotDot);
qDebug() << "Autostart:" << autostartEntries;
for (int i = 0; i < autostartEntries.length(); ++i) {
QString exec;
//qDebug() << autostartDir.absoluteFilePath(autostartEntries[i])
QSettings desktopFileReader(autostartDir.absoluteFilePath(
autostartEntries[i]), QSettings::IniFormat);
desktopFileReader.sync();
desktopFileReader.beginGroup("Desktop Entry");
exec = desktopFileReader.value("Exec").toString();
desktopFileReader.endGroup();
// https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-1.0.html
// 'The Exec key'
if (exec[exec.length()-2] == "%") {
exec.chop(2);
}
QProcess* process = new QProcess(this);
process->start(exec);
}
}
void Initializer::reconfigurePanel() {
for (int i = 0; i < panels.count(); ++i) {
delete panels[i];
}
panels.clear();
delete mCfgMan;
mCfgMan = new ConfigManager();
mCfgMan->readConfig();
mCfgMan->setFields();
for (int i = 1; i <= mCfgMan->mCountPanels; ++i) {
if (!mCfgMan->mPanels.at(i-1).isNull) {
Panel* panel = new Panel(this, mCfgMan, i, mApp, panels);
panels.append(panel);
}
}
}
void Initializer::highlightPanel(int n) {
if (n >= 1 && n <= panels.count()) {
panels.at(n-1)->highlight();
}
else {
qDebug() << "Cannot highlight: Panel" << n << "does not exist!";
}
}
void Initializer::playStartupSound() {
QString path = mCfgMan->mStartupSound;
if (!path.isEmpty() && QFile::exists(path)) {
qDebug() << "Startup sound" << path;
mPlayer->setMedia(QUrl::fromLocalFile(path));
mPlayer->play();
}
}
Initializer::Initializer(QApplication* app) {
qDebug() << QString("plainPanel %1.%2.%3").arg(MAJOR_VER,
MINOR_VER,
PATCH_VER);
mCfgMan = new ConfigManager();
mCfgMan->readConfig();
mCfgMan->setFields();
mApp = app;
mPlayer = new QMediaPlayer();
panels.clear();
for (int i = 1; i <= mCfgMan->mCountPanels; ++i) {
if (!mCfgMan->mPanels.at(i-1).isNull) {
Panel* panel = new Panel(this, mCfgMan, i, mApp, panels);
panels.append(panel);
}
}
autostart();
DBusIntegration db("org.plainDE.plainPanel", "/Actions", "org.plainDE.actions", this);
playStartupSound();
}
Initializer::~Initializer() {
}