Parent Directory | Revision Log
OSD nav begun
1 | /* |
2 | * Copyright (C) 2008 Till Harbaum <till@harbaum.org>. |
3 | * |
4 | * This file is part of GPXView. |
5 | * |
6 | * GPXView is free software: you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation, either version 3 of the License, or |
9 | * (at your option) any later version. |
10 | * |
11 | * GPXView is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU General Public License |
17 | * along with GPXView. If not, see <http://www.gnu.org/licenses/>. |
18 | */ |
19 | |
20 | #include <libosso.h> |
21 | |
22 | #ifdef ENABLE_BROWSER_INTERFACE |
23 | #include <tablet-browser-interface.h> |
24 | #endif |
25 | |
26 | #include "gpxview.h" |
27 | #include "dbus.h" |
28 | |
29 | #ifdef ENABLE_MAEMO_MAPPER |
30 | #define MM_DBUS_SERVICE "com.gnuite.maemo_mapper" |
31 | #define MM_DBUS_PATH "/com/gnuite/maemo_mapper" |
32 | #define MM_DBUS_INTERFACE "com.gnuite.maemo_mapper" |
33 | #endif |
34 | |
35 | #include <glib.h> |
36 | #include <dbus/dbus-glib-lowlevel.h> |
37 | #include <dbus/dbus-glib.h> |
38 | |
39 | #ifdef ENABLE_MAEMO_MAPPER |
40 | |
41 | static DBusHandlerResult signal_filter |
42 | (DBusConnection *connection, DBusMessage *message, void *user_data); |
43 | |
44 | static DBusHandlerResult |
45 | signal_filter (DBusConnection *connection, DBusMessage *message, void *user_data) { |
46 | /* User data is the event loop we are running in */ |
47 | appdata_t *appdata = (appdata_t*)user_data; |
48 | |
49 | if(dbus_message_is_signal(message, MM_DBUS_SERVICE, |
50 | "view_position_changed")) { |
51 | DBusError error; |
52 | double lat, lon; |
53 | dbus_error_init (&error); |
54 | |
55 | printf("Received \"view position changed\"\n"); |
56 | |
57 | if(dbus_message_get_args |
58 | (message, &error, DBUS_TYPE_DOUBLE, &lat, |
59 | DBUS_TYPE_DOUBLE, &lon, DBUS_TYPE_INVALID)) { |
60 | |
61 | g_print(" Position received: %f/%f\n", (float)lat, (float)lon); |
62 | |
63 | /* store position for further processing */ |
64 | appdata->mmpos.lat = lat; |
65 | appdata->mmpos.lon = lon; |
66 | appdata->mmpos_valid = TRUE; |
67 | |
68 | } else { |
69 | g_print(" Error getting message: %s\n", error.message); |
70 | dbus_error_free (&error); |
71 | } |
72 | return DBUS_HANDLER_RESULT_HANDLED; |
73 | } |
74 | |
75 | return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
76 | } |
77 | |
78 | void dbus_register(appdata_t *appdata) { |
79 | DBusConnection *bus; |
80 | DBusError error; |
81 | |
82 | dbus_error_init (&error); |
83 | bus = dbus_bus_get (DBUS_BUS_SESSION, &error); |
84 | if (!bus) { |
85 | g_warning ("Failed to connect to the D-BUS daemon: %s", error.message); |
86 | dbus_error_free (&error); |
87 | return; |
88 | } |
89 | dbus_connection_setup_with_g_main(bus, NULL); |
90 | |
91 | /* listening to messages from all objects as no path is specified */ |
92 | dbus_bus_add_match (bus, "type='signal',interface='"MM_DBUS_INTERFACE"'", |
93 | &error); |
94 | dbus_connection_add_filter(bus, signal_filter, appdata, NULL); |
95 | } |
96 | |
97 | /* if pos==NULL only the screen is refreshed, useful if e.g. */ |
98 | /* the poi database changed */ |
99 | int dbus_mm_set_position(appdata_t *appdata, pos_t *pos) { |
100 | osso_rpc_t retval; |
101 | osso_return_t ret; |
102 | |
103 | if(pos) |
104 | ret = osso_rpc_run(appdata->osso_context, |
105 | MM_DBUS_SERVICE, |
106 | MM_DBUS_PATH, |
107 | MM_DBUS_INTERFACE, |
108 | "set_view_center", |
109 | &retval, |
110 | DBUS_TYPE_DOUBLE, (double)pos->lat, |
111 | DBUS_TYPE_DOUBLE, (double)pos->lon, |
112 | DBUS_TYPE_INVALID); |
113 | else |
114 | ret = osso_rpc_run(appdata->osso_context, |
115 | MM_DBUS_SERVICE, |
116 | MM_DBUS_PATH, |
117 | MM_DBUS_INTERFACE, |
118 | "set_view_center", |
119 | &retval, |
120 | DBUS_TYPE_INVALID); |
121 | |
122 | osso_rpc_free_val(&retval); |
123 | |
124 | if(ret != OSSO_OK) |
125 | errorf(_("Unable to communicate with Maemo-Mapper. " |
126 | "You need to have Maemo-Mapper installed " |
127 | "to use this feature.")); |
128 | |
129 | return(ret == OSSO_OK)?0:1; |
130 | } |
131 | #endif |
132 | |
133 | #ifdef ENABLE_BROWSER_INTERFACE |
134 | int browser_url(appdata_t *appdata, char *url) { |
135 | osso_return_t ret; |
136 | |
137 | #if 1 |
138 | ret = osso_rpc_run_with_defaults(appdata->osso_context, "osso_browser", |
139 | OSSO_BROWSER_OPEN_NEW_WINDOW_REQ, NULL, |
140 | DBUS_TYPE_STRING, url, |
141 | DBUS_TYPE_BOOLEAN, FALSE, DBUS_TYPE_INVALID); |
142 | #else |
143 | osso_rpc_t retval; |
144 | ret = osso_rpc_run(appdata->osso_context, |
145 | OSSO_BROWSER_SERVICE, |
146 | OSSO_BROWSER_REQ_PATH, |
147 | OSSO_BROWSER_REQ_INTERFACE, |
148 | OSSO_BROWSER_OPEN_NEW_WINDOW_REQ, |
149 | &retval, |
150 | DBUS_TYPE_STRING, url, |
151 | DBUS_TYPE_BOOLEAN, FALSE, |
152 | DBUS_TYPE_INVALID); |
153 | |
154 | osso_rpc_free_val(&retval); |
155 | #endif |
156 | |
157 | if(ret != OSSO_OK) |
158 | errorf(_("Unable to display URL in browser!")); |
159 | |
160 | return(ret == OSSO_OK)?0:1; |
161 | } |
162 | #endif |