#include "settings.h"
#include "poi-gui.h"
#include "osm.h"
-
+#include "osm-db.h"
+#include "dialogs.h"
#include "help.h"
+#include "track.h"
+#include "poi-gui.h"
#ifdef WITH_OSSO
#include <libosso.h>
#include "ui-maemo.h"
#endif
-#define POI_QUICK_BUTTONS (9)
-
typedef struct _search_dialog search_dialog;
struct _search_dialog {
GtkWidget *dialog;
const gchar *name;
};
+#define QPBS_X (4)
+#define QPBS_Y (3)
+#define POI_QUICK_BUTTONS (QPBS_X*QPBS_Y)
+
static struct _quick_poi_categories quick_poi_categories[] = {
{ NODE_AMENITY_SPEEDCAM, "Speedcam", },
{ NODE_AMENITY_FUEL, "Fuel", },
{ NODE_AMENITY_PARKING, "Parking", },
+ { NODE_AMENITY_TAXI, "Taxi", },
{ NODE_AMENITY_PUB, "Pub", },
{ NODE_AMENITY_CAFE, "Cafe", },
- { NODE_AMENITY_FOOD, "Food", },
+ { NODE_AMENITY_FOOD, "Fast Food", },
+ { NODE_AMENITY_RESTAURANT, "Restaurant", },
{ NODE_AMENITY_SHOP, "Shop", },
{ NODE_AMENITY_BANK, "Bank", },
{ NODE_AMENITY_ATM, "ATM", },
+ { NODE_AMENITY_POST_BOX, "Post box", },
};
-/* Quick POI information structure */
-typedef struct _poi_quick_data poi_quick_data;
-static struct _poi_quick_data {
- GtkWidget *dialog;
- GtkWidget *label;
- gdouble lat;
- gdouble lon;
-} qp;
+static poi_quick_data qp;
static gboolean
category_delete(GtkWidget *widget, delete_poi *dpoi)
dialog = gtk_dialog_new_with_buttons(_("POI Categories"),
GTK_WINDOW(_window),
- GTK_DIALOG_MODAL, GTK_STOCK_OK,
+ GTK_DIALOG_MODAL, GTK_STOCK_CLOSE,
GTK_RESPONSE_ACCEPT, NULL);
help_dialog_help_enable(GTK_DIALOG(dialog), HELP_ID_POICAT);
g_signal_connect(G_OBJECT(btn_add), "clicked", G_CALLBACK(category_add_cb), tree_view);
gtk_widget_show_all(dialog);
-while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
- break;
-}
+gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
return TRUE;
else
cid=-1;
-if ((strlen(gtk_entry_get_text(sd->search_entry))<2) && (cid==-1)) {
+if ((strlen(gtk_entry_get_text(GTK_ENTRY(sd->search_entry)))<2) && (cid==-1)) {
popup_error(sd->dialog, _("Query string too short. Minimum 2 characters."));
return TRUE;
}
-s=g_strdup(gtk_entry_get_text(sd->search_entry));
+s=g_strdup(gtk_entry_get_text(GTK_ENTRY(sd->search_entry)));
g_printf("Search: [%s]\n", s);
#if 0
gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 250);
gtk_widget_show_all(dialog);
-gtk_dialog_run(dialog);
+gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
return TRUE;
}
static gboolean
-poi_quick_button_cb(GtkWidget *w, gpointer data)
+poi_quick_button_cb(GtkWidget *button, gpointer data)
{
poi_info *p;
+poi_quick_data *qpdata=(poi_quick_data *)data;
+
+g_assert(data);
p=poi_new();
-p->cat_id=GPOINTER_TO_INT(data);
+p->cat_id=GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button), "pid"));
-if (strlen(gtk_entry_get_text(GTK_ENTRY(qp.label)))>0) {
- p->label=g_strdup(gtk_entry_get_text(GTK_ENTRY(qp.label)));
+if (strlen(gtk_entry_get_text(GTK_ENTRY(qpdata->label)))>0) {
+ p->label=g_strdup(gtk_entry_get_text(GTK_ENTRY(qpdata->label)));
} else {
p->label=g_strdup("");
}
-p->lat=qp.lat;
-p->lon=qp.lon;
+if (qpdata->fixed==TRUE) {
+ p->lat=qpdata->lat;
+ p->lon=qpdata->lon;
+} else {
+ p->lat=_gps->data.lat;
+ p->lon=_gps->data.lon;
+}
p->desc=g_strdup("Quick POI, update information please.");
/* poi_add frees the label and desc so strdup */
gchar *txt;
map_poi_cache_clear();
- map_force_redraw();
- gtk_widget_destroy(qp.dialog);
/* Add a text break to the current track */
- txt=g_strdup_printf("QP: %f %f %s", p->lat, p->lon, p->label);
+ /* XXX: Get category string in here if label is empty */
+ txt=g_strdup_printf("QP(%d): %f %f %s", p->cat_id, p->lat, p->lon, p->label);
track_insert_mark_text(txt);
+
+ map_force_redraw();
+ if (qpdata->close==TRUE)
+ gtk_widget_destroy(qpdata->dialog);
+
+ hildon_banner_show_information(_window, NULL, _("POI added"));
}
poi_free(p);
return TRUE;
}
-gboolean
-poi_quick_dialog(gdouble lat, gdouble lon)
+static void
+poi_button_set_icon(GtkWidget *button, node_type_t t)
{
-GtkWidget *table;
+const gchar *iname;
+GdkPixbuf *icon=NULL;
+
+iname=poi_get_icon_from_type(t);
+if (iname)
+ icon=poi_get_icon(iname, TRUE);
+if (icon) {
+ gtk_button_set_image(GTK_BUTTON(button), gtk_image_new_from_pixbuf(icon));
+ gtk_button_set_image_position(GTK_BUTTON(button), GTK_POS_TOP);
+}
+}
+
+/**
+ * Return a vbox filled with POI_QUICK_BUTTONS POI buttons and one for other POI,
+ * with an optinal POI label.
+ */
+GtkWidget *
+poi_quick_button_box(poi_quick_data *qpdata)
+{
+GtkWidget *table, *vbox;
GtkWidget *buttons[POI_QUICK_BUTTONS];
-guint x,y;
+GtkWidget *otherbtn;
+guint x, y;
-qp.lat=lat;
-qp.lon=lon;
+vbox=gtk_vbox_new(FALSE, 6);
+table = gtk_table_new(QPBS_Y, QPBS_X, TRUE);
+gtk_table_set_col_spacings(GTK_TABLE(table), 6);
+gtk_table_set_row_spacings(GTK_TABLE(table), 6);
+
+for (y=0;y<QPBS_Y;y++) {
+ for (x=0;x<QPBS_X;x++) {
+ guint p=y*(QPBS_X)+x;
+
+ g_debug("B: %d (%d,%d)", p, x, y);
+ buttons[p]=gtk_button_new_with_label(quick_poi_categories[p].name);
+ poi_button_set_icon(buttons[p], quick_poi_categories[p].type);
+ gtk_table_attach(GTK_TABLE(table), buttons[p], x, x+1, y, y+1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 6, 6);
+ g_object_set_data(G_OBJECT(buttons[p]), "pid", GINT_TO_POINTER(quick_poi_categories[p].type));
+ g_signal_connect(G_OBJECT(buttons[p]), "clicked", G_CALLBACK(poi_quick_button_cb), qpdata);
+ }
+}
+
+gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0);
+
+/* Other POI button */
+otherbtn=gtk_button_new_with_label("Other POI");
+poi_button_set_icon(otherbtn, NODE_AMENITY_GENERIC);
+gtk_box_pack_start(GTK_BOX(vbox), otherbtn, TRUE, FALSE, 6);
+g_object_set_data(G_OBJECT(otherbtn), "pid", GINT_TO_POINTER(NODE_AMENITY_GENERIC));
+g_signal_connect(G_OBJECT(otherbtn), "clicked", G_CALLBACK(poi_quick_button_cb), qpdata);
+
+gtk_box_pack_start(GTK_BOX(vbox), qpdata->label = gtk_entry_new(), TRUE, FALSE, 0);
+
+return vbox;
+}
+
+/**
+ * Show simple dialog for adding a POI.
+ * Uses the above helper to get the buttons. The location is given as paramters.
+ */
+gboolean
+poi_quick_dialog(gdouble lat, gdouble lon)
+{
+GtkWidget *box;
qp.dialog=gtk_dialog_new_with_buttons(_("Quick POI"),
GTK_WINDOW(_window),
help_dialog_help_enable(GTK_DIALOG(qp.dialog), HELP_ID_POIQUICK);
-gtk_box_pack_start(GTK_BOX(GTK_DIALOG(qp.dialog)->vbox), table = gtk_table_new(3, 3, FALSE), TRUE, TRUE, 0);
-
-gtk_table_set_col_spacings(GTK_TABLE(table), 6);
-gtk_table_set_row_spacings(GTK_TABLE(table), 6);
-gtk_table_set_homogeneous(GTK_TABLE(table), TRUE);
-
-for (x=0;x<3;x++) {
- for (y=0;y<3;y++) {
- guint p=x+y*3;
- const gchar *iname;
- GdkPixbuf *icon=NULL;
-
- buttons[p]=gtk_button_new_with_label(quick_poi_categories[p].name);
-
- iname=poi_get_icon_from_type(quick_poi_categories[p].type);
- if (iname)
- icon=poi_get_icon(iname, TRUE);
- if (icon)
- gtk_button_set_image(buttons[p], gtk_image_new_from_pixbuf(icon));
+qp.fixed=TRUE;
+qp.lat=lat;
+qp.lon=lon;
+qp.close=TRUE;
- gtk_table_attach(GTK_TABLE(table), buttons[p], x, x+1, y, y+1, GTK_FILL, 0, 2, 4);
- g_signal_connect(G_OBJECT(buttons[p]), "clicked", G_CALLBACK(poi_quick_button_cb), GINT_TO_POINTER(quick_poi_categories[p].type));
- }
-}
+box=poi_quick_button_box(&qp);
+gtk_box_pack_start(GTK_BOX(GTK_DIALOG(qp.dialog)->vbox), box, TRUE, TRUE, 0);
-gtk_box_pack_start(GTK_BOX(GTK_DIALOG(qp.dialog)->vbox), qp.label = gtk_entry_new(), TRUE, TRUE, 0);
gtk_widget_show_all(qp.dialog);
if (gtk_dialog_run(GTK_DIALOG(qp.dialog))==GTK_RESPONSE_REJECT)