2006-04-07 [paul] 2.1.0cvs13
[claws.git] / src / plugins / dillo_viewer / dillo_prefs.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws 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 2 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, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 /*
21  * The structure of this file has been borrowed from the structure of
22  * the image_viewer plugin file. I also used it as an example of how to
23  * build the preferences for the dillo plugin.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 #  include "config.h"
28 #endif
29
30 #include "defs.h"
31
32 #include <glib.h>
33 #include <glib/gi18n.h>
34 #include <gtk/gtk.h>
35
36 #include "gtkutils.h"
37 #include "utils.h"
38 #include "prefs.h"
39 #include "prefs_gtk.h"
40 #include "prefswindow.h"
41
42 #include "dillo_prefs.h"
43
44 #define PREFS_BLOCK_NAME "Dillo"
45
46 DilloBrowserPrefs dillo_prefs;
47
48 typedef struct _DilloBrowserPage DilloBrowserPage;
49
50 struct _DilloBrowserPage {
51         PrefsPage page;
52         GtkWidget *local;
53         GtkWidget *full;
54 };
55
56 static PrefParam param[] = {
57         {"local_browse", "TRUE", &dillo_prefs.local, P_BOOL, NULL, NULL, NULL},
58         {"full_window", "TRUE", &dillo_prefs.full, P_BOOL, NULL, NULL, NULL},
59         {0,0,0,0,0,0,0}
60 };
61
62 static DilloBrowserPage prefs_page;
63
64 static void create_dillo_prefs_page     (PrefsPage *page,
65                                          GtkWindow *window,
66                                          gpointer   data);
67 static void destroy_dillo_prefs_page    (PrefsPage *page);
68 static void save_dillo_prefs            (PrefsPage *page);
69
70 void dillo_prefs_init(void)
71 {
72         static gchar *path[3];
73         gchar *rcpath;
74
75         path[0] = _("Plugins");
76         path[1] = _("Dillo Browser");
77         path[2] = NULL;
78
79         prefs_set_default(param);
80         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
81         prefs_read_config(param, PREFS_BLOCK_NAME, rcpath, NULL);
82         g_free(rcpath);
83         
84         prefs_page.page.path = path;
85         prefs_page.page.create_widget = create_dillo_prefs_page;
86         prefs_page.page.destroy_widget = destroy_dillo_prefs_page;
87         prefs_page.page.save_page = save_dillo_prefs;
88
89         prefs_gtk_register_page((PrefsPage *) &prefs_page);
90 }
91
92 void dillo_prefs_done(void)
93 {
94         prefs_gtk_unregister_page((PrefsPage *) &prefs_page);
95 }
96
97 static void create_dillo_prefs_page(PrefsPage *page,
98                                     GtkWindow *window,
99                                     gpointer data)
100 {
101         DilloBrowserPage *prefs_page = (DilloBrowserPage *) page;
102
103         GtkWidget *vbox;
104         GtkWidget *local_checkbox;
105         GtkWidget *full_checkbox;
106         GtkWidget *label;
107         GtkTooltips *local_tooltip;
108         GtkTooltips *full_tooltip;
109
110         vbox = gtk_vbox_new(FALSE, 3);
111         gtk_container_set_border_width(GTK_CONTAINER(vbox), VBOX_BORDER);
112         gtk_widget_show(vbox);
113         
114         local_tooltip = gtk_tooltips_new();
115         local_checkbox = gtk_check_button_new_with_label
116                                 (_("Do not load remote links in mails"));
117         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(local_checkbox),
118                                      dillo_prefs.local);
119         gtk_box_pack_start(GTK_BOX(vbox), local_checkbox, FALSE, FALSE, 0);
120         gtk_widget_show(local_checkbox);
121         gtk_tooltips_set_tip(GTK_TOOLTIPS(local_tooltip), local_checkbox,
122                              _("Equivalent to Dillo's '--local' option"), NULL);
123         
124         label = gtk_label_new(_("You can still load remote links "
125                               "by reloading the page"));
126         gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
127         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
128         gtkut_widget_set_small_font_size (label);
129         gtk_widget_show(label);
130
131         full_tooltip = gtk_tooltips_new();
132         full_checkbox = gtk_check_button_new_with_label
133                                 (_("Full window mode (hide controls)"));
134         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(full_checkbox),
135                                       dillo_prefs.full);
136         gtk_box_pack_start(GTK_BOX(vbox), full_checkbox, FALSE, FALSE, 0);
137         gtk_widget_show(full_checkbox);
138         gtk_tooltips_set_tip(GTK_TOOLTIPS(full_tooltip), full_checkbox,
139                              _("Equivalent to Dillo's '--fullwindow' option"),
140                              NULL);
141         
142         prefs_page->local = local_checkbox;
143         prefs_page->full = full_checkbox;
144         prefs_page->page.widget = vbox;
145 }
146
147 static void destroy_dillo_prefs_page(PrefsPage *page)
148 {
149         /* Do nothing! */
150 }
151
152 static void save_dillo_prefs(PrefsPage *page)
153 {
154         DilloBrowserPage *prefs_page = (DilloBrowserPage *) page;
155         PrefFile *pref_file;
156         gchar *rc_file_path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
157                                           COMMON_RC, NULL);
158         
159         dillo_prefs.local = gtk_toggle_button_get_active
160                                 (GTK_TOGGLE_BUTTON(prefs_page->local));
161         dillo_prefs.full = gtk_toggle_button_get_active
162                                 (GTK_TOGGLE_BUTTON(prefs_page->full));
163         
164         pref_file = prefs_write_open(rc_file_path);
165         g_free(rc_file_path);
166         
167         if (!(pref_file) ||
168             (prefs_set_block_label(pref_file, PREFS_BLOCK_NAME) < 0))
169           return;
170         
171         if (prefs_write_param(param, pref_file->fp) < 0) {
172           g_warning("failed to write Dillo Plugin configuration\n");
173           prefs_file_close_revert(pref_file);
174           return;
175         }
176         fprintf(pref_file->fp, "\n");
177         prefs_file_close(pref_file);
178 }