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> |
39 |
#include <hildon/hildon-picker-button.h> |
#include <hildon/hildon-picker-button.h> |
40 |
#include <hildon/hildon-picker-dialog.h> |
#include <hildon/hildon-picker-dialog.h> |
41 |
|
#include <hildon/hildon-check-button.h> |
42 |
#endif |
#endif |
43 |
|
|
44 |
float roundf(float x); |
float roundf(float x); |
326 |
return valid; |
return valid; |
327 |
} |
} |
328 |
|
|
329 |
GtkWidget *red_entry_new(void) { |
GtkWidget *red_entry_new_with_text(char *str) { |
330 |
GdkColor color; |
GdkColor color; |
331 |
|
|
332 |
GtkWidget *widget = entry_new(); |
GtkWidget *widget = entry_new(); |
333 |
gdk_color_parse("#ff0000", &color); |
gdk_color_parse("#ff0000", &color); |
334 |
gtk_widget_modify_text(widget, TAG_STATE, &color); |
gtk_widget_modify_text(widget, TAG_STATE, &color); |
335 |
|
if(str) gtk_entry_set_text(GTK_ENTRY(widget), str); |
336 |
|
|
337 |
return widget; |
return widget; |
338 |
} |
} |
339 |
|
|
612 |
} |
} |
613 |
#endif |
#endif |
614 |
|
|
615 |
|
/* whatever there is in the entry: if it's illegal make it */ |
616 |
|
#define ILLEGAL_LAT "X --° --,---'" |
617 |
|
#define ILLEGAL_LON "X ---° --,---'" |
618 |
|
|
619 |
|
static void pos_lat_check(GtkWidget *widget) { |
620 |
|
if(isnan(pos_parse_lat((char*)gtk_entry_get_text(GTK_ENTRY(widget))))) { |
621 |
|
#ifndef COORDINATE_PICKER |
622 |
|
gtk_entry_set_text(GTK_ENTRY(widget), ILLEGAL_LAT); |
623 |
|
#else |
624 |
|
mark(widget, FALSE); |
625 |
|
gtk_button_set_label(GTK_BUTTON(widget), ILLEGAL_LAT); |
626 |
|
#endif |
627 |
|
} |
628 |
|
} |
629 |
|
|
630 |
|
static void pos_lon_check(GtkWidget *widget) { |
631 |
|
if(isnan(pos_parse_lon((char*)gtk_entry_get_text(GTK_ENTRY(widget))))) { |
632 |
|
#ifndef COORDINATE_PICKER |
633 |
|
gtk_entry_set_text(GTK_ENTRY(widget), ILLEGAL_LON); |
634 |
|
#else |
635 |
|
mark(widget, FALSE); |
636 |
|
gtk_button_set_label(GTK_BUTTON(widget), ILLEGAL_LON); |
637 |
|
#endif |
638 |
|
} |
639 |
|
} |
640 |
|
|
641 |
/* a entry that is colored red when being "active" */ |
/* a entry that is colored red when being "active" */ |
642 |
GtkWidget *lat_entry_new(float lat) { |
GtkWidget *lat_entry_new(float lat) { |
643 |
char str[32]; |
char str[32]; |
644 |
pos_lat_str(str, sizeof(str), lat); |
pos_lat_str(str, sizeof(str), lat); |
645 |
|
|
646 |
#ifndef COORDINATE_PICKER |
#ifndef COORDINATE_PICKER |
647 |
GdkColor color; |
GtkWidget *widget = red_entry_new_with_text(str); |
|
|
|
|
GtkWidget *widget = entry_new(); |
|
|
gdk_color_parse("#ff0000", &color); |
|
|
gtk_widget_modify_text(widget, TAG_STATE, &color); |
|
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(widget), str); |
|
648 |
|
|
649 |
g_signal_connect(G_OBJECT(widget), "changed", |
g_signal_connect(G_OBJECT(widget), "changed", |
650 |
G_CALLBACK(callback_modified_lat), NULL); |
G_CALLBACK(callback_modified_lat), NULL); |
662 |
(GtkSignalFunc)on_lat_picker_button_press, NULL); |
(GtkSignalFunc)on_lat_picker_button_press, NULL); |
663 |
#endif |
#endif |
664 |
|
|
665 |
|
pos_lat_check(widget); |
666 |
return widget; |
return widget; |
667 |
} |
} |
668 |
|
|
764 |
pos_lon_str(str, sizeof(str), lon); |
pos_lon_str(str, sizeof(str), lon); |
765 |
|
|
766 |
#ifndef COORDINATE_PICKER |
#ifndef COORDINATE_PICKER |
767 |
GdkColor color; |
GtkWidget *widget = red_entry_new_with_text(str); |
|
|
|
|
GtkWidget *widget = entry_new(); |
|
|
gdk_color_parse("#ff0000", &color); |
|
|
gtk_widget_modify_text(widget, TAG_STATE, &color); |
|
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(widget), str); |
|
|
|
|
768 |
g_signal_connect(G_OBJECT(widget), "changed", |
g_signal_connect(G_OBJECT(widget), "changed", |
769 |
G_CALLBACK(callback_modified_lon), NULL); |
G_CALLBACK(callback_modified_lon), NULL); |
770 |
|
|
781 |
(GtkSignalFunc)on_lon_picker_button_press, NULL); |
(GtkSignalFunc)on_lon_picker_button_press, NULL); |
782 |
#endif |
#endif |
783 |
|
|
784 |
|
pos_lon_check(widget); |
785 |
return widget; |
return widget; |
786 |
} |
} |
787 |
|
|
814 |
g_object_set_data(G_OBJECT(widget), "latitude", (gpointer)lat_int); |
g_object_set_data(G_OBJECT(widget), "latitude", (gpointer)lat_int); |
815 |
g_signal_emit_by_name(widget, "changed"); |
g_signal_emit_by_name(widget, "changed"); |
816 |
#endif |
#endif |
817 |
|
pos_lat_check(widget); |
818 |
} |
} |
819 |
|
|
820 |
void lon_entry_set(GtkWidget *widget, float lon) { |
void lon_entry_set(GtkWidget *widget, float lon) { |
828 |
g_object_set_data(G_OBJECT(widget), "longitude", (gpointer)lon_int); |
g_object_set_data(G_OBJECT(widget), "longitude", (gpointer)lon_int); |
829 |
g_signal_emit_by_name(widget, "changed"); |
g_signal_emit_by_name(widget, "changed"); |
830 |
#endif |
#endif |
831 |
|
pos_lon_check(widget); |
832 |
} |
} |
833 |
|
|
834 |
void lat_label_set(GtkWidget *widget, float lat) { |
void lat_label_set(GtkWidget *widget, float lat) { |
965 |
distance_str(str, sizeof(str), dist, mil); |
distance_str(str, sizeof(str), dist, mil); |
966 |
|
|
967 |
#ifndef COORDINATE_PICKER |
#ifndef COORDINATE_PICKER |
968 |
GdkColor color; |
GtkWidget *widget = red_entry_new_with_text(str); |
|
GtkWidget *widget = entry_new(); |
|
|
gdk_color_parse("#ff0000", &color); |
|
|
gtk_widget_modify_text(widget, TAG_STATE, &color); |
|
|
|
|
|
gtk_entry_set_text(GTK_ENTRY(widget), str); |
|
|
|
|
969 |
g_signal_connect(G_OBJECT(widget), "changed", |
g_signal_connect(G_OBJECT(widget), "changed", |
970 |
G_CALLBACK(callback_modified_dist), NULL); |
G_CALLBACK(callback_modified_dist), NULL); |
971 |
|
|
1004 |
#ifndef COORDINATE_PICKER |
#ifndef COORDINATE_PICKER |
1005 |
gtk_entry_set_text(GTK_ENTRY(widget), str); |
gtk_entry_set_text(GTK_ENTRY(widget), str); |
1006 |
#else |
#else |
1007 |
|
gtk_button_set_label(GTK_BUTTON(widget), str); |
1008 |
int dist_int = (int)roundf(dist * 1000); // km -> m |
int dist_int = (int)roundf(dist * 1000); // km -> m |
1009 |
if(mil) dist_int = (int)roundf(dist * 5280.0); // mi -> ft |
if(mil) dist_int = (int)roundf(dist * 5280.0); // mi -> ft |
1010 |
g_object_set_data(G_OBJECT(widget), "distance", (gpointer)dist_int); |
g_object_set_data(G_OBJECT(widget), "distance", (gpointer)dist_int); |
1011 |
g_object_set_data(G_OBJECT(widget), "mil", (gpointer)mil); |
g_object_set_data(G_OBJECT(widget), "mil", (gpointer)mil); |
1012 |
gtk_button_set_label(GTK_BUTTON(widget), str); |
g_signal_emit_by_name(widget, "changed"); |
1013 |
#endif |
#endif |
1014 |
} |
} |
1015 |
|
|
1204 |
} |
} |
1205 |
#endif |
#endif |
1206 |
|
|
1207 |
|
#ifdef ENABLE_MAEMO_MAPPER |
1208 |
|
static void cb_mm(GtkWidget *item, gpointer data) { |
1209 |
|
appdata_t *appdata = (appdata_t*)data; |
1210 |
|
|
1211 |
|
pos_set(item, appdata->mmpos.lat, appdata->mmpos.lon); |
1212 |
|
} |
1213 |
|
#endif |
1214 |
|
|
1215 |
static void cb_cache(GtkWidget *item, gpointer data) { |
static void cb_cache(GtkWidget *item, gpointer data) { |
1216 |
appdata_t *appdata = (appdata_t*)data; |
appdata_t *appdata = (appdata_t*)data; |
1217 |
|
|
1222 |
|
|
1223 |
if(!id) |
if(!id) |
1224 |
pos_set(item, cache->pos.lat, cache->pos.lon); |
pos_set(item, cache->pos.lat, cache->pos.lon); |
1225 |
else if(id == 1) |
else if(id == 1) { |
1226 |
pos_set(item, cache->notes->pos.lat, cache->notes->pos.lon); |
/* fetch position out of notes dialog since they probably */ |
1227 |
else { |
/* haven't been saved yet */ |
1228 |
|
pos_t pos = notes_get_pos(appdata->cache_context); |
1229 |
|
pos_set(item, pos.lat, pos.lon); |
1230 |
|
} else { |
1231 |
wpt_t *wpt = cache->wpt; |
wpt_t *wpt = cache->wpt; |
1232 |
while(wpt && id > 2) { |
while(wpt && id > 2) { |
1233 |
wpt = wpt->next; |
wpt = wpt->next; |
1279 |
gint id = 2; |
gint id = 2; |
1280 |
while(location) { |
while(location) { |
1281 |
if(pos_valid(&location->pos)) |
if(pos_valid(&location->pos)) |
1282 |
menu_add(menu, appdata, icon_get_widget(ICON_POS, 21), |
menu_add(menu, appdata, icon_get_widget(ICON_POS, 17), |
1283 |
location->name, cb_gps, id, lon_entry, lat_entry); |
location->name, cb_gps, id, lon_entry, lat_entry); |
1284 |
|
|
1285 |
id++; |
id++; |
1296 |
cb_map, 0, lon_entry, lat_entry); |
cb_map, 0, lon_entry, lat_entry); |
1297 |
#endif |
#endif |
1298 |
|
|
1299 |
|
#ifdef ENABLE_MAEMO_MAPPER |
1300 |
|
if(appdata->mmpos_valid) { |
1301 |
|
menu_add(menu, appdata, icon_get_widget(ICON_POS, 24), |
1302 |
|
_("Maemo Mapper position"), cb_mm, 0, lon_entry, lat_entry); |
1303 |
|
} |
1304 |
|
#endif |
1305 |
|
|
1306 |
if(appdata->cur_cache) { |
if(appdata->cur_cache) { |
1307 |
cache_t *cache = appdata->cur_cache; |
cache_t *cache = appdata->cur_cache; |
1308 |
|
|
1315 |
name, cb_cache, 0, lon_entry, lat_entry); |
name, cb_cache, 0, lon_entry, lat_entry); |
1316 |
|
|
1317 |
/* overwritten cache position */ |
/* overwritten cache position */ |
1318 |
if(cache->notes && pos_valid(&cache->notes->pos)) |
if(appdata->cache_context && notes_get_override(appdata->cache_context)) |
1319 |
menu_add(menu, appdata, icon_get_widget(ICON_POS, cache->type + 6), |
menu_add(menu, appdata, icon_get_widget(ICON_POS, cache->type + 6), |
1320 |
_("Modified coordinate"), cb_cache, 1, lon_entry, lat_entry); |
_("Modified coordinate"), cb_cache, 1, lon_entry, lat_entry); |
1321 |
|
|
1470 |
gint id = 2; |
gint id = 2; |
1471 |
while(location) { |
while(location) { |
1472 |
if(pos_valid(&location->pos)) |
if(pos_valid(&location->pos)) |
1473 |
preset_picker_add(store, appdata, icon_get(ICON_POS, 21), |
preset_picker_add(store, appdata, icon_get(ICON_POS, 17), |
1474 |
location->name, cb_gps, id); |
location->name, cb_gps, id); |
1475 |
|
|
1476 |
id++; |
id++; |
1480 |
if(pos_valid(&appdata->geomath)) |
if(pos_valid(&appdata->geomath)) |
1481 |
preset_picker_add(store, appdata, icon_get(ICON_POS, 19), |
preset_picker_add(store, appdata, icon_get(ICON_POS, 19), |
1482 |
_("Geomath projection"), cb_geomath, 0); |
_("Geomath projection"), cb_geomath, 0); |
1483 |
|
|
1484 |
#ifdef ENABLE_OSM_GPS_MAP |
#ifdef ENABLE_OSM_GPS_MAP |
1485 |
if(pos_valid(&appdata->map.pos)) |
if(pos_valid(&appdata->map.pos)) |
1486 |
preset_picker_add(store, appdata, icon_get(ICON_POS, 20), |
preset_picker_add(store, appdata, icon_get(ICON_POS, 20), |
1487 |
_("Map position"), cb_map, 0); |
_("Map position"), cb_map, 0); |
1488 |
#endif |
#endif |
1489 |
|
|
1490 |
|
#ifdef ENABLE_MAEMO_MAPPER |
1491 |
|
if(appdata->mmpos_valid) { |
1492 |
|
preset_picker_add(store, appdata, icon_get(ICON_POS, 24), |
1493 |
|
_("Maemo Mapper position"), cb_mm, 0); |
1494 |
|
} |
1495 |
|
#endif |
1496 |
|
|
1497 |
if(appdata->cur_cache) { |
if(appdata->cur_cache) { |
1498 |
cache_t *cache = appdata->cur_cache; |
cache_t *cache = appdata->cur_cache; |
1499 |
|
|
1506 |
name, cb_cache, 0); |
name, cb_cache, 0); |
1507 |
|
|
1508 |
/* overwritten cache position */ |
/* overwritten cache position */ |
1509 |
if(cache->notes && pos_valid(&cache->notes->pos)) |
if(appdata->cache_context && notes_get_override(appdata->cache_context)) |
1510 |
preset_picker_add(store, appdata, icon_get(ICON_POS, cache->type + 6), |
preset_picker_add(store, appdata, icon_get(ICON_POS, cache->type + 6), |
1511 |
_("Modified coordinate"), cb_cache, 1); |
_("Modified coordinate"), cb_cache, 1); |
1512 |
|
|
1559 |
|
|
1560 |
if(event->type == GDK_BUTTON_PRESS) { |
if(event->type == GDK_BUTTON_PRESS) { |
1561 |
GtkWidget *dialog = |
GtkWidget *dialog = |
1562 |
gtk_dialog_new_with_buttons(_("Preset coordinates"), |
gtk_dialog_new_with_buttons(_("Use coordinate"), |
1563 |
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))), |
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))), |
1564 |
GTK_DIALOG_MODAL, |
GTK_DIALOG_MODAL, |
1565 |
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, |
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, |
1586 |
|
|
1587 |
GtkWidget *button = gtk_button_new(); |
GtkWidget *button = gtk_button_new(); |
1588 |
|
|
1589 |
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)); |
1590 |
|
|
1591 |
gtk_widget_set_tooltip_text(button, _("Preset coordinates")); |
#ifndef USE_MAEMO |
1592 |
|
gtk_widget_set_tooltip_text(button, _("Use coordinate")); |
1593 |
|
#endif |
1594 |
|
|
1595 |
g_object_set_data(G_OBJECT(button), "lat_entry", (gpointer)lat_entry); |
g_object_set_data(G_OBJECT(button), "lat_entry", (gpointer)lat_entry); |
1596 |
g_object_set_data(G_OBJECT(button), "lon_entry", (gpointer)lon_entry); |
g_object_set_data(G_OBJECT(button), "lon_entry", (gpointer)lon_entry); |
1601 |
|
|
1602 |
gtk_signal_connect(GTK_OBJECT(button), "destroy", |
gtk_signal_connect(GTK_OBJECT(button), "destroy", |
1603 |
(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)); |
|
1604 |
#else |
#else |
1605 |
#ifdef FREMANTLE |
#ifdef FREMANTLE |
1606 |
hildon_gtk_widget_set_theme_size(button, |
hildon_gtk_widget_set_theme_size(button, |
1614 |
return button; |
return button; |
1615 |
} |
} |
1616 |
|
|
1617 |
|
#if defined(ENABLE_MAEMO_MAPPER) || defined(ENABLE_OSM_GPS_MAP) |
1618 |
|
static pos_t goto_pos_get(GtkWidget *item) { |
1619 |
|
pos_t pos; |
1620 |
|
|
1621 |
|
GtkWidget *lat_entry = g_object_get_data(G_OBJECT(item), "lat_entry"); |
1622 |
|
pos.lat = lat_entry_get(lat_entry); |
1623 |
|
|
1624 |
|
GtkWidget *lon_entry = g_object_get_data(G_OBJECT(item), "lon_entry"); |
1625 |
|
pos.lon = lon_entry_get(lon_entry); |
1626 |
|
|
1627 |
|
return pos; |
1628 |
|
} |
1629 |
|
|
1630 |
|
#if defined(ENABLE_MAEMO_MAPPER) && defined(ENABLE_OSM_GPS_MAP) |
1631 |
|
#ifdef ENABLE_MAEMO_MAPPER |
1632 |
|
static void cb_mm_set(GtkWidget *item, gpointer data) { |
1633 |
|
appdata_t *appdata = (appdata_t*)data; |
1634 |
|
|
1635 |
|
pos_t pos = goto_pos_get(item); |
1636 |
|
if(!isnan(pos.lat) && !isnan(pos.lon)) |
1637 |
|
dbus_mm_set_position(appdata, &pos); |
1638 |
|
} |
1639 |
|
#endif |
1640 |
|
|
1641 |
|
#ifdef ENABLE_OSM_GPS_MAP |
1642 |
|
static void cb_map_set(GtkWidget *item, gpointer data) { |
1643 |
|
appdata_t *appdata = (appdata_t*)data; |
1644 |
|
|
1645 |
|
pos_t pos = goto_pos_get(item); |
1646 |
|
if(!isnan(pos.lat) && !isnan(pos.lon)) { |
1647 |
|
map(appdata); |
1648 |
|
osm_gps_map_set_center(OSM_GPS_MAP(appdata->map.context->widget), |
1649 |
|
pos.lat, pos.lon); |
1650 |
|
} |
1651 |
|
} |
1652 |
|
#endif |
1653 |
|
|
1654 |
|
#ifndef PRESET_PICKER_DIALOG |
1655 |
|
static GtkWidget *goto_popup_menu_create(appdata_t *appdata, |
1656 |
|
GtkWidget *lat_entry, GtkWidget *lon_entry) { |
1657 |
|
GtkWidget *menu = gtk_menu_new(); |
1658 |
|
|
1659 |
|
#if defined(ENABLE_OSM_GPS_MAP) |
1660 |
|
menu_add(menu, appdata, icon_get_widget(ICON_POS, 20), |
1661 |
|
_("Internal map"), cb_map_set, 0, lon_entry, lat_entry); |
1662 |
|
#endif |
1663 |
|
|
1664 |
|
#if defined(ENABLE_MAEMO_MAPPER) |
1665 |
|
menu_add(menu, appdata, icon_get_widget(ICON_POS, 24), |
1666 |
|
_("Maemo Mapper"), cb_mm_set, 0, lon_entry, lat_entry); |
1667 |
|
#endif |
1668 |
|
|
1669 |
|
gtk_widget_show_all(menu); |
1670 |
|
|
1671 |
|
return menu; |
1672 |
|
} |
1673 |
|
#else |
1674 |
|
static GtkWidget *goto_picker_create(appdata_t *appdata, |
1675 |
|
GtkWidget *lat_entry, GtkWidget *lon_entry) { |
1676 |
|
GtkCellRenderer *renderer; |
1677 |
|
GtkListStore *store; |
1678 |
|
|
1679 |
|
GtkWidget *view = gtk_tree_view_new(); |
1680 |
|
|
1681 |
|
g_object_set_data(G_OBJECT(view), "lat_entry", (gpointer)lat_entry); |
1682 |
|
g_object_set_data(G_OBJECT(view), "lon_entry", (gpointer)lon_entry); |
1683 |
|
|
1684 |
|
/* --- "Icon" column --- */ |
1685 |
|
renderer = gtk_cell_renderer_pixbuf_new(); |
1686 |
|
gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(view), |
1687 |
|
-1, "Icon", renderer, "pixbuf", PRESET_PICKER_COL_ICON, NULL); |
1688 |
|
|
1689 |
|
/* --- "Name" column --- */ |
1690 |
|
renderer = gtk_cell_renderer_text_new(); |
1691 |
|
g_object_set(renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL ); |
1692 |
|
GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes( |
1693 |
|
"Name", renderer, "text", PRESET_PICKER_COL_NAME, NULL); |
1694 |
|
gtk_tree_view_column_set_expand(column, TRUE); |
1695 |
|
gtk_tree_view_insert_column(GTK_TREE_VIEW(view), column, -1); |
1696 |
|
|
1697 |
|
store = gtk_list_store_new(PRESET_PICKER_NUM_COLS, |
1698 |
|
GDK_TYPE_PIXBUF, |
1699 |
|
G_TYPE_STRING, |
1700 |
|
G_TYPE_INT, |
1701 |
|
G_TYPE_POINTER); |
1702 |
|
|
1703 |
|
#if defined(ENABLE_OSM_GPS_MAP) |
1704 |
|
preset_picker_add(store, appdata, icon_get(ICON_POS, 20), |
1705 |
|
_("Internal map"), cb_map_set, 0); |
1706 |
|
#endif |
1707 |
|
|
1708 |
|
#if defined(ENABLE_MAEMO_MAPPER) |
1709 |
|
preset_picker_add(store, appdata, icon_get(ICON_POS, 24), |
1710 |
|
_("Maemo Mapper"), cb_mm_set, 0); |
1711 |
|
#endif |
1712 |
|
|
1713 |
|
gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store)); |
1714 |
|
g_object_unref(store); |
1715 |
|
|
1716 |
|
/* make list react on clicks */ |
1717 |
|
g_signal_connect(view, "row-activated", |
1718 |
|
(GCallback)on_preset_picker_activated, appdata); |
1719 |
|
|
1720 |
|
/* put this inside a scrolled view */ |
1721 |
|
#ifndef USE_PANNABLE_AREA |
1722 |
|
GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL); |
1723 |
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), |
1724 |
|
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); |
1725 |
|
gtk_container_add(GTK_CONTAINER(scrolled_window), view); |
1726 |
|
return scrolled_window; |
1727 |
|
#else |
1728 |
|
GtkWidget *pannable_area = hildon_pannable_area_new(); |
1729 |
|
gtk_container_add(GTK_CONTAINER(pannable_area), view); |
1730 |
|
return pannable_area; |
1731 |
|
#endif |
1732 |
|
} |
1733 |
|
#endif |
1734 |
|
#endif |
1735 |
|
|
1736 |
|
static gint on_goto_button_press(GtkWidget *button, |
1737 |
|
GdkEventButton *event, gpointer data) { |
1738 |
|
appdata_t *appdata = (appdata_t*)data; |
1739 |
|
|
1740 |
|
if(event->type == GDK_BUTTON_PRESS) { |
1741 |
|
|
1742 |
|
#if defined(ENABLE_MAEMO_MAPPER) && !defined(ENABLE_OSM_GPS_MAP) |
1743 |
|
/* only maemo mapper is being used */ |
1744 |
|
pos_t pos = goto_pos_get(button); |
1745 |
|
if(!isnan(pos.lat) && !isnan(pos.lon)) |
1746 |
|
dbus_mm_set_position(appdata, &pos); |
1747 |
|
#elif !defined(ENABLE_MAEMO_MAPPER) && defined(ENABLE_OSM_GPS_MAP) |
1748 |
|
/* only internal map is being used */ |
1749 |
|
pos_t pos = goto_pos_get(button); |
1750 |
|
if(!isnan(pos.lat) && !isnan(pos.lon)) { |
1751 |
|
map(appdata); |
1752 |
|
osm_gps_map_set_center(OSM_GPS_MAP(appdata->map.context->widget), |
1753 |
|
pos.lat, pos.lon); |
1754 |
|
} |
1755 |
|
#else |
1756 |
|
|
1757 |
|
gpointer lat_entry = g_object_get_data(G_OBJECT(button), "lat_entry"); |
1758 |
|
g_assert(lat_entry); |
1759 |
|
gpointer lon_entry = g_object_get_data(G_OBJECT(button), "lon_entry"); |
1760 |
|
g_assert(lon_entry); |
1761 |
|
|
1762 |
|
#ifndef PRESET_PICKER_DIALOG |
1763 |
|
GtkWidget *menu = g_object_get_data(G_OBJECT(button), "menu"); |
1764 |
|
if(!menu) { |
1765 |
|
menu = goto_popup_menu_create(appdata, lat_entry, lon_entry); |
1766 |
|
g_object_set_data(G_OBJECT(button), "menu", (gpointer)menu); |
1767 |
|
} |
1768 |
|
|
1769 |
|
/* draw a popup menu */ |
1770 |
|
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, |
1771 |
|
event->button, event->time); |
1772 |
|
#else |
1773 |
|
GtkWidget *dialog = |
1774 |
|
gtk_dialog_new_with_buttons(_("Show coordinate on map"), |
1775 |
|
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))), |
1776 |
|
GTK_DIALOG_MODAL, |
1777 |
|
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, |
1778 |
|
NULL); |
1779 |
|
|
1780 |
|
gtk_window_set_default_size(GTK_WINDOW(dialog), 400, 210); |
1781 |
|
|
1782 |
|
gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), |
1783 |
|
goto_picker_create(appdata, lat_entry, lon_entry)); |
1784 |
|
|
1785 |
|
gtk_widget_show_all(dialog); |
1786 |
|
gtk_dialog_run(GTK_DIALOG(dialog)); |
1787 |
|
gtk_widget_destroy(dialog); |
1788 |
|
#endif |
1789 |
|
|
1790 |
|
#endif |
1791 |
|
|
1792 |
|
return TRUE; |
1793 |
|
} |
1794 |
|
return FALSE; |
1795 |
|
} |
1796 |
|
|
1797 |
|
/* a button which makes the map/maemo mapper go to the associated */ |
1798 |
|
/* position */ |
1799 |
|
GtkWidget *goto_coordinate(appdata_t *appdata, |
1800 |
|
GtkWidget *lat_entry, GtkWidget *lon_entry) { |
1801 |
|
|
1802 |
|
GtkWidget *button = gtk_button_new(); |
1803 |
|
|
1804 |
|
gtk_button_set_image(GTK_BUTTON(button), icon_get_widget(ICON_POS, 23)); |
1805 |
|
|
1806 |
|
#ifndef USE_MAEMO |
1807 |
|
gtk_widget_set_tooltip_text(button, _("Show coordinate on map")); |
1808 |
|
#endif |
1809 |
|
|
1810 |
|
g_object_set_data(G_OBJECT(button), "lat_entry", (gpointer)lat_entry); |
1811 |
|
g_object_set_data(G_OBJECT(button), "lon_entry", (gpointer)lon_entry); |
1812 |
|
|
1813 |
|
gtk_signal_connect(GTK_OBJECT(button), "button-press-event", |
1814 |
|
(GtkSignalFunc)on_goto_button_press, appdata); |
1815 |
|
|
1816 |
|
#ifndef PRESET_PICKER_DIALOG |
1817 |
|
gtk_signal_connect(GTK_OBJECT(button), "destroy", |
1818 |
|
(GtkSignalFunc)on_popup_destroy, appdata); |
1819 |
|
#else |
1820 |
|
#ifdef FREMANTLE |
1821 |
|
hildon_gtk_widget_set_theme_size(button, |
1822 |
|
(HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH)); |
1823 |
|
#endif |
1824 |
|
#endif |
1825 |
|
|
1826 |
|
return button; |
1827 |
|
} |
1828 |
|
#else |
1829 |
|
/* no map installed */ |
1830 |
|
GtkWidget *goto_coordinate(appdata_t *appdata, |
1831 |
|
GtkWidget *lat_entry, GtkWidget *lon_entry) { |
1832 |
|
return gtk_label_new(""); |
1833 |
|
} |
1834 |
|
#endif |
1835 |
|
|
1836 |
GtkWidget *entry_new(void) { |
GtkWidget *entry_new(void) { |
1837 |
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
1838 |
return gtk_entry_new(); |
return gtk_entry_new(); |
1937 |
angle_str(str, sizeof(str), angle); |
angle_str(str, sizeof(str), angle); |
1938 |
|
|
1939 |
#ifndef COORDINATE_PICKER |
#ifndef COORDINATE_PICKER |
1940 |
GtkWidget *widget = red_entry_new(); |
GtkWidget *widget = red_entry_new_with_text(str); |
|
gtk_entry_set_text(GTK_ENTRY(widget), str); |
|
|
|
|
1941 |
g_signal_connect(G_OBJECT(widget), "changed", |
g_signal_connect(G_OBJECT(widget), "changed", |
1942 |
G_CALLBACK(callback_modified_angle), NULL); |
G_CALLBACK(callback_modified_angle), NULL); |
1943 |
#else |
#else |
1954 |
#endif |
#endif |
1955 |
return widget; |
return widget; |
1956 |
} |
} |
1957 |
|
|
1958 |
float angle_entry_get(GtkWidget *widget) { |
float angle_entry_get(GtkWidget *widget) { |
1959 |
#ifndef COORDINATE_PICKER |
#ifndef COORDINATE_PICKER |
1960 |
char *p = (char*)gtk_entry_get_text(GTK_ENTRY(widget)); |
char *p = (char*)gtk_entry_get_text(GTK_ENTRY(widget)); |
1976 |
g_signal_emit_by_name(widget, "changed"); |
g_signal_emit_by_name(widget, "changed"); |
1977 |
#endif |
#endif |
1978 |
} |
} |
1979 |
|
|
1980 |
|
GtkWidget *toggle_button_new_with_label(char *label) { |
1981 |
|
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
1982 |
|
return gtk_check_button_new_with_label(label); |
1983 |
|
#else |
1984 |
|
GtkWidget *cbut = gtk_toggle_button_new_with_label(label); |
1985 |
|
hildon_gtk_widget_set_theme_size(cbut, |
1986 |
|
(HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH)); |
1987 |
|
gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(cbut), FALSE); |
1988 |
|
return cbut; |
1989 |
|
#endif |
1990 |
|
} |
1991 |
|
|
1992 |
|
void toggle_button_set_active(GtkWidget *button, gboolean active) { |
1993 |
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), active); |
1994 |
|
} |
1995 |
|
|
1996 |
|
gboolean toggle_button_get_active(GtkWidget *button) { |
1997 |
|
return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)); |
1998 |
|
} |
1999 |
|
|
2000 |
|
GtkWidget *check_button_new_with_label(char *label) { |
2001 |
|
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
2002 |
|
return gtk_check_button_new_with_label(label); |
2003 |
|
#else |
2004 |
|
GtkWidget *cbut = |
2005 |
|
hildon_check_button_new(HILDON_SIZE_FINGER_HEIGHT | |
2006 |
|
HILDON_SIZE_AUTO_WIDTH); |
2007 |
|
gtk_button_set_label(GTK_BUTTON(cbut), label); |
2008 |
|
return cbut; |
2009 |
|
#endif |
2010 |
|
} |
2011 |
|
|
2012 |
|
void check_button_set_active(GtkWidget *button, gboolean active) { |
2013 |
|
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
2014 |
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), active); |
2015 |
|
#else |
2016 |
|
hildon_check_button_set_active(HILDON_CHECK_BUTTON(button), active); |
2017 |
|
#endif |
2018 |
|
} |
2019 |
|
|
2020 |
|
gboolean check_button_get_active(GtkWidget *button) { |
2021 |
|
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
2022 |
|
return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)); |
2023 |
|
#else |
2024 |
|
return hildon_check_button_get_active(HILDON_CHECK_BUTTON(button)); |
2025 |
|
#endif |
2026 |
|
} |
2027 |
|
|
2028 |
|
GtkWidget *button_new(void) { |
2029 |
|
GtkWidget *button = gtk_button_new(); |
2030 |
|
#if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR == 5) |
2031 |
|
hildon_gtk_widget_set_theme_size(button, |
2032 |
|
(HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH)); |
2033 |
|
#endif |
2034 |
|
return button; |
2035 |
|
} |
2036 |
|
|
2037 |
|
GtkWidget *button_new_with_label(char *label) { |
2038 |
|
GtkWidget *button = gtk_button_new_with_label(label); |
2039 |
|
#if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR == 5) |
2040 |
|
hildon_gtk_widget_set_theme_size(button, |
2041 |
|
(HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH)); |
2042 |
|
#endif |
2043 |
|
return button; |
2044 |
|
} |
2045 |
|
|
2046 |
|
static void on_browse(GtkWidget *widget, gpointer data) { |
2047 |
|
GtkWidget *dialog; |
2048 |
|
|
2049 |
|
char **fileptr = g_object_get_data(G_OBJECT(widget), "fileptr"); |
2050 |
|
|
2051 |
|
#ifdef USE_MAEMO |
2052 |
|
dialog = hildon_file_chooser_dialog_new( |
2053 |
|
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(widget))), |
2054 |
|
GTK_FILE_CHOOSER_ACTION_SAVE); |
2055 |
|
#else |
2056 |
|
dialog = gtk_file_chooser_dialog_new( |
2057 |
|
g_object_get_data(G_OBJECT(widget), "sel_title"), |
2058 |
|
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(widget))), |
2059 |
|
GTK_FILE_CHOOSER_ACTION_SAVE, |
2060 |
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
2061 |
|
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, |
2062 |
|
NULL); |
2063 |
|
#endif |
2064 |
|
|
2065 |
|
if(*fileptr) { |
2066 |
|
printf("set filename <%s>\n", *fileptr); |
2067 |
|
|
2068 |
|
if(!g_file_test(*fileptr, G_FILE_TEST_EXISTS)) { |
2069 |
|
char *last_sep = strrchr(*fileptr, '/'); |
2070 |
|
if(last_sep) { |
2071 |
|
*last_sep = 0; // seperate path from file |
2072 |
|
|
2073 |
|
/* the user just created a new document */ |
2074 |
|
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), |
2075 |
|
*fileptr); |
2076 |
|
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), |
2077 |
|
last_sep+1); |
2078 |
|
|
2079 |
|
/* restore full filename */ |
2080 |
|
*last_sep = '/'; |
2081 |
|
} |
2082 |
|
} else |
2083 |
|
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), *fileptr); |
2084 |
|
} |
2085 |
|
|
2086 |
|
if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_FM_OK) { |
2087 |
|
gchar *name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); |
2088 |
|
if(name) { |
2089 |
|
if(*fileptr) g_free(*fileptr); |
2090 |
|
*fileptr = g_strdup(name); |
2091 |
|
|
2092 |
|
#ifndef FREMANTLE |
2093 |
|
GtkWidget *label = g_object_get_data(G_OBJECT(widget), "label"); |
2094 |
|
gtk_label_set_text(GTK_LABEL(label), *fileptr); |
2095 |
|
#else |
2096 |
|
hildon_button_set_value(HILDON_BUTTON(widget), *fileptr); |
2097 |
|
#endif |
2098 |
|
} |
2099 |
|
} |
2100 |
|
|
2101 |
|
gtk_widget_destroy (dialog); |
2102 |
|
} |
2103 |
|
|
2104 |
|
GtkWidget *export_file(char *sel_title, char **filename) { |
2105 |
|
/* non-fremantle and classic gtk use a rather ugly and */ |
2106 |
|
/* complex layout */ |
2107 |
|
#ifndef FREMANTLE |
2108 |
|
GtkWidget *vbox = gtk_vbox_new(FALSE, 0); |
2109 |
|
GtkWidget *hbox = gtk_hbox_new(FALSE, 0); |
2110 |
|
GtkWidget *label = gtk_label_new(_("Export to")); |
2111 |
|
gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE,0); |
2112 |
|
gtk_misc_set_alignment(GTK_MISC(label), 0.f, 0.5f); |
2113 |
|
GtkWidget *button = button_new_with_label(_("Browse")); |
2114 |
|
g_object_set_data(G_OBJECT(button), "sel_title", sel_title); |
2115 |
|
g_object_set_data(G_OBJECT(button), "fileptr", filename); |
2116 |
|
gtk_signal_connect(GTK_OBJECT(button), "clicked", |
2117 |
|
GTK_SIGNAL_FUNC(on_browse), NULL); |
2118 |
|
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE,0); |
2119 |
|
gtk_box_pack_start_defaults(GTK_BOX(vbox), hbox); |
2120 |
|
|
2121 |
|
label = gtk_label_new((*filename)?*filename:""); |
2122 |
|
g_object_set_data(G_OBJECT(button), "label", label); |
2123 |
|
gtk_misc_set_alignment(GTK_MISC(label), 0.f, 0.5f); |
2124 |
|
gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_MIDDLE); |
2125 |
|
|
2126 |
|
gtk_box_pack_start_defaults(GTK_BOX(vbox), label); |
2127 |
|
return vbox; |
2128 |
|
#else |
2129 |
|
GtkWidget *button = hildon_button_new_with_text( |
2130 |
|
(HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH), |
2131 |
|
HILDON_BUTTON_ARRANGEMENT_VERTICAL, |
2132 |
|
_("Export to"), *filename); |
2133 |
|
hildon_button_set_title_alignment(HILDON_BUTTON(button), 0.5, 0.5); |
2134 |
|
hildon_button_set_value_alignment(HILDON_BUTTON(button), 0.5, 0.5); |
2135 |
|
g_object_set_data(G_OBJECT(button), "sel_title", sel_title); |
2136 |
|
g_object_set_data(G_OBJECT(button), "fileptr", filename); |
2137 |
|
gtk_signal_connect(GTK_OBJECT(button), "clicked", |
2138 |
|
GTK_SIGNAL_FUNC(on_browse), NULL); |
2139 |
|
return button; |
2140 |
|
#endif |
2141 |
|
} |
2142 |
|
|
2143 |
|
|