[gnome-photos] Move the code to update the OffsetControllers' count
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] Move the code to update the OffsetControllers' count
- Date: Wed, 11 Jan 2017 13:19:52 +0000 (UTC)
commit 418a1e1069e6b65618f0c7cb7956ee83ac3c6451
Author: Debarshi Ray <debarshir gnome org>
Date: Wed Jan 11 10:26:37 2017 +0100
Move the code to update the OffsetControllers' count
Once we port to GtkFlowBox, we will lose the ViewModel class.
Therefore, we need to find a new home for the code that resets the
OffsetControllers' count whenever BaseItems are added or removed to
the child BaseManagers inside ItemManager.
TrackerController is a good choice because it already uses ItemManager
and the mode-specific OffsetController.
The other option was to do it in ItemManager itself, but since some
OffsetControllers also use ItemManager it will create problems when the
singletons are initially created.
https://bugzilla.gnome.org/show_bug.cgi?id=690623
src/photos-tracker-controller.c | 62 ++++++++++++++++++++++++++++++++++++++-
src/photos-view-model.c | 44 ---------------------------
2 files changed, 61 insertions(+), 45 deletions(-)
---
diff --git a/src/photos-tracker-controller.c b/src/photos-tracker-controller.c
index 5ddd6ad..2ead21e 100644
--- a/src/photos-tracker-controller.c
+++ b/src/photos-tracker-controller.c
@@ -1,6 +1,6 @@
/*
* Photos - access, organize and share your photos on GNOME
- * Copyright © 2012 – 2016 Red Hat, Inc.
+ * Copyright © 2012 – 2017 Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -61,6 +61,7 @@ struct _PhotosTrackerControllerPrivate
gboolean refresh_pending;
gint query_queued_flags;
gint64 last_query_time;
+ guint reset_count_id;
};
enum
@@ -86,6 +87,11 @@ EGG_DEFINE_COUNTER (instances,
"Number of PhotosTrackerController instances")
+enum
+{
+ RESET_COUNT_TIMEOUT = 500 /* ms */
+};
+
typedef enum
{
PHOTOS_TRACKER_REFRESH_FLAGS_NONE = 0,
@@ -97,6 +103,41 @@ static void photos_tracker_controller_refresh_internal (PhotosTrackerController
static void photos_tracker_controller_set_query_status (PhotosTrackerController *self, gboolean
query_status);
+static gboolean
+photos_tracker_controller_reset_count_timeout (gpointer user_data)
+{
+ PhotosTrackerController *self = PHOTOS_TRACKER_CONTROLLER (user_data);
+ PhotosTrackerControllerPrivate *priv;
+
+ priv = photos_tracker_controller_get_instance_private (self);
+
+ priv->reset_count_id = 0;
+ photos_offset_controller_reset_count (priv->offset_cntrlr);
+ return G_SOURCE_REMOVE;
+}
+
+
+static void
+photos_tracker_controller_item_added_removed (PhotosTrackerController *self)
+{
+ PhotosTrackerControllerPrivate *priv;
+
+ priv = photos_tracker_controller_get_instance_private (self);
+
+ /* Update the count so that PhotosOffsetController has the correct
+ * values. Otherwise things like loading more items and "No
+ * Results" page will not work correctly.
+ */
+
+ if (priv->reset_count_id == 0)
+ {
+ priv->reset_count_id = g_timeout_add (RESET_COUNT_TIMEOUT,
+ photos_tracker_controller_reset_count_timeout,
+ self);
+ }
+}
+
+
static void
photos_tracker_controller_query_error (PhotosTrackerController *self, GError *error)
{
@@ -362,11 +403,24 @@ photos_tracker_controller_constructed (GObject *object)
{
PhotosTrackerController *self = PHOTOS_TRACKER_CONTROLLER (object);
PhotosTrackerControllerPrivate *priv;
+ PhotosBaseManager *item_mngr_chld;
priv = photos_tracker_controller_get_instance_private (self);
G_OBJECT_CLASS (photos_tracker_controller_parent_class)->constructed (object);
+ item_mngr_chld = photos_item_manager_get_for_mode (PHOTOS_ITEM_MANAGER (priv->item_mngr), priv->mode);
+ g_signal_connect_object (item_mngr_chld,
+ "object-added",
+ G_CALLBACK (photos_tracker_controller_item_added_removed),
+ self,
+ G_CONNECT_SWAPPED);
+ g_signal_connect_object (item_mngr_chld,
+ "object-removed",
+ G_CALLBACK (photos_tracker_controller_item_added_removed),
+ self,
+ G_CONNECT_SWAPPED);
+
priv->offset_cntrlr = PHOTOS_TRACKER_CONTROLLER_GET_CLASS (self)->get_offset_controller (self);
g_signal_connect_swapped (priv->offset_cntrlr,
"offset-changed",
@@ -383,6 +437,12 @@ photos_tracker_controller_dispose (GObject *object)
priv = photos_tracker_controller_get_instance_private (self);
+ if (priv->reset_count_id != 0)
+ {
+ g_source_remove (priv->reset_count_id);
+ priv->reset_count_id = 0;
+ }
+
g_clear_object (&priv->src_mngr);
g_clear_object (&priv->offset_cntrlr);
g_clear_object (&priv->queue);
diff --git a/src/photos-view-model.c b/src/photos-view-model.c
index cca4a5c..6652e5d 100644
--- a/src/photos-view-model.c
+++ b/src/photos-view-model.c
@@ -50,7 +50,6 @@ struct _PhotosViewModel
gchar *row_ref_key;
gint n_rows;
gint64 oldest_mtime;
- guint reset_count_id;
};
enum
@@ -63,12 +62,6 @@ enum
G_DEFINE_TYPE (PhotosViewModel, photos_view_model, GTK_TYPE_LIST_STORE);
-enum
-{
- RESET_COUNT_TIMEOUT = 500 /* ms */
-};
-
-
static void
photos_view_model_info_set (PhotosViewModel *self, PhotosBaseItem *item, GtkTreeIter *iter)
{
@@ -84,25 +77,6 @@ photos_view_model_info_set (PhotosViewModel *self, PhotosBaseItem *item, GtkTree
}
-static gboolean
-photos_view_model_reset_count_timeout (gpointer user_data)
-{
- PhotosViewModel *self = PHOTOS_VIEW_MODEL (user_data);
-
- self->reset_count_id = 0;
- photos_offset_controller_reset_count (self->offset_cntrlr);
- return G_SOURCE_REMOVE;
-}
-
-
-static void
-photos_view_model_reset_count (PhotosViewModel *self)
-{
- if (self->reset_count_id == 0)
- self->reset_count_id = g_timeout_add (RESET_COUNT_TIMEOUT, photos_view_model_reset_count_timeout, self);
-}
-
-
static void
photos_view_model_add_item (PhotosViewModel *self, PhotosBaseItem *item)
{
@@ -113,12 +87,6 @@ photos_view_model_add_item (PhotosViewModel *self, PhotosBaseItem *item)
gint step;
gint64 mtime;
- /* Update the count so that PhotosOffsetController has the correct
- * values. Otherwise things like loading more items and "No
- * Results" page will not work correctly.
- */
- photos_view_model_reset_count (self);
-
offset = photos_offset_controller_get_offset (self->offset_cntrlr);
step = photos_offset_controller_get_step (self->offset_cntrlr);
mtime = photos_base_item_get_mtime (item);
@@ -207,12 +175,6 @@ photos_view_model_item_removed_foreach (GtkTreeModel *model,
static void
photos_view_model_remove_item (PhotosViewModel *self, PhotosBaseItem *item)
{
- /* Update the count so that PhotosOffsetController has the correct
- * values. Otherwise things like loading more items and "No
- * Results" page will not work correctly.
- */
- photos_view_model_reset_count (self);
-
self->oldest_mtime = G_MAXINT64;
gtk_tree_model_foreach (GTK_TREE_MODEL (self), photos_view_model_item_removed_foreach, item);
g_object_set_data (G_OBJECT (item), self->row_ref_key, NULL);
@@ -320,12 +282,6 @@ photos_view_model_dispose (GObject *object)
{
PhotosViewModel *self = PHOTOS_VIEW_MODEL (object);
- if (self->reset_count_id != 0)
- {
- g_source_remove (self->reset_count_id);
- self->reset_count_id = 0;
- }
-
g_clear_object (&self->offset_cntrlr);
g_clear_object (&self->trk_cntrlr);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]