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