Commit af8c524c authored by Daniel Brötzmann's avatar Daniel Brötzmann

AddContact: Fix group selection

parent 8d25a0f6
......@@ -30,9 +30,10 @@
# General Actions
def on_add_contact_jid(_action, param):
contact_jid = param.get_string()
open_window('AddNewContactWindow', account=None, contact_jid=contact_jid)
jid = param.get_string()
open_window('AddContact', account=None, jid=jid)
# Application Menu Actions
......@@ -107,10 +108,8 @@ def on_create_gc(_action, param):
def on_add_contact(_action, param):
account, contact_jid = param.get_strv()
if not contact_jid:
contact_jid = None
open_window('AddNewContactWindow', account=account, contact_jid=contact_jid)
account, jid = param.get_strv()
open_window('AddContact', account=account, jid=jid or None)
def on_single_message(_action, param):
......
......@@ -27,16 +27,17 @@
from .util import open_window
class AddNewContactWindow(Gtk.ApplicationWindow, EventHelper):
class AddContact(Gtk.ApplicationWindow, EventHelper):
uid_labels = {'jabber': _('XMPP Address'),
'gadu-gadu': _('GG Number'),
'icq': _('ICQ Number')}
def __init__(self, account=None, contact_jid=None, user_nick=None, group=None):
def __init__(self, account=None, jid=None, nick=None, group=None):
Gtk.ApplicationWindow.__init__(self)
EventHelper.__init__(self)
self.set_application(app.app)
self.set_type_hint(Gdk.WindowTypeHint.DIALOG)
self.set_position(Gtk.WindowPosition.CENTER)
self.set_show_menubar(False)
self.set_resizable(False)
......@@ -45,10 +46,11 @@ def __init__(self, account=None, contact_jid=None, user_nick=None, group=None):
self.connect_after('key-press-event', self._on_key_press)
self.account = account
self._group = group
self.adding_jid = False
if contact_jid is not None:
contact_jid = app.get_jid_without_resource(str(contact_jid))
if jid is not None:
jid = app.get_jid_without_resource(str(jid))
# fill accounts with active accounts
accounts = app.get_enabled_accounts_with_labels()
......@@ -119,16 +121,16 @@ def __init__(self, account=None, contact_jid=None, user_nick=None, group=None):
self._ui.protocol_combobox.set_active(0)
self._ui.auto_authorize_checkbutton.show()
if contact_jid:
if jid:
self.jid_escaped = True
type_ = app.get_transport_name_from_jid(contact_jid)
type_ = app.get_transport_name_from_jid(jid)
if not type_:
type_ = 'jabber'
if type_ == 'jabber':
self._ui.uid_entry.set_text(contact_jid)
self._ui.uid_entry.set_text(jid)
transport = None
else:
uid, transport = app.get_name_and_server_from_jid(contact_jid)
uid, transport = app.get_name_and_server_from_jid(jid)
self._ui.uid_entry.set_text(uid.replace('%', '@', 1))
self._ui.show_contact_info_button.set_sensitive(True)
......@@ -155,24 +157,14 @@ def __init__(self, account=None, contact_jid=None, user_nick=None, group=None):
break
iter_ = model.iter_next(iter_)
i += 1
if user_nick:
self._ui.nickname_entry.set_text(user_nick)
if nick:
self._ui.nickname_entry.set_text(nick)
self._ui.nickname_entry.grab_focus()
else:
self.jid_escaped = False
self._ui.uid_entry.grab_focus()
group_names = []
for acct in accounts:
for g in app.groups[acct[0]].keys():
if g not in helpers.special_groups and g not in group_names:
group_names.append(g)
group_names.sort()
i = 0
for g in group_names:
self._ui.group_comboboxentry.append_text(g)
if group == g:
self._ui.group_comboboxentry.set_active(i)
i += 1
self._update_groups()
if len(accounts) > 1:
liststore = self._ui.account_combobox.get_model()
......@@ -201,6 +193,16 @@ def __init__(self, account=None, contact_jid=None, user_nick=None, group=None):
('presence-received', ged.GUI1, self._nec_presence_received),
])
def _update_groups(self):
self._ui.group_comboboxentry.get_model().clear()
index = 0
client = app.get_client(self.account)
for item in client.get_module('Roster').get_groups():
self._ui.group_comboboxentry.append_text(item)
if item == self._group:
self._ui.group_comboboxentry.set_active(index)
index += 1
def on_uid_entry_changed(self, widget):
is_empty = bool(not self._ui.uid_entry.get_text() == '')
self._ui.show_contact_info_button.set_sensitive(is_empty)
......@@ -339,6 +341,7 @@ def on_account_combobox_changed(self, widget):
message_buffer = self._ui.message_textview.get_buffer()
message_buffer.set_text(helpers.get_subscription_request_msg(account))
self.account = account
self._update_groups()
def on_protocol_jid_combobox_changed(self, widget):
model = widget.get_model()
......
......@@ -109,7 +109,7 @@ def __str__(self):
'Preferences': 'gajim.gui.preferences',
'CreateGroupchatWindow': 'gajim.gui.groupchat_creation',
'StartChatDialog': 'gajim.gui.start_chat',
'AddNewContactWindow': 'gajim.gui.add_contact',
'AddContact': 'gajim.gui.add_contact',
'SingleMessageWindow': 'gajim.gui.single_message',
'Bookmarks': 'gajim.gui.bookmarks',
'AccountWizard': 'gajim.gui.account_wizard',
......
......@@ -59,13 +59,13 @@
from gajim.gui.gstreamer import create_gtk_widget
from gajim.gui.dialogs import DialogButton
from gajim.gui.dialogs import ConfirmationDialog
from gajim.gui.add_contact import AddNewContactWindow
from gajim.gui.util import get_cursor
from gajim.gui.util import format_mood
from gajim.gui.util import format_activity
from gajim.gui.util import format_tune
from gajim.gui.util import format_location
from gajim.gui.util import get_activity_icon_name
from gajim.gui.util import open_window
from gajim.gui.const import ControlType
from gajim.command_system.implementation.hosts import ChatCommands
......@@ -355,7 +355,8 @@ def delegate_action(self, action):
return Gdk.EVENT_PROPAGATE
def _on_add_to_roster(self, _action, _param):
AddNewContactWindow(self.account, self.contact.jid)
open_window('AddContact', account=self.account,
jid=self.contact.jid)
def _on_block_contact(self, _action, _param):
app.window.block_contact(self.account, self.contact.jid)
......
......@@ -332,7 +332,7 @@ def add_private_chat(self, account, jid, select=False):
@staticmethod
def _add_to_roster(_action, param):
_workspace, account, jid = param.unpack()
open_window('AddNewContactWindow', account=account, contact_jid=jid)
open_window('AddContact', account=account, jid=jid)
def get_control(self, *args, **kwargs):
return self._chat_page.get_control(*args, **kwargs)
......
......@@ -23,7 +23,6 @@
from gajim.gui_menu_builder import get_subscription_menu
from .add_contact import AddNewContactWindow
from .util import open_window
......@@ -102,7 +101,8 @@ def _on_subscription_accept(self, _action, param):
self._client.get_module('Presence').subscribed(jid)
contact = self._client.get_module('Contacts').get_contact(jid)
if not contact.is_in_roster:
AddNewContactWindow(self._account, jid, contact.name)
open_window('AddContact', account=self._account,
jid=jid, nick=contact.name)
self._listbox.remove(row)
def _on_subscription_block(self, _action, param):
......
......@@ -33,7 +33,7 @@
from gajim.common import helpers
from gajim.common.structs import OutgoingMessage
from gajim.gui.add_contact import AddNewContactWindow
from gajim.gui.add_contact import AddContact
log = logging.getLogger('gajim.remote_control')
......@@ -729,13 +729,13 @@ def add_contact(self, jid, account):
if account:
if app.account_is_available(account):
# if given account is active, use it
AddNewContactWindow(account=account, contact_jid=jid)
AddContact(account=account, jid=jid)
else:
# wrong account
return False
else:
# if account is not given, show account combobox
AddNewContactWindow(account=None, contact_jid=jid)
AddContact(account=None, jid=jid)
return True
def remove_contact(self, jid, account):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment