~noskcaj/ubuntu/trusty/ekiga/ftbfs

« back to all changes in this revision

Viewing changes to src/gui/accounts.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2006-01-28 18:49:20 UTC
  • Revision ID: james.westby@ubuntu.com-20060128184920-v525ihmiv7id40xs
Tags: upstream-1.99.0
ImportĀ upstreamĀ versionĀ 1.99.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/* GnomeMeeting -- A Video-Conferencing application
 
3
 * Copyright (C) 2000-2006 Damien Sandras
 
4
 *
 
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 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
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.
 
14
 *
 
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.
 
18
 *
 
19
 *
 
20
 * GnomeMeeting is licensed under the GPL license and as a special exception,
 
21
 * you have permission to link or otherwise combine this program with the
 
22
 * programs OpenH323 and Pwlib, and distribute the combination, without
 
23
 * applying the requirements of the GNU GPL to the OpenH323 program, as long
 
24
 * as you do follow the requirements of the GNU GPL for all the rest of the
 
25
 * software thus combined.
 
26
 */
 
27
 
 
28
 
 
29
/*
 
30
 *                         accounts.cpp  -  description
 
31
 *                         ----------------------------
 
32
 *   begin                : Sun Feb 13 2005
 
33
 *   copyright            : (C) 2000-2006 by Damien Sandras
 
34
 *   description          : This file contains all the functions needed to
 
35
 *                          manipulate H323/SIP/... provider accounts.
 
36
 */
 
37
 
 
38
 
 
39
#include "../../config.h"
 
40
 
 
41
#include "accounts.h"
 
42
#include "callbacks.h"
 
43
#include "misc.h"
 
44
#include "main.h"
 
45
#include "preferences.h"
 
46
#include "history.h"
 
47
 
 
48
#include "manager.h"
 
49
#include "sip.h"
 
50
#include "h323.h"
 
51
#include "ekiga.h"
 
52
 
 
53
#include "gmconf.h"
 
54
#include "gmdialog.h"
 
55
 
 
56
 
 
57
typedef struct GmAccountsEditWindow_ {
 
58
 
 
59
  GtkWidget *account_entry;
 
60
  GtkWidget *protocol_option_menu;
 
61
  GtkWidget *host_label;
 
62
  GtkWidget *host_entry;
 
63
  GtkWidget *username_entry;
 
64
  GtkWidget *auth_username_label;
 
65
  GtkWidget *auth_username_entry;
 
66
  GtkWidget *password_entry;
 
67
  GtkWidget *domain_label;
 
68
  GtkWidget *domain_entry;
 
69
  GtkWidget *timeout_entry;
 
70
 
 
71
} GmAccountsEditWindow;
 
72
 
 
73
#define GM_ACCOUNTS_EDIT_WINDOW(x) (GmAccountsEditWindow *) (x)
 
74
 
 
75
typedef struct GmAccountsWindow_ {
 
76
 
 
77
  GtkWidget *accounts_list;
 
78
  GtkWidget *delete_button;
 
79
  GtkWidget *edit_button;
 
80
  GtkWidget *default_button;
 
81
 
 
82
} GmAccountsWindow;
 
83
 
 
84
#define GM_ACCOUNTS_WINDOW(x) (GmAccountsWindow *) (x)
 
85
 
 
86
 
 
87
/* Functions */
 
88
 
 
89
/* DESCRIPTION  : /
 
90
 * BEHAVIOR     : Returns a GmAccount from its string representation.
 
91
 * PRE          : /
 
92
 */
 
93
static GmAccount *gm_aw_from_string_to_account (gchar *);
 
94
 
 
95
 
 
96
/* DESCRIPTION  : /
 
97
 * BEHAVIOR     : Returns a string representing a GmAccount.
 
98
 * PRE          : /
 
99
 */
 
100
static gchar *gm_aw_from_account_to_string (GmAccount *);
 
101
 
 
102
 
 
103
/* GUI Functions */
 
104
 
 
105
/* DESCRIPTION  : /
 
106
 * BEHAVIOR     : Frees a GmAccountsWindow and its content.
 
107
 * PRE          : A non-NULL pointer to a GmAccountsWindow structure.
 
108
 */
 
109
static void gm_aw_destroy (gpointer);
 
110
 
 
111
 
 
112
/* DESCRIPTION  : /
 
113
 * BEHAVIOR     : Returns a pointer to the private GmAccountsWindow structure
 
114
 *                used by the preferences window GMObject.
 
115
 * PRE          : The given GtkWidget pointer must be a preferences window 
 
116
 *                GMObject.
 
117
 */
 
118
static GmAccountsWindow *gm_aw_get_aw (GtkWidget *);
 
119
 
 
120
 
 
121
/* DESCRIPTION  : /
 
122
 * BEHAVIOR     : Creates and run a dialog where the user can edit a new
 
123
 *                or an already selected account. It also checks if all
 
124
 *                required parameters are present, and once a valid choice
 
125
 *                has been entered and validated, it is added/modified in
 
126
 *                the accounts database.
 
127
 * PRE          : The GmAccount is a valid pointer to a valid GmAccount
 
128
 *                that we are editing. If it is NULL, it means we
 
129
 *                are creating a new account.
 
130
 */
 
131
static void gm_aw_edit_account_dialog_run (GtkWidget *accounts_window,
 
132
                                           GmAccount *account,
 
133
                                           GtkWidget *parent_window);
 
134
 
 
135
 
 
136
/* DESCRIPTION  : /
 
137
 * BEHAVIOR     : Creates and run a dialog asking to the user if he wants
 
138
 *                to delete the given account.
 
139
 * PRE          : The GmAccount is a valid pointer to a valid GmAccount
 
140
 *                that we are editing. If can not be NULL.
 
141
 */
 
142
static void gm_aw_delete_account_dialog_run (GtkWidget *accounts_window,
 
143
                                             GmAccount *account,
 
144
                                             GtkWidget *parent_window);
 
145
 
 
146
 
 
147
/* DESCRIPTION  : /
 
148
 * BEHAVIOR     : Returns the currently selected account in the main window.
 
149
 *                (if any).
 
150
 * PRE          : /
 
151
 */
 
152
static GmAccount *gm_aw_get_selected_account (GtkWidget *accounts_window);
 
153
 
 
154
 
 
155
/* GTK+ Callbacks */
 
156
 
 
157
/* DESCRIPTION  :  This callback is called when the user clicks
 
158
 *                 on an account in the accounts window or when
 
159
 *                 there is an event_after.
 
160
 * BEHAVIOR     :  It updates the accounts window buttons sensitivity.
 
161
 * PRE          :  data is a valid pointer to the GmAccountsWindow.
 
162
 */
 
163
static gint account_clicked_cb (GtkWidget *w,
 
164
                                GdkEventButton *e,
 
165
                                gpointer data);
 
166
 
 
167
 
 
168
/* DESCRIPTION  :  This callback is called when the user clicks
 
169
 *                 on an account to enable it in the accounts window.
 
170
 * BEHAVIOR     :  It updates the accounts list configuration to enable/disable
 
171
 *                 the account. It also calls the Register operation from
 
172
 *                 the GMManager to refresh the status of that account.
 
173
 * PRE          :  /
 
174
 */
 
175
static void account_toggled_cb (GtkCellRendererToggle *cell,
 
176
                                gchar *path_str,
 
177
                                gpointer data);
 
178
 
 
179
 
 
180
/* DESCRIPTION  :  This callback is called when the user chooses to add
 
181
 *                 an account.
 
182
 * BEHAVIOR     :  It runs the edit account dialog until the user validates
 
183
 *                 it with correct data.
 
184
 * PRE          :  /
 
185
 */
 
186
static void add_account_cb (GtkWidget *button, 
 
187
                            gpointer data);
 
188
 
 
189
 
 
190
/* DESCRIPTION  :  This callback is called when the user chooses to edit
 
191
 *                 an account.
 
192
 * BEHAVIOR     :  It runs the edit account dialog until the user validates
 
193
 *                 it with correct data.
 
194
 * PRE          :  /
 
195
 */
 
196
static void edit_account_cb (GtkWidget *button, 
 
197
                             gpointer data);
 
198
 
 
199
 
 
200
/* DESCRIPTION  :  This callback is called when the user chooses to set
 
201
 *                 an account as default.
 
202
 * BEHAVIOR     :  It sets it as default, only one default at a time.
 
203
 * PRE          :  /
 
204
 */
 
205
static void set_account_as_default_cb (GtkWidget *button, 
 
206
                                       gpointer data);
 
207
 
 
208
 
 
209
/* DESCRIPTION  :  This callback is called when the user chooses to delete
 
210
 *                 an account.
 
211
 * BEHAVIOR     :  It runs the delete account dialog until the user validates
 
212
 *                 it.
 
213
 * PRE          :  /
 
214
 */
 
215
static void delete_account_cb (GtkWidget *button, 
 
216
                               gpointer data);
 
217
 
 
218
 
 
219
/* DESCRIPTION  :  This callback is called when the user changes the protocol
 
220
 *                 in the account dialog.
 
221
 * BEHAVIOR     :  Updates the content and labels.
 
222
 * PRE          :  data is a valid pointer to a valid GmAccountWindow.
 
223
 */
 
224
static void account_dialog_protocol_changed_cb (GtkWidget *menu,
 
225
                                                gpointer data);
 
226
 
 
227
 
 
228
/* Columns for the VoIP accounts */
 
