[gnome-photos/wip/rishi/edit-preview: 6/6] utils: photos_utils_create_placeholder_icon_for_scale



commit da0db101fac8e93f7a0250ff3821f870375f6b98
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue Nov 24 03:17:33 2015 +0100

    utils: photos_utils_create_placeholder_icon_for_scale

 src/photos-base-item.c |   47 +-------------------------------------
 src/photos-utils.c     |   57 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/photos-utils.h     |    2 +
 3 files changed, 61 insertions(+), 45 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index 6b175a1..54742b9 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -137,57 +137,14 @@ static GdkPixbuf *
 photos_base_item_create_placeholder_icon (const gchar *icon_name)
 {
   GApplication *app;
-  GdkPixbuf *centered_pixbuf = NULL;
-  GdkPixbuf *pixbuf = NULL;
   GdkPixbuf *ret_val = NULL;
-  GError *error;
-  GIcon *icon = NULL;
-  GList *windows;
-  GtkIconInfo *info = NULL;
-  GtkIconTheme *theme;
-  GtkStyleContext *context;
   gint icon_size;
   gint scale;
 
   app = g_application_get_default ();
-  windows = gtk_application_get_windows (GTK_APPLICATION (app));
-  if (windows == NULL)
-    goto out;
-
-  icon = g_themed_icon_new (icon_name);
+  icon_size = photos_utils_get_icon_size_unscaled ();
   scale = photos_application_get_scale_factor (PHOTOS_APPLICATION (app));
-  theme = gtk_icon_theme_get_default ();
-  info = gtk_icon_theme_lookup_by_gicon_for_scale (theme,
-                                                   icon,
-                                                   16,
-                                                   scale,
-                                                   GTK_ICON_LOOKUP_FORCE_SIZE | 
GTK_ICON_LOOKUP_FORCE_SYMBOLIC);
-  if (info == NULL)
-    goto out;
-
-  context = gtk_widget_get_style_context (GTK_WIDGET (windows->data));
-
-  error = NULL;
-  pixbuf = gtk_icon_info_load_symbolic_for_context (info, context, NULL, &error);
-  if (error != NULL)
-    {
-      g_warning ("Unable to load icon '%s': %s", icon_name, error->message);
-      g_error_free (error);
-      goto out;
-    }
-
-  icon_size = photos_utils_get_icon_size ();
-  centered_pixbuf = photos_utils_center_pixbuf (pixbuf, icon_size);
-  photos_utils_border_pixbuf (centered_pixbuf);
-
-  ret_val = centered_pixbuf;
-  centered_pixbuf = NULL;
-
- out:
-  g_clear_object (&centered_pixbuf);
-  g_clear_object (&pixbuf);
-  g_clear_object (&info);
-  g_clear_object (&icon);
+  ret_val = photos_utils_create_placeholder_icon_for_scale (icon_name, icon_size, scale);
   return ret_val;
 }
 
diff --git a/src/photos-utils.c b/src/photos-utils.c
index c875e99..f52ad03 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -273,6 +273,63 @@ photos_utils_create_orientation_node (GeglNode *parent, GQuark orientation)
 
 
 GdkPixbuf *
+photos_utils_create_placeholder_icon_for_scale (const gchar *name, gint size, gint scale)
+{
+  GApplication *app;
+  GdkPixbuf *centered_pixbuf = NULL;
+  GdkPixbuf *pixbuf = NULL;
+  GdkPixbuf *ret_val = NULL;
+  GError *error;
+  GIcon *icon = NULL;
+  GList *windows;
+  GtkIconInfo *info = NULL;
+  GtkIconTheme *theme;
+  GtkStyleContext *context;
+  gint size_scaled;
+
+  app = g_application_get_default ();
+  windows = gtk_application_get_windows (GTK_APPLICATION (app));
+  if (windows == NULL)
+    goto out;
+
+  icon = g_themed_icon_new (name);
+  theme = gtk_icon_theme_get_default ();
+  info = gtk_icon_theme_lookup_by_gicon_for_scale (theme,
+                                                   icon,
+                                                   16,
+                                                   scale,
+                                                   GTK_ICON_LOOKUP_FORCE_SIZE | 
GTK_ICON_LOOKUP_FORCE_SYMBOLIC);
+  if (info == NULL)
+    goto out;
+
+  context = gtk_widget_get_style_context (GTK_WIDGET (windows->data));
+
+  error = NULL;
+  pixbuf = gtk_icon_info_load_symbolic_for_context (info, context, NULL, &error);
+  if (error != NULL)
+    {
+      g_warning ("Unable to load icon '%s': %s", name, error->message);
+      g_error_free (error);
+      goto out;
+    }
+
+  size_scaled = size * scale;
+  centered_pixbuf = photos_utils_center_pixbuf (pixbuf, size_scaled);
+  photos_utils_border_pixbuf (centered_pixbuf);
+
+  ret_val = centered_pixbuf;
+  centered_pixbuf = NULL;
+
+ out:
+  g_clear_object (&centered_pixbuf);
+  g_clear_object (&pixbuf);
+  g_clear_object (&info);
+  g_clear_object (&icon);
+  return ret_val;
+}
+
+
+GdkPixbuf *
 photos_utils_create_pixbuf_from_node (GeglNode *node)
 {
   GdkPixbuf *pixbuf = NULL;
diff --git a/src/photos-utils.h b/src/photos-utils.h
index cbfc171..ced5d08 100644
--- a/src/photos-utils.h
+++ b/src/photos-utils.h
@@ -70,6 +70,8 @@ GeglNode        *photos_utils_create_orientation_node     (GeglNode *parent, GQu
 
 GdkPixbuf       *photos_utils_create_pixbuf_from_node     (GeglNode *node);
 
+GdkPixbuf       *photos_utils_create_placeholder_icon_for_scale (const gchar *name, gint size, gint scale);
+
 GIcon           *photos_utils_create_symbolic_icon_for_scale (const gchar *name, gint base_size, gint scale);
 
 gboolean         photos_utils_create_thumbnail            (GFile *file, GCancellable *cancellable, GError 
**error);


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