2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 2001-2006 Match Grun and the Sylpheed-Claws team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * Import LDIF address book data.
31 #include <glib/gi18n.h>
32 #include <gdk/gdkkeysyms.h>
33 #include <gtk/gtkwindow.h>
34 #include <gtk/gtksignal.h>
35 #include <gtk/gtklabel.h>
36 #include <gtk/gtkentry.h>
37 #include <gtk/gtktable.h>
38 #include <gtk/gtkbutton.h>
41 #include "addressbook.h"
42 #include "addressitem.h"
44 #include "stock_pixmap.h"
45 #include "prefs_common.h"
46 #include "manage_window.h"
52 #define IMPORTLDIF_GUESS_NAME "LDIF Import"
54 #define PAGE_FILE_INFO 0
55 #define PAGE_ATTRIBUTES 1
58 #define IMPORTLDIF_WIDTH 390
59 #define IMPORTLDIF_HEIGHT 300
61 #define FIELDS_N_COLS 4
62 #define FIELDS_COL_WIDTH_RESERVED 10
63 #define FIELDS_COL_WIDTH_SELECT 10
64 #define FIELDS_COL_WIDTH_FIELD 140
65 #define FIELDS_COL_WIDTH_ATTRIB 140
68 FIELD_COL_RESERVED = 0,
72 } ImpLdif_FieldColPos;
75 * LDIF dialog definition.
77 static struct _ImpLdif_Dlg {
82 GtkWidget *clist_field;
83 GtkWidget *entryField;
84 GtkWidget *entryAttrib;
85 GtkWidget *checkSelect;
89 GtkWidget *labelRecords;
102 static struct _AddressFileSelection _imp_ldif_file_selector_;
103 static AddressBookFile *_importedBook_;
104 static AddressIndex *_imp_addressIndex_;
105 static LdifFile *_ldifFile_ = NULL;
107 static GdkPixmap *markxpm;
108 static GdkBitmap *markxpmmask;
111 * Structure of error message table.
113 typedef struct _ErrMsgTableEntry ErrMsgTableEntry;
114 struct _ErrMsgTableEntry {
119 static gchar *_errMsgUnknown_ = N_( "Unknown" );
122 * Lookup table of error messages for general errors. Note that a NULL
123 * description signifies the end of the table.
125 static ErrMsgTableEntry _lutErrorsLDIF_[] = {
126 { MGU_SUCCESS, N_("Success") },
127 { MGU_BAD_ARGS, N_("Bad arguments") },
128 { MGU_NO_FILE, N_("File not specified") },
129 { MGU_OPEN_FILE, N_("Error opening file") },
130 { MGU_ERROR_READ, N_("Error reading file") },
131 { MGU_EOF, N_("End of file encountered") },
132 { MGU_OO_MEMORY, N_("Error allocating memory") },
133 { MGU_BAD_FORMAT, N_("Bad file format") },
134 { MGU_ERROR_WRITE, N_("Error writing to file") },
135 { MGU_OPEN_DIRECTORY, N_("Error opening directory") },
136 { MGU_NO_PATH, N_("No path specified") },
141 * Lookup message for specified error code.
142 * \param lut Lookup table.
143 * \param code Code to lookup.
144 * \return Description associated to code.
146 static gchar *imp_ldif_err2string( ErrMsgTableEntry lut[], gint code ) {
148 ErrMsgTableEntry entry;
151 for( i = 0; ; i++ ) {
153 if( entry.description == NULL ) break;
154 if( entry.code == code ) {
155 desc = entry.description;
160 desc = _errMsgUnknown_;
166 * Display message in status field.
167 * \param msg Message to display.
169 static void imp_ldif_status_show( gchar *msg ) {
170 if( impldif_dlg.statusbar != NULL ) {
171 gtk_statusbar_pop( GTK_STATUSBAR(impldif_dlg.statusbar),
172 impldif_dlg.status_cid );
175 GTK_STATUSBAR(impldif_dlg.statusbar),
176 impldif_dlg.status_cid, msg );
182 * Select and display status message appropriate for the page being displayed.
184 static void imp_ldif_message( void ) {
188 pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(impldif_dlg.notebook) );
189 if( pageNum == PAGE_FILE_INFO ) {
190 sMsg = _( "Please specify address book name and file to import." );
192 else if( pageNum == PAGE_ATTRIBUTES ) {
193 sMsg = _( "Select and rename LDIF field names to import." );
195 else if( pageNum == PAGE_FINISH ) {
196 sMsg = _( "File imported." );
198 imp_ldif_status_show( sMsg );
202 * Update list with data for current row.
203 * \param clist List to update.
205 static void imp_ldif_update_row( GtkCList *clist ) {
207 gchar *text[ FIELDS_N_COLS ];
210 if( impldif_dlg.rowIndSelect < 0 ) return;
211 row = impldif_dlg.rowIndSelect;
213 rec = gtk_clist_get_row_data( clist, row );
214 text[ FIELD_COL_RESERVED ] = "";
215 text[ FIELD_COL_SELECT ] = "";
216 text[ FIELD_COL_FIELD ] = rec->tagName;
217 text[ FIELD_COL_ATTRIB ] = rec->userName;
219 gtk_clist_freeze( clist );
220 gtk_clist_remove( clist, row );
221 if( row == impldif_dlg.rowCount - 1 ) {
222 gtk_clist_append( clist, text );
225 gtk_clist_insert( clist, row, text );
227 if( rec->selected ) {
228 gtk_clist_set_pixmap(
229 clist, row, FIELD_COL_SELECT, markxpm, markxpmmask );
231 if( rec->reserved ) {
232 gtk_clist_set_pixmap(
233 clist, row, FIELD_COL_RESERVED, markxpm, markxpmmask );
236 gtk_clist_set_row_data( clist, row, rec );
237 gtk_clist_thaw( clist );
241 * Load list with LDIF fields read from file.
242 * \param ldf LDIF control data.
244 static void imp_ldif_load_fields( LdifFile *ldf ) {
245 GtkCList *clist = GTK_CLIST(impldif_dlg.clist_field);
247 gchar *text[ FIELDS_N_COLS ];
249 impldif_dlg.rowIndSelect = -1;
250 impldif_dlg.rowCount = 0;
251 if( ! ldf->accessFlag ) return;
252 gtk_clist_clear( clist );
253 list = ldif_get_fieldlist( ldf );
256 Ldif_FieldRec *rec = node->data;
259 text[ FIELD_COL_RESERVED ] = "";
260 text[ FIELD_COL_SELECT ] = "";
261 text[ FIELD_COL_FIELD ] = rec->tagName;
262 text[ FIELD_COL_ATTRIB ] = rec->userName;
263 row = gtk_clist_append( clist, text );
264 gtk_clist_set_row_data( clist, row, rec );
265 if( rec->selected ) {
266 gtk_clist_set_pixmap( clist, row,
267 FIELD_COL_SELECT, markxpm, markxpmmask );
269 if( rec->reserved ) {
270 gtk_clist_set_pixmap( clist, row,
271 FIELD_COL_RESERVED, markxpm, markxpmmask );
273 impldif_dlg.rowCount++;
274 node = g_list_next( node );
278 ldif_set_accessed( ldf, FALSE );
282 * Callback function when list iterm selected.
283 * \param clist List widget.
286 * \param event Event object.
287 * \param data User data.
289 static void imp_ldif_field_list_selected(
290 GtkCList *clist, gint row, gint column, GdkEvent *event,
293 Ldif_FieldRec *rec = gtk_clist_get_row_data( clist, row );
295 impldif_dlg.rowIndSelect = row;
296 gtk_entry_set_text( GTK_ENTRY(impldif_dlg.entryAttrib), "" );
298 /* Update widget contents */
300 GTK_LABEL(impldif_dlg.entryField), rec->tagName );
303 GTK_ENTRY(impldif_dlg.entryAttrib), rec->userName );
304 gtk_toggle_button_set_active(
305 GTK_TOGGLE_BUTTON( impldif_dlg.checkSelect),
308 /* Disable widgets for reserved fields */
309 gtk_widget_set_sensitive(
310 impldif_dlg.entryAttrib, ! rec->reserved );
311 gtk_widget_set_sensitive(
312 impldif_dlg.checkSelect, ! rec->reserved );
313 gtk_widget_set_sensitive(
314 impldif_dlg.btnModify, ! rec->reserved );
316 gtk_widget_grab_focus(impldif_dlg.entryAttrib);
320 * Callback function to toggle selected LDIF field.
321 * \param clist List to update.
322 * \param event Event object.
325 static gboolean imp_ldif_field_list_toggle(
326 GtkCList *clist, GdkEventButton *event, gpointer data )
329 gboolean toggle = FALSE;
331 if( ! event ) return FALSE;
332 if( impldif_dlg.rowIndSelect < 0 ) return FALSE;
333 if( event->button == 1 ) {
334 /* If single click in select column */
335 if( event->type == GDK_BUTTON_PRESS ) {
340 gtk_clist_get_selection_info( clist, x, y, &row, &col );
341 if( col != FIELD_COL_SELECT ) return FALSE;
342 if( row > impldif_dlg.rowCount ) return FALSE;
345 impldif_dlg.rowIndSelect = row;
349 /* If double click anywhere in row */
350 else if( event->type == GDK_2BUTTON_PRESS ) {
354 /* Toggle field selection */
356 rec = gtk_clist_get_row_data(
357 clist, impldif_dlg.rowIndSelect );
359 ldif_field_toggle( rec );
360 imp_ldif_update_row( clist );
367 * Callback function to update LDIF field data from input fields.
368 * \param widget Widget (button).
369 * \param data User data.
371 static void imp_ldif_modify_pressed( GtkWidget *widget, gpointer data ) {
372 GtkCList *clist = GTK_CLIST(impldif_dlg.clist_field);
376 if( impldif_dlg.rowIndSelect < 0 ) return;
377 row = impldif_dlg.rowIndSelect;
378 rec = gtk_clist_get_row_data( clist, impldif_dlg.rowIndSelect );
380 ldif_field_set_name( rec, gtk_editable_get_chars(
381 GTK_EDITABLE(impldif_dlg.entryAttrib), 0, -1 ) );
382 ldif_field_set_selected( rec, gtk_toggle_button_get_active(
383 GTK_TOGGLE_BUTTON( impldif_dlg.checkSelect) ) );
384 imp_ldif_update_row( clist );
385 gtk_clist_select_row( clist, row, 0 );
386 gtk_label_set_text( GTK_LABEL(impldif_dlg.entryField), "" );
387 gtk_entry_set_text( GTK_ENTRY(impldif_dlg.entryAttrib), "" );
388 gtk_toggle_button_set_active(
389 GTK_TOGGLE_BUTTON( impldif_dlg.checkSelect), FALSE );
393 * Test whether we can move off fields page.
394 * \return <i>TRUE</i> if OK to move off page.
396 static gboolean imp_ldif_field_move() {
397 gboolean retVal = FALSE;
399 AddressBookFile *abf = NULL;
401 if( _importedBook_ ) {
402 addrbook_free_book( _importedBook_ );
405 abf = addrbook_create_book();
406 addrbook_set_path( abf, _imp_addressIndex_->filePath );
407 addrbook_set_name( abf, impldif_dlg.nameBook );
408 newFile = addrbook_guess_next_file( abf );
409 addrbook_set_file( abf, newFile );
412 /* Import data into file */
413 if( ldif_import_data( _ldifFile_, abf->addressCache ) == MGU_SUCCESS ) {
414 addrbook_save_data( abf );
415 _importedBook_ = abf;
419 addrbook_free_book( abf );
426 * Test whether we can move off file page.
427 * \return <i>TRUE</i> if OK to move off page.
429 static gboolean imp_ldif_file_move() {
430 gboolean retVal = FALSE;
434 gboolean errFlag = FALSE;
436 sFile = gtk_editable_get_chars( GTK_EDITABLE(impldif_dlg.entryFile), 0, -1 );
437 g_strchug( sFile ); g_strchomp( sFile );
439 sName = gtk_editable_get_chars( GTK_EDITABLE(impldif_dlg.entryName), 0, -1 );
440 g_strchug( sName ); g_strchomp( sName );
442 g_free( impldif_dlg.nameBook );
443 g_free( impldif_dlg.fileName );
444 impldif_dlg.nameBook = sName;
445 impldif_dlg.fileName = sFile;
447 gtk_entry_set_text( GTK_ENTRY(impldif_dlg.entryFile), sFile );
448 gtk_entry_set_text( GTK_ENTRY(impldif_dlg.entryName), sName );
450 if( *sFile == '\0'|| strlen( sFile ) < 1 ) {
451 sMsg = _( "Please select a file." );
452 gtk_widget_grab_focus(impldif_dlg.entryFile);
456 if( *sName == '\0'|| strlen( sName ) < 1 ) {
457 if( ! errFlag ) sMsg = _( "Address book name must be supplied." );
458 gtk_widget_grab_focus(impldif_dlg.entryName);
463 /* Read attribute list */
464 ldif_set_file( _ldifFile_, sFile );
465 if( ldif_read_tags( _ldifFile_ ) == MGU_SUCCESS ) {
467 /* ldif_print_file( _ldifFile_, stdout ); */
468 imp_ldif_load_fields( _ldifFile_ );
472 sMsg = _( "Error reading LDIF fields." );
475 imp_ldif_status_show( sMsg );
481 * Display finish page.
483 static void imp_ldif_finish_show() {
487 name = gtk_editable_get_chars( GTK_EDITABLE(impldif_dlg.entryName), 0, -1 );
488 gtk_label_set_text( GTK_LABEL(impldif_dlg.labelBook), name );
490 gtk_label_set_text( GTK_LABEL(impldif_dlg.labelFile), _ldifFile_->path );
491 gtk_label_set_text( GTK_LABEL(impldif_dlg.labelRecords), itos( _ldifFile_->importCount ) );
492 gtk_widget_set_sensitive( impldif_dlg.btnPrev, FALSE );
493 gtk_widget_set_sensitive( impldif_dlg.btnNext, FALSE );
494 if( _ldifFile_->retVal == MGU_SUCCESS ) {
495 sMsg = _( "LDIF file imported successfully." );
498 sMsg = imp_ldif_err2string( _lutErrorsLDIF_, _ldifFile_->retVal );
500 imp_ldif_status_show( sMsg );
501 gtk_widget_grab_focus(impldif_dlg.btnCancel);
505 * Callback function to select previous page.
506 * \param widget Widget (button).
508 static void imp_ldif_prev( GtkWidget *widget ) {
511 pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(impldif_dlg.notebook) );
512 if( pageNum == PAGE_ATTRIBUTES ) {
513 /* Goto file page stuff */
514 gtk_notebook_set_current_page(
515 GTK_NOTEBOOK(impldif_dlg.notebook), PAGE_FILE_INFO );
516 gtk_widget_set_sensitive( impldif_dlg.btnPrev, FALSE );
522 * Callback function to select next page.
523 * \param widget Widget (button).
525 static void imp_ldif_next( GtkWidget *widget ) {
528 pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(impldif_dlg.notebook) );
529 if( pageNum == PAGE_FILE_INFO ) {
530 /* Goto attributes stuff */
531 if( imp_ldif_file_move() ) {
532 gtk_notebook_set_current_page(
533 GTK_NOTEBOOK(impldif_dlg.notebook), PAGE_ATTRIBUTES );
535 gtk_widget_set_sensitive( impldif_dlg.btnPrev, TRUE );
538 gtk_widget_set_sensitive( impldif_dlg.btnPrev, FALSE );
541 else if( pageNum == PAGE_ATTRIBUTES ) {
542 /* Goto finish stuff */
543 if( imp_ldif_field_move() ) {
544 gtk_notebook_set_current_page(
545 GTK_NOTEBOOK(impldif_dlg.notebook), PAGE_FINISH );
546 gtk_button_set_label(GTK_BUTTON(impldif_dlg.btnCancel),
548 imp_ldif_finish_show();
554 * Callback function to cancel and close dialog.
555 * \param widget Widget (button).
556 * \param data User data.
558 static void imp_ldif_cancel( GtkWidget *widget, gpointer data ) {
561 pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(impldif_dlg.notebook) );
562 if( pageNum != PAGE_FINISH ) {
563 impldif_dlg.cancelled = TRUE;
570 * Create LDIF file selection dialog.
571 * \param afs Address file selection data.
573 static void imp_ldif_file_select_create( AddressFileSelection *afs ) {
574 gchar *file = filesel_select_file_open(_("Select LDIF File"), NULL);
577 afs->cancelled = TRUE;
579 afs->cancelled = FALSE;
580 gtk_entry_set_text( GTK_ENTRY(impldif_dlg.entryFile), file );
586 * Callback function to display LDIF file selection dialog.
588 static void imp_ldif_file_select( void ) {
589 imp_ldif_file_select_create( & _imp_ldif_file_selector_ );
593 * Callback function to handle dialog close event.
594 * \param widget Widget (dialog).
595 * \param event Event object.
596 * \param data User data.
598 static gint imp_ldif_delete_event( GtkWidget *widget, GdkEventAny *event, gpointer data ) {
599 imp_ldif_cancel( widget, data );
604 * Callback function to respond to dialog key press events.
605 * \param widget Widget.
606 * \param event Event object.
607 * \param data User data.
609 static gboolean imp_ldif_key_pressed( GtkWidget *widget, GdkEventKey *event, gpointer data ) {
610 if (event && event->keyval == GDK_Escape) {
611 imp_ldif_cancel( widget, data );
617 * Format notebook "file" page.
618 * \param pageNum Page (tab) number.
619 * \param pageLbl Page (tab) label.
621 static void imp_ldif_page_file( gint pageNum, gchar *pageLbl ) {
625 GtkWidget *entryFile;
626 GtkWidget *entryName;
628 GtkTooltips *toolTip;
631 vbox = gtk_vbox_new(FALSE, 8);
632 gtk_container_add( GTK_CONTAINER( impldif_dlg.notebook ), vbox );
633 gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
635 label = gtk_label_new( pageLbl );
636 gtk_widget_show( label );
637 gtk_notebook_set_tab_label(
638 GTK_NOTEBOOK( impldif_dlg.notebook ),
639 gtk_notebook_get_nth_page(
640 GTK_NOTEBOOK( impldif_dlg.notebook ), pageNum ),
643 table = gtk_table_new(2, 3, FALSE);
644 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
645 gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
646 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
647 gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
651 label = gtk_label_new(_("Address Book"));
652 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
654 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
656 entryName = gtk_entry_new();
657 gtk_table_attach(GTK_TABLE(table), entryName, 1, 2, top, (top + 1),
658 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
660 toolTip = gtk_tooltips_new();
661 gtk_tooltips_set_tip( toolTip, entryName, _(
662 "Specify the name for the address book that will " \
663 "be created from the LDIF file data." ),
668 label = gtk_label_new(_("File Name"));
669 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
671 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
673 entryFile = gtk_entry_new();
674 gtk_table_attach(GTK_TABLE(table), entryFile, 1, 2, top, (top + 1),
675 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
677 toolTip = gtk_tooltips_new();
678 gtk_tooltips_set_tip( toolTip, entryFile,
679 _( "The full file specification of the LDIF file to import." ),
682 btnFile = gtkut_get_browse_file_btn(_("B_rowse"));
683 gtk_table_attach(GTK_TABLE(table), btnFile, 2, 3, top, (top + 1),
686 toolTip = gtk_tooltips_new();
687 gtk_tooltips_set_tip( toolTip, btnFile,
688 _( "Select the LDIF file to import." ),
691 gtk_widget_show_all(vbox);
694 g_signal_connect(G_OBJECT(btnFile), "clicked",
695 G_CALLBACK(imp_ldif_file_select), NULL);
697 impldif_dlg.entryFile = entryFile;
698 impldif_dlg.entryName = entryName;
702 * Format notebook fields page.
703 * \param pageNum Page (tab) number.
704 * \param pageLbl Page (tab) label.
706 static void imp_ldif_page_fields( gint pageNum, gchar *pageLbl ) {
712 GtkWidget *clist_swin;
713 GtkWidget *clist_field;
714 GtkWidget *entryField;
715 GtkWidget *entryAttrib;
716 GtkWidget *checkSelect;
717 GtkWidget *btnModify;
719 GtkTooltips *toolTip;
722 gchar *titles[ FIELDS_N_COLS ];
725 titles[ FIELD_COL_RESERVED ] = _("R");
726 titles[ FIELD_COL_SELECT ] = _("S");
727 titles[ FIELD_COL_FIELD ] = _("LDIF Field Name");
728 titles[ FIELD_COL_ATTRIB ] = _("Attribute Name");
730 vbox = gtk_vbox_new(FALSE, 8);
731 gtk_container_add( GTK_CONTAINER( impldif_dlg.notebook ), vbox );
732 gtk_container_set_border_width( GTK_CONTAINER (vbox), 4 );
734 label = gtk_label_new( pageLbl );
735 gtk_widget_show( label );
736 gtk_notebook_set_tab_label(
737 GTK_NOTEBOOK( impldif_dlg.notebook ),
738 gtk_notebook_get_nth_page(GTK_NOTEBOOK( impldif_dlg.notebook ), pageNum ),
741 /* Upper area - Field list */
742 vboxt = gtk_vbox_new( FALSE, 4 );
743 gtk_container_add( GTK_CONTAINER( vbox ), vboxt );
745 clist_swin = gtk_scrolled_window_new( NULL, NULL );
746 gtk_container_add( GTK_CONTAINER(vboxt), clist_swin );
747 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(clist_swin),
748 GTK_POLICY_AUTOMATIC,
749 GTK_POLICY_AUTOMATIC);
751 clist_field = gtk_clist_new_with_titles( FIELDS_N_COLS, titles );
752 gtk_container_add( GTK_CONTAINER(clist_swin), clist_field );
753 gtk_clist_set_selection_mode(
754 GTK_CLIST(clist_field), GTK_SELECTION_BROWSE );
755 gtk_clist_set_column_width( GTK_CLIST(clist_field),
756 FIELD_COL_RESERVED, FIELDS_COL_WIDTH_RESERVED );
757 gtk_clist_set_column_width( GTK_CLIST(clist_field),
758 FIELD_COL_SELECT, FIELDS_COL_WIDTH_SELECT );
759 gtk_clist_set_column_width( GTK_CLIST(clist_field),
760 FIELD_COL_FIELD, FIELDS_COL_WIDTH_FIELD );
761 gtk_clist_set_column_width( GTK_CLIST(clist_field),
762 FIELD_COL_ATTRIB, FIELDS_COL_WIDTH_ATTRIB );
764 /* Remove focus capability for column headers */
765 for( i = 0; i < FIELDS_N_COLS; i++ ) {
766 GTK_WIDGET_UNSET_FLAGS(
767 GTK_CLIST(clist_field)->column[i].button,
771 /* Lower area - Edit area */
772 vboxb = gtk_vbox_new( FALSE, 4 );
773 gtk_box_pack_end(GTK_BOX(vbox), vboxb, FALSE, FALSE, 2);
775 /* Data entry area */
776 table = gtk_table_new( 3, 3, FALSE);
777 gtk_box_pack_start(GTK_BOX(vboxb), table, FALSE, FALSE, 0);
778 gtk_table_set_row_spacings(GTK_TABLE(table), 4);
779 gtk_table_set_col_spacings(GTK_TABLE(table), 4);
783 label = gtk_label_new(_("LDIF Field"));
784 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
786 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
788 entryField = gtk_label_new( "" );
789 gtk_misc_set_alignment(GTK_MISC(entryField), 0.01, 0.5);
790 gtk_table_attach(GTK_TABLE(table), entryField, 1, 3, top, (top + 1),
791 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
795 label = gtk_label_new(_("Attribute"));
796 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
798 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
800 entryAttrib = gtk_entry_new();
801 gtk_table_attach(GTK_TABLE(table), entryAttrib, 1, 3, top, (top + 1),
802 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
804 toolTip = gtk_tooltips_new();
805 gtk_tooltips_set_tip( toolTip, entryAttrib,
806 _( "The LDIF field can be renamed to the User Attribute name." ),
811 label = gtk_label_new( _( "???" ) );
813 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
816 gtk_misc_set_alignment(GTK_MISC(label), 0.5, 0.5);
819 * Use an event box to attach some help in the form of a tooltip.
820 * Tried this for the clist but it looked bad.
822 eventBox = gtk_event_box_new();
823 gtk_container_add( GTK_CONTAINER(eventBox), label );
824 gtk_table_attach(GTK_TABLE(table), eventBox, 0, 1, top, (top + 1),
827 toolTip = gtk_tooltips_new();
828 gtk_tooltips_set_tip( toolTip, eventBox, _(
829 "Choose the LDIF field that will be renamed or selected " \
830 "for import in the list above. Reserved fields (marked " \
831 "with a tick in the \"R\" column), are automatically " \
832 "imported and cannot be renamed. A single click in the " \
833 "Select (\"S\") column will select the field for import " \
834 "with a tick. A single click anywhere in the row will " \
835 "select that field for rename in the input area below " \
836 "the list. A double click anywhere in the row will also " \
837 "select the field for import."
841 checkSelect = gtk_check_button_new_with_label( _( "Select for Import" ) );
842 gtk_table_attach(GTK_TABLE(table), checkSelect, 1, 2, top, (top + 1),
843 GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
845 toolTip = gtk_tooltips_new();
846 gtk_tooltips_set_tip( toolTip, checkSelect,
847 _( "Select the LDIF field for import into the address book." ),
850 btnModify = gtk_button_new_with_label( _(" Modify "));
851 gtk_table_attach(GTK_TABLE(table), btnModify, 2, 3, top, (top + 1),
854 toolTip = gtk_tooltips_new();
855 gtk_tooltips_set_tip( toolTip, btnModify,
856 _( "This button will update the list above with the data supplied." ),
859 gtk_widget_show_all(vbox);
862 g_signal_connect( G_OBJECT(clist_field), "select_row",
863 G_CALLBACK(imp_ldif_field_list_selected), NULL );
864 g_signal_connect( G_OBJECT(clist_field), "button_press_event",
865 G_CALLBACK(imp_ldif_field_list_toggle), NULL );
866 g_signal_connect( G_OBJECT(btnModify), "clicked",
867 G_CALLBACK(imp_ldif_modify_pressed), NULL );
869 impldif_dlg.clist_field = clist_field;
870 impldif_dlg.entryField = entryField;
871 impldif_dlg.entryAttrib = entryAttrib;
872 impldif_dlg.checkSelect = checkSelect;
873 impldif_dlg.btnModify = btnModify;
877 * Format notebook finish page.
878 * \param pageNum Page (tab) number.
879 * \param pageLbl Page (tab) label.
881 static void imp_ldif_page_finish( gint pageNum, gchar *pageLbl ) {
885 GtkWidget *labelBook;
886 GtkWidget *labelFile;
887 GtkWidget *labelRecs;
890 vbox = gtk_vbox_new(FALSE, 8);
891 gtk_container_add( GTK_CONTAINER( impldif_dlg.notebook ), vbox );
892 gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
894 label = gtk_label_new( pageLbl );
895 gtk_widget_show( label );
896 gtk_notebook_set_tab_label(
897 GTK_NOTEBOOK( impldif_dlg.notebook ),
898 gtk_notebook_get_nth_page( GTK_NOTEBOOK( impldif_dlg.notebook ), pageNum ),
901 table = gtk_table_new(3, 2, FALSE);
902 gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
903 gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
904 gtk_table_set_row_spacings(GTK_TABLE(table), 8);
905 gtk_table_set_col_spacings(GTK_TABLE(table), 8);
909 label = gtk_label_new( _( "Address Book :" ) );
910 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
911 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
913 labelBook = gtk_label_new("");
914 gtk_table_attach(GTK_TABLE(table), labelBook, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
915 gtk_misc_set_alignment(GTK_MISC(labelBook), 0, 0.5);
919 label = gtk_label_new( _( "File Name :" ) );
920 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
921 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
923 labelFile = gtk_label_new("");
924 gtk_table_attach(GTK_TABLE(table), labelFile, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
925 gtk_misc_set_alignment(GTK_MISC(labelFile), 0, 0.5);
929 label = gtk_label_new( _("Records Imported :") );
930 gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
931 gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
933 labelRecs = gtk_label_new("");
934 gtk_table_attach(GTK_TABLE(table), labelRecs, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
935 gtk_misc_set_alignment(GTK_MISC(labelRecs), 0, 0.5);
937 impldif_dlg.labelBook = labelBook;
938 impldif_dlg.labelFile = labelFile;
939 impldif_dlg.labelRecords = labelRecs;
943 * Create main dialog decorations (excluding notebook pages).
945 static void imp_ldif_dialog_create() {
953 GtkWidget *btnCancel;
955 GtkWidget *statusbar;
957 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
958 gtk_widget_set_size_request(window, IMPORTLDIF_WIDTH, IMPORTLDIF_HEIGHT );
959 gtk_container_set_border_width( GTK_CONTAINER(window), 0 );
960 gtk_window_set_title( GTK_WINDOW(window), _("Import LDIF file into Address Book") );
961 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
962 gtk_window_set_modal(GTK_WINDOW(window), TRUE);
963 g_signal_connect(G_OBJECT(window), "delete_event",
964 G_CALLBACK(imp_ldif_delete_event),
966 g_signal_connect(G_OBJECT(window), "key_press_event",
967 G_CALLBACK(imp_ldif_key_pressed),
970 vbox = gtk_vbox_new(FALSE, 4);
971 gtk_widget_show(vbox);
972 gtk_container_add(GTK_CONTAINER(window), vbox);
974 vnbox = gtk_vbox_new(FALSE, 4);
975 gtk_container_set_border_width(GTK_CONTAINER(vnbox), 4);
976 gtk_widget_show(vnbox);
977 gtk_box_pack_start(GTK_BOX(vbox), vnbox, TRUE, TRUE, 0);
980 notebook = gtk_notebook_new();
981 gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), FALSE );
982 gtk_widget_show(notebook);
983 gtk_box_pack_start(GTK_BOX(vnbox), notebook, TRUE, TRUE, 0);
984 gtk_container_set_border_width(GTK_CONTAINER(notebook), 6);
987 hsbox = gtk_hbox_new(FALSE, 0);
988 gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, BORDER_WIDTH);
989 statusbar = gtk_statusbar_new();
990 gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, BORDER_WIDTH);
993 gtkut_stock_button_set_create(&hbbox,
994 &btnCancel, GTK_STOCK_CANCEL,
995 &btnPrev, GTK_STOCK_GO_BACK,
996 &btnNext, GTK_STOCK_GO_FORWARD);
997 gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
998 gtk_container_set_border_width(GTK_CONTAINER(hbbox), 2);
999 gtk_widget_grab_default(btnNext);
1001 /* Button handlers */
1002 g_signal_connect(G_OBJECT(btnPrev), "clicked",
1003 G_CALLBACK(imp_ldif_prev), NULL);
1004 g_signal_connect(G_OBJECT(btnNext), "clicked",
1005 G_CALLBACK(imp_ldif_next), NULL);
1006 g_signal_connect(G_OBJECT(btnCancel), "clicked",
1007 G_CALLBACK(imp_ldif_cancel), NULL);
1009 gtk_widget_show_all(vbox);
1011 impldif_dlg.window = window;
1012 impldif_dlg.notebook = notebook;
1013 impldif_dlg.btnPrev = btnPrev;
1014 impldif_dlg.btnNext = btnNext;
1015 impldif_dlg.btnCancel = btnCancel;
1016 impldif_dlg.statusbar = statusbar;
1017 impldif_dlg.status_cid = gtk_statusbar_get_context_id(
1018 GTK_STATUSBAR(statusbar), "Import LDIF Dialog" );
1023 * Create import LDIF dialog.
1025 static void imp_ldif_create() {
1026 imp_ldif_dialog_create();
1027 imp_ldif_page_file( PAGE_FILE_INFO, _( "File Info" ) );
1028 imp_ldif_page_fields( PAGE_ATTRIBUTES, _( "Attributes" ) );
1029 imp_ldif_page_finish( PAGE_FINISH, _( "Finish" ) );
1030 gtk_widget_show_all( impldif_dlg.window );
1035 * \param addrIndex Address index.
1036 * \return Address book file of imported data, or <i>NULL</i> if import
1039 AddressBookFile *addressbook_imp_ldif( AddressIndex *addrIndex ) {
1040 _importedBook_ = NULL;
1041 _imp_addressIndex_ = addrIndex;
1043 if( ! impldif_dlg.window )
1046 gtk_button_set_label(GTK_BUTTON(impldif_dlg.btnCancel),
1049 impldif_dlg.cancelled = FALSE;
1050 gtk_widget_show(impldif_dlg.window);
1051 manage_window_set_transient(GTK_WINDOW(impldif_dlg.window));
1052 gtk_widget_grab_default(impldif_dlg.btnNext);
1054 gtk_entry_set_text( GTK_ENTRY(impldif_dlg.entryName), IMPORTLDIF_GUESS_NAME );
1055 gtk_entry_set_text( GTK_ENTRY(impldif_dlg.entryFile), "" );
1056 gtk_label_set_text( GTK_LABEL(impldif_dlg.entryField), "" );
1057 gtk_entry_set_text( GTK_ENTRY(impldif_dlg.entryAttrib), "" );
1058 gtk_clist_clear( GTK_CLIST(impldif_dlg.clist_field) );
1059 gtk_notebook_set_current_page( GTK_NOTEBOOK(impldif_dlg.notebook), PAGE_FILE_INFO );
1060 gtk_widget_set_sensitive( impldif_dlg.btnPrev, FALSE );
1061 gtk_widget_set_sensitive( impldif_dlg.btnNext, TRUE );
1062 stock_pixmap_gdk( impldif_dlg.window, STOCK_PIXMAP_MARK,
1063 &markxpm, &markxpmmask );
1065 gtk_widget_grab_focus(impldif_dlg.entryFile);
1067 impldif_dlg.rowIndSelect = -1;
1068 impldif_dlg.rowCount = 0;
1069 g_free( impldif_dlg.nameBook );
1070 g_free( impldif_dlg.fileName );
1071 impldif_dlg.nameBook = NULL;
1072 impldif_dlg.fileName = NULL;
1074 _ldifFile_ = ldif_create();
1076 gtk_widget_hide(impldif_dlg.window);
1077 ldif_free( _ldifFile_ );
1079 _imp_addressIndex_ = NULL;
1081 g_free( impldif_dlg.nameBook );
1082 g_free( impldif_dlg.fileName );
1083 impldif_dlg.nameBook = NULL;
1084 impldif_dlg.fileName = NULL;
1086 if( impldif_dlg.cancelled == TRUE ) return NULL;
1087 return _importedBook_;
1091 * ============================================================================
1093 * ============================================================================