~unity-team/unity-scope-click/devel

« back to all changes in this revision

Viewing changes to scope/clickapps/apps-query.cpp

  • Committer: Tarmac
  • Author(s): Pawel Stolowski
  • Date: 2014-08-19 16:43:51 UTC
  • mfrom: (385.4.5 sort-departments)
  • Revision ID: tarmac-20140819164351-ee8bdtm0777613l7
Sort departments alphabetically.

Approved by Rodney Dawes, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
#include <unity/scopes/Department.h>
41
41
 
42
42
#include <vector>
 
43
#include <locale>
43
44
 
44
45
#include <click/click-i18n.h>
45
46
#include "apps-query.h"
317
318
        auto name = current_dep_id == "" ? all_dept_name : impl->depts_db->get_department_name(current_dep_id, locales);
318
319
        unity::scopes::Department::SPtr current = unity::scopes::Department::create(current_dep_id, query(), name);
319
320
 
 
321
        unity::scopes::DepartmentList children;
 
322
 
320
323
        // attach subdepartments to it
321
324
        for (auto const& subdep: impl->depts_db->get_children_departments(current_dep_id))
322
325
        {
356
359
                    name = impl->depts_db->get_department_name(subdep.id, locales);
357
360
                    unity::scopes::Department::SPtr dep = unity::scopes::Department::create(subdep.id, query(), name);
358
361
                    dep->set_has_subdepartments(subdep.has_children);
359
 
                    current->add_subdepartment(dep);
 
362
                    children.push_back(dep);
360
363
                }
361
364
                catch (const std::exception &e)
362
365
                {
365
368
            }
366
369
        }
367
370
 
 
371
        if (children.size() > 0)
 
372
        {
 
373
            const std::locale loc("");
 
374
            children.sort([&loc](const unity::scopes::Department::SCPtr &d1, const unity::scopes::Department::SCPtr &d2) -> bool {
 
375
                    return loc(d1->label(), d2->label()) > 0;
 
376
                });
 
377
            current->set_subdepartments(children);
 
378
        }
 
379
 
368
380
        // if current is not the top, then gets its parent
369
381
        if (current_dep_id != "")
370
382
        {