RSSyl: Allow use of .netrc by libcurl. Bug/enhancement #3309, by Vincent Pelletier
[claws.git] / src / plugins / fetchinfo / fetchinfo_plugin_gtk.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2003 Hiroyuki Yamamoto and the Claws Mail 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 3 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 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #  include "claws-features.h"
23 #endif
24
25 #include "defs.h"
26 #include "version.h"
27 #include "claws.h"
28
29 #include <glib.h>
30 #include <glib/gi18n.h>
31 #include <gtk/gtk.h>
32
33 #include "plugin.h"
34 #include "utils.h"
35 #include "prefs.h"
36 #include "prefs_gtk.h"
37
38 #include "fetchinfo_plugin.h"
39
40 struct FetchinfoPage
41 {
42         PrefsPage page;
43         
44         GtkWidget *fetchinfo_enable;
45         GtkWidget *fetchinfo_uidl;
46         GtkWidget *fetchinfo_account;
47         GtkWidget *fetchinfo_server;
48         GtkWidget *fetchinfo_userid;
49         GtkWidget *fetchinfo_time;
50 };
51
52 static void fetchinfo_set_sensitive(struct FetchinfoPage *page, gboolean enable)
53 {
54         gtk_widget_set_sensitive(GTK_WIDGET(page->fetchinfo_uidl), enable);
55         gtk_widget_set_sensitive(GTK_WIDGET(page->fetchinfo_account), enable);
56         gtk_widget_set_sensitive(GTK_WIDGET(page->fetchinfo_server), enable);
57         gtk_widget_set_sensitive(GTK_WIDGET(page->fetchinfo_userid), enable);
58         gtk_widget_set_sensitive(GTK_WIDGET(page->fetchinfo_time), enable);
59 }
60
61 static void fetchinfo_enable_cb(GtkWidget *widget, gpointer data)
62 {
63         struct FetchinfoPage *page = (struct FetchinfoPage *) data;
64
65         fetchinfo_set_sensitive(page, gtk_toggle_button_get_active(
66                 GTK_TOGGLE_BUTTON(page->fetchinfo_enable)));
67 }
68
69 #define ADD_NEW_CHECKBOX(line, button, text) \
70         button = gtk_check_button_new_with_label (text); \
71         gtk_widget_show (button); \
72         gtk_table_attach (GTK_TABLE (table), button, 1, 2, line, line+1, \
73                           (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), \
74                           (GtkAttachOptions) (0), 0, 0);
75
76 static void fetchinfo_create_widget_func(PrefsPage * _page, GtkWindow *window, gpointer data)
77 {
78         struct FetchinfoPage *page = (struct FetchinfoPage *) _page;
79         FetchinfoConfig *config;
80         GtkWidget *table;
81         GtkWidget *fetchinfo_enable;
82         GtkWidget *fetchinfo_uidl;
83         GtkWidget *fetchinfo_account;
84         GtkWidget *fetchinfo_server;
85         GtkWidget *fetchinfo_userid;
86         GtkWidget *fetchinfo_time;
87
88         table = gtk_table_new (6, 3, FALSE);
89         gtk_widget_show(table);
90         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
91         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
92
93         /* i18n: Heading of a preferences section determining which headers to add */
94         fetchinfo_enable = gtk_check_button_new_with_label (_("Add fetchinfo headers"));
95         gtk_widget_show (fetchinfo_enable);
96         gtk_table_attach (GTK_TABLE (table), fetchinfo_enable, 0, 2, 0, 1,
97                           (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
98                           (GtkAttachOptions) (0), 0, 0);
99
100         /* i18n: Description of a header to be added */
101         ADD_NEW_CHECKBOX(1, fetchinfo_uidl,     _("UIDL"));
102         /* i18n: Description of a header to be added */
103         ADD_NEW_CHECKBOX(2, fetchinfo_account,  _("Account name"));
104         /* i18n: Description of a header to be added */
105         ADD_NEW_CHECKBOX(3, fetchinfo_server,   _("Receive server"));
106         /* i18n: Description of a header to be added */
107         ADD_NEW_CHECKBOX(4, fetchinfo_userid,   _("UserID"));
108         /* i18n: Description of a header to be added */
109         ADD_NEW_CHECKBOX(5, fetchinfo_time,     _("Fetch time"));
110
111         config = fetchinfo_get_config();
112
113         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fetchinfo_enable),
114                                      config->fetchinfo_enable);
115         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fetchinfo_uidl),
116                                      config->fetchinfo_uidl);
117         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fetchinfo_account),
118                                      config->fetchinfo_account);
119         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fetchinfo_server),
120                                      config->fetchinfo_server);
121         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fetchinfo_userid),
122                                      config->fetchinfo_userid);
123         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fetchinfo_time),
124                                      config->fetchinfo_time);
125
126         g_signal_connect(G_OBJECT(fetchinfo_enable), "released",
127                          G_CALLBACK(fetchinfo_enable_cb), page);
128
129         page->fetchinfo_enable  = fetchinfo_enable;
130         page->fetchinfo_uidl    = fetchinfo_uidl;
131         page->fetchinfo_account = fetchinfo_account;
132         page->fetchinfo_server  = fetchinfo_server;
133         page->fetchinfo_userid  = fetchinfo_userid;
134         page->fetchinfo_time    = fetchinfo_time;
135
136         page->page.widget = table;
137
138         fetchinfo_set_sensitive(page, config->fetchinfo_enable);
139 }
140 #undef ADD_NEW_CHECKBOX
141
142 static void fetchinfo_destroy_widget_func(PrefsPage *_page)
143 {
144         debug_print("Destroying Fetchinfo widget\n");
145 }
146
147 static void fetchinfo_save_func(PrefsPage *_page)
148 {
149         struct FetchinfoPage *page = (struct FetchinfoPage *) _page;
150         FetchinfoConfig *config;
151
152         debug_print("Saving Fetchinfo Page\n");
153
154         config = fetchinfo_get_config();
155
156         config->fetchinfo_enable  = gtk_toggle_button_get_active(
157                 GTK_TOGGLE_BUTTON(page->fetchinfo_enable) );
158         config->fetchinfo_uidl    = gtk_toggle_button_get_active(
159                 GTK_TOGGLE_BUTTON(page->fetchinfo_uidl)   );
160         config->fetchinfo_account = gtk_toggle_button_get_active(
161                 GTK_TOGGLE_BUTTON(page->fetchinfo_account));
162         config->fetchinfo_server  = gtk_toggle_button_get_active(
163                 GTK_TOGGLE_BUTTON(page->fetchinfo_server) );
164         config->fetchinfo_userid  = gtk_toggle_button_get_active(
165                 GTK_TOGGLE_BUTTON(page->fetchinfo_userid) );
166         config->fetchinfo_time    = gtk_toggle_button_get_active(
167                 GTK_TOGGLE_BUTTON(page->fetchinfo_time)   );
168
169         fetchinfo_save_config();
170 }
171
172 static struct FetchinfoPage fetchinfo_page;
173
174 gint fetchinfo_gtk_init(void)
175 {
176         static gchar *path[3];
177
178         path[0] = _("Plugins");
179         path[1] = _("Fetchinfo");
180         path[2] = NULL;
181
182         fetchinfo_page.page.path = path;
183         fetchinfo_page.page.create_widget = fetchinfo_create_widget_func;
184         fetchinfo_page.page.destroy_widget = fetchinfo_destroy_widget_func;
185         fetchinfo_page.page.save_page = fetchinfo_save_func;
186         
187         prefs_gtk_register_page((PrefsPage *) &fetchinfo_page);
188
189         debug_print("Fetchinfo GTK plugin loaded\n");
190         return 0;       
191 }
192
193 void fetchinfo_gtk_done(void)
194 {
195         prefs_gtk_unregister_page((PrefsPage *) &fetchinfo_page);
196
197         debug_print("Fetchinfo GTK plugin unloaded\n");
198 }