changeset 7e5938fe32c5 in /home/hg/repos/gajim

details:http://hg.gajim.org/gajim?cmd=changeset;node=7e5938fe32c5
description: store bookmarks in both pubsub and xml, and copy those from xml to 
pubsub on startup

diffstat:

 src/common/connection.py          |  20 +++++++++++---------
 src/common/connection_handlers.py |  36 +++++++++++++++---------------------
 src/common/pubsub.py              |  21 +++++++++++++++++++--
 3 files changed, 45 insertions(+), 32 deletions(-)

diffs (167 lines):

diff -r 6f3e3886b765 -r 7e5938fe32c5 src/common/connection.py
--- a/src/common/connection.py  Fri Jul 31 15:50:11 2009 +0200
+++ b/src/common/connection.py  Fri Jul 31 17:11:55 2009 +0200
@@ -1589,22 +1589,24 @@
                iq2.addChild(name='gajim', namespace='gajim:prefs')
                self.connection.send(iq)
 
-       def get_bookmarks(self):
+       def get_bookmarks(self, storage_type=None):
                '''Get Bookmarks from storage or PubSub if supported as 
described in
-               XEP 0048'''
-               self.bookmarks = [] #avoid multiple bookmarks when re-connecting
+               XEP 0048
+               storage_type can be set to xml to force request to xml 
storage'''
                if not self.connection:
                        return
-               if self.pubsub_supported:
-                       self.send_pb_retrieve('', 'storage:bookmarks', 
self._PrivatePubsubCB)
+               if self.pubsub_supported and storage_type != 'xml':
+                       self.send_pb_retrieve('', 'storage:bookmarks')
                else:
                        iq = common.xmpp.Iq(typ='get')
                        iq2 = iq.addChild(name='query', 
namespace=common.xmpp.NS_PRIVATE)
                        iq2.addChild(name='storage', 
namespace='storage:bookmarks')
                        self.connection.send(iq)
 
-       def store_bookmarks(self):
-               ''' Send bookmarks to the storage namespace or PubSub if 
supported'''
+       def store_bookmarks(self, storage_type=None):
+               ''' Send bookmarks to the storage namespace or PubSub if 
supported
+               storage_type can be set to 'pubsub' or 'xml' so store in only 
one method
+               else it will be stored on both'''
                if not self.connection:
                        return
                iq = common.xmpp.Node(tag='storage', attrs={'xmlns': 
'storage:bookmarks'})
@@ -1624,7 +1626,7 @@
                        if bm.get('print_status', None):
                                iq2.setTagData('print_status', 
bm['print_status'])
 
-               if self.pubsub_supported:
+               if self.pubsub_supported and storage_type != 'xml':
                        if self.pubsub_publish_options_supported:
                                options = common.xmpp.Node(common.xmpp.NS_DATA 
+ ' x',
                                        attrs={'type': 'submit'})
@@ -1639,7 +1641,7 @@
                                options = None
                        self.send_pb_publish('', 'storage:bookmarks', iq, 
'current',
                                options=options)
-               else:
+               if storage_type != 'pubsub':
                        iqA = common.xmpp.Iq(typ='set')
                        iqB = iqA.addChild(name='query', 
namespace=common.xmpp.NS_PRIVATE)
                        iqB.addChild(node=iq)
diff -r 6f3e3886b765 -r 7e5938fe32c5 src/common/connection_handlers.py
--- a/src/common/connection_handlers.py Fri Jul 31 15:50:11 2009 +0200
+++ b/src/common/connection_handlers.py Fri Jul 31 17:11:55 2009 +0200
@@ -1529,7 +1529,7 @@
                if storage:
                        ns = storage.getNamespace()
                        if ns == 'storage:bookmarks':
-                               self._parse_bookmarks(storage)
+                               self._parse_bookmarks(storage, 'xml')
                        elif ns == 'gajim:prefs':
                                # Preferences data
                                # http://www.xmpp.org/extensions/xep-0049.html
@@ -1548,27 +1548,12 @@
                                        annotation = note.getData()
                                        self.annotations[jid] = annotation
 
-       def _PrivatePubsubCB(self, conn, request):
-               '''Private data from PubSub'''
-               gajim.log.debug('_PrivatePubsubCB')
-               pubsub = request.getTag('pubsub')
-               if not pubsub:
-                       return
-               items = pubsub.getTag('items')
-               if not items:
-                       return
-               item = items.getTag('item')
-               if not item:
-                       return
-               storage = item.getTag('storage')
-               if storage:
-                       ns = storage.getNamespace()
-                       if ns == 'storage:bookmarks':
-                               self._parse_bookmarks(storage)
-
-       def _parse_bookmarks(self, storage):
+       def _parse_bookmarks(self, storage, storage_type):
+               '''storage_type can be 'pubsub' or 'xml' to tell from where we 
got
+               bookmarks'''
                # Bookmarked URLs and Conferences
                # http://www.xmpp.org/extensions/xep-0048.html
+               resend_to_pubsub = False
                confs = storage.getTags('conference')
                for conf in confs:
                        autojoin_val = conf.getAttr('autojoin')
@@ -1592,8 +1577,17 @@
                                log.warn('Invalid JID: %s, ignoring it' % 
conf.getAttr('jid'))
                                continue
 
-                       self.bookmarks.append(bm)
+                       if bm not in self.bookmarks:
+                               self.bookmarks.append(bm)
+                               if storage_type == 'xml':
+                                       # We got a bookmark that was not in 
pubsub
+                                       resend_to_pubsub = True
                self.dispatch('BOOKMARKS', self.bookmarks)
+               if storage_type == 'pubsub':
+                       # We gor bookmarks from pubsub, now get those from xml 
to merge them
+                       self.get_bookmarks(storage_type='xml')
+               if self.pubsub_supported and resend_to_pubsub:
+                       self.store_bookmarks('pubsub')
 
        def _rosterSetCB(self, con, iq_obj):
                log.debug('rosterSetCB')
diff -r 6f3e3886b765 -r 7e5938fe32c5 src/common/pubsub.py
--- a/src/common/pubsub.py      Fri Jul 31 15:50:11 2009 +0200
+++ b/src/common/pubsub.py      Fri Jul 31 17:11:55 2009 +0200
@@ -78,7 +78,7 @@
 
                self.connection.send(query)
 
-       def send_pb_retrieve(self, jid, node, cb, *args, **kwargs): 
+       def send_pb_retrieve(self, jid, node, cb=None, *args, **kwargs): 
                '''Get items from a node''' 
                if not self.connection or self.connected < 2: 
                        return 
@@ -87,7 +87,8 @@
                r = r.addChild('items', {'node': node}) 
                id_ = self.connection.send(query)
 
-               self.__callbacks[id_]=(cb, args, kwargs)
+               if cb:
+                       self.__callbacks[id_]=(cb, args, kwargs)
 
        def send_pb_retract(self, jid, node, id_):
                '''Delete item from a node'''
@@ -143,12 +144,28 @@
                self.connection.send(query)
 
        def _PubSubCB(self, conn, stanza):
+               gajim.log.debug('_PubsubCB')
                try:
                        cb, args, kwargs = self.__callbacks.pop(stanza.getID())
                        cb(conn, stanza, *args, **kwargs)
                except Exception:
                        pass
 
+               pubsub = stanza.getTag('pubsub')
+               if not pubsub:
+                       return
+               items = pubsub.getTag('items')
+               if not items:
+                       return
+               item = items.getTag('item')
+               if not item:
+                       return
+               storage = item.getTag('storage')
+               if storage:
+                       ns = storage.getNamespace()
+                       if ns == 'storage:bookmarks':
+                               self._parse_bookmarks(storage, 'pubsub')
+
        def request_pb_configuration(self, jid, node):
                if not self.connection or self.connected < 2:
                        return
_______________________________________________
Commits mailing list
Commits@gajim.org
http://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to