~larryprice/libertine-scope/libertine-store-internal-packages

« back to all changes in this revision

Viewing changes to scope/apps/query.cpp

Add link to Store in Apps Scope

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include <QFile>
32
32
#include <QTextStream>
33
33
 
 
34
 
34
35
namespace usc = unity::scopes;
35
36
 
 
37
 
36
38
namespace
37
39
{
38
40
static const auto ROOT_DEPT_TITLE = _("Desktop Apps");
41
43
static const auto APP_ID_FIELD = "app_id";
42
44
static const auto DEPARTMENT_ID_FIELD = "department_id";
43
45
static const auto EXCLUDED_APPS_FILTER_TITLE = _("Exclude Apps: ");
 
46
static const auto SEARCH_STORE_HINT = _("Search for '%s' in the store");
 
47
static const auto SEARCH_STORE_CATEGORY_TITLE = _("Get more apps from the store");
44
48
 
45
49
struct AppInfo
46
50
{
107
111
        }
108
112
    }
109
113
)";
 
114
 
 
115
 
 
116
static const auto CATEGORY_STORE = R"(
 
117
    {
 
118
      "schema-version": 1,
 
119
      "template": {
 
120
        "category-layout": "grid",
 
121
        "overlay": true,
 
122
        "card-background": "color:///#E95420"
 
123
      },
 
124
      "components": {
 
125
        "title": "title",
 
126
        "art": {
 
127
          "aspect-ratio": 0.55,
 
128
          "field": "art"
 
129
        },
 
130
        "overlay-color": "overlay-color"
 
131
      }
 
132
    }
 
133
)";
110
134
} // anonymous namespace
111
135
 
112
136
 
113
 
std::string const Query::NO_RESULTS_HINT = _("No applications available. Install new applications with the Libertine Manager.");
114
 
std::string const Query::ALL_RESULTS_FILTERED_HINT = _("All applications hidden. Reset filters or check the Hidden Desktop Apps department.");
 
137
std::string const Query::NO_RESULTS_HINT = _("No applications available in this department.");
 
138
std::string const Query::ALL_RESULTS_FILTERED_HINT = _("All applications filtered. Reset filters or clear department.");
115
139
 
116
140
 
117
141
Query::
118
 
Query(usc::CannedQuery const&    query,
119
 
      usc::SearchMetadata const& metadata,
120
 
      Libertine::Factory const&  libertine_factory,
 
142
Query(usc::CannedQuery const&     query,
 
143
      usc::SearchMetadata const&  metadata,
 
144
      Libertine::Factory const&   libertine_factory,
121
145
      std::shared_ptr<HiddenApps> hidden,
122
 
      std::shared_ptr<Blacklist> blacklist)
 
146
      std::shared_ptr<Blacklist>  blacklist,
 
147
      std::string const&          data_directory)
123
148
  : usc::SearchQueryBase(query, metadata)
124
149
  , libertine_factory_(libertine_factory)
125
150
  , hidden_(hidden)
126
151
  , blacklist_(blacklist)
 
152
  , data_directory_(data_directory)
127
153
{
128
154
}
129
155
 
201
227
 
202
228
 
203
229
void Query::
 
230
add_store_link(usc::SearchReplyProxy const& reply) const
 
231
{
 
232
  const auto querystr = query().query_string();
 
233
  auto cat_title = SEARCH_STORE_CATEGORY_TITLE;
 
234
 
 
235
  if (!querystr.empty())
 
236
  {
 
237
    char tmp[512];
 
238
    if (snprintf(tmp, sizeof(tmp), SEARCH_STORE_HINT, querystr.c_str()) > 0)
 
239
    {
 
240
        cat_title = tmp;
 
241
    }
 
242
  }
 
243
 
 
244
  usc::CategoryRenderer rdr(CATEGORY_STORE);
 
245
  auto cat = reply->register_category("hint", cat_title, "", rdr);
 
246
 
 
247
  const unity::scopes::CannedQuery store_scope(STORE_SCOPE_FULL_NAME, querystr, "");
 
248
 
 
249
  usc::CategorisedResult res(cat);
 
250
  res.set_title(_("Install X Apps"));
 
251
  res.set_art(data_directory_ + "/store.svg");
 
252
  res.set_uri(store_scope.to_uri());
 
253
  res["overlay-color"] = "transparent";
 
254
  reply->push(res);
 
255
}
 
