Fix english
[claws.git] / src / plugins / rssyl / rssyl_prefs.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2004 Hiroyuki Yamamoto
4  * This file (C) 2005 Andrej Kacian <andrej@kacian.sk>
5  *
6  * - Plugin preferences
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #  include "config.h"
25 #include "claws-features.h"
26 #endif
27
28 #include <glib.h>
29 #include <glib/gi18n.h>
30
31 #include "common/defs.h"
32 #include "common/utils.h"
33 #include "gtk/gtkutils.h"
34 #include "prefs_gtk.h"
35
36 #include "rssyl_prefs.h"
37
38 static RSSylPrefsPage rssyl_prefs_page;
39 RSSylPrefs rssyl_prefs;
40
41 static void destroy_rssyl_prefs_page(PrefsPage *page);
42 static void create_rssyl_prefs_page(PrefsPage *page,
43                 GtkWindow *window, gpointer data);
44 static void save_rssyl_prefs(PrefsPage *page);
45
46 static PrefParam param[] = {
47         { "refresh_interval", RSSYL_PREF_DEFAULT_REFRESH, &rssyl_prefs.refresh, P_INT,
48                 NULL, NULL, NULL },
49         { "expired_keep", RSSYL_PREF_DEFAULT_EXPIRED, &rssyl_prefs.expired, P_INT,
50                 NULL, NULL, NULL },
51         { "refresh_on_startup", "FALSE", &rssyl_prefs.refresh_on_startup, P_BOOL,
52                 NULL, NULL, NULL },
53         { "cookies_path", "", &rssyl_prefs.cookies_path, P_STRING,
54                 NULL, NULL, NULL },
55         { "ssl_verify_peer", "TRUE", &rssyl_prefs.ssl_verify_peer, P_BOOL,
56                 NULL, NULL, NULL },
57         { 0, 0, 0, 0, 0, 0, 0 }
58 };
59
60 void rssyl_prefs_init(void)
61 {
62         static gchar *path[3];
63         gchar *rcpath;
64
65         path[0] = _("Plugins");
66         path[1] = "RSSyl";              /* We don't need this translated */
67         path[2] = NULL;
68
69         prefs_set_default(param);
70         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
71         prefs_read_config(param, PREFS_BLOCK_NAME, rcpath, NULL);
72         g_free(rcpath);
73
74         rssyl_prefs_page.page.path = path;
75         rssyl_prefs_page.page.create_widget = create_rssyl_prefs_page;
76         rssyl_prefs_page.page.destroy_widget = destroy_rssyl_prefs_page;
77         rssyl_prefs_page.page.save_page = save_rssyl_prefs;
78         rssyl_prefs_page.page.weight = 30.0;
79
80         prefs_gtk_register_page((PrefsPage *) &rssyl_prefs_page);
81 }
82
83 void rssyl_prefs_done(void)
84 {
85         prefs_gtk_unregister_page((PrefsPage *) &rssyl_prefs_page);
86 }
87
88 static void create_rssyl_prefs_page(PrefsPage *page,
89                 GtkWindow *window, gpointer data)
90 {
91         RSSylPrefsPage *prefs_page = (RSSylPrefsPage *) page;
92         GtkWidget *table;
93         GtkWidget *refresh;
94         GtkWidget *expired;
95         GtkWidget *refresh_on_startup;
96         GtkWidget *cookies_path;
97         GtkWidget *ssl_verify_peer_checkbtn;
98         GtkWidget *label;
99         GtkObject *refresh_adj, *expired_adj;
100
101         table = gtk_table_new(RSSYL_NUM_PREFS, 2, FALSE);
102         gtk_container_set_border_width(GTK_CONTAINER(table), 6);
103         gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
104         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
105
106         label = gtk_label_new(_("Default refresh interval in minutes"));
107         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
108         gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1,
109                         GTK_FILL, 0, 0, 0);
110
111         refresh_adj = gtk_adjustment_new(rssyl_prefs.refresh,
112                         0, 100000, 1, 10, 0);
113         refresh = gtk_spin_button_new(GTK_ADJUSTMENT(refresh_adj), 1, 0);
114         gtk_table_attach(GTK_TABLE(table), refresh, 1, 2, 0, 1,
115                         GTK_FILL, 0, 0, 0);
116         CLAWS_SET_TIP(refresh,
117                         _("Set to 0 to disable automatic refreshing"));
118
119         label = gtk_label_new(_("Default number of expired items to keep"));
120         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
121         gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
122                         GTK_FILL, 0, 0, 0);
123
124         expired_adj = gtk_adjustment_new(rssyl_prefs.expired,
125                         -1, 100000, 1, 10, 0);
126         expired = gtk_spin_button_new(GTK_ADJUSTMENT(expired_adj), 1, 0);
127         gtk_table_attach(GTK_TABLE(table), expired, 1, 2, 1, 2,
128                         GTK_FILL, 0, 0, 0);
129         CLAWS_SET_TIP(expired,
130                         _("Set to -1 to keep expired items"));
131
132         refresh_on_startup = gtk_check_button_new_with_label(
133                         _("Refresh all feeds on application start"));
134         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(refresh_on_startup),
135                         rssyl_prefs.refresh_on_startup);
136         gtk_table_attach(GTK_TABLE(table), refresh_on_startup, 0, 2, 3, 4,
137                         GTK_FILL | GTK_EXPAND, 0, 0, 0);
138
139         label = gtk_label_new(_("Path to cookies file"));
140         gtk_table_attach(GTK_TABLE(table), label, 0, 1, 4, 5,
141                         GTK_FILL, 0, 0, 0);
142         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
143
144         cookies_path = gtk_entry_new ();
145         gtk_entry_set_text(GTK_ENTRY(cookies_path), rssyl_prefs.cookies_path);
146         gtk_table_attach(GTK_TABLE(table), cookies_path, 1, 2, 4, 5,
147                         GTK_FILL | GTK_EXPAND, 0, 0, 0);
148         CLAWS_SET_TIP(cookies_path,
149                         _("Path to Netscape-style cookies.txt file containing your cookies"));
150
151         ssl_verify_peer_checkbtn = gtk_check_button_new_with_label(
152                         _("Verify SSL certificate validity for new feeds"));
153         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ssl_verify_peer_checkbtn),
154                         rssyl_prefs.ssl_verify_peer);
155         gtk_table_attach(GTK_TABLE(table), ssl_verify_peer_checkbtn, 0, 2, 5, 6,
156                         GTK_FILL | GTK_EXPAND, 0, 0, 0);
157
158         gtk_widget_show_all(table);
159
160         prefs_page->page.widget = table;
161         prefs_page->refresh = refresh;
162         prefs_page->expired = expired;
163         prefs_page->refresh_on_startup = refresh_on_startup;
164         prefs_page->cookies_path = cookies_path;
165         prefs_page->ssl_verify_peer_checkbtn = ssl_verify_peer_checkbtn;
166 }
167
168 static void destroy_rssyl_prefs_page(PrefsPage *page)
169 {
170         /* Do nothing! */
171 }
172
173 static void save_rssyl_prefs(PrefsPage *page)
174 {
175         RSSylPrefsPage *prefs_page = (RSSylPrefsPage *)page;
176         PrefFile *pref_file;
177         gchar *rc_file_path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
178                         COMMON_RC, NULL);
179
180         rssyl_prefs.refresh = gtk_spin_button_get_value_as_int(
181                         GTK_SPIN_BUTTON(prefs_page->refresh));
182         rssyl_prefs.expired = gtk_spin_button_get_value_as_int(
183                         GTK_SPIN_BUTTON(prefs_page->expired));
184         rssyl_prefs.refresh_on_startup = gtk_toggle_button_get_active(
185                         GTK_TOGGLE_BUTTON(prefs_page->refresh_on_startup));
186         g_free(rssyl_prefs.cookies_path);
187         rssyl_prefs.cookies_path = g_strdup(gtk_entry_get_text(
188                         GTK_ENTRY(prefs_page->cookies_path)));
189         rssyl_prefs.ssl_verify_peer = gtk_toggle_button_get_active(
190                         GTK_TOGGLE_BUTTON(prefs_page->ssl_verify_peer_checkbtn));
191
192         pref_file = prefs_write_open(rc_file_path);
193         g_free(rc_file_path);
194
195         if( !pref_file || prefs_set_block_label(pref_file, PREFS_BLOCK_NAME) < 0 )
196                                 return;
197
198         if( prefs_write_param(param, pref_file->fp) < 0 ) {
199                 g_warning("Failed to write RSSyl plugin configuration\n");
200                 prefs_file_close_revert(pref_file);
201                 return;
202         }
203
204         if (fprintf(pref_file->fp, "\n") < 0) {
205                 FILE_OP_ERROR(rc_file_path, "fprintf");
206                 prefs_file_close_revert(pref_file);
207         } else
208                 prefs_file_close(pref_file);
209 }
210
211 RSSylPrefs *rssyl_prefs_get(void)
212 {
213         return &rssyl_prefs;
214 }