[gnome-boxes] Show items matching selected category
- From: Marc-Andre Lureau <malureau src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] Show items matching selected category
- Date: Wed, 2 Nov 2011 22:48:47 +0000 (UTC)
commit 1f06a7d0bf4477cc88d846d9d9c6069b19efb14a
Author: Marc-Andrà Lureau <marcandre lureau gmail com>
Date: Wed Nov 2 23:44:32 2011 +0100
Show items matching selected category
src/app.vala | 3 +-
src/collection-view.vala | 78 ++++++++++++++++++++++++++++++++++++----------
src/collection.vala | 12 ++++++-
src/sidebar.vala | 14 +++++---
4 files changed, 83 insertions(+), 24 deletions(-)
---
diff --git a/src/app.vala b/src/app.vala
index 25fea53..4523272 100644
--- a/src/app.vala
+++ b/src/app.vala
@@ -58,6 +58,7 @@ private class Boxes.App: Boxes.UI {
public void set_category (Category category) {
topbar.label.set_text (category.name);
+ view.category = category;
}
private async void setup_libvirt (CollectionSource source) {
@@ -165,7 +166,7 @@ private class Boxes.App: Boxes.UI {
topbar = new Topbar (this);
sidebar = new Sidebar (this);
- view = new CollectionView (this);
+ view = new CollectionView (this, sidebar.category);
window.show_all ();
diff --git a/src/collection-view.vala b/src/collection-view.vala
index 4edf6ef..63fc12d 100644
--- a/src/collection-view.vala
+++ b/src/collection-view.vala
@@ -11,8 +11,19 @@ private class Boxes.CollectionView: Boxes.UI {
private Clutter.FlowLayout layout;
private Clutter.Box over_boxes; // a box on top of boxes list
- public CollectionView (App app) {
+ private Category _category;
+ public Category category {
+ get { return _category; }
+ set {
+ _category = value;
+ if (sorted != null)
+ update_view ();
+ }
+ }
+
+ public CollectionView (App app, Category category) {
this.app = app;
+ this.category = category;
sorted = new SortedCollection ((a, b) => {
return strcmp (a.name.down (), b.name.down ());
});
@@ -103,23 +114,56 @@ private class Boxes.CollectionView: Boxes.UI {
}
}
- public void add_item (CollectionItem item) {
+ public void update_item_visible (CollectionItem item) {
+ var visible = false;
+
if (item is Machine) {
var machine = item as Machine;
- machine.ui_state = UIState.COLLECTION;
- actor_remove (machine.actor);
+ switch (category.kind) {
+ case Category.Kind.USER:
+ visible = category.name in machine.source.categories;
+ break;
+ case Category.Kind.NEW:
+ visible = true;
+ break;
+ }
+ }
- var iter = sorted.insert (machine);
+ item.actor.visible = visible;
+ }
- if (iter.is_begin ())
- boxes.pack_before (machine.actor, null);
- else {
- var prev = iter.prev ().get ();
- boxes.pack_after (machine.actor, prev.actor);
- }
- } else
+ public void update_view () {
+ var iter = sorted.sequence.get_begin_iter ();
+
+ while (!iter.is_end ()) {
+ var item = iter.get ();
+ update_item_visible (item);
+ iter = iter.next ();
+ }
+ }
+
+ public void add_item (CollectionItem item) {
+ var machine = item as Machine;
+
+ if (machine == null) {
warning ("Cannot add item %p in %s".printf (&item, sorted.to_string ()));
+ return;
+ }
+
+ item.ui_state = UIState.COLLECTION;
+ actor_remove (item.actor);
+
+ var iter = sorted.insert (item);
+
+ if (iter.is_begin ())
+ boxes.pack_before (item.actor, null);
+ else {
+ var prev = iter.prev ().get ();
+ boxes.pack_after (item.actor, prev.actor);
+ }
+
+ update_item_visible (item);
}
public void remove_item (CollectionItem item) {
@@ -189,7 +233,7 @@ private class Boxes.CollectionView: Boxes.UI {
}
private class SortedCollection: GLib.Object {
- GLib.Sequence<CollectionItem> boxes_sequence = new GLib.Sequence<CollectionItem> ();
+ public GLib.Sequence<CollectionItem> sequence = new GLib.Sequence<CollectionItem> ();
CompareDataFunc<CollectionItem> compare;
public SortedCollection(owned CompareDataFunc<CollectionItem> compare) {
@@ -197,18 +241,18 @@ private class Boxes.CollectionView: Boxes.UI {
}
public SequenceIter<CollectionItem> insert (owned CollectionItem item) {
- return boxes_sequence.insert_sorted (item, compare);
+ return sequence.insert_sorted (item, compare);
}
public void remove (CollectionItem item) {
- var iter = boxes_sequence.lookup (item, compare);
- boxes_sequence.remove (iter);
+ var iter = sequence.lookup (item, compare);
+ sequence.remove (iter);
}
public string to_string () {
var str = "";
- var iter = boxes_sequence.get_begin_iter ();
+ var iter = sequence.get_begin_iter ();
while (!iter.is_end ()) {
str += iter.get ().name + " ";
iter = iter.next ();
diff --git a/src/collection.vala b/src/collection.vala
index 343c780..673387d 100644
--- a/src/collection.vala
+++ b/src/collection.vala
@@ -25,9 +25,19 @@ private class Boxes.Collection: GLib.Object {
}
private class Boxes.Category: GLib.Object {
+ public enum Kind {
+ USER,
+ NEW,
+ FAVORITES,
+ PRIVATE,
+ SHARED
+ }
+
public string name;
+ public Kind kind;
- public Category (string name) {
+ public Category (string name, Kind kind = Kind.USER) {
this.name = name;
+ this.kind = kind;
}
}
diff --git a/src/sidebar.vala b/src/sidebar.vala
index 0e5c992..0c058de 100644
--- a/src/sidebar.vala
+++ b/src/sidebar.vala
@@ -14,6 +14,7 @@ private class Boxes.Sidebar: Boxes.UI {
public Notebook notebook;
public TreeView default_tree_view;
public TreeView user_tree_view;
+ public Category category;
private App app;
private uint width;
@@ -92,8 +93,10 @@ private class Boxes.Sidebar: Boxes.UI {
model.get (iter, 4, out category);
model.get (iter, 2, out selectable);
- if (selectable)
+ if (selectable) {
+ this.category = category;
app.set_category (category);
+ }
(treeview == default_tree_view ? user_tree_view : default_tree_view).get_selection ().unselect_all ();
});
@@ -142,10 +145,11 @@ private class Boxes.Sidebar: Boxes.UI {
vbox.pack_start (default_tree_view, false, false, 0);
var listmodel = default_tree_view.get_model () as Gtk.ListStore;
- list_append (listmodel, new Category (_("New and Recent")));
- list_append (listmodel, new Category (_("Favorites")), "emblem-favorite-symbolic");
- list_append (listmodel, new Category (_("Private")), "channel-secure-symbolic");
- list_append (listmodel, new Category (_("Shared with you")), "emblem-shared-symbolic");
+ category = new Category (_("New and Recent"), Category.Kind.NEW);
+ list_append (listmodel, category);
+ list_append (listmodel, new Category (_("Favorites"), Category.Kind.FAVORITES), "emblem-favorite-symbolic");
+ list_append (listmodel, new Category (_("Private"), Category.Kind.PRIVATE), "channel-secure-symbolic");
+ list_append (listmodel, new Category (_("Shared with you"), Category.Kind.SHARED), "emblem-shared-symbolic");
default_tree_view.get_selection ().select_path (new Gtk.TreePath.from_string ("0"));
var label = new Gtk.Label (_("Collections"));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]