Fix conflicts
[claws.git] / src / editaddress.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
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 3 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, see <http://www.gnu.org/licenses/>.
17  * 
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 <glib/gi18n.h>
28 #include <gdk/gdkkeysyms.h>
29 #include <gtk/gtkwindow.h>
30 #include <gtk/gtksignal.h>
31 #include <gtk/gtklabel.h>
32 #include <gtk/gtkvbox.h>
33 #include <gtk/gtkentry.h>
34 #include <gtk/gtktable.h>
35
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 "filesel.h"
44 #include "codeconv.h"
45 #include "editaddress.h"
46 #include "editaddress_other_attributes_ldap.h"
47 #include "prefs_common.h"
48
49 /* transient data */
50 static struct _PersonEdit_dlg personeditdlg;
51 static AddressBookFile *current_abf = NULL;
52 static ItemPerson *current_person = NULL;
53 static ItemFolder *current_parent_folder = NULL;
54 static EditAddressPostUpdateCallback edit_person_close_post_update_cb = NULL;
55
56 typedef enum {
57         EMAIL_COL_EMAIL   = 0,
58         EMAIL_COL_ALIAS   = 1,
59         EMAIL_COL_REMARKS = 2
60 } PersonEditEMailColumnPos;
61
62 typedef enum {
63         ATTRIB_COL_NAME    = 0,
64         ATTRIB_COL_VALUE   = 1
65 } PersonEditAttribColumnPos;
66
67 #define EDITPERSON_WIDTH      520
68 #define EDITPERSON_HEIGHT     320
69
70 #ifndef MAEMO
71 # define EMAIL_N_COLS          3
72 # define EMAIL_COL_WIDTH_EMAIL 180
73 # define EMAIL_COL_WIDTH_ALIAS 80
74 #else
75 # define EMAIL_N_COLS          1
76 # define EMAIL_COL_WIDTH_EMAIL 130
77 # define EMAIL_COL_WIDTH_ALIAS 130
78 #endif
79
80 #ifndef MAEMO
81 # define ATTRIB_N_COLS          2
82 # define ATTRIB_COL_WIDTH_NAME  240
83 # define ATTRIB_COL_WIDTH_VALUE 0
84 #else
85 # define ATTRIB_N_COLS          2
86 # define ATTRIB_COL_WIDTH_NAME  120
87 # define ATTRIB_COL_WIDTH_VALUE 120
88 #endif
89
90 #define PAGE_BASIC             0
91 #define PAGE_EMAIL             1
92 #define PAGE_ATTRIBUTES        2
93
94 static gboolean addressbook_edit_person_close( gboolean cancelled );
95
96 static void edit_person_status_show( gchar *msg ) {
97         if( personeditdlg.statusbar != NULL ) {
98                 gtk_statusbar_pop( GTK_STATUSBAR(personeditdlg.statusbar), personeditdlg.status_cid );
99                 if( msg ) {
100                         gtk_statusbar_push( GTK_STATUSBAR(personeditdlg.statusbar), personeditdlg.status_cid, msg );
101                 }
102         }
103 }
104
105 static void edit_person_ok(GtkWidget *widget, gboolean *cancelled) {
106         *cancelled = FALSE;
107         if (prefs_common.addressbook_use_editaddress_dialog)
108                 gtk_main_quit();
109         else
110                 addressbook_edit_person_close( *cancelled );
111 }
112
113 static void edit_person_cancel(GtkWidget *widget, gboolean *cancelled) {
114         *cancelled = TRUE;
115         if (prefs_common.addressbook_use_editaddress_dialog)
116                 gtk_main_quit();
117         else
118                 addressbook_edit_person_close( *cancelled );
119 }
120
121 static gint edit_person_delete_event(GtkWidget *widget, GdkEventAny *event, gboolean *cancelled) {
122         *cancelled = TRUE;
123         if (prefs_common.addressbook_use_editaddress_dialog)
124                 gtk_main_quit();
125         else
126                 addressbook_edit_person_close( *cancelled );
127         return TRUE;
128 }
129
130 static gboolean edit_person_key_pressed(GtkWidget *widget, GdkEventKey *event, gboolean *cancelled) {
131         if (prefs_common.addressbook_use_editaddress_dialog) {
132         if (event && event->keyval == GDK_Escape) {
133                 *cancelled = TRUE;
134                 gtk_main_quit();
135         }
136         }
137         return FALSE;
138 }
139
140 static gchar *_title_new_ = NULL;
141 static gchar *_title_edit_ = NULL;
142
143 static void edit_person_set_widgets_title( gchar *text )
144 {
145         gchar *label = NULL;
146
147         g_return_if_fail( text != NULL );
148
149         gtk_label_set_text(GTK_LABEL(personeditdlg.title), "");
150         label = g_markup_printf_escaped("<b>%s</b>", text);
151         gtk_label_set_markup(GTK_LABEL(personeditdlg.title), label);
152         g_free(label);
153 }
154
155 static void edit_person_set_window_title( gint pageNum ) {
156         gchar *sTitle;
157
158         if( _title_new_ == NULL ) {
159                 _title_new_ = g_strdup( _("Add New Person") );
160                 _title_edit_ = g_strdup( _("Edit Person Details") );
161         }
162
163         if( pageNum == PAGE_BASIC ) {
164                 if( personeditdlg.editNew ) {
165                         if (prefs_common.addressbook_use_editaddress_dialog)
166                                 gtk_window_set_title( GTK_WINDOW(personeditdlg.container), _title_new_ );
167                         else
168                                 edit_person_set_widgets_title( _title_new_ );
169                 }
170                 else {
171                         if (prefs_common.addressbook_use_editaddress_dialog)
172                                 gtk_window_set_title( GTK_WINDOW(personeditdlg.container), _title_edit_ );
173                         else
174                                 edit_person_set_widgets_title( _title_edit_ );
175                 }
176         }
177         else {
178                 if( personeditdlg.entry_name == NULL ) {
179                         sTitle = g_strdup( _title_edit_ );
180                 }
181                 else {
182                         gchar *name;
183                         name = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_name), 0, -1 );
184                         sTitle = g_strdup_printf( "%s - %s", _title_edit_, name );
185                         g_free( name );
186                 }
187                 if (prefs_common.addressbook_use_editaddress_dialog)
188                         gtk_window_set_title( GTK_WINDOW(personeditdlg.container), sTitle );
189                 else
190                         edit_person_set_widgets_title( sTitle );
191                 g_free( sTitle );
192         }
193 }
194
195 static void edit_person_email_clear( gpointer data ) {
196         gtk_entry_set_text( GTK_ENTRY(personeditdlg.entry_email), "" );
197         gtk_entry_set_text( GTK_ENTRY(personeditdlg.entry_alias), "" );
198         gtk_entry_set_text( GTK_ENTRY(personeditdlg.entry_remarks), "" );
199 }
200
201 static void edit_person_attrib_clear( gpointer data ) {
202         if (!personeditdlg.ldap) {
203                 gtk_entry_set_text( GTK_ENTRY(personeditdlg.entry_atname), "" );
204                 gtk_entry_set_text( GTK_ENTRY(personeditdlg.entry_atvalue), "" );
205         }
206 }
207
208 static void edit_person_switch_page( GtkNotebook *notebook, GtkNotebookPage *page,
209                                         gint pageNum, gpointer user_data)
210 {
211         edit_person_set_window_title( pageNum );
212         edit_person_status_show( "" );
213 }
214
215 /*
216 * Load clist with a copy of person's email addresses.
217 */
218 static void edit_person_load_email( ItemPerson *person ) {
219         GList *node = person->listEMail;
220         GtkCList *clist = GTK_CLIST(personeditdlg.clist_email);
221         gchar *text[ EMAIL_N_COLS ];
222         while( node ) {
223                 ItemEMail *emorig = ( ItemEMail * ) node->data;
224                 ItemEMail *email = addritem_copyfull_item_email( emorig );
225                 gint row;
226                 text[ EMAIL_COL_EMAIL   ] = email->address;
227 #ifndef MAEMO
228                 text[ EMAIL_COL_ALIAS   ] = email->obj.name;
229                 text[ EMAIL_COL_REMARKS ] = email->remarks;
230 #endif
231                 row = gtk_clist_append( clist, text );
232                 gtk_clist_set_row_data( clist, row, email );
233                 node = g_list_next( node );
234         }
235 }
236
237 static void edit_person_email_list_selected( GtkCList *clist, gint row, gint column, GdkEvent *event, gpointer data ) {
238         ItemEMail *email = gtk_clist_get_row_data( clist, row );
239         if( email ) {
240                 if( email->address )
241                         gtk_entry_set_text( GTK_ENTRY(personeditdlg.entry_email), email->address );
242                 if( ADDRITEM_NAME(email) )
243                         gtk_entry_set_text( GTK_ENTRY(personeditdlg.entry_alias), ADDRITEM_NAME(email) );
244                 if( email->remarks )
245                         gtk_entry_set_text( GTK_ENTRY(personeditdlg.entry_remarks), email->remarks );
246                 if (!personeditdlg.read_only) {
247                         gtk_widget_set_sensitive(personeditdlg.email_del, TRUE);
248                         gtk_widget_set_sensitive(personeditdlg.email_up, row > 0);
249                         gtk_widget_set_sensitive(personeditdlg.email_down, gtk_clist_get_row_data(clist, row + 1) != NULL);
250                 }
251         } else {
252                 gtk_widget_set_sensitive(personeditdlg.email_del, FALSE);
253                 gtk_widget_set_sensitive(personeditdlg.email_up, FALSE);
254                 gtk_widget_set_sensitive(personeditdlg.email_down, FALSE);
255         }
256         personeditdlg.rowIndEMail = row;
257         edit_person_status_show( NULL );
258 }
259
260 static void edit_person_email_move( gint dir ) {
261         GtkCList *clist = GTK_CLIST(personeditdlg.clist_email);
262         gint row = personeditdlg.rowIndEMail + dir;
263         ItemEMail *email = gtk_clist_get_row_data( clist, row );
264         if( email ) {
265                 gtk_clist_row_move( clist, personeditdlg.rowIndEMail, row );
266                 personeditdlg.rowIndEMail = row;
267                 if (!personeditdlg.read_only) {
268                         gtk_widget_set_sensitive(personeditdlg.email_up, row > 0);
269                         gtk_widget_set_sensitive(personeditdlg.email_down, gtk_clist_get_row_data(clist, row + 1) != NULL);
270                 }
271         } else {
272                 gtk_widget_set_sensitive(personeditdlg.email_up, FALSE);
273                 gtk_widget_set_sensitive(personeditdlg.email_down, FALSE);
274         }
275         edit_person_email_clear( NULL );
276         edit_person_status_show( NULL );
277 }
278
279 static void edit_person_email_move_up( gpointer data ) {
280         edit_person_email_move( -1 );
281 }
282
283 static void edit_person_email_move_down( gpointer data ) {
284         edit_person_email_move( +1 );
285 }
286
287 static void edit_person_email_delete( gpointer data ) {
288         GtkCList *clist = GTK_CLIST(personeditdlg.clist_email);
289         gint row = personeditdlg.rowIndEMail;
290         ItemEMail *email = gtk_clist_get_row_data( clist, row );
291         edit_person_email_clear( NULL );
292         if( email ) {
293                 /* Remove list entry */
294                 gtk_clist_remove( clist, row );
295                 addritem_free_item_email( email );
296                 email = NULL;
297         }
298
299         /* Position hilite bar */
300         email = gtk_clist_get_row_data( clist, row );
301         if( ! email ) {
302                 personeditdlg.rowIndEMail = -1 + row;
303         }
304         if (!personeditdlg.read_only) {
305                 gtk_widget_set_sensitive(personeditdlg.email_del, gtk_clist_get_row_data(clist, 0) != NULL);
306                 gtk_widget_set_sensitive(personeditdlg.email_up, gtk_clist_get_row_data(clist, personeditdlg.rowIndEMail + 1) != NULL);
307                 gtk_widget_set_sensitive(personeditdlg.email_down, gtk_clist_get_row_data(clist, personeditdlg.rowIndEMail - 1) != NULL);
308         }
309         edit_person_status_show( NULL );
310 }
311
312 static ItemEMail *edit_person_email_edit( gboolean *error, ItemEMail *email ) {
313         ItemEMail *retVal = NULL;
314         gchar *sEmail, *sAlias, *sRemarks, *sEmail_;
315
316         *error = TRUE;
317         sEmail_ = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_email), 0, -1 );
318         sAlias = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_alias), 0, -1 );
319         sRemarks = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_remarks), 0, -1 );
320         sEmail = mgu_email_check_empty( sEmail_ );
321         g_free( sEmail_ );
322
323         if( sEmail ) {
324                 if( email == NULL ) {
325                         email = addritem_create_item_email();
326                 }
327                 addritem_email_set_address( email, sEmail );
328                 addritem_email_set_alias( email, sAlias );
329                 addritem_email_set_remarks( email, sRemarks );
330                 retVal = email;
331                 *error = FALSE;
332         }
333         else {
334                 edit_person_status_show( _( "An Email address must be supplied." ) );
335         }
336
337         g_free( sEmail );
338         g_free( sAlias );
339         g_free( sRemarks );
340
341         return retVal;
342 }
343
344 static void edit_person_email_modify( gpointer data ) {
345         gboolean errFlg = FALSE;
346         GtkCList *clist = GTK_CLIST(personeditdlg.clist_email);
347         gint row = personeditdlg.rowIndEMail;
348         ItemEMail *email = gtk_clist_get_row_data( clist, row );
349         if( email ) {
350                 edit_person_email_edit( &errFlg, email );
351                 if( ! errFlg ) {
352                         gtk_clist_set_text( clist, row, EMAIL_COL_EMAIL, email->address );
353                         gtk_clist_set_text( clist, row, EMAIL_COL_ALIAS, email->obj.name );
354                         gtk_clist_set_text( clist, row, EMAIL_COL_REMARKS, email->remarks );
355                         edit_person_email_clear( NULL );
356                 }
357         }
358 }
359
360 static void edit_person_email_add( gpointer data ) {
361         GtkCList *clist = GTK_CLIST(personeditdlg.clist_email);
362         gboolean errFlg = FALSE;
363         ItemEMail *email = NULL;
364         gint row = personeditdlg.rowIndEMail;
365         if( gtk_clist_get_row_data( clist, row ) == NULL ) row = 0;
366
367         email = edit_person_email_edit( &errFlg, NULL );
368         if( ! errFlg ) {
369                 gchar *text[ EMAIL_N_COLS ];
370                 text[ EMAIL_COL_EMAIL   ] = email->address;
371 #ifndef MAEMO
372                 text[ EMAIL_COL_ALIAS   ] = email->obj.name;
373                 text[ EMAIL_COL_REMARKS ] = email->remarks;
374 #endif
375                 row = gtk_clist_insert( clist, 1 + row, text );
376                 gtk_clist_set_row_data( clist, row, email );
377                 gtk_clist_select_row( clist, row, 0 );
378                 edit_person_email_clear( NULL );
379         }
380 }
381
382 /*
383 * Comparison using cell contents (text in first column). Used for sort
384 * address index widget.
385 */
386 static gint edit_person_attrib_compare_func(
387         GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2 )
388 {
389         GtkCell *cell1 = ((GtkCListRow *)ptr1)->cell;
390         GtkCell *cell2 = ((GtkCListRow *)ptr2)->cell;
391         gchar *name1 = NULL, *name2 = NULL;
392
393         if( cell1 ) name1 = cell1->u.text;
394         if( cell2 ) name2 = cell2->u.text;
395         if( ! name1 ) return ( name2 != NULL );
396         if( ! name2 ) return -1;
397         return g_utf8_collate( name1, name2 );
398 }
399
400 static gboolean list_find_attribute(const gchar *attr)
401 {
402         GtkCList *clist = GTK_CLIST(personeditdlg.clist_attrib);
403         UserAttribute *attrib;
404         gint row = 0;
405         while( (attrib = gtk_clist_get_row_data( clist, row )) ) {
406                 if (!g_ascii_strcasecmp(attrib->name, attr)) {
407                         gtk_clist_select_row(clist, row, 0);
408                         return TRUE;
409                 }
410                 row++;
411         }
412         return FALSE;
413 }
414
415 static gboolean list_find_email(const gchar *addr)
416 {
417         GtkCList *clist = GTK_CLIST(personeditdlg.clist_email);
418         ItemEMail *email;
419         gint row = 0;
420         while( (email = gtk_clist_get_row_data( clist, row )) ) {
421                 if (!g_ascii_strcasecmp(email->address, addr)) {
422                         gtk_clist_select_row(clist, row, 0);
423                         return TRUE;
424                 }
425                 row++;
426         }
427         return FALSE;
428 }
429
430 /*
431 * Load clist with a copy of person's email addresses.
432 */
433 static void edit_person_load_attrib( ItemPerson *person ) {
434         GList *node = person->listAttrib;
435         GtkCList *clist = GTK_CLIST(personeditdlg.clist_attrib);
436         gchar *text[ ATTRIB_N_COLS ];
437         while( node ) {
438                 UserAttribute *atorig = ( UserAttribute * ) node->data;
439                 UserAttribute *attrib = addritem_copy_attribute( atorig );
440                 gint row;
441                 debug_print("name: %s value: %s\n", attrib->name, attrib->value);
442                 text[ ATTRIB_COL_NAME  ] = attrib->name;
443                 text[ ATTRIB_COL_VALUE ] = attrib->value;
444
445                 row = gtk_clist_append( clist, text );
446                 gtk_clist_set_row_data( clist, row, attrib );
447                 node = g_list_next( node );
448         }
449 }
450
451 static void edit_person_attrib_list_selected( GtkCList *clist, gint row, gint column, GdkEvent *event, gpointer data ) {
452         UserAttribute *attrib = gtk_clist_get_row_data( clist, row );
453         if( attrib && !personeditdlg.read_only && !personeditdlg.ldap ) {
454                 gtk_entry_set_text( GTK_ENTRY(personeditdlg.entry_atname), attrib->name );
455                 gtk_entry_set_text( GTK_ENTRY(personeditdlg.entry_atvalue), attrib->value );
456                 gtk_widget_set_sensitive(personeditdlg.attrib_del, TRUE);
457         } else {
458                 gtk_widget_set_sensitive(personeditdlg.attrib_del, FALSE);
459         }
460         personeditdlg.rowIndAttrib = row;
461         edit_person_status_show( NULL );
462 }
463
464 static void edit_person_attrib_delete( gpointer data ) {
465         GtkCList *clist = GTK_CLIST(personeditdlg.clist_attrib);
466         gint row = personeditdlg.rowIndAttrib;
467         UserAttribute *attrib = gtk_clist_get_row_data( clist, row );
468         edit_person_attrib_clear( NULL );
469         if( attrib ) {
470                 /* Remove list entry */
471                 gtk_clist_remove( clist, row );
472                 addritem_free_attribute( attrib );
473                 attrib = NULL;
474         }
475
476         /* Position hilite bar */
477         attrib = gtk_clist_get_row_data( clist, row );
478         if( ! attrib ) {
479                 personeditdlg.rowIndAttrib = -1 + row;
480         } 
481         
482         if (!personeditdlg.read_only && !personeditdlg.ldap)
483                 gtk_widget_set_sensitive(personeditdlg.attrib_del, gtk_clist_get_row_data(clist, 0) != NULL);
484         
485         edit_person_status_show( NULL );
486 }
487
488 static UserAttribute *edit_person_attrib_edit( gboolean *error, UserAttribute *attrib ) {
489         UserAttribute *retVal = NULL;
490         gchar *sName, *sValue, *sName_, *sValue_;
491
492         *error = TRUE;
493         sName_ = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_atname), 0, -1 );
494         sValue_ = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_atvalue), 0, -1 );
495         sName = mgu_email_check_empty( sName_ );
496         sValue = mgu_email_check_empty( sValue_ );
497         g_free( sName_ );
498         g_free( sValue_ );
499
500         if( sName && sValue ) {
501                 if( attrib == NULL ) {
502                         attrib = addritem_create_attribute();
503                 }
504                 addritem_attrib_set_name( attrib, sName );
505                 addritem_attrib_set_value( attrib, sValue );
506                 retVal = attrib;
507                 *error = FALSE;
508         }
509         else {
510                 edit_person_status_show( _( "A Name and Value must be supplied." ) );
511         }
512
513         g_free( sName );
514         g_free( sValue );
515
516         return retVal;
517 }
518
519 static void edit_person_attrib_modify( gpointer data ) {
520         gboolean errFlg = FALSE;
521         GtkCList *clist = GTK_CLIST(personeditdlg.clist_attrib);
522         gint row = personeditdlg.rowIndAttrib;
523         UserAttribute *attrib = gtk_clist_get_row_data( clist, row );
524         if( attrib ) {
525                 edit_person_attrib_edit( &errFlg, attrib );
526                 if( ! errFlg ) {
527                         gtk_clist_set_text( clist, row, ATTRIB_COL_NAME, attrib->name );
528                         gtk_clist_set_text( clist, row, ATTRIB_COL_VALUE, attrib->value );
529                         edit_person_attrib_clear( NULL );
530                 }
531         }
532 }
533
534 static void edit_person_attrib_add( gpointer data ) {
535         GtkCList *clist = GTK_CLIST(personeditdlg.clist_attrib);
536         gboolean errFlg = FALSE;
537         UserAttribute *attrib = NULL;
538         gint row = personeditdlg.rowIndAttrib;
539         if( gtk_clist_get_row_data( clist, row ) == NULL ) row = 0;
540
541         attrib = edit_person_attrib_edit( &errFlg, NULL );
542         if( ! errFlg ) {
543                 gchar *text[ ATTRIB_N_COLS ];
544                 text[ ATTRIB_COL_NAME  ] = attrib->name;
545                 text[ ATTRIB_COL_VALUE ] = attrib->value;
546
547                 row = gtk_clist_insert( clist, 1 + row, text );
548                 gtk_clist_set_row_data( clist, row, attrib );
549                 gtk_clist_select_row( clist, row, 0 );
550                 edit_person_attrib_clear( NULL );
551         }
552 }
553
554 /*!
555  *\brief        Save Gtk object size to prefs dataset
556  */
557 static void edit_person_size_allocate_cb(GtkWidget *widget,
558                                          GtkAllocation *allocation)
559 {
560         g_return_if_fail(allocation != NULL);
561
562         prefs_common.addressbookeditpersonwin_width = allocation->width;
563         prefs_common.addressbookeditpersonwin_height = allocation->height;
564 }
565
566 /* build edit person widgets, return a pointer to the main container of the widgetset (a vbox) */
567 static GtkWidget* addressbook_edit_person_widgets_create( GtkWidget* container, gboolean *cancelled )
568 {
569         GtkWidget *vbox;
570         GtkWidget *vnbox;
571         GtkWidget *notebook;
572         GtkWidget *hbbox;
573         GtkWidget *ok_btn;
574         GtkWidget *cancel_btn;
575
576         vbox = gtk_vbox_new(FALSE, 4);
577          gtk_container_set_border_width(GTK_CONTAINER(vbox), BORDER_WIDTH); 
578         gtk_widget_show(vbox);
579         gtk_container_add(GTK_CONTAINER(container), vbox);
580
581         vnbox = gtk_vbox_new(FALSE, 4);
582         gtk_container_set_border_width(GTK_CONTAINER(vnbox), 4);
583         gtk_widget_show(vnbox);
584         gtk_box_pack_start(GTK_BOX(vbox), vnbox, TRUE, TRUE, 0);
585
586         /* Notebook */
587         notebook = gtk_notebook_new();
588         gtk_widget_show(notebook);
589         gtk_box_pack_start(GTK_BOX(vnbox), notebook, TRUE, TRUE, 0);
590         gtk_container_set_border_width(GTK_CONTAINER(notebook), 6);
591
592         /* Button panel */
593         if (prefs_common.addressbook_use_editaddress_dialog)
594         gtkut_stock_button_set_create(&hbbox, &cancel_btn, GTK_STOCK_CANCEL,
595                                       &ok_btn, GTK_STOCK_OK,
596                                       NULL, NULL);
597         else
598                 gtkut_stock_with_text_button_set_create(&hbbox,
599                                           &cancel_btn, GTK_STOCK_CANCEL, _("Discard"),
600                                       &ok_btn, GTK_STOCK_OK, _("Apply"),
601                                       NULL, NULL, NULL);
602         gtk_box_pack_end(GTK_BOX(vnbox), hbbox, FALSE, FALSE, 0);
603         gtk_widget_grab_default(ok_btn);
604
605         g_signal_connect(G_OBJECT(ok_btn), "clicked",
606                          G_CALLBACK(edit_person_ok), cancelled);
607         g_signal_connect(G_OBJECT(cancel_btn), "clicked",
608                          G_CALLBACK(edit_person_cancel), cancelled);
609         g_signal_connect(G_OBJECT(notebook), "switch_page",
610                          G_CALLBACK(edit_person_switch_page), NULL );
611
612         gtk_widget_show_all(vbox);
613
614         personeditdlg.notebook   = notebook;
615         personeditdlg.ok_btn     = ok_btn;
616         personeditdlg.cancel_btn = cancel_btn;
617
618         return vbox;
619 }
620
621 static void addressbook_edit_person_dialog_create( gboolean *cancelled ) {
622         GtkWidget *window;
623         GtkWidget *hsbox;
624         GtkWidget *vbox;
625         GtkWidget *statusbar;
626         static GdkGeometry geometry;
627
628         window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "editaddress");
629         /* gtk_container_set_border_width(GTK_CONTAINER(window), 0); */
630         gtk_window_set_title(GTK_WINDOW(window), _("Edit Person Data"));
631         gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
632         gtk_window_set_modal(GTK_WINDOW(window), TRUE); 
633         g_signal_connect(G_OBJECT(window), "delete_event",
634                          G_CALLBACK(edit_person_delete_event),
635                          cancelled);
636         g_signal_connect(G_OBJECT(window), "size_allocate",
637                          G_CALLBACK(edit_person_size_allocate_cb),
638                         cancelled);
639         g_signal_connect(G_OBJECT(window), "key_press_event",
640                          G_CALLBACK(edit_person_key_pressed),
641                          cancelled);
642
643         vbox = addressbook_edit_person_widgets_create(window, cancelled);
644
645         /* Status line */
646         hsbox = gtk_hbox_new(FALSE, 0);
647         gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, BORDER_WIDTH);
648         statusbar = gtk_statusbar_new();
649         gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH);
650
651         if (!geometry.min_height) {
652                 geometry.min_width = EDITPERSON_WIDTH;
653                 geometry.min_height = EDITPERSON_HEIGHT;
654         }
655
656         gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
657                                       GDK_HINT_MIN_SIZE);
658         gtk_widget_set_size_request(window, prefs_common.addressbookeditpersonwin_width,
659                                     prefs_common.addressbookeditpersonwin_height);
660
661         personeditdlg.container  = window;
662         personeditdlg.statusbar  = statusbar;
663         personeditdlg.status_cid = gtk_statusbar_get_context_id( GTK_STATUSBAR(statusbar), "Edit Person Dialog" );
664
665 }
666
667 /* parent must be a box */
668 static void addressbook_edit_person_widgetset_create( GtkWidget *parent, gboolean *cancelled )
669 {
670         GtkWidget *vbox;
671         GtkWidget *label;
672
673         if ( parent == NULL )
674                 g_warning("addressbook_edit_person_widgetset_create: parent is NULL");
675
676         vbox = gtk_vbox_new(FALSE, 0);
677         gtk_box_pack_end(GTK_BOX(parent), vbox, TRUE, TRUE, 0);
678
679         label = gtk_label_new(_("Edit Person Data"));
680         gtk_label_set_justify( GTK_LABEL(label), GTK_JUSTIFY_CENTER);
681         gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
682
683         addressbook_edit_person_widgets_create(vbox, cancelled);
684
685         gtk_widget_set_size_request(vbox, EDITPERSON_WIDTH, EDITPERSON_HEIGHT);
686
687         personeditdlg.container = vbox;
688         personeditdlg.title = label;
689         personeditdlg.statusbar  = NULL;
690         personeditdlg.status_cid = 0;
691 }
692
693 void addressbook_edit_person_widgetset_hide( void )
694 {
695         if ( personeditdlg.container )
696                 gtk_widget_hide( personeditdlg.container );
697 }
698
699 GtkWidget *picture;
700
701 static void addressbook_edit_person_set_picture(gpointer data)
702 {
703                 GError *error = NULL;
704                 gchar *filename;
705                 int width, height, scalewidth, scaleheight;
706                 if ( (filename = filesel_select_file_open(_("Choose a picture"), NULL)) ) {
707                         personeditdlg.picture = gdk_pixbuf_new_from_file(filename, &error);
708                         personeditdlg.picture_set = TRUE;
709                         g_free(filename);
710                         width = gdk_pixbuf_get_width(personeditdlg.picture);
711                         height = gdk_pixbuf_get_height(personeditdlg.picture);
712                         
713                         if ( width > 128 || height > 128 ) {
714                                 if (width > height) {
715                                         scaleheight = (height * 128) / width;
716                                         scalewidth = 128;
717                                 }
718                                 else {
719                                         scalewidth = (width * 128) / height;
720                                         scaleheight = 128;
721                                 }
722                                 personeditdlg.picture = gdk_pixbuf_scale_simple(personeditdlg.picture, scalewidth, scaleheight, GDK_INTERP_BILINEAR);
723                         }
724                 gtk_image_set_from_pixbuf(GTK_IMAGE(picture), personeditdlg.picture);
725                 }
726 }
727
728 static void addressbook_edit_person_page_basic( gint pageNum, gchar *pageLbl ) {
729         GtkWidget *vbox;
730         GtkWidget *hbox;
731         GtkWidget *table;
732         GtkWidget *label;
733         GtkWidget *ebox_picture;
734         GtkWidget *frame_picture;
735         GtkWidget *entry_name;
736         GtkWidget *entry_fn;
737         GtkWidget *entry_ln;
738         GtkWidget *entry_nn;
739         const gchar *locale;
740         gint top = 0;
741
742         vbox = gtk_vbox_new( FALSE, 20 );
743         hbox = gtk_hbox_new( FALSE, 8 );
744
745         gtk_widget_show( vbox );        
746         
747         /* User's picture */
748         ebox_picture = gtk_event_box_new();
749         frame_picture = gtk_frame_new("Photo");
750         
751         /* Room for a photo */
752         personeditdlg.picture = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 128, 128);
753         personeditdlg.picture_set = FALSE;
754         picture = gtk_image_new_from_pixbuf(personeditdlg.picture);
755         
756         gtk_container_add(GTK_CONTAINER(ebox_picture), picture);
757         gtk_container_add(GTK_CONTAINER(frame_picture), ebox_picture);  
758         gtk_container_add(GTK_CONTAINER( personeditdlg.notebook ), hbox );
759         gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
760         gtk_container_set_border_width( GTK_CONTAINER (hbox), BORDER_WIDTH );
761
762         label = gtk_label_new_with_mnemonic( pageLbl );
763         gtk_widget_show( label );
764         
765         gtk_box_pack_start(GTK_BOX(hbox), frame_picture, TRUE, TRUE, 0);
766         
767         gtk_notebook_set_tab_label(
768                 GTK_NOTEBOOK( personeditdlg.notebook ),
769                 gtk_notebook_get_nth_page( GTK_NOTEBOOK( personeditdlg.notebook ), pageNum ), label );
770         
771         g_signal_connect(G_OBJECT(ebox_picture), "button_press_event", 
772                         G_CALLBACK(addressbook_edit_person_set_picture), NULL);
773
774         table = gtk_table_new( 3, 3, FALSE);
775
776 #define ATTACH_ROW(text, entry) \
777 { \
778         label = gtk_label_new(text); \
779         gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), \
780                          GTK_FILL, 0, 0, 0); \
781         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
782  \
783         entry = gtk_entry_new(); \
784         gtk_table_attach(GTK_TABLE(table), entry, 1, 2, top, (top + 1), \
785                          GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0); \
786         top++; \
787 }
788
789 #define ATTACH_HIDDEN_ROW(text, entry) \
790 { \
791         entry = gtk_entry_new(); \
792 }
793
794 #ifndef MAEMO
795         ATTACH_ROW(_("Display Name"), entry_name);
796 #else
797         ATTACH_HIDDEN_ROW(_("Display Name"), entry_name);
798 #endif
799         locale = conv_get_current_locale();
800         if (locale &&
801             (!g_ascii_strncasecmp(locale, "ja", 2) ||
802              !g_ascii_strncasecmp(locale, "ko", 2) ||
803              !g_ascii_strncasecmp(locale, "zh", 2))) {
804                 ATTACH_ROW(_("Last Name"), entry_ln);
805                 ATTACH_ROW(_("First Name"), entry_fn);
806         } else {
807                 ATTACH_ROW(_("First Name"), entry_fn);
808                 ATTACH_ROW(_("Last Name"), entry_ln);
809         }
810 #ifndef MAEMO
811         ATTACH_ROW(_("Nickname"), entry_nn);
812 #else
813         ATTACH_HIDDEN_ROW(_("Nickname"), entry_nn);
814 #endif
815
816 #undef ATTACH_ROW
817 #undef ATTACH_HIDDEN_ROW
818         gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0);
819         gtk_box_pack_end(GTK_BOX(hbox), vbox, TRUE, TRUE, 0);
820         gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
821         gtk_table_set_row_spacings(GTK_TABLE(table), 15);
822         gtk_table_set_col_spacings(GTK_TABLE(table), 8);
823
824         gtk_widget_show_all(vbox);
825         personeditdlg.entry_name  = entry_name;
826         personeditdlg.entry_first = entry_fn;
827         personeditdlg.entry_last  = entry_ln;
828         personeditdlg.entry_nick  = entry_nn;
829 }
830
831 static gboolean email_adding = FALSE, email_saving = FALSE;
832
833 static void edit_person_entry_email_changed (GtkWidget *entry, gpointer data)
834 {
835         gboolean non_empty = gtk_clist_get_row_data(GTK_CLIST(personeditdlg.clist_email), 0) != NULL;
836
837         if (personeditdlg.read_only)
838                 return;
839
840         if (gtk_entry_get_text(GTK_ENTRY(personeditdlg.entry_email)) == NULL
841         ||  strlen(gtk_entry_get_text(GTK_ENTRY(personeditdlg.entry_email))) == 0) {
842                 gtk_widget_set_sensitive(personeditdlg.email_add,FALSE);
843                 gtk_widget_set_sensitive(personeditdlg.email_mod,FALSE);
844                 email_adding = FALSE;
845                 email_saving = FALSE;
846         } else if (list_find_email(gtk_entry_get_text(GTK_ENTRY(personeditdlg.entry_email)))) {
847                 gtk_widget_set_sensitive(personeditdlg.email_add,FALSE);
848                 gtk_widget_set_sensitive(personeditdlg.email_mod,non_empty);
849                 email_adding = FALSE;
850                 email_saving = non_empty;
851         } else {
852                 gtk_widget_set_sensitive(personeditdlg.email_add,TRUE);
853                 gtk_widget_set_sensitive(personeditdlg.email_mod,non_empty);
854                 email_adding = TRUE;
855                 email_saving = non_empty;
856         }
857 }
858
859 static gboolean edit_person_entry_email_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
860 {
861         if (event && event->keyval == GDK_Return) {
862                 if (email_saving)
863                         edit_person_email_modify(NULL);         
864                 else if (email_adding)
865                         edit_person_email_add(NULL);
866         }
867         return FALSE;
868 }
869
870
871 static void addressbook_edit_person_page_email( gint pageNum, gchar *pageLbl ) {
872         GtkWidget *vbox;
873         GtkWidget *hbox;
874         GtkWidget *vboxl;
875         GtkWidget *vboxb;
876         GtkWidget *vbuttonbox;
877         GtkWidget *buttonUp;
878         GtkWidget *buttonDown;
879         GtkWidget *buttonDel;
880         GtkWidget *buttonMod;
881         GtkWidget *buttonAdd;
882
883         GtkWidget *table;
884         GtkWidget *label;
885         GtkWidget *clist_swin;
886         GtkWidget *clist;
887         GtkWidget *entry_email;
888         GtkWidget *entry_alias;
889         GtkWidget *entry_remarks;
890         gint top;
891
892         gchar *titles[ EMAIL_N_COLS ];
893         gint i;
894
895         titles[ EMAIL_COL_EMAIL   ] = _("Email Address");
896 #ifndef MAEMO
897         titles[ EMAIL_COL_ALIAS   ] = _("Alias");
898         titles[ EMAIL_COL_REMARKS ] = _("Remarks");
899 #endif
900         vbox = gtk_vbox_new( FALSE, 8 );
901         gtk_widget_show( vbox );
902         gtk_container_add( GTK_CONTAINER( personeditdlg.notebook ), vbox );
903         gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
904
905         label = gtk_label_new_with_mnemonic( pageLbl );
906         gtk_widget_show( label );
907         gtk_notebook_set_tab_label(
908                 GTK_NOTEBOOK( personeditdlg.notebook ),
909                 gtk_notebook_get_nth_page( GTK_NOTEBOOK( personeditdlg.notebook ), pageNum ), label );
910
911         /* Split into two areas */
912         hbox = gtk_hbox_new( FALSE, 0 );
913         gtk_container_add( GTK_CONTAINER( vbox ), hbox );
914
915         /* Address list */
916         vboxl = gtk_vbox_new( FALSE, 4 );
917         gtk_container_add( GTK_CONTAINER( hbox ), vboxl );
918         gtk_container_set_border_width( GTK_CONTAINER(vboxl), 4 );
919
920         clist_swin = gtk_scrolled_window_new( NULL, NULL );
921         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(clist_swin),
922                                        GTK_POLICY_AUTOMATIC,
923                                        GTK_POLICY_AUTOMATIC);
924
925         clist = gtk_clist_new_with_titles( EMAIL_N_COLS, titles );
926
927         gtk_container_add( GTK_CONTAINER(clist_swin), clist );
928         gtk_clist_set_selection_mode( GTK_CLIST(clist), GTK_SELECTION_BROWSE );
929         gtk_clist_set_column_width( GTK_CLIST(clist), EMAIL_COL_EMAIL, EMAIL_COL_WIDTH_EMAIL );
930         gtk_clist_set_column_width( GTK_CLIST(clist), EMAIL_COL_ALIAS, EMAIL_COL_WIDTH_ALIAS );
931
932         for( i = 0; i < EMAIL_N_COLS; i++ )
933                 GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(clist)->column[i].button, GTK_CAN_FOCUS);
934
935         /* Data entry area */
936         table = gtk_table_new( 4, 2, FALSE);
937
938 #ifndef MAEMO
939         gtk_container_add( GTK_CONTAINER(vboxl), clist_swin );
940         gtk_box_pack_start(GTK_BOX(vboxl), table, FALSE, FALSE, 0);
941 #else
942         gtk_box_pack_start(GTK_BOX(vboxl), table, FALSE, FALSE, 0);
943         gtk_container_add( GTK_CONTAINER(vboxl), clist_swin );
944         gtk_clist_column_titles_hide(GTK_CLIST(clist));
945 #endif
946         gtk_container_set_border_width( GTK_CONTAINER(table), 4 );
947         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
948         gtk_table_set_col_spacings(GTK_TABLE(table), 4);
949
950         entry_email = gtk_entry_new();
951         entry_alias = gtk_entry_new();
952         entry_remarks = gtk_entry_new();
953
954         /* First row */
955         top = 0;
956         label = gtk_label_new(_("Email Address"));
957         gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
958         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
959
960         gtk_table_attach(GTK_TABLE(table), entry_email, 1, 2, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
961
962 #ifndef MAEMO
963         /* Next row */
964         ++top;
965         label = gtk_label_new(_("Alias"));
966         gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
967         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
968
969         gtk_table_attach(GTK_TABLE(table), entry_alias, 1, 2, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
970
971         /* Next row */
972         ++top;
973         label = gtk_label_new(_("Remarks"));
974         gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
975         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
976
977         gtk_table_attach(GTK_TABLE(table), entry_remarks, 1, 2, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
978 #endif
979
980         /* Button box */
981         vboxb = gtk_vbox_new( FALSE, 4 );
982         gtk_box_pack_start(GTK_BOX(hbox), vboxb, FALSE, FALSE, 2);
983
984         vbuttonbox = gtk_vbutton_box_new();
985         gtk_button_box_set_layout( GTK_BUTTON_BOX(vbuttonbox), GTK_BUTTONBOX_START );
986         gtk_box_set_spacing( GTK_BOX(vbuttonbox), 8 );
987         gtk_container_set_border_width( GTK_CONTAINER(vbuttonbox), 4 );
988         gtk_container_add( GTK_CONTAINER(vboxb), vbuttonbox );
989
990         /* Buttons */
991         buttonUp = gtk_button_new_from_stock(GTK_STOCK_GO_UP);
992         buttonDown = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN);
993         buttonDel = gtk_button_new_from_stock(GTK_STOCK_DELETE);
994         buttonMod = gtk_button_new_from_stock(GTK_STOCK_SAVE);
995         buttonAdd = gtk_button_new_from_stock(GTK_STOCK_ADD);
996         
997
998 #ifndef MAEMO
999         gtk_container_add( GTK_CONTAINER(vbuttonbox), buttonUp );
1000
1001         gtk_container_add( GTK_CONTAINER(vbuttonbox), buttonDown );
1002 #endif
1003         gtk_container_add( GTK_CONTAINER(vbuttonbox), buttonDel );
1004
1005         gtk_container_add( GTK_CONTAINER(vbuttonbox), buttonMod );
1006
1007         gtk_container_add( GTK_CONTAINER(vbuttonbox), buttonAdd );
1008
1009         gtk_widget_show_all(vbox);
1010
1011         /* Event handlers */
1012         g_signal_connect( G_OBJECT(clist), "select_row",
1013                           G_CALLBACK( edit_person_email_list_selected), NULL );
1014         g_signal_connect( G_OBJECT(buttonUp), "clicked",
1015                           G_CALLBACK( edit_person_email_move_up ), NULL );
1016         g_signal_connect( G_OBJECT(buttonDown), "clicked",
1017                           G_CALLBACK( edit_person_email_move_down ), NULL );
1018         g_signal_connect( G_OBJECT(buttonDel), "clicked",
1019                           G_CALLBACK( edit_person_email_delete ), NULL );
1020         g_signal_connect( G_OBJECT(buttonMod), "clicked",
1021                           G_CALLBACK( edit_person_email_modify ), NULL );
1022         g_signal_connect( G_OBJECT(buttonAdd), "clicked",
1023                           G_CALLBACK( edit_person_email_add ), NULL );
1024         g_signal_connect(G_OBJECT(entry_email), "changed",
1025                          G_CALLBACK(edit_person_entry_email_changed), NULL);
1026         g_signal_connect(G_OBJECT(entry_email), "key_press_event",
1027                          G_CALLBACK(edit_person_entry_email_pressed), NULL);
1028         g_signal_connect(G_OBJECT(entry_alias), "key_press_event",
1029                          G_CALLBACK(edit_person_entry_email_pressed), NULL);
1030         g_signal_connect(G_OBJECT(entry_remarks), "key_press_event",
1031                          G_CALLBACK(edit_person_entry_email_pressed), NULL);
1032
1033         personeditdlg.clist_email   = clist;
1034         personeditdlg.entry_email   = entry_email;
1035         personeditdlg.entry_alias   = entry_alias;
1036         personeditdlg.entry_remarks = entry_remarks;
1037         personeditdlg.email_up = buttonUp;
1038         personeditdlg.email_down = buttonDown;
1039         personeditdlg.email_del = buttonDel;
1040         personeditdlg.email_mod = buttonMod;
1041         personeditdlg.email_add = buttonAdd;
1042 }
1043
1044 static gboolean attrib_adding = FALSE, attrib_saving = FALSE;
1045
1046 static void edit_person_entry_att_changed (GtkWidget *entry, gpointer data)
1047 {
1048         gboolean non_empty = gtk_clist_get_row_data(GTK_CLIST(personeditdlg.clist_attrib), 0) != NULL;
1049
1050         if (personeditdlg.read_only || personeditdlg.ldap)
1051                 return;
1052
1053         if (gtk_entry_get_text(GTK_ENTRY(personeditdlg.entry_atname)) == NULL
1054         ||  strlen(gtk_entry_get_text(GTK_ENTRY(personeditdlg.entry_atname))) == 0) {
1055                 gtk_widget_set_sensitive(personeditdlg.attrib_add,FALSE);
1056                 gtk_widget_set_sensitive(personeditdlg.attrib_mod,FALSE);
1057                 attrib_adding = FALSE;
1058                 attrib_saving = FALSE;
1059         } else if (list_find_attribute(gtk_entry_get_text(GTK_ENTRY(personeditdlg.entry_atname)))) {
1060                 gtk_widget_set_sensitive(personeditdlg.attrib_add,FALSE);
1061                 gtk_widget_set_sensitive(personeditdlg.attrib_mod,non_empty);
1062                 attrib_adding = FALSE;
1063                 attrib_saving = non_empty;
1064         } else {
1065                 gtk_widget_set_sensitive(personeditdlg.attrib_add,TRUE);
1066                 gtk_widget_set_sensitive(personeditdlg.attrib_mod,non_empty);
1067                 attrib_adding = TRUE;
1068                 attrib_saving = non_empty;
1069         }
1070 }
1071
1072 static gboolean edit_person_entry_att_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
1073 {
1074         if (event && event->keyval == GDK_Return) {
1075                 if (attrib_saving)
1076                         edit_person_attrib_modify(NULL);
1077                 else if (attrib_adding)
1078                         edit_person_attrib_add(NULL);
1079         }
1080         return FALSE;
1081 }
1082
1083 static void addressbook_edit_person_page_attrib( gint pageNum, gchar *pageLbl ) {
1084         GtkWidget *vbox;
1085         GtkWidget *hbox;
1086         GtkWidget *vboxl;
1087         GtkWidget *vboxb;
1088         GtkWidget *vbuttonbox;
1089         GtkWidget *buttonDel;
1090         GtkWidget *buttonMod;
1091         GtkWidget *buttonAdd;
1092
1093         GtkWidget *table;
1094         GtkWidget *label;
1095         GtkWidget *clist_swin;
1096         GtkWidget *clist;
1097         GtkWidget *entry_name;
1098         GtkWidget *entry_value;
1099         gint top;
1100
1101         gchar *titles[ ATTRIB_N_COLS ];
1102         gint i;
1103
1104         titles[ ATTRIB_COL_NAME  ] = _("Name");
1105         titles[ ATTRIB_COL_VALUE ] = _("Value");
1106
1107         vbox = gtk_vbox_new( FALSE, 8 );
1108         gtk_widget_show( vbox );
1109         gtk_container_add( GTK_CONTAINER( personeditdlg.notebook ), vbox );
1110         gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
1111
1112         label = gtk_label_new_with_mnemonic( pageLbl );
1113         gtk_widget_show( label );
1114         gtk_notebook_set_tab_label(
1115                 GTK_NOTEBOOK( personeditdlg.notebook ),
1116                 gtk_notebook_get_nth_page( GTK_NOTEBOOK( personeditdlg.notebook ), pageNum ), label );
1117
1118         /* Split into two areas */
1119         hbox = gtk_hbox_new( FALSE, 0 );
1120         gtk_container_add( GTK_CONTAINER( vbox ), hbox );
1121
1122         /* Attribute list */
1123         vboxl = gtk_vbox_new( FALSE, 4 );
1124         gtk_container_add( GTK_CONTAINER( hbox ), vboxl );
1125         gtk_container_set_border_width( GTK_CONTAINER(vboxl), 4 );
1126
1127         clist_swin = gtk_scrolled_window_new( NULL, NULL );
1128         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(clist_swin),
1129                                        GTK_POLICY_AUTOMATIC,
1130                                        GTK_POLICY_AUTOMATIC);
1131
1132         clist = gtk_clist_new_with_titles( ATTRIB_N_COLS, titles );
1133         gtk_container_add( GTK_CONTAINER(clist_swin), clist );
1134         gtk_clist_set_selection_mode( GTK_CLIST(clist), GTK_SELECTION_BROWSE );
1135         gtk_clist_set_compare_func( GTK_CLIST(clist), edit_person_attrib_compare_func );
1136         gtk_clist_set_auto_sort( GTK_CLIST(clist), TRUE );
1137         gtk_clist_set_column_width( GTK_CLIST(clist), ATTRIB_COL_NAME, ATTRIB_COL_WIDTH_NAME );
1138         gtk_clist_set_column_width( GTK_CLIST(clist), ATTRIB_COL_VALUE, ATTRIB_COL_WIDTH_VALUE );
1139
1140         for( i = 0; i < ATTRIB_N_COLS; i++ )
1141                 GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(clist)->column[i].button, GTK_CAN_FOCUS);
1142
1143         /* Data entry area */
1144 #ifndef MAEMO
1145         table = gtk_table_new( 4, 2, FALSE);
1146         gtk_container_add( GTK_CONTAINER(vboxl), clist_swin );
1147         gtk_box_pack_start(GTK_BOX(vboxl), table, FALSE, FALSE, 0);
1148 #else
1149         table = gtk_table_new( 2, 4, FALSE);
1150         gtk_box_pack_start(GTK_BOX(vboxl), table, FALSE, FALSE, 0);
1151         gtk_container_add( GTK_CONTAINER(vboxl), clist_swin );
1152         gtk_clist_column_titles_hide(GTK_CLIST(clist));
1153 #endif
1154         gtk_container_set_border_width( GTK_CONTAINER(table), 4 );
1155         gtk_table_set_row_spacings(GTK_TABLE(table), 4);
1156         gtk_table_set_col_spacings(GTK_TABLE(table), 4);
1157
1158         /* First row */
1159         top = 0;
1160 #ifndef MAEMO
1161         label = gtk_label_new(_("Name"));
1162         gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
1163         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
1164
1165         entry_name = gtk_entry_new();
1166         gtk_table_attach(GTK_TABLE(table), entry_name, 1, 2, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
1167
1168         /* Next row */
1169         ++top;
1170         label = gtk_label_new(_("Value"));
1171         gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
1172         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
1173
1174         entry_value = gtk_entry_new();
1175         gtk_table_attach(GTK_TABLE(table), entry_value, 1, 2, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
1176 #else
1177         label = gtk_label_new(_("Name"));
1178         gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_FILL, 0, 0, 0);
1179         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
1180
1181         entry_name = gtk_entry_new();
1182         gtk_table_attach(GTK_TABLE(table), entry_name, 1, 2, 0, 1, GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
1183
1184         /* Next row */
1185         ++top;
1186         label = gtk_label_new(_("Value"));
1187         gtk_table_attach(GTK_TABLE(table), label, 2, 3, 0, 1, GTK_FILL, 0, 0, 0);
1188         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
1189
1190         entry_value = gtk_entry_new();
1191         gtk_table_attach(GTK_TABLE(table), entry_value, 3, 4, 0, 1, GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
1192 #endif
1193         /* Button box */
1194         vboxb = gtk_vbox_new( FALSE, 4 );
1195         gtk_box_pack_start(GTK_BOX(hbox), vboxb, FALSE, FALSE, 2);
1196
1197         vbuttonbox = gtk_vbutton_box_new();
1198         gtk_button_box_set_layout( GTK_BUTTON_BOX(vbuttonbox), GTK_BUTTONBOX_START );
1199         gtk_box_set_spacing( GTK_BOX(vbuttonbox), 8 );
1200         gtk_container_set_border_width( GTK_CONTAINER(vbuttonbox), 4 );
1201         gtk_container_add( GTK_CONTAINER(vboxb), vbuttonbox );
1202
1203         /* Buttons */
1204         buttonDel = gtk_button_new_from_stock(GTK_STOCK_DELETE);
1205         gtk_container_add( GTK_CONTAINER(vbuttonbox), buttonDel );
1206
1207         buttonMod = gtk_button_new_from_stock(GTK_STOCK_SAVE);
1208         gtk_container_add( GTK_CONTAINER(vbuttonbox), buttonMod );
1209
1210         buttonAdd = gtk_button_new_from_stock(GTK_STOCK_ADD);
1211         gtk_container_add( GTK_CONTAINER(vbuttonbox), buttonAdd );
1212         
1213         gtk_widget_set_sensitive(buttonDel,FALSE);
1214         gtk_widget_set_sensitive(buttonMod,FALSE);
1215         gtk_widget_set_sensitive(buttonAdd,FALSE);
1216
1217         gtk_widget_show_all(vbox);
1218
1219         /* Event handlers */
1220         g_signal_connect( G_OBJECT(clist), "select_row",
1221                           G_CALLBACK( edit_person_attrib_list_selected), NULL );
1222         g_signal_connect( G_OBJECT(buttonDel), "clicked",
1223                           G_CALLBACK( edit_person_attrib_delete ), NULL );
1224         g_signal_connect( G_OBJECT(buttonMod), "clicked",
1225                           G_CALLBACK( edit_person_attrib_modify ), NULL );
1226         g_signal_connect( G_OBJECT(buttonAdd), "clicked",
1227                           G_CALLBACK( edit_person_attrib_add ), NULL );
1228         g_signal_connect(G_OBJECT(entry_name), "changed",
1229                          G_CALLBACK(edit_person_entry_att_changed), NULL);
1230         g_signal_connect(G_OBJECT(entry_name), "key_press_event",
1231                          G_CALLBACK(edit_person_entry_att_pressed), NULL);
1232         g_signal_connect(G_OBJECT(entry_value), "key_press_event",
1233                          G_CALLBACK(edit_person_entry_att_pressed), NULL);
1234
1235         personeditdlg.clist_attrib  = clist;
1236         personeditdlg.entry_atname  = entry_name;
1237         personeditdlg.entry_atvalue = entry_value;
1238         personeditdlg.attrib_add = buttonAdd;
1239         personeditdlg.attrib_del = buttonDel;
1240         personeditdlg.attrib_mod = buttonMod;
1241 }
1242
1243 static void addressbook_edit_person_create( GtkWidget *parent, gboolean *cancelled ) {
1244         if (prefs_common.addressbook_use_editaddress_dialog)
1245                 addressbook_edit_person_dialog_create( cancelled );
1246         else
1247                 addressbook_edit_person_widgetset_create( parent, cancelled );
1248         addressbook_edit_person_page_basic( PAGE_BASIC, _( "_User Data" ) );
1249         addressbook_edit_person_page_email( PAGE_EMAIL, _( "_Email Addresses" ) );
1250 #ifdef USE_LDAP
1251         if (personeditdlg.ldap)
1252                 addressbook_edit_person_page_attrib_ldap(&personeditdlg, PAGE_ATTRIBUTES, _("O_ther Attributes"));
1253         else
1254 #endif
1255                 addressbook_edit_person_page_attrib( PAGE_ATTRIBUTES, _( "O_ther Attributes" ) );
1256         gtk_widget_show_all( personeditdlg.container );
1257 }
1258
1259 /*
1260 * Return list of email items.
1261 */
1262 static GList *edit_person_build_email_list() {
1263         GtkCList *clist = GTK_CLIST(personeditdlg.clist_email);
1264         GList *listEMail = NULL;
1265         ItemEMail *email;
1266         gint row = 0;
1267         while( (email = gtk_clist_get_row_data( clist, row )) ) {
1268                 listEMail = g_list_append( listEMail, email );
1269                 row++;
1270         }
1271         return listEMail;
1272 }
1273
1274 /*
1275 * Return list of attributes.
1276 */
1277 static GList *edit_person_build_attrib_list() {
1278         GtkCList *clist = GTK_CLIST(personeditdlg.clist_attrib);
1279         GList *listAttrib = NULL;
1280         UserAttribute *attrib;
1281         gint row = 0;
1282         while( (attrib = gtk_clist_get_row_data( clist, row )) ) {
1283                 listAttrib = g_list_append( listAttrib, attrib );
1284                 row++;
1285         }
1286         return listAttrib;
1287 }
1288
1289 static void update_sensitivity(void)
1290 {
1291         gtk_widget_set_sensitive(personeditdlg.entry_name,    !personeditdlg.read_only);
1292         gtk_widget_set_sensitive(personeditdlg.entry_first,   !personeditdlg.read_only);
1293         gtk_widget_set_sensitive(personeditdlg.entry_last,    !personeditdlg.read_only);
1294         gtk_widget_set_sensitive(personeditdlg.entry_nick,    !personeditdlg.read_only && !personeditdlg.ldap);
1295         gtk_widget_set_sensitive(personeditdlg.entry_email,   !personeditdlg.read_only);
1296         gtk_widget_set_sensitive(personeditdlg.entry_alias,   !personeditdlg.read_only && !personeditdlg.ldap);
1297         gtk_widget_set_sensitive(personeditdlg.entry_remarks, !personeditdlg.read_only && !personeditdlg.ldap);
1298         gtk_widget_set_sensitive(personeditdlg.email_up,      !personeditdlg.read_only);
1299         gtk_widget_set_sensitive(personeditdlg.email_down,    !personeditdlg.read_only);
1300         gtk_widget_set_sensitive(personeditdlg.email_del,     !personeditdlg.read_only);
1301         gtk_widget_set_sensitive(personeditdlg.email_mod,     !personeditdlg.read_only);
1302         gtk_widget_set_sensitive(personeditdlg.email_add,     !personeditdlg.read_only);
1303         gtk_widget_set_sensitive(personeditdlg.entry_atname,  !personeditdlg.read_only);
1304         gtk_widget_set_sensitive(personeditdlg.entry_atvalue, !personeditdlg.read_only);
1305         gtk_widget_set_sensitive(personeditdlg.attrib_add,    !personeditdlg.read_only);
1306         gtk_widget_set_sensitive(personeditdlg.attrib_del,    !personeditdlg.read_only);
1307         gtk_widget_set_sensitive(personeditdlg.attrib_mod,    !personeditdlg.read_only);
1308 }
1309
1310 static void addressbook_edit_person_flush_transient( void )
1311 {
1312         ItemPerson *person = current_person;
1313         EditAddressPostUpdateCallback callback = edit_person_close_post_update_cb;
1314
1315         /* reset transient data */
1316         current_abf = NULL;
1317         current_person = NULL;
1318         current_parent_folder = NULL;
1319         edit_person_close_post_update_cb = NULL;
1320
1321         /* post action to perform on addressbook side */
1322         if (callback)
1323                 callback( person );
1324 }
1325
1326 void addressbook_edit_person_invalidate( AddressBookFile *abf, ItemFolder *parent_folder,
1327                                                                                  ItemPerson *person )
1328 {
1329         if (current_abf == NULL &&
1330                 current_person == NULL &&
1331                 current_parent_folder == NULL)
1332                 /* edit address form is already hidden */
1333                 return;
1334
1335         /* unconditional invalidation or invalidating the currently edited item */
1336         if ( ( abf == NULL && person == NULL && parent_folder == NULL )
1337                 || (current_abf == abf ||
1338                         current_person == person ||
1339                         current_parent_folder == parent_folder))
1340                 addressbook_edit_person_close( TRUE );
1341 }
1342
1343 static gboolean addressbook_edit_person_close( gboolean cancelled )
1344 {
1345         GList *listEMail = NULL;
1346         GList *listAttrib = NULL;
1347         GError *error;
1348         gchar *cn = NULL;
1349
1350         listEMail = edit_person_build_email_list();
1351         listAttrib = edit_person_build_attrib_list();
1352         if( cancelled ) {
1353                 addritem_free_list_email( listEMail );
1354                 addritem_free_list_attribute( listAttrib );
1355                 gtk_clist_clear( GTK_CLIST(personeditdlg.clist_email) );
1356                 gtk_clist_clear( GTK_CLIST(personeditdlg.clist_attrib) );
1357
1358                 if (!prefs_common.addressbook_use_editaddress_dialog)
1359                         gtk_widget_hide( personeditdlg.container );
1360
1361                 /* no callback, as we're discarding the form */
1362                 edit_person_close_post_update_cb = NULL;
1363                 addressbook_edit_person_flush_transient();
1364
1365                 /* set focus to the address list (this is done by the post_update_cb usually) */
1366                 addressbook_address_list_set_focus();
1367                 return FALSE;
1368         }
1369
1370 #ifndef MAEMO
1371         cn = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_name), 0, -1 );
1372 #else
1373         {
1374                 gchar *first = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_first), 0, -1 );
1375                 gchar *last = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_last), 0, -1 );
1376                 cn = g_strdup_printf("%s%s%s", first, (first && last && *first && *last)?" ":"", last);
1377                 g_free(first);
1378                 g_free(last);
1379         }
1380 #endif
1381         if( current_person && current_abf ) {
1382                 /* Update email/attribute list for existing current_person */
1383                 addrbook_update_address_list( current_abf, current_person, listEMail );
1384                 addrbook_update_attrib_list( current_abf, current_person, listAttrib );
1385         }
1386         else {
1387                 /* Create new current_person and email/attribute list */
1388                 if( cn == NULL || *cn == '\0' ) {
1389                         /* Wasting our time */
1390                         if( listEMail == NULL && listAttrib == NULL ) cancelled = TRUE;
1391                 }
1392                 if( ! cancelled && current_abf ) {
1393                         current_person = addrbook_add_address_list( current_abf, current_parent_folder, listEMail );
1394                         addrbook_add_attrib_list( current_abf, current_person, listAttrib );
1395                 }
1396         }
1397         listEMail = NULL;
1398         listAttrib = NULL;
1399
1400         if( ! cancelled ) {
1401                 /* Set current_person stuff */          
1402
1403                 gchar *name;
1404                 addritem_person_set_common_name( current_person, cn );
1405                 if (personeditdlg.picture_set) {
1406                         name = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S, 
1407                                                         ADDRITEM_ID(current_person), NULL );
1408                         gdk_pixbuf_save(personeditdlg.picture, name, "png", &error, NULL);
1409                         addritem_person_set_picture( current_person, ADDRITEM_ID(current_person) ) ;
1410                         g_free( name );
1411                 }
1412                 name = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_first), 0, -1 );
1413                 addritem_person_set_first_name( current_person, name );
1414                 g_free( name );
1415                 name = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_last), 0, -1 );
1416                 addritem_person_set_last_name( current_person, name );
1417                 g_free( name );
1418                 name = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_nick), 0, -1 );
1419                 addritem_person_set_nick_name( current_person, name );
1420                 g_free( name );
1421         }
1422         g_free( cn );
1423
1424         gtk_clist_clear( GTK_CLIST(personeditdlg.clist_email) );
1425         gtk_clist_clear( GTK_CLIST(personeditdlg.clist_attrib) );
1426
1427         if (!prefs_common.addressbook_use_editaddress_dialog)
1428                 gtk_widget_hide( personeditdlg.container );
1429
1430         addressbook_edit_person_flush_transient();
1431
1432         return TRUE;
1433 }
1434  
1435 /*
1436 * Edit person.
1437 * Enter: abf    Address book.
1438 *        parent Parent folder for person (or NULL if adding to root folder). Argument is
1439 *               only required for new objects).
1440 *        person Person to edit, or NULL for a new person object.
1441 *        pgMail If TRUE, E-Mail page will be activated.
1442 * Return: Edited object, or NULL if cancelled.*/
1443 ItemPerson *addressbook_edit_person( AddressBookFile *abf, ItemFolder *parent_folder, ItemPerson *person,
1444                                                                          gboolean pgMail, GtkWidget *parent_container,
1445                                                                          void (*post_update_cb) (ItemPerson *person),
1446                                                                          gboolean get_focus) {
1447         static gboolean cancelled;
1448         GError *error = NULL;
1449
1450         /* set transient data */
1451         current_abf = abf;
1452         current_person = person;
1453         current_parent_folder = parent_folder;
1454         edit_person_close_post_update_cb = post_update_cb;
1455         personeditdlg.ldap = (abf && abf->type == ADBOOKTYPE_LDAP)? TRUE : FALSE;
1456         if( !personeditdlg.container )
1457                 addressbook_edit_person_create(parent_container, &cancelled);
1458
1459         /* typically, get focus when dialog mode is enabled, or when editing a new address */
1460         if( get_focus ) {
1461                 gtk_widget_grab_focus(personeditdlg.ok_btn);
1462                 gtk_widget_grab_focus(personeditdlg.entry_name);
1463         }
1464         
1465         personeditdlg.read_only = (current_abf == NULL);
1466         update_sensitivity();
1467
1468         gtk_widget_show(personeditdlg.container);
1469         if (prefs_common.addressbook_use_editaddress_dialog)
1470                 manage_window_set_transient(GTK_WINDOW(personeditdlg.container));
1471         else
1472                 if (get_focus)
1473                         addressbook_address_list_disable_some_actions();
1474
1475         /* Clear all fields */
1476         personeditdlg.rowIndEMail = -1;
1477         personeditdlg.rowIndAttrib = -1;
1478         edit_person_status_show( "" );
1479         gtk_clist_clear( GTK_CLIST(personeditdlg.clist_email) );
1480         gtk_clist_clear( GTK_CLIST(personeditdlg.clist_attrib) );
1481         gtk_entry_set_text(GTK_ENTRY(personeditdlg.entry_name), "" );
1482         gtk_entry_set_text(GTK_ENTRY(personeditdlg.entry_first), "" );
1483         gtk_entry_set_text(GTK_ENTRY(personeditdlg.entry_last), "" );
1484         gtk_entry_set_text(GTK_ENTRY(personeditdlg.entry_nick), "" );
1485
1486         personeditdlg.editNew = FALSE;
1487         if( current_person ) {
1488                 if( ADDRITEM_NAME(current_person) )
1489                         gtk_entry_set_text(GTK_ENTRY(personeditdlg.entry_name), ADDRITEM_NAME(person) );
1490                 else
1491                         personeditdlg.picture = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, 128, 128);
1492                 if( current_person->picture ) { 
1493                         gchar *filename = g_strconcat( get_rc_dir(), G_DIR_SEPARATOR_S, ADDRBOOK_DIR, G_DIR_SEPARATOR_S, 
1494                                                         current_person->picture, NULL );
1495                         personeditdlg.picture = gdk_pixbuf_new_from_file(filename, &error);
1496                         personeditdlg.picture_set = TRUE;
1497                         g_free(filename);
1498                 } else {
1499                         personeditdlg.picture_set = FALSE;
1500                         personeditdlg.picture = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 128, 128);
1501                 }
1502                 gtk_image_set_from_pixbuf(GTK_IMAGE(picture), personeditdlg.picture);
1503
1504                 if( current_person->firstName )
1505                         gtk_entry_set_text(GTK_ENTRY(personeditdlg.entry_first), current_person->firstName );
1506                 if( current_person->lastName )
1507                         gtk_entry_set_text(GTK_ENTRY(personeditdlg.entry_last), current_person->lastName );
1508                 if( current_person->nickName )
1509                         gtk_entry_set_text(GTK_ENTRY(personeditdlg.entry_nick), current_person->nickName );
1510                 edit_person_load_email( current_person );
1511                 edit_person_load_attrib( current_person );
1512                 gtk_entry_set_text(GTK_ENTRY(personeditdlg.entry_atvalue), "");
1513         }
1514         else {
1515                 personeditdlg.editNew = TRUE;
1516         }
1517
1518         /* Select appropriate start page */
1519         if( pgMail ) {
1520                 gtk_notebook_set_current_page( GTK_NOTEBOOK(personeditdlg.notebook), PAGE_EMAIL );
1521         }
1522         else {
1523                 gtk_notebook_set_current_page( GTK_NOTEBOOK(personeditdlg.notebook), PAGE_BASIC );
1524         }
1525
1526         gtk_clist_select_row( GTK_CLIST(personeditdlg.clist_email), 0, 0 );
1527         gtk_clist_select_row( GTK_CLIST(personeditdlg.clist_attrib), 0, 0 );
1528         edit_person_email_clear( NULL );
1529         if (current_person)
1530                 edit_person_email_list_selected(GTK_CLIST(personeditdlg.clist_email), 0, 0, NULL, NULL);
1531
1532         edit_person_attrib_clear( NULL );
1533
1534         if (prefs_common.addressbook_use_editaddress_dialog) {
1535
1536         gtk_main();
1537                 gtk_widget_hide( personeditdlg.container );
1538
1539                 if (!addressbook_edit_person_close( cancelled ))
1540                         return NULL;
1541         }
1542
1543         return current_person;
1544 }
1545
1546 /*
1547 * End of Source.
1548 */
1549