diff --git a/blueman/gui/manager/ManagerDeviceList.py b/blueman/gui/manager/ManagerDeviceList.py
index d1b4120aa..439240cbc 100644
--- a/blueman/gui/manager/ManagerDeviceList.py
+++ b/blueman/gui/manager/ManagerDeviceList.py
@@ -78,10 +78,6 @@ def __init__(self, inst: "Blueman", adapter: Optional[str] = None) -> None:
self._batteries: Dict[str, Battery] = {}
self.Config = Gio.Settings(schema_id="org.blueman.general")
- 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.connect("query-tooltip", self.tooltip_query)
self.tooltip_row: Optional[Gtk.TreePath] = None
@@ -102,20 +98,11 @@ def __init__(self, inst: "Blueman", adapter: Optional[str] = None) -> None:
self.set_search_equal_func(self.search_func)
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'):
- sort_by = settings['sort-by']
- sort_order = settings['sort-order']
-
- if sort_order == 'ascending':
- sort_type = Gtk.SortType.ASCENDING
- else:
- sort_type = Gtk.SortType.DESCENDING
-
- column_id = self.ids.get(sort_by)
-
- if column_id:
- self.liststore.set_sort_column_id(column_id, sort_type)
+ # Setup sorting on paired. Function will hanlde further sorting
+ sort_column_id = self.ids.get("paired")
+ assert sort_column_id is not None
+ self.liststore.set_sort_column_id(sort_column_id, Gtk.SortType.ASCENDING)
+ self.liststore.set_sort_func(sort_column_id, self.sort_func)
def on_icon_theme_changed(self, _icon_them: Gtk.IconTheme) -> None:
for row in self.liststore:
@@ -148,6 +135,26 @@ def filter_func(self, _model: Gtk.TreeModel, tree_iter: Gtk.TreeIter, _data: Any
else:
return True
+ def sort_func(self, _model: Gtk.TreeModel, rowa_iter: Gtk.TreeIter, rowb_iter: Gtk.TreeIter, _data: Any) -> int:
+ if not self.liststore.iter_is_valid(rowa_iter) or not self.liststore.iter_is_valid(rowb_iter):
+ return 0
+
+ rowa = self.get(rowa_iter, "alias", "connected", "paired")
+ rowb = self.get(rowb_iter, "alias", "connected", "paired")
+
+ if rowa["alias"] is None or rowb["alias"] is None:
+ return 0
+
+ key1 = (rowa["paired"], not rowa["connected"], rowa["alias"])
+ key2 = (rowb["paired"], not rowb["connected"], rowb["alias"])
+
+ if key1 > key2:
+ return 1
+ elif key1 < key2:
+ return -1
+ else:
+ return 0
+
def drag_recv(self, _widget: Gtk.Widget, context: Gdk.DragContext, x: int, y: int, selection: Gtk.SelectionData,
_info: int, time: int) -> None:
diff --git a/blueman/gui/manager/ManagerMenu.py b/blueman/gui/manager/ManagerMenu.py
index e6cf438e1..40dbb2e8b 100644
--- a/blueman/gui/manager/ManagerMenu.py
+++ b/blueman/gui/manager/ManagerMenu.py
@@ -55,22 +55,6 @@ def __init__(self, blueman: "Blueman"):
item_unnamed = blueman.builder.get_widget("hide_unnamed_item", Gtk.CheckMenuItem)
self.blueman.Config.bind("hide-unnamed", item_unnamed, "active", Gio.SettingsBindFlags.DEFAULT)
- self._sort_alias_item = blueman.builder.get_widget("sort_name_item", Gtk.CheckMenuItem)
- self._sort_timestamp_item = blueman.builder.get_widget("sort_added_item", Gtk.CheckMenuItem)
-
- sort_config = self.Config['sort-by']
- if sort_config == "alias":
- self._sort_alias_item.props.active = True
- 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
-
item_plugins = blueman.builder.get_widget("plugins_item", Gtk.ImageMenuItem)
item_plugins.connect('activate', self._on_plugin_dialog_activate)
@@ -98,39 +82,9 @@ def __init__(self, blueman: "Blueman"):
self.device_menu: Optional[ManagerDeviceMenu] = None
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]
- if key == 'sort-by':
- if value == "alias":
- if not self._sort_alias_item.props.active:
- self._sort_alias_item.props.active = True
- 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":
+
+ def _on_settings_changed(self, _settings: Gio.Settings, key: str) -> None:
+ if key == "hide-unnamed":
logging.debug("refilter")
self.blueman.List.filter.refilter()
diff --git a/data/org.blueman.gschema.xml b/data/org.blueman.gschema.xml
index 6d1607525..e5e20312a 100644
--- a/data/org.blueman.gschema.xml
+++ b/data/org.blueman.gschema.xml
@@ -35,23 +35,6 @@
Show Manager's StatusBar
Show or hide the Manager's StatusBar
-
-
-
-
-
- "timestamp"
- Sort device list
- Sort the device list by column, possible values are timestamp and alias
-
-
-
-
-
-
- "ascending"
- Sort ascending or descending
-
Hide devices with no name
true
diff --git a/data/ui/manager-main.ui b/data/ui/manager-main.ui
index 58aeeced7..f3acdfba4 100644
--- a/data/ui/manager-main.ui
+++ b/data/ui/manager-main.ui
@@ -167,53 +167,6 @@
False
-
-
-