[gtk+] icon theme: Add a way to create GtkIconInfos from files
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] icon theme: Add a way to create GtkIconInfos from files
- Date: Thu, 14 Jan 2016 19:02:34 +0000 (UTC)
commit 7d717c8113dc25690088f1e81449e32e8f337a06
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Jan 14 12:53:50 2016 -0500
icon theme: Add a way to create GtkIconInfos from files
This is sometimes needed, and calling into actual icon theme
code just for it is confusing - the resulting icon does not
depend on the icon theme at all.
https://bugzilla.gnome.org/show_bug.cgi?id=760536
gtk/gtkicontheme.c | 71 ++++++++++++++++++++++++++++-----------------
gtk/gtkiconthemeprivate.h | 5 +++
2 files changed, 49 insertions(+), 27 deletions(-)
---
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index 00ae351..544f79e 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -37,7 +37,7 @@
#include "win32/gdkwin32.h"
#endif /* G_OS_WIN32 */
-#include "gtkicontheme.h"
+#include "gtkiconthemeprivate.h"
#include "gtkcsspalettevalueprivate.h"
#include "gtkcssrgbavalueprivate.h"
#include "gtkdebug.h"
@@ -5464,37 +5464,20 @@ gtk_icon_theme_lookup_by_gicon_for_scale (GtkIconTheme *icon_theme,
return info;
}
+ else if (G_IS_FILE_ICON (icon))
+ {
+ GFile *file = g_file_icon_get_file (G_FILE_ICON (icon));
+
+ info = gtk_icon_info_new_for_file (file, size, scale);
+ info->forced_size = (flags & GTK_ICON_LOOKUP_FORCE_SIZE) != 0;
+
+ return info;
+ }
else if (G_IS_LOADABLE_ICON (icon))
{
info = icon_info_new (ICON_THEME_DIR_UNTHEMED, size, 1);
info->loadable = G_LOADABLE_ICON (g_object_ref (icon));
info->is_svg = FALSE;
-
- if (G_IS_FILE_ICON (icon))
- {
- GFile *file = g_file_icon_get_file (G_FILE_ICON (icon));
- if (file != NULL)
- {
- info->icon_file = g_object_ref (file);
- info->is_resource = g_file_has_uri_scheme (file, "resource");
-
- if (info->is_resource)
- {
- gchar *uri;
-
- uri = g_file_get_uri (file);
- info->filename = g_strdup (uri + 11); /* resource:// */
- g_free (uri);
- }
- else
- {
- info->filename = g_file_get_path (file);
- }
-
- info->is_svg = suffix_from_name (info->filename) == ICON_SUFFIX_SVG;
- }
- }
-
info->desired_size = size;
info->desired_scale = scale;
info->forced_size = (flags & GTK_ICON_LOOKUP_FORCE_SIZE) != 0;
@@ -5573,3 +5556,37 @@ gtk_icon_info_new_for_pixbuf (GtkIconTheme *icon_theme,
return info;
}
+
+GtkIconInfo *
+gtk_icon_info_new_for_file (GFile *file,
+ gint size,
+ gint scale)
+{
+ GtkIconInfo *info;
+
+ info = icon_info_new (ICON_THEME_DIR_UNTHEMED, size, 1);
+ info->loadable = G_LOADABLE_ICON (g_file_icon_new (file));
+ info->icon_file = g_object_ref (file);
+ info->is_resource = g_file_has_uri_scheme (file, "resource");
+
+ if (info->is_resource)
+ {
+ gchar *uri;
+
+ uri = g_file_get_uri (file);
+ info->filename = g_strdup (uri + 11); /* resource:// */
+ g_free (uri);
+ }
+ else
+ {
+ info->filename = g_file_get_path (file);
+ }
+
+ info->is_svg = suffix_from_name (info->filename) == ICON_SUFFIX_SVG;
+
+ info->desired_size = size;
+ info->desired_scale = scale;
+ info->forced_size = FALSE;
+
+ return info;
+}
diff --git a/gtk/gtkiconthemeprivate.h b/gtk/gtkiconthemeprivate.h
index 77d9561..ca9d517 100644
--- a/gtk/gtkiconthemeprivate.h
+++ b/gtk/gtkiconthemeprivate.h
@@ -19,6 +19,7 @@
#define __GTK_ICON_THEME_PRIVATE_H__
#include <gtk/gtkicontheme.h>
+#include <gtk/gtkcssstyleprivate.h>
void gtk_icon_theme_lookup_symbolic_colors (GtkCssStyle *style,
GdkRGBA *color_out,
@@ -26,4 +27,8 @@ void gtk_icon_theme_lookup_symbolic_colors (GtkCssStyle *style,
GdkRGBA *warning_out,
GdkRGBA *error_out);
+GtkIconInfo *gtk_icon_info_new_for_file (GFile *file,
+ gint size,
+ gint scale);
+
#endif /* __GTK_ICON_THEME_PRIVATE_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]