Statistics
| Revision:

root / src / importldif.c @ 3032

History | View | Annotate | Download (26 kB)

1 1 hiro
/*
2 1 hiro
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 1 hiro
 * Copyright (C) 2001 Match Grun
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
#include <gtk/gtkwindow.h>
30 1 hiro
#include <gtk/gtksignal.h>
31 237 hiro
#include <gtk/gtkvbox.h>
32 1 hiro
#include <gtk/gtklabel.h>
33 1 hiro
#include <gtk/gtkentry.h>
34 1 hiro
#include <gtk/gtktable.h>
35 1 hiro
#include <gtk/gtkbutton.h>
36 1607 hiro
#include <gtk/gtkhbbox.h>
37 237 hiro
#include <gtk/gtkcheckbutton.h>
38 237 hiro
#include <gtk/gtktogglebutton.h>
39 237 hiro
#include <gtk/gtkstatusbar.h>
40 237 hiro
#include <gtk/gtknotebook.h>
41 237 hiro
#include <gtk/gtkstock.h>
42 1 hiro
43 1 hiro
#include "addrbook.h"
44 1 hiro
#include "addressbook.h"
45 1 hiro
#include "addressitem.h"
46 1603 hiro
#include "filesel.h"
47 1 hiro
#include "gtkutils.h"
48 1 hiro
#include "stock_pixmap.h"
49 1 hiro
#include "prefs_common.h"
50 1 hiro
#include "manage_window.h"
51 1 hiro
#include "mgutils.h"
52 1 hiro
#include "ldif.h"
53 1604 hiro
#include "codeconv.h"
54 1 hiro
#include "utils.h"
55 1 hiro
56 1 hiro
#define IMPORTLDIF_GUESS_NAME "LDIF Import"
57 1 hiro
58 1 hiro
#define PAGE_FILE_INFO             0
59 1 hiro
#define PAGE_ATTRIBUTES            1
60 1 hiro
#define PAGE_FINISH                2
61 1 hiro
62 1 hiro
#define IMPORTLDIF_WIDTH           380
63 1 hiro
#define IMPORTLDIF_HEIGHT          300
64 1 hiro
65 1 hiro
#define FIELDS_N_COLS              3
66 1 hiro
#define FIELDS_COL_WIDTH_SELECT    10
67 1 hiro
#define FIELDS_COL_WIDTH_FIELD     140
68 1 hiro
#define FIELDS_COL_WIDTH_ATTRIB    140
69 1 hiro
70 1 hiro
typedef enum {
71 1 hiro
        FIELD_COL_SELECT  = 0,
72 1 hiro
        FIELD_COL_FIELD   = 1,
73 1 hiro
        FIELD_COL_ATTRIB  = 2
74 1 hiro
} ImpLdif_FieldColPos;
75 1 hiro
76 1 hiro
static struct _ImpLdif_Dlg {
77 1 hiro
        GtkWidget *window;
78 1 hiro
        GtkWidget *notebook;
79 1 hiro
        GtkWidget *file_entry;
80 1 hiro
        GtkWidget *name_entry;
81 1 hiro
        GtkWidget *clist_field;
82 1 hiro
        GtkWidget *name_ldif;
83 1 hiro
        GtkWidget *name_attrib;
84 1 hiro
        GtkWidget *check_select;
85 1 hiro
        GtkWidget *labelBook;
86 1 hiro
        GtkWidget *labelFile;
87 1 hiro
        GtkWidget *labelRecords;
88 1 hiro
        GtkWidget *btnPrev;
89 1 hiro
        GtkWidget *btnNext;
90 1 hiro
        GtkWidget *btnCancel;
91 1 hiro
        GtkWidget *statusbar;
92 1 hiro
        gint      status_cid;
93 1 hiro
        gint      rowIndSelect;
94 1 hiro
        gint      rowCount;
95 1 hiro
        gchar     *nameBook;
96 1 hiro
        gchar     *fileName;
97 1 hiro
        gboolean  cancelled;
98 1 hiro
} impldif_dlg;
99 1 hiro
100 1 hiro
static AddressBookFile *_importedBook_;
101 1 hiro
static AddressIndex *_imp_addressIndex_;
102 1 hiro
static LdifFile *_ldifFile_ = NULL;
103 1 hiro
104 1 hiro
static GdkPixmap *markxpm;
105 1 hiro
static GdkBitmap *markxpmmask;
106 1 hiro
107 1 hiro
static void imp_ldif_status_show( gchar *msg ) {
108 1 hiro
        if( impldif_dlg.statusbar != NULL ) {
109 1 hiro
                gtk_statusbar_pop( GTK_STATUSBAR(impldif_dlg.statusbar), impldif_dlg.status_cid );
110 1 hiro
                if( msg ) {
111 1 hiro
                        gtk_statusbar_push( GTK_STATUSBAR(impldif_dlg.statusbar), impldif_dlg.status_cid, msg );
112 1 hiro
                }
113 1 hiro
        }
114 1 hiro
}
115 1 hiro
116 1 hiro
static void imp_ldif_message( void ) {
117 1 hiro
        gchar *sMsg = NULL;
118 1 hiro
        gint pageNum;
119 1 hiro
120 1 hiro
        pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(impldif_dlg.notebook) );
121 1 hiro
        if( pageNum == PAGE_FILE_INFO ) {
122 1 hiro
                sMsg = _( "Please specify address book name and file to import." );
123 1 hiro
        }
124 1 hiro
        else if( pageNum == PAGE_ATTRIBUTES ) {
125 1 hiro
                sMsg = _( "Select and rename LDIF field names to import." );
126 1 hiro
        }
127 1 hiro
        else if( pageNum == PAGE_FINISH ) {
128 1 hiro
                sMsg = _( "File imported." );
129 1 hiro
        }
130 1 hiro
        imp_ldif_status_show( sMsg );
131 1 hiro
}
132 1 hiro
133 1 hiro
static gchar *imp_ldif_guess_file( AddressBookFile *abf ) {
134 1 hiro
        gchar *newFile = NULL;
135 1 hiro
        GList *fileList = NULL;
136 1 hiro
        gint fileNum = 1;
137 1 hiro
        fileList = addrbook_get_bookfile_list( abf );
138 1 hiro
        if( fileList ) {
139 1 hiro
                fileNum = 1 + abf->maxValue;
140 1 hiro
        }
141 1 hiro
        newFile = addrbook_gen_new_file_name( fileNum );
142 1 hiro
        g_list_free( fileList );
143 1 hiro
        fileList = NULL;
144 1 hiro
        return newFile;
145 1 hiro
}
146 1 hiro
147 1 hiro
static void imp_ldif_update_row( GtkCList *clist ) {
148 1 hiro
        Ldif_FieldRec *rec;
149 1 hiro
        gchar *text[ FIELDS_N_COLS ];
150 1 hiro
        gint row;
151 1 hiro
152 1 hiro
        if( impldif_dlg.rowIndSelect < 0 ) return;
153 1 hiro
        row = impldif_dlg.rowIndSelect;
154 1 hiro
155 1 hiro
        rec = gtk_clist_get_row_data( clist, row );
156 1 hiro
        text[ FIELD_COL_SELECT ] = "";
157 1 hiro
        text[ FIELD_COL_FIELD  ] = rec->tagName;
158 1 hiro
        text[ FIELD_COL_ATTRIB ] = rec->userName;
159 1 hiro
160 1 hiro
        gtk_clist_freeze( clist );
161 1 hiro
        gtk_clist_remove( clist, row );
162 1 hiro
        if( row == impldif_dlg.rowCount - 1 ) {
163 1 hiro
                gtk_clist_append( clist, text );
164 1 hiro
        }
165 1 hiro
        else {
166 1 hiro
                gtk_clist_insert( clist, row, text );
167 1 hiro
        }
168 1 hiro
        if( rec->selected )
169 1 hiro
                gtk_clist_set_pixmap( clist, row, FIELD_COL_SELECT, markxpm, markxpmmask );
170 1 hiro
171 1 hiro
        gtk_clist_set_row_data( clist, row, rec );
172 1 hiro
        gtk_clist_thaw( clist );
173 1 hiro
}
174 1 hiro
175 1 hiro
static void imp_ldif_load_fields( LdifFile *ldf ) {
176 1 hiro
        GtkCList *clist = GTK_CLIST(impldif_dlg.clist_field);
177 1 hiro
        GList *node, *list;
178 1 hiro
        gchar *text[ FIELDS_N_COLS ];
179 1 hiro
180 1 hiro
        impldif_dlg.rowIndSelect = -1;
181 1 hiro
        impldif_dlg.rowCount = 0;
182 1 hiro
        if( ! ldf->accessFlag ) return;
183 1 hiro
        gtk_clist_clear( clist );
184 1 hiro
        list = ldif_get_fieldlist( ldf );
185 1 hiro
        node = list;
186 1 hiro
        while( node ) {
187 1 hiro
                Ldif_FieldRec *rec = node->data;
188 1 hiro
                gint row;
189 1 hiro
190 1 hiro
                if( ! rec->reserved ) {
191 1 hiro
                        text[ FIELD_COL_SELECT ] = "";
192 1 hiro
                        text[ FIELD_COL_FIELD  ] = rec->tagName;
193 1 hiro
                        text[ FIELD_COL_ATTRIB ] = rec->userName;
194 1 hiro
                        row = gtk_clist_append( clist, text );
195 1 hiro
                        gtk_clist_set_row_data( clist, row, rec );
196 1 hiro
                        if( rec->selected )
197 1 hiro
                                gtk_clist_set_pixmap( clist, row, FIELD_COL_SELECT, markxpm, markxpmmask );
198 1 hiro
                        impldif_dlg.rowCount++;
199 1 hiro
                }
200 1 hiro
                node = g_list_next( node );
201 1 hiro
        }
202 1 hiro
        g_list_free( list );
203 1 hiro
        list = NULL;
204 1 hiro
        ldif_set_accessed( ldf, FALSE );
205 1 hiro
}
206 1 hiro
207 1 hiro
static void imp_ldif_field_list_selected( GtkCList *clist, gint row, gint column, GdkEvent *event, gpointer data ) {
208 1 hiro
        Ldif_FieldRec *rec = gtk_clist_get_row_data( clist, row );
209 1 hiro
210 1 hiro
        impldif_dlg.rowIndSelect = row;
211 1 hiro
        gtk_entry_set_text( GTK_ENTRY(impldif_dlg.name_attrib), "" );
212 1 hiro
        if( rec ) {
213 1 hiro
                gtk_label_set_text( GTK_LABEL(impldif_dlg.name_ldif), rec->tagName );
214 1 hiro
                if( rec->userName )
215 1 hiro
                        gtk_entry_set_text( GTK_ENTRY(impldif_dlg.name_attrib), rec->userName );
216 1 hiro
                gtk_toggle_button_set_active(
217 1 hiro
                        GTK_TOGGLE_BUTTON( impldif_dlg.check_select),
218 1 hiro
                        rec->selected );
219 1 hiro
        }
220 1 hiro
        gtk_widget_grab_focus(impldif_dlg.name_attrib);
221 1 hiro
}
222 1 hiro
223 1 hiro
static gboolean imp_ldif_field_list_toggle( GtkCList *clist, GdkEventButton *event, gpointer data ) {
224 1 hiro
        if( ! event ) return FALSE;
225 1 hiro
        if( impldif_dlg.rowIndSelect < 0 ) return FALSE;
226 1 hiro
        if( event->button == 1 ) {
227 1 hiro
                if( event->type == GDK_2BUTTON_PRESS ) {
228 1 hiro
                        Ldif_FieldRec *rec = gtk_clist_get_row_data( clist, impldif_dlg.rowIndSelect );
229 1 hiro
                        if( rec ) {
230 1 hiro
                                rec->selected = ! rec->selected;
231 1 hiro
                                imp_ldif_update_row( clist );
232 1 hiro
                        }
233 1 hiro
                }
234 1 hiro
        }
235 1 hiro
        return FALSE;
236 1 hiro
}
237 1 hiro
238 1 hiro
static void imp_ldif_modify_pressed( GtkWidget *widget, gpointer data ) {
239 1 hiro
        GtkCList *clist = GTK_CLIST(impldif_dlg.clist_field);
240 1 hiro
        Ldif_FieldRec *rec;
241 1 hiro
        gint row;
242 1 hiro
243 1 hiro
        if( impldif_dlg.rowIndSelect < 0 ) return;
244 1 hiro
        row = impldif_dlg.rowIndSelect;
245 1 hiro
        rec = gtk_clist_get_row_data( clist, impldif_dlg.rowIndSelect );
246 1 hiro
247 1 hiro
        g_free( rec->userName );
248 1 hiro
        rec->userName = gtk_editable_get_chars( GTK_EDITABLE(impldif_dlg.name_attrib), 0, -1 );
249 1 hiro
        rec->selected = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( impldif_dlg.check_select) );
250 1 hiro
        imp_ldif_update_row( clist );
251 1 hiro
        gtk_clist_select_row( clist, row, 0 );
252 1 hiro
        gtk_label_set_text( GTK_LABEL(impldif_dlg.name_ldif), "" );
253 1 hiro
        gtk_entry_set_text( GTK_ENTRY(impldif_dlg.name_attrib), "" );
254 1 hiro
        gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( impldif_dlg.check_select), FALSE );
255 1 hiro
}
256 1 hiro
257 1 hiro
/*
258 1 hiro
* Move off fields page.
259 1 hiro
* return: TRUE if OK to move off page.
260 1 hiro
*/
261 1 hiro
static gboolean imp_ldif_field_move() {
262 1 hiro
        gboolean retVal = FALSE;
263 1 hiro
        gchar *newFile;
264 1 hiro
        AddressBookFile *abf = NULL;
265 1 hiro
266 1 hiro
        if( _importedBook_ ) {
267 1 hiro
                addrbook_free_book( _importedBook_ );
268 1 hiro
        }
269 1 hiro
270 1 hiro
        abf = addrbook_create_book();
271 1 hiro
        addrbook_set_path( abf, _imp_addressIndex_->filePath );
272 1 hiro
        addrbook_set_name( abf, impldif_dlg.nameBook );
273 1 hiro
        newFile = imp_ldif_guess_file( abf );
274 1 hiro
        addrbook_set_file( abf, newFile );
275 1 hiro
        g_free( newFile );
276 1 hiro
277 1 hiro
        /* Import data into file */
278 1 hiro
        if( ldif_import_data( _ldifFile_, abf->addressCache ) == MGU_SUCCESS ) {
279 1 hiro
                addrbook_save_data( abf );
280 1 hiro
                abf->dirtyFlag = TRUE;
281 1 hiro
                _importedBook_ = abf;
282 1 hiro
                retVal = TRUE;
283 1 hiro
        }
284 1 hiro
        else {
285 1 hiro
                addrbook_free_book( abf );
286 1 hiro
        }
287 1 hiro
288 1 hiro
        return retVal;
289 1 hiro
}
290 1 hiro
291 1 hiro
/*
292 1 hiro
* Move off fields page.
293 1 hiro
* return: TRUE if OK to move off page.
294 1 hiro
*/
295 1 hiro
static gboolean imp_ldif_file_move() {
296 1 hiro
        gboolean retVal = FALSE;
297 1 hiro
        gchar *sName;
298 1 hiro
        gchar *sFile;
299 1 hiro
        gchar *sMsg = NULL;
300 1 hiro
        gboolean errFlag = FALSE;
301 1 hiro
302 1 hiro
        sFile = gtk_editable_get_chars( GTK_EDITABLE(impldif_dlg.file_entry), 0, -1 );
303 1 hiro
        g_strchug( sFile ); g_strchomp( sFile );
304 1 hiro
305 1 hiro
        sName = gtk_editable_get_chars( GTK_EDITABLE(impldif_dlg.name_entry), 0, -1 );
306 1 hiro
        g_strchug( sName ); g_strchomp( sName );
307 1 hiro
308 1 hiro
        g_free( impldif_dlg.nameBook );
309 1 hiro
        g_free( impldif_dlg.fileName );
310 1 hiro
        impldif_dlg.nameBook = sName;
311 1 hiro
        impldif_dlg.fileName = sFile;
312 1 hiro
313 1 hiro
        gtk_entry_set_text( GTK_ENTRY(impldif_dlg.file_entry), sFile );
314 1 hiro
        gtk_entry_set_text( GTK_ENTRY(impldif_dlg.name_entry), sName );
315 1 hiro
316 1 hiro
        if( *sFile == '\0'|| strlen( sFile ) < 1 ) {
317 1 hiro
                sMsg = _( "Please select a file." );
318 1 hiro
                gtk_widget_grab_focus(impldif_dlg.file_entry);
319 1 hiro
                errFlag = TRUE;
320 1 hiro
        }
321 1 hiro
322 1 hiro
        if( *sName == '\0'|| strlen( sName ) < 1 ) {
323 1 hiro
                if( ! errFlag ) sMsg = _( "Address book name must be supplied." );
324 1 hiro
                gtk_widget_grab_focus(impldif_dlg.name_entry);
325 1 hiro
                errFlag = TRUE;
326 1 hiro
        }
327 1 hiro
328 1 hiro
        if( ! errFlag ) {
329 1605 hiro
                gchar *sFSFile;
330 1 hiro
                /* Read attribute list */
331 1605 hiro
                sFSFile = conv_filename_from_utf8( sFile );
332 1605 hiro
                ldif_set_file( _ldifFile_, sFSFile );
333 1605 hiro
                g_free( sFSFile );
334 1 hiro
                if( ldif_read_tags( _ldifFile_ ) == MGU_SUCCESS ) {
335 1 hiro
                        /* Load fields */
336 1 hiro
                        /* ldif_print_file( _ldifFile_, stdout ); */
337 1 hiro
                        imp_ldif_load_fields( _ldifFile_ );
338 1 hiro
                        retVal = TRUE;
339 1 hiro
                }
340 1 hiro
                else {
341 1 hiro
                        sMsg = _( "Error reading LDIF fields." );
342 1 hiro
                }
343 1 hiro
        }
344 1 hiro
        imp_ldif_status_show( sMsg );
345 1 hiro
346 1 hiro
        return retVal;
347 1 hiro
}
348 1 hiro
349 1 hiro
/*
350 1 hiro
 * Display finish page.
351 1 hiro
 */
