Check for NULLs params within the functions
[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         stock_pixmap_themes_list_free(tdata->themes);
356         prefs_themes_free_names(tdata);
357
358         tdata->themes = stock_pixmap_themes_list_new();
359
360         tpaths = tdata->themes;
361         while (tpaths != NULL) {
362                 ThemeName *name = g_new0(ThemeName, 1);
363                 gchar *sname = g_path_get_basename((const gchar *)(tpaths->data));
364
365                 if (IS_INTERNAL_THEME(sname))
366                         name->name = g_strdup(_("Default internal theme"));
367                 else
368                         name->name = g_strdup(sname);
369                 name->item = tpaths;
370
371                 tdata->names = g_list_append(tdata->names, name);
372                 if (!strcmp2(tpaths->data, prefs_common.pixmap_theme_path)) {
373                         tdata->displayed = (gchar *)tpaths->data;
374                 }
375                 tpaths = g_list_next(tpaths);
376                 g_free(sname);  
377         }
378 }
379
380 void prefs_themes_init(void)
381 {
382         ThemesData   *tdata;
383         ThemesPage   *page;
384         GList        *tpaths;
385         static gchar *path[3];
386
387         path[0] = _("Display");
388         path[1] = _("Themes");
389         path[2] = NULL;
390
391         debug_print("Creating preferences for themes...\n");
392
393         tdata = g_new0(ThemesData, 1);
394         prefs_themes_data = tdata;
395
396         prefs_themes_get_themes_and_names(tdata);
397
398         page = g_new0(ThemesPage, 1);
399
400         page->page.path = path;
401         page->page.create_widget = prefs_themes_create_widget;
402         page->page.destroy_widget = prefs_themes_destroy_widget;
403         page->page.save_page = prefs_themes_save;
404         page->page.weight = 130.0;
405         prefs_gtk_register_page((PrefsPage *) page);
406
407         tdata->page = page;
408
409         tpaths = g_list_first(tdata->themes);
410         if (tdata->displayed == NULL)
411                 tdata->displayed = (gchar *)(tpaths->data);
412 #ifdef HAVE_SVG
413         if (prefs_common.pixmap_scaling_auto)
414                 prefs_common.pixmap_scaling_ppi = prefs_themes_get_adjusted_ppi();
415 #endif
416 }
417
418 static void prefs_themes_free_names(ThemesData *tdata)
419 {
420         GList *names;
421
422         cm_return_if_fail(tdata != NULL);
423         cm_return_if_fail(tdata->names != NULL);
424
425         names = tdata->names;
426         while (names != NULL) {
427                 ThemeName *tn = (ThemeName *)(names->data);
428
429                 tn->item = NULL;
430                 g_free(tn->name);
431                 g_free(tn);
432
433                 names = g_list_next(names);
434         }
435         g_list_free(tdata->names);
436         tdata->names = NULL;
437 }
438
439 void prefs_themes_done(void)
440 {
441         ThemesData *tdata = prefs_themes_data;
442
443         debug_print("Finished preferences for themes.\n");
444
445         stock_pixmap_themes_list_free(tdata->themes);
446         prefs_themes_free_names(tdata); 
447         g_free(tdata->page);
448         g_free(tdata);
449 }
450
451 static void prefs_themes_btn_remove_clicked_cb(GtkWidget *widget, gpointer data)
452 {
453         ThemesData *tdata = prefs_themes_data;
454         gchar      *theme_str;
455         gchar      *alert_title = NULL;
456         AlertValue  val = 0;
457         gchar      *tmp = NULL;
458
459         theme_str = tdata->displayed;
460
461         tmp = g_path_get_basename(theme_str);
462
463         if (IS_SYSTEM_THEME(theme_str)) {
464                 if (!superuser_p()) {
465                         alertpanel_error(_("Only root can remove system themes"));
466                         return;
467                 }
468                 alert_title = g_strdup_printf(_("Remove system theme '%s'"), tmp);
469         }
470         if (NULL == alert_title) {
471                 alert_title = g_strdup_printf(_("Remove theme '%s'"), tmp);
472         }
473
474         g_free(tmp);
475
476         val = alertpanel(alert_title,
477                          _("Are you sure you want to remove this theme?"),
478                          GTK_STOCK_NO, GTK_STOCK_YES, NULL);
479         g_free(alert_title);
480
481         if (G_ALERTALTERNATE == val) {
482                 gchar *status = NULL;
483
484                 prefs_themes_foreach_file(theme_str, prefs_themes_file_remove, &status); 
485                 if (0 != rmdir(theme_str)) {
486                         if (status != NULL) {
487                                 alertpanel_error(_("File %s failed\nwhile removing theme."), status);
488                                 g_free(status);
489                         }
490                         else
491                                 alertpanel_error(_("Removing theme directory failed."));
492                 }
493                 else {  
494                         alertpanel_notice(_("Theme removed successfully"));
495                         /* update interface back to first theme */
496                         prefs_themes_get_themes_and_names(tdata);
497                         prefs_themes_set_themes_menu(GTK_COMBO_BOX(tdata->page->op_menu), tdata);
498                         prefs_themes_display_global_stats(tdata);
499                         tdata->displayed = (gchar *)((g_list_first(tdata->themes))->data);
500                         prefs_themes_get_theme_info(tdata);
501                 }
502         }
503 }
504
505 static void prefs_themes_btn_install_clicked_cb(GtkWidget *widget, gpointer data)
506 {
507         gchar      *filename, *source;
508         gchar      *themeinfo, *themename;
509         gchar      *alert_title = NULL;
510         CopyInfo   *cinfo;
511         AlertValue  val = 0;
512         ThemesData *tdata = prefs_themes_data;
513
514         filename = filesel_select_file_open_folder(_("Select theme folder"), NULL);
515         if (filename == NULL) 
516                 return;
517
518         if (filename[strlen(filename) - 1] != G_DIR_SEPARATOR)
519                 filename = g_strconcat(filename, G_DIR_SEPARATOR_S, NULL);
520         else
521                 filename = g_strdup(filename);
522
523         cinfo = g_new0(CopyInfo, 1);
524         source = g_path_get_dirname(filename);
525         themename = g_path_get_basename(source);
526         debug_print("Installing '%s' theme from %s\n", themename, filename);
527
528         themeinfo = g_strconcat(source, G_DIR_SEPARATOR_S, THEMEINFO_FILE, NULL);
529         alert_title = g_strdup_printf(_("Install theme '%s'"), themename);
530         if (file_exist(themeinfo, FALSE) == FALSE) {
531                 val = alertpanel(alert_title,
532                                  _("This folder doesn't seem to be a theme folder.\nInstall anyway?"),
533                                  GTK_STOCK_NO, GTK_STOCK_YES, NULL);
534                 if (G_ALERTALTERNATE != val)
535                         goto end_inst;
536         }
537         if (superuser_p ()) {
538                 val = alertpanel(alert_title,
539                                  _("Do you want to install theme for all users?"),
540                                  GTK_STOCK_NO, GTK_STOCK_YES, NULL);
541                 switch (val) {
542                 case G_ALERTALTERNATE:
543                         cinfo->dest = stock_pixmap_get_system_theme_dir_for_theme(
544                                                 themename);
545                         break;
546                 case G_ALERTDEFAULT:
547                         break;
548                 default:
549                         goto end_inst;
550                 }
551         }
552         g_free(alert_title);
553         if (cinfo->dest == NULL) {
554                 cinfo->dest = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
555                                           PIXMAP_THEME_DIR, G_DIR_SEPARATOR_S,
556                                           themename, NULL);
557         }
558         if (TRUE == is_dir_exist(cinfo->dest)) {
559                 AlertValue val = alertpanel_full(_("Theme exists"),
560                                 _("A theme with the same name is\nalready installed in this location.\n\n"
561                                   "Do you want to replace it?"),
562                                 GTK_STOCK_CANCEL, _("Overwrite"), NULL, FALSE,
563                                 NULL, ALERT_WARNING, G_ALERTDEFAULT);
564                 if (val == G_ALERTALTERNATE) {
565                         if (remove_dir_recursive(cinfo->dest) < 0) {
566                                 alertpanel_error(_("Couldn't delete the old theme in %s."), cinfo->dest);
567                                 goto end_inst;
568                         }
569                 } else {
570                         goto end_inst;
571                 }
572         }
573         if (0 != make_dir_hier(cinfo->dest)) {
574                 alertpanel_error(_("Couldn't create destination directory %s."), cinfo->dest);
575                 goto end_inst;
576         }
577         prefs_themes_foreach_file(source, prefs_themes_file_install, cinfo);
578         if (cinfo->status == NULL) {
579                 GList *insted;
580
581                 /* update interface to show newly installed theme */
582                 prefs_themes_get_themes_and_names(tdata);
583                 insted = g_list_find_custom(tdata->themes, 
584                                             (gpointer)(cinfo->dest), 
585                                             (GCompareFunc)strcmp2);
586                 if (NULL != insted) {
587                         alertpanel_notice(_("Theme installed successfully."));
588                         tdata->displayed = (gchar *)(insted->data);
589                         prefs_themes_set_themes_menu(GTK_COMBO_BOX(tdata->page->op_menu), tdata);
590                         prefs_themes_display_global_stats(tdata);
591                         prefs_themes_get_theme_info(tdata);
592                 }
593                 else
594                         alertpanel_error(_("Failed installing theme"));
595         }
596         else
597                 alertpanel_error(_("File %s failed\nwhile installing theme."), cinfo->status);
598 end_inst:
599         g_free(cinfo->dest);
600         g_free(filename);
601         g_free(source);
602         g_free(themeinfo);
603         g_free(cinfo);
604         g_free(themename);
605 }
606
607 static void prefs_themes_menu_item_activated_cb(GtkWidget *widget, gpointer data)
608 {
609         ThemesData *tdata = prefs_themes_data;
610         gchar      *path;
611         GtkTreeModel *model;
612         GtkTreeIter iter;
613
614         cm_return_if_fail(gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget), &iter));
615
616         model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
617         gtk_tree_model_get(model, &iter, 1, &path, -1);
618
619         tdata->displayed = path;
620         prefs_themes_get_theme_info(tdata);
621 }
622
623 #ifdef HAVE_SVG
624 #define MM_INCH 0.0393700787402
625 static gdouble prefs_themes_compute_ppi(GdkScreen *screen)
626 {
627         gdouble wp = gdk_screen_get_width(screen);
628         gdouble hp = gdk_screen_get_height(screen);
629         gdouble wi = gdk_screen_get_width_mm(screen);
630         gdouble hi = gdk_screen_get_height_mm(screen);
631         gdouble dp, di;
632
633         debug_print("screen is %f x %f pixels, %f x %f mm\n", wp, hp, wi, hi);
634
635         /* https://en.wikipedia.org/wiki/Pixel_density */
636         wi *= MM_INCH;
637         hi *= MM_INCH;
638         dp = sqrt(wp * wp + hp * hp);
639         di = sqrt(wi * wi + hi * hi);
640
641         return (di != 0.0)? dp / di: 0.0;
642 }
643
644 static gdouble prefs_themes_get_adjusted_ppi(void)
645 {
646         gdouble ppi, cppi;
647         GdkScreen * screen = gdk_screen_get_default();
648
649         if (screen == NULL) { /* oops! */
650                 g_warning("unable to get default GDK screen");
651                 return MIN_PPI;
652         }
653
654         ppi = gdk_screen_get_resolution(screen);
655         cppi = prefs_themes_compute_ppi(screen);
656         debug_print("returned PPI: %f / computed PPI: %f\n", ppi, cppi);
657         /*
658          gdk_screen_get_resolution doesn't seem to work well when running
659          on a remote display and returns the value of the local display.
660          height/width functions do this better, so we can compute a PPI
661          from them and take the highest value.
662         */
663         return MAX(ppi, cppi);
664 }
665
666 static void prefs_themes_checkbtn_enable_scaling_toggled_cb (GtkWidget *widget, gpointer data)
667 {
668         ThemesPage *page = (ThemesPage *) data;
669         gboolean enabled = gtk_toggle_button_get_active(
670                                 GTK_TOGGLE_BUTTON (widget));
671         gboolean automatic = gtk_toggle_button_get_active(
672                                 GTK_TOGGLE_BUTTON (page->checkbtn_scaling_auto));
673
674         gtk_widget_set_sensitive(page->checkbtn_scaling_auto, enabled);
675         gtk_widget_set_sensitive(page->spinbtn_scaling_ppi, enabled && !automatic);
676         gtk_widget_set_sensitive(page->label_scaling_ppi, enabled && !automatic);
677 }
678
679 static void prefs_themes_checkbtn_scaling_auto_toggled_cb(GtkWidget *widget, gpointer data)
680 {
681         ThemesPage *page = (ThemesPage *) data;
682         gboolean automatic = gtk_toggle_button_get_active(
683                                 GTK_TOGGLE_BUTTON (widget));
684
685         gtk_widget_set_sensitive(page->spinbtn_scaling_ppi, !automatic);
686         gtk_widget_set_sensitive(page->label_scaling_ppi, !automatic);
687
688         if (automatic) /* update PPI value */
689                 gtk_spin_button_set_value(
690                                 GTK_SPIN_BUTTON (page->spinbtn_scaling_ppi),
691                                 prefs_themes_get_adjusted_ppi());
692 }
693 #endif
694
695 static void prefs_themes_update_buttons(const ThemesData *tdata)
696 {
697         ThemesPage *theme = tdata->page;
698         gboolean    can_rem, can_use;
699
700         can_use = !IS_CURRENT_THEME(tdata->displayed);
701         can_rem = can_use && !IS_INTERNAL_THEME(tdata->displayed);
702
703         if (theme->btn_remove != NULL)
704                 gtk_widget_set_sensitive(theme->btn_remove, can_rem);
705 }
706
707 /* placeholders may already be utf8 (i18n) */
708 #define SET_LABEL_TEXT_UTF8(label, text)                                \
709 {                                                                       \
710         gchar *tmpstr;                                                  \
711                                                                         \
712         if (!g_utf8_validate(text, -1, NULL))                           \
713                 tmpstr = conv_codeset_strdup(text,                      \
714                         conv_get_locale_charset_str(),  CS_UTF_8);      \
715         else                                                            \
716                 tmpstr = g_strdup(text);                                \
717                                                                         \
718         gtk_label_set_text(GTK_LABEL(label), tmpstr);                   \
719         gtk_label_set_selectable(GTK_LABEL(label), TRUE);               \
720         g_free(tmpstr);                                                 \
721 }
722 static void prefs_themes_display_theme_info(ThemesData *tdata, const ThemeInfo *info)
723 {
724         ThemesPage *theme = tdata->page;
725         gchar *save_prefs_path;
726         gint   i;
727
728         SET_LABEL_TEXT_UTF8(theme->name,        info->name);
729         SET_LABEL_TEXT_UTF8(theme->author,      info->author);
730         SET_LABEL_TEXT_UTF8(theme->url,         info->url);
731         SET_LABEL_TEXT_UTF8(theme->status,      info->status);
732
733         save_prefs_path = prefs_common.pixmap_theme_path;
734         prefs_common.pixmap_theme_path = tdata->displayed;
735         for (i = 0; i < PREVIEW_ICONS; ++i) {
736                 stock_pixbuf_gdk(prefs_themes_icons[i], &(theme->pixbufs[i]));
737                 gtk_image_set_from_pixbuf(GTK_IMAGE(theme->icons[i]),
738                                 theme->pixbufs[i]);
739         }
740         prefs_common.pixmap_theme_path = save_prefs_path;
741
742         prefs_themes_update_buttons(tdata);
743 }
744 #undef SET_LABEL_TEXT_UTF8
745
746 static void prefs_themes_display_global_stats(const ThemesData *tdata)
747 {
748         ThemesPage *theme = tdata->page;
749         GList      *tnames = tdata->names;
750         gchar      *gstats;
751         gint        sys = 0;
752         gint        usr = 0;
753         gint        all = 0;
754
755         while (tnames != NULL) {
756                 ThemeName *tname = (ThemeName *)(tnames->data);
757                 gchar     *tpath = (gchar *)(tname->item->data);
758                 
759                 if (IS_SYSTEM_THEME(tpath)) 
760                         ++sys;
761                 else if (!IS_INTERNAL_THEME(tpath)) 
762                         ++usr;
763                 ++all;
764                 tnames = g_list_next(tnames);
765         }
766
767         gstats = g_strdup_printf(_("%d themes available (%d user, %d system, 1 internal)"),
768                                  all, usr, sys);
769         gtk_label_set_text(GTK_LABEL(theme->global), gstats);
770         gtk_label_set_justify (GTK_LABEL (theme->global), GTK_JUSTIFY_LEFT);
771         gtkut_widget_set_small_font_size (theme->global);
772         g_free(gstats);
773 }
774
775 #define INFOFILE_LINE_LEN 80
776
777 #define FGETS_INFOFILE_LINE() \
778         line[0] = '\0'; \
779         if (fgets(line, INFOFILE_LINE_LEN, finfo) != NULL && (len = strlen(line)) > 0) { \
780                 if (line[len - 1] == '\n') line[len - 1] = '\0'; \
781         } \
782         else { \
783                 g_strlcpy(line, _("Unknown"),sizeof(line)); \
784         }
785
786 static void prefs_themes_get_theme_info(ThemesData *tdata)
787 {
788         FILE  *finfo;
789         gchar *sinfo;
790         gchar *path;
791         gchar  line[INFOFILE_LINE_LEN];
792         gint   len;
793         ThemeInfo *info;
794         ThemesPage *theme = tdata->page;
795
796         cm_return_if_fail(theme != NULL);
797         path = tdata->displayed;
798         cm_return_if_fail(path != NULL);
799
800         debug_print("Getting theme info for %s\n", path);
801
802         info = g_new0(ThemeInfo, 1);
803
804         if (IS_INTERNAL_THEME(path)) {
805                 info->name = g_strdup(_("Default internal theme"));
806                 info->author = g_strdup(_("The Claws Mail Team"));
807                 info->url = g_strdup(HOMEPAGE_URI);
808                 info->status = g_strdup_printf(_("Internal theme has %d icons"), N_STOCK_PIXMAPS);
809         }
810         else {
811                 sinfo = g_strconcat(path, G_DIR_SEPARATOR_S, THEMEINFO_FILE, NULL);
812                 finfo = g_fopen(sinfo, "r");
813                 if (finfo == NULL) {
814                         info->name = g_strdup(_("No info file available for this theme"));
815                         info->author = g_strdup(_("Unknown"));
816                         info->url = g_strdup(_("Unknown"));
817                 }
818                 else {
819                         FGETS_INFOFILE_LINE()
820                         info->name = g_strdup(line);
821                         FGETS_INFOFILE_LINE()
822                         info->author = g_strdup(line);
823                         FGETS_INFOFILE_LINE()
824                         info->url = g_strdup(line);
825                 
826                         fclose(finfo);
827                 }
828                 g_free(sinfo);
829
830                 info->status = prefs_themes_get_theme_stats(path);
831                 if (info->status == NULL) {
832                         info->status = g_strdup(_("Error: couldn't get theme status"));
833                 }
834         }
835
836         prefs_themes_display_theme_info(tdata, info);
837
838         g_free(info->name);
839         g_free(info->author);
840         g_free(info->url);
841         g_free(info->status);
842
843         g_free(info);
844 }
845
846 #undef FGETS_INFOFILE_LINE
847
848 static gchar *prefs_themes_get_theme_stats(const gchar *dirname)
849 {
850         gchar   *stats;
851         DirInfo *dinfo;
852         gint     i;
853
854         dinfo = g_new0(DirInfo, 1);
855         dinfo->supported = stock_pixmap_theme_extensions();
856         for (i = 0; (dinfo->supported)[i] != NULL; ++i);
857         dinfo->length = g_malloc(i * sizeof(gint));
858         for (i = 0; (dinfo->supported)[i] != NULL; ++i) {
859                 (dinfo->length)[i] = strlen((dinfo->supported)[i]);
860         }
861         prefs_themes_foreach_file(dirname, prefs_themes_file_stats, dinfo);
862         stats = g_strdup_printf(_("%d files (%d icons), size: %s"),
863                                 dinfo->files, dinfo->pixms,
864                                 to_human_readable((goffset)dinfo->bytes));
865         g_free(dinfo->length);
866         g_free(dinfo);
867         return stats;
868 }
869
870 static void prefs_themes_create_widget(PrefsPage *page, GtkWindow *window, gpointer data)
871 {
872         ThemesPage *prefs_themes = (ThemesPage *)page;
873         ThemesData *tdata = prefs_themes_data;
874
875         GtkWidget *vbox1;
876         GtkWidget *frame1;
877         GtkWidget *vbox2;
878         GtkWidget *hbox3;
879         GtkWidget *menu_themes;
880         GtkWidget *btn_install;
881         GtkWidget *btn_more;
882         GtkWidget *label_global_status;
883         GtkWidget *frame_info;
884         GtkWidget *table1;
885         GtkWidget *label1;
886         GtkWidget *label2;
887         GtkWidget *label3;
888         GtkWidget *label_name;
889         GtkWidget *label_author;
890         GtkWidget *label_url;
891         GtkWidget *label4;
892         GtkWidget *label_status;
893         GtkWidget *frame_preview;
894         GtkWidget *hbox1;
895         GtkWidget *icon_1;
896         GtkWidget *icon_2;
897         GtkWidget *icon_3;
898         GtkWidget *icon_4;
899         GtkWidget *icon_5;
900         GtkWidget *icon_6;
901         GtkWidget *icon_7;
902         GtkWidget *frame_buttons;
903         GtkWidget *hbuttonbox1;
904         GtkWidget *btn_remove;
905         GtkCellRenderer *renderer;
906 #ifdef HAVE_SVG
907         GtkWidget *frame_scaling;
908         GtkWidget *checkbtn_enable_alpha;
909         GtkWidget *checkbtn_enable_scaling;
910         GtkWidget *checkbtn_scaling_auto;
911         GtkWidget *label_scaling_ppi;
912         GtkWidget *spinbtn_scaling_ppi;
913         GtkAdjustment *spinbtn_scaling_ppi_adj;
914 #endif
915
916         vbox1 = gtk_vbox_new (FALSE, VSPACING);
917         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
918         gtk_widget_show (vbox1);
919
920         vbox2 = gtkut_get_options_frame(vbox1, &frame1, _("Selector"));
921
922         hbox3 = gtk_hbox_new (FALSE, 5);
923         gtk_widget_show (hbox3);
924         gtk_box_pack_start (GTK_BOX (vbox2), hbox3, FALSE, FALSE, 0);
925         gtk_container_set_border_width (GTK_CONTAINER (hbox3), 5);
926
927         menu_themes = gtk_combo_box_new();
928         gtk_widget_show (menu_themes);
929         gtk_box_pack_start (GTK_BOX (hbox3), menu_themes, FALSE, FALSE, 0);
930
931         btn_install = gtk_button_new_with_label (_("Install new..."));
932         gtk_widget_show (btn_install);
933         gtk_box_pack_start (GTK_BOX (hbox3), btn_install, FALSE, FALSE, 0);
934         gtkut_widget_set_can_default (btn_install, TRUE);
935
936         btn_more = gtkut_get_link_btn((GtkWidget *)window, THEMES_URI, _("Get more..."));
937         gtk_widget_show (btn_more);
938         gtk_box_pack_start (GTK_BOX (hbox3), btn_more, FALSE, FALSE, 0);
939
940         label_global_status = gtk_label_new ("");
941         gtk_widget_show (label_global_status);
942         gtk_box_pack_start (GTK_BOX (vbox2), label_global_status, FALSE, FALSE, 0);
943         gtk_label_set_justify (GTK_LABEL (label_global_status), GTK_JUSTIFY_LEFT);
944         gtk_misc_set_alignment (GTK_MISC (label_global_status), 0, 0.5);
945         gtk_misc_set_padding (GTK_MISC (label_global_status), 6, 0);
946
947         PACK_FRAME(vbox1, frame_info, _("Information"));
948
949         table1 = gtk_table_new (4, 2, FALSE);
950         gtk_widget_show (table1);
951         gtk_container_add (GTK_CONTAINER (frame_info), table1);
952
953         label1 = gtk_label_new (_("Name: "));
954         gtk_widget_show (label1);
955         gtk_table_attach (GTK_TABLE (table1), label1, 0, 1, 0, 1,
956                         (GtkAttachOptions) (GTK_FILL),
957                         (GtkAttachOptions) (0), 8, 2);
958         gtk_label_set_justify (GTK_LABEL (label1), GTK_JUSTIFY_LEFT);
959         gtk_misc_set_alignment (GTK_MISC (label1), 0, 0.5);
960
961         label2 = gtk_label_new (_("Author: "));
962         gtk_widget_show (label2);
963         gtk_table_attach (GTK_TABLE (table1), label2, 0, 1, 1, 2,
964                         (GtkAttachOptions) (GTK_FILL),
965                         (GtkAttachOptions) (0), 8, 2);
966         gtk_label_set_justify (GTK_LABEL (label2), GTK_JUSTIFY_LEFT);
967         gtk_misc_set_alignment (GTK_MISC (label2), 0, 0.5);
968
969         label3 = gtk_label_new (_("URL:"));
970         gtk_widget_show (label3);
971         gtk_table_attach (GTK_TABLE (table1), label3, 0, 1, 2, 3,
972                         (GtkAttachOptions) (GTK_FILL),
973                         (GtkAttachOptions) (0), 8, 2);
974         gtk_misc_set_alignment (GTK_MISC (label3), 0, 0.5);
975
976         label_name = gtk_label_new ("");
977         gtk_widget_show (label_name);
978         gtk_table_attach (GTK_TABLE (table1), label_name, 1, 2, 0, 1,
979                         (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
980                         (GtkAttachOptions) (0), 0, 0);
981         gtk_misc_set_alignment (GTK_MISC (label_name), 0, 0.5);
982
983         label_author = gtk_label_new ("");
984         gtk_widget_show (label_author);
985         gtk_table_attach (GTK_TABLE (table1), label_author, 1, 2, 1, 2,
986                         (GtkAttachOptions) (GTK_FILL),
987                         (GtkAttachOptions) (0), 0, 0);
988         gtk_misc_set_alignment (GTK_MISC (label_author), 0, 0.5);
989
990         label_url = gtk_label_new ("");
991         gtk_widget_show (label_url);
992         gtk_table_attach (GTK_TABLE (table1), label_url, 1, 2, 2, 3,
993                         (GtkAttachOptions) (GTK_FILL),
994                         (GtkAttachOptions) (0), 0, 0);
995         gtk_misc_set_alignment (GTK_MISC (label_url), 0, 0.5);
996
997         label4 = gtk_label_new (_("Status:"));
998         gtk_widget_show (label4);
999         gtk_table_attach (GTK_TABLE (table1), label4, 0, 1, 3, 4,
1000                         (GtkAttachOptions) (GTK_FILL),
1001                         (GtkAttachOptions) (0), 8, 2);
1002         gtk_misc_set_alignment (GTK_MISC (label4), 0, 0.5);
1003
1004         label_status = gtk_label_new ("");
1005         gtk_widget_show (label_status);
1006         gtk_table_attach (GTK_TABLE (table1), label_status, 1, 2, 3, 4,
1007                         (GtkAttachOptions) (GTK_FILL),
1008                         (GtkAttachOptions) (0), 0, 0);
1009         gtk_misc_set_alignment (GTK_MISC (label_status), 0, 0.5);
1010
1011         PACK_FRAME(vbox1, frame_preview, _("Preview"));
1012
1013         hbox1 = gtk_hbox_new (FALSE, 0);
1014         gtk_widget_show (hbox1);
1015         gtk_container_add (GTK_CONTAINER (frame_preview), hbox1);
1016
1017         icon_1 = gtk_image_new();
1018         gtk_widget_show (icon_1);
1019         gtk_box_pack_start (GTK_BOX (hbox1), icon_1, TRUE, TRUE, 2);
1020         gtk_misc_set_padding (GTK_MISC (icon_1), 0, 5);
1021
1022         icon_2 = gtk_image_new();
1023         gtk_widget_show (icon_2);
1024         gtk_box_pack_start (GTK_BOX (hbox1), icon_2, TRUE, TRUE, 2);
1025         gtk_misc_set_padding (GTK_MISC (icon_2), 0, 5);
1026
1027         icon_3 = gtk_image_new();
1028         gtk_widget_show (icon_3);
1029         gtk_box_pack_start (GTK_BOX (hbox1), icon_3, TRUE, TRUE, 2);
1030         gtk_misc_set_padding (GTK_MISC (icon_3), 0, 5);
1031
1032         icon_4 = gtk_image_new();
1033         gtk_widget_show (icon_4);
1034         gtk_box_pack_start (GTK_BOX (hbox1), icon_4, TRUE, TRUE, 2);
1035         gtk_misc_set_padding (GTK_MISC (icon_4), 0, 5);
1036
1037         icon_5 = gtk_image_new();
1038         gtk_widget_show (icon_5);
1039         gtk_box_pack_start (GTK_BOX (hbox1), icon_5, TRUE, TRUE, 2);
1040         gtk_misc_set_padding (GTK_MISC (icon_5), 0, 5);
1041
1042         icon_6 = gtk_image_new();
1043         gtk_widget_show (icon_6);
1044         gtk_box_pack_start (GTK_BOX (hbox1), icon_6, TRUE, TRUE, 0);
1045         gtk_misc_set_padding (GTK_MISC (icon_6), 0, 5);
1046
1047         icon_7 = gtk_image_new();
1048         gtk_widget_show (icon_7);
1049         gtk_box_pack_start (GTK_BOX (hbox1), icon_7, TRUE, TRUE, 0);
1050         gtk_misc_set_padding (GTK_MISC (icon_7), 0, 5);
1051
1052         PACK_FRAME(vbox1, frame_buttons, _("Actions"));
1053
1054         hbuttonbox1 = gtk_hbutton_box_new ();
1055         gtk_widget_show (hbuttonbox1);
1056         gtk_container_add (GTK_CONTAINER (frame_buttons), hbuttonbox1);
1057         gtk_container_set_border_width (GTK_CONTAINER (hbuttonbox1), 5);
1058         gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox1), GTK_BUTTONBOX_START);
1059         gtk_box_set_spacing (GTK_BOX (hbuttonbox1), 5);
1060
1061         btn_remove = gtk_button_new_with_label (_("Remove"));
1062         gtk_widget_show (btn_remove);
1063         gtk_container_add (GTK_CONTAINER (hbuttonbox1), btn_remove);
1064         gtkut_widget_set_can_default (btn_remove, TRUE);
1065
1066 #ifdef HAVE_SVG
1067         PACK_FRAME(vbox1, frame_scaling, _("SVG rendering"));
1068
1069         vbox2 = gtk_vbox_new (FALSE, VSPACING);
1070         gtk_widget_show (vbox2);
1071         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 5);
1072         gtk_container_add (GTK_CONTAINER (frame_scaling), vbox2);
1073
1074         PACK_CHECK_BUTTON(vbox2, checkbtn_enable_alpha, _("Enable alpha channel"));
1075         PACK_CHECK_BUTTON(vbox2, checkbtn_enable_scaling, _("Force scaling"));
1076         PACK_CHECK_BUTTON(vbox2, checkbtn_scaling_auto, _("Automatic"));
1077
1078         hbox3 = gtk_hbox_new (FALSE, 5);
1079         gtk_widget_show (hbox3);
1080
1081         label_scaling_ppi = gtk_label_new (_("Pixels per inch (PPI)"));
1082         gtk_widget_show (label_scaling_ppi);
1083         gtk_box_pack_start (GTK_BOX (hbox3), label_scaling_ppi,
1084                         FALSE, FALSE, 5);
1085
1086         spinbtn_scaling_ppi_adj = GTK_ADJUSTMENT(
1087                 gtk_adjustment_new (MIN_PPI, MIN_PPI, MAX_PPI, 1, 10, 0));
1088         spinbtn_scaling_ppi = gtk_spin_button_new(
1089                         spinbtn_scaling_ppi_adj, 1.0, 0);
1090         gtk_widget_show (spinbtn_scaling_ppi);
1091         gtk_box_pack_start (GTK_BOX (hbox3), spinbtn_scaling_ppi,
1092                         FALSE, FALSE, 5);
1093
1094         gtk_box_pack_start (GTK_BOX (vbox2), hbox3, FALSE, FALSE, 0);
1095
1096         /* initialize widget values */
1097         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (checkbtn_enable_alpha),
1098                         prefs_common.enable_alpha_svg);
1099         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (checkbtn_enable_scaling),
1100                         prefs_common.enable_pixmap_scaling);
1101         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (checkbtn_scaling_auto),
1102                         prefs_common.pixmap_scaling_auto);
1103         gtk_spin_button_set_value(GTK_SPIN_BUTTON (spinbtn_scaling_ppi),
1104                         prefs_common.pixmap_scaling_ppi);
1105
1106         /* sensitivity */
1107         gtk_widget_set_sensitive(checkbtn_scaling_auto,
1108                         prefs_common.enable_pixmap_scaling);
1109         gtk_widget_set_sensitive(spinbtn_scaling_ppi,
1110                         prefs_common.enable_pixmap_scaling
1111                                 && !prefs_common.pixmap_scaling_auto);
1112         gtk_widget_set_sensitive(label_scaling_ppi,
1113                         prefs_common.enable_pixmap_scaling
1114                                 && !prefs_common.pixmap_scaling_auto);
1115
1116         /* signals */
1117         g_signal_connect(G_OBJECT(checkbtn_enable_scaling), "toggled",
1118                          G_CALLBACK(prefs_themes_checkbtn_enable_scaling_toggled_cb),
1119                          prefs_themes);
1120         g_signal_connect(G_OBJECT(checkbtn_scaling_auto), "toggled",
1121                          G_CALLBACK(prefs_themes_checkbtn_scaling_auto_toggled_cb),
1122                          prefs_themes);
1123 #endif
1124
1125         g_signal_connect(G_OBJECT(btn_remove), "clicked",
1126                          G_CALLBACK(prefs_themes_btn_remove_clicked_cb),
1127                          NULL);
1128         g_signal_connect(G_OBJECT(btn_install), "clicked",
1129                          G_CALLBACK(prefs_themes_btn_install_clicked_cb),
1130                          NULL);
1131
1132         prefs_themes->window = GTK_WIDGET(window);
1133
1134         prefs_themes->name   = label_name;
1135         prefs_themes->author = label_author;
1136         prefs_themes->url    = label_url;
1137         prefs_themes->status = label_status;
1138         prefs_themes->global = label_global_status;
1139
1140         prefs_themes->icons[0] = icon_1;
1141         prefs_themes->icons[1] = icon_2;
1142         prefs_themes->icons[2] = icon_3;
1143         prefs_themes->icons[3] = icon_4;
1144         prefs_themes->icons[4] = icon_5;
1145         prefs_themes->icons[5] = icon_6;
1146         prefs_themes->icons[6] = icon_7;
1147
1148         prefs_themes->btn_remove  = btn_remove;
1149         prefs_themes->btn_install = btn_install;
1150         prefs_themes->btn_more    = btn_more;
1151
1152         prefs_themes->op_menu     = menu_themes;
1153
1154 #ifdef HAVE_SVG
1155         prefs_themes->checkbtn_enable_alpha   = checkbtn_enable_alpha;
1156         prefs_themes->checkbtn_enable_scaling = checkbtn_enable_scaling;
1157         prefs_themes->checkbtn_scaling_auto   = checkbtn_scaling_auto;
1158         prefs_themes->label_scaling_ppi       = label_scaling_ppi;
1159         prefs_themes->spinbtn_scaling_ppi     = spinbtn_scaling_ppi;
1160 #endif
1161
1162         prefs_themes->page.widget = vbox1;
1163         
1164         prefs_themes_set_themes_menu(GTK_COMBO_BOX(menu_themes), tdata);
1165         renderer = gtk_cell_renderer_text_new();
1166         gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(menu_themes), renderer, TRUE);
1167         gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(menu_themes), renderer,
1168                                         "text", 0, NULL);
1169
1170         prefs_themes_get_theme_info(tdata);
1171         prefs_themes_display_global_stats(tdata);
1172 }
1173
1174 static void prefs_themes_destroy_widget(PrefsPage *page)
1175 {
1176         /* ThemesPage *theme = (ThemesPage *)page; */
1177 }
1178
1179 static void prefs_themes_save(PrefsPage *page)
1180 {
1181         ThemesData *tdata = prefs_themes_data;
1182         gchar      *theme_str = tdata->displayed;
1183 #ifdef HAVE_SVG
1184         ThemesPage *tpage = (ThemesPage *) page;
1185         gboolean alpha = prefs_common.enable_alpha_svg;
1186         gboolean scaling = prefs_common.enable_pixmap_scaling;
1187         gboolean scaling_auto = prefs_common.pixmap_scaling_auto;
1188         gint scaling_ppi = prefs_common.pixmap_scaling_ppi;
1189
1190         prefs_common.enable_alpha_svg = gtk_toggle_button_get_active(
1191                 GTK_TOGGLE_BUTTON (tpage->checkbtn_enable_alpha));
1192         prefs_common.enable_pixmap_scaling = gtk_toggle_button_get_active(
1193                 GTK_TOGGLE_BUTTON (tpage->checkbtn_enable_scaling));
1194         prefs_common.pixmap_scaling_auto = gtk_toggle_button_get_active(
1195                 GTK_TOGGLE_BUTTON (tpage->checkbtn_scaling_auto));
1196         prefs_common.pixmap_scaling_ppi = gtk_spin_button_get_value_as_int (
1197                 GTK_SPIN_BUTTON (tpage->spinbtn_scaling_ppi));
1198 #endif
1199
1200         if (!IS_CURRENT_THEME(theme_str)) {
1201                 debug_print("Changing theme to %s\n", theme_str);
1202                 g_free(prefs_common.pixmap_theme_path);
1203
1204                 prefs_common.pixmap_theme_path = g_strdup(theme_str);
1205
1206                 main_window_reflect_prefs_all_real(TRUE);
1207                 compose_reflect_prefs_pixmap_theme();
1208                 addrcompl_reflect_prefs_pixmap_theme();
1209
1210                 prefs_themes_update_buttons(tdata);
1211         }
1212 #ifdef HAVE_SVG
1213         else if (scaling != prefs_common.enable_pixmap_scaling
1214                         || alpha != prefs_common.enable_alpha_svg
1215                         || (scaling_auto != prefs_common.pixmap_scaling_auto
1216                                 && scaling_ppi != prefs_common.pixmap_scaling_ppi)) {
1217                 /* same theme, different scaling options */
1218                 debug_print("Updating theme scaling\n");
1219                 stock_pixmap_invalidate_all_icons();
1220                 main_window_reflect_prefs_all_real(TRUE);
1221                 compose_reflect_prefs_pixmap_theme();
1222                 addrcompl_reflect_prefs_pixmap_theme();
1223         }
1224 #endif
1225 }
1226