Philipp Hörist pushed to branch master at gajim / gajim
Commits: c8d19f60 by Daniel Brötzmann at 2020-09-26T10:40:25+02:00 Replace InvitationReceivedDialog with GroupChatInvitation
- - - - -
10 changed files:
- gajim/common/events.py - gajim/common/modules/muc.py - gajim/data/gui/groupchat_info_scrolled.ui - − gajim/data/gui/groupchat_invitation_received.ui - gajim/gtk/const.py - gajim/gtk/dialogs.py - gajim/gtk/groupchat_info.py - + gajim/gtk/groupchat_invitation.py - gajim/gui_interface.py - gajim/roster_window.py
Changes:
===================================== gajim/common/events.py ===================================== @@ -22,6 +22,8 @@
import time
+from gajim.common import app +
class Event: """ @@ -130,6 +132,16 @@ class GcInvitationtEvent(Event): for key, value in vars(event).items(): setattr(self, key, value)
+ def get_inviter_name(self): + if self.from_.bare_match(self.muc): + return self.from_.resource + + contact = app.contacts.get_first_contact_from_jid( + self.account, self.from_.bare) + if contact is None: + return str(self.from_) + return contact.get_shown_name() + class FileRequestEvent(Event): type_ = 'file-request' def __init__(self, file_props, time_=None, show_in_roster=False, show_in_systray=True):
===================================== gajim/common/modules/muc.py ===================================== @@ -771,12 +771,28 @@ class MUC(BaseModule): self._log.info('We are already in this room') raise nbxmpp.NodeProcessed
- app.nec.push_incoming_event( - NetworkEvent('muc-invitation', - account=self._account, - **data._asdict())) + self._con.get_module('Discovery').disco_muc( + data.muc, + request_vcard=True, + callback=self._on_disco_result_after_invite, + user_data=data) + raise nbxmpp.NodeProcessed
+ def _on_disco_result_after_invite(self, task): + try: + result = task.finish() + except StanzaError as error: + self._log.warning(error) + return + + invite_data = task.get_user_data() + app.nec.push_incoming_event( + NetworkEvent('muc-invitation', + account=self._account, + info=result.info, + **invite_data._asdict())) + def invite(self, room, to, reason=None, continue_=False): type_ = InviteType.MEDIATED contact = app.contacts.get_contact_from_full_jid(self._account, to)
===================================== gajim/data/gui/groupchat_info_scrolled.ui ===================================== @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- Generated with glade 3.22.2 --> +<!-- Generated with glade 3.36.0 --> <interface> <requires lib="gtk+" version="3.20"/> <object class="GtkGrid" id="info_grid"> @@ -170,23 +170,6 @@ <property name="top_attach">8</property> </packing> </child> - <child> - <object class="GtkLabel"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="halign">center</property> - <property name="valign">start</property> - <property name="label" translatable="yes">Configuration</property> - <style> - <class name="bold16"/> - </style> - </object> - <packing> - <property name="left_attach">0</property> - <property name="top_attach">10</property> - <property name="width">2</property> - </packing> - </child> <child> <object class="GtkLinkButton" id="logs"> <property name="label" translatable="yes">button</property>
===================================== gajim/data/gui/groupchat_invitation_received.ui deleted ===================================== @@ -1,156 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- Generated with glade 3.22.1 --> -<interface> - <requires lib="gtk+" version="3.20"/> - <object class="GtkGrid" id="grid"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="border_width">18</property> - <property name="row_spacing">6</property> - <property name="column_spacing">12</property> - <child> - <object class="GtkLabel" id="invitation_label"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label"><b>contact/jid</b> has invited you to the group chat <b>muc.jid</b></property> - <property name="use_markup">True</property> - <property name="wrap">True</property> - <property name="max_width_chars">50</property> - <property name="xalign">0</property> - </object> - <packing> - <property name="left_attach">1</property> - <property name="top_attach">1</property> - </packing> - </child> - <child> - <object class="GtkImage"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="icon_name">system-users-symbolic</property> - <property name="icon_size">6</property> - </object> - <packing> - <property name="left_attach">0</property> - <property name="top_attach">1</property> - </packing> - </child> - <child> - <object class="GtkLabel"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label" translatable="yes">Group Chat Invitation</property> - <style> - <class name="large-header"/> - </style> - </object> - <packing> - <property name="left_attach">0</property> - <property name="top_attach">0</property> - <property name="width">2</property> - </packing> - </child> - <child> - <object class="GtkBox"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="margin_top">12</property> - <property name="spacing">6</property> - <property name="homogeneous">True</property> - <child> - <object class="GtkButton" id="decline_button"> - <property name="label" translatable="yes">_Decline</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="use_underline">True</property> - <signal name="clicked" handler="on_decline_button_clicked" swapped="no"/> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkButton" id="accept_button"> - <property name="label" translatable="yes">_Accept</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <property name="use_underline">True</property> - <signal name="clicked" handler="on_accept_button_clicked" swapped="no"/> - <style> - <class name="suggested-action"/> - </style> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">True</property> - <property name="position">1</property> - </packing> - </child> - </object> - <packing> - <property name="left_attach">0</property> - <property name="top_attach">4</property> - <property name="width">2</property> - </packing> - </child> - <child> - <object class="GtkExpander" id="message_expander"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="margin_top">6</property> - <property name="resize_toplevel">True</property> - <child> - <object class="GtkEntry" id="decline_message"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="margin_top">6</property> - <property name="placeholder_text" translatable="yes">Message...</property> - <property name="show_emoji_icon">True</property> - </object> - </child> - <child type="label"> - <object class="GtkLabel"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="margin_left">6</property> - <property name="label" translatable="yes">_Message if you decline (optional)</property> - <property name="use_underline">True</property> - <property name="mnemonic_widget">decline_message</property> - <signal name="mnemonic-activate" handler="on_message_mnemonic_activate" swapped="no"/> - <style> - <class name="dim-label"/> - </style> - </object> - </child> - </object> - <packing> - <property name="left_attach">1</property> - <property name="top_attach">3</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="comment_label"> - <property name="can_focus">False</property> - <property name="no_show_all">True</property> - <property name="label"><comment></property> - <property name="wrap">True</property> - <property name="max_width_chars">50</property> - <property name="xalign">0</property> - </object> - <packing> - <property name="left_attach">1</property> - <property name="top_attach">2</property> - </packing> - </child> - <child> - <placeholder/> - </child> - <child> - <placeholder/> - </child> - </object> -</interface>
===================================== gajim/gtk/const.py ===================================== @@ -129,4 +129,5 @@ WINDOW_MODULES = { 'PluginsWindow': 'gajim.plugins.gui', 'Features': 'gajim.gtk.features', 'StatusChange': 'gajim.gtk.status_change', + 'GroupChatInvitation': 'gajim.gtk.groupchat_invitation', }
===================================== gajim/gtk/dialogs.py ===================================== @@ -295,64 +295,6 @@ class CertificateDialog(Gtk.ApplicationWindow): self._clipboard.set_text(clipboard_text, -1)
-class InvitationReceivedDialog(Gtk.ApplicationWindow): - def __init__(self, account, event): - Gtk.ApplicationWindow.__init__(self) - self.set_name('InvitationReceivedDialog') - self.set_application(app.app) - self.set_position(Gtk.WindowPosition.CENTER) - self.set_resizable(False) - self.set_show_menubar(False) - self.set_title(_('Group Chat Invitation ')) - - self._ui = get_builder('groupchat_invitation_received.ui') - self.add(self._ui.grid) - self.show_all() - self._ui.connect_signals(self) - - self.account = account - self.room_jid = str(event.muc) - self.from_ = str(event.from_) - self.password = event.password - - if event.from_.bare_match(event.muc): - contact_text = event.from_.resource - else: - contact = app.contacts.get_first_contact_from_jid( - self.account, event.from_.bare) - if contact is None: - contact_text = str(event.from_) - else: - contact_text = contact.get_shown_name() - - invitation_label = _('<b>%(contact)s</b> has invited you to the ' - 'group chat <b>%(room_jid)s</b>') % \ - {'contact': contact_text, - 'room_jid': self.room_jid} - self._ui.invitation_label.set_markup(invitation_label) - - if event.reason: - comment = GLib.markup_escape_text(event.reason) - comment = _('Comment: %s') % comment - self._ui.comment_label.show() - self._ui.comment_label.set_text(comment) - - def on_message_mnemonic_activate(self, _widget, _group_cycling=False): - self._ui.message_expander.set_expanded(True) - - def on_accept_button_clicked(self, _widget): - app.interface.show_or_join_groupchat(self.account, - self.room_jid, - password=self.password) - self.destroy() - - def on_decline_button_clicked(self, _widget): - text = self._ui.decline_message.get_text() - app.connections[self.account].get_module('MUC').decline( - self.room_jid, self.from_, text) - self.destroy() - - class PassphraseDialog: """ Class for Passphrase dialog
===================================== gajim/gtk/groupchat_info.py ===================================== @@ -101,14 +101,23 @@ class GroupChatInfoScrolled(Gtk.ScrolledWindow): Gtk.ScrolledWindow.__init__(self) if options is None: options = {} + + self._minimal = options.get('minimal', False) + self.set_size_request(options.get('width', 400), -1) self.set_halign(Gtk.Align.CENTER) - self.set_vexpand(True) - self.set_min_content_height(400) - self.set_policy(Gtk.PolicyType.NEVER, - Gtk.PolicyType.AUTOMATIC) + + if self._minimal: + self.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.NEVER) + else: + self.set_vexpand(True) + self.set_min_content_height(400) + self.set_policy(Gtk.PolicyType.NEVER, + Gtk.PolicyType.AUTOMATIC) + self._account = account self._info = None + self._ui = get_builder('groupchat_info_scrolled.ui') self.add(self._ui.info_grid) self._ui.connect_signals(self) @@ -165,6 +174,12 @@ class GroupChatInfoScrolled(Gtk.ScrolledWindow): self._ui.description.set_visible(has_desc) self._ui.description_label.set_visible(has_desc)
+ # Set address + self._ui.address.set_text(str(info.jid)) + + if self._minimal: + return + # Set subject self.set_subject(info.muc_subject)
@@ -174,9 +189,6 @@ class GroupChatInfoScrolled(Gtk.ScrolledWindow): self._ui.users.set_visible(has_users) self._ui.users_image.set_visible(has_users)
- # Set address - self._ui.address.set_text(str(info.jid)) - # Set contacts self._ui.contact_box.foreach(self._ui.contact_box.remove) has_contacts = bool(info.muc_contacts)
===================================== gajim/gtk/groupchat_invitation.py ===================================== @@ -0,0 +1,117 @@ +# This file is part of Gajim. +# +# Gajim is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published +# by the Free Software Foundation; version 3 only. +# +# Gajim is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Gajim. If not, see http://www.gnu.org/licenses/. + +from gi.repository import Gdk +from gi.repository import Gtk + +from gajim.common import app +from gajim.common.i18n import _ +from gajim.common.helpers import get_group_chat_nick + +from gajim.gtk.groupchat_info import GroupChatInfoScrolled +from gajim.gtk.groupchat_nick import NickChooser + + +class GroupChatInvitation(Gtk.ApplicationWindow): + def __init__(self, account, event): + Gtk.ApplicationWindow.__init__(self) + self.set_name('GroupChatInvitation') + self.set_application(app.app) + self.set_position(Gtk.WindowPosition.CENTER) + self.set_show_menubar(False) + self.set_title(_('Group Chat Invitation')) + self.set_type_hint(Gdk.WindowTypeHint.DIALOG) + + self.account = account + self._room_jid = str(event.muc) + self._from = str(event.from_) + self._password = event.password + + main_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=12) + main_box.set_valign(Gtk.Align.FILL) + main_box.get_style_context().add_class('padding-18') + + 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()) + contact_label.get_style_context().add_class('bold16') + contact_label.set_halign(Gtk.Align.CENTER) + contact_label.set_justify(Gtk.Justification.CENTER) + contact_label.set_line_wrap(True) + invitation_label = Gtk.Label( + label=_('Has invited you to a group chat.\nDo you want to join?')) + invitation_label.set_halign(Gtk.Align.CENTER) + 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_label) + main_box.add(invitation_label) + + decline_button = Gtk.Button.new_with_mnemonic(_('_Decline')) + decline_button.set_halign(Gtk.Align.START) + decline_button.connect('clicked', self._on_decline) + + self._nick_chooser = NickChooser() + self._nick_chooser.set_text( + get_group_chat_nick(self.account, event.info.jid)) + + join_button = Gtk.Button.new_with_mnemonic(_('_Join')) + join_button.set_halign(Gtk.Align.END) + join_button.get_style_context().add_class('suggested-action') + join_button.connect('clicked', self._on_join) + + join_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) + join_box.get_style_context().add_class('linked') + join_box.set_halign(Gtk.Align.END) + join_box.add(self._nick_chooser) + join_box.add(join_button) + + button_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL) + button_box.set_margin_top(6) + button_box.pack_start(decline_button, False, False, 0) + button_box.pack_end(join_box, False, False, 0) + + main_box.add(button_box) + + self.connect('key-press-event', self._on_key_press_event) + + self.add(main_box) + + join_button.set_can_default(True) + join_button.grab_focus() + + self.show_all() + + def _on_key_press_event(self, _widget, event): + if event.keyval == Gdk.KEY_Escape: + self.destroy() + + 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) + self.destroy() + + def _on_decline(self, _widget): + app.connections[self.account].get_module('MUC').decline( + self._room_jid, self._from) + self.destroy()
===================================== gajim/gui_interface.py ===================================== @@ -98,7 +98,6 @@ from gajim.gtk.dialogs import ConfirmationDialog from gajim.gtk.dialogs import ConfirmationCheckDialog from gajim.gtk.dialogs import InputDialog from gajim.gtk.dialogs import PassphraseDialog -from gajim.gtk.dialogs import InvitationReceivedDialog from gajim.gtk.filechoosers import FileChooserDialog from gajim.gtk.emoji_data import emoji_data from gajim.gtk.emoji_data import emoji_ascii_data @@ -376,28 +375,29 @@ class Interface: 'jid': event.from_})
def handle_event_gc_invitation(self, event): - if helpers.allow_popup_window(event.account) or not self.systray_enabled: - InvitationReceivedDialog(event.account, event) - return + event = events.GcInvitationtEvent(event)
- from_ = str(event.from_) - muc = str(event.muc) + if (helpers.allow_popup_window(event.account) or + not self.systray_enabled): + open_window('GroupChatInvitation', + account=event.account, + event=event) + return
- event_ = events.GcInvitationtEvent(event) - self.add_event(event.account, from_, event_) + self.add_event(event.account, str(event.from_), event)
if helpers.allow_showing_notification(event.account): + contact_name = event.get_inviter_name() event_type = _('Group Chat Invitation') - text = _('You are invited to {room} by {user}').format(room=muc, - user=from_) + text = _(f'{contact_name} invited you to {event.info.muc_name}') app.notification.popup(event_type, - from_, + str(event.from_), event.account, 'gc-invitation', 'gajim-gc_invitation', event_type, text, - room_jid=muc) + room_jid=event.muc)
@staticmethod def handle_event_client_cert_passphrase(obj): @@ -1165,7 +1165,9 @@ class Interface: event = app.events.get_first_event(account, jid, type_) if event is None: return - InvitationReceivedDialog(account, event) + open_window('GroupChatInvitation', + account=account, + event=event) app.events.remove_events(account, jid, event) self.roster.draw_contact(jid, account) elif type_ == 'subscription_request':
===================================== gajim/roster_window.py ===================================== @@ -68,7 +68,6 @@ from gajim.gtk.dialogs import ErrorDialog from gajim.gtk.dialogs import InputDialog from gajim.gtk.dialogs import WarningDialog from gajim.gtk.dialogs import InformationDialog -from gajim.gtk.dialogs import InvitationReceivedDialog from gajim.gtk.single_message import SingleMessageWindow from gajim.gtk.add_contact import AddNewContactWindow from gajim.gtk.service_registration import ServiceRegistration @@ -1918,7 +1917,9 @@ class RosterWindow: return True
if event.type_ == 'gc-invitation': - InvitationReceivedDialog(account, event) + open_window('GroupChatInvitation', + account=account, + event=event) app.events.remove_events(account, jid, event) return True
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/commit/c8d19f60b5aa149291768b37c4cf0e618...