Statistics
| Revision:

root / src / editgroup.c @ 1

History | View | Annotate | Download (16.7 KB)

1
/*
2
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3
 * Copyright (C) 1999-2002 Hiroyuki Yamamoto
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
 */
19

    
20
#ifdef HAVE_CONFIG_H
21
#  include "config.h"
22
#endif
23

    
24
#include "defs.h"
25

    
26
#include <glib.h>
27
#include <gdk/gdkkeysyms.h>
28

    
29
#include "intl.h"
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
        gint rowIndGroup;
74
        gint rowIndAvail;
75

    
76
} groupeditdlg;
77

    
78

    
79
static gchar *_edit_group_dfl_message_ = NULL;
80

    
81
static void edit_group_status_show( gchar *msg ) {
82
        if( groupeditdlg.statusbar != NULL ) {
83
                gtk_statusbar_pop( GTK_STATUSBAR(groupeditdlg.statusbar), groupeditdlg.status_cid );
84
                if( msg ) {
85
                        gtk_statusbar_push( GTK_STATUSBAR(groupeditdlg.statusbar), groupeditdlg.status_cid, msg );
86
                }
87
        }
88
}
89

    
90
static void edit_group_ok(GtkWidget *widget, gboolean *cancelled) {
91
        gchar *sName;
92
        gboolean errFlag = TRUE;
93

    
94
        sName = gtk_editable_get_chars( GTK_EDITABLE(groupeditdlg.entry_name), 0, -1 );
95
        if( sName ) {
96
                g_strstrip( sName );
97
                if( *sName != '\0' ) {
98
                        gtk_entry_set_text(GTK_ENTRY(groupeditdlg.entry_name), sName );
99
                        *cancelled = FALSE;
100
                        gtk_main_quit();
101
                        errFlag = FALSE;
102
                }
103
        }
104
        if( errFlag ) {
105
                edit_group_status_show( _( "A Group Name must be supplied." ) );
106
        }
107
        g_free( sName );
108
}
109
        
