diff options
author | lovetox <philipp@hoerist.com> | 2020-07-31 16:14:22 +0300 |
---|---|---|
committer | lovetox <philipp@hoerist.com> | 2020-08-11 22:20:33 +0300 |
commit | abe45ce77a4e175a4fae11c961d3cb44de6a4694 (patch) | |
tree | 37a1b67a52685269980d8990c106d794cd9d9642 | |
parent | b1fed001561adf8614b43aa9fb4d6d59cef94625 (diff) |
Preferences: Simplify combobox code
-rw-r--r-- | gajim/common/config.py | 1 | ||||
-rw-r--r-- | gajim/data/gui/preferences_window.ui | 10 | ||||
-rw-r--r-- | gajim/gtk/preferences.py | 15 | ||||
-rw-r--r-- | gajim/message_window.py | 18 |
4 files changed, 25 insertions, 19 deletions
diff --git a/gajim/common/config.py b/gajim/common/config.py index 0c0dafcc1..b4096387a 100644 --- a/gajim/common/config.py +++ b/gajim/common/config.py @@ -54,7 +54,6 @@ opt_int = ['integer', 0] opt_str = ['string', 0] opt_bool = ['boolean', 0] opt_color = ['color', r'(#[0-9a-fA-F]{6})|rgb\(\d+,\d+,\d+\)|rgba\(\d+,\d+,\d+,[01]\.?\d*\)'] -opt_one_window_types = ['never', 'always', 'always_with_roster', 'peracct', 'pertype'] class Config: diff --git a/gajim/data/gui/preferences_window.ui b/gajim/data/gui/preferences_window.ui index 706d2ea14..cffdd2bf7 100644 --- a/gajim/data/gui/preferences_window.ui +++ b/gajim/data/gui/preferences_window.ui @@ -61,24 +61,31 @@ </object> <object class="GtkListStore" id="one_window_type_liststore"> <columns> - <!-- column-name item --> + <!-- column-name text --> + <column type="gchararray"/> + <!-- column-name setting --> <column type="gchararray"/> </columns> <data> <row> <col id="0" translatable="yes">Detached contact list with detached chats</col> + <col id="1">never</col> </row> <row> <col id="0" translatable="yes">Detached contact list with single chat</col> + <col id="1">always</col> </row> <row> <col id="0" translatable="yes">Single window for everything</col> + <col id="1">always_with_roster</col> </row> <row> <col id="0" translatable="yes">Detached contact list with chat grouped by account</col> + <col id="1" translatable="yes">peracct</col> </row> <row> <col id="0" translatable="yes">Detached contact list with chat grouped by type</col> + <col id="1">pertype</col> </row> </data> </object> @@ -262,6 +269,7 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="model">one_window_type_liststore</property> + <property name="id_column">1</property> <signal name="changed" handler="on_one_window_type_combo_changed" swapped="no"/> <child> <object class="GtkCellRendererText"/> diff --git a/gajim/gtk/preferences.py b/gajim/gtk/preferences.py index 4509b8409..43ce9ade6 100644 --- a/gajim/gtk/preferences.py +++ b/gajim/gtk/preferences.py @@ -29,7 +29,6 @@ except Exception: from gajim.common import app from gajim.common import configpaths from gajim.common import helpers -from gajim.common import config as c_config from gajim.common import idle from gajim.common.nec import NetworkEvent from gajim.common.i18n import _ @@ -69,12 +68,8 @@ class Preferences(Gtk.ApplicationWindow): ### General tab ### ## Behavior of Windows and Tabs # 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._ui.one_window_type_combobox.set_active(choices.index(type_)) - else: - self._ui.one_window_type_combobox.set_active(0) + self._ui.one_window_type_combobox.set_active_id( + app.config.get('one_message_window')) # Show roster on startup self._ui.show_roster_on_startup.set_active_id( @@ -495,10 +490,8 @@ class Preferences(Gtk.ApplicationWindow): yield ctrl ### General tab ### - 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) + def on_one_window_type_combo_changed(self, combobox): + app.config.set('one_message_window', combobox.get_active_id()) app.interface.msg_win_mgr.reconfig() def on_show_roster_on_startup_changed(self, combobox): diff --git a/gajim/message_window.py b/gajim/message_window.py index 026f57c95..3c87bab05 100644 --- a/gajim/message_window.py +++ b/gajim/message_window.py @@ -31,7 +31,6 @@ from gi.repository import GObject from gi.repository import GLib from gi.repository import Gio -from gajim import common from gajim.common import app from gajim.common import ged from gajim.common.i18n import Q_ @@ -56,7 +55,13 @@ from gajim.gtk.const import ControlType log = logging.getLogger('gajim.message_window') -#################### + +WINDOW_TYPES = ['never', + 'always', + 'always_with_roster', + 'peracct', + 'pertype'] + class MessageWindow(EventHelper): """ @@ -877,7 +882,7 @@ class MessageWindowMgr(GObject.GObject): 'window-delete': (GObject.SignalFlags.RUN_LAST, None, (object,)), } - # These constants map to common.config.opt_one_window_types indices + # These constants map to WINDOW_TYPES indices ( ONE_MSG_WINDOW_NEVER, ONE_MSG_WINDOW_ALWAYS, @@ -885,6 +890,7 @@ class MessageWindowMgr(GObject.GObject): ONE_MSG_WINDOW_PERACCT, ONE_MSG_WINDOW_PERTYPE, ) = range(5) + # A key constant for the main window in ONE_MSG_WINDOW_ALWAYS mode MAIN_WIN = 'main' # A key constant for the main window in ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER mode @@ -904,7 +910,7 @@ class MessageWindowMgr(GObject.GObject): # Map the mode to a int constant for frequent compares mode = app.config.get('one_message_window') - self.mode = common.config.opt_one_window_types.index(mode) + self.mode = WINDOW_TYPES.index(mode) self.parent_win = parent_window self.parent_paned = parent_paned @@ -1198,10 +1204,10 @@ class MessageWindowMgr(GObject.GObject): for w in self.windows(): self.save_state(w) mode = app.config.get('one_message_window') - if self.mode == common.config.opt_one_window_types.index(mode): + if self.mode == WINDOW_TYPES.index(mode): # No change return - self.mode = common.config.opt_one_window_types.index(mode) + self.mode = WINDOW_TYPES.index(mode) controls = [] for w in self.windows(): |