[gnome-photos] Use a fallback name in the header bar when there is no nie:title



commit d1c3dba9e8a185af3df528be46cb21241ee54f31
Author: Debarshi Ray <debarshir gnome org>
Date:   Fri Nov 28 18:27:37 2014 +0100

    Use a fallback name in the header bar when there is no nie:title
    
    Add a pure virtual method to PhotosBaseItem so that different
    implementations can offer their own fallbacks. For local content we
    use the filename without the extension; for remote content we use
    something like "Facebook — 2nd January 2013", where the second part is
    the mtime.
    
    This is not implemented, yet, for media server items.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=733214

 po/POTFILES.in                 |    3 +++
 src/photos-base-item.c         |   28 ++++++++++++++++++++++++++++
 src/photos-base-item.h         |    5 +++++
 src/photos-facebook-item.c     |   29 +++++++++++++++++++++++++++++
 src/photos-flickr-item.c       |   29 +++++++++++++++++++++++++++++
 src/photos-google-item.c       |   30 ++++++++++++++++++++++++++++++
 src/photos-local-item.c        |   13 +++++++++++++
 src/photos-main-toolbar.c      |    2 +-
 src/photos-media-server-item.c |   10 ++++++++++
 9 files changed, 148 insertions(+), 1 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 562864b..d739667 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -15,7 +15,10 @@ src/photos-delete-notification.c
 [type: gettext/glade]src/photos-dlna-renderers-dialog.ui
 src/photos-embed.c
 src/photos-empty-results-box.c
+src/photos-facebook-item.c
 src/photos-fetch-metas-job.c
+src/photos-flickr-item.c
+src/photos-google-item.c
 src/photos-indexing-notification.c
 src/photos-load-more-button.c
 src/photos-local-item.c
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 56c95fe..78d777d 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -70,10 +70,12 @@ struct _PhotosBaseItemPrivate
   const gchar *thumb_path;
   gchar *author;
   gchar *default_app_name;
+  gchar *filename;
   gchar *id;
   gchar *identifier;
   gchar *mime_type;
   gchar *name;
+  gchar *name_fallback;
   gchar *rdf_type;
   gchar *resource_urn;
   gchar *type_description;
@@ -865,6 +867,8 @@ photos_base_item_populate_from_cursor (PhotosBaseItem *self, TrackerSparqlCursor
     title = "";
   priv->name = g_strdup (title);
 
+  priv->filename = g_strdup (tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_FILENAME, NULL));
+
   priv->width = tracker_sparql_cursor_get_integer (cursor, PHOTOS_QUERY_COLUMNS_WIDTH);
   priv->height = tracker_sparql_cursor_get_integer (cursor, PHOTOS_QUERY_COLUMNS_HEIGHT);
 
@@ -879,6 +883,7 @@ photos_base_item_populate_from_cursor (PhotosBaseItem *self, TrackerSparqlCursor
   flash = tracker_sparql_cursor_get_string (cursor, PHOTOS_QUERY_COLUMNS_FLASH, NULL);
   priv->flash = g_quark_from_string (flash);
 
+  priv->name_fallback = PHOTOS_BASE_ITEM_GET_CLASS (self)->create_name_fallback (self);
   photos_base_item_refresh_icon (self);
 }
 
@@ -961,10 +966,12 @@ photos_base_item_finalize (GObject *object)
 
   g_free (priv->author);
   g_free (priv->default_app_name);
+  g_free (priv->filename);
   g_free (priv->id);
   g_free (priv->identifier);
   g_free (priv->mime_type);
   g_free (priv->name);
+  g_free (priv->name_fallback);
   g_free (priv->rdf_type);
   g_free (priv->resource_urn);
   g_free (priv->type_description);
@@ -1199,6 +1206,13 @@ photos_base_item_get_flash (PhotosBaseItem *self)
 }
 
 
+const gchar *
+photos_base_item_get_filename (PhotosBaseItem *self)
+{
+  return self->priv->filename;
+}
+
+
 gdouble
 photos_base_item_get_fnumber (PhotosBaseItem *self)
 {
@@ -1255,6 +1269,20 @@ photos_base_item_get_name (PhotosBaseItem *self)
 }
 
 
