]> git.tdb.fi Git - ext/subsurface.git/blobdiff - gtk-gui.c
Remove the ability to 'Import' .SDA files
[ext/subsurface.git] / gtk-gui.c
index 3efeab0f60ebcf4f2d31c5329e092ffc06770acf..002b804148cb977a10d79a45138b96d1ce8f4799 100644 (file)
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -33,10 +33,13 @@ struct units output_units;
 
 static GtkWidget *dive_profile;
 
+visible_cols_t visible_cols = {TRUE, FALSE};
+
 void repaint_dive(void)
 {
        update_dive(current_dive);
-       gtk_widget_queue_draw(dive_profile);
+       if (dive_profile)
+               gtk_widget_queue_draw(dive_profile);
 }
 
 static char *existing_filename;
@@ -87,6 +90,8 @@ void report_error(GError* error)
 static void file_open(GtkWidget *w, gpointer data)
 {
        GtkWidget *dialog;
+       GtkFileFilter *filter;
+
        dialog = gtk_file_chooser_dialog_new("Open File",
                GTK_WINDOW(main_window),
                GTK_FILE_CHOOSER_ACTION_OPEN,
@@ -95,6 +100,15 @@ static void file_open(GtkWidget *w, gpointer data)
                NULL);
        gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
 
+       filter = gtk_file_filter_new();
+       gtk_file_filter_add_pattern(filter, "*.xml");
+       gtk_file_filter_add_pattern(filter, "*.XML");
+       gtk_file_filter_add_pattern(filter, "*.sda");
+       gtk_file_filter_add_pattern(filter, "*.SDA");
+       gtk_file_filter_add_mime_type(filter, "text/xml");
+       gtk_file_filter_set_name(filter, "XML file");
+       gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
+
        if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
                GSList *filenames;
                char *filename;
@@ -141,7 +155,7 @@ static void file_save(GtkWidget *w, gpointer data)
                filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
                save_dives(filename);
                g_free(filename);
-               mark_divelist_changed(TRUE);
+               mark_divelist_changed(FALSE);
        }
        gtk_widget_destroy(dialog);
 }
@@ -165,13 +179,19 @@ static void ask_save_changes()
        gtk_widget_destroy(dialog);
 }
 
-void on_destroy(GtkWidget* w, gpointer data)
+static gboolean on_delete(GtkWidget* w, gpointer data)
 {
        /* Make sure to flush any modified dive data */
        update_dive(NULL);
 
        if (unsaved_changes())
                ask_save_changes();
+
+       return FALSE; /* go ahead, kill the program, we're good now */
+}
+
+static void on_destroy(GtkWidget* w, gpointer data)
+{
        gtk_main_quit();
 }
 
@@ -237,10 +257,19 @@ UNITCALLBACK(set_cuft, volume, CUFT)
 UNITCALLBACK(set_celsius, temperature, CELSIUS)
 UNITCALLBACK(set_fahrenheit, temperature, FAHRENHEIT)
 
+#define OPTIONCALLBACK(name, option) \
+static void name(GtkWidget *w, gpointer data) \
+{ \
+       option = GTK_TOGGLE_BUTTON(w)->active; \
+}
+
+OPTIONCALLBACK(otu_toggle, visible_cols.otu)
+OPTIONCALLBACK(sac_toggle, visible_cols.sac)
+
 static void preferences_dialog(GtkWidget *w, gpointer data)
 {
        int result;
-       GtkWidget *dialog, *font, *frame, *box;
+       GtkWidget *dialog, *font, *frame, *box, *vbox, *button;
 
        menu_units = output_units;
 
@@ -252,7 +281,8 @@ static void preferences_dialog(GtkWidget *w, gpointer data)
                NULL);
 
        frame = gtk_frame_new("Units");
-       gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), frame, FALSE, FALSE, 5);
+       vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+       gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
 
        box = gtk_vbox_new(FALSE, 6);
        gtk_container_add(GTK_CONTAINER(frame), box);
@@ -277,8 +307,24 @@ static void preferences_dialog(GtkWidget *w, gpointer data)
                "Fahrenheit",  set_fahrenheit, (output_units.temperature == FAHRENHEIT),
                NULL);
 
