summaryrefslogtreecommitdiffstats
path: root/divelist-gtk.c
diff options
context:
space:
mode:
authorGravatar Miika Turkia <miika.turkia@gmail.com>2013-04-27 16:10:26 +0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-04-27 21:00:11 -0700
commit172982b86038812e8914d1017c910168cf80e640 (patch)
treef1f6526f2de99019a6b18b375608bc0d91ded3f7 /divelist-gtk.c
parent5c4a7c749885efc620f168860c051631e18ea786 (diff)
downloadsubsurface-172982b86038812e8914d1017c910168cf80e640.tar.gz
Display divelogs.de upload status to the user
This shows a dialog indicating the success or failure of divelogs.de upload. Currently the raw XML returned from the SOAP request is also displayed. Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'divelist-gtk.c')
-rw-r--r--divelist-gtk.c53
1 files changed, 49 insertions, 4 deletions
diff --git a/divelist-gtk.c b/divelist-gtk.c
index f523805c1..8bc836589 100644
--- a/divelist-gtk.c
+++ b/divelist-gtk.c
@@ -1366,6 +1366,30 @@ static void delete_dive_cb(GtkWidget *menuitem, GtkTreePath *path)
mark_divelist_changed(TRUE);
}
+void divelogs_status_dialog(char *error, GtkMessageType type)
+{
+ GtkWidget *dialog, *vbox, *label;
+
+ dialog = gtk_message_dialog_new(
+ GTK_WINDOW(main_window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ type,
+ GTK_BUTTONS_OK,
+ _("%s: Response from divelogs.de"), type == GTK_MESSAGE_INFO ? _("Info") : _("Error")
+ );
+
+ vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+
+ label = create_label("%s", error);
+ gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
+
+ gtk_widget_show_all(dialog);
+ gtk_dialog_run(GTK_DIALOG(dialog));
+
+ gtk_widget_destroy(dialog);
+
+}
+
#if defined(LIBZIP) && defined(XSLT)
static void upload_dives_divelogs(const gboolean selected)
{
@@ -1381,6 +1405,8 @@ static void upload_dives_divelogs(const gboolean selected)
struct zip_source *s[dive_table.nr];
struct zip *zip;
const gchar *tmpdir = g_get_tmp_dir();
+ GtkMessageType type;
+ char *error = NULL;
/*
* Creating a temporary .DLD file to be eventually uploaded to
@@ -1451,10 +1477,29 @@ static void upload_dives_divelogs(const gboolean selected)
}
}
zip_close(zip);
- if (divelogde_upload(tempfile))
- g_unlink(tempfile);
- else
- fprintf(stderr,"upload of %s failed\n", tempfile);
+ if (!divelogde_upload(tempfile, &error)) {
+ error = strdup(_("Communication error with divelogs.de"));
+ type = GTK_MESSAGE_ERROR;
+ } else {
+ /* The upload status XML message should be parsed
+ * properly and displayed in a sensible manner. But just
+ * displaying the raw message is better than nothing.
+ * And at least the dialog is customized to indicate
+ * error or success.
+ */
+ if (strstr(error, "failed"))
+ type = GTK_MESSAGE_ERROR;
+ else
+ type = GTK_MESSAGE_INFO;
+ }
+
+
+ if (error) {
+ divelogs_status_dialog(error, type);
+ free(error);
+ }
+
+ g_unlink(tempfile);
g_free(tempfile);
}