+const gchar *
+photos_base_item_get_name_with_fallback (PhotosBaseItem *self)
+{
+  PhotosBaseItemPrivate *priv = self->priv;
+  const gchar *name;
+
+  name = priv->name;
+  if (name == NULL || name[0] == '\0')
+    name = priv->name_fallback;
+
+  return name;
+}
+
+
 GdkPixbuf *
 photos_base_item_get_original_icon (PhotosBaseItem *self)
 {
diff --git a/src/photos-base-item.h b/src/photos-base-item.h
index 652ae16..1443ab3 100644
--- a/src/photos-base-item.h
+++ b/src/photos-base-item.h
@@ -73,6 +73,7 @@ struct _PhotosBaseItemClass
   const gchar *miner_object_path;
 
   /* virtual methods */
+  gchar *(*create_name_fallback) (PhotosBaseItem *self);
   gboolean (*create_thumbnail) (PhotosBaseItem *self, GCancellable *cancellable, GError **error);
   gchar *(*download) (PhotosBaseItem *self, GCancellable *cancellable, GError **error);
   GtkWidget *(*get_source_widget) (PhotosBaseItem *self);
@@ -116,6 +117,8 @@ gdouble             photos_base_item_get_exposure_time  (PhotosBaseItem *self);
 
 GQuark              photos_base_item_get_flash          (PhotosBaseItem *self);
 
+const gchar        *photos_base_item_get_filename       (PhotosBaseItem *self);
+
 gdouble             photos_base_item_get_fnumber        (PhotosBaseItem *self);
 
 gdouble             photos_base_item_get_focal_length   (PhotosBaseItem *self);
@@ -132,6 +135,8 @@ gint64              photos_base_item_get_mtime          (PhotosBaseItem *self);
 
 const gchar        *photos_base_item_get_name           (PhotosBaseItem *self);
 
+const gchar        *photos_base_item_get_name_with_fallback (PhotosBaseItem *self);
+
 GdkPixbuf          *photos_base_item_get_original_icon  (PhotosBaseItem *self);
 
 const gchar        *photos_base_item_get_resource_urn   (PhotosBaseItem *self);
diff --git a/src/photos-facebook-item.c b/src/photos-facebook-item.c
index 3a06595..d25443b 100644
--- a/src/photos-facebook-item.c
+++ b/src/photos-facebook-item.c
@@ -30,6 +30,7 @@
 #include <gfbgraph/gfbgraph-goa-authorizer.h>
 #include <gio/gio.h>
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <goa/goa.h>
 #include <libgnome-desktop/gnome-desktop-thumbnail.h>
 
@@ -55,6 +56,33 @@ G_DEFINE_TYPE_WITH_CODE (PhotosFacebookItem, photos_facebook_item, PHOTOS_TYPE_B
                                                          0));
 
 
+static gchar *
+photos_facebook_item_create_name_fallback (PhotosBaseItem *item)
+{
+  PhotosFacebookItem *self = PHOTOS_FACEBOOK_ITEM (item);
+  GDateTime *date_modified;
+  const gchar *provider_name;
+  gchar *ret_val;
+  gchar *date_modified_str;
+  gint64 mtime;
+
+  provider_name = photos_utils_get_provider_name (self->priv->src_mngr, item);
+
+  mtime = photos_base_item_get_mtime (item);
+  date_modified = g_date_time_new_from_unix_local (mtime);
+  date_modified_str = g_date_time_format (date_modified, "%x");
+
+  /* Translators: this is the fallback title in the form
+   *  "Facebook — 2nd January 2013".
+   */
+  ret_val = g_strdup_printf ("%s — %s", provider_name, date_modified_str);
+
+  g_free (date_modified_str);
+  g_date_time_unref (date_modified);
+  return ret_val;
+}
+
+
 static GFBGraphPhoto *
 photos_facebook_get_gfbgraph_photo (PhotosBaseItem *item, GCancellable *cancellable, GError **error)
 {
@@ -276,6 +304,7 @@ photos_facebook_item_class_init (PhotosFacebookItemClass *class)
 
   object_class->constructed = photos_facebook_item_constructed;
   object_class->dispose = photos_facebook_item_dispose;
+  base_item_class->create_name_fallback = photos_facebook_item_create_name_fallback;
   base_item_class->create_thumbnail = photos_facebook_item_create_thumbnail;
   base_item_class->download = photos_facebook_item_download;
   base_item_class->get_source_widget = photos_facebook_item_get_source_widget;
diff --git a/src/photos-flickr-item.c b/src/photos-flickr-item.c
index 0061938..ae8905d 100644
--- a/src/photos-flickr-item.c
+++ b/src/photos-flickr-item.c
@@ -29,6 +29,7 @@
 
 #include <gio/gio.h>
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <goa/goa.h>
 #include <grilo.h>
 #include <libgnome-desktop/gnome-desktop-thumbnail.h>
@@ -65,6 +66,33 @@ struct _PhotosFlickrItemSyncData
 };
 
 
