~nick-dedekind/unity8/indicator.submenu-reinit

« back to all changes in this revision

Viewing changes to main.cpp

  • Committer: Nick Dedekind
  • Date: 2013-09-16 07:37:30 UTC
  • mfrom: (229.1.91 trunk)
  • Revision ID: nicholas.dedekind@gmail.com-20130916073730-3o9iv6i9h0d2c7rl
merged with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <QtQml/QQmlContext>
26
26
#include <qpa/qplatformnativeinterface.h>
27
27
#include <QLibrary>
 
28
#include <QDebug>
28
29
#include <libintl.h>
 
30
#include <dlfcn.h>
29
31
 
30
32
// local
31
33
#include "paths.h"
32
34
#include "MouseTouchAdaptor.h"
33
35
#include "ApplicationArguments.h"
34
36
 
 
37
#include <unity-mir/qmirserver.h>
 
38
 
35
39
namespace {
36
40
 
37
41
void prependImportPaths(QQmlEngine *engine, const QStringList &paths)
72
76
}
73
77
} // namespace {
74
78
 
75
 
int main(int argc, char** argv)
 
79
int startShell(int argc, const char** argv, void* server)
76
80
{
77
81
    /* Workaround Qt platform integration plugin not advertising itself
78
82
       as having the following capabilities:
82
86
    setenv("QML_FORCE_THREADED_RENDERER", "1", 1);
83
87
    setenv("QML_FIXED_ANIMATION_STEP", "1", 1);
84
88
 
 
89
    const bool isUbuntuMirServer = qgetenv("QT_QPA_PLATFORM") == "ubuntumirserver";
 
90
 
85
91
    QGuiApplication::setApplicationName("Unity 8");
86
 
    QGuiApplication application(argc, argv);
 
92
    QGuiApplication *application;
 
93
    if (isUbuntuMirServer) {
 
94
        QLibrary unityMir("unity-mir", 1);
 
95
        unityMir.load();
 
96
 
 
97
        typedef QGuiApplication* (*createServerApplication_t)(int&, const char **, void*);
 
98
        createServerApplication_t createQMirServerApplication = (createServerApplication_t) unityMir.resolve("createQMirServerApplication");
 
99
        if (!createQMirServerApplication) {
 
100
            qDebug() << "unable to resolve symbol: createQMirServerApplication";
 
101
            return 4;
 
102
        }
 
103
 
 
104
        application = createQMirServerApplication(argc, argv, server);
 
105
    } else {
 
106
        application = new QGuiApplication(argc, (char**)argv);
 
107
    }
87
108
 
88
109
    resolveIconTheme();
89
110
 
90
 
    QStringList args = application.arguments();
 
111
    QStringList args = application->arguments();
91
112
    ApplicationArguments qmlArgs(args);
92
113
 
93
114
    // The testability driver is only loaded by QApplication but not by QGuiApplication.
124
145
    if (args.contains(QLatin1String("-mousetouch"))) {
125
146
        mouseTouchAdaptor = new MouseTouchAdaptor;
126
147
        mouseTouchAdaptor->setTargetWindow(view);
127
 
        application.installNativeEventFilter(mouseTouchAdaptor);
 
148
        application->installNativeEventFilter(mouseTouchAdaptor);
128
149
    }
129
150
 
130
151
    QPlatformNativeInterface* nativeInterface = QGuiApplication::platformNativeInterface();
139
160
    QUrl source("Shell.qml");
140
161
    prependImportPaths(view->engine(), ::overrideImportPaths());
141
162
    appendImportPaths(view->engine(), ::fallbackImportPaths());
 
163
 
 
164
    QStringList importPath = view->engine()->importPathList().filter("qt5/imports");
 
165
    if (isUbuntuMirServer) {
 
166
        importPath.first().append("/Unity-Mir");
 
167
        view->engine()->addImportPath(importPath.first());
 
168
    }
 
169
 
142
170
    view->setSource(source);
143
171
    view->setColor("transparent");
144
172
 
145
 
    if (qgetenv("QT_QPA_PLATFORM") == "ubuntu" || args.contains(QLatin1String("-fullscreen"))) {
 
173
    if (qgetenv("QT_QPA_PLATFORM") == "ubuntu" || isUbuntuMirServer || args.contains(QLatin1String("-fullscreen"))) {
146
174
        view->showFullScreen();
147
175
    } else {
148
176
        view->show();
149
177
    }
150
178
 
151
 
    int result = application.exec();
 
179
    int result = application->exec();
152
180
 
153
181
    delete mouseTouchAdaptor;
 
182
    delete application;
154
183
 
155
184
    return result;
156
185
}
 
186
 
 
187
int main(int argc, const char *argv[])
 
188
{
 
189
    // For ubuntumirserver/ubuntumirclient
 
190
    if (qgetenv("QT_QPA_PLATFORM").startsWith("ubuntumir")) {
 
191
        setenv("QT_QPA_PLATFORM", "ubuntumirserver", 1);
 
192
 
 
193
        // If we use unity-mir directly, we automatically link to the Mir-server
 
194
        // platform-api bindings, which result in unexpected behaviour when
 
195
        // running the non-Mir scenario.
 
196
        QLibrary unityMir("unity-mir", 1);
 
197
        unityMir.load();
 
198
        if (!unityMir.isLoaded()) {
 
199
            qDebug() << "Library unity-mir not found/loaded";
 
200
            return 1;
 
201
        }
 
202
 
 
203
        typedef QMirServer* (*createServer_t)(int, const char **);
 
204
        createServer_t createQMirServer = (createServer_t) unityMir.resolve("createQMirServer");
 
205
        if (!createQMirServer) {
 
206
            qDebug() << "unable to resolve symbol: createQMirServer";
 
207
            return 2;
 
208
        }
 
209
 
 
210
        QMirServer* mirServer = createQMirServer(argc, argv);
 
211
 
 
212
        typedef int (*runWithClient_t)(QMirServer*, std::function<int(int, const char**, void*)>);
 
213
        runWithClient_t runWithClient = (runWithClient_t) unityMir.resolve("runQMirServerWithClient");
 
214
        if (!runWithClient) {
 
215
            qDebug() << "unable to resolve symbol: runWithClient";
 
216
            return 3;
 
217
        }
 
218
 
 
219
        return runWithClient(mirServer, startShell);
 
220
    } else {
 
221
        return startShell(argc, argv, nullptr);
 
222
    }
 
223
}