[gnome-photos] item-manager: Add "load-started" and "load-finished" signals
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] item-manager: Add "load-started" and "load-finished" signals
- Date: Fri, 26 Sep 2014 16:06:09 +0000 (UTC)
commit 8862e0a7bfe48d2441dd87402336a01e1547a5ea
Author: Debarshi Ray <debarshir gnome org>
Date: Fri Sep 26 11:23:20 2014 +0200
item-manager: Add "load-started" and "load-finished" signals
This keeps the code in sync with gnome-documents.
src/photos-embed.c | 78 +++++++-----------------------------------
src/photos-item-manager.c | 82 +++++++++++++++++++++++++++++++++++++++++++++
src/photos-item-manager.h | 3 ++
3 files changed, 98 insertions(+), 65 deletions(-)
---
diff --git a/src/photos-embed.c b/src/photos-embed.c
index 27e138b..62b1441 100644
--- a/src/photos-embed.c
+++ b/src/photos-embed.c
@@ -63,7 +63,6 @@ struct _PhotosEmbedSearchState
struct _PhotosEmbedPrivate
{
GAction *search_action;
- GCancellable *loader_cancellable;
GtkWidget *collections;
GtkWidget *favorites;
GtkWidget *no_results;
@@ -213,28 +212,16 @@ photos_embed_prepare_for_preview (PhotosEmbed *self)
static void
-photos_embed_item_load (GObject *source_object, GAsyncResult *res, gpointer user_data)
+photos_embed_load_finished (PhotosEmbed *self, PhotosBaseItem *item, GeglNode *node)
{
- PhotosEmbed *self = PHOTOS_EMBED (user_data);
PhotosEmbedPrivate *priv = self->priv;
- GError *error;
- GeglNode *node;
GtkListStore *model;
GtkTreePath *current_path;
- PhotosBaseItem *item = PHOTOS_BASE_ITEM (source_object);
PhotosWindowMode mode;
photos_embed_clear_load_timer (self);
- g_clear_object (&priv->loader_cancellable);
-
- error = NULL;
- node = photos_base_item_load_finish (item, res, &error);
- if (error != NULL)
- {
- g_warning ("Unable to load the item: %s", error->message);
- g_error_free (error);
- goto out;
- }
+ if (node == NULL)
+ return;
mode = photos_mode_controller_get_window_mode (priv->mode_cntrlr);
@@ -269,10 +256,6 @@ photos_embed_item_load (GObject *source_object, GAsyncResult *res, gpointer user
photos_embed_prepare_for_preview (self);
photos_mode_controller_set_can_fullscreen (priv->mode_cntrlr, TRUE);
-
- out:
- g_clear_object (&node);
- g_object_unref (self);
}
@@ -291,6 +274,14 @@ photos_embed_load_show_timeout (gpointer user_data)
static void
+photos_embed_load_started (PhotosEmbed *self)
+{
+ photos_embed_clear_load_timer (self);
+ self->priv->load_show_id = g_timeout_add (400, photos_embed_load_show_timeout, g_object_ref (self));
+}
+
+
+static void
photos_embed_restore_search (PhotosEmbed *self)
{
PhotosEmbedPrivate *priv = self->priv;
@@ -352,22 +343,6 @@ photos_embed_active_changed (PhotosBaseManager *manager, GObject *object, gpoint
state = g_variant_new ("b", show_search);
g_action_change_state (priv->search_action, state);
-
- if (object == NULL)
- return;
-
- photos_embed_clear_load_timer (self);
-
- if (photos_base_item_is_collection (PHOTOS_BASE_ITEM (object)))
- return;
-
- priv->load_show_id = g_timeout_add (400, photos_embed_load_show_timeout, g_object_ref (self));
-
- priv->loader_cancellable = g_cancellable_new ();
- photos_base_item_load_async (PHOTOS_BASE_ITEM (object),
- priv->loader_cancellable,
- photos_embed_item_load,
- g_object_ref (self));
}
@@ -453,13 +428,6 @@ photos_embed_prepare_for_collections (PhotosEmbed *self)
PhotosEmbedPrivate *priv = self->priv;
photos_base_manager_set_active_object (priv->item_mngr, NULL);
-
- if (priv->loader_cancellable != NULL)
- {
- g_cancellable_cancel (priv->loader_cancellable);
- g_clear_object (&priv->loader_cancellable);
- }
-
photos_spinner_box_stop (PHOTOS_SPINNER_BOX (priv->spinner_box));
gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "collections");
}
@@ -471,13 +439,6 @@ photos_embed_prepare_for_favorites (PhotosEmbed *self)
PhotosEmbedPrivate *priv = self->priv;
photos_base_manager_set_active_object (priv->item_mngr, NULL);
-
- if (priv->loader_cancellable != NULL)
- {
- g_cancellable_cancel (priv->loader_cancellable);
- g_clear_object (&priv->loader_cancellable);
- }
-
photos_spinner_box_stop (PHOTOS_SPINNER_BOX (priv->spinner_box));
gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "favorites");
}
@@ -489,13 +450,6 @@ photos_embed_prepare_for_overview (PhotosEmbed *self)
PhotosEmbedPrivate *priv = self->priv;
photos_base_manager_set_active_object (priv->item_mngr, NULL);
-
- if (priv->loader_cancellable != NULL)
- {
- g_cancellable_cancel (priv->loader_cancellable);
- g_clear_object (&priv->loader_cancellable);
- }
-
photos_spinner_box_stop (PHOTOS_SPINNER_BOX (priv->spinner_box));
gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "overview");
}
@@ -507,13 +461,6 @@ photos_embed_prepare_for_search (PhotosEmbed *self)
PhotosEmbedPrivate *priv = self->priv;
photos_base_manager_set_active_object (priv->item_mngr, NULL);
-
- if (priv->loader_cancellable != NULL)
- {
- g_cancellable_cancel (priv->loader_cancellable);
- g_clear_object (&priv->loader_cancellable);
- }
-
photos_spinner_box_stop (PHOTOS_SPINNER_BOX (priv->spinner_box));
gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "search");
}
@@ -647,7 +594,6 @@ photos_embed_dispose (GObject *object)
photos_embed_clear_search (self);
g_clear_object (&priv->ntfctn_mngr);
- g_clear_object (&priv->loader_cancellable);
g_clear_object (&priv->item_mngr);
g_clear_object (&priv->src_mngr);
g_clear_object (&priv->srch_mngr);
@@ -774,6 +720,8 @@ photos_embed_init (PhotosEmbed *self)
priv->item_mngr = g_object_ref (state->item_mngr);
g_signal_connect (priv->item_mngr, "active-changed", G_CALLBACK (photos_embed_active_changed), self);
+ g_signal_connect_swapped (priv->item_mngr, "load-finished", G_CALLBACK (photos_embed_load_finished), self);
+ g_signal_connect_swapped (priv->item_mngr, "load-started", G_CALLBACK (photos_embed_load_started), self);
priv->src_mngr = g_object_ref (state->src_mngr);
g_signal_connect_swapped (priv->src_mngr, "active-changed", G_CALLBACK (photos_embed_search_changed),
self);
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index 967c174..a8f330e 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -25,6 +25,7 @@
#include "config.h"
+#include <gio/gio.h>
#include <glib.h>
#include <tracker-sparql.h>
@@ -41,6 +42,7 @@
struct _PhotosItemManagerPrivate
{
+ GCancellable *loader_cancellable;
GHashTable *collections;
GIOExtensionPoint *extension_point;
GQueue *collection_path;
@@ -51,6 +53,8 @@ struct _PhotosItemManagerPrivate
enum
{
ACTIVE_COLLECTION_CHANGED,
+ LOAD_FINISHED,
+ LOAD_STARTED,
LAST_SIGNAL
};
@@ -171,6 +175,19 @@ photos_item_manager_changes_pending (PhotosItemManager *self, GHashTable *change
static void
+photos_item_manager_clear_active_item_load (PhotosItemManager *self)
+{
+ PhotosItemManagerPrivate *priv = self->priv;
+
+ if (priv->loader_cancellable != NULL)
+ {
+ g_cancellable_cancel (priv->loader_cancellable);
+ g_clear_object (&priv->loader_cancellable);
+ }
+}
+
+
+static void
photos_item_manager_collection_path_free_foreach (gpointer data, gpointer user_data)
{
g_clear_object (&data);
@@ -191,6 +208,33 @@ photos_item_manager_get_where (PhotosBaseManager *mngr, gint flags)
static void
+photos_item_manager_item_load (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+ PhotosItemManager *self = PHOTOS_ITEM_MANAGER (user_data);
+ PhotosItemManagerPrivate *priv = self->priv;
+ GError *error;
+ GeglNode *node = NULL;
+ PhotosBaseItem *item = PHOTOS_BASE_ITEM (source_object);
+
+ g_clear_object (&priv->loader_cancellable);
+
+ error = NULL;
+ node = photos_base_item_load_finish (item, res, &error);
+ if (error != NULL)
+ {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_warning ("Unable to load the item: %s", error->message);
+ g_error_free (error);
+ }
+
+ g_signal_emit (self, signals[LOAD_FINISHED], 0, item, node);
+
+ g_clear_object (&node);
+ g_object_unref (self);
+}
+
+
+static void
photos_item_manager_remove_object_by_id (PhotosBaseManager *mngr, const gchar *id)
{
PhotosItemManager *self = PHOTOS_ITEM_MANAGER (mngr);
@@ -237,6 +281,8 @@ photos_item_manager_set_active_object (PhotosBaseManager *manager, GObject *obje
goto out;
}
+ photos_item_manager_clear_active_item_load (self);
+
/* This is when we are going back to the overview from the preview. */
if (object == NULL)
goto end;
@@ -273,6 +319,14 @@ photos_item_manager_set_active_object (PhotosBaseManager *manager, GObject *obje
recent = gtk_recent_manager_get_default ();
uri = photos_base_item_get_uri (PHOTOS_BASE_ITEM (object));
gtk_recent_manager_add_item (recent, uri);
+
+ priv->loader_cancellable = g_cancellable_new ();
+ photos_base_item_load_async (PHOTOS_BASE_ITEM (object),
+ priv->loader_cancellable,
+ photos_item_manager_item_load,
+ g_object_ref (self));
+
+ g_signal_emit (self, signals[LOAD_STARTED], 0, PHOTOS_BASE_ITEM (object));
}
out:
@@ -294,6 +348,7 @@ photos_item_manager_dispose (GObject *object)
}
g_clear_pointer (&priv->collections, (GDestroyNotify) g_hash_table_unref);
+ g_clear_object (&priv->loader_cancellable);
g_clear_object (&priv->active_collection);
g_clear_object (&priv->monitor);
@@ -345,6 +400,31 @@ photos_item_manager_class_init (PhotosItemManagerClass *class)
G_TYPE_NONE,
1,
PHOTOS_TYPE_BASE_ITEM);
+
+ signals[LOAD_FINISHED] = g_signal_new ("load-finished",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (PhotosItemManagerClass,
+ load_finished),
+ NULL, /*accumulator */
+ NULL, /*accu_data */
+ g_cclosure_marshal_generic,
+ G_TYPE_NONE,
+ 2,
+ PHOTOS_TYPE_BASE_ITEM,
+ GEGL_TYPE_NODE);
+
+ signals[LOAD_STARTED] = g_signal_new ("load-started",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (PhotosItemManagerClass,
+ load_started),
+ NULL, /*accumulator */
+ NULL, /*accu_data */
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1,
+ PHOTOS_TYPE_BASE_ITEM);
}
@@ -361,6 +441,8 @@ photos_item_manager_activate_previous_collection (PhotosItemManager *self)
PhotosItemManagerPrivate *priv = self->priv;
gpointer *collection;
+ photos_item_manager_clear_active_item_load (self);
+
collection = g_queue_pop_head (priv->collection_path);
g_assert (collection == NULL || PHOTOS_IS_BASE_ITEM (collection));
diff --git a/src/photos-item-manager.h b/src/photos-item-manager.h
index d176c51..43f6155 100644
--- a/src/photos-item-manager.h
+++ b/src/photos-item-manager.h
@@ -25,6 +25,7 @@
#ifndef PHOTOS_ITEM_MANAGER_H
#define PHOTOS_ITEM_MANAGER_H
+#include <gegl.h>
#include <gtk/gtk.h>
#include <tracker-sparql.h>
@@ -71,6 +72,8 @@ struct _PhotosItemManagerClass
/* signals */
void (*active_collection_changed) (PhotosItemManager *self, PhotosBaseItem *collection);
+ void (*load_finished) (PhotosItemManager *self, PhotosBaseItem *item, GeglNode *node);
+ void (*load_started) (PhotosItemManager *self, PhotosBaseItem *item);
};
GType photos_item_manager_get_type (void) G_GNUC_CONST;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]