2 * Copyright (C) 2006, 2007 John Costigan.
4 * POI and GPS-Info code originally written by Cezary Jackiewicz.
6 * Default map data provided by http://www.openstreetmap.org/
8 * This file is part of Maemo Mapper.
10 * Maemo Mapper is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * Maemo Mapper is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Maemo Mapper. If not, see <http://www.gnu.org/licenses/>.
31 #include "dbus/dbus.h"
33 #define DBUS_API_SUBJECT_TO_CHANGE
42 static DBusConnection *_bus = NULL;
44 /***********************
45 * BELOW: DBUS METHODS *
46 ***********************/
49 dbus_ifc_cb_default(const gchar *interface, const gchar *method,
50 GArray *args, gpointer data, osso_rpc_t *retval)
52 printf("%s()\n", __PRETTY_FUNCTION__);
54 if(!strcmp(method, "top_application"))
56 g_idle_add((GSourceFunc)window_present, NULL);
59 retval->type = DBUS_TYPE_INVALID;
61 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
66 dbus_ifc_set_view_position_idle(SetViewPositionArgs *args)
69 printf("%s(%f, %f, %d, %f)\n", __PRETTY_FUNCTION__, args->new_lat,
70 args->new_lon, args->new_zoom, args->new_viewing_angle);
75 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(
76 _menu_view_ac_none_item), TRUE);
78 latlon2unit(args->new_lat, args->new_lon, center.unitx, center.unity);
80 map_center_unit_full(center, args->new_zoom, args->new_viewing_angle);
85 vprintf("%s(): return FALSE\n", __PRETTY_FUNCTION__);
90 dbus_ifc_handle_set_view_center(GArray *args, osso_rpc_t *retval)
92 printf("%s()\n", __PRETTY_FUNCTION__);
93 SetViewPositionArgs *svca = g_new(SetViewPositionArgs, 1);
95 /* Argument 3: int: zoom. Get this first because we might need it to
96 * calculate the next latitude and/or longitude. */
98 && g_array_index(args, osso_rpc_t, 2).type == DBUS_TYPE_INT32)
100 svca->new_zoom = CLAMP(g_array_index(args, osso_rpc_t, 2).value.i,
104 svca->new_zoom = _next_zoom;
108 /* Latitude and/or Longitude are not defined. Calculate next. */
109 Point new_center = map_calc_new_center(svca->new_zoom);
110 unit2latlon(new_center.unitx, new_center.unity,
111 svca->new_lat, svca->new_lon);
114 /* Argument 1: double: latitude. */
116 && g_array_index(args, osso_rpc_t, 0).type == DBUS_TYPE_DOUBLE)
118 svca->new_lat = CLAMP(g_array_index(args, osso_rpc_t, 0).value.d,
122 /* Argument 2: double: longitude. */
124 && g_array_index(args, osso_rpc_t, 1).type == DBUS_TYPE_DOUBLE)
126 svca->new_lon = CLAMP(g_array_index(args, osso_rpc_t, 1).value.d,
130 /* Argument 4: double: viewing angle. */
132 && g_array_index(args, osso_rpc_t, 3).type == DBUS_TYPE_DOUBLE)
134 svca->new_viewing_angle
135 = (gint)(g_array_index(args, osso_rpc_t, 2).value.d + 0.5) % 360;
138 svca->new_viewing_angle = _center_mode > 0 && _center_rotate
139 ? _gps.heading : _next_map_rotate_angle;
141 g_idle_add((GSourceFunc)dbus_ifc_set_view_position_idle, svca);
142 retval->type = DBUS_TYPE_INVALID;
144 vprintf("%s(): return OSSO_OK\n", __PRETTY_FUNCTION__);
149 dbus_ifc_controller(const gchar *interface, const gchar *method,
150 GArray *args, gpointer data, osso_rpc_t *retval)
152 printf("%s(%s)\n", __PRETTY_FUNCTION__, method);
154 /* Method: set_view_center */
155 if(!strcmp(method, MM_DBUS_METHOD_SET_VIEW_POSITION))
156 return dbus_ifc_handle_set_view_center(args, retval);
158 vprintf("%s(): return OSSO_ERROR\n", __PRETTY_FUNCTION__);
162 /***********************
163 * ABOVE: DBUS METHODS *
164 ***********************/
167 /***********************
168 * BELOW: DBUS SIGNALS *
169 ***********************/
172 dbus_ifc_fire_view_position_changed(
173 Point new_center, gint new_zoom, gdouble new_viewing_angle)
175 DBusMessage *message = NULL;
176 gdouble new_lat, new_lon;
177 printf("%s(%d, %d, %d, %f)\n", __PRETTY_FUNCTION__, new_center.unitx,
178 new_center.unity, new_zoom, new_viewing_angle);
180 unit2latlon(new_center.unitx, new_center.unity, new_lat, new_lon);
182 if(NULL == (message = dbus_message_new_signal(MM_DBUS_PATH,
183 MM_DBUS_INTERFACE, MM_DBUS_SIGNAL_VIEW_POSITION_CHANGED))
184 || !dbus_message_append_args(message,
185 DBUS_TYPE_DOUBLE, &new_lat,
186 DBUS_TYPE_DOUBLE, &new_lon,
187 DBUS_TYPE_INT32, &new_zoom,
188 DBUS_TYPE_DOUBLE, &new_viewing_angle,
190 || !dbus_connection_send(_bus, message, NULL))
192 g_printerr("Error sending view_position_changed signal.\n");
196 dbus_message_unref(message);
198 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
202 dbus_ifc_fire_view_dimensions_changed(
203 gint new_view_width_pixels, gint new_view_height_pixels)
205 DBusMessage *message = NULL;
206 printf("%s(%d, %d)\n", __PRETTY_FUNCTION__,
207 new_view_width_pixels, new_view_height_pixels);
209 if(NULL == (message = dbus_message_new_signal(MM_DBUS_PATH,
210 MM_DBUS_INTERFACE, MM_DBUS_SIGNAL_VIEW_DIMENSIONS_CHANGED))
211 || !dbus_message_append_args(message,
212 DBUS_TYPE_INT32, &new_view_width_pixels,
213 DBUS_TYPE_INT32, &new_view_height_pixels,
215 || !dbus_connection_send(_bus, message, NULL))
217 g_printerr("Error sending view_dimensions_changed signal.\n");
221 dbus_message_unref(message);
223 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
226 /***********************
227 * ABOVE: DBUS SIGNALS *
228 ***********************/
234 printf("%s()\n", __PRETTY_FUNCTION__);
236 if(OSSO_OK != osso_rpc_set_default_cb_f(_osso, dbus_ifc_cb_default, NULL))
237 g_printerr("osso_rpc_set_default_cb_f failed.\n");
239 if(OSSO_OK != osso_rpc_set_cb_f(_osso, MM_DBUS_SERVICE,
240 MM_DBUS_PATH, MM_DBUS_INTERFACE, dbus_ifc_controller, NULL))
241 g_printerr("osso_rpc_set_cb_f failed.\n");
243 dbus_error_init(&error);
244 if(NULL == (_bus = dbus_bus_get(DBUS_BUS_SESSION, &error)))
246 g_printerr("Error getting session bus: %s: %s\n",
247 (dbus_error_is_set(&error)
248 ? error.name : "<no error message>"),
249 (dbus_error_is_set(&error)
250 ? error.message : ""));
253 vprintf("%s(): return\n", __PRETTY_FUNCTION__);