2
* Copyright (C) 2015 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Xavi Garcia <xavi.garcia.mena@canonical.com>
19
#include <unity/scopes/qt/internal/QDepartmentImpl.h>
20
#include <unity/scopes/qt/internal/QCannedQueryImpl.h>
21
#include <unity/scopes/qt/QUtils.h>
23
#include <unity/scopes/Department.h>
24
#include <unity/scopes/CannedQuery.h>
26
#include <QtCore/QListIterator>
28
using namespace unity::scopes;
29
using namespace unity::scopes::qt;
30
using namespace unity::scopes::qt::internal;
32
namespace sc = unity::scopes;
34
QDepartmentImpl::QDepartmentImpl(QCannedQuery const& query, QString const& label)
35
: api_department_(sc::Department::create(*query.p->api_query_, label.toUtf8().data()))
39
QDepartmentImpl::QDepartmentImpl(QString const& department_id, QCannedQuery const& query, QString const& label)
41
sc::Department::create(department_id.toUtf8().data(), *query.p->api_query_, label.toUtf8().data()))
45
QDepartmentImpl::QDepartmentImpl(Department const& api_department)
46
: api_department_(new sc::Department(api_department))
50
void QDepartmentImpl::set_has_subdepartments(bool subdepartments)
52
api_department_->set_has_subdepartments(subdepartments);
55
void QDepartmentImpl::set_subdepartments(QDepartmentList const& departments)
57
DepartmentList api_list;
58
QListIterator<QSharedPointer<QDepartment const>> it(departments);
61
api_list.push_back(it.next().data()->p->api_department_);
63
api_department_->set_subdepartments(api_list);
66
void QDepartmentImpl::add_subdepartment(QDepartment::SCPtr const& department)
68
api_department_->add_subdepartment(department->p->api_department_);
71
void QDepartmentImpl::set_alternate_label(QString const& label)
73
api_department_->set_alternate_label(label.toUtf8().data());
76
QString QDepartmentImpl::alternate_label() const
78
return QString::fromUtf8(api_department_->alternate_label().c_str());
81
QString QDepartmentImpl::id() const
83
return QString::fromUtf8(api_department_->id().c_str());
86
QString QDepartmentImpl::label() const
88
return QString::fromUtf8(api_department_->label().c_str());
91
QCannedQuery QDepartmentImpl::query() const
93
return QCannedQuery(api_department_->query());
96
bool QDepartmentImpl::has_subdepartments() const
98
return api_department_->has_subdepartments();
101
QDepartmentList QDepartmentImpl::subdepartments() const
103
QDepartmentList ret_list;
104
for (auto item : api_department_->subdepartments())
106
QSharedPointer<QDepartment> qdepartment(new QDepartment(new QDepartmentImpl(*item)));
107
ret_list.push_back(qdepartment);
112
QVariantMap QDepartmentImpl::serialize() const
114
return scopeVariantMapToQVariantMap(api_department_->serialize());
117
// static QDepartment::UPtr QDepartmentImpl::create(QVariantMap const& var)
121
// static void QDepartmentImpl::validate_departments(QDepartment::SCPtr const& parent);
122
// static void QDepartmentImpl::validate_departments(QDepartment::SCPtr const& parent, QString const& current_id);
123
// static QVariantMap QDepartmentImpl::serialize_departments(QDepartment::SCPtr const& parent);
124
// static QDepartment::SCPtr QDepartmentImpl::find_subdepartment_by_id(QDepartment::SCPtr const& department, QString
128
// static void QDepartmentImpl::validate_departments(QDepartment::SCPtr const& department, std::unordered_set<QString>&