[misc] XEP-145 (annotations) support. Thanks fixes #776

This commit is contained in:
Yann Leboulanger 2006-11-09 19:13:53 +00:00
parent bac3b8f2f2
commit a4c29cd6c2
4 changed files with 109 additions and 0 deletions

View File

@ -2550,6 +2550,66 @@
<property name="type">tab</property>
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow_annotation">
<property name="border_width">6</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="shadow_type">GTK_SHADOW_IN</property>
<property name="window_placement">GTK_CORNER_TOP_LEFT</property>
<child>
<widget class="GtkTextView" id="textview_annotation">
<property name="height_request">70</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="overwrite">False</property>
<property name="accepts_tab">True</property>
<property name="justification">GTK_JUSTIFY_LEFT</property>
<property name="wrap_mode">GTK_WRAP_NONE</property>
<property name="cursor_visible">True</property>
<property name="pixels_above_lines">0</property>
<property name="pixels_below_lines">0</property>
<property name="pixels_inside_wrap">0</property>
<property name="left_margin">0</property>
<property name="right_margin">0</property>
<property name="indent">0</property>
<property name="text" translatable="yes"></property>
</widget>
</child>
</widget>
<packing>
<property name="tab_expand">False</property>
<property name="tab_fill">True</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label58">
<property name="visible">True</property>
<property name="label" translatable="yes">Comments</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="type">tab</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>

View File

@ -58,6 +58,7 @@ class Connection(ConnectionHandlers):
self.time_to_reconnect = None
self.new_account_info = None
self.bookmarks = []
self.annotations = {}
self.on_purpose = False
self.last_io = gajim.idlequeue.current_time()
self.last_sent = []
@ -543,6 +544,9 @@ class Connection(ConnectionHandlers):
#Get bookmarks from private namespace
self.get_bookmarks()
#Get annotations
self.get_annotations()
#Inform GUI we just signed in
self.dispatch('SIGNED_IN', ())
@ -934,6 +938,31 @@ class Connection(ConnectionHandlers):
iq5 = iq4.setTagData('print_status', bm['print_status'])
self.connection.send(iq)
def get_annotations(self):
'''Get Annonations from storage as described in XEP 0048, and XEP 0145'''
self.annotations = {}
if not self.connection:
return
iq = common.xmpp.Iq(typ='get')
iq2 = iq.addChild(name='query', namespace='jabber:iq:private')
iq2.addChild(name='storage', namespace='storage:rosternotes')
self.connection.send(iq)
def store_annotations(self):
'''Set Annonations in private storage as described in XEP 0048, and XEP 0145'''
if not self.connection:
return
iq = common.xmpp.Iq(typ='set')
iq2 = iq.addChild(name='query', namespace='jabber:iq:private')
iq3 = iq2.addChild(name='storage', namespace='storage:rosternotes')
for jid in self.annotations.keys():
if self.annotations[jid]:
iq4 = iq3.addChild(name = "note")
iq4.setAttr('jid', jid)
iq4.setData(self.annotations[jid])
self.connection.send(iq)
def get_metacontacts(self):
'''Get metacontacts list from storage as described in JEP 0049'''
if not self.connection:

View File

@ -1192,6 +1192,14 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco)
# http://www.jabber.org/jeps/jep-0049.html
#TODO: implement this
pass
elif ns == 'storage:rosternotes':
# Annotations
# http://www.xmpp.org/extensions/xep-0145.html
notes = storage.getTags('note')
for note in notes:
jid = note.getAttr('jid')
annotation = note.getData()
self.annotations[jid] = annotation
def _PrivateErrorCB(self, con, iq_obj):
gajim.log.debug('PrivateErrorCB')
@ -1833,6 +1841,9 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco)
# Get bookmarks from private namespace
self.get_bookmarks()
# Get annotations from private namespace
self.get_annotations()
# If it's a gmail account,
# inform the server that we want e-mail notifications
if gajim.get_server_from_jid(our_jid) in gajim.gmail_domains:

View File

@ -77,6 +77,10 @@ class VcardWindow:
self.update_progressbar)
self.fill_jabber_page()
annotations = gajim.connections[self.account].annotations
if self.contact.jid in annotations:
buffer = self.xml.get_widget('textview_annotation').get_buffer()
buffer.set_text(annotations[self.contact.jid])
self.xml.signal_autoconnect(self)
self.window.show_all()
@ -90,6 +94,11 @@ class VcardWindow:
if self.update_progressbar_timeout_id is not None:
gobject.source_remove(self.update_progressbar_timeout_id)
del gajim.interface.instances[self.account]['infos'][self.contact.jid]
buffer = self.xml.get_widget('textview_annotation').get_buffer()
gajim.connections[self.account].annotations[self.contact.jid] = \
buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter())
gajim.connections[self.account].store_annotations()
def on_vcard_information_window_key_press_event(self, widget, event):
if event.keyval == gtk.keysyms.Escape: