Statistics
| Revision:

root / src / importcsv.c @ 1609

History | View | Annotate | Download (26.4 kB)

1 1600 hiro
/*
2 1600 hiro
 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 1600 hiro
 * Copyright (C) 1999-2007 Hiroyuki Yamamoto
4 1600 hiro
 *
5 1600 hiro
 * This program is free software; you can redistribute it and/or modify
6 1600 hiro
 * it under the terms of the GNU General Public License as published by
7 1600 hiro
 * the Free Software Foundation; either version 2 of the License, or
8 1600 hiro
 * (at your option) any later version.
9 1600 hiro
 *
10 1600 hiro
 * This program is distributed in the hope that it will be useful,
11 1600 hiro
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 1600 hiro
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 1600 hiro
 * GNU General Public License for more details.
14 1600 hiro
 *
15 1600 hiro
 * You should have received a copy of the GNU General Public License
16 1600 hiro
 * along with this program; if not, write to the Free Software
17 1600 hiro
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 1600 hiro
 */
19 1600 hiro
20 1600 hiro
/*
21 1600 hiro
 * Edit VCard address book data.
22 1600 hiro
 */
23 1600 hiro
24 1600 hiro
#ifdef HAVE_CONFIG_H
25 1600 hiro
#  include "config.h"
26 1600 hiro
#endif
27 1600 hiro
28 1600 hiro
#include "defs.h"
29 1600 hiro
30 1600 hiro
#include <glib.h>
31 1600 hiro
#include <glib/gi18n.h>
32 1600 hiro
#include <gdk/gdkkeysyms.h>
33 1600 hiro
#include <gtk/gtkwindow.h>
34 1600 hiro
#include <gtk/gtksignal.h>
35 1600 hiro
#include <gtk/gtkvbox.h>
36 1600 hiro
#include <gtk/gtklabel.h>
37 1600 hiro
#include <gtk/gtkentry.h>
38 1600 hiro
#include <gtk/gtktable.h>
39 1600 hiro
#include <gtk/gtkbutton.h>
40 1600 hiro
#include <gtk/gtkhbbox.h>
41 1600 hiro
#include <gtk/gtkcheckbutton.h>
42 1600 hiro
#include <gtk/gtktogglebutton.h>
43 1600 hiro
#include <gtk/gtkstatusbar.h>
44 1600 hiro
#include <gtk/gtknotebook.h>
45 1600 hiro
#include <gtk/gtkstock.h>
46 1600 hiro
47 1600 hiro
#include <stdio.h>
48 1600 hiro
49 1600 hiro
#include "addrbook.h"
50 1600 hiro
#include "addressbook.h"
51 1600 hiro
#include "addressitem.h"
52 1603 hiro
#include "filesel.h"
53 1600 hiro
#include "gtkutils.h"
54 1600 hiro
#include "stock_pixmap.h"
55 1600 hiro
#include "prefs_common.h"
56 1600 hiro
#include "manage_window.h"
57 1600 hiro
#include "mgutils.h"
58 1600 hiro
#include "importcsv.h"
59 1604 hiro
#include "codeconv.h"
60 1600 hiro
#include "utils.h"
61 1600 hiro
62 1600 hiro
#define IMPORTCSV_GUESS_NAME "CSV Import"
63 1600 hiro
64 1600 hiro
#define PAGE_FILE_INFO             0
65 1600 hiro
#define PAGE_ATTRIBUTES            1
66 1600 hiro
#define PAGE_FINISH                2
67 1600 hiro
68 1608 hiro
#define IMPORTCSV_WIDTH           420
69 1608 hiro
#define IMPORTCSV_HEIGHT          320
70 1600 hiro
71 1600 hiro
#define FIELDS_N_COLS              3
72 1600 hiro
#define FIELDS_COL_WIDTH_SELECT    10
73 1600 hiro
#define FIELDS_COL_WIDTH_FIELD     140
74 1600 hiro
#define FIELDS_COL_WIDTH_ATTRIB    140
75 1600 hiro
76 1600 hiro
typedef enum {
77 1600 hiro
        FIELD_COL_SELECT  = 0,
78 1600 hiro
        FIELD_COL_FIELD   = 1,
79 1600 hiro
        FIELD_COL_ATTRIB  = 2
80 1600 hiro
} ImpCSV_FieldColPos;
81 1600 hiro
82 1607 hiro
static struct _ImpCSVDlg {
83 1600 hiro
        GtkWidget *window;
84 1600 hiro
        GtkWidget *notebook;
85 1600 hiro
        GtkWidget *file_entry;
86 1600 hiro
        GtkWidget *name_entry;
87 1600 hiro
        GtkWidget *clist_field;
88 1600 hiro
        GtkWidget *check_select;
89 1600 hiro
        GtkWidget *labelBook;
90 1600 hiro
        GtkWidget *labelFile;
91 1600 hiro
        GtkWidget *labelRecords;
92 1600 hiro
        GtkWidget *btnPrev;
93 1600 hiro
        GtkWidget *btnNext;
94 1600 hiro
        GtkWidget *btnCancel;
95 1600 hiro
        GtkWidget *statusbar;
96 1600 hiro
        gint      status_cid;
97 1600 hiro
        gint      rowIndSelect;
98 1600 hiro
        gint      rowCount;
99 1600 hiro
        gchar     *nameBook;
100 1600 hiro
        gchar     *fileName;
101 1600 hiro
        gboolean  cancelled;
102 1600 hiro
} impcsv_dlg;
103 1600 hiro
104 1600 hiro
typedef enum {
105 1600 hiro
        ATTR_FIRST_NAME,
106 1600 hiro
        ATTR_LAST_NAME,
107 1600 hiro
        ATTR_DISPLAY_NAME,
108 1600 hiro
        ATTR_NICK_NAME,
109 1600 hiro
        ATTR_EMAIL_ADDRESS,
110 1609 hiro
        ATTR_REMARKS,
111 1600 hiro
112 1600 hiro
        N_CSV_ATTRIB
113 1600 hiro
} ImpCSVAttribIndex;
114 1600 hiro
115 1600 hiro
static struct _ImpCSVAttrib {
116 1600 hiro
        gchar *name;
117 1607 hiro
        gchar *value;
118 1600 hiro
        gint col;
119 1600 hiro
        gboolean enabled;
120 1600 hiro
} imp_csv_attrib[] = {
121 1607 hiro
        {N_("First Name"),        NULL, 0, TRUE},
122 1607 hiro
        {N_("Last Name"),        NULL, 1, TRUE},
123 1607 hiro
        {N_("Display Name"),        NULL, 2, TRUE},
124 1607 hiro
        {N_("Nick Name"),        NULL, 3, TRUE},
125 1609 hiro
        {N_("E-Mail Address"),        NULL, 4, TRUE},
126 1609 hiro
        {N_("Remarks"),                NULL, 5, TRUE}
127 1600 hiro
};
128 1600 hiro
129 1600 hiro
static AddressBookFile *_importedBook_;
130 1600 hiro
static AddressIndex *_imp_addressIndex_;
131 1600 hiro
static gint importCount = 0;
132 1600 hiro
static gint result;
133 1600 hiro
134 1600 hiro
static GdkPixmap *markxpm;
135 1600 hiro
static GdkBitmap *markxpmmask;
136 1600 hiro
137 1600 hiro
static void imp_csv_status_show( gchar *msg ) {
138 1600 hiro
        if( impcsv_dlg.statusbar != NULL ) {
139 1600 hiro
                gtk_statusbar_pop( GTK_STATUSBAR(impcsv_dlg.statusbar), impcsv_dlg.status_cid );
140 1600 hiro
                if( msg ) {
141 1600 hiro
                        gtk_statusbar_push( GTK_STATUSBAR(impcsv_dlg.statusbar), impcsv_dlg.status_cid, msg );
142 1600 hiro
                }
143 1600 hiro
        }
144 1600 hiro
}
145 1600 hiro
146 1600 hiro
static void imp_csv_message( void ) {
147 1600 hiro
        gchar *sMsg = NULL;
148 1600 hiro
        gint pageNum;
149 1600 hiro
150 1600 hiro
        pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(impcsv_dlg.notebook) );
