d2ec2a07071ec10b9c898991ee2b137ef302c626
[claws.git] / src / editgroup.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws 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 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 <glib/gi18n.h>
28 #include <gdk/gdkkeysyms.h>
29
30 #include "addressbook.h"
31 #include "addressitem.h"
32 #include "addrbook.h"
33 #include "addritem.h"
34
35 #include "mgutils.h"
36
37 #include "prefs_common.h"
38
39 #include "alertpanel.h"
40 #include "inputdialog.h"
41 #include "manage_window.h"
42 #include "gtkutils.h"
43
44 #define ADDRESSBOOK_GUESS_FOLDER_NAME   "NewFolder"
45 #define ADDRESSBOOK_GUESS_GROUP_NAME    "NewGroup"
46
47 #define EDITGROUP_WIDTH      580
48 #define EDITGROUP_HEIGHT     340
49
50 typedef enum {
51         GROUP_COL_NAME    = 0,
52         GROUP_COL_EMAIL   = 1,
53         GROUP_COL_REMARKS = 2
54 } GroupEditEMailColumnPos;
55
56 #define GROUP_N_COLS          3
57 #define GROUP_COL_WIDTH_NAME  140
58 #define GROUP_COL_WIDTH_EMAIL 120
59
60 static struct _GroupEdit_dlg {
61         GtkWidget *window;
62         GtkWidget *ok_btn;
63         GtkWidget *cancel_btn;
64         GtkWidget *statusbar;
65         gint status_cid;
66
67         /* Basic data tab */
68         GtkWidget *entry_name;
69         GtkCList *clist_group;
70         GtkCList *clist_avail;
71
72         GHashTable *hashEMail;
73
74 } groupeditdlg;
75
76
77 static gchar *_edit_group_dfl_message_ = NULL;
78
79 static void edit_group_status_show( gchar *msg ) {
80         if( groupeditdlg.statusbar != NULL ) {
81                 gtk_statusbar_pop( GTK_STATUSBAR(groupeditdlg.statusbar), groupeditdlg.status_cid );
82                 if( msg ) {
83                         gtk_statusbar_push( GTK_STATUSBAR(groupeditdlg.statusbar), groupeditdlg.status_cid, msg );
84                 }
85         }
86 }
87
88 static void edit_group_ok(GtkWidget *widget, gboolean *cancelled) {
89         gchar *sName;
90         gboolean errFlag = TRUE;
91
92         sName = gtk_editable_get_chars( GTK_EDITABLE(groupeditdlg.entry_name), 0, -1 );
93         if( sName ) {
94                 g_strstrip( sName );
95                 if( *sName != '\0' ) {
96                         gtk_entry_set_text(GTK_ENTRY(groupeditdlg.entry_name), sName );
97                         *cancelled = FALSE;
98                         gtk_main_quit();
99                         errFlag = FALSE;
100                 }
101         }
102         if( errFlag ) {
103                 edit_group_status_show( _( "A Group Name must be supplied." ) );
104         }
105         g_free( sName );
106 }
107         
108 static void edit_group_cancel(GtkWidget *widget, gboolean *cancelled) {
109         *cancelled = TRUE;
110         gtk_main_quit();
111 }
112
113 static gint edit_group_delete_event(GtkWidget *widget, GdkEventAny *event, gboolean *cancelled) {
114         *cancelled = TRUE;
115         gtk_main_quit();
116         return TRUE;
117 }
118
119 static gboolean edit_group_key_pressed(GtkWidget *widget, GdkEventKey *event, gboolean *cancelled) {
120         if (event && event->keyval == GDK_Escape) {
121                 *cancelled = TRUE;
122                 gtk_main_quit();
123         }
124         return FALSE;
125 }
126
127 static gchar *edit_group_format_item_clist( ItemPerson *person, ItemEMail *email ) {
128         gchar *str = NULL;
129         gchar *aName = ADDRITEM_NAME(email);
130         if( aName == NULL || *aName == '\0' ) return str;
131         if( person ) {
132                 str = g_strdup_printf( "%s - %s", ADDRITEM_NAME(person), aName );
133         }
134         else {
135                 str = g_strdup( aName );
136         }
137         return str;
138 }
139
140 static gint edit_group_clist_add_email( GtkCList *clist, ItemEMail *email ) {
141         ItemPerson *person = ( ItemPerson * ) ADDRITEM_PARENT(email);
142         gchar *str = edit_group_format_item_clist( person, email );
143         gchar *text[ GROUP_N_COLS ];
144         gint row;
145         if( str ) {
146                 text[ GROUP_COL_NAME ] = str;
147         }
148         else {
149                 text[ GROUP_COL_NAME ] = ADDRITEM_NAME(person);
150         }
151         text[ GROUP_COL_EMAIL   ] = email->address;
152         text[ GROUP_COL_REMARKS ] = email->remarks;
153         
154         row = gtk_clist_append( clist, text );
155         gtk_clist_set_row_data( clist, row, email );
156         return row;
157 }
158
159 static void edit_group_load_clist( GtkCList *clist, GList *listEMail ) {
160         GList *node = listEMail;
161         gtk_clist_freeze(clist);
162         while( node ) {
163                 ItemEMail *email = node->data;
164                 edit_group_clist_add_email( clist, email );
165                 node = g_list_next( node );
166         }
167         gtk_clist_thaw(clist);
168 }
169
170
171 static void edit_group_move_email( GtkCList *clist_from, GtkCList *clist_to, GtkCTreeNode *node ) {
172         ItemEMail *email = gtk_ctree_node_get_row_data( GTK_CTREE(clist_from), node );
173         GtkCTreeNode *next = gtkut_ctree_node_next(GTK_CTREE(clist_from), node);
174         GtkCTreeNode *prev = gtkut_ctree_node_prev(GTK_CTREE(clist_from), node);
175         int rrow = 0;
176         if( email ) {
177                 gtk_ctree_remove_node(GTK_CTREE(clist_from), node);
178                 rrow = edit_group_clist_add_email( clist_to, email );
179                 gtk_clist_select_row( clist_to, rrow, 0 );
180                 if (next)
181                         gtk_ctree_select(GTK_CTREE(clist_from), next);
182                 else if (prev)
183                         gtk_ctree_select(GTK_CTREE(clist_from), prev);
184         }
185 }
186
187 static void edit_group_to_group( GtkWidget *widget, gpointer data ) {
188         GList *selected = g_list_copy(GTK_CLIST(groupeditdlg.clist_avail)->selection);
189         /* Clear the selected rows on destination clist */
190         gtk_clist_freeze(groupeditdlg.clist_avail);
191         gtk_clist_freeze(groupeditdlg.clist_group);
192         gtk_clist_unselect_all(groupeditdlg.clist_group);
193         while (selected) {
194                 edit_group_move_email( groupeditdlg.clist_avail,
195                                         groupeditdlg.clist_group, GTK_CTREE_NODE(selected->data) );
196                 selected = selected->next;
197         }
198         g_list_free(selected);
199         gtk_clist_thaw(groupeditdlg.clist_avail);
200         gtk_clist_thaw(groupeditdlg.clist_group);
201 }
202
203 static void edit_group_to_avail( GtkWidget *widget, gpointer data ) {
204         GList *selected = g_list_copy(GTK_CLIST(groupeditdlg.clist_group)->selection);
205         gtk_clist_freeze(groupeditdlg.clist_avail);
206         gtk_clist_freeze(groupeditdlg.clist_group);
207         gtk_clist_unselect_all(groupeditdlg.clist_avail);
208         while (selected) {
209                 edit_group_move_email( groupeditdlg.clist_group,
210                                         groupeditdlg.clist_avail, GTK_CTREE_NODE(selected->data) );
211                 selected = selected->next;
212         }
213         g_list_free(selected);
214         gtk_clist_thaw(groupeditdlg.clist_avail);
215         gtk_clist_thaw(groupeditdlg.clist_group);
216 }
217
218 static gboolean edit_group_list_group_button( GtkCList *clist, GdkEventButton *event, gpointer data ) {
219         if( ! event ) return FALSE;
220         
221         if( event->button == 1 ) {
222                 if( event->type == GDK_2BUTTON_PRESS ) {
223                         edit_group_to_avail( NULL, NULL );
224                 }
225         }
226         return FALSE;
227 }
228
229 static gboolean edit_group_list_avail_button( GtkCList *clist, GdkEventButton *event, gpointer data ) {
230         if( ! event ) return FALSE;
231         
232         if( event->button == 1 ) {
233                 if( event->type == GDK_2BUTTON_PRESS ) {
234                         edit_group_to_group( NULL, NULL );
235                 }
236         }
237         return FALSE;
238 }
239
240 static gint edit_group_list_compare_func( GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2 ) {
241         GtkCell *cell1 = ((GtkCListRow *)ptr1)->cell;
242         GtkCell *cell2 = ((GtkCListRow *)ptr2)->cell;
243         gchar *name1 = NULL, *name2 = NULL;
244         if( cell1 ) name1 = cell1->u.text;
245         if( cell2 ) name2 = cell2->u.text;
246         if( ! name1 ) return ( name2 != NULL );
247         if( ! name2 ) return -1;
248         return g_utf8_collate( name1, name2 );
249 }
250
251 static void addressbook_edit_group_create( gboolean *cancelled ) {
252         GtkWidget *window;
253         GtkWidget *vbox;
254         GtkWidget *hbbox;
255         GtkWidget *ok_btn;
256         GtkWidget *cancel_btn;
257         GtkWidget *hsbox;
258         GtkWidget *statusbar;
259
260         GtkWidget *hboxg;
261         GtkWidget *table;
262         GtkWidget *label;
263         GtkWidget *entry_name;
264         GtkWidget *hboxl;
265         GtkWidget *vboxl;
266         GtkWidget *hboxh;
267
268         GtkWidget *clist_swin;
269         GtkWidget *clist_group;
270         GtkWidget *clist_avail;
271
272         GtkWidget *buttonGroup;
273         GtkWidget *buttonAvail;
274         gint top;
275
276         gchar *titles[ GROUP_N_COLS ];
277         gint i;
278
279         titles[ GROUP_COL_NAME    ] = _( "Name" );
280         titles[ GROUP_COL_EMAIL   ] = _("Email Address");
281         titles[ GROUP_COL_REMARKS ] = _("Remarks");
282
283         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
284         gtk_widget_set_size_request(window, EDITGROUP_WIDTH, EDITGROUP_HEIGHT );
285         gtk_container_set_border_width(GTK_CONTAINER(window), 0);
286         gtk_window_set_title(GTK_WINDOW(window), _("Edit Group Data"));
287         gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
288         gtk_window_set_modal(GTK_WINDOW(window), TRUE); 
289         g_signal_connect(G_OBJECT(window), "delete_event",
290                          G_CALLBACK(edit_group_delete_event),
291                          cancelled);
292         g_signal_connect(G_OBJECT(window), "key_press_event",
293                          G_CALLBACK(edit_group_key_pressed),
294                          cancelled);
295
296         vbox = gtk_vbox_new( FALSE, 6 );
297         gtk_container_set_border_width(GTK_CONTAINER(vbox), BORDER_WIDTH);
298         gtk_widget_show( vbox );
299         gtk_container_add( GTK_CONTAINER( window ), vbox );
300
301         /* Group area */
302         hboxg = gtk_hbox_new( FALSE, 0 );
303         gtk_box_pack_start(GTK_BOX(vbox), hboxg, FALSE, FALSE, 0);
304
305         /* Data entry area */
306         table = gtk_table_new( 1, 3, FALSE);
307         gtk_box_pack_start(GTK_BOX(hboxg), table, TRUE, TRUE, 0);
308         gtk_container_set_border_width( GTK_CONTAINER(table), 4 );
309         gtk_table_set_row_spacings(GTK_TABLE(table), 0);
310         gtk_table_set_col_spacings(GTK_TABLE(table), 4);
311
312         /* First row */
313         top = 0;
314         label = gtk_label_new(_("Group Name"));
315         gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
316         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
317
318         entry_name = gtk_entry_new();
319         gtk_table_attach(GTK_TABLE(table), entry_name, 1, 2, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
320
321         /* List area */
322         hboxl = gtk_hbox_new( FALSE, 6 );
323         gtk_container_set_border_width( GTK_CONTAINER(hboxl), 8 );
324         gtk_box_pack_start(GTK_BOX(vbox), hboxl, TRUE, TRUE, 0);
325
326         /* Group list */
327         vboxl = gtk_vbox_new( FALSE, 0 );
328         gtk_box_pack_start(GTK_BOX(hboxl), vboxl, TRUE, TRUE, 0);
329
330         hboxh = gtk_hbox_new( FALSE, 0 );
331         gtk_container_set_border_width( GTK_CONTAINER(hboxh), 4 );
332         gtk_box_pack_start(GTK_BOX(vboxl), hboxh, FALSE, FALSE, 0);
333         label = gtk_label_new(_("Addresses in Group"));
334         gtk_box_pack_start(GTK_BOX(hboxh), label, TRUE, TRUE, 0);
335         buttonAvail = gtk_button_new_with_label( _( " -> " ) );
336         gtk_box_pack_end(GTK_BOX(hboxh), buttonAvail, FALSE, FALSE, 0);
337
338         clist_swin = gtk_scrolled_window_new( NULL, NULL );
339         gtk_box_pack_start(GTK_BOX(vboxl), clist_swin, TRUE, TRUE, 0);
340         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(clist_swin),
341                                        GTK_POLICY_AUTOMATIC,
342                                        GTK_POLICY_AUTOMATIC);
343
344         clist_group = gtk_sctree_new_with_titles( GROUP_N_COLS, GROUP_N_COLS, titles );
345         gtk_container_add( GTK_CONTAINER(clist_swin), clist_group );
346         gtk_clist_set_selection_mode( GTK_CLIST(clist_group), GTK_SELECTION_EXTENDED );
347         gtk_clist_set_column_width( GTK_CLIST(clist_group), GROUP_COL_NAME, GROUP_COL_WIDTH_NAME );
348         gtk_clist_set_column_width( GTK_CLIST(clist_group), GROUP_COL_EMAIL, GROUP_COL_WIDTH_EMAIL );
349         gtk_clist_set_compare_func( GTK_CLIST(clist_group), edit_group_list_compare_func );
350         gtk_clist_set_auto_sort( GTK_CLIST(clist_group), TRUE );
351
352         for( i = 0; i < GROUP_N_COLS; i++ )
353                 GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(clist_group)->column[i].button, GTK_CAN_FOCUS);
354
355         /* Available list */
356         vboxl = gtk_vbox_new( FALSE, 0 );
357         gtk_box_pack_start(GTK_BOX(hboxl), vboxl, TRUE, TRUE, 0);
358
359         hboxh = gtk_hbox_new( FALSE, 0 );
360         gtk_container_set_border_width( GTK_CONTAINER(hboxh), 4 );
361         gtk_box_pack_start(GTK_BOX(vboxl), hboxh, FALSE, FALSE, 0);
362         buttonGroup = gtk_button_new_with_label( _( " <- " ) );
363         gtk_box_pack_start(GTK_BOX(hboxh), buttonGroup, FALSE, FALSE, 0);
364         label = gtk_label_new(_("Available Addresses"));
365         gtk_box_pack_end(GTK_BOX(hboxh), label, TRUE, TRUE, 0);
366
367         clist_swin = gtk_scrolled_window_new( NULL, NULL );
368         gtk_box_pack_start(GTK_BOX(vboxl), clist_swin, TRUE, TRUE, 0);
369         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(clist_swin),
370                                        GTK_POLICY_AUTOMATIC,
371                                        GTK_POLICY_AUTOMATIC);
372
373         clist_avail = gtk_sctree_new_with_titles( GROUP_N_COLS, GROUP_N_COLS, titles );
374         gtk_container_add( GTK_CONTAINER(clist_swin), clist_avail );
375         gtk_clist_set_selection_mode( GTK_CLIST(clist_avail), GTK_SELECTION_EXTENDED );
376         gtk_clist_set_column_width( GTK_CLIST(clist_avail), GROUP_COL_NAME, GROUP_COL_WIDTH_NAME );
377         gtk_clist_set_column_width( GTK_CLIST(clist_avail), GROUP_COL_EMAIL, GROUP_COL_WIDTH_EMAIL );
378         gtk_clist_set_compare_func( GTK_CLIST(clist_avail), edit_group_list_compare_func );
379         gtk_clist_set_auto_sort( GTK_CLIST(clist_avail), TRUE );
380
381         for( i = 0; i < GROUP_N_COLS; i++ )
382                 GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(clist_avail)->column[i].button, GTK_CAN_FOCUS);
383
384         /* Status line */
385         hsbox = gtk_hbox_new(FALSE, 0);
386         gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, BORDER_WIDTH);
387         statusbar = gtk_statusbar_new();
388         gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH);
389
390         /* Button panel */
391         gtkut_stock_button_set_create(&hbbox, &cancel_btn, GTK_STOCK_CANCEL,
392                                       &ok_btn, GTK_STOCK_OK,
393                                       NULL, NULL);
394         gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
395         gtk_widget_grab_default(ok_btn);
396
397         g_signal_connect(G_OBJECT(ok_btn), "clicked",
398                          G_CALLBACK(edit_group_ok), cancelled);
399         g_signal_connect(G_OBJECT(cancel_btn), "clicked",
400                          G_CALLBACK(edit_group_cancel), cancelled);
401
402         gtk_widget_show_all(vbox);
403
404         /* Event handlers */
405         g_signal_connect( G_OBJECT(buttonGroup), "clicked",
406                           G_CALLBACK( edit_group_to_group ), NULL );
407         g_signal_connect( G_OBJECT(buttonAvail), "clicked",
408                           G_CALLBACK( edit_group_to_avail ), NULL );
409         g_signal_connect(G_OBJECT(clist_avail), "button_press_event",
410                          G_CALLBACK(edit_group_list_avail_button), NULL);
411         g_signal_connect(G_OBJECT(clist_group), "button_press_event",
412                          G_CALLBACK(edit_group_list_group_button), NULL);
413
414         groupeditdlg.window     = window;
415         groupeditdlg.ok_btn     = ok_btn;
416         groupeditdlg.cancel_btn = cancel_btn;
417         groupeditdlg.statusbar  = statusbar;
418         groupeditdlg.status_cid = gtk_statusbar_get_context_id( GTK_STATUSBAR(statusbar), "Edit Group Dialog" );
419
420         groupeditdlg.entry_name  = entry_name;
421         groupeditdlg.clist_group = GTK_CLIST( clist_group );
422         groupeditdlg.clist_avail = GTK_CLIST( clist_avail );
423
424         if( ! _edit_group_dfl_message_ ) {
425                 _edit_group_dfl_message_ = _( "Move Email Addresses to or from Group with arrow buttons" );
426         }
427 }
428
429 /*
430 * Return list of email items.
431 */
432 static GList *edit_group_build_email_list() {
433         GtkCList *clist = GTK_CLIST(groupeditdlg.clist_group);
434         GList *listEMail = NULL;
435         ItemEMail *email;
436         gint row = 0;
437         while( (email = gtk_clist_get_row_data( clist, row )) ) {
438                 listEMail = g_list_append( listEMail, email );
439                 row++;
440         }
441         return listEMail;
442 }
443
444 /*
445 * Edit group.
446 * Enter: abf    Address book.
447 *        folder Parent folder for group (or NULL if adding to root folder). Argument is
448 *               only required for new objects).
449 *        group  Group to edit, or NULL for a new group object.
450 * Return: Edited object, or NULL if cancelled.
451 */
452 ItemGroup *addressbook_edit_group( AddressBookFile *abf, ItemFolder *parent, ItemGroup *group ) {
453         static gboolean cancelled;
454         GList *listEMail = NULL;
455         gchar *name;
456
457         if (!groupeditdlg.window)
458                 addressbook_edit_group_create(&cancelled);
459         gtk_widget_grab_focus(groupeditdlg.ok_btn);
460         gtk_widget_grab_focus(groupeditdlg.entry_name);
461         gtk_widget_show(groupeditdlg.window);
462         manage_window_set_transient(GTK_WINDOW(groupeditdlg.window));
463
464         /* Clear all fields */
465         edit_group_status_show( "" );
466         gtk_clist_clear( GTK_CLIST(groupeditdlg.clist_group) );
467         gtk_clist_clear( GTK_CLIST(groupeditdlg.clist_avail) );
468
469         if( group ) {
470                 if( ADDRITEM_NAME(group) )
471                         gtk_entry_set_text(GTK_ENTRY(groupeditdlg.entry_name), ADDRITEM_NAME(group) );
472                 edit_group_load_clist( groupeditdlg.clist_group, group->listEMail );
473                 gtk_window_set_title( GTK_WINDOW(groupeditdlg.window), _("Edit Group Details"));
474         }
475         else {
476                 gtk_window_set_title( GTK_WINDOW(groupeditdlg.window), _("Add New Group"));
477                 gtk_entry_set_text(GTK_ENTRY(groupeditdlg.entry_name), ADDRESSBOOK_GUESS_GROUP_NAME );
478         }
479
480         listEMail = addrbook_get_available_email_list( abf, group );
481         edit_group_load_clist( groupeditdlg.clist_avail, listEMail );
482         mgu_clear_list( listEMail );
483         listEMail = NULL;
484         gtk_clist_select_row( groupeditdlg.clist_group, 0, 0 );
485         gtk_clist_select_row( groupeditdlg.clist_avail, 0, 0 );
486
487         edit_group_status_show( _edit_group_dfl_message_ );
488
489         gtk_main();
490         gtk_widget_hide( groupeditdlg.window );
491
492         if( cancelled ) {
493                 return NULL;
494         }
495
496         listEMail = edit_group_build_email_list();
497         if( group ) {
498                 /* Update email list */
499                 addrbook_update_group_list( abf, group, listEMail );
500         }
501         else {
502                 /* Create new person and email list */
503                 group = addrbook_add_group_list( abf, parent, listEMail );
504         }
505         name = gtk_editable_get_chars( GTK_EDITABLE(groupeditdlg.entry_name), 0, -1 );
506         addritem_group_set_name( group, name );
507         g_free( name );
508
509         listEMail = NULL;
510         return group;
511 }
512
513 /*
514 * Edit folder.
515 * Enter: abf    Address book.
516 *        parent Parent folder for folder (or NULL if adding to root folder). Argument is
517 *               only required for new objects).
518 *        folder Folder to edit, or NULL for a new folder object.
519 * Return: Edited object, or NULL if cancelled.
520 */
521 ItemFolder *addressbook_edit_folder( AddressBookFile *abf, ItemFolder *parent, ItemFolder *folder ) {
522         gchar *name = NULL;
523
524         if( folder ) {
525                 name = g_strdup( ADDRITEM_NAME(folder) );
526                 name = input_dialog( _("Edit folder"), _("Input the new name of folder:"), name );
527         }
528         else {
529                 name = input_dialog( _("New folder"),
530                                 _("Input the name of new folder:"),
531                                 _(ADDRESSBOOK_GUESS_FOLDER_NAME) );
532         }
533         if( ! name ) return NULL;
534         g_strstrip( name );
535         if( *name == '\0' ) {
536                 g_free( name );
537                 return NULL;
538         }
539         if( folder ) {
540                 if( strcmp( name, ADDRITEM_NAME(folder) ) == 0 ) {
541                         g_free( name );
542                         return NULL;
543                 }
544         }
545
546         if( ! folder ) {
547                 folder = addrbook_add_new_folder( abf, parent );
548         }
549         addritem_folder_set_name( folder, name );
550         g_free( name );
551         return folder;
552 }
553
554 /*
555 * End of Source.
556 */
557