+static gchar *
+photos_flickr_item_create_name_fallback (PhotosBaseItem *item)
+{
+  PhotosFlickrItem *self = PHOTOS_FLICKR_ITEM (item);
+  GDateTime *date_modified;
+  const gchar *provider_name;
+  gchar *ret_val;
+  gchar *date_modified_str;
+  gint64 mtime;
+
+  provider_name = photos_utils_get_provider_name (self->priv->src_mngr, item);
+
+  mtime = photos_base_item_get_mtime (item);
+  date_modified = g_date_time_new_from_unix_local (mtime);
+  date_modified_str = g_date_time_format (date_modified, "%x");
+
+  /* Translators: this is the fallback title in the form
+   *  "Facebook — 2nd January 2013".
+   */
+  ret_val = g_strdup_printf ("%s — %s", provider_name, date_modified_str);
+
+  g_free (date_modified_str);
+  g_date_time_unref (date_modified);
+  return ret_val;
+}
+
+
 static GrlOperationOptions *
 photos_flickr_item_get_grl_options (GrlSource *source)
 {
@@ -378,6 +406,7 @@ photos_flickr_item_class_init (PhotosFlickrItemClass *class)
 
   object_class->constructed = photos_flickr_item_constructed;
   object_class->dispose = photos_flickr_item_dispose;
+  base_item_class->create_name_fallback = photos_flickr_item_create_name_fallback;
   base_item_class->create_thumbnail = photos_flickr_item_create_thumbnail;
   base_item_class->download = photos_flickr_item_download;
   base_item_class->get_source_widget = photos_flickr_item_get_source_widget;
diff --git a/src/photos-google-item.c b/src/photos-google-item.c
index cc7a04f..86fab34 100644
--- a/src/photos-google-item.c
+++ b/src/photos-google-item.c
@@ -1,5 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2014 Red Hat, Inc.
  * Copyright © 2014 Saurav Agarwalla
  *
  * This program is free software; you can redistribute it and/or
@@ -28,6 +29,7 @@
 #include <gdata/gdata.h>
 #include <gio/gio.h>
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <libgnome-desktop/gnome-desktop-thumbnail.h>
 
 #include "photos-base-manager.h"
@@ -52,6 +54,33 @@ G_DEFINE_TYPE_WITH_CODE (PhotosGoogleItem, photos_google_item, PHOTOS_TYPE_BASE_
                                                          0));
 
 
