#include <string.h>

#include <panel-applet.h>
#include <gtk/gtklabel.h>
#include <ghttp.h>

static gboolean gadsm_applet_fill (
      PanelApplet *applet,
      const gchar *iid,
      gpointer data)
{
   GtkWidget *label;

   if (strcmp (iid, "OAFIID:GADSM") != 0)
      return FALSE;

   /* This is the http request object */
   ghttp_request *request = NULL;
   /* Allocate a new empty request object */
   request = ghttp_request_new();
   /* Set the URI for the request object */
   ghttp_set_uri(request, "http://localhost:8080/index.html");
   /* Close the connection after you are done. */
   ghttp_set_header(request, http_hdr_Connection, "close");
   /* Prepare the connection */
   ghttp_prepare(request);
   /* Process the request */
   ghttp_process(request);
   /* Write out the body. Note that the body of the request may not be null terminated so we have to be careful of the length. */
   fwrite(ghttp_get_body(request), ghttp_get_body_len(request), 1, stdout);
   /* Destroy the request. This closes any file descriptors that may be open and will free any memory associated with the request. */
   ghttp_request_destroy(request);

   label = gtk_label_new ("Hello World");
   gtk_container_add (GTK_CONTAINER (applet), label);

   gtk_widget_show_all (GTK_WIDGET (applet));

   return TRUE;
}

PANEL_APPLET_BONOBO_FACTORY ("OAFIID:GADSM_Factory",
      PANEL_TYPE_APPLET,
      "The Hello World Applet",
      "0",
      gadsm_applet_fill,
      NULL);
