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>
This commit is contained in:
Miika Turkia 2013-04-27 16:10:26 +03:00 committed by Dirk Hohndel
parent 5c4a7c7498
commit 172982b860
3 changed files with 52 additions and 10 deletions

View file

@ -1366,6 +1366,30 @@ static void delete_dive_cb(GtkWidget *menuitem, GtkTreePath *path)
mark_divelist_changed(TRUE); 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) #if defined(LIBZIP) && defined(XSLT)
static void upload_dives_divelogs(const gboolean selected) 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_source *s[dive_table.nr];
struct zip *zip; struct zip *zip;
const gchar *tmpdir = g_get_tmp_dir(); const gchar *tmpdir = g_get_tmp_dir();
GtkMessageType type;
char *error = NULL;
/* /*
* Creating a temporary .DLD file to be eventually uploaded to * 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); zip_close(zip);
if (divelogde_upload(tempfile)) if (!divelogde_upload(tempfile, &error)) {
g_unlink(tempfile); error = strdup(_("Communication error with divelogs.de"));
else type = GTK_MESSAGE_ERROR;
fprintf(stderr,"upload of %s failed\n", tempfile); } 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); g_free(tempfile);
} }

View file

@ -359,7 +359,7 @@ static gboolean divelogde_dialog(const char **user, const char **pass)
return ret; return ret;
} }
int divelogde_upload(char *fn) int divelogde_upload(char *fn, char **error)
{ {
SoupMessage *msg; SoupMessage *msg;
SoupMultipart *multipart; SoupMultipart *multipart;
@ -386,10 +386,7 @@ int divelogde_upload(char *fn)
soup_message_headers_append(msg->request_headers, "Accept", "text/xml"); soup_message_headers_append(msg->request_headers, "Accept", "text/xml");
soup_session_send_message(session, msg); soup_session_send_message(session, msg);
if (SOUP_STATUS_IS_SUCCESSFUL(msg->status_code)) { if (SOUP_STATUS_IS_SUCCESSFUL(msg->status_code)) {
/* we should really check if the XML returned indicates that *error = strdup(msg->response_body->data);
* the profiles were successfully uploaded...
*/
fprintf(stderr, "%s\n", (gchar *)msg->response_body->data);
ret = TRUE; ret = TRUE;
} }
soup_session_abort(session); soup_session_abort(session);

View file

@ -1,3 +1,3 @@
extern void webservice_download_dialog(void); extern void webservice_download_dialog(void);
extern gboolean webservice_request_user_xml(const gchar *, gchar **, guint *, guint *); 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);