on fa379ff help sign in
unity8/tools/scopetool.cpp
105 lines 3.7 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"
37int main(int argc, char *argv[])
39 /* Workaround Qt platform integration plugin not advertising itself
40 as having the following capabilities:
41 - QPlatformIntegration::ThreadedOpenGL
42 - QPlatformIntegration::BufferQueueingOpenGL
43 */
44 setenv("QML_FORCE_THREADED_RENDERER", "1", 1);
45 setenv("QML_FIXED_ANIMATION_STEP", "1", 1);
47 // ignore favorites in unity-scopes-shell plugin
48 setenv("UNITY_SCOPES_NO_FAVORITES", "1", 1);
50 QGuiApplication::setApplicationName("Unity Scope Tool");
51 QGuiApplication *application;
52 application = new QGuiApplication(argc, argv);
54 QCommandLineParser parser;
55 parser.setApplicationDescription("Unity Scope Tool\n\n"
56 "This tool allows development and testing of scopes. Running it without\n"
57 "any arguments will open a session to all scopes available on the system.\n"
58 "Otherwise passing a path to a scope config file will open a session with\n"
59 "only that scope (assuming that the binary implementing the scope can be\n"
60 "found in the same directory as the config file).");
61 parser.addHelpOption();
62 parser.addPositionalArgument("scopes", "Paths to scope config files to spawn, optionally.", "[scopes...]");
64 QCommandLineOption includeSystemScopes("include-system-scopes",
65 "Initialize the registry with scopes installed on this system");
66 QCommandLineOption includeServerScopes("include-server-scopes",
67 "Initialize the registry with scopes on the default server");
69 parser.addOption(includeServerScopes);
70 parser.addOption(includeSystemScopes);
72 parser.process(*application);
74 QStringList extraScopes = parser.positionalArguments();
76 QScopedPointer<RegistryTracker> tracker;
77 if (!extraScopes.isEmpty()) {
78 bool systemScopes = parser.isSet(includeSystemScopes);
79 bool serverScopes = parser.isSet(includeServerScopes);
80 tracker.reset(new RegistryTracker(extraScopes, systemScopes, serverScopes));
81 }
83 bindtextdomain("unity8", translationDirectory().toUtf8().data());
85 QQuickView* view = new QQuickView();
86 view->setResizeMode(QQuickView::SizeRootObjectToView);
87 view->setTitle(QGuiApplication::applicationName());
88 view->engine()->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory()));
90 QUrl source(::qmlDirectory() + "ScopeTool.qml");
91 prependImportPaths(view->engine(), ::overrideImportPaths());
92 prependImportPaths(view->engine(), ::nonMirImportPaths());
93 appendImportPaths(view->engine(), ::fallbackImportPaths());
95 view->setSource(source);
97 view->show();
99 int result = application->exec();
101 delete view;
102 delete application;
104 return result;