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); |
974 |
#ifndef COORDINATE_PICKER |
#ifndef COORDINATE_PICKER |
975 |
gtk_entry_set_text(GTK_ENTRY(widget), str); |
gtk_entry_set_text(GTK_ENTRY(widget), str); |
976 |
#else |
#else |
977 |
|
gtk_button_set_label(GTK_BUTTON(widget), str); |
978 |
int dist_int = (int)roundf(dist * 1000); // km -> m |
int dist_int = (int)roundf(dist * 1000); // km -> m |
979 |
if(mil) dist_int = (int)roundf(dist * 5280.0); // mi -> ft |
if(mil) dist_int = (int)roundf(dist * 5280.0); // mi -> ft |
980 |
g_object_set_data(G_OBJECT(widget), "distance", (gpointer)dist_int); |
g_object_set_data(G_OBJECT(widget), "distance", (gpointer)dist_int); |
981 |
g_object_set_data(G_OBJECT(widget), "mil", (gpointer)mil); |
g_object_set_data(G_OBJECT(widget), "mil", (gpointer)mil); |
982 |
gtk_button_set_label(GTK_BUTTON(widget), str); |
g_signal_emit_by_name(widget, "changed"); |
983 |
#endif |
#endif |
984 |
} |
} |
985 |
|
|
1178 |
static void cb_mm(GtkWidget *item, gpointer data) { |
static void cb_mm(GtkWidget *item, gpointer data) { |
1179 |
appdata_t *appdata = (appdata_t*)data; |
appdata_t *appdata = (appdata_t*)data; |
1180 |
|
|
1181 |
pos_set(item, appdata->mmpos.lat, appdata->mpos.lon); |
pos_set(item, appdata->mmpos.lat, appdata->mmpos.lon); |
1182 |
} |
} |
1183 |
#endif |
#endif |
1184 |
|
|
1269 |
#ifdef ENABLE_MAEMO_MAPPER |
#ifdef ENABLE_MAEMO_MAPPER |
1270 |
if(appdata->mmpos_valid) { |
if(appdata->mmpos_valid) { |
1271 |
menu_add(menu, appdata, icon_get_widget(ICON_POS, 24), |
menu_add(menu, appdata, icon_get_widget(ICON_POS, 24), |
1272 |
_("Maemo mapper position"), cb_mm, 0, lon_entry, lat_entry); |
_("Maemo Mapper position"), cb_mm, 0, lon_entry, lat_entry); |
1273 |
} |
} |
1274 |
#endif |
#endif |
1275 |
|
|
1459 |
|
|
1460 |
#ifdef ENABLE_MAEMO_MAPPER |
#ifdef ENABLE_MAEMO_MAPPER |
1461 |
if(appdata->mmpos_valid) { |
if(appdata->mmpos_valid) { |
1462 |
preset_picker_add(menu, appdata, icon_get(ICON_POS, 24), |
preset_picker_add(store, appdata, icon_get(ICON_POS, 24), |
1463 |
_("Maemo mapper position"), cb_mm, 0); |
_("Maemo Mapper position"), cb_mm, 0); |
1464 |
} |
} |
1465 |
#endif |
#endif |
1466 |
|
|
1529 |
|
|
1530 |
if(event->type == GDK_BUTTON_PRESS) { |
if(event->type == GDK_BUTTON_PRESS) { |
1531 |
GtkWidget *dialog = |
GtkWidget *dialog = |
1532 |
gtk_dialog_new_with_buttons(_("Preset coordinates"), |
gtk_dialog_new_with_buttons(_("Use coordinate"), |
1533 |
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))), |
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))), |
1534 |
GTK_DIALOG_MODAL, |
GTK_DIALOG_MODAL, |
1535 |
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, |
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, |
1558 |
|
|
1559 |
gtk_button_set_image(GTK_BUTTON(button), icon_get_widget(ICON_POS, 22)); |
gtk_button_set_image(GTK_BUTTON(button), icon_get_widget(ICON_POS, 22)); |
1560 |
|
|
1561 |
gtk_widget_set_tooltip_text(button, _("Preset coordinates")); |
#ifndef USE_MAEMO |
1562 |
|
gtk_widget_set_tooltip_text(button, _("Use coordinate")); |
1563 |
|
#endif |
1564 |
|
|
1565 |
g_object_set_data(G_OBJECT(button), "lat_entry", (gpointer)lat_entry); |
g_object_set_data(G_OBJECT(button), "lat_entry", (gpointer)lat_entry); |
1566 |
g_object_set_data(G_OBJECT(button), "lon_entry", (gpointer)lon_entry); |
g_object_set_data(G_OBJECT(button), "lon_entry", (gpointer)lon_entry); |
1597 |
return pos; |
return pos; |
1598 |
} |
} |
1599 |
|
|
1600 |
|
#if defined(ENABLE_MAEMO_MAPPER) && defined(ENABLE_OSM_GPS_MAP) |
1601 |
#ifdef ENABLE_MAEMO_MAPPER |
#ifdef ENABLE_MAEMO_MAPPER |
1602 |
static void cb_mm_set(GtkWidget *item, gpointer data) { |
static void cb_mm_set(GtkWidget *item, gpointer data) { |
1603 |
appdata_t *appdata = (appdata_t*)data; |
appdata_t *appdata = (appdata_t*)data; |
1608 |
} |
} |
1609 |
#endif |
#endif |
1610 |
|
|
1611 |
|
#ifdef ENABLE_OSM_GPS_MAP |
1612 |
static void cb_map_set(GtkWidget *item, gpointer data) { |
static void cb_map_set(GtkWidget *item, gpointer data) { |
1613 |
appdata_t *appdata = (appdata_t*)data; |
appdata_t *appdata = (appdata_t*)data; |
1614 |
|
|
1619 |
pos.lat, pos.lon); |
pos.lat, pos.lon); |
1620 |
} |
} |
1621 |
} |
} |
1622 |
|
#endif |
1623 |
|
|
1624 |
#ifndef PRESET_PICKER_DIALOG |
#ifndef PRESET_PICKER_DIALOG |
1625 |
static GtkWidget *goto_popup_menu_create(appdata_t *appdata, |
static GtkWidget *goto_popup_menu_create(appdata_t *appdata, |
1628 |
|
|
1629 |
#if defined(ENABLE_OSM_GPS_MAP) |
#if defined(ENABLE_OSM_GPS_MAP) |
1630 |
menu_add(menu, appdata, icon_get_widget(ICON_POS, 20), |
menu_add(menu, appdata, icon_get_widget(ICON_POS, 20), |
1631 |
_("Map position"), cb_map_set, 0, lon_entry, lat_entry); |
_("Internal map"), cb_map_set, 0, lon_entry, lat_entry); |
1632 |
#endif |
#endif |
1633 |
|
|
1634 |
#if defined(ENABLE_MAEMO_MAPPER) |
#if defined(ENABLE_MAEMO_MAPPER) |
1635 |
menu_add(menu, appdata, icon_get_widget(ICON_POS, 24), |
menu_add(menu, appdata, icon_get_widget(ICON_POS, 24), |
1636 |
_("Maemo mapper position"), cb_mm_set, 0, lon_entry, lat_entry); |
_("Maemo Mapper"), cb_mm_set, 0, lon_entry, lat_entry); |
1637 |
#endif |
#endif |
1638 |
|
|
1639 |
gtk_widget_show_all(menu); |
gtk_widget_show_all(menu); |
1672 |
|
|
1673 |
#if defined(ENABLE_OSM_GPS_MAP) |
#if defined(ENABLE_OSM_GPS_MAP) |
1674 |
preset_picker_add(store, appdata, icon_get(ICON_POS, 20), |
preset_picker_add(store, appdata, icon_get(ICON_POS, 20), |
1675 |
_("Map position"), cb_map_set, 0); |
_("Internal map"), cb_map_set, 0); |
1676 |
#endif |
#endif |
1677 |
|
|
1678 |
#if defined(ENABLE_MAEMO_MAPPER) |
#if defined(ENABLE_MAEMO_MAPPER) |
1679 |
preset_picker_add(store, appdata, icon_get(ICON_POS, 24), |
preset_picker_add(store, appdata, icon_get(ICON_POS, 24), |
1680 |
_("Maemo mapper position"), cb_mm_set, 0); |
_("Maemo Mapper"), cb_mm_set, 0); |
1681 |
#endif |
#endif |
1682 |
|
|
1683 |
gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store)); |
gtk_tree_view_set_model(GTK_TREE_VIEW(view), GTK_TREE_MODEL(store)); |
1701 |
#endif |
#endif |
1702 |
} |
} |
1703 |
#endif |
#endif |
1704 |
|
#endif |
1705 |
|
|
1706 |
static gint on_goto_button_press(GtkWidget *button, |
static gint on_goto_button_press(GtkWidget *button, |
1707 |
GdkEventButton *event, gpointer data) { |
GdkEventButton *event, gpointer data) { |
1712 |
#if defined(ENABLE_MAEMO_MAPPER) && !defined(ENABLE_OSM_GPS_MAP) |
#if defined(ENABLE_MAEMO_MAPPER) && !defined(ENABLE_OSM_GPS_MAP) |
1713 |
/* only maemo mapper is being used */ |
/* only maemo mapper is being used */ |
1714 |
pos_t pos = goto_pos_get(button); |
pos_t pos = goto_pos_get(button); |
1715 |
if(!isnan(pos.lat) && !isnan(pos.lon)) { |
if(!isnan(pos.lat) && !isnan(pos.lon)) |
1716 |
dbus_mm_set_position(appdata, &pos); |
dbus_mm_set_position(appdata, &pos); |
1717 |
#elif !defined(ENABLE_MAEMO_MAPPER) && defined(ENABLE_OSM_GPS_MAP) |
#elif !defined(ENABLE_MAEMO_MAPPER) && defined(ENABLE_OSM_GPS_MAP) |
1718 |
/* only internal map is being used */ |
/* only internal map is being used */ |
1741 |
event->button, event->time); |
event->button, event->time); |
1742 |
#else |
#else |
1743 |
GtkWidget *dialog = |
GtkWidget *dialog = |
1744 |
gtk_dialog_new_with_buttons(_("Map coordinates"), |
gtk_dialog_new_with_buttons(_("Show coordinate on map"), |
1745 |
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))), |
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(button))), |
1746 |
GTK_DIALOG_MODAL, |
GTK_DIALOG_MODAL, |
1747 |
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, |
GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, |
1773 |
|
|
1774 |
gtk_button_set_image(GTK_BUTTON(button), icon_get_widget(ICON_POS, 23)); |
gtk_button_set_image(GTK_BUTTON(button), icon_get_widget(ICON_POS, 23)); |
1775 |
|
|
1776 |
gtk_widget_set_tooltip_text(button, _("Goto coordinates")); |
#ifndef USE_MAEMO |
1777 |
|
gtk_widget_set_tooltip_text(button, _("Show coordinate on map")); |
1778 |
|
#endif |
1779 |
|
|
1780 |
g_object_set_data(G_OBJECT(button), "lat_entry", (gpointer)lat_entry); |
g_object_set_data(G_OBJECT(button), "lat_entry", (gpointer)lat_entry); |
1781 |
g_object_set_data(G_OBJECT(button), "lon_entry", (gpointer)lon_entry); |
g_object_set_data(G_OBJECT(button), "lon_entry", (gpointer)lon_entry); |
1924 |
#endif |
#endif |
1925 |
return widget; |
return widget; |
1926 |
} |
} |
1927 |
|
|
1928 |
float angle_entry_get(GtkWidget *widget) { |
float angle_entry_get(GtkWidget *widget) { |
1929 |
#ifndef COORDINATE_PICKER |
#ifndef COORDINATE_PICKER |
1930 |
char *p = (char*)gtk_entry_get_text(GTK_ENTRY(widget)); |
char *p = (char*)gtk_entry_get_text(GTK_ENTRY(widget)); |
1946 |
g_signal_emit_by_name(widget, "changed"); |
g_signal_emit_by_name(widget, "changed"); |
1947 |
#endif |
#endif |
1948 |
} |
} |
1949 |
|
|
1950 |
|
GtkWidget *toggle_button_new_with_label(char *label) { |
1951 |
|
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
1952 |
|
return gtk_check_button_new_with_label(label); |
1953 |
|
#else |
1954 |
|
GtkWidget *cbut = gtk_toggle_button_new_with_label(label); |
1955 |
|
hildon_gtk_widget_set_theme_size(cbut, |
1956 |
|
(HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH)); |
1957 |
|
gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(cbut), FALSE); |
1958 |
|
return cbut; |
1959 |
|
#endif |
1960 |
|
} |
1961 |
|
|
1962 |
|
void toggle_button_set_active(GtkWidget *button, gboolean active) { |
1963 |
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), active); |
1964 |
|
} |
1965 |
|
|
1966 |
|
gboolean toggle_button_get_active(GtkWidget *button) { |
1967 |
|
return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)); |
1968 |
|
} |
1969 |
|
|
1970 |
|
GtkWidget *check_button_new_with_label(char *label) { |
1971 |
|
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
1972 |
|
return gtk_check_button_new_with_label(label); |
1973 |
|
#else |
1974 |
|
GtkWidget *cbut = |
1975 |
|
hildon_check_button_new(HILDON_SIZE_FINGER_HEIGHT | |
1976 |
|
HILDON_SIZE_AUTO_WIDTH); |
1977 |
|
gtk_button_set_label(GTK_BUTTON(cbut), label); |
1978 |
|
return cbut; |
1979 |
|
#endif |
1980 |
|
} |
1981 |
|
|
1982 |
|
void check_button_set_active(GtkWidget *button, gboolean active) { |
1983 |
|
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
1984 |
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), active); |
1985 |
|
#else |
1986 |
|
hildon_check_button_set_active(HILDON_CHECK_BUTTON(button), active); |
1987 |
|
#endif |
1988 |
|
} |
1989 |
|
|
1990 |
|
gboolean check_button_get_active(GtkWidget *button) { |
1991 |
|
#if !defined(USE_MAEMO) || (MAEMO_VERSION_MAJOR < 5) |
1992 |
|
return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)); |
1993 |
|
#else |
1994 |
|
return hildon_check_button_get_active(HILDON_CHECK_BUTTON(button)); |
1995 |
|
#endif |
1996 |
|
} |
1997 |
|
|
1998 |
|
GtkWidget *button_new(void) { |
1999 |
|
GtkWidget *button = gtk_button_new(); |
2000 |
|
#if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR == 5) |
2001 |
|
hildon_gtk_widget_set_theme_size(button, |
2002 |
|
(HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH)); |
2003 |
|
#endif |
2004 |
|
return button; |
2005 |
|
} |
2006 |
|
|
2007 |
|
GtkWidget *button_new_with_label(char *label) { |
2008 |
|
GtkWidget *button = gtk_button_new_with_label(label); |
2009 |
|
#if defined(USE_MAEMO) && (MAEMO_VERSION_MAJOR == 5) |
2010 |
|
hildon_gtk_widget_set_theme_size(button, |
2011 |
|
(HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH)); |
2012 |
|
#endif |
2013 |
|
return button; |
2014 |
|
} |
2015 |
|
|
2016 |
|
static void on_browse(GtkWidget *widget, gpointer data) { |
2017 |
|
GtkWidget *dialog; |
2018 |
|
|
2019 |
|
char **fileptr = g_object_get_data(G_OBJECT(widget), "fileptr"); |
2020 |
|
|
2021 |
|
#ifdef USE_MAEMO |
2022 |
|
dialog = hildon_file_chooser_dialog_new( |
2023 |
|
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(widget))), |
2024 |
|
GTK_FILE_CHOOSER_ACTION_SAVE); |
2025 |
|
#else |
2026 |
|
dialog = gtk_file_chooser_dialog_new( |
2027 |
|
g_object_get_data(G_OBJECT(widget), "sel_title"), |
2028 |
|
GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(widget))), |
2029 |
|
GTK_FILE_CHOOSER_ACTION_SAVE, |
2030 |
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, |
2031 |
|
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, |
2032 |
|
NULL); |
2033 |
|
#endif |
2034 |
|
|
2035 |
|
if(*fileptr) { |
2036 |
|
printf("set filename <%s>\n", *fileptr); |
2037 |
|
|
2038 |
|
if(!g_file_test(*fileptr, G_FILE_TEST_EXISTS)) { |
2039 |
|
char *last_sep = strrchr(*fileptr, '/'); |
2040 |
|
if(last_sep) { |
2041 |
|
*last_sep = 0; // seperate path from file |
2042 |
|
|
2043 |
|
/* the user just created a new document */ |
2044 |
|
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), |
2045 |
|
*fileptr); |
2046 |
|
gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), |
2047 |
|
last_sep+1); |
2048 |
|
|
2049 |
|
/* restore full filename */ |
2050 |
|
*last_sep = '/'; |
2051 |
|
} |
2052 |
|
} else |
2053 |
|
gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog), *fileptr); |
2054 |
|
} |
2055 |
|
|
2056 |
|
if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_FM_OK) { |
2057 |
|
gchar *name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); |
2058 |
|
if(name) { |
2059 |
|
if(*fileptr) g_free(*fileptr); |
2060 |
|
*fileptr = g_strdup(name); |
2061 |
|
|
2062 |
|
#ifndef FREMANTLE |
2063 |
|
GtkWidget *label = g_object_get_data(G_OBJECT(widget), "label"); |
2064 |
|
gtk_label_set_text(GTK_LABEL(label), *fileptr); |
2065 |
|
#else |
2066 |
|
hildon_button_set_value(HILDON_BUTTON(widget), *fileptr); |
2067 |
|
#endif |
2068 |
|
} |
2069 |
|
} |
2070 |
|
|
2071 |
|
gtk_widget_destroy (dialog); |
2072 |
|
} |
2073 |
|
|
2074 |
|
GtkWidget *export_file(char *sel_title, char **filename) { |
2075 |
|
/* non-fremantle and classic gtk use a rather ugly and */ |
2076 |
|
/* complex layout */ |
2077 |
|
#ifndef FREMANTLE |
2078 |
|
GtkWidget *vbox = gtk_vbox_new(FALSE, 0); |
2079 |
|
GtkWidget *hbox = gtk_hbox_new(FALSE, 0); |
2080 |
|
GtkWidget *label = gtk_label_new(_("Export to")); |
2081 |
|
gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE,0); |
2082 |
|
gtk_misc_set_alignment(GTK_MISC(label), 0.f, 0.5f); |
2083 |
|
GtkWidget *button = button_new_with_label(_("Browse")); |
2084 |
|
g_object_set_data(G_OBJECT(button), "sel_title", sel_title); |
2085 |
|
g_object_set_data(G_OBJECT(button), "fileptr", filename); |
2086 |
|
gtk_signal_connect(GTK_OBJECT(button), "clicked", |
2087 |
|
GTK_SIGNAL_FUNC(on_browse), NULL); |
2088 |
|
gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE,0); |
2089 |
|
gtk_box_pack_start_defaults(GTK_BOX(vbox), hbox); |
2090 |
|
|
2091 |
|
label = gtk_label_new((*filename)?*filename:""); |
2092 |
|
g_object_set_data(G_OBJECT(button), "label", label); |
2093 |
|
gtk_misc_set_alignment(GTK_MISC(label), 0.f, 0.5f); |
2094 |
|
gtk_label_set_ellipsize(GTK_LABEL(label), PANGO_ELLIPSIZE_MIDDLE); |
2095 |
|
|
2096 |
|
gtk_box_pack_start_defaults(GTK_BOX(vbox), label); |
2097 |
|
return vbox; |
2098 |
|
#else |
2099 |
|
GtkWidget *button = hildon_button_new_with_text( |
2100 |
|
(HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH), |
2101 |
|
HILDON_BUTTON_ARRANGEMENT_VERTICAL, |
2102 |
|
_("Export to"), *filename); |
2103 |
|
hildon_button_set_title_alignment(HILDON_BUTTON(button), 0.5, 0.5); |
2104 |
|
hildon_button_set_value_alignment(HILDON_BUTTON(button), 0.5, 0.5); |
2105 |
|
g_object_set_data(G_OBJECT(button), "sel_title", sel_title); |
2106 |
|
g_object_set_data(G_OBJECT(button), "fileptr", filename); |
2107 |
|
gtk_signal_connect(GTK_OBJECT(button), "clicked", |
2108 |
|
GTK_SIGNAL_FUNC(on_browse), NULL); |
2109 |
|
return button; |
2110 |
|
#endif |
2111 |
|
} |
2112 |
|
|
2113 |
|
|