[gnome-photos/wip/rishi/share-point: 7/10] application: Add share action



commit fb70b6ddba3cdf7b414de196d792018736299f92
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 |   68 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 68 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index bf1c5be..0124aac 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -58,6 +58,7 @@
 #include "photos-single-item-job.h"
 #include "photos-source.h"
 #include "photos-source-manager.h"
+#include "photos-share-dialog.h"
 #include "photos-tracker-extract-priority.h"
 #include "photos-utils.h"
 
@@ -99,6 +100,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;
@@ -1270,6 +1272,68 @@ 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);
+      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);
@@ -1689,6 +1753,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]