1.1.47
by Ken VanDine
Import upstream version 3.1.3 |
1 |
/*
|
2 |
* Copyright(C) 2010 Neil Jagdish Patel
|
|
3 |
* Copyright(C) 2010 Canonical Ltd.
|
|
4 |
*
|
|
5 |
* This library is free software; you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU Lesser General Public License
|
|
7 |
* version 3.0 as published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This library 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 Lesser General Public License version 3.0 for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU Lesser General Public
|
|
15 |
* License along with this library. If not, see
|
|
16 |
* <http://www.gnu.org/licenses/>.
|
|
17 |
*
|
|
18 |
* Authored by Ken VaDine <ken.vandine@canonical.com>
|
|
19 |
*/
|
|
20 |
||
21 |
[DBus (name = "com.Gwibber.Searches")] |
|
22 |
private interface SearchesInterface : Object { |
|
23 |
public abstract string Get (string id) throws GLib.IOError; |
|
24 |
public abstract string List () throws GLib.IOError; |
|
25 |
public abstract string Create (string query) throws GLib.IOError; |
|
26 |
public abstract void Delete (string id) throws GLib.IOError; |
|
27 |
public signal void Updated (string account); |
|
28 |
public signal void Created (string account); |
|
29 |
public signal void Deleted (string account); |
|
30 |
}
|
|
31 |
||
32 |
namespace Gwibber |
|
33 |
{
|
|
34 |
public class Searches : Object |
|
35 |
{
|
|
36 |
private const string searches_name = "com.Gwibber.Searches"; |
|
37 |
private const string searches_path = "/com/gwibber/Searches"; |
|
38 |
||
39 |
private SearchesInterface searches; |
|
40 |
private Gwibber.Utils utils; |
|
41 |
||
42 |
/**
|
|
43 |
Searches::is_available:
|
|
44 |
@arg0: The current state
|
|
45 |
||
46 |
Emitted when com.Gwibber.Searches availability state changes
|
|
47 |
*/
|
|
1.1.52
by Ken VanDine
Import upstream version 3.1.4+r1103 |
48 |
public signal void is_available (bool is_up); |
49 |
public signal void updated (string id); |
|
50 |
public signal void deleted (string id); |
|
51 |
public signal void created (string id); |
|
1.1.47
by Ken VanDine
Import upstream version 3.1.3 |
52 |
|
53 |
public Searches () |
|
54 |
{
|
|
55 |
try
|
|
56 |
{
|
|
57 |
searches = Bus.get_proxy_sync(BusType.SESSION, |
|
58 |
searches_name, |
|
59 |
searches_path); |
|
60 |
utils = new Gwibber.Utils(); |
|
61 |
utils.setup(searches_name); |
|
62 |
utils.available.connect(searches_available); |
|
63 |
||
64 |
searches.Updated.connect((source) => { |
|
1.1.52
by Ken VanDine
Import upstream version 3.1.4+r1103 |
65 |
search_updated (source); |
1.1.47
by Ken VanDine
Import upstream version 3.1.3 |
66 |
});
|
67 |
searches.Created.connect((source) => { |
|
1.1.52
by Ken VanDine
Import upstream version 3.1.4+r1103 |
68 |
search_created (source); |
1.1.47
by Ken VanDine
Import upstream version 3.1.3 |
69 |
});
|
70 |
searches.Deleted.connect((source) => { |
|
1.1.52
by Ken VanDine
Import upstream version 3.1.4+r1103 |
71 |
search_deleted (source); |
1.1.47
by Ken VanDine
Import upstream version 3.1.3 |
72 |
});
|
73 |
||
74 |
}
|
|
75 |
catch (GLib.IOError e) |
|
76 |
{
|
|
77 |
warning ("Unable to get Gwibber Searches: "+e.message); |
|
78 |
}
|
|
79 |
}
|
|
80 |
||
81 |
||
82 |
/**
|
|
83 |
* com.Gwibber.Searches
|
|
84 |
**/
|
|
85 |
public Gee.HashMap <string?, string?> lookup(string id) |
|
86 |
{
|
|
1.1.67
by Ken VanDine
Import upstream version 3.3.3 |
87 |
var searches_map = new Gee.HashMap <string?, string?> (); |
1.1.47
by Ken VanDine
Import upstream version 3.1.3 |
88 |
try
|
89 |
{
|
|
90 |
var result = searches.Get(id); |
|
91 |
var parser = new Json.Parser(); |
|
92 |
parser.load_from_data(result, -1); |
|
93 |
Json.Object obj = parser.get_root().get_object(); |
|
94 |
var members = obj.get_members(); |
|
95 |
foreach (string member in members) |
|
96 |
{
|
|
97 |
searches_map[member] = obj.get_string_member(member); |
|
98 |
}
|
|
99 |
}
|
|
1.1.68
by Ken VanDine
Import upstream version 3.3.4 |
100 |
catch (GLib.Error e) |
1.1.47
by Ken VanDine
Import upstream version 3.1.3 |
101 |
{
|
102 |
warning (e.message); |
|
103 |
}
|
|
1.1.67
by Ken VanDine
Import upstream version 3.3.3 |
104 |
return searches_map; |
1.1.47
by Ken VanDine
Import upstream version 3.1.3 |
105 |
}
|
106 |
||
107 |
/**
|
|
108 |
* com.Gwibber.Searches
|
|
109 |
**/
|
|
110 |
public void delete(string id) |
|
111 |
{
|
|
112 |
try
|
|
113 |
{
|
|
114 |
searches.Delete(id); |
|
115 |
}
|
|
116 |
catch (GLib.IOError e) |
|
117 |
{
|
|
118 |
warning (e.message); |
|
119 |
}
|
|
120 |
return; |
|
121 |
}
|
|
122 |
||
123 |
||
124 |
/**
|
|
125 |
* com.Gwibber.Searches
|
|
126 |
**/
|
|
127 |
public string create(string name, string query) |
|
128 |
{
|
|
1.1.52
by Ken VanDine
Import upstream version 3.1.4+r1103 |
129 |
var searches_list = list (); |
130 |
foreach (Gee.HashMap<string?, string?> s in searches_list ) |
|
131 |
{
|
|
132 |
if (s["name"] == name && s["query"] == query) |
|
133 |
{
|
|
134 |
debug ("search stream exists, updating"); |
|
135 |
updated(s["id"]); |
|
136 |
return s["id"]; |
|
137 |
}
|
|
138 |
}
|
|
139 |
||
1.1.47
by Ken VanDine
Import upstream version 3.1.3 |
140 |
try
|
141 |
{
|
|
142 |
return searches.Create("{\"query\": \"" + query + "\", \"name\": \""+ name + "\"}"); |
|
143 |
}
|
|
144 |
catch (GLib.IOError e) |
|
145 |
{
|
|
146 |
warning (e.message); |
|
147 |
return ""; |
|
148 |
}
|
|
149 |
}
|
|
150 |
||
151 |
||
152 |
/**
|
|
153 |
* com.Gwibber.Searches
|
|
154 |
**/
|
|
155 |
public List<Gee.HashMap?> list() |
|
156 |
{
|
|
1.1.67
by Ken VanDine
Import upstream version 3.3.3 |
157 |
var searches_list = new List<Gee.HashMap<string?, string?>> (); |
1.1.47
by Ken VanDine
Import upstream version 3.1.3 |
158 |
try
|
159 |
{
|
|
160 |
var result = searches.List(); |
|
161 |
var parser = new Json.Parser(); |
|
162 |
parser.load_from_data(result, -1); |
|
163 |
Json.Array nodeArray = parser.get_root().get_array(); |
|
164 |
for(int i = 0; i < nodeArray.get_length(); i++) { |
|
165 |
var searches_map = new Gee.HashMap <string?, string?> (); |
|
166 |
var members = nodeArray.get_element(i).get_object().get_members(); |
|
167 |
foreach (string member in members) |
|
168 |
{
|
|
169 |
searches_map[member] = nodeArray.get_element(i).get_object().get_string_member(member); |
|
170 |
}
|
|
171 |
searches_list.append(searches_map); |
|
172 |
}
|
|
173 |
}
|
|
1.1.68
by Ken VanDine
Import upstream version 3.3.4 |
174 |
catch (GLib.Error e) |
1.1.47
by Ken VanDine
Import upstream version 3.1.3 |
175 |
{
|
176 |
warning (e.message); |
|
177 |
}
|
|
1.1.67
by Ken VanDine
Import upstream version 3.3.3 |
178 |
return searches_list; |
1.1.47
by Ken VanDine
Import upstream version 3.1.3 |
179 |
}
|
180 |
||
181 |
public void search_deleted(string data) |
|
182 |
{
|
|
183 |
try { |
|
184 |
var parser = new Json.Parser(); |
|
185 |
parser.load_from_data(data, -1); |
|
186 |
var root_object = parser.get_root().get_object(); |
|
187 |
string id = root_object.get_string_member("id"); |
|
188 |
deleted(id); |
|
189 |
} catch(GLib.Error e) { |
|
190 |
warning (e.message); |
|
191 |
}
|
|
192 |
}
|
|
193 |
||
194 |
public void search_created(string data) |
|
195 |
{
|
|
196 |
try { |
|
197 |
var parser = new Json.Parser(); |
|
198 |
parser.load_from_data(data, -1); |
|
199 |
var root_object = parser.get_root().get_object(); |
|
200 |
string id = root_object.get_string_member("id"); |
|
201 |
created(id); |
|
202 |
} catch(GLib.Error e) { |
|
203 |
warning (e.message); |
|
204 |
}
|
|
205 |
}
|
|
206 |
||
1.1.52
by Ken VanDine
Import upstream version 3.1.4+r1103 |
207 |
public void search_updated(string data) |
208 |
{
|
|
209 |
try { |
|
210 |
var parser = new Json.Parser(); |
|
211 |
parser.load_from_data(data, -1); |
|
212 |
var root_object = parser.get_root().get_object(); |
|
213 |
string id = root_object.get_string_member("id"); |
|
214 |
updated(id); |
|
215 |
} catch(GLib.Error e) { |
|
216 |
warning (e.message); |
|
217 |
}
|
|
218 |
}
|
|
219 |
||
220 |
||
1.1.47
by Ken VanDine
Import upstream version 3.1.3 |
221 |
public void searches_available(bool is_up) |
222 |
{
|
|
223 |
is_available(is_up); |
|
224 |
}
|
|
225 |
}
|
|
226 |
}
|