[seahorse] KeyManagerStore: use Gcr.FilterCollection.
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [seahorse] KeyManagerStore: use Gcr.FilterCollection.
- Date: Wed, 15 Aug 2018 08:33:38 +0000 (UTC)
commit d426b10de7d9dca2f1641ad8b890a66ae2b21e3b
Author: Niels De Graef <nielsdegraef gmail com>
Date: Wed Aug 15 10:26:29 2018 +0200
KeyManagerStore: use Gcr.FilterCollection.
In the long term, we should get rid of Seahorse.Collection by replacing
it with Gcr.FilterCollection in other parts of the code base as well,
but I don't want to change too much code so close to release.
Fixes #175, as I can no longer reproduce it with these changes.
https://gitlab.gnome.org/GNOME/seahorse/issues/175
common/key-manager-store.vala | 70 ++++++++++++++++++++++++++++++++--------
pgp/seahorse-keyserver-results.c | 2 --
src/key-manager.vala | 50 +++++-----------------------
3 files changed, 65 insertions(+), 57 deletions(-)
---
diff --git a/common/key-manager-store.vala b/common/key-manager-store.vala
index 38ccf60e..1638514a 100644
--- a/common/key-manager-store.vala
+++ b/common/key-manager-store.vala
@@ -27,9 +27,37 @@ public class Seahorse.KeyManagerStore : Gcr.CollectionModel {
private static Gdk.Atom XDS_ATOM = Gdk.Atom.intern("XdndDirectSave0", false);
private static Gdk.Atom TEXT_ATOM = Gdk.Atom.intern("text/plain", false);
- public enum Mode {
- ALL,
- FILTERED
+ public enum ShowFilter {
+ ANY,
+ PERSONAL,
+ TRUSTED;
+
+ public unowned string? to_string() {
+ switch (this) {
+ case ShowFilter.ANY:
+ return "";
+ case ShowFilter.PERSONAL:
+ return "personal";
+ case ShowFilter.TRUSTED:
+ return "trusted";
+ default:
+ assert_not_reached();
+ }
+ }
+
+ public static ShowFilter from_string(string? str) {
+ switch (str) {
+ case null:
+ case "":
+ return ShowFilter.ANY;
+ case "personal":
+ return ShowFilter.PERSONAL;
+ case "trusted":
+ return ShowFilter.TRUSTED;
+ default:
+ assert_not_reached();
+ }
+ }
}
private enum DragInfo {
@@ -65,6 +93,8 @@ public class Seahorse.KeyManagerStore : Gcr.CollectionModel {
}
private string _filter = "";
+ public ShowFilter showfilter { get; set; default = ShowFilter.ANY; }
+
private enum Column {
ICON,
MARKUP,
@@ -90,10 +120,8 @@ public class Seahorse.KeyManagerStore : Gcr.CollectionModel {
null);
}
- public KeyManagerStore (Gcr.Collection? collection, Gtk.TreeView? view, Predicate? pred, GLib.Settings
settings) {
- pred.custom = on_filter_visible;
- pred.custom_target = this;
- this.collection = new Collection.for_predicate (collection, pred, null);
+ public KeyManagerStore (Gcr.Collection? collection, Gtk.TreeView? view, GLib.Settings settings) {
+ this.collection = new Gcr.FilterCollection.with_callback(collection, on_filter_visible);
this.settings = settings;
// The sorted model is the top level model
@@ -132,8 +160,6 @@ public class Seahorse.KeyManagerStore : Gcr.CollectionModel {
view.append_column(col);
col.set_sort_column_id(Column.LABEL);
- // Use predicate to figure out which columns to add
-
// Also watch for sort-changed on the store
this.sort_column_changed.connect(on_sort_column_changed);
@@ -184,14 +210,32 @@ public class Seahorse.KeyManagerStore : Gcr.CollectionModel {
return false;
}
+ private bool apply_showfilter(GLib.Object? obj) {
+ if (this.showfilter == ShowFilter.ANY)
+ return true;
+
+ unowned Object? object = obj as Object;
+ if (object == null)
+ return false;
+
+ switch (this.showfilter) {
+ case ShowFilter.PERSONAL:
+ return Seahorse.Flags.PERSONAL in object.object_flags;
+ case ShowFilter.TRUSTED:
+ return Seahorse.Flags.TRUSTED in object.object_flags;
+ }
+
+ return false;
+ }
+
// Called to filter each row
- private static bool on_filter_visible (GLib.Object? obj, void* custom_target) {
- KeyManagerStore self = (KeyManagerStore) custom_target;
- return self.object_contains_filtered_text (obj, self.filter);
+ private bool on_filter_visible (GLib.Object? obj) {
+ return apply_showfilter(obj)
+ && object_contains_filtered_text(obj, this.filter);
}
public void refilter() {
- ((Collection) get_collection()).refresh();
+ ((Gcr.FilterCollection) this.collection).refilter();
}
// Update the sort order for a column
diff --git a/pgp/seahorse-keyserver-results.c b/pgp/seahorse-keyserver-results.c
index 5ecf201d..297add25 100644
--- a/pgp/seahorse-keyserver-results.c
+++ b/pgp/seahorse-keyserver-results.c
@@ -41,7 +41,6 @@ enum {
struct _SeahorseKeyserverResultsPrivate {
char *search_string;
- SeahorsePredicate pred;
GtkTreeView *view;
GcrSimpleCollection *collection;
GtkActionGroup *import_actions;
@@ -326,7 +325,6 @@ seahorse_keyserver_results_constructed (GObject *obj)
self->pv->store = seahorse_key_manager_store_new (GCR_COLLECTION (self->pv->collection),
self->pv->view,
- &self->pv->pred,
self->pv->settings);
on_view_selection_changed (selection, self);
diff --git a/src/key-manager.vala b/src/key-manager.vala
index 9768b8cc..d1ee558a 100644
--- a/src/key-manager.vala
+++ b/src/key-manager.vala
@@ -25,7 +25,6 @@ public class Seahorse.KeyManager : Catalog {
private Gtk.ActionGroup view_actions;
private Gtk.RadioAction show_action;
private Gtk.SearchEntry filter_entry;
- private Predicate pred;
private Sidebar sidebar;
private Gtk.TreeView view;
@@ -36,12 +35,6 @@ public class Seahorse.KeyManager : Catalog {
private int sidebar_width;
private uint sidebar_width_sig;
- private enum ShowFilter {
- ANY,
- PERSONAL,
- TRUSTED,
- }
-
private enum DndTarget { // Drag 'n Drop target type
PLAIN,
URIS
@@ -62,9 +55,9 @@ public class Seahorse.KeyManager : Catalog {
};
private const Gtk.RadioActionEntry[] VIEW_RADIO_ACTIONS = {
- { "view-personal", null, N_("Show _Personal"), null, N_("Only show personal keys, certificates and
passwords"), ShowFilter.PERSONAL },
- { "view-trusted", null, N_("Show _Trusted"), null, N_("Only show trusted keys, certificates and
passwords"), ShowFilter.TRUSTED },
- { "view-any", null, N_("Show _Any"), null, N_("Show all keys, certificates and passwords"),
ShowFilter.ANY },
+ { "view-personal", null, N_("Show _Personal"), null, N_("Only show personal keys, certificates and
passwords"), KeyManagerStore.ShowFilter.PERSONAL },
+ { "view-trusted", null, N_("Show _Trusted"), null, N_("Only show trusted keys, certificates and
passwords"), KeyManagerStore.ShowFilter.TRUSTED },
+ { "view-any", null, N_("Show _Any"), null, N_("Show all keys, certificates and passwords"),
KeyManagerStore.ShowFilter.ANY },
};
public KeyManager(Application app) {
@@ -94,7 +87,7 @@ public class Seahorse.KeyManager : Catalog {
this.view.realize();
// Add new key store and associate it
- this.store = new KeyManagerStore(this.collection, this.view, this.pred, this.settings);
+ this.store = new KeyManagerStore(this.collection, this.view, this.settings);
init_actions();
@@ -351,41 +344,14 @@ public class Seahorse.KeyManager : Catalog {
this.application.quit();
}
- private string update_view_filter() {
- string val = "";
-
- switch (this.show_action.get_current_value()) {
- case ShowFilter.PERSONAL:
- this.pred.flags = Seahorse.Flags.PERSONAL;
- val = "personal";
- break;
- case ShowFilter.TRUSTED:
- this.pred.flags = Seahorse.Flags.TRUSTED;
- val = "trusted";
- break;
- case ShowFilter.ANY:
- this.pred.flags = 0;
- val = "";
- break;
- }
-
+ private unowned string update_view_filter() {
+ this.store.showfilter = (KeyManagerStore.ShowFilter) this.show_action.current_value;
this.store.refilter();
- return val;
+ return this.store.showfilter.to_string();
}
private void on_item_filter_changed(GLib.Settings settings, string? key) {
- int radio;
-
- string? value = settings.get_string(key);
- if (value == null || value == "")
- radio = ShowFilter.ANY;
- else if (value == "personal")
- radio = ShowFilter.PERSONAL;
- else if (value == "trusted")
- radio = ShowFilter.TRUSTED;
- else
- radio = -1;
-
+ int radio = KeyManagerStore.ShowFilter.from_string(settings.get_string(key));
this.show_action.set_current_value(radio);
update_view_filter();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]