+static gchar *
+photos_google_item_create_name_fallback (PhotosBaseItem *item)
+{
+  PhotosGoogleItem *self = PHOTOS_GOOGLE_ITEM (item);
+  GDateTime *date_modified;
+  const gchar *provider_name;
+  gchar *ret_val;
+  gchar *date_modified_str;
+  gint64 mtime;
+
+  provider_name = photos_utils_get_provider_name (self->priv->src_mngr, item);
+
+  mtime = photos_base_item_get_mtime (item);
+  date_modified = g_date_time_new_from_unix_local (mtime);
+  date_modified_str = g_date_time_format (date_modified, "%x");
+
+  /* Translators: this is the fallback title in the form
+   *  "Facebook — 2nd January 2013".
+   */
+  ret_val = g_strdup_printf ("%s — %s", provider_name, date_modified_str);
+
+  g_free (date_modified_str);
+  g_date_time_unref (date_modified);
+  return ret_val;
+}
+
+
 static GDataEntry *
 photos_google_get_picasaweb_file (PhotosBaseItem *item, GCancellable *cancellable, GError **error)
 {
@@ -307,6 +336,7 @@ photos_google_item_class_init (PhotosGoogleItemClass *class)
 
   object_class->constructed = photos_google_item_constructed;
   object_class->dispose = photos_google_item_dispose;
+  base_item_class->create_name_fallback = photos_google_item_create_name_fallback;
   base_item_class->create_thumbnail = photos_google_item_create_thumbnail;
   base_item_class->download = photos_google_item_download;
   base_item_class->get_source_widget = photos_google_item_get_source_widget;
diff --git a/src/photos-local-item.c b/src/photos-local-item.c
index 360ffe4..978a054 100644
--- a/src/photos-local-item.c
+++ b/src/photos-local-item.c
@@ -64,6 +64,18 @@ photos_local_item_delete (GObject *source_object, GAsyncResult *res, gpointer us
 }
 
 
+static gchar *
+photos_local_item_create_name_fallback (PhotosBaseItem *item)
+{
+  const gchar *filename;
+  gchar *ret_val;
+
+  filename = photos_base_item_get_filename (item);
+  ret_val = photos_utils_filename_strip_extension (filename);
+  return ret_val;
+}
+
+
 static gboolean
 photos_local_item_create_thumbnail (PhotosBaseItem *item, GCancellable *cancellable, GError **error)
 {
@@ -187,6 +199,7 @@ photos_local_item_class_init (PhotosLocalItemClass *class)
   PhotosBaseItemClass *base_item_class = PHOTOS_BASE_ITEM_CLASS (class);
 
   object_class->constructed = photos_local_item_constructed;
+  base_item_class->create_name_fallback = photos_local_item_create_name_fallback;
   base_item_class->create_thumbnail = photos_local_item_create_thumbnail;
   base_item_class->download = photos_local_item_download;
   base_item_class->get_source_widget = photos_local_item_get_source_widget;
diff --git a/src/photos-main-toolbar.c b/src/photos-main-toolbar.c
index 4180388..3d41c4c 100644
--- a/src/photos-main-toolbar.c
+++ b/src/photos-main-toolbar.c
@@ -131,7 +131,7 @@ photos_main_toolbar_set_toolbar_title (PhotosMainToolbar *self)
 
       item = photos_base_manager_get_active_object (priv->item_mngr);
       if (item != NULL)
-        primary = g_markup_printf_escaped ("%s", photos_base_item_get_name (PHOTOS_BASE_ITEM (item)));
+        primary = g_markup_printf_escaped ("%s", photos_base_item_get_name_with_fallback (PHOTOS_BASE_ITEM 
(item)));
     }
 
   if (selection_mode)
diff --git a/src/photos-media-server-item.c b/src/photos-media-server-item.c
index d6afb93..b8fb61e 100644
--- a/src/photos-media-server-item.c
+++ b/src/photos-media-server-item.c
@@ -1,6 +1,7 @@
 /*
  * Photos - access, organize and share your photos on GNOME
  * Copyright © 2014 Pranav Kant
+ * Copyright © 2014 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
@@ -52,6 +53,14 @@ G_DEFINE_TYPE_WITH_CODE (PhotosMediaServerItem, photos_media_server_item, PHOTOS
                                                          0));
 
 
+static gchar *
+photos_media_server_item_create_name_fallback (PhotosBaseItem *item)
+{
+  /* TODO: provide a sane fallback */
+  return g_strdup ("");
+}
+
+
 static gboolean
 photos_media_server_item_create_thumbnail (PhotosBaseItem *item, GCancellable *cancellable, GError **error)
 {
@@ -187,6 +196,7 @@ photos_media_server_item_class_init (PhotosMediaServerItemClass *class)
 
   object_class->constructed = photos_media_server_item_constructed;
   object_class->dispose = photos_media_server_item_dispose;
+  base_item_class->create_name_fallback = photos_media_server_item_create_name_fallback;
   base_item_class->create_thumbnail = photos_media_server_item_create_thumbnail;
   base_item_class->download = photos_media_server_item_download;
   base_item_class->get_source_widget = photos_media_server_item_get_source_widget;


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