#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;
{ NODE_AMENITY_ATM, "ATM", },
};
-/* 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)
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->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);
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);
if (iname)
icon=poi_get_icon(iname, TRUE);
if (icon) {
- gtk_button_set_image(button, gtk_image_new_from_pixbuf(icon));
- gtk_button_set_image_position(button, GTK_POS_TOP);
+ gtk_button_set_image(GTK_BUTTON(button), gtk_image_new_from_pixbuf(icon));
+ gtk_button_set_image_position(GTK_BUTTON(button), GTK_POS_TOP);
}
}
-gboolean
-poi_quick_dialog(gdouble lat, gdouble lon)
+#define QPBS_X (3)
+#define QPBS_Y (3)
+#define POI_QUICK_BUTTONS (QPBS_X*QPBS_Y)
+
+/**
+ * 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;
+GtkWidget *table, *vbox;
GtkWidget *buttons[POI_QUICK_BUTTONS];
GtkWidget *otherbtn;
guint x,y;
-qp.lat=lat;
-qp.lon=lon;
-
-qp.dialog=gtk_dialog_new_with_buttons(_("Quick POI"),
- GTK_WINDOW(_window),
- GTK_DIALOG_MODAL,
- GTK_STOCK_CANCEL,
- GTK_RESPONSE_REJECT,
- NULL);
-
-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);
-
+vbox=gtk_vbox_new(FALSE, 3);
+table = gtk_table_new(QPBS_X, QPBS_Y, FALSE);
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;
+for (x=0;x<QPBS_X;x++) {
+ for (y=0;y<QPBS_Y;y++) {
+ guint p=x+y*QPBS_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_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));
+ 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);
-g_signal_connect(G_OBJECT(otherbtn), "clicked", G_CALLBACK(poi_quick_button_cb), GINT_TO_POINTER(NODE_AMENITY_GENERIC));
-gtk_box_pack_start(GTK_BOX(GTK_DIALOG(qp.dialog)->vbox), otherbtn, TRUE, TRUE, 0);
+gtk_box_pack_start(GTK_BOX(vbox), otherbtn, TRUE, TRUE, 0);
+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, TRUE, 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),
+ GTK_DIALOG_MODAL,
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_REJECT,
+ NULL);
+
+help_dialog_help_enable(GTK_DIALOG(qp.dialog), HELP_ID_POIQUICK);
+
+qp.fixed=TRUE;
+qp.lat=lat;
+qp.lon=lon;
+qp.close=TRUE;
+
+box=poi_quick_button_box(&qp);
+gtk_box_pack_start(GTK_BOX(GTK_DIALOG(qp.dialog)->vbox), box, TRUE, TRUE, 0);
-/* Optional Label */
-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)