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