151 1600 hiro
        if( pageNum == PAGE_FILE_INFO ) {
152 1600 hiro
                sMsg = _( "Please specify address book name and file to import." );
153 1600 hiro
        }
154 1600 hiro
        else if( pageNum == PAGE_ATTRIBUTES ) {
155 1600 hiro
                sMsg = _( "Select and reorder CSV field names to import." );
156 1600 hiro
        }
157 1600 hiro
        else if( pageNum == PAGE_FINISH ) {
158 1600 hiro
                sMsg = _( "File imported." );
159 1600 hiro
        }
160 1600 hiro
        imp_csv_status_show( sMsg );
161 1600 hiro
}
162 1600 hiro
163 1600 hiro
static gchar *imp_csv_guess_file( AddressBookFile *abf ) {
164 1600 hiro
        gchar *newFile = NULL;
165 1600 hiro
        GList *fileList = NULL;
166 1600 hiro
        gint fileNum = 1;
167 1600 hiro
        fileList = addrbook_get_bookfile_list( abf );
168 1600 hiro
        if( fileList ) {
169 1600 hiro
                fileNum = 1 + abf->maxValue;
170 1600 hiro
        }
171 1600 hiro
        newFile = addrbook_gen_new_file_name( fileNum );
172 1600 hiro
        g_list_free( fileList );
173 1600 hiro
        fileList = NULL;
174 1600 hiro
        return newFile;
175 1600 hiro
}
176 1600 hiro
177 1603 hiro
static gboolean imp_csv_load_fields( gchar *sFile ) {
178 1600 hiro
        GtkCList *clist = GTK_CLIST(impcsv_dlg.clist_field);
179 1600 hiro
        FILE *fp;
180 1600 hiro
        gchar buf[BUFFSIZE];
181 1600 hiro
        CharSet enc;
182 1600 hiro
183 1603 hiro
        g_return_val_if_fail(sFile != NULL, FALSE);
184 1600 hiro
185 1600 hiro
        impcsv_dlg.rowIndSelect = -1;
186 1600 hiro
        impcsv_dlg.rowCount = 0;
187 1600 hiro
        gtk_clist_clear( clist );
188 1600 hiro
189 1600 hiro
        enc = conv_check_file_encoding(sFile);
190 1600 hiro
191 1600 hiro
        if ((fp = g_fopen(sFile, "rb")) == NULL) {
192 1603 hiro
                return FALSE;
193 1600 hiro
        }
194 1600 hiro
195 1606 hiro
        if (fgets(buf, sizeof(buf), fp) != NULL) {
196 1600 hiro
                gchar *str;
197 1606 hiro
                gchar **strv;
198 1606 hiro
                gchar *text[ FIELDS_N_COLS ];
199 1606 hiro
                gint i;
200 1606 hiro
                guint fields_len;
201 1606 hiro
                guint data_len = 0;
202 1606 hiro
                guint len;
203 1607 hiro
                gint row;
204 1600 hiro
205 1600 hiro
                strretchomp(buf);
206 1600 hiro
                if (enc == C_UTF_8)
207 1600 hiro
                        str = g_strdup(buf);
208 1600 hiro
                else
209 1600 hiro
                        str = conv_localetodisp(buf, NULL);
210 1600 hiro
                strv = g_strsplit(str, ",", 0);
211 1606 hiro
                fields_len = sizeof(imp_csv_attrib) / sizeof(imp_csv_attrib[0]);
212 1606 hiro
                while (strv[data_len])
213 1606 hiro
                        ++data_len;
214 1606 hiro
                len = MAX(fields_len, data_len);
215 1601 hiro
216 1606 hiro
                for (i = 0; i < len; i++) {
217 1600 hiro
                        text[ FIELD_COL_SELECT ] = "";
218 1606 hiro
                        if (i < data_len)
219 1606 hiro
                                text[ FIELD_COL_FIELD  ] = strv[i];
220 1606 hiro
                        else
221 1606 hiro
                                text[ FIELD_COL_FIELD  ] = "";
222 1606 hiro
                        if (i < fields_len)
223 1606 hiro
                                text[ FIELD_COL_ATTRIB ] =
224 1606 hiro
                                        gettext(imp_csv_attrib[i].name);
225 1606 hiro
                        else
226 1606 hiro
                                text[ FIELD_COL_ATTRIB ] = "";
227 1607 hiro
                        row = gtk_clist_append(clist, text);
228 1607 hiro
                        if (i < fields_len) {
229 1607 hiro
                                imp_csv_attrib[i].value = NULL;
230 1607 hiro
                                imp_csv_attrib[i].col = row;
231 1607 hiro
                                gtk_clist_set_row_data
232 1607 hiro
                                        (clist, row, &imp_csv_attrib[i]);
233 1608 hiro
                                if (imp_csv_attrib[i].enabled)
234 1608 hiro
                                        gtk_clist_set_pixmap(clist, row, FIELD_COL_SELECT, markxpm, markxpmmask);
235 1607 hiro
                        }
236 1600 hiro
                }
237 1601 hiro
                g_strfreev(strv);
238 1600 hiro
                g_free(str);
239 1600 hiro
        }
240 1600 hiro
241 1600 hiro
        fclose(fp);
242 1603 hiro
243 1603 hiro
        return TRUE;
244 1600 hiro
}
245 1600 hiro
246 1608 hiro
static void imp_csv_field_list_selected( GtkCList *clist, gint row, gint column, GdkEvent *event ) {
247 1608 hiro
        if (event && event->type == GDK_2BUTTON_PRESS)
248 1608 hiro
                return;
249 1600 hiro
250 1608 hiro
        if (column == FIELD_COL_SELECT) {
251 1608 hiro
                struct _ImpCSVAttrib *attr;
252 1608 hiro
                attr = gtk_clist_get_row_data( clist, row );
253 1608 hiro
                if (attr) {
254 1608 hiro
                        attr->enabled ^= TRUE;
255 1608 hiro
                        if (attr->enabled)
256 1608 hiro
                                gtk_clist_set_pixmap(clist, row, FIELD_COL_SELECT, markxpm, markxpmmask);
257 1608 hiro
                        else
258 1608 hiro
                                gtk_clist_set_text(clist, row, FIELD_COL_SELECT, "");
259 1608 hiro
                }
260 1608 hiro
        }
261 1600 hiro
}
262 1600 hiro
263 1607 hiro
static void imp_csv_field_list_up( GtkWidget *button, gpointer data ) {
264 1607 hiro
        GtkCList *clist = GTK_CLIST(impcsv_dlg.clist_field);
265 1607 hiro
        gchar *text;
266 1607 hiro
        gint row;
267 1607 hiro
        struct _ImpCSVAttrib *src_attr;
268 1607 hiro
        struct _ImpCSVAttrib *dest_attr;
269 1607 hiro
        gchar *src_text;
270 1607 hiro
        gchar *dest_text;
271 1607 hiro
272 1607 hiro
        if (!clist->selection) return;
273 1607 hiro
274 1607 hiro
        row = GPOINTER_TO_INT( clist->selection->data );
275 1609 hiro
        if ( row > 0 && row < clist->rows ) {
276 1607 hiro
                gtk_clist_freeze( clist );
277 1607 hiro
278 1607 hiro
                src_attr = gtk_clist_get_row_data( clist, row );
279 1607 hiro
                dest_attr = gtk_clist_get_row_data( clist, row - 1 );
280 1607 hiro
281 1607 hiro
                gtk_clist_row_move( clist, row, row - 1 );
282 1607 hiro
283 1607 hiro
                gtk_clist_get_text( clist, row, FIELD_COL_FIELD, &text );
284 1607 hiro
                src_text = g_strdup( text );
285 1607 hiro
                gtk_clist_get_text( clist, row - 1, FIELD_COL_FIELD, &text );
286 1607 hiro
                dest_text = g_strdup( text );
287 1607 hiro
                gtk_clist_set_text( clist, row - 1, FIELD_COL_FIELD, src_text );
288 1607 hiro
                gtk_clist_set_text( clist, row, FIELD_COL_FIELD, dest_text );
289 1607 hiro
                g_free( dest_text );
290 1607 hiro
                g_free( src_text );
291 1607 hiro
292 1607 hiro
                if ( src_attr )
293 1607 hiro
                        src_attr->col = row - 1;
294 1607 hiro
                if ( dest_attr )
295 1607 hiro
                        dest_attr->col = row;
296 1607 hiro
297 1607 hiro
                gtk_clist_thaw( clist );
298 1607 hiro
        }
299 1607 hiro
}
300 1607 hiro
301 1607 hiro
static void imp_csv_field_list_down( GtkWidget *button, gpointer data ) {
302 1607 hiro
        GtkCList *clist = GTK_CLIST(impcsv_dlg.clist_field);
303 1607 hiro
        gchar *text;
304 1607 hiro
        gint row;
305 1607 hiro
        struct _ImpCSVAttrib *src_attr;
306 1607 hiro
        struct _ImpCSVAttrib *dest_attr;
307 1607 hiro
        gchar *src_text;
308 1607 hiro
        gchar *dest_text;
309 1607 hiro
310 1607 hiro
        if (!clist->selection) return;
311 1607 hiro
312 1607 hiro
        row = GPOINTER_TO_INT( clist->selection->data );
313 1609 hiro
        if ( row >= 0 && row < clist->rows - 1 ) {
314 1607 hiro
                gtk_clist_freeze( clist );
315 1607 hiro
316 1607 hiro
                src_attr = gtk_clist_get_row_data( clist, row );
317 1607 hiro
                dest_attr = gtk_clist_get_row_data( clist, row + 1 );
318 1607 hiro
319 1607 hiro
                gtk_clist_row_move( clist, row, row + 1 );
320 1607 hiro
321 1607 hiro
                gtk_clist_get_text( clist, row, FIELD_COL_FIELD, &text );
322 1607 hiro
                src_text = g_strdup( text );
323 1607 hiro
                gtk_clist_get_text( clist, row + 1, FIELD_COL_FIELD, &text );
324 1607 hiro
                dest_text = g_strdup( text );
325 1607 hiro
                gtk_clist_set_text( clist, row + 1, FIELD_COL_FIELD, src_text );
326 1607 hiro
                gtk_clist_set_text( clist, row, FIELD_COL_FIELD, dest_text );
327 1607 hiro
                g_free( dest_text );
328 1607 hiro
                g_free( src_text );
329 1607 hiro
330 1607 hiro
                if ( src_attr )
331 1607 hiro
                        src_attr->col = row + 1;
332 1607 hiro
                if ( dest_attr )
333 1607 hiro
                        dest_attr->col = row;
334 1607 hiro
335 1607 hiro
                gtk_clist_thaw( clist );
336 1607 hiro
        }
337 1607 hiro
}
338 1607 hiro
339 1600 hiro
static gint imp_csv_import_data( gchar *csvFile, AddressCache *cache ) {
340 1600 hiro
        FILE *fp;
341 1600 hiro
        gchar buf[BUFFSIZE];
342 1600 hiro
        gint i;
343 1600 hiro
        gchar **strv;
344 1601 hiro
        CharSet enc;
345 1607 hiro
        guint fields_len;
346 1600 hiro
        gchar *firstName = NULL;
347 1600 hiro
        gchar *lastName = NULL;
348 1600 hiro
        gchar *fullName = NULL;
349 1600 hiro
        gchar *nickName = NULL;
350 1600 hiro
        gchar *address = NULL;
351 1609 hiro
        gchar *remarks = NULL;
352 1600 hiro
        ItemPerson *person;
353 1600 hiro
        ItemEMail *email;
354 1600 hiro
        gint count = 0;
355 1600 hiro
356 1600 hiro
        g_return_val_if_fail( csvFile != NULL, MGU_BAD_ARGS );
357 1600 hiro
358 1600 hiro
        addrcache_clear( cache );
359 1600 hiro
        cache->dataRead = FALSE;
360 1600 hiro
361 1601 hiro
        enc = conv_check_file_encoding(csvFile);
362 1601 hiro
363 1600 hiro
        if ((fp = g_fopen(csvFile, "rb")) == NULL) {
364 1600 hiro
                return;
365 1600 hiro
        }
366 1600 hiro
367 1607 hiro
        fields_len = sizeof(imp_csv_attrib) / sizeof(imp_csv_attrib[0]);
368 1607 hiro
369 1600 hiro
        while (fgets(buf, sizeof(buf), fp) != NULL) {
370 1601 hiro
                gchar *str;
371 1607 hiro
                guint col, cols = 0;
372 1601 hiro
373 1600 hiro
                strretchomp(buf);
374 1601 hiro
                if (enc == C_UTF_8)
375 1601 hiro
                        str = g_strdup(buf);
376 1601 hiro
                else
377 1601 hiro
                        str = conv_localetodisp(buf, NULL);
378 1601 hiro
                strv = g_strsplit(str, ",", 0);
379 1607 hiro
                while (strv[cols])
380 1607 hiro
                        ++cols;
381 1600 hiro
382 1607 hiro
                for (i = 0; i < fields_len; i++) {
383 1607 hiro
                        if (!imp_csv_attrib[i].enabled)
384 1607 hiro
                                continue;
385 1607 hiro
                        col = imp_csv_attrib[i].col;
386 1607 hiro
                        if (col >= cols || !*strv[col])
387 1607 hiro
                                continue;
388 1607 hiro
                        imp_csv_attrib[i].value = strv[col];
389 1600 hiro
                }
390 1600 hiro
391 1607 hiro
                firstName = imp_csv_attrib[ATTR_FIRST_NAME].value;
392 1607 hiro
                lastName  = imp_csv_attrib[ATTR_LAST_NAME].value;
393 1607 hiro
                fullName  = imp_csv_attrib[ATTR_DISPLAY_NAME].value;
394 1607 hiro
                nickName  = imp_csv_attrib[ATTR_NICK_NAME].value;
395 1607 hiro
                address   = imp_csv_attrib[ATTR_EMAIL_ADDRESS].value;
396 1609 hiro
                remarks   = imp_csv_attrib[ATTR_REMARKS].value;
397 1607 hiro
398 1607 hiro
                if (!fullName && !firstName && !lastName && address)
399 1607 hiro
                        fullName = address;
400 1607 hiro
401 1600 hiro
                person = addritem_create_item_person();
402 1600 hiro
                addritem_person_set_common_name( person, fullName);
403 1600 hiro
                addritem_person_set_first_name( person, firstName);
404 1600 hiro
                addritem_person_set_last_name( person, lastName);
405 1600 hiro
                addritem_person_set_nick_name( person, nickName);
406 1600 hiro
                addrcache_id_person( cache, person );
407 1600 hiro
                addrcache_add_person( cache, person );
408 1600 hiro
409 1607 hiro
                if (address) {
410 1600 hiro
                        email = addritem_create_item_email();
411 1600 hiro
                        addritem_email_set_address( email, address );
412 1609 hiro
                        addritem_email_set_remarks( email, remarks );
413 1600 hiro
                        addrcache_id_email( cache, email );
414 1600 hiro
                        addrcache_person_add_email( cache, person, email );
415 1600 hiro
                }
416 1600 hiro
417 1607 hiro
                for (i = 0; i < fields_len; i++)
418 1607 hiro
                        imp_csv_attrib[i].value = NULL;
419 1600 hiro
                g_strfreev(strv);
420 1601 hiro
                g_free(str);
421 1600 hiro
422 1600 hiro
                count++;
423 1600 hiro
        }
424 1600 hiro
425 1600 hiro
        fclose(fp);
426 1600 hiro
427 1600 hiro
        cache->modified = FALSE;
428 1600 hiro
        cache->dataRead = TRUE;
429 1600 hiro
        importCount = count;
430 1600 hiro
431 1600 hiro
        return MGU_SUCCESS;
432 1600 hiro
}
433 1600 hiro
434 1600 hiro
/*
435 1600 hiro
* Move off fields page.
436 1600 hiro
* return: TRUE if OK to move off page.
437 1600 hiro
*/
438 1600 hiro
static gboolean imp_csv_field_move() {
439 1600 hiro
        gboolean retVal = FALSE;
440 1600 hiro
        gchar *newFile;
441 1600 hiro
        AddressBookFile *abf = NULL;
442 1600 hiro
443 1600 hiro
        if( _importedBook_ ) {
444 1600 hiro
                addrbook_free_book( _importedBook_ );
445 1600 hiro
        }
446 1600 hiro
447 1600 hiro
        abf = addrbook_create_book();
448 1600 hiro
        addrbook_set_path( abf, _imp_addressIndex_->filePath );
449 1600 hiro
        addrbook_set_name( abf, impcsv_dlg.nameBook );
450 1600 hiro
        newFile = imp_csv_guess_file( abf );
451 1600 hiro
        addrbook_set_file( abf, newFile );
452 1600 hiro
        g_free( newFile );
453 1600 hiro
454 1600 hiro
        /* Import data into file */
455 1600 hiro
        if( imp_csv_import_data( impcsv_dlg.fileName, abf->addressCache ) == MGU_SUCCESS ) {
456 1600 hiro
                addrbook_save_data( abf );
457 1600 hiro
                abf->dirtyFlag = TRUE;
458 1600 hiro
                _importedBook_ = abf;
459 1600 hiro
                retVal = TRUE;
460 1600 hiro
        }
461 1600 hiro
        else {
462 1600 hiro
                addrbook_free_book( abf );
463 1600 hiro
        }
464 1600 hiro
465 1600 hiro
        return retVal;
466 1600 hiro
}
467 1600 hiro
468 1600 hiro
/*
469 1600 hiro
* Move off fields page.
470 1600 hiro
* return: TRUE if OK to move off page.
471 1600 hiro
*/
472 1600 hiro
static gboolean imp_csv_file_move() {
473 1600 hiro
        gboolean retVal = FALSE;
474 1600 hiro
        gchar *sName;
475 1600 hiro
        gchar *sFile;
476 1600 hiro
        gchar *sMsg = NULL;
477 1600 hiro
        gboolean errFlag = FALSE;
478 1600 hiro
479 1600 hiro
        sFile = gtk_editable_get_chars( GTK_EDITABLE(impcsv_dlg.file_entry), 0, -1 );
480 1600 hiro
        g_strchug( sFile ); g_strchomp( sFile );
481 1600 hiro
482 1600 hiro
        sName = gtk_editable_get_chars( GTK_EDITABLE(impcsv_dlg.name_entry), 0, -1 );
483 1600 hiro
        g_strchug( sName ); g_strchomp( sName );
484 1600 hiro
485 1600 hiro
        g_free( impcsv_dlg.nameBook );
486 1600 hiro
        g_free( impcsv_dlg.fileName );
487 1600 hiro
        impcsv_dlg.nameBook = sName;
488 1600 hiro
        impcsv_dlg.fileName = sFile;
489 1600 hiro
490 1600 hiro
        gtk_entry_set_text( GTK_ENTRY(impcsv_dlg.file_entry), sFile );
491 1600 hiro
        gtk_entry_set_text( GTK_ENTRY(impcsv_dlg.name_entry), sName );
492 1600 hiro
493 1600 hiro
        if( *sFile == '\0'|| strlen( sFile ) < 1 ) {
494 1600 hiro
                sMsg = _( "Please select a file." );
495 1600 hiro
                gtk_widget_grab_focus(impcsv_dlg.file_entry);
496 1600 hiro
                errFlag = TRUE;
497 1600 hiro
        }
498 1600 hiro
499 1600 hiro
        if( *sName == '\0'|| strlen( sName ) < 1 ) {
500 1600 hiro
                if( ! errFlag ) sMsg = _( "Address book name must be supplied." );
501 1600 hiro
                gtk_widget_grab_focus(impcsv_dlg.name_entry);
502 1600 hiro
                errFlag = TRUE;
503 1600 hiro
        }
504 1600 hiro
505 1600 hiro
        if( ! errFlag ) {
506 1605 hiro
                gchar *sFSFile;
507 1605 hiro
                sFSFile = conv_filename_from_utf8( sFile );
508 1605 hiro
                if ( ! imp_csv_load_fields( sFSFile ) ) {
509 1603 hiro
                        sMsg = _( "Error reading CSV fields." );
510 1603 hiro
                } else {
511 1603 hiro
                        retVal = TRUE;
512 1603 hiro
                }
513 1605 hiro
                g_free( sFSFile );
514 1600 hiro
        }
515 1600 hiro
        imp_csv_status_show( sMsg );
516 1600 hiro
517 1600 hiro
        return retVal;
518 1600 hiro
}
519 1600 hiro
520 1600 hiro
/*
521 1600 hiro
 * Display finish page.
522 1600 hiro
 */
