Commit 309cd5b7 authored by Philipp Hörist's avatar Philipp Hörist

Preferences: Simplify combobox code

parent 347fbb83
Pipeline #5987 passed with stages
in 3 minutes and 59 seconds
......@@ -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:
......
......@@ -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"/>
......
......@@ -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):
......
......@@ -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():
......
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