| 76 |
76 |
| 77 return g_strdup(text); |
77 return g_strdup(text); |
| 78 } |
78 } |
| 79 |
79 |
| 80 static void |
80 static void |
| 81 proxy_changed_cb(const gchar *name, PurplePrefType type, gconstpointer value, |
81 pidgin_proxy_prefs_type_changed_cb(GSettings *settings, char *key, |
| 82 gpointer data) |
82 gpointer data) |
| 83 { |
83 { |
| 84 PidginProxyPrefs *prefs = data; |
84 PidginProxyPrefs *prefs = data; |
| 85 const char *proxy = value; |
85 char *current = g_settings_get_string(settings, key); |
| 86 |
86 |
| 87 gtk_widget_set_visible(prefs->options, |
87 gtk_widget_set_visible(prefs->options, |
| 88 !purple_strequal(proxy, "none") && |
88 !purple_strequal(current, "No Proxy") && |
| 89 !purple_strequal(proxy, "envvar")); |
89 !purple_strequal(current, "Use Environmental Settings")); |
| 90 } |
90 |
| 91 |
91 g_free(current); |
| 92 static void |
|
| 93 proxy_print_option(GtkWidget *entry, gpointer data) |
|
| 94 { |
|
| 95 PidginProxyPrefs *prefs = data; |
|
| 96 |
|
| 97 if (entry == prefs->host) { |
|
| 98 purple_prefs_set_string("/purple/proxy/host", |
|
| 99 gtk_editable_get_text(GTK_EDITABLE(entry))); |
|
| 100 } else if (entry == prefs->port) { |
|
| 101 purple_prefs_set_int("/purple/proxy/port", |
|
| 102 gtk_spin_button_get_value_as_int( |
|
| 103 GTK_SPIN_BUTTON(entry))); |
|
| 104 } else if (entry == prefs->username) { |
|
| 105 purple_prefs_set_string("/purple/proxy/username", |
|
| 106 gtk_editable_get_text(GTK_EDITABLE(entry))); |
|
| 107 } else if (entry == prefs->password) { |
|
| 108 purple_prefs_set_string("/purple/proxy/password", |
|
| 109 gtk_editable_get_text(GTK_EDITABLE(entry))); |
|
| 110 } |
|
| 111 } |
92 } |
| 112 |
93 |
| 113 static void |
94 static void |
| 114 proxy_row_activated_cb(G_GNUC_UNUSED AdwActionRow *row, gpointer data) |
95 proxy_row_activated_cb(G_GNUC_UNUSED AdwActionRow *row, gpointer data) |
| 115 { |
96 { |
| 120 return; |
101 return; |
| 121 } |
102 } |
| 122 |
103 |
| 123 purple_notify_error(NULL, NULL, _("Cannot start proxy configuration program."), err->message, NULL); |
104 purple_notify_error(NULL, NULL, _("Cannot start proxy configuration program."), err->message, NULL); |
| 124 g_error_free(err); |
105 g_error_free(err); |
| |
106 } |
| |
107 |
| |
108 static gboolean |
| |
109 pidgin_proxy_prefs_get_type_mapping(GValue *value, GVariant *variant, |
| |
110 G_GNUC_UNUSED gpointer data) |
| |
111 { |
| |
112 const char *current = g_variant_get_string(variant, NULL); |
| |
113 guint position = 0; |
| |
114 |
| |
115 /* The values for position are dependent on the order of the GtkStringList |
| |
116 * in prefs/proxy.ui. |
| |
117 */ |
| |
118 if(purple_strequal(current, "No Proxy")) { |
| |
119 position = 0; |
| |
120 } else if(purple_strequal(current, "SOCKS4")) { |
| |
121 position = 1; |
| |
122 } else if(purple_strequal(current, "SOCKS5")) { |
| |
123 position = 2; |
| |
124 } else if(purple_strequal(current, "TOR")) { |
| |
125 position = 3; |
| |
126 } else if(purple_strequal(current, "HTTP")) { |
| |
127 position = 4; |
| |
128 } else if(purple_strequal(current, "Use Environmental Settings")) { |
| |
129 position = 5; |
| |
130 } else { |
| |
131 return FALSE; |
| |
132 } |
| |
133 |
| |
134 g_value_set_uint(value, position); |
| |
135 |
| |
136 return TRUE; |
| |
137 } |
| |
138 |
| |
139 static GVariant * |
| |
140 pidgin_proxy_prefs_set_type_mapping(const GValue *gvalue, |
| |
141 G_GNUC_UNUSED const GVariantType *expected_type, |
| |
142 G_GNUC_UNUSED gpointer data) |
| |
143 { |
| |
144 guint position = g_value_get_uint(gvalue); |
| |
145 |
| |
146 /* The index of these items is dependent on the order of the GtkStringList |
| |
147 * in prefs/proxy.ui. |
| |
148 */ |
| |
149 const char *map[] = { |
| |
150 "No Proxy", "SOCKS4", "SOCKS5", "TOR", "HTTP", |
| |
151 "Use Environmental Settings", |
| |
152 }; |
| |
153 |
| |
154 if(position >= G_N_ELEMENTS(map)) { |
| |
155 return NULL; |
| |
156 } |
| |
157 |
| |
158 return g_variant_new_string(map[position]); |
| |
159 } |
| |
160 |
| |
161 static void |
| |
162 pidgin_proxy_prefs_init_gnome(PidginProxyPrefs *prefs) { |
| |
163 gchar *path = NULL; |
| |
164 |
| |
165 gtk_widget_set_visible(prefs->gnome, TRUE); |
| |
166 gtk_widget_set_visible(prefs->nongnome, FALSE); |
| |
167 |
| |
168 path = g_find_program_in_path("gnome-network-properties"); |
| |
169 if (path == NULL) { |
| |
170 path = g_find_program_in_path("gnome-network-preferences"); |
| |
171 } |
| |
172 if (path == NULL) { |
| |
173 path = g_find_program_in_path("gnome-control-center"); |
| |
174 if (path != NULL) { |
| |
175 char *tmp = g_strdup_printf("%s network", path); |
| |
176 g_free(path); |
| |
177 path = tmp; |
| |
178 } |
| |
179 } |
| |
180 |
| |
181 prefs->gnome_program_path = path; |
| |
182 gtk_widget_set_visible(prefs->gnome_not_found, path == NULL); |
| |
183 gtk_widget_set_visible(prefs->gnome_program, path != NULL); |
| |
184 } |
| |
185 |
| |
186 static void |
| |
187 pidgin_proxy_prefs_init_non_gnome(PidginProxyPrefs *prefs) { |
| |
188 GSettings *settings = NULL; |
| |
189 gpointer settings_backend = NULL; |
| |
190 |
| |
191 settings_backend = purple_core_get_settings_backend(); |
| |
192 settings = g_settings_new_with_backend("im.pidgin.Purple.Proxy", |
| |
193 settings_backend); |
| |
194 |
| |
195 gtk_widget_set_visible(prefs->gnome, FALSE); |
| |
196 gtk_widget_set_visible(prefs->nongnome, TRUE); |
| |
197 |
| |
198 g_settings_bind_with_mapping(settings, "type", |
| |
199 prefs->type, "selected", |
| |
200 G_SETTINGS_BIND_DEFAULT, |
| |
201 pidgin_proxy_prefs_get_type_mapping, |
| |
202 pidgin_proxy_prefs_set_type_mapping, |
| |
203 NULL, |
| |
204 NULL); |
| |
205 |
| |
206 g_settings_bind(settings, "host", prefs->host, "text", |
| |
207 G_SETTINGS_BIND_DEFAULT); |
| |
208 g_settings_bind(settings, "port", prefs->port, "value", |
| |
209 G_SETTINGS_BIND_DEFAULT); |
| |
210 g_settings_bind(settings, "username", prefs->username, "text", |
| |
211 G_SETTINGS_BIND_DEFAULT); |
| |
212 g_settings_bind(settings, "password", prefs->password, "text", |
| |
213 G_SETTINGS_BIND_DEFAULT); |
| |
214 |
| |
215 g_signal_connect_object(settings, "changed::type", |
| |
216 G_CALLBACK(pidgin_proxy_prefs_type_changed_cb), |
| |
217 prefs, 0); |
| |
218 |
| |
219 /* Manually call the callback to set the initial visibility. */ |
| |
220 pidgin_proxy_prefs_type_changed_cb(settings, "type", prefs); |
| 125 } |
221 } |
| 126 |
222 |
| 127 /****************************************************************************** |
223 /****************************************************************************** |
| 128 * GObject Implementation |
224 * GObject Implementation |
| 129 *****************************************************************************/ |
225 *****************************************************************************/ |
| 175 widget_class, PidginProxyPrefs, password); |
271 widget_class, PidginProxyPrefs, password); |
| 176 gtk_widget_class_bind_template_callback(widget_class, |
272 gtk_widget_class_bind_template_callback(widget_class, |
| 177 proxy_type_expression_cb); |
273 proxy_type_expression_cb); |
| 178 gtk_widget_class_bind_template_callback(widget_class, |
274 gtk_widget_class_bind_template_callback(widget_class, |
| 179 proxy_row_activated_cb); |
275 proxy_row_activated_cb); |
| 180 gtk_widget_class_bind_template_callback(widget_class, |
|
| 181 proxy_print_option); |
|
| 182 } |
276 } |
| 183 |
277 |
| 184 static void |
278 static void |
| 185 pidgin_proxy_prefs_init(PidginProxyPrefs *prefs) |
279 pidgin_proxy_prefs_init(PidginProxyPrefs *prefs) |
| 186 { |
280 { |
| 187 PurpleProxyInfo *proxy_info; |
|
| 188 |
281 |
| 189 gtk_widget_init_template(GTK_WIDGET(prefs)); |
282 gtk_widget_init_template(GTK_WIDGET(prefs)); |
| 190 |
283 |
| 191 if(purple_running_gnome()) { |
284 if(purple_running_gnome()) { |
| 192 gchar *path = NULL; |
285 pidgin_proxy_prefs_init_gnome(prefs); |
| 193 |
|
| 194 gtk_widget_set_visible(prefs->gnome, TRUE); |
|
| 195 gtk_widget_set_visible(prefs->nongnome, FALSE); |
|
| 196 |
|
| 197 path = g_find_program_in_path("gnome-network-properties"); |
|
| 198 if (path == NULL) { |
|
| 199 path = g_find_program_in_path("gnome-network-preferences"); |
|
| 200 } |
|
| 201 if (path == NULL) { |
|
| 202 path = g_find_program_in_path("gnome-control-center"); |
|
| 203 if (path != NULL) { |
|
| 204 char *tmp = g_strdup_printf("%s network", path); |
|
| 205 g_free(path); |
|
| 206 path = tmp; |
|
| 207 } |
|
| 208 } |
|
| 209 |
|
| 210 prefs->gnome_program_path = path; |
|
| 211 gtk_widget_set_visible(prefs->gnome_not_found, path == NULL); |
|
| 212 gtk_widget_set_visible(prefs->gnome_program, path != NULL); |
|
| 213 |
|
| 214 } else { |
286 } else { |
| 215 gtk_widget_set_visible(prefs->gnome, FALSE); |
287 pidgin_proxy_prefs_init_non_gnome(prefs); |
| 216 gtk_widget_set_visible(prefs->nongnome, TRUE); |
|
| 217 |
|
| 218 pidgin_prefs_bind_combo_row("/purple/proxy/type", prefs->type); |
|
| 219 |
|
| 220 proxy_info = purple_global_proxy_get_info(); |
|
| 221 |
|
| 222 purple_prefs_connect_callback(prefs, "/purple/proxy/type", |
|
| 223 proxy_changed_cb, prefs); |
|
| 224 |
|
| 225 if (proxy_info != NULL) { |
|
| 226 const gchar *value = NULL; |
|
| 227 |
|
| 228 value = purple_proxy_info_get_hostname(proxy_info); |
|
| 229 if(value != NULL) { |
|
| 230 gtk_editable_set_text(GTK_EDITABLE(prefs->host), value); |
|
| 231 } |
|
| 232 |
|
| 233 if (purple_proxy_info_get_port(proxy_info) != 0) { |
|
| 234 gtk_spin_button_set_value( |
|
| 235 GTK_SPIN_BUTTON(prefs->port), |
|
| 236 purple_proxy_info_get_port(proxy_info)); |
|
| 237 } |
|
| 238 |
|
| 239 value = purple_proxy_info_get_username(proxy_info); |
|
| 240 if(value != NULL) { |
|
| 241 gtk_editable_set_text(GTK_EDITABLE(prefs->username), value); |
|
| 242 } |
|
| 243 |
|
| 244 value = purple_proxy_info_get_password(proxy_info); |
|
| 245 if(value != NULL) { |
|
| 246 gtk_editable_set_text(GTK_EDITABLE(prefs->password), value); |
|
| 247 } |
|
| 248 } |
|
| 249 |
|
| 250 proxy_changed_cb("/purple/proxy/type", PURPLE_PREF_STRING, |
|
| 251 purple_prefs_get_string("/purple/proxy/type"), |
|
| 252 prefs); |
|
| 253 } |
288 } |
| 254 } |
289 } |
| 255 |
290 |
| 256 /****************************************************************************** |
291 /****************************************************************************** |
| 257 * API |
292 * API |
| 258 *****************************************************************************/ |
293 *****************************************************************************/ |
| 259 GtkWidget * |
294 GtkWidget * |
| 260 pidgin_proxy_prefs_new(void) { |
295 pidgin_proxy_prefs_new(void) { |
| 261 return GTK_WIDGET(g_object_new(PIDGIN_TYPE_PROXY_PREFS, NULL)); |
296 return g_object_new(PIDGIN_TYPE_PROXY_PREFS, NULL); |
| 262 } |
297 } |