523 1600 hiro
static void imp_csv_finish_show() {
524 1600 hiro
        gchar *sMsg;
525 1600 hiro
        gchar *name;
526 1600 hiro
527 1600 hiro
        name = gtk_editable_get_chars( GTK_EDITABLE(impcsv_dlg.name_entry), 0, -1 );
528 1600 hiro
        gtk_label_set_text( GTK_LABEL(impcsv_dlg.labelBook), name );
529 1600 hiro
        g_free( name );
530 1600 hiro
        gtk_label_set_text( GTK_LABEL(impcsv_dlg.labelFile), impcsv_dlg.fileName );
531 1600 hiro
        gtk_label_set_text( GTK_LABEL(impcsv_dlg.labelRecords), itos( importCount ) );
532 1600 hiro
        gtk_widget_set_sensitive( impcsv_dlg.btnPrev, FALSE );
533 1600 hiro
        gtk_widget_set_sensitive( impcsv_dlg.btnNext, FALSE );
534 1600 hiro
        if( result == MGU_SUCCESS ) {
535 1600 hiro
                sMsg = _( "CSV file imported successfully." );
536 1600 hiro
        }
537 1600 hiro
        else {
538 1600 hiro
                sMsg = mgu_error2string( result );
539 1600 hiro
        }
540 1600 hiro
        imp_csv_status_show( sMsg );
541 1600 hiro
        gtk_button_set_label(GTK_BUTTON(impcsv_dlg.btnCancel), GTK_STOCK_CLOSE);
542 1600 hiro
        gtk_widget_grab_focus(impcsv_dlg.btnCancel);
543 1600 hiro
}
544 1600 hiro
545 1600 hiro
static void imp_csv_prev( GtkWidget *widget ) {
546 1600 hiro
        gint pageNum;
547 1600 hiro
548 1600 hiro
        pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(impcsv_dlg.notebook) );
