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