256
 
 
257
 
 
258
void Query::
204
259
run(usc::SearchReplyProxy const& reply)
205
260
{
206
261
  if (!hidden_->empty())
219
274
 
220
275
  QRegExp search_query(QString::fromStdString(query().query_string()), Qt::CaseInsensitive);
221
276
  bool has_no_apps = true,
222
 
       all_filtered = true;
 
277
       all_filtered = true,
 
278
       is_hidden_dept = query().department_id() == HIDDEN_DEPT_ID;
223
279
 
224
280
  for (auto const& container: libertine->get_container_list())
225
281
  {
230
286
 
231
287
    for (auto const& app: container->app_launchers())
232
288
    {
 
289
      auto app_info = parse_app_info(app.uri());
 
290
 
 
291
      // ignore blacklisted apps
 
292
      if (blacklist_->app_is_blacklisted(app_info.app_id, container->id()))
 
293
      {
 
294
        continue;
 
295
      }
 
296
 
 
297
      // ignore hidden apps unless in hidden dept
 
298
      if ((!is_hidden_dept && hidden_->app_is_hidden(app_info.key)) ||
 
299
          (is_hidden_dept && !hidden_->app_is_hidden(app_info.key)))
 
300
      {
 
301
        continue;
 
302
      }
 
303
 
233
304
      has_no_apps = false;
 
305
 
234
306
      if (!(search_query.isEmpty() || QString::fromStdString(app.name()).contains(search_query)))
235
307
      {
236
308
        continue;
237
309
      }
238
310
 
239
 
      auto app_info = parse_app_info(app.uri());
240
 
 
241
 
      if (blacklist_->app_is_blacklisted(app_info.app_id, container->id()))
242
 
      {
243
 
        continue;
244
 
      }
245
 
 
246
311
      if (excludes_by_filter.contains(app_info.key))
247
312
      {
248
313
        continue;
249
314
      }
250
315
 
251
 
      // ignore hidden apps in root department
252
 
      if (query().department_id().empty() || query().department_id() == ROOT_DEPT_ID)
253
 
      {
254
 
        if (hidden_->app_is_hidden(app_info.key))
255
 
        {
256
 
          continue;
257
 
        }
258
 
      }
259
 
      else if (!hidden_->app_is_hidden(app_info.key))
260
 
      {
261
 
        continue;
262
 
      }
263
 
 
264
316
      usc::CategorisedResult result(category);
265
317
      result.set_title(app.name());
266
318
      result.set_art(app.icon());
267
319
      result.set_uri(app.uri());
268
320
      result[DESCRIPTION_FIELD] = app.description();
269
321
      result[APP_ID_FIELD] = app_info.key.toStdString();
270
 
      result[DEPARTMENT_ID_FIELD] = (query().department_id().empty() || query().department_id() == ROOT_DEPT_ID) ? ROOT_DEPT_ID : HIDDEN_DEPT_ID;
 
322
      result[DEPARTMENT_ID_FIELD] = is_hidden_dept ? HIDDEN_DEPT_ID : ROOT_DEPT_ID;
271
323
 
272
324
      if (!reply->push(result))
273
325
      {
278
330
    }
279
331
  }
280
332
 
281
 
  if (has_no_apps)
 
333
  if (is_hidden_dept)
282
334
  {
283
 
    show_hint(reply, NO_RESULTS_HINT);
 
335
      if (has_no_apps)
 
336
      {
 
337
        show_hint(reply, NO_RESULTS_HINT);
 
338
      }
 
339
      else if (all_filtered)
 
340
      {
 
341
        show_hint(reply, ALL_RESULTS_FILTERED_HINT);
 
342
      }
284
343
  }
285
 
  else if (all_filtered)
 
344
  else
286
345
  {
287
 
    show_hint(reply, ALL_RESULTS_FILTERED_HINT);
 
346
    add_store_link(reply);
288
347
  }
289
348
}