549 1600 hiro
        if( pageNum == PAGE_ATTRIBUTES ) {
550 1600 hiro
                /* Goto file page stuff */
551 1600 hiro
                gtk_notebook_set_current_page(
552 1600 hiro
                        GTK_NOTEBOOK(impcsv_dlg.notebook), PAGE_FILE_INFO );
553 1600 hiro
                gtk_widget_set_sensitive( impcsv_dlg.btnPrev, FALSE );
554 1600 hiro
        }
555 1600 hiro
        imp_csv_message();
556 1600 hiro
}
557 1600 hiro
558 1600 hiro
static void imp_csv_next( GtkWidget *widget ) {
559 1600 hiro
        gint pageNum;
560 1600 hiro
561 1600 hiro
        pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(impcsv_dlg.notebook) );
562 1600 hiro
        if( pageNum == PAGE_FILE_INFO ) {
563 1600 hiro
                /* Goto attributes stuff */
564 1600 hiro
                if( imp_csv_file_move() ) {
565 1600 hiro
                        gtk_notebook_set_current_page(
566 1600 hiro
                                GTK_NOTEBOOK(impcsv_dlg.notebook), PAGE_ATTRIBUTES );
567 1600 hiro
                        imp_csv_message();
568 1600 hiro
                        gtk_widget_set_sensitive( impcsv_dlg.btnPrev, TRUE );
569 1600 hiro
                }
570 1600 hiro
                else {
571 1600 hiro
                        gtk_widget_set_sensitive( impcsv_dlg.btnPrev, FALSE );
572 1600 hiro
                }
573 1600 hiro
        }
