From 4b6da5127abd3b9f9a864fcc8984c5ddd909b7b5 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Tue, 19 Jun 2007 14:31:52 +0300 Subject: [PATCH] Make Home location setting/goto/save/load work. --- src/cb.c | 29 +++++++++++++++++++++++++++++ src/cb.h | 2 ++ src/config.c | 16 ++++++++++++---- src/mapper-types.h | 11 ++++++++++- src/settings-gconf.h | 3 +++ src/ui-common.c | 9 ++++++--- src/ui-common.h | 1 + 7 files changed, 63 insertions(+), 8 deletions(-) diff --git a/src/cb.c b/src/cb.c index 83d3bfb..6d8a0e9 100644 --- a/src/cb.c +++ b/src/cb.c @@ -445,6 +445,23 @@ gboolean menu_cb_goto_latlon(GtkAction * action) return TRUE; } +gboolean menu_cb_goto_home(GtkAction * action) +{ + guint unitx, unity; + + printf("%s()\n", __PRETTY_FUNCTION__); + + if (_center_mode > 0) + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM + (_menu_ac_none_item), TRUE); + + latlon2unit(_home.lat, _home.lon, unitx, unity); + map_center_unit(unitx, unity); + + vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__); + return TRUE; +} + gboolean menu_cb_goto_gps(GtkAction * action) { printf("%s()\n", __PRETTY_FUNCTION__); @@ -1255,6 +1272,18 @@ gboolean cb_add_poi(GtkAction * action) return TRUE; } +gboolean cmenu_cb_loc_set_home(GtkAction * action) +{ + printf("%s()\n", __PRETTY_FUNCTION__); + + _pos.unitx = x2unit(_cmenu_position_x); + _pos.unity = y2unit(_cmenu_position_y); + unit2latlon(_pos.unitx, _pos.unity, _home.lat, _home.lon); + + vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__); + return TRUE; +} + gboolean cmenu_cb_loc_set_gps(GtkAction * action) { printf("%s()\n", __PRETTY_FUNCTION__); diff --git a/src/cb.h b/src/cb.h index 43640e0..c4cce18 100644 --- a/src/cb.h +++ b/src/cb.h @@ -71,6 +71,7 @@ gboolean menu_cb_ac_none(GtkAction * action); /* Callbacks for the "Go to" submenu. */ gboolean menu_cb_goto_latlon(GtkAction * action); gboolean menu_cb_goto_gps(GtkAction * action); +gboolean menu_cb_goto_home(GtkAction * action); gboolean menu_cb_goto_nextway(GtkAction * action); gboolean menu_cb_goto_nearpoi(GtkAction * action); @@ -94,6 +95,7 @@ gboolean cmenu_cb_loc_add_route(GtkAction * action); gboolean cmenu_cb_loc_add_way(GtkAction * action); gboolean cmenu_cb_loc_add_poi(GtkAction * action); gboolean cmenu_cb_loc_set_gps(GtkAction * action); +gboolean cmenu_cb_loc_set_home(GtkAction * action); gboolean cb_add_poi(GtkAction * action); diff --git a/src/config.c b/src/config.c index 29b7ef9..ec1df43 100644 --- a/src/config.c +++ b/src/config.c @@ -278,12 +278,14 @@ config_save() GCONF_KEY_INFO_FONT_SIZE, INFO_FONT_TEXT[_info_font_size], NULL); - /* Save last saved latitude. */ + /* Save last saved latitude/longiture. */ gconf_client_set_float(gconf_client, GCONF_KEY_LAT, _gps.lat, NULL); - - /* Save last saved longitude. */ gconf_client_set_float(gconf_client, GCONF_KEY_LON, _gps.lon, NULL); + /* Save home lat/lon. */ + gconf_client_set_float(gconf_client, GCONF_KEY_HOME_LAT, _home.lat, NULL); + gconf_client_set_float(gconf_client, GCONF_KEY_HOME_LON, _home.lon, NULL); + /* Save last center point. */ { gfloat center_lat, center_lon; @@ -601,7 +603,13 @@ void config_init() _gps.lat = gconf_client_get_float(gconf_client, GCONF_KEY_LAT, NULL); _gps.lon = gconf_client_get_float(gconf_client, GCONF_KEY_LON, NULL); if (_gps.lat==0.0) _gps.lat=64.0; - if (_gps.lon==0.0) _gps.lon=24.0; + if (_gps.lon==0.0) _gps.lon=22.0; + + /* Home */ + _home.lat = gconf_client_get_float(gconf_client, GCONF_KEY_HOME_LAT, NULL); + _home.lon = gconf_client_get_float(gconf_client, GCONF_KEY_HOME_LON, NULL); + if (_home.lat==0.0) _home.lat=64.0; + if (_home.lon==0.0) _home.lon=22.0; /* Get last center point. */ { diff --git a/src/mapper-types.h b/src/mapper-types.h index da1593e..8aa9edc 100644 --- a/src/mapper-types.h +++ b/src/mapper-types.h @@ -179,7 +179,15 @@ typedef enum { } SpeedLocation; gchar *SPEED_LOCATION_TEXT[SPEED_LOCATION_ENUM_COUNT]; -/** A general definition of a point in the Maemo Mapper unit system. */ +/** A lat/lon/alt position */ +typedef struct _Position Position; +struct _Position { + gfloat lat; + gfloat lon; + gfloat altitude; +}; + +/** A general definition of a point in the Mapper unit system. */ typedef struct _Point Point; struct _Point { guint unitx; @@ -268,5 +276,6 @@ struct _BrowseInfo { }; Point _point_null; +Position _home; #endif diff --git a/src/settings-gconf.h b/src/settings-gconf.h index eb19833..cbbaf80 100644 --- a/src/settings-gconf.h +++ b/src/settings-gconf.h @@ -71,6 +71,9 @@ #define GCONF_KEY_CENTER_LON GCONF_KEY_PREFIX"/center_longitude" #define GCONF_KEY_ZOOM GCONF_KEY_PREFIX"/zoom" +#define GCONF_KEY_HOME_LAT GCONF_KEY_PREFIX"/home_latitude" +#define GCONF_KEY_HOME_LON GCONF_KEY_PREFIX"/home_longitude" + /* Display features */ #define GCONF_KEY_SHOWSCALE GCONF_KEY_PREFIX"/show_scale" #define GCONF_KEY_SHOWTRACKS GCONF_KEY_PREFIX"/show_tracks" diff --git a/src/ui-common.c b/src/ui-common.c index 90be9c0..30d714a 100644 --- a/src/ui-common.c +++ b/src/ui-common.c @@ -593,9 +593,10 @@ static void menu_init() = gtk_menu_item_new_with_label(_("Add POI..."))); gtk_widget_set_sensitive(_cmenu_loc_add_poi, _db != NULL); gtk_menu_append(submenu, gtk_separator_menu_item_new()); - gtk_menu_append(submenu, _cmenu_loc_set_gps - = + gtk_menu_append(submenu, _cmenu_loc_set_gps = gtk_menu_item_new_with_label(_("Set as GPS Location"))); + gtk_menu_append(submenu, _cmenu_loc_set_home = + gtk_menu_item_new_with_label(_("Set as Home Location"))); /* Setup the waypoint context menu. */ gtk_menu_append(menu, menu_item @@ -665,6 +666,8 @@ static void menu_init() G_CALLBACK(cmenu_cb_loc_add_poi), NULL); g_signal_connect(G_OBJECT(_cmenu_loc_set_gps), "activate", G_CALLBACK(cmenu_cb_loc_set_gps), NULL); + g_signal_connect(G_OBJECT(_cmenu_loc_set_home), "activate", + G_CALLBACK(cmenu_cb_loc_set_home), NULL); g_signal_connect(G_OBJECT(_cmenu_way_show_latlon_item), "activate", G_CALLBACK(cmenu_cb_way_show_latlon), NULL); @@ -715,7 +718,7 @@ GtkWidget *item; item = gtk_tool_button_new_from_stock (GTK_STOCK_HOME); gtk_toolbar_insert (GTK_TOOLBAR (_toolbar), item, -1); -/* g_signal_connect (item, "clicked", G_CALLBACK (cb_jump_to_home), NULL); */ +g_signal_connect (item, "clicked", G_CALLBACK (menu_cb_goto_home), NULL); item = gtk_tool_button_new_from_stock (GTK_STOCK_JUMP_TO); gtk_toolbar_insert (GTK_TOOLBAR (_toolbar), item, -1); diff --git a/src/ui-common.h b/src/ui-common.h index 71c4a83..99a91fa 100644 --- a/src/ui-common.h +++ b/src/ui-common.h @@ -162,6 +162,7 @@ GtkWidget *_cmenu_loc_add_route; GtkWidget *_cmenu_loc_add_way; GtkWidget *_cmenu_loc_add_poi; GtkWidget *_cmenu_loc_set_gps; +GtkWidget *_cmenu_loc_set_home; /* Menu items for the "Waypoint" context menu. */ GtkWidget *_cmenu_way_show_latlon_item; -- 2.39.5