Philipp Hörist pushed to branch master at gajim / gajim
Commits: 185e1b93 by lovetox at 2020-07-31T15:02:23+02:00 Preferences: Simplify combobox code
- - - - - 347fbb83 by lovetox at 2020-07-31T15:02:45+02:00 Remove unused code
- - - - - 309cd5b7 by lovetox at 2020-07-31T15:14:22+02:00 Preferences: Simplify combobox code
- - - - -
4 changed files:
- gajim/common/config.py - gajim/data/gui/preferences_window.ui - gajim/gtk/preferences.py - gajim/message_window.py
Changes:
===================================== gajim/common/config.py ===================================== @@ -54,9 +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'] -opt_show_roster_on_startup = ['always', 'never', 'last_state'] -opt_treat_incoming_messages = ['', 'chat', 'normal']
class Config:
===================================== 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> @@ -112,18 +119,23 @@ </object> <object class="GtkListStore" id="show_roster_on_startup_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">Always</col> + <col id="1">always</col> </row> <row> <col id="0" translatable="yes">Never</col> + <col id="1">never</col> </row> <row> <col id="0" translatable="yes">Last state</col> + <col id="1">last_state</col> </row> </data> </object> @@ -257,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"/> @@ -275,6 +288,7 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="model">show_roster_on_startup_liststore</property> + <property name="id_column">1</property> <signal name="changed" handler="on_show_roster_on_startup_changed" swapped="no"/> <child> <object class="GtkCellRendererText"/>
===================================== 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,20 +68,12 @@ 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 - choices = c_config.opt_show_roster_on_startup - type_ = app.config.get('show_roster_on_startup') - if type_ in choices: - self._ui.show_roster_on_startup.set_active(choices.index(type_)) - else: - self._ui.show_roster_on_startup.set_active(0) + self._ui.show_roster_on_startup.set_active_id( + app.config.get('show_roster_on_startup'))
# Quit on roster x st = app.config.get('quit_on_roster_x_button') @@ -499,16 +490,12 @@ 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, 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_show_roster_on_startup_changed(self, combobox): + app.config.set('show_roster_on_startup', combobox.get_active_id())
def on_quit_on_roster_x_checkbutton_toggled(self, widget): self.on_checkbutton_toggled(widget, 'quit_on_roster_x_button')
===================================== 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():
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/e503523cad8e611df0f510c9c9dcdc19...