[gnome-photos] properties-dialog: Do item specific tasks in respective subclasses



commit 0d5caaa9a7575950579dbb724a53284097dce52a
Author: Pranav Kant <pranav913 gmail com>
Date:   Mon Jun 23 20:55:15 2014 +0530

    properties-dialog: Do item specific tasks in respective subclasses
    
    https://bugzilla.gnome.org/show_bug.cgi?id=731865

 src/photos-base-item.c         |    6 ++--
 src/photos-base-item.h         |    4 +-
 src/photos-facebook-item.c     |   13 +++++++---
 src/photos-flickr-item.c       |   13 +++++++---
 src/photos-local-item.c        |   40 +++++++++++++++++++++++++++---
 src/photos-properties-dialog.c |   53 +---------------------------------------
 6 files changed, 60 insertions(+), 69 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index b636d12..5a900de 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -1214,10 +1214,10 @@ photos_base_item_get_resource_urn (PhotosBaseItem *self)
 }
 
 
-const gchar *
-photos_base_item_get_source_name (PhotosBaseItem *self)
+GtkWidget *
+photos_base_item_get_source_widget (PhotosBaseItem *self)
 {
-  return PHOTOS_BASE_ITEM_GET_CLASS (self)->get_source_name(self);
+  return PHOTOS_BASE_ITEM_GET_CLASS (self)->get_source_widget(self);
 }
 
 
diff --git a/src/photos-base-item.h b/src/photos-base-item.h
index 6e31b86..65d1d44 100644
--- a/src/photos-base-item.h
+++ b/src/photos-base-item.h
@@ -71,7 +71,7 @@ struct _PhotosBaseItemClass
   /* virtual methods */
   gboolean (*create_thumbnail) (PhotosBaseItem *self, GCancellable *cancellable, GError **error);
   gchar *(*download) (PhotosBaseItem *self, GCancellable *cancellable, GError **error);
-  const gchar *(*get_source_name) (PhotosBaseItem *self);
+  GtkWidget *(*get_source_widget) (PhotosBaseItem *self);
   void (*open) (PhotosBaseItem *self, GdkScreen *screen, guint32 timestamp);
   void (*set_favorite) (PhotosBaseItem *self, gboolean favorite);
   void (*update_type_description) (PhotosBaseItem *self);
@@ -131,7 +131,7 @@ GdkPixbuf          *photos_base_item_get_original_icon  (PhotosBaseItem *self);
 
 const gchar        *photos_base_item_get_resource_urn   (PhotosBaseItem *self);
 
-const gchar        *photos_base_item_get_source_name    (PhotosBaseItem *self);
+GtkWidget          *photos_base_item_get_source_widget  (PhotosBaseItem *self);
 
 cairo_surface_t    *photos_base_item_get_surface        (PhotosBaseItem *self);
 
diff --git a/src/photos-facebook-item.c b/src/photos-facebook-item.c
index b0ad9cb..937b9d1 100644
--- a/src/photos-facebook-item.c
+++ b/src/photos-facebook-item.c
@@ -191,10 +191,15 @@ photos_facebook_item_download (PhotosBaseItem *item, GCancellable *cancellable,
 }
 
 
-static const gchar *
-photos_facebook_item_get_source_name (PhotosBaseItem *item)
+static GtkWidget *
+photos_facebook_item_get_source_widget (PhotosBaseItem *item)
 {
-  return _("Facebook");
+  GtkWidget *source_widget;
+
+  source_widget = gtk_link_button_new_with_label ("https://www.facebook.com/";, _("Facebook"));
+  gtk_widget_set_halign (source_widget, GTK_ALIGN_START);
+
+  return source_widget;
 }
 
 
@@ -266,6 +271,6 @@ photos_facebook_item_class_init (PhotosFacebookItemClass *class)
   object_class->dispose = photos_facebook_item_dispose;
   base_item_class->create_thumbnail = photos_facebook_item_create_thumbnail;
   base_item_class->download = photos_facebook_item_download;
-  base_item_class->get_source_name = photos_facebook_item_get_source_name;
+  base_item_class->get_source_widget = photos_facebook_item_get_source_widget;
   base_item_class->open = photos_facebook_item_open;
 }
diff --git a/src/photos-flickr-item.c b/src/photos-flickr-item.c
index b2168ab..473fcd8 100644
--- a/src/photos-flickr-item.c
+++ b/src/photos-flickr-item.c
@@ -276,10 +276,15 @@ photos_flickr_item_download (PhotosBaseItem *item, GCancellable *cancellable, GE
 }
 
 
-static const gchar *
-photos_flickr_item_get_source_name (PhotosBaseItem *item)
+static GtkWidget *
+photos_flickr_item_get_source_widget (PhotosBaseItem *item)
 {
-  return _("Flickr");
+  GtkWidget *source_widget;
+
+  source_widget = gtk_link_button_new_with_label ("https://www.flickr.com/";, _("Flickr"));
+  gtk_widget_set_halign (source_widget, GTK_ALIGN_START);
+
+  return source_widget;
 }
 
 
