Commit e3effdcb authored by Philipp Hörist's avatar Philipp Hörist

Refactor SubscriptionWindow

parent 80ceee57
<?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>
......@@ -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}, {}])
......
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