1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2007 Collabora Ltd.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors: Xavier Claessens <xclaesse@gmail.com>
*/
#include "config.h"
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <glade/glade.h>
#include <libmissioncontrol/mc-profile.h>
#include <libempathy/empathy-utils.h>
#include <libempathy/empathy-debug.h>
#include "empathy-account-widget-jabber.h"
#include "empathy-ui-utils.h"
#define DEBUG_DOMAIN "AccountWidgetJabber"
#define PORT_WITHOUT_SSL 5222
#define PORT_WITH_SSL 5223
typedef struct {
McAccount *account;
GtkWidget *vbox_settings;
GtkWidget *button_forget;
GtkWidget *entry_id;
GtkWidget *entry_password;
GtkWidget *entry_resource;
GtkWidget *entry_server;
GtkWidget *spinbutton_port;
GtkWidget *spinbutton_priority;
GtkWidget *checkbutton_ssl;
GtkWidget *checkbutton_ignore_ssl_errors;
GtkWidget *checkbutton_encryption;
} EmpathyAccountWidgetJabber;
static gboolean account_widget_jabber_entry_focus_cb (GtkWidget *widget,
GdkEventFocus *event,
EmpathyAccountWidgetJabber *settings);
static void account_widget_jabber_entry_changed_cb (GtkWidget *widget,
EmpathyAccountWidgetJabber *settings);
static void account_widget_jabber_checkbutton_toggled_cb (GtkWidget *widget,
EmpathyAccountWidgetJabber *settings);
static void account_widget_jabber_value_changed_cb (GtkWidget *spinbutton,
EmpathyAccountWidgetJabber *settings);
static void account_widget_jabber_button_forget_clicked_cb (GtkWidget *button,
EmpathyAccountWidgetJabber *settings);
static void account_widget_jabber_destroy_cb (GtkWidget *widget,
EmpathyAccountWidgetJabber *settings);
static void account_widget_jabber_setup (EmpathyAccountWidgetJabber *settings);
static gboolean
account_widget_jabber_entry_focus_cb (GtkWidget *widget,
GdkEventFocus *event,
EmpathyAccountWidgetJabber *settings)
{
const gchar *param;
const gchar *str;
if (widget == settings->entry_password) {
param = "password";
}
else if (widget == settings->entry_resource) {
param = "resource";
}
else if (widget == settings->entry_server) {
param = "server";
}
else if (widget == settings->entry_id) {
param = "account";
} else {
return FALSE;
}
str = gtk_entry_get_text (GTK_ENTRY (widget));
if (G_STR_EMPTY (str)) {
gchar *value = NULL;
mc_account_unset_param (settings->account, param);
mc_account_get_param_string (settings->account, param, &value);
empathy_debug (DEBUG_DOMAIN, "Unset %s and restore to %s", param, value);
gtk_entry_set_text (GTK_ENTRY (widget), value ? value : "");
g_free (value);
} else {
empathy_debug (DEBUG_DOMAIN, "Setting %s to %s", param, str);
mc_account_set_param_string (settings->account, param, str);
}
return FALSE;
}
static void
account_widget_jabber_entry_changed_cb (GtkWidget *widget,
EmpathyAccountWidgetJabber *settings)
{
if (widget == settings->entry_password) {
const gchar *str;
str = gtk_entry_get_text (GTK_ENTRY (widget));
gtk_widget_set_sensitive (settings->button_forget, !G_STR_EMPTY (str));
}
}
static void
account_widget_jabber_checkbutton_toggled_cb (GtkWidget *widget,
EmpathyAccountWidgetJabber *settings)
{
gboolean value;
gboolean default_value;
const gchar *param;
value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
if (widget == settings->checkbutton_ssl) {
gint port = 0;
mc_account_get_param_int (settings->account, "port", &port);
if (value) {
if (port == PORT_WITHOUT_SSL || port == 0) {
port = PORT_WITH_SSL;
}
} else {
if (port == PORT_WITH_SSL || port == 0) {
port = PORT_WITHOUT_SSL;
}
}
gtk_spin_button_set_value (GTK_SPIN_BUTTON (settings->spinbutton_port), port);
param = "old-ssl";
}
else if (widget == settings->checkbutton_ignore_ssl_errors) {
param = "ignore-ssl-errors";
}
else if (widget == settings->checkbutton_encryption) {
param = "require-encryption";
} else {
return;
}
/* FIXME: This is ugly! checkbox don't have a "not-set" value so we
* always unset the param and set the value if different from the
* default value. */
mc_account_unset_param (settings->account, param);
mc_account_get_param_boolean (settings->account, param, &default_value);
if (default_value != value) {
empathy_debug (DEBUG_DOMAIN, "Setting %s to %d", param, value);
mc_account_set_param_boolean (settings->account, param, value);
} else {
empathy_debug (DEBUG_DOMAIN, "Unset %s", param, value);
}
}
static void
account_widget_jabber_value_changed_cb (GtkWidget *spinbutton,
EmpathyAccountWidgetJabber *settings)
{
gdouble value;
const gchar *param;
value = gtk_spin_button_get_value (GTK_SPIN_BUTTON (spinbutton));
if (spinbutton == settings->spinbutton_port) {
param = "port";
}
else if (spinbutton == settings->spinbutton_priority) {
param = "priority";
} else {
return;
}
if (value != 0) {
empathy_debug (DEBUG_DOMAIN, "Setting %s to %d", param, (gint) value);
mc_account_set_param_int (settings->account, param, (gint) value);
} else {
gint val;
mc_account_unset_param (settings->account, param);
mc_account_get_param_int (settings->account, param, &val);
empathy_debug (DEBUG_DOMAIN, "Unset %s and restore to %d", param, val);
gtk_spin_button_set_value (GTK_SPIN_BUTTON (spinbutton), val);
}
}
static void
account_widget_jabber_button_forget_clicked_cb (GtkWidget *button,
EmpathyAccountWidgetJabber *settings)
{
empathy_debug (DEBUG_DOMAIN, "Unset password");
mc_account_unset_param (settings->account, "password");
gtk_entry_set_text (GTK_ENTRY (settings->entry_password), "");
}
static void
account_widget_jabber_destroy_cb (GtkWidget *widget,
EmpathyAccountWidgetJabber *settings)
{
g_object_unref (settings->account);
g_free (settings);
}
static void
account_widget_jabber_setup (EmpathyAccountWidgetJabber *settings)
{
gint port = 0;
gint priority = 0;
gchar *id = NULL;
gchar *resource = NULL;
gchar *server = NULL;
gchar *password = NULL;
gboolean old_ssl = FALSE;
gboolean ignore_ssl_errors = FALSE;
gboolean encryption = FALSE;
mc_account_get_param_int (settings->account, "port", &port);
mc_account_get_param_int (settings->account, "priority", &priority);
mc_account_get_param_string (settings->account, "account", &id);
mc_account_get_param_string (settings->account, "resource", &resource);
mc_account_get_param_string (settings->account, "server", &server);
mc_account_get_param_string (settings->account, "password", &password);
mc_account_get_param_boolean (settings->account, "old-ssl", &old_ssl);
mc_account_get_param_boolean (settings->account, "ignore-ssl-errors", &ignore_ssl_errors);
mc_account_get_param_boolean (settings->account, "require-encryption", &encryption);
if (!id) {
McProfile *profile;
const gchar *server;
profile = mc_account_get_profile (settings->account);
server = mc_profile_get_default_account_domain (profile);
if (server) {
id = g_strconcat ("user@", server, NULL);
}
g_object_unref (profile);
}
gtk_spin_button_set_value (GTK_SPIN_BUTTON (settings->spinbutton_port), port);
gtk_spin_button_set_value (GTK_SPIN_BUTTON (settings->spinbutton_priority), priority);
gtk_entry_set_text (GTK_ENTRY (settings->entry_id), id ? id : "");
gtk_entry_set_text (GTK_ENTRY (settings->entry_resource), resource ? resource : "");
gtk_entry_set_text (GTK_ENTRY (settings->entry_server), server ? server : "");
gtk_entry_set_text (GTK_ENTRY (settings->entry_password), password ? password : "");
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (settings->checkbutton_ssl), old_ssl);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (settings->checkbutton_ignore_ssl_errors), ignore_ssl_errors);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (settings->checkbutton_encryption), encryption);
gtk_widget_set_sensitive (settings->button_forget, !G_STR_EMPTY (password));
g_free (id);
g_free (resource);
g_free (server);
g_free (password);
}
GtkWidget *
empathy_account_widget_jabber_new (McAccount *account)
{
EmpathyAccountWidgetJabber *settings;
GladeXML *glade;
GtkSizeGroup *size_group;
GtkWidget *label_id, *label_password;
GtkWidget *label_server, *label_resource;
GtkWidget *label_port, *label_priority;
settings = g_new0 (EmpathyAccountWidgetJabber, 1);
settings->account = g_object_ref (account);
glade = empathy_glade_get_file ("empathy-account-widget-jabber.glade",
"vbox_jabber_settings",
NULL,
"vbox_jabber_settings", &settings->vbox_settings,
"button_forget", &settings->button_forget,
"label_id", &label_id,
"label_password", &label_password,
"label_resource", &label_resource,
"label_priority", &label_priority,
"label_server", &label_server,
"label_port", &label_port,
"entry_id", &settings->entry_id,
"entry_password", &settings->entry_password,
"entry_resource", &settings->entry_resource,
"entry_server", &settings->entry_server,
"spinbutton_port", &settings->spinbutton_port,
"spinbutton_priority", &settings->spinbutton_priority,
"checkbutton_ssl", &settings->checkbutton_ssl,
"checkbutton_ignore_ssl_errors", &settings->checkbutton_ignore_ssl_errors,
"checkbutton_encryption", &settings->checkbutton_encryption,
NULL);
account_widget_jabber_setup (settings);
empathy_glade_connect (glade,
settings,
"vbox_jabber_settings", "destroy", account_widget_jabber_destroy_cb,
"button_forget", "clicked", account_widget_jabber_button_forget_clicked_cb,
"entry_password", "changed", account_widget_jabber_entry_changed_cb,
"spinbutton_port", "value-changed", account_widget_jabber_value_changed_cb,
"spinbutton_priority", "value-changed", account_widget_jabber_value_changed_cb,
"entry_id", "focus-out-event", account_widget_jabber_entry_focus_cb,
"entry_password", "focus-out-event", account_widget_jabber_entry_focus_cb,
"entry_resource", "focus-out-event", account_widget_jabber_entry_focus_cb,
"entry_server", "focus-out-event", account_widget_jabber_entry_focus_cb,
"checkbutton_ssl", "toggled", account_widget_jabber_checkbutton_toggled_cb,
"checkbutton_ignore_ssl_errors", "toggled", account_widget_jabber_checkbutton_toggled_cb,
"checkbutton_encryption", "toggled", account_widget_jabber_checkbutton_toggled_cb,
NULL);
g_object_unref (glade);
/* Set up remaining widgets */
size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
gtk_size_group_add_widget (size_group, label_id);
gtk_size_group_add_widget (size_group, label_password);
gtk_size_group_add_widget (size_group, label_resource);
gtk_size_group_add_widget (size_group, label_server);
gtk_size_group_add_widget (size_group, label_port);
gtk_size_group_add_widget (size_group, label_priority);
g_object_unref (size_group);
gtk_widget_show (settings->vbox_settings);
return settings->vbox_settings;
}
|