229
enum {
 
230
 
 
231
  COLUMN_ACCOUNT_WEIGHT,
 
232
  COLUMN_ACCOUNT_ENABLED,
 
233
  COLUMN_ACCOUNT_DEFAULT,
 
234
  COLUMN_ACCOUNT_AID,
 
235
  COLUMN_ACCOUNT_ACCOUNT_NAME,
 
236
  COLUMN_ACCOUNT_PROTOCOL_NAME,
 
237
  COLUMN_ACCOUNT_HOST,
 
238
  COLUMN_ACCOUNT_DOMAIN,
 
239
  COLUMN_ACCOUNT_USERNAME,
 
240
  COLUMN_ACCOUNT_AUTH_USERNAME,
 
241
  COLUMN_ACCOUNT_PASSWORD,
 
242
  COLUMN_ACCOUNT_STATE,
 
243
  COLUMN_ACCOUNT_TIMEOUT,
 
244
  COLUMN_ACCOUNT_METHOD,
 
245
  COLUMN_ACCOUNT_VOICEMAILS,
 
246
  COLUMN_ACCOUNT_ERROR_MESSAGE,
 
247
  COLUMN_ACCOUNT_ACTIVATABLE,
 
248
  COLUMN_ACCOUNT_NUMBER
 
249
};
 
250
 
 
251
 
 
252
/* Functions */
 
253
static GmAccount *
 
254
gm_aw_from_string_to_account (gchar *str)
 
255
{
 
256
  GmAccount *account = NULL;
 
257
 
 
258
  gchar **couple = NULL;
 
259
 
 
260
  int size = 0;
 
261
  
 
262
  g_return_val_if_fail (str != NULL, NULL);
 
263
  
 
264
  couple = g_strsplit (str, "|", 0);
 
265
 
 
266
  if (couple) {
 
267
 
 
268
    while (couple [size])
 
269
      size++;
 
270
    size = size + 1;
 
271
 
 
272
    account = gm_account_new ();
 
273
 
 
274
    if (size >= 1 && couple [0])
 
275
      account->enabled = atoi (couple [0]);
 
276
    if (size >= 2 && couple [1])
 
277
      account->default_account = atoi (couple [1]);
 
278
    if (size >= 3 && couple [2])
 
279
      account->aid = g_strdup (couple [2]);
 
280
    if (size >= 4 && couple [3])
 
281
      account->account_name = g_strdup (couple [3]);
 
282
    if (size >= 5 && couple [4])
 
283
      account->protocol_name = g_strdup (couple [4]);
 
284
    if (size >= 6 && couple [5])
 
285
      account->host = g_strdup (couple [5]);
 
286
    if (size >= 7 && couple [6])
 
287
      account->domain = g_strdup (couple [6]);
 
288
    if (size >= 8 && couple [7])
 
289
      account->username = g_strdup (couple [7]);
 
290
    if (size >= 9 && couple [8])
 
291
      account->auth_username = g_strdup (couple [8]);
 
292
    if (size >= 10 && couple [9])
 
293
      account->password = g_strdup (couple [9]);
 
294
    if (size >= 11 && couple [10])
 
295
      account->timeout = atoi (couple [10]);
 
296
    if (size >= 12 && couple [11])
 
297
      account->method = atoi (couple [11]);
 
298
 
 
299
    g_strfreev (couple);
 
300
  }
 
301
 
 
302
  return account;
 
303
}
 
304
 
 
305
 
 
306
static gchar *
 
307
gm_aw_from_account_to_string (GmAccount *account)
 
308
{
 
309
  g_return_val_if_fail (account != NULL, NULL);
 
310
  
 
311
  return g_strdup_printf ("%d|%d|%s|%s|%s|%s|%s|%s|%s|%s|%d|%d", 
 
312
                          account->enabled,
 
313
                          account->default_account,
 
314
                          account->aid, 
 
315
                          account->account_name, 
 
316
                          account->protocol_name,
 
317
                          account->host,
 
318
                          account->domain,
 
319
                          account->username,
 
320
                          account->auth_username,
 
321
                          account->password,
 
322
                          account->timeout,
 
323
                          account->method);
 
324
}
 
325
 
 
326
 
 
327
/* GUI Functions */
 
328
static void
 
329
gm_aw_destroy (gpointer aw)
 
330
{
 
331
  g_return_if_fail (aw != NULL);
 
332
 
 
333
  delete ((GmAccountsWindow *) aw);
 
334
}
 
335
 
 
336
 
 
337
static GmAccountsWindow *
 
338
gm_aw_get_aw (GtkWidget *accounts_window)
 
339
{
 
340
  g_return_val_if_fail (accounts_window != NULL, NULL);
 
341
 
 
342
  return GM_ACCOUNTS_WINDOW (g_object_get_data (G_OBJECT (accounts_window), "GMObject"));
 
343
}
 
344
 
 
345
 
 
346
static void
 
347
gm_aw_edit_account_dialog_run (GtkWidget *accounts_window,
 
348
                               GmAccount *account,
 
349
                               GtkWidget *parent_window)
 
350
{
 
351
  GtkWidget *dialog = NULL;
 
352
 
 
353
  GtkWidget *expander = NULL;
 
354
 
 
355
  GtkSizeGroup *size_group_label = NULL;
 
356
  GtkSizeGroup *size_group_entry = NULL;
 
357
  
 
358
  GtkWidget *table = NULL;
 
359
  GtkWidget *label = NULL;
 
360
 
 
361
  PRegularExpression regex ("^[a-z0-9][-._a-z0-9 ]*$", 
 
362
                            PRegularExpression::IgnoreCase);
 
363
 
 
364
  PString username;
 
365
  PString auth_username;
 
366
  PString host;
 
367
  PString domain;
 
368
  PString password;
 
369
  PString account_name;
 
370
  PString timeout;
 
371
 
 
372
  gchar *timeout_string = NULL;
 
373
 
 
374
  gint protocol = 0;
 
375
 
 
376
  gboolean valid = FALSE;
 
377
  gboolean is_editing = FALSE;
 
378
 
 
379
  GmAccountsEditWindow *aew = NULL;
 
380
 
 
381
  is_editing = (account != NULL);
 
382
 
 
383
  /**/
 
384
  aew = new GmAccountsEditWindow ();
 
385
  dialog =
 
386
    gtk_dialog_new_with_buttons (_("Edit the Account Information"), 
 
387
                                 GTK_WINDOW (NULL),
 
388
                                 GTK_DIALOG_MODAL,
 
389
                                 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
 
390
                                 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
 
391
                                 NULL);
 
392
  gtk_dialog_set_default_response (GTK_DIALOG (dialog),
 
393
                                   GTK_RESPONSE_ACCEPT);
 
394
  gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
 
395
  gtk_window_set_transient_for (GTK_WINDOW (dialog), 
 
396
                                GTK_WINDOW (parent_window));
 
397
 
 
398
  size_group_entry = gtk_size_group_new (GTK_SIZE_GROUP_BOTH);
 
399
  size_group_label = gtk_size_group_new (GTK_SIZE_GROUP_BOTH);
 
400
  
 
401
  table = gtk_table_new (7, 2, FALSE);
 
402
  gtk_table_set_row_spacings (GTK_TABLE (table), 3);
 
403
  gtk_table_set_col_spacings (GTK_TABLE (table), 6);
 
404
  gtk_container_set_border_width (GTK_CONTAINER (table), 12);
 
405
  gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), table);
 
406
 
 
407
 
 
408
  /* Account Name */
 
409
  label = gtk_label_new (_("Account Name:"));
 
410
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
 
411
  aew->account_entry = gtk_entry_new ();
 
412
  gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 0, 1); 
 
413
  gtk_table_attach_defaults (GTK_TABLE (table), aew->account_entry, 1, 2, 0, 1); 
 
414
  gtk_entry_set_activates_default (GTK_ENTRY (aew->account_entry), TRUE);
 
415
  if (account && account->account_name)
 
416
    gtk_entry_set_text (GTK_ENTRY (aew->account_entry), account->account_name);
 
417
 
 
418
  /* Protocol */
 
419
  if (!is_editing) {
 
420
 
 
421
    label = gtk_label_new (_("Protocol:"));
 
422
    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
 
423
    gtk_label_set_mnemonic_widget (GTK_LABEL (label), aew->protocol_option_menu);
 
424
    
 
425
    aew->protocol_option_menu = gtk_combo_box_new_text ();
 
426
    gtk_combo_box_append_text (GTK_COMBO_BOX (aew->protocol_option_menu), "SIP");
 
427
    gtk_combo_box_append_text (GTK_COMBO_BOX (aew->protocol_option_menu), "H323");
 
428
    gtk_combo_box_set_active (GTK_COMBO_BOX (aew->protocol_option_menu), 0);
 
429
 
 
430
    gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 1, 2); 
 
431
    gtk_table_attach_defaults (GTK_TABLE (table), aew->protocol_option_menu, 
 
432
                               1, 2, 1, 2); 
 
433
 
 
434
    g_signal_connect (GTK_COMBO_BOX (aew->protocol_option_menu),
 
435
                      "changed",
 
436
                      G_CALLBACK (account_dialog_protocol_changed_cb),
 
437
                      (gpointer) aew);
 
438
  }
 
439
 
 
440
  /* Host */
 
441
  if (!account || !strcmp (account->protocol_name, "SIP"))
 
442
    aew->host_label = gtk_label_new (_("Registrar:"));
 
443
  else
 
444
    aew->host_label = gtk_label_new (_("Gatekeeper:"));
 
445
  gtk_misc_set_alignment (GTK_MISC (aew->host_label), 0.0, 0.5);
 
446
  aew->host_entry = gtk_entry_new ();
 
447
  gtk_size_group_add_widget (size_group_label, aew->host_label);
 
448
  gtk_size_group_add_widget (size_group_entry, aew->host_entry);
 
449
  gtk_table_attach_defaults (GTK_TABLE (table), aew->host_label, 0, 1, 2, 3); 
 
450
  gtk_table_attach_defaults (GTK_TABLE (table), aew->host_entry, 1, 2, 2, 3); 
 
451
  gtk_entry_set_activates_default (GTK_ENTRY (aew->host_entry), TRUE);
 
452
  if (account && account->host)
 
453
    gtk_entry_set_text (GTK_ENTRY (aew->host_entry), account->host);
 
454
 
 
455
  /* User Name */
 
456
  label = gtk_label_new (_("User Name:"));
 
457
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
 
458
  aew->username_entry = gtk_entry_new ();
 
459
  gtk_size_group_add_widget (size_group_label, label);
 
