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