2 * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2018 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, see <http://www.gnu.org/licenses/>.
21 #include <glib/gi18n.h>
24 #include "common/defs.h"
25 #include "common/proxy.h"
29 #include "prefs_common.h"
30 #include "prefs_gtk.h"
31 #include "passwordstore.h"
33 typedef struct _ProxyPage
37 GtkWidget
*proxy_checkbtn
;
38 GtkWidget
*socks4_radiobtn
;
39 GtkWidget
*socks5_radiobtn
;
40 GtkWidget
*proxy_host_entry
;
41 GtkWidget
*proxy_port_spinbtn
;
42 GtkWidget
*proxy_auth_checkbtn
;
43 GtkWidget
*proxy_name_entry
;
44 GtkWidget
*proxy_pass_entry
;
47 static void showpwd_checkbtn_toggled(GtkToggleButton
*button
,
50 static void prefs_proxy_create_widget(PrefsPage
*_page
, GtkWindow
*window
,
53 ProxyPage
*page
= (ProxyPage
*)_page
;
55 GtkWidget
*vbox0
, *vbox1
, *vbox2
;
58 GtkWidget
*proxy_checkbtn
;
59 GtkWidget
*socks4_radiobtn
, *socks5_radiobtn
;
60 GtkWidget
*proxy_auth_checkbtn
;
61 GtkWidget
*proxy_frame
;
62 GtkWidget
*proxy_host_entry
;
63 GtkWidget
*proxy_port_spinbtn
;
64 GtkWidget
*proxy_name_entry
;
65 GtkWidget
*proxy_pass_entry
;
70 vbox0
= gtk_vbox_new(FALSE
, VSPACING
);
71 gtk_container_set_border_width(GTK_CONTAINER(vbox0
), VBOX_BORDER
);
73 proxy_checkbtn
= gtk_check_button_new_with_label(_("Use proxy server"));
74 PACK_FRAME(vbox0
, proxy_frame
, NULL
);
75 gtk_frame_set_label_widget(GTK_FRAME(proxy_frame
), proxy_checkbtn
);
77 vbox1
= gtk_vbox_new(FALSE
, VSPACING_NARROW
);
78 gtk_container_set_border_width(GTK_CONTAINER(vbox1
), 8);
79 gtk_container_add(GTK_CONTAINER(proxy_frame
), vbox1
);
81 hbox
= gtk_hbox_new(FALSE
, 8);
82 gtk_box_pack_start(GTK_BOX(vbox1
), hbox
, FALSE
, FALSE
, 0);
84 socks4_radiobtn
= gtk_radio_button_new_with_label(NULL
, "SOCKS4");
85 gtk_box_pack_start(GTK_BOX(hbox
), socks4_radiobtn
, FALSE
, FALSE
, 0);
86 g_object_set_data(G_OBJECT(socks4_radiobtn
), MENU_VAL_ID
,
87 GINT_TO_POINTER(PROXY_SOCKS4
));
89 socks5_radiobtn
= gtk_radio_button_new_with_label_from_widget(
90 GTK_RADIO_BUTTON(socks4_radiobtn
), "SOCKS5");
91 gtk_box_pack_start(GTK_BOX(hbox
), socks5_radiobtn
, FALSE
, FALSE
, 0);
92 g_object_set_data(G_OBJECT(socks5_radiobtn
), MENU_VAL_ID
,
93 GINT_TO_POINTER(PROXY_SOCKS5
));
95 hbox
= gtk_hbox_new(FALSE
, 8);
96 gtk_box_pack_start(GTK_BOX(vbox1
), hbox
, FALSE
, FALSE
, 0);
98 label
= gtk_label_new(_("Hostname"));
99 gtk_box_pack_start(GTK_BOX(hbox
), label
, FALSE
, FALSE
, 0);
101 proxy_host_entry
= gtk_entry_new();
102 gtk_widget_set_size_request(proxy_host_entry
, DEFAULT_ENTRY_WIDTH
, -1);
103 gtk_box_pack_start(GTK_BOX(hbox
), proxy_host_entry
, TRUE
, TRUE
, 0);
105 label
= gtk_label_new(_("Port"));
106 gtk_box_pack_start(GTK_BOX(hbox
), label
, FALSE
, FALSE
, 0);
108 proxy_port_spinbtn
= gtk_spin_button_new_with_range(0, 65535, 1080);
109 gtk_widget_set_size_request(proxy_port_spinbtn
, 64, -1);
110 gtk_box_pack_start(GTK_BOX(hbox
), proxy_port_spinbtn
, FALSE
, FALSE
, 0);
112 vbox2
= gtk_vbox_new(FALSE
, VSPACING_NARROW
);
113 gtk_box_pack_start(GTK_BOX(vbox1
), vbox2
, FALSE
, FALSE
, 0);
115 PACK_CHECK_BUTTON(vbox2
, proxy_auth_checkbtn
, _("Use authentication"));
117 table
= gtk_table_new(2, 4, FALSE
);
119 gtk_table_set_row_spacings(GTK_TABLE(table
), VSPACING_NARROW
);
120 gtk_table_set_col_spacings(GTK_TABLE(table
), 9);
121 gtk_box_pack_start(GTK_BOX(vbox2
), table
, FALSE
, FALSE
, 0);
123 label
= gtk_label_new(_("Username"));
124 gtk_table_attach(GTK_TABLE(table
), label
, 0, 1, 0, 1,
125 GTK_SHRINK
| GTK_FILL
,
126 GTK_SHRINK
| GTK_FILL
, 0, 0);
128 proxy_name_entry
= gtk_entry_new();
129 gtk_widget_set_size_request(proxy_name_entry
, DEFAULT_ENTRY_WIDTH
, -1);
130 gtk_table_attach(GTK_TABLE(table
), proxy_name_entry
, 1, 2, 0, 1,
131 GTK_EXPAND
| GTK_SHRINK
| GTK_FILL
,
132 GTK_EXPAND
| GTK_SHRINK
| GTK_FILL
, 0, 0);
134 label
= gtk_label_new(_("Password"));
135 gtk_table_attach(GTK_TABLE(table
), label
, 2, 3, 0, 1,
136 GTK_SHRINK
| GTK_FILL
,
137 GTK_SHRINK
| GTK_FILL
, 0, 0);
139 proxy_pass_entry
= gtk_entry_new();
140 gtk_widget_set_size_request(proxy_pass_entry
, DEFAULT_ENTRY_WIDTH
, -1);
141 gtk_entry_set_visibility(GTK_ENTRY(proxy_pass_entry
), FALSE
);
142 gtk_table_attach(GTK_TABLE(table
), proxy_pass_entry
, 3, 4, 0, 1,
143 GTK_EXPAND
| GTK_SHRINK
| GTK_FILL
,
144 GTK_EXPAND
| GTK_SHRINK
| GTK_FILL
, 0, 0);
146 button
= gtk_check_button_new_with_label(_("Show password"));
147 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button
), FALSE
);
148 gtk_table_attach(GTK_TABLE(table
), button
, 3, 4, 1, 2,
149 GTK_SHRINK
| GTK_FILL
,
150 GTK_SHRINK
| GTK_FILL
, 0, 0);
151 g_signal_connect(G_OBJECT(button
), "toggled",
152 G_CALLBACK(showpwd_checkbtn_toggled
), proxy_pass_entry
);
154 gtk_widget_show_all(vbox0
);
156 SET_TOGGLE_SENSITIVITY(proxy_checkbtn
, vbox1
);
157 SET_TOGGLE_SENSITIVITY(proxy_auth_checkbtn
, table
);
158 SET_TOGGLE_SENSITIVITY(socks5_radiobtn
, vbox2
);
160 /* Set widgets to their correct states, based on prefs. */
161 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(proxy_checkbtn
),
162 prefs_common
.use_proxy
);
163 if (prefs_common
.proxy_info
.proxy_type
== PROXY_SOCKS4
)
164 button
= socks4_radiobtn
;
166 button
= socks5_radiobtn
;
167 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button
), TRUE
);
168 gtk_entry_set_text(GTK_ENTRY(proxy_host_entry
),
169 prefs_common
.proxy_info
.proxy_host
);
170 gtk_spin_button_set_value(GTK_SPIN_BUTTON(proxy_port_spinbtn
),
171 (gdouble
)prefs_common
.proxy_info
.proxy_port
);
172 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(proxy_auth_checkbtn
),
173 prefs_common
.proxy_info
.use_proxy_auth
);
174 gtk_entry_set_text(GTK_ENTRY(proxy_name_entry
),
175 prefs_common
.proxy_info
.proxy_name
);
178 passwd_store_get(PWS_CORE
, PWS_CORE_PROXY
, PWS_CORE_PROXY_PASS
);
179 gtk_entry_set_text(GTK_ENTRY(proxy_pass_entry
), buf
!= NULL
? buf
: "");
181 memset(buf
, 0, strlen(buf
));
185 page
->proxy_checkbtn
= proxy_checkbtn
;
186 page
->socks4_radiobtn
= socks4_radiobtn
;
187 page
->socks5_radiobtn
= socks5_radiobtn
;
188 page
->proxy_host_entry
= proxy_host_entry
;
189 page
->proxy_port_spinbtn
= proxy_port_spinbtn
;
190 page
->proxy_auth_checkbtn
= proxy_auth_checkbtn
;
191 page
->proxy_name_entry
= proxy_name_entry
;
192 page
->proxy_pass_entry
= proxy_pass_entry
;
193 page
->page
.widget
= vbox0
;
197 static void prefs_proxy_destroy_widget(PrefsPage
*_page
)
202 static void prefs_proxy_save(PrefsPage
*_page
)
204 ProxyPage
*page
= (ProxyPage
*)_page
;
206 prefs_common
.use_proxy
= gtk_toggle_button_get_active(
207 GTK_TOGGLE_BUTTON(page
->proxy_checkbtn
));
209 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(page
->socks4_radiobtn
)))
210 prefs_common
.proxy_info
.proxy_type
= PROXY_SOCKS4
;
212 prefs_common
.proxy_info
.proxy_type
= PROXY_SOCKS5
;
214 g_free(prefs_common
.proxy_info
.proxy_host
);
215 prefs_common
.proxy_info
.proxy_host
= g_strdup(gtk_entry_get_text(
216 GTK_ENTRY(page
->proxy_host_entry
)));
218 prefs_common
.proxy_info
.proxy_port
= gtk_spin_button_get_value_as_int(
219 GTK_SPIN_BUTTON(page
->proxy_port_spinbtn
));
221 prefs_common
.proxy_info
.use_proxy_auth
= gtk_toggle_button_get_active(
222 GTK_TOGGLE_BUTTON(page
->proxy_auth_checkbtn
));
224 g_free(prefs_common
.proxy_info
.proxy_name
);
225 prefs_common
.proxy_info
.proxy_name
= g_strdup(gtk_entry_get_text(
226 GTK_ENTRY(page
->proxy_name_entry
)));
228 passwd_store_set(PWS_CORE
, PWS_CORE_PROXY
, PWS_CORE_PROXY_PASS
,
229 gtk_entry_get_text(GTK_ENTRY(page
->proxy_pass_entry
)), FALSE
);
233 ProxyPage
*prefs_proxy
;
235 void prefs_proxy_init(void)
238 static gchar
*path
[3];
240 path
[0] = _("Mail Handling");
241 path
[1] = _("Proxy");
244 page
= g_new0(ProxyPage
, 1);
245 page
->page
.path
= path
;
246 page
->page
.create_widget
= prefs_proxy_create_widget
;
247 page
->page
.destroy_widget
= prefs_proxy_destroy_widget
;
248 page
->page
.save_page
= prefs_proxy_save
;
249 page
->page
.weight
= 190.0;
251 prefs_gtk_register_page((PrefsPage
*)page
);
255 void prefs_proxy_done(void)
257 prefs_gtk_unregister_page((PrefsPage
*)prefs_proxy
);
261 static void showpwd_checkbtn_toggled(GtkToggleButton
*button
,
264 gboolean active
= gtk_toggle_button_get_active(button
);
265 GtkWidget
*entry
= GTK_WIDGET(user_data
);
267 gtk_entry_set_visibility(GTK_ENTRY(entry
), active
);