From 725ef29a85788e90703247dd448547567c369163 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Sun, 22 Jul 2007 09:04:33 +0000 Subject: [PATCH] add 2 buttons to search window: add contact to roster and information. fixes #3304 --- data/glade/search_window.glade | 402 +++++++++++++++++---------------- src/search_window.py | 71 +++++- 2 files changed, 279 insertions(+), 194 deletions(-) diff --git a/data/glade/search_window.glade b/data/glade/search_window.glade index 6a3e6133a..efa3dd993 100644 --- a/data/glade/search_window.glade +++ b/data/glade/search_window.glade @@ -1,191 +1,215 @@ - - - + + + - - - 12 - Search - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - True - False - True - False - False - GDK_WINDOW_TYPE_HINT_NORMAL - GDK_GRAVITY_NORTH_WEST - True - False - - - - - - True - False - 6 - - - - True - False - 0 - - - - True - Please wait while retrieving search form... - False - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - True - False - - - - - - True - GTK_PROGRESS_LEFT_TO_RIGHT - 0 - 0.10000000149 - PANGO_ELLIPSIZE_NONE - - - 0 - True - False - - - - - - - - - 0 - True - True - - - - - - True - GTK_BUTTONBOX_END - 6 - - - - True - True - True - GTK_RELIEF_NORMAL - True - - - - - True - 0.5 - 0.5 - 0 - 0 - 0 - 0 - 0 - 0 - - - - True - False - 2 - - - - True - gtk-find - 4 - 0.5 - 0.5 - 0 - 0 - - - 0 - False - False - - - - - - True - _Search - True - False - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - False - False - - - - - - - - - - - - True - True - True - gtk-close - True - GTK_RELIEF_NORMAL - True - - - - - - 0 - False - True - - - - - - + + 12 + Search + + + + + True + 6 + + + True + + + True + Please wait while retrieving search form... + + + False + + + + + True + 0.10000000149 + + + False + 1 + + + + + + + + + + True + 6 + GTK_BUTTONBOX_END + + + False + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True + 0 + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 2 + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + gtk-add + + + False + False + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + _Add contact + True + + + False + False + 1 + + + + + + + + + + + False + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True + 0 + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 2 + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + gtk-info + + + False + False + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + _Information + True + + + False + False + 1 + + + + + + + + + 1 + + + + + True + True + True + 0 + + + + True + 0 + 0 + + + True + 2 + + + True + gtk-find + + + False + False + + + + + True + _Search + True + + + False + False + 1 + + + + + + + + + 2 + + + + + True + True + True + gtk-close + True + 0 + + + + 3 + + + + + False + 1 + + + + + diff --git a/src/search_window.py b/src/search_window.py index f3eaddecc..ce40eb282 100644 --- a/src/search_window.py +++ b/src/search_window.py @@ -19,6 +19,7 @@ from common import xmpp, gajim, dataforms import gtkgui_helpers import dialogs +import vcard import config import dataforms_widget @@ -33,7 +34,8 @@ class SearchWindow: # retrieving widgets from xml self.xml = gtkgui_helpers.get_glade('search_window.glade') self.window = self.xml.get_widget('search_window') - for name in ('label', 'progressbar', 'search_vbox', 'search_button'): + for name in ('label', 'progressbar', 'search_vbox', 'search_button', + 'add_contact_button', 'information_button'): self.__dict__[name] = self.xml.get_widget(name) # displaying the window @@ -44,6 +46,9 @@ class SearchWindow: self.is_form = None + # Is there a jid column in results ? if -1: no, else column number + self.jid_column = -1 + def request_form(self): gajim.connections[self.account].request_search_fields(self.jid) @@ -83,6 +88,27 @@ class SearchWindow: self.pulse_id = gobject.timeout_add(80, self.pulse_callback) self.search_button.hide() + def on_add_contact_button_clicked(self, widget): + (model, iter) = self.result_treeview.get_selection().get_selected() + if not iter: + return + jid = model[iter][self.jid_column] + dialogs.AddNewContactWindow(self.account, jid) + + def on_information_button_clicked(self, widget): + (model, iter) = self.result_treeview.get_selection().get_selected() + if not iter: + return + jid = model[iter][self.jid_column] + if gajim.interface.instances[self.account]['infos'].has_key(jid): + gajim.interface.instances[self.account]['infos'][jid].window.present() + else: + contact = gajim.contacts.create_contact(jid = jid, name='', groups=[], + show='', status='', sub='', ask='', resource='', priority=0, + keyID='', our_chatstate=None, chatstate=None) + gajim.interface.instances[self.account]['infos'][jid] = \ + vcard.VcardWindow(contact, self.account) + def on_form_arrived(self, form, is_form): if self.pulse_id: gobject.source_remove(self.pulse_id) @@ -110,6 +136,19 @@ class SearchWindow: self.data_form_widget.show_all() self.search_vbox.pack_start(self.data_form_widget) + def on_result_treeview_cursor_changed(self, treeview): + if self.jid_column == -1: + return + (model, iter) = treeview.get_selection().get_selected() + if not iter: + return + if model[iter][self.jid_column]: + self.add_contact_button.set_sensitive(True) + self.information_button.set_sensitive(True) + else: + self.add_contact_button.set_sensitive(False) + self.information_button.set_sensitive(False) + def on_result_arrived(self, form, is_form): if self.pulse_id: gobject.source_remove(self.pulse_id) @@ -124,8 +163,10 @@ class SearchWindow: # We suppose all items have the same fields sw = gtk.ScrolledWindow() sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) - treeview = gtk.TreeView() - sw.add(treeview) + self.result_treeview = gtk.TreeView() + self.result_treeview.connect('cursor-changed', + self.on_result_treeview_cursor_changed) + sw.add(self.result_treeview) # Create model fieldtypes = [str]*len(form[0]) model = gtk.ListStore(*fieldtypes) @@ -135,13 +176,18 @@ class SearchWindow: # Create columns counter = 0 for field in form[0].keys(): - treeview.append_column( + self.result_treeview.append_column( gtk.TreeViewColumn(field, gtk.CellRendererText(), text = counter)) + if field == 'jid': + self.jid_column = counter counter += 1 - treeview.set_model(model) + self.result_treeview.set_model(model) sw.show_all() self.search_vbox.pack_start(sw) + if self.jid_column > -1: + self.add_contact_button.show() + self.information_button.show() return self.dataform = dataforms.ExtendForm(node = form) @@ -154,8 +200,23 @@ class SearchWindow: self.label.show() return + self.result_treeview = self.data_form_widget.records_treeview + selection = self.result_treeview.get_selection() + selection.set_mode(gtk.SELECTION_SINGLE) + self.result_treeview.connect('cursor-changed', + self.on_result_treeview_cursor_changed) + + counter = 0 + for field in self.dataform.items[0].fields: + if field.var == 'jid': + self.jid_column = counter + break + counter += 1 self.search_vbox.pack_start(self.data_form_widget) self.data_form_widget.show() + if self.jid_column > -1: + self.add_contact_button.show() + self.information_button.show() if self.data_form_widget.title: self.window.set_title('%s - Search - Gajim' % \ self.data_form_widget.title)