29 |
|
|
30 |
#include "gpxview.h" |
#include "gpxview.h" |
31 |
|
|
32 |
|
#ifdef ENABLE_OSM_GPS_MAP |
33 |
|
#include "osm-gps-map.h" |
34 |
|
#endif |
35 |
|
|
36 |
#if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR >= 5) |
#if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR >= 5) |
37 |
#include <hildon/hildon-entry.h> |
#include <hildon/hildon-entry.h> |
38 |
#include <hildon/hildon-touch-selector.h> |
#include <hildon/hildon-touch-selector.h> |
1172 |
} |
} |
1173 |
#endif |
#endif |
1174 |
|
|
1175 |
|
#ifdef ENABLE_MAEMO_MAPPER |
1176 |
|
static void cb_mm(GtkWidget *item, gpointer data) { |
1177 |
|
appdata_t *appdata = (appdata_t*)data; |
1178 |
|
|
1179 |
|
pos_set(item, appdata->mmpos.lat, appdata->mpos.lon); |
1180 |
|
} |
1181 |
|
#endif |
1182 |
|
|
1183 |
static void cb_cache(GtkWidget *item, gpointer data) { |
static void cb_cache(GtkWidget *item, gpointer data) { |
1184 |
appdata_t *appdata = (appdata_t*)data; |
appdata_t *appdata = (appdata_t*)data; |
1185 |
|
|
1247 |
gint id = 2; |
gint id = 2; |
1248 |
while(location) { |
while(location) { |
1249 |
if(pos_valid(&location->pos)) |
if(pos_valid(&location->pos)) |
1250 |
menu_add(menu, appdata, icon_get_widget(ICON_POS, 21), |
menu_add(menu, appdata, icon_get_widget(ICON_POS, 17), |
1251 |
location->name, cb_gps, id, lon_entry, lat_entry); |
location->name, cb_gps, id, lon_entry, lat_entry); |
1252 |
|
|
1253 |
id++; |
id++; |
1264 |
cb_map, 0, lon_entry, lat_entry); |
cb_map, 0, lon_entry, lat_entry); |
1265 |
#endif |
#endif |
1266 |
|
|
1267 |
|
#ifdef ENABLE_MAEMO_MAPPER |
1268 |
|
if(appdata->mmpos_valid) { |
1269 |
|
menu_add(menu, appdata, icon_get_widget(ICON_POS, 24), |
1270 |
|
_("Maemo mapper position"), cb_mm, 0, lon_entry, lat_entry); |
1271 |
|
} |
1272 |
|
#endif |
1273 |
|
|
1274 |
if(appdata->cur_cache) { |
if(appdata->cur_cache) { |
1275 |
cache_t *cache = appdata->cur_cache; |
cache_t *cache = appdata->cur_cache; |
1276 |
|
|
1438 |
gint id = 2; |
gint id = 2; |
1439 |
while(location) { |
while(location) { |
1440 |
if(pos_valid(&location->pos)) |
if(pos_valid(&location->pos)) |
1441 |
preset_picker_add(store, appdata, icon_get(ICON_POS, 21), |
preset_picker_add(store, appdata, icon_get(ICON_POS, 17), |
1442 |
location->name, cb_gps, id); |
location->name, cb_gps, id); |
1443 |
|
|
1444 |
id++; |
id++; |
1448 |
if(pos_valid(&appdata->geomath)) |
if(pos_valid(&appdata->geomath)) |
1449 |
preset_picker_add(store, appdata, icon_get(ICON_POS, 19), |
preset_picker_add(store, appdata, icon_get(ICON_POS, 19), |
1450 |
_("Geomath projection"), cb_geomath, 0); |
_("Geomath projection"), cb_geomath, 0); |
1451 |
|
|
1452 |
#ifdef ENABLE_OSM_GPS_MAP |
#ifdef ENABLE_OSM_GPS_MAP |
1453 |
if(pos_valid(&appdata->map.pos)) |
if(pos_valid(&appdata->map.pos)) |
1454 |
preset_picker_add(store, appdata, icon_get(ICON_POS, 20), |
preset_picker_add(store, appdata, icon_get(ICON_POS, 20), |
1455 |
_("Map position"), cb_map, 0); |
_("Map position"), cb_map, 0); |
1456 |
#endif |
#endif |
1457 |
|
|
1458 |
|
#ifdef ENABLE_MAEMO_MAPPER |
1459 |
|
if(appdata->mmpos_valid) { |
1460 |
|
preset_picker_add(menu, appdata, icon_get(ICON_POS, 24), |
1461 |
|
_("Maemo mapper position"), cb_mm, 0); |
1462 |
|
} |
1463 |
|
#endif |
1464 |
|
|
1465 |
if(appdata->cur_cache) { |
if(appdata->cur_cache) { |
1466 |
cache_t *cache = appdata->cur_cache; |
cache_t *cache = appdata->cur_cache; |
1467 |
|
|
1554 |
|
|
1555 |
GtkWidget *button = gtk_button_new(); |
GtkWidget *button = gtk_button_new(); |
1556 |
|
|
1557 |
gtk_button_set_image(GTK_BUTTON(button), icon_get_widget(ICON_POS, 17)); |
gtk_button_set_image(GTK_BUTTON(button), icon_get_widget(ICON_POS, 22)); |
1558 |
|
|
1559 |
gtk_widget_set_tooltip_text(button, _("Preset coordinates")); |
gtk_widget_set_tooltip_text(button, _("Preset coordinates")); |
1560 |
|
|
1567 |
|
|
1568 |
gtk_signal_connect(GTK_OBJECT(button), "destroy", |
gtk_signal_connect(GTK_OBJECT(button), "destroy", |
1569 |
(GtkSignalFunc)on_popup_destroy, appdata); |
(GtkSignalFunc)on_popup_destroy, appdata); |
|
|
|
|
g_object_set_data(G_OBJECT(button), "menu", |
|
|
popup_menu_create(appdata, lat_entry, lon_entry)); |
|
1570 |
#else |
#else |
1571 |
#ifdef FREMANTLE |
#ifdef FREMANTLE |
1572 |
hildon_gtk_widget_set_theme_size(button, |
hildon_gtk_widget_set_theme_size(button, |
1580 |
return button; |
return button; |
1581 |
} |
} |
1582 |
|
|
1583 |
|
#if defined(ENABLE_MAEMO_MAPPER) || defined(ENABLE_OSM_GPS_MAP) |
1584 |
|
static pos_t goto_pos_get(GtkWidget *item) { |
1585 |
|
pos_t pos; |
1586 |
|
|
1587 |
|
GtkWidget *lat_entry = g_object_get_data(G_OBJECT(item), "lat_entry"); |
1588 |
|
pos.lat = lat_entry_get(lat_entry); |
1589 |
|
|
1590 |
|
GtkWidget *lon_entry = g_object_get_data(G_OBJECT(item), "lon_entry"); |
1591 |
|
pos.lon = lon_entry_get(lon_entry); |
1592 |
|
|
1593 |
|
return pos; |
1594 |
|
} |
1595 |
|
|
1596 |
|
#ifdef ENABLE_MAEMO_MAPPER |
1597 |
|
static void cb_mm_set(GtkWidget *item, gpointer data) { |
1598 |
|
appdata_t *appdata = (appdata_t*)data; |
1599 |
|
|
1600 |
|
pos_t pos = goto_pos_get(item); |
1601 |
|
if(!isnan(pos.lat) && !isnan(pos.lon)) |
1602 |
|
dbus_mm_set_position(appdata, &pos); |
1603 |
|
} |
1604 |
|
#endif |
1605 |
|
|
1606 |
|
static void cb_map_set(GtkWidget *item, gpointer data) { |
1607 |
|
appdata_t *appdata = (appdata_t*)data; |
1608 |
|
|
1609 |
|
pos_t pos = goto_pos_get(item); |
1610 |
|
if(!isnan(pos.lat) && !isnan(pos.lon)) { |
1611 |
|
map(appdata); |
1612 |
|
osm_gps_map_set_center(OSM_GPS_MAP(appdata->map.context->widget), |
1613 |
|
pos.lat, pos.lon); |
1614 |
|
} |
1615 |
|
} |
1616 |
|
|
1617 |
|
#ifndef PRESET_PICKER_DIALOG |
1618 |
|
static GtkWidget *goto_popup_menu_create(appdata_t *appdata, |
1619 |
|
GtkWidget *lat_entry, GtkWidget *lon_entry) { |
1620 |
|
GtkWidget *menu = gtk_menu_new(); |
1621 |
|
|
1622 |
|
#if defined(ENABLE_OSM_GPS_MAP) |
1623 |
|
menu_add(menu, appdata, icon_get_widget(ICON_POS, 20), |
1624 |
|
_("Map position"), cb_map_set, 0, lon_entry, lat_entry); |
1625 |
|
#endif |
1626 |
|
|
1627 |
|
#if defined(ENABLE_MAEMO_MAPPER) |
1628 |
|
menu_add(menu, appdata, icon_get_widget(ICON_POS, 24), |
1629 |
|
_("Maemo mapper position"), cb_mm_set, 0, lon_entry, lat_entry); |
1630 |
|
#endif |
1631 |
|
|
1632 |
|
gtk_widget_show_all(menu); |
1633 |
|
|
1634 |
|
return menu; |
1635 |
|
} |
1636 |
|
#else |
1637 |
|
static GtkWidget *goto_picker_create(appdata_t *appdata, |
1638 |
|
GtkWidget *lat_entry, GtkWidget *lon_entry) { |
1639 |
|
GtkCellRenderer *renderer; |
1640 |
|
GtkListStore *store; |
1641 |
|
|
1642 |
|
GtkWidget *view = gtk_tree_view_new(); |
1643 |
|
|
1644 |
|
g_object_set_data(G_OBJECT(view), "lat_entry", (gpointer)lat_entry); |
1645 |
|
g_object_set_data(G_OBJECT(view), "lon_entry", (gpointer)lon_entry); |
1646 |
|
|
1647 |
|
/* --- "Icon" column --- */ |
1648 |
|
renderer = gtk_cell_renderer_pixbuf_new(); |
1649 |
|
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), |
1650 |
|
-1, "Icon", renderer, "pixbuf", PRESET_PICKER_COL_ICON, NULL); |
1651 |
|
|
1652 |
|
/* --- "Name" column --- */ |
1653 |
|
renderer = gtk_cell_renderer_text_new(); |
1654 |
|
g_object_set(renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL ); |
1655 |
|
GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes( |
1656 |
|
"Name", renderer, "text", PRESET_PICKER_COL_NAME, NULL); |
1657 |
|
gtk_tree_view_column_set_expand(column, TRUE); |
1658 |
|
gtk_tree_view_insert_column(GTK_TREE_VIEW(view), column, -1); |
1659 |
|
|
1660 |
|
store = gtk_list_store_new(PRESET_PICKER_NUM_COLS, |
1661 |
|
GDK_TYPE_PIXBUF, |
1662 |
|
G_TYPE_STRING, |
1663 |
|
G_TYPE_INT, |
1664 |
|
G_TYPE_POINTER); |
1665 |
|
|
1666 |
|
#if defined(ENABLE_OSM_GPS_MAP) |
1667 |
|
preset_picker_add(store, appdata, icon_get(ICON_POS, 20), |
1668 |
|
_("Map position"), cb_map_set, 0); |
1669 |
|
#endif |
1670 |
|
|
1671 |
|
#if defined(ENABLE_MAEMO_MAPPER) |
1672 |
|
preset_picker_add(store, appdata, icon_get(ICON_POS, 24), |
1673 |
|
_("Maemo mapper position"), cb_mm_set, 0); |
1674 |
|
#endif |
1675 |
|
|
1676 |
|
gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store)); |
1677 |
|
g_object_unref(store); |
1678 |
|
|
1679 |
|
/* make list react on clicks */ |
1680 |
|
g_signal_connect(view, "row-activated", |
1681 |
|
(GCallback)on_preset_picker_activated, appdata); |
1682 |
|
|
1683 |
|
/* put this inside a scrolled view */ |
1684 |
|
#ifndef USE_PANNABLE_AREA |
1685 |
|
GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL); |
1686 |
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), |
1687 |
|
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); |
1688 |
|
gtk_container_add(GTK_CONTAINER(scrolled_window), view); |
1689 |
|
return scrolled_window; |
1690 |
|
#else |
1691 |
|
GtkWidget *pannable_area = hildon_pannable_area_new(); |
1692 |
|
gtk_container_add(GTK_CONTAINER(pannable_area), view); |
1693 |
|
return pannable_area; |
1694 |
|
#endif |
1695 |
|
} |
1696 |
|
#endif |
1697 |
|
|
1698 |
|
static gint on_goto_button_press(GtkWidget *button, |
1699 |
|
GdkEventButton *event, gpointer data) { |
1700 |
|
appdata_t *appdata = (appdata_t*)data; |
1701 |
|
|
1702 |
|
if(event->type == GDK_BUTTON_PRESS) { |
1703 |
|
|
1704 |
|
#if defined(ENABLE_MAEMO_MAPPER) && !defined(ENABLE_OSM_GPS_MAP) |
1705 |
|
/* only maemo mapper is being used */ |
1706 |
|
pos_t pos = goto_pos_get(button); |
1707 |
|
if(!isnan(pos.lat) && !isnan(pos.lon)) { |
1708 |
|
dbus_mm_set_position(appdata, &pos); |
1709 |
|
#elif !defined(ENABLE_MAEMO_MAPPER) && defined(ENABLE_OSM_GPS_MAP) |
1710 |
|
/* only internal map is being used */ |
1711 |
|
pos_t pos = goto_pos_get(button); |
1712 |
|
if(!isnan(pos.lat) && !isnan(pos.lon)) { |
1713 |
|
map(appdata); |
1714 |
|
osm_gps_map_set_center(OSM_GPS_MAP(appdata->map.context->widget), |
1715 |
|
pos.lat, pos.lon); |
1716 |
|
} |
1717 |
|
#else |
1718 |
|
|
1719 |
|
gpointer lat_entry = g_object_get_data(G_OBJECT(button), "lat_entry"); |
1720 |
|
g_assert(lat_entry); |
1721 |
|
gpointer lon_entry = g_object_get_data(G_OBJECT(button), "lon_entry"); |
1722 |
|
g_assert(lon_entry); |
1723 |
|
|
1724 |
|
#ifndef PRESET_PICKER_DIALOG |
1725 |
|
GtkWidget *menu = g_object_get_data(G_OBJECT(button), "menu"); |
1726 |
|
if(!menu) { |
1727 |
|
menu = goto_popup_menu_create(appdata, lat_entry, lon_entry); |
1728 |
|
g_object_set_data(G_OBJECT(button), "menu", (gpointer)menu); |
1729 |
|
} |
1730 |
|
|
1731 |
|
/* draw a popup menu */ |
1732 |
|
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, |
1733 |
|
event->button, event->time); |
1734 |
|
#else |
1735 |
|
GtkWidget *dialog = |
1736 |
|
gtk_dialog_new_with_buttons(_("Map coordinates"), |
1737 |
|
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))), |
1738 |
|
GTK_DIALOG_MODAL, |
1739 |
|
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, |
1740 |
|
NULL); |
1741 |
|
|
1742 |
|
gtk_window_set_default_size(GTK_WINDOW(dialog), 400, 210); |
1743 |
|
|
1744 |
|
gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), |
1745 |
|
goto_picker_create(appdata, lat_entry, lon_entry)); |
1746 |
|
|
1747 |
|
gtk_widget_show_all(dialog); |
1748 |
|
gtk_dialog_run(GTK_DIALOG(dialog)); |
1749 |
|
gtk_widget_destroy(dialog); |
1750 |
|
#endif |
1751 |
|
|
1752 |
|
#endif |
1753 |
|
|
1754 |
|
return TRUE; |
1755 |
|
} |
1756 |
|
return FALSE; |
1757 |
|
} |
1758 |
|
|
1759 |
|
/* a button which makes the map/maemo mapper go to the associated */ |
1760 |
|
/* position */ |
1761 |
|
GtkWidget *goto_coordinate(appdata_t *appdata, |
1762 |
|
GtkWidget *lat_entry, GtkWidget *lon_entry) { |
1763 |
|
|
1764 |
|
GtkWidget *button = gtk_button_new(); |
1765 |
|
|
1766 |
|
gtk_button_set_image(GTK_BUTTON(button), icon_get_widget(ICON_POS, 23)); |
1767 |
|
|
1768 |
|
gtk_widget_set_tooltip_text(button, _("Goto coordinates")); |
1769 |
|
|
1770 |
|
g_object_set_data(G_OBJECT(button), "lat_entry", (gpointer)lat_entry); |
1771 |
|
g_object_set_data(G_OBJECT(button), "lon_entry", (gpointer)lon_entry); |
1772 |
|
|
1773 |
|
gtk_signal_connect(GTK_OBJECT(button), "button-press-event", |
1774 |
|
(GtkSignalFunc)on_goto_button_press, appdata); |
1775 |
|
|
1776 |
|
#ifndef PRESET_PICKER_DIALOG |
1777 |
|
gtk_signal_connect(GTK_OBJECT(button), "destroy", |
1778 |
|
(GtkSignalFunc)on_popup_destroy, appdata); |
1779 |
|
#else |
1780 |
|
#ifdef FREMANTLE |
1781 |
|
hildon_gtk_widget_set_theme_size(button, |
1782 |
|
(HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH)); |
1783 |
|
#endif |
1784 |
|
#endif |
1785 |
|
|
1786 |
|
return button; |
1787 |
|
} |
1788 |
|
#else |
1789 |
|
/* no map installed */ |
1790 |
|
GtkWidget *goto_coordinate(appdata_t *appdata, |
1791 |
|
GtkWidget *lat_entry, GtkWidget *lon_entry) { |
1792 |
|
return gtk_label_new(""); |
1793 |
|
} |
1794 |
|
#endif |
1795 |
|
|
1796 |
GtkWidget *entry_new(void) { |
GtkWidget *entry_new(void) { |
1797 |
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
1798 |
return gtk_entry_new(); |
return gtk_entry_new(); |