Makefile cleanup, start implementation of nval commands (not working yet)
[metawatch.git] / mw_main.c
index 406e09c..17b52ad 100644 (file)
--- a/mw_main.c
+++ b/mw_main.c
 #include <dbus/dbus-glib.h>
 #include <dbus/dbus-glib-lowlevel.h>
 
+#include <libsoup/soup.h>
+
+#include <libxml/tree.h>
+#include <libxml/parser.h>
+
 /*
 #include <bluetooth/sdp.h>
 #include <bluetooth/sdp_lib.h>
@@ -44,6 +49,8 @@ typedef struct {
        int con_fd;             /* console input fd */
        char cmdline[128];
        int cmdline_pos;
+       SoupSession *msoup;
+       SoupMessage *smsg;
 } mwdata_t;
 
 void bitmap_test(mwdevice_t *mwdevice)
@@ -430,6 +437,32 @@ void test_oled(mwdevice_t *mwdevice, unsigned char oled)
        mw_free_pbuffer(mwbuf);
 }
 
+static void
+weather_soup_callback (SoupSession *session, SoupMessage *msg, gpointer user_data)
+{
+       xmlDocPtr xdoc;
+
+       /* Handle the response here */
+       if (msg->response_body->data != NULL && msg->response_body->length != 0) {
+               fprintf(stderr, "%s\n", msg->response_body->data);
+               xdoc = xmlReadMemory(msg->response_body->data, msg->response_body->length, "noname.xml", NULL, 0);
+               if (xdoc == NULL) {
+                       fprintf(stderr, "Failed to parse document\n");
+                       return;
+               }
+               xmlFreeDoc(xdoc);
+               xmlCleanupParser();
+       }
+}
+
+void do_weather(mwdata_t *mwdata)
+{
+       mwdata->msoup = soup_session_async_new();
+       mwdata->smsg = soup_message_new ("GET", "http://www.google.com/ig/api?weather=siegen&hl=de");
+       soup_session_send_message (mwdata->msoup, mwdata->smsg);
+       soup_session_queue_message (mwdata->msoup, mwdata->smsg, weather_soup_callback, mwdata);
+}
+
 void print_help(void)
 {
 }
@@ -535,6 +568,18 @@ void process_cmd(char *cmdline, int clinep, mwdata_t *mwdata)
        if (strncmp(cmdline, "cal", 3) == 0) {
                draw_idle_calendar(&mwdata->mwdevice);
        }
+       if (strncmp(cmdline, "wet", 3) == 0) {
+               do_weather(mwdata);
+       }
+       if (strncmp(cmdline, "c24", 3) == 0) {
+               mdata[0] = MW_RTC_CLOCK_24HR;
+               mw_nval_operation(&mwdata->mwdevice, MW_NVAL_OPERATION_WRITE, MW_NVAL_TIME_FORMAT, 1, mdata);
+       }
+       if (strncmp(cmdline, "g24", 3) == 0) {
+               mdata[0] = 0;
+               mdata[1] = 0;
+               mw_nval_operation(&mwdata->mwdevice, MW_NVAL_OPERATION_READ, MW_NVAL_TIME_FORMAT, 2, mdata);
+       }
 }