File: main.cpp

package info (click to toggle)
gammaray 3.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 21,612 kB
  • sloc: cpp: 94,643; ansic: 2,227; sh: 336; python: 164; yacc: 90; lex: 82; xml: 61; makefile: 26
file content (124 lines) | stat: -rw-r--r-- 3,542 bytes parent folder | download
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
/*
  main.cpp

  This file is part of GammaRay, the Qt application inspection and manipulation tool.

  SPDX-FileCopyrightText: 2015 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
  Author: Volker Krause <volker.krause@kdab.com>

  SPDX-License-Identifier: GPL-2.0-or-later

  Contact KDAB at <info@kdab.com> for commercial licensing options.
*/

#include <config-gammaray.h>
#include <config-gammaray-version.h>

#include <common/paths.h>

#include <launcher/core/launcher.h>
#include <launcher/core/launchoptions.h>
#include <launcher/ui/launcherwindow.h>

#include <client/clientconnectionmanager.h>

#include <QApplication>
#include <QPointer>

using namespace GammaRay;

class InternalLauncher : public Launcher
{
    Q_OBJECT
public:
    explicit InternalLauncher(const LaunchOptions &options, QObject *parent = nullptr)
        : Launcher(options, parent)
    {
    }

signals:
    void launchClient(const QUrl &serverAddress);

protected:
    void startClient(const QUrl &serverAddress) override
    {
        emit launchClient(serverAddress);
    }
};

class Orchestrator : public QObject
{
    Q_OBJECT
public:
    explicit Orchestrator(QObject *parent = nullptr)
        : QObject(parent)
    {
        m_launcherWindow = new LauncherWindow;
        // For some reason, Qt4 on OSX does not respect setQuitOnLastWindowClosed(false)
        m_launcherWindow->setAttribute(Qt::WA_QuitOnClose, false);
        connect(m_launcherWindow, SIGNAL(accepted()), this, SLOT(launcherWindowAccepted()));
        connect(m_launcherWindow, SIGNAL(rejected()), QCoreApplication::instance(), SLOT(quit()));
        m_launcherWindow->show();
    }

public slots:
    void launcherWindowAccepted()
    {
        Q_ASSERT(m_launcherWindow);
        Q_ASSERT(m_launcherWindow->result() == QDialog::Accepted);
        const LaunchOptions opts = m_launcherWindow->launchOptions();

        if (!opts.isValid()) {
            QCoreApplication::exit(1);
            return;
        }

        m_launcher = new InternalLauncher(opts, this);
        connect(m_launcher, SIGNAL(launchClient(QUrl)), this, SLOT(startClient(QUrl)));
        connect(m_launcher, SIGNAL(finished()), this, SLOT(launcherFinished()));
        m_launcher->start();
    }

    void startClient(const QUrl &serverAddress)
    {
        auto *conMan = new ClientConnectionManager(this);
        connect(conMan, SIGNAL(ready()), conMan, SLOT(createMainWindow()));
        connect(conMan, SIGNAL(disconnected()), QApplication::instance(), SLOT(quit()));
        connect(conMan, SIGNAL(persistentConnectionError(QString)), conMan,
                SLOT(handlePersistentConnectionError(QString)));
        conMan->connectToHost(serverAddress);
    }

    void launcherFinished()
    {
        m_launcher->deleteLater();
    }

private:
    QPointer<LauncherWindow> m_launcherWindow;
    QPointer<Launcher> m_launcher;
};

int main(int argc, char **argv)
{
    QCoreApplication::setOrganizationName("KDAB");
    QCoreApplication::setOrganizationDomain("kdab.com");
    QCoreApplication::setApplicationName("GammaRay");
    QCoreApplication::setApplicationVersion(GAMMARAY_COMPACT_VERSION_STRING);
    QApplication::setQuitOnLastWindowClosed(false);

    QApplication app(argc, argv);
    Paths::setRelativeRootPath(
#if defined(Q_OS_MACX) && defined(GAMMARAY_INSTALL_QT_LAYOUT)
        GAMMARAY_INVERSE_BUNDLE_DIR
#else
        GAMMARAY_INVERSE_BIN_DIR
#endif
    );
    ClientConnectionManager::init();

    Orchestrator o;
    return app.exec();
}

#include "main.moc"