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>
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.
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.
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.
29 #include <glib/gi18n.h>
31 /* Claws Mail includes */
32 #include <common/defs.h>
33 #include <prefs_gtk.h>
34 #include <mainwindow.h>
38 #include "rssyl_prefs.h"
39 #include "rssyl_feed.h"
41 static RPrefsPage rssyl_gtk_prefs_page;
44 static void destroy_rssyl_prefs_page(PrefsPage *page);
45 static void create_rssyl_prefs_page(PrefsPage *page,
46 GtkWindow *window, gpointer data);
47 static void save_rssyl_prefs(PrefsPage *page);
48 static void rssyl_apply_prefs(void);
50 static PrefParam param[] = {
51 { "refresh_interval", PREF_DEFAULT_REFRESH, &rssyl_prefs.refresh, P_INT,
53 { "refresh_on_startup", "FALSE", &rssyl_prefs.refresh_on_startup, P_BOOL,
55 { "refresh_enabled", "TRUE", &rssyl_prefs.refresh_enabled, P_BOOL,
57 { "cookies_path", "", &rssyl_prefs.cookies_path, P_STRING,
59 { "ssl_verify_peer", "TRUE", &rssyl_prefs.ssl_verify_peer, P_BOOL,
61 { 0, 0, 0, 0, 0, 0, 0 }
64 void rssyl_prefs_init(void)
66 static gchar *path[3];
69 path[0] = _("Plugins");
70 path[1] = "RSSyl"; /* We don't need this translated */
73 prefs_set_default(param);
74 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
75 prefs_read_config(param, PREFS_BLOCK_NAME, rcpath, NULL);
78 rssyl_gtk_prefs_page.page.path = path;
79 rssyl_gtk_prefs_page.page.create_widget = create_rssyl_prefs_page;
80 rssyl_gtk_prefs_page.page.destroy_widget = destroy_rssyl_prefs_page;
81 rssyl_gtk_prefs_page.page.save_page = save_rssyl_prefs;
82 rssyl_gtk_prefs_page.page.weight = 30.0;
84 prefs_gtk_register_page((PrefsPage *) &rssyl_gtk_prefs_page);
87 void rssyl_prefs_done(void)
89 prefs_gtk_unregister_page((PrefsPage *) &rssyl_gtk_prefs_page);
92 /* Toggle the refresh timeout spinbutton sensitivity after the
93 * checkbutton was toggled. */
95 rssyl_refresh_enabled_toggled_cb(GtkToggleButton *tb, gpointer data)
97 gtk_widget_set_sensitive(GTK_WIDGET(data),
98 gtk_toggle_button_get_active(tb));
102 static void create_rssyl_prefs_page(PrefsPage *page,
103 GtkWindow *window, gpointer data)
106 RPrefsPage *prefs_page = (RPrefsPage *) page;
108 GtkWidget *refresh, *refresh_enabled;
110 GtkWidget *refresh_on_startup;
111 GtkObject *refresh_adj;
112 GtkWidget *cookies_path;
113 GtkWidget *ssl_verify_peer;
114 #if !(GTK_CHECK_VERSION(2, 12, 0))
115 GtkTooltips *tooltips;
117 tooltips = gtk_tooltips_new();
118 gtk_tooltips_enable(tooltips);
121 table = gtk_table_new(3, 2, FALSE);
122 gtk_container_set_border_width(GTK_CONTAINER(table), 5);
123 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
124 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
126 /* Refresh interval */
127 refresh_enabled = gtk_check_button_new_with_label(
128 _("Default refresh interval in minutes"));
129 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(refresh_enabled),
130 rssyl_prefs.refresh_enabled);
131 gtk_table_attach(GTK_TABLE(table), refresh_enabled, 0, 1, row, row+1,
132 GTK_FILL | GTK_EXPAND, 0, 0, 0);
134 refresh_adj = gtk_adjustment_new(rssyl_prefs.refresh,
135 1, 100000, 1, 10, 0);
136 refresh = gtk_spin_button_new(GTK_ADJUSTMENT(refresh_adj), 1, 0);
137 gtk_widget_set_sensitive(GTK_WIDGET(refresh), rssyl_prefs.refresh_enabled);
138 gtk_table_attach(GTK_TABLE(table), refresh, 1, 2, row, row+1,
141 g_signal_connect(G_OBJECT(refresh_enabled), "toggled",
142 G_CALLBACK(rssyl_refresh_enabled_toggled_cb), refresh);
145 /* Whether to refresh all feeds on CM startup */
146 refresh_on_startup = gtk_check_button_new_with_label(
147 _("Refresh all feeds on application start"));
148 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(refresh_on_startup),
149 rssyl_prefs.refresh_on_startup);
150 gtk_table_attach(GTK_TABLE(table), refresh_on_startup, 0, 2, row, row+1,
151 GTK_FILL | GTK_EXPAND, 0, 0, 0);
154 /* Path to cookies file for libcurl to use */
155 label = gtk_label_new(_("Path to cookies file"));
156 gtk_table_attach(GTK_TABLE(table), label, 0, 1, row, row+1,
157 GTK_FILL | GTK_EXPAND, 0, 0, 0);
158 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
160 cookies_path = gtk_entry_new();
161 gtk_entry_set_text(GTK_ENTRY(cookies_path), rssyl_prefs.cookies_path);
162 gtk_table_attach(GTK_TABLE(table), cookies_path, 1, 2, row, row+1,
164 #if !(GTK_CHECK_VERSION(2, 12, 0))
165 gtk_tooltips_set_tip(tooltips, cookies_path,
166 _("Path to Netscape-style cookies.txt file containing your cookies"), NULL);
168 gtk_widget_set_tooltip_text(cookies_path,
169 _("Path to Netscape-style cookies.txt file containing your cookies"));
174 /* Whether to verify SSL peer certificate */
175 ssl_verify_peer = gtk_check_button_new_with_label(
176 _("Verify SSL certificates validity for new feeds"));
177 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ssl_verify_peer),
178 rssyl_prefs.ssl_verify_peer);
179 gtk_table_attach(GTK_TABLE(table), ssl_verify_peer, 0, 2, row, row+1,
180 GTK_FILL | GTK_EXPAND, 0, 0, 0);
182 gtk_widget_show_all(table);
184 /* Store pointers to relevant widgets */
185 prefs_page->page.widget = table;
186 prefs_page->refresh_enabled = refresh_enabled;
187 prefs_page->refresh = refresh;
188 prefs_page->refresh_on_startup = refresh_on_startup;
189 prefs_page->cookies_path = cookies_path;
190 prefs_page->ssl_verify_peer = ssl_verify_peer;
193 static void destroy_rssyl_prefs_page(PrefsPage *page)
198 static void save_rssyl_prefs(PrefsPage *page)
200 RPrefsPage *prefs_page = (RPrefsPage *)page;
202 gchar *rc_file_path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
205 /* Grab values from GTK widgets */
206 rssyl_prefs.refresh_enabled = gtk_toggle_button_get_active(
207 GTK_TOGGLE_BUTTON(prefs_page->refresh_enabled));
208 rssyl_prefs.refresh = gtk_spin_button_get_value_as_int(
209 GTK_SPIN_BUTTON(prefs_page->refresh));
210 rssyl_prefs.refresh_on_startup = gtk_toggle_button_get_active(
211 GTK_TOGGLE_BUTTON(prefs_page->refresh_on_startup));
212 g_free(rssyl_prefs.cookies_path);
213 rssyl_prefs.cookies_path = g_strdup(gtk_entry_get_text(
214 GTK_ENTRY(prefs_page->cookies_path)));
215 rssyl_prefs.ssl_verify_peer = gtk_toggle_button_get_active(
216 GTK_TOGGLE_BUTTON(prefs_page->ssl_verify_peer));
218 /* Store prefs in rc file */
219 pref_file = prefs_write_open(rc_file_path);
220 g_free(rc_file_path);
222 if( !pref_file || prefs_set_block_label(pref_file, PREFS_BLOCK_NAME) < 0 )
225 if( prefs_write_param(param, pref_file->fp) < 0 ) {
226 g_warning("Failed to write RSSyl plugin configuration\n");
227 prefs_file_close_revert(pref_file);
231 fprintf(pref_file->fp, "\n");
232 prefs_file_close(pref_file);
237 RPrefs *rssyl_prefs_get(void)
242 static void rssyl_start_default_refresh_timeouts_func(FolderItem *item,
245 RFolderItem *ritem = (RFolderItem *)item;
246 guint prefs_interval = GPOINTER_TO_UINT(data);
248 if( !IS_RSSYL_FOLDER_ITEM(item) )
251 if( folder_item_parent(item) == NULL || ritem->url == NULL )
254 /* Feeds which use default refresh interval */
255 if( ritem->default_refresh_interval ) {
256 /* Start a new timer if the default value has changed
257 * (ritem->refresh_interval should contain previous default
258 * value in this case). */
259 if( ritem->refresh_interval != prefs_interval ) {
260 ritem->refresh_interval = prefs_interval;
261 rssyl_feed_start_refresh_timeout(ritem);
266 static void rssyl_start_default_refresh_timeouts(void)
268 RPrefs *rsprefs = rssyl_prefs_get();
270 folder_func_to_all_folders(
271 (FolderItemFunc)rssyl_start_default_refresh_timeouts_func,
272 GUINT_TO_POINTER(rsprefs->refresh));
275 /* rssyl_apply_prefs():
276 * Do what's needed to start using newly set preferences */
277 static void rssyl_apply_prefs(void)
279 /* Update refresh timeouts for feeds which use default interval. */
280 rssyl_start_default_refresh_timeouts();
282 /* Nothing else here, so far... */