Refactor SubscriptionWindow
This commit is contained in:
parent
80ceee57af
commit
e3effdcb6c
|
@ -1,27 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.18.3 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.12"/>
|
||||
<object class="GtkAccelGroup" id="accelgroup1"/>
|
||||
<object class="GtkMenu" id="subscription_request_popup_menu">
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkMenuItem" id="start_chat_menuitem">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">_Start Chat</property>
|
||||
<property name="use_underline">True</property>
|
||||
<signal name="activate" handler="on_start_chat_activate" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuItem" id="information_menuitem">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label">_Information</property>
|
||||
<property name="use_underline">True</property>
|
||||
<signal name="activate" handler="on_contact_info_activate" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
|
@ -1,29 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.18.3 -->
|
||||
<!-- Generated with glade 3.20.1 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.12"/>
|
||||
<object class="GtkImage" id="image1">
|
||||
<object class="GtkMenu" id="subscription_request_popup_menu">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="stock">gtk-add</property>
|
||||
</object>
|
||||
<object class="GtkImage" id="image2">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="stock">gtk-cancel</property>
|
||||
</object>
|
||||
<object class="GtkTextBuffer" id="textbuffer1"/>
|
||||
<object class="GtkWindow" id="subscription_request_window">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="border_width">12</property>
|
||||
<property name="title" translatable="yes">Subscription Request</property>
|
||||
<property name="resizable">False</property>
|
||||
<property name="type_hint">dialog</property>
|
||||
<signal name="destroy" handler="on_subscription_request_window_destroy" swapped="no"/>
|
||||
<child>
|
||||
<object class="GtkBox" id="vbox10">
|
||||
<object class="GtkMenuItem" id="start_chat_menuitem">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">_Start Chat</property>
|
||||
<property name="use_underline">True</property>
|
||||
<signal name="activate" handler="on_start_chat_activate" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuItem" id="information_menuitem">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label">_Information</property>
|
||||
<property name="use_underline">True</property>
|
||||
<signal name="activate" handler="on_contact_info_activate" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkBox" id="subscription_box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_left">18</property>
|
||||
<property name="margin_right">18</property>
|
||||
<property name="margin_top">18</property>
|
||||
<property name="margin_bottom">18</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">5</property>
|
||||
<child>
|
||||
|
@ -51,7 +58,6 @@
|
|||
<property name="editable">False</property>
|
||||
<property name="wrap_mode">word</property>
|
||||
<property name="cursor_visible">False</property>
|
||||
<property name="buffer">textbuffer1</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
|
@ -70,12 +76,12 @@
|
|||
<property name="layout_style">end</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="close_button">
|
||||
<property name="label">gtk-close</property>
|
||||
<property name="label">_Close</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="can_default">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="use_stock">True</property>
|
||||
<property name="use_underline">True</property>
|
||||
<signal name="clicked" handler="on_close_button_clicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
|
@ -92,7 +98,6 @@
|
|||
<property name="can_default">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="tooltip_text" translatable="yes">Deny authorization from contact so he or she cannot know when you're connected</property>
|
||||
<property name="image">image2</property>
|
||||
<property name="use_underline">True</property>
|
||||
<signal name="clicked" handler="on_deny_button_clicked" swapped="no"/>
|
||||
</object>
|
||||
|
@ -103,59 +108,23 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="actions_button">
|
||||
<object class="GtkMenuButton">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<signal name="clicked" handler="on_actions_button_clicked" swapped="no"/>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="popup">subscription_request_popup_menu</property>
|
||||
<property name="use_popover">False</property>
|
||||
<child>
|
||||
<object class="GtkBox" id="hbox3009">
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="spacing">2</property>
|
||||
<child>
|
||||
<object class="GtkImage" id="image1338">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="stock">gtk-execute</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label372">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes" comments="Make sure the character after "_" is not M/m (conflicts with Alt+M that is supposed to show the Emoticon Selector)">_Actions</property>
|
||||
<property name="use_underline">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkArrow" id="arrow4">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="arrow_type">down</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<property name="icon_name">applications-system-symbolic</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
@ -165,10 +134,8 @@
|
|||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="can_default">True</property>
|
||||
<property name="has_default">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="tooltip_text" translatable="yes">Authorize contact so he or she can know when you're connected</property>
|
||||
<property name="image">image1</property>
|
||||
<property name="use_underline">True</property>
|
||||
<signal name="clicked" handler="on_authorize_button_clicked" swapped="no"/>
|
||||
</object>
|
||||
|
@ -186,6 +153,4 @@
|
|||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
|
|
|
@ -2269,10 +2269,18 @@ class DoubleInputDialog:
|
|||
else:
|
||||
self.cancel_handler()
|
||||
|
||||
class SubscriptionRequestWindow:
|
||||
class SubscriptionRequestWindow(Gtk.ApplicationWindow):
|
||||
def __init__(self, jid, text, account, user_nick=None):
|
||||
Gtk.ApplicationWindow.__init__(self)
|
||||
self.set_name('SubscriptionRequest')
|
||||
self.set_application(app.app)
|
||||
self.set_show_menubar(False)
|
||||
self.set_resizable(False)
|
||||
self.set_position(Gtk.WindowPosition.CENTER)
|
||||
self.set_title(_('Subscription Request'))
|
||||
|
||||
xml = gtkgui_helpers.get_gtk_builder('subscription_request_window.ui')
|
||||
self.window = xml.get_object('subscription_request_window')
|
||||
self.add(xml.get_object('subscription_box'))
|
||||
self.jid = jid
|
||||
self.account = account
|
||||
self.user_nick = user_nick
|
||||
|
@ -2282,10 +2290,16 @@ class SubscriptionRequestWindow:
|
|||
% {'account': account, 'jid': self.jid}
|
||||
else:
|
||||
prompt_text = _('Subscription request from %s') % self.jid
|
||||
xml.get_object('from_label').set_text(prompt_text)
|
||||
xml.get_object('message_textview').get_buffer().set_text(text)
|
||||
|
||||
from_label = xml.get_object('from_label')
|
||||
from_label.set_text(prompt_text)
|
||||
|
||||
textview = xml.get_object('message_textview')
|
||||
textview.get_buffer().set_text(text)
|
||||
|
||||
self.set_default(xml.get_object('authorize_button'))
|
||||
xml.connect_signals(self)
|
||||
self.window.show_all()
|
||||
self.show_all()
|
||||
|
||||
def on_subscription_request_window_destroy(self, widget):
|
||||
"""
|
||||
|
@ -2295,21 +2309,15 @@ class SubscriptionRequestWindow:
|
|||
# remove us from open windows
|
||||
del app.interface.instances[self.account]['sub_request'][self.jid]
|
||||
|
||||
def prepare_popup_menu(self):
|
||||
xml = gtkgui_helpers.get_gtk_builder('subscription_request_popup_menu.ui')
|
||||
menu = xml.get_object('subscription_request_popup_menu')
|
||||
xml.connect_signals(self)
|
||||
return menu
|
||||
|
||||
def on_close_button_clicked(self, widget):
|
||||
self.window.destroy()
|
||||
self.destroy()
|
||||
|
||||
def on_authorize_button_clicked(self, widget):
|
||||
"""
|
||||
Accept the request
|
||||
"""
|
||||
app.connections[self.account].send_authorization(self.jid)
|
||||
self.window.destroy()
|
||||
self.destroy()
|
||||
contact = app.contacts.get_contact(self.account, self.jid)
|
||||
if not contact or _('Not in Roster') in contact.groups:
|
||||
AddNewContactWindow(self.account, self.jid, self.user_nick)
|
||||
|
@ -2342,16 +2350,7 @@ class SubscriptionRequestWindow:
|
|||
contact = app.contacts.get_contact(self.account, self.jid)
|
||||
if contact and _('Not in Roster') in contact.get_shown_groups():
|
||||
app.interface.roster.remove_contact(self.jid, self.account)
|
||||
self.window.destroy()
|
||||
|
||||
def on_actions_button_clicked(self, widget):
|
||||
"""
|
||||
Popup action menu
|
||||
"""
|
||||
menu = self.prepare_popup_menu()
|
||||
menu.show_all()
|
||||
gtkgui_helpers.popup_emoticons_under_button(menu, widget,
|
||||
self.window.get_window())
|
||||
self.destroy()
|
||||
|
||||
class JoinGroupchatWindow(Gtk.ApplicationWindow):
|
||||
def __init__(self, account, room_jid, password=None, automatic=None):
|
||||
|
|
|
@ -151,43 +151,6 @@ def get_completion_liststore(entry):
|
|||
entry.set_completion(completion)
|
||||
return liststore
|
||||
|
||||
|
||||
def popup_emoticons_under_button(menu, button, parent_win):
|
||||
"""
|
||||
Popup the emoticons menu under button, which is in parent_win
|
||||
"""
|
||||
window_x1, window_y1 = parent_win.get_origin()[1:]
|
||||
|
||||
def position_menu_under_button(menu, _x=None, _y=None, data=None):
|
||||
# inline function, which will not keep refs, when used as CB
|
||||
alloc = button.get_allocation()
|
||||
button_x, button_y = alloc.x, alloc.y
|
||||
translated_coordinates = button.translate_coordinates(
|
||||
app.interface.roster.window, 0, 0)
|
||||
if translated_coordinates:
|
||||
button_x, button_y = translated_coordinates
|
||||
|
||||
# now convert them to X11-relative
|
||||
window_x, window_y = window_x1, window_y1
|
||||
x = window_x + button_x
|
||||
y = window_y + button_y
|
||||
|
||||
menu_height = menu.get_preferred_size()[0].height
|
||||
|
||||
## should we pop down or up?
|
||||
if (y + alloc.height + menu_height < Gdk.Screen.height()):
|
||||
# now move the menu below the button
|
||||
y += alloc.height
|
||||
else:
|
||||
# now move the menu above the button
|
||||
y -= menu_height
|
||||
|
||||
# push_in is True so all the menuitems are always inside screen
|
||||
push_in = True
|
||||
return (x, y, push_in)
|
||||
|
||||
menu.popup(None, None, position_menu_under_button, None, 1, 0)
|
||||
|
||||
def get_theme_font_for_option(theme, option):
|
||||
"""
|
||||
Return string description of the font, stored in theme preferences
|
||||
|
|
|
@ -499,7 +499,7 @@ class Interface:
|
|||
account = obj.conn.name
|
||||
if helpers.allow_popup_window(account) or not self.systray_enabled:
|
||||
if obj.jid in self.instances[account]['sub_request']:
|
||||
self.instances[account]['sub_request'][obj.jid].window.destroy()
|
||||
self.instances[account]['sub_request'][obj.jid].destroy()
|
||||
self.instances[account]['sub_request'][obj.jid] = \
|
||||
dialogs.SubscriptionRequestWindow(obj.jid, obj.status, account,
|
||||
obj.user_nick)
|
||||
|
@ -829,7 +829,7 @@ class Interface:
|
|||
self.roster.draw_contact(obj.jid, account)
|
||||
if obj.jid in self.instances[account]['sub_request'] and obj.sub in (
|
||||
'from', 'both'):
|
||||
self.instances[account]['sub_request'][obj.jid].window.destroy()
|
||||
self.instances[account]['sub_request'][obj.jid].destroy()
|
||||
|
||||
def handle_event_bookmarks(self, obj):
|
||||
# ('BOOKMARKS', account, [{name,jid,autojoin,password,nick}, {}])
|
||||
|
|
Loading…
Reference in New Issue