110
static void edit_group_cancel(GtkWidget *widget, gboolean *cancelled) {
111
        *cancelled = TRUE;
112
        gtk_main_quit();
113
}
114

    
115
static gint edit_group_delete_event(GtkWidget *widget, GdkEventAny *event, gboolean *cancelled) {
116
        *cancelled = TRUE;
117
        gtk_main_quit();
118
        return TRUE;
119
}
120

    
121
static gboolean edit_group_key_pressed(GtkWidget *widget, GdkEventKey *event, gboolean *cancelled) {
122
        if (event && event->keyval == GDK_Escape) {
123
                *cancelled = TRUE;
124
                gtk_main_quit();
125
        }
126
        return FALSE;
127
}
128

    
129
static gchar *edit_group_format_item_clist( ItemPerson *person, ItemEMail *email ) {
130
        gchar *str = NULL;
131
        gchar *aName = ADDRITEM_NAME(email);
132
        if( aName == NULL || *aName == '\0' ) return str;
133
        if( person ) {
134
                str = g_strdup_printf( "%s - %s", ADDRITEM_NAME(person), aName );
135
        }
136
        else {
137
                str = g_strdup( aName );
138
        }
139
        return str;
140
}
141

    
142
static gint edit_group_clist_add_email( GtkCList *clist, ItemEMail *email ) {
143
        ItemPerson *person = ( ItemPerson * ) ADDRITEM_PARENT(email);
144
        gchar *str = edit_group_format_item_clist( person, email );
145
        gchar *text[ GROUP_N_COLS ];
146
        gint row;
147
        if( str ) {
148
                text[ GROUP_COL_NAME ] = str;
149
        }
150
        else {
151
                text[ GROUP_COL_NAME ] = ADDRITEM_NAME(person);
152
        }
153
        text[ GROUP_COL_EMAIL   ] = email->address;
154
        text[ GROUP_COL_REMARKS ] = email->remarks;
155
        row = gtk_clist_append( clist, text );
156
        gtk_clist_set_row_data( clist, row, email );
157
        return row;
158
}
159

    
160
static void edit_group_load_clist( GtkCList *clist, GList *listEMail ) {
161
        GList *node = listEMail;
162
        while( node ) {
163
                ItemEMail *email = node->data;
164
                edit_group_clist_add_email( clist, email );
165
                node = g_list_next( node );
166
        }
167
}
168

    
169
static void edit_group_group_selected( GtkCList *clist, gint row, gint column, GdkEvent *event, gpointer data ) {
170
        groupeditdlg.rowIndGroup = row;
171
}
172

    
173
static void edit_group_avail_selected( GtkCList *clist, gint row, gint column, GdkEvent *event, gpointer data ) {
174
        groupeditdlg.rowIndAvail = row;
175
}
176

    
177
static gint edit_group_move_email( GtkCList *clist_from, GtkCList *clist_to, gint row ) {
178
        ItemEMail *email = gtk_clist_get_row_data( clist_from, row );
179
        gint rrow = -1;
180
        if( email ) {
181
                gtk_clist_remove( clist_from, row );
182
                rrow = edit_group_clist_add_email( clist_to, email );
183
                gtk_clist_select_row( clist_to, rrow, 0 );
184
        }
185
        return rrow;
186
}
187

    
188
static void edit_group_to_group( GtkWidget *widget, gpointer data ) {
189
        groupeditdlg.rowIndGroup = edit_group_move_email( groupeditdlg.clist_avail,
190
                                        groupeditdlg.clist_group, groupeditdlg.rowIndAvail );
191
}
192

    
193
static void edit_group_to_avail( GtkWidget *widget, gpointer data ) {
194
        groupeditdlg.rowIndAvail = edit_group_move_email( groupeditdlg.clist_group,
195
                                        groupeditdlg.clist_avail, groupeditdlg.rowIndGroup );
196
}
197

    
198
static gboolean edit_group_list_group_button( GtkCList *clist, GdkEventButton *event, gpointer data ) {
199
        if( ! event ) return FALSE;
200
        if( event->button == 1 ) {
201
                if( event->type == GDK_2BUTTON_PRESS ) {
202
                        edit_group_to_avail( NULL, NULL );
203
                }
204
        }
205
        return FALSE;
206
}
207

    
208
static gboolean edit_group_list_avail_button( GtkCList *clist, GdkEventButton *event, gpointer data ) {
209
        if( ! event ) return FALSE;
210
        if( event->button == 1 ) {
211
                if( event->type == GDK_2BUTTON_PRESS ) {
212
                        edit_group_to_group( NULL, NULL );
213
                }
214
        }
215
        return FALSE;
216
}
217

    
218
static gint edit_group_list_compare_func( GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2 ) {
219
        GtkCell *cell1 = ((GtkCListRow *)ptr1)->cell;
220
        GtkCell *cell2 = ((GtkCListRow *)ptr2)->cell;
221
        gchar *name1 = NULL, *name2 = NULL;
222
        if( cell1 ) name1 = cell1->u.text;
223
        if( cell2 ) name2 = cell2->u.text;
224
        if( ! name1 ) return ( name2 != NULL );
225
        if( ! name2 ) return -1;
226
        return strcasecmp( name1, name2 );
227
}
228

    
229
static void addressbook_edit_group_create( gboolean *cancelled ) {
230
        GtkWidget *window;
231
        GtkWidget *vbox;
232
        GtkWidget *hbbox;
233
        GtkWidget *ok_btn;
234
        GtkWidget *cancel_btn;
235
        GtkWidget *hsbox;
236
        GtkWidget *statusbar;
237

    
238
        GtkWidget *hboxg;
239
        GtkWidget *table;
240
        GtkWidget *label;
241
        GtkWidget *entry_name;
242
        GtkWidget *hboxl;
243
        GtkWidget *vboxl;
244
        GtkWidget *hboxh;
245

    
246
        GtkWidget *clist_swin;
247
        GtkWidget *clist_group;
248
        GtkWidget *clist_avail;
249

    
250
        GtkWidget *buttonGroup;
251
        GtkWidget *buttonAvail;
252
        gint top;
253

    
254
        gchar *titles[ GROUP_N_COLS ];
255
        gint i;
256

    
257
        titles[ GROUP_COL_NAME    ] = _( "Name" );
258
        titles[ GROUP_COL_EMAIL   ] = _("E-Mail Address");
259
        titles[ GROUP_COL_REMARKS ] = _("Remarks");
260

    
261
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
262
        gtk_widget_set_size_request(window, EDITGROUP_WIDTH, EDITGROUP_HEIGHT );
263
        gtk_container_set_border_width(GTK_CONTAINER(window), 0);
264
        gtk_window_set_title(GTK_WINDOW(window), _("Edit Group Data"));
265
        gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
266
        gtk_window_set_modal(GTK_WINDOW(window), TRUE);        
267
        g_signal_connect(G_OBJECT(window), "delete_event",
268
                         G_CALLBACK(edit_group_delete_event),
269
                         cancelled);
270
        g_signal_connect(G_OBJECT(window), "key_press_event",
271
                         G_CALLBACK(edit_group_key_pressed),
272
                         cancelled);
273

    
274
        vbox = gtk_vbox_new( FALSE, 6 );
275
        gtk_container_set_border_width(GTK_CONTAINER(vbox), BORDER_WIDTH);
276
        gtk_widget_show( vbox );
277
        gtk_container_add( GTK_CONTAINER( window ), vbox );
278

    
279
        /* Group area */
280
        hboxg = gtk_hbox_new( FALSE, 0 );
281
        gtk_box_pack_start(GTK_BOX(vbox), hboxg, FALSE, FALSE, 0);
282

    
283
        /* Data entry area */
284
        table = gtk_table_new( 1, 3, FALSE);
285
        gtk_box_pack_start(GTK_BOX(hboxg), table, TRUE, TRUE, 0);
286
        gtk_container_set_border_width( GTK_CONTAINER(table), 4 );
287
        gtk_table_set_row_spacings(GTK_TABLE(table), 0);
288
        gtk_table_set_col_spacings(GTK_TABLE(table), 4);
289

    
290
        /* First row */
291
        top = 0;
292
        label = gtk_label_new(_("Group Name"));
293
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
294
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
295

    
296
        entry_name = gtk_entry_new();
297
        gtk_table_attach(GTK_TABLE(table), entry_name, 1, 2, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
298

    
299
        /* List area */
300
        hboxl = gtk_hbox_new( FALSE, 6 );
301
        gtk_container_set_border_width( GTK_CONTAINER(hboxl), 8 );
302
        gtk_box_pack_start(GTK_BOX(vbox), hboxl, TRUE, TRUE, 0);
303

    
304
        /* Group list */
305
        vboxl = gtk_vbox_new( FALSE, 0 );
306
        gtk_box_pack_start(GTK_BOX(hboxl), vboxl, TRUE, TRUE, 0);
307

    
308
        hboxh = gtk_hbox_new( FALSE, 0 );
309
        gtk_container_set_border_width( GTK_CONTAINER(hboxh), 4 );
310
        gtk_box_pack_start(GTK_BOX(vboxl), hboxh, FALSE, FALSE, 0);
311
        label = gtk_label_new(_("Addresses in Group"));
312
        gtk_box_pack_start(GTK_BOX(hboxh), label, TRUE, TRUE, 0);
313
        buttonAvail = gtk_button_new_with_label( _( " -> " ) );
314
        gtk_box_pack_end(GTK_BOX(hboxh), buttonAvail, FALSE, FALSE, 0);
315

    
316
        clist_swin = gtk_scrolled_window_new( NULL, NULL );
317
        gtk_box_pack_start(GTK_BOX(vboxl), clist_swin, TRUE, TRUE, 0);
318
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(clist_swin),
319
                                       GTK_POLICY_AUTOMATIC,
320
                                       GTK_POLICY_ALWAYS);
321

    
322
        clist_group = gtk_clist_new_with_titles( GROUP_N_COLS, titles );
323
        gtk_container_add( GTK_CONTAINER(clist_swin), clist_group );
324
        gtk_clist_set_selection_mode( GTK_CLIST(clist_group), GTK_SELECTION_BROWSE );
325
        gtk_clist_set_column_width( GTK_CLIST(clist_group), GROUP_COL_NAME, GROUP_COL_WIDTH_NAME );
326
        gtk_clist_set_column_width( GTK_CLIST(clist_group), GROUP_COL_EMAIL, GROUP_COL_WIDTH_EMAIL );
327
        gtk_clist_set_compare_func( GTK_CLIST(clist_group), edit_group_list_compare_func );
328
        gtk_clist_set_auto_sort( GTK_CLIST(clist_group), TRUE );
329

    
330
        for( i = 0; i < GROUP_N_COLS; i++ )
331
                GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(clist_group)->column[i].button, GTK_CAN_FOCUS);
