forked from fuchsmich/smpc
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmain.cpp
More file actions
111 lines (94 loc) · 3.4 KB
/
main.cpp
File metadata and controls
111 lines (94 loc) · 3.4 KB
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
111
#include <nemonotifications-qt5/notification.h>
#include <sailfishapp.h>
#include <QDebug>
#include <QGuiApplication>
#include <QQuickView>
#include "src/controller.h"
#include "src/resourcehandler.h"
quint32 m_notificationId = 0;
void showNotification(QString body, QString summary) {
qWarning() << Q_FUNC_INFO;
Notification n;
n.setReplacesId(m_notificationId);
n.setPreviewBody(body);
n.setPreviewSummary(summary);
n.publish();
m_notificationId = n.replacesId();
}
void removeNotification() {
if (m_notificationId == 0) {
return;
}
Notification n;
n.setReplacesId(m_notificationId);
n.close();
m_notificationId = 0;
}
void stopMPD() {
QProcess process;
QString exitMessage = "";
process.start("/usr/bin/systemctl", QStringList() << "--user"
<< "is-active"
<< "mpd");
process.waitForFinished(-1);
if (process.exitCode() == 0) {
qDebug() << "Stopping MPD ";
process.start("/usr/bin/systemctl", QStringList() << "--user"
<< "stop"
<< "mpd");
exitMessage = "Stopped MPD service";
process.waitForFinished(-1);
}
if (!exitMessage.isEmpty()) {
removeNotification();
showNotification(exitMessage, "");
}
exit(0);
}
QString mkdir(QString path, QString name) {
QDir dir(path);
QDir rmdir(path + "/" + name);
rmdir.removeRecursively();
if (!dir.mkdir(name)) {
QFileInfo info(path);
if (!info.isWritable())
return QString("No permissions to create %1").arg(name);
return QString("Cannot create folder %1").arg(name);
}
return QString();
}
Q_DECL_EXPORT int main(int argc, char *argv[]) {
QScopedPointer<QGuiApplication> app(SailfishApp::application(argc, argv));
app->setOrganizationName("harbour-smpc");
app->setApplicationName("harbour-smpc");
ResourceHandler *resourceHandler = new ResourceHandler();
QLocale::setDefault(QLocale::c());
QQuickView *view = SailfishApp::createView();
view->engine()->addImportPath("/usr/share/harbour-smpc/qml/");
view->setSource(SailfishApp::pathTo("qml/main.qml"));
view->setDefaultAlphaBuffer(true);
view->rootContext()->setContextProperty("version", APP_VERSION);
view->rootContext()->setContextProperty("buildyear", BUILD_YEAR);
view->rootContext()->setContextProperty(QLatin1String("resourceHandler"),
resourceHandler);
foreach (QString path, view->engine()->importPathList()) {
qDebug() << path;
}
mkdir("/tmp", "harbour-smpc");
QSettings mySets;
int stopMPDOnExit =
mySets.value("general_properties/stop_mpd_on_exit", "0").toInt();
// Turn on/off debuglogging according to setting
bool debugLogEnabled =
mySets.value("general_properties/debuglog_enabled", false).toBool();
QLoggingCategory::defaultCategory()->setEnabled(QtMsgType::QtDebugMsg,
debugLogEnabled);
Controller *control = new Controller(view, nullptr);
view->rootContext()->setContextProperty("ctl", control);
view->show();
int retVal = app->exec();
if (stopMPDOnExit == 1) {
stopMPD();
}
return retVal;
}