~xavi-garcia-mena/unity-scopes-api/utils-qt

« back to all changes in this revision

Viewing changes to src/scopes/qt/internal/QResultImpl.cpp

  • Committer: Xavi Garcia
  • Date: 2015-01-20 13:59:36 UTC
  • Revision ID: xavi.garcia.mena@canonical.com-20150120135936-cogxk8ok7g0gvo8g
Added Qt-bindings classes

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2015 Canonical Ltd
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 *
 
16
 * Authored by: Xavi Garcia <xavi.garcia.mena@canonical.com>
 
17
 */
 
18
 
 
19
#include <unity/scopes/qt/internal/QResultImpl.h>
 
20
 
 
21
#include <unity/scopes/qt/QResult.h>
 
22
#include <unity/scopes/qt/QScopeVariant.h>
 
23
#include <unity/scopes/qt/QUtils.h>
 
24
 
 
25
#include <unity/scopes/Result.h>
 
26
 
 
27
using namespace unity::scopes;
 
28
using namespace unity::scopes::qt;
 
29
using namespace unity::scopes::qt::internal;
 
30
 
 
31
class APIResult : public Result
 
32
{
 
33
public:
 
34
    APIResult(APIResult const& other)
 
35
        : Result(other){};
 
36
 
 
37
    APIResult(APIResult&&) = default;
 
38
 
 
39
    APIResult& operator=(APIResult const& other)
 
40
    {
 
41
        if (this != &other)
 
42
        {
 
43
            *this = other;
 
44
        }
 
45
        return *this;
 
46
    }
 
47
 
 
48
    APIResult& operator=(APIResult&&) = default;
 
49
 
 
50
    APIResult(const VariantMap& variant_map)
 
51
        : Result(variant_map){};
 
52
 
 
53
    static VariantMap getValidEmptyMap()
 
54
    {
 
55
        VariantMap retMap;
 
56
        VariantMap emptyMap;
 
57
        VariantMap attrsMap;
 
58
 
 
59
        attrsMap["uri"] = Variant(std::string());
 
60
        retMap["internal"] = emptyMap;
 
61
        retMap["attrs"] = attrsMap;
 
62
 
 
63
        return retMap;
 
64
    }
 
65
};
 
66
 
 
67
QResultImpl::QResultImpl(unity::scopes::Result* api_result)
 
68
    : api_result_(api_result)
 
69
{
 
70
}
 
71
 
 
72
QResultImpl::QResultImpl(const VariantMap& variant_map)
 
73
    : api_result_(new APIResult(variant_map))
 
74
{
 
75
}
 
76
 
 
77
QResultImpl::QResultImpl(internal::QResultImpl* impl)
 
78
    : api_result_(impl->api_result_.get())
 
79
{
 
80
}
 
81
 
 
82
QResultImpl::QResultImpl(QResultImpl const& other)
 
83
    : api_result_(other.api_result_.get())
 
84
{
 
85
}
 
86
 
 
87
QResultImpl::QResultImpl(unity::scopes::Result const& other)
 
88
    : api_result_(new Result(other))
 
89
{
 
90
}
 
91
 
 
92
QResultImpl::~QResultImpl() = default;
 
93
 
 
94
void QResultImpl::store(QResult const& other, bool intercept_activation)
 
95
{
 
96
    api_result_->store(*other.p->api_result_, intercept_activation);
 
97
}
 
98
 
 
99
bool QResultImpl::has_stored_result() const
 
100
{
 
101
    return api_result_->has_stored_result();
 
102
}
 
103
 
 
104
QResult QResultImpl::retrieve() const
 
105
{
 
106
    return QResult(api_result_->retrieve().serialize());
 
107
}
 
108
 
 
109
void QResultImpl::set_uri(QString const& uri)
 
110
{
 
111
    api_result_->set_uri(uri.toUtf8().data());
 
112
}
 
113
 
 
114
void QResultImpl::set_title(QString const& title)
 
115
{
 
116
    api_result_->set_title(title.toUtf8().data());
 
117
}
 
118
 
 
119
void QResultImpl::set_art(QString const& image)
 
120
{
 
121
    api_result_->set_art(image.toUtf8().data());
 
122
}
 
123
 
 
124
void QResultImpl::set_dnd_uri(QString const& dnd_uri)
 
125
{
 
126
    api_result_->set_dnd_uri(dnd_uri.toUtf8().data());
 
127
}
 
128
 
 
129
void QResultImpl::set_intercept_activation()
 
130
{
 
131
    api_result_->set_intercept_activation();
 
132
}
 
133
 
 
134
bool QResultImpl::direct_activation() const
 
135
{
 
136
    return api_result_->direct_activation();
 
137
}
 
138
 
 
139
ScopeProxy QResultImpl::target_scope_proxy() const
 
140
{
 
141
    return api_result_->target_scope_proxy();
 
142
}
 
143
 
 
144
QScopeVariant& QResultImpl::operator[](QString const& key)
 
145
{
 
146
    QScopeVariant qVariant(&((*api_result_)[key.toUtf8().data()]));
 
147
    return_variants[key] = qVariant;
 
148
    return return_variants[key];
 
149
}
 
150
 
 
151
QVariant const& QResultImpl::operator[](QString const& key) const
 
152
{
 
153
    QVariant ret = scopeVariantToQVariant((*api_result_)[key.toUtf8().data()]);
 
154
    return_const_variants[key] = ret;
 
155
    return return_const_variants[key];
 
156
}
 
157
 
 
158
QString QResultImpl::uri() const noexcept
 
159
{
 
160
    return QString::fromUtf8(api_result_->uri().c_str());
 
161
}
 
162
 
 
163
QString QResultImpl::title() const noexcept
 
164
{
 
165
    return QString::fromUtf8(api_result_->title().c_str());
 
166
}
 
167
 
 
168
QString QResultImpl::art() const noexcept
 
169
{
 
170
    return QString::fromUtf8(api_result_->art().c_str());
 
171
}
 
172
 
 
173
QString QResultImpl::dnd_uri() const noexcept
 
174
{
 
175
    return QString::fromUtf8(api_result_->dnd_uri().c_str());
 
176
}
 
177
 
 
178
bool QResultImpl::contains(QString const& key) const
 
179
{
 
180
    return api_result_->contains(key.toUtf8().data());
 
181
}
 
182
 
 
183
QVariant const& QResultImpl::value(QString const& key) const
 
184
{
 
185
    QVariant ret = scopeVariantToQVariant(api_result_->value(key.toUtf8().data()));
 
186
    return_const_variants[key] = ret;
 
187
    return return_const_variants[key];
 
188
}
 
189
 
 
190
VariantMap QResultImpl::serialize() const
 
191
{
 
192
    return api_result_->serialize();
 
193
}