[gnome-news] tracker: make adding channels an asynchronous operation
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-news] tracker: make adding channels an asynchronous operation
- Date: Mon, 7 Nov 2016 12:07:10 +0000 (UTC)
commit 83e7232dc64cd2d999e54a5def001f11ed03fd7a
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Mon Nov 7 09:50:59 2016 -0200
tracker: make adding channels an asynchronous operation
gnomenews/tracker.py | 27 ++++++++++++++++++++++++---
1 files changed, 24 insertions(+), 3 deletions(-)
---
diff --git a/gnomenews/tracker.py b/gnomenews/tracker.py
index a17d4b1..c6feeb3 100644
--- a/gnomenews/tracker.py
+++ b/gnomenews/tracker.py
@@ -107,22 +107,43 @@ class Tracker(GObject.GObject):
return ret[0]
@log
- def add_channel(self, url, update_interval=30):
+ def add_channel(self, url, update_interval=30, cancellable=None, callback=None, user_data=None):
"""Add channel to fetching by tracker
Args:
url (str): URL of the channel.
update_interval (Optional[int]): Update interval in minutes.
Don't use less than 1 minute.
+ cancellable (Optional[Gio.Cancellable]): Optional Gio.Cancellable
+ callback (Optional[callable]): Optional callback for when the operation
+ is finished
+ user_data (Optional[object]): Data to the callback
"""
- self.sparql.update("""
+
+ query = """
INSERT {
_:FeedSettings a mfo:FeedSettings ;
mfo:updateInterval %i .
_:Feed a nie:DataObject, mfo:FeedChannel ;
mfo:feedSettings _:FeedSettings ;
nie:url "%s" }
- """ % (update_interval, url), GLib.PRIORITY_DEFAULT, None)
+ """ % (update_interval, url)
+
+ self.sparql.update_async(query, GLib.PRIORITY_DEFAULT, cancellable,
+ self._channel_added_cb, (callback, user_data))
+
+ @log
+ def _channel_added_cb(self, connection, result, data):
+
+ (callback, user_data) = data
+
+ try:
+ result = connection.update_finish(result)
+ except GLib.Error:
+ result = False
+
+ if callback:
+ callback(user_data)
@log
def mark_post_as_read(self, url, data=None):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]