diff --git a/gajim/gtk/account_page.py b/gajim/gtk/account_page.py index 84b2f875fbff8dd60890782d50f71268927e551c..b62b65d6e9bd31961c1409e34c639788063da368 100644 --- a/gajim/gtk/account_page.py +++ b/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) diff --git a/gajim/gtk/notification_manager.py b/gajim/gtk/notification_manager.py index cab98377103743e4e327c311348db89e5cab93d4..52c153048d68bd1eca9b8f08a710f684f5096b67 100644 --- a/gajim/gtk/notification_manager.py +++ b/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) diff --git a/gajim/gui_interface.py b/gajim/gui_interface.py index fd4310efb30dafa2160c164f0cc378889457e3cc..dcad777d72da23f15734d9cc8dfc0d3d2e4f49b1 100644 --- a/gajim/gui_interface.py +++ b/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: