Statistics
| Revision:

root / src / editaddress.c @ 1

History | View | Annotate | Download (36.5 KB)

1
/*
2
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3
 * Copyright (C) 1999-2002 Hiroyuki Yamamoto
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
#ifdef HAVE_CONFIG_H
21
#  include "config.h"
22
#endif
23

    
24
#include "defs.h"
25

    
26
#include <glib.h>
27
#include <gdk/gdkkeysyms.h>
28
#include <gtk/gtkwindow.h>
29
#include <gtk/gtksignal.h>
30
#include <gtk/gtklabel.h>
31
#include <gtk/gtkvbox.h>
32
#include <gtk/gtkentry.h>
33
#include <gtk/gtktable.h>
34

    
35
#include "intl.h"
36
#include "mgutils.h"
37
#include "addressbook.h"
38
#include "addressitem.h"
39
#include "addritem.h"
40
#include "addrbook.h"
41
#include "manage_window.h"
42
#include "gtkutils.h"
43
#include "codeconv.h"
44

    
45
#include "prefs_common.h"
46

    
47
/*
48
static struct _AddressEdit_dlg {
49
        GtkWidget *window;
50
        GtkWidget *name_entry;
51
        GtkWidget *addr_entry;
52
        GtkWidget *rem_entry;
53
        GtkWidget *ok_btn;
54
        GtkWidget *cancel_btn;
55
} addredit;
56
*/
57

    
58
static struct _PersonEdit_dlg {
59
        GtkWidget *window;
60
        GtkWidget *notebook;
61
        GtkWidget *ok_btn;
62
        GtkWidget *cancel_btn;
63
        GtkWidget *statusbar;
64
        gint status_cid;
65

    
66
        /* Basic data tab */
67
        GtkWidget *entry_name;
68
        GtkWidget *entry_first;
69
        GtkWidget *entry_last;
70
        GtkWidget *entry_nick;
71

    
72
        /* EMail data tab */
73
        GtkWidget *entry_email;
74
        GtkWidget *entry_alias;
75
        GtkWidget *entry_remarks;
76
        GtkWidget *clist_email;
77

    
78
        /* Attribute data tab */
79
        GtkWidget *entry_atname;
80
        GtkWidget *entry_atvalue;
81
        GtkWidget *clist_attrib;
82

    
83
        gint rowIndEMail;
84
        gint rowIndAttrib;
85
        gboolean editNew;
86

    
87
} personeditdlg;
88

    
89
typedef enum {
90
        EMAIL_COL_EMAIL   = 0,
91
        EMAIL_COL_ALIAS   = 1,
92
        EMAIL_COL_REMARKS = 2
93
} PersonEditEMailColumnPos;
94

    
95
typedef enum {
96
        ATTRIB_COL_NAME    = 0,
97
        ATTRIB_COL_VALUE   = 1
98
} PersonEditAttribColumnPos;
99

    
100
#define EDITPERSON_WIDTH      520
101
#define EDITPERSON_HEIGHT     340
102

    
103
#define EMAIL_N_COLS          3
104
#define EMAIL_COL_WIDTH_EMAIL 180
105
#define EMAIL_COL_WIDTH_ALIAS 80
106

    
107
#define ATTRIB_N_COLS          2
108
#define ATTRIB_COL_WIDTH_NAME  120
109
#define ATTRIB_COL_WIDTH_VALUE 180
110

    
111
#define PAGE_BASIC             0
112
#define PAGE_EMAIL             1
113
#define PAGE_ATTRIBUTES        2
114

    
115
#if 0
116
#define SET_LABEL_AND_ENTRY(str, entry, top) \
117
{ \
118
        label = gtk_label_new(str); \
119
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
120
                         GTK_FILL, 0, 0, 0); \
121
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
122
 \
123
        entry = gtk_entry_new(); \
124
        gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
125
                         GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
126
}
127

128
static void edit_address_ok(GtkWidget *widget, gboolean *cancelled)
129
{
130
        *cancelled = FALSE;
131
        gtk_main_quit();
132
}
133

134
static void edit_address_cancel(GtkWidget *widget, gboolean *cancelled)
135
{
136
        *cancelled = TRUE;
137
        gtk_main_quit();
138
}
139

140
static gint edit_address_delete_event(GtkWidget *widget, GdkEventAny *event,
141
                                      gboolean *cancelled)
142
{
143
        *cancelled = TRUE;
144
        gtk_main_quit();
145

146
        return TRUE;
147
}
148

149
static gboolean edit_address_key_pressed(GtkWidget *widget, GdkEventKey *event,
150
                                         gboolean *cancelled)
151
{
152
        if (event && event->keyval == GDK_Escape) {
153
                *cancelled = TRUE;
154
                gtk_main_quit();
155
        }
156
        return FALSE;
157
}
158

159
static void addressbook_edit_address_create(gboolean *cancelled)
160
{
161
        GtkWidget *window;
162
        GtkWidget *vbox;
163
        GtkWidget *table;
164
        GtkWidget *label;
165
        GtkWidget *name_entry;
166
        GtkWidget *addr_entry;
167
        GtkWidget *rem_entry;
168
        GtkWidget *hbbox;
169
        GtkWidget *ok_btn;
170
        GtkWidget *cancel_btn;
171

172
        debug_print("Creating edit_address window...\n");
173

174
        window = gtk_window_new(GTK_WINDOW_DIALOG);
175
        gtk_widget_set_size_request(window, 400, -1);
176
        /* gtk_container_set_border_width(GTK_CONTAINER(window), 8); */
177
        gtk_window_set_title(GTK_WINDOW(window), _("Edit address"));
178
        gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
179
        gtk_window_set_modal(GTK_WINDOW(window), TRUE);        
180
        g_signal_connect(G_OBJECT(window), "delete_event",
181
                         G_CALLBACK(edit_address_delete_event),
182
                         cancelled);
183
        g_signal_connect(G_OBJECT(window), "key_press_event",
184
                         G_CALLBACK(edit_address_key_pressed),
185
                         cancelled);
186

187
        vbox = gtk_vbox_new(FALSE, 8);
188
        gtk_container_add(GTK_CONTAINER(window), vbox);
189

190
        table = gtk_table_new(3, 2, FALSE);
191
        gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
192
        gtk_table_set_row_spacings(GTK_TABLE(table), 8);
193
        gtk_table_set_col_spacings(GTK_TABLE(table), 8);
194

195
        SET_LABEL_AND_ENTRY(_("Name"),    name_entry, 0);
196
        SET_LABEL_AND_ENTRY(_("Address"), addr_entry, 1);
197
        SET_LABEL_AND_ENTRY(_("Remarks"), rem_entry,  2);
198

199
        gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
200
                                &cancel_btn, _("Cancel"), NULL, NULL);
201
        gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
202
        gtk_widget_grab_default(ok_btn);
203

204
        g_signal_connect(G_OBJECT(ok_btn), "clicked",
205
                         G_CALLBACK(edit_address_ok), cancelled);
206
        g_signal_connect(G_OBJECT(cancel_btn), "clicked",
207
                         G_CALLBACK(edit_address_cancel), cancelled);
208

209
        gtk_widget_show_all(vbox);
210

211
        addredit.window     = window;
212
        addredit.name_entry = name_entry;
213
        addredit.addr_entry = addr_entry;
214
        addredit.rem_entry  = rem_entry;
215
        addredit.ok_btn     = ok_btn;
216
        addredit.cancel_btn = cancel_btn;
217
}
218

219
AddressItem *addressbook_edit_address(AddressItem *item)
220
{
221
        static gboolean cancelled;
222
        const gchar *str;
223

224
        if (!addredit.window)
225
                addressbook_edit_address_create(&cancelled);
226
        gtk_widget_grab_focus(addredit.ok_btn);
227
        gtk_widget_grab_focus(addredit.name_entry);
228
        gtk_widget_show(addredit.window);
229
        manage_window_set_transient(GTK_WINDOW(addredit.window));
230

231
        gtk_entry_set_text(GTK_ENTRY(addredit.name_entry), "");
232
        gtk_entry_set_text(GTK_ENTRY(addredit.addr_entry), "");
233
        gtk_entry_set_text(GTK_ENTRY(addredit.rem_entry),  "");
234

235
        if (item) {
236
                if (ADDRESS_OBJECT_NAME(item))
237
                        gtk_entry_set_text(GTK_ENTRY(addredit.name_entry),
238
                                           ADDRESS_OBJECT_NAME(item));
239
                if (item->address)
240
                        gtk_entry_set_text(GTK_ENTRY(addredit.addr_entry),
241
                                           item->address);
242
                if (item->remarks)
243
                        gtk_entry_set_text(GTK_ENTRY(addredit.rem_entry),
244
                                           item->remarks);
245
        }
246

247
        gtk_main();
248
        gtk_widget_hide(addredit.window);
249
        if (cancelled == TRUE) return NULL;
250

251
        str = gtk_entry_get_text(GTK_ENTRY(addredit.name_entry));
252
        if (*str == '\0') return NULL;
253

254
        if (!item) {
255
                item = mgu_create_address();
256
                ADDRESS_OBJECT_TYPE(item) = ADDR_ITEM;
257
        }
258

259
        g_free(ADDRESS_OBJECT_NAME(item));
260
        ADDRESS_OBJECT_NAME(item) = g_strdup(str);
261

262
        str = gtk_entry_get_text(GTK_ENTRY(addredit.addr_entry));
263
        g_free(item->address);
264
        if (*str == '\0')
265
                item->address = NULL;
266
        else
267
                item->address = g_strdup(str);
268

269
        str = gtk_entry_get_text(GTK_ENTRY(addredit.rem_entry));
270
        g_free(item->remarks);
271
        if (*str == '\0')
272
                item->remarks = NULL;
273
        else
274
                item->remarks = g_strdup(str);
275

276
        return item;
277
}
278
#endif /* 0 */
279

    
280
static void edit_person_status_show( gchar *msg ) {
281
        if( personeditdlg.statusbar != NULL ) {
282
                gtk_statusbar_pop( GTK_STATUSBAR(personeditdlg.statusbar), personeditdlg.status_cid );
283
                if( msg ) {
284
                        gtk_statusbar_push( GTK_STATUSBAR(personeditdlg.statusbar), personeditdlg.status_cid, msg );
285
                }
286
        }
287
}
288

    
289
static void edit_person_ok(GtkWidget *widget, gboolean *cancelled) {
290
        *cancelled = FALSE;
291
        gtk_main_quit();
292
}
293

    
294
static void edit_person_cancel(GtkWidget *widget, gboolean *cancelled) {
295
        *cancelled = TRUE;
296
        gtk_main_quit();
297
}
298

    
299
static gint edit_person_delete_event(GtkWidget *widget, GdkEventAny *event, gboolean *cancelled) {
300
        *cancelled = TRUE;
301
        gtk_main_quit();
302
        return TRUE;
303
}
304

    
305
static gboolean edit_person_key_pressed(GtkWidget *widget, GdkEventKey *event, gboolean *cancelled) {
306
        if (event && event->keyval == GDK_Escape) {
307
                *cancelled = TRUE;
308
                gtk_main_quit();
309
        }
310
        return FALSE;
311
}
312

    
313
static gchar *_title_new_ = NULL;
314
static gchar *_title_edit_ = NULL;
315

    
316
static void edit_person_set_window_title( gint pageNum ) {
317
        gchar *sTitle;
318

    
319
        if( _title_new_ == NULL ) {
320
                _title_new_ = g_strdup( _("Add New Person") );
321
                _title_edit_ = g_strdup( _("Edit Person Details") );
322
        }
323

    
324
        if( pageNum == PAGE_BASIC ) {
325
                if( personeditdlg.editNew ) {
326
                        gtk_window_set_title( GTK_WINDOW(personeditdlg.window), _title_new_ );
327
                }
328
                else {
329
                        gtk_window_set_title( GTK_WINDOW(personeditdlg.window), _title_edit_ );
330
                }
331
        }
332
        else {
333
                if( personeditdlg.entry_name == NULL ) {
334
                        sTitle = g_strdup( _title_edit_ );
335
                }
336
                else {
337
                        gchar *name;
338
                        name = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_name), 0, -1 );
339
                        sTitle = g_strdup_printf( "%s - %s", _title_edit_, name );
340
                        g_free( name );
341
                }
342
                gtk_window_set_title( GTK_WINDOW(personeditdlg.window), sTitle );
343
                g_free( sTitle );
344
        }
345
}
346

    
347
static void edit_person_email_clear( gpointer data ) {
348
        gtk_entry_set_text( GTK_ENTRY(personeditdlg.entry_email), "" );
349
        gtk_entry_set_text( GTK_ENTRY(personeditdlg.entry_alias), "" );
350
        gtk_entry_set_text( GTK_ENTRY(personeditdlg.entry_remarks), "" );
351
}
352

    
353
static void edit_person_attrib_clear( gpointer data ) {
354
        gtk_entry_set_text( GTK_ENTRY(personeditdlg.entry_atname), "" );
355
        gtk_entry_set_text( GTK_ENTRY(personeditdlg.entry_atvalue), "" );
356
}
357

    
358
static void edit_person_switch_page( GtkNotebook *notebook, GtkNotebookPage *page,
359
                                        gint pageNum, gpointer user_data)
360
{
361
        edit_person_set_window_title( pageNum );
362
        edit_person_status_show( "" );
363
}
364

    
365
/*
366
* Load clist with a copy of person's email addresses.
367
*/
368
void edit_person_load_email( ItemPerson *person ) {
369
        GList *node = person->listEMail;
370
        GtkCList *clist = GTK_CLIST(personeditdlg.clist_email);
371
        gchar *text[ EMAIL_N_COLS ];
372
        while( node ) {
373
                ItemEMail *emorig = ( ItemEMail * ) node->data;
374
                ItemEMail *email = addritem_copy_item_email( emorig );
375
                gint row;
376
                text[ EMAIL_COL_EMAIL   ] = email->address;
377
                text[ EMAIL_COL_ALIAS   ] = email->obj.name;
378
                text[ EMAIL_COL_REMARKS ] = email->remarks;
379

    
380
                row = gtk_clist_append( clist, text );
381
                gtk_clist_set_row_data( clist, row, email );
382
                node = g_list_next( node );
383
        }
384
}
385

    
386
static void edit_person_email_list_selected( GtkCList *clist, gint row, gint column, GdkEvent *event, gpointer data ) {
387
        ItemEMail *email = gtk_clist_get_row_data( clist, row );
388
        if( email ) {
389
                if( email->address )
390
                        gtk_entry_set_text( GTK_ENTRY(personeditdlg.entry_email), email->address );
391
                if( ADDRITEM_NAME(email) )
392
                        gtk_entry_set_text( GTK_ENTRY(personeditdlg.entry_alias), ADDRITEM_NAME(email) );
393
                if( email->remarks )
394
                        gtk_entry_set_text( GTK_ENTRY(personeditdlg.entry_remarks), email->remarks );
395
        }
396
        personeditdlg.rowIndEMail = row;
397
        edit_person_status_show( NULL );
398
}
399

    
400
static void edit_person_email_move( gint dir ) {
401
        GtkCList *clist = GTK_CLIST(personeditdlg.clist_email);
402
        gint row = personeditdlg.rowIndEMail + dir;
403
        ItemEMail *email = gtk_clist_get_row_data( clist, row );
404
        if( email ) {
405
                gtk_clist_row_move( clist, personeditdlg.rowIndEMail, row );
406
                personeditdlg.rowIndEMail = row;
407
        }
408
        edit_person_email_clear( NULL );
409
        edit_person_status_show( NULL );
410
}
411

    
412
static void edit_person_email_move_up( gpointer data ) {
413
        edit_person_email_move( -1 );
414
}
415

    
416
static void edit_person_email_move_down( gpointer data ) {
417
        edit_person_email_move( +1 );
418
}
419

    
420
static void edit_person_email_delete( gpointer data ) {
421
        GtkCList *clist = GTK_CLIST(personeditdlg.clist_email);
422
        gint row = personeditdlg.rowIndEMail;
423
        ItemEMail *email = gtk_clist_get_row_data( clist, row );
424
        edit_person_email_clear( NULL );
425
        if( email ) {
426
                /* Remove list entry */
427
                gtk_clist_remove( clist, row );
428
                addritem_free_item_email( email );
429
                email = NULL;
430
        }
431

    
432
        /* Position hilite bar */
433
        email = gtk_clist_get_row_data( clist, row );
434
        if( ! email ) {
435
                personeditdlg.rowIndEMail = -1 + row;
436
        }
437
        edit_person_status_show( NULL );
438
}
439

    
440
static ItemEMail *edit_person_email_edit( gboolean *error, ItemEMail *email ) {
441
        ItemEMail *retVal = NULL;
442
        gchar *sEmail, *sAlias, *sRemarks, *sEmail_;
443

    
444
        *error = TRUE;
445
        sEmail_ = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_email), 0, -1 );
446
        sAlias = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_alias), 0, -1 );
447
        sRemarks = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_remarks), 0, -1 );
448
        sEmail = mgu_email_check_empty( sEmail_ );
449
        g_free( sEmail_ );
450

    
451
        if( sEmail ) {
452
                if( email == NULL ) {
453
                        email = addritem_create_item_email();
454
                }
455
                addritem_email_set_address( email, sEmail );
456
                addritem_email_set_alias( email, sAlias );
457
                addritem_email_set_remarks( email, sRemarks );
458
                retVal = email;
459
                *error = FALSE;
460
        }
461
        else {
462
                edit_person_status_show( _( "An E-Mail address must be supplied." ) );
463
        }
464

    
465
        g_free( sEmail );
466
        g_free( sAlias );
467
        g_free( sRemarks );
468

    
469
        return retVal;