460
  gtk_size_group_add_widget (size_group_entry, aew->username_entry);
 
461
  gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 4, 5); 
 
462
  gtk_table_attach_defaults (GTK_TABLE (table), aew->username_entry, 
 
463
                             1, 2, 4, 5); 
 
464
  gtk_entry_set_activates_default (GTK_ENTRY (aew->username_entry), TRUE);
 
465
  if (account && account->username)
 
466
    gtk_entry_set_text (GTK_ENTRY (aew->username_entry), account->username);
 
467
 
 
468
  /* Password */
 
469
  label = gtk_label_new (_("Password:"));
 
470
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
 
471
  aew->password_entry = gtk_entry_new ();
 
472
  gtk_size_group_add_widget (size_group_label, label);
 
473
  gtk_size_group_add_widget (size_group_entry, aew->password_entry);
 
474
  gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 5, 6); 
 
475
  gtk_table_attach_defaults (GTK_TABLE (table), aew->password_entry, 
 
476
                             1, 2, 5, 6); 
 
477
  gtk_entry_set_activates_default (GTK_ENTRY (aew->password_entry), TRUE);
 
478
  gtk_entry_set_visibility (GTK_ENTRY (aew->password_entry), FALSE);
 
479
  if (account && account->password)
 
480
    gtk_entry_set_text (GTK_ENTRY (aew->password_entry), account->password);
 
481
  
 
482
 
 
483
  /* Advanced Options */
 
484
  expander = gtk_expander_new_with_mnemonic (_("More _Options"));
 
485
  gtk_table_attach_defaults (GTK_TABLE (table), expander, 0, 2, 6, 7); 
 
486
  
 
487
  table = gtk_table_new (3, 2, FALSE);
 
488
  gtk_table_set_row_spacings (GTK_TABLE (table), 3);
 
489
  gtk_table_set_col_spacings (GTK_TABLE (table), 6);
 
490
  gtk_container_set_border_width (GTK_CONTAINER (table), 0);
 
491
  gtk_container_add (GTK_CONTAINER (expander), table);
 
492
  
 
493
  /* Auth User Name */
 
494
  if (!account || !strcmp (account->protocol_name, "SIP")) {
 
495
 
 
496
    aew->auth_username_label = gtk_label_new (_("Authentication Login:"));
 
497
    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
 
498
    aew->auth_username_entry = gtk_entry_new ();
 
499
    gtk_size_group_add_widget (size_group_label, aew->auth_username_label);
 
500
    gtk_size_group_add_widget (size_group_entry, aew->auth_username_entry);
 
501
    gtk_table_attach_defaults (GTK_TABLE (table), aew->auth_username_label, 
 
502
                               0, 1, 0, 1); 
 
503
    gtk_table_attach_defaults (GTK_TABLE (table), aew->auth_username_entry, 
 
504
                               1, 2, 0, 1); 
 
505
    gtk_entry_set_activates_default (GTK_ENTRY (aew->auth_username_entry), 
 
506
                                     TRUE);
 
507
    if (account && account->auth_username)
 
508
      gtk_entry_set_text (GTK_ENTRY (aew->auth_username_entry), 
 
509
                          account->auth_username);
 
510
  }
 
511
 
 
512
  /* Realm/Domain */
 
513
  if (!account || !strcmp (account->protocol_name, "SIP"))
 
514
    aew->domain_label = gtk_label_new (_("Realm/Domain:"));
 
515
  else
 
516
    aew->domain_label = gtk_label_new (_("Gatekeeper ID:"));
 
517
  gtk_misc_set_alignment (GTK_MISC (aew->domain_label), 0.0, 0.5);
 
518
  aew->domain_entry = gtk_entry_new ();
 
519
  gtk_size_group_add_widget (size_group_label, aew->domain_label);
 
520
  gtk_size_group_add_widget (size_group_entry, aew->domain_entry);
 
521
  gtk_table_attach_defaults (GTK_TABLE (table), aew->domain_label, 0, 1, 1, 2); 
 
522
  gtk_table_attach_defaults (GTK_TABLE (table), aew->domain_entry, 1, 2, 1, 2); 
 
523
  gtk_entry_set_activates_default (GTK_ENTRY (aew->domain_entry), TRUE);
 
524
  if (account && account->domain)
 
525
    gtk_entry_set_text (GTK_ENTRY (aew->domain_entry), account->domain);
 
526
 
 
527
  /* Timeout */
 
528
  label = gtk_label_new (_("Registration Timeout:"));
 
529
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
 
530
  aew->timeout_entry = gtk_entry_new ();
 
531
  gtk_size_group_add_widget (size_group_label, label);
 
532
  gtk_size_group_add_widget (size_group_entry, aew->timeout_entry);
 
533
  gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 2, 3); 
 
534
  gtk_table_attach_defaults (GTK_TABLE (table), aew->timeout_entry, 
 
535
                             1, 2, 2, 3); 
 
536
  gtk_entry_set_activates_default (GTK_ENTRY (aew->timeout_entry), TRUE);
 
537
  if (account) 
 
538
    timeout_string = g_strdup_printf ("%d", account->timeout);
 
539
  else
 
540
    timeout_string = g_strdup ("3600");
 
541
  gtk_entry_set_text (GTK_ENTRY (aew->timeout_entry), timeout_string);
 
542
  g_free (timeout_string);
 
543
 
 
544
 
 
545
  gtk_widget_show_all (dialog);
 
546
  while (!valid) {
 
547
 
 
548
    switch (gtk_dialog_run (GTK_DIALOG (dialog))) {
 
549
 
 
550
    case GTK_RESPONSE_ACCEPT:
 
551
 
 
552
      username = gtk_entry_get_text (GTK_ENTRY (aew->username_entry));
 
553
      if (aew->auth_username_entry)
 
554
        auth_username = gtk_entry_get_text (GTK_ENTRY (aew->auth_username_entry));
 
555
      account_name = gtk_entry_get_text (GTK_ENTRY (aew->account_entry));
 
556
      host = gtk_entry_get_text (GTK_ENTRY (aew->host_entry));
 
557
      password = gtk_entry_get_text (GTK_ENTRY (aew->password_entry));
 
558
      domain = gtk_entry_get_text (GTK_ENTRY (aew->domain_entry));
 
559
      timeout = gtk_entry_get_text (GTK_ENTRY (aew->timeout_entry));
 
560
 
 
561
      if (!is_editing)
 
562
        protocol = // take it from the menu
 
563
          gtk_combo_box_get_active (GTK_COMBO_BOX (aew->protocol_option_menu));
 
564
      else // take it from the existing account field
 
565
        protocol = (account->protocol_name 
 
566
                    && !strcmp (account->protocol_name, "SIP") ? 0 : 1);
 
567
 
 
568
      /* Check at least an account name, registrar, 
 
569
       * and username are provided */
 
570
      if (protocol == 0) // SIP
 
571
        valid = (username.FindRegEx (regex) != P_MAX_INDEX
 
572
                 && account_name.FindRegEx (regex) != P_MAX_INDEX);
 
573
      else // H323
 
574
        valid = (account_name.FindRegEx (regex) != P_MAX_INDEX);
 
575
 
 
576
      if (valid) {
 
577
 
 
578
        if (!is_editing)
 
579
          account = gm_account_new ();
 
580
 
 
581
        g_free (account->username);
 
582
        g_free (account->auth_username);
 
583
        g_free (account->account_name);
 
584
        g_free (account->host);
 
585
        g_free (account->password);
 
586
        g_free (account->domain);
 
587
        if (!is_editing)
 
588
          g_free (account->protocol_name);
 
589
 
 
590
        account->account_name = g_strdup (account_name);
 
591
        account->host = g_strdup (host);
 
592
        account->username = g_strdup (username);
 
593
        
 
594
        if (!strcmp (domain, ""))
 
595
          if (protocol == 0) // SIP
 
596
            account->domain = g_strdup (host);
 
597
          else
 
598
            account->domain = g_strdup ("");
 
599
        else
 
600
          account->domain = g_strdup (domain);
 
601
 
 
602
        if (!strcmp (auth_username, ""))
 
603
          account->auth_username = g_strdup (username);
 
604
        else
 
605
          account->auth_username = g_strdup (auth_username);
 
606
 
 
607
        account->password = g_strdup (password);
 
608
        if (atoi (timeout) == 0)
 
609
          account->timeout = 3600;
 
610
        else 
 
611
          account->timeout = PMAX (atoi (timeout), 25);
 
612
 
 
613
        if (!is_editing)
 
614
          account->protocol_name = g_strdup ((protocol == 0) ? "SIP" : "H323");
 
615
 
 
616
        /* The GUI will be updated through the GmConf notifiers */
 
617
        if (is_editing) 
 
618
          gnomemeeting_account_modify (account);
 
619
        else 
 
620
          gnomemeeting_account_add (account);
 
621
      }
 
622
      else {
 
623
        if (protocol == 0) // SIP
 
624
          gnomemeeting_error_dialog (GTK_WINDOW (dialog), _("Missing information"), _("Please make sure to provide a valid account name, host name, and user name."));
 
625
        else // H323
 
626
          gnomemeeting_error_dialog (GTK_WINDOW (dialog), _("Missing information"), _("Please make sure to provide a valid account name, host name and registration timeout."));
 
627
      }
 
628
      break;
 
629
 
 
630
    case GTK_RESPONSE_REJECT:
 
631
      valid = TRUE;
 
632
      break;
 
633
    }
 
634
  }
 
635
 
 
636
  delete ((GmAccountsEditWindow *) aew);
 
637
  gtk_widget_destroy (dialog);
 
638
}
 
639
 
 
640
 
 
641
static void 
 
642
gm_aw_delete_account_dialog_run (GtkWidget *accounts_window,
 
643
                                 GmAccount *account,
 
644
                                 GtkWidget *parent_window)
 
