Remove inclusion of sys/socket.h from nntp-thread.c
[claws.git] / src / plugins / fetchinfo / fetchinfo_plugin_gtk.c
blobae6c23f1241f6e6137120ad735f568684db4da38
1 /*
2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2021 the Claws Mail Team
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.
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.
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.
20 #ifdef HAVE_CONFIG_H
21 # include "config.h"
22 # include "claws-features.h"
23 #endif
25 #include "defs.h"
26 #include "version.h"
27 #include "claws.h"
29 #include <glib.h>
30 #include <glib/gi18n.h>
31 #include <gtk/gtk.h>
33 #include "plugin.h"
34 #include "utils.h"
35 #include "prefs.h"
36 #include "prefs_gtk.h"
38 #include "fetchinfo_plugin.h"
40 struct FetchinfoPage
42 PrefsPage page;
44 GtkWidget *fetchinfo_enable;
45 GtkWidget *fetchinfo_uidl;
46 GtkWidget *fetchinfo_account;
47 GtkWidget *fetchinfo_server;
48 GtkWidget *fetchinfo_userid;
49 GtkWidget *fetchinfo_time;
52 static void fetchinfo_set_sensitive(struct FetchinfoPage *page, gboolean enable)
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);
61 static void fetchinfo_enable_cb(GtkWidget *widget, gpointer data)
63 struct FetchinfoPage *page = (struct FetchinfoPage *) data;
65 fetchinfo_set_sensitive(page, gtk_toggle_button_get_active(
66 GTK_TOGGLE_BUTTON(page->fetchinfo_enable)));
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);
75 static void fetchinfo_create_widget_func(PrefsPage * _page, GtkWindow *window, gpointer data)
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;
87 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
88 gtk_container_set_border_width(GTK_CONTAINER(vbox), 10);
89 gtk_widget_show(vbox);
91 /* TRANSLATORS: 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);
96 PACK_FRAME (vbox, frame, _("Headers to be added"))
98 hdr_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 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);
103 /* TRANSLATORS: 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 /* TRANSLATORS: 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 /* TRANSLATORS: 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 /* TRANSLATORS: 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 /* TRANSLATORS: 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"));
114 config = fetchinfo_get_config();
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);
129 g_signal_connect(G_OBJECT(fetchinfo_enable), "released",
130 G_CALLBACK(fetchinfo_enable_cb), page);
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;
139 page->page.widget = vbox;
141 fetchinfo_set_sensitive(page, config->fetchinfo_enable);
143 #undef ADD_NEW_CHECKBOX
145 static void fetchinfo_destroy_widget_func(PrefsPage *_page)
147 debug_print("Destroying Fetchinfo widget\n");
150 static void fetchinfo_save_func(PrefsPage *_page)
152 struct FetchinfoPage *page = (struct FetchinfoPage *) _page;
153 FetchinfoConfig *config;
155 debug_print("Saving Fetchinfo Page\n");
157 config = fetchinfo_get_config();
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) );
172 fetchinfo_save_config();
175 static struct FetchinfoPage fetchinfo_page;
177 gint fetchinfo_gtk_init(void)
179 static gchar *path[3];
181 path[0] = _("Plugins");
182 path[1] = _("Fetchinfo");
183 path[2] = NULL;
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 fetchinfo_page.page.weight = 40.0;
191 prefs_gtk_register_page((PrefsPage *) &fetchinfo_page);
193 debug_print("Fetchinfo GTK plugin loaded\n");
194 return 0;
197 void fetchinfo_gtk_done(void)
199 prefs_gtk_unregister_page((PrefsPage *) &fetchinfo_page);
201 debug_print("Fetchinfo GTK plugin unloaded\n");