+       frame = gtk_frame_new("Columns");
+       gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), frame, FALSE, FALSE, 5);
+
+       box = gtk_hbox_new(FALSE, 6);
+       gtk_container_add(GTK_CONTAINER(frame), box);
+
+       button = gtk_check_button_new_with_label("Show SAC");
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.sac);
+       gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
+       g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(sac_toggle), NULL);
+
+       button = gtk_check_button_new_with_label("Show OTU");
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), visible_cols.otu);
+       gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 6);
+       g_signal_connect(G_OBJECT(button), "toggled", G_CALLBACK(otu_toggle), NULL);
+
        font = gtk_font_button_new_with_font(divelist_font);
-       gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), font, FALSE, FALSE, 5);
+       gtk_box_pack_start(GTK_BOX(vbox), font, FALSE, FALSE, 5);
 
        gtk_widget_show_all(dialog);
        result = gtk_dialog_run(GTK_DIALOG(dialog));
@@ -292,10 +338,13 @@ static void preferences_dialog(GtkWidget *w, gpointer data)
                output_units = menu_units;
                update_dive_list_units();
                repaint_dive();
+               update_dive_list_col_visibility();
                gconf_client_set_bool(gconf, GCONF_NAME(feet), output_units.length == FEET, NULL);
                gconf_client_set_bool(gconf, GCONF_NAME(psi), output_units.pressure == PSI, NULL);
                gconf_client_set_bool(gconf, GCONF_NAME(cuft), output_units.volume == CUFT, NULL);
                gconf_client_set_bool(gconf, GCONF_NAME(fahrenheit), output_units.temperature == FAHRENHEIT, NULL);
+               gconf_client_set_bool(gconf, GCONF_NAME(SAC), ! visible_cols.sac, NULL); /* inverted to get the correct default */
+               gconf_client_set_bool(gconf, GCONF_NAME(OTU), visible_cols.otu, NULL);
                gconf_client_set_string(gconf, GCONF_NAME(divelist_font), divelist_font, NULL);
        }
        gtk_widget_destroy(dialog);
@@ -304,7 +353,7 @@ static void preferences_dialog(GtkWidget *w, gpointer data)
 static void renumber_dialog(GtkWidget *w, gpointer data)
 {
        int result;
-       GtkWidget *dialog, *frame, *button;
+       GtkWidget *dialog, *frame, *button, *vbox;
 
        dialog = gtk_dialog_new_with_buttons("Renumber",
                GTK_WINDOW(main_window),
@@ -313,8 +362,10 @@ static void renumber_dialog(GtkWidget *w, gpointer data)
                GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
                NULL);
 
+       vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+
        frame = gtk_frame_new("New starting number");
-       gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), frame);
+       gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
 
        button = gtk_spin_button_new_with_range(1, 50000, 1);
        gtk_container_add(GTK_CONTAINER(frame), button);
@@ -329,9 +380,32 @@ static void renumber_dialog(GtkWidget *w, gpointer data)
        gtk_widget_destroy(dialog);
 }
 
+static void about_dialog(GtkWidget *w, gpointer data)
+{
+       const char *logo_property = NULL;
+       GdkPixbuf *logo = NULL;
+       GtkWidget *image = gtk_image_new_from_file("icon.svg");
+
+       if (image) {
+               logo = gtk_image_get_pixbuf(GTK_IMAGE(image));
+               logo_property = "logo";
+       }
+
+       gtk_show_about_dialog(NULL,
+               "program-name", "SubSurface",
+               "comments", "Half-arsed divelog software in C",
+               "license", "GPLv2",
+               "version", VERSION_STRING,
+               "copyright", "Linus Torvalds 2011",
+               /* Must be last: */
+               logo_property, logo,
+               NULL);
+}
+
 static GtkActionEntry menu_items[] = {
        { "FileMenuAction", GTK_STOCK_FILE, "File", NULL, NULL, NULL},
        { "LogMenuAction",  GTK_STOCK_FILE, "Log", NULL, NULL, NULL},
+       { "HelpMenuAction", GTK_STOCK_HELP, "Help", NULL, NULL, NULL},
        { "OpenFile",       GTK_STOCK_OPEN, NULL,   "<control>O", NULL, G_CALLBACK(file_open) },
        { "SaveFile",       GTK_STOCK_SAVE, NULL,   "<control>S", NULL, G_CALLBACK(file_save) },
        { "Print",          GTK_STOCK_PRINT, NULL,  "<control>P", NULL, G_CALLBACK(do_print) },
@@ -339,6 +413,7 @@ static GtkActionEntry menu_items[] = {
        { "Preferences",    NULL, "Preferences", NULL, NULL, G_CALLBACK(preferences_dialog) },
        { "Renumber",       NULL, "Renumber", NULL, NULL, G_CALLBACK(renumber_dialog) },
        { "Quit",           GTK_STOCK_QUIT, NULL,   "<control>Q", NULL, G_CALLBACK(quit) },
+       { "About",           GTK_STOCK_ABOUT, NULL,  NULL, NULL, G_CALLBACK(about_dialog) },
 };
 static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
 
@@ -359,6 +434,9 @@ static const gchar* ui_string = " \
                        <menu name=\"LogMenu\" action=\"LogMenuAction\"> \
                                <menuitem name=\"Renumber\" action=\"Renumber\" /> \
                        </menu> \
+                       <menu name=\"Help\" action=\"HelpMenuAction\"> \
+                               <menuitem name=\"About\" action=\"About\" /> \
+                       </menu> \
                </menubar> \
        </ui> \
 ";
@@ -384,17 +462,99 @@ static void switch_page(GtkNotebook *notebook, gint arg1, gpointer user_data)
        repaint_dive();
 }
 
