2009-01-09 [colin] 3.7.0cvs19
[claws.git] / src / prefs_themes.c
index da9e7d8d6e1011c9f307b568abcf8e104545bd58..c6fa47e7ce728e62ab3f92837d210fdda2bdf99d 100644 (file)
@@ -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,13 +162,15 @@ 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);
                if (len > 4) {
-                       if (filename[len - 1] == 'm' && filename[len - 2] == 'p' &&
-                           filename[len - 3] == 'x' && filename[len - 4] == '.')
+                       const gchar *extension = filename+(len-4);
+                       if (!strcmp(extension, ".xpm"))
+                               di->pixms++;
+                       else if (!strcmp(extension, ".png"))
                                di->pixms++;
                }
        }
@@ -189,7 +190,7 @@ static void prefs_themes_file_remove(const gchar *filename, gpointer data)
                        g_warning("prefs_themes_file_remove(): subdir in theme dir skipped: '%s'.\n",
                                                base);
        }
-       else if (0 != g_unlink(filename)) {
+       else if (0 != claws_unlink(filename)) {
                (*status) = g_strdup(filename);
        }
        g_free(base);
@@ -231,7 +232,7 @@ static void prefs_themes_foreach_file(const gchar *dirname, const FileFunc func,
        g_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;
        }
 
@@ -252,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;
-       
+       gchar *system_theme_dir;
+       gboolean is_sys = FALSE;
+
        g_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)
@@ -525,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;
@@ -542,11 +547,22 @@ static void prefs_themes_btn_install_clicked_cb(GtkWidget *widget, gpointer data
                                          themename, NULL);
        }
        if (TRUE == is_dir_exist(cinfo->dest)) {
-               alertpanel_error(_("A theme with the same name is\nalready installed in this location"));
-               goto end_inst;
+               AlertValue val = alertpanel_full(_("Theme exists"),
+                               _("A theme with the same name is\nalready installed in this location.\n\n"
+                                 "Do you want to replace it?"),
+                               GTK_STOCK_CANCEL, _("Overwrite"), NULL, FALSE,
+                               NULL, ALERT_WARNING, G_ALERTDEFAULT);
+               if (val == G_ALERTALTERNATE) {
+                       if (remove_dir_recursive(cinfo->dest) < 0) {
+                               alertpanel_error(_("Couldn't delete the old theme in %s."), cinfo->dest);
+                               goto end_inst;
+                       }
+               } else {
+                       goto end_inst;
+               }
        }
        if (0 != make_dir_hier(cinfo->dest)) {
-               alertpanel_error(_("Couldn't create destination directory"));
+               alertpanel_error(_("Couldn't create destination directory %s."), cinfo->dest);
                goto end_inst;
        }
        prefs_themes_foreach_file(source, prefs_themes_file_install, cinfo);
@@ -559,7 +575,7 @@ static void prefs_themes_btn_install_clicked_cb(GtkWidget *widget, gpointer data
                                            (gpointer)(cinfo->dest), 
                                            (GCompareFunc)strcmp2);
                if (NULL != insted) {
-                       alertpanel_notice(_("Theme installed successfully"));
+                       alertpanel_notice(_("Theme installed successfully."));
                        tdata->displayed = (gchar *)(insted->data);
                        prefs_themes_set_themes_menu(GTK_COMBO_BOX(tdata->page->op_menu), tdata);
                        prefs_themes_display_global_stats(tdata);
@@ -638,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;
 
@@ -761,7 +777,7 @@ static gchar *prefs_themes_get_theme_stats(const gchar *dirname)
        
        prefs_themes_foreach_file(dirname, prefs_themes_file_stats, dinfo);
        stats = g_strdup_printf(_("%d files (%d icons), size: %s"), 
-                               dinfo->files, dinfo->pixms, to_human_readable(dinfo->bytes));
+                               dinfo->files, dinfo->pixms, to_human_readable((goffset)dinfo->bytes));
        
        g_free(dinfo);
        return stats;