Skip to content

Commit

Permalink
ManagerMenu: Change sort-by key to a boolean and bind it to widget
Browse files Browse the repository at this point in the history
  • Loading branch information
infirit committed Jan 4, 2025
1 parent 72f5722 commit 64f9cfb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 32 deletions.
11 changes: 5 additions & 6 deletions blueman/gui/manager/ManagerDeviceList.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __init__(self, inst: "Blueman", adapter: str | None = None) -> None:
self.Config.connect('changed', self._on_settings_changed)
# Set the correct sorting
self._on_settings_changed(self.Config, "sort-by")
self._on_settings_changed(self.Config, "sort-type")
self._on_settings_changed(self.Config, "sort-descending")

self.connect("query-tooltip", self.tooltip_query)
self.tooltip_row: Gtk.TreePath | None = None
Expand All @@ -115,14 +115,13 @@ def __init__(self, inst: "Blueman", adapter: str | None = None) -> None:
self.filter.set_visible_func(self.filter_func)

def _on_settings_changed(self, settings: Gio.Settings, key: str) -> None:
if key in ('sort-by', 'sort-order'):
if key in ('sort-by', 'sort-descending'):
sort_by = settings['sort-by']
sort_order = settings['sort-order']

if sort_order == 'ascending':
sort_type = Gtk.SortType.ASCENDING
else:
if settings['sort-descending']:
sort_type = Gtk.SortType.DESCENDING
else:
sort_type = Gtk.SortType.ASCENDING

column_id = self.ids.get(sort_by)

Expand Down
22 changes: 2 additions & 20 deletions blueman/gui/manager/ManagerMenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,8 @@ def __init__(self, blueman: "Blueman"):
else:
self._sort_timestamp_item.props.active = True

self._sort_type_item = blueman.builder.get_widget("sort_descending_item", Gtk.CheckMenuItem)

if self.Config['sort-order'] == "ascending":
self._sort_type_item.props.active = False
else:
self._sort_type_item.props.active = True
sort_descending_item = blueman.builder.get_widget("sort_descending_item", Gtk.CheckMenuItem)
self.blueman.Config.bind("sort-descending", sort_descending_item, "active", Gio.SettingsBindFlags.DEFAULT)

item_plugins = blueman.builder.get_widget("plugins_item", Gtk.ImageMenuItem)
item_plugins.connect('activate', self._on_plugin_dialog_activate)
Expand Down Expand Up @@ -102,19 +98,12 @@ def __init__(self, blueman: "Blueman"):
self.Config.connect("changed", self._on_settings_changed)
self._sort_alias_item.connect("activate", self._on_sorting_changed, "alias")
self._sort_timestamp_item.connect("activate", self._on_sorting_changed, "timestamp")
self._sort_type_item.connect("activate", self._on_sorting_changed, "sort-type")

def _on_sorting_changed(self, btn: Gtk.CheckMenuItem, sort_opt: str) -> None:
if sort_opt == 'alias' and btn.props.active:
self.Config['sort-by'] = "alias"
elif sort_opt == "timestamp" and btn.props.active:
self.Config['sort-by'] = "timestamp"
elif sort_opt == 'sort-type':
# FIXME bind widget to gsetting
if btn.props.active:
self.Config["sort-order"] = "descending"
else:
self.Config["sort-order"] = "ascending"

def _on_settings_changed(self, settings: Gio.Settings, key: str) -> None:
value = settings[key]
Expand All @@ -125,13 +114,6 @@ def _on_settings_changed(self, settings: Gio.Settings, key: str) -> None:
elif value == "timestamp":
if not self._sort_timestamp_item.props.active:
self._sort_timestamp_item.props.active = True
elif key == "sort-type":
if value == "ascending":
if not self._sort_type_item.props.active:
self._sort_type_item.props.active = True
else:
if not self._sort_type_item.props.active:
self._sort_type_item.props.active = False
elif key == "hide-unnamed":
logging.debug("refilter")
self.blueman.List.filter.refilter()
Expand Down
8 changes: 2 additions & 6 deletions data/org.blueman.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,8 @@
<summary>Sort device list</summary>
<description>Sort the device list by column, possible values are timestamp and alias</description>
</key>
<key type="s" name="sort-order">
<choices>
<choice value="ascending"/>
<choice value="descending"/>
</choices>
<default>"ascending"</default>
<key type="b" name="sort-descending">
<default>false</default>
<summary>Sort ascending or descending</summary>
</key>
<key type="b" name="hide-unnamed">
Expand Down

0 comments on commit 64f9cfb

Please sign in to comment.