2005-02-01 [paul] 1.0.0cvs24.2
[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-2003 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 <gtk/gtk.h>
34
35 #include "intl.h"
36 #include "utils.h"
37 #include "prefs.h"
38 #include "prefs_gtk.h"
39 #include "prefswindow.h"
40
41 #include "dillo_prefs.h"
42
43 #define PREFS_BLOCK_NAME "Dillo"
44
45 DilloBrowserPrefs dillo_prefs;
46
47 typedef struct _DilloBrowserPage DilloBrowserPage;
48
49 struct _DilloBrowserPage {
50         PrefsPage page;
51         GtkWidget *local;
52         GtkWidget *full;
53 };
54
55 static PrefParam param[] = {
56         {"local_browse", "TRUE", &dillo_prefs.local, P_BOOL, NULL, NULL, NULL},
57         {"full_window", "TRUE", &dillo_prefs.full, P_BOOL, NULL, NULL, NULL},
58         {0,0,0,0,0,0,0}
59 };
60
61 DilloBrowserPage prefs_page;
62
63 static void create_dillo_prefs_page     (PrefsPage *page,
64                                          GtkWindow *window,
65                                          gpointer   data);
66 static void destroy_dillo_prefs_page    (PrefsPage *page);
67 static void save_dillo_prefs            (PrefsPage *page);
68
69 void dillo_prefs_init(void)
70 {
71         static gchar *path[3];
72         gchar *rcpath;
73
74         path[0] = _("Message View");
75         path[1] = _("Dillo Browser");
76         path[2] = NULL;
77
78         prefs_set_default(param);
79         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
80         prefs_read_config(param, PREFS_BLOCK_NAME, rcpath, NULL);
81         g_free(rcpath);
82         
83         prefs_page.page.path = path;
84         prefs_page.page.create_widget = create_dillo_prefs_page;
85         prefs_page.page.destroy_widget = destroy_dillo_prefs_page;
86         prefs_page.page.save_page = save_dillo_prefs;
87         
88         prefs_gtk_register_page((PrefsPage *) &prefs_page);
89 }
90
91 void dillo_prefs_done(void)
92 {
93         prefs_gtk_unregister_page((PrefsPage *) &prefs_page);
94 }
95
96 static void create_dillo_prefs_page(PrefsPage *page,
97                                     GtkWindow *window,
98                                     gpointer data)
99 {
100         DilloBrowserPage *prefs_page = (DilloBrowserPage *) page;
101
102         GtkWidget *vbox;
103         GtkWidget *local_checkbox;
104         GtkWidget *full_checkbox;
105         GtkWidget *label;
106         GtkTooltips *local_tooltip;
107         GtkTooltips *full_tooltip;
108
109         vbox = gtk_vbox_new(FALSE, 3);
110         gtk_container_set_border_width(GTK_CONTAINER(vbox), 3);
111         gtk_widget_show(vbox);
112         
113         local_tooltip = gtk_tooltips_new();
114         local_checkbox = gtk_check_button_new_with_label
115                                 (_("Do not load remote links in mails"));
116         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(local_checkbox),
117                                      dillo_prefs.local);
118         gtk_box_pack_start(GTK_BOX(vbox), local_checkbox, FALSE, FALSE, 0);
119         gtk_widget_show(local_checkbox);
120         gtk_tooltips_set_tip(GTK_TOOLTIPS(local_tooltip), local_checkbox,
121                              _("Equivalent to Dillo's '--local' option"), NULL);
122         
123         label = gtk_label_new(_("You can still load remote links "
124                               "by reloading the page"));
125         gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
126         gtk_widget_show(label);
127
128         full_tooltip = gtk_tooltips_new();
129         full_checkbox = gtk_check_button_new_with_label
130                                 (_("Full window mode (hide controls)"));
131         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(full_checkbox),
132                                       dillo_prefs.full);
133         gtk_box_pack_start(GTK_BOX(vbox), full_checkbox, FALSE, FALSE, 0);
134         gtk_widget_show(full_checkbox);
135         gtk_tooltips_set_tip(GTK_TOOLTIPS(full_tooltip), full_checkbox,
136                              _("Equivalent to Dillo's '--fullwindow' option"),
137                              NULL);
138         
139         prefs_page->local = local_checkbox;
140         prefs_page->full = full_checkbox;
141         prefs_page->page.widget = vbox;
142 }
143
144 static void destroy_dillo_prefs_page(PrefsPage *page)
145 {
146         /* Do nothing! */
147 }
148
149 static void save_dillo_prefs(PrefsPage *page)
150 {
151         DilloBrowserPage *prefs_page = (DilloBrowserPage *) page;
152         PrefFile *pref_file;
153         gchar *rc_file_path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
154                                           COMMON_RC, NULL);
155         
156         dillo_prefs.local = gtk_toggle_button_get_active
157                                 (GTK_TOGGLE_BUTTON(prefs_page->local));
158         dillo_prefs.full = gtk_toggle_button_get_active
159                                 (GTK_TOGGLE_BUTTON(prefs_page->full));
160         
161         pref_file = prefs_write_open(rc_file_path);
162         g_free(rc_file_path);
163         
164         if (!(pref_file) ||
165             (prefs_set_block_label(pref_file, PREFS_BLOCK_NAME) < 0))
166           return;
167         
168         if (prefs_write_param(param, pref_file->fp) < 0) {
169           g_warning("failed to write Dillo Plugin configuration\n");
170           prefs_file_close_revert(pref_file);
171           return;
172         }
173         fprintf(pref_file->fp, "\n");
174         prefs_file_close(pref_file);
175 }