1 #include "proxy_setting_view.h"
2 #include "urlgfe.h"
3
on_toggled(ProxySettingView * view)4 static void on_toggled (ProxySettingView* view)
5 {
6 gboolean auth_sensitive;
7 gboolean proxy_sensitive;
8
9 proxy_sensitive = !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(view->radio_none));
10 auth_sensitive = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(view->toggle_authentication));
11
12 if (proxy_sensitive == FALSE)
13 auth_sensitive = FALSE;
14
15 gtk_widget_set_sensitive (view->label_host, proxy_sensitive);
16 gtk_widget_set_sensitive (view->label_port, proxy_sensitive);
17 gtk_widget_set_sensitive (view->entry_host, proxy_sensitive);
18 gtk_widget_set_sensitive (view->spin_port, proxy_sensitive);
19 gtk_widget_set_sensitive (view->toggle_authentication, proxy_sensitive);
20
21 gtk_widget_set_sensitive (view->label_username, auth_sensitive);
22 gtk_widget_set_sensitive (view->label_password, auth_sensitive);
23 gtk_widget_set_sensitive (view->entry_username, auth_sensitive);
24 gtk_widget_set_sensitive (view->entry_password, auth_sensitive);
25 }
26
proxy_setting_view_init(ProxySettingView * view)27 void proxy_setting_view_init (ProxySettingView* view)
28 {
29 GtkWidget* hbox;
30 GtkWidget* vbox;
31 GtkSizeGroup* size_group;
32
33 // class initial base class : SettingView
34 setting_view_init (SETTING_VIEW (view));
35
36 view->self = gtk_hbox_new (FALSE, 3);
37
38 // initial and setup widgets -----------------------------------
39 view->radio_none = gtk_radio_button_new_with_mnemonic (NULL,
40 _("_Don't use"));
41 view->radio_http = gtk_radio_button_new_with_mnemonic_from_widget (
42 (GtkRadioButton*)view->radio_none,
43 "_HTTP");
44 view->radio_socks5 = gtk_radio_button_new_with_mnemonic_from_widget (
45 (GtkRadioButton*)view->radio_none,
46 "_SOCKS v5");
47
48 view->entry_host = gtk_entry_new ();
49 view->spin_port = gtk_spin_button_new_with_range (0.0, 65535.0, 1.0);
50 view->label_host = gtk_label_new_with_mnemonic (_("Host:"));
51 view->label_port = gtk_label_new_with_mnemonic (":");
52 gtk_entry_set_width_chars (GTK_ENTRY (view->spin_port), 4);
53 gtk_label_set_mnemonic_widget (GTK_LABEL(view->label_host),
54 view->entry_host);
55 gtk_label_set_mnemonic_widget (GTK_LABEL(view->label_port),
56 view->spin_port);
57
58 view->toggle_authentication = gtk_check_button_new_with_mnemonic (_("Authentication"));
59 view->entry_username = gtk_entry_new ();
60 view->entry_password = gtk_entry_new ();
61 view->label_username = gtk_label_new_with_mnemonic (_("Username:"));
62 view->label_password = gtk_label_new_with_mnemonic (_("Password:"));
63 gtk_entry_set_visibility (GTK_ENTRY (view->entry_password), FALSE);
64 gtk_label_set_mnemonic_widget (GTK_LABEL(view->label_username),
65 view->entry_username);
66 gtk_label_set_mnemonic_widget (GTK_LABEL(view->label_password),
67 view->entry_password);
68
69 // pack left side widgets ---------------------------------------
70 size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
71 gtk_size_group_add_widget (size_group, view->radio_none);
72 gtk_size_group_add_widget (size_group, view->radio_http);
73 gtk_size_group_add_widget (size_group, view->radio_socks5);
74
75 vbox = gtk_vbox_new (FALSE, 3);
76 gtk_box_pack_start (GTK_BOX(vbox), view->radio_none, FALSE, FALSE, 0);
77 gtk_box_pack_start (GTK_BOX(vbox), view->radio_http, FALSE, FALSE, 0);
78 gtk_box_pack_start (GTK_BOX(vbox), view->radio_socks5, FALSE, FALSE, 0);
79 // pack left side
80 gtk_box_pack_start (GTK_BOX(view->self), vbox, FALSE, FALSE, 0);
81
82 // pack center separator ----------------------------------------
83 gtk_box_pack_start (GTK_BOX(view->self), gtk_vseparator_new(),
84 FALSE, FALSE, 0);
85
86 // pack right side widgets --------------------------------------
87 size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
88 // gtk_size_group_add_widget (size_group, view->label_host);
89 // gtk_size_group_add_widget (size_group, view->label_port);
90 gtk_size_group_add_widget (size_group, view->label_username);
91 gtk_size_group_add_widget (size_group, view->label_password);
92
93 vbox = gtk_vbox_new (FALSE, 3);
94 // pack proxy & port
95 hbox = gtk_hbox_new (FALSE, 3);
96 gtk_box_pack_start (GTK_BOX(hbox), view->label_host, FALSE, FALSE, 0);
97 gtk_box_pack_start (GTK_BOX(hbox), view->entry_host, TRUE, TRUE, 0);
98 // gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
99 // hbox = gtk_hbox_new (FALSE, 3);
100 gtk_box_pack_start (GTK_BOX(hbox), view->label_port, FALSE, FALSE, 0);
101 gtk_box_pack_start (GTK_BOX(hbox), view->spin_port, FALSE, FALSE, 0);
102 gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
103 /*
104 // pack proxy
105 hbox = gtk_hbox_new (FALSE, 3);
106 gtk_box_pack_start (GTK_BOX(hbox), view->label_host, FALSE, FALSE, 0);
107 gtk_box_pack_start (GTK_BOX(hbox), view->entry_host, TRUE, TRUE, 0);
108 gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
109 // pack port
110 hbox = gtk_hbox_new (FALSE, 3);
111 gtk_box_pack_start (GTK_BOX(hbox), view->label_port, FALSE, FALSE, 0);
112 gtk_box_pack_start (GTK_BOX(hbox), view->spin_port, FALSE, FALSE, 0);
113 gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
114 */
115 gtk_box_pack_start (GTK_BOX(vbox), view->toggle_authentication, TRUE, TRUE, 0);
116 // pack username
117 hbox = gtk_hbox_new (FALSE, 3);
118 gtk_box_pack_start (GTK_BOX(hbox), view->label_username, FALSE, FALSE, 0);
119 gtk_box_pack_start (GTK_BOX(hbox), view->entry_username, TRUE, TRUE, 0);
120 gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
121 // pack password
122 hbox = gtk_hbox_new (FALSE, 3);
123 gtk_box_pack_start (GTK_BOX(hbox), view->label_password, FALSE, FALSE, 0);
124 gtk_box_pack_start (GTK_BOX(hbox), view->entry_password, TRUE, TRUE, 0);
125 gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
126 // pack right side
127 gtk_box_pack_start (GTK_BOX(view->self), vbox, FALSE, FALSE, 0);
128
129
130 // change setting view container
131 SETTING_VIEW (view)->view_container = view->self;
132
133 on_toggled (view);
134
135 gtk_widget_show_all (view->self);
136
137 g_signal_connect_swapped (view->radio_none, "toggled",
138 G_CALLBACK(on_toggled), view);
139 g_signal_connect_swapped (view->toggle_authentication, "toggled",
140 G_CALLBACK(on_toggled), view);
141 }
142
proxy_setting_view_set(ProxySettingView * view,ProxySetting * setting)143 void proxy_setting_view_set (ProxySettingView* view,
144 ProxySetting* setting)
145 {
146 if (setting==NULL)
147 return;
148
149 gtk_entry_set_text (GTK_ENTRY(view->entry_host),
150 STR_N2E(setting->address));
151 gtk_entry_set_text (GTK_ENTRY(view->entry_username),
152 STR_N2E(setting->username));
153 gtk_entry_set_text (GTK_ENTRY(view->entry_password),
154 STR_N2E(setting->password));
155 gtk_spin_button_set_value (GTK_SPIN_BUTTON(view->spin_port),
156 setting->port);
157
158 switch (setting->type) {
159 case PROXY_TYPE_NONE:
160 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(view->radio_none), TRUE);
161 break;
162 case PROXY_TYPE_HTTP:
163 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(view->radio_http), TRUE);
164 break;
165 case PROXY_TYPE_SOCKS5:
166 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(view->radio_socks5), TRUE);
167 }
168 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(view->toggle_authentication),
169 setting->authentication);
170 }
171
proxy_setting_view_get(ProxySettingView * view,ProxySetting * setting)172 void proxy_setting_view_get (ProxySettingView* view,
173 ProxySetting* setting)
174 {
175 proxy_setting_set_address (setting,
176 gtk_entry_get_text (GTK_ENTRY(view->entry_host)));
177 proxy_setting_set_username (setting,
178 gtk_entry_get_text (GTK_ENTRY(view->entry_username)));
179 proxy_setting_set_password (setting,
180 gtk_entry_get_text (GTK_ENTRY(view->entry_password)));
181 setting->port = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(view->spin_port));
182
183 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (view->radio_none)))
184 setting->type = PROXY_TYPE_NONE;
185 else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (view->radio_http)))
186 setting->type = PROXY_TYPE_HTTP;
187 else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (view->radio_socks5)))
188 setting->type = PROXY_TYPE_SOCKS5;
189
190 setting->authentication = gtk_toggle_button_get_active (
191 GTK_TOGGLE_BUTTON (view->toggle_authentication));
192 }
193
proxy_setting_view_set_multiple(ProxySettingView * view,gboolean multiple)194 void proxy_setting_view_set_multiple (ProxySettingView *view,
195 gboolean multiple)
196 {
197 }
198
199