+static const char notebook_group[] = "123";
+#define GRP_ID ((void *)notebook_group)
+typedef struct {
+       char *name;
+       GtkWidget *widget;
+       GtkWidget *box;
+       gulong delete_handler;
+       gulong destroy_handler;
+} notebook_data_t;
+
+static notebook_data_t nbd[2]; /* we rip at most two notebook pages off */
+
+static GtkNotebook *create_new_notebook_window(GtkNotebook *source,
+               GtkWidget *page,
+               gint x, gint y, gpointer data)
+{
+       GtkWidget *win, *notebook, *vbox;
+       notebook_data_t *nbdp;
+
+       /* pick the right notebook page data and return if both are detached */
+       if (nbd[0].widget == NULL)
+               nbdp = nbd;
+       else if (nbd[1].widget == NULL)
+               nbdp = nbd + 1;
+       else
+               return NULL;
+
+       nbdp->name = strdup(gtk_widget_get_name(page));
+       nbdp->widget = win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+       gtk_window_set_title(GTK_WINDOW(win), nbdp->name);
+       gtk_window_move(GTK_WINDOW(win), x, y);
+
+       /* Destroying the dive list will kill the application */
+       nbdp->delete_handler = g_signal_connect(G_OBJECT(win), "delete-event", G_CALLBACK(on_delete), NULL);
+       nbdp->destroy_handler = g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(on_destroy), NULL);
+
+       nbdp->box = vbox = gtk_vbox_new(FALSE, 0);
+       gtk_container_add(GTK_CONTAINER(win), vbox);
+
+       notebook = gtk_notebook_new();
+       gtk_notebook_set_group(GTK_NOTEBOOK(notebook), GRP_ID);
+       gtk_widget_set_name(notebook, nbdp->name);
+       /* disallow drop events */
+       gtk_drag_dest_set(notebook, 0, NULL, 0, 0);
+       gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 6);
+       gtk_widget_set_size_request(notebook, 450, 350);
+
+       gtk_widget_show_all(win);
+       return GTK_NOTEBOOK(notebook);
+}
+
+static void drag_cb(GtkWidget *widget, GdkDragContext *context,
+       gint x, gint y, guint time,
+       gpointer user_data)
+{
+       GtkWidget *source;
+       notebook_data_t *nbdp;
+
+       source = gtk_drag_get_source_widget(context);
+       if (nbd[0].name && ! strcmp(nbd[0].name,gtk_widget_get_name(source)))
+               nbdp = nbd;
+       else if (nbd[1].name && ! strcmp(nbd[1].name,gtk_widget_get_name(source)))
+               nbdp = nbd + 1;
+       else
+               /* HU? */
+               return;
+
+       gtk_drag_finish(context, TRUE, TRUE, time);
+
+       /* we no longer need the widget - but getting rid of this is hard;
+        * remove the signal handler, remove the notebook from the box
+        * then destroy the widget (and clear out our data structure) */
+       g_signal_handler_disconnect(nbdp->widget,nbdp->delete_handler);
+       g_signal_handler_disconnect(nbdp->widget,nbdp->destroy_handler);
+       gtk_container_remove(GTK_CONTAINER(nbdp->box), source);
+       gtk_widget_destroy(nbdp->widget);
+       nbdp->widget = NULL;
+       free(nbdp->name);
+       nbdp->name = NULL;
+}
+
 void init_ui(int argc, char **argv)
 {
        GtkWidget *win;
-       GtkWidget *paned;
-       GtkWidget *info_box;
        GtkWidget *notebook;
        GtkWidget *dive_info;
        GtkWidget *dive_list;
        GtkWidget *equipment;
        GtkWidget *menubar;
        GtkWidget *vbox;
+       static const GtkTargetEntry notebook_target = {
+               "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, 0
+       };
 
        gtk_init(&argc, &argv);
 
@@ -409,7 +569,11 @@ void init_ui(int argc, char **argv)
                output_units.volume = CUFT;
        if (gconf_client_get_bool(gconf, GCONF_NAME(fahrenheit), NULL))
                output_units.temperature = FAHRENHEIT;
-
+       /* an unset key is FALSE - so in order to get the default behavior right we 
+          invert the meaning of the SAC key */
+       visible_cols.otu = gconf_client_get_bool(gconf, GCONF_NAME(OTU), NULL);
+       visible_cols.sac = ! gconf_client_get_bool(gconf, GCONF_NAME(SAC), NULL);
+               
        divelist_font = gconf_client_get_string(gconf, GCONF_NAME(divelist_font), NULL);
        if (!divelist_font)
                divelist_font = DIVELIST_DEFAULT_FONT;
@@ -417,6 +581,7 @@ void init_ui(int argc, char **argv)
        error_info_bar = NULL;
        win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_icon_from_file(GTK_WINDOW(win), "icon.svg", NULL);
+       g_signal_connect(G_OBJECT(win), "delete-event", G_CALLBACK(on_delete), NULL);
        g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(on_destroy), NULL);
        main_window = win;
 
