Merge lp:~kalikiana/ubuntu-ui-toolkit/appname into lp:ubuntu-ui-toolkit
- appname
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Zoltan Balogh |
Approved revision: | 713 |
Merged at revision: | 752 |
Proposed branch: | lp:~kalikiana/ubuntu-ui-toolkit/appname |
Merge into: | lp:ubuntu-ui-toolkit |
Diff against target: |
376 lines (+286/-0) 9 files modified
modules/Ubuntu/Components/MainView.qml (+5/-0) modules/Ubuntu/Components/plugin/plugin.cpp (+7/-0) modules/Ubuntu/Components/plugin/plugin.pro (+2/-0) modules/Ubuntu/Components/plugin/ucapplication.cpp (+57/-0) modules/Ubuntu/Components/plugin/ucapplication.h (+53/-0) tests/unit/tst_mainview/AppName.qml (+23/-0) tests/unit/tst_mainview/tst_mainview.cpp (+132/-0) tests/unit/tst_mainview/tst_mainview.pro (+6/-0) tests/unit/unit.pro (+1/-0) |
To merge this branch: | bzr merge lp:~kalikiana/ubuntu-ui-toolkit/appname |
Related bugs: |
|
Related blueprints: |
SDK: Application Data Folders
(Undefined)
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot | continuous-integration | Approve | |
Zsombor Egri | Approve | ||
Tim Peeters | Pending | ||
Review via email: mp+180601@code.launchpad.net |
Commit message
Set QCoreApplicatio
Description of the change
Antti Kaijanmäki (kaijanmaki) wrote : | # |
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:699
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:700
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:701
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Tim Peeters (tpeeters) wrote : | # |
why do you need applicationName in i18n? Is it really something different than domain, and can you not use only one variables that combines these two?
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:705
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
Tim Peeters (tpeeters) wrote : | # |
why do you need organizationName?
Cris Dywan (kalikiana) wrote : | # |
> why do you need organizationName?
As the code says: "// Unset organization to skip an extra folder component"
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:707
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:708
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
Zsombor Egri (zsombi) wrote : | # |
63 + qmlRegisterUncr
This is not needed. Pls remove.
Zsombor Egri (zsombi) wrote : | # |
35 + /* Set name and organization on Application which QStandardPaths
36 + honors to construct folders.
37 + This works across platforms. For confinement we rely on the fact
38 + that the folders are whitelisted based on the app name. Similar
39 + to how Unity uses it to distinguish running applications.
40 + */
41 + UbuntuApplicati
42 + // Unset organization to skip an extra folder component
43 + UbuntuApplicati
If we anyway set the organizationName to an empty string, shouldn't we do this in the UCApplication itself? Do we have to expose it? Or do you expect to use it at some point in QML?
Zsombor Egri (zsombi) wrote : | # |
Nice one! Have you ran unit tests on the device?
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:709
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
Cris Dywan (kalikiana) wrote : | # |
I'm not able to do anything with my device at the moment because it doesn't boot, so this is all tested on the desktop only, I'm still trying to figure out what the problem is.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:711
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
Zsombor Egri (zsombi) wrote : | # |
seems you have errors in documentation.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:712
http://
Executed test runs:
UNSTABLE: http://
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
UNSTABLE: http://
SUCCESS: http://
deb: http://
UNSTABLE: http://
UNSTABLE: http://
Click here to trigger a rebuild:
http://
Zsombor Egri (zsombi) wrote : | # |
Hold on, if I create a QSettings() object right after the application name is set, the path the setting file will be located will look as follows: ~/.config/
If I create it with QSetting("", UCApplication:
Seems the QCoreApplicatio
Cris Dywan (kalikiana) wrote : | # |
The problem is in QSettings using its own mechanism to build the path which diverges from the rest of Qt as far as I can say - so either we can find a way to override it or we need to patch it. All other APIs will add another folder level when setting an organizationName even if it's the app name.
Zsombor Egri (zsombi) wrote : | # |
OK, then let's forget about this. We will use QSetting with custom
constructor.
On Wed, Sep 18, 2013 at 7:09 PM, Christian Dywan <email address hidden>wrote:
> The problem is in QSettings using its own mechanism to build the path
> which diverges from the rest of Qt as far as I can say - so either we can
> find a way to override it or we need to patch it. All other APIs will add
> another folder level when setting an organizationName even if it's the app
> name.
> --
>
> https:/
> You are reviewing the proposed merge of
> lp:~kalikiana/ubuntu-ui-toolkit/appname into lp:ubuntu-ui-toolkit.
>
Zsombor Egri (zsombi) : | # |
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:712
http://
Executed test runs:
ABORTED: http://
FAILURE: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:712
http://
Executed test runs:
UNSTABLE: http://
ABORTED: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
UNSTABLE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
UNSTABLE: http://
ABORTED: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:712
http://
Executed test runs:
SUCCESS: http://
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
UNSTABLE: http://
UNSTABLE: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Autolanding.
More details in the following jenkins job:
http://
Executed test runs:
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
UNSTABLE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Autolanding.
More details in the following jenkins job:
http://
Executed test runs:
UNSTABLE: http://
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
UNSTABLE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
UNSTABLE: http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:713
http://
Executed test runs:
UNSTABLE: http://
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
UNSTABLE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
UNSTABLE: http://
UNSTABLE: http://
Click here to trigger a rebuild:
http://
Cris Dywan (kalikiana) wrote : | # |
Affected by bug 1229110
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Autolanding.
More details in the following jenkins job:
http://
Executed test runs:
UNSTABLE: http://
UNSTABLE: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
UNSTABLE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
UNSTABLE: http://
UNSTABLE: http://
PS Jenkins bot (ps-jenkins) : | # |
Preview Diff
1 | === modified file 'modules/Ubuntu/Components/MainView.qml' | |||
2 | --- modules/Ubuntu/Components/MainView.qml 2013-08-22 17:15:35 +0000 | |||
3 | +++ modules/Ubuntu/Components/MainView.qml 2013-09-23 08:32:16 +0000 | |||
4 | @@ -133,6 +133,10 @@ | |||
5 | 133 | \preliminary | 133 | \preliminary |
6 | 134 | The property holds the application's name, which must be the same as the | 134 | The property holds the application's name, which must be the same as the |
7 | 135 | desktop file's name. | 135 | desktop file's name. |
8 | 136 | The name also sets the name of the QCoreApplication and defaults for data | ||
9 | 137 | and cache folders that work on the desktop and under confinement. | ||
10 | 138 | C++ code that writes files may use QStandardPaths::writableLocation with | ||
11 | 139 | QStandardPaths::DataLocation or QStandardPaths::CacheLocation. | ||
12 | 136 | */ | 140 | */ |
13 | 137 | property string applicationName: "" | 141 | property string applicationName: "" |
14 | 138 | 142 | ||
15 | @@ -334,6 +338,7 @@ | |||
16 | 334 | onApplicationNameChanged: { | 338 | onApplicationNameChanged: { |
17 | 335 | if (applicationName !== "") { | 339 | if (applicationName !== "") { |
18 | 336 | i18n.domain = applicationName; | 340 | i18n.domain = applicationName; |
19 | 341 | UbuntuApplication.applicationName = applicationName | ||
20 | 337 | } | 342 | } |
21 | 338 | } | 343 | } |
22 | 339 | } | 344 | } |
23 | 340 | 345 | ||
24 | === modified file 'modules/Ubuntu/Components/plugin/plugin.cpp' | |||
25 | --- modules/Ubuntu/Components/plugin/plugin.cpp 2013-08-23 11:13:21 +0000 | |||
26 | +++ modules/Ubuntu/Components/plugin/plugin.cpp 2013-09-23 08:32:16 +0000 | |||
27 | @@ -42,6 +42,7 @@ | |||
28 | 42 | #include "ucfontutils.h" | 42 | #include "ucfontutils.h" |
29 | 43 | #include "ucarguments.h" | 43 | #include "ucarguments.h" |
30 | 44 | #include "ucargument.h" | 44 | #include "ucargument.h" |
31 | 45 | #include "ucapplication.h" | ||
32 | 45 | #include "ucalarm.h" | 46 | #include "ucalarm.h" |
33 | 46 | #include "ucalarmmodel.h" | 47 | #include "ucalarmmodel.h" |
34 | 47 | #include "unitythemeiconprovider.h" | 48 | #include "unitythemeiconprovider.h" |
35 | @@ -167,6 +168,12 @@ | |||
36 | 167 | QObject::connect(&UbuntuI18n::instance(), SIGNAL(languageChanged()), | 168 | QObject::connect(&UbuntuI18n::instance(), SIGNAL(languageChanged()), |
37 | 168 | &i18nChangeListener, SLOT(updateContextProperty())); | 169 | &i18nChangeListener, SLOT(updateContextProperty())); |
38 | 169 | 170 | ||
39 | 171 | // We can't use 'Application' because it exists (undocumented) | ||
40 | 172 | context->setContextProperty("UbuntuApplication", &UCApplication::instance()); | ||
41 | 173 | static ContextPropertyChangeListener applicationChangeListener(context, "UbuntuApplication"); | ||
42 | 174 | QObject::connect(&UCApplication::instance(), SIGNAL(applicationNameChanged()), | ||
43 | 175 | &applicationChangeListener, SLOT(updateContextProperty())); | ||
44 | 176 | |||
45 | 170 | context->setContextProperty("units", &UCUnits::instance()); | 177 | context->setContextProperty("units", &UCUnits::instance()); |
46 | 171 | static ContextPropertyChangeListener unitsChangeListener(context, "units"); | 178 | static ContextPropertyChangeListener unitsChangeListener(context, "units"); |
47 | 172 | QObject::connect(&UCUnits::instance(), SIGNAL(gridUnitChanged()), | 179 | QObject::connect(&UCUnits::instance(), SIGNAL(gridUnitChanged()), |
48 | 173 | 180 | ||
49 | === modified file 'modules/Ubuntu/Components/plugin/plugin.pro' | |||
50 | --- modules/Ubuntu/Components/plugin/plugin.pro 2013-08-28 14:07:46 +0000 | |||
51 | +++ modules/Ubuntu/Components/plugin/plugin.pro 2013-09-23 08:32:16 +0000 | |||
52 | @@ -40,6 +40,7 @@ | |||
53 | 40 | qquickclipboard_p.h \ | 40 | qquickclipboard_p.h \ |
54 | 41 | ucubuntuanimation.h \ | 41 | ucubuntuanimation.h \ |
55 | 42 | ucfontutils.h \ | 42 | ucfontutils.h \ |
56 | 43 | ucapplication.h \ | ||
57 | 43 | ucarguments.h \ | 44 | ucarguments.h \ |
58 | 44 | ucargument.h \ | 45 | ucargument.h \ |
59 | 45 | ucalarm.h \ | 46 | ucalarm.h \ |
60 | @@ -68,6 +69,7 @@ | |||
61 | 68 | qquickmimedata.cpp \ | 69 | qquickmimedata.cpp \ |
62 | 69 | ucubuntuanimation.cpp \ | 70 | ucubuntuanimation.cpp \ |
63 | 70 | ucfontutils.cpp \ | 71 | ucfontutils.cpp \ |
64 | 72 | ucapplication.cpp \ | ||
65 | 71 | ucarguments.cpp \ | 73 | ucarguments.cpp \ |
66 | 72 | ucargument.cpp \ | 74 | ucargument.cpp \ |
67 | 73 | ucalarm.cpp \ | 75 | ucalarm.cpp \ |
68 | 74 | 76 | ||
69 | === added file 'modules/Ubuntu/Components/plugin/ucapplication.cpp' | |||
70 | --- modules/Ubuntu/Components/plugin/ucapplication.cpp 1970-01-01 00:00:00 +0000 | |||
71 | +++ modules/Ubuntu/Components/plugin/ucapplication.cpp 2013-09-23 08:32:16 +0000 | |||
72 | @@ -0,0 +1,57 @@ | |||
73 | 1 | /* | ||
74 | 2 | * Copyright 2013 Canonical Ltd. | ||
75 | 3 | * | ||
76 | 4 | * This program is free software; you can redistribute it and/or modify | ||
77 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
78 | 6 | * the Free Software Foundation; version 3. | ||
79 | 7 | * | ||
80 | 8 | * This program is distributed in the hope that it will be useful, | ||
81 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
82 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
83 | 11 | * GNU Lesser General Public License for more details. | ||
84 | 12 | * | ||
85 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
86 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
87 | 15 | * | ||
88 | 16 | * Author: Christian Dywan <christian.dywan@canonical.om> | ||
89 | 17 | */ | ||
90 | 18 | |||
91 | 19 | #include "ucapplication.h" | ||
92 | 20 | |||
93 | 21 | #include <QtCore/QCoreApplication> | ||
94 | 22 | #include <QDebug> | ||
95 | 23 | |||
96 | 24 | /*! | ||
97 | 25 | * \qmltype UbuntuApplication | ||
98 | 26 | * \instantiates UCApplication | ||
99 | 27 | * \inqmlmodule Ubuntu.Components 0.1 | ||
100 | 28 | * \ingroup ubuntu | ||
101 | 29 | * \brief UbuntuApplication is a QML binding for a subset of QCoreApplication. | ||
102 | 30 | * | ||
103 | 31 | * UbuntuApplication is a context property in QML. | ||
104 | 32 | */ | ||
105 | 33 | UCApplication::UCApplication(QObject* parent) : QObject(parent) | ||
106 | 34 | { | ||
107 | 35 | } | ||
108 | 36 | |||
109 | 37 | /*! | ||
110 | 38 | * \qmlproperty string Application::applicationName | ||
111 | 39 | * \internal | ||
112 | 40 | * The name of the application, see QCoreApplication::applicationName | ||
113 | 41 | */ | ||
114 | 42 | QString UCApplication::applicationName() { | ||
115 | 43 | return QCoreApplication::applicationName(); | ||
116 | 44 | } | ||
117 | 45 | |||
118 | 46 | void UCApplication::setApplicationName(QString applicationName) { | ||
119 | 47 | /* QStandardPaths uses the name to build folder names. | ||
120 | 48 | This works across platforms. For confinement we rely on the fact | ||
121 | 49 | that the folders are whitelisted based on the app name. Similar | ||
122 | 50 | to how Unity uses it to distinguish running applications. | ||
123 | 51 | */ | ||
124 | 52 | QCoreApplication::setApplicationName(applicationName); | ||
125 | 53 | // Unset organization to skip an extra folder component | ||
126 | 54 | QCoreApplication::setOrganizationName(""); | ||
127 | 55 | Q_EMIT applicationNameChanged(); | ||
128 | 56 | } | ||
129 | 57 | |||
130 | 0 | 58 | ||
131 | === added file 'modules/Ubuntu/Components/plugin/ucapplication.h' | |||
132 | --- modules/Ubuntu/Components/plugin/ucapplication.h 1970-01-01 00:00:00 +0000 | |||
133 | +++ modules/Ubuntu/Components/plugin/ucapplication.h 2013-09-23 08:32:16 +0000 | |||
134 | @@ -0,0 +1,53 @@ | |||
135 | 1 | /* | ||
136 | 2 | * Copyright 2013 Canonical Ltd. | ||
137 | 3 | * | ||
138 | 4 | * This program is free software; you can redistribute it and/or modify | ||
139 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
140 | 6 | * the Free Software Foundation; version 3. | ||
141 | 7 | * | ||
142 | 8 | * This program is distributed in the hope that it will be useful, | ||
143 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
144 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
145 | 11 | * GNU Lesser General Public License for more details. | ||
146 | 12 | * | ||
147 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
148 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
149 | 15 | * | ||
150 | 16 | * Author: Christian Dywan <christian.dywan@canonical.om> | ||
151 | 17 | */ | ||
152 | 18 | |||
153 | 19 | #ifndef UBUNTU_COMPONENTS_APPLICATION_H | ||
154 | 20 | #define UBUNTU_COMPONENTS_APPLICATION_H | ||
155 | 21 | |||
156 | 22 | #include <QtCore/QObject> | ||
157 | 23 | |||
158 | 24 | class QQmlContext; | ||
159 | 25 | class QQmlEngine; | ||
160 | 26 | |||
161 | 27 | class UCApplication : public QObject | ||
162 | 28 | { | ||
163 | 29 | Q_OBJECT | ||
164 | 30 | Q_PROPERTY(QString applicationName READ applicationName WRITE setApplicationName NOTIFY applicationNameChanged) | ||
165 | 31 | |||
166 | 32 | private: | ||
167 | 33 | Q_DISABLE_COPY(UCApplication) | ||
168 | 34 | explicit UCApplication(QObject* parent = 0); | ||
169 | 35 | |||
170 | 36 | |||
171 | 37 | public: | ||
172 | 38 | static UCApplication& instance() { | ||
173 | 39 | static UCApplication instance; | ||
174 | 40 | return instance; | ||
175 | 41 | } | ||
176 | 42 | |||
177 | 43 | // getter | ||
178 | 44 | QString applicationName(); | ||
179 | 45 | |||
180 | 46 | // setter | ||
181 | 47 | void setApplicationName(QString applicationName); | ||
182 | 48 | |||
183 | 49 | Q_SIGNALS: | ||
184 | 50 | void applicationNameChanged(); | ||
185 | 51 | }; | ||
186 | 52 | |||
187 | 53 | #endif // UBUNTU_COMPONENTS_I18N_H | ||
188 | 0 | 54 | ||
189 | === added directory 'tests/unit/tst_mainview' | |||
190 | === added file 'tests/unit/tst_mainview/AppName.qml' | |||
191 | --- tests/unit/tst_mainview/AppName.qml 1970-01-01 00:00:00 +0000 | |||
192 | +++ tests/unit/tst_mainview/AppName.qml 2013-09-23 08:32:16 +0000 | |||
193 | @@ -0,0 +1,23 @@ | |||
194 | 1 | /* | ||
195 | 2 | * Copyright 2013 Canonical Ltd. | ||
196 | 3 | * | ||
197 | 4 | * This program is free software; you can redistribute it and/or modify | ||
198 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
199 | 6 | * the Free Software Foundation; version 3. | ||
200 | 7 | * | ||
201 | 8 | * This program is distributed in the hope that it will be useful, | ||
202 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
203 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
204 | 11 | * GNU Lesser General Public License for more details. | ||
205 | 12 | * | ||
206 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
207 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
208 | 15 | */ | ||
209 | 16 | |||
210 | 17 | import QtQuick 2.0 | ||
211 | 18 | import Ubuntu.Components 0.1 | ||
212 | 19 | |||
213 | 20 | MainView { | ||
214 | 21 | objectName: "appName" | ||
215 | 22 | applicationName: "org.gnu.wildebeest" | ||
216 | 23 | } | ||
217 | 0 | 24 | ||
218 | === added file 'tests/unit/tst_mainview/tst_mainview.cpp' | |||
219 | --- tests/unit/tst_mainview/tst_mainview.cpp 1970-01-01 00:00:00 +0000 | |||
220 | +++ tests/unit/tst_mainview/tst_mainview.cpp 2013-09-23 08:32:16 +0000 | |||
221 | @@ -0,0 +1,132 @@ | |||
222 | 1 | /* | ||
223 | 2 | * Copyright 2012-2013 Canonical Ltd. | ||
224 | 3 | * | ||
225 | 4 | * This program is free software; you can redistribute it and/or modify | ||
226 | 5 | * it under the terms of the GNU Lesser General Public License as published by | ||
227 | 6 | * the Free Software Foundation; version 3. | ||
228 | 7 | * | ||
229 | 8 | * This program is distributed in the hope that it will be useful, | ||
230 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
231 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
232 | 11 | * GNU Lesser General Public License for more details. | ||
233 | 12 | * | ||
234 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
235 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
236 | 15 | * | ||
237 | 16 | * Author: Christian Dywan <christian.dywan@canonical.com> | ||
238 | 17 | */ | ||
239 | 18 | |||
240 | 19 | #include <QtCore/QString> | ||
241 | 20 | #include <QtCore/QTextCodec> | ||
242 | 21 | #include <QtCore/QStandardPaths> | ||
243 | 22 | #include <QtCore/QProcessEnvironment> | ||
244 | 23 | #include <QtCore/QDebug> | ||
245 | 24 | #include <QtTest/QTest> | ||
246 | 25 | #include <QtTest/QSignalSpy> | ||
247 | 26 | #include <QtCore/QCoreApplication> | ||
248 | 27 | #include <QtQml/QQmlEngine> | ||
249 | 28 | #include <QtQuick/QQuickView> | ||
250 | 29 | #include <QtQuick/QQuickItem> | ||
251 | 30 | #include <QtCore/QThread> | ||
252 | 31 | #include <QtCore/QFileInfo> | ||
253 | 32 | #include <QtCore/QDir> | ||
254 | 33 | |||
255 | 34 | #include "ucapplication.h" | ||
256 | 35 | #include "ucunits.h" | ||
257 | 36 | |||
258 | 37 | class tst_MainView : public QObject | ||
259 | 38 | { | ||
260 | 39 | Q_OBJECT | ||
261 | 40 | |||
262 | 41 | private: | ||
263 | 42 | QQuickView *view; | ||
264 | 43 | |||
265 | 44 | public: | ||
266 | 45 | tst_MainView() : | ||
267 | 46 | view(0) | ||
268 | 47 | { | ||
269 | 48 | } | ||
270 | 49 | |||
271 | 50 | QQuickItem *loadTest(const QString &document) | ||
272 | 51 | { | ||
273 | 52 | // load the document | ||
274 | 53 | view->setSource(QUrl::fromLocalFile(document)); | ||
275 | 54 | QTest::waitForEvents(); | ||
276 | 55 | |||
277 | 56 | return view->rootObject(); | ||
278 | 57 | } | ||
279 | 58 | |||
280 | 59 | QQuickItem *testItem(QQuickItem *that, const QString &identifier) | ||
281 | 60 | { | ||
282 | 61 | if (that->property(identifier.toLocal8Bit()).isValid()) | ||
283 | 62 | return that->property(identifier.toLocal8Bit()).value<QQuickItem*>(); | ||
284 | 63 | |||
285 | 64 | QList<QQuickItem*> children = that->findChildren<QQuickItem*>(identifier); | ||
286 | 65 | return (children.count() > 0) ? children[0] : 0; | ||
287 | 66 | } | ||
288 | 67 | |||
289 | 68 | private Q_SLOTS: | ||
290 | 69 | |||
291 | 70 | void initTestCase() | ||
292 | 71 | { | ||
293 | 72 | QString modules("../../../modules"); | ||
294 | 73 | QVERIFY(QDir(modules).exists()); | ||
295 | 74 | |||
296 | 75 | view = new QQuickView; | ||
297 | 76 | QQmlEngine *quickEngine = view->engine(); | ||
298 | 77 | |||
299 | 78 | view->setGeometry(0,0, UCUnits::instance().gu(40), UCUnits::instance().gu(30)); | ||
300 | 79 | //add modules folder so we have access to the plugin from QML | ||
301 | 80 | QStringList imports = quickEngine->importPathList(); | ||
302 | 81 | imports.prepend(QDir(modules).absolutePath()); | ||
303 | 82 | quickEngine->setImportPathList(imports); | ||
304 | 83 | } | ||
305 | 84 | |||
306 | 85 | void cleanupTestCase() | ||
307 | 86 | { | ||
308 | 87 | delete view; | ||
309 | 88 | } | ||
310 | 89 | |||
311 | 90 | void testCase_AppName() | ||
312 | 91 | { | ||
313 | 92 | QQuickItem *root = loadTest("AppName.qml"); | ||
314 | 93 | QVERIFY(root); | ||
315 | 94 | QQuickItem *mainView = root; | ||
316 | 95 | QString applicationName(mainView->property("applicationName").toString()); | ||
317 | 96 | QCOMPARE(applicationName, QString("org.gnu.wildebeest")); | ||
318 | 97 | QCOMPARE(applicationName, QCoreApplication::applicationName()); | ||
319 | 98 | QCOMPARE(QString(""), QCoreApplication::organizationName()); | ||
320 | 99 | } | ||
321 | 100 | |||
322 | 101 | void testSetApplicationName() { | ||
323 | 102 | QString appName("com.ubuntu.foo"); | ||
324 | 103 | UCApplication::instance().setApplicationName(appName); | ||
325 | 104 | QCOMPARE(UCApplication::instance().applicationName(), appName); | ||
326 | 105 | QCOMPARE(QCoreApplication::applicationName(), appName); | ||
327 | 106 | QCOMPARE(QString(""), QCoreApplication::organizationName()); | ||
328 | 107 | } | ||
329 | 108 | |||
330 | 109 | void testExpectedDataFolder() { | ||
331 | 110 | QString appName("net.weight.gain"); | ||
332 | 111 | UCApplication::instance().setApplicationName(appName); | ||
333 | 112 | QString dataFolder(QStandardPaths::writableLocation(QStandardPaths::DataLocation)); | ||
334 | 113 | QString xdgDataHome(QProcessEnvironment::systemEnvironment().value("XDG_DATA_HOME", | ||
335 | 114 | QProcessEnvironment::systemEnvironment().value("HOME") + "/.local/share")); | ||
336 | 115 | QString expectedDataFolder(xdgDataHome + "/" + appName); | ||
337 | 116 | QCOMPARE(dataFolder, expectedDataFolder); | ||
338 | 117 | } | ||
339 | 118 | |||
340 | 119 | void testExpectedCacheFolder() { | ||
341 | 120 | QString appName("cat.long.very"); | ||
342 | 121 | UCApplication::instance().setApplicationName(appName); | ||
343 | 122 | QString cacheFolder(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)); | ||
344 | 123 | QString xdgCacheHome(QProcessEnvironment::systemEnvironment().value("XDG_CACHE_HOME", | ||
345 | 124 | QProcessEnvironment::systemEnvironment().value("HOME") + "/.cache")); | ||
346 | 125 | QString expectedCacheFolder(xdgCacheHome + "/" + appName); | ||
347 | 126 | QCOMPARE(cacheFolder, expectedCacheFolder); | ||
348 | 127 | } | ||
349 | 128 | }; | ||
350 | 129 | |||
351 | 130 | QTEST_MAIN(tst_MainView) | ||
352 | 131 | |||
353 | 132 | #include "tst_mainview.moc" | ||
354 | 0 | 133 | ||
355 | === added file 'tests/unit/tst_mainview/tst_mainview.pro' | |||
356 | --- tests/unit/tst_mainview/tst_mainview.pro 1970-01-01 00:00:00 +0000 | |||
357 | +++ tests/unit/tst_mainview/tst_mainview.pro 2013-09-23 08:32:16 +0000 | |||
358 | @@ -0,0 +1,6 @@ | |||
359 | 1 | include(../test-include.pri) | ||
360 | 2 | |||
361 | 3 | QT += gui | ||
362 | 4 | SOURCES += tst_mainview.cpp | ||
363 | 5 | |||
364 | 6 | OTHER_FILES += $$system(ls tst_*.qml) | ||
365 | 0 | 7 | ||
366 | === modified file 'tests/unit/unit.pro' | |||
367 | --- tests/unit/unit.pro 2013-08-28 09:49:02 +0000 | |||
368 | +++ tests/unit/unit.pro 2013-09-23 08:32:16 +0000 | |||
369 | @@ -20,6 +20,7 @@ | |||
370 | 20 | tst_qquick_image_extension \ | 20 | tst_qquick_image_extension \ |
371 | 21 | tst_performance \ | 21 | tst_performance \ |
372 | 22 | tst_ubuntu_shape \ | 22 | tst_ubuntu_shape \ |
373 | 23 | tst_mainview \ | ||
374 | 23 | tst_arguments \ | 24 | tst_arguments \ |
375 | 24 | tst_argument \ | 25 | tst_argument \ |
376 | 25 | tst_layouts \ | 26 | tst_layouts \ |
Should this be ApplicationIden tifier in our API? AFAIK we are using $APP_ID and "Application Identifier" in our docs and discussion.