332

    
333
        /* Available list */
334
        vboxl = gtk_vbox_new( FALSE, 0 );
335
        gtk_box_pack_start(GTK_BOX(hboxl), vboxl, TRUE, TRUE, 0);
336

    
337
        hboxh = gtk_hbox_new( FALSE, 0 );
338
        gtk_container_set_border_width( GTK_CONTAINER(hboxh), 4 );
339
        gtk_box_pack_start(GTK_BOX(vboxl), hboxh, FALSE, FALSE, 0);
340
        buttonGroup = gtk_button_new_with_label( _( " <- " ) );
341
        gtk_box_pack_start(GTK_BOX(hboxh), buttonGroup, FALSE, FALSE, 0);
342
        label = gtk_label_new(_("Available Addresses"));
343
        gtk_box_pack_end(GTK_BOX(hboxh), label, TRUE, TRUE, 0);
344

    
345
        clist_swin = gtk_scrolled_window_new( NULL, NULL );
346
        gtk_box_pack_start(GTK_BOX(vboxl), clist_swin, TRUE, TRUE, 0);
347
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(clist_swin),
348
                                       GTK_POLICY_AUTOMATIC,
349
                                       GTK_POLICY_ALWAYS);
350

    
351
        clist_avail = gtk_clist_new_with_titles( GROUP_N_COLS, titles );