@@ -427,26 +592,28 @@ void init_ui(int argc, char **argv)
        menubar = get_menubar_menu(win);
        gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);
 
-       /* HPane for left the dive list, and right the dive info */
-       paned = gtk_vpaned_new();
-       gtk_box_pack_end(GTK_BOX(vbox), paned, TRUE, TRUE, 0);
-
-       /* Create the actual divelist */
-       dive_list = dive_list_create();
-       gtk_paned_add2(GTK_PANED(paned), dive_list);
-
-       /* VBox for dive info, and tabs */
-       info_box = gtk_vbox_new(FALSE, 6);
-       gtk_paned_add1(GTK_PANED(paned), info_box);
-
        /* Notebook for dive info vs profile vs .. */
        notebook = gtk_notebook_new();
+       gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 6);
+       gtk_notebook_set_group(GTK_NOTEBOOK(notebook), GRP_ID);
+       g_signal_connect(notebook, "create-window", G_CALLBACK(create_new_notebook_window), NULL);
+       gtk_drag_dest_set(notebook, GTK_DEST_DEFAULT_ALL, &notebook_target, 1, GDK_ACTION_MOVE);
+       g_signal_connect(notebook, "drag-drop", G_CALLBACK(drag_cb), notebook);
        g_signal_connect(notebook, "switch-page", G_CALLBACK(switch_page), NULL);
-       gtk_box_pack_start(GTK_BOX(info_box), notebook, TRUE, TRUE, 6);
+
+       /* Create the actual divelist */
+       dive_list = dive_list_create();
+       gtk_widget_set_name(dive_list, "Dive List");
+       gtk_notebook_append_page(GTK_NOTEBOOK(notebook), dive_list, gtk_label_new("Dive List"));
+       gtk_notebook_set_tab_detachable(GTK_NOTEBOOK(notebook), dive_list, 1);
+       gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(notebook), dive_list, 1);
 
        /* Frame for dive profile */
        dive_profile = dive_profile_widget();
+       gtk_widget_set_name(dive_profile, "Dive Profile");
        gtk_notebook_append_page(GTK_NOTEBOOK(notebook), dive_profile, gtk_label_new("Dive Profile"));
+       gtk_notebook_set_tab_detachable(GTK_NOTEBOOK(notebook), dive_profile, 1);
+       gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(notebook), dive_profile, 1);
 
        /* Frame for extended dive info */
        dive_info = extended_dive_info_widget();
@@ -467,46 +634,6 @@ void run_ui(void)
        gtk_main();
 }
 
