[gnome-photos/wip/favorites: 10/12] view-model: Filter the items from PhotosItemManager based on the mode
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/favorites: 10/12] view-model: Filter the items from PhotosItemManager based on the mode
- Date: Wed, 12 Dec 2012 18:14:24 +0000 (UTC)
commit ea0f75c19cf2f6ad72bb792bd99565227a7aa4cb
Author: Debarshi Ray <debarshir gnome org>
Date: Wed Dec 12 23:05:16 2012 +0530
view-model: Filter the items from PhotosItemManager based on the mode
src/photos-view-model.c | 108 +++++++++++++++++++++++++++++++++++++----------
src/photos-view-model.h | 3 +-
2 files changed, 87 insertions(+), 24 deletions(-)
---
diff --git a/src/photos-view-model.c b/src/photos-view-model.c
index 472f97b..11b70e3 100644
--- a/src/photos-view-model.c
+++ b/src/photos-view-model.c
@@ -25,6 +25,7 @@
#include "config.h"
+#include "photos-enums.h"
#include "photos-item-manager.h"
#include "photos-view-model.h"
@@ -32,6 +33,13 @@
struct _PhotosViewModelPrivate
{
PhotosBaseManager *item_mngr;
+ PhotosWindowMode mode;
+};
+
+enum
+{
+ PROP_0,
+ PROP_MODE
};
@@ -53,21 +61,21 @@ photos_view_model_info_set (PhotosViewModel *self, PhotosBaseItem *item, GtkTree
}
-static void
-photos_view_model_info_updated (PhotosBaseItem *item, gpointer user_data)
+static GtkTreeRowReference *
+photos_view_model_add_item (PhotosViewModel *self, PhotosBaseItem *item)
{
- PhotosViewModel *self = PHOTOS_VIEW_MODEL (user_data);
GtkTreeIter iter;
GtkTreePath *path;
GtkTreeRowReference *row_ref;
- row_ref = (GtkTreeRowReference *) g_object_get_data (G_OBJECT (item), "row-ref");
- path = gtk_tree_row_reference_get_path (row_ref);
- if (path == NULL)
- return;
-
- gtk_tree_model_get_iter (GTK_TREE_MODEL (self), &iter, path);
+ gtk_list_store_append (GTK_LIST_STORE (self), &iter);
photos_view_model_info_set (self, item, &iter);
+
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (self), &iter);
+ row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (self), path);
+ gtk_tree_path_free (path);
+
+ return row_ref;
}
@@ -97,32 +105,58 @@ photos_view_model_item_removed_foreach (GtkTreeModel *model,
static void
-photos_view_model_object_added (PhotosViewModel *self, GObject *object)
+photos_view_model_object_removed (PhotosViewModel *self, GObject *object)
{
+ PhotosBaseItem *item = PHOTOS_BASE_ITEM (object);
+
+ gtk_tree_model_foreach (GTK_TREE_MODEL (self), photos_view_model_item_removed_foreach, item);
+ g_object_set_data (object, "row-ref", NULL);
+}
+
+
+static void
+photos_view_model_info_updated (PhotosBaseItem *item, gpointer user_data)
+{
+ PhotosViewModel *self = PHOTOS_VIEW_MODEL (user_data);
GtkTreeIter iter;
GtkTreePath *path;
GtkTreeRowReference *row_ref;
- PhotosBaseItem *item = PHOTOS_BASE_ITEM (object);
- gtk_list_store_append (GTK_LIST_STORE (self), &iter);
- photos_view_model_info_set (self, item, &iter);
+ row_ref = (GtkTreeRowReference *) g_object_get_data (G_OBJECT (item), "row-ref");
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (self), &iter);
- row_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL (self), path);
- gtk_tree_path_free (path);
+ if (self->priv->mode == PHOTOS_WINDOW_MODE_FAVORITES && !photos_base_item_is_favorite (item) && row_ref != NULL)
+ photos_view_model_object_removed (self, G_OBJECT (item));
+ else if (row_ref == NULL)
+ {
+ row_ref = photos_view_model_add_item (self, item);
+ g_object_set_data_full (G_OBJECT (item), "row-ref", row_ref, (GDestroyNotify) gtk_tree_row_reference_free);
+ }
+ else
+ {
+ path = gtk_tree_row_reference_get_path (row_ref);
+ if (path == NULL)
+ return;
- g_object_set_data_full (G_OBJECT (item), "row-ref", row_ref, (GDestroyNotify) gtk_tree_row_reference_free);
- g_signal_connect (item, "info-updated", G_CALLBACK (photos_view_model_info_updated), self);
+ gtk_tree_model_get_iter (GTK_TREE_MODEL (self), &iter, path);
+ photos_view_model_info_set (self, item, &iter);
+ }
}
static void
-photos_view_model_object_removed (PhotosViewModel *self, GObject *object)
+photos_view_model_object_added (PhotosViewModel *self, GObject *object)
{
+ GtkTreeRowReference *row_ref;
PhotosBaseItem *item = PHOTOS_BASE_ITEM (object);
- gtk_tree_model_foreach (GTK_TREE_MODEL (self), photos_view_model_item_removed_foreach, item);
- g_object_set_data (object, "row-ref", NULL);
+ if (self->priv->mode == PHOTOS_WINDOW_MODE_FAVORITES && !photos_base_item_is_favorite (item))
+ goto out;
+
+ row_ref = photos_view_model_add_item (self, item);
+ g_object_set_data_full (G_OBJECT (item), "row-ref", row_ref, (GDestroyNotify) gtk_tree_row_reference_free);
+
+ out:
+ g_signal_connect (item, "info-updated", G_CALLBACK (photos_view_model_info_updated), self);
}
@@ -138,6 +172,24 @@ photos_view_model_dispose (GObject *object)
static void
+photos_view_model_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+ PhotosViewModel *self = PHOTOS_VIEW_MODEL (object);
+
+ switch (prop_id)
+ {
+ case PROP_MODE:
+ self->priv->mode = (PhotosWindowMode) g_value_get_enum (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+static void
photos_view_model_init (PhotosViewModel *self)
{
PhotosViewModelPrivate *priv;
@@ -168,13 +220,23 @@ photos_view_model_class_init (PhotosViewModelClass *class)
GObjectClass *object_class = G_OBJECT_CLASS (class);
object_class->dispose = photos_view_model_dispose;
+ object_class->set_property = photos_view_model_set_property;
+
+ g_object_class_install_property (object_class,
+ PROP_MODE,
+ g_param_spec_enum ("mode",
+ "PhotosWindowMode enum",
+ "The mode for which the model holds the data",
+ PHOTOS_TYPE_WINDOW_MODE,
+ PHOTOS_WINDOW_MODE_NONE,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
g_type_class_add_private (class, sizeof (PhotosViewModelPrivate));
}
GtkListStore *
-photos_view_model_new (void)
+photos_view_model_new (PhotosWindowMode mode)
{
- return g_object_new (PHOTOS_TYPE_VIEW_MODEL, NULL);
+ return g_object_new (PHOTOS_TYPE_VIEW_MODEL, "mode", mode, NULL);
}
diff --git a/src/photos-view-model.h b/src/photos-view-model.h
index cbdc1ff..4a3c686 100644
--- a/src/photos-view-model.h
+++ b/src/photos-view-model.h
@@ -28,6 +28,7 @@
#include <gtk/gtk.h>
#include "photos-base-item.h"
+#include "photos-mode-controller.h"
G_BEGIN_DECLS
@@ -81,7 +82,7 @@ struct _PhotosViewModelClass
GType photos_view_model_get_type (void) G_GNUC_CONST;
-GtkListStore *photos_view_model_new (void);
+GtkListStore *photos_view_model_new (PhotosWindowMode mode);
void photos_view_model_item_added (PhotosViewModel *self, PhotosBaseItem *item);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]