on de040db help sign in
unity8/tools/scopetool.cpp
112 lines 3.9 kB history raw
1/*
2 * Copyright (C) 2012 Canonical, Ltd.
3 *
4 * Authors:
5 * Gerry Boland <gerry.boland@canonical.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
20// Qt
21#include <QtQuick/QQuickView>
22#include <QtGui/QGuiApplication>
23#include <QtQml/QQmlEngine>
24#include <QtQml/QQmlContext>
25#include <QScopedPointer>
26#include <QDebug>
27#include <QCommandLineParser>
28#include <QCommandLineOption>
29#include <libintl.h>
32// local
33#include <paths.h>
34#include "registry-tracker.h"
35#include "unix-signal-handler.h"
38int main(int argc, char *argv[])
40 /* Workaround Qt platform integration plugin not advertising itself
41 as having the following capabilities:
42 - QPlatformIntegration::ThreadedOpenGL
43 - QPlatformIntegration::BufferQueueingOpenGL
44 */
45 setenv("QML_FORCE_THREADED_RENDERER", "1", 1);
46 setenv("QML_FIXED_ANIMATION_STEP", "1", 1);
48 // ignore favorites in unity-scopes-shell plugin
49 setenv("UNITY_SCOPES_NO_FAVORITES", "1", 1);
51 QGuiApplication::setApplicationName("Unity Scope Tool");
52 QGuiApplication *application;
53 application = new QGuiApplication(argc, argv);
55 QCommandLineParser parser;
56 parser.setApplicationDescription("Unity Scope Tool\n\n"
57 "This tool allows development and testing of scopes. Running it without\n"
58 "any arguments will open a session to all scopes available on the system.\n"
59 "Otherwise passing a path to a scope config file will open a session with\n"
60 "only that scope (assuming that the binary implementing the scope can be\n"
61 "found in the same directory as the config file).");
62 parser.addHelpOption();
63 parser.addPositionalArgument("scopes", "Paths to scope config files to spawn, optionally.", "[scopes...]");
65 QCommandLineOption includeSystemScopes("include-system-scopes",
66 "Initialize the registry with scopes installed on this system");
67 QCommandLineOption includeServerScopes("include-server-scopes",
68 "Initialize the registry with scopes on the default server");
70 parser.addOption(includeServerScopes);
71 parser.addOption(includeSystemScopes);
73 parser.process(*application);
75 QStringList extraScopes = parser.positionalArguments();
77 QScopedPointer<RegistryTracker> tracker;
78 if (!extraScopes.isEmpty()) {
79 bool systemScopes = parser.isSet(includeSystemScopes);
80 bool serverScopes = parser.isSet(includeServerScopes);
81 tracker.reset(new RegistryTracker(extraScopes, systemScopes, serverScopes));
82 }
84 bindtextdomain("unity8", translationDirectory().toUtf8().data());
85 textdomain("unity8");
87 QQuickView* view = new QQuickView();
88 view->setResizeMode(QQuickView::SizeRootObjectToView);
89 view->setTitle(QGuiApplication::applicationName());
90 view->engine()->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
92 QUrl source(::qmlDirectory() + "/ScopeTool.qml");
93 prependImportPaths(view->engine(), ::overrideImportPaths());
94 prependImportPaths(view->engine(), ::nonMirImportPaths());
95 appendImportPaths(view->engine(), ::fallbackImportPaths());
97 view->setSource(source);
99 view->show();
101 UnixSignalHandler signal_handler([]{
102 QGuiApplication::exit(0);
103 });
104 signal_handler.setupUnixSignalHandlers();
106 int result = application->exec();
108 delete view;
109 delete application;
111 return result;