574 1600 hiro
        else if( pageNum == PAGE_ATTRIBUTES ) {
575 1600 hiro
                /* Goto finish stuff */
576 1600 hiro
                if( imp_csv_field_move() ) {
577 1600 hiro
                        gtk_notebook_set_current_page(
578 1600 hiro
                                GTK_NOTEBOOK(impcsv_dlg.notebook), PAGE_FINISH );
579 1600 hiro
                        imp_csv_finish_show();
580 1600 hiro
                }
581 1600 hiro
        }
582 1600 hiro
}
583 1600 hiro
584 1600 hiro
static void imp_csv_cancel( GtkWidget *widget, gpointer data ) {
585 1600 hiro
        gint pageNum;
586 1600 hiro
587 1600 hiro
        pageNum = gtk_notebook_get_current_page( GTK_NOTEBOOK(impcsv_dlg.notebook) );
588 1600 hiro
        if( pageNum != PAGE_FINISH ) {
589 1600 hiro
                impcsv_dlg.cancelled = TRUE;
590 1600 hiro
        }
591 1600 hiro
        gtk_main_quit();
592 1600 hiro
}
593 1600 hiro
594 1600 hiro
static void imp_csv_file_select( void ) {
595 1603 hiro
        gchar *sSelFile;
596 1600 hiro
597 1607 hiro
        sSelFile = filesel_select_file( _("Select CSV File"), NULL,
598 1603 hiro
                                        GTK_FILE_CHOOSER_ACTION_OPEN );
599 1603 hiro
        if (sSelFile) {
600 1604 hiro
                gchar *sUTF8File;
601 1604 hiro
                sUTF8File = conv_filename_to_utf8( sSelFile );
602 1604 hiro
                gtk_entry_set_text( GTK_ENTRY(impcsv_dlg.file_entry), sUTF8File );
603 1604 hiro
                g_free( sUTF8File );
604 1603 hiro
                g_free( sSelFile );
605 1603 hiro
        }
606 1600 hiro
}
607 1600 hiro
608 1600 hiro
static gint imp_csv_delete_event( GtkWidget *widget, GdkEventAny *event, gpointer data ) {
609 1600 hiro
        imp_csv_cancel( widget, data );
610 1600 hiro
        return TRUE;
611 1600 hiro
}
612 1600 hiro
613 1600 hiro
static gboolean imp_csv_key_pressed( GtkWidget *widget, GdkEventKey *event, gpointer data ) {
614 1600 hiro
        if (event && event->keyval == GDK_Escape) {
615 1600 hiro
                imp_csv_cancel( widget, data );
616 1600 hiro
        }
617 1600 hiro
        return FALSE;
618 1600 hiro
}
619 1600 hiro
620 1600 hiro
static void imp_csv_page_file( gint pageNum, gchar *pageLbl ) {
621 1600 hiro
        GtkWidget *vbox;
622 1600 hiro
        GtkWidget *table;
623 1600 hiro
        GtkWidget *label;
624 1600 hiro
        GtkWidget *file_entry;
625 1600 hiro
        GtkWidget *name_entry;
626 1600 hiro
        GtkWidget *file_btn;
627 1600 hiro
        gint top;
628 1600 hiro
629 1600 hiro
        vbox = gtk_vbox_new(FALSE, 8);
630 1600 hiro
        gtk_container_add( GTK_CONTAINER( impcsv_dlg.notebook ), vbox );
631 1600 hiro
        gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
632 1600 hiro
633 1600 hiro
        label = gtk_label_new( pageLbl );
634 1600 hiro
        gtk_widget_show( label );
635 1600 hiro
        gtk_notebook_set_tab_label(
636 1600 hiro
                GTK_NOTEBOOK( impcsv_dlg.notebook ),
637 1600 hiro
                gtk_notebook_get_nth_page(
638 1600 hiro
                        GTK_NOTEBOOK( impcsv_dlg.notebook ), pageNum ),
639 1600 hiro
                label );
640 1600 hiro
641 1600 hiro
        table = gtk_table_new(2, 3, FALSE);
642 1600 hiro
        gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
643 1600 hiro
        gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
644 1600 hiro
        gtk_table_set_row_spacings(GTK_TABLE(table), 8);
645 1600 hiro
        gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
646 1600 hiro
647 1600 hiro
        /* First row */
648 1600 hiro
        top = 0;
649 1600 hiro
        label = gtk_label_new(_("Address Book"));
650 1600 hiro
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
651 1600 hiro
                GTK_FILL, 0, 0, 0);
