Daniel Brötzmann pushed to branch mainwindow at gajim / gajim
Commits: 02cb001b by wurstsalat at 2021-03-21T15:46:35+01:00 GroupChatInvitation: Fix accepting invitation
- - - - - 19a89a09 by wurstsalat at 2021-03-21T15:57:57+01:00 AccountPage: Handle muc invite/decline
- - - - -
4 changed files:
- gajim/gtk/account_page.py - gajim/gtk/groupchat_invitation.py - gajim/gtk/notification_manager.py - gajim/gui_interface.py
Changes:
===================================== gajim/gtk/account_page.py ===================================== @@ -70,6 +70,8 @@ def __init__(self, account): self.register_events([ ('subscribe-presence-received', ged.GUI1, self._subscribe_received), ('unsubscribed-presence-received', ged.GUI1, self._unsubscribed_received), + ('muc-invitation', ged.GUI1, self._muc_invitation_received), + ('muc-decline', ged.GUI1, self._muc_invitation_declined), ]) # pylint: enable=line-too-long
@@ -109,11 +111,16 @@ def update(self): self._status_selector.update()
def _subscribe_received(self, event): - self._notification_manager.add_subscription_request( - event.jid, event.status, user_nick=event.user_nick) + self._notification_manager.add_subscription_request(event)
def _unsubscribed_received(self, event): - self._notification_manager.add_unsubscribed(event.jid) + self._notification_manager.add_unsubscribed(event) + + def _muc_invitation_received(self, event): + self._notification_manager.add_invitation_received(event) + + def _muc_invitation_declined(self, event): + self._notification_manager.add_invitation_declined(event)
def process_event(self, event): self._roster.process_event(event)
===================================== gajim/gtk/groupchat_invitation.py ===================================== @@ -35,6 +35,7 @@ def __init__(self, account, event): self.set_type_hint(Gdk.WindowTypeHint.DIALOG)
self.account = account + self._client = app.get_client(account) self._room_jid = str(event.muc) self._from = str(event.from_) self._password = event.password @@ -45,16 +46,20 @@ def __init__(self, account, event):
muc_info_box = GroupChatInfoScrolled(account, {'minimal': True}) muc_info_box.set_from_disco_info(event.info) - main_box.add(muc_info_box)
separator = Gtk.Separator() - contact_label = Gtk.Label(label=event.get_inviter_name()) + main_box.add(separator) + + contact = self._client.get_module('Contacts').get_contact( + event.from_.bare) + contact_label = Gtk.Label(label=contact.name) contact_label.get_style_context().add_class('bold16') contact_label.set_line_wrap(True) contact_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6) contact_box.set_halign(Gtk.Align.CENTER) contact_box.add(contact_label) + main_box.add(contact_box)
enabled_accounts = app.get_enabled_accounts_with_labels() if len(enabled_accounts) > 1: @@ -69,9 +74,6 @@ def __init__(self, account, event): invitation_label.set_justify(Gtk.Justification.CENTER) invitation_label.set_max_width_chars(50) invitation_label.set_line_wrap(True) - - main_box.add(separator) - main_box.add(contact_box) main_box.add(invitation_label)
decline_button = Gtk.Button.new_with_mnemonic(_('_Decline')) @@ -115,13 +117,10 @@ def _on_key_press_event(self, _widget, event):
def _on_join(self, _widget): nickname = self._nick_chooser.get_text() - app.interface.show_or_join_groupchat(self.account, - self._room_jid, - nick=nickname, - password=self._password) + app.interface.show_add_join_groupchat( + self.account, self._room_jid, nickname=nickname) self.destroy()
def _on_decline(self, _widget): - app.connections[self.account].get_module('MUC').decline( - self._room_jid, self._from) + self._client.get_module('MUC').decline(self._room_jid, self._from) self.destroy()
===================================== gajim/gtk/notification_manager.py ===================================== @@ -23,6 +23,7 @@ from gajim.gui_menu_builder import get_subscription_menu
from .add_contact import AddNewContactWindow +from .util import open_window
class NotificationManager(Gtk.ScrolledWindow): @@ -132,21 +133,31 @@ def _get_notification_row(self, jid): return child return None
- def add_subscription_request(self, jid, text, user_nick=None): - row = self._get_notification_row(jid) + def add_subscription_request(self, event): + row = self._get_notification_row(event.jid) if row is None: self._listbox.add(SubscriptionRequestRow( - self._account, jid, text, user_nick)) + self._account, event.jid, event.status, event.user_nick)) elif row.type == 'unsubscribed': self._listbox.remove(row)
- def add_unsubscribed(self, jid): - row = self._get_notification_row(jid) + def add_unsubscribed(self, event): + row = self._get_notification_row(event.jid) if row is None: - self._listbox.add(UnsubscribedRow(self._account, jid)) + self._listbox.add(UnsubscribedRow(self._account, event.jid)) elif row.type == 'subscribe': self._listbox.remove(row)
+ def add_invitation_received(self, event): + row = self._get_notification_row(event.muc) + if row is None: + self._listbox.add(InvitationReceivedRow(self._account, event)) + + def add_invitation_declined(self, event): + row = self._get_notification_row(event.muc) + if row is None: + self._listbox.add(InvitationDeclinedRow(self._account, event)) +
class NotificationRow(Gtk.ListBoxRow): def __init__(self, account, jid): @@ -170,7 +181,7 @@ def _generate_label():
class SubscriptionRequestRow(NotificationRow): - def __init__(self, account, jid, text, user_nick): + def __init__(self, account, jid, text, user_nick=None): NotificationRow.__init__(self, account, jid) self.type = 'subscribe'
@@ -259,3 +270,97 @@ def __init__(self, account, jid):
def _on_dismiss(self, _button): self.get_parent().remove(self) + + +class InvitationReceivedRow(NotificationRow): + def __init__(self, account, event): + NotificationRow.__init__(self, account, event.muc) + self.type = 'invitation-received' + + self._event = event + + image = Gtk.Image.new_from_icon_name( + 'system-users-symbolic', Gtk.IconSize.DND) + image.set_valign(Gtk.Align.CENTER) + self.grid.attach(image, 1, 1, 1, 2) + + title_label = self._generate_label() + title_label.set_text(_('Group Chat Invitation Received')) + title_label.get_style_context().add_class('bold') + self.grid.attach(title_label, 2, 1, 1, 1) + + contact = self._client.get_module('Contacts').get_contact( + event.from_.bare) + invitation_text = _('%(contact)s invited you to %(chat)s') % { + 'contact': contact.name, + 'chat': event.info.muc_name} + text_label = self._generate_label() + text_label.set_text(invitation_text) + text_label.set_tooltip_text(invitation_text) + text_label.get_style_context().add_class('dim-label') + self.grid.attach(text_label, 2, 2, 1, 1) + + show_button = Gtk.Button.new_with_label(label=_('Show')) + show_button.set_valign(Gtk.Align.CENTER) + show_button.set_tooltip_text('Show Invitation') + show_button.connect('clicked', self._on_show_invitation) + self.grid.attach(show_button, 3, 1, 1, 2) + + decline_button = Gtk.Button.new_with_label(label=_('Decline')) + decline_button.set_valign(Gtk.Align.CENTER) + decline_button.set_tooltip_text('Decline Invitation') + decline_button.connect('clicked', self._on_decline_invitation) + self.grid.attach(decline_button, 4, 1, 1, 2) + + self.show_all() + + def _on_show_invitation(self, _button): + open_window('GroupChatInvitation', + account=self._account, + event=self._event) + self.get_parent().remove(self) + + def _on_decline_invitation(self, _button): + self._client.get_module('MUC').decline( + self.jid, self._event.from_.bare) + self.get_parent().remove(self) + + +class InvitationDeclinedRow(NotificationRow): + def __init__(self, account, event): + NotificationRow.__init__(self, account, event.muc) + self.type = 'invitation-declined' + + image = Gtk.Image.new_from_icon_name( + 'system-users-symbolic', Gtk.IconSize.DND) + image.set_valign(Gtk.Align.CENTER) + self.grid.attach(image, 1, 1, 1, 2) + + title_label = self._generate_label() + title_label.set_text(_('Group Chat Invitation Declined')) + title_label.get_style_context().add_class('bold') + self.grid.attach(title_label, 2, 1, 1, 1) + + contact = self._client.get_module('Contacts').get_contact( + event.from_.bare) + invitation_text = _('%(contact)s declined your invitation ' + 'to %(chat)s') % { + 'contact': contact.name, + 'chat': event.info.muc_name} + text_label = self._generate_label() + text_label.set_text(invitation_text) + text_label.set_tooltip_text(invitation_text) + text_label.get_style_context().add_class('dim-label') + self.grid.attach(text_label, 2, 2, 1, 1) + + dismiss_button = Gtk.Button.new_from_icon_name( + 'window-close-symbolic', Gtk.IconSize.BUTTON) + dismiss_button.set_valign(Gtk.Align.CENTER) + dismiss_button.set_tooltip_text(_('Remove Notification')) + dismiss_button.connect('clicked', self._on_dismiss) + self.grid.attach(dismiss_button, 3, 1, 1, 2) + + self.show_all() + + def _on_dismiss(self, _button): + self.get_parent().remove(self)
===================================== gajim/gui_interface.py ===================================== @@ -302,6 +302,7 @@ def handle_event_msgnotsent(obj): msg_type='error')
def handle_event_gc_decline(self, event): + # TODO: Adapt to new mainwindow gc_control = self.msg_win_mgr.get_gc_control(str(event.muc), event.account) if gc_control: @@ -317,20 +318,24 @@ def handle_event_gc_decline(self, event): def handle_event_gc_invitation(self, event): event = events.GcInvitationtEvent(event)
- if (helpers.allow_popup_window(event.account) or - not self.systray_enabled): - open_window('GroupChatInvitation', - account=event.account, - event=event) - return + # TODO: show account page + # if (helpers.allow_popup_window(event.account) or + # not self.systray_enabled): + # open_window('GroupChatInvitation', + # account=event.account, + # event=event) + # return
- self.add_event(event.account, str(event.from_), event) + #self.add_event(event.account, str(event.from_), event)
if helpers.allow_showing_notification(event.account): - contact_name = event.get_inviter_name() + client = app.get_client(event.account) + contact = client.get_module('Contacts').get_contact( + event.from_.bare) event_type = _('Group Chat Invitation') text = _('%(contact)s invited you to %(chat)s') % { - 'contact': contact_name, 'chat': event.info.muc_name} + 'contact': contact.name, + 'chat': event.info.muc_name} app.notification.popup(event_type, str(event.from_), event.account, @@ -1160,11 +1165,12 @@ def handle_event(self, account, fjid, type_): event = app.events.get_first_event(account, jid, type_) if event is None: return - open_window('GroupChatInvitation', - account=account, - event=event) + # TODO: Show account page + # open_window('GroupChatInvitation', + # account=account, + # event=event) app.events.remove_events(account, jid, event) - self.roster.draw_contact(jid, account) + # self.roster.draw_contact(jid, account) elif type_ == 'subscription_request': event = app.events.get_first_event(account, jid, type_) if event is None:
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/df1dd5c2de43cfb808b1bb8cc9803526...