645
{
 
646
  GtkWidget *dialog = NULL;
 
647
 
 
648
  gchar *confirm_msg = NULL;
 
649
 
 
650
  g_return_if_fail (accounts_window != NULL);
 
651
  g_return_if_fail (account != NULL);
 
652
 
 
653
  /* Create the dialog to delete the account */
 
654
  confirm_msg = 
 
655
    g_strdup_printf (_("Are you sure you want to delete account %s?"), 
 
656
                     account->account_name);
 
657
  dialog =
 
658
    gtk_message_dialog_new (GTK_WINDOW (accounts_window),
 
659
                            GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION,
 
660
                            GTK_BUTTONS_YES_NO, confirm_msg);
 
661
  g_free (confirm_msg);
 
662
 
 
663
  gtk_dialog_set_default_response (GTK_DIALOG (dialog),
 
664
                                   GTK_RESPONSE_YES);
 
665
 
 
666
  gtk_widget_show_all (dialog);
 
667
 
 
668
 
 
669
  /* Now run the dialg */
 
670
  switch (gtk_dialog_run (GTK_DIALOG (dialog))) {
 
671
 
 
672
  case GTK_RESPONSE_YES:
 
673
 
 
674
    /* The GUI will be updated throught the GmConf notifiers */
 
675
    gnomemeeting_account_delete (account);
 
676
    break;
 
677
  }
 
678
 
 
679
  gtk_widget_destroy (dialog);
 
680
}
 
681
 
 
682
 
 
683
GmAccount *
 
684
gm_aw_get_selected_account (GtkWidget *accounts_window)
 
685
{
 
686
  GmAccountsWindow *aw = NULL;
 
687
 
 
688
  GtkTreeModel *model = NULL;
 
689
  GtkTreeSelection *selection = NULL;
 
690
  GtkTreeIter iter;
 
691
 
 
692
  GmAccount *account = NULL;
 
693
 
 
694
  g_return_val_if_fail (accounts_window != NULL, NULL);
 
695
 
 
696
  /* Get the required data */
 
697
  aw = gm_aw_get_aw (accounts_window);
 
698
 
 
699
  g_return_val_if_fail (aw != NULL, NULL);
 
700
 
 
701
  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (aw->accounts_list));
 
702
  model = gtk_tree_view_get_model (GTK_TREE_VIEW (aw->accounts_list));
 
703
 
 
704
  if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
 
705
 
 
706
    account = gm_account_new ();
 
707
 
 
708
    gtk_tree_model_get (GTK_TREE_MODEL (model), &iter, 
 
709
                        COLUMN_ACCOUNT_ENABLED, &account->enabled,
 
710
                        COLUMN_ACCOUNT_DEFAULT, &account->default_account,
 
711
                        COLUMN_ACCOUNT_AID, &account->aid,
 
712
                        COLUMN_ACCOUNT_ACCOUNT_NAME, &account->account_name,
 
713
                        COLUMN_ACCOUNT_PROTOCOL_NAME, &account->protocol_name,
 
714
                        COLUMN_ACCOUNT_HOST, &account->host,
 
715
                        COLUMN_ACCOUNT_DOMAIN, &account->domain,
 
716
                        COLUMN_ACCOUNT_USERNAME, &account->username,
 
717
                        COLUMN_ACCOUNT_AUTH_USERNAME, &account->auth_username,
 
718
                        COLUMN_ACCOUNT_PASSWORD, &account->password,
 
719
                        COLUMN_ACCOUNT_TIMEOUT, &account->timeout,
 
720
                        COLUMN_ACCOUNT_METHOD, &account->method,
 
721
                        -1); 
 
722
 
 
723
    if (account->timeout == 0)
 
724
      account->timeout = 3600;
 
725
  }
 
726
 
 
727
  return account;
 
728
}
 
729
 
 
730
 
 
731
/* GTK+ Callbacks */
 
732
static gint
 
733
account_clicked_cb (GtkWidget *w,
 
734
                    GdkEventButton *e,
 
735
                    gpointer data)
 
736
{
 
737
  GmAccount *account = NULL;
 
738
  GmAccountsWindow *aw = NULL;
 
739
 
 
740
  g_return_val_if_fail (data != NULL, FALSE);
 
741
 
 
742
  aw = gm_aw_get_aw (GTK_WIDGET (data));
 
743
  g_return_val_if_fail (aw != NULL, FALSE);
 
744
  
 
745
  account = gm_aw_get_selected_account (GTK_WIDGET (data));
 
746
 
 
747
  if (account) {
 
748
 
 
749
    gtk_widget_set_sensitive (aw->delete_button, TRUE);
 
750
    gtk_widget_set_sensitive (aw->edit_button, TRUE);
 
751
    if (!account->default_account)
 
752
      gtk_widget_set_sensitive (aw->default_button, TRUE);
 
753
    else
 
754
      gtk_widget_set_sensitive (aw->default_button, FALSE);
 
755
 
 
756
    gm_account_delete (account);
 
757
  }
 
758
  else {
 
759
 
 
760
    gtk_widget_set_sensitive (aw->delete_button, FALSE);
 
761
    gtk_widget_set_sensitive (aw->edit_button, FALSE);
 
762
    gtk_widget_set_sensitive (aw->default_button, FALSE);
 
763
  }
 
764
 
 
765
  return TRUE;
 
766
}
 
767
 
 
768
 
 
769
static void
 
770
account_toggled_cb (GtkCellRendererToggle *cell,
 
771
                    gchar *path_str,
 
772
                    gpointer data)
 
773
{
 
774
  GMManager *ep = NULL;
 
775
 
 
776
  GmAccountsWindow *aw = NULL;
 
777
  GmAccount *account = NULL;
 
778
 
 
779
  GtkTreePath *path = NULL;
 
780
  GtkTreeSelection *selection = NULL;
 
781
 
 
782
  GtkWidget *accounts_window = NULL;
 
783
 
 
784
  accounts_window = GnomeMeeting::Process ()->GetAccountsWindow ();
 
785
  ep = GnomeMeeting::Process ()->GetManager ();
 
786
 
 
787
  aw = gm_aw_get_aw (accounts_window);
 
788
 
 
789
 
 
790
  /* Make sure the toggled row is selected */
 
791
  selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (aw->accounts_list));
 
792
  path = gtk_tree_path_new_from_string (path_str);
 
793
  gtk_tree_selection_select_path (selection, path);
 
794
  gtk_tree_path_free (path);
 
795
 
 
796
  /* Update the config */
 
797
  account = gm_aw_get_selected_account (accounts_window);
 
798
  gnomemeeting_account_toggle_active (account);
 
799
 
 
800
  /* Update the account */
 
801
  gdk_threads_leave ();
 
802
  ep->Register (account);
 
803
  gdk_threads_enter ();
 
804
 
 
805
  gm_account_delete (account);
 
806
}
 
807
 
 
808
 
 
809
static void
 
810
add_account_cb (GtkWidget *button, 
 
811
                gpointer data)
 
812
{
 
813
  GtkWidget *accounts_window = NULL;
 
814
 
 
815
  accounts_window = GnomeMeeting::Process ()->GetAccountsWindow (); 
 
816
 
 
817
  gm_aw_edit_account_dialog_run (GTK_WIDGET (accounts_window), 
 
818
                                 NULL, 
 
819
                                 GTK_WIDGET (accounts_window));
 
820
}
 
821
 
 
822
 
 
823
static void
 
824
edit_account_cb (GtkWidget *button, 
 
825
                 gpointer data)
 
826
{
 
827
  GmAccount *account = NULL;
 
828
  GtkWidget *accounts_window = NULL;
 
829
 
 
830
  accounts_window = GnomeMeeting::Process ()->GetAccountsWindow (); 
 
831
 
 
832
  account = gm_aw_get_selected_account (accounts_window);
 
833
  gm_aw_edit_account_dialog_run (GTK_WIDGET (accounts_window), 
 
834
                                 account, 
 
835
                                 GTK_WIDGET (accounts_window));
 
836
  gm_account_delete (account);
 
837
}
 
838
 
 
839
 
 
840
static void
 
841
set_account_as_default_cb (GtkWidget *button, 
 
842
                           gpointer data)
 
843
{
 
844
  GmAccount *account = NULL;
 
845
  GtkWidget *accounts_window = NULL;
 
846
 
 
847
  accounts_window = GnomeMeeting::Process ()->GetAccountsWindow (); 
 
848
 
 
849
  account = gm_aw_get_selected_account (accounts_window);
 
850
  gnomemeeting_account_set_default (account, TRUE);
 
851
  gm_account_delete (account);
 
852
}
 
853
 
 
854
 
 
855
static void
 
856
delete_account_cb (GtkWidget *button, 
 
857
                   gpointer data)
 
858
{
 
859
  GmAccount *account = NULL;
 
860
  GtkWidget *accounts_window = NULL;
 
861
 
 
862
  accounts_window = GnomeMeeting::Process ()->GetAccountsWindow (); 
 
863
 
 
864
  account = gm_aw_get_selected_account (accounts_window);
 
865
  if (account)
 
866
    gm_aw_delete_account_dialog_run (GTK_WIDGET (accounts_window), 
 
867
                                     account, 
 
868
                                     GTK_WIDGET (accounts_window));
 
869
  gm_account_delete (account);
 
870
}
 
871
 
 
872
 
 
873
static void
 
874
account_dialog_protocol_changed_cb (GtkWidget *menu,
 
875
                                    gpointer data)
 
876
{
 
877
  GmAccountsEditWindow *aew = NULL;
 
878
 
 
879
  g_return_if_fail (data != NULL);
 
880
 
 
881
  aew = GM_ACCOUNTS_EDIT_WINDOW (data);
 
882
 
 
883
  switch (gtk_combo_box_get_active (GTK_COMBO_BOX (aew->protocol_option_menu)))
 
884
    {
 
885
    case 0:
 
886
      gtk_label_set_text (GTK_LABEL (aew->host_label), _("Registrar:"));
 
887
      gtk_label_set_text (GTK_LABEL (aew->domain_label), _("Realm/Domain:"));
 
888
      gtk_widget_show (aew->auth_username_label);
 
889
      gtk_widget_show (aew->auth_username_entry);
 
890
      break;
 
891
 
 
892
    case 1:
 
893
      gtk_label_set_text (GTK_LABEL (aew->host_label), _("Gatekeeper:"));
 
894
      gtk_label_set_text (GTK_LABEL (aew->domain_label), _("Gatekeeper ID:"));
 
895
      gtk_widget_hide (aew->auth_username_label);
 
896
      gtk_widget_hide (aew->auth_username_entry);
 
897
      break;
 
898
    };
 
899
}
 