470
}
471

    
472
static void edit_person_email_modify( gpointer data ) {
473
        gboolean errFlg = FALSE;
474
        GtkCList *clist = GTK_CLIST(personeditdlg.clist_email);
475
        gint row = personeditdlg.rowIndEMail;
476
        ItemEMail *email = gtk_clist_get_row_data( clist, row );
477
        if( email ) {
478
                edit_person_email_edit( &errFlg, email );
479
                if( ! errFlg ) {
480
                        gtk_clist_set_text( clist, row, EMAIL_COL_EMAIL, email->address );
481
                        gtk_clist_set_text( clist, row, EMAIL_COL_ALIAS, email->obj.name );
482
                        gtk_clist_set_text( clist, row, EMAIL_COL_REMARKS, email->remarks );
483
                        edit_person_email_clear( NULL );
484
                }
485
        }
486
}
487

    
488
static void edit_person_email_add( gpointer data ) {
489
        GtkCList *clist = GTK_CLIST(personeditdlg.clist_email);
490
        gboolean errFlg = FALSE;
491
        ItemEMail *email = NULL;
492
        gint row = personeditdlg.rowIndEMail;
493
        if( gtk_clist_get_row_data( clist, row ) == NULL ) row = 0;
494

    
495
        email = edit_person_email_edit( &errFlg, NULL );
496
        if( ! errFlg ) {
497
                gchar *text[ EMAIL_N_COLS ];
498
                text[ EMAIL_COL_EMAIL   ] = email->address;
499
                text[ EMAIL_COL_ALIAS   ] = email->obj.name;
500
                text[ EMAIL_COL_REMARKS ] = email->remarks;
501

    
502
                row = gtk_clist_insert( clist, 1 + row, text );
503
                gtk_clist_set_row_data( clist, row, email );
504
                gtk_clist_select_row( clist, row, 0 );
505
                edit_person_email_clear( NULL );
506
        }
507
}
508

    
509
/*
510
* Load clist with a copy of person's email addresses.
511
*/
512
void edit_person_load_attrib( ItemPerson *person ) {
513
        GList *node = person->listAttrib;
514
        GtkCList *clist = GTK_CLIST(personeditdlg.clist_attrib);
515
        gchar *text[ ATTRIB_N_COLS ];
516
        while( node ) {
517
                UserAttribute *atorig = ( UserAttribute * ) node->data;
518
                UserAttribute *attrib = addritem_copy_attribute( atorig );
519
                gint row;
520
                text[ ATTRIB_COL_NAME  ] = attrib->name;
521
                text[ ATTRIB_COL_VALUE ] = attrib->value;
522

    
523
                row = gtk_clist_append( clist, text );
524
                gtk_clist_set_row_data( clist, row, attrib );
525
                node = g_list_next( node );
526
        }
527
}
528

    
529
static void edit_person_attrib_list_selected( GtkCList *clist, gint row, gint column, GdkEvent *event, gpointer data ) {
530
        UserAttribute *attrib = gtk_clist_get_row_data( clist, row );
531
        if( attrib ) {
532
                gtk_entry_set_text( GTK_ENTRY(personeditdlg.entry_atname), attrib->name );
533
                gtk_entry_set_text( GTK_ENTRY(personeditdlg.entry_atvalue), attrib->value );
534
        }
535
        personeditdlg.rowIndAttrib = row;
536
        edit_person_status_show( NULL );
537
}
538

    
539
static void edit_person_attrib_delete( gpointer data ) {
540
        GtkCList *clist = GTK_CLIST(personeditdlg.clist_attrib);
541
        gint row = personeditdlg.rowIndAttrib;
542
        UserAttribute *attrib = gtk_clist_get_row_data( clist, row );
543
        edit_person_attrib_clear( NULL );
544
        if( attrib ) {
545
                /* Remove list entry */
546
                gtk_clist_remove( clist, row );
547
                addritem_free_attribute( attrib );
548
                attrib = NULL;
549
        }
550

    
551
        /* Position hilite bar */
552
        attrib = gtk_clist_get_row_data( clist, row );
553
        if( ! attrib ) {
554
                personeditdlg.rowIndAttrib = -1 + row;
555
        }
556
        edit_person_status_show( NULL );
557
}
558

    
559
static UserAttribute *edit_person_attrib_edit( gboolean *error, UserAttribute *attrib ) {
560
        UserAttribute *retVal = NULL;
561
        gchar *sName, *sValue, *sName_, *sValue_;
562

    
563
        *error = TRUE;
564
        sName_ = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_atname), 0, -1 );
565
        sValue_ = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_atvalue), 0, -1 );
566
        sName = mgu_email_check_empty( sName_ );
567
        sValue = mgu_email_check_empty( sValue_ );
568
        g_free( sName_ );
569
        g_free( sValue_ );
570

    
571
        if( sName && sValue ) {
572
                if( attrib == NULL ) {
573
                        attrib = addritem_create_attribute();
574
                }
575
                addritem_attrib_set_name( attrib, sName );
576
                addritem_attrib_set_value( attrib, sValue );
577
                retVal = attrib;
578
                *error = FALSE;
579
        }
580
        else {
581
                edit_person_status_show( _( "A Name and Value must be supplied." ) );
582
        }
583

    
584
        g_free( sName );
585
        g_free( sValue );
586

    
587
        return retVal;
588
}
589

    
590
static void edit_person_attrib_modify( gpointer data ) {
591
        gboolean errFlg = FALSE;
592
        GtkCList *clist = GTK_CLIST(personeditdlg.clist_attrib);
593
        gint row = personeditdlg.rowIndAttrib;
594
        UserAttribute *attrib = gtk_clist_get_row_data( clist, row );
595
        if( attrib ) {
596
                edit_person_attrib_edit( &errFlg, attrib );
597
                if( ! errFlg ) {
598
                        gtk_clist_set_text( clist, row, ATTRIB_COL_NAME, attrib->name );
599
                        gtk_clist_set_text( clist, row, ATTRIB_COL_VALUE, attrib->value );
600
                        edit_person_attrib_clear( NULL );
601
                }
602
        }
603
}
604

    
605
static void edit_person_attrib_add( gpointer data ) {
606
        GtkCList *clist = GTK_CLIST(personeditdlg.clist_attrib);
607
        gboolean errFlg = FALSE;
608
        UserAttribute *attrib = NULL;
609
        gint row = personeditdlg.rowIndAttrib;
610
        if( gtk_clist_get_row_data( clist, row ) == NULL ) row = 0;
611

    
612
        attrib = edit_person_attrib_edit( &errFlg, NULL );
613
        if( ! errFlg ) {
614
                gchar *text[ EMAIL_N_COLS ];
615
                text[ ATTRIB_COL_NAME  ] = attrib->name;
616
                text[ ATTRIB_COL_VALUE ] = attrib->value;
617

    
618
                row = gtk_clist_insert( clist, 1 + row, text );
619
                gtk_clist_set_row_data( clist, row, attrib );
620
                gtk_clist_select_row( clist, row, 0 );
621
                edit_person_attrib_clear( NULL );
622
        }
623
}
624

    
625
static void addressbook_edit_person_dialog_create( gboolean *cancelled ) {
626
        GtkWidget *window;
627
        GtkWidget *vbox;
628
        GtkWidget *vnbox;
629
        GtkWidget *notebook;
630
        GtkWidget *hbbox;
631
        GtkWidget *ok_btn;
632
        GtkWidget *cancel_btn;
633
        GtkWidget *hsbox;
634
        GtkWidget *statusbar;
635

    
636
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
637
        gtk_widget_set_size_request(window, EDITPERSON_WIDTH, EDITPERSON_HEIGHT );
638
        /* gtk_container_set_border_width(GTK_CONTAINER(window), 0); */
639
        gtk_window_set_title(GTK_WINDOW(window), _("Edit Person Data"));
640
        gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
641
        gtk_window_set_modal(GTK_WINDOW(window), TRUE);        
642
        g_signal_connect(G_OBJECT(window), "delete_event",
643
                         G_CALLBACK(edit_person_delete_event),
644
                         cancelled);
645
        g_signal_connect(G_OBJECT(window), "key_press_event",
646
                         G_CALLBACK(edit_person_key_pressed),
647
                         cancelled);
648

    
649
        vbox = gtk_vbox_new(FALSE, 4);
650
        /* gtk_container_set_border_width(GTK_CONTAINER(vbox), BORDER_WIDTH); */
651
        gtk_widget_show(vbox);
652
        gtk_container_add(GTK_CONTAINER(window), vbox);
653

    
654
        vnbox = gtk_vbox_new(FALSE, 4);
655
        gtk_container_set_border_width(GTK_CONTAINER(vnbox), 4);
656
        gtk_widget_show(vnbox);
657
        gtk_box_pack_start(GTK_BOX(vbox), vnbox, TRUE, TRUE, 0);
658

    
659
        /* Notebook */
660
        notebook = gtk_notebook_new();
661
        gtk_widget_show(notebook);
662
        gtk_box_pack_start(GTK_BOX(vnbox), notebook, TRUE, TRUE, 0);
663
        gtk_container_set_border_width(GTK_CONTAINER(notebook), 6);
664

    
665
        /* Status line */
666
        hsbox = gtk_hbox_new(FALSE, 0);
667
        gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, BORDER_WIDTH);