352
        gtk_container_add( GTK_CONTAINER(clist_swin), clist_avail );
353
        gtk_clist_set_selection_mode( GTK_CLIST(clist_avail), GTK_SELECTION_BROWSE );
354
        gtk_clist_set_column_width( GTK_CLIST(clist_avail), GROUP_COL_NAME, GROUP_COL_WIDTH_NAME );
355
        gtk_clist_set_column_width( GTK_CLIST(clist_avail), GROUP_COL_EMAIL, GROUP_COL_WIDTH_EMAIL );
356
        gtk_clist_set_compare_func( GTK_CLIST(clist_avail), edit_group_list_compare_func );
357
        gtk_clist_set_auto_sort( GTK_CLIST(clist_avail), TRUE );
358

    
359
        for( i = 0; i < GROUP_N_COLS; i++ )
360
                GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(clist_avail)->column[i].button, GTK_CAN_FOCUS);
361

    
362
        /* Status line */
363
        hsbox = gtk_hbox_new(FALSE, 0);
364
        gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, BORDER_WIDTH);
365
        statusbar = gtk_statusbar_new();
366
        gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH);
367

    
368
        /* Button panel */
369
        gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
370
                                &cancel_btn, _("Cancel"), NULL, NULL);
371
        gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
372
        gtk_widget_grab_default(ok_btn);
