[Pkg-ROX-devel] Bug#273072: rox-filer: 2.1 icon theme support backport
Filip Van Raemdonck
Filip Van Raemdonck <mechanix@debian.org>, 273072@bugs.debian.org
Thu, 23 Sep 2004 20:07:04 +0200
--4Ckj6UjgE2iN1+kY
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Package: rox-filer
Tags: patch
Hi,
Attached is a patch I have sitting around for the 2.1 icon theme support,
backported to 2.0.1. The bits about options are left out for now. (which
means the theme _must_ be symlinked to, or installed in $icon_dir/ROX)
Just as in 2.1, this keeps the 2.0 icon support as default and only uses
icon themes if the old way cannot provide an icon.
Regards,
Filip
-- System Information:
Debian Release: 3.1
APT prefers unstable
APT policy: (500, 'unstable'), (500, 'testing')
Architecture: i386 (i686)
Kernel: Linux 2.4.27
Locale: LANG=C, LC_CTYPE=nl_BE@euro
--
"Beer is God's way of telling us that he loves us and wants us to be happy."
-- Benjamin Franklin
--4Ckj6UjgE2iN1+kY
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="005-fdicons.patch"
--- ROX-Filer/src/type.c.orig
+++ ROX-Filer/src/type.c
@@ -40,6 +40,8 @@
# include <libgnomevfs/gnome-vfs-application-registry.h>
#endif
+#include <gtk/gtkicontheme.h>
+
#include "global.h"
#include "string.h"
@@ -89,6 +91,7 @@
static char *get_action_save_path(GtkWidget *dialog);
static MIME_type *get_mime_type(const gchar *type_name, gboolean can_create);
static gboolean remove_handler_with_confirm(const guchar *path);
+static void set_icon_theme(void);
/* When working out the type for a file, this hash table is checked
* first...
@@ -129,9 +132,13 @@
static Option o_display_colour_types;
+static GtkIconTheme *icon_theme = NULL;
+
void type_init(void)
{
int i;
+
+ icon_theme = gtk_icon_theme_new();
extension_hash = g_hash_table_new(g_str_hash, g_str_equal);
type_hash = g_hash_table_new(g_str_hash, g_str_equal);
@@ -156,6 +163,8 @@
opt_type_colours[i][1]);
alloc_type_colours();
+ set_icon_theme();
+
option_add_notify(alloc_type_colours);
}
@@ -164,6 +173,7 @@
*/
void reread_mime_files(void)
{
+ gtk_icon_theme_rescan_if_needed(icon_theme);
load_mime_types();
}
@@ -411,8 +421,8 @@
*/
MaskedPixmap *type_to_icon(MIME_type *type)
{
- char *path;
- char *type_name;
+ GdkPixbuf *full;
+ char *type_name, *path;
time_t now;
if (type == NULL)
@@ -435,8 +445,8 @@
type->image = NULL;
}
- type_name = g_strconcat(type->media_type, "_",
- type->subtype, ".png", NULL);
+ type_name = g_strconcat(type->media_type, "_", type->subtype,
+ ".png", NULL);
path = choices_find_path_load(type_name, "MIME-icons");
if (!path)
{
@@ -452,6 +462,39 @@
g_free(path);
}
+ if (type->image)
+ goto out;
+
+ type_name = g_strconcat("mime-", type->media_type, ":",
+ type->subtype, NULL);
+ full = gtk_icon_theme_load_icon(icon_theme, type_name, HUGE_HEIGHT,
+ 0, NULL);
+ g_free(type_name);
+ if (!full)
+ {
+ /* Ugly hack... try for a GNOME icon */
+ type_name = g_strconcat("gnome-mime-", type->media_type,
+ "-", type->subtype, NULL);
+ full = gtk_icon_theme_load_icon(icon_theme,
+ type_name,
+ HUGE_HEIGHT, 0, NULL);
+ g_free(type_name);
+ }
+ if (!full)
+ {
+ /* Try for a media type */
+ type_name = g_strconcat("mime-", type->media_type, NULL);
+ full = gtk_icon_theme_load_icon(icon_theme,
+ type_name,
+ HUGE_HEIGHT, 0, NULL);
+ g_free(type_name);
+ }
+ if (full)
+ {
+ type->image = masked_pixmap_new(full);
+ g_object_unref(full);
+ }
+
if (!type->image)
{
/* One ref from the type structure, one returned */
@@ -459,6 +502,7 @@
g_object_ref(im_unknown);
}
+out:
type->image_time = now;
g_object_ref(type->image);
@@ -1367,3 +1411,57 @@
return type->comment;
}
+
+static void set_icon_theme(void)
+{
+ GtkIconInfo *info;
+ char *icon_home;
+ const char *theme_name = NULL; /*o_icon_theme.value;*/
+
+ if (!theme_name || !*theme_name)
+ theme_name = "ROX";
+
+ while (1)
+ {
+ gtk_icon_theme_set_custom_theme(icon_theme, theme_name);
+ info = gtk_icon_theme_lookup_icon(icon_theme,
+ "mime-application:postscript",
+ ICON_HEIGHT, 0);
+ if (!info)
+ {
+ info = gtk_icon_theme_lookup_icon(icon_theme,
+ "gnome-mime-application-postscript",
+ ICON_HEIGHT, 0);
+ }
+ if (info)
+ {
+ gtk_icon_info_free(info);
+ return;
+ }
+
+ if (strcmp(theme_name, "ROX") == 0)
+ break;
+
+ delayed_error(_("Icon theme '%s' does not contain MIME icons. "
+ "Using ROX default theme instead."),
+ theme_name);
+
+ theme_name = "ROX";
+ }
+
+ icon_home = g_build_filename(home_dir, ".icons", NULL);
+ if (!file_exists(icon_home))
+ mkdir(icon_home, 0755);
+ g_free(icon_home);
+
+ icon_home = g_build_filename(home_dir, ".icons", "ROX", NULL);
+ if (symlink(make_path(app_dir, "ROX"), icon_home))
+ delayed_error(_("Failed to create symlink '%s':\n%s\n\n"
+ "(this may mean that the ROX theme already exists there, but "
+ "the 'mime-application:postscript' icon couldn't be loaded for "
+ "some reason)"), icon_home, g_strerror(errno));
+ g_free(icon_home);
+
+ gtk_icon_theme_rescan_if_needed(icon_theme);
+}
+
--4Ckj6UjgE2iN1+kY--