668
        statusbar = gtk_statusbar_new();
669
        gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH);
670

    
671
        /* Button panel */
672
        gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
673
                                &cancel_btn, _("Cancel"), NULL, NULL);
674
        gtk_box_pack_end(GTK_BOX(vnbox), hbbox, FALSE, FALSE, 0);
675
        gtk_widget_grab_default(ok_btn);
676

    
677
        g_signal_connect(G_OBJECT(ok_btn), "clicked",
678
                         G_CALLBACK(edit_person_ok), cancelled);
679
        g_signal_connect(G_OBJECT(cancel_btn), "clicked",
680
                         G_CALLBACK(edit_person_cancel), cancelled);
681
        g_signal_connect(G_OBJECT(notebook), "switch_page",
682
                         G_CALLBACK(edit_person_switch_page), NULL);
683

    
684
        gtk_widget_show_all(vbox);
685

    
686
        personeditdlg.window     = window;
687
        personeditdlg.notebook   = notebook;
688
        personeditdlg.ok_btn     = ok_btn;
689
        personeditdlg.cancel_btn = cancel_btn;
690
        personeditdlg.statusbar  = statusbar;
691
        personeditdlg.status_cid = gtk_statusbar_get_context_id( GTK_STATUSBAR(statusbar), "Edit Person Dialog" );
692

    
693
}
694

    
695
void addressbook_edit_person_page_basic( gint pageNum, gchar *pageLbl ) {
696
        GtkWidget *vbox;
697
        GtkWidget *table;
698
        GtkWidget *label;
699
        GtkWidget *entry_name;
700
        GtkWidget *entry_fn;
701
        GtkWidget *entry_ln;
702
        GtkWidget *entry_nn;
703
        const gchar *locale;
704
        gint top = 0;
705

    
706
        vbox = gtk_vbox_new( FALSE, 8 );
707
        gtk_widget_show( vbox );
708
        gtk_container_add( GTK_CONTAINER( personeditdlg.notebook ), vbox );
709
        gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
710

    
711
        label = gtk_label_new( pageLbl );
712
        gtk_widget_show( label );
713
        gtk_notebook_set_tab_label(
714
                GTK_NOTEBOOK( personeditdlg.notebook ),
715
                gtk_notebook_get_nth_page( GTK_NOTEBOOK( personeditdlg.notebook ), pageNum ), label );
716

    
717
        table = gtk_table_new( 4, 3, FALSE);
718
        gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
719
        gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
720
        gtk_table_set_row_spacings(GTK_TABLE(table), 8);
721
        gtk_table_set_col_spacings(GTK_TABLE(table), 8);
722

    
723
#define ATTACH_ROW(text, entry) \
724
{ \
725
        label = gtk_label_new(text); \
726
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
727
                         GTK_FILL, 0, 0, 0); \
728
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
729
 \
730
        entry = gtk_entry_new(); \
731
        gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
732
                         GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
733
        top++; \
734
}
735

    
736
        ATTACH_ROW(_("Display Name"), entry_name);
737
        locale = conv_get_current_locale();
738
        if (locale &&
739
            (!g_strncasecmp(locale, "ja", 2) ||
740
             !g_strncasecmp(locale, "ko", 2) ||
741
             !g_strncasecmp(locale, "zh", 2))) {
742
                ATTACH_ROW(_("Last Name"), entry_ln);
743
                ATTACH_ROW(_("First Name"), entry_fn);
744
        } else {
745
                ATTACH_ROW(_("First Name"), entry_fn);
746
                ATTACH_ROW(_("Last Name"), entry_ln);
747
        }
748
        ATTACH_ROW(_("Nick Name"), entry_nn);
749

    
750
#undef ATTACH_ROW
751

    
752
        gtk_widget_show_all(vbox);
753

    
754
        personeditdlg.entry_name  = entry_name;
755
        personeditdlg.entry_first = entry_fn;
756
        personeditdlg.entry_last  = entry_ln;
757
        personeditdlg.entry_nick  = entry_nn;
758
}
759

    
760
void addressbook_edit_person_page_email( gint pageNum, gchar *pageLbl ) {
761
        GtkWidget *vbox;
762
        GtkWidget *hbox;
763
        GtkWidget *vboxl;
764
        GtkWidget *vboxb;
765
        GtkWidget *vbuttonbox;
766
        GtkWidget *buttonUp;
767
        GtkWidget *buttonDown;
768
        GtkWidget *buttonDel;
769
        GtkWidget *buttonMod;
770
        GtkWidget *buttonAdd;
771
        GtkWidget *buttonClr;
772

    
773
        GtkWidget *table;
774
        GtkWidget *label;
775
        GtkWidget *clist_swin;
776
        GtkWidget *clist;
777
        GtkWidget *entry_email;
778
        GtkWidget *entry_alias;
779
        GtkWidget *entry_remarks;
780
        gint top;
781

    
782
        gchar *titles[ EMAIL_N_COLS ];
783
        gint i;
784

    
785
        titles[ EMAIL_COL_EMAIL   ] = _("E-Mail Address");
786
        titles[ EMAIL_COL_ALIAS   ] = _("Alias");
787
        titles[ EMAIL_COL_REMARKS ] = _("Remarks");
788

    
789
        vbox = gtk_vbox_new( FALSE, 8 );
790
        gtk_widget_show( vbox );
791
        gtk_container_add( GTK_CONTAINER( personeditdlg.notebook ), vbox );
792
        gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
793

    
794
        label = gtk_label_new( pageLbl );
795
        gtk_widget_show( label );
796
        gtk_notebook_set_tab_label(
797
                GTK_NOTEBOOK( personeditdlg.notebook ),
798
                gtk_notebook_get_nth_page( GTK_NOTEBOOK( personeditdlg.notebook ), pageNum ), label );
799

    
800
        /* Split into two areas */
801
        hbox = gtk_hbox_new( FALSE, 0 );
802
        gtk_container_add( GTK_CONTAINER( vbox ), hbox );
803

    
804
        /* EMail list */
805
        vboxl = gtk_vbox_new( FALSE, 4 );
806
        gtk_container_add( GTK_CONTAINER( hbox ), vboxl );
807
        gtk_container_set_border_width( GTK_CONTAINER(vboxl), 4 );
808

    
809
        /* Address list */
810
        clist_swin = gtk_scrolled_window_new( NULL, NULL );
811
        gtk_container_add( GTK_CONTAINER(vboxl), clist_swin );
812
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(clist_swin),
813
                                       GTK_POLICY_AUTOMATIC,
814
                                       GTK_POLICY_ALWAYS);
