use thumbnail factory to store and retrieve metatheme thumbs (bug #448968)
2007-08-03 Jens Granseuer <jensgr@gmx.net> * appearance-desktop.c: (wp_props_load_wallpaper), (wp_add_image), (wp_scale_type_changed), (wp_shade_type_changed), (wp_update_preview), (wp_load_stuffs), (desktop_init), (desktop_shutdown): * appearance-main.c: (init_appearance_data), (main_window_response): * appearance-themes.c: (theme_get_mtime), (theme_thumbnail_update), (theme_get_thumbnail_from_cache), (theme_thumbnail_done_cb), (theme_thumbnail_generate): * appearance.h: * gnome-wp-xml.c: (gnome_wp_load_legacy), (gnome_wp_xml_load_xml): use thumbnail factory to store and retrieve metatheme thumbs (bug #448968) svn path=/trunk/; revision=7955
This commit is contained in:
parent
aa9ddd3739
commit
b7ad0952dc
6 changed files with 130 additions and 26 deletions
|
@ -1,3 +1,19 @@
|
|||
2007-08-03 Jens Granseuer <jensgr@gmx.net>
|
||||
|
||||
* appearance-desktop.c: (wp_props_load_wallpaper), (wp_add_image),
|
||||
(wp_scale_type_changed), (wp_shade_type_changed),
|
||||
(wp_update_preview), (wp_load_stuffs), (desktop_init),
|
||||
(desktop_shutdown):
|
||||
* appearance-main.c: (init_appearance_data),
|
||||
(main_window_response):
|
||||
* appearance-themes.c: (theme_get_mtime), (theme_thumbnail_update),
|
||||
(theme_get_thumbnail_from_cache), (theme_thumbnail_done_cb),
|
||||
(theme_thumbnail_generate):
|
||||
* appearance.h:
|
||||
* gnome-wp-xml.c: (gnome_wp_load_legacy), (gnome_wp_xml_load_xml):
|
||||
use thumbnail factory to store and retrieve metatheme thumbs
|
||||
(bug #448968)
|
||||
|
||||
2007-08-03 Jens Granseuer <jensgr@gmx.net>
|
||||
|
||||
* data/appearance.glade:
|
||||
|
|
|
@ -127,7 +127,7 @@ wp_props_load_wallpaper (gchar *key,
|
|||
|
||||
gtk_list_store_append (GTK_LIST_STORE (data->wp_model), &iter);
|
||||
|
||||
pixbuf = gnome_wp_item_get_thumbnail (item, data->wp_thumbs);
|
||||
pixbuf = gnome_wp_item_get_thumbnail (item, data->thumb_factory);
|
||||
gnome_wp_item_update_description (item);
|
||||
|
||||
gtk_list_store_set (GTK_LIST_STORE (data->wp_model), &iter,
|
||||
|
@ -162,7 +162,7 @@ wp_add_image (AppearanceData *data,
|
|||
}
|
||||
else
|
||||
{
|
||||
item = gnome_wp_item_new (filename, data->wp_hash, data->wp_thumbs);
|
||||
item = gnome_wp_item_new (filename, data->wp_hash, data->thumb_factory);
|
||||
|
||||
if (item != NULL)
|
||||
{
|
||||
|
@ -337,7 +337,7 @@ wp_scale_type_changed (GtkComboBox *combobox,
|
|||
break;
|
||||
}
|
||||
|
||||
pixbuf = gnome_wp_item_get_thumbnail (item, data->wp_thumbs);
|
||||
pixbuf = gnome_wp_item_get_thumbnail (item, data->thumb_factory);
|
||||
gtk_list_store_set (GTK_LIST_STORE (data->wp_model),
|
||||
&iter,
|
||||
0, pixbuf,
|
||||
|
@ -380,7 +380,7 @@ wp_shade_type_changed (GtkWidget *combobox,
|
|||
break;
|
||||
}
|
||||
|
||||
pixbuf = gnome_wp_item_get_thumbnail (item, data->wp_thumbs);
|
||||
pixbuf = gnome_wp_item_get_thumbnail (item, data->thumb_factory);
|
||||
gtk_list_store_set (GTK_LIST_STORE (data->wp_model), &iter,
|
||||
0, pixbuf,
|
||||
-1);
|
||||
|
@ -796,7 +796,7 @@ wp_update_preview (GtkFileChooser *chooser,
|
|||
|
||||
if (mime_type)
|
||||
{
|
||||
pixbuf = gnome_thumbnail_factory_generate_thumbnail (data->wp_thumbs,
|
||||
pixbuf = gnome_thumbnail_factory_generate_thumbnail (data->thumb_factory,
|
||||
uri,
|
||||
mime_type);
|
||||
g_free (mime_type);
|
||||
|
@ -880,7 +880,7 @@ wp_load_stuffs (void *user_data)
|
|||
item = g_hash_table_lookup (data->wp_hash, "(none)");
|
||||
if (item == NULL)
|
||||
{
|
||||
item = gnome_wp_item_new ("(none)", data->wp_hash, data->wp_thumbs);
|
||||
item = gnome_wp_item_new ("(none)", data->wp_hash, data->thumb_factory);
|
||||
if (item != NULL)
|
||||
{
|
||||
wp_props_load_wallpaper (item->filename, item, data);
|
||||
|
@ -941,8 +941,6 @@ desktop_init (AppearanceData *data,
|
|||
|
||||
data->wp_hash = g_hash_table_new (g_str_hash, g_str_equal);
|
||||
|
||||
data->wp_thumbs = gnome_thumbnail_factory_new (GNOME_THUMBNAIL_SIZE_NORMAL);
|
||||
|
||||
gconf_client_add_dir (data->client, WP_KEYBOARD_PATH,
|
||||
GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
|
||||
gconf_client_add_dir (data->client, WP_PATH_KEY,
|
||||
|
@ -1088,7 +1086,6 @@ desktop_shutdown (AppearanceData *data)
|
|||
gnome_wp_xml_save_list (data);
|
||||
g_slist_foreach (data->wp_uris, (GFunc) g_free, NULL);
|
||||
g_slist_free (data->wp_uris);
|
||||
g_object_unref (data->wp_thumbs);
|
||||
g_object_ref_sink (data->wp_filesel);
|
||||
g_object_unref (data->wp_filesel);
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include <libgnome/libgnome.h>
|
||||
#include <libgnomeui/gnome-ui-init.h>
|
||||
/* ---------------------------------- */
|
||||
#include <libgnomeui/gnome-thumbnail.h>
|
||||
|
||||
static AppearanceData *
|
||||
init_appearance_data (int *argc, char ***argv)
|
||||
|
@ -60,6 +61,7 @@ init_appearance_data (int *argc, char ***argv)
|
|||
data = g_new (AppearanceData, 1);
|
||||
data->client = gconf_client_get_default ();
|
||||
data->xml = ui;
|
||||
data->thumb_factory = gnome_thumbnail_factory_new (GNOME_THUMBNAIL_SIZE_NORMAL);
|
||||
}
|
||||
|
||||
return data;
|
||||
|
@ -80,6 +82,7 @@ main_window_response (GtkWidget *widget,
|
|||
desktop_shutdown (data);
|
||||
font_shutdown (data);
|
||||
|
||||
g_object_unref (data->thumb_factory);
|
||||
g_object_unref (data->client);
|
||||
g_object_unref (data->xml);
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include <libwindow-settings/gnome-wm-manager.h>
|
||||
#include <string.h>
|
||||
#include <libgnomevfs/gnome-vfs.h>
|
||||
#include <libgnomeui/gnome-thumbnail.h>
|
||||
|
||||
#define CUSTOM_THEME_NAME "__custom__"
|
||||
|
||||
|
@ -54,26 +55,113 @@ static const GtkTargetEntry drop_types[] =
|
|||
{"_NETSCAPE_URL", 0, TARGET_NS_URL}
|
||||
};
|
||||
|
||||
static time_t
|
||||
theme_get_mtime (const char *name)
|
||||
{
|
||||
GnomeThemeMetaInfo *theme;
|
||||
time_t mtime = -1;
|
||||
|
||||
theme = gnome_theme_meta_info_find (name);
|
||||
if (theme != NULL) {
|
||||
GnomeVFSFileInfo *file_info;
|
||||
GnomeVFSResult result;
|
||||
|
||||
file_info = gnome_vfs_file_info_new ();
|
||||
|
||||
result = gnome_vfs_get_file_info (theme->path, file_info,
|
||||
GNOME_VFS_FILE_INFO_DEFAULT |
|
||||
GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
|
||||
|
||||
if (result == GNOME_VFS_OK)
|
||||
mtime = file_info->mtime;
|
||||
|
||||
gnome_vfs_file_info_unref (file_info);
|
||||
}
|
||||
|
||||
return mtime;
|
||||
}
|
||||
|
||||
static void
|
||||
theme_thumbnail_update (GdkPixbuf *pixbuf,
|
||||
gchar *theme_name,
|
||||
AppearanceData *data,
|
||||
gboolean cache)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
GtkTreeModel *model = GTK_TREE_MODEL (data->theme_store);
|
||||
|
||||
/* find item in model and update thumbnail */
|
||||
if (!pixbuf)
|
||||
return;
|
||||
|
||||
if (theme_find_in_model (model, theme_name, &iter)) {
|
||||
time_t mtime;
|
||||
|
||||
gtk_list_store_set (data->theme_store, &iter, COL_THUMBNAIL, pixbuf, -1);
|
||||
|
||||
#if 1
|
||||
/* cache thumbnail */
|
||||
if (cache && (mtime = theme_get_mtime (theme_name)) != -1) {
|
||||
gchar *path;
|
||||
|
||||
/* try to share thumbs with nautilus, use themes:/// */
|
||||
path = g_strconcat ("themes:///", theme_name, NULL);
|
||||
|
||||
gnome_thumbnail_factory_save_thumbnail (data->thumb_factory,
|
||||
pixbuf, path, mtime);
|
||||
|
||||
g_free (path);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
g_object_unref (pixbuf);
|
||||
}
|
||||
|
||||
static GdkPixbuf *
|
||||
theme_get_thumbnail_from_cache (GnomeThemeMetaInfo *info, AppearanceData *data)
|
||||
{
|
||||
GdkPixbuf *thumb = NULL;
|
||||
gchar *path, *thumb_filename;
|
||||
time_t mtime;
|
||||
|
||||
if (info == data->theme_custom)
|
||||
return NULL;
|
||||
|
||||
mtime = theme_get_mtime (info->name);
|
||||
if (mtime == -1)
|
||||
return NULL;
|
||||
|
||||
/* try to share thumbs with nautilus, use themes:/// */
|
||||
path = g_strconcat ("themes:///", info->name, NULL);
|
||||
thumb_filename = gnome_thumbnail_factory_lookup (data->thumb_factory,
|
||||
path, mtime);
|
||||
g_free (path);
|
||||
|
||||
if (thumb_filename != NULL)
|
||||
thumb = gdk_pixbuf_new_from_file (thumb_filename, NULL);
|
||||
|
||||
return thumb;
|
||||
}
|
||||
|
||||
static void
|
||||
theme_thumbnail_done_cb (GdkPixbuf *pixbuf, gchar *theme_name, AppearanceData *data)
|
||||
{
|
||||
/* find item in model and update thumbnail */
|
||||
if (pixbuf) {
|
||||
GtkTreeIter iter;
|
||||
GtkTreeModel *model = GTK_TREE_MODEL (data->theme_store);
|
||||
|
||||
if (theme_find_in_model (model, theme_name, &iter))
|
||||
gtk_list_store_set (data->theme_store, &iter, COL_THUMBNAIL, pixbuf, -1);
|
||||
|
||||
g_object_unref (pixbuf);
|
||||
}
|
||||
theme_thumbnail_update (pixbuf, theme_name, data, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
theme_thumbnail_generate (GnomeThemeMetaInfo *info, AppearanceData *data)
|
||||
{
|
||||
generate_meta_theme_thumbnail_async (info,
|
||||
(ThemeThumbnailFunc) theme_thumbnail_done_cb, data, NULL);
|
||||
GdkPixbuf *thumb;
|
||||
|
||||
thumb = theme_get_thumbnail_from_cache (info, data);
|
||||
|
||||
if (thumb != NULL)
|
||||
theme_thumbnail_update (thumb, info->name, data, FALSE);
|
||||
else
|
||||
generate_meta_theme_thumbnail_async (info,
|
||||
(ThemeThumbnailFunc) theme_thumbnail_done_cb, data, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -32,10 +32,10 @@
|
|||
typedef struct {
|
||||
GConfClient *client;
|
||||
GladeXML *xml;
|
||||
GnomeThumbnailFactory *thumb_factory;
|
||||
|
||||
/* desktop */
|
||||
GHashTable *wp_hash;
|
||||
GnomeThumbnailFactory *wp_thumbs;
|
||||
gboolean wp_update_gconf;
|
||||
GtkIconView *wp_view;
|
||||
GtkTreeModel *wp_model;
|
||||
|
|
|
@ -73,7 +73,7 @@ static void gnome_wp_load_legacy (AppearanceData *data) {
|
|||
if (foo[strlen (foo) - 1] == '\n') {
|
||||
foo[strlen (foo) - 1] = '\0';
|
||||
}
|
||||
|
||||
|
||||
item = g_hash_table_lookup (data->wp_hash, foo);
|
||||
if (item != NULL) {
|
||||
continue;
|
||||
|
@ -83,7 +83,7 @@ static void gnome_wp_load_legacy (AppearanceData *data) {
|
|||
continue;
|
||||
}
|
||||
|
||||
item = gnome_wp_item_new (foo, data->wp_hash, data->wp_thumbs);
|
||||
item = gnome_wp_item_new (foo, data->wp_hash, data->thumb_factory);
|
||||
if (item != NULL && item->fileinfo == NULL) {
|
||||
gnome_wp_item_free (item);
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ static void gnome_wp_load_legacy (AppearanceData *data) {
|
|||
g_free (foo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
g_free (filename);
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,7 @@ static void gnome_wp_xml_load_xml (AppearanceData *data,
|
|||
if ((wp->filename != NULL &&
|
||||
g_file_test (wp->filename, G_FILE_TEST_EXISTS)) ||
|
||||
!strcmp (wp->filename, "(none)")) {
|
||||
wp->fileinfo = gnome_wp_info_new (wp->filename, data->wp_thumbs);
|
||||
wp->fileinfo = gnome_wp_info_new (wp->filename, data->thumb_factory);
|
||||
|
||||
if (wp->name == NULL || !strcmp (wp->filename, "(none)")) {
|
||||
g_free (wp->name);
|
||||
|
|
Loading…
Add table
Reference in a new issue