352 1 hiro
static void imp_ldif_finish_show() {
353 1 hiro
        gchar *sMsg;
354 1 hiro
        gchar *name;
355 1 hiro
356 1 hiro
        name = gtk_editable_get_chars( GTK_EDITABLE(impldif_dlg.name_entry), 0, -1 );
357 1 hiro
        gtk_label_set_text( GTK_LABEL(impldif_dlg.labelBook), name );
358 1 hiro
        g_free( name );
359 1 hiro
        gtk_label_set_text( GTK_LABEL(impldif_dlg.labelFile), _ldifFile_->path );
360 1 hiro
        gtk_label_set_text( GTK_LABEL(impldif_dlg.labelRecords), itos( _ldifFile_->importCount ) );
361 1 hiro
        gtk_widget_set_sensitive( impldif_dlg.btnPrev, FALSE );
362 1 hiro
        gtk_widget_set_sensitive( impldif_dlg.btnNext, FALSE );
363 1 hiro
        if( _ldifFile_->retVal == MGU_SUCCESS ) {
364 1 hiro
                sMsg = _( "LDIF file imported successfully." );
365 1 hiro
        }
366 1 hiro
        else {
367 1 hiro
                sMsg = mgu_error2string( _ldifFile_->retVal );
368 1 hiro
        }
369 1 hiro
        imp_ldif_status_show( sMsg );
370 1152 hiro
        gtk_button_set_label(GTK_BUTTON(impldif_dlg.btnCancel), GTK_STOCK_CLOSE);
371 1 hiro
        gtk_widget_grab_focus(impldif_dlg.btnCancel);
372 1 hiro
}
373 1 hiro
374 1 hiro
static void imp_ldif_prev( GtkWidget *widget ) {
375 1 hiro
        gint pageNum;
376 1 hiro
377 1 hiro
        pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(impldif_dlg.notebook) );
