#include <libintl.h>
#include <locale.h>
#include <gtkhtml/gtkhtml.h>
+#include <gtkhtml/gtkhtml-stream.h>
#include "utils.h"
#include "poi.h"
return TRUE;
}
+/**
+ * Url click callback
+ */
static void
-poi_info_url_cb(GtkHTML *html, const gchar *url, gpointer data)
+poi_info_url_clicked_cb(GtkHTML *html, const gchar *url, gpointer data)
{
g_printf("URL: %s\n", url);
#ifdef WITH_OSSO
OSSO_BROWSER_OPEN_NEW_WINDOW_REQ, NULL,
DBUS_TYPE_STRING, url, DBUS_TYPE_BOOLEAN, FALSE, DBUS_TYPE_INVALID);
#else
-
+g_debug("Not yet implemented for !OSSO\n");
#endif
}
+
+/**
+ * Callback to load requested url
+ */
+static void
+poi_info_url_requested_cb(GtkHTML *html, const char *url, GtkHTMLStream *stream)
+{
+g_printf("URL: %s\n", url);
+gtk_html_stream_close(stream, GTK_HTML_STREAM_ERROR);
+}
+
+static void
+poi_info_title_cb(GtkHTML *html, const gchar *title)
+{
+g_printf("Title: %s\n", title);
+}
+
+#define WRITE_HTML(html, args...) \
+ { gchar *ph; \
+ ph=g_markup_printf_escaped(html, ##args); \
+ gtk_html_write(GTK_HTML(info), s, ph, strlen(ph)); \
+ g_free(ph); }
+
+/**
+ * Display a nice POI information dialog
+ *
+ */
gboolean
poi_info_dialog(guint poi_id)
{
GtkWidget *info;
GtkWidget *sw;
poi_info *p;
-gchar *phtml;
+GtkHTMLStream *s;
gint ls;
p=poi_get_by_id(poi_id);
-if (!p)
+if (!p) {
+ g_debug("Requested info for POI %d that does not exist!\n", poi_id);
return FALSE;
-
-ls=strlen(p->label);
-
-phtml=g_markup_printf_escaped(
- "<html><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"
- "<body>"
- "<b>%s%s</b><br><table>"
- "<tr><th align=\"left\">Location:</th><td>%f, %f</td></tr>"
- "<tr><th align=\"left\">Public:</th><td>%s</td></tr>"
- "<tr><th align=\"left\">Source:</th><td>%s</td></tr>"
- "<tr><th align=\"left\">Category:</th><td>%s</td></tr>"
- "<tr><th align=\"left\">Description:</th><td>%s</td></tr>"
- "<tr><th align=\"left\">URL:</th><td><a href=\"%s\">%s</a></td></tr>"
- "<tr><th align=\"left\">Postal Code:</th><td>%s</td></tr>"
- "</table></body></html>",
- ls>0 ? p->label : p->cat_label,
- ls==0 ? " (No name)" : "",
- p->lat, p->lon,
- p->public==1 ? "Yes" : "No",
- p->source==POI_SOURCE_OSM ? "OpenStreetMap" : "Other",
- p->cat_label ? p->cat_label : "",
- p->desc ? p->desc : "",
- p->url ? p->url : "",
- p->url ? p->url : "",
- p->postal_code ? p->postal_code : "");
+}
dialog=gtk_dialog_new_with_buttons(_("POI"),
- GTK_WINDOW(_window),
- GTK_DIALOG_MODAL,
- GTK_STOCK_OK,
- GTK_RESPONSE_ACCEPT,
+ GTK_WINDOW(_window), GTK_DIALOG_MODAL,
+ GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
NULL);
/* XXX: Add edit button */
gtk_container_add(GTK_CONTAINER(sw), info);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), sw, TRUE, TRUE, 0);
-g_signal_connect(G_OBJECT(info), "link_clicked", G_CALLBACK(poi_info_url_cb), NULL);
+g_signal_connect(G_OBJECT(info), "link_clicked", G_CALLBACK(poi_info_url_clicked_cb), NULL);
+g_signal_connect(G_OBJECT(info), "url_requested", G_CALLBACK(poi_info_url_requested_cb), NULL);
+g_signal_connect(G_OBJECT(info), "title_changed", G_CALLBACK(poi_info_title_cb), dialog);
+
+s=gtk_html_begin(GTK_HTML(info));
+ls=strlen(p->label);
+
+/* XXX: Format lat/lon according to settings */
+
+WRITE_HTML("<html><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">" \
+ "<head><title>POI - %s</title></head><body><b>%s (<i>%s</i>)</b><br/><table>" \
+ "<tr><th align=\"left\">Location:</th><td>%.5f, %.5f</td></tr>",
+ ls>0 ? p->label : _("(Unknown)"),
+ ls>0 ? p->label : _("(Unknown)"), p->cat_label,
+ p->lat, p->lon);
-gtk_html_load_from_string(info, phtml, -1);
+if (p->postal_code)
+ WRITE_HTML("<tr><th align=\"left\">Postal Code:</th><td>%s</td></tr>", p->postal_code);
+if (p->url)
+ WRITE_HTML("<tr><th align=\"left\">Link:</th><td><a href=\"%s\">%s</a></td></tr>", p->url, p->url);
+if (p->desc)
+ WRITE_HTML("<tr><th align=\"left\" colspan=\"2\">Description:</th><td colspan=\"2\">%s</td></tr>", p->desc);
+
+WRITE_HTML("</table><br/>");
+
+# if 0
+if (p->image)
+ WRITE_HTML("<img src=\"%s\">", p->image);
+#endif
+
+WRITE_HTML("</body></html>");
+gtk_html_end(GTK_HTML(info), s, GTK_HTML_STREAM_OK);
+
+poi_free(p);
gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 250);
gtk_widget_show_all(dialog);
gtk_dialog_run(dialog);
gtk_widget_destroy(dialog);
-g_free(phtml);
-poi_free(p);
-
return TRUE;
}
+
/**
* poi_edit_dialog
*