-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
161 lines (128 loc) · 4.25 KB
/
main.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/***************************************************************************
**
** Copyright (C) 2010, 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/
#include "mthemedaemonserver.h"
#include <QDebug>
#include <QApplication>
#include <signal.h>
#include <systemd/sd-daemon.h>
#ifdef CLOSE_ON_ENTER
#include "keypresswaiter.h"
#endif
#include "logger.h"
namespace
{
QtMsgType outputLevel = QtDebugMsg;
Logger logger;
}
static int setup_unix_signal_handlers()
{
struct sigaction sighup, sigterm, sigint, sigusr1;
sighup.sa_handler = MThemeDaemonServer::hupSignalHandler;
sigemptyset(&sighup.sa_mask);
sighup.sa_flags = SA_RESTART;
if (sigaction(SIGHUP, &sighup, 0) > 0)
return 1;
sigterm.sa_handler = MThemeDaemonServer::termSignalHandler;
sigemptyset(&sigterm.sa_mask);
sigterm.sa_flags = SA_RESTART;
if (sigaction(SIGTERM, &sigterm, 0) > 0)
return 2;
sigint.sa_handler = MThemeDaemonServer::intSignalHandler;
sigemptyset(&sigint.sa_mask);
sigint.sa_flags = SA_RESTART;
if (sigaction(SIGINT, &sigint, 0) > 0)
return 3;
sigusr1.sa_handler = MThemeDaemonServer::usr1SignalHandler;
sigemptyset(&sigusr1.sa_mask);
sigusr1.sa_flags = SA_RESTART;
if (sigaction(SIGUSR1, &sigusr1, 0) > 0)
return 4;
return 0;
}
static QtMsgType getOutputLevelFromArgs(QStringList arguments)
{
QString argLevel;
int index = arguments.indexOf("-output-level") + 1;
if (index > 0 && index < arguments.length()) {
argLevel = arguments[index];
logger.setLogLevel(argLevel);
}
index = arguments.indexOf("-log-path") + 1;
if (index > 0 && index < arguments.length()) {
logger.setLogPath(arguments[index]);
}
if (argLevel == "debug")
return QtDebugMsg;
if (argLevel == "warning")
return QtWarningMsg;
if (argLevel == "critical")
return QtCriticalMsg;
#ifdef __arm__
return QtCriticalMsg;
#else
return QtWarningMsg;
#endif
}
static void mMessageHandler(QtMsgType type, const char *msg)
{
logger.log(type, QString(msg));
if (type < outputLevel)
return;
fprintf(stderr, "%s\n", msg);
if (type == QtFatalMsg)
abort();
}
int main(int argc, char **argv)
{
setup_unix_signal_handlers();
// make sure we are not loading the maemo6 qt style which
// could interfere with us
QApplication::setStyle("windows");
#ifndef HAVE_MEEGOGRAPHICSSYSTEM
QApplication::setGraphicsSystem("native");
#endif // HAVE_MEEGOGRAPHICSSYSTEM
QApplication app(argc, argv);
outputLevel = getOutputLevelFromArgs(app.arguments());
qInstallMsgHandler(mMessageHandler);
// Apply custom server address, if the "-address" has been passed as argument
QString serverAddress;
int index = app.arguments().indexOf("-address");
if ((index >= 0) && (index + 1 < app.arguments().count())) {
serverAddress = app.arguments().at(index + 1);
}
MThemeDaemonServer server(serverAddress);
#ifdef CLOSE_ON_ENTER
KeyPressWaiter keyWaiter;
QObject::connect(&keyWaiter, SIGNAL(finished()), qApp, SLOT(quit()));
keyWaiter.start();
#endif
/* Notify systemd if requested */
if (app.arguments().indexOf("-systemd") >= 0) {
sd_notify(0, "READY=1");
}
if (app.arguments().indexOf("-quitimmediately") >= 0) {
QTimer::singleShot(0, &app, SLOT(quit()));
}
if (app.arguments().indexOf("-log-graphics-files") >= 0) {
MThemeDaemon::printGraphicalFiles = true;
}
index = app.arguments().indexOf("-slowdown");
if ((index >= 0) && (index + 1 < app.arguments().count())) {
bool conversionOk;
int slowDown = app.arguments().at(index + 1).toInt(&conversionOk);
if (conversionOk) {
server.setSlowDown(slowDown);
qDebug() << "Slowing down theme asset requests by" << slowDown << "microseconds";
}
}
return app.exec();
}