splashapp.cpp 4.9 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
 *   Copyright (C) 2010 Ivan Cukic <ivan.cukic(at)kde.org>
 *   Copyright (C) 2013 Martin Klapetek <mklapetek(at)kde.org>
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License version 2,
 *   or (at your option) any later version, as published by the Free
 *   Software Foundation
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details
 *
 *   You should have received a copy of the GNU General Public
 *   License along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

21
22
#include "splashwindow.h"
#include "splashapp.h"
23
24
25

#include <QPixmap>
#include <QCursor>
26
#include <qscreen.h>
27
#include <QDBusConnection>
28
29
#include <QDate>
#include <QDebug>
30
#include <QCommandLineParser>
31

32
#include <KQuickAddons/QtQuickSettings>
33
34
35
36
37
#include <KWindowSystem>
#include <KWayland/Client/connection_thread.h>
#include <KWayland/Client/registry.h>
#include <KWayland/Client/plasmashell.h>

38
39
#define TEST_STEP_INTERVAL 2000

40
/**
41
 * There are 7 used stages in ksplash
42
 *  - initial
43
 *  - kcminit
44
 *  - kinit
45
46
47
48
49
50
 *  - ksmserver
 *  - wm
 *  - ready
 *  - desktop
 */

51
SplashApp::SplashApp(int &argc, char ** argv)
52
    : QGuiApplication(argc, argv),
53
      m_stage(0),
54
      m_testing(false),
55
      m_window(false)
56
{
57
58
    KQuickAddons::QtQuickSettings::init();

59
    QCommandLineParser parser;
60
61
62
63
    parser.addOption(QCommandLineOption(QStringLiteral("test"), QStringLiteral("Run in test mode")));
    parser.addOption(QCommandLineOption(QStringLiteral("window"), QStringLiteral("Run in windowed mode")));
    parser.addOption(QCommandLineOption(QStringLiteral("nofork"), QStringLiteral("Don't fork")));
    parser.addOption(QCommandLineOption(QStringLiteral("pid"), QStringLiteral("Print the pid of the child process")));
64
    parser.addPositionalArgument(QStringLiteral("theme"), QStringLiteral("Path to the theme to test"));
65
66
67
    parser.addHelpOption();

    parser.process(*this);
68
69
    m_testing = parser.isSet(QStringLiteral("test"));
    m_window = parser.isSet(QStringLiteral("window"));
70
    m_theme = parser.positionalArguments().value(0);
71

72
73
74
75
    QDBusConnection dbus = QDBusConnection::sessionBus();
    dbus.registerObject(QStringLiteral("/KSplash"), this, QDBusConnection::ExportScriptableSlots);
    dbus.registerService(QStringLiteral("org.kde.KSplash"));

76
77
    setupWaylandIntegration();

78
79
    foreach(QScreen* screen, screens())
        adoptScreen(screen);
80

81
    setStage(QStringLiteral("initial"));
82

83
    if (KWindowSystem::isPlatformWayland()) {
84
85
86
        setStage(QStringLiteral("wm"));
    }

87
    QPixmap cursor(32, 32);
88
    cursor.fill(Qt::transparent);
89
90
91
92
93
94
    setOverrideCursor(QCursor(cursor));

    if (m_testing) {
        m_timer.start(TEST_STEP_INTERVAL, this);
    }

95
    connect(this, &QGuiApplication::screenAdded, this, &SplashApp::adoptScreen);
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

}

SplashApp::~SplashApp()
{
    qDeleteAll(m_windows);
}

void SplashApp::timerEvent(QTimerEvent * event)
{
    if (event->timerId() == m_timer.timerId()) {
        m_timer.stop();

        setStage(m_stage + 1);

        m_timer.start(TEST_STEP_INTERVAL, this);
    }
}

void SplashApp::setStage(const QString &stage)
{
117
118
119
120
121
    //filter out startup events from KDED as they will be removed in a future release
    if (stage == QLatin1String("kded") || stage == QLatin1String("confupdate")) {
        return;
    }

122
123
124
125
126
127
128
129
130
    if (m_stages.contains(stage)) {
        return;
    }
    m_stages.append(stage);
    setStage(m_stages.count());
}

void SplashApp::setStage(int stage)
{
131
132
    m_stage = stage;
    if (m_stage == 7) {
133
        QGuiApplication::exit(EXIT_SUCCESS);
134
135
136
137
138
139
    }
    foreach (SplashWindow *w, m_windows) {
        w->setStage(stage);
    }
}

140
void SplashApp::adoptScreen(QScreen* screen)
141
{
142
    SplashWindow *w = new SplashWindow(m_testing, m_window, m_theme);
143
    w->setGeometry(screen->geometry());
144
    w->setStage(m_stage);
145
    w->setVisible(true);
146
147
148
149
150
151
152
    m_windows << w;

    connect(screen, &QScreen::geometryChanged, w, &SplashWindow::setGeometry);
    connect(screen, &QObject::destroyed, w, [this, w](){
        m_windows.removeAll(w);
        w->deleteLater();
    });
153
}
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174

void SplashApp::setupWaylandIntegration()
{
    if (!KWindowSystem::isPlatformWayland()) {
        return;
    }
    using namespace KWayland::Client;
    ConnectionThread *connection = ConnectionThread::fromApplication(this);
    if (!connection) {
        return;
    }
    Registry *registry = new Registry(this);
    registry->create(connection);
    connect(registry, &Registry::plasmaShellAnnounced, this,
        [this, registry] (quint32 name, quint32 version) {
            m_waylandPlasmaShell = registry->createPlasmaShell(name, version, this);
        }
    );
    registry->setup();
    connection->roundtrip();
}