900
 
 
901
 
 
902
/* Implementation of public functions */
 
903
GmAccount *
 
904
gm_account_new ()
 
905
{
 
906
  GmAccount *account = NULL;
 
907
 
 
908
  account = g_new (GmAccount, 1);
 
909
 
 
910
  account->aid = g_strdup (OpalGloballyUniqueID ().AsString ());
 
911
  account->account_name = NULL;
 
912
  account->protocol_name = NULL;
 
913
  account->host = NULL;
 
914
  account->domain = NULL;
 
915
  account->username = NULL;
 
916
  account->auth_username = NULL;
 
917
  account->password = NULL;
 
918
  account->enabled = FALSE;
 
919
  account->default_account = FALSE;
 
920
  account->timeout = 3600;
 
921
  account->method = 0;
 
922
 
 
923
  return account;
 
924
}
 
925
 
 
926
 
 
927
void
 
928
gm_account_delete (GmAccount *account)
 
929
{
 
930
  if (!account)
 
931
    return;
 
932
 
 
933
  g_free (account->aid);
 
934
  g_free (account->account_name);
 
935
  g_free (account->protocol_name);
 
936
  g_free (account->domain);
 
937
  g_free (account->auth_username);
 
938
  g_free (account->username);
 
939
  g_free (account->password);
 
940
  g_free (account->host);
 
941
 
 
942
  g_free (account);
 
943
}
 
944
 
 
945
 
 
946
GmAccount *
 
947
gm_account_copy (GmAccount *a)
 
948
{
 
949
  GmAccount *account = NULL;
 
950
 
 
951
  if (!a)
 
952
    return account;
 
953
 
 
954
  account = g_new (GmAccount, 1);
 
955
 
 
956
  account->aid = g_strdup (a->aid);
 
957
  account->account_name = g_strdup (a->account_name);
 
958
  account->protocol_name = g_strdup (a->protocol_name);
 
959
  account->host = g_strdup (a->host);
 
960
  account->domain = g_strdup (a->domain);
 
961
  account->username = g_strdup (a->username);
 
962
  account->auth_username = g_strdup (a->auth_username);
 
963
  account->password = g_strdup (a->password);
 
964
  account->enabled = a->enabled;
 
965
  account->default_account = a->default_account;
 
966
  account->timeout = a->timeout;
 
967
  account->method = a->method;
 
968
 
 
969
  return account;
 
970
}
 
971
 
 
972
 
 
973
gboolean 
 
974
gnomemeeting_account_add (GmAccount *account)
 
975
{
 
976
  GSList *list = NULL;
 
977
  gchar *entry = NULL;
 
978
 
 
979
  if (account == NULL)
 
980
    return FALSE;
 
981
  
 
982
  list = 
 
983
    gm_conf_get_string_list (PROTOCOLS_KEY "accounts_list");
 
984
 
 
985
  if (list == NULL)
 
986
    account->default_account = TRUE;
 
987
 
 
988
  entry = gm_aw_from_account_to_string (account);
 
989
 
 
990
  list = g_slist_append (list, (gpointer) entry);
 
991
  gm_conf_set_string_list (PROTOCOLS_KEY "accounts_list", 
 
992
                           list);
 
993
 
 
994
  g_slist_foreach (list, (GFunc) g_free, NULL);
 
995
  g_slist_free (list);
 
996
 
 
997
  return TRUE;
 
998
}
 
999
 
 
1000
 
 
1001
gboolean 
 
1002
gnomemeeting_account_delete (GmAccount *account)
 
1003
{
 
1004
  GSList *list = NULL;
 
1005
  GSList *l = NULL;
 
1006
  GSList *l_default_delete = NULL;
 
1007
  GSList *l_delete = NULL;
 
1008
 
 
1009
  GmAccount *current_account = NULL;
 
1010
  
 
1011
  gchar *entry = NULL;
 
1012
 
 
1013
  gboolean found = FALSE;
 
1014
  gboolean new_default = FALSE;
 
1015
 
 
1016
  if (account == NULL)
 
1017
    return FALSE;
 
1018
 
 
1019
  list = 
 
1020
    gm_conf_get_string_list (PROTOCOLS_KEY "accounts_list");
 
1021
 
 
1022
  l = list;
 
1023
  while (l && (!found || !new_default)) {
 
1024
 
 
1025
    if (l->data) {
 
1026
 
 
1027
      current_account = gm_aw_from_string_to_account ((char *) l->data);
 
1028
      if (current_account->aid && account->aid 
 
1029
          && !strcmp (current_account->aid, account->aid)) {
 
1030
        
 
1031
        found = TRUE;
 
1032
        l_delete = l;
 
1033
      }
 
1034
      else if (account->default_account) { /* It was the default account */
 
1035
 
 
1036
        if (current_account->protocol_name && account->protocol_name
 
1037
            && !strcmp (current_account->protocol_name, 
 
1038
                        account->protocol_name)) {
 
1039
 
 
1040
          l_default_delete = l;
 
1041
          current_account->default_account = TRUE;
 
1042
          entry = gm_aw_from_account_to_string (current_account);
 
1043
          new_default = TRUE;
 
1044
        }
 
1045
      }
 
1046
 
 
1047
      gm_account_delete (current_account);
 
1048
    }
 
1049
 
 
1050
    l = g_slist_next (l);
 
1051
  }
 
1052
 
 
1053
  if (found) {
 
1054
 
 
1055
    list = g_slist_remove_link (list, l_delete);
 
1056
 
 
1057
    g_free (l_delete->data);
 
1058
    g_slist_free_1 (l_delete);
 
1059
  }
 
1060
 
 
1061
  if (new_default) {
 
1062
 
 
1063
    list = g_slist_insert_before (list, l_default_delete, (gpointer) entry);
 
1064
    list = g_slist_remove_link (list, l_default_delete);
 
1065
 
 
1066
    g_free (l_default_delete->data);
 
1067
    g_slist_free_1 (l_default_delete);
 
1068
  }
 
1069
 
 
1070
  gm_conf_set_string_list (PROTOCOLS_KEY "accounts_list", 
 
1071
                           list);
 
1072
 
 
1073
  g_slist_foreach (list, (GFunc) g_free, NULL);
 
1074
  g_slist_free (list);
 
1075
 
 
1076
  return found;
 
1077
}
 
1078
 
 
1079
 
 
1080
gboolean 
 
1081
gnomemeeting_account_modify (GmAccount *account)
 
1082
{
 
1083
  GSList *list = NULL;
 
1084
  GSList *l = NULL;
 
1085
 
 
1086
  gchar *entry = NULL;
 
1087
  gchar **couple = NULL;
 
1088
 
 
1089
  gboolean found = FALSE;
 
1090
 
 
1091
  if (account == NULL)
 
1092
    return FALSE;
 
1093
 
 
1094
  list = 
 
1095
    gm_conf_get_string_list (PROTOCOLS_KEY "accounts_list");
 
1096
 
 
1097
  entry = gm_aw_from_account_to_string (account);
 
1098
 
 
1099
  l = list;
 
1100
  while (l && !found) {
 
1101
 
 
1102
    if (l->data) {
 
1103
 
 
1104
      couple = g_strsplit ((const char *) l->data, "|", 0);
 
1105
      if (couple && couple [2] && !strcmp (couple [2], account->aid)) {
 
1106
 
 
1107
        found = TRUE;
 
1108
        break;
 
1109
      }
 
1110
    }
 
1111
 
 
1112
    l = g_slist_next (l);
 
1113
  }
 
1114
 
 
1115
  if (found) {
 
1116
 
 
1117
    list = g_slist_insert_before (list, l, (gpointer) entry);
 
1118
    list = g_slist_remove_link (list, l);
 
1119
 
 
1120
    g_free (l->data);
 
1121
    g_slist_free_1 (l);
 
1122
 
 
1123
    gm_conf_set_string_list (PROTOCOLS_KEY "accounts_list", 
 
1124
                             list);
 
1125
  }
 
1126
 
 
1127
  g_slist_foreach (list, (GFunc) g_free, NULL);
 
1128
  g_slist_free (list);
 
1129
 
 
1130
  return found;
 
1131
}
 
1132
 
 
1133
 
 
1134
GSList *
 
1135
gnomemeeting_get_accounts_list ()
 
1136
{
 
1137
  GSList *result = NULL;
 
1138
 
 
1139
  GSList *accounts_data_iter = NULL;
 
1140
  GSList *accounts_data = NULL;
 
1141
 
 
1142
  GmAccount *account = NULL;
 
1143
 
 
1144
  accounts_data = 
 
1145
    gm_conf_get_string_list (PROTOCOLS_KEY "accounts_list");
 
1146
 
 
1147
  accounts_data_iter = accounts_data;
 
1148
  while (accounts_data_iter) {
 
1149
 
 
1150
    account = gm_aw_from_string_to_account ((gchar *) accounts_data_iter->data);
 
1151
 
 
1152
    if (account != NULL)
 
1153
      result = g_slist_append (result, (void *) account);
 
1154
 
 
1155
    accounts_data_iter = g_slist_next (accounts_data_iter);
 
1156
  }
 
1157
 
 
1158
  g_slist_foreach (accounts_data, (GFunc) g_free, NULL);
 
1159
  g_slist_free (accounts_data);
 
1160
 
 
1161
  return result;
 
1162
}
 
1163
 
 
1164
 
 
1165
GmAccount *
 
1166
gnomemeeting_get_account (const char *domain)
 
