10f6baf9a76c29e283e3e5f0f3e11fe5dff07145
[claws.git] / src / prefs_themes.c
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 2003-2015 Hiroyuki Yamamoto & the Claws Mail team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #ifdef HAVE_CONFIG_H
20 #  include <config.h>
21 #endif
22
23 #include "defs.h"
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <sys/stat.h>
29 #ifdef HAVE_SVG
30 #include <math.h>
31 #endif
32
33 #include <glib.h>
34 #include <glib/gi18n.h>
35 #include <gtk/gtk.h>
36
37 #include "utils.h"
38 #include "codeconv.h"
39 #include "prefs_common.h"
40 #include "prefs_gtk.h"
41
42 #include "gtk/gtkutils.h"
43 #include "gtk/prefswindow.h"
44 #include "gtk/filesel.h"
45
46 #include "stock_pixmap.h"
47 #include "mainwindow.h"
48 #include "compose.h"
49 #include "alertpanel.h"
50 #include "addr_compl.h"
51
52 #define IS_CURRENT_THEME(path)  (strcmp(prefs_common.pixmap_theme_path, path) == 0)
53 #define IS_INTERNAL_THEME(path) (strcmp(DEFAULT_PIXMAP_THEME, path) == 0)
54 #define IS_SYSTEM_THEME(path)   (prefs_themes_is_system_theme(path))
55
56 #define PREVIEW_ICONS 7
57
58 typedef struct _ThemesPage
59 {
60         PrefsPage page;
61
62         GtkWidget *window;              /* do not modify */
63
64         GtkWidget *op_menu;
65         GtkWidget *btn_install;
66         GtkWidget *btn_more;
67         GtkWidget *global;
68
69         GtkWidget *name;
70         GtkWidget *author;
71         GtkWidget *url;
72         GtkWidget *status;
73
74         GtkWidget *icons[PREVIEW_ICONS];
75
76         GtkWidget *btn_remove;
77
78         GdkPixbuf *pixbufs[PREVIEW_ICONS];
79
80 #ifdef HAVE_SVG
81         GtkWidget *checkbtn_enable_alpha;
82         GtkWidget *checkbtn_enable_scaling;
83         GtkWidget *checkbtn_scaling_auto;
84         GtkWidget *label_scaling_ppi;
85         GtkWidget *spinbtn_scaling_ppi;
86 #endif
87 } ThemesPage;
88
89 typedef struct _ThemeInfo
90 {
91         gchar *name;
92         gchar *author;
93         gchar *url;
94         gchar *status;
95 } ThemeInfo;
96
97 typedef struct _ThemeName
98 {
99         gchar *name;
100         GList *item;
101 } ThemeName;
102
103 typedef struct _ThemesData
104 {
105         GList      *themes;
106         GList      *names;
107         gchar      *displayed;
108         ThemesPage *page;
109 } ThemesData;
110
111 typedef void (*FileFunc) (const gchar *filename, gpointer data);
112
113 typedef struct _DirInfo {
114         gint bytes;
115         gint files;
116         gint pixms;
117         /* extensions info */
118         const char **supported;
119         gint *length;
120 } DirInfo;
121
122 typedef struct _CopyInfo {
123         gchar *dest;
124         gchar *status;
125 } CopyInfo;
126
127 static ThemesData *prefs_themes_data;
128
129 StockPixmap prefs_themes_icons[PREVIEW_ICONS] = { 
130         STOCK_PIXMAP_DIR_CLOSE,
131         STOCK_PIXMAP_MAIL_SEND,
132         STOCK_PIXMAP_MAIL_RECEIVE, 
133         STOCK_PIXMAP_MAIL_ATTACH,
134         STOCK_PIXMAP_BOOK, 
135         STOCK_PIXMAP_MIME_TEXT_PLAIN, 
136         STOCK_PIXMAP_REPLIED
137 };
138
139
140
141 static void prefs_themes_btn_remove_clicked_cb  (GtkWidget *widget, gpointer data);
142 static void prefs_themes_btn_install_clicked_cb (GtkWidget *widget, gpointer data);
143 static void prefs_themes_menu_item_activated_cb (GtkWidget *widget, gpointer data);
144 #ifdef HAVE_SVG
145 static gdouble prefs_themes_compute_ppi(GdkScreen *screen);
146 static gdouble prefs_themes_get_adjusted_ppi(void);
147 static void prefs_themes_checkbtn_enable_scaling_toggled_cb (GtkWidget *widget, gpointer data);
148 static void prefs_themes_checkbtn_scaling_auto_toggled_cb (GtkWidget *widget, gpointer data);
149 #endif
150
151 static void prefs_themes_update_buttons         (const ThemesData *tdata);
152 static void prefs_themes_display_global_stats   (const ThemesData *tdata);
153 static void prefs_themes_get_theme_info         (ThemesData *tdata);
154 static void prefs_themes_display_theme_info     (ThemesData *tdata, const ThemeInfo *info);
155 static void prefs_themes_get_themes_and_names   (ThemesData *tdata);
156 static int prefs_themes_cmp_name(gconstpointer a, gconstpointer b);
157 static void prefs_themes_free_names             (ThemesData *tdata);
158
159 static void prefs_themes_set_themes_menu        (GtkComboBox *combo, const ThemesData *tdata);
160
161 static gchar *prefs_themes_get_theme_stats      (const gchar *dirname);
162 static gboolean prefs_themes_is_system_theme    (const gchar *dirname);
163
164 static void prefs_themes_create_widget          (PrefsPage *page, GtkWindow *window, gpointer data);
165 static void prefs_themes_destroy_widget         (PrefsPage *page);
166 static void prefs_themes_save                   (PrefsPage *page);
167
168 static void prefs_themes_foreach_file           (const gchar *dirname, const FileFunc func, gpointer data);
169 static void prefs_themes_file_stats             (const gchar *filename, gpointer data);
170 static void prefs_themes_file_remove            (const gchar *filename, gpointer data);
171 static void prefs_themes_file_install           (const gchar *filename, gpointer data);
172
173
174
175 static void prefs_themes_file_stats(const gchar *filename, gpointer data)
176 {
177         GStatBuf s;
178         DirInfo *di = (DirInfo *)data;
179         gint len;
180         gint i;
181
182         if (0 == g_stat(filename, &s) && 0 != S_ISREG(s.st_mode)) {
183                 di->bytes += s.st_size;
184                 di->files++;
185                 len = strlen(filename);
186                 for (i = 0; (di->supported)[i] != NULL; ++i) {
187                         gint curlen = (di->length)[i];
188                         if (len <= curlen)
189                                 continue;
190                         const gchar *extension = filename + (len - curlen);
191                         if (!strcmp(extension, (di->supported)[i])) {
192                                 di->pixms++;
193                                 break;
194                         }
195                 }
196         }
197 }
198         
199 static void prefs_themes_file_remove(const gchar *filename, gpointer data)
200 {
201         gchar **status = (gchar **)data;
202         gchar *base;
203
204         if ((*status) != NULL)
205                 return;
206
207         base = g_path_get_basename(filename);
208         if (TRUE == is_dir_exist(filename)) {
209                 if (strcmp(base, ".") != 0 && strcmp(base, "..") != 0)
210                         g_warning("prefs_themes_file_remove(): subdir in theme dir skipped: '%s'.",
211                                                 base);
212         }
213         else if (0 != claws_unlink(filename)) {
214                 (*status) = g_strdup(filename);
215         }
216         g_free(base);
217 }
218
219 static void prefs_themes_file_install(const gchar *filename, gpointer data)
220 {
221         CopyInfo *ci = (CopyInfo *)data;
222         gchar *base;
223
224         if (ci->status != NULL)
225                 return;
226
227         base = g_path_get_basename(filename);
228         if (TRUE == is_dir_exist(filename)) {
229                 if (strcmp(base, ".") != 0 && strcmp(base, "..") !=0 )
230                         g_warning("prefs_themes_file_install(): subdir in theme dir skipped: '%s'.",
231                                                 base);
232         }
233         else {
234                 gchar *fulldest;
235
236                 fulldest = g_strconcat(ci->dest, G_DIR_SEPARATOR_S, base, NULL);
237
238                 if (0 != copy_file(filename, fulldest, FALSE)) {
239                         ci->status = g_strdup(filename);
240                 }
241                 g_free(fulldest);
242         }
243         g_free(base);
244 }
245
246 static void prefs_themes_foreach_file(const gchar *dirname, const FileFunc func, gpointer data)
247 {
248         const gchar *entry;
249         gchar *fullentry;
250         GDir *dp;
251         GError *error = NULL;
252
253         cm_return_if_fail(dirname != NULL);
254         cm_return_if_fail(func != NULL);
255
256         if ((dp = g_dir_open(dirname, 0, &error)) == NULL) {
257                 debug_print("couldn't open dir '%s': %s (%d)\n", dirname,
258                                 error->message, error->code);
259                 g_error_free(error);
260                 return;
261         }
262
263         while ((entry = g_dir_read_name(dp)) != NULL) {
264
265                 fullentry = g_strconcat(dirname, G_DIR_SEPARATOR_S, entry, NULL);
266
267                 (*func)(fullentry, data);
268
269                 g_free(fullentry);
270         }
271         g_dir_close(dp);
272 }
273
274 static gboolean prefs_themes_is_system_theme(const gchar *dirname)
275 {
276         gint len;
277         gchar *system_theme_dir;
278         gboolean is_sys = FALSE;
279
280         cm_return_val_if_fail(dirname != NULL, FALSE);
281
282         system_theme_dir = stock_pixmap_get_system_theme_dir_for_theme(NULL);
283         len = strlen(system_theme_dir);
284         if (strlen(dirname) > len && 0 == strncmp(dirname, system_theme_dir, len))
285                 is_sys = TRUE;
286
287         g_free(system_theme_dir);
288
289         return is_sys;
290 }
291
292 static void prefs_themes_set_themes_menu(GtkComboBox *combo, const ThemesData *tdata)
293 {
294         GtkListStore *store;
295         GtkTreeIter iter;
296         GList     *themes = tdata->names;
297         gint       i = 0, active = 0;
298         GList     *sorted_list = NULL;
299
300         cm_return_if_fail(combo != NULL);
301
302         /* sort theme data list by data name */
303         while (themes != NULL) {
304                 ThemeName *tname = (ThemeName *)(themes->data);
305
306                 sorted_list = g_list_insert_sorted(sorted_list, (gpointer)(tname),
307                                                    (GCompareFunc)prefs_themes_cmp_name);
308
309                 themes = g_list_next(themes);
310         }
311
312         store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_POINTER);
313
314         /* feed gtk_menu w/ sorted themes names */
315         themes = sorted_list;
316         while (themes != NULL) {
317                 ThemeName *tname = (ThemeName *)(themes->data);
318                 gchar     *tpath = (gchar *)(tname->item->data);
319
320                 gtk_list_store_append(store, &iter);
321                 gtk_list_store_set(store, &iter,
322                                    0, tname->name,
323                                    1, tname->item->data, -1);
324
325                 if (tdata->displayed != NULL && !strcmp2(tdata->displayed,tpath))
326                         active = i;
327                 ++i;
328
329                 themes = g_list_next(themes);
330         }
331
332         g_list_free(sorted_list);
333
334         g_signal_connect(G_OBJECT(combo), "changed",
335                          G_CALLBACK(prefs_themes_menu_item_activated_cb),
336                          NULL);
337
338         gtk_combo_box_set_model(combo, GTK_TREE_MODEL(store));
339         gtk_combo_box_set_active(combo, active);
340 }
341
342 static int prefs_themes_cmp_name(gconstpointer a_p, gconstpointer b_p)
343 {
344         /* compare two ThemeData structures by their name attribute */
345         return strcmp2((gchar *)(((ThemeName*)a_p)->name),
346                                         (gchar *)(((ThemeName*)b_p)->name));
347 }
348
349 static void prefs_themes_get_themes_and_names(ThemesData *tdata)
350 {
351         GList *tpaths;
352
353         cm_return_if_fail(tdata != NULL);
354
355         if (tdata->themes != NULL)
356                 stock_pixmap_themes_list_free(tdata->themes);
357         if (tdata->names != NULL)
358                 prefs_themes_free_names(tdata);
359
360         tdata->themes = stock_pixmap_themes_list_new();
361
362         tpaths = tdata->themes;
363         while (tpaths != NULL) {
364                 ThemeName *name = g_new0(ThemeName, 1);
365                 gchar *sname = g_path_get_basename((const gchar *)(tpaths->data));
366
367                 if (IS_INTERNAL_THEME(sname))
368                         name->name = g_strdup(_("Default internal theme"));
369                 else
370                         name->name = g_strdup(sname);
371                 name->item = tpaths;
372
373                 tdata->names = g_list_append(tdata->names, name);
374                 if (!strcmp2(tpaths->data, prefs_common.pixmap_theme_path)) {
375                         tdata->displayed = (gchar *)tpaths->data;
376                 }
377                 tpaths = g_list_next(tpaths);
378                 g_free(sname);  
379         }
380 }
381
382 void prefs_themes_init(void)
383 {
384         ThemesData   *tdata;
385         ThemesPage   *page;
386         GList        *tpaths;
387         static gchar *path[3];
388
389         path[0] = _("Display");
390         path[1] = _("Themes");
391         path[2] = NULL;
392
393         debug_print("Creating preferences for themes...\n");
394
395         tdata = g_new0(ThemesData, 1);
396         prefs_themes_data = tdata;
397
398         prefs_themes_get_themes_and_names(tdata);
399
400         page = g_new0(ThemesPage, 1);
401
402         page->page.path = path;
403         page->page.create_widget = prefs_themes_create_widget;
404         page->page.destroy_widget = prefs_themes_destroy_widget;
405         page->page.save_page = prefs_themes_save;
406         page->page.weight = 130.0;
407         prefs_gtk_register_page((PrefsPage *) page);
408
409         tdata->page = page;
410
411         tpaths = g_list_first(tdata->themes);
412         if (tdata->displayed == NULL)
413                 tdata->displayed = (gchar *)(tpaths->data);
414 #ifdef HAVE_SVG
415         if (prefs_common.pixmap_scaling_auto)
416                 prefs_common.pixmap_scaling_ppi = prefs_themes_get_adjusted_ppi();
417 #endif
418 }
419
420 static void prefs_themes_free_names(ThemesData *tdata)
421 {
422         GList *names;
423
424         names = tdata->names;
425         while (names != NULL) {
426                 ThemeName *tn = (ThemeName *)(names->data);
427
428                 tn->item = NULL;
429                 g_free(tn->name);
430                 g_free(tn);
431
432                 names = g_list_next(names);
433         }
434         g_list_free(tdata->names);
435         tdata->names = NULL;
436 }
437
438 void prefs_themes_done(void)
439 {
440         ThemesData *tdata = prefs_themes_data;
441
442         debug_print("Finished preferences for themes.\n");
443
444         stock_pixmap_themes_list_free(tdata->themes);
445         prefs_themes_free_names(tdata); 
446         g_free(tdata->page);
447         g_free(tdata);
448 }
449
450 static void prefs_themes_btn_remove_clicked_cb(GtkWidget *widget, gpointer data)
451 {
452         ThemesData *tdata = prefs_themes_data;
453         gchar      *theme_str;
454         gchar      *alert_title = NULL;
455         AlertValue  val = 0;
456         gchar      *tmp = NULL;
457
458         theme_str = tdata->displayed;
459
460         tmp = g_path_get_basename(theme_str);
461
462         if (IS_SYSTEM_THEME(theme_str)) {
463                 if (!superuser_p()) {
464                         alertpanel_error(_("Only root can remove system themes"));
465                         return;
466                 }
467                 alert_title = g_strdup_printf(_("Remove system theme '%s'"), tmp);
468         }
469         if (NULL == alert_title) {
470                 alert_title = g_strdup_printf(_("Remove theme '%s'"), tmp);
471         }
472
473         g_free(tmp);
474
475         val = alertpanel(alert_title,
476                          _("Are you sure you want to remove this theme?"),
477                          GTK_STOCK_NO, GTK_STOCK_YES, NULL);
478         g_free(alert_title);
479
480         if (G_ALERTALTERNATE == val) {
481                 gchar *status = NULL;
482
483                 prefs_themes_foreach_file(theme_str, prefs_themes_file_remove, &status); 
484                 if (0 != rmdir(theme_str)) {
485                         if (status != NULL) {
486                                 alertpanel_error(_("File %s failed\nwhile removing theme."), status);
487                                 g_free(status);
488                         }
489                         else
490                                 alertpanel_error(_("Removing theme directory failed."));
491                 }
492                 else {  
493                         alertpanel_notice(_("Theme removed successfully"));
494                         /* update interface back to first theme */
495                         prefs_themes_get_themes_and_names(tdata);
496                         prefs_themes_set_themes_menu(GTK_COMBO_BOX(tdata->page->op_menu), tdata);
497                         prefs_themes_display_global_stats(tdata);
498                         tdata->displayed = (gchar *)((g_list_first(tdata->themes))->data);
499                         prefs_themes_get_theme_info(tdata);
500                 }
501         }
502 }
503
504 static void prefs_themes_btn_install_clicked_cb(GtkWidget *widget, gpointer data)
505 {
506         gchar      *filename, *source;
507         gchar      *themeinfo, *themename;
508         gchar      *alert_title = NULL;
509         CopyInfo   *cinfo;
510         AlertValue  val = 0;
511         ThemesData *tdata = prefs_themes_data;
512
513         filename = filesel_select_file_open_folder(_("Select theme folder"), NULL);
514         if (filename == NULL) 
515                 return;
516
517         if (filename[strlen(filename) - 1] != G_DIR_SEPARATOR)
518                 filename = g_strconcat(filename, G_DIR_SEPARATOR_S, NULL);
519         else
520                 filename = g_strdup(filename);
521
522         cinfo = g_new0(CopyInfo, 1);
523         source = g_path_get_dirname(filename);
524         themename = g_path_get_basename(source);
525         debug_print("Installing '%s' theme from %s\n", themename, filename);
526
527         themeinfo = g_strconcat(source, G_DIR_SEPARATOR_S, THEMEINFO_FILE, NULL);
528         alert_title = g_strdup_printf(_("Install theme '%s'"), themename);
529         if (file_exist(themeinfo, FALSE) == FALSE) {
530                 val = alertpanel(alert_title,
531                                  _("This folder doesn't seem to be a theme folder.\nInstall anyway?"),
532                                  GTK_STOCK_NO, GTK_STOCK_YES, NULL);
533                 if (G_ALERTALTERNATE != val)
534                         goto end_inst;
535         }
536         if (superuser_p ()) {
537                 val = alertpanel(alert_title,
538                                  _("Do you want to install theme for all users?"),
539                                  GTK_STOCK_NO, GTK_STOCK_YES, NULL);
540                 switch (val) {
541                 case G_ALERTALTERNATE:
542                         cinfo->dest = stock_pixmap_get_system_theme_dir_for_theme(
543                                                 themename);
544                         break;
545                 case G_ALERTDEFAULT:
546                         break;
547                 default:
548                         goto end_inst;
549                 }
550         }
551         g_free(alert_title);
552         if (cinfo->dest == NULL) {
553                 cinfo->dest = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
554                                           PIXMAP_THEME_DIR, G_DIR_SEPARATOR_S,
555                                           themename, NULL);
556         }
557         if (TRUE == is_dir_exist(cinfo->dest)) {
558                 AlertValue val = alertpanel_full(_("Theme exists"),
559                                 _("A theme with the same name is\nalready installed in this location.\n\n"
560                                   "Do you want to replace it?"),
561                                 GTK_STOCK_CANCEL, _("Overwrite"), NULL, FALSE,
562                                 NULL, ALERT_WARNING, G_ALERTDEFAULT);
563                 if (val == G_ALERTALTERNATE) {
564                         if (remove_dir_recursive(cinfo->dest) < 0) {
565                                 alertpanel_error(_("Couldn't delete the old theme in %s."), cinfo->dest);
566                                 goto end_inst;
567                         }
568                 } else {
569                         goto end_inst;
570                 }
571         }
572         if (0 != make_dir_hier(cinfo->dest)) {
573                 alertpanel_error(_("Couldn't create destination directory %s."), cinfo->dest);
574                 goto end_inst;
575         }
576         prefs_themes_foreach_file(source, prefs_themes_file_install, cinfo);
577         if (cinfo->status == NULL) {
578                 GList *insted;
579
580                 /* update interface to show newly installed theme */
581                 prefs_themes_get_themes_and_names(tdata);
582                 insted = g_list_find_custom(tdata->themes, 
583                                             (gpointer)(cinfo->dest), 
584                                             (GCompareFunc)strcmp2);
585                 if (NULL != insted) {
586                         alertpanel_notice(_("Theme installed successfully."));
587                         tdata->displayed = (gchar *)(insted->data);
588                         prefs_themes_set_themes_menu(GTK_COMBO_BOX(tdata->page->op_menu), tdata);
589                         prefs_themes_display_global_stats(tdata);
590                         prefs_themes_get_theme_info(tdata);
591                 }
592                 else
593                         alertpanel_error(_("Failed installing theme"));
594         }
595         else
596                 alertpanel_error(_("File %s failed\nwhile installing theme."), cinfo->status);
597 end_inst:
598         g_free(cinfo->dest);
599         g_free(filename);
600         g_free(source);
601         g_free(themeinfo);
602         g_free(cinfo);
603         g_free(themename);
604 }
605
606 static void prefs_themes_menu_item_activated_cb(GtkWidget *widget, gpointer data)
607 {
608         ThemesData *tdata = prefs_themes_data;
609         gchar      *path;
610         GtkTreeModel *model;
611         GtkTreeIter iter;
612
613         cm_return_if_fail(gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &iter));
614
615         model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
616         gtk_tree_model_get(model, &iter, 1, &path, -1);
617
618         tdata->displayed = path;
619         prefs_themes_get_theme_info(tdata);
620 }
621
622 #ifdef HAVE_SVG
623 #define MM_INCH 0.0393700787402
624 static gdouble prefs_themes_compute_ppi(GdkScreen *screen)
625 {
626         gdouble wp = gdk_screen_get_width(screen);
627         gdouble hp = gdk_screen_get_height(screen);
628         gdouble wi = gdk_screen_get_width_mm(screen);
629         gdouble hi = gdk_screen_get_height_mm(screen);
630         gdouble dp, di;
631
632         debug_print("screen is %f x %f pixels, %f x %f mm\n", wp, hp, wi, hi);
633
634         /* https://en.wikipedia.org/wiki/Pixel_density */
635         wi *= MM_INCH;
636         hi *= MM_INCH;
637         dp = sqrt(wp * wp + hp * hp);
638         di = sqrt(wi * wi + hi * hi);
639
640         return (di != 0.0)? dp / di: 0.0;
641 }
642
643 static gdouble prefs_themes_get_adjusted_ppi(void)
644 {
645         gdouble ppi, cppi;
646         GdkScreen * screen = gdk_screen_get_default();
647
648         if (screen == NULL) { /* oops! */
649                 g_warning("unable to get default GDK screen");
650                 return MIN_PPI;
651         }
652
653         ppi = gdk_screen_get_resolution(screen);
654         cppi = prefs_themes_compute_ppi(screen);
655         debug_print("returned PPI: %f / computed PPI: %f\n", ppi, cppi);
656         /*
657          gdk_screen_get_resolution doesn't seem to work well when running
658          on a remote display and returns the value of the local display.
659          height/width functions do this better, so we can compute a PPI
660          from them and take the highest value.
661         */
662         return MAX(ppi, cppi);
663 }
664
665 static void prefs_themes_checkbtn_enable_scaling_toggled_cb (GtkWidget *widget, gpointer data)
666 {
667         ThemesPage *page = (ThemesPage *) data;
668         gboolean enabled = gtk_toggle_button_get_active(
669                                 GTK_TOGGLE_BUTTON (widget));
670         gboolean automatic = gtk_toggle_button_get_active(
671                                 GTK_TOGGLE_BUTTON (page->checkbtn_scaling_auto));
672
673         gtk_widget_set_sensitive(page->checkbtn_scaling_auto, enabled);
674         gtk_widget_set_sensitive(page->spinbtn_scaling_ppi, enabled && !automatic);
675         gtk_widget_set_sensitive(page->label_scaling_ppi, enabled && !automatic);
676 }
677
678 static void prefs_themes_checkbtn_scaling_auto_toggled_cb(GtkWidget *widget, gpointer data)
679 {
680         ThemesPage *page = (ThemesPage *) data;
681         gboolean automatic = gtk_toggle_button_get_active(
682                                 GTK_TOGGLE_BUTTON (widget));
683
684         gtk_widget_set_sensitive(page->spinbtn_scaling_ppi, !automatic);
685         gtk_widget_set_sensitive(page->label_scaling_ppi, !automatic);
686
687         if (automatic) /* update PPI value */
688                 gtk_spin_button_set_value(
689                                 GTK_SPIN_BUTTON (page->spinbtn_scaling_ppi),
690                                 prefs_themes_get_adjusted_ppi());
691 }
692 #endif
693
694 static void prefs_themes_update_buttons(const ThemesData *tdata)
695 {
696         ThemesPage *theme = tdata->page;
697         gboolean    can_rem, can_use;
698
699         can_use = !IS_CURRENT_THEME(tdata->displayed);
700         can_rem = can_use && !IS_INTERNAL_THEME(tdata->displayed);
701
702         if (theme->btn_remove != NULL)
703                 gtk_widget_set_sensitive(theme->btn_remove, can_rem);
704 }
705
706 /* placeholders may already be utf8 (i18n) */
707 #define SET_LABEL_TEXT_UTF8(label, text)                                \
708 {                                                                       \
709         gchar *tmpstr;                                                  \
710                                                                         \
711         if (!g_utf8_validate(text, -1, NULL))                           \
712                 tmpstr = conv_codeset_strdup(text,                      \
713                         conv_get_locale_charset_str(),  CS_UTF_8);      \
714         else                                                            \
715                 tmpstr = g_strdup(text);                                \
716                                                                         \
717         gtk_label_set_text(GTK_LABEL(label), tmpstr);                   \
718         gtk_label_set_selectable(GTK_LABEL(label), TRUE);               \
719         g_free(tmpstr);                                                 \
720 }
721 static void prefs_themes_display_theme_info(ThemesData *tdata, const ThemeInfo *info)
722 {
723         ThemesPage *theme = tdata->page;
724         gchar *save_prefs_path;
725         gint   i;
726
727         SET_LABEL_TEXT_UTF8(theme->name,        info->name);
728         SET_LABEL_TEXT_UTF8(theme->author,      info->author);
729         SET_LABEL_TEXT_UTF8(theme->url,         info->url);
730         SET_LABEL_TEXT_UTF8(theme->status,      info->status);
731
732         save_prefs_path = prefs_common.pixmap_theme_path;
733         prefs_common.pixmap_theme_path = tdata->displayed;
734         for (i = 0; i < PREVIEW_ICONS; ++i) {
735                 stock_pixbuf_gdk(prefs_themes_icons[i], &(theme->pixbufs[i]));
736                 gtk_image_set_from_pixbuf(GTK_IMAGE(theme->icons[i]),
737                                 theme->pixbufs[i]);
738         }
739         prefs_common.pixmap_theme_path = save_prefs_path;
740
741         prefs_themes_update_buttons(tdata);
742 }
743 #undef SET_LABEL_TEXT_UTF8
744
745 static void prefs_themes_display_global_stats(const ThemesData *tdata)
746 {
747         ThemesPage *theme = tdata->page;
748         GList      *tnames = tdata->names;
749         gchar      *gstats;
750         gint        sys = 0;
751         gint        usr = 0;
752         gint        all = 0;
753
754         while (tnames != NULL) {
755                 ThemeName *tname = (ThemeName *)(tnames->data);
756                 gchar     *tpath = (gchar *)(tname->item->data);
757                 
758                 if (IS_SYSTEM_THEME(tpath)) 
759                         ++sys;
760                 else if (!IS_INTERNAL_THEME(tpath)) 
761                         ++usr;
762                 ++all;
763                 tnames = g_list_next(tnames);
764         }
765
766         gstats = g_strdup_printf(_("%d themes available (%d user, %d system, 1 internal)"),
767                                  all, usr, sys);
768         gtk_label_set_text(GTK_LABEL(theme->global), gstats);
769         gtk_label_set_justify (GTK_LABEL (theme->global), GTK_JUSTIFY_LEFT);
770         gtkut_widget_set_small_font_size (theme->global);
771         g_free(gstats);
772 }
773
774 #define INFOFILE_LINE_LEN 80
775
776 #define FGETS_INFOFILE_LINE() \
777         line[0] = '\0'; \
778         if (fgets(line, INFOFILE_LINE_LEN, finfo) != NULL && (len = strlen(line)) > 0) { \
779                 if (line[len - 1] == '\n') line[len - 1] = '\0'; \
780         } \
781         else { \
782                 g_strlcpy(line, _("Unknown"),sizeof(line)); \
783         }
784
785 static void prefs_themes_get_theme_info(ThemesData *tdata)
786 {
787         FILE  *finfo;
788         gchar *sinfo;
789         gchar *path;
790         gchar  line[INFOFILE_LINE_LEN];
791         gint   len;
792         ThemeInfo *info;
793         ThemesPage *theme = tdata->page;
794
795         cm_return_if_fail(theme != NULL);
796         path = tdata->displayed;
797         cm_return_if_fail(path != NULL);
798
799         debug_print("Getting theme info for %s\n", path);
800
801         info = g_new0(ThemeInfo, 1);
802
803         if (IS_INTERNAL_THEME(path)) {
804                 info->name = g_strdup(_("Default internal theme"));
805                 info->author = g_strdup(_("The Claws Mail Team"));
806                 info->url = g_strdup(HOMEPAGE_URI);
807                 info->status = g_strdup_printf(_("Internal theme has %d icons"), N_STOCK_PIXMAPS);
808         }
809         else {
810                 sinfo = g_strconcat(path, G_DIR_SEPARATOR_S, THEMEINFO_FILE, NULL);
811                 finfo = g_fopen(sinfo, "r");
812                 if (finfo == NULL) {
813                         info->name = g_strdup(_("No info file available for this theme"));
814                         info->author = g_strdup(_("Unknown"));
815                         info->url = g_strdup(_("Unknown"));
816                 }
817                 else {
818                         FGETS_INFOFILE_LINE()
819                         info->name = g_strdup(line);
820                         FGETS_INFOFILE_LINE()
821                         info->author = g_strdup(line);
822                         FGETS_INFOFILE_LINE()
823                         info->url = g_strdup(line);
824                 
825                         fclose(finfo);
826                 }
827                 g_free(sinfo);
828
829                 info->status = prefs_themes_get_theme_stats(path);
830                 if (info->status == NULL) {
831                         info->status = g_strdup(_("Error: couldn't get theme status"));
832                 }
833         }
834
835         prefs_themes_display_theme_info(tdata, info);
836
837         g_free(info->name);
838         g_free(info->author);
839         g_free(info->url);
840         g_free(info->status);
841
842         g_free(info);
843 }
844
845 #undef FGETS_INFOFILE_LINE
846
847 static gchar *prefs_themes_get_theme_stats(const gchar *dirname)
848 {
849         gchar   *stats;
850         DirInfo *dinfo;
851         gint     i;
852
853         dinfo = g_new0(DirInfo, 1);
854         dinfo->supported = stock_pixmap_theme_extensions();
855         for (i = 0; (dinfo->supported)[i] != NULL; ++i);
856         dinfo->length = g_malloc(i * sizeof(gint));
857         for (i = 0; (dinfo->supported)[i] != NULL; ++i) {
858                 (dinfo->length)[i] = strlen((dinfo->supported)[i]);
859         }
860         prefs_themes_foreach_file(dirname, prefs_themes_file_stats, dinfo);
861         stats = g_strdup_printf(_("%d files (%d icons), size: %s"),
862                                 dinfo->files, dinfo->pixms,
863                                 to_human_readable((goffset)dinfo->bytes));
864         g_free(dinfo->length);
865         g_free(dinfo);
866         return stats;
867 }
868
869 static void prefs_themes_create_widget(PrefsPage *page, GtkWindow *window, gpointer data)
870 {
871         ThemesPage *prefs_themes = (ThemesPage *)page;
872         ThemesData *tdata = prefs_themes_data;
873
874         GtkWidget *vbox1;
875         GtkWidget *frame1;
876         GtkWidget *vbox2;
877         GtkWidget *hbox3;
878         GtkWidget *menu_themes;
879         GtkWidget *btn_install;
880         GtkWidget *btn_more;
881         GtkWidget *label_global_status;
882         GtkWidget *frame_info;
883         GtkWidget *table1;
884         GtkWidget *label1;
885         GtkWidget *label2;
886         GtkWidget *label3;
887         GtkWidget *label_name;
888         GtkWidget *label_author;
889         GtkWidget *label_url;
890         GtkWidget *label4;
891         GtkWidget *label_status;
892         GtkWidget *frame_preview;
893         GtkWidget *hbox1;
894         GtkWidget *icon_1;
895         GtkWidget *icon_2;
896         GtkWidget *icon_3;
897         GtkWidget *icon_4;
898         GtkWidget *icon_5;
899         GtkWidget *icon_6;
900         GtkWidget *icon_7;
901         GtkWidget *frame_buttons;
902         GtkWidget *hbuttonbox1;
903         GtkWidget *btn_remove;
904         GtkCellRenderer *renderer;
905 #ifdef HAVE_SVG
906         GtkWidget *frame_scaling;
907         GtkWidget *checkbtn_enable_alpha;
908         GtkWidget *checkbtn_enable_scaling;
909         GtkWidget *checkbtn_scaling_auto;
910         GtkWidget *label_scaling_ppi;
911         GtkWidget *spinbtn_scaling_ppi;
912         GtkAdjustment *spinbtn_scaling_ppi_adj;
913 #endif
914
915         vbox1 = gtk_vbox_new (FALSE, VSPACING);
916         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
917         gtk_widget_show (vbox1);
918
919         vbox2 = gtkut_get_options_frame(vbox1, &frame1, _("Selector"));
920
921         hbox3 = gtk_hbox_new (FALSE, 5);
922         gtk_widget_show (hbox3);
923         gtk_box_pack_start (GTK_BOX (vbox2), hbox3, FALSE, FALSE, 0);
924         gtk_container_set_border_width (GTK_CONTAINER (hbox3), 5);
925
926         menu_themes = gtk_combo_box_new();
927         gtk_widget_show (menu_themes);
928         gtk_box_pack_start (GTK_BOX (hbox3), menu_themes, FALSE, FALSE, 0);
929
930         btn_install = gtk_button_new_with_label (_("Install new..."));
931         gtk_widget_show (btn_install);
932         gtk_box_pack_start (GTK_BOX (hbox3), btn_install, FALSE, FALSE, 0);
933         gtkut_widget_set_can_default (btn_install, TRUE);
934
935         btn_more = gtkut_get_link_btn((GtkWidget *)window, THEMES_URI, _("Get more..."));
936         gtk_widget_show (btn_more);
937         gtk_box_pack_start (GTK_BOX (hbox3), btn_more, FALSE, FALSE, 0);
938
939         label_global_status = gtk_label_new ("");
940         gtk_widget_show (label_global_status);
941         gtk_box_pack_start (GTK_BOX (vbox2), label_global_status, FALSE, FALSE, 0);
942         gtk_label_set_justify (GTK_LABEL (label_global_status), GTK_JUSTIFY_LEFT);
943         gtk_misc_set_alignment (GTK_MISC (label_global_status), 0, 0.5);
944         gtk_misc_set_padding (GTK_MISC (label_global_status), 6, 0);
945
946         PACK_FRAME(vbox1, frame_info, _("Information"));
947
948         table1 = gtk_table_new (4, 2, FALSE);
949         gtk_widget_show (table1);
950         gtk_container_add (GTK_CONTAINER (frame_info), table1);
951
952         label1 = gtk_label_new (_("Name: "));
953         gtk_widget_show (label1);
954         gtk_table_attach (GTK_TABLE (table1), label1, 0, 1, 0, 1,
955                         (GtkAttachOptions) (GTK_FILL),
956                         (GtkAttachOptions) (0), 8, 2);
957         gtk_label_set_justify (GTK_LABEL (label1), GTK_JUSTIFY_LEFT);
958         gtk_misc_set_alignment (GTK_MISC (label1), 0, 0.5);
959
960         label2 = gtk_label_new (_("Author: "));
961         gtk_widget_show (label2);
962         gtk_table_attach (GTK_TABLE (table1), label2, 0, 1, 1, 2,
963                         (GtkAttachOptions) (GTK_FILL),
964                         (GtkAttachOptions) (0), 8, 2);
965         gtk_label_set_justify (GTK_LABEL (label2), GTK_JUSTIFY_LEFT);
966         gtk_misc_set_alignment (GTK_MISC (label2), 0, 0.5);
967
968         label3 = gtk_label_new (_("URL:"));
969         gtk_widget_show (label3);
970         gtk_table_attach (GTK_TABLE (table1), label3, 0, 1, 2, 3,
971                         (GtkAttachOptions) (GTK_FILL),
972                         (GtkAttachOptions) (0), 8, 2);
973         gtk_misc_set_alignment (GTK_MISC (label3), 0, 0.5);
974
975         label_name = gtk_label_new ("");
976         gtk_widget_show (label_name);
977         gtk_table_attach (GTK_TABLE (table1), label_name, 1, 2, 0, 1,
978                         (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
979                         (GtkAttachOptions) (0), 0, 0);
980         gtk_misc_set_alignment (GTK_MISC (label_name), 0, 0.5);
981
982         label_author = gtk_label_new ("");
983         gtk_widget_show (label_author);
984         gtk_table_attach (GTK_TABLE (table1), label_author, 1, 2, 1, 2,
985                         (GtkAttachOptions) (GTK_FILL),
986                         (GtkAttachOptions) (0), 0, 0);
987         gtk_misc_set_alignment (GTK_MISC (label_author), 0, 0.5);
988
989         label_url = gtk_label_new ("");
990         gtk_widget_show (label_url);
991         gtk_table_attach (GTK_TABLE (table1), label_url, 1, 2, 2, 3,
992                         (GtkAttachOptions) (GTK_FILL),
993                         (GtkAttachOptions) (0), 0, 0);
994         gtk_misc_set_alignment (GTK_MISC (label_url), 0, 0.5);
995
996         label4 = gtk_label_new (_("Status:"));
997         gtk_widget_show (label4);
998         gtk_table_attach (GTK_TABLE (table1), label4, 0, 1, 3, 4,
999                         (GtkAttachOptions) (GTK_FILL),
1000                         (GtkAttachOptions) (0), 8, 2);
1001         gtk_misc_set_alignment (GTK_MISC (label4), 0, 0.5);
1002
1003         label_status = gtk_label_new ("");
1004         gtk_widget_show (label_status);
1005         gtk_table_attach (GTK_TABLE (table1), label_status, 1, 2, 3, 4,
1006                         (GtkAttachOptions) (GTK_FILL),
1007                         (GtkAttachOptions) (0), 0, 0);
1008         gtk_misc_set_alignment (GTK_MISC (label_status), 0, 0.5);
1009
1010         PACK_FRAME(vbox1, frame_preview, _("Preview"));
1011
1012         hbox1 = gtk_hbox_new (FALSE, 0);
1013         gtk_widget_show (hbox1);
1014         gtk_container_add (GTK_CONTAINER (frame_preview), hbox1);
1015
1016         icon_1 = gtk_image_new();
1017         gtk_widget_show (icon_1);
1018         gtk_box_pack_start (GTK_BOX (hbox1), icon_1, TRUE, TRUE, 2);
1019         gtk_misc_set_padding (GTK_MISC (icon_1), 0, 5);
1020
1021         icon_2 = gtk_image_new();
1022         gtk_widget_show (icon_2);
1023         gtk_box_pack_start (GTK_BOX (hbox1), icon_2, TRUE, TRUE, 2);
1024         gtk_misc_set_padding (GTK_MISC (icon_2), 0, 5);
1025
1026         icon_3 = gtk_image_new();
1027         gtk_widget_show (icon_3);
1028         gtk_box_pack_start (GTK_BOX (hbox1), icon_3, TRUE, TRUE, 2);
1029         gtk_misc_set_padding (GTK_MISC (icon_3), 0, 5);
1030
1031         icon_4 = gtk_image_new();
1032         gtk_widget_show (icon_4);
1033         gtk_box_pack_start (GTK_BOX (hbox1), icon_4, TRUE, TRUE, 2);
1034         gtk_misc_set_padding (GTK_MISC (icon_4), 0, 5);
1035
1036         icon_5 = gtk_image_new();
1037         gtk_widget_show (icon_5);
1038         gtk_box_pack_start (GTK_BOX (hbox1), icon_5, TRUE, TRUE, 2);
1039         gtk_misc_set_padding (GTK_MISC (icon_5), 0, 5);
1040
1041         icon_6 = gtk_image_new();
1042         gtk_widget_show (icon_6);
1043         gtk_box_pack_start (GTK_BOX (hbox1), icon_6, TRUE, TRUE, 0);
1044         gtk_misc_set_padding (GTK_MISC (icon_6), 0, 5);
1045
1046         icon_7 = gtk_image_new();
1047         gtk_widget_show (icon_7);
1048         gtk_box_pack_start (GTK_BOX (hbox1), icon_7, TRUE, TRUE, 0);
1049         gtk_misc_set_padding (GTK_MISC (icon_7), 0, 5);
1050
1051         PACK_FRAME(vbox1, frame_buttons, _("Actions"));
1052
1053         hbuttonbox1 = gtk_hbutton_box_new ();
1054         gtk_widget_show (hbuttonbox1);
1055         gtk_container_add (GTK_CONTAINER (frame_buttons), hbuttonbox1);
1056         gtk_container_set_border_width (GTK_CONTAINER (hbuttonbox1), 5);
1057         gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox1), GTK_BUTTONBOX_START);
1058         gtk_box_set_spacing (GTK_BOX (hbuttonbox1), 5);
1059
1060         btn_remove = gtk_button_new_with_label (_("Remove"));
1061         gtk_widget_show (btn_remove);
1062         gtk_container_add (GTK_CONTAINER (hbuttonbox1), btn_remove);
1063         gtkut_widget_set_can_default (btn_remove, TRUE);
1064
1065 #ifdef HAVE_SVG
1066         PACK_FRAME(vbox1, frame_scaling, _("SVG rendering"));
1067
1068         vbox2 = gtk_vbox_new (FALSE, VSPACING);
1069         gtk_widget_show (vbox2);
1070         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 5);
1071         gtk_container_add (GTK_CONTAINER (frame_scaling), vbox2);
1072
1073         PACK_CHECK_BUTTON(vbox2, checkbtn_enable_alpha, _("Enable alpha channel"));
1074         PACK_CHECK_BUTTON(vbox2, checkbtn_enable_scaling, _("Force scaling"));
1075         PACK_CHECK_BUTTON(vbox2, checkbtn_scaling_auto, _("Automatic"));
1076
1077         hbox3 = gtk_hbox_new (FALSE, 5);
1078         gtk_widget_show (hbox3);
1079
1080         label_scaling_ppi = gtk_label_new (_("Pixels per inch (PPI)"));
1081         gtk_widget_show (label_scaling_ppi);
1082         gtk_box_pack_start (GTK_BOX (hbox3), label_scaling_ppi,
1083                         FALSE, FALSE, 5);
1084
1085         spinbtn_scaling_ppi_adj = GTK_ADJUSTMENT(
1086                 gtk_adjustment_new (MIN_PPI, MIN_PPI, MAX_PPI, 1, 10, 0));
1087         spinbtn_scaling_ppi = gtk_spin_button_new(
1088                         spinbtn_scaling_ppi_adj, 1.0, 0);
1089         gtk_widget_show (spinbtn_scaling_ppi);
1090         gtk_box_pack_start (GTK_BOX (hbox3), spinbtn_scaling_ppi,
1091                         FALSE, FALSE, 5);
1092
1093         gtk_box_pack_start (GTK_BOX (vbox2), hbox3, FALSE, FALSE, 0);
1094
1095         /* initialize widget values */
1096         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (checkbtn_enable_alpha),
1097                         prefs_common.enable_alpha_svg);
1098         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (checkbtn_enable_scaling),
1099                         prefs_common.enable_pixmap_scaling);
1100         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (checkbtn_scaling_auto),
1101                         prefs_common.pixmap_scaling_auto);
1102         gtk_spin_button_set_value(GTK_SPIN_BUTTON (spinbtn_scaling_ppi),
1103                         prefs_common.pixmap_scaling_ppi);
1104
1105         /* sensitivity */
1106         gtk_widget_set_sensitive(checkbtn_scaling_auto,
1107                         prefs_common.enable_pixmap_scaling);
1108         gtk_widget_set_sensitive(spinbtn_scaling_ppi,
1109                         prefs_common.enable_pixmap_scaling
1110                                 && !prefs_common.pixmap_scaling_auto);
1111         gtk_widget_set_sensitive(label_scaling_ppi,
1112                         prefs_common.enable_pixmap_scaling
1113                                 && !prefs_common.pixmap_scaling_auto);
1114
1115         /* signals */
1116         g_signal_connect(G_OBJECT(checkbtn_enable_scaling), "toggled",
1117                          G_CALLBACK(prefs_themes_checkbtn_enable_scaling_toggled_cb),
1118                          prefs_themes);
1119         g_signal_connect(G_OBJECT(checkbtn_scaling_auto), "toggled",
1120                          G_CALLBACK(prefs_themes_checkbtn_scaling_auto_toggled_cb),
1121                          prefs_themes);
1122 #endif
1123
1124         g_signal_connect(G_OBJECT(btn_remove), "clicked",
1125                          G_CALLBACK(prefs_themes_btn_remove_clicked_cb),
1126                          NULL);
1127         g_signal_connect(G_OBJECT(btn_install), "clicked",
1128                          G_CALLBACK(prefs_themes_btn_install_clicked_cb),
1129                          NULL);
1130
1131         prefs_themes->window = GTK_WIDGET(window);
1132
1133         prefs_themes->name   = label_name;
1134         prefs_themes->author = label_author;
1135         prefs_themes->url    = label_url;
1136         prefs_themes->status = label_status;
1137         prefs_themes->global = label_global_status;
1138
1139         prefs_themes->icons[0] = icon_1;
1140         prefs_themes->icons[1] = icon_2;
1141         prefs_themes->icons[2] = icon_3;
1142         prefs_themes->icons[3] = icon_4;
1143         prefs_themes->icons[4] = icon_5;
1144         prefs_themes->icons[5] = icon_6;
1145         prefs_themes->icons[6] = icon_7;
1146
1147         prefs_themes->btn_remove  = btn_remove;
1148         prefs_themes->btn_install = btn_install;
1149         prefs_themes->btn_more    = btn_more;
1150
1151         prefs_themes->op_menu     = menu_themes;
1152
1153 #ifdef HAVE_SVG
1154         prefs_themes->checkbtn_enable_alpha   = checkbtn_enable_alpha;
1155         prefs_themes->checkbtn_enable_scaling = checkbtn_enable_scaling;
1156         prefs_themes->checkbtn_scaling_auto   = checkbtn_scaling_auto;
1157         prefs_themes->label_scaling_ppi       = label_scaling_ppi;
1158         prefs_themes->spinbtn_scaling_ppi     = spinbtn_scaling_ppi;
1159 #endif
1160
1161         prefs_themes->page.widget = vbox1;
1162         
1163         prefs_themes_set_themes_menu(GTK_COMBO_BOX(menu_themes), tdata);
1164         renderer = gtk_cell_renderer_text_new();
1165         gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(menu_themes), renderer, TRUE);
1166         gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(menu_themes), renderer,
1167                                         "text", 0, NULL);
1168
1169         prefs_themes_get_theme_info(tdata);
1170         prefs_themes_display_global_stats(tdata);
1171 }
1172
1173 static void prefs_themes_destroy_widget(PrefsPage *page)
1174 {
1175         /* ThemesPage *theme = (ThemesPage *)page; */
1176 }
1177
1178 static void prefs_themes_save(PrefsPage *page)
1179 {
1180         ThemesData *tdata = prefs_themes_data;
1181         gchar      *theme_str = tdata->displayed;
1182 #ifdef HAVE_SVG
1183         ThemesPage *tpage = (ThemesPage *) page;
1184         gboolean alpha = prefs_common.enable_alpha_svg;
1185         gboolean scaling = prefs_common.enable_pixmap_scaling;
1186         gboolean scaling_auto = prefs_common.pixmap_scaling_auto;
1187         gint scaling_ppi = prefs_common.pixmap_scaling_ppi;
1188
1189         prefs_common.enable_alpha_svg = gtk_toggle_button_get_active(
1190                 GTK_TOGGLE_BUTTON (tpage->checkbtn_enable_alpha));
1191         prefs_common.enable_pixmap_scaling = gtk_toggle_button_get_active(
1192                 GTK_TOGGLE_BUTTON (tpage->checkbtn_enable_scaling));
1193         prefs_common.pixmap_scaling_auto = gtk_toggle_button_get_active(
1194                 GTK_TOGGLE_BUTTON (tpage->checkbtn_scaling_auto));
1195         prefs_common.pixmap_scaling_ppi = gtk_spin_button_get_value_as_int (
1196                 GTK_SPIN_BUTTON (tpage->spinbtn_scaling_ppi));
1197 #endif
1198
1199         if (!IS_CURRENT_THEME(theme_str)) {
1200                 debug_print("Changing theme to %s\n", theme_str);
1201                 g_free(prefs_common.pixmap_theme_path);
1202
1203                 prefs_common.pixmap_theme_path = g_strdup(theme_str);
1204
1205                 main_window_reflect_prefs_all_real(TRUE);
1206                 compose_reflect_prefs_pixmap_theme();
1207                 addrcompl_reflect_prefs_pixmap_theme();
1208
1209                 prefs_themes_update_buttons(tdata);
1210         }
1211 #ifdef HAVE_SVG
1212         else if (scaling != prefs_common.enable_pixmap_scaling
1213                         || alpha != prefs_common.enable_alpha_svg
1214                         || (scaling_auto != prefs_common.pixmap_scaling_auto
1215                                 && scaling_ppi != prefs_common.pixmap_scaling_ppi)) {
1216                 /* same theme, different scaling options */
1217                 debug_print("Updating theme scaling\n");
1218                 stock_pixmap_invalidate_all_icons();
1219                 main_window_reflect_prefs_all_real(TRUE);
1220                 compose_reflect_prefs_pixmap_theme();
1221                 addrcompl_reflect_prefs_pixmap_theme();
1222         }
1223 #endif
1224 }
1225