Statistics
| Revision:

root / src / editgroup.c @ 155

History | View | Annotate | Download (16.7 kB)

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