-/* get the filenames the user selects and call the parsing function
- * on them
- * return 0 if the user cancelled the dialog
- */
-int open_import_file_dialog(char *filterpattern, char *filtertext, 
-                       void(* parse_function)(char *))
-{
-       int ret=0;
-
-       GtkWidget *dialog;
-       GtkFileFilter *filter = gtk_file_filter_new ();
-       gtk_file_filter_add_pattern (filter, filterpattern);
-       gtk_file_filter_set_name(filter, filtertext);
-       dialog = gtk_file_chooser_dialog_new("Open File",
-                                       GTK_WINDOW(main_window),
-                                       GTK_FILE_CHOOSER_ACTION_OPEN,
-                                       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-                                       GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
-                                       NULL);
-       gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
-       gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog),filter);
-
-       if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
-               GSList *filenames;
-               char *filename;
-               filenames = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
-               while(filenames != NULL) {
-                       filename = (char *)filenames->data;
-                       parse_function(filename);
-                       g_free(filename);
-                       filenames = g_slist_next(filenames);
-               }
-               g_slist_free(filenames);
-               ret = 1;
-       }
-       gtk_widget_destroy(dialog);
-
-       return ret;
-}
-
 static gboolean expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
 {
        struct dive *dive = current_dive;
@@ -567,20 +694,23 @@ static void fill_computer_list(GtkListStore *store)
        }
 }
 
-static GtkComboBox *dive_computer_selector(GtkWidget *dialog)
+static GtkComboBox *dive_computer_selector(GtkWidget *vbox)
 {
-       GtkWidget *hbox, *combo_box;
+       GtkWidget *hbox, *combo_box, *frame;
        GtkListStore *model;
        GtkCellRenderer *renderer;
 
        hbox = gtk_hbox_new(FALSE, 6);
-       gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, FALSE, 3);
+       gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 3);
 
        model = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
        fill_computer_list(model);
 
+       frame = gtk_frame_new("Dive computer");
+       gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 3);
+
        combo_box = gtk_combo_box_new_with_model(GTK_TREE_MODEL(model));
-       gtk_box_pack_start(GTK_BOX(hbox), combo_box, FALSE, TRUE, 3);
+       gtk_container_add(GTK_CONTAINER(frame), combo_box);
 
        renderer = gtk_cell_renderer_text_new();
        gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo_box), renderer, TRUE);
@@ -589,13 +719,31 @@ static GtkComboBox *dive_computer_selector(GtkWidget *dialog)
        return GTK_COMBO_BOX(combo_box);
 }
 
+static GtkEntry *dive_computer_device(GtkWidget *vbox)
+{
+       GtkWidget *hbox, *entry, *frame;
+
+       hbox = gtk_hbox_new(FALSE, 6);
+       gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 3);
+
+       frame = gtk_frame_new("Device name");
+       gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, TRUE, 3);
+
+       entry = gtk_entry_new();
+       gtk_container_add(GTK_CONTAINER(frame), entry);
+       gtk_entry_set_text(GTK_ENTRY(entry), "/dev/ttyUSB0");
+
+       return GTK_ENTRY(entry);
+}
+
 void import_dialog(GtkWidget *w, gpointer data)
 {
        int result;
-       GtkWidget *dialog, *hbox;
+       GtkWidget *dialog, *hbox, *vbox;
        GtkComboBox *computer;
+       GtkEntry *device;
        device_data_t devicedata = {
-               .devname = "/dev/ttyUSB0",
+               .devname = NULL,
        };
 
        dialog = gtk_dialog_new_with_buttons("Import from dive computer",
@@ -605,12 +753,15 @@ void import_dialog(GtkWidget *w, gpointer data)
                GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
                NULL);
 
-       computer = dive_computer_selector(dialog);
+       vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+
+       computer = dive_computer_selector(vbox);
+       device = dive_computer_device(vbox);
 
        hbox = gtk_hbox_new(FALSE, 6);
-       gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, TRUE, 3);
-       devicedata.progress->bar = gtk_progress_bar_new();
-       gtk_container_add(GTK_CONTAINER(hbox), devicedata.progress->bar);
+       gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 3);
+       devicedata.progress.bar = gtk_progress_bar_new();
+       gtk_container_add(GTK_CONTAINER(hbox), devicedata.progress.bar);
 
        gtk_widget_show_all(dialog);
        result = gtk_dialog_run(GTK_DIALOG(dialog));
@@ -629,6 +780,7 @@ void import_dialog(GtkWidget *w, gpointer data)
                        -1);
                devicedata.type = type;
                devicedata.name = comp;
+               devicedata.devname = gtk_entry_get_text(device);
                do_import(&devicedata);
                break;
        default:
@@ -644,3 +796,11 @@ void update_progressbar(progressbar_t *progress, double value)
 {
        gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress->bar), value);
 }
+
+
+void set_filename(const char *filename)
+{
+       if (filename)
+               existing_filename = strdup(filename);
+       return;
+}