/***** * * Copyright (C) 2004, 2005 Pablo Belin * All Rights Reserved * * This file is part of the gprelude program. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * *****/ #include #include #include #include #include #include #include #include "list.h" #include "gprelude-mem.h" #include "gprelude-sys.h" #include "db-interface.h" #include "db-interface-sax.h" #include "gprelude-config.h" #include "gprelude-store.h" struct gprelude_store { gprelude_store_flags_t flags; GtkWidget *dialog; GtkWidget *import_radio; GtkWidget *export_radio; GtkWidget *filename_entry; GtkWidget *selection; void(*import)(gprelude_store_t *store, const char *filename ); void(*export)(gprelude_store_t *store, const char *filename); void *data; }; static GtkWidget *create_gprelude_store_selection ( gprelude_store_t *store ) { GtkWidget *selection; selection = gtk_file_selection_new ( "Browse..." ); gtk_window_set_transient_for ( GTK_WINDOW(selection), GTK_WINDOW(store->dialog) ); gtk_file_selection_set_select_multiple ( GTK_FILE_SELECTION(selection), FALSE ); return selection; } static void cb_gprelude_store_browse ( GtkWidget *button, gprelude_store_t *store ) { int response; const char *filename; response = gtk_dialog_run ( GTK_DIALOG(store->selection) ); switch ( response ) { case GTK_RESPONSE_OK: filename = gtk_file_selection_get_filename ( GTK_FILE_SELECTION(store->selection) ); gtk_entry_set_text ( GTK_ENTRY(store->filename_entry), filename ); default: gtk_widget_hide ( store->selection ); } } static GtkWidget *create_gprelude_store_ornament ( gprelude_store_t *store ) { GtkWidget *table, *box, *button; table = gtk_table_new ( 4, 4, FALSE ); gtk_table_set_row_spacings ( GTK_TABLE(table), 10 ); gtk_table_set_col_spacings ( GTK_TABLE(table), 15 ); store->import_radio = gtk_radio_button_new_with_label ( NULL, "Import" ); gtk_table_attach_defaults ( GTK_TABLE(table), store->import_radio, 1, 2, 1, 2 ); gtk_widget_show ( store->import_radio ); store->export_radio = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(store->import_radio), "Export" ); gtk_table_attach_defaults ( GTK_TABLE(table), store->export_radio, 2, 3, 1, 2 ); gtk_widget_show ( store->export_radio ); box = gtk_hbox_new ( FALSE, 5 ); store->filename_entry = gtk_entry_new (); gtk_entry_set_width_chars ( GTK_ENTRY(store->filename_entry), 48 ); gtk_box_pack_start ( GTK_BOX(box), store->filename_entry, TRUE, TRUE, 0 ); gtk_widget_show ( store->filename_entry ); button = gtk_button_new_with_label ( "Browse..." ); g_signal_connect ( G_OBJECT(button), "clicked", G_CALLBACK(cb_gprelude_store_browse), store ); gtk_box_pack_start ( GTK_BOX(box), button, FALSE, FALSE, 0 ); gtk_widget_show ( button ); gtk_table_attach ( GTK_TABLE(table), box, 1, 3, 2, 3, GTK_EXPAND|GTK_FILL, 0, 0, 0 ); gtk_widget_show ( box ); return table; } gprelude_store_t *gprelude_store_new ( GtkWidget *parent, gprelude_config_t *config, const char *title, gprelude_store_flags_t flags, void(*cb_import)(gprelude_store_t *store, const char *filename), void(*cb_export)(gprelude_store_t *store, const char *filename), void *data ) { gprelude_store_t *store; GtkWidget *ornament; store = malloc ( sizeof(gprelude_store_t) ); if ( !store ) { log ( LOG_ERR, "memory exhausted.\n" ); return NULL; } store->flags = flags; store->import = cb_import; store->export = cb_export; store->data = data; store->dialog = gtk_dialog_new_with_buttons ( title ? title : "", GTK_WINDOW(parent), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK, GTK_RESPONSE_OK, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL ); store->selection = create_gprelude_store_selection ( store ); ornament = create_gprelude_store_ornament ( store ); gtk_container_add ( GTK_CONTAINER(GTK_DIALOG(store->dialog)->vbox), ornament ); gtk_widget_show ( ornament ); return store; } int gprelude_store_destroy ( gprelude_store_t *store ) { return gprelude_free ( store ); } void run_gprelude_store ( gprelude_store_t *store ) { int response; const char *filename; response = gtk_dialog_run ( GTK_DIALOG(store->dialog) ); switch ( response ) { case GTK_RESPONSE_OK: filename = gtk_file_selection_get_filename ( GTK_FILE_SELECTION(store->selection) ); if ( filename && *filename != '\0' ) { if ( gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(store->import_radio) ) ) { //store->import ( store, filename ); } else { //store->export ( store, filename ); } } if ( !(store->flags & gprelude_store_flags_destroy) ) { run_gprelude_store ( store ); break; } default: gtk_widget_destroy ( store->dialog ); } }