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/QResultImpl.h>
21
#include <unity/scopes/qt/QResult.h>
22
#include <unity/scopes/qt/QScopeVariant.h>
23
#include <unity/scopes/qt/QUtils.h>
25
#include <unity/scopes/Result.h>
27
using namespace unity::scopes;
28
using namespace unity::scopes::qt;
29
using namespace unity::scopes::qt::internal;
31
class APIResult : public Result
34
APIResult(APIResult const& other)
37
APIResult(APIResult&&) = default;
39
APIResult& operator=(APIResult const& other)
48
APIResult& operator=(APIResult&&) = default;
50
APIResult(const VariantMap& variant_map)
51
: Result(variant_map){};
53
static VariantMap getValidEmptyMap()
59
attrsMap["uri"] = Variant(std::string());
60
retMap["internal"] = emptyMap;
61
retMap["attrs"] = attrsMap;
67
QResultImpl::QResultImpl(unity::scopes::Result* api_result)
68
: api_result_(api_result)
72
QResultImpl::QResultImpl(const VariantMap& variant_map)
73
: api_result_(new APIResult(variant_map))
77
QResultImpl::QResultImpl(internal::QResultImpl* impl)
78
: api_result_(impl->api_result_.get())
82
QResultImpl::QResultImpl(QResultImpl const& other)
83
: api_result_(other.api_result_.get())
87
QResultImpl::QResultImpl(unity::scopes::Result const& other)
88
: api_result_(new Result(other))
92
QResultImpl::~QResultImpl() = default;
94
void QResultImpl::store(QResult const& other, bool intercept_activation)
96
api_result_->store(*other.p->api_result_, intercept_activation);
99
bool QResultImpl::has_stored_result() const
101
return api_result_->has_stored_result();
104
QResult QResultImpl::retrieve() const
106
return QResult(api_result_->retrieve().serialize());
109
void QResultImpl::set_uri(QString const& uri)
111
api_result_->set_uri(uri.toUtf8().data());
114
void QResultImpl::set_title(QString const& title)
116
api_result_->set_title(title.toUtf8().data());
119
void QResultImpl::set_art(QString const& image)
121
api_result_->set_art(image.toUtf8().data());
124
void QResultImpl::set_dnd_uri(QString const& dnd_uri)
126
api_result_->set_dnd_uri(dnd_uri.toUtf8().data());
129
void QResultImpl::set_intercept_activation()
131
api_result_->set_intercept_activation();
134
bool QResultImpl::direct_activation() const
136
return api_result_->direct_activation();
139
ScopeProxy QResultImpl::target_scope_proxy() const
141
return api_result_->target_scope_proxy();
144
QScopeVariant& QResultImpl::operator[](QString const& key)
146
QScopeVariant qVariant(&((*api_result_)[key.toUtf8().data()]));
147
return_variants[key] = qVariant;
148
return return_variants[key];
151
QVariant const& QResultImpl::operator[](QString const& key) const
153
QVariant ret = scopeVariantToQVariant((*api_result_)[key.toUtf8().data()]);
154
return_const_variants[key] = ret;
155
return return_const_variants[key];
158
QString QResultImpl::uri() const noexcept
160
return QString::fromUtf8(api_result_->uri().c_str());
163
QString QResultImpl::title() const noexcept
165
return QString::fromUtf8(api_result_->title().c_str());
168
QString QResultImpl::art() const noexcept
170
return QString::fromUtf8(api_result_->art().c_str());
173
QString QResultImpl::dnd_uri() const noexcept
175
return QString::fromUtf8(api_result_->dnd_uri().c_str());
178
bool QResultImpl::contains(QString const& key) const
180
return api_result_->contains(key.toUtf8().data());
183
QVariant const& QResultImpl::value(QString const& key) const
185
QVariant ret = scopeVariantToQVariant(api_result_->value(key.toUtf8().data()));
186
return_const_variants[key] = ret;
187
return return_const_variants[key];
190
VariantMap QResultImpl::serialize() const
192
return api_result_->serialize();