[gnome-photos/wip/rishi/issue-115-load-error: 20/20] Propagate any GError while loading a BaseItem
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/issue-115-load-error: 20/20] Propagate any GError while loading a BaseItem
- Date: Tue, 23 Oct 2018 13:28:05 +0000 (UTC)
commit da575cdc6dc03aacb95cd3a42c81b5eb1a0ce45d
Author: Debarshi Ray <debarshir gnome org>
Date: Tue Oct 9 15:26:32 2018 +0200
Propagate any GError while loading a BaseItem
A subsequent commit will use this to provide some visual feedback to
the user, instead of a blank window, which is the case now.
https://gitlab.gnome.org/GNOME/gnome-photos/issues/115
po/POTFILES.in | 1 +
src/photos-application.c | 4 ++++
src/photos-embed.c | 17 ++++++++++++++---
src/photos-item-manager.c | 42 +++++++++++++++++++++++++++++++++++-------
src/photos-marshalers.list | 1 +
5 files changed, 55 insertions(+), 10 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 03a82026..919b9c18 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -20,6 +20,7 @@ src/photos-help-overlay.ui
src/photos-import-dialog.c
src/photos-import-dialog.ui
src/photos-indexing-notification.c
+src/photos-item-manager.c
src/photos-local-item.c
src/photos-main-toolbar.c
src/photos-main-window.c
diff --git a/src/photos-application.c b/src/photos-application.c
index fbf81341..03b67b5f 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -2905,6 +2905,10 @@ photos_application_startup (GApplication *application)
gtk_application_set_accels_for_action (GTK_APPLICATION (self), detailed_action_name, zoom_out_accels);
}
+ g_signal_connect_swapped (self->state->item_mngr,
+ "load-error",
+ G_CALLBACK (photos_application_load_changed),
+ self);
g_signal_connect_swapped (self->state->item_mngr,
"load-finished",
G_CALLBACK (photos_application_load_changed),
diff --git a/src/photos-embed.c b/src/photos-embed.c
index 45a1b4e6..2dc82bcf 100644
--- a/src/photos-embed.c
+++ b/src/photos-embed.c
@@ -346,13 +346,19 @@ photos_embed_prepare_for_preview (PhotosEmbed *self, PhotosWindowMode old_mode)
static void
-photos_embed_load_finished (PhotosEmbed *self, PhotosBaseItem *item, GeglNode *node)
+photos_embed_load_error (PhotosEmbed *self, const gchar *message, GError *error)
{
photos_embed_clear_load_timer (self);
photos_spinner_box_stop (PHOTOS_SPINNER_BOX (self->spinner_box));
+}
- if (node == NULL)
- return;
+
+static void
+photos_embed_load_finished (PhotosEmbed *self, PhotosBaseItem *item, GeglNode *node)
+{
+ photos_embed_clear_load_timer (self);
+ photos_spinner_box_stop (PHOTOS_SPINNER_BOX (self->spinner_box));
+ g_return_if_fail (GEGL_IS_NODE (node));
photos_preview_view_set_node (PHOTOS_PREVIEW_VIEW (self->preview), node);
@@ -869,6 +875,11 @@ photos_embed_init (PhotosEmbed *self)
G_CONNECT_SWAPPED);
self->item_mngr = g_object_ref (state->item_mngr);
+ g_signal_connect_object (self->item_mngr,
+ "load-error",
+ G_CALLBACK (photos_embed_load_error),
+ self,
+ G_CONNECT_SWAPPED);
g_signal_connect_object (self->item_mngr,
"load-finished",
G_CALLBACK (photos_embed_load_finished),
diff --git a/src/photos-item-manager.c b/src/photos-item-manager.c
index cd33ef60..dd737e17 100644
--- a/src/photos-item-manager.c
+++ b/src/photos-item-manager.c
@@ -1,6 +1,6 @@
/*
* Photos - access, organize and share your photos on GNOME
- * Copyright © 2012 – 2017 Red Hat, Inc.
+ * Copyright © 2012 – 2018 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 as published by
@@ -28,6 +28,7 @@
#include <dazzle.h>
#include <gio/gio.h>
#include <glib.h>
+#include <glib/gi18n.h>
#include <tracker-sparql.h>
#include "photos-debug.h"
@@ -72,6 +73,7 @@ enum
ACTIVE_COLLECTION_CHANGED,
CAN_FULLSCREEN_CHANGED,
FULLSCREEN_CHANGED,
+ LOAD_ERROR,
LOAD_FINISHED,
LOAD_STARTED,
WINDOW_MODE_CHANGED,
@@ -806,18 +808,32 @@ photos_item_manager_item_load (GObject *source_object, GAsyncResult *res, gpoint
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_autofree gchar *message = NULL;
self->load_state = PHOTOS_LOAD_STATE_ERROR;
- }
- else
- {
- self->load_state = PHOTOS_LOAD_STATE_FINISHED;
+
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ {
+ const gchar *domain_str;
+ const gchar *name;
+
+ domain_str = g_quark_to_string (error->domain);
+ g_warning ("Unable to load item: (%s, %d) %s", domain_str, error->code, error->message);
+
+ name = photos_base_item_get_name_with_fallback (item);
+ message = g_strdup_printf (_("Oops! Unable to load “%s”"), name);
+ }
+
+ g_signal_emit (self, signals[LOAD_ERROR], 0, message, error);
+ goto out;
}
}
+ self->load_state = PHOTOS_LOAD_STATE_FINISHED;
g_signal_emit (self, signals[LOAD_FINISHED], 0, item, node);
+
+ out:
+ return;
}
@@ -1147,6 +1163,18 @@ photos_item_manager_class_init (PhotosItemManagerClass *class)
1,
G_TYPE_BOOLEAN);
+ signals[LOAD_ERROR] = g_signal_new ("load-error",
+ G_TYPE_FROM_CLASS (class),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, /*accumulator */
+ NULL, /*accu_data */
+ _photos_marshal_VOID__STRING_ENUM,
+ G_TYPE_NONE,
+ 2,
+ G_TYPE_STRING,
+ G_TYPE_ERROR);
+
signals[LOAD_FINISHED] = g_signal_new ("load-finished",
G_TYPE_FROM_CLASS (class),
G_SIGNAL_RUN_LAST,
diff --git a/src/photos-marshalers.list b/src/photos-marshalers.list
index ea1cd27e..47396eec 100644
--- a/src/photos-marshalers.list
+++ b/src/photos-marshalers.list
@@ -2,4 +2,5 @@ VOID:BOXED,BOXED
VOID:DOUBLE,ENUM
VOID:ENUM,ENUM
VOID:INT,INT
+VOID:STRING,ENUM
VOID:STRING,STRING
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]