1167
{
 
1168
  GmAccount *current_account = NULL;
 
1169
 
 
1170
  GSList *list = NULL;
 
1171
  GSList *l = NULL;
 
1172
 
 
1173
  gboolean found = FALSE;
 
1174
  
 
1175
  g_return_val_if_fail (domain != NULL, NULL);
 
1176
  
 
1177
  list = 
 
1178
    gm_conf_get_string_list (PROTOCOLS_KEY "accounts_list");
 
1179
 
 
1180
  l = list;
 
1181
  while (l && !found) {
 
1182
 
 
1183
    if (l->data) {
 
1184
 
 
1185
      current_account = gm_aw_from_string_to_account ((gchar *) l->data);
 
1186
      if ((current_account->domain
 
1187
          && !g_ascii_strcasecmp (current_account->domain, domain))
 
1188
          || (current_account->host
 
1189
              && !g_ascii_strcasecmp (current_account->host, domain))) {
 
1190
        
 
1191
        found = TRUE;
 
1192
        break;
 
1193
      }
 
1194
 
 
1195
      gm_account_delete (current_account);
 
1196
      current_account = NULL;
 
1197
    }
 
1198
 
 
1199
    l = g_slist_next (l);
 
1200
  }
 
1201
 
 
1202
  g_slist_foreach (list, (GFunc) g_free, NULL);
 
1203
  g_slist_free (list);
 
1204
 
 
1205
  return current_account;
 
1206
}
 
1207
 
 
1208
 
 
1209
GmAccount *
 
1210
gnomemeeting_get_default_account (gchar *protocol)
 
1211
{
 
1212
  GmAccount *current_account = NULL;
 
1213
 
 
1214
  GSList *list = NULL;
 
1215
  GSList *l = NULL;
 
1216
 
 
1217
  gboolean found = FALSE;
 
1218
  
 
1219
  g_return_val_if_fail (protocol != NULL, NULL);
 
1220
  
 
1221
  list = 
 
1222
    gm_conf_get_string_list (PROTOCOLS_KEY "accounts_list");
 
1223
 
 
1224
  l = list;
 
1225
  while (l && !found) {
 
1226
 
 
1227
    if (l->data) {
 
1228
 
 
1229
      current_account = gm_aw_from_string_to_account ((gchar *) l->data);
 
1230
      if (current_account->protocol_name
 
1231
          && current_account->default_account
 
1232
          && !g_ascii_strcasecmp (current_account->protocol_name, protocol)) {
 
1233
        
 
1234
        found = TRUE;
 
1235
        break;
 
1236
      }
 
1237
 
 
1238
      gm_account_delete (current_account);
 
1239
      current_account = NULL;
 
1240
    }
 
1241
 
 
1242
    l = g_slist_next (l);
 
1243
  }
 
1244
 
 
1245
  g_slist_foreach (list, (GFunc) g_free, NULL);
 
1246
  g_slist_free (list);
 
1247
 
 
1248
  return current_account;
 
1249
}
 
1250
 
 
1251
 
 
1252
gboolean 
 
1253
gnomemeeting_account_toggle_active (GmAccount *account)
 
1254
{
 
1255
  GmAccount *current_account = NULL;
 
1256
  
 
1257
  GSList *accounts = NULL;
 
1258
  GSList *accounts_iter = NULL;
 
1259
  
 
1260
  gchar *entry = NULL;
 
1261
 
 
1262
  if (!account)
 
1263
    return FALSE;
 
1264
 
 
1265
  accounts = gm_conf_get_string_list (PROTOCOLS_KEY "accounts_list");
 
1266
 
 
1267
  accounts_iter = accounts;
 
1268
  while (accounts_iter) {
 
1269
 
 
1270
    current_account = 
 
1271
      gm_aw_from_string_to_account ((gchar *) accounts_iter->data);
 
1272
 
 
1273
    if (!strcmp (account->protocol_name, "H323")
 
1274
        && !strcmp (current_account->protocol_name, "H323")
 
1275
        && !account->enabled) 
 
1276
      current_account->enabled = FALSE;
 
1277
    
 
1278
    if (!strcmp (current_account->aid, account->aid)) {
 
1279
      
 
1280
      current_account->enabled = !account->enabled;
 
1281
      account->enabled = current_account->enabled;
 
1282
    }
 
1283
    
 
1284
    entry = gm_aw_from_account_to_string (current_account);
 
1285
    g_free (accounts_iter->data);
 
1286
    accounts_iter->data = entry;
 
1287
 
 
1288
    accounts_iter = g_slist_next (accounts_iter);
 
1289
  }
 
1290
 
 
1291
  gm_conf_set_string_list (PROTOCOLS_KEY "accounts_list", accounts);
 
1292
  
 
1293
  g_slist_foreach (accounts, (GFunc) g_free, NULL);
 
1294
  g_slist_free (accounts);
 
1295
 
 
1296
  return TRUE;
 
1297
}
 
1298
 
 
1299
 
 
1300
gboolean 
 
1301
gnomemeeting_account_set_default (GmAccount *account,
 
1302
                                  gboolean default_account)
 
1303
{
 
1304
  GmAccount *current_account = NULL;
 
1305
 
 
1306
  GSList *accounts = NULL;
 
1307
  GSList *accounts_iter = NULL;
 
1308
 
 
1309
  gchar *entry = NULL;
 
1310
  
 
1311
  gboolean found = FALSE;
 
1312
  
 
1313
  if (!account || !account->protocol_name)
 
1314
    return FALSE;
 
1315
 
 
1316
  accounts = gm_conf_get_string_list (PROTOCOLS_KEY "accounts_list");
 
1317
 
 
1318
  /* Only one account for each protocol as default at a time */
 
1319
  accounts_iter = accounts;
 
1320
  while (accounts_iter) {
 
1321
 
 
1322
    current_account = 
 
1323
      gm_aw_from_string_to_account ((gchar *) accounts_iter->data);
 
1324
    if (!strcmp (current_account->protocol_name, account->protocol_name)) {
 
1325
      
 
1326
      /* Same protocol, other account */
 
1327
      if (strcmp (current_account->aid, account->aid)) {
 
1328
 
 
1329
        current_account->default_account = !default_account;
 
1330
      }
 
1331
      /* Same protocol, same account */
 
1332
      else {
 
1333
 
 
1334
        current_account->default_account = default_account;
 
1335
        account->default_account = default_account;
 
1336
        found = TRUE;
 
1337
      }
 
1338
 
 
1339
      entry = gm_aw_from_account_to_string (current_account);
 
1340
      g_free (accounts_iter->data);
 
1341
      accounts_iter->data = entry;
 
1342
    }
 
1343
 
 
1344
    accounts_iter = g_slist_next (accounts_iter);
 
1345
  }
 
1346
  
 
1347
  gm_conf_set_string_list (PROTOCOLS_KEY "accounts_list", accounts);
 
1348
  
 
1349
  g_slist_foreach (accounts, (GFunc) g_free, NULL);
 
1350
  g_slist_free (accounts);
 
1351
  
 
1352
  return found;
 
1353
}
 
1354
 
 
1355
 
 
1356
GtkWidget *
 
1357
gm_accounts_window_new ()
 
1358
{
 
1359
  GmAccountsWindow *aw = NULL;
 
1360
 
 
1361
  GtkWidget *window = NULL;
 
1362
 
 
1363
  GtkWidget *event_box = NULL;
 
1364
  GtkWidget *scroll_window = NULL;
 
1365
 
 
1366
  GtkWidget *frame = NULL;
 
1367
  GtkWidget *hbox = NULL;
 
1368
 
 
1369
  GtkWidget *button = NULL;
 
1370
  GtkWidget *buttons_vbox = NULL;
 
1371
  GtkWidget *alignment = NULL;
 
1372
 
 
1373
  GtkCellRenderer *renderer = NULL;
 
1374
  GtkListStore *list_store = NULL;
 
1375
  GtkTreeViewColumn *column = NULL;
 
1376
 
 
1377
  gchar *column_names [] = {
 
1378
 
 
1379
    "",
 
1380
    "",
 
1381
    "",
 
1382
    "",
 
1383
    _("Account Name"),
 
1384
    _("Protocol"),
 
1385
    "",
 
1386
    "",
 
1387
    "",
 
1388
    "",
 
1389
    "",
 
1390
    "",
 
1391
    "",
 
1392
    "",
 
1393
    _("Voice Mails"),
 
1394
    _("Status"),
 
1395
    ""
 
1396
  };
 
1397
 
 
1398
  /* The window */
 
1399
  window = gtk_dialog_new ();
 
1400
  gtk_dialog_add_button (GTK_DIALOG (window), GTK_STOCK_CLOSE, 0);
 
1401
 
 
1402
  g_object_set_data_full (G_OBJECT (window), "window_name",
 
1403
                          g_strdup ("accounts_window"), g_free);
 
1404
 
 
1405
  gtk_window_set_title (GTK_WINDOW (window), _("Accounts"));
 
1406
  gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
 
1407
 
 
1408
  aw = new GmAccountsWindow ();
 
1409
  g_object_set_data_full (G_OBJECT (window), "GMObject", 
 
1410
                          aw, gm_aw_destroy);
 
1411
 
 
1412
 
 
1413
  /* The accounts list store */
 
1414
  list_store = gtk_list_store_new (COLUMN_ACCOUNT_NUMBER,
 
1415
                                   G_TYPE_INT,
 
1416
                                   G_TYPE_BOOLEAN, /* Enabled? */
 
1417
                                   G_TYPE_BOOLEAN, /* Default? */
 
1418
                                   G_TYPE_STRING,  /* AID */
 
1419
                                   G_TYPE_STRING,  /* Account Name */
 
1420
                                   G_TYPE_STRING,  /* Protocol Name */
 
1421
                                   G_TYPE_STRING,  /* Host */
 
1422
                                   G_TYPE_STRING,  /* Domain */
 
1423
                                   G_TYPE_STRING,  /* Username */
 
1424
                                   G_TYPE_STRING,  /* Auth Username */
 
1425
                                   G_TYPE_STRING,  /* Password */
 
1426
                                   G_TYPE_INT,     /* State */
 
1427
                                   G_TYPE_INT,     /* Timeout */
 
1428
                                   G_TYPE_INT,     /* Method */
 
1429
                                   G_TYPE_STRING,  /* VoiceMails */  
 
1430
                                   G_TYPE_STRING,  /* Error Message */  
 
1431
                                   G_TYPE_INT);    /* Activatable */
 
1432
 
 
1433
  aw->accounts_list = 
 
1434
    gtk_tree_view_new_with_model (GTK_TREE_MODEL (list_store));
 
1435
  gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (aw->accounts_list), TRUE);
 
