[gnome-photos] application, done-notification: Use a GAction to handle the revert
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos] application, done-notification: Use a GAction to handle the revert
- Date: Sat, 16 Jul 2016 19:26:48 +0000 (UTC)
commit 358ed343da905101b32a61855f2c58fa18dfe536
Author: Debarshi Ray <debarshir gnome org>
Date: Sun Jul 10 01:32:34 2016 +0200
application, done-notification: Use a GAction to handle the revert
This will make it easier to add nice things like keyboard shortcuts in
the future.
https://bugzilla.gnome.org/show_bug.cgi?id=763908
src/photos-application.c | 69 +++++++++++++++++++++++++++++++++
src/photos-done-notification.c | 83 +++++++++++----------------------------
2 files changed, 93 insertions(+), 59 deletions(-)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index c438f95..bf1c5be 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -80,6 +80,7 @@ struct _PhotosApplication
GSimpleAction *edit_action;
GSimpleAction *edit_cancel_action;
GSimpleAction *edit_done_action;
+ GSimpleAction *edit_revert_action;
GSimpleAction *fs_action;
GSimpleAction *gear_action;
GSimpleAction *insta_action;
@@ -788,6 +789,65 @@ photos_application_edit_current (PhotosApplication *self)
static void
+photos_application_edit_revert_pipeline_save (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+ PhotosApplication *self = PHOTOS_APPLICATION (user_data);
+ GError *error;
+ PhotosBaseItem *item = PHOTOS_BASE_ITEM (source_object);
+
+ error = NULL;
+ if (!photos_base_item_pipeline_save_finish (item, res, &error))
+ {
+ g_warning ("Unable to save pipeline: %s", error->message);
+ g_error_free (error);
+ }
+
+ g_application_release (G_APPLICATION (self));
+}
+
+
+static void
+photos_application_edit_revert_revert (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+ PhotosApplication *self = PHOTOS_APPLICATION (user_data);
+ GError *error;
+ PhotosBaseItem *item = PHOTOS_BASE_ITEM (source_object);
+
+ error = NULL;
+ if (!photos_base_item_operations_revert_finish (item, res, &error))
+ {
+ g_warning ("Unable to process item: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ g_application_hold (G_APPLICATION (self));
+ photos_base_item_pipeline_save_async (item, NULL, photos_application_edit_revert_pipeline_save, self);
+
+ out:
+ g_action_activate (G_ACTION (self->draw_action), NULL);
+ g_application_release (G_APPLICATION (self));
+}
+
+
+static void
+photos_application_edit_revert (PhotosApplication *self, GVariant *parameter)
+{
+ PhotosBaseItem *item;
+ const gchar *id;
+
+ id = g_variant_get_string (parameter, NULL);
+ g_return_if_fail (id != NULL && id[0] != '\0');
+
+ item = PHOTOS_BASE_ITEM (photos_base_manager_get_object_by_id (self->state->item_mngr, id));
+ g_return_if_fail (item != NULL);
+
+ g_application_hold (G_APPLICATION (self));
+ photos_base_item_operations_revert_async (item, NULL, photos_application_edit_revert_revert, self);
+}
+
+
+static void
photos_application_fullscreen (PhotosApplication *self, GVariant *parameter)
{
photos_mode_controller_toggle_fullscreen (self->state->mode_cntrlr);
@@ -1530,6 +1590,14 @@ photos_application_startup (GApplication *application)
self->edit_done_action = g_simple_action_new ("edit-done", NULL);
g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (self->edit_done_action));
+ self->edit_revert_action = g_simple_action_new ("edit-revert", G_VARIANT_TYPE_STRING);
+ g_simple_action_set_enabled (self->edit_revert_action, FALSE);
+ g_signal_connect_swapped (self->edit_revert_action,
+ "activate",
+ G_CALLBACK (photos_application_edit_revert),
+ self);
+ g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (self->edit_revert_action));
+
self->fs_action = g_simple_action_new ("fullscreen", NULL);
g_signal_connect_swapped (self->fs_action, "activate", G_CALLBACK (photos_application_fullscreen), self);
g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (self->fs_action));
@@ -1689,6 +1757,7 @@ photos_application_dispose (GObject *object)
g_clear_object (&self->edit_action);
g_clear_object (&self->edit_cancel_action);
g_clear_object (&self->edit_done_action);
+ g_clear_object (&self->edit_revert_action);
g_clear_object (&self->fs_action);
g_clear_object (&self->gear_action);
g_clear_object (&self->insta_action);
diff --git a/src/photos-done-notification.c b/src/photos-done-notification.c
index b80515a..28120c3 100644
--- a/src/photos-done-notification.c
+++ b/src/photos-done-notification.c
@@ -1,6 +1,7 @@
/*
* Photos - access, organize and share your photos on GNOME
* Copyright © 2016 Rafael Fonseca
+ * Copyright © 2016 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
@@ -26,6 +27,7 @@
#include "photos-base-item.h"
#include "photos-done-notification.h"
+#include "photos-filterable.h"
#include "photos-icons.h"
#include "photos-notification-manager.h"
#include "photos-search-context.h"
@@ -34,6 +36,7 @@
struct _PhotosDoneNotification
{
GtkGrid parent_instance;
+ GAction *edit_revert_action;
PhotosBaseItem *item;
GtkWidget *ntfctn_mngr;
guint timeout_id;
@@ -69,6 +72,7 @@ photos_done_notification_remove_timeout (PhotosDoneNotification *self)
static void
photos_done_notification_destroy (PhotosDoneNotification *self)
{
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (self->edit_revert_action), FALSE);
photos_done_notification_remove_timeout (self);
gtk_widget_destroy (GTK_WIDGET (self));
}
@@ -86,66 +90,8 @@ photos_done_notification_timeout (gpointer user_data)
static void
-photos_done_notification_pipeline_save_finish (GObject *source_object, GAsyncResult *res, gpointer user_data)
-{
- GApplication *app;
- GError *error = NULL;
- PhotosBaseItem *item = PHOTOS_BASE_ITEM (source_object);
-
- if (!photos_base_item_pipeline_save_finish (item, res, &error))
- {
- g_warning ("Unable to save pipeline: %s", error->message);
- g_error_free (error);
- }
-
- app = g_application_get_default ();
- g_application_release (app);
-}
-
-
-static void
-photos_done_notification_edit_undo_process (GObject *source_object, GAsyncResult *res, gpointer user_data)
-{
- GApplication *app;
- GAction *action;
- GError *error = NULL;
- PhotosBaseItem *item = PHOTOS_BASE_ITEM (source_object);
-
- app = g_application_get_default ();
-
- if (!photos_base_item_operations_revert_finish (item, res, &error))
- {
- g_warning ("Unable to process item: %s", error->message);
- g_error_free (error);
- goto out;
- }
-
- g_application_hold (app);
- photos_base_item_pipeline_save_async (item,
- NULL,
- photos_done_notification_pipeline_save_finish,
- NULL);
-
- out:
- action = g_action_map_lookup_action (G_ACTION_MAP (app), "draw-current");
- g_action_activate (action, NULL);
- g_application_release (app);
-}
-
-
-static void
photos_done_notification_undo_clicked (PhotosDoneNotification *self)
{
- GApplication *app;
-
- app = g_application_get_default ();
- g_application_hold (app);
-
- photos_base_item_operations_revert_async (self->item,
- NULL,
- photos_done_notification_edit_undo_process,
- NULL);
-
photos_done_notification_destroy (self);
}
@@ -158,6 +104,7 @@ photos_done_notification_constructed (GObject *object)
GtkWidget *image;
GtkWidget *label;
GtkWidget *undo;
+ const gchar *id;
const gchar *name;
gchar *msg;
@@ -177,8 +124,19 @@ photos_done_notification_constructed (GObject *object)
undo = gtk_button_new_with_label (_("Undo"));
gtk_widget_set_valign (undo, GTK_ALIGN_CENTER);
+ gtk_actionable_set_action_name (GTK_ACTIONABLE (undo), "app.edit-revert");
+ id = photos_filterable_get_id (PHOTOS_FILTERABLE (self->item));
+ gtk_actionable_set_action_target (GTK_ACTIONABLE (undo), "s", id);
gtk_container_add (GTK_CONTAINER (self), undo);
- g_signal_connect_swapped (undo, "clicked", G_CALLBACK (photos_done_notification_undo_clicked), self);
+ /* GtkButton will activate the GAction in a signal handler with the
+ * 'after' flag set. We need to ensure that we don't self-destruct
+ * before that.
+ */
+ g_signal_connect_object (undo,
+ "clicked",
+ G_CALLBACK (photos_done_notification_undo_clicked),
+ self,
+ G_CONNECT_AFTER | G_CONNECT_SWAPPED);
image = gtk_image_new_from_icon_name (PHOTOS_ICON_WINDOW_CLOSE_SYMBOLIC, GTK_ICON_SIZE_INVALID);
gtk_widget_set_margin_bottom (image, 2);
@@ -195,6 +153,7 @@ photos_done_notification_constructed (GObject *object)
photos_notification_manager_add_notification (PHOTOS_NOTIFICATION_MANAGER (self->ntfctn_mngr),
GTK_WIDGET (self));
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (self->edit_revert_action), TRUE);
self->timeout_id = g_timeout_add_seconds (DONE_TIMEOUT, photos_done_notification_timeout, self);
}
@@ -205,6 +164,7 @@ photos_done_notification_dispose (GObject *object)
{
PhotosDoneNotification *self = PHOTOS_DONE_NOTIFICATION (object);
+ g_simple_action_set_enabled (G_SIMPLE_ACTION (self->edit_revert_action), FALSE);
photos_done_notification_remove_timeout (self);
g_clear_object (&self->item);
@@ -238,6 +198,11 @@ photos_done_notification_set_property (GObject *object, guint prop_id, const GVa
static void
photos_done_notification_init (PhotosDoneNotification *self)
{
+ GApplication *app;
+
+ app = g_application_get_default ();
+ self->edit_revert_action = g_action_map_lookup_action (G_ACTION_MAP (app), "edit-revert");
+
self->ntfctn_mngr = photos_notification_manager_dup_singleton ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]