291
291
searchReply->push(res);
294
void click::apps::Query::push_local_departments(scopes::SearchReplyProxy const& replyProxy)
294
void click::apps::Query::push_local_departments(scopes::SearchReplyProxy const& replyProxy, const std::vector<Application>& apps)
296
296
auto const current_dep_id = query().department_id();
297
297
const std::list<std::string> locales = { search_metadata().locale(), "en_US" };
300
// create helper lookup of all departments of currently installed apps.
301
// note that apps that are passed here are supposed to be already filterd by current department
302
// that means we only have subdepartments of current department (or subdepartment(s) of subdepartment(s)
303
// and so on of current department, as the hierarchy may be of arbitrary depth.
304
std::unordered_set<std::string> all_subdepartments;
305
for (auto const app: apps)
307
all_subdepartments.insert(app.real_department);
299
310
unity::scopes::Department::SPtr root;
309
320
// attach subdepartments to it
310
321
for (auto const& subdep: impl->depts_db->get_children_departments(current_dep_id))
312
// if single supdepartment fails, then ignore it and continue with others
315
name = impl->depts_db->get_department_name(subdep.id, locales);
316
unity::scopes::Department::SPtr dep = unity::scopes::Department::create(subdep.id, query(), name);
317
dep->set_has_subdepartments(subdep.has_children);
318
current->add_subdepartment(dep);
320
catch (const std::exception &e)
322
qWarning() << "Failed to create subdeparment:" << QString::fromStdString(e.what());
324
// check if this subdepartment either directly matches a subdepartment of installed app,
325
// or is any of the departments of installed apps is a descendant of current subdepartment.
326
// the latter means we have app somewhere in the subtree of the current subdepartment, so it
327
// needs to be shown.
328
bool show_subdepartment = false;
329
auto it = all_subdepartments.find(subdep.id);
330
if (it != all_subdepartments.end())
332
// subdepartment id matches directly one of the ids from all_subdepartments
333
show_subdepartment = true;
334
all_subdepartments.erase(it);
338
// no direct match - we need to check descendants of this subdepartment
339
// by querying the db
340
for (auto it = all_subdepartments.begin(); it != all_subdepartments.end(); it++)
342
if (impl->depts_db->is_descendant_of_department(*it, subdep.id))
344
show_subdepartment = true;
345
all_subdepartments.erase(it);
351
if (show_subdepartment)
353
// if single supdepartment fails, then ignore it and continue with others
356
name = impl->depts_db->get_department_name(subdep.id, locales);
357
unity::scopes::Department::SPtr dep = unity::scopes::Department::create(subdep.id, query(), name);
358
dep->set_has_subdepartments(subdep.has_children);
359
current->add_subdepartment(dep);
361
catch (const std::exception &e)
363
qWarning() << "Failed to create subdeparment:" << QString::fromStdString(e.what());