save config regulary when we change an option.

This commit is contained in:
Yann Leboulanger 2012-04-18 10:15:53 +02:00
parent be3a948838
commit b846ac8793
9 changed files with 16 additions and 37 deletions

View File

@ -209,7 +209,6 @@ class AdvancedConfigurationWindow(object):
else: else:
self.remember_option(option, modelrow[1], newval) self.remember_option(option, modelrow[1], newval)
gajim.config.set(option, newval) gajim.config.set(option, newval)
gajim.interface.save_config()
modelrow[1] = self.right_true_dict[newval] modelrow[1] = self.right_true_dict[newval]
self.check_for_restart() self.check_for_restart()
@ -244,7 +243,6 @@ class AdvancedConfigurationWindow(object):
else: else:
self.remember_option(option, modelrow[1], text) self.remember_option(option, modelrow[1], text)
gajim.config.set(option, text) gajim.config.set(option, text)
gajim.interface.save_config()
modelrow[1] = text modelrow[1] = text
self.check_for_restart() self.check_for_restart()
@ -279,7 +277,6 @@ class AdvancedConfigurationWindow(object):
else: else:
self.remember_option(option, modelrow[C_VALUE], default) self.remember_option(option, modelrow[C_VALUE], default)
gajim.config.set(option, default) gajim.config.set(option, default)
gajim.interface.save_config()
modelrow[C_VALUE] = self.right_true_dict[default] modelrow[C_VALUE] = self.right_true_dict[default]
self.check_for_restart() self.check_for_restart()
else: else:

View File