378 1 hiro
        if( pageNum == PAGE_ATTRIBUTES ) {
379 1 hiro
                /* Goto file page stuff */
380 1 hiro
                gtk_notebook_set_current_page(
381 1 hiro
                        GTK_NOTEBOOK(impldif_dlg.notebook), PAGE_FILE_INFO );
382 1 hiro
                gtk_widget_set_sensitive( impldif_dlg.btnPrev, FALSE );
383 1 hiro
        }
384 1 hiro
        imp_ldif_message();
385 1 hiro
}
386 1 hiro
387 1 hiro
static void imp_ldif_next( GtkWidget *widget ) {
388 1 hiro
        gint pageNum;
389 1 hiro
390 1 hiro
        pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(impldif_dlg.notebook) );
391 1 hiro
        if( pageNum == PAGE_FILE_INFO ) {
392 1 hiro
                /* Goto attributes stuff */
393 1 hiro
                if( imp_ldif_file_move() ) {
394 1 hiro
                        gtk_notebook_set_current_page(
395 1 hiro
                                GTK_NOTEBOOK(impldif_dlg.notebook), PAGE_ATTRIBUTES );
396 1 hiro
                        imp_ldif_message();
397 1 hiro
                        gtk_widget_set_sensitive( impldif_dlg.btnPrev, TRUE );
398 1 hiro
                }
399 1 hiro
                else {
400 1 hiro
                        gtk_widget_set_sensitive( impldif_dlg.btnPrev, FALSE );
401 1 hiro
                }
402 1 hiro
        }
