Merge lp:~rmescandon/scopecreator/rss-template-read-settings-from-metadata-take2 into lp:~scopecreator-team/scopecreator/rss-template
- rss-template-read-settings-from-metadata-take2
- Merge into rss-template
Proposed by
Roberto Mier Escandon
Status: | Merged |
---|---|
Merged at revision: | 11 |
Proposed branch: | lp:~rmescandon/scopecreator/rss-template-read-settings-from-metadata-take2 |
Merge into: | lp:~scopecreator-team/scopecreator/rss-template |
Prerequisite: | lp:~rmescandon/scopecreator/rss-template-keywords-support |
Diff against target: |
455 lines (+203/-82) 6 files modified
data/rss.canonical_rss.ini.in (+3/-0) include/scope/query.h (+23/-1) include/scope/scope.h (+9/-0) po/rss.pot (+6/-2) src/scope/query.cpp (+143/-74) src/scope/scope.cpp (+19/-5) |
To merge this branch: | bzr merge lp:~rmescandon/scopecreator/rss-template-read-settings-from-metadata-take2 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Scott Sweeny (community) | Approve | ||
Review via email: mp+267443@code.launchpad.net |
Commit message
Same features than branch
scopecreator/
but reading scope .ini file directly using QSettings instead of using Scope::metadata
This solution is working well and can be used as alternative to scopecreator/
Description of the change
Same features than branch
scopecreator/
but reading scope .ini file directly using QSettings instead of using Scope::metadata
This solution is working well and can be used as alternative to scopecreator/
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'data/rss.canonical_rss.ini.in' | |||
2 | --- data/rss.canonical_rss.ini.in 2015-08-08 22:18:29 +0000 | |||
3 | +++ data/rss.canonical_rss.ini.in 2015-08-08 22:18:29 +0000 | |||
4 | @@ -10,3 +10,6 @@ | |||
5 | 10 | PageHeader.Logo=logo.png | 10 | PageHeader.Logo=logo.png |
6 | 11 | PageHeader.Background=color:///#e9e7e8 | 11 | PageHeader.Background=color:///#e9e7e8 |
7 | 12 | PageHeader.DividerColor=#ffeb00 | 12 | PageHeader.DividerColor=#ffeb00 |
8 | 13 | Emblem=logo.png | ||
9 | 14 | DateTimeFormat="hh:mm, d MMMM" | ||
10 | 15 | BigFirstResult=true | ||
11 | 13 | 16 | ||
12 | === modified file 'include/scope/query.h' | |||
13 | --- include/scope/query.h 2015-08-08 22:18:29 +0000 | |||
14 | +++ include/scope/query.h 2015-08-08 22:18:29 +0000 | |||
15 | @@ -25,6 +25,9 @@ | |||
16 | 25 | #include <unity/scopes/SearchQueryBase.h> | 25 | #include <unity/scopes/SearchQueryBase.h> |
17 | 26 | #include <unity/scopes/ReplyProxyFwd.h> | 26 | #include <unity/scopes/ReplyProxyFwd.h> |
18 | 27 | 27 | ||
19 | 28 | #include <QSharedPointer> | ||
20 | 29 | #include <QSettings> | ||
21 | 30 | |||
22 | 28 | #include <map> | 31 | #include <map> |
23 | 29 | 32 | ||
24 | 30 | namespace scope { | 33 | namespace scope { |
25 | @@ -40,7 +43,8 @@ | |||
26 | 40 | public: | 43 | public: |
27 | 41 | Query(const unity::scopes::CannedQuery &query, | 44 | Query(const unity::scopes::CannedQuery &query, |
28 | 42 | const unity::scopes::SearchMetadata &metadata, | 45 | const unity::scopes::SearchMetadata &metadata, |
30 | 43 | const std::string scope_directory); | 46 | const std::string& scope_directory, |
31 | 47 | const QSharedPointer<QSettings>& scopeConfig); | ||
32 | 44 | 48 | ||
33 | 45 | ~Query() = default; | 49 | ~Query() = default; |
34 | 46 | 50 | ||
35 | @@ -51,6 +55,7 @@ | |||
36 | 51 | private: | 55 | private: |
37 | 52 | api::Client client_; | 56 | api::Client client_; |
38 | 53 | std::string scope_directory_; | 57 | std::string scope_directory_; |
39 | 58 | QSharedPointer<QSettings> mScopeConfig; | ||
40 | 54 | 59 | ||
41 | 55 | /// @brief keyword_feeds_ map correlating aggregator scopes keywords to feed urls | 60 | /// @brief keyword_feeds_ map correlating aggregator scopes keywords to feed urls |
42 | 56 | std::map<std::string, std::string> keyword_feeds_; | 61 | std::map<std::string, std::string> keyword_feeds_; |
43 | @@ -65,6 +70,23 @@ | |||
44 | 65 | /// from an aggregator scope. If found, it is returned a std::pair with the feed url (pair.second) and its related | 70 | /// from an aggregator scope. If found, it is returned a std::pair with the feed url (pair.second) and its related |
45 | 66 | /// search keyword (pair.first) | 71 | /// search keyword (pair.first) |
46 | 67 | std::pair<std::string, std::string> find_url_for_keywords(const std::set<std::string>& search_keywords); | 72 | std::pair<std::string, std::string> find_url_for_keywords(const std::set<std::string>& search_keywords); |
47 | 73 | |||
48 | 74 | /// @brief get_display_name returns the scope name to display | ||
49 | 75 | std::string get_display_name(); | ||
50 | 76 | |||
51 | 77 | /// @brief get_icon returns the scoe icon file path. scope_directory/icon.png if value is not set in scope config | ||
52 | 78 | std::string get_icon(); | ||
53 | 79 | |||
54 | 80 | /// @brief get_emblem gets the emblem by reading the appearance parameter "Emblem" value if set. If not set, | ||
55 | 81 | /// scope_directory/emblem.png file is used by default | ||
56 | 82 | std::string get_emblem(); | ||
57 | 83 | |||
58 | 84 | /// @brief get_date_time_format returns the format to be shown for the date and time for every result shown in an | ||
59 | 85 | /// aggregator scope. If this parameter is not set, the default format is 'hh:mm, d MMMM' | ||
60 | 86 | std::string get_date_time_format(); | ||
61 | 87 | |||
62 | 88 | /// @brief get_big_first_result returns true if wanted to have first returned value in a format with a big image and overlayed | ||
63 | 89 | bool get_big_first_result(); | ||
64 | 68 | }; | 90 | }; |
65 | 69 | 91 | ||
66 | 70 | } | 92 | } |
67 | 71 | 93 | ||
68 | === modified file 'include/scope/scope.h' | |||
69 | --- include/scope/scope.h 2015-03-25 03:17:53 +0000 | |||
70 | +++ include/scope/scope.h 2015-08-08 22:18:29 +0000 | |||
71 | @@ -28,6 +28,9 @@ | |||
72 | 28 | #include <unity/scopes/QueryBase.h> | 28 | #include <unity/scopes/QueryBase.h> |
73 | 29 | #include <unity/scopes/PreviewQueryBase.h> | 29 | #include <unity/scopes/PreviewQueryBase.h> |
74 | 30 | 30 | ||
75 | 31 | #include <QSettings> | ||
76 | 32 | #include <QSharedPointer> | ||
77 | 33 | |||
78 | 31 | namespace scope { | 34 | namespace scope { |
79 | 32 | 35 | ||
80 | 33 | /** | 36 | /** |
81 | @@ -62,6 +65,12 @@ | |||
82 | 62 | unity::scopes::SearchQueryBase::UPtr search( | 65 | unity::scopes::SearchQueryBase::UPtr search( |
83 | 63 | unity::scopes::CannedQuery const& q, | 66 | unity::scopes::CannedQuery const& q, |
84 | 64 | unity::scopes::SearchMetadata const&) override; | 67 | unity::scopes::SearchMetadata const&) override; |
85 | 68 | |||
86 | 69 | private: | ||
87 | 70 | std::string scope_id_; | ||
88 | 71 | QSharedPointer<QSettings> mScopeConfig; | ||
89 | 72 | |||
90 | 73 | void loadScopeConfig(); | ||
91 | 65 | }; | 74 | }; |
92 | 66 | 75 | ||
93 | 67 | } | 76 | } |
94 | 68 | 77 | ||
95 | === modified file 'po/rss.pot' | |||
96 | --- po/rss.pot 2015-08-08 22:18:29 +0000 | |||
97 | +++ po/rss.pot 2015-08-08 22:18:29 +0000 | |||
98 | @@ -8,7 +8,7 @@ | |||
99 | 8 | msgstr "" | 8 | msgstr "" |
100 | 9 | "Project-Id-Version: PACKAGE VERSION\n" | 9 | "Project-Id-Version: PACKAGE VERSION\n" |
101 | 10 | "Report-Msgid-Bugs-To: \n" | 10 | "Report-Msgid-Bugs-To: \n" |
103 | 11 | "POT-Creation-Date: 2015-08-03 17:04+0200\n" | 11 | "POT-Creation-Date: 2015-08-09 00:05+0200\n" |
104 | 12 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | 12 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
105 | 13 | "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | 13 | "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
106 | 14 | "Language-Team: LANGUAGE <LL@li.org>\n" | 14 | "Language-Team: LANGUAGE <LL@li.org>\n" |
107 | @@ -21,6 +21,10 @@ | |||
108 | 21 | msgid "Vox" | 21 | msgid "Vox" |
109 | 22 | msgstr "" | 22 | msgstr "" |
110 | 23 | 23 | ||
112 | 24 | #: ../src/scope/query.cpp:266 | 24 | #: ../src/scope/query.cpp:309 |
113 | 25 | msgid "Open" | 25 | msgid "Open" |
114 | 26 | msgstr "" | 26 | msgstr "" |
115 | 27 | |||
116 | 28 | #: ../src/scope/query.cpp:316 | ||
117 | 29 | msgid "More from " | ||
118 | 30 | msgstr "" | ||
119 | 27 | 31 | ||
120 | === modified file 'src/scope/query.cpp' | |||
121 | --- src/scope/query.cpp 2015-08-08 22:18:29 +0000 | |||
122 | +++ src/scope/query.cpp 2015-08-08 22:18:29 +0000 | |||
123 | @@ -19,7 +19,6 @@ | |||
124 | 19 | 19 | ||
125 | 20 | #include <boost/algorithm/string/trim.hpp> | 20 | #include <boost/algorithm/string/trim.hpp> |
126 | 21 | #include <boost/algorithm/string/predicate.hpp> | 21 | #include <boost/algorithm/string/predicate.hpp> |
127 | 22 | #include <boost/foreach.hpp> | ||
128 | 23 | 22 | ||
129 | 24 | #include <scope/localization.h> | 23 | #include <scope/localization.h> |
130 | 25 | #include <scope/query.h> | 24 | #include <scope/query.h> |
131 | @@ -29,6 +28,7 @@ | |||
132 | 29 | #include <unity/scopes/CategoryRenderer.h> | 28 | #include <unity/scopes/CategoryRenderer.h> |
133 | 30 | #include <unity/scopes/Department.h> | 29 | #include <unity/scopes/Department.h> |
134 | 31 | #include <unity/scopes/QueryBase.h> | 30 | #include <unity/scopes/QueryBase.h> |
135 | 31 | #include <unity/scopes/CannedQuery.h> | ||
136 | 32 | #include <unity/scopes/SearchReply.h> | 32 | #include <unity/scopes/SearchReply.h> |
137 | 33 | #include <unity/scopes/VariantBuilder.h> | 33 | #include <unity/scopes/VariantBuilder.h> |
138 | 34 | #include <unity/scopes/SearchMetadata.h> | 34 | #include <unity/scopes/SearchMetadata.h> |
139 | @@ -43,8 +43,6 @@ | |||
140 | 43 | #include <QJsonObject> | 43 | #include <QJsonObject> |
141 | 44 | #include <QDateTime> | 44 | #include <QDateTime> |
142 | 45 | 45 | ||
143 | 46 | #define foreach BOOST_FOREACH | ||
144 | 47 | |||
145 | 48 | namespace sc = unity::scopes; | 46 | namespace sc = unity::scopes; |
146 | 49 | namespace alg = boost::algorithm; | 47 | namespace alg = boost::algorithm; |
147 | 50 | 48 | ||
148 | @@ -52,6 +50,23 @@ | |||
149 | 52 | using namespace api; | 50 | using namespace api; |
150 | 53 | using namespace scope; | 51 | using namespace scope; |
151 | 54 | 52 | ||
152 | 53 | std::string FIRST_NEWS_LAYOUT = R"( | ||
153 | 54 | { | ||
154 | 55 | "schema-version" : 1, | ||
155 | 56 | "template" : { | ||
156 | 57 | "category-layout" : "grid", | ||
157 | 58 | "card-size": "large", | ||
158 | 59 | "overlay": true | ||
159 | 60 | }, | ||
160 | 61 | "components" : { | ||
161 | 62 | "title" : "title", | ||
162 | 63 | "art" : { | ||
163 | 64 | "field": "art", | ||
164 | 65 | "aspect-ratio": 2.1 | ||
165 | 66 | } | ||
166 | 67 | } | ||
167 | 68 | } | ||
168 | 69 | )"; | ||
169 | 55 | 70 | ||
170 | 56 | std::string NEWS_LAYOUT = R"( | 71 | std::string NEWS_LAYOUT = R"( |
171 | 57 | { | 72 | { |
172 | @@ -147,29 +162,32 @@ | |||
173 | 147 | } | 162 | } |
174 | 148 | 163 | ||
175 | 149 | pair<string,string> Query::find_url_for_keywords(const set<string>& search_keywords) { | 164 | pair<string,string> Query::find_url_for_keywords(const set<string>& search_keywords) { |
177 | 150 | foreach(string search_keyword, search_keywords) { | 165 | for(const string& search_keyword : search_keywords) { |
178 | 151 | auto it = keyword_feeds_.find(search_keyword); | 166 | auto it = keyword_feeds_.find(search_keyword); |
179 | 152 | if (it != keyword_feeds_.end()) { | 167 | if (it != keyword_feeds_.end()) { |
181 | 153 | string found_url = it->second; | 168 | const string& found_url = it->second; |
182 | 154 | return std::pair<string, string>(search_keyword, found_url); | 169 | return std::pair<string, string>(search_keyword, found_url); |
183 | 155 | } | 170 | } |
184 | 156 | } | 171 | } |
185 | 157 | return std::pair<string, string>{}; | 172 | return std::pair<string, string>{}; |
186 | 158 | } | 173 | } |
187 | 159 | 174 | ||
192 | 160 | Query::Query(const sc::CannedQuery &query, const sc::SearchMetadata &metadata, const string scope_directory) : | 175 | Query::Query(const sc::CannedQuery &query, |
193 | 161 | sc::SearchQueryBase(query, metadata), | 176 | const sc::SearchMetadata &search_metadata, |
194 | 162 | client_(), | 177 | const string& scope_directory, |
195 | 163 | scope_directory_(scope_directory) { | 178 | const QSharedPointer<QSettings>& scopeConfig) |
196 | 179 | : sc::SearchQueryBase(query, search_metadata) | ||
197 | 180 | , client_{} | ||
198 | 181 | , scope_directory_{scope_directory} | ||
199 | 182 | , mScopeConfig{scopeConfig} { | ||
200 | 164 | } | 183 | } |
201 | 165 | 184 | ||
202 | 166 | void Query::cancelled() { | 185 | void Query::cancelled() { |
203 | 167 | client_.cancel(); | 186 | client_.cancel(); |
204 | 168 | } | 187 | } |
205 | 169 | 188 | ||
206 | 170 | |||
207 | 171 | void Query::run(sc::SearchReplyProxy const& reply) { | 189 | void Query::run(sc::SearchReplyProxy const& reply) { |
209 | 172 | try { | 190 | try { |
210 | 173 | // Start by getting information about the query | 191 | // Start by getting information about the query |
211 | 174 | const sc::CannedQuery &query(sc::SearchQueryBase::query()); | 192 | const sc::CannedQuery &query(sc::SearchQueryBase::query()); |
212 | 175 | 193 | ||
213 | @@ -203,74 +221,105 @@ | |||
214 | 203 | 221 | ||
215 | 204 | vector<Client::Item> results = client_.getItems(feedUrl); | 222 | vector<Client::Item> results = client_.getItems(feedUrl); |
216 | 205 | 223 | ||
218 | 206 | // Register a category for the forecast | 224 | // Register a category for the common news |
219 | 207 | auto news_cat = reply->register_category("news", | 225 | auto news_cat = reply->register_category("news", |
220 | 208 | "", "", sc::CategoryRenderer(NEWS_LAYOUT)); | 226 | "", "", sc::CategoryRenderer(NEWS_LAYOUT)); |
236 | 209 | 227 | auto first_news_cat = reply->register_category("first_news", | |
237 | 210 | // For each of the forecast days | 228 | "", "", sc::CategoryRenderer(FIRST_NEWS_LAYOUT)); |
238 | 211 | for (const auto &item : results) { | 229 | |
239 | 212 | 230 | if (results.size() > 0) { | |
240 | 213 | // Filter by search term if we have one | 231 | |
241 | 214 | if (!query_string.empty()) { | 232 | // Get common values for all results to avoid asking for them in every iteration |
242 | 215 | QString qry = QString::fromStdString(query_string); | 233 | std::string emblem = get_emblem(); |
243 | 216 | QString title = QString::fromStdString(item.title); | 234 | std::string date_time_format = get_date_time_format(); |
244 | 217 | QString summary = QString::fromStdString(item.summary); | 235 | bool show_big_result = get_big_first_result(); |
245 | 218 | QString content = QString::fromStdString(item.content); | 236 | |
246 | 219 | 237 | // For each of the results vector items | |
247 | 220 | if (!title.contains(qry, Qt::CaseInsensitive) && | 238 | for (const auto &item : results) { |
248 | 221 | !summary.contains(qry, Qt::CaseInsensitive) && | 239 | |
249 | 222 | !content.contains(qry, Qt::CaseInsensitive)) { | 240 | // Filter by search term if we have one |
250 | 223 | continue; | 241 | if (!query_string.empty()) { |
251 | 242 | QString qry = QString::fromStdString(query_string); | ||
252 | 243 | QString title = QString::fromStdString(item.title); | ||
253 | 244 | QString summary = QString::fromStdString(item.summary); | ||
254 | 245 | QString content = QString::fromStdString(item.content); | ||
255 | 246 | |||
256 | 247 | if (!title.contains(qry, Qt::CaseInsensitive) && | ||
257 | 248 | !summary.contains(qry, Qt::CaseInsensitive) && | ||
258 | 249 | !content.contains(qry, Qt::CaseInsensitive)) { | ||
259 | 250 | continue; | ||
260 | 251 | } | ||
261 | 224 | } | 252 | } |
287 | 225 | } | 253 | |
288 | 226 | 254 | // Create a result if having title at least | |
289 | 227 | // Create a result | 255 | if (!item.title.empty() && !item.uri.empty()) { |
290 | 228 | sc::CategorisedResult res(news_cat); | 256 | |
291 | 229 | 257 | // If surfacing in not aggregated mode and set big-first-result setting to true, show first result in big | |
292 | 230 | // We must have a URI | 258 | sc::Category::SCPtr cat = |
293 | 231 | res.set_uri(item.uri); | 259 | show_big_result && !meta.is_aggregated() && query_string.empty() ? |
294 | 232 | res.set_dnd_uri(item.uri); | 260 | first_news_cat : |
295 | 233 | 261 | news_cat; | |
296 | 234 | // Set the rest of the attributes | 262 | |
297 | 235 | res.set_title(item.title); | 263 | show_big_result = false; |
298 | 236 | res.set_art(item.art); | 264 | |
299 | 237 | res["published"] = sc::Variant(item.published); | 265 | sc::CategorisedResult res(cat); |
300 | 238 | res["author"] = sc::Variant(item.author); | 266 | |
301 | 239 | res["summary"] = sc::Variant(item.summary); | 267 | // We must have a URI |
302 | 240 | res["content"] = sc::Variant(item.content); | 268 | res.set_uri(item.uri); |
303 | 241 | res["emblem"] = sc::Variant(scope_directory_+"/images/emblem.png"); | 269 | res.set_dnd_uri(item.uri); |
304 | 242 | 270 | ||
305 | 243 | if (res.art().empty()) { | 271 | // Set the rest of the attributes |
306 | 244 | res.set_art(scope_directory_ + "/icon.png"); | 272 | res.set_title(item.title); |
307 | 245 | } | 273 | res.set_art(item.art); |
308 | 246 | 274 | res["author"] = sc::Variant(item.author); | |
309 | 247 | // if searched from aggregated, set formatted date to subtitle in case found keyword is related with news | 275 | res["summary"] = sc::Variant(item.summary); |
310 | 248 | if (meta.is_aggregated()) { | 276 | res["content"] = sc::Variant(item.content); |
311 | 249 | if (boost::starts_with(found_keyword, "news.")) { | 277 | res["emblem"] = sc::Variant(emblem); |
312 | 278 | |||
313 | 279 | if (res.art().empty()) { | ||
314 | 280 | res.set_art(get_icon()); | ||
315 | 281 | } | ||
316 | 282 | |||
317 | 250 | QString date = QString::fromStdString(item.published); | 283 | QString date = QString::fromStdString(item.published); |
318 | 284 | |||
319 | 251 | if (!date.isEmpty()){ | 285 | if (!date.isEmpty()){ |
342 | 252 | QDateTime ipostTime = QDateTime::fromString(date, Qt::RFC2822Date); | 286 | QDateTime ipostTime = QDateTime::fromString(date, Qt::ISODate); |
343 | 253 | QString readeableTime = ipostTime.toString("hh:mm, d MMMM"); | 287 | QString readableTime = ipostTime.toString(QString::fromStdString(date_time_format)); |
344 | 254 | res["subtitle"] = readeableTime.toStdString(); | 288 | res["published"] = readableTime.toStdString(); |
345 | 255 | } | 289 | } |
346 | 256 | } | 290 | |
347 | 257 | } | 291 | // if searched from aggregated, set formatted date to subtitle in case found keyword is related with news |
348 | 258 | 292 | if (meta.is_aggregated()) { | |
349 | 259 | sc::VariantBuilder actions; | 293 | if (boost::starts_with(found_keyword, "news.")) { |
350 | 260 | actions.add_tuple({ | 294 | res["subtitle"] = res["published"]; |
351 | 261 | {"id", sc::Variant("open")}, | 295 | } |
352 | 262 | {"label", sc::Variant(_("Open"))}, | 296 | } |
353 | 263 | {"uri", sc::Variant(res.dnd_uri())} | 297 | |
354 | 264 | }); | 298 | sc::VariantBuilder actions; |
355 | 265 | res["actions"] = actions.end(); | 299 | actions.add_tuple({ |
356 | 266 | 300 | {"id", sc::Variant("open")}, | |
357 | 267 | // Push the result | 301 | {"label", sc::Variant(_("Open"))}, |
358 | 268 | if (!reply->push(res)) { | 302 | {"uri", sc::Variant(res.dnd_uri())} |
359 | 269 | // If we fail to push, it means the query has been cancelled. | 303 | }); |
360 | 270 | // So don't continue; | 304 | |
361 | 271 | return; | 305 | if (meta.is_aggregated()) { |
362 | 272 | } | 306 | actions.add_tuple({ |
363 | 273 | } | 307 | {"id", sc::Variant("more")}, |
364 | 308 | {"label", sc::Variant(_("More from ") + get_display_name())}, | ||
365 | 309 | {"uri", sc::Variant(query.to_uri())} | ||
366 | 310 | }); | ||
367 | 311 | } | ||
368 | 312 | res["actions"] = actions.end(); | ||
369 | 313 | |||
370 | 314 | // Push the result | ||
371 | 315 | if (!reply->push(res)) { | ||
372 | 316 | // If we fail to push, it means the query has been cancelled. | ||
373 | 317 | // So don't continue; | ||
374 | 318 | return; | ||
375 | 319 | } | ||
376 | 320 | } // end if (!item.title.empty() && !item.uri.empty()) ... | ||
377 | 321 | } // end for (const auto &item : results) ... | ||
378 | 322 | } // end if (results.size > 0) ... | ||
379 | 274 | 323 | ||
380 | 275 | } catch (domain_error &e) { | 324 | } catch (domain_error &e) { |
381 | 276 | // Handle exceptions being thrown by the client API | 325 | // Handle exceptions being thrown by the client API |
382 | @@ -279,3 +328,23 @@ | |||
383 | 279 | } | 328 | } |
384 | 280 | } | 329 | } |
385 | 281 | 330 | ||
386 | 331 | string Query::get_icon() { | ||
387 | 332 | return scope_directory_ + "/" + mScopeConfig->value("ScopeConfig/Icon", "/icon.png").toString().toStdString(); | ||
388 | 333 | } | ||
389 | 334 | |||
390 | 335 | string Query::get_display_name() { | ||
391 | 336 | return mScopeConfig->value("ScopeConfig/DisplayName", "").toString().toStdString(); | ||
392 | 337 | } | ||
393 | 338 | |||
394 | 339 | string Query::get_emblem() { | ||
395 | 340 | return scope_directory_ + "/" + mScopeConfig->value("Appearance/Emblem", "/emblem.png").toString().toStdString(); | ||
396 | 341 | } | ||
397 | 342 | |||
398 | 343 | string Query::get_date_time_format() { | ||
399 | 344 | return mScopeConfig->value("Appearance/DateTimeFormat", "hh:mm, d MMMM").toString().toStdString(); | ||
400 | 345 | } | ||
401 | 346 | |||
402 | 347 | bool Query::get_big_first_result() { | ||
403 | 348 | return mScopeConfig->value("Appearance/BigFirstResult", false).toBool(); | ||
404 | 349 | } | ||
405 | 350 | |||
406 | 282 | 351 | ||
407 | === modified file 'src/scope/scope.cpp' | |||
408 | --- src/scope/scope.cpp 2015-03-25 03:17:53 +0000 | |||
409 | +++ src/scope/scope.cpp 2015-08-08 22:18:29 +0000 | |||
410 | @@ -1,4 +1,4 @@ | |||
412 | 1 | /* | 1 | /* |
413 | 2 | * Copyright 2015 Canonical Ltd. | 2 | * Copyright 2015 Canonical Ltd. |
414 | 3 | * | 3 | * |
415 | 4 | * This program is free software; you can redistribute it and/or modify | 4 | * This program is free software; you can redistribute it and/or modify |
416 | @@ -31,21 +31,35 @@ | |||
417 | 31 | using namespace api; | 31 | using namespace api; |
418 | 32 | using namespace scope; | 32 | using namespace scope; |
419 | 33 | 33 | ||
421 | 34 | void Scope::start(string const&) { | 34 | void Scope::start(string const& scope_id) { |
422 | 35 | |||
423 | 36 | scope_id_ = scope_id; | ||
424 | 35 | 37 | ||
425 | 36 | setlocale(LC_ALL, ""); | 38 | setlocale(LC_ALL, ""); |
426 | 37 | string translation_directory = ScopeBase::scope_directory() | 39 | string translation_directory = ScopeBase::scope_directory() |
427 | 38 | + "/../share/locale/"; | 40 | + "/../share/locale/"; |
428 | 39 | bindtextdomain(GETTEXT_PACKAGE, translation_directory.c_str()); | 41 | bindtextdomain(GETTEXT_PACKAGE, translation_directory.c_str()); |
429 | 42 | |||
430 | 43 | loadScopeConfig(); | ||
431 | 40 | } | 44 | } |
432 | 41 | 45 | ||
433 | 42 | void Scope::stop() { | 46 | void Scope::stop() { |
434 | 43 | } | 47 | } |
435 | 44 | 48 | ||
436 | 49 | void Scope::loadScopeConfig() { | ||
437 | 50 | |||
438 | 51 | std::string scope_config_file = ScopeBase::scope_directory() + "/" + scope_id_ + ".ini"; | ||
439 | 52 | mScopeConfig = QSharedPointer<QSettings>::create(QString::fromStdString(scope_config_file), QSettings::IniFormat); | ||
440 | 53 | |||
441 | 54 | /* | ||
442 | 55 | qDebug() << "ALL KEYS:" << scope_config_->allKeys(); | ||
443 | 56 | qDebug() << "ICON KEY:" << scope_config_->value("ScopeConfig/Icon").toString(); | ||
444 | 57 | */ | ||
445 | 58 | } | ||
446 | 59 | |||
447 | 45 | sc::SearchQueryBase::UPtr Scope::search(const sc::CannedQuery &query, | 60 | sc::SearchQueryBase::UPtr Scope::search(const sc::CannedQuery &query, |
451 | 46 | const sc::SearchMetadata &metadata) { | 61 | const sc::SearchMetadata &search_metadata) { |
452 | 47 | // Boilerplate construction of Query | 62 | return sc::SearchQueryBase::UPtr(new Query(query, search_metadata, scope_directory(), mScopeConfig)); |
450 | 48 | return sc::SearchQueryBase::UPtr(new Query(query, metadata, scope_directory())); | ||
453 | 49 | } | 63 | } |
454 | 50 | 64 | ||
455 | 51 | sc::PreviewQueryBase::UPtr Scope::preview(sc::Result const& result, | 65 | sc::PreviewQueryBase::UPtr Scope::preview(sc::Result const& result, |
I've been running a scope based on this for a few weeks now and it works flawlessly :-)
Merging.