@ -36,7 +36,9 @@ import sys
import re import re
import copy import copy
import defs import defs
import gobject
from common import gajim
( (
OPT_TYPE, OPT_TYPE,
@ -618,6 +620,7 @@ class Config:
return return
self.__options[1][optname] = value self.__options[1][optname] = value
self._timeout_save()
def get(self, optname=None): def get(self, optname=None):
if not optname: if not optname:
@ -660,6 +663,7 @@ class Config:
opt[1][name] = {} opt[1][name] = {}
for o in opt[0]: for o in opt[0]:
opt[1][name][o] = opt[0][o][OPT_VAL] opt[1][name][o] = opt[0][o][OPT_VAL]
self._timeout_save()
def del_per(self, typename, name, subname = None): # per_group_of_option def del_per(self, typename, name, subname = None): # per_group_of_option
if typename not in self.__options_per_key: if typename not in self.__options_per_key:
@ -672,6 +676,7 @@ class Config:
# if subname is specified, delete the item in the group. # if subname is specified, delete the item in the group.
elif subname in opt[1][name]: elif subname in opt[1][name]:
del opt[1][name][subname] del opt[1][name][subname]
self._timeout_save()
def set_per(self, optname, key, subname, value): # per_group_of_option def set_per(self, optname, key, subname, value): # per_group_of_option
if optname not in self.__options_per_key: if optname not in self.__options_per_key:
@ -693,6 +698,7 @@ class Config:
# raise RuntimeError, '%s of %s cannot be None' % optname # raise RuntimeError, '%s of %s cannot be None' % optname
return return
obj[subname] = value obj[subname] = value
self._timeout_save()
def get_per(self, optname, key=None, subname=None): # per_group_of_option def get_per(self, optname, key=None, subname=None): # per_group_of_option
if optname not in self.__options_per_key: if optname not in self.__options_per_key:
@ -778,9 +784,19 @@ class Config:
for opt in self.__options[0]: for opt in self.__options[0]:
self.__options[1][opt] = self.__options[0][opt][OPT_VAL] self.__options[1][opt] = self.__options[0][opt][OPT_VAL]
def _really_save(self):
gajim.interface.save_config()
return False
def _timeout_save(self):
if self.save_timeout_id:
return
self.save_timeout_id = gobject.timeout_add(1000, self._really_save)
def __init__(self): def __init__(self):
#init default values #init default values
self._init_options() self._init_options()
self.save_timeout_id = None
for event in self.soundevents_default: for event in self.soundevents_default:
default = self.soundevents_default[event] default = self.soundevents_default[event]
self.add_per('soundevents', event) self.add_per('soundevents', event)

View File

@ -610,7 +610,6 @@ class PreferencesWindow:
if change_sensitivity_widgets: if change_sensitivity_widgets:
for w in change_sensitivity_widgets: for w in change_sensitivity_widgets:
w.set_sensitive(widget.get_active()) w.set_sensitive(widget.get_active())
gajim.interface.save_config()
def on_per_account_checkbutton_toggled(self, widget, config_name, def on_per_account_checkbutton_toggled(self, widget, config_name,
change_sensitivity_widgets=None): change_sensitivity_widgets=None):
@ -620,7 +619,6 @@ class PreferencesWindow:
if change_sensitivity_widgets: if change_sensitivity_widgets:
for w in change_sensitivity_widgets: for w in change_sensitivity_widgets:
w.set_sensitive(widget.get_active()) w.set_sensitive(widget.get_active())
gajim.interface.save_config()
def _get_all_controls(self): def _get_all_controls(self):
for ctrl in gajim.interface.msg_win_mgr.get_controls(): for ctrl in gajim.interface.msg_win_mgr.get_controls():
@ -700,21 +698,18 @@ class PreferencesWindow:
active = widget.get_active() active = widget.get_active()
config_type = common.config.opt_one_window_types[active] config_type = common.config.opt_one_window_types[active]
gajim.config.set('one_message_window', config_type) gajim.config.set('one_message_window', config_type)
gajim.interface.save_config()
gajim.interface.msg_win_mgr.reconfig() gajim.interface.msg_win_mgr.reconfig()
def on_show_roster_on_startup_changed(self, widget): def on_show_roster_on_startup_changed(self, widget):
active = widget.get_active() active = widget.get_active()
config_type = common.config.opt_show_roster_on_startup[active] config_type = common.config.opt_show_roster_on_startup[active]
gajim.config.set('show_roster_on_startup', config_type) gajim.config.set('show_roster_on_startup', config_type)
gajim.interface.save_config()
def on_compact_view_checkbutton_toggled(self, widget): def on_compact_view_checkbutton_toggled(self, widget):
active = widget.get_active() active = widget.get_active()
for ctrl in self._get_all_controls(): for ctrl in self._get_all_controls():
ctrl.chat_buttons_set_visible(active) ctrl.chat_buttons_set_visible(active)
gajim.config.set('compact_view', active) gajim.config.set('compact_view', active)
gajim.interface.save_config()
def on_xhtml_checkbutton_toggled(self, widget): def on_xhtml_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'ignore_incoming_xhtml') self.on_checkbutton_toggled(widget, 'ignore_incoming_xhtml')
@ -744,7 +739,6 @@ class PreferencesWindow:
def on_speller_checkbutton_toggled(self, widget): def on_speller_checkbutton_toggled(self, widget):
active = widget.get_active() active = widget.get_active()
gajim.config.set('use_speller', active) gajim.config.set('use_speller', active)
gajim.interface.save_config()
if active: if active:
lang = gajim.config.get('speller_language') lang = gajim.config.get('speller_language')
if not lang: if not lang:
@ -776,7 +770,6 @@ class PreferencesWindow:
# begin repainting themed widgets throughout # begin repainting themed widgets throughout
gajim.interface.roster.repaint_themed_widgets() gajim.interface.roster.repaint_themed_widgets()
gajim.interface.roster.change_roster_style(None) gajim.interface.roster.change_roster_style(None)
gajim.interface.save_config()
def update_theme_list(self): def update_theme_list(self):
theme_combobox = self.xml.get_object('theme_combobox') theme_combobox = self.xml.get_object('theme_combobox')
@ -803,7 +796,6 @@ class PreferencesWindow:
icon_string = model[active][1].decode('utf-8') icon_string = model[active][1].decode('utf-8')
gajim.config.set('iconset', icon_string) gajim.config.set('iconset', icon_string)
gtkgui_helpers.reload_jabber_state_images() gtkgui_helpers.reload_jabber_state_images()
gajim.interface.save_config()
def on_transports_iconsets_checkbutton_toggled(self, widget): def on_transports_iconsets_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'use_transports_iconsets') self.on_checkbutton_toggled(widget, 'use_transports_iconsets')
@ -898,7 +890,6 @@ class PreferencesWindow:
color_string = gtkgui_helpers.make_color_string(color) color_string = gtkgui_helpers.make_color_string(color)
gajim.config.set(text, color_string) gajim.config.set(text, color_string)
self.update_text_tags() self.update_text_tags()
gajim.interface.save_config()
def on_preference_widget_font_set(self, widget, text): def on_preference_widget_font_set(self, widget, text):
if widget: if widget:
@ -907,7 +898,6 @@ class PreferencesWindow:
font = '' font = ''
gajim.config.set(text, font) gajim.config.set(text, font)
self.update_text_font() self.update_text_font()
gajim.interface.save_config()
def update_text_font(self): def update_text_font(self):
""" """
@ -988,7 +978,6 @@ class PreferencesWindow:
self.draw_color_widgets() self.draw_color_widgets()
self.update_text_tags() self.update_text_tags()
gajim.interface.save_config()
def _set_color(self, state, widget_name, option): def _set_color(self, state, widget_name, option):
""" """
@ -1000,7 +989,6 @@ class PreferencesWindow:
else: else:
color_string = '' color_string = ''
gajim.config.set(option, color_string) gajim.config.set(option, color_string)
gajim.interface.save_config()
def on_incoming_msg_checkbutton_toggled(self, widget): def on_incoming_msg_checkbutton_toggled(self, widget):
state = widget.get_active() state = widget.get_active()
@ -1022,7 +1010,6 @@ class PreferencesWindow:
gajim.interface.sleeper = common.sleepy.Sleepy( gajim.interface.sleeper = common.sleepy.Sleepy(
gajim.config.get('autoawaytime') * 60, gajim.config.get('autoawaytime') * 60,
gajim.config.get('autoxatime') * 60) gajim.config.get('autoxatime') * 60)
gajim.interface.save_config()
def on_auto_away_message_entry_changed(self, widget): def on_auto_away_message_entry_changed(self, widget):
gajim.config.set('autoaway_message', widget.get_text().decode('utf-8')) gajim.config.set('autoaway_message', widget.get_text().decode('utf-8'))
@ -1037,7 +1024,6 @@ class PreferencesWindow:
gajim.interface.sleeper = common.sleepy.Sleepy( gajim.interface.sleeper = common.sleepy.Sleepy(
gajim.config.get('autoawaytime') * 60, gajim.config.get('autoawaytime') * 60,
gajim.config.get('autoxatime') * 60) gajim.config.get('autoxatime') * 60)
gajim.interface.save_config()
def on_auto_xa_message_entry_changed(self, widget): def on_auto_xa_message_entry_changed(self, widget):
gajim.config.set('autoxa_message', widget.get_text().decode('utf-8')) gajim.config.set('autoxa_message', widget.get_text().decode('utf-8'))
@ -1106,7 +1092,6 @@ class PreferencesWindow:
model[iter_][i].decode('utf-8')) model[iter_][i].decode('utf-8'))
i += 1 i += 1
iter_ = model.iter_next(iter_) iter_ = model.iter_next(iter_)
gajim.interface.save_config()
def on_msg_treemodel_row_changed(self, model, path, iter_): def on_msg_treemodel_row_changed(self, model, path, iter_):
self.save_status_messages(model) self.save_status_messages(model)
@ -1152,19 +1137,15 @@ class PreferencesWindow:
elif widget.get_active() == 1: elif widget.get_active() == 1:
gajim.config.set('autodetect_browser_mailer', False) gajim.config.set('autodetect_browser_mailer', False)
self.xml.get_object('custom_apps_frame').show() self.xml.get_object('custom_apps_frame').show()
gajim.interface.save_config()
def on_custom_browser_entry_changed(self, widget): def on_custom_browser_entry_changed(self, widget):
gajim.config.set('custombrowser', widget.get_text().decode('utf-8')) gajim.config.set('custombrowser', widget.get_text().decode('utf-8'))
gajim.interface.save_config()
def on_custom_mail_client_entry_changed(self, widget): def on_custom_mail_client_entry_changed(self, widget):
gajim.config.set('custommailapp', widget.get_text().decode('utf-8')) gajim.config.set('custommailapp', widget.get_text().decode('utf-8'))
gajim.interface.save_config()
def on_custom_file_manager_entry_changed(self, widget): def on_custom_file_manager_entry_changed(self, widget):
gajim.config.set('custom_file_manager', widget.get_text().decode('utf-8')) gajim.config.set('custom_file_manager', widget.get_text().decode('utf-8'))
gajim.interface.save_config()
def on_log_show_changes_checkbutton_toggled(self, widget): def on_log_show_changes_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'log_contact_status_changes') self.on_checkbutton_toggled(widget, 'log_contact_status_changes')
@ -2472,7 +2453,6 @@ class AccountsWindow:
if change_sensitivity_widgets: if change_sensitivity_widgets:
for w in change_sensitivity_widgets: for w in change_sensitivity_widgets:
w.set_sensitive(widget.get_active()) w.set_sensitive(widget.get_active())
gajim.interface.save_config()
def on_merge_checkbutton_toggled(self, widget): def on_merge_checkbutton_toggled(self, widget):
self.on_checkbutton_toggled(widget, 'mergeaccounts') self.on_checkbutton_toggled(widget, 'mergeaccounts')
@ -2487,7 +2467,6 @@ class AccountsWindow:
if account == gajim.ZEROCONF_ACC_NAME: if account == gajim.ZEROCONF_ACC_NAME:
gajim.connections[account].disable_account() gajim.connections[account].disable_account()
del gajim.connections[account] del gajim.connections[account]
gajim.interface.save_config()
del gajim.interface.instances[account] del gajim.interface.instances[account]
del gajim.interface.minimized_controls[account] del gajim.interface.minimized_controls[account]
del gajim.nicks[account] del gajim.nicks[account]
@ -2557,7 +2536,6 @@ class AccountsWindow:
gajim.interface.roster.regroup = False gajim.interface.roster.regroup = False
gajim.interface.roster.setup_and_draw_roster() gajim.interface.roster.setup_and_draw_roster()
gajim.interface.roster.set_actions_menu_needs_rebuild() gajim.interface.roster.set_actions_menu_needs_rebuild()
gajim.interface.save_config()
def on_enable_zeroconf_checkbutton2_toggled(self, widget): def on_enable_zeroconf_checkbutton2_toggled(self, widget):
# don't do anything if there is an account with the local name but is a # don't do anything if there is an account with the local name but is a
@ -3072,7 +3050,6 @@ class RemoveAccountWindow:
del gajim.connections[self.account] del gajim.connections[self.account]
gajim.logger.remove_roster(gajim.get_jid_from_account(self.account)) gajim.logger.remove_roster(gajim.get_jid_from_account(self.account))
gajim.config.del_per('accounts', self.account) gajim.config.del_per('accounts', self.account)
gajim.interface.save_config()
del gajim.interface.instances[self.account] del gajim.interface.instances[self.account]
if self.account in gajim.nicks: if self.account in gajim.nicks:
del gajim.interface.minimized_controls[self.account] del gajim.interface.minimized_controls[self.account]
@ -4025,7 +4002,6 @@ class AccountCreationWizardWindow:
gajim.interface.roster.regroup = False gajim.interface.roster.regroup = False
gajim.interface.roster.setup_and_draw_roster() gajim.interface.roster.setup_and_draw_roster()
gajim.interface.roster.set_actions_menu_needs_rebuild() gajim.interface.roster.set_actions_menu_needs_rebuild()
gajim.interface.save_config()
class ManagePEPServicesWindow: class ManagePEPServicesWindow:
def __init__(self, account): def __init__(self, account):
@ -4173,7 +4149,6 @@ class ManageSoundsWindow:
bool(model[path][0])) bool(model[path][0]))
gajim.config.set_per('soundevents', sound_event, 'path', gajim.config.set_per('soundevents', sound_event, 'path',
model[iter_][2].decode('utf-8')) model[iter_][2].decode('utf-8'))
gajim.interface.save_config()
def sound_toggled_cb(self, cell, path): def sound_toggled_cb(self, cell, path):
model = self.sound_tree.get_model() model = self.sound_tree.get_model()