815

    
816
        clist = gtk_clist_new_with_titles( EMAIL_N_COLS, titles );
817
        gtk_container_add( GTK_CONTAINER(clist_swin), clist );
818
        gtk_clist_set_selection_mode( GTK_CLIST(clist), GTK_SELECTION_BROWSE );
819
        gtk_clist_set_column_width( GTK_CLIST(clist), EMAIL_COL_EMAIL, EMAIL_COL_WIDTH_EMAIL );
820
        gtk_clist_set_column_width( GTK_CLIST(clist), EMAIL_COL_ALIAS, EMAIL_COL_WIDTH_ALIAS );
821

    
822
        for( i = 0; i < EMAIL_N_COLS; i++ )
823
                GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(clist)->column[i].button, GTK_CAN_FOCUS);
824

    
825
        /* Data entry area */
826
        table = gtk_table_new( 4, 2, FALSE);
827
        gtk_box_pack_start(GTK_BOX(vboxl), table, FALSE, FALSE, 0);
828
        gtk_container_set_border_width( GTK_CONTAINER(table), 4 );
829
        gtk_table_set_row_spacings(GTK_TABLE(table), 4);
830
        gtk_table_set_col_spacings(GTK_TABLE(table), 4);
831

    
832
        /* First row */
833
        top = 0;
834
        label = gtk_label_new(_("E-Mail Address"));
835
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
836
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
837

    
838
        entry_email = gtk_entry_new();
