2010-10-17 [colin] 3.7.6cvs56
[claws.git] / src / prefs_themes.c
index cb99e27585a1d7d0dd0b907ac4b4afa9ca62df35..1f52f67d9b40b556985e125f9bf13744f47c94db 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2003-2007 Hiroyuki Yamamoto & the Claws Mail team
+ * Copyright (C) 2003-2009 Hiroyuki Yamamoto & the Claws Mail team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -73,8 +73,7 @@ typedef struct _ThemesPage
        GtkWidget *btn_use;
        GtkWidget *btn_remove;
 
-       GdkPixmap *pixmaps[PREVIEW_ICONS];
-       GdkBitmap *masks[PREVIEW_ICONS];
+       GdkPixbuf *pixbufs[PREVIEW_ICONS];
 
        /* gchar     *theme_path; */
 } ThemesPage;
@@ -163,7 +162,7 @@ static void prefs_themes_file_stats(const gchar *filename, gpointer data)
        DirInfo    *di = (DirInfo *)data;
        gint        len;
        
-       if (0 == stat(filename, &s) && 0 != S_ISREG(s.st_mode)) {
+       if (0 == g_stat(filename, &s) && 0 != S_ISREG(s.st_mode)) {
                di->bytes += s.st_size;
                di->files++;
                len = strlen(filename);
@@ -229,11 +228,11 @@ static void prefs_themes_foreach_file(const gchar *dirname, const FileFunc func,
        struct dirent *d;
        DIR           *dp;
 
-       g_return_if_fail(dirname != NULL);
-       g_return_if_fail(func != NULL);
+       cm_return_if_fail(dirname != NULL);
+       cm_return_if_fail(func != NULL);
        
        if ((dp = opendir(dirname)) == NULL) {
-               debug_print("directory %s not found", dirname);
+               debug_print("directory %s not found\n", dirname);
                return;
        }
 
@@ -254,14 +253,19 @@ static void prefs_themes_foreach_file(const gchar *dirname, const FileFunc func,
 static gboolean prefs_themes_is_system_theme(const gchar *dirname)
 {
        gint len;
-       
-       g_return_val_if_fail(dirname != NULL, FALSE);
+       gchar *system_theme_dir;
+       gboolean is_sys = FALSE;
+
+       cm_return_val_if_fail(dirname != NULL, FALSE);
 
-       len = strlen(PACKAGE_DATA_DIR);
-       if (strlen(dirname) > len && 0 == strncmp(dirname, PACKAGE_DATA_DIR, len))
-               return TRUE;
+       system_theme_dir = stock_pixmap_get_system_theme_dir_for_theme(NULL);
+       len = strlen(system_theme_dir);
+       if (strlen(dirname) > len && 0 == strncmp(dirname, system_theme_dir, len))
+               is_sys = TRUE;
        
-       return FALSE;
+       g_free(system_theme_dir);
+
+       return is_sys;
 }
 
 static void prefs_themes_set_themes_menu(GtkComboBox *combo, const ThemesData *tdata)
@@ -272,7 +276,7 @@ static void prefs_themes_set_themes_menu(GtkComboBox *combo, const ThemesData *t
        gint       i = 0, active = 0;
        GList     *sorted_list = NULL;
 
-       g_return_if_fail(combo != NULL);
+       cm_return_if_fail(combo != NULL);
 
        /* sort theme data list by data name */
        while (themes != NULL) {
@@ -325,7 +329,7 @@ static void prefs_themes_get_themes_and_names(ThemesData *tdata)
 {
        GList *tpaths;
        
-       g_return_if_fail(tdata != NULL);
+       cm_return_if_fail(tdata != NULL);
        
        if (tdata->themes != NULL)
                stock_pixmap_themes_list_free(tdata->themes);
@@ -527,9 +531,8 @@ static void prefs_themes_btn_install_clicked_cb(GtkWidget *widget, gpointer data
                                 GTK_STOCK_NO, GTK_STOCK_YES, NULL);
                switch (val) {
                case G_ALERTALTERNATE:
-                       cinfo->dest = g_strconcat(PACKAGE_DATA_DIR, G_DIR_SEPARATOR_S,
-                                                 PIXMAP_THEME_DIR, G_DIR_SEPARATOR_S, 
-                                                 themename, NULL);
+                       cinfo->dest = stock_pixmap_get_system_theme_dir_for_theme(
+                                               themename);
                        break;
                case G_ALERTDEFAULT:
                        break;
@@ -599,7 +602,7 @@ static void prefs_themes_menu_item_activated_cb(GtkWidget *widget, gpointer data
        GtkTreeModel *model;
        GtkTreeIter iter;
        
-       g_return_if_fail(gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &iter));
+       cm_return_if_fail(gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &iter));
        
        model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget));                 
        gtk_tree_model_get(model, &iter, 1, &path, -1); 
@@ -651,10 +654,10 @@ static void prefs_themes_display_theme_info(ThemesData *tdata, const ThemeInfo *
        save_prefs_path = prefs_common.pixmap_theme_path;
        prefs_common.pixmap_theme_path = tdata->displayed;
        for (i = 0; i < PREVIEW_ICONS; ++i) {
-               stock_pixmap_gdk(theme->window, prefs_themes_icons[i], 
-                               &(theme->pixmaps[i]), &(theme->masks[i]));
-               gtk_image_set_from_pixmap(GTK_IMAGE(theme->icons[i]),
-                               theme->pixmaps[i], theme->masks[i]);
+               stock_pixbuf_gdk(theme->window, prefs_themes_icons[i], 
+                               &(theme->pixbufs[i]));
+               gtk_image_set_from_pixbuf(GTK_IMAGE(theme->icons[i]),
+                               theme->pixbufs[i]);
        }
        prefs_common.pixmap_theme_path = save_prefs_path;
 
@@ -713,9 +716,9 @@ static void prefs_themes_get_theme_info(ThemesData *tdata)
        ThemeInfo *info;
        ThemesPage *theme = tdata->page;
 
-       g_return_if_fail(theme != NULL);
+       cm_return_if_fail(theme != NULL);
        path = tdata->displayed;
-       g_return_if_fail(path != NULL);
+       cm_return_if_fail(path != NULL);
 
        debug_print("Getting theme info for %s\n", path);
        
@@ -780,40 +783,6 @@ static gchar *prefs_themes_get_theme_stats(const gchar *dirname)
        return stats;
 }
 
-/* BEGIN GLADE CODE */
-/* This is a dummy pixmap we use when a pixmap can't be found. */
-static char *dummy_pixmap_xpm[] = {
-       /* columns rows colors chars-per-pixel */
-       "1 1 1 1",
-       "  c None",
-       /* pixels */
-       " "
-};
-
-/* This is an internally used function to create pixmaps. */
-static GtkWidget* create_dummy_pixmap(GtkWidget *widget)
-{
-       GdkColormap *colormap;
-       GdkPixmap *gdkpixmap;
-       GdkBitmap *mask;
-       GtkWidget *pixmap;
-
-       colormap = gtk_widget_get_colormap (widget);
-       gdkpixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &mask,
-                       NULL, dummy_pixmap_xpm);
-       if (gdkpixmap == NULL)
-               g_error ("Couldn't create replacement pixmap.");
-       pixmap = gtk_image_new_from_pixmap(gdkpixmap, mask);
-       g_object_unref (gdkpixmap);
-       g_object_unref (mask);
-       return pixmap;
-}
-/* END GLADE CODE */
-
-/* glade generates some calls to a create_pixmap support function 
- * we don't really need. */
-#define create_pixmap(widget,filename) create_dummy_pixmap(widget)
-
 static void prefs_themes_create_widget(PrefsPage *page, GtkWindow *window, gpointer data)
 {
        ThemesPage *prefs_themes = (ThemesPage *)page;
@@ -870,7 +839,7 @@ static void prefs_themes_create_widget(PrefsPage *page, GtkWindow *window, gpoin
        btn_install = gtk_button_new_with_label (_("Install new..."));
        gtk_widget_show (btn_install);
        gtk_box_pack_start (GTK_BOX (hbox3), btn_install, FALSE, FALSE, 0);
-       GTK_WIDGET_SET_FLAGS (btn_install, GTK_CAN_DEFAULT);
+       gtkut_widget_set_can_default (btn_install, TRUE);
 
        btn_more = gtkut_get_link_btn((GtkWidget *)window, THEMES_URI, _("Get more..."));
        gtk_widget_show (btn_more);
@@ -953,37 +922,37 @@ static void prefs_themes_create_widget(PrefsPage *page, GtkWindow *window, gpoin
        gtk_widget_show (hbox1);
        gtk_container_add (GTK_CONTAINER (frame_preview), hbox1);
 
-       icon_1 = create_pixmap (vbox1, NULL);
+       icon_1 = gtk_image_new();
        gtk_widget_show (icon_1);
        gtk_box_pack_start (GTK_BOX (hbox1), icon_1, TRUE, TRUE, 2);
        gtk_misc_set_padding (GTK_MISC (icon_1), 0, 5);
 
-       icon_2 = create_pixmap (vbox1, NULL);
+       icon_2 = gtk_image_new();
        gtk_widget_show (icon_2);
        gtk_box_pack_start (GTK_BOX (hbox1), icon_2, TRUE, TRUE, 2);
        gtk_misc_set_padding (GTK_MISC (icon_2), 0, 5);
 
-       icon_3 = create_pixmap (vbox1, NULL);
+       icon_3 = gtk_image_new();
        gtk_widget_show (icon_3);
        gtk_box_pack_start (GTK_BOX (hbox1), icon_3, TRUE, TRUE, 2);
        gtk_misc_set_padding (GTK_MISC (icon_3), 0, 5);
 
-       icon_4 = create_pixmap (vbox1, NULL);
+       icon_4 = gtk_image_new();
        gtk_widget_show (icon_4);
        gtk_box_pack_start (GTK_BOX (hbox1), icon_4, TRUE, TRUE, 2);
        gtk_misc_set_padding (GTK_MISC (icon_4), 0, 5);
 
-       icon_5 = create_pixmap (vbox1, NULL);
+       icon_5 = gtk_image_new();
        gtk_widget_show (icon_5);
        gtk_box_pack_start (GTK_BOX (hbox1), icon_5, TRUE, TRUE, 2);
        gtk_misc_set_padding (GTK_MISC (icon_5), 0, 5);
 
-       icon_6 = create_pixmap (vbox1, NULL);
+       icon_6 = gtk_image_new();
        gtk_widget_show (icon_6);
        gtk_box_pack_start (GTK_BOX (hbox1), icon_6, TRUE, TRUE, 0);
        gtk_misc_set_padding (GTK_MISC (icon_6), 0, 5);
 
-       icon_7 = create_pixmap (vbox1, NULL);
+       icon_7 = gtk_image_new();
        gtk_widget_show (icon_7);
        gtk_box_pack_start (GTK_BOX (hbox1), icon_7, TRUE, TRUE, 0);
        gtk_misc_set_padding (GTK_MISC (icon_7), 0, 5);
@@ -1000,12 +969,12 @@ static void prefs_themes_create_widget(PrefsPage *page, GtkWindow *window, gpoin
        btn_use = gtk_button_new_with_label (_("Use this"));
        gtk_widget_show (btn_use);
        gtk_container_add (GTK_CONTAINER (hbuttonbox1), btn_use);
-       GTK_WIDGET_SET_FLAGS (btn_use, GTK_CAN_DEFAULT);
+       gtkut_widget_set_can_default (btn_use, TRUE);
 
        btn_remove = gtk_button_new_with_label (_("Remove"));
        gtk_widget_show (btn_remove);
        gtk_container_add (GTK_CONTAINER (hbuttonbox1), btn_remove);
-       GTK_WIDGET_SET_FLAGS (btn_remove, GTK_CAN_DEFAULT);
+       gtkut_widget_set_can_default (btn_remove, TRUE);
 
        g_signal_connect(G_OBJECT(btn_use), "clicked",
                         G_CALLBACK(prefs_themes_btn_use_clicked_cb),