Commit da575cdc authored by Debarshi Ray's avatar Debarshi Ray

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.

#115
parent 2c543091
Pipeline #37088 passed with stage
in 12 minutes and 59 seconds
......@@ -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
......
......@@ -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),
......
......@@ -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),
......
/*
* 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,
......
......@@ -2,4 +2,5 @@ VOID:BOXED,BOXED
VOID:DOUBLE,ENUM
VOID:ENUM,ENUM
VOID:INT,INT
VOID:STRING,ENUM
VOID:STRING,STRING
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment