[gnome-photos/wip/rishi/edit-preview: 3/9] base-item, utils: Move create_placeholder_icon
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/edit-preview: 3/9] base-item, utils: Move create_placeholder_icon
- Date: Tue, 24 Nov 2015 16:42:13 +0000 (UTC)
commit 65428d292f155575f01326934714cfda3e4c384f
Author: Debarshi Ray <debarshir gnome org>
Date: Tue Nov 24 03:17:33 2015 +0100
base-item, utils: Move create_placeholder_icon
... and adjust it to accept the unscaled size and scale separately. We
need it when creating previews in ToolFilters.
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 90b4333..eb9a05d 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 (¢ered_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 1d1b785..13d61f5 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -271,6 +271,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 (¢ered_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 99302bd..071159f 100644
--- a/src/photos-utils.h
+++ b/src/photos-utils.h
@@ -68,6 +68,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]