652 1600 hiro
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
653 1600 hiro
654 1600 hiro
        name_entry = gtk_entry_new();
655 1600 hiro
        gtk_table_attach(GTK_TABLE(table), name_entry, 1, 2, top, (top + 1),
656 1600 hiro
                GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
657 1600 hiro
658 1600 hiro
        /* Second row */
659 1600 hiro
        top = 1;
660 1600 hiro
        label = gtk_label_new(_("File Name"));
661 1600 hiro
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
662 1600 hiro
                GTK_FILL, 0, 0, 0);
663 1600 hiro
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
664 1600 hiro
665 1600 hiro
        file_entry = gtk_entry_new();
666 1600 hiro
        gtk_table_attach(GTK_TABLE(table), file_entry, 1, 2, top, (top + 1),
667 1600 hiro
                GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
668 1600 hiro
669 1600 hiro
        file_btn = gtk_button_new_with_label( _(" ... "));
670 1600 hiro
        gtk_table_attach(GTK_TABLE(table), file_btn, 2, 3, top, (top + 1),
671 1600 hiro
                GTK_FILL, 0, 3, 0);
672 1600 hiro
673 1600 hiro
        gtk_widget_show_all(vbox);
674 1600 hiro
675 1600 hiro
        /* Button handler */
676 1600 hiro
        g_signal_connect(G_OBJECT(file_btn), "clicked",
677 1600 hiro
                         G_CALLBACK(imp_csv_file_select), NULL);
678 1600 hiro
679 1600 hiro
        impcsv_dlg.file_entry = file_entry;
680 1600 hiro
        impcsv_dlg.name_entry = name_entry;
681 1600 hiro
}
682 1600 hiro
683 1600 hiro
static void imp_csv_page_fields( gint pageNum, gchar *pageLbl ) {
684 1600 hiro
        GtkWidget *vbox;
685 1607 hiro
        GtkWidget *hbox;
686 1600 hiro
687 1600 hiro
        GtkWidget *label;
688 1600 hiro
        GtkWidget *clist_swin;
689 1600 hiro
        GtkWidget *clist_field;
690 1600 hiro
691 1607 hiro
        GtkWidget *btn_vbox;
692 1607 hiro
        GtkWidget *btn_vbox1;
693 1607 hiro
        GtkWidget *up_btn;
694 1607 hiro
        GtkWidget *down_btn;
695 1607 hiro
696 1600 hiro
        gchar *titles[ FIELDS_N_COLS ];
697 1600 hiro
        gint i;
698 1600 hiro
699 1600 hiro
        titles[ FIELD_COL_SELECT ] = _("S");
700 1600 hiro
        titles[ FIELD_COL_FIELD  ] = _("CSV Field");
701 1608 hiro
        titles[ FIELD_COL_ATTRIB ] = _("Address Book Field");
702 1600 hiro
703 1600 hiro
        vbox = gtk_vbox_new(FALSE, 8);
704 1600 hiro
        gtk_container_add( GTK_CONTAINER( impcsv_dlg.notebook ), vbox );
705 1600 hiro
        gtk_container_set_border_width( GTK_CONTAINER (vbox), 4 );
706 1600 hiro
707 1600 hiro
        label = gtk_label_new( pageLbl );
708 1600 hiro
        gtk_widget_show( label );
709 1600 hiro
        gtk_notebook_set_tab_label(
710 1600 hiro
                GTK_NOTEBOOK( impcsv_dlg.notebook ),
711 1600 hiro
                gtk_notebook_get_nth_page(GTK_NOTEBOOK( impcsv_dlg.notebook ), pageNum ),
712 1600 hiro
                label );
713 1600 hiro
714 1607 hiro
        hbox = gtk_hbox_new( FALSE, 4 );
715 1607 hiro
        gtk_box_pack_start( GTK_BOX( vbox ), hbox, TRUE, TRUE, 0 );
716 1600 hiro
717 1600 hiro
        clist_swin = gtk_scrolled_window_new( NULL, NULL );
718 1607 hiro
        gtk_box_pack_start( GTK_BOX(hbox), clist_swin, TRUE, TRUE, 0 );
719 1600 hiro
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(clist_swin),
720 1600 hiro
                                       GTK_POLICY_AUTOMATIC,
721 1600 hiro
                                       GTK_POLICY_ALWAYS);
722 1600 hiro
723 1600 hiro
        clist_field = gtk_clist_new_with_titles( FIELDS_N_COLS, titles );
724 1600 hiro
        gtk_container_add( GTK_CONTAINER(clist_swin), clist_field );
725 1600 hiro
        gtk_clist_set_selection_mode( GTK_CLIST(clist_field), GTK_SELECTION_BROWSE );
726 1600 hiro
        gtk_clist_set_column_width(
727 1600 hiro
                        GTK_CLIST(clist_field), FIELD_COL_SELECT, FIELDS_COL_WIDTH_SELECT );
728 1600 hiro
        gtk_clist_set_column_width(
729 1600 hiro
                        GTK_CLIST(clist_field), FIELD_COL_FIELD, FIELDS_COL_WIDTH_FIELD );
730 1600 hiro
        gtk_clist_set_column_width(
731 1600 hiro
                        GTK_CLIST(clist_field), FIELD_COL_ATTRIB, FIELDS_COL_WIDTH_ATTRIB );
732 1600 hiro
        gtkut_clist_set_redraw( GTK_CLIST(clist_field) );
733 1600 hiro
734 1600 hiro
        for( i = 0; i < FIELDS_N_COLS; i++ )
735 1600 hiro
                GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(clist_field)->column[i].button, GTK_CAN_FOCUS);
736 1600 hiro
737 1607 hiro
        btn_vbox = gtk_vbox_new( FALSE, 0 );
738 1607 hiro
        gtk_box_pack_start( GTK_BOX( hbox ), btn_vbox, FALSE, FALSE, 0 );
739 1607 hiro
        gtk_container_set_border_width( GTK_CONTAINER (btn_vbox), 4 );
740 1607 hiro
741 1607 hiro
        btn_vbox1 = gtk_vbox_new( FALSE, 8 );
