/* ====================================================================
 * FTD4Linux Software License, Version 1.0
 *
 * Copyright (c) 2000-2004 The FTD4Linux Development Team.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        FTD4Linux Development Team (http://www.ftd4linux.2y.net/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "FTD" and "FTD4Linux" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact alguno@ftd4linux.2y.net.
 *
 * 5. Products derived from this software may not be called "FTD4Linux",
 *    nor may "FTD4Linux" appear in their name, without prior written
 *    permission of the FTD4Linux Development Team.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE FTD4LINUX DEVELOPMENT TEAM OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#include <stdio.h>
#include "ftd_gui_main.h"
#include "ftd_gui_import_ftddb.h"

static gboolean ftd_gui_import_destroy(GtkWidget *caller, gpointer data);

void
ftd_gui_create_import_ftddb_window (void)
{
    FtdGuiImport *import;
    GtkWidget *vbox1;
    GtkWidget *label1;
    GtkWidget *hbox1;

    g_assert(gui);

    if (gui->import) {
        gtk_window_present(GTK_WINDOW(gui->import->window));
        return;
    }

    gui->import = import = g_malloc0(sizeof(FtdGuiImport));

    import->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_container_set_border_width (GTK_CONTAINER (import->window), 6);
    gtk_window_set_title (GTK_WINDOW (import->window), "FTD 3.8 Database Importeren");
    gtk_window_set_default_size (GTK_WINDOW (import->window), 440, 250);
    gtk_window_set_resizable (GTK_WINDOW (import->window), FALSE);

    vbox1 = gtk_vbox_new (FALSE, 0);
    gtk_widget_show (vbox1);
    gtk_container_add (GTK_CONTAINER (import->window), vbox1);

    label1 = gtk_label_new ("Geef hieronder de locatie op van een FTD 3.8 postbestand dat je wilt importeren en druk op de knop 'Importeren' om het importeerproces te beginnen.");
    gtk_widget_show (label1);
    gtk_box_pack_start (GTK_BOX (vbox1), label1, FALSE, TRUE, 6);
    gtk_label_set_line_wrap (GTK_LABEL (label1), TRUE);
    gtk_misc_set_alignment (GTK_MISC (label1), 0, 0.5);

    hbox1 = gtk_hbox_new (FALSE, 0);
    gtk_widget_show (hbox1);
    gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, TRUE, 0);

    import->entry_filename = gtk_entry_new ();
    gtk_widget_show (import->entry_filename);
    gtk_box_pack_start (GTK_BOX (hbox1), import->entry_filename, TRUE, TRUE, 3);
    GTK_WIDGET_UNSET_FLAGS (import->entry_filename, GTK_CAN_FOCUS);
    gtk_widget_set_sensitive (import->entry_filename, FALSE);

    import->button_select_file = gtk_button_new_with_mnemonic ("Selecteer database");
    gtk_widget_show (import->button_select_file);
    gtk_box_pack_start (GTK_BOX (hbox1), import->button_select_file, TRUE, TRUE, 6);
    gtk_container_set_border_width (GTK_CONTAINER (import->button_select_file), 3);
    GTK_WIDGET_UNSET_FLAGS (import->button_select_file, GTK_CAN_FOCUS);

    import->progressbar = gtk_progress_bar_new ();
    gtk_widget_show (import->progressbar);
    gtk_box_pack_start (GTK_BOX (vbox1), import->progressbar, FALSE, TRUE, 6);
    gtk_progress_bar_set_text (GTK_PROGRESS_BAR (import->progressbar), "Wachten totdat het importeren gestart wordt . . .");

    import->button_import = gtk_button_new_with_mnemonic ("Importeren");
    gtk_widget_show (import->button_import);
    gtk_box_pack_start (GTK_BOX (vbox1), import->button_import, FALSE, TRUE, 4);
    GTK_WIDGET_UNSET_FLAGS (import->button_import, GTK_CAN_FOCUS);

    g_signal_connect(G_OBJECT(import->window), "destroy",
                     G_CALLBACK(ftd_gui_import_destroy), NULL);

    gtk_widget_show_all (import->window);
}

static gboolean
ftd_gui_import_destroy(GtkWidget *caller, gpointer data)
{
    g_assert(gui);
    g_assert(gui->import);

    g_free(gui->import);
    gui->import = NULL;

    return FALSE;
}
