[gnome-photos/wip/rishi/share-point: 15/18] application: Add share action



commit 999ad5909194a0cd28e2cb409ec5375f98f8c4b7
Author: Umang Jain <mailumangjain gmail com>
Date:   Fri Jul 15 22:29:12 2016 +0530

    application: Add share action
    
    https://bugzilla.gnome.org/show_bug.cgi?id=751181

 src/photos-application.c |   70 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 70 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index d59d813..789d656 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -58,6 +58,8 @@
 #include "photos-single-item-job.h"
 #include "photos-source.h"
 #include "photos-source-manager.h"
+#include "photos-share-dialog.h"
+#include "photos-share-notification.h"
 #include "photos-tracker-extract-priority.h"
 #include "photos-utils.h"
 
@@ -99,6 +101,7 @@ struct _PhotosApplication
   GSimpleAction *sel_none_action;
   GSimpleAction *set_bg_action;
   GSimpleAction *set_ss_action;
+  GSimpleAction *share_action;
   GSimpleAction *sharpen_action;
   GtkWidget *main_window;
   PhotosCameraCache *camera_cache;
@@ -1335,6 +1338,69 @@ photos_application_set_bg_common (PhotosApplication *self, GVariant *parameter,
 
 
 static void
+photos_application_share_share (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+  PhotosApplication *self = PHOTOS_APPLICATION (user_data);
+  PhotosSharePoint *share_point = PHOTOS_SHARE_POINT (source_object);
+  GError *error = NULL;
+
+  photos_share_point_share_finish (share_point, res, &error);
+  if (error != NULL)
+    {
+      g_warning ("Unable to share the image: %s", error->message);
+      photos_share_notification_new_with_error (share_point, error);
+      g_error_free (error);
+      goto out;
+    }
+
+ out:
+  g_application_unmark_busy (G_APPLICATION (self));
+  g_application_release (G_APPLICATION (self));
+}
+
+
+static void
+photos_application_share_response (GtkDialog *dialog, gint response_id, gpointer user_data)
+{
+  PhotosApplication *self = PHOTOS_APPLICATION (user_data);
+  PhotosBaseItem *item;
+  PhotosSharePoint *share_point;
+
+  if (response_id != GTK_RESPONSE_OK)
+    goto out;
+
+  share_point = photos_share_dialog_get_selected_share_point (PHOTOS_SHARE_DIALOG (dialog));
+  g_return_if_fail (share_point != NULL);
+
+  item = photos_application_get_selection_or_active_item (self);
+  g_return_if_fail (item != NULL);
+
+  g_application_hold (G_APPLICATION (self));
+  g_application_mark_busy (G_APPLICATION (self));
+  photos_share_point_share_async (share_point, item, NULL, photos_application_share_share, self);
+
+ out:
+  gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
+
+static void
+photos_application_share_current (PhotosApplication *self)
+{
+  GtkWidget *dialog;
+  PhotosBaseItem *item;
+
+  item = photos_application_get_selection_or_active_item (self);
+  g_return_if_fail (item != NULL);
+  g_return_if_fail (!photos_base_item_is_collection (item));
+
+  dialog = photos_share_dialog_new (GTK_WINDOW (self->main_window), item);
+  gtk_widget_show_all (dialog);
+  g_signal_connect (dialog, "response", G_CALLBACK (photos_application_share_response), self);
+}
+
+
+static void
 photos_application_start_miners (PhotosApplication *self)
 {
   photos_application_create_miners (self);
@@ -1754,6 +1820,10 @@ photos_application_startup (GApplication *application)
   g_signal_connect_swapped (self->set_ss_action, "activate", G_CALLBACK (photos_application_set_bg_common), 
self);
   g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (self->set_ss_action));
 
+  self->share_action = g_simple_action_new ("share-current", NULL);
+  g_signal_connect_swapped (self->share_action, "activate", G_CALLBACK (photos_application_share_current), 
self);
+  g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (self->share_action));
+
   self->sharpen_action = g_simple_action_new ("sharpen-current", G_VARIANT_TYPE_DOUBLE);
   g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (self->sharpen_action));
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]