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.
25 #include "claws-features.h"
29 #include <glib/gi18n.h>
31 #include "common/defs.h"
32 #include "common/utils.h"
33 #include "gtk/gtkutils.h"
34 #include "prefs_gtk.h"
36 #include "rssyl_prefs.h"
38 static RSSylPrefsPage rssyl_prefs_page;
39 RSSylPrefs rssyl_prefs;
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);
46 static PrefParam param[] = {
47 { "refresh_interval", RSSYL_PREF_DEFAULT_REFRESH, &rssyl_prefs.refresh, P_INT,
49 { "expired_keep", RSSYL_PREF_DEFAULT_EXPIRED, &rssyl_prefs.expired, P_INT,
51 { "refresh_on_startup", FALSE, &rssyl_prefs.refresh_on_startup, P_BOOL,
53 { "cookies_path", "", &rssyl_prefs.cookies_path, P_STRING,
55 { 0, 0, 0, 0, 0, 0, 0 }
58 void rssyl_prefs_init(void)
60 static gchar *path[3];
63 path[0] = _("Plugins");
64 path[1] = "RSSyl"; /* We don't need this translated */
67 prefs_set_default(param);
68 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
69 prefs_read_config(param, PREFS_BLOCK_NAME, rcpath, NULL);
72 rssyl_prefs_page.page.path = path;
73 rssyl_prefs_page.page.create_widget = create_rssyl_prefs_page;
74 rssyl_prefs_page.page.destroy_widget = destroy_rssyl_prefs_page;
75 rssyl_prefs_page.page.save_page = save_rssyl_prefs;
76 rssyl_prefs_page.page.weight = 30.0;
78 prefs_gtk_register_page((PrefsPage *) &rssyl_prefs_page);
81 void rssyl_prefs_done(void)
83 prefs_gtk_unregister_page((PrefsPage *) &rssyl_prefs_page);
86 static void create_rssyl_prefs_page(PrefsPage *page,
87 GtkWindow *window, gpointer data)
89 RSSylPrefsPage *prefs_page = (RSSylPrefsPage *) page;
93 GtkWidget *refresh_on_startup;
94 GtkWidget *cookies_path;
96 GtkObject *refresh_adj, *expired_adj;
98 table = gtk_table_new(RSSYL_NUM_PREFS, 2, FALSE);
99 gtk_container_set_border_width(GTK_CONTAINER(table), 5);
100 gtk_table_set_row_spacings(GTK_TABLE(table), VSPACING_NARROW);
101 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
103 label = gtk_label_new(_("Default refresh interval in minutes"));
104 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
105 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1,
108 refresh_adj = gtk_adjustment_new(rssyl_prefs.refresh,
109 0, 100000, 1, 10, 0);
110 refresh = gtk_spin_button_new(GTK_ADJUSTMENT(refresh_adj), 1, 0);
111 gtk_table_attach(GTK_TABLE(table), refresh, 1, 2, 0, 1,
113 CLAWS_SET_TIP(refresh,
114 _("Set to 0 to disable automatic refreshing"));
116 label = gtk_label_new(_("Default number of expired items to keep"));
117 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
118 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
121 expired_adj = gtk_adjustment_new(rssyl_prefs.expired,
122 -1, 100000, 1, 10, 0);
123 expired = gtk_spin_button_new(GTK_ADJUSTMENT(expired_adj), 1, 0);
124 gtk_table_attach(GTK_TABLE(table), expired, 1, 2, 1, 2,
126 CLAWS_SET_TIP(expired,
127 _("Set to -1 to keep expired items"));
129 refresh_on_startup = gtk_check_button_new_with_label(
130 _("Refresh all feeds on application start"));
131 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(refresh_on_startup),
132 rssyl_prefs.refresh_on_startup);
133 gtk_table_attach(GTK_TABLE(table), refresh_on_startup, 0, 2, 3, 4,
134 GTK_FILL | GTK_EXPAND, 0, 0, 0);
136 label = gtk_label_new(_("Path to cookies file"));
137 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 4, 5,
139 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
141 cookies_path = gtk_entry_new ();
142 gtk_entry_set_text(GTK_ENTRY(cookies_path), rssyl_prefs.cookies_path);
143 gtk_table_attach(GTK_TABLE(table), cookies_path, 1, 2, 4, 5,
144 GTK_FILL | GTK_EXPAND, 0, 0, 0);
145 CLAWS_SET_TIP(cookies_path,
146 _("Path to Netscape-style cookies.txt file containing your cookies"));
148 gtk_widget_show_all(table);
150 prefs_page->page.widget = table;
151 prefs_page->refresh = refresh;
152 prefs_page->expired = expired;
153 prefs_page->refresh_on_startup = refresh_on_startup;
154 prefs_page->cookies_path = cookies_path;
157 static void destroy_rssyl_prefs_page(PrefsPage *page)
162 static void save_rssyl_prefs(PrefsPage *page)
164 RSSylPrefsPage *prefs_page = (RSSylPrefsPage *)page;
166 gchar *rc_file_path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
169 rssyl_prefs.refresh = gtk_spin_button_get_value_as_int(
170 GTK_SPIN_BUTTON(prefs_page->refresh));
171 rssyl_prefs.expired = gtk_spin_button_get_value_as_int(
172 GTK_SPIN_BUTTON(prefs_page->expired));
173 rssyl_prefs.refresh_on_startup = gtk_toggle_button_get_active(
174 GTK_TOGGLE_BUTTON(prefs_page->refresh_on_startup));
175 g_free(rssyl_prefs.cookies_path);
176 rssyl_prefs.cookies_path = g_strdup(gtk_entry_get_text(
177 GTK_ENTRY(prefs_page->cookies_path)));
179 pref_file = prefs_write_open(rc_file_path);
180 g_free(rc_file_path);
182 if( !pref_file || prefs_set_block_label(pref_file, PREFS_BLOCK_NAME) < 0 )
185 if( prefs_write_param(param, pref_file->fp) < 0 ) {
186 g_warning("Failed to write RSSyl plugin configuration\n");
187 prefs_file_close_revert(pref_file);
191 if (fprintf(pref_file->fp, "\n") < 0) {
192 FILE_OP_ERROR(rc_file_path, "fprintf");
193 prefs_file_close_revert(pref_file);
195 prefs_file_close(pref_file);
198 RSSylPrefs *rssyl_prefs_get(void)