Add profile button to add contact dialog

This lets the user query the VCard of the contact before adding
This commit is contained in:
Daniel Brötzmann 2019-04-09 21:53:34 +02:00 committed by Philipp Hörist
parent 64d1401307
commit de790f5e4c
2 changed files with 50 additions and 2 deletions

View File

@ -16,6 +16,11 @@
<column type="gchararray"/> <column type="gchararray"/>
</columns> </columns>
</object> </object>
<object class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">user-info-symbolic</property>
</object>
<object class="GtkTextBuffer" id="message_textbuffer"> <object class="GtkTextBuffer" id="message_textbuffer">
<property name="text" translatable="yes">I would like to add you to my contact list.</property> <property name="text" translatable="yes">I would like to add you to my contact list.</property>
<signal name="end-user-action" handler="on_message_textbuffer_changed" swapped="no"/> <signal name="end-user-action" handler="on_message_textbuffer_changed" swapped="no"/>
@ -144,6 +149,7 @@
<packing> <packing>
<property name="left_attach">1</property> <property name="left_attach">1</property>
<property name="top_attach">3</property> <property name="top_attach">3</property>
<property name="width">2</property>
</packing> </packing>
</child> </child>
<child> <child>
@ -163,6 +169,7 @@
<packing> <packing>
<property name="left_attach">1</property> <property name="left_attach">1</property>
<property name="top_attach">4</property> <property name="top_attach">4</property>
<property name="width">2</property>
</packing> </packing>
</child> </child>
<child> <child>
@ -254,6 +261,7 @@
<packing> <packing>
<property name="left_attach">1</property> <property name="left_attach">1</property>
<property name="top_attach">1</property> <property name="top_attach">1</property>
<property name="width">2</property>
</packing> </packing>
</child> </child>
<child> <child>
@ -275,6 +283,22 @@
<packing> <packing>
<property name="left_attach">1</property> <property name="left_attach">1</property>
<property name="top_attach">0</property> <property name="top_attach">0</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="show_contact_info_button">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Query Contact Info</property>
<property name="image">image1</property>
<signal name="clicked" handler="on_show_contact_info_button_clicked" swapped="no"/>
</object>
<packing>
<property name="left_attach">2</property>
<property name="top_attach">2</property>
</packing> </packing>
</child> </child>
</object> </object>

View File

@ -15,6 +15,7 @@
from gi.repository import Gdk from gi.repository import Gdk
from gi.repository import Gtk from gi.repository import Gtk
from gajim import vcard
from gajim.common import app from gajim.common import app
from gajim.common import ged from gajim.common import ged
from gajim.common import helpers from gajim.common import helpers
@ -58,8 +59,9 @@ class AddNewContactWindow(Gtk.ApplicationWindow):
self.xml.connect_signals(self) self.xml.connect_signals(self)
for w in ('account_combobox', 'account_label', 'prompt_label', for w in ('account_combobox', 'account_label', 'prompt_label',
'uid_label', 'uid_entry', 'protocol_combobox', 'uid_label', 'uid_entry', 'show_contact_info_button',
'protocol_jid_combobox', 'protocol_label', 'nickname_entry', 'protocol_combobox', 'protocol_jid_combobox',
'protocol_label', 'nickname_entry',
'message_scrolledwindow', 'save_message_checkbutton', 'message_scrolledwindow', 'save_message_checkbutton',
'register_hbox', 'add_button', 'message_textview', 'register_hbox', 'add_button', 'message_textview',
'connected_label', 'group_comboboxentry', 'connected_label', 'group_comboboxentry',
@ -68,6 +70,7 @@ class AddNewContactWindow(Gtk.ApplicationWindow):
self.__dict__[w] = self.xml.get_object(w) self.__dict__[w] = self.xml.get_object(w)
self.subscription_table = [self.uid_label, self.uid_entry, self.subscription_table = [self.uid_label, self.uid_entry,
self.show_contact_info_button,
self.nickname_label, self.nickname_entry, self.nickname_label, self.nickname_entry,
self.group_label, self.group_comboboxentry] self.group_label, self.group_comboboxentry]
@ -191,6 +194,7 @@ class AddNewContactWindow(Gtk.ApplicationWindow):
self.account)) self.account))
message_buffer.set_text(msg) message_buffer.set_text(msg)
self.uid_entry.connect('changed', self.on_uid_entry_changed)
self.show_all() self.show_all()
app.ged.register_event_handler('gateway-prompt-received', ged.GUI1, app.ged.register_event_handler('gateway-prompt-received', ged.GUI1,
@ -204,6 +208,26 @@ class AddNewContactWindow(Gtk.ApplicationWindow):
app.ged.remove_event_handler('gateway-prompt-received', ged.GUI1, app.ged.remove_event_handler('gateway-prompt-received', ged.GUI1,
self._nec_gateway_prompt_received) self._nec_gateway_prompt_received)
def on_uid_entry_changed(self, widget):
is_empty = bool(not self.uid_entry.get_text() == '')
self.show_contact_info_button.set_sensitive(is_empty)
def on_show_contact_info_button_clicked(self, widget):
"""
Ask for vCard
"""
jid = self.uid_entry.get_text().strip()
if jid in app.interface.instances[self.account]['infos']:
app.interface.instances[self.account]['infos'][jid].window.present()
else:
contact = app.contacts.create_contact(jid=jid, account=self.account)
app.interface.instances[self.account]['infos'][jid] = \
vcard.VcardWindow(contact, self.account)
# Remove xmpp page
app.interface.instances[self.account]['infos'][jid].xml.\
get_object('information_notebook').remove_page(0)
def on_register_button_clicked(self, widget): def on_register_button_clicked(self, widget):
model = self.protocol_jid_combobox.get_model() model = self.protocol_jid_combobox.get_model()
row = self.protocol_jid_combobox.get_active() row = self.protocol_jid_combobox.get_active()