1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
|
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
* Copyright (C) 2001-2002 Match Grun
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* Edit JPilot address book data.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef USE_JPILOT
#include "defs.h"
#include <glib.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtkwindow.h>
#include <gtk/gtksignal.h>
#include <gtk/gtkhbox.h>
#include <gtk/gtklabel.h>
#include <gtk/gtkentry.h>
#include <gtk/gtkhbbox.h>
#include <gtk/gtkbutton.h>
#include "intl.h"
#include "addressbook.h"
#include "prefs_common.h"
#include "addressitem.h"
#include "jpilot.h"
#include "mgutils.h"
#include "gtkutils.h"
#include "manage_window.h"
#define ADDRESSBOOK_GUESS_JPILOT "MyJPilot"
#define JPILOT_NUM_CUSTOM_LABEL 4
static struct _JPilotEdit {
GtkWidget *window;
GtkWidget *name_entry;
GtkWidget *file_entry;
GtkWidget *custom_check[JPILOT_NUM_CUSTOM_LABEL];
GtkWidget *custom_label[JPILOT_NUM_CUSTOM_LABEL];
GtkWidget *ok_btn;
GtkWidget *cancel_btn;
GtkWidget *statusbar;
gint status_cid;
} jpilotedit;
static struct _AddressFileSelection jpilot_file_selector;
/*
* Edit functions.
*/
void edit_jpilot_status_show( gchar *msg ) {
if( jpilotedit.statusbar != NULL ) {
gtk_statusbar_pop( GTK_STATUSBAR(jpilotedit.statusbar), jpilotedit.status_cid );
if( msg ) {
gtk_statusbar_push( GTK_STATUSBAR(jpilotedit.statusbar), jpilotedit.status_cid, msg );
}
}
}
static gint edit_jpilot_delete_event( GtkWidget *widget, GdkEventAny *event, gboolean *cancelled ) {
*cancelled = TRUE;
gtk_main_quit();
return TRUE;
}
static void edit_jpilot_key_pressed( GtkWidget *widget, GdkEventKey *event, gboolean *cancelled ) {
if (event && event->keyval == GDK_Escape) {
*cancelled = TRUE;
gtk_main_quit();
}
}
static void edit_jpilot_ok( GtkWidget *widget, gboolean *cancelled ) {
*cancelled = FALSE;
gtk_main_quit();
}
static void edit_jpilot_cancel( GtkWidget *widget, gboolean *cancelled ) {
*cancelled = TRUE;
gtk_main_quit();
}
static void edit_jpilot_fill_check_box( JPilotFile *jpf ) {
gint i;
GList *node, *customLbl = NULL;
gchar *labelName;
gboolean done, checked;
for( i = 0; i < JPILOT_NUM_CUSTOM_LABEL; i++ ) {
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( jpilotedit.custom_check[i] ), FALSE );
gtk_label_set_text( GTK_LABEL( jpilotedit.custom_label[i] ), "" );
}
done = FALSE;
i = 0;
customLbl = jpilot_load_custom_label( jpf, customLbl );
node = customLbl;
while( ! done ) {
if( node ) {
labelName = node->data;
gtk_label_set_text( GTK_LABEL( jpilotedit.custom_label[i] ), labelName );
checked = jpilot_test_custom_label( jpf, labelName );
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( jpilotedit.custom_check[i] ), checked );
i++;
if( i >= JPILOT_NUM_CUSTOM_LABEL ) done = TRUE;
node = g_list_next( node );
}
else {
done = TRUE;
}
}
mgu_free_dlist( customLbl );
customLbl = NULL;
}
static void edit_jpilot_fill_check_box_new() {
gint i;
for( i = 0; i < JPILOT_NUM_CUSTOM_LABEL; i++ ) {
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( jpilotedit.custom_check[i] ), FALSE );
gtk_label_set_text( GTK_LABEL( jpilotedit.custom_label[i] ), "" );
}
}
static void edit_jpilot_read_check_box( JPilotFile *pilotFile ) {
gint i;
gchar *labelName;
jpilot_clear_custom_labels( pilotFile );
for( i = 0; i < JPILOT_NUM_CUSTOM_LABEL; i++ ) {
if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(jpilotedit.custom_check[i]) ) ) {
labelName = GTK_LABEL(jpilotedit.custom_label[i])->label;
jpilot_add_custom_label( pilotFile, labelName );
}
}
}
static void edit_jpilot_file_check( void ) {
gint t = -1;
gchar *sFile;
gchar *sMsg;
gboolean flg;
flg = FALSE;
sFile = gtk_editable_get_chars( GTK_EDITABLE(jpilotedit.file_entry), 0, -1 );
if( sFile ) {
g_strchomp( sFile ); g_strchug( sFile );
if( *sFile != '\0' ) {
/* Attempt to read file */
JPilotFile *jpf = jpilot_create_path( sFile );
t = jpilot_read_data( jpf );
if( t == MGU_SUCCESS ) {
/* Set check boxes */
edit_jpilot_fill_check_box( jpf );
flg = TRUE;
}
jpilot_free( jpf );
jpf = NULL;
}
}
if( ! flg ) {
/* Clear all check boxes */
edit_jpilot_fill_check_box_new();
}
g_free( sFile );
/* Display appropriate message */
if( t == MGU_SUCCESS ) {
sMsg = "";
}
else if( t == MGU_BAD_FORMAT || t == MGU_OO_MEMORY ) {
sMsg = _("File does not appear to be JPilot format.");
}
else {
sMsg = _("Could not read file.");
}
edit_jpilot_status_show( sMsg );
}
static void edit_jpilot_file_ok( GtkWidget *widget, gpointer data ) {
gchar *sFile;
AddressFileSelection *afs;
GtkWidget *fileSel;
afs = ( AddressFileSelection * ) data;
fileSel = afs->fileSelector;
sFile = gtk_file_selection_get_filename( GTK_FILE_SELECTION(fileSel) );
afs->cancelled = FALSE;
gtk_entry_set_text( GTK_ENTRY(jpilotedit.file_entry), sFile );
gtk_widget_hide( afs->fileSelector );
gtk_grab_remove( afs->fileSelector );
edit_jpilot_file_check();
gtk_widget_grab_focus( jpilotedit.file_entry );
}
static void edit_jpilot_file_cancel( GtkWidget *widget, gpointer data ) {
AddressFileSelection *afs = ( AddressFileSelection * ) data;
afs->cancelled = TRUE;
gtk_widget_hide( afs->fileSelector );
gtk_grab_remove( afs->fileSelector );
gtk_widget_grab_focus( jpilotedit.file_entry );
}
static void edit_jpilot_file_select_create( AddressFileSelection *afs ) {
GtkWidget *fileSelector;
fileSelector = gtk_file_selection_new( _("Select JPilot File") );
gtk_file_selection_hide_fileop_buttons( GTK_FILE_SELECTION(fileSelector) );
gtk_signal_connect( GTK_OBJECT (GTK_FILE_SELECTION(fileSelector)->ok_button),
"clicked", GTK_SIGNAL_FUNC (edit_jpilot_file_ok), ( gpointer ) afs );
gtk_signal_connect( GTK_OBJECT (GTK_FILE_SELECTION(fileSelector)->cancel_button),
"clicked", GTK_SIGNAL_FUNC (edit_jpilot_file_cancel), ( gpointer ) afs );
afs->fileSelector = fileSelector;
afs->cancelled = TRUE;
}
static void edit_jpilot_file_select( void ) {
gchar *sFile;
if (! jpilot_file_selector.fileSelector )
edit_jpilot_file_select_create( & jpilot_file_selector );
sFile = gtk_editable_get_chars( GTK_EDITABLE(jpilotedit.file_entry), 0, -1 );
gtk_file_selection_set_filename( GTK_FILE_SELECTION( jpilot_file_selector.fileSelector ), sFile );
g_free( sFile );
gtk_widget_show( jpilot_file_selector.fileSelector );
gtk_grab_add( jpilot_file_selector.fileSelector );
}
static void addressbook_edit_jpilot_create( gboolean *cancelled ) {
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *table;
GtkWidget *label;
GtkWidget *name_entry;
GtkWidget *file_entry;
GtkWidget *vbox_custom;
GtkWidget *frame_custom;
GtkWidget *custom_check[JPILOT_NUM_CUSTOM_LABEL];
GtkWidget *custom_label[JPILOT_NUM_CUSTOM_LABEL];
GtkWidget *hlbox;
GtkWidget *hbbox;
GtkWidget *hsep;
GtkWidget *ok_btn;
GtkWidget *cancel_btn;
GtkWidget *check_btn;
GtkWidget *file_btn;
GtkWidget *hsbox;
GtkWidget *statusbar;
gint top, i;
window = gtk_window_new(GTK_WINDOW_DIALOG);
gtk_widget_set_usize(window, 450, -1);
gtk_container_set_border_width(GTK_CONTAINER(window), 0);
gtk_window_set_title(GTK_WINDOW(window), _("Edit JPilot Entry"));
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_modal(GTK_WINDOW(window), TRUE);
gtk_signal_connect(GTK_OBJECT(window), "delete_event",
GTK_SIGNAL_FUNC(edit_jpilot_delete_event),
cancelled);
gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
GTK_SIGNAL_FUNC(edit_jpilot_key_pressed),
cancelled);
vbox = gtk_vbox_new(FALSE, 8);
gtk_container_add(GTK_CONTAINER(window), vbox);
gtk_container_set_border_width( GTK_CONTAINER(vbox), 0 );
table = gtk_table_new(2 + JPILOT_NUM_CUSTOM_LABEL, 3, FALSE);
gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
gtk_table_set_row_spacings(GTK_TABLE(table), 8);
gtk_table_set_col_spacings(GTK_TABLE(table), 8);
/* First row */
top = 0;
label = gtk_label_new(_("Name"));
gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
name_entry = gtk_entry_new();
gtk_table_attach(GTK_TABLE(table), name_entry, 1, 2, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
check_btn = gtk_button_new_with_label( _(" Check File "));
gtk_table_attach(GTK_TABLE(table), check_btn, 2, 3, top, (top + 1), GTK_FILL, 0, 3, 0);
/* Second row */
top = 1;
label = gtk_label_new(_("File"));
gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
file_entry = gtk_entry_new();
gtk_table_attach(GTK_TABLE(table), file_entry, 1, 2, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
file_btn = gtk_button_new_with_label( _(" ... "));
gtk_table_attach(GTK_TABLE(table), file_btn, 2, 3, top, (top + 1), GTK_FILL, 0, 3, 0);
/* Third row */
top = 2;
frame_custom = gtk_frame_new(_("Additional e-Mail address item(s)"));
gtk_table_attach(GTK_TABLE(table), frame_custom, 1, 2, top, (top + JPILOT_NUM_CUSTOM_LABEL), GTK_FILL, 0, 0, 0);
/* Now do custom labels. */
vbox_custom = gtk_vbox_new (FALSE, 8);
for( i = 0; i < JPILOT_NUM_CUSTOM_LABEL; i++ ) {
hlbox = gtk_hbox_new( FALSE, 0 );
custom_check[i] = gtk_check_button_new();
custom_label[i] = gtk_label_new( "" );
gtk_box_pack_start( GTK_BOX(hlbox), custom_check[i], FALSE, FALSE, 0 );
gtk_box_pack_start( GTK_BOX(hlbox), custom_label[i], TRUE, TRUE, 0 );
gtk_box_pack_start( GTK_BOX(vbox_custom), hlbox, TRUE, TRUE, 0 );
gtk_misc_set_alignment(GTK_MISC(custom_label[i]), 0, 0.5);
top++;
}
gtk_container_add (GTK_CONTAINER (frame_custom), vbox_custom);
gtk_container_set_border_width( GTK_CONTAINER(vbox_custom), 8 );
/* Status line */
hsbox = gtk_hbox_new(FALSE, 0);
gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, BORDER_WIDTH);
statusbar = gtk_statusbar_new();
gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH);
/* Button panel */
gtkut_button_set_create(&hbbox, &ok_btn, _("OK"),
&cancel_btn, _("Cancel"), NULL, NULL);
gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
gtk_container_set_border_width( GTK_CONTAINER(hbbox), 0 );
gtk_widget_grab_default(ok_btn);
hsep = gtk_hseparator_new();
gtk_box_pack_end(GTK_BOX(vbox), hsep, FALSE, FALSE, 0);
gtk_signal_connect(GTK_OBJECT(ok_btn), "clicked",
GTK_SIGNAL_FUNC(edit_jpilot_ok), cancelled);
gtk_signal_connect(GTK_OBJECT(cancel_btn), "clicked",
GTK_SIGNAL_FUNC(edit_jpilot_cancel), cancelled);
gtk_signal_connect(GTK_OBJECT(file_btn), "clicked",
GTK_SIGNAL_FUNC(edit_jpilot_file_select), NULL);
gtk_signal_connect(GTK_OBJECT(check_btn), "clicked",
GTK_SIGNAL_FUNC(edit_jpilot_file_check), NULL);
gtk_widget_show_all(vbox);
jpilotedit.window = window;
jpilotedit.name_entry = name_entry;
jpilotedit.file_entry = file_entry;
jpilotedit.ok_btn = ok_btn;
jpilotedit.cancel_btn = cancel_btn;
jpilotedit.statusbar = statusbar;
jpilotedit.status_cid = gtk_statusbar_get_context_id( GTK_STATUSBAR(statusbar), "Edit JPilot Dialog" );
for( i = 0; i < JPILOT_NUM_CUSTOM_LABEL; i++ ) {
jpilotedit.custom_check[i] = custom_check[i];
jpilotedit.custom_label[i] = custom_label[i];
}
}
AdapterDSource *addressbook_edit_jpilot( AddressIndex *addrIndex, AdapterDSource *ads ) {
static gboolean cancelled;
gchar *sName;
gchar *sFile;
AddressDataSource *ds = NULL;
JPilotFile *jpf = NULL;
gboolean fin;
if( ! jpilotedit.window )
addressbook_edit_jpilot_create(&cancelled);
gtk_widget_grab_focus(jpilotedit.ok_btn);
gtk_widget_grab_focus(jpilotedit.name_entry);
gtk_widget_show(jpilotedit.window);
manage_window_set_transient(GTK_WINDOW(jpilotedit.window));
edit_jpilot_status_show( "" );
if( ads ) {
ds = ads->dataSource;
jpf = ds->rawDataSource;
if ( jpilot_get_name( jpf ) )
gtk_entry_set_text(GTK_ENTRY(jpilotedit.name_entry),
jpilot_get_name( jpf ) );
if (jpf->path)
gtk_entry_set_text(GTK_ENTRY(jpilotedit.file_entry), jpf->path);
gtk_window_set_title( GTK_WINDOW(jpilotedit.window), _("Edit JPilot Entry"));
edit_jpilot_fill_check_box( jpf );
}
else {
gchar *guessFile = jpilot_find_pilotdb();
gtk_entry_set_text(GTK_ENTRY(jpilotedit.name_entry), ADDRESSBOOK_GUESS_JPILOT );
gtk_entry_set_text(GTK_ENTRY(jpilotedit.file_entry), guessFile );
gtk_window_set_title( GTK_WINDOW(jpilotedit.window), _("Add New JPilot Entry"));
edit_jpilot_fill_check_box_new();
if( *guessFile != '\0' ) {
edit_jpilot_file_check();
}
}
gtk_main();
gtk_widget_hide(jpilotedit.window);
if (cancelled == TRUE) return NULL;
fin = FALSE;
sName = gtk_editable_get_chars( GTK_EDITABLE(jpilotedit.name_entry), 0, -1 );
sFile = gtk_editable_get_chars( GTK_EDITABLE(jpilotedit.file_entry), 0, -1 );
if( *sName == '\0' ) fin = TRUE;
if( *sFile == '\0' ) fin = TRUE;
if( ! fin ) {
if( ! ads ) {
jpf = jpilot_create();
ds = addrindex_index_add_datasource( addrIndex, ADDR_IF_JPILOT, jpf );
ads = addressbook_create_ds_adapter( ds, ADDR_JPILOT, NULL );
}
addressbook_ads_set_name( ads, sName );
jpilot_set_name( jpf, sName );
jpilot_set_file( jpf, sFile );
edit_jpilot_read_check_box( jpf );
}
g_free( sName );
g_free( sFile );
return ads;
}
#endif /* USE_JPILOT */
/*
* End of Source.
*/
|