403 1 hiro
        else if( pageNum == PAGE_ATTRIBUTES ) {
404 1 hiro
                /* Goto finish stuff */
405 1 hiro
                if( imp_ldif_field_move() ) {
406 1 hiro
                        gtk_notebook_set_current_page(
407 1 hiro
                                GTK_NOTEBOOK(impldif_dlg.notebook), PAGE_FINISH );
408 1 hiro
                        imp_ldif_finish_show();
409 1 hiro
                }
410 1 hiro
        }
411 1 hiro
}
412 1 hiro
413 1 hiro
static void imp_ldif_cancel( GtkWidget *widget, gpointer data ) {
414 1 hiro
        gint pageNum;
415 1 hiro
416 1 hiro
        pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(impldif_dlg.notebook) );
417 1 hiro
        if( pageNum != PAGE_FINISH ) {
418 1 hiro
                impldif_dlg.cancelled = TRUE;
419 1 hiro
        }
420 1 hiro
        gtk_main_quit();
421 1 hiro
}
422 1 hiro
423 1 hiro
static void imp_ldif_file_select( void ) {
424 1603 hiro
        gchar *sSelFile;
425 1 hiro
426 1607 hiro
        sSelFile = filesel_select_file( _("Select LDIF File"), NULL,
427 1603 hiro
                                        GTK_FILE_CHOOSER_ACTION_OPEN );
428 1603 hiro
        if ( sSelFile ) {
429 1604 hiro
                gchar *sUTF8File;
430 1604 hiro
                sUTF8File = conv_filename_to_utf8( sSelFile );
431 1604 hiro
                gtk_entry_set_text( GTK_ENTRY(impldif_dlg.file_entry), sUTF8File );
432 1604 hiro
                g_free( sUTF8File );
433 1603 hiro
                g_free( sSelFile );
434 1603 hiro
        }
435 1 hiro
}
436 1 hiro
437 1 hiro
static gint imp_ldif_delete_event( GtkWidget *widget, GdkEventAny *event, gpointer data ) {
438 1 hiro
        imp_ldif_cancel( widget, data );
439 1 hiro
        return TRUE;
440 1 hiro
}
441 1 hiro
442 1 hiro
static gboolean imp_ldif_key_pressed( GtkWidget *widget, GdkEventKey *event, gpointer data ) {
443 1 hiro
        if (event && event->keyval == GDK_Escape) {
444 1 hiro
                imp_ldif_cancel( widget, data );
445 1 hiro
        }
446 1 hiro
        return FALSE;
447 1 hiro
}
448 1 hiro
449 1 hiro
static void imp_ldif_page_file( gint pageNum, gchar *pageLbl ) {
450 1 hiro
        GtkWidget *vbox;
451 1 hiro
        GtkWidget *table;
452 1 hiro
        GtkWidget *label;
453 1 hiro
        GtkWidget *file_entry;
454 1 hiro
        GtkWidget *name_entry;
455 1 hiro
        GtkWidget *file_btn;
456 1 hiro
        gint top;
457 1 hiro
458 1 hiro
        vbox = gtk_vbox_new(FALSE, 8);
459 1 hiro
        gtk_container_add( GTK_CONTAINER( impldif_dlg.notebook ), vbox );
460 1 hiro
        gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
461 1 hiro
462 1 hiro
        label = gtk_label_new( pageLbl );
463 1 hiro
        gtk_widget_show( label );
464 1 hiro
        gtk_notebook_set_tab_label(
465 1 hiro
                GTK_NOTEBOOK( impldif_dlg.notebook ),
466 1 hiro
                gtk_notebook_get_nth_page(
467 1 hiro
                        GTK_NOTEBOOK( impldif_dlg.notebook ), pageNum ),
468 1 hiro
                label );
469 1 hiro
470 1 hiro
        table = gtk_table_new(2, 3, FALSE);
471 1 hiro
        gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
472 1 hiro
        gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
473 1 hiro
        gtk_table_set_row_spacings(GTK_TABLE(table), 8);
474 1 hiro
        gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
475 1 hiro
476 1 hiro
        /* First row */
477 1 hiro
        top = 0;
478 1 hiro
        label = gtk_label_new(_("Address Book"));
479 1 hiro
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
480 1 hiro
                GTK_FILL, 0, 0, 0);
