Fetchinfo: slightly improve prefs, add hints
[claws.git] / src / plugins / fetchinfo / fetchinfo_plugin_gtk.c
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2015 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(button, text, tip) \
70         button = gtk_check_button_new_with_label (text); \
71         gtk_widget_show (button); \
72         gtk_box_pack_start(GTK_BOX(hdr_vbox), button, FALSE, FALSE, 0); \
73         gtk_widget_set_tooltip_text(GTK_WIDGET(button), tip);
74
75 static void fetchinfo_create_widget_func(PrefsPage * _page, GtkWindow *window, gpointer data)
76 {
77         struct FetchinfoPage *page = (struct FetchinfoPage *) _page;
78         FetchinfoConfig *config;
79         GtkWidget *vbox, *frame, *hdr_vbox;
80         GtkWidget *fetchinfo_enable;
81         GtkWidget *fetchinfo_uidl;
82         GtkWidget *fetchinfo_account;
83         GtkWidget *fetchinfo_server;
84         GtkWidget *fetchinfo_userid;
85         GtkWidget *fetchinfo_time;
86
87         vbox = gtk_vbox_new(FALSE, 0);
88         gtk_container_set_border_width(GTK_CONTAINER(vbox), 10);
89         gtk_widget_show(vbox);
90
91         /* i18n: Heading of a preferences section determining which headers to add */
92         fetchinfo_enable = gtk_check_button_new_with_label (_("Add fetchinfo headers"));
93         gtk_widget_show (fetchinfo_enable);
94         gtk_box_pack_start(GTK_BOX(vbox), fetchinfo_enable, FALSE, FALSE, 5);
95
96         PACK_FRAME (vbox, frame, _("Headers to be added"))
97
98         hdr_vbox = gtk_vbox_new(FALSE, 0);
99         gtk_widget_show(hdr_vbox);
100         gtk_container_add(GTK_CONTAINER(frame), hdr_vbox);
101         gtk_container_set_border_width(GTK_CONTAINER(hdr_vbox), 8);
102
103         /* i18n: Description of a header to be added */
104         ADD_NEW_CHECKBOX(fetchinfo_uidl, _("UIDL"), _("Adds the X-FETCH-UIDL header with the unique ID listing of message (POP3)"));
105         /* i18n: Description of a header to be added */
106         ADD_NEW_CHECKBOX(fetchinfo_account, _("Account name"), _("Adds the X-FETCH-ACCOUNT header with the account name"));
107         /* i18n: Description of a header to be added */
108         ADD_NEW_CHECKBOX(fetchinfo_server, _("Receive server"), _("Adds the X-FETCH-SERVER header with the receive server"));
109         /* i18n: Description of a header to be added */
110         ADD_NEW_CHECKBOX(fetchinfo_userid, _("UserID"), _("Adds the X-FETCH-USERID header with the user ID"));
111         /* i18n: Description of a header to be added */
112         ADD_NEW_CHECKBOX(fetchinfo_time, _("Fetch time"), _("Adds the X-FETCH-TIME header with the date and time of message retrieval in RFC822 format"));
113
114         config = fetchinfo_get_config();
115
116         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fetchinfo_enable),
117                                      config->fetchinfo_enable);
118         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fetchinfo_uidl),
119                                      config->fetchinfo_uidl);
120         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fetchinfo_account),
121                                      config->fetchinfo_account);
122         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fetchinfo_server),
123                                      config->fetchinfo_server);
124         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fetchinfo_userid),
125                                      config->fetchinfo_userid);
126         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(fetchinfo_time),
127                                      config->fetchinfo_time);
128
129         g_signal_connect(G_OBJECT(fetchinfo_enable), "released",
130                          G_CALLBACK(fetchinfo_enable_cb), page);
131
132         page->fetchinfo_enable  = fetchinfo_enable;
133         page->fetchinfo_uidl    = fetchinfo_uidl;
134         page->fetchinfo_account = fetchinfo_account;
135         page->fetchinfo_server  = fetchinfo_server;
136         page->fetchinfo_userid  = fetchinfo_userid;
137         page->fetchinfo_time    = fetchinfo_time;
138
139         page->page.widget = vbox;
140
141         fetchinfo_set_sensitive(page, config->fetchinfo_enable);
142 }
143 #undef ADD_NEW_CHECKBOX
144
145 static void fetchinfo_destroy_widget_func(PrefsPage *_page)
146 {
147         debug_print("Destroying Fetchinfo widget\n");
148 }
149
150 static void fetchinfo_save_func(PrefsPage *_page)
151 {
152         struct FetchinfoPage *page = (struct FetchinfoPage *) _page;
153         FetchinfoConfig *config;
154
155         debug_print("Saving Fetchinfo Page\n");
156
157         config = fetchinfo_get_config();
158
159         config->fetchinfo_enable  = gtk_toggle_button_get_active(
160                 GTK_TOGGLE_BUTTON(page->fetchinfo_enable) );
161         config->fetchinfo_uidl    = gtk_toggle_button_get_active(
162                 GTK_TOGGLE_BUTTON(page->fetchinfo_uidl)   );
163         config->fetchinfo_account = gtk_toggle_button_get_active(
164                 GTK_TOGGLE_BUTTON(page->fetchinfo_account));
165         config->fetchinfo_server  = gtk_toggle_button_get_active(
166                 GTK_TOGGLE_BUTTON(page->fetchinfo_server) );
167         config->fetchinfo_userid  = gtk_toggle_button_get_active(
168                 GTK_TOGGLE_BUTTON(page->fetchinfo_userid) );
169         config->fetchinfo_time    = gtk_toggle_button_get_active(
170                 GTK_TOGGLE_BUTTON(page->fetchinfo_time)   );
171
172         fetchinfo_save_config();
173 }
174
175 static struct FetchinfoPage fetchinfo_page;
176
177 gint fetchinfo_gtk_init(void)
178 {
179         static gchar *path[3];
180
181         path[0] = _("Plugins");
182         path[1] = _("Fetchinfo");
183         path[2] = NULL;
184
185         fetchinfo_page.page.path = path;
186         fetchinfo_page.page.create_widget = fetchinfo_create_widget_func;
187         fetchinfo_page.page.destroy_widget = fetchinfo_destroy_widget_func;
188         fetchinfo_page.page.save_page = fetchinfo_save_func;
189         
190         prefs_gtk_register_page((PrefsPage *) &fetchinfo_page);
191
192         debug_print("Fetchinfo GTK plugin loaded\n");
193         return 0;       
194 }
195
196 void fetchinfo_gtk_done(void)
197 {
198         prefs_gtk_unregister_page((PrefsPage *) &fetchinfo_page);
199
200         debug_print("Fetchinfo GTK plugin unloaded\n");
201 }