aboutsummaryrefslogtreecommitdiff
path: root/mthemedaemon/main.cpp
blob: afb35c92093d3f0967f1a7f7735801a9e3115270 (plain)
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
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (directui@nokia.com)
**
** This file is part of libmeegotouch.
**
** If you have questions regarding the use of this file, please contact
** Nokia at directui@nokia.com.
**
** 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>

#ifdef CLOSE_ON_ENTER
#include "keypresswaiter.h"
#endif

static int setup_unix_signal_handlers()
{
    struct sigaction sighup, sigterm, sigint;

    sighup.sa_handler = MThemeDaemonServer::hupSignalHandler;
    sigemptyset(&sighup.sa_mask);
    sighup.sa_flags = 0;
    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;

     return 0;
 }

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");
#else
    // For the moment we use the native graphicssystem to share X pixmaps if
    // nothing else is specified explicitly.
    // Later we use the shiny new meego graphicssystem features by default.
    if (qApp->arguments().indexOf("-graphicssystem") == -1) {
        QApplication::setGraphicsSystem("native");
    }
#endif // HAVE_MEEGOGRAPHICSSYSTEM

    QApplication app(argc, argv);

    // 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

    if (app.arguments().indexOf("-quitimmediately") >= 0) {
        QTimer::singleShot(0, &app, SLOT(quit()));
    }

    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();
}