Commit c778ed69 authored by Philipp Hörist's avatar Philipp Hörist Committed by Philipp Hörist

Move Preferences into own module

- Port Preferences to Gtk.ApplicationWindow
parent 42adff1b
......@@ -69,11 +69,10 @@ def tree_model_pre_order(model, treeiter):
class AdvancedConfigurationWindow(object):
def __init__(self):
def __init__(self, transient):
self.xml = gtkgui_helpers.get_gtk_builder('advanced_configuration_window.ui')
self.window = self.xml.get_object('advanced_configuration_window')
self.window.set_transient_for(
app.interface.instances['preferences'].window)
self.window.set_transient_for(transient)
self.entry = self.xml.get_object('advanced_entry')
self.desc_label = self.xml.get_object('advanced_desc_label')
self.restart_box = self.xml.get_object('restart_box')
......
......@@ -28,6 +28,7 @@ from gajim import disco
from gajim.gtk.history_sync import HistorySyncAssistant
from gajim.gtk.server_info import ServerInfoDialog
from gajim.gtk.mam_preferences import MamPreferences
from gajim.gtk.preferences import Preferences
from gajim.gtk import JoinGroupchatWindow
from gajim.gtk import StartChatDialog
from gajim.gtk import AddNewContactWindow
......@@ -50,11 +51,11 @@ def on_add_contact_jid(action, param):
def on_preferences(action, param):
if 'preferences' in interface.instances:
interface.instances['preferences'].window.present()
window = app.get_app_window(Preferences)
if window is None:
Preferences()
else:
interface.instances['preferences'] = \
config.PreferencesWindow()
window.present()
def on_plugins(action, param):
......
......@@ -35,1149 +35,19 @@ import os
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import Pango
from gi.repository import GObject
from gi.repository import GLib
from gajim.common import config as c_config
from gajim.common import idle
from gajim.common.i18n import Q_
from gajim import gtkgui_helpers
from gajim import dialogs
from gajim import cell_renderer_image
from gajim import message_control
from gajim.chat_control_base import ChatControlBase
from gajim.gajim_themes_window import GajimThemesWindow
from gajim.advanced_configuration_window import AdvancedConfigurationWindow
from gajim import dataforms_widget
from gajim import gui_menu_builder
from gajim.gtk import AspellDictError
from gajim.gtk import ConfirmationDialog
from gajim.gtk import ConfirmationDialogDoubleRadio
from gajim.gtk import ErrorDialog
from gajim.gtk import InputDialog
from gajim.gtk import WarningDialog
from gajim.common import helpers
from gajim.common import app
from gajim.common import connection
from gajim.common.modules import dataforms
from gajim.common import ged
from gajim.common import configpaths
from gajim.accounts_window import AccountsWindow
try:
from gajim.common.multimedia_helpers import AudioInputManager, AudioOutputManager
from gajim.common.multimedia_helpers import VideoInputManager, VideoOutputManager
HAS_GST = True
except (ImportError, ValueError):
HAS_GST = False
if app.is_installed('GSPELL'):
from gi.repository import Gspell
#---------- PreferencesWindow class -------------#
class PreferencesWindow:
"""
Class for Preferences window
"""
def on_preferences_window_destroy(self, widget):
"""
Close window
"""
del app.interface.instances['preferences']
def __init__(self):
"""
Initialize Preferences window
"""
self.xml = gtkgui_helpers.get_gtk_builder('preferences_window.ui')
self.window = self.xml.get_object('preferences_window')
self.window.set_transient_for(app.interface.roster.window)
self.notebook = self.xml.get_object('preferences_notebook')
self.one_window_type_combobox = self.xml.get_object(
'one_window_type_combobox')
self.iconset_combobox = self.xml.get_object('iconset_combobox')
self.notify_on_signin_checkbutton = self.xml.get_object(
'notify_on_signin_checkbutton')
self.notify_on_signout_checkbutton = self.xml.get_object(
'notify_on_signout_checkbutton')
self.auto_popup_away_checkbutton = self.xml.get_object(
'auto_popup_away_checkbutton')
self.auto_popup_chat_opened_checkbutton = self.xml.get_object(
'auto_popup_chat_opened_checkbutton')
self.sound_dnd_checkbutton = self.xml.get_object('sound_dnd_checkbutton')
self.auto_away_checkbutton = self.xml.get_object('auto_away_checkbutton')
self.auto_away_time_spinbutton = self.xml.get_object(
'auto_away_time_spinbutton')
self.auto_away_message_entry = self.xml.get_object(
'auto_away_message_entry')
self.auto_xa_checkbutton = self.xml.get_object('auto_xa_checkbutton')
self.auto_xa_time_spinbutton = self.xml.get_object(
'auto_xa_time_spinbutton')
self.auto_xa_message_entry = self.xml.get_object('auto_xa_message_entry')
### General tab ###
# Display avatars in roster
st = app.config.get('show_avatars_in_roster')
self.xml.get_object('show_avatars_in_roster_checkbutton'). \
set_active(st)
# Display status msg under contact name in roster
st = app.config.get('show_status_msgs_in_roster')
self.xml.get_object('show_status_msgs_in_roster_checkbutton'). \
set_active( st)
# Display PEP in roster
st1 = app.config.get('show_mood_in_roster')
st2 = app.config.get('show_activity_in_roster')
st3 = app.config.get('show_tunes_in_roster')
st4 = app.config.get('show_location_in_roster')
w = self.xml.get_object('show_pep_in_roster_checkbutton')
if st1 == st2 == st3 == st4:
w.set_active(st1)
else:
w.set_inconsistent(True)
# Sort contacts by show
st = app.config.get('sort_by_show_in_roster')
self.xml.get_object('sort_by_show_in_roster_checkbutton').set_active(st)
st = app.config.get('sort_by_show_in_muc')
self.xml.get_object('sort_by_show_in_muc_checkbutton').set_active(st)
# emoticons
emoticons_combobox = self.xml.get_object('emoticons_combobox')
emoticon_themes = helpers.get_available_emoticon_themes()
emoticons_combobox.append_text(_('Disabled'))
for theme in emoticon_themes:
emoticons_combobox.append_text(theme)
config_theme = app.config.get('emoticons_theme')
if config_theme not in emoticon_themes:
config_theme = _('Disabled')
emoticons_combobox.set_id_column(0)
emoticons_combobox.set_active_id(config_theme)
# Set default for single window type
choices = c_config.opt_one_window_types
type_ = app.config.get('one_message_window')
if type_ in choices:
self.one_window_type_combobox.set_active(choices.index(type_))
else:
self.one_window_type_combobox.set_active(0)
# Show roster on startup
show_roster_combobox = self.xml.get_object('show_roster_on_startup')
choices = c_config.opt_show_roster_on_startup
type_ = app.config.get('show_roster_on_startup')
if type_ in choices:
show_roster_combobox.set_active(choices.index(type_))
else:
show_roster_combobox.set_active(0)
# Ignore XHTML
st = app.config.get('ignore_incoming_xhtml')
self.xml.get_object('xhtml_checkbutton').set_active(st)
# use speller
if app.is_installed('GSPELL'):
st = app.config.get('use_speller')
self.xml.get_object('speller_checkbutton').set_active(st)
else:
self.xml.get_object('speller_checkbutton').set_sensitive(False)
# XEP-0184 positive ack
st = app.config.get('positive_184_ack')
self.xml.get_object('positive_184_ack_checkbutton').set_active(st)
# Show avatar in tabs
st = app.config.get('show_avatar_in_tabs')
self.xml.get_object('show_avatar_in_tabs_checkbutton').set_active(st)
### Style tab ###
# Themes
theme_combobox = self.xml.get_object('theme_combobox')
cell = Gtk.CellRendererText()
theme_combobox.pack_start(cell, True)
theme_combobox.add_attribute(cell, 'text', 0)
self.update_theme_list()
# iconset
iconsets_list = os.listdir(
os.path.join(configpaths.get('DATA'), 'iconsets'))
if os.path.isdir(configpaths.get('MY_ICONSETS')):
iconsets_list += os.listdir(configpaths.get('MY_ICONSETS'))
# new model, image in 0, string in 1
model = Gtk.ListStore(Gtk.Image, str)
renderer_image = cell_renderer_image.CellRendererImage(0, 0)
renderer_text = Gtk.CellRendererText()
renderer_text.set_property('xpad', 5)
self.iconset_combobox.pack_start(renderer_image, False)
self.iconset_combobox.pack_start(renderer_text, True)
self.iconset_combobox.add_attribute(renderer_text, 'text', 1)
self.iconset_combobox.add_attribute(renderer_image, 'image', 0)
self.iconset_combobox.set_model(model)
l = []
for dir in iconsets_list:
if not os.path.isdir(os.path.join(configpaths.get('DATA'), 'iconsets', dir)) \
and not os.path.isdir(os.path.join(configpaths.get('MY_ICONSETS'), dir)):
continue
if dir != '.svn' and dir != 'transports':
l.append(dir)
if l.count == 0:
l.append(' ')
for i in range(len(l)):
preview = Gtk.Image()
files = []
files.append(os.path.join(helpers.get_iconset_path(l[i]), '16x16',
'online.png'))
files.append(os.path.join(helpers.get_iconset_path(l[i]), '16x16',
'online.gif'))
for file_ in files:
if os.path.exists(file_):
preview.set_from_file(file_)
model.append([preview, l[i]])
if app.config.get('iconset') == l[i]:
self.iconset_combobox.set_active(i)
# Use transports iconsets
st = app.config.get('use_transports_iconsets')
self.xml.get_object('transports_iconsets_checkbutton').set_active(st)
# Color widgets
self.draw_color_widgets()
# Font for messages
font = app.config.get('conversation_font')
# try to set default font for the current desktop env
fontbutton = self.xml.get_object('conversation_fontbutton')
if font == '':
fontbutton.set_sensitive(False)
self.xml.get_object('default_chat_font').set_active(True)
else:
fontbutton.set_font_name(font)
### Personal Events tab ###
# outgoing send chat state notifications
st = app.config.get('outgoing_chat_state_notifications')
combo = self.xml.get_object('outgoing_chat_states_combobox')
if st == 'all':
combo.set_active(0)
elif st == 'composing_only':
combo.set_active(1)
else: # disabled
combo.set_active(2)
# displayed send chat state notifications
st = app.config.get('displayed_chat_state_notifications')
combo = self.xml.get_object('displayed_chat_states_combobox')
if st == 'all':
combo.set_active(0)
elif st == 'composing_only':
combo.set_active(1)
else: # disabled
combo.set_active(2)
### Notifications tab ###
# On new event
on_event_combobox = self.xml.get_object('on_event_combobox')
if app.config.get('autopopup'):
on_event_combobox.set_active(0)
elif app.config.get('notify_on_new_message'):
on_event_combobox.set_active(1)
else:
on_event_combobox.set_active(2)
# notify on online statuses
st = app.config.get('notify_on_signin')
self.notify_on_signin_checkbutton.set_active(st)
# notify on offline statuses
st = app.config.get('notify_on_signout')
self.notify_on_signout_checkbutton.set_active(st)
# autopopupaway
st = app.config.get('autopopupaway')
self.auto_popup_away_checkbutton.set_active(st)
# autopopup_chat_opened
st = app.config.get('autopopup_chat_opened')
self.auto_popup_chat_opened_checkbutton.set_active(st)
# sounddnd
st = app.config.get('sounddnd')
self.sound_dnd_checkbutton.set_active(st)
# Systray
systray_combobox = self.xml.get_object('systray_combobox')
if app.config.get('trayicon') == 'never':
systray_combobox.set_active(0)
elif app.config.get('trayicon') == 'on_event':
systray_combobox.set_active(1)
else:
systray_combobox.set_active(2)
# sounds
if app.config.get('sounds_on'):
self.xml.get_object('play_sounds_checkbutton').set_active(True)
else:
self.xml.get_object('manage_sounds_button').set_sensitive(False)
#### Status tab ###
# Autoaway
st = app.config.get('autoaway')
self.auto_away_checkbutton.set_active(st)
# Autoawaytime
st = app.config.get('autoawaytime')
self.auto_away_time_spinbutton.set_value(st)
self.auto_away_time_spinbutton.set_sensitive(app.config.get('autoaway'))
# autoaway message
st = app.config.get('autoaway_message')
self.auto_away_message_entry.set_text(st)
self.auto_away_message_entry.set_sensitive(app.config.get('autoaway'))
# Autoxa
st = app.config.get('autoxa')
self.auto_xa_checkbutton.set_active(st)
# Autoxatime
st = app.config.get('autoxatime')
self.auto_xa_time_spinbutton.set_value(st)
self.auto_xa_time_spinbutton.set_sensitive(app.config.get('autoxa'))
# autoxa message
st = app.config.get('autoxa_message')
self.auto_xa_message_entry.set_text(st)
self.auto_xa_message_entry.set_sensitive(app.config.get('autoxa'))
if not idle.Monitor.is_available():
self.xml.get_object('autoaway_table').set_sensitive(False)
# ask_status when online / offline
st = app.config.get('ask_online_status')
self.xml.get_object('prompt_online_status_message_checkbutton').\
set_active(st)
st = app.config.get('ask_offline_status')
self.xml.get_object('prompt_offline_status_message_checkbutton').\
set_active(st)
# Default Status messages
self.default_msg_tree = self.xml.get_object('default_msg_treeview')
self.fill_default_msg_treeview()
# Status messages
self.msg_tree = self.xml.get_object('msg_treeview')
renderer = Gtk.CellRendererText()
renderer.connect('edited', self.on_msg_cell_edited)
renderer.set_property('editable', True)
col = Gtk.TreeViewColumn('name', renderer, text=0)
self.msg_tree.append_column(col)
self.fill_msg_treeview()
buf = self.xml.get_object('msg_textview').get_buffer()
buf.connect('end-user-action', self.on_msg_textview_changed)
### Audio / Video tab ###
def create_av_combobox(opt_name, device_dict, config_name=None,
key=None):
combobox = self.xml.get_object(opt_name + '_combobox')
cell = Gtk.CellRendererText()
cell.set_property('ellipsize', Pango.EllipsizeMode.END)
cell.set_property('ellipsize-set', True)
combobox.pack_start(cell, True)
combobox.add_attribute(cell, 'text', 0)
model = Gtk.ListStore(str, str)
combobox.set_model(model)
if config_name:
config = app.config.get(config_name)
else:
config = app.config.get(opt_name + '_device')
for index, (name, value) in enumerate(sorted(device_dict.items(),
key=key)):
model.append((name, value))
if config == value:
combobox.set_active(index)
if HAS_GST and app.is_installed('FARSTREAM'):
create_av_combobox('audio_input', AudioInputManager().get_devices())
create_av_combobox('audio_output', AudioOutputManager().get_devices(
))
create_av_combobox('video_input', VideoInputManager().get_devices())
create_av_combobox('video_output', VideoOutputManager().get_devices(
))
create_av_combobox('video_framerate', {_('Default'): '',
'15fps': '15/1', '10fps': '10/1', '5fps': '5/1',
'2.5fps': '5/2'}, 'video_framerate', key=lambda x: -1 if \
not x[1] else float(x[0][:-3]))
create_av_combobox('video_size', {_('Default'): '',
'800x600': '800x600', '640x480': '640x480',
'320x240': '320x240'}, 'video_size', key=lambda x: -1 if \
not x[1] else int(x[0][:3]))
st = app.config.get('video_see_self')
self.xml.get_object('video_see_self_checkbutton').set_active(st)
else:
for opt_name in ('audio_input', 'audio_output', 'video_input',
'video_output', 'video_framerate', 'video_size'):
combobox = self.xml.get_object(opt_name + '_combobox')
combobox.set_sensitive(False)
# STUN
cb = self.xml.get_object('stun_checkbutton')
st = app.config.get('use_stun_server')
cb.set_active(st)
entry = self.xml.get_object('stun_server_entry')
entry.set_text(app.config.get('stun_server'))
if not st:
entry.set_sensitive(False)
### Advanced tab ###
# open links with
if os.name == 'nt':
applications_frame = self.xml.get_object('applications_frame')
applications_frame.set_no_show_all(True)
applications_frame.hide()
else:
self.applications_combobox = self.xml.get_object(
'applications_combobox')
self.xml.get_object('custom_apps_frame').hide()
self.xml.get_object('custom_apps_frame').set_no_show_all(True)
if app.config.get('autodetect_browser_mailer'):
self.applications_combobox.set_active(0)
else:
self.applications_combobox.set_active(1)
self.xml.get_object('custom_apps_frame').show()
self.xml.get_object('custom_browser_entry').set_text(
app.config.get('custombrowser'))
self.xml.get_object('custom_mail_client_entry').set_text(
app.config.get('custommailapp'))
self.xml.get_object('custom_file_manager_entry').set_text(
app.config.get('custom_file_manager'))
# log status changes of contacts
st = app.config.get('log_contact_status_changes')
self.xml.get_object('log_show_changes_checkbutton').set_active(st)
# send os info
w = self.xml.get_object('send_os_info_checkbutton')
st = self.get_per_account_option('send_os_info')
if st == 'mixed':
w.set_inconsistent(True)
else:
w.set_active(st)
# send absolute time info
w = self.xml.get_object('send_time_info_checkbutton')
st = self.get_per_account_option('send_time_info')
if st == 'mixed':
w.set_inconsistent(True)
else:
w.set_active(st)
# send idle time
w = self.xml.get_object('send_idle_time_checkbutton')
st = self.get_per_account_option('send_idle_time')
if st == 'mixed':
w.set_inconsistent(True)
else:
w.set_active(st)
self.update_proxy_list()
# Ignore messages from unknown contacts
w = self.xml.get_object('ignore_events_from_unknown_contacts_checkbutton')
st = self.get_per_account_option('ignore_unknown_contacts')
if st == 'mixed':
w.set_inconsistent(True)
else:
w.set_active(st)
self.xml.connect_signals(self)
self.msg_tree.get_model().connect('row-changed',
self.on_msg_treemodel_row_changed)
self.msg_tree.get_model().connect('row-deleted',
self.on_msg_treemodel_row_deleted)
self.default_msg_tree.get_model().connect('row-changed',
self.on_default_msg_treemodel_row_changed)
self.theme_preferences = None
self.sounds_preferences = None
self.notebook.set_current_page(0)
self.window.show_all()
gtkgui_helpers.possibly_move_window_in_current_desktop(self.window)
def on_preferences_window_key_press_event(self, widget, event):
if event.keyval == Gdk.KEY_Escape:
self.window.destroy()
def get_per_account_option(self, opt):
"""
Return the value of the option opt if it's the same in all accounts else
returns "mixed"
"""
if len(app.connections) == 0:
# a non existent key return default value
return app.config.get_per('accounts', '__default__', opt)
val = None
for account in app.connections:
v = app.config.get_per('accounts', account, opt)
if val is None:
val = v
elif val != v:
return 'mixed'
return val
def on_checkbutton_toggled(self, widget, config_name,
change_sensitivity_widgets=None):
app.config.set(config_name, widget.get_active())
if change_sensitivity_widgets:
for w in change_sensitivity_widgets:
w.set_sensitive(widget.get_active())
def on_per_account_checkbutton_toggled(self, widget, config_name,
change_sensitivity_widgets=None):
for account in app.connections:
app.config.set_per('accounts', account, config_name,
widget.get_active())
if change_sensitivity_widgets:
for w in change_sensitivity_widgets:
w.set_sensitive(widget.get_active())
def _get_all_controls(self):
for ctrl in app.interface.msg_win_mgr.get_controls():
yield ctrl
for account in app.connections:
for ctrl in app.interface.minimized_controls[account].values():
yield ctrl
def _get_all_muc_controls(self):
for ctrl in app.interface.msg_win_mgr.get_controls(
message_control.TYPE_GC):
yield ctrl
for account in app.connections:
for ctrl in app.interface.minimized_controls[account].values():
yield ctrl
def on_sort_by_show_in_roster_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'sort_by_show_in_roster')
app.interface.roster.setup_and_draw_roster()
def on_sort_by_show_in_muc_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'sort_by_show_in_muc')
# Redraw groupchats
for ctrl in self._get_all_muc_controls():
ctrl.draw_roster()
def on_show_avatars_in_roster_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'show_avatars_in_roster')
app.interface.roster.setup_and_draw_roster()
# Redraw groupchats (in an ugly way)
for ctrl in self._get_all_muc_controls():
ctrl.draw_roster()
def on_show_status_msgs_in_roster_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'show_status_msgs_in_roster')
app.interface.roster.setup_and_draw_roster()
for ctrl in self._get_all_muc_controls():
ctrl.update_ui()
def on_show_pep_in_roster_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'show_mood_in_roster')
self.on_checkbutton_toggled(widget, 'show_activity_in_roster')
self.on_checkbutton_toggled(widget, 'show_tunes_in_roster')
self.on_checkbutton_toggled(widget, 'show_location_in_roster')
app.interface.roster.setup_and_draw_roster()
def on_emoticons_combobox_changed(self, widget):
active = widget.get_active()
model = widget.get_model()
emot_theme = model[active][0]
if emot_theme == _('Disabled'):
app.config.set('emoticons_theme', '')
else:
app.config.set('emoticons_theme', emot_theme)
app.interface.init_emoticons()
app.interface.make_regexps()
self.toggle_emoticons()
def toggle_emoticons(self):
"""
Update emoticons state in Opened Chat Windows
"""
for ctrl in self._get_all_controls():
ctrl.toggle_emoticons()
def on_one_window_type_combo_changed(self, widget):
active = widget.get_active()
config_type = c_config.opt_one_window_types[active]
app.config.set('one_message_window', config_type)
app.interface.msg_win_mgr.reconfig()
def on_show_roster_on_startup_changed(self, widget):
active = widget.get_active()
config_type = c_config.opt_show_roster_on_startup[active]
app.config.set('show_roster_on_startup', config_type)
def on_xhtml_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'ignore_incoming_xhtml')
helpers.update_optional_features()
def apply_speller(self):
for ctrl in self._get_all_controls():
if isinstance(ctrl, ChatControlBase):
ctrl.set_speller()
def on_speller_checkbutton_toggled(self, widget):
active = widget.get_active()
app.config.set('use_speller', active)
if not active:
return
lang = app.config.get('speller_language')
gspell_lang = Gspell.language_lookup(lang)
if gspell_lang is None:
gspell_lang = Gspell.language_get_default()
if gspell_lang is None:
AspellDictError(lang)
app.config.set('use_speller', False)
widget.set_active(False)
else:
app.config.set('speller_language', gspell_lang.get_code())
self.apply_speller()
def on_positive_184_ack_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'positive_184_ack')
def on_show_avatar_in_tabs_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'show_avatar_in_tabs')
def on_theme_combobox_changed(self, widget):
model = widget.get_model()
active = widget.get_active()
config_theme = model[active][0].replace(' ', '_')
app.config.set('roster_theme', config_theme)
# begin repainting themed widgets throughout
app.interface.roster.repaint_themed_widgets()
app.interface.roster.change_roster_style(None)
gtkgui_helpers.load_css()
def update_theme_list(self):
theme_combobox = self.xml.get_object('theme_combobox')
model = Gtk.ListStore(str)
theme_combobox.set_model(model)
i = 0
for config_theme in app.config.get_per('themes'):
theme = config_theme.replace('_', ' ')
model.append([theme])
if app.config.get('roster_theme') == config_theme:
theme_combobox.set_active(i)
i += 1
def on_manage_theme_button_clicked(self, widget):
if self.theme_preferences is None:
self.theme_preferences = GajimThemesWindow()
else:
self.theme_preferences.window.present()
self.theme_preferences.select_active_theme()
def on_iconset_combobox_changed(self, widget):
model = widget.get_model()
active = widget.get_active()
icon_string = model[active][1]
app.config.set('iconset', icon_string)
gtkgui_helpers.reload_jabber_state_images()
def on_transports_iconsets_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'use_transports_iconsets')
gtkgui_helpers.reload_jabber_state_images()
def on_outgoing_chat_states_combobox_changed(self, widget):
active = widget.get_active()