summaryrefslogtreecommitdiffstats
path: root/webservice.c
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-06-06 11:31:55 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-06-06 11:31:55 -0300
commitf55ae1570738ec4e890ec35504e2c1e5c81364cc (patch)
tree7185ea93b9b90ab9b0bc3b0a406d6f0e5343396f /webservice.c
parentc1cf6c02a8a82296840d3a4c6948bc04a5bb5e51 (diff)
downloadsubsurface-f55ae1570738ec4e890ec35504e2c1e5c81364cc.tar.gz
Hoocked up the buttons and the parsing of the XML.
The XML is now being correctly parsed, Clicking on Help will open the browser pointing to the api site, and clicking on cancel will cancel the download. Clicking on Apply still doesn't apply, but that's next. :) Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Diffstat (limited to 'webservice.c')
-rw-r--r--webservice.c60
1 files changed, 2 insertions, 58 deletions
diff --git a/webservice.c b/webservice.c
index f4f8baeb4..2ac19c85a 100644
--- a/webservice.c
+++ b/webservice.c
@@ -1,36 +1,16 @@
#include <libintl.h>
#include <glib/gi18n.h>
#include <libsoup/soup.h>
-#include <libxml/tree.h>
-#include <libxml/parser.h>
+
#include "dive.h"
#include "divelist.h"
#include "display-gtk.h"
#include "file.h"
+#include "webservice.h"
struct dive_table gps_location_table;
static gboolean merge_locations_into_dives(void);
-enum {
- DD_STATUS_OK,
- DD_STATUS_ERROR_CONNECT,
- DD_STATUS_ERROR_ID,
- DD_STATUS_ERROR_PARSE,
-};
-
-static const gchar *download_dialog_status_text(const gint status)
-{
- switch (status) {
- case DD_STATUS_ERROR_CONNECT:
- return _("Connection Error: ");
- case DD_STATUS_ERROR_ID:
- return _("Invalid user identifier!");
- case DD_STATUS_ERROR_PARSE:
- return _("Cannot parse response!");
- }
- return _("Download Success!");
-}
-
/* provides a state of the download dialog contents and the downloaded xml */
struct download_dialog_state {
GtkWidget *uid;
@@ -73,42 +53,6 @@ gboolean webservice_request_user_xml(const gchar *user_id,
return ret;
}
-/* requires that there is a <download> or <error> tag under the <root> tag */
-static void download_dialog_traverse_xml(xmlNodePtr node, guint *download_status)
-{
- xmlNodePtr cur_node;
- for (cur_node = node; cur_node; cur_node = cur_node->next) {
- if ((!strcmp((const char *)cur_node->name, (const char *)"download")) &&
- (!strcmp((const char *)xmlNodeGetContent(cur_node), (const char *)"ok"))) {
- *download_status = DD_STATUS_OK;
- return;
- } else if (!strcmp((const char *)cur_node->name, (const char *)"error")) {
- *download_status = DD_STATUS_ERROR_ID;
- return;
- }
- }
-}
-
-static guint download_dialog_parse_response(gchar *xmldata, guint len)
-{
- xmlNodePtr root;
- xmlDocPtr doc = xmlParseMemory(xmldata, len);
- guint status = DD_STATUS_ERROR_PARSE;
-
- if (!doc)
- return DD_STATUS_ERROR_PARSE;
- root = xmlDocGetRootElement(doc);
- if (!root) {
- status = DD_STATUS_ERROR_PARSE;
- goto end;
- }
- if (root->children)
- download_dialog_traverse_xml(root->children, &status);
- end:
- xmlFreeDoc(doc);
- return status;
-}
-
static void download_dialog_connect_cb(GtkWidget *w, gpointer data)
{
struct download_dialog_state *state = (struct download_dialog_state *)data;