373

    
374
        g_signal_connect(G_OBJECT(ok_btn), "clicked",
375
                         G_CALLBACK(edit_group_ok), cancelled);
376
        g_signal_connect(G_OBJECT(cancel_btn), "clicked",
377
                         G_CALLBACK(edit_group_cancel), cancelled);
378

    
379
        gtk_widget_show_all(vbox);
380

    
381
        /* Event handlers */
382
        g_signal_connect(G_OBJECT(clist_group), "select_row",
383
                         G_CALLBACK( edit_group_group_selected), NULL);
384
        g_signal_connect(G_OBJECT(clist_avail), "select_row",
385
                         G_CALLBACK( edit_group_avail_selected), NULL);
386
        g_signal_connect(G_OBJECT(buttonGroup), "clicked",
387
                         G_CALLBACK( edit_group_to_group ), NULL);
388
        g_signal_connect(G_OBJECT(buttonAvail), "clicked",
389
                         G_CALLBACK( edit_group_to_avail ), NULL);
390
        g_signal_connect(G_OBJECT(clist_avail), "button_press_event",
391
                         G_CALLBACK(edit_group_list_avail_button), NULL);
392
        g_signal_connect(G_OBJECT(clist_group), "button_press_event",
393
                         G_CALLBACK(edit_group_list_group_button), NULL);
394

    
395
        groupeditdlg.window     = window;
396
        groupeditdlg.ok_btn     = ok_btn;
397
        groupeditdlg.cancel_btn = cancel_btn;
398
        groupeditdlg.statusbar  = statusbar;
399
        groupeditdlg.status_cid = gtk_statusbar_get_context_id( GTK_STATUSBAR(statusbar), "Edit Group Dialog" );
400

    
401
        groupeditdlg.entry_name  = entry_name;
402
        groupeditdlg.clist_group = GTK_CLIST( clist_group );
403
        groupeditdlg.clist_avail = GTK_CLIST( clist_avail );
404

    
405
        if( ! _edit_group_dfl_message_ ) {
406
                _edit_group_dfl_message_ = _( "Move E-Mail Addresses to or from Group with arrow buttons" );
407
        }