742 1607 hiro
        gtk_box_pack_start( GTK_BOX( btn_vbox ), btn_vbox1, TRUE, FALSE, 0 );
743 1607 hiro
744 1607 hiro
        up_btn = gtk_button_new_with_label( _("Up") );
745 1607 hiro
        gtk_box_pack_start( GTK_BOX( btn_vbox1 ), up_btn, FALSE, FALSE, 0 );
746 1607 hiro
        down_btn = gtk_button_new_with_label( _("Down") );
747 1607 hiro
        gtk_box_pack_start( GTK_BOX( btn_vbox1 ), down_btn, FALSE, FALSE, 0 );
748 1607 hiro
749 1600 hiro
        gtk_widget_show_all(vbox);
750 1600 hiro
751 1600 hiro
        g_signal_connect( G_OBJECT(clist_field), "select_row",
752 1600 hiro
                          G_CALLBACK(imp_csv_field_list_selected), NULL );
753 1607 hiro
        g_signal_connect( G_OBJECT(up_btn), "clicked",
754 1607 hiro
                          G_CALLBACK(imp_csv_field_list_up), NULL );
755 1607 hiro
        g_signal_connect( G_OBJECT(down_btn), "clicked",
756 1607 hiro
                          G_CALLBACK(imp_csv_field_list_down), NULL );
757 1600 hiro
758 1600 hiro
        impcsv_dlg.clist_field  = clist_field;
