1276.2.8
by Neil Jagdish Patel
a mid-point commit |
1 |
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
|
2 |
/*
|
|
3 |
* Copyright (C) 2011 Canonical Ltd
|
|
4 |
*
|
|
5 |
* This program is free software: you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License version 3 as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16 |
*
|
|
17 |
* Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
|
|
18 |
*/
|
|
19 |
||
1276.2.12
by Neil Jagdish Patel
Clean up Model implementation and add tests, incliding support for testing dbus-based services |
20 |
#include "Result.h" |
1276.2.43
by Neil Jagdish Patel
Put the accessing of DeeModelIters inside the RowAdaptorBase class and use sigc::bind to manipulate those functions for getters - excellent idea by Tim |
21 |
#include <sigc++/bind.h> |
3008.2.34
by Nick Dedekind
Fixed preview action not sending action id. Check string pointers in Result::FromVariant |
22 |
#include "GLibWrapper.h" |
1276.2.8
by Neil Jagdish Patel
a mid-point commit |
23 |
|
1276.2.19
by Neil Jagdish Patel
update to coding style |
24 |
namespace unity |
25 |
{
|
|
26 |
namespace dash |
|
27 |
{
|
|
1276.2.8
by Neil Jagdish Patel
a mid-point commit |
28 |
|
3008.2.1
by Nick Dedekind
100 scopes work |
29 |
namespace
|
30 |
{
|
|
31 |
enum ResultColumn |
|
32 |
{
|
|
33 |
URI, |
|
34 |
ICON_HINT, |
|
35 |
CATEGORY, |
|
36 |
RESULT_TYPE, |
|
37 |
MIMETYPE, |
|
38 |
TITLE, |
|
39 |
COMMENT, |
|
40 |
DND_URI, |
|
41 |
METADATA
|
|
42 |
};
|
|
43 |
}
|
|
44 |
||
1276.2.12
by Neil Jagdish Patel
Clean up Model implementation and add tests, incliding support for testing dbus-based services |
45 |
Result::Result(DeeModel* model, |
46 |
DeeModelIter* iter, |
|
47 |
DeeModelTag* renderer_tag) |
|
1276.2.27
by Neil Jagdish Patel
clean up RowAdaptorBase |
48 |
: RowAdaptorBase(model, iter, renderer_tag) |
1276.2.8
by Neil Jagdish Patel
a mid-point commit |
49 |
{
|
1276.2.39
by Neil Jagdish Patel
Make copy constructors work |
50 |
SetupGetters(); |
51 |
}
|
|
52 |
||
53 |
Result::Result(Result const& other) |
|
1276.3.18
by Neil Jagdish Patel
use default copy constructor |
54 |
: RowAdaptorBase(other) |
1276.2.39
by Neil Jagdish Patel
Make copy constructors work |
55 |
{
|
56 |
SetupGetters(); |
|
57 |
}
|
|
58 |
||
1276.3.14
by Neil Jagdish Patel
Fix issues raised by Tim |
59 |
Result& Result::operator=(Result const& other) |
1276.3.5
by Neil Jagdish Patel
Lens search tests |
60 |
{
|
1276.3.17
by Neil Jagdish Patel
[merge] parent and fix issues related to that |
61 |
RowAdaptorBase::operator=(other); |
62 |
SetupGetters(); |
|
1276.3.14
by Neil Jagdish Patel
Fix issues raised by Tim |
63 |
return *this; |
1276.3.5
by Neil Jagdish Patel
Lens search tests |
64 |
}
|
65 |
||
1276.2.39
by Neil Jagdish Patel
Make copy constructors work |
66 |
void Result::SetupGetters() |
67 |
{
|
|
2950.2.3
by Nick Dedekind
Better testability of dee model rows. |
68 |
uri.SetGetterFunction(sigc::mem_fun(this, &Result::GetURI)); |
69 |
icon_hint.SetGetterFunction(sigc::mem_fun(this, &Result::GetIconHint)); |
|
70 |
category_index.SetGetterFunction(sigc::mem_fun(this, &Result::GetCategoryIndex)); |
|
3008.2.1
by Nick Dedekind
100 scopes work |
71 |
result_type.SetGetterFunction(sigc::mem_fun(this, &Result::GetResultType)); |
2950.2.3
by Nick Dedekind
Better testability of dee model rows. |
72 |
mimetype.SetGetterFunction(sigc::mem_fun(this, &Result::GetMimeType)); |
73 |
name.SetGetterFunction(sigc::mem_fun(this, &Result::GetName)); |
|
74 |
comment.SetGetterFunction(sigc::mem_fun(this, &Result::GetComment)); |
|
75 |
dnd_uri.SetGetterFunction(sigc::mem_fun(this, &Result::GetDndURI)); |
|
3008.2.42
by Nick Dedekind
More unit tests |
76 |
hints.SetGetterFunction(sigc::mem_fun(this, &Result::GetHints)); |
1276.2.8
by Neil Jagdish Patel
a mid-point commit |
77 |
}
|
2950.2.3
by Nick Dedekind
Better testability of dee model rows. |
78 |
|
3008.2.1
by Nick Dedekind
100 scopes work |
79 |
std::string Result::GetURI() const { return GetStringAt(ResultColumn::URI); } |
80 |
std::string Result::GetIconHint() const { return GetStringAt(ResultColumn::ICON_HINT); } |
|
3008.2.7
by Nick Dedekind
Fixed 64bit size_t->unsigned int conversion. |
81 |
unsigned Result::GetCategoryIndex() const { return GetUIntAt(ResultColumn::CATEGORY); } |
3008.2.1
by Nick Dedekind
100 scopes work |
82 |
unsigned Result::GetResultType() const { return GetUIntAt(ResultColumn::RESULT_TYPE); } |
83 |
std::string Result::GetMimeType() const { return GetStringAt(ResultColumn::MIMETYPE); } |
|
84 |
std::string Result::GetName() const { return GetStringAt(ResultColumn::TITLE); } |
|
85 |
std::string Result::GetComment() const { return GetStringAt(ResultColumn::COMMENT); } |
|
86 |
std::string Result::GetDndURI() const { return GetStringAt(ResultColumn::DND_URI); } |
|
3008.2.22
by Nick Dedekind
New libunity scope API. |
87 |
glib::HintsMap Result::GetHints() const |
88 |
{
|
|
89 |
glib::HintsMap hints; |
|
90 |
GetVariantAt(ResultColumn::METADATA).ASVToHints(hints); |
|
91 |
return hints; |
|
92 |
}
|
|
93 |
||
94 |
LocalResult::LocalResult() |
|
95 |
{
|
|
96 |
}
|
|
97 |
||
98 |
LocalResult::LocalResult(LocalResult const& other) |
|
99 |
{
|
|
100 |
operator=(other); |
|
101 |
}
|
|
102 |
||
103 |
LocalResult::LocalResult(Result const& result) |
|
104 |
{
|
|
105 |
operator=(result); |
|
106 |
}
|
|
107 |
||
108 |
LocalResult& LocalResult::operator=(Result const& rhs) |
|
109 |
{
|
|
110 |
uri = rhs.uri; |
|
111 |
icon_hint = rhs.icon_hint; |
|
112 |
category_index = rhs.category_index; |
|
113 |
result_type = rhs.result_type; |
|
114 |
mimetype = rhs.mimetype; |
|
115 |
name = rhs.name; |
|
116 |
comment = rhs.comment; |
|
117 |
dnd_uri = rhs.dnd_uri; |
|
118 |
hints = rhs.hints; |
|
119 |
||
120 |
return *this; |
|
121 |
}
|
|
122 |
||
123 |
LocalResult& LocalResult::operator=(LocalResult const& rhs) |
|
124 |
{
|
|
125 |
if (this == &rhs) |
|
126 |
return *this; |
|
127 |
||
128 |
uri = rhs.uri; |
|
129 |
icon_hint = rhs.icon_hint; |
|
130 |
category_index = rhs.category_index; |
|
131 |
result_type = rhs.result_type; |
|
132 |
mimetype = rhs.mimetype; |
|
133 |
name = rhs.name; |
|
134 |
comment = rhs.comment; |
|
135 |
dnd_uri = rhs.dnd_uri; |
|
136 |
hints = rhs.hints; |
|
137 |
||
138 |
return *this; |
|
139 |
}
|
|
140 |
||
141 |
bool LocalResult::operator==(LocalResult const& rhs) const |
|
142 |
{
|
|
143 |
return uri == rhs.uri; |
|
144 |
}
|
|
145 |
||
146 |
bool LocalResult::operator!=(LocalResult const& rhs) const |
|
147 |
{
|
|
148 |
return !(operator==(rhs)); |
|
149 |
}
|
|
150 |
||
151 |
std::vector<glib::Variant> LocalResult::Variants() const |
|
152 |
{
|
|
153 |
std::vector<glib::Variant> vars; |
|
154 |
vars.push_back(g_variant_new_string(uri.c_str())); |
|
155 |
vars.push_back(g_variant_new_string(icon_hint.c_str())); |
|
156 |
vars.push_back(g_variant_new_uint32(category_index)); |
|
157 |
vars.push_back(g_variant_new_uint32(result_type)); |
|
158 |
vars.push_back(g_variant_new_string(mimetype.c_str())); |
|
159 |
vars.push_back(g_variant_new_string(name.c_str())); |
|
160 |
vars.push_back(g_variant_new_string(comment.c_str())); |
|
161 |
vars.push_back(g_variant_new_string(dnd_uri.c_str())); |
|
162 |
vars.push_back(glib::Variant::FromHints(hints)); |
|
163 |
||
164 |
return vars; |
|
165 |
}
|
|
166 |
||
167 |
glib::Variant LocalResult::Variant() const |
|
168 |
{
|
|
169 |
GVariantBuilder b; |
|
170 |
g_variant_builder_init(&b, G_VARIANT_TYPE("av")); |
|
171 |
||
172 |
std::vector<glib::Variant> vars = Variants(); |
|
173 |
for (glib::Variant const& v : vars) |
|
174 |
{
|
|
3008.2.50
by Nick Dedekind
fixed code review comments |
175 |
g_variant_builder_add(&b, "v", (GVariant*)v); |
3008.2.22
by Nick Dedekind
New libunity scope API. |
176 |
}
|
177 |
||
178 |
return g_variant_builder_end(&b); |
|
179 |
}
|
|
180 |
||
181 |
LocalResult LocalResult::FromVariant(glib::Variant const& v) |
|
182 |
{
|
|
183 |
GVariantIter* var_iter; |
|
184 |
GVariant* value = NULL; |
|
185 |
||
186 |
if (!v || !g_variant_is_of_type (v, G_VARIANT_TYPE ("av"))) |
|
187 |
{
|
|
188 |
return LocalResult(); |
|
189 |
}
|
|
190 |
||
191 |
g_variant_get(v, g_variant_get_type_string(v), &var_iter); |
|
192 |
||
193 |
int i = 0; |
|
194 |
std::vector<glib::Variant> vars; |
|
195 |
LocalResult result; |
|
196 |
while (g_variant_iter_loop(var_iter, "v", &value)) |
|
197 |
{
|
|
198 |
vars.push_back(value); |
|
3008.2.34
by Nick Dedekind
Fixed preview action not sending action id. Check string pointers in Result::FromVariant |
199 |
switch (i) |
3008.2.22
by Nick Dedekind
New libunity scope API. |
200 |
{
|
201 |
case URI: |
|
3008.2.34
by Nick Dedekind
Fixed preview action not sending action id. Check string pointers in Result::FromVariant |
202 |
result.uri = glib::gchar_to_string(g_variant_get_string(value, NULL)); |
3008.2.22
by Nick Dedekind
New libunity scope API. |
203 |
break; |
204 |
case ICON_HINT: |
|
3008.2.34
by Nick Dedekind
Fixed preview action not sending action id. Check string pointers in Result::FromVariant |
205 |
result.icon_hint = glib::gchar_to_string(g_variant_get_string(value, NULL)); |
3008.2.22
by Nick Dedekind
New libunity scope API. |
206 |
break; |
207 |
case CATEGORY: |
|
208 |
result.category_index = g_variant_get_uint32(value); |
|
209 |
break; |
|
210 |
case RESULT_TYPE: |
|
211 |
result.result_type = g_variant_get_uint32(value); |
|
212 |
break; |
|
213 |
case MIMETYPE: |
|
3008.2.34
by Nick Dedekind
Fixed preview action not sending action id. Check string pointers in Result::FromVariant |
214 |
result.mimetype = glib::gchar_to_string(g_variant_get_string(value, NULL)); |
3008.2.22
by Nick Dedekind
New libunity scope API. |
215 |
break; |
216 |
case TITLE: |
|
3008.2.34
by Nick Dedekind
Fixed preview action not sending action id. Check string pointers in Result::FromVariant |
217 |
result.name = glib::gchar_to_string(g_variant_get_string(value, NULL)); |
3008.2.22
by Nick Dedekind
New libunity scope API. |
218 |
break; |
219 |
case COMMENT: |
|
3008.2.34
by Nick Dedekind
Fixed preview action not sending action id. Check string pointers in Result::FromVariant |
220 |
result.comment = glib::gchar_to_string(g_variant_get_string(value, NULL)); |
3008.2.22
by Nick Dedekind
New libunity scope API. |
221 |
break; |
222 |
case DND_URI: |
|
3008.2.34
by Nick Dedekind
Fixed preview action not sending action id. Check string pointers in Result::FromVariant |
223 |
result.dnd_uri = glib::gchar_to_string(g_variant_get_string(value, NULL)); |
3008.2.22
by Nick Dedekind
New libunity scope API. |
224 |
break; |
225 |
case METADATA: |
|
226 |
glib::HintsMap hints; |
|
227 |
if (glib::Variant(value).ASVToHints(hints)) |
|
228 |
{
|
|
229 |
result.hints = hints; |
|
230 |
}
|
|
231 |
break; |
|
232 |
}
|
|
3008.2.34
by Nick Dedekind
Fixed preview action not sending action id. Check string pointers in Result::FromVariant |
233 |
i++; |
3008.2.22
by Nick Dedekind
New libunity scope API. |
234 |
}
|
235 |
g_variant_iter_free (var_iter); |
|
236 |
||
237 |
return result; |
|
238 |
}
|
|
239 |
||
240 |
void LocalResult::clear() |
|
241 |
{
|
|
242 |
uri.clear(); |
|
243 |
}
|
|
244 |
||
245 |
bool LocalResult::empty() const |
|
246 |
{
|
|
247 |
return uri.empty(); |
|
248 |
}
|
|
1276.2.8
by Neil Jagdish Patel
a mid-point commit |
249 |
|
250 |
}
|
|
251 |
}
|