408
}
409

    
410
/*
411
* Return list of email items.
412
*/
413
static GList *edit_group_build_email_list() {
414
        GtkCList *clist = GTK_CLIST(groupeditdlg.clist_group);
415
        GList *listEMail = NULL;
416
        ItemEMail *email;
417
        gint row = 0;
418
        while( (email = gtk_clist_get_row_data( clist, row )) ) {
419
                listEMail = g_list_append( listEMail, email );
420
                row++;
421
        }
422
        return listEMail;
423
}
424

    
425
/*
426
* Edit group.
427
* Enter: abf    Address book.
428
*        folder Parent folder for group (or NULL if adding to root folder). Argument is
429
*               only required for new objects).
430
*        group  Group to edit, or NULL for a new group object.
431
* Return: Edited object, or NULL if cancelled.
432
*/
433
ItemGroup *addressbook_edit_group( AddressBookFile *abf, ItemFolder *parent, ItemGroup *group ) {
434
        static gboolean cancelled;
435
        GList *listEMail = NULL;
436
        gchar *name;
437

    
438
        if (!groupeditdlg.window)
439
                addressbook_edit_group_create(&cancelled);
440
        gtk_widget_grab_focus(groupeditdlg.ok_btn);
441
        gtk_widget_grab_focus(groupeditdlg.entry_name);
442
        gtk_widget_show(groupeditdlg.window);
443
        manage_window_set_transient(GTK_WINDOW(groupeditdlg.window));
444

    
445
        /* Clear all fields */
446
        groupeditdlg.rowIndGroup = -1;
447
        groupeditdlg.rowIndAvail = -1;
448
        edit_group_status_show( "" );
449
        gtk_clist_clear( GTK_CLIST(groupeditdlg.clist_group) );
450
        gtk_clist_clear( GTK_CLIST(groupeditdlg.clist_avail) );
451

    
452
        if( group ) {
453
                if( ADDRITEM_NAME(group) )
454
                        gtk_entry_set_text(GTK_ENTRY(groupeditdlg.entry_name), ADDRITEM_NAME(group) );
455
                edit_group_load_clist( groupeditdlg.clist_group, group->listEMail );
456
                gtk_window_set_title( GTK_WINDOW(groupeditdlg.window), _("Edit Group Details"));
457
        }
458
        else {
459
                gtk_window_set_title( GTK_WINDOW(groupeditdlg.window), _("Add New Group"));
460
                gtk_entry_set_text(GTK_ENTRY(groupeditdlg.entry_name), ADDRESSBOOK_GUESS_GROUP_NAME );
461
        }
462

    
463
        listEMail = addrbook_get_available_email_list( abf, group );
464
        edit_group_load_clist( groupeditdlg.clist_avail, listEMail );
465
        mgu_clear_list( listEMail );
466
        listEMail = NULL;
467
        gtk_clist_select_row( groupeditdlg.clist_group, 0, 0 );
468
        gtk_clist_select_row( groupeditdlg.clist_avail, 0, 0 );
469

    
470
        edit_group_status_show( _edit_group_dfl_message_ );
471

    
472
        gtk_main();
473
        gtk_widget_hide( groupeditdlg.window );
474

    
475
        if( cancelled ) {
476
                return NULL;
477
        }
478

    
479
        listEMail = edit_group_build_email_list();
480
        if( group ) {
481
                /* Update email list */
482
                addrbook_update_group_list( abf, group, listEMail );
483
        }
484
        else {
485
                /* Create new person and email list */
486
                group = addrbook_add_group_list( abf, parent, listEMail );
487
        }
488
        name = gtk_editable_get_chars( GTK_EDITABLE(groupeditdlg.entry_name), 0, -1 );
489
        addritem_group_set_name( group, name );
490
        g_free( name );
491

    
492
        listEMail = NULL;
493
        return group;
494
}
495

    
496
/*
497
* Edit folder.
498
* Enter: abf    Address book.
499
*        parent Parent folder for folder (or NULL if adding to root folder). Argument is
500
*               only required for new objects).
501
*        folder        Folder to edit, or NULL for a new folder object.
502
* Return: Edited object, or NULL if cancelled.
503
*/
504
ItemFolder *addressbook_edit_folder( AddressBookFile *abf, ItemFolder *parent, ItemFolder *folder ) {
505
        gchar *name = NULL;
506

    
507
        if( folder ) {
508
                name = g_strdup( ADDRITEM_NAME(folder) );
509
                name = input_dialog( _("Edit folder"), _("Input the new name of folder:"), name );
510
        }
511
        else {
512
                name = input_dialog( _("New folder"),
513
                                _("Input the name of new folder:"),
514
                                _(ADDRESSBOOK_GUESS_FOLDER_NAME) );
515
        }
516
        if( ! name ) return NULL;
517
        g_strstrip( name );
518
        if( *name == '\0' ) {
519
                g_free( name );
520
                return NULL;
521
        }
522
        if( folder ) {
523
                if( strcasecmp( name, ADDRITEM_NAME(folder) ) == 0 ) {
524
                        g_free( name );
525
                        return NULL;
526
                }
527
        }
528

    
529
        if( ! folder ) {
530
                folder = addrbook_add_new_folder( abf, parent );
531
        }
532
        addritem_folder_set_name( folder, name );
533
        g_free( name );
534
        return folder;
535
}
536

    
537
/*
538
* End of Source.
539
*/
540