aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--divelist-gtk.c53
-rw-r--r--webservice.c7
-rw-r--r--webservice.h2
3 files changed, 52 insertions, 10 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);
}
diff --git a/webservice.c b/webservice.c
index f11dc37a9..c01b1a844 100644
--- a/webservice.c
+++ b/webservice.c
@@ -359,7 +359,7 @@ static gboolean divelogde_dialog(const char **user, const char **pass)
return ret;
}
-int divelogde_upload(char *fn)
+int divelogde_upload(char *fn, char **error)
{
SoupMessage *msg;
SoupMultipart *multipart;
@@ -386,10 +386,7 @@ int divelogde_upload(char *fn)
soup_message_headers_append(msg->request_headers, "Accept", "text/xml");
soup_session_send_message(session, msg);
if (SOUP_STATUS_IS_SUCCESSFUL(msg->status_code)) {
- /* we should really check if the XML returned indicates that
- * the profiles were successfully uploaded...
- */
- fprintf(stderr, "%s\n", (gchar *)msg->response_body->data);
+ *error = strdup(msg->response_body->data);
ret = TRUE;
}
soup_session_abort(session);
diff --git a/webservice.h b/webservice.h
index bb3a71f3b..e1eb0ce47 100644
--- a/webservice.h
+++ b/webservice.h
@@ -1,3 +1,3 @@
extern void webservice_download_dialog(void);
extern gboolean webservice_request_user_xml(const gchar *, gchar **, guint *, guint *);
-extern int divelogde_upload(char *fn);
+extern int divelogde_upload(char *fn, char **error);