@@ -368,6 +373,6 @@ photos_flickr_item_class_init (PhotosFlickrItemClass *class)
   object_class->dispose = photos_flickr_item_dispose;
   base_item_class->create_thumbnail = photos_flickr_item_create_thumbnail;
   base_item_class->download = photos_flickr_item_download;
-  base_item_class->get_source_name = photos_flickr_item_get_source_name;
+  base_item_class->get_source_widget = photos_flickr_item_get_source_widget;
   base_item_class->open = photos_flickr_item_open;
 }
diff --git a/src/photos-local-item.c b/src/photos-local-item.c
index 35d67e3..013c8b4 100644
--- a/src/photos-local-item.c
+++ b/src/photos-local-item.c
@@ -69,10 +69,42 @@ photos_local_item_download (PhotosBaseItem *item, GCancellable *cancellable, GEr
 }
 
 
-static const gchar *
-photos_local_item_get_source_name (PhotosBaseItem *item)
+static GtkWidget *
+photos_local_item_get_source_widget (PhotosBaseItem *item)
 {
-  return _("Local");
+  GtkWidget *source_widget;
+
+  if (photos_base_item_is_collection (item))
+    {
+      source_widget = gtk_label_new (_("Local"));
+      gtk_widget_set_halign (source_widget, GTK_ALIGN_START);
+    }
+  else
+    {
+      GFile *file;
+      GFile *source_link;
+      GtkWidget *label;
+      const gchar *uri;
+      gchar *source_path;
+      gchar *source_uri;
+
+      uri = photos_base_item_get_uri (item);
+      file = g_file_new_for_uri (uri);
+      source_link = g_file_get_parent (file);
+      source_path = g_file_get_path (source_link);
+      source_uri = g_file_get_uri (source_link);
+
+      source_widget = gtk_link_button_new_with_label (source_uri, source_path);
+      gtk_widget_set_halign (source_widget, GTK_ALIGN_START);
+
+      label = gtk_bin_get_child (GTK_BIN (source_widget));
+      gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
+
+      g_object_unref (source_link);
+      g_object_unref (file);
+    }
+
+  return source_widget;
 }
 
 
@@ -116,5 +148,5 @@ photos_local_item_class_init (PhotosLocalItemClass *class)
   object_class->constructed = photos_local_item_constructed;
   base_item_class->create_thumbnail = photos_local_item_create_thumbnail;
   base_item_class->download = photos_local_item_download;
-  base_item_class->get_source_name = photos_local_item_get_source_name;
+  base_item_class->get_source_widget = photos_local_item_get_source_widget;
 }
diff --git a/src/photos-properties-dialog.c b/src/photos-properties-dialog.c
index 60c7c13..6743d24 100644
--- a/src/photos-properties-dialog.c
+++ b/src/photos-properties-dialog.c
@@ -383,58 +383,7 @@ photos_properties_dialog_constructed (GObject *object)
       gtk_grid_attach_next_to (GTK_GRID (priv->grid), author_data, author_w, GTK_POS_RIGHT, 2, 1);
     }
 
-  if (PHOTOS_IS_FACEBOOK_ITEM (item))
-    {
-      const gchar *source_name;
-
-      source_name = photos_base_item_get_source_name (item);
-      source_data = gtk_link_button_new_with_label ("https://www.facebook.com/";, source_name);
-      gtk_widget_set_halign (source_data, GTK_ALIGN_START);
-    }
-  else if (PHOTOS_IS_FLICKR_ITEM (item))
-    {
-      const gchar *source_name;
-
-      source_name = photos_base_item_get_source_name (item);
-      source_data = gtk_link_button_new_with_label ("https://www.flickr.com/";, source_name);
-      gtk_widget_set_halign (source_data, GTK_ALIGN_START);
-    }
-  else /* local item */
-    {
-      if (photos_base_item_is_collection (item))
-        {
-          const gchar *source_name;
-
-          source_name = photos_base_item_get_source_name (item);
-          source_data = gtk_label_new (source_name);
-          gtk_widget_set_halign (source_data, GTK_ALIGN_START);
-        }
-      else
-        {
-          GFile *file;
-          GFile *source_link;
-          GtkWidget *label;
-          const gchar *uri;
-          gchar *source_path;
-          gchar *source_uri;
-
-          uri = photos_base_item_get_uri (item);
-          file = g_file_new_for_uri (uri);
-          source_link = g_file_get_parent (file);
-          source_path = g_file_get_path (source_link);
-          source_uri = g_file_get_uri (source_link);
-
-          source_data = gtk_link_button_new_with_label (source_uri, source_path);
-          gtk_widget_set_halign (source_data, GTK_ALIGN_START);
-
-          label = gtk_bin_get_child (GTK_BIN (source_data));
-          gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
-
-          g_object_unref (source_link);
-          g_object_unref (file);
-        }
-    }
-
+  source_data = photos_base_item_get_source_widget (item);
   gtk_grid_attach_next_to (GTK_GRID (priv->grid), source_data, source, GTK_POS_RIGHT, 2, 1);
 
   date_modified_data = gtk_label_new (date_modified_str);


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