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