Philipp Hörist pushed to branch manage-roster at gajim / gajim


Commits:
a74a9b47 by Philipp Hörist at 2025-01-01T13:35:11+01:00
Add search

- - - - -


2 changed files:

- gajim/data/gui/manage_roster.ui
- gajim/gtk/manage_roster.py


Changes:

=====================================
gajim/data/gui/manage_roster.ui
=====================================
@@ -4,6 +4,19 @@
   <object class="GtkBox" id="main">
     <property name="orientation">1</property>
     <property name="spacing">18</property>
+    <child>
+      <object class="GtkBox" id="top_box">
+        <property name="orientation">0</property>
+        <property name="spacing">18</property>
+        <child>
+          <object class="GtkSearchEntry" id="search_entry">
+            <property name="focusable">1</property>
+            <property name="hexpand">1</property>
+            <property name="placeholder-text" 
translatable="yes">Search…</property>
+          </object>
+        </child>
+      </object>
+    </child>
     <child>
         <object class="GtkBox" id="scrolled_box">
           <property name="orientation">1</property>


=====================================
gajim/gtk/manage_roster.py
=====================================
@@ -120,7 +120,17 @@ def __init__(self, account: str) -> None:
             model=self._model, sorter=sorter, section_sorter=section_sorter
         )
 
-        self._selection_model = Gtk.MultiSelection(model=sort_model)
+        expression = Gtk.PropertyExpression.new(
+            this_type=RosterListItem,
+            expression=None,
+            property_name="search_string",
+        )
+
+        self._string_filter = Gtk.StringFilter.new(expression)
+
+        filter_model = Gtk.FilterListModel(model=sort_model, 
filter=self._string_filter)
+
+        self._selection_model = Gtk.MultiSelection(model=filter_model)
         self._ui.column_view.set_model(self._selection_model)
 
         self._popover_menu = GajimPopover(None)
@@ -137,6 +147,8 @@ def __init__(self, account: str) -> None:
 
         
self._ui.import_button.set_menu_model(get_manage_roster_import_menu(accounts))
 
+        self._connect(self._ui.search_entry, "search-changed", 
self._on_search_changed)
+
         self.register_event("roster-push", ged.GUI2, self._on_roster_push)
         self._client.connect_signal("state-changed", 
self._on_client_state_changed)
 
@@ -148,6 +160,7 @@ def _cleanup(self, *args: Any) -> None:
         del self._popover_menu
         del self._model
         del self._actions
+        del self._string_filter
         self._client.disconnect_all_from_obj(self)
         self.unregister_events()
 
@@ -243,6 +256,9 @@ def _on_client_state_changed(
             assert isinstance(action, Gio.SimpleAction)
             action.set_enabled(state.is_connected)
 
+    def _on_search_changed(self, search_entry: Gtk.SearchEntry) -> None:
+        self._string_filter.set_search(search_entry.get_text())
+
     def _on_add_to_group(self, _action: Gio.SimpleAction, param: GLib.Variant) 
-> None:
         self._add_to_group(param.get_string())
 
@@ -544,6 +560,7 @@ class RosterListItem(GObject.Object):
     ask = GObject.Property(type=object)
     subscription = GObject.Property(type=object)
     group = GObject.Property(type=str)
+    search_string = GObject.Property(type=str)
 
     def __init__(self, item: RosterItem, group: str) -> None:
 
@@ -556,6 +573,7 @@ def __init__(self, item: RosterItem, group: str) -> None:
             ask=ask,
             subscription=subscription,
             group=group,
+            search_string=f"{item.jid}|{item.name or ''}",
         )
 
     def _get_subscription_data(self, subscription: str | None) -> tuple[str, 
str, str]:



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/a74a9b474523b2441953658960ab92b6d4a86c24

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/a74a9b474523b2441953658960ab92b6d4a86c24
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to