759 1600 hiro
}
760 1600 hiro
761 1600 hiro
static void imp_csv_page_finish( gint pageNum, gchar *pageLbl ) {
762 1600 hiro
        GtkWidget *vbox;
763 1600 hiro
        GtkWidget *table;
764 1600 hiro
        GtkWidget *label;
765 1600 hiro
        GtkWidget *labelBook;
766 1600 hiro
        GtkWidget *labelFile;
767 1600 hiro
        GtkWidget *labelRecs;
768 1600 hiro
        gint top;
769 1600 hiro
770 1600 hiro
        vbox = gtk_vbox_new(FALSE, 8);
771 1600 hiro
        gtk_container_add( GTK_CONTAINER( impcsv_dlg.notebook ), vbox );
772 1600 hiro
        gtk_container_set_border_width( GTK_CONTAINER (vbox), BORDER_WIDTH );
773 1600 hiro
774 1600 hiro
        label = gtk_label_new( pageLbl );
775 1600 hiro
        gtk_widget_show( label );
776 1600 hiro
        gtk_notebook_set_tab_label(
777 1600 hiro
                GTK_NOTEBOOK( impcsv_dlg.notebook ),
778 1600 hiro
                gtk_notebook_get_nth_page( GTK_NOTEBOOK( impcsv_dlg.notebook ), pageNum ), label );
779 1600 hiro
780 1600 hiro
        table = gtk_table_new(3, 2, FALSE);
781 1600 hiro
        gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
782 1600 hiro
        gtk_container_set_border_width( GTK_CONTAINER(table), 8 );
783 1600 hiro
        gtk_table_set_row_spacings(GTK_TABLE(table), 8);
784 1600 hiro
        gtk_table_set_col_spacings(GTK_TABLE(table), 8 );
785 1600 hiro
786 1600 hiro
        /* First row */
787 1600 hiro
        top = 0;
788 1600 hiro
        label = gtk_label_new(_("Address Book :"));
789 1600 hiro
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
790 1600 hiro
        gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
791 1600 hiro
792 1600 hiro
        labelBook = gtk_label_new("");
793 1600 hiro
        gtk_table_attach(GTK_TABLE(table), labelBook, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
794 1600 hiro
        gtk_misc_set_alignment(GTK_MISC(labelBook), 0, 0.5);
795 1600 hiro
796 1600 hiro
        /* Second row */
797 1600 hiro
        top++;
798 1600 hiro
        label = gtk_label_new(_("File Name :"));
799 1600 hiro
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
800 1600 hiro
        gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
801 1600 hiro
802 1600 hiro
        labelFile = gtk_label_new("");
803 1600 hiro
        gtk_table_attach(GTK_TABLE(table), labelFile, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
804 1600 hiro
        gtk_misc_set_alignment(GTK_MISC(labelFile), 0, 0.5);
805 1600 hiro
806 1600 hiro
        /* Third row */
807 1600 hiro
        top++;
808 1600 hiro
        label = gtk_label_new(_("Records :"));
809 1600 hiro
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
810 1600 hiro
        gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
811 1600 hiro
812 1600 hiro
        labelRecs = gtk_label_new("");
813 1600 hiro
        gtk_table_attach(GTK_TABLE(table), labelRecs, 1, 2, top, (top + 1), GTK_FILL, 0, 0, 0);
814 1600 hiro
        gtk_misc_set_alignment(GTK_MISC(labelRecs), 0, 0.5);
815 1600 hiro
816 1600 hiro
        impcsv_dlg.labelBook    = labelBook;
817 1600 hiro
        impcsv_dlg.labelFile    = labelFile;
818 1600 hiro
        impcsv_dlg.labelRecords = labelRecs;
819 1600 hiro
}
820 1600 hiro
821 1600 hiro
static void imp_csv_dialog_create() {
822 1600 hiro
        GtkWidget *window;
823 1600 hiro
        GtkWidget *vbox;
824 1600 hiro
        GtkWidget *vnbox;
825 1600 hiro
        GtkWidget *notebook;
826 1600 hiro
        GtkWidget *hbbox;
827 1600 hiro
        GtkWidget *btnPrev;
828 1600 hiro
        GtkWidget *btnNext;
829 1600 hiro
        GtkWidget *btnCancel;
830 1600 hiro
        GtkWidget *hsbox;
831 1600 hiro
        GtkWidget *statusbar;
832 1600 hiro
833 1600 hiro
        window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
834 1600 hiro
        gtk_widget_set_size_request(window, IMPORTCSV_WIDTH, IMPORTCSV_HEIGHT );
835 1600 hiro
        gtk_container_set_border_width( GTK_CONTAINER(window), 0 );
836 1600 hiro
        gtk_window_set_title( GTK_WINDOW(window), _("Import CSV file into Address Book") );
837 1600 hiro
        gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
838 1600 hiro
        gtk_window_set_modal(GTK_WINDOW(window), TRUE);
839 1600 hiro
        g_signal_connect(G_OBJECT(window), "delete_event",
840 1600 hiro
                         G_CALLBACK(imp_csv_delete_event), NULL);
841 1600 hiro
        g_signal_connect(G_OBJECT(window), "key_press_event",
842 1600 hiro
                         G_CALLBACK(imp_csv_key_pressed), NULL);
843 1600 hiro
844 1600 hiro
        vbox = gtk_vbox_new(FALSE, 4);
845 1600 hiro
        gtk_widget_show(vbox);
846 1600 hiro
        gtk_container_add(GTK_CONTAINER(window), vbox);
847 1600 hiro
848 1600 hiro
        vnbox = gtk_vbox_new(FALSE, 4);
849 1600 hiro
        gtk_container_set_border_width(GTK_CONTAINER(vnbox), 4);
850 1600 hiro
        gtk_widget_show(vnbox);
851 1600 hiro
        gtk_box_pack_start(GTK_BOX(vbox), vnbox, TRUE, TRUE, 0);
852 1600 hiro
853 1600 hiro
        /* Notebook */
854 1600 hiro
        notebook = gtk_notebook_new();
855 1600 hiro
        gtk_notebook_set_show_tabs( GTK_NOTEBOOK(notebook), FALSE );
856 1600 hiro
        gtk_widget_show(notebook);
857 1600 hiro
        gtk_box_pack_start(GTK_BOX(vnbox), notebook, TRUE, TRUE, 0);
858 1600 hiro
        gtk_container_set_border_width(GTK_CONTAINER(notebook), 6);
859 1600 hiro
860 1600 hiro
        /* Status line */
861 1600 hiro
        hsbox = gtk_hbox_new(FALSE, 0);
862 1600 hiro
        gtk_box_pack_end(GTK_BOX(vbox), hsbox, FALSE, FALSE, 0);
863 1600 hiro
        statusbar = gtk_statusbar_new();
864 1600 hiro
        gtk_box_pack_start(GTK_BOX(hsbox), statusbar, TRUE, TRUE, 0);
865 1600 hiro
866 1600 hiro
        /* Button panel */
867 1600 hiro
        gtkut_stock_button_set_create(&hbbox, &btnNext, _("Next"),
868 1600 hiro
                                      &btnPrev, _("Prev"),
869 1600 hiro
                                      &btnCancel, GTK_STOCK_CANCEL);
870 1600 hiro
        gtk_button_box_set_child_secondary(GTK_BUTTON_BOX(hbbox), btnCancel,
871 1600 hiro
                                           TRUE);
872 1600 hiro
        gtkut_box_set_reverse_order(GTK_BOX(hbbox), FALSE);
873 1600 hiro
        gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
874 1600 hiro
        gtk_container_set_border_width(GTK_CONTAINER(hbbox), 2);
875 1600 hiro
        gtk_widget_grab_default(btnNext);
876 1600 hiro
877 1600 hiro
        /* Button handlers */
878 1600 hiro
        g_signal_connect(G_OBJECT(btnPrev), "clicked",
879 1600 hiro
                         G_CALLBACK(imp_csv_prev), NULL);
880 1600 hiro
        g_signal_connect(G_OBJECT(btnNext), "clicked",
881 1600 hiro
                         G_CALLBACK(imp_csv_next), NULL);
882 1600 hiro
        g_signal_connect(G_OBJECT(btnCancel), "clicked",
883 1600 hiro
                         G_CALLBACK(imp_csv_cancel), NULL);
884 1600 hiro
885 1600 hiro
        gtk_widget_show_all(vbox);
886 1600 hiro
887 1600 hiro
        impcsv_dlg.window     = window;
888 1600 hiro
        impcsv_dlg.notebook   = notebook;
889 1600 hiro
        impcsv_dlg.btnPrev    = btnPrev;
890 1600 hiro
        impcsv_dlg.btnNext    = btnNext;
891 1600 hiro
        impcsv_dlg.btnCancel  = btnCancel;
892 1600 hiro
        impcsv_dlg.statusbar  = statusbar;
893 1600 hiro
        impcsv_dlg.status_cid = gtk_statusbar_get_context_id(
894 1600 hiro
                        GTK_STATUSBAR(statusbar), "Import CSV Dialog" );
895 1600 hiro
896 1600 hiro
}
897 1600 hiro
898 1600 hiro
static void imp_csv_create() {
899 1600 hiro
        imp_csv_dialog_create();
900 1600 hiro
        imp_csv_page_file( PAGE_FILE_INFO, _( "File Info" ) );
901 1600 hiro
        imp_csv_page_fields( PAGE_ATTRIBUTES, _( "Fields" ) );
902 1600 hiro
        imp_csv_page_finish( PAGE_FINISH, _( "Finish" ) );
903 1600 hiro
        gtk_widget_show_all( impcsv_dlg.window );
904 1600 hiro
}
905 1600 hiro
906 1600 hiro
AddressBookFile *addressbook_imp_csv( AddressIndex *addrIndex ) {
907 1600 hiro
        _importedBook_ = NULL;
908 1600 hiro
        _imp_addressIndex_ = addrIndex;
909 1600 hiro
910 1600 hiro
        if( ! impcsv_dlg.window )
911 1600 hiro
                imp_csv_create();
912 1600 hiro
        impcsv_dlg.cancelled = FALSE;
913 1600 hiro
        gtk_widget_show(impcsv_dlg.window);
914 1600 hiro
        manage_window_set_transient(GTK_WINDOW(impcsv_dlg.window));
915 1600 hiro
        gtk_widget_grab_default(impcsv_dlg.btnNext);
916 1600 hiro
917 1600 hiro
        gtk_entry_set_text( GTK_ENTRY(impcsv_dlg.name_entry), IMPORTCSV_GUESS_NAME );
918 1600 hiro
        gtk_entry_set_text( GTK_ENTRY(impcsv_dlg.file_entry), "" );
919 1600 hiro
        gtk_clist_clear( GTK_CLIST(impcsv_dlg.clist_field) );
920 1600 hiro
        gtk_notebook_set_current_page( GTK_NOTEBOOK(impcsv_dlg.notebook), PAGE_FILE_INFO );
921 1600 hiro
        gtk_widget_set_sensitive( impcsv_dlg.btnPrev, FALSE );
922 1600 hiro
        gtk_widget_set_sensitive( impcsv_dlg.btnNext, TRUE );
923 1600 hiro
        gtk_button_set_label( GTK_BUTTON(impcsv_dlg.btnCancel), GTK_STOCK_CANCEL );
924 1600 hiro
        stock_pixmap_gdk( impcsv_dlg.window, STOCK_PIXMAP_MARK,
925 1600 hiro
                          &markxpm, &markxpmmask );
926 1600 hiro
        imp_csv_message();
927 1600 hiro
        gtk_widget_grab_focus(impcsv_dlg.file_entry);
928 1600 hiro
929 1600 hiro
        impcsv_dlg.rowIndSelect = -1;
930 1600 hiro
        impcsv_dlg.rowCount = 0;
931 1600 hiro
        g_free( impcsv_dlg.nameBook );
932 1600 hiro
        g_free( impcsv_dlg.fileName );
933 1600 hiro
        impcsv_dlg.nameBook = NULL;
934 1600 hiro
        impcsv_dlg.fileName = NULL;
935 1600 hiro
        importCount = 0;
936 1600 hiro
937 1600 hiro
        gtk_main();
938 1600 hiro
        gtk_widget_hide(impcsv_dlg.window);
939 1600 hiro
        _imp_addressIndex_ = NULL;
940 1600 hiro
941 1600 hiro
        g_free( impcsv_dlg.nameBook );
942 1600 hiro
        g_free( impcsv_dlg.fileName );
943 1600 hiro
        impcsv_dlg.nameBook = NULL;
944 1600 hiro
        impcsv_dlg.fileName = NULL;
945 1600 hiro
946 1600 hiro
        if( impcsv_dlg.cancelled == TRUE ) return NULL;
947 1600 hiro
        return _importedBook_;
948 1600 hiro
}
949 1600 hiro
950 1600 hiro
/*
951 1600 hiro
* End of Source.
952 1600 hiro
*/