Merge lp:~zeitgeist/zeitgeist/bb-extensions-conf into lp:~zeitgeist/zeitgeist/bluebird
- bb-extensions-conf
- Merge into bluebird
Proposed by
Siegfried Gevatter
Status: | Merged |
---|---|
Merged at revision: | 275 |
Proposed branch: | lp:~zeitgeist/zeitgeist/bb-extensions-conf |
Merge into: | lp:~zeitgeist/zeitgeist/bluebird |
Diff against target: |
357 lines (+204/-20) 7 files modified
extensions/blacklist.vala (+55/-18) extensions/ds-registry.vala (+7/-1) extensions/histogram.vala (+5/-0) src/Makefile.am (+1/-0) src/engine.vala (+3/-1) src/extension-store.vala (+118/-0) src/extension.vala (+15/-0) |
To merge this branch: | bzr merge lp:~zeitgeist/zeitgeist/bb-extensions-conf |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michal Hruby (community) | Approve | ||
Review via email: mp+76902@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Siegfried Gevatter (rainct) wrote : | # |
Great. Thanks for the review.
1) Changed, wasn't quite happy with get_name.
2) I'd rather not, if they really need to do something weird they can add a new function.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'extensions/blacklist.vala' |
2 | --- extensions/blacklist.vala 2011-09-24 16:04:43 +0000 |
3 | +++ extensions/blacklist.vala 2011-09-25 14:01:24 +0000 |
4 | @@ -42,6 +42,47 @@ |
5 | [DBus (signature = "s(asassay)")] Variant event_template); |
6 | } |
7 | |
8 | + namespace BlacklistTemplates |
9 | + { |
10 | + private const string SIG_BLACKLIST = "a{s("+Utils.SIG_EVENT+")}"; |
11 | + |
12 | + private static HashTable<string, Event> from_variant ( |
13 | + Variant templates_variant) |
14 | + { |
15 | + var blacklist = new HashTable<string, Event> (str_hash, str_equal); |
16 | + |
17 | + assert (templates_variant.get_type_string () == SIG_BLACKLIST); |
18 | + foreach (Variant template_variant in templates_variant) |
19 | + { |
20 | + VariantIter iter = template_variant.iterator (); |
21 | + string template_id = iter.next_value ().get_string (); |
22 | + // FIXME: throw exception upon error instead of aborting |
23 | + Event template = new Event.from_variant (iter.next_value ()); |
24 | + blacklist.insert (template_id, template); |
25 | + } |
26 | + |
27 | + return blacklist; |
28 | + } |
29 | + |
30 | + public static Variant to_variant (HashTable<string, Event> blacklist) |
31 | + { |
32 | + var vb = new VariantBuilder (new VariantType (SIG_BLACKLIST)); |
33 | + { |
34 | + var iter = HashTableIter<string, Event> (blacklist); |
35 | + string template_id; |
36 | + Event event_template; |
37 | + while (iter.next (out template_id, out event_template)) |
38 | + { |
39 | + vb.open (new VariantType ("{s("+Utils.SIG_EVENT+")}")); |
40 | + vb.add ("s", template_id); |
41 | + vb.add_value (event_template.to_variant ()); |
42 | + vb.close (); |
43 | + } |
44 | + } |
45 | + return vb.end (); |
46 | + } |
47 | + } |
48 | + |
49 | class Blacklist: Extension, RemoteBlacklist |
50 | { |
51 | private HashTable<string, Event> blacklist; |
52 | @@ -54,9 +95,13 @@ |
53 | |
54 | construct |
55 | { |
56 | - blacklist = new HashTable<string, Event> (str_hash, str_equal); |
57 | - |
58 | - // FIXME: load blacklist from file |
59 | + // Restore previous blacklist from database, or create an empty one |
60 | + Variant? templates = retrieve_config ("blacklist", |
61 | + BlacklistTemplates.SIG_BLACKLIST); |
62 | + if (templates != null) |
63 | + blacklist = BlacklistTemplates.from_variant (templates); |
64 | + else |
65 | + blacklist = new HashTable<string, Event> (str_hash, str_equal); |
66 | |
67 | // This will be called after bus is acquired, so it shouldn't block |
68 | try |
69 | @@ -71,6 +116,10 @@ |
70 | } |
71 | } |
72 | |
73 | + public override string get_name () { |
74 | + return "blacklist"; |
75 | + } |
76 | + |
77 | public override void unload () |
78 | { |
79 | try |
80 | @@ -92,7 +141,8 @@ |
81 | |
82 | private void flush () |
83 | { |
84 | - // FIXME: write to file. |
85 | + Variant v = BlacklistTemplates.to_variant (blacklist); |
86 | + store_config ("blacklist", v); |
87 | } |
88 | |
89 | public override void pre_insert_events (GenericArray<Event?> events, |
90 | @@ -130,20 +180,7 @@ |
91 | |
92 | public Variant get_templates () |
93 | { |
94 | - var vb = new VariantBuilder (new VariantType ("a{s("+Utils.SIG_EVENT+")}")); |
95 | - { |
96 | - var iter = HashTableIter<string, Event> (blacklist); |
97 | - string template_id; |
98 | - Event event_template; |
99 | - while (iter.next (out template_id, out event_template)) |
100 | - { |
101 | - vb.open (new VariantType ("{s("+Utils.SIG_EVENT+")}")); |
102 | - vb.add ("s", template_id); |
103 | - vb.add_value (event_template.to_variant ()); |
104 | - vb.close (); |
105 | - } |
106 | - } |
107 | - return vb.end (); |
108 | + return BlacklistTemplates.to_variant (blacklist); |
109 | } |
110 | |
111 | } |
112 | |
113 | === modified file 'extensions/ds-registry.vala' |
114 | --- extensions/ds-registry.vala 2011-09-16 09:15:06 +0000 |
115 | +++ extensions/ds-registry.vala 2011-09-25 14:01:24 +0000 |
116 | @@ -140,7 +140,7 @@ |
117 | var connection = Bus.get_sync (BusType.SESSION, null); |
118 | registration_id = connection.register_object<RemoteRegistry> ( |
119 | "/org/gnome/zeitgeist/data_source_registry", this); |
120 | - |
121 | + |
122 | connection.signal_subscribe ("org.freedesktop.DBus", |
123 | "org.freedesktop.DBus", "NameOwnerChanged", |
124 | "/org/freedesktop/DBus", null, 0, |
125 | @@ -199,6 +199,12 @@ |
126 | // gobject.timeout_add(DISK_WRITE_TIMEOUT, self._write_to_disk) |
127 | } |
128 | |
129 | + |
130 | + public override string get_name () |
131 | + { |
132 | + return "data-source-registry"; |
133 | + } |
134 | + |
135 | public override void unload () |
136 | { |
137 | try |
138 | |
139 | === modified file 'extensions/histogram.vala' |
140 | --- extensions/histogram.vala 2011-09-05 16:19:38 +0000 |
141 | +++ extensions/histogram.vala 2011-09-25 14:01:24 +0000 |
142 | @@ -49,6 +49,11 @@ |
143 | } |
144 | } |
145 | |
146 | + public override string get_name () |
147 | + { |
148 | + return "histogram"; |
149 | + } |
150 | + |
151 | public override void unload () |
152 | { |
153 | try |
154 | |
155 | === modified file 'src/Makefile.am' |
156 | --- src/Makefile.am 2011-09-15 17:57:10 +0000 |
157 | +++ src/Makefile.am 2011-09-25 14:01:24 +0000 |
158 | @@ -32,6 +32,7 @@ |
159 | remote.vala \ |
160 | extension.vala \ |
161 | extension-collection.vala \ |
162 | + extension-store.vala \ |
163 | notify.vala \ |
164 | sql.vala \ |
165 | utils.vala \ |
166 | |
167 | === modified file 'src/engine.vala' |
168 | --- src/engine.vala 2011-09-19 14:12:03 +0000 |
169 | +++ src/engine.vala 2011-09-25 14:01:24 +0000 |
170 | @@ -35,6 +35,7 @@ |
171 | { |
172 | |
173 | public Zeitgeist.SQLite.ZeitgeistDatabase database { get; private set; } |
174 | + public ExtensionStore extension_store; |
175 | private ExtensionCollection extension_collection; |
176 | private unowned Sqlite.Database db; |
177 | |
178 | @@ -57,6 +58,7 @@ |
179 | mimetypes_table = new TableLookup (database, "mimetype"); |
180 | actors_table = new TableLookup (database, "actor"); |
181 | |
182 | + extension_store = new ExtensionStore (this); |
183 | extension_collection = new ExtensionCollection (this); |
184 | } |
185 | |
186 | @@ -701,7 +703,7 @@ |
187 | manifestations_table.get_id (event.manifestation)); |
188 | retrieval_stmt.bind_int64 (4, actors_table.get_id (event.actor)); |
189 | |
190 | - if ((rc = retrieval_stmt.step()) != Sqlite.ROW) { |
191 | + if ((rc = retrieval_stmt.step ()) != Sqlite.ROW) { |
192 | warning ("SQL error: %d, %s\n", rc, db.errmsg ()); |
193 | return 0; |
194 | } |
195 | |
196 | === added file 'src/extension-store.vala' |
197 | --- src/extension-store.vala 1970-01-01 00:00:00 +0000 |
198 | +++ src/extension-store.vala 2011-09-25 14:01:24 +0000 |
199 | @@ -0,0 +1,118 @@ |
200 | +/* extension-store.vala |
201 | + * |
202 | + * Copyright © 2011 Collabora Ltd. |
203 | + * By Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com> |
204 | + * |
205 | + * This program is free software: you can redistribute it and/or modify |
206 | + * it under the terms of the GNU Lesser General Public License as published by |
207 | + * the Free Software Foundation, either version 2.1 of the License, or |
208 | + * (at your option) any later version. |
209 | + * |
210 | + * This program is distributed in the hope that it will be useful, |
211 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
212 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
213 | + * GNU General Public License for more details. |
214 | + * |
215 | + * You should have received a copy of the GNU Lesser General Public License |
216 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
217 | + * |
218 | + */ |
219 | + |
220 | +using Zeitgeist; |
221 | + |
222 | +namespace Zeitgeist |
223 | +{ |
224 | + public class ExtensionStore : Object |
225 | + { |
226 | + |
227 | + private Zeitgeist.SQLite.ZeitgeistDatabase database; |
228 | + private unowned Sqlite.Database db; |
229 | + private Sqlite.Statement storage_stmt; |
230 | + private Sqlite.Statement retrieval_stmt; |
231 | + |
232 | + public ExtensionStore (Zeitgeist.Engine engine) { |
233 | + database = engine.database; |
234 | + db = database.database; |
235 | + prepare_queries (); |
236 | + } |
237 | + |
238 | + private void prepare_queries () |
239 | + throws EngineError |
240 | + { |
241 | + int rc; |
242 | + string sql; |
243 | + |
244 | + // Prepare storage query |
245 | + sql = """ |
246 | + INSERT OR REPLACE INTO extensions_conf ( |
247 | + extension, key, value |
248 | + ) VALUES ( |
249 | + ?, ?, ? |
250 | + )"""; |
251 | + rc = database.database.prepare_v2 (sql, -1, out storage_stmt); |
252 | + database.assert_query_success (rc, "Storage query error"); |
253 | + |
254 | + // Prepare retrieval query |
255 | + sql = """ |
256 | + SELECT value |
257 | + FROM extensions_conf |
258 | + WHERE extension=? AND key=? |
259 | + """; |
260 | + rc = database.database.prepare_v2 (sql, -1, out retrieval_stmt); |
261 | + database.assert_query_success (rc, "Retrieval query error"); |
262 | + } |
263 | + |
264 | + /** |
265 | + * Store the given Variant under the given (extension, key) |
266 | + * identifier, replacing any previous value. |
267 | + */ |
268 | + public void store (string extension, string key, Variant data) |
269 | + { |
270 | + int rc; |
271 | + storage_stmt.reset (); |
272 | + storage_stmt.bind_text (1, extension); |
273 | + storage_stmt.bind_text (2, key); |
274 | + storage_stmt.bind_blob (3, data.get_data (), (int) data.get_size ()); |
275 | + |
276 | + if ((rc = storage_stmt.step ()) != Sqlite.DONE) |
277 | + warning ("SQL error: %d, %s", rc, db.errmsg ()); |
278 | + } |
279 | + |
280 | + /** |
281 | + * Retrieve a previously stored value. |
282 | + */ |
283 | + public Variant? retrieve(string extension, string key, VariantType format) |
284 | + { |
285 | + retrieval_stmt.reset (); |
286 | + retrieval_stmt.bind_text (1, extension); |
287 | + retrieval_stmt.bind_text (2, key); |
288 | + |
289 | + int rc = retrieval_stmt.step (); |
290 | + if (rc != Sqlite.ROW) |
291 | + { |
292 | + if (rc != Sqlite.DONE) |
293 | + warning ("SQL error: %d, %s", rc, db.errmsg ()); |
294 | + return null; |
295 | + } |
296 | + |
297 | + unowned uchar[] blob; |
298 | + blob = (uchar[]) retrieval_stmt.column_blob (0); |
299 | + blob.length = retrieval_stmt.column_bytes (0); |
300 | + |
301 | + Variant? data = null; |
302 | + if (blob != null) |
303 | + { |
304 | + ByteArray byte_array = new ByteArray.sized (blob.length); |
305 | + byte_array.append (blob); |
306 | + |
307 | + data = Variant.new_from_data<ByteArray> (format, |
308 | + byte_array.data, false, byte_array); |
309 | + } |
310 | + |
311 | + retrieval_stmt.reset (); |
312 | + return data; |
313 | + } |
314 | + |
315 | + } |
316 | +} |
317 | +// vim:expandtab:ts=4:sw=4 |
318 | |
319 | === modified file 'src/extension.vala' |
320 | --- src/extension.vala 2011-09-17 10:41:24 +0000 |
321 | +++ src/extension.vala 2011-09-25 14:01:24 +0000 |
322 | @@ -2,6 +2,8 @@ |
323 | * |
324 | * Copyright © 2011 Manish Sinha <manishsinha@ubuntu.com> |
325 | * Copyright © 2011 Michal Hruby <michal.mhr@gmail.com> |
326 | + * Copyright © 2011 Collabora Ltd. |
327 | + * By Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com> |
328 | * |
329 | * This program is free software: you can redistribute it and/or modify |
330 | * it under the terms of the GNU Lesser General Public License as published by |
331 | @@ -36,6 +38,8 @@ |
332 | { |
333 | public unowned Engine engine { get; construct set; } |
334 | |
335 | + public abstract string get_name(); |
336 | + |
337 | /** |
338 | * This method gets called before Zeitgeist stops. |
339 | * |
340 | @@ -122,6 +126,17 @@ |
341 | public virtual void post_delete_events (uint32[] ids, BusName? sender) |
342 | { |
343 | } |
344 | + |
345 | + protected void store_config (string key, Variant data) |
346 | + { |
347 | + engine.extension_store.store (get_name (), key, data); |
348 | + } |
349 | + |
350 | + protected Variant? retrieve_config (string key, string format) |
351 | + { |
352 | + VariantType type = new VariantType(format); |
353 | + return engine.extension_store.retrieve (get_name (), key, type); |
354 | + } |
355 | } |
356 | |
357 | [CCode (has_target = false)] |
1) I'd get rid of the get_name method, we can just use get_type().name()
2) if the extension needed something special, store/retrieve could be virtual
Other than that it looks fine, feel free to merge!