View File

@ -2983,7 +2983,6 @@ class SingleMessageWindow:
width, height = self.window.get_size() width, height = self.window.get_size()
gajim.config.set('single-msg-width', width) gajim.config.set('single-msg-width', width)
gajim.config.set('single-msg-height', height) gajim.config.set('single-msg-height', height)
gajim.interface.save_config()
def on_single_message_window_delete_event(self, window, ev): def on_single_message_window_delete_event(self, window, ev):
self.save_pos() self.save_pos()

View File

@ -828,7 +828,6 @@ _('This type of service does not contain any items to browse.'))
self.address_comboboxentry.append_text(j) self.address_comboboxentry.append_text(j)
gajim.config.set('latest_disco_addresses', gajim.config.set('latest_disco_addresses',
' '.join(self.latest_addresses)) ' '.join(self.latest_addresses))
gajim.interface.save_config()
self.travel(jid, '') self.travel(jid, '')
def on_services_treeview_row_activated(self, widget, path, col = 0): def on_services_treeview_row_activated(self, widget, path, col = 0):

View File

@ -291,12 +291,10 @@ class GajimThemesWindow:
# use faster functions for this # use faster functions for this
if self.current_option == 'banner': if self.current_option == 'banner':
gajim.interface.roster.repaint_themed_widgets() gajim.interface.roster.repaint_themed_widgets()
gajim.interface.save_config()
return return
if self.no_update: if self.no_update:
return return
gajim.interface.roster.change_roster_style(self.current_option) gajim.interface.roster.change_roster_style(self.current_option)
gajim.interface.save_config()
def _set_font(self): def _set_font(self):
""" """
@ -318,7 +316,6 @@ class GajimThemesWindow:
if self.no_update: if self.no_update:
return return
gajim.interface.roster.change_roster_style(self.current_option) gajim.interface.roster.change_roster_style(self.current_option)
gajim.interface.save_config()
def _toggle_font_widgets(self, font_props): def _toggle_font_widgets(self, font_props):
""" """