481 1 hiro
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
482 1 hiro
483 1 hiro
        name_entry = gtk_entry_new();
484 1 hiro
        gtk_table_attach(GTK_TABLE(table), name_entry, 1, 2, top, (top + 1),
485 1 hiro
                GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
486 1 hiro
487 1 hiro
        /* Second row */
488 1 hiro
        top = 1;
489 1 hiro
        label = gtk_label_new(_("File Name"));
490 1 hiro
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
491 1 hiro
                GTK_FILL, 0, 0, 0);
492 1 hiro
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
493 1 hiro
494 1 hiro
        file_entry = gtk_entry_new();
495 1 hiro
        gtk_table_attach(GTK_TABLE(table), file_entry, 1, 2, top, (top + 1),
496 1 hiro
                GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
497 1 hiro
498 1 hiro
        file_btn = gtk_button_new_with_label( _(" ... "));
499 1 hiro
        gtk_table_attach(GTK_TABLE(table), file_btn, 2, 3, top, (top + 1),
500 1 hiro
                GTK_FILL, 0, 3, 0);
501 1 hiro
502 1 hiro
        gtk_widget_show_all(vbox);
503 1 hiro
504 1 hiro
        /* Button handler */
505 1 hiro
        g_signal_connect(G_OBJECT(file_btn), "clicked",
506 1 hiro
                         G_CALLBACK(imp_ldif_file_select), NULL);
507 1 hiro
508 1 hiro
        impldif_dlg.file_entry = file_entry;
509 1 hiro
        impldif_dlg.name_entry = name_entry;
510 1 hiro
}
511 1 hiro
512 1 hiro
static void imp_ldif_page_fields( gint pageNum, gchar *pageLbl ) {
513 1 hiro
        GtkWidget *vbox;
514 1 hiro
        GtkWidget *vboxt;
515 1 hiro
        GtkWidget *vboxb;
516 1 hiro
        GtkWidget *buttonMod;
517 1 hiro
518 1 hiro
        GtkWidget *table;
519 1 hiro
        GtkWidget *label;
520 1 hiro
        GtkWidget *clist_swin;
521 1 hiro
        GtkWidget *clist_field;
522 1 hiro
        GtkWidget *name_ldif;
523 1 hiro
        GtkWidget *name_attrib;
524 1 hiro
        GtkWidget *check_select;
525 1 hiro
        gint top;
526 1 hiro
527 1 hiro
        gchar *titles[ FIELDS_N_COLS ];
528 1 hiro
        gint i;
529 1 hiro
530 1 hiro
        titles[ FIELD_COL_SELECT ] = _("S");
531 1 hiro
        titles[ FIELD_COL_FIELD  ] = _("LDIF Field");
532 1 hiro
        titles[ FIELD_COL_ATTRIB ] = _("Attribute Name");
533 1 hiro
534 1 hiro
        vbox = gtk_vbox_new(FALSE, 8);
535 1 hiro
        gtk_container_add( GTK_CONTAINER( impldif_dlg.notebook ), vbox );
536 1 hiro
        gtk_container_set_border_width( GTK_CONTAINER (vbox), 4 );
537 1 hiro
538 1 hiro
        label = gtk_label_new( pageLbl );
539 1 hiro
        gtk_widget_show( label );
540 1 hiro
        gtk_notebook_set_tab_label(
541 1 hiro
                GTK_NOTEBOOK( impldif_dlg.notebook ),
542 1 hiro
                gtk_notebook_get_nth_page(GTK_NOTEBOOK( impldif_dlg.notebook ), pageNum ),
543 1 hiro
                label );
544 1 hiro
545 1 hiro
        /* Upper area - Field list */
546 1 hiro
        vboxt = gtk_vbox_new( FALSE, 4 );
547 1 hiro
        gtk_container_add( GTK_CONTAINER( vbox ), vboxt );
548 1 hiro
549 1 hiro
        clist_swin = gtk_scrolled_window_new( NULL, NULL );
550 1 hiro
        gtk_container_add( GTK_CONTAINER(vboxt), clist_swin );
551 1 hiro
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(clist_swin),
552 1 hiro
                                       GTK_POLICY_AUTOMATIC,
553 1 hiro
                                       GTK_POLICY_ALWAYS);
554 1 hiro
555 1 hiro
        clist_field = gtk_clist_new_with_titles( FIELDS_N_COLS, titles );
556 1 hiro
        gtk_container_add( GTK_CONTAINER(clist_swin), clist_field );
557 1 hiro
        gtk_clist_set_selection_mode( GTK_CLIST(clist_field), GTK_SELECTION_BROWSE );
558 1 hiro
        gtk_clist_set_column_width(
559 1 hiro
                        GTK_CLIST(clist_field), FIELD_COL_SELECT, FIELDS_COL_WIDTH_SELECT );
560 1 hiro
        gtk_clist_set_column_width(
561 1 hiro
                        GTK_CLIST(clist_field), FIELD_COL_FIELD, FIELDS_COL_WIDTH_FIELD );
562 1 hiro
        gtk_clist_set_column_width(
563 1 hiro
                        GTK_CLIST(clist_field), FIELD_COL_ATTRIB, FIELDS_COL_WIDTH_ATTRIB );
564 1577 hiro
        gtkut_clist_set_redraw( GTK_CLIST(clist_field) );
565 1 hiro
566 1 hiro
        for( i = 0; i < FIELDS_N_COLS; i++ )
