2
* Copyright 2013 Canonical Ltd.
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.
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.
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/>.
16
* Author: Christian Dywan <christian.dywan@canonical.om>
19
#include "ucapplication.h"
21
#include <QtCore/QCoreApplication>
23
#include <QtQml/QQmlContext>
24
#include <QtQml/QQmlEngine>
25
#include <QtCore/QStandardPaths>
26
#include <QtGui/QGuiApplication>
29
* \qmltype UbuntuApplication
30
* \instantiates UCApplication
31
* \inqmlmodule Ubuntu.Components 1.1
33
* \brief UbuntuApplication is a QML binding for a subset of QCoreApplication.
35
* UbuntuApplication is a context property in QML.
37
UCApplication::UCApplication(QObject* parent) : QObject(parent), m_context(0)
38
, m_inputMethod(QGuiApplication::inputMethod())
40
// Make sure we receive application name changes from C++ modules
41
connect(QCoreApplication::instance(), &QCoreApplication::applicationNameChanged,
42
this, &UCApplication::applicationNameChanged);
45
void UCApplication::setContext(QQmlContext* context) {
51
* The name of the application, see QCoreApplication::applicationName
53
QString UCApplication::applicationName() {
54
return QCoreApplication::applicationName();
57
void UCApplication::setApplicationName(const QString& applicationName) {
58
/* QStandardPaths uses the name to build folder names.
59
This works across platforms. For confinement we rely on the fact
60
that the folders are whitelisted based on the app name. Similar
61
to how Unity uses it to distinguish running applications.
63
QCoreApplication::setApplicationName(applicationName);
64
// Unset organization to skip an extra folder component
65
QCoreApplication::setOrganizationName(QString());
67
Ensure that LocalStorage and WebKit use the same location
68
Docs are ambiguous: in practise applicationName is ignored by default
70
QQmlEngine* engine(m_context->engine());
71
QString dataFolder(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
72
engine->setOfflineStoragePath(dataFolder);
73
// Get Qtlabs.settings to use a sane path
74
QCoreApplication::setOrganizationDomain(applicationName);
79
* The global input method. Can be overridden for testing.
81
QObject* UCApplication::inputMethod() {
85
void UCApplication::setInputMethod(QObject* inputMethod) {
86
m_inputMethod = inputMethod;