Merge lp:unity-scopes-shell/rtm-14.09 into lp:unity-scopes-shell
- rtm-14.09
- Merge into trunk
Proposed by
Pete Woods
Status: | Merged |
---|---|
Approved by: | Pete Woods |
Approved revision: | 127 |
Merged at revision: | 125 |
Proposed branch: | lp:unity-scopes-shell/rtm-14.09 |
Merge into: | lp:unity-scopes-shell |
Diff against target: |
707 lines (+330/-62) 16 files modified
debian/changelog (+12/-0) debian/control (+1/-2) src/Unity/CMakeLists.txt (+1/-2) src/Unity/collectors.cpp (+52/-12) src/Unity/collectors.h (+1/-1) src/Unity/scope.cpp (+26/-7) src/Unity/scope.h (+2/-0) src/Unity/settingsmodel.cpp (+48/-27) src/Unity/settingsmodel.h (+13/-8) tests/CMakeLists.txt (+1/-1) tests/data/CMakeLists.txt (+1/-0) tests/data/mock-scope-info/CMakeLists.txt (+15/-0) tests/data/mock-scope-info/mock-scope-info.cpp (+121/-0) tests/data/mock-scope-info/mock-scope-info.ini.in (+5/-0) tests/registry-spawner.h (+1/-1) tests/resultstest.cpp (+30/-1) |
To merge this branch: | bzr merge lp:unity-scopes-shell/rtm-14.09 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Unity Team | Pending | ||
Review via email: mp+231341@code.launchpad.net |
Commit message
Sync with RTM
Description of the change
Sync with RTM
To post a comment you must log in.
lp:unity-scopes-shell/rtm-14.09
updated
- 128. By Pete Woods
-
Bump the version number
- 129. By Pete Woods
-
Hide the RTM release
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'debian/changelog' |
2 | --- debian/changelog 2014-08-06 19:44:56 +0000 |
3 | +++ debian/changelog 2014-08-20 14:26:16 +0000 |
4 | @@ -1,3 +1,15 @@ |
5 | +unity-scopes-shell (0.5.4-0ubuntu1) UNRELEASED; urgency=medium |
6 | + |
7 | + [ Pete Woods ] |
8 | + * Switch to QSettings, removing U1DB dependencies Support new location |
9 | + setting. |
10 | + |
11 | + [ Marcus Tomlinson ] |
12 | + * Added support for ScopeInterface::Status::NoInternet and |
13 | + NoLocationData completion statuses |
14 | + |
15 | + -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Mon, 18 Aug 2014 18:41:35 +0000 |
16 | + |
17 | unity-scopes-shell (0.5.3+14.10.20140806-0ubuntu1) utopic; urgency=medium |
18 | |
19 | [ Michal Hruby ] |
20 | |
21 | === modified file 'debian/control' |
22 | --- debian/control 2014-08-05 09:35:00 +0000 |
23 | +++ debian/control 2014-08-20 14:26:16 +0000 |
24 | @@ -4,11 +4,10 @@ |
25 | Build-Depends: cmake, |
26 | debhelper (>= 9), |
27 | libunity-api-dev (>= 7.88), |
28 | - libunity-scopes-dev (>= 0.6.0~), |
29 | + libunity-scopes-dev (>= 0.6.2~), |
30 | libgsettings-qt-dev (>= 0.1), |
31 | libqtdbustest1-dev (>= 0.2), |
32 | libqtdbusmock1-dev (>= 0.2), |
33 | - libu1db-qt5-dev, |
34 | libubuntu-location-service-dev (>= 2.0.1), |
35 | pkg-config, |
36 | python-tornado, |
37 | |
38 | === modified file 'src/Unity/CMakeLists.txt' |
39 | --- src/Unity/CMakeLists.txt 2014-08-05 09:35:00 +0000 |
40 | +++ src/Unity/CMakeLists.txt 2014-08-20 14:26:16 +0000 |
41 | @@ -3,9 +3,8 @@ |
42 | |
43 | # Dependencies |
44 | pkg_check_modules(SCOPES_API REQUIRED unity-shell-scopes=4) |
45 | -pkg_check_modules(SCOPESLIB REQUIRED libunity-scopes>=0.6.0) |
46 | +pkg_check_modules(SCOPESLIB REQUIRED libunity-scopes>=0.6.2) |
47 | pkg_check_modules(GSETTINGSQT REQUIRED gsettings-qt) |
48 | -pkg_check_modules(U1DB REQUIRED libu1db-qt5) |
49 | pkg_check_modules(UBUNTU_LOCATION_SERVICE REQUIRED ubuntu-location-service) |
50 | |
51 | include_directories( |
52 | |
53 | === modified file 'src/Unity/collectors.cpp' |
54 | --- src/Unity/collectors.cpp 2014-08-05 09:35:00 +0000 |
55 | +++ src/Unity/collectors.cpp 2014-08-20 14:26:16 +0000 |
56 | @@ -39,6 +39,55 @@ |
57 | |
58 | const QEvent::Type PushEvent::eventType = static_cast<QEvent::Type>(QEvent::registerEventType()); |
59 | |
60 | +namespace |
61 | +{ |
62 | + |
63 | +CollectorBase::Status getStatus(scopes::CompletionDetails const& details) |
64 | +{ |
65 | + // Gather info from the completion details |
66 | + bool no_internet = false; |
67 | + bool no_location_data = false; |
68 | + bool unknown = false; |
69 | + for (auto const& info : details.info_list()) |
70 | + { |
71 | + switch (info.code()) |
72 | + { |
73 | + case scopes::OperationInfo::NoInternet: |
74 | + no_internet = true; |
75 | + break; |
76 | + case scopes::OperationInfo::NoLocationData: |
77 | + no_location_data = true; |
78 | + break; |
79 | + case scopes::OperationInfo::Unknown: |
80 | + unknown = true; |
81 | + break; |
82 | + default: |
83 | + break; |
84 | + } |
85 | + } |
86 | + |
87 | + // Return status (in order of priority) |
88 | + if (no_internet) |
89 | + { |
90 | + return CollectorBase::Status::NO_INTERNET; |
91 | + } |
92 | + else if (no_location_data) |
93 | + { |
94 | + return CollectorBase::Status::NO_LOCATION_DATA; |
95 | + } |
96 | + else if (unknown) |
97 | + { |
98 | + return CollectorBase::Status::UNKNOWN; |
99 | + } |
100 | + else if (details.status() == scopes::CompletionDetails::Cancelled) |
101 | + { |
102 | + return CollectorBase::Status::CANCELLED; |
103 | + } |
104 | + return CollectorBase::Status::FINISHED; |
105 | +} |
106 | + |
107 | +} |
108 | + |
109 | CollectorBase::CollectorBase(): m_status(Status::INCOMPLETE), m_posted(false) |
110 | { |
111 | m_timer.start(); |
112 | @@ -324,10 +373,7 @@ |
113 | // this might be called from any thread (might be main, might be any other thread) |
114 | void SearchResultReceiver::finished(scopes::CompletionDetails const& details) |
115 | { |
116 | - CollectorBase::Status status = details.status() == scopes::CompletionDetails::CompletionStatus::Cancelled ? |
117 | - CollectorBase::Status::CANCELLED : CollectorBase::Status::FINISHED; |
118 | - |
119 | - postCollectedResults(status); |
120 | + postCollectedResults(getStatus(details)); |
121 | } |
122 | |
123 | PreviewDataReceiver::PreviewDataReceiver(QObject* receiver): |
124 | @@ -364,10 +410,7 @@ |
125 | // this might be called from any thread (might be main, might be any other thread) |
126 | void PreviewDataReceiver::finished(scopes::CompletionDetails const& details) |
127 | { |
128 | - CollectorBase::Status status = details.status() == scopes::CompletionDetails::CompletionStatus::Cancelled ? |
129 | - CollectorBase::Status::CANCELLED : CollectorBase::Status::FINISHED; |
130 | - |
131 | - postCollectedResults(status); |
132 | + postCollectedResults(getStatus(details)); |
133 | } |
134 | |
135 | void ActivationReceiver::activated(scopes::ActivationResponse const& response) |
136 | @@ -377,10 +420,7 @@ |
137 | |
138 | void ActivationReceiver::finished(scopes::CompletionDetails const& details) |
139 | { |
140 | - CollectorBase::Status status = details.status() == scopes::CompletionDetails::CompletionStatus::Cancelled ? |
141 | - CollectorBase::Status::CANCELLED : CollectorBase::Status::FINISHED; |
142 | - |
143 | - postCollectedResults(status); |
144 | + postCollectedResults(getStatus(details)); |
145 | } |
146 | |
147 | ActivationReceiver::ActivationReceiver(QObject* receiver, std::shared_ptr<scopes::Result> const& result): |
148 | |
149 | === modified file 'src/Unity/collectors.h' |
150 | --- src/Unity/collectors.h 2014-08-05 09:35:00 +0000 |
151 | +++ src/Unity/collectors.h 2014-08-20 14:26:16 +0000 |
152 | @@ -47,7 +47,7 @@ |
153 | class CollectorBase |
154 | { |
155 | public: |
156 | - enum Status { INCOMPLETE, FINISHED, CANCELLED }; |
157 | + enum Status { UNKNOWN, INCOMPLETE, FINISHED, CANCELLED, NO_INTERNET, NO_LOCATION_DATA }; |
158 | |
159 | CollectorBase(); |
160 | virtual ~CollectorBase(); |
161 | |
162 | === modified file 'src/Unity/scope.cpp' |
163 | --- src/Unity/scope.cpp 2014-08-06 08:35:20 +0000 |
164 | +++ src/Unity/scope.cpp 2014-08-20 14:26:16 +0000 |
165 | @@ -134,7 +134,21 @@ |
166 | flushUpdates(); |
167 | |
168 | setSearchInProgress(false); |
169 | - setStatus(status == CollectorBase::Status::FINISHED ? Status::Okay : Status::Unknown); |
170 | + |
171 | + switch (status) { |
172 | + case CollectorBase::Status::FINISHED: |
173 | + case CollectorBase::Status::CANCELLED: |
174 | + setStatus(Status::Okay); |
175 | + break; |
176 | + case CollectorBase::Status::NO_INTERNET: |
177 | + setStatus(Status::NoInternet); |
178 | + break; |
179 | + case CollectorBase::Status::NO_LOCATION_DATA: |
180 | + setStatus(Status::NoLocationData); |
181 | + break; |
182 | + default: |
183 | + setStatus(Status::Unknown); |
184 | + } |
185 | |
186 | // Don't schedule a refresh if the query suffered an error |
187 | if (status == CollectorBase::Status::FINISHED) { |
188 | @@ -617,15 +631,20 @@ |
189 | } |
190 | } |
191 | try { |
192 | - // TODO Verify that the scope is allowed to access the location data |
193 | - if (m_scopeMetadata && m_scopeMetadata->location_data_needed()) |
194 | + if (m_settingsModel && m_scopeMetadata && m_scopeMetadata->location_data_needed()) |
195 | { |
196 | - meta.set_location(m_locationService->location()); |
197 | + QVariant locationEnabled = m_settingsModel->value("internal.location"); |
198 | + if (locationEnabled.type() == QVariant::Bool && locationEnabled.toBool()) |
199 | + { |
200 | + meta.set_location(m_locationService->location()); |
201 | + } |
202 | } |
203 | } |
204 | catch (std::domain_error& e) |
205 | { |
206 | } |
207 | + meta.set_internet_connectivity(m_network_manager.isOnline() ? scopes::SearchMetadata::Connected : scopes::SearchMetadata::Disconnected); |
208 | + |
209 | scopes::SearchListenerBase::SPtr listener(new SearchResultReceiver(this)); |
210 | m_searchController->setListener(listener); |
211 | try { |
212 | @@ -658,13 +677,13 @@ |
213 | scopes::Variant settings_definitions; |
214 | settings_definitions = m_scopeMetadata->settings_definitions(); |
215 | QDir shareDir; |
216 | - if(qEnvironmentVariableIsSet("UNITY_SCOPES_SETTINGS_DIR")) |
217 | + if(qEnvironmentVariableIsSet("UNITY_SCOPES_CONFIG_DIR")) |
218 | { |
219 | - shareDir = qgetenv("UNITY_SCOPES_SETTINGS_DIR"); |
220 | + shareDir = qgetenv("UNITY_SCOPES_CONFIG_DIR"); |
221 | } |
222 | else |
223 | { |
224 | - shareDir = QDir::home().filePath(".local/share"); |
225 | + shareDir = QDir::home().filePath(".config/unity-scopes"); |
226 | } |
227 | |
228 | m_settingsModel.reset( |
229 | |
230 | === modified file 'src/Unity/scope.h' |
231 | --- src/Unity/scope.h 2014-08-04 16:27:17 +0000 |
232 | +++ src/Unity/scope.h 2014-08-20 14:26:16 +0000 |
233 | @@ -26,6 +26,7 @@ |
234 | #include <QTimer> |
235 | #include <QMetaType> |
236 | #include <QMetaObject> |
237 | +#include <QNetworkConfigurationManager> |
238 | #include <QPointer> |
239 | #include <QMultiMap> |
240 | #include <QSet> |
241 | @@ -233,6 +234,7 @@ |
242 | QMap<Department*, QString> m_inverseDepartments; |
243 | QMetaObject::Connection m_metadataConnection; |
244 | LocationService::Ptr m_locationService; |
245 | + QNetworkConfigurationManager m_network_manager; |
246 | }; |
247 | |
248 | } // namespace scopes_ng |
249 | |
250 | === modified file 'src/Unity/settingsmodel.cpp' |
251 | --- src/Unity/settingsmodel.cpp 2014-08-05 16:24:32 +0000 |
252 | +++ src/Unity/settingsmodel.cpp 2014-08-20 14:26:16 +0000 |
253 | @@ -27,18 +27,15 @@ |
254 | using namespace scopes_ng; |
255 | namespace sc = unity::scopes; |
256 | |
257 | -static const QString SETTING_GROUP("default"); |
258 | - |
259 | -static const QString SETTING_ID_PATTERN("%1-%2"); |
260 | - |
261 | -SettingsModel::SettingsModel(const QDir& shareDir, const QString& scopeId, |
262 | +SettingsModel::SettingsModel(const QDir& configDir, const QString& scopeId, |
263 | const QVariant& settingsDefinitions, QObject* parent, |
264 | int settingsTimeout) |
265 | : SettingsModelInterface(parent), m_settingsTimeout(settingsTimeout) |
266 | { |
267 | - shareDir.mkdir(scopeId); |
268 | - QDir databaseDir = shareDir.filePath(scopeId); |
269 | - m_database.setPath(databaseDir.filePath("settings.db")); |
270 | + configDir.mkpath(scopeId); |
271 | + QDir databaseDir = configDir.filePath(scopeId); |
272 | + |
273 | + m_settings.reset(new QSettings(databaseDir.filePath("settings.ini"), QSettings::IniFormat)); |
274 | |
275 | for (const auto &it : settingsDefinitions.toList()) |
276 | { |
277 | @@ -46,27 +43,38 @@ |
278 | QString id = data["id"].toString(); |
279 | QString displayName = data["displayName"].toString(); |
280 | QVariantMap properties; |
281 | + QVariant defaultValue; |
282 | if (data.contains("displayValues")) |
283 | { |
284 | properties["values"] = data["displayValues"].toList(); |
285 | } |
286 | QString type = data["type"].toString(); |
287 | |
288 | - QVariantMap defaults; |
289 | + QVariant::Type variantType; |
290 | + |
291 | + if(type == "boolean") |
292 | + { |
293 | + variantType = QVariant::Bool; |
294 | + } |
295 | + else if(type == "list") |
296 | + { |
297 | + variantType = QVariant::UInt; |
298 | + } |
299 | + else if(type == "number") |
300 | + { |
301 | + variantType = QVariant::Double; |
302 | + } |
303 | + else if(type == "string") |
304 | + { |
305 | + variantType = QVariant::String; |
306 | + } |
307 | + |
308 | if(data.contains("defaultValue")) |
309 | { |
310 | - defaults["value"] = data["defaultValue"]; |
311 | - properties["defaultValue"] = data["defaultValue"]; |
312 | + defaultValue = data["defaultValue"]; |
313 | + properties["defaultValue"] = defaultValue; |
314 | } |
315 | |
316 | - QSharedPointer<U1db::Document> document(new U1db::Document); |
317 | - document->setDocId(SETTING_ID_PATTERN.arg(SETTING_GROUP, id)); |
318 | - document->setDefaults(defaults); |
319 | - document->setDatabase(&m_database); |
320 | - document->setCreate(true); |
321 | - |
322 | - m_documents[id] = document; |
323 | - |
324 | QSharedPointer<QTimer> timer(new QTimer()); |
325 | timer->setProperty("setting_id", id); |
326 | timer->setSingleShot(true); |
327 | @@ -77,9 +85,11 @@ |
328 | m_timers[id] = timer; |
329 | |
330 | QSharedPointer<Data> setting( |
331 | - new Data(id, displayName, type, properties)); |
332 | + new Data(id, displayName, type, properties, defaultValue, |
333 | + variantType)); |
334 | |
335 | m_data << setting; |
336 | + m_data_by_id[id] = setting; |
337 | } |
338 | } |
339 | |
340 | @@ -108,9 +118,8 @@ |
341 | break; |
342 | case Roles::RoleValue: |
343 | { |
344 | - QSharedPointer<U1db::Document> document = m_documents[data->id]; |
345 | - QVariantMap contents = document->getContents().toMap(); |
346 | - result = contents["value"]; |
347 | + result = m_settings->value(data->id, data->defaultValue); |
348 | + result.convert(data->variantType); |
349 | break; |
350 | } |
351 | default: |
352 | @@ -121,6 +130,21 @@ |
353 | return result; |
354 | } |
355 | |
356 | +QVariant SettingsModel::value(const QString& id) const |
357 | +{ |
358 | + m_settings->sync(); |
359 | + |
360 | + QVariant result; |
361 | + |
362 | + QSharedPointer<Data> data = m_data_by_id[id]; |
363 | + if (data) |
364 | + { |
365 | + result = m_settings->value(data->id, data->defaultValue); |
366 | + result.convert(data->variantType); |
367 | + } |
368 | + return result; |
369 | +} |
370 | + |
371 | bool SettingsModel::setData(const QModelIndex &index, const QVariant &value, |
372 | int role) |
373 | { |
374 | @@ -170,8 +194,5 @@ |
375 | QString setting_id = timer->property("setting_id").toString(); |
376 | QVariant value = timer->property("value"); |
377 | |
378 | - QSharedPointer<U1db::Document> document = m_documents[setting_id]; |
379 | - QVariantMap map; |
380 | - map["value"] = value; |
381 | - document->setContents(map); |
382 | + m_settings->setValue(setting_id, value); |
383 | } |
384 | |
385 | === modified file 'src/Unity/settingsmodel.h' |
386 | --- src/Unity/settingsmodel.h 2014-07-08 09:52:28 +0000 |
387 | +++ src/Unity/settingsmodel.h 2014-08-20 14:26:16 +0000 |
388 | @@ -20,14 +20,13 @@ |
389 | #ifndef NG_PREVIEW_SETTTINGSMODEL_H_ |
390 | #define NG_PREVIEW_SETTTINGSMODEL_H_ |
391 | |
392 | -#include <libu1db-qt5/database.h> |
393 | -#include <libu1db-qt5/document.h> |
394 | #include <unity/SymbolExport.h> |
395 | #include <unity/shell/scopes/SettingsModelInterface.h> |
396 | |
397 | #include <QAbstractListModel> |
398 | #include <QList> |
399 | #include <QSharedPointer> |
400 | +#include <QSettings> |
401 | |
402 | QT_BEGIN_NAMESPACE |
403 | class QDir; |
404 | @@ -47,17 +46,21 @@ |
405 | QString displayName; |
406 | QString type; |
407 | QVariant properties; |
408 | + QVariant defaultValue; |
409 | + QVariant::Type variantType; |
410 | |
411 | Data(QString const& id_, QString const& displayName_, |
412 | - QString const& type_, QVariant const& properties_) |
413 | - : id(id_), displayName(displayName_), type(type_), properties( |
414 | - properties_) |
415 | + QString const& type_, QVariant const& properties_, |
416 | + QVariant const& defaultValue_, QVariant::Type variantType_) : |
417 | + id(id_), displayName(displayName_), type(type_), properties( |
418 | + properties_), defaultValue(defaultValue_), variantType( |
419 | + variantType_) |
420 | { |
421 | } |
422 | }; |
423 | |
424 | public: |
425 | - explicit SettingsModel(const QDir& shareDir, const QString& scopeId, |
426 | + explicit SettingsModel(const QDir& configDir, const QString& scopeId, |
427 | const QVariant& settingsDefinitions, QObject* parent = 0, |
428 | int settingsTimeout = 300); |
429 | |
430 | @@ -71,6 +74,8 @@ |
431 | |
432 | int count() const override; |
433 | |
434 | + QVariant value(const QString& id) const; |
435 | + |
436 | protected Q_SLOTS: |
437 | void settings_timeout(); |
438 | |
439 | @@ -79,9 +84,9 @@ |
440 | |
441 | QList<QSharedPointer<Data>> m_data; |
442 | |
443 | - U1db::Database m_database; |
444 | + QMap<QString, QSharedPointer<Data>> m_data_by_id; |
445 | |
446 | - QMap<QString, QSharedPointer<U1db::Document>> m_documents; |
447 | + QScopedPointer<QSettings> m_settings; |
448 | |
449 | QMap<QString, QSharedPointer<QTimer>> m_timers; |
450 | }; |
451 | |
452 | === modified file 'tests/CMakeLists.txt' |
453 | --- tests/CMakeLists.txt 2014-08-05 16:24:32 +0000 |
454 | +++ tests/CMakeLists.txt 2014-08-20 14:26:16 +0000 |
455 | @@ -1,5 +1,5 @@ |
456 | pkg_check_modules(SCOPES_API REQUIRED unity-shell-scopes=3) |
457 | -pkg_check_modules(SCOPESLIB REQUIRED libunity-scopes>=0.6.0) |
458 | +pkg_check_modules(SCOPESLIB REQUIRED libunity-scopes>=0.6.2) |
459 | pkg_check_modules(GSETTINGSQT REQUIRED gsettings-qt) |
460 | pkg_check_modules(QTDBUSTEST REQUIRED libqtdbustest-1>=0.2 REQUIRED) |
461 | pkg_check_modules(QTDBUSMOCK REQUIRED libqtdbusmock-1>=0.2 REQUIRED) |
462 | |
463 | === modified file 'tests/data/CMakeLists.txt' |
464 | --- tests/data/CMakeLists.txt 2014-07-29 10:50:23 +0000 |
465 | +++ tests/data/CMakeLists.txt 2014-08-20 14:26:16 +0000 |
466 | @@ -1,6 +1,7 @@ |
467 | add_subdirectory(mock-scope) |
468 | add_subdirectory(mock-scope-departments) |
469 | add_subdirectory(mock-scope-double-nav) |
470 | +add_subdirectory(mock-scope-info) |
471 | add_subdirectory(mock-scope-ttl) |
472 | add_subdirectory(scopes) |
473 | |
474 | |
475 | === added directory 'tests/data/mock-scope-info' |
476 | === added file 'tests/data/mock-scope-info/CMakeLists.txt' |
477 | --- tests/data/mock-scope-info/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
478 | +++ tests/data/mock-scope-info/CMakeLists.txt 2014-08-20 14:26:16 +0000 |
479 | @@ -0,0 +1,15 @@ |
480 | +pkg_check_modules(SCOPESLIB REQUIRED libunity-scopes>=0.4.0) |
481 | + |
482 | +set(SCOPES_BIN_DIR ${SCOPESLIB_LIBDIR}) |
483 | + |
484 | +include_directories(${SCOPESLIB_INCLUDE_DIRS}) |
485 | +include_directories(${CMAKE_CURRENT_BINARY_DIR}) |
486 | + |
487 | +set(SCOPE_SOURCES |
488 | + mock-scope-info.cpp |
489 | + ) |
490 | + |
491 | +add_library(mock-scope-info MODULE ${SCOPE_SOURCES}) |
492 | +target_link_libraries(mock-scope-info ${SCOPESLIB_LDFLAGS}) |
493 | + |
494 | +configure_file(mock-scope-info.ini.in mock-scope-info.ini) |
495 | |
496 | === added file 'tests/data/mock-scope-info/mock-scope-info.cpp' |
497 | --- tests/data/mock-scope-info/mock-scope-info.cpp 1970-01-01 00:00:00 +0000 |
498 | +++ tests/data/mock-scope-info/mock-scope-info.cpp 2014-08-20 14:26:16 +0000 |
499 | @@ -0,0 +1,121 @@ |
500 | +/* |
501 | + * Copyright (C) 2014 Canonical Ltd |
502 | + * |
503 | + * This program is free software: you can redistribute it and/or modify |
504 | + * it under the terms of the GNU Lesser General Public License version 3 as |
505 | + * published by the Free Software Foundation. |
506 | + * |
507 | + * This program is distributed in the hope that it will be useful, |
508 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
509 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
510 | + * GNU Lesser General Public License for more details. |
511 | + * |
512 | + * You should have received a copy of the GNU Lesser General Public License |
513 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
514 | + * |
515 | + * Authored by: Marcus Tomlinson <marcus.tomlinson@canonical.com> |
516 | + */ |
517 | + |
518 | +#include <unity/scopes/ScopeBase.h> |
519 | +#include <unity/scopes/SearchReply.h> |
520 | + |
521 | +#include <atomic> |
522 | + |
523 | +#define EXPORT __attribute__ ((visibility ("default"))) |
524 | + |
525 | +using namespace std; |
526 | +using namespace unity::scopes; |
527 | + |
528 | +class MyQuery : public SearchQueryBase |
529 | +{ |
530 | +public: |
531 | + MyQuery(CannedQuery const& query, SearchMetadata const& metadata) |
532 | + : SearchQueryBase(query, metadata) |
533 | + , m_query(query.query_string()) |
534 | + { |
535 | + } |
536 | + |
537 | + ~MyQuery() |
538 | + { |
539 | + } |
540 | + |
541 | + virtual void cancelled() override |
542 | + { |
543 | + } |
544 | + |
545 | + virtual void run(SearchReplyProxy const& reply) override |
546 | + { |
547 | + // No info (Status::Okay) |
548 | + if (m_query == "no_info") |
549 | + { |
550 | + } |
551 | + // NoInternet (Status::NoInternet) |
552 | + if (m_query == "no_internet") |
553 | + { |
554 | + reply->info(OperationInfo{OperationInfo::NoInternet}); |
555 | + } |
556 | + // NoLocationData (Status::NoLocationData) |
557 | + if (m_query == "no_location") |
558 | + { |
559 | + reply->info(OperationInfo{OperationInfo::NoLocationData}); |
560 | + } |
561 | + // DefaultSettingsUsed (unknown to shell but known to run-time so Status::Okay) |
562 | + if (m_query == "shell_unknown") |
563 | + { |
564 | + reply->info(OperationInfo{OperationInfo::DefaultSettingsUsed}); |
565 | + } |
566 | + // DefaultSettingsUsed (unknown to runtime so Status::Unknown) |
567 | + if (m_query == "runtime_unknown") |
568 | + { |
569 | + reply->info(OperationInfo{static_cast<OperationInfo::InfoCode>(OperationInfo::LastInfoCode_ + 1)}); |
570 | + } |
571 | + // NoLocationData and NoInternet (Status::NoInternet takes priority) |
572 | + if (m_query == "no_location_no_internet") |
573 | + { |
574 | + reply->info(OperationInfo{OperationInfo::NoLocationData}); |
575 | + reply->info(OperationInfo{OperationInfo::NoInternet}); |
576 | + } |
577 | + } |
578 | + |
579 | +private: |
580 | + std::string m_query; |
581 | +}; |
582 | + |
583 | +class MyScope : public ScopeBase |
584 | +{ |
585 | +public: |
586 | + MyScope() |
587 | + { |
588 | + } |
589 | + |
590 | + virtual SearchQueryBase::UPtr search(CannedQuery const& q, SearchMetadata const& metadata) override |
591 | + { |
592 | + return SearchQueryBase::UPtr(new MyQuery(q, metadata)); |
593 | + } |
594 | + |
595 | + virtual PreviewQueryBase::UPtr preview(Result const&, ActionMetadata const&) override |
596 | + { |
597 | + return nullptr; |
598 | + } |
599 | +}; |
600 | + |
601 | +extern "C" |
602 | +{ |
603 | + |
604 | + EXPORT |
605 | + unity::scopes::ScopeBase* |
606 | + // cppcheck-suppress unusedFunction |
607 | + UNITY_SCOPE_CREATE_FUNCTION() |
608 | + { |
609 | + return new MyScope; |
610 | + } |
611 | + |
612 | + EXPORT |
613 | + void |
614 | + // cppcheck-suppress unusedFunction |
615 | + UNITY_SCOPE_DESTROY_FUNCTION(unity::scopes::ScopeBase* scope_base) |
616 | + { |
617 | + delete scope_base; |
618 | + } |
619 | + |
620 | +} |
621 | |
622 | === added file 'tests/data/mock-scope-info/mock-scope-info.ini.in' |
623 | --- tests/data/mock-scope-info/mock-scope-info.ini.in 1970-01-01 00:00:00 +0000 |
624 | +++ tests/data/mock-scope-info/mock-scope-info.ini.in 2014-08-20 14:26:16 +0000 |
625 | @@ -0,0 +1,5 @@ |
626 | +[ScopeConfig] |
627 | +DisplayName = mock-info.DisplayName |
628 | +Description = mock-info.Description |
629 | +Icon = /mock-info.Icon |
630 | +Author = mock-info.Author |
631 | |
632 | === modified file 'tests/registry-spawner.h' |
633 | --- tests/registry-spawner.h 2014-08-05 16:24:32 +0000 |
634 | +++ tests/registry-spawner.h 2014-08-20 14:26:16 +0000 |
635 | @@ -35,7 +35,7 @@ |
636 | public: |
637 | RegistrySpawner() |
638 | { |
639 | - qputenv("UNITY_SCOPES_SETTINGS_DIR", m_tempDir.path().toUtf8()); |
640 | + qputenv("UNITY_SCOPES_CONFIG_DIR", m_tempDir.path().toUtf8()); |
641 | |
642 | QDir endpointdir(QFileInfo(TEST_RUNTIME_CONFIG).dir()); |
643 | endpointdir.cd(QString("endpoints")); |
644 | |
645 | === modified file 'tests/resultstest.cpp' |
646 | --- tests/resultstest.cpp 2014-08-01 11:43:58 +0000 |
647 | +++ tests/resultstest.cpp 2014-08-20 14:26:16 +0000 |
648 | @@ -88,6 +88,7 @@ |
649 | QScopedPointer<Scopes> m_scopes; |
650 | Scope* m_scope; |
651 | Scope* m_scope_ttl; |
652 | + Scope* m_scope_info; |
653 | QScopedPointer<RegistrySpawner> m_registry; |
654 | |
655 | private Q_SLOTS: |
656 | @@ -121,8 +122,13 @@ |
657 | |
658 | // get scope proxy for TTL scope |
659 | m_scope_ttl = qobject_cast<scopes_ng::Scope*>(m_scopes->getScopeById(QString("mock-scope-ttl"))); |
660 | - QVERIFY(m_scope != nullptr); |
661 | + QVERIFY(m_scope_ttl != nullptr); |
662 | m_scope_ttl->setActive(true); |
663 | + |
664 | + // get scope proxy for info scope (sends info() messages) |
665 | + m_scope_info = qobject_cast<scopes_ng::Scope*>(m_scopes->getScopeById(QString("mock-scope-info"))); |
666 | + QVERIFY(m_scope_info != nullptr); |
667 | + m_scope_info->setActive(true); |
668 | } |
669 | |
670 | void cleanup() |
671 | @@ -130,6 +136,7 @@ |
672 | m_scopes.reset(); |
673 | m_scope = nullptr; |
674 | m_scope_ttl = nullptr; |
675 | + m_scope_info = nullptr; |
676 | } |
677 | |
678 | void testScopeCommunication() |
679 | @@ -666,6 +673,28 @@ |
680 | QCOMPARE(m_scope->searchQuery(), QString("next-scope-query")); |
681 | } |
682 | |
683 | + void testInfoStatus() |
684 | + { |
685 | + // No info (Status::Okay) |
686 | + performSearch(m_scope_info, QString("no_info")); |
687 | + QCOMPARE(m_scope_info->status(), unity::shell::scopes::ScopeInterface::Status::Okay); |
688 | + // NoInternet (Status::NoInternet) |
689 | + performSearch(m_scope_info, QString("no_internet")); |
690 | + QCOMPARE(m_scope_info->status(), unity::shell::scopes::ScopeInterface::Status::NoInternet); |
691 | + // NoLocationData (Status::NoLocationData) |
692 | + performSearch(m_scope_info, QString("no_location")); |
693 | + QCOMPARE(m_scope_info->status(), unity::shell::scopes::ScopeInterface::Status::NoLocationData); |
694 | + // DefaultSettingsUsed (unknown to shell but known to run-time so Status::Okay) |
695 | + performSearch(m_scope_info, QString("shell_unknown")); |
696 | + QCOMPARE(m_scope_info->status(), unity::shell::scopes::ScopeInterface::Status::Okay); |
697 | + // DefaultSettingsUsed (unknown to runtime so Status::Unknown) |
698 | + performSearch(m_scope_info, QString("runtime_unknown")); |
699 | + QCOMPARE(m_scope_info->status(), unity::shell::scopes::ScopeInterface::Status::Unknown); |
700 | + // NoLocationData and NoInternet (Status::NoInternet takes priority) |
701 | + performSearch(m_scope_info, QString("no_location_no_internet")); |
702 | + QCOMPARE(m_scope_info->status(), unity::shell::scopes::ScopeInterface::Status::NoInternet); |
703 | + } |
704 | + |
705 | }; |
706 | |
707 | QTEST_GUILESS_MAIN(ResultsTest) |