View File

@ -654,5 +654,3 @@ class HistoryWindow:
gajim.config.set('history_window_y-position', y) gajim.config.set('history_window_y-position', y)
gajim.config.set('history_window_width', width); gajim.config.set('history_window_width', width);
gajim.config.set('history_window_height', height); gajim.config.set('history_window_height', height);
gajim.interface.save_config()

View File

@ -1198,7 +1198,6 @@ class MessageWindowMgr(gobject.GObject):
def reconfig(self): def reconfig(self):
for w in self.windows(): for w in self.windows():
self.save_state(w) self.save_state(w)
gajim.interface.save_config()
mode = gajim.config.get('one_message_window') mode = gajim.config.get('one_message_window')
if self.mode == common.config.opt_one_window_types.index(mode): if self.mode == common.config.opt_one_window_types.index(mode):
# No change # No change

View File

@ -367,7 +367,6 @@ class StatusIcon:
def on_sounds_mute_menuitem_activate(self, widget): def on_sounds_mute_menuitem_activate(self, widget):
gajim.config.set('sounds_on', not widget.get_active()) gajim.config.set('sounds_on', not widget.get_active())
gajim.interface.save_config()
def on_show_roster_menuitem_activate(self, widget): def on_show_roster_menuitem_activate(self, widget):
win = gajim.interface.roster.window win = gajim.interface.roster.window