Commit 687d0fda authored by Philipp Hörist's avatar Philipp Hörist

ChatControl: Access attributes on GtkBuilder directly

parent 52ccca95
......@@ -102,25 +102,21 @@ class ChatControl(ChatControlBase):
self.last_recv_message_marks = None
self.last_message_timestamp = None
self._formattings_button = self.xml.get_object('formattings_button')
self.emoticons_button = self.xml.get_object('emoticons_button')
self.toggle_emoticons()
self.widget_set_visible(self.xml.get_object('banner_eventbox'),
app.config.get('hide_chat_banner'))
self.widget_set_visible(self.xml.banner_eventbox,
app.config.get('hide_chat_banner'))
self.sendfile_button = self.xml.get_object('sendfile_button')
self.sendfile_button.set_action_name('win.send-file-' + \
self.control_id)
self.xml.sendfile_button.set_action_name(
'win.send-file-%s' % self.control_id)
# Menu for the HeaderBar
self.control_menu = gui_menu_builder.get_singlechat_menu(
self.control_id, self.account, self.contact.jid)
settings_menu = self.xml.get_object('settings_menu')
settings_menu.set_menu_model(self.control_menu)
self._audio_banner_image = self.xml.get_object('audio_banner_image')
self._video_banner_image = self.xml.get_object('video_banner_image')
# Settings menu
self.xml.settings_menu.set_menu_model(self.control_menu)
self.audio_sid = None
self.audio_state = self.JINGLE_STATE_NULL
self.audio_available = False
......@@ -133,7 +129,7 @@ class ChatControl(ChatControlBase):
self.show_avatar()
# Hook up signals
widget = self.xml.get_object('location_eventbox')
widget = self.xml.location_eventbox
id_ = widget.connect('button-release-event',
self.on_location_eventbox_button_release_event)
self.handlers[id_] = widget
......@@ -151,11 +147,11 @@ class ChatControl(ChatControlBase):
id_ = widget.connect('released', self.on_num_button_released)
self.handlers[id_] = widget
widget = self.xml.get_object('mic_hscale')
widget = self.xml.mic_hscale
id_ = widget.connect('value_changed', self.on_mic_hscale_value_changed)
self.handlers[id_] = widget
widget = self.xml.get_object('sound_hscale')
widget = self.xml.sound_hscale
id_ = widget.connect('value_changed', self.on_sound_hscale_value_changed)
self.handlers[id_] = widget
......@@ -168,9 +164,9 @@ class ChatControl(ChatControlBase):
self.info_bar_label.set_ellipsize(Pango.EllipsizeMode.END)
content_area.add(self.info_bar_label)
self.info_bar.set_no_show_all(True)
widget = self.xml.get_object('vbox2')
widget.pack_start(self.info_bar, False, True, 5)
widget.reorder_child(self.info_bar, 1)
self.xml.vbox2.pack_start(self.info_bar, False, True, 5)
self.xml.vbox2.reorder_child(self.info_bar, 1)
# List of waiting infobar messages
self.info_bar_queue = []
......@@ -196,8 +192,7 @@ class ChatControl(ChatControlBase):
self.update_ui()
self.set_lock_image()
self.encryption_menu = self.xml.get_object('encryption_menu')
self.encryption_menu.set_menu_model(
self.xml.encryption_menu.set_menu_model(
gui_menu_builder.get_encryption_menu(
self.control_id, self.type_id, self.account == 'Local'))
self.set_encryption_menu_icon()
......@@ -326,7 +321,7 @@ class ChatControl(ChatControlBase):
tooltip_text = _('Send File…')
else:
tooltip_text = _('No File Transfer available')
self.sendfile_button.set_tooltip_text(tooltip_text)
self.xml.sendfile_button.set_tooltip_text(tooltip_text)
# Convert to GC
if app.config.get_per('accounts', self.account, 'is_zeroconf'):
......@@ -411,12 +406,12 @@ class ChatControl(ChatControlBase):
# Formatting
# TODO: find out what encryption allows for xhtml and which not
if self.contact.supports(NS_XHTML_IM):
self._formattings_button.set_sensitive(True)
self._formattings_button.set_tooltip_text(_(
self.xml.formattings_button.set_sensitive(True)
self.xml.formattings_button.set_tooltip_text(_(
'Show a list of formattings'))
else:
self._formattings_button.set_sensitive(False)
self._formattings_button.set_tooltip_text(
self.xml.formattings_button.set_sensitive(False)
self.xml.formattings_button.set_tooltip_text(
_('This contact does not support HTML'))
# Jingle detection
......@@ -462,13 +457,13 @@ class ChatControl(ChatControlBase):
def _get_pep_widget(self, type_):
if type_ == PEPEventType.MOOD:
return self.xml.get_object('mood_image')
return self.xml.mood_image
if type_ == PEPEventType.ACTIVITY:
return self.xml.get_object('activity_image')
return self.xml.activity_image
if type_ == PEPEventType.TUNE:
return self.xml.get_object('tune_image')
return self.xml.tune_image
if type_ == PEPEventType.LOCATION:
return self.xml.get_object('location_image')
return self.xml.location_image
@ensure_proper_control
def _on_mood_received(self, _event):
......@@ -498,7 +493,7 @@ class ChatControl(ChatControlBase):
self.account, event.jid, event.resource)
if contact is None:
return
self.xml.get_object('phone_image').set_visible(contact.uses_phone)
self.xml.phone_image.set_visible(contact.uses_phone)
def _update_jingle(self, jingle_type):
if jingle_type not in ('audio', 'video'):
......@@ -525,15 +520,15 @@ class ChatControl(ChatControlBase):
def update_audio(self):
self._update_jingle('audio')
hbox = self.xml.get_object('audio_buttons_hbox')
hbox = self.xml.audio_buttons_hbox
if self.audio_state == self.JINGLE_STATE_CONNECTED:
# Set volume from config
input_vol = app.config.get('audio_input_volume')
output_vol = app.config.get('audio_output_volume')
input_vol = max(min(input_vol, 100), 0)
output_vol = max(min(output_vol, 100), 0)
self.xml.get_object('mic_hscale').set_value(input_vol)
self.xml.get_object('sound_hscale').set_value(output_vol)
self.xml.mic_hscale.set_value(input_vol)
self.xml.sound_hscale.set_value(output_vol)
# Show vbox
hbox.set_no_show_all(False)
hbox.show_all()
......@@ -656,8 +651,6 @@ class ChatControl(ChatControlBase):
contact = self.contact
jid = contact.jid
banner_name_label = self.xml.get_object('banner_name_label')
name = contact.get_shown_name()
if self.resource:
name += '/' + self.resource
......@@ -717,18 +710,18 @@ class ChatControl(ChatControlBase):
if status_escaped:
status_text = make_href_markup(status_escaped)
status_text = '<span size="x-small" weight="light">%s</span>' % status_text
self.banner_status_label.set_tooltip_text(status)
self.banner_status_label.set_no_show_all(False)
self.banner_status_label.show()
self.xml.banner_label.set_tooltip_text(status)
self.xml.banner_label.set_no_show_all(False)
self.xml.banner_label.show()
else:
status_text = ''
self.banner_status_label.hide()
self.banner_status_label.set_no_show_all(True)
self.xml.banner_label.hide()
self.xml.banner_label.set_no_show_all(True)
self.banner_status_label.set_markup(status_text)
self.xml.banner_label.set_markup(status_text)
# setup the label that holds name and jid
banner_name_label.set_markup(label_text)
banner_name_label.set_tooltip_text(label_tooltip)
self.xml.banner_name_label.set_markup(label_text)
self.xml.banner_name_label.set_tooltip_text(label_tooltip)
def close_jingle_content(self, jingle_type):
sid = getattr(self, jingle_type + '_sid')
......@@ -751,13 +744,13 @@ class ChatControl(ChatControlBase):
if getattr(self, jingle_type + '_state') == \
self.JINGLE_STATE_NULL:
if jingle_type == 'video':
video_hbox = self.xml.get_object('video_hbox')
video_hbox = self.xml.video_hbox
video_hbox.set_no_show_all(False)
if app.config.get('video_see_self'):
fixed = self.xml.get_object('outgoing_fixed')
fixed = self.xml.outgoing_fixed
fixed.set_no_show_all(False)
video_hbox.show_all()
out_da = self.xml.get_object('outgoing_drawingarea')
out_da = self.xml.outgoing_drawingarea
out_da.realize()
if os.name == 'nt':
out_xid = out_da.get_window().handle
......@@ -766,7 +759,7 @@ class ChatControl(ChatControlBase):
else:
out_xid = None
video_hbox.show_all()
in_da = self.xml.get_object('incoming_drawingarea')
in_da = self.xml.incoming_drawingarea
in_da.realize()
in_xid = in_da.get_window().get_xid()
sid = app.connections[self.account].get_module('Jingle').start_video(
......@@ -776,10 +769,10 @@ class ChatControl(ChatControlBase):
'start_' + jingle_type)(self.contact.get_full_jid())
getattr(self, 'set_' + jingle_type + '_state')('connecting', sid)
else:
video_hbox = self.xml.get_object('video_hbox')
video_hbox = self.xml.video_hbox
video_hbox.set_no_show_all(True)
video_hbox.hide()
fixed = self.xml.get_object('outgoing_fixed')
fixed = self.xml.outgoing_fixed
fixed.set_no_show_all(True)
self.close_jingle_content(jingle_type)
......
......@@ -158,15 +158,15 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
self.parent_win.redraw_tab(self)
def setup_seclabel(self):
self.seclabel_combo.hide()
self.seclabel_combo.set_no_show_all(True)
self.xml.label_selector.hide()
self.xml.label_selector.set_no_show_all(True)
lb = Gtk.ListStore(str)
self.seclabel_combo.set_model(lb)
self.xml.label_selector.set_model(lb)
cell = Gtk.CellRendererText()
cell.set_property('xpad', 5) # padding for status text
self.seclabel_combo.pack_start(cell, True)
self.xml.label_selector.pack_start(cell, True)
# text to show is in in first column of liststore
self.seclabel_combo.add_attribute(cell, 'text', 0)
self.xml.label_selector.add_attribute(cell, 'text', 0)
con = app.connections[self.account]
jid = self.contact.jid
if self.TYPE_ID == 'pm':
......@@ -184,7 +184,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
if event.jid != jid:
return
model = self.seclabel_combo.get_model()
model = self.xml.label_selector.get_model()
model.clear()
sel = 0
......@@ -194,9 +194,9 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
if label == default:
sel = index
self.seclabel_combo.set_active(sel)
self.seclabel_combo.set_no_show_all(False)
self.seclabel_combo.show_all()
self.xml.label_selector.set_active(sel)
self.xml.label_selector.set_no_show_all(False)
self.xml.label_selector.show_all()
def __init__(self, type_id, parent_win, widget_name, contact, acct,
resource=None):
......@@ -217,16 +217,16 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
if self.TYPE_ID != message_control.TYPE_GC:
# Create banner and connect signals
widget = self.xml.get_object('banner_eventbox')
id_ = widget.connect('button-press-event',
id_ = self.xml.banner_eventbox.connect(
'button-press-event',
self._on_banner_eventbox_button_press_event)
self.handlers[id_] = widget
self.handlers[id_] = self.xml.banner_eventbox
self.banner_status_label = self.xml.get_object('banner_label')
if self.banner_status_label is not None:
id_ = self.banner_status_label.connect('populate_popup',
if self.xml.banner_label is not None:
id_ = self.xml.banner_label.connect(
'populate_popup',
self.on_banner_label_populate_popup)
self.handlers[id_] = self.banner_status_label
self.handlers[id_] = self.xml.banner_label
# Init DND
self.TARGET_TYPE_URI_LIST = 80
......@@ -274,8 +274,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
self._on_html_textview_grab_focus)
self.handlers[id_] = self.conv_textview.tv
self.conv_scrolledwindow = self.xml.get_object(
'conversation_scrolledwindow')
self.conv_scrolledwindow = self.xml.conversation_scrolledwindow
self.conv_scrolledwindow.add(self.conv_textview.tv)
widget = self.conv_scrolledwindow.get_vadjustment()
id_ = widget.connect('changed',
......@@ -295,8 +294,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
self.msg_scrolledwindow = ScrolledWindow()
self.msg_scrolledwindow.add(self.msg_textview)
hbox = self.xml.get_object('hbox')
hbox.pack_start(self.msg_scrolledwindow, True, True, 0)
self.xml.hbox.pack_start(self.msg_scrolledwindow, True, True, 0)
id_ = self.msg_textview.connect('paste-clipboard',
self._on_message_textview_paste_event)
......@@ -317,8 +315,6 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
self.dnd_list,
Gdk.DragAction.COPY)
self._overlay = self.xml.get_object('overlay')
# the following vars are used to keep history of user's messages
self.sent_history = []
self.sent_history_pos = 0
......@@ -338,9 +334,6 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
self.command_hits = []
self.last_key_tabs = False
# Security Labels
self.seclabel_combo = self.xml.get_object('label_selector')
con = app.connections[self.account]
con.get_module('Chatstate').set_active(self.contact)
......@@ -393,7 +386,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
return Gdk.EVENT_STOP
if action == 'show-emoji-chooser':
self.emoticons_button.get_popover().show()
self.xml.emoticons_button.get_popover().show()
return Gdk.EVENT_STOP
if action == 'copy-text':
......@@ -497,10 +490,10 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
return state
def set_encryption_menu_icon(self):
image = self.encryption_menu.get_image()
image = self.xml.encryption_menu.get_image()
if image is None:
image = Gtk.Image()
self.encryption_menu.set_image(image)
self.xml.encryption_menu.set_image(image)
if not self.encryption:
image.set_from_icon_name('channel-insecure-symbolic',
Gtk.IconSize.MENU)
......@@ -878,7 +871,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
ft.send_file(self.account, contact, path)
def get_seclabel(self):
idx = self.seclabel_combo.get_active()
idx = self.xml.label_selector.get_active()
if idx == -1:
return
......@@ -1098,11 +1091,11 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
Hide show emoticons_button
"""
if app.config.get('emoticons_theme'):
self.emoticons_button.set_no_show_all(False)
self.emoticons_button.show()
self.xml.emoticons_button.set_no_show_all(False)
self.xml.emoticons_button.show()
else:
self.emoticons_button.set_no_show_all(True)
self.emoticons_button.hide()
self.xml.emoticons_button.set_no_show_all(True)
self.xml.emoticons_button.hide()
def set_emoticon_popover(self):
if not app.config.get('emoticons_theme'):
......@@ -1112,8 +1105,7 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
return
emoji_chooser.text_widget = self.msg_textview
emoticons_button = self.xml.get_object('emoticons_button')
emoticons_button.set_popover(emoji_chooser)
self.xml.emoticons_button.set_popover(emoji_chooser)
def on_color_menuitem_activate(self, widget):
color_dialog = Gtk.ColorChooserDialog(None, self.parent_win.window)
......
......@@ -356,6 +356,7 @@
<child>
<object class="GtkMenuButton" id="formattings_button">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="focus_on_click">False</property>
<property name="receives_default">True</property>
......
......@@ -93,12 +93,8 @@ class GroupchatControl(ChatControlBase):
self.force_non_minimizable = False
self.is_anonymous = True
self.emoticons_button = self.xml.get_object('emoticons_button')
self.toggle_emoticons()
formattings_button = self.xml.get_object('formattings_button')
formattings_button.set_sensitive(False)
self.room_jid = self.contact.jid
self._muc_data = muc_data
......@@ -138,32 +134,26 @@ class GroupchatControl(ChatControlBase):
self._nick_completion = NickCompletionGenerator(muc_data.nick)
self.last_key_tabs = False
self.name_label = self.xml.get_object('banner_name_label')
self.event_box = self.xml.get_object('banner_eventbox')
self.setup_seclabel()
# Send file
self.sendfile_button = self.xml.get_object('sendfile_button')
self.sendfile_button.set_action_name('win.send-file-' + \
self.control_id)
self.xml.sendfile_button.set_action_name(
'win.send-file-%s' % self.control_id)
# Encryption
self.set_lock_image()
self.encryption_menu = self.xml.get_object('encryption_menu')
self.encryption_menu.set_menu_model(
self.xml.encryption_menu.set_menu_model(
gui_menu_builder.get_encryption_menu(self.control_id, self.type_id))
self.set_encryption_menu_icon()
# Banner
self.banner_actionbar = self.xml.get_object('banner_actionbar')
self.hide_roster_button = Gtk.Button.new_from_icon_name(
'go-next-symbolic', Gtk.IconSize.MENU)
self.hide_roster_button.set_valign(Gtk.Align.CENTER)
self.hide_roster_button.connect('clicked',
lambda *args: self.show_roster())
self.banner_actionbar.pack_end(self.hide_roster_button)
self.xml.banner_actionbar.pack_end(self.hide_roster_button)
# Holds CaptchaRequest widget
self._captcha_request = None
......@@ -176,8 +166,8 @@ class GroupchatControl(ChatControlBase):
self.control_menu = gui_menu_builder.get_groupchat_menu(self.control_id,
self.account,
self.room_jid)
settings_menu = self.xml.get_object('settings_menu')
settings_menu.set_menu_model(self.control_menu)
self.xml.settings_menu.set_menu_model(self.control_menu)
self._event_handlers = [
('muc-creation-failed', ged.GUI1, self._on_muc_creation_failed),
......@@ -401,7 +391,7 @@ class GroupchatControl(ChatControlBase):
tooltip_text = _('Send File (max. %s MiB)…') % max_file_size
else:
tooltip_text = _('No File Transfer available')
self.sendfile_button.set_tooltip_text(tooltip_text)
self.xml.sendfile_button.set_tooltip_text(tooltip_text)
# Upload Avatar
vcard_support = False
......@@ -781,7 +771,7 @@ class GroupchatControl(ChatControlBase):
Draw the text in the fat line at the top of the window that houses the
room jid
"""
self.name_label.set_text(self.room_name)
self.xml.banner_name_label.set_text(self.room_name)
def _nec_update_room_avatar(self, obj):
if obj.jid != self.room_jid:
......@@ -1134,14 +1124,12 @@ class GroupchatControl(ChatControlBase):
# Update Roster
app.interface.roster.draw_contact(self.room_jid, self.account)
formattings_button = self.xml.get_object('formattings_button')
formattings_button.set_sensitive(True)
self.xml.formattings_button.set_sensitive(True)
self.update_actions()
def got_disconnected(self):
formattings_button = self.xml.get_object('formattings_button')
formattings_button.set_sensitive(False)
self.xml.formattings_button.set_sensitive(False)
self.roster.enable_sort(False)
self.roster.clear()
......
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