839
        gtk_table_attach(GTK_TABLE(table), entry_email, 1, 2, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
840

    
841
        /* Next row */
842
        ++top;
843
        label = gtk_label_new(_("Alias"));
844
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
845
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
846

    
847
        entry_alias = gtk_entry_new();
848
        gtk_table_attach(GTK_TABLE(table), entry_alias, 1, 2, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
849

    
850
        /* Next row */
851
        ++top;
852
        label = gtk_label_new(_("Remarks"));
853
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
854
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
855

    
856
        entry_remarks = gtk_entry_new();
857
        gtk_table_attach(GTK_TABLE(table), entry_remarks, 1, 2, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
858

    
859
        /* Button box */
860
        vboxb = gtk_vbox_new( FALSE, 4 );
861
        gtk_box_pack_start(GTK_BOX(hbox), vboxb, FALSE, FALSE, 2);
862

    
863
        vbuttonbox = gtk_vbutton_box_new();
864
        gtk_button_box_set_layout( GTK_BUTTON_BOX(vbuttonbox), GTK_BUTTONBOX_START );
865
        gtk_box_set_spacing( GTK_BOX(vbuttonbox), 8 );
866
        gtk_container_set_border_width( GTK_CONTAINER(vbuttonbox), 4 );
867
        gtk_container_add( GTK_CONTAINER(vboxb), vbuttonbox );
868

    
869
        /* Buttons */
870
        buttonUp = gtk_button_new_with_label( _( "Move Up" ) );
871
        gtk_container_add( GTK_CONTAINER(vbuttonbox), buttonUp );
872

    
873
        buttonDown = gtk_button_new_with_label( _( "Move Down" ) );
874
        gtk_container_add( GTK_CONTAINER(vbuttonbox), buttonDown );
875

    
876
        buttonDel = gtk_button_new_with_label( _( "Delete" ) );
877
        gtk_container_add( GTK_CONTAINER(vbuttonbox), buttonDel );
878

    
879
        buttonMod = gtk_button_new_with_label( _( "Modify" ) );
880
        gtk_container_add( GTK_CONTAINER(vbuttonbox), buttonMod );
881

    
882
        buttonAdd = gtk_button_new_with_label( _( "Add" ) );
883
        gtk_container_add( GTK_CONTAINER(vbuttonbox), buttonAdd );
884

    
885
        buttonClr = gtk_button_new_with_label( _( "Clear" ) );
886
        gtk_container_add( GTK_CONTAINER(vbuttonbox), buttonClr );
887

    
888
        gtk_widget_show_all(vbox);
889

    
890
        /* Event handlers */
891
        g_signal_connect( G_OBJECT(clist), "select_row",
892
                          G_CALLBACK( edit_person_email_list_selected), NULL );
893
        g_signal_connect( G_OBJECT(buttonUp), "clicked",
894
                          G_CALLBACK( edit_person_email_move_up ), NULL );
895
        g_signal_connect( G_OBJECT(buttonDown), "clicked",
896
                          G_CALLBACK( edit_person_email_move_down ), NULL );
897
        g_signal_connect( G_OBJECT(buttonDel), "clicked",
898
                          G_CALLBACK( edit_person_email_delete ), NULL );
899
        g_signal_connect( G_OBJECT(buttonMod), "clicked",
900
                          G_CALLBACK( edit_person_email_modify ), NULL );
901
        g_signal_connect( G_OBJECT(buttonAdd), "clicked",
902
                          G_CALLBACK( edit_person_email_add ), NULL );
903
        g_signal_connect( G_OBJECT(buttonClr), "clicked",
904
                          G_CALLBACK( edit_person_email_clear ), NULL );
905

    
906
        personeditdlg.clist_email   = clist;
907
        personeditdlg.entry_email   = entry_email;
908
        personeditdlg.entry_alias   = entry_alias;
909
        personeditdlg.entry_remarks = entry_remarks;
910
}
911

    
912
void addressbook_edit_person_page_attrib( gint pageNum, gchar *pageLbl ) {
913
        GtkWidget *vbox;
914
        GtkWidget *hbox;
915
        GtkWidget *vboxl;
916
        GtkWidget *vboxb;
917
        GtkWidget *vbuttonbox;
918
        GtkWidget *buttonDel;
919
        GtkWidget *buttonMod;
920
        GtkWidget *buttonAdd;
921
        GtkWidget *buttonClr;
922

    
923
        GtkWidget *table;
924
        GtkWidget *label;
925
        GtkWidget *clist_swin;
926
        GtkWidget *clist;
927
        GtkWidget *entry_name;
928
        GtkWidget *entry_value;
929
        gint top;
930

    
931
        gchar *titles[ ATTRIB_N_COLS ];
932
        gint i;
933

    
934
        titles[ ATTRIB_COL_NAME  ] = _("Name");
935
        titles[ ATTRIB_COL_VALUE ] = _("Value");
936

    
937
        vbox = gtk_vbox_new( FALSE, 8 );
938
        gtk_widget_show( vbox );
939
        gtk_container_add( GTK_CONTAINER( personeditdlg.notebook ), vbox );
940
        gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
941

    
942
        label = gtk_label_new( pageLbl );
943
        gtk_widget_show( label );
944
        gtk_notebook_set_tab_label(
945
                GTK_NOTEBOOK( personeditdlg.notebook ),
946
                gtk_notebook_get_nth_page( GTK_NOTEBOOK( personeditdlg.notebook ), pageNum ), label );
947

    
948
        /* Split into two areas */
949
        hbox = gtk_hbox_new( FALSE, 0 );
950
        gtk_container_add( GTK_CONTAINER( vbox ), hbox );
951

    
952
        /* Attribute list */
953
        vboxl = gtk_vbox_new( FALSE, 4 );
954
        gtk_container_add( GTK_CONTAINER( hbox ), vboxl );
955
        gtk_container_set_border_width( GTK_CONTAINER(vboxl), 4 );
956

    
957
        /* Address list */
958
        clist_swin = gtk_scrolled_window_new( NULL, NULL );
959
        gtk_container_add( GTK_CONTAINER(vboxl), clist_swin );
960
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(clist_swin),
961
                                       GTK_POLICY_AUTOMATIC,
962
                                       GTK_POLICY_ALWAYS);
963

    
964
        clist = gtk_clist_new_with_titles( ATTRIB_N_COLS, titles );
965
        gtk_container_add( GTK_CONTAINER(clist_swin), clist );
966
        gtk_clist_set_selection_mode( GTK_CLIST(clist), GTK_SELECTION_BROWSE );
967
        gtk_clist_set_column_width( GTK_CLIST(clist), ATTRIB_COL_NAME, ATTRIB_COL_WIDTH_NAME );
968
        gtk_clist_set_column_width( GTK_CLIST(clist), ATTRIB_COL_VALUE, ATTRIB_COL_WIDTH_VALUE );
969

    
970
        for( i = 0; i < ATTRIB_N_COLS; i++ )
971
                GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(clist)->column[i].button, GTK_CAN_FOCUS);
972

    
973
        /* Data entry area */
974
        table = gtk_table_new( 4, 2, FALSE);
975
        gtk_box_pack_start(GTK_BOX(vboxl), table, FALSE, FALSE, 0);
976
        gtk_container_set_border_width( GTK_CONTAINER(table), 4 );
977
        gtk_table_set_row_spacings(GTK_TABLE(table), 4);
978
        gtk_table_set_col_spacings(GTK_TABLE(table), 4);
979

    
980
        /* First row */
981
        top = 0;
982
        label = gtk_label_new(_("Name"));
983
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
984
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
985

    
986
        entry_name = gtk_entry_new();
987
        gtk_table_attach(GTK_TABLE(table), entry_name, 1, 2, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
988

    
989
        /* Next row */
990
        ++top;
991
        label = gtk_label_new(_("Value"));
992
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
993
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
994

    
995
        entry_value = gtk_entry_new();
996
        gtk_table_attach(GTK_TABLE(table), entry_value, 1, 2, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
997

    
998
        /* Button box */
999
        vboxb = gtk_vbox_new( FALSE, 4 );
1000
        gtk_box_pack_start(GTK_BOX(hbox), vboxb, FALSE, FALSE, 2);
1001

    
1002
        vbuttonbox = gtk_vbutton_box_new();
1003
        gtk_button_box_set_layout( GTK_BUTTON_BOX(vbuttonbox), GTK_BUTTONBOX_START );
1004
        gtk_box_set_spacing( GTK_BOX(vbuttonbox), 8 );
1005
        gtk_container_set_border_width( GTK_CONTAINER(vbuttonbox), 4 );
1006
        gtk_container_add( GTK_CONTAINER(vboxb), vbuttonbox );
1007

    
1008
        /* Buttons */
1009
        buttonDel = gtk_button_new_with_label( _( "Delete" ) );
1010
        gtk_container_add( GTK_CONTAINER(vbuttonbox), buttonDel );
1011

    
1012
        buttonMod = gtk_button_new_with_label( _( "Modify" ) );
1013
        gtk_container_add( GTK_CONTAINER(vbuttonbox), buttonMod );
1014

    
1015
        buttonAdd = gtk_button_new_with_label( _( "Add" ) );
1016
        gtk_container_add( GTK_CONTAINER(vbuttonbox), buttonAdd );
1017

    
1018
        buttonClr = gtk_button_new_with_label( _( "Clear" ) );
1019
        gtk_container_add( GTK_CONTAINER(vbuttonbox), buttonClr );
1020

    
1021
        gtk_widget_show_all(vbox);
1022

    
1023
        /* Event handlers */
1024
        g_signal_connect( G_OBJECT(clist), "select_row",
1025
                          G_CALLBACK( edit_person_attrib_list_selected), NULL );
1026
        g_signal_connect( G_OBJECT(buttonDel), "clicked",
1027
                          G_CALLBACK( edit_person_attrib_delete ), NULL );
1028
        g_signal_connect( G_OBJECT(buttonMod), "clicked",
1029
                          G_CALLBACK( edit_person_attrib_modify ), NULL );
1030
        g_signal_connect( G_OBJECT(buttonAdd), "clicked",
1031
                          G_CALLBACK( edit_person_attrib_add ), NULL );
1032
        g_signal_connect( G_OBJECT(buttonClr), "clicked",
1033
                          G_CALLBACK( edit_person_attrib_clear ), NULL );
1034

    
1035
        personeditdlg.clist_attrib  = clist;
1036
        personeditdlg.entry_atname  = entry_name;
1037
        personeditdlg.entry_atvalue = entry_value;
1038
}
1039

    
1040
static void addressbook_edit_person_create( gboolean *cancelled ) {
1041
        addressbook_edit_person_dialog_create( cancelled );
1042
        addressbook_edit_person_page_basic( PAGE_BASIC, _( "Basic Data" ) );
1043
        addressbook_edit_person_page_email( PAGE_EMAIL, _( "E-Mail Address" ) );
1044
        addressbook_edit_person_page_attrib( PAGE_ATTRIBUTES, _( "User Attributes" ) );
1045
        gtk_widget_show_all( personeditdlg.window );
1046
}
1047

    
1048
/*
1049
* Return list of email items.
1050
*/
1051
static GList *edit_person_build_email_list() {
1052
        GtkCList *clist = GTK_CLIST(personeditdlg.clist_email);
1053
        GList *listEMail = NULL;
1054
        ItemEMail *email;
1055
        gint row = 0;
1056
        while( (email = gtk_clist_get_row_data( clist, row )) ) {
1057
                listEMail = g_list_append( listEMail, email );
1058
                row++;
1059
        }
1060
        return listEMail;
1061
}
1062

    
1063
/*
1064
* Return list of attributes.
1065
*/
1066
static GList *edit_person_build_attrib_list() {
1067
        GtkCList *clist = GTK_CLIST(personeditdlg.clist_attrib);
1068
        GList *listAttrib = NULL;
1069
        UserAttribute *attrib;
1070
        gint row = 0;
1071
        while( (attrib = gtk_clist_get_row_data( clist, row )) ) {
1072
                listAttrib = g_list_append( listAttrib, attrib );
1073
                row++;
1074
        }
1075
        return listAttrib;
1076
}
1077

    
1078
/*
1079
* Edit person.
1080
* Enter: abf    Address book.
1081
*        parent Parent folder for person (or NULL if adding to root folder). Argument is
1082
*               only required for new objects).
1083
*        person Person to edit, or NULL for a new person object.
1084
*        pgMail If TRUE, E-Mail page will be activated.
1085
* Return: Edited object, or NULL if cancelled.
1086
*/
1087
ItemPerson *addressbook_edit_person( AddressBookFile *abf, ItemFolder *parent, ItemPerson *person, gboolean pgMail ) {
1088
        static gboolean cancelled;
1089
        GList *listEMail = NULL;
1090
        GList *listAttrib = NULL;
1091
        gchar *cn = NULL;
1092

    
1093
        if (!personeditdlg.window)
1094
                addressbook_edit_person_create(&cancelled);
1095
        gtk_widget_grab_focus(personeditdlg.ok_btn);
1096
        gtk_widget_grab_focus(personeditdlg.entry_name);
1097
        gtk_widget_show(personeditdlg.window);
1098
        manage_window_set_transient(GTK_WINDOW(personeditdlg.window));
1099

    
1100
        /* Clear all fields */
1101
        personeditdlg.rowIndEMail = -1;
1102
        personeditdlg.rowIndAttrib = -1;
1103
        edit_person_status_show( "" );
1104
        gtk_clist_clear( GTK_CLIST(personeditdlg.clist_email) );
1105
        gtk_clist_clear( GTK_CLIST(personeditdlg.clist_attrib) );
1106
        gtk_entry_set_text(GTK_ENTRY(personeditdlg.entry_name), "" );
1107
        gtk_entry_set_text(GTK_ENTRY(personeditdlg.entry_first), "" );
1108
        gtk_entry_set_text(GTK_ENTRY(personeditdlg.entry_last), "" );
1109
        gtk_entry_set_text(GTK_ENTRY(personeditdlg.entry_nick), "" );
1110

    
1111
        personeditdlg.editNew = FALSE;
1112
        if( person ) {
1113
                if( ADDRITEM_NAME(person) )
1114
                        gtk_entry_set_text(GTK_ENTRY(personeditdlg.entry_name), ADDRITEM_NAME(person) );
1115
                if( person->firstName )
1116
                        gtk_entry_set_text(GTK_ENTRY(personeditdlg.entry_first), person->firstName );
1117
                if( person->lastName )
1118
                        gtk_entry_set_text(GTK_ENTRY(personeditdlg.entry_last), person->lastName );
1119
                if( person->nickName )
1120
                        gtk_entry_set_text(GTK_ENTRY(personeditdlg.entry_nick), person->nickName );
1121
                edit_person_load_email( person );
1122
                edit_person_load_attrib( person );
1123
        }
1124
        else {
1125
                personeditdlg.editNew = TRUE;
1126
        }
1127

    
1128
        /* Select appropriate start page */
1129
        if( pgMail ) {
1130
                gtk_notebook_set_current_page( GTK_NOTEBOOK(personeditdlg.notebook), PAGE_EMAIL );
1131
        }
1132
        else {
1133
                gtk_notebook_set_current_page( GTK_NOTEBOOK(personeditdlg.notebook), PAGE_BASIC );
1134
        }
1135

    
1136
        gtk_clist_select_row( GTK_CLIST(personeditdlg.clist_email), 0, 0 );
1137
        gtk_clist_select_row( GTK_CLIST(personeditdlg.clist_attrib), 0, 0 );
1138
        edit_person_email_clear( NULL );
1139
        edit_person_attrib_clear( NULL );
1140

    
1141
        gtk_main();
1142
        gtk_widget_hide( personeditdlg.window );
1143

    
1144
        listEMail = edit_person_build_email_list();
1145
        listAttrib = edit_person_build_attrib_list();
1146
        if( cancelled ) {
1147
                addritem_free_list_email( listEMail );
1148
                gtk_clist_clear( GTK_CLIST(personeditdlg.clist_email) );
1149
                gtk_clist_clear( GTK_CLIST(personeditdlg.clist_attrib) );
1150
                return NULL;
1151
        }
1152

    
1153
        cn = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_name), 0, -1 );
1154
        if( person ) {
1155
                /* Update email/attribute list */
1156
                addrbook_update_address_list( abf, person, listEMail );
1157
                addrbook_update_attrib_list( abf, person, listAttrib );
1158
        }
1159
        else {
1160
                /* Create new person and email/attribute list */
1161
                if( cn == NULL || *cn == '\0' ) {
1162
                        /* Wasting our time */
1163
                        if( listEMail == NULL && listAttrib == NULL ) cancelled = TRUE;
1164
                }
1165
                if( ! cancelled ) {
1166
                        person = addrbook_add_address_list( abf, parent, listEMail );
1167
                        addrbook_add_attrib_list( abf, person, listAttrib );
1168
                }
1169
        }
1170

    
1171
        if( !cancelled ) {
1172
                /* Set person stuff */
1173
                gchar *name;
1174
                addritem_person_set_common_name( person, cn );
1175
                name = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_first), 0, -1 );
1176
                addritem_person_set_first_name( person, name );
1177
                g_free( name );
1178
                name = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_last), 0, -1 );
1179
                addritem_person_set_last_name( person, name );
1180
                g_free( name );
1181
                name = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_nick), 0, -1 );
1182
                addritem_person_set_nick_name( person, name );
1183
                g_free( name );
1184
        }
1185
        g_free( cn );
1186

    
1187
        listEMail = NULL;
1188

    
1189
        gtk_clist_clear( GTK_CLIST(personeditdlg.clist_email) );
1190
        gtk_clist_clear( GTK_CLIST(personeditdlg.clist_attrib) );
1191

    
1192
        return person;
1193
}
1194

    
1195
/*
1196
* End of Source.
1197
*/
1198