]> err.no Git - mapper/commitdiff
Split the quick button box generation into its own function.
authorKaj-Michael Lang <milang@onion.tal.org>
Tue, 26 Feb 2008 11:19:02 +0000 (13:19 +0200)
committerKaj-Michael Lang <milang@onion.tal.org>
Tue, 26 Feb 2008 11:19:02 +0000 (13:19 +0200)
Will be used to create a quick poi tab for very-quick access for on-the-road mapping.

src/poi-gui.c
src/poi-gui.h

index a8e6c08da7fa042f6d9fb7eaa16c2c14c96e0cf4..f4c69bd2b06bf4a688371df54c02ec1ee651e444 100644 (file)
 #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>
@@ -41,8 +43,6 @@
 #include "ui-maemo.h"
 #endif
 
-#define POI_QUICK_BUTTONS (9)
-
 typedef struct _search_dialog search_dialog;
 struct _search_dialog {
        GtkWidget *dialog;
@@ -82,14 +82,7 @@ static struct _quick_poi_categories quick_poi_categories[] = {
        { 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)
@@ -470,12 +463,12 @@ if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(sd->cmb_category), &iter)==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
@@ -806,7 +799,7 @@ poi_free(p);
 
 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;
@@ -972,21 +965,28 @@ 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 */
@@ -996,12 +996,16 @@ if (poi_add(p)==FALSE) {
        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);
@@ -1018,57 +1022,85 @@ iname=poi_get_icon_from_type(t);
 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)
index c5d743b3c8f7e1fc099b6596ca4ac4f242824bec..2dc7b9d473250ea077f884531ec02ea68aaf6008 100644 (file)
@@ -34,9 +34,21 @@ typedef enum {
        ACTION_EDIT_POI,
 } POIAction;
 
+/* Quick POI information structure */
+typedef struct _poi_quick_data poi_quick_data;
+struct _poi_quick_data {
+    GtkWidget *dialog;
+    GtkWidget *label;
+    gboolean fixed;
+    gboolean close;
+    gdouble lat;
+    gdouble lon;
+};
+
 gboolean poi_select(guint unitx, guint unity, guint range, poi_info *poi);
 gboolean poi_edit_dialog(POIAction action, poi_info *poi);
 gboolean poi_search_dialog(GtkListStore *store, poi_info *poi, gdouble lat, gdouble lon);
+GtkWidget *poi_quick_button_box(poi_quick_data *qpdata);
 gboolean poi_quick_dialog(gdouble lat, gdouble lon);
 
 gboolean poi_info_dialog(guint poi_id);