1436
  gtk_tree_view_set_reorderable (GTK_TREE_VIEW (aw->accounts_list), TRUE);
 
1437
 
 
1438
  renderer = gtk_cell_renderer_toggle_new ();
 
1439
  column = gtk_tree_view_column_new_with_attributes (_("A"),
 
1440
                                                     renderer,
 
1441
                                                     "active", 
 
1442
                                                     COLUMN_ACCOUNT_ENABLED,
 
1443
                                                     NULL);
 
1444
  gtk_tree_view_column_set_fixed_width (GTK_TREE_VIEW_COLUMN (column), 25);
 
1445
  gtk_tree_view_append_column (GTK_TREE_VIEW (aw->accounts_list), column);
 
1446
  gtk_tree_view_column_add_attribute (column, renderer, 
 
1447
                                      "activatable", 
 
1448
                                      COLUMN_ACCOUNT_ACTIVATABLE);
 
1449
  g_signal_connect (G_OBJECT (renderer), "toggled",
 
1450
                    G_CALLBACK (account_toggled_cb),
 
1451
                    (gpointer) aw->accounts_list);
 
1452
 
 
1453
 
 
1454
  /* Add all text renderers, ie all except the 
 
1455
   * "ACCOUNT_ENABLED/DEFAULT" columns */
 
1456
  for (int i = COLUMN_ACCOUNT_AID ; i < COLUMN_ACCOUNT_NUMBER - 1 ; i++) {
 
1457
 
 
1458
    renderer = gtk_cell_renderer_text_new ();
 
1459
    column = gtk_tree_view_column_new_with_attributes (column_names [i],
 
1460
                                                       renderer,
 
1461
                                                       "text", 
 
1462
                                                       i,
 
1463
                                                       "weight",
 
1464
                                                       COLUMN_ACCOUNT_WEIGHT,
 
1465
                                                       NULL);
 
1466
    gtk_tree_view_append_column (GTK_TREE_VIEW (aw->accounts_list), column);
 
1467
    gtk_tree_view_column_set_resizable (GTK_TREE_VIEW_COLUMN (column), TRUE);
 
1468
    gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column),
 
1469
                                     GTK_TREE_VIEW_COLUMN_AUTOSIZE);
 
1470
    if (i == COLUMN_ACCOUNT_ACCOUNT_NAME)
 
1471
      gtk_tree_view_column_set_sort_column_id (column,
 
1472
                                               COLUMN_ACCOUNT_ACCOUNT_NAME);
 
1473
 
 
1474
    if (i == COLUMN_ACCOUNT_AID 
 
1475
        || i == COLUMN_ACCOUNT_HOST
 
1476
        || i == COLUMN_ACCOUNT_TIMEOUT
 
1477
        || i == COLUMN_ACCOUNT_METHOD 
 
1478
        || i == COLUMN_ACCOUNT_DOMAIN
 
1479
        || i == COLUMN_ACCOUNT_USERNAME
 
1480
        || i == COLUMN_ACCOUNT_AUTH_USERNAME
 
1481
        || i == COLUMN_ACCOUNT_PASSWORD
 
1482
        || i == COLUMN_ACCOUNT_STATE)
 
1483
      g_object_set (G_OBJECT (column), "visible", false, NULL);
 
1484
  }
 
1485
 
 
1486
  g_signal_connect (G_OBJECT (aw->accounts_list), "event_after",
 
1487
                    G_CALLBACK (account_clicked_cb), window);
 
1488
  
 
1489
 
 
1490
  /* The scrolled window with the accounts list store */
 
1491
  scroll_window = gtk_scrolled_window_new (FALSE, FALSE);
 
1492
  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll_window), 
 
1493
                                  GTK_POLICY_AUTOMATIC, 
 
1494
                                  GTK_POLICY_AUTOMATIC);
 
1495
 
 
1496
  event_box = gtk_event_box_new ();
 
1497
  hbox = gtk_hbox_new (FALSE, 4);
 
1498
  gtk_container_set_border_width (GTK_CONTAINER (hbox), 4);
 
1499
  gtk_container_add (GTK_CONTAINER (event_box), hbox);
 
1500
 
 
1501
  frame = gtk_frame_new (NULL);
 
1502
  gtk_widget_set_size_request (GTK_WIDGET (frame), 250, 150);
 
1503
  gtk_container_set_border_width (GTK_CONTAINER (frame), 
 
1504
                                  2 * GNOMEMEETING_PAD_SMALL);
 
1505
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
 
1506
  gtk_container_add (GTK_CONTAINER (frame), scroll_window);
 
1507
  gtk_container_add (GTK_CONTAINER (scroll_window), aw->accounts_list);
 
1508
  gtk_container_set_border_width (GTK_CONTAINER (aw->accounts_list), 0);
 
1509
  gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
 
1510
 
 
1511
 
 
1512
  /* The buttons */
 
1513
  alignment = gtk_alignment_new (1, 0.5, 0, 0);
 
1514
  buttons_vbox = gtk_vbutton_box_new ();
 
1515
 
 
1516
  gtk_box_set_spacing (GTK_BOX (buttons_vbox), 2 * GNOMEMEETING_PAD_SMALL);
 
1517
 
 
1518
  gtk_container_add (GTK_CONTAINER (alignment), buttons_vbox);
 
1519
  gtk_box_pack_start (GTK_BOX (hbox), alignment, 
 
1520
                      FALSE, FALSE, 2 * GNOMEMEETING_PAD_SMALL);
 
1521
 
 
1522
  button = gtk_button_new_from_stock (GTK_STOCK_ADD);
 
1523
  gtk_box_pack_start (GTK_BOX (buttons_vbox), button, TRUE, TRUE, 0);
 
1524
  g_signal_connect (G_OBJECT (button), "clicked", 
 
1525
                    GTK_SIGNAL_FUNC (add_account_cb), NULL); 
 
1526
 
 
1527
  aw->delete_button = gtk_button_new_from_stock (GTK_STOCK_REMOVE);
 
1528
  gtk_widget_set_sensitive (aw->delete_button, FALSE);
 
1529
  gtk_box_pack_start (GTK_BOX (buttons_vbox), aw->delete_button, TRUE, TRUE, 0);
 
1530
  g_signal_connect (G_OBJECT (aw->delete_button), "clicked", 
 
1531
                    GTK_SIGNAL_FUNC (delete_account_cb), NULL); 
 
1532
 
 
1533
  aw->edit_button = gtk_button_new_from_stock (GTK_STOCK_PROPERTIES);
 
1534
  gtk_widget_set_sensitive (aw->edit_button, FALSE);
 
1535
  gtk_box_pack_start (GTK_BOX (buttons_vbox), aw->edit_button, TRUE, TRUE, 0);
 
1536
  g_signal_connect (G_OBJECT (aw->edit_button), "clicked", 
 
1537
                    GTK_SIGNAL_FUNC (edit_account_cb), NULL); 
 
1538
  
 
1539
  aw->default_button = gtk_button_new_with_mnemonic (_("_Default"));
 
1540
  gtk_widget_set_sensitive (aw->default_button, FALSE);
 
1541
  gtk_box_pack_start (GTK_BOX (buttons_vbox), 
 
1542
                      aw->default_button, TRUE, TRUE, 0);
 
1543
  g_signal_connect (G_OBJECT (aw->default_button), "clicked", 
 
1544
                    GTK_SIGNAL_FUNC (set_account_as_default_cb), NULL); 
 
1545
 
 
1546
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox), 
 
1547
                      event_box, TRUE, TRUE, 0);
 
1548
 
 
1549
 
 
1550
  /* Generic signals */
 
1551
  g_signal_connect_swapped (GTK_OBJECT (window), 
 
1552
                            "response", 
 
1553
                            G_CALLBACK (gnomemeeting_window_hide),
 
1554
                            (gpointer) window);
 
1555
 
 
1556
  g_signal_connect (GTK_OBJECT (window), "delete-event", 
 
1557
                    G_CALLBACK (delete_window_cb), NULL);
 
1558
 
 
1559
  gtk_widget_show_all (GTK_WIDGET (GTK_DIALOG (window)->vbox));
 
1560
 
 
1561
  
 
1562
  /* We update it the accounts list to make sure the cursor is updated */
 
1563
  gm_accounts_window_update_accounts_list (window);
 
1564
 
 
1565
  
 
1566
  return window;
 
1567
}
 
1568
 
 
1569
 
 
1570
void
 
1571
gm_accounts_window_update_account_state (GtkWidget *accounts_window,
 
1572
                                         gboolean refreshing,
 
1573
                                         const gchar *domain,
 
1574
                                         const gchar *user,
 
1575
                                         const gchar *status,
 
1576
                                         const gchar *voicemails)
 
