X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=gtk-gui.c;h=1e053e52b22837b3ed9df9554b337e25bf9da749;hb=e5692a77c3f99fe485f6490f567f6cc9cea2adff;hp=ca033835d31630a9144fdbb3505a2a612f9ca267;hpb=c8f3dc3594aa850829ab87ac7d290776dfb846bd;p=ext%2Fsubsurface.git diff --git a/gtk-gui.c b/gtk-gui.c index ca03383..1e053e5 100644 --- a/gtk-gui.c +++ b/gtk-gui.c @@ -32,12 +32,18 @@ static GtkWidget *dive_profile; visible_cols_t visible_cols = {TRUE, FALSE}; static const char *default_dive_computer; +static const char *default_dive_computer_device; static int is_default_dive_computer(const char *name) { return default_dive_computer && !strcmp(name, default_dive_computer); } +static int is_default_dive_computer_device(const char *name) +{ + return default_dive_computer_device && !strcmp(name, default_dive_computer_device); +} + static void set_default_dive_computer(const char *name) { if (!name || !*name) @@ -48,6 +54,16 @@ static void set_default_dive_computer(const char *name) subsurface_set_conf("dive_computer", PREF_STRING, name); } +static void set_default_dive_computer_device(const char *name) +{ + if (!name || !*name) + return; + if (is_default_dive_computer_device(name)) + return; + default_dive_computer_device = name; + subsurface_set_conf("dive_computer_device", PREF_STRING, name); +} + void repaint_dive(void) { update_dive(current_dive); @@ -624,13 +640,13 @@ static const gchar* ui_string = " \ \ \ \ - \ - \ \ - \ + \ \ \ \ + \ + \ \ \ \ @@ -709,6 +725,7 @@ void init_ui(int *argcp, char ***argvp) divelist_font = subsurface_get_conf("divelist_font", PREF_STRING); default_dive_computer = subsurface_get_conf("dive_computer", PREF_STRING); + default_dive_computer_device = subsurface_get_conf("dive_computer_device", PREF_STRING); error_info_bar = NULL; win = gtk_window_new(GTK_WINDOW_TOPLEVEL); @@ -939,6 +956,14 @@ static GtkComboBox *dive_computer_selector(GtkWidget *vbox) return GTK_COMBO_BOX(combo_box); } +const char *subsurface_device_name() +{ + if (!default_dive_computer_device || !*default_dive_computer_device) + return subsurface_USB_name(); + else + return default_dive_computer_device; +} + static GtkEntry *dive_computer_device(GtkWidget *vbox) { GtkWidget *hbox, *entry, *frame; @@ -951,7 +976,7 @@ static GtkEntry *dive_computer_device(GtkWidget *vbox) entry = gtk_entry_new(); gtk_container_add(GTK_CONTAINER(frame), entry); - gtk_entry_set_text(GTK_ENTRY(entry), subsurface_USB_name()); + gtk_entry_set_text(GTK_ENTRY(entry), subsurface_device_name()); return GTK_ENTRY(entry); } @@ -1013,10 +1038,33 @@ static void do_import_file(gpointer data, gpointer user_data) } } +static GtkWidget *import_dive_computer(device_data_t *data, GtkDialog *dialog) +{ + GError *error; + GtkWidget *vbox, *info, *container, *label, *button; + + error = do_import(data); + if (!error) + return NULL; + + button = gtk_dialog_get_widget_for_response(dialog, GTK_RESPONSE_ACCEPT); + gtk_button_set_use_stock(GTK_BUTTON(button), 0); + gtk_button_set_label(GTK_BUTTON(button), "Retry"); + + vbox = gtk_dialog_get_content_area(dialog); + + info = gtk_info_bar_new(); + container = gtk_info_bar_get_content_area(GTK_INFO_BAR(info)); + label = gtk_label_new(error->message); + gtk_container_add(GTK_CONTAINER(container), label); + gtk_box_pack_start(GTK_BOX(vbox), info, FALSE, FALSE, 0); + return info; +} + void import_dialog(GtkWidget *w, gpointer data) { int result; - GtkWidget *dialog, *hbox, *vbox, *label; + GtkWidget *dialog, *hbox, *vbox, *label, *info = NULL; GtkComboBox *computer; GtkEntry *device; GtkWidget *XMLchooser; @@ -1042,6 +1090,7 @@ void import_dialog(GtkWidget *w, gpointer data) devicedata.progress.bar = gtk_progress_bar_new(); gtk_container_add(GTK_CONTAINER(hbox), devicedata.progress.bar); +repeat: gtk_widget_show_all(dialog); result = gtk_dialog_run(GTK_DIALOG(dialog)); switch (result) { @@ -1053,6 +1102,8 @@ void import_dialog(GtkWidget *w, gpointer data) case GTK_RESPONSE_ACCEPT: /* what happened - did the user pick a file? In that case * we ignore whether a dive computer model was picked */ + if (info) + gtk_widget_destroy(info); list = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(XMLchooser)); if (g_slist_length(list) == 0) { if (!gtk_combo_box_get_active_iter(computer, &iter)) @@ -1066,7 +1117,10 @@ void import_dialog(GtkWidget *w, gpointer data) devicedata.name = comp; devicedata.devname = gtk_entry_get_text(device); set_default_dive_computer(devicedata.name); - do_import(&devicedata); + set_default_dive_computer_device(devicedata.devname); + info = import_dive_computer(&devicedata, GTK_DIALOG(dialog)); + if (info) + goto repeat; } else { g_slist_foreach(list,do_import_file,NULL); g_slist_free(list); @@ -1085,6 +1139,10 @@ void update_progressbar(progressbar_t *progress, double value) gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress->bar), value); } +void update_progressbar_text(progressbar_t *progress, const char *text) +{ + gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress->bar), text); +} void set_filename(const char *filename) {