summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-05-02 12:49:03 -0700
committerGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-05-02 12:49:03 -0700
commitb0ba22a06879697efa7c429b9df8e13feaa02480 (patch)
tree7b5391ba66ea08de8e296c7abcd97a0a96fd9fec
parentc8f3dc3594aa850829ab87ac7d290776dfb846bd (diff)
downloadsubsurface-b0ba22a06879697efa7c429b9df8e13feaa02480.tar.gz
Show dive import error messages in the import dialog
.. not in the main window. And leave the import dialog open, so that you can either try doing it again, or cancel. This makes it much easier to re-try a failed dive import, and actually makes the failure more obvious too. Todo: - make the "Ok" button change to "Retry" when an error happens - try to see if we can catch the actual status update messages from libdivecomputer and show them too in the import dialog. Right now they are printed out to stderr by the library. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--gtk-gui.c26
-rw-r--r--libdivecomputer.c10
-rw-r--r--libdivecomputer.h2
3 files changed, 30 insertions, 8 deletions
diff --git a/gtk-gui.c b/gtk-gui.c
index ca033835d..0bc79954f 100644
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -1013,10 +1013,27 @@ static void do_import_file(gpointer data, gpointer user_data)
}
}
+static GtkWidget *import_dive_computer(device_data_t *data, GtkBox *vbox)
+{
+ GError *error;
+ GtkWidget *info, *container, *label;
+
+ error = do_import(data);
+ if (!error)
+ return NULL;
+
+ 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(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 +1059,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 +1071,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 +1086,9 @@ 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);
+ info = import_dive_computer(&devicedata, GTK_BOX(vbox));
+ if (info)
+ goto repeat;
} else {
g_slist_foreach(list,do_import_file,NULL);
g_slist_free(list);
diff --git a/libdivecomputer.c b/libdivecomputer.c
index 14f794e8c..4495b1716 100644
--- a/libdivecomputer.c
+++ b/libdivecomputer.c
@@ -18,7 +18,7 @@
#define NOT_FROG
#endif
-static void error(const char *fmt, ...)
+static GError *error(const char *fmt, ...)
{
va_list args;
GError *error;
@@ -28,8 +28,7 @@ static void error(const char *fmt, ...)
g_quark_from_string("subsurface"),
DIVE_ERROR_PARSE, fmt, args);
va_end(args);
- report_error(error);
- g_error_free(error);
+ return error;
}
static parser_status_t create_parser(device_data_t *devdata, parser_t **parser)
@@ -512,7 +511,7 @@ static void *pthread_wrapper(void *_data)
return (void *)err_string;
}
-void do_import(device_data_t *data)
+GError *do_import(device_data_t *data)
{
pthread_t pthread;
void *retval;
@@ -527,7 +526,8 @@ void do_import(device_data_t *data)
if (pthread_join(pthread, &retval) < 0)
retval = "Odd pthread error return";
if (retval)
- error(retval, data->name, data->devname);
+ return error(retval, data->name, data->devname);
+ return NULL;
}
/*
diff --git a/libdivecomputer.h b/libdivecomputer.h
index 57d274cc6..c6e99fa73 100644
--- a/libdivecomputer.h
+++ b/libdivecomputer.h
@@ -34,6 +34,6 @@ struct device_list {
};
extern struct device_list device_list[];
-extern void do_import(device_data_t *data);
+extern GError *do_import(device_data_t *data);
#endif