1577
{
 
1578
  OpalTransportAddress addr1;
 
1579
  OpalTransportAddress addr2;
 
1580
  
 
1581
  GtkTreeModel *model = NULL;
 
1582
 
 
1583
  GtkTreeIter iter;
 
1584
 
 
1585
  gchar *host = NULL;
 
1586
  gchar *realm = NULL;
 
1587
  gchar *username = NULL;
 
1588
 
 
1589
  gboolean active = FALSE;
 
1590
 
 
1591
  GmAccountsWindow *aw = NULL;
 
1592
 
 
1593
  g_return_if_fail (accounts_window != NULL);
 
1594
  g_return_if_fail (user != NULL);
 
1595
  g_return_if_fail (domain != NULL);
 
1596
 
 
1597
  aw = gm_aw_get_aw (accounts_window);
 
1598
 
 
1599
  model = gtk_tree_view_get_model (GTK_TREE_VIEW (aw->accounts_list));
 
1600
 
 
1601
  if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter)){
 
1602
 
 
1603
    do {
 
1604
 
 
1605
      gtk_tree_model_get (GTK_TREE_MODEL (model), &iter,
 
1606
                          COLUMN_ACCOUNT_ENABLED, &active,
 
1607
                          COLUMN_ACCOUNT_HOST, &host,
 
1608
                          COLUMN_ACCOUNT_DOMAIN, &realm,
 
1609
                          COLUMN_ACCOUNT_USERNAME, &username,
 
1610
                          -1);
 
1611
 
 
1612
      if (((host && domain && !strcmp (host, domain))
 
1613
           || (realm && domain && !strcmp (realm, domain)))
 
1614
          && (username && user && !strcmp (username, user))) {
 
1615
        
 
1616
        gtk_list_store_set (GTK_LIST_STORE (model), &iter,
 
1617
                            COLUMN_ACCOUNT_STATE, refreshing, -1);
 
1618
        if (status)
 
1619
          gtk_list_store_set (GTK_LIST_STORE (model), &iter,
 
1620
                              COLUMN_ACCOUNT_ERROR_MESSAGE, status, -1);
 
1621
        if (voicemails)
 
1622
          gtk_list_store_set (GTK_LIST_STORE (model), &iter,
 
1623
                              COLUMN_ACCOUNT_VOICEMAILS, voicemails, -1);
 
1624
      }
 
1625
      else if (!active)
 
1626
        gtk_list_store_set (GTK_LIST_STORE (model), &iter,
 
1627
                            COLUMN_ACCOUNT_ERROR_MESSAGE, "", -1);
 
1628
 
 
1629
      g_free (host);
 
1630
      g_free (realm);
 
1631
      g_free (username);
 
1632
 
 
1633
    } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter));
 
1634
  }
 
1635
 
 
1636
 
 
1637
  /* We update it the accounts list to make sure the cursor is updated */
 
1638
  gm_accounts_window_update_accounts_list (accounts_window);
 
1639
}
 
1640
 
 
1641
 
 
1642
void
 
1643
gm_accounts_window_update_accounts_list (GtkWidget *accounts_window)
 
1644
{
 
1645
  GmAccountsWindow *aw = NULL;
 
1646
 
 
1647
  GdkCursor *cursor = NULL;
 
1648
 
 
1649
  GtkTreeSelection *selection = NULL;
 
1650
  GtkTreeModel *model = NULL;
 
1651
  GtkTreeIter iter;
 
1652
 
 
1653
  gchar *selected_aid = NULL;
 
1654
  gchar *aid = NULL;
 
1655
 
 
1656
  GmAccount *account = NULL;
 
1657
 
 
1658
  GSList *accounts_data = NULL;
 
1659
  GSList *accounts_data_iter = NULL;
 
1660
 
 
1661
  gboolean found = FALSE;
 
1662
  gboolean enabled = FALSE;
 
1663
  gboolean refreshing = FALSE;
 
1664
  gboolean busy = FALSE;
 
1665
  gboolean valid_iter = TRUE;
 
1666
 
 
1667
  g_return_if_fail (accounts_window != NULL);
 
1668
 
 
1669
  aw = gm_aw_get_aw (accounts_window);
 
1670
 
 
1671
 
 
1672
  /* Get the data and the selected codec */
 
1673
  model = gtk_tree_view_get_model (GTK_TREE_VIEW (aw->accounts_list));
 
1674
  selection = 
 
1675
    gtk_tree_view_get_selection (GTK_TREE_VIEW (aw->accounts_list));
 
1676
 
 
1677
  if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
 
1678
 
 
1679
    gtk_tree_model_get (GTK_TREE_MODEL (model), &iter,
 
1680
                        COLUMN_ACCOUNT_AID, &selected_aid, -1);
 
1681
  }
 
1682
 
 
1683
 
 
1684
  /* Loop through all accounts in the configuration.
 
1685
   * Then find that account in the GUI and updates it. 
 
1686
   * If we do not find the account in the GUI, append the new account
 
1687
   * at the end.
 
1688
   */
 
1689
  accounts_data = gnomemeeting_get_accounts_list (); 
 
1690
  accounts_data_iter = accounts_data;
 
1691
  while (accounts_data_iter && accounts_data_iter->data) {
 
1692
 
 
1693
    account = GM_ACCOUNT (accounts_data_iter->data);
 
1694
 
 
1695
    found = FALSE;
 
1696
    if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter)) {
 
1697
 
 
1698
      do {
 
1699
 
 
1700
        gtk_tree_model_get (GTK_TREE_MODEL (model), &iter,
 
1701
                            COLUMN_ACCOUNT_ENABLED, &enabled,
 
1702
                            COLUMN_ACCOUNT_STATE, &refreshing,
 
1703
                            COLUMN_ACCOUNT_AID, &aid, -1);
 
1704
        if (aid && account->aid && !strcmp (account->aid, aid)) {
 
1705
 
 
1706
          busy = busy || refreshing;
 
1707
          found = TRUE;
 
1708
        }
 
1709
        g_free (aid);
 
1710
 
 
1711
      } while (!found && 
 
1712
               gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter)); 
 
1713
    }
 
1714
    if (!found) /* No existing entry for that account */ 
 
1715
      gtk_list_store_append (GTK_LIST_STORE (model), &iter);
 
1716
 
 
1717
    gtk_list_store_set (GTK_LIST_STORE (model), &iter, 
 
1718
                        COLUMN_ACCOUNT_WEIGHT, 
 
1719
                        account->default_account?
 
1720
                        PANGO_WEIGHT_BOLD:PANGO_WEIGHT_NORMAL,
 
1721
                        COLUMN_ACCOUNT_ENABLED, account->enabled,
 
1722
                        COLUMN_ACCOUNT_DEFAULT, account->default_account,
 
1723
                        COLUMN_ACCOUNT_AID, account->aid,
 
1724
                        COLUMN_ACCOUNT_ACCOUNT_NAME, account->account_name,
 
1725
                        COLUMN_ACCOUNT_PROTOCOL_NAME, account->protocol_name,
 
1726
                        COLUMN_ACCOUNT_HOST, account->host,
 
1727
                        COLUMN_ACCOUNT_DOMAIN, account->domain,
 
1728
                        COLUMN_ACCOUNT_USERNAME, account->username,
 
1729
                        COLUMN_ACCOUNT_AUTH_USERNAME, account->auth_username,
 
1730
                        COLUMN_ACCOUNT_PASSWORD, account->password,
 
1731
                        COLUMN_ACCOUNT_TIMEOUT, account->timeout,
 
1732
                        COLUMN_ACCOUNT_METHOD, account->method,
 
1733
                        -1); 
 
1734
 
 
1735
    if (selected_aid && account->aid 
 
1736
        && !strcmp (selected_aid, account->aid))
 
1737
      gtk_tree_selection_select_iter (selection, &iter);
 
1738
 
 
1739
    accounts_data_iter = g_slist_next (accounts_data_iter);
 
1740
  }
 
1741
 
 
1742
 
 
1743
  /* Loop through the accounts in the window, and check
 
1744
   * if they are in the configuration. If not, remove them from the GUI.
 
1745
   */
 
1746
  if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter)) {
 
1747
 
 
1748
    do {
 
1749
 
 
1750
      found = FALSE;
 
1751
      valid_iter = TRUE;
 
1752
 
 
1753
      gtk_tree_model_get (GTK_TREE_MODEL (model), &iter,
 
1754
                          COLUMN_ACCOUNT_AID, &aid, -1);
 
1755
 
 
1756
      accounts_data_iter = accounts_data;
 
1757
      while (accounts_data_iter && accounts_data_iter->data && !found) {
 
1758
 
 
1759
        account = GM_ACCOUNT (accounts_data_iter->data);
 
1760
 
 
1761
        if (account->aid && aid && !strcmp (account->aid, aid))
 
1762
          found = TRUE;
 
1763
 
 
1764
        accounts_data_iter = g_slist_next (accounts_data_iter);
 
1765
      }
 
1766
 
 
1767
      if (!found)
 
1768
        valid_iter = gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
 
1769
 
 
1770
      g_free (aid);
 
1771
 
 
1772
    } while (valid_iter &&
 
1773
             gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter)); 
 
1774
  }
 
1775
 
 
1776
 
 
1777
  /* Free things */
 
1778
  g_slist_foreach (accounts_data, (GFunc) gm_account_delete, NULL);
 
1779
  g_slist_free (accounts_data);
 
1780
 
 
1781
 
 
1782
  /* Update the cursor and the activatable state of all accounts
 
1783
   * following we are refreshing or not */
 
1784
  if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (model), &iter)) {
 
1785
 
 
1786
    do {
 
1787
 
 
1788
      gtk_list_store_set (GTK_LIST_STORE (model), &iter,
 
1789
                          COLUMN_ACCOUNT_ACTIVATABLE, !busy, -1);
 
1790
    } while (gtk_tree_model_iter_next (GTK_TREE_MODEL (model), &iter));
 
1791
  }
 
1792
 
 
1793
  gtk_widget_realize (GTK_WIDGET (accounts_window));
 
1794
 
 
1795
  if (busy) {
 
1796
 
 
1797
    cursor = gdk_cursor_new (GDK_WATCH);
 
1798
    gdk_window_set_cursor (GTK_WIDGET (accounts_window)->window, cursor);
 
1799
    gdk_cursor_unref (cursor);
 
1800
  }
 
1801
  else
 
1802
    gdk_window_set_cursor (GTK_WIDGET (accounts_window)->window, NULL);
 
1803
}
 
1804