567 1 hiro
                GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(clist_field)->column[i].button, GTK_CAN_FOCUS);
568 1 hiro
569 1 hiro
        /* Lower area - Edit area */
570 1 hiro
        vboxb = gtk_vbox_new( FALSE, 4 );
571 1 hiro
        gtk_box_pack_end(GTK_BOX(vbox), vboxb, FALSE, FALSE, 2);
572 1 hiro
573 1 hiro
        /* Data entry area */
574 1 hiro
        table = gtk_table_new( 3, 3, FALSE);
575 1 hiro
        gtk_box_pack_start(GTK_BOX(vboxb), table, FALSE, FALSE, 0);
576 1 hiro
        gtk_table_set_row_spacings(GTK_TABLE(table), 4);
577 1 hiro
        gtk_table_set_col_spacings(GTK_TABLE(table), 4);
578 1 hiro
579 1 hiro
        /* First row */
580 1 hiro
        top = 0;
581 1 hiro
        label = gtk_label_new(_("LDIF Field"));
582 1 hiro
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
583 1 hiro
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
584 1 hiro
585 1 hiro
        name_ldif = gtk_label_new( "" );
586 1 hiro
        gtk_misc_set_alignment(GTK_MISC(name_ldif), 0.01, 0.5);
587 1 hiro
        gtk_table_attach(GTK_TABLE(table), name_ldif, 1, 3, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
588 1 hiro
589 1 hiro
        /* Second row */
590 1 hiro
        ++top;
591 1 hiro
        label = gtk_label_new(_("Attribute"));
592 1 hiro
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
593 1 hiro
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
594 1 hiro
595 1 hiro
        name_attrib = gtk_entry_new();
596 1 hiro
        gtk_table_attach(GTK_TABLE(table), name_attrib, 1, 3, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
597 1 hiro
598 1 hiro
        /* Next row */
599 1 hiro
        ++top;
600 1 hiro
        label = gtk_label_new(_("Select"));
601 1 hiro
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
602 1 hiro
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
603 1 hiro
604 1 hiro
        check_select = gtk_check_button_new();
605 1 hiro
        gtk_table_attach(GTK_TABLE(table), check_select, 1, 2, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
606 1 hiro
607 1 hiro
        buttonMod = gtk_button_new_with_label( _("Modify"));
608 1 hiro
        gtk_table_attach(GTK_TABLE(table), buttonMod, 2, 3, top, (top + 1), GTK_FILL, 0, 3, 0);
609 1 hiro
610 1 hiro
        gtk_widget_show_all(vbox);
611 1 hiro
612 1 hiro
        /* Event handlers */
613 1 hiro
        g_signal_connect( G_OBJECT(clist_field), "select_row",
614 1 hiro
                          G_CALLBACK(imp_ldif_field_list_selected), NULL );
615 1 hiro
        g_signal_connect( G_OBJECT(clist_field), "button_press_event",
616 1 hiro
                          G_CALLBACK(imp_ldif_field_list_toggle), NULL );
617 1 hiro
        g_signal_connect( G_OBJECT(buttonMod), "clicked",
618 1 hiro
                          G_CALLBACK(imp_ldif_modify_pressed), NULL );
619 1 hiro
620 1 hiro
        impldif_dlg.clist_field  = clist_field;
621 1 hiro
        impldif_dlg.name_ldif    = name_ldif;
622 1 hiro
        impldif_dlg.name_attrib  = name_attrib;
623 1 hiro
        impldif_dlg.check_select = check_select;
624 1 hiro
}
625 1 hiro
626 1 hiro
static void imp_ldif_page_finish( gint pageNum, gchar *pageLbl ) {
627 1 hiro
        GtkWidget *vbox;
628 1 hiro
        GtkWidget *table;
629 1 hiro
        GtkWidget *label;
630 1 hiro
        GtkWidget *labelBook;
631 1 hiro
        GtkWidget *labelFile;
632 1 hiro
        GtkWidget *labelRecs;
633 1 hiro
        gint top;
634 1 hiro
635 1 hiro
        vbox = gtk_vbox_new(FALSE, 8);
636 1 hiro
        gtk_container_add( GTK_CONTAINER( impldif_dlg.notebook ), vbox );
637 1 hiro
        gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
638 1 hiro
639 1 hiro
        label = gtk_label_new( pageLbl );
640 1 hiro
        gtk_widget_show( label );
641 1 hiro
        gtk_notebook_set_tab_label(
642 1 hiro
                GTK_NOTEBOOK( impldif_dlg.notebook ),
643 1 hiro
                gtk_notebook_get_nth_page( GTK_NOTEBOOK( impldif_dlg.notebook ), pageNum ), label );
644 1 hiro
645 1 hiro
        table = gtk_table_new(3, 2, FALSE);
646 1 hiro
        gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
647 1 hiro
        gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
648 1 hiro
        gtk_table_set_row_spacings(GTK_TABLE(table), 8);
649 1 hiro
        gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
650 1 hiro
651 1 hiro
        /* First row */
652 1 hiro
        top = 0;
653 1 hiro
        label = gtk_label_new(_("Address Book :"));
654 1 hiro
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
655 1 hiro
        gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
656 1 hiro
657 1 hiro
        labelBook = gtk_label_new("");
658 1 hiro
        gtk_table_attach(GTK_TABLE(table), labelBook, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
659 1 hiro
        gtk_misc_set_alignment(GTK_MISC(labelBook), 0, 0.5);
660 1 hiro
661 1 hiro
        /* Second row */
662 1 hiro
        top++;
663 1 hiro
        label = gtk_label_new(_("File Name :"));
664 1 hiro
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
665 1 hiro
        gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
666 1 hiro
667 1 hiro
        labelFile = gtk_label_new("");
668 1 hiro
        gtk_table_attach(GTK_TABLE(table), labelFile, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
669 1 hiro
        gtk_misc_set_alignment(GTK_MISC(labelFile), 0, 0.5);
670 1 hiro
671 1 hiro
        /* Third row */
672 1 hiro
        top++;
673 1 hiro
        label = gtk_label_new(_("Records :"));
674 1 hiro
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
675 1 hiro
        gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
676 1 hiro
677 1 hiro
        labelRecs = gtk_label_new("");
678 1 hiro
        gtk_table_attach(GTK_TABLE(table), labelRecs, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
679 1 hiro
        gtk_misc_set_alignment(GTK_MISC(labelRecs), 0, 0.5);
680 1 hiro
681 1 hiro
        impldif_dlg.labelBook    = labelBook;
682 1 hiro
        impldif_dlg.labelFile    = labelFile;
683 1 hiro
        impldif_dlg.labelRecords = labelRecs;
684 1 hiro
}
685 1 hiro
686 1 hiro
static void imp_ldif_dialog_create() {
687 1 hiro
        GtkWidget *window;
688 1 hiro
        GtkWidget *vbox;
689 1 hiro
        GtkWidget *vnbox;
690 1 hiro
        GtkWidget *notebook;
691 1 hiro
        GtkWidget *hbbox;
692 1 hiro
        GtkWidget *btnPrev;
693 1 hiro
        GtkWidget *btnNext;
694 1 hiro
        GtkWidget *btnCancel;
695 1 hiro
        GtkWidget *hsbox;
696 1 hiro
        GtkWidget *statusbar;
697 1 hiro
698 1 hiro
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
699 1 hiro
        gtk_widget_set_size_request(window, IMPORTLDIF_WIDTH, IMPORTLDIF_HEIGHT );
700 1 hiro
        gtk_container_set_border_width( GTK_CONTAINER(window), 0 );
701 1 hiro
        gtk_window_set_title( GTK_WINDOW(window), _("Import LDIF file into Address Book") );
702 1 hiro
        gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
703 1 hiro
        gtk_window_set_modal(GTK_WINDOW(window), TRUE);
704 1 hiro
        g_signal_connect(G_OBJECT(window), "delete_event",
705 1 hiro
                         G_CALLBACK(imp_ldif_delete_event), NULL);
706 1 hiro
        g_signal_connect(G_OBJECT(window), "key_press_event",
707 1 hiro
                         G_CALLBACK(imp_ldif_key_pressed), NULL);
708 1620 hiro
        MANAGE_WINDOW_SIGNALS_CONNECT(window);
709 1 hiro
710 1 hiro
        vbox = gtk_vbox_new(FALSE, 4);
711 1 hiro
        gtk_widget_show(vbox);
712 1 hiro
        gtk_container_add(GTK_CONTAINER(window), vbox);
713 1 hiro
714 1 hiro
        vnbox = gtk_vbox_new(FALSE, 4);
715 1 hiro
        gtk_container_set_border_width(GTK_CONTAINER(vnbox), 4);
716 1 hiro
        gtk_widget_show(vnbox);
717 1 hiro
        gtk_box_pack_start(GTK_BOX(vbox), vnbox, TRUE, TRUE, 0);
718 1 hiro
719 1 hiro
        /* Notebook */
720 1 hiro
        notebook = gtk_notebook_new();
721 1 hiro
        gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), FALSE );
722 1 hiro
        gtk_widget_show(notebook);
723 1 hiro
        gtk_box_pack_start(GTK_BOX(vnbox), notebook, TRUE, TRUE, 0);
724 1 hiro
        gtk_container_set_border_width(GTK_CONTAINER(notebook), 6);
725 1 hiro
726 1 hiro
        /* Status line */
727 1 hiro
        hsbox = gtk_hbox_new(FALSE, 0);
728 1040 hiro
        gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, 0);
729 1 hiro
        statusbar = gtk_statusbar_new();
730 1040 hiro
        gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, 0);
731 1 hiro
732 1 hiro
        /* Button panel */
733 1607 hiro
        gtkut_stock_button_set_create(&hbbox, &btnNext, _("Next"),
734 1607 hiro
                                      &btnPrev, _("Prev"),
735 31 hiro
                                      &btnCancel, GTK_STOCK_CANCEL);
736 1607 hiro
        gtk_button_box_set_child_secondary(GTK_BUTTON_BOX(hbbox), btnCancel,
737 1607 hiro
                                           TRUE);
738 1607 hiro
        gtkut_box_set_reverse_order(GTK_BOX(hbbox), FALSE);
739 1 hiro
        gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
740 1 hiro
        gtk_container_set_border_width(GTK_CONTAINER(hbbox), 2);
741 1 hiro
        gtk_widget_grab_default(btnNext);
742 1 hiro
743 1 hiro
        /* Button handlers */
744 1 hiro
        g_signal_connect(G_OBJECT(btnPrev), "clicked",
745 1 hiro
                         G_CALLBACK(imp_ldif_prev), NULL);
746 1 hiro
        g_signal_connect(G_OBJECT(btnNext), "clicked",
747 1 hiro
                         G_CALLBACK(imp_ldif_next), NULL);
748 1 hiro
        g_signal_connect(G_OBJECT(btnCancel), "clicked",
749 1 hiro
                         G_CALLBACK(imp_ldif_cancel), NULL);
750 1 hiro
751 1 hiro
        gtk_widget_show_all(vbox);
752 1 hiro
753 1 hiro
        impldif_dlg.window     = window;
754 1 hiro
        impldif_dlg.notebook   = notebook;
755 1 hiro
        impldif_dlg.btnPrev    = btnPrev;
756 1 hiro
        impldif_dlg.btnNext    = btnNext;
757 1 hiro
        impldif_dlg.btnCancel  = btnCancel;
758 1 hiro
        impldif_dlg.statusbar  = statusbar;
759 1 hiro
        impldif_dlg.status_cid = gtk_statusbar_get_context_id(
760 1 hiro
                        GTK_STATUSBAR(statusbar), "Import LDIF Dialog" );
761 1 hiro
762 1 hiro
}
763 1 hiro
764 1 hiro
static void imp_ldif_create() {
765 1 hiro
        imp_ldif_dialog_create();
766 1 hiro
        imp_ldif_page_file( PAGE_FILE_INFO, _( "File Info" ) );
767 1 hiro
        imp_ldif_page_fields( PAGE_ATTRIBUTES, _( "Attributes" ) );
768 1 hiro
        imp_ldif_page_finish( PAGE_FINISH, _( "Finish" ) );
769 1 hiro
        gtk_widget_show_all( impldif_dlg.window );
770 1 hiro
}
771 1 hiro
772 1 hiro
AddressBookFile *addressbook_imp_ldif( AddressIndex *addrIndex ) {
773 1 hiro
        _importedBook_ = NULL;
774 1 hiro
        _imp_addressIndex_ = addrIndex;
775 1 hiro
776 1 hiro
        if( ! impldif_dlg.window )
777 1 hiro
                imp_ldif_create();
778 1 hiro
        impldif_dlg.cancelled = FALSE;
779 1 hiro
        manage_window_set_transient(GTK_WINDOW(impldif_dlg.window));
780 1 hiro
        gtk_widget_grab_default(impldif_dlg.btnNext);
781 1 hiro
782 1 hiro
        gtk_entry_set_text( GTK_ENTRY(impldif_dlg.name_entry), IMPORTLDIF_GUESS_NAME );
783 1 hiro
        gtk_entry_set_text( GTK_ENTRY(impldif_dlg.file_entry), "" );
784 1 hiro
        gtk_label_set_text( GTK_LABEL(impldif_dlg.name_ldif), "" );
785 1 hiro
        gtk_entry_set_text( GTK_ENTRY(impldif_dlg.name_attrib), "" );
786 1 hiro
        gtk_clist_clear( GTK_CLIST(impldif_dlg.clist_field) );
787 1 hiro
        gtk_notebook_set_current_page( GTK_NOTEBOOK(impldif_dlg.notebook), PAGE_FILE_INFO );
788 1 hiro
        gtk_widget_set_sensitive( impldif_dlg.btnPrev, FALSE );
789 1 hiro
        gtk_widget_set_sensitive( impldif_dlg.btnNext, TRUE );
790 1152 hiro
        gtk_button_set_label( GTK_BUTTON(impldif_dlg.btnCancel), GTK_STOCK_CANCEL );
791 1 hiro
        stock_pixmap_gdk( impldif_dlg.window, STOCK_PIXMAP_MARK,
792 1 hiro
                          &markxpm, &markxpmmask );
793 1 hiro
        imp_ldif_message();
794 1 hiro
        gtk_widget_grab_focus(impldif_dlg.file_entry);
795 1 hiro
796 1 hiro
        impldif_dlg.rowIndSelect = -1;
797 1 hiro
        impldif_dlg.rowCount = 0;
798 1 hiro
        g_free( impldif_dlg.nameBook );
799 1 hiro
        g_free( impldif_dlg.fileName );
800 1 hiro
        impldif_dlg.nameBook = NULL;
801 1 hiro
        impldif_dlg.fileName = NULL;
802 1 hiro
803 1 hiro
        _ldifFile_ = ldif_create();
804 1620 hiro
805 1620 hiro
        gtk_widget_show(impldif_dlg.window);
806 1620 hiro
807 1 hiro
        gtk_main();
808 1 hiro
        gtk_widget_hide(impldif_dlg.window);
809 1 hiro
        ldif_free( _ldifFile_ );
810 1 hiro
        _ldifFile_ = NULL;
811 1 hiro
        _imp_addressIndex_ = NULL;
812 1 hiro
813 1 hiro
        g_free( impldif_dlg.nameBook );
814 1 hiro
        g_free( impldif_dlg.fileName );
815 1 hiro
        impldif_dlg.nameBook = NULL;
816 1 hiro
        impldif_dlg.fileName = NULL;
817 1 hiro
818 1 hiro
        if( impldif_dlg.cancelled == TRUE ) return NULL;
819 1 hiro
        return _importedBook_;
820 1 hiro
}
821 1 hiro
822 2672 hiro
AddressBookFile *addressbook_imp_ldif_file( AddressIndex *addrIndex,
823 2672 hiro
                                            const gchar *file,
824 2672 hiro
                                            const gchar *book_name ) {
825 2672 hiro
        gchar *fsfile;
826 2672 hiro
        GList *node, *list;
827 2759 hiro
        gboolean ret = FALSE;
828 2672 hiro
829 2672 hiro
        g_return_val_if_fail(addrIndex != NULL, NULL);
830 2672 hiro
        g_return_val_if_fail(file != NULL, NULL);
831 2672 hiro
        g_return_val_if_fail(book_name != NULL, NULL);
832 2672 hiro
833 2672 hiro
        debug_print("addressbook_imp_ldif_file: file: %s name: %s\n",
834 2672 hiro
                    file, book_name);
835 2672 hiro
836 2672 hiro
        _importedBook_ = NULL;
837 2672 hiro
        _imp_addressIndex_ = addrIndex;
838 2672 hiro
        _ldifFile_ = ldif_create();
839 2672 hiro
840 2672 hiro
        fsfile = conv_filename_from_utf8( file );
841 2672 hiro
        ldif_set_file(_ldifFile_, fsfile);
842 2672 hiro
        g_free( fsfile );
843 2672 hiro
844 2672 hiro
        if( ldif_read_tags( _ldifFile_ ) != MGU_SUCCESS )
845 2672 hiro
                goto finish;
846 2672 hiro
        list = ldif_get_fieldlist( _ldifFile_ );
847 2672 hiro
        node = list;
848 2672 hiro
        while( node ) {
849 2672 hiro
                Ldif_FieldRec *rec = node->data;
850 2672 hiro
                if( ! rec->reserved ) {
851 2672 hiro
                        if( g_ascii_strcasecmp( rec->tagName, "dn" ) != 0 ) {
852 2672 hiro
                                rec->selected = TRUE;
853 2672 hiro
                        }
854 2672 hiro
                }
855 2672 hiro
                node = g_list_next( node );
856 2672 hiro
        }
857 2672 hiro
        g_list_free( list );
858 2672 hiro
859 2672 hiro
        g_free( impldif_dlg.nameBook );
860 2672 hiro
        impldif_dlg.nameBook = g_strdup(book_name);
861 2672 hiro
862 2672 hiro
        ret = imp_ldif_field_move();
863 2672 hiro
864 2672 hiro
        g_free( impldif_dlg.nameBook );
865 2672 hiro
        impldif_dlg.nameBook = NULL;
866 2672 hiro
867 2672 hiro
finish:
868 2672 hiro
        ldif_free( _ldifFile_ );
869 2672 hiro
        _ldifFile_ = NULL;
870 2672 hiro
        _imp_addressIndex_ = NULL;
871 2672 hiro
872 2672 hiro
        if (ret)
873 2672 hiro
                debug_print("addressbook_imp_ldif_file: import succeeded\n");
874 2672 hiro
875 2672 hiro
        return _importedBook_;
876 2672 hiro
}
877 2672 hiro
878 1 hiro
/*
879 1 hiro
* End of Source.
880 1 hiro
*/