[gnome-photos] properties-dialog: Use PhotosCameraCache to show the camera



commit 90d696f33ab5dbd251a0bf27f87cfbc7ca95b362
Author: Debarshi Ray <debarshir gnome org>
Date:   Mon Aug 12 12:33:12 2013 +0200

    properties-dialog: Use PhotosCameraCache to show the camera

 src/photos-application.c       |    9 +++++
 src/photos-properties-dialog.c |   69 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 77 insertions(+), 1 deletions(-)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index cb33058..21bc10b 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -34,6 +34,7 @@
 
 #include "eog-debug.h"
 #include "photos-application.h"
+#include "photos-camera-cache.h"
 #include "photos-dlna-renderers-dialog.h"
 #include "photos-gom-miner.h"
 #include "photos-item-manager.h"
@@ -62,6 +63,7 @@ struct _PhotosApplicationPrivate
   GtkWidget *main_window;
   PhotosBaseManager *item_mngr;
   PhotosBaseManager *src_mngr;
+  PhotosCameraCache *camera_cache;
   PhotosModeController *mode_cntrlr;
 };
 
@@ -421,6 +423,12 @@ photos_application_startup (GApplication *application)
 
   priv->item_mngr = photos_item_manager_new ();
   priv->src_mngr = photos_source_manager_new ();
+
+  /* A dummy reference to keep it alive during the lifetime of the
+   * application.
+   */
+  priv->camera_cache = photos_camera_cache_new ();
+
   priv->mode_cntrlr = photos_mode_controller_new ();
 
   action = g_simple_action_new ("about", NULL);
@@ -548,6 +556,7 @@ photos_application_dispose (GObject *object)
   g_clear_object (&priv->flickr_miner);
   g_clear_object (&priv->item_mngr);
   g_clear_object (&priv->src_mngr);
+  g_clear_object (&priv->camera_cache);
   g_clear_object (&priv->mode_cntrlr);
 
   G_OBJECT_CLASS (photos_application_parent_class)->dispose (object);
diff --git a/src/photos-properties-dialog.c b/src/photos-properties-dialog.c
index ec70030..00eee63 100644
--- a/src/photos-properties-dialog.c
+++ b/src/photos-properties-dialog.c
@@ -29,6 +29,7 @@
 #include <glib.h>
 #include <glib/gi18n.h>
 
+#include "photos-camera-cache.h"
 #include "photos-flickr-item.h"
 #include "photos-item-manager.h"
 #include "photos-local-item.h"
@@ -38,8 +39,12 @@
 
 struct _PhotosPropertiesDialogPrivate
 {
+  GCancellable *cancellable;
+  GtkWidget *camera_w;
+  GtkWidget *grid;
   GtkWidget *title_entry;
   PhotosBaseManager *item_mngr;
+  PhotosCameraCache *camera_cache;
   gchar *urn;
   guint title_entry_timeout;
 };
@@ -61,6 +66,42 @@ enum
 };
 
 
+static void
+photos_properties_dialog_get_camera (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+  PhotosPropertiesDialog *self;
+  PhotosPropertiesDialogPrivate *priv;
+  GError *error;
+  gchar *camera;
+
+  error = NULL;
+  camera = photos_camera_cache_get_camera_finish (PHOTOS_CAMERA_CACHE (source_object), res, &error);
+  if (error != NULL)
+    {
+      if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+        g_warning ("Unable to get camera: %s", error->message);
+      g_error_free (error);
+      return;
+    }
+
+  /* Now we know that self has not been destroyed. */
+  self = PHOTOS_PROPERTIES_DIALOG (user_data);
+  priv = self->priv;
+
+  if (camera != NULL)
+    {
+      GtkWidget *camera_data;
+
+      camera_data = gtk_label_new (camera);
+      gtk_widget_set_halign (camera_data, GTK_ALIGN_START);
+      gtk_grid_attach_next_to (GTK_GRID (priv->grid), camera_data, priv->camera_w, GTK_POS_RIGHT, 2, 1);
+      gtk_widget_show (camera_data);
+    }
+
+  g_free (camera);
+}
+
+
 static gboolean
 photos_properties_dialog_title_entry_timeout (gpointer user_data)
 {
@@ -113,6 +154,7 @@ photos_properties_dialog_constructed (GObject *object)
   GtkWidget *source;
   GtkWidget *source_data;
   GtkWidget *title;
+  GQuark equipment;
   PhotosBaseItem *item;
   const gchar *author;
   const gchar *name;
@@ -141,7 +183,7 @@ photos_properties_dialog_constructed (GObject *object)
       g_date_time_unref (date_created);
     }
 
-  grid = gtk_grid_new ();
+  priv->grid = grid = gtk_grid_new ();
   gtk_widget_set_halign (grid, GTK_ALIGN_CENTER);
   gtk_widget_set_margin_left (grid, 24);
   gtk_widget_set_margin_right (grid, 24);
@@ -208,6 +250,21 @@ photos_properties_dialog_constructed (GObject *object)
   gtk_style_context_add_class (context, "dim-label");
   gtk_container_add (GTK_CONTAINER (grid), item_type);
 
+  equipment = photos_base_item_get_equipment (item);
+  photos_camera_cache_get_camera_async (priv->camera_cache,
+                                        equipment,
+                                        priv->cancellable,
+                                        photos_properties_dialog_get_camera,
+                                        self);
+  if (equipment != 0)
+    {
+      priv->camera_w = gtk_label_new (_("Camera"));
+      gtk_widget_set_halign (priv->camera_w, GTK_ALIGN_END);
+      context = gtk_widget_get_style_context (priv->camera_w);
+      gtk_style_context_add_class (context, "dim-label");
+      gtk_container_add (GTK_CONTAINER (grid), priv->camera_w);
+    }
+
   name = photos_base_item_get_name (item);
 
   if (PHOTOS_IS_LOCAL_ITEM (item))
@@ -310,7 +367,14 @@ photos_properties_dialog_dispose (GObject *object)
   PhotosPropertiesDialog *self = PHOTOS_PROPERTIES_DIALOG (object);
   PhotosPropertiesDialogPrivate *priv = self->priv;
 
+  if (priv->cancellable != NULL)
+    {
+      g_cancellable_cancel (priv->cancellable);
+      g_clear_object (&priv->cancellable);
+    }
+
   g_clear_object (&priv->item_mngr);
+  g_clear_object (&priv->camera_cache);
 
   G_OBJECT_CLASS (photos_properties_dialog_parent_class)->dispose (object);
 }
@@ -357,7 +421,10 @@ photos_properties_dialog_init (PhotosPropertiesDialog *self)
   self->priv = photos_properties_dialog_get_instance_private (self);
   priv = self->priv;
 
+  priv->cancellable = g_cancellable_new ();
   priv->item_mngr = photos_item_manager_new ();
+  priv->camera_cache = photos_camera_cache_new ();
+
   gtk_dialog_add_button (GTK_DIALOG (self), _("Done"), GTK_RESPONSE_OK);
   gtk_dialog_set_default_response (GTK_DIALOG (self), GTK_RESPONSE_OK);
 }


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