on bionic help sign in
unity8/tools/indicatorsclient/indicatorsclient.cpp
83 lines 2.8 kB history raw
1/*
2 * Copyright 2013-2016 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Renato Araujo Oliveira Filho <renato@canonical.com>
18 * Nick Dedekind <nick.dedekind@canonical.com>
19 */
21#include "indicatorsclient.h"
23#include <paths.h>
25#include <QQuickView>
26#include <QQmlContext>
27#include <QQmlEngine>
28#include <QDebug>
29#include <QTranslator>
30#include <QLibraryInfo>
31#include <QLocale>
33IndicatorsClient::IndicatorsClient(int &argc, char **argv)
34 : QObject(0),
35 m_view(0)
37 m_application = new QApplication(argc, argv);
39 QTranslator qtTranslator;
40 if (qtTranslator.load(QLocale(), QStringLiteral("qt_"), qgetenv("SNAP"), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) {
41 m_application->installTranslator(&qtTranslator);
42 }
44 QStringList args = m_application->arguments();
46 m_view = new QQuickView;
47 m_view->engine()->setBaseUrl(QUrl::fromLocalFile(::qmlDirectory() + "/Panel/Indicators/client/"));
48 prependImportPaths(m_view->engine(), ::overrideImportPaths());
49 appendImportPaths(m_view->engine(), ::fallbackImportPaths());
51 QString profile = QStringLiteral("phone");
52 if (args.contains(QStringLiteral("-profile")) && args.size() > args.indexOf(QStringLiteral("-profile")) + 1) {
53 profile = args.at(args.indexOf(QStringLiteral("-profile")) + 1);
54 }
55 m_view->rootContext()->setContextProperty(QStringLiteral("indicatorProfile"), profile);
57 m_view->setSource(QUrl(QStringLiteral("IndicatorsClient.qml")));
58 m_view->setResizeMode(QQuickView::SizeRootObjectToView);
59 if (args.contains(QStringLiteral("-windowgeometry")) && args.size() > args.indexOf(QStringLiteral("-windowgeometry")) + 1) {
60 QStringList geometryArg = args.at(args.indexOf(QStringLiteral("-windowgeometry")) + 1).split('x');
61 if (geometryArg.size() == 2) {
62 m_view->resize(geometryArg.at(0).toInt(), geometryArg.at(1).toInt());
63 }
64 } else {
65 //Usable size on desktop
66 m_view->setMinimumSize(QSize(480, 720));
67 }
70IndicatorsClient::~IndicatorsClient()
72 if (m_view != 0) {
73 delete m_view;
74 }
76 delete m_application;
79int IndicatorsClient::run()
81 m_view->show();
82 return m_application->exec();