Contents of /trunk/src/dbus.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (show annotations)
Fri Jun 26 12:24:24 2009 UTC (14 years, 10 months ago) by harbaum
File MIME type: text/plain
File size: 4503 byte(s)
Stackable window control flow fixes
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 #define MM_DBUS_SERVICE "com.gnuite.maemo_mapper"
30 #define MM_DBUS_PATH "/com/gnuite/maemo_mapper"
31 #define MM_DBUS_INTERFACE "com.gnuite.maemo_mapper"
32
33 #include <glib.h>
34 #include <dbus/dbus-glib-lowlevel.h>
35 #include <dbus/dbus-glib.h>
36
37 static DBusHandlerResult signal_filter
38 (DBusConnection *connection, DBusMessage *message, void *user_data);
39
40 static DBusHandlerResult
41 signal_filter (DBusConnection *connection, DBusMessage *message, void *user_data) {
42 /* User data is the event loop we are running in */
43 appdata_t *appdata = (appdata_t*)user_data;
44
45 if(dbus_message_is_signal(message, MM_DBUS_SERVICE,
46 "view_position_changed")) {
47 DBusError error;
48 double lat, lon;
49 dbus_error_init (&error);
50
51 printf("Received \"view position changed\"\n");
52
53 if(dbus_message_get_args
54 (message, &error, DBUS_TYPE_DOUBLE, &lat,
55 DBUS_TYPE_DOUBLE, &lon, DBUS_TYPE_INVALID)) {
56
57 g_print(" Position received: %f/%f\n", (float)lat, (float)lon);
58
59 /* store position for further processing */
60 appdata->mmpos.lat = lat;
61 appdata->mmpos.lon = lon;
62 appdata->mmpos_valid = TRUE;
63
64 } else {
65 g_print(" Error getting message: %s\n", error.message);
66 dbus_error_free (&error);
67 }
68 return DBUS_HANDLER_RESULT_HANDLED;
69 }
70
71 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
72 }
73
74 void dbus_register(appdata_t *appdata) {
75 DBusConnection *bus;
76 DBusError error;
77
78 dbus_error_init (&error);
79 bus = dbus_bus_get (DBUS_BUS_SESSION, &error);
80 if (!bus) {
81 g_warning ("Failed to connect to the D-BUS daemon: %s", error.message);
82 dbus_error_free (&error);
83 return;
84 }
85 dbus_connection_setup_with_g_main(bus, NULL);
86
87 /* listening to messages from all objects as no path is specified */
88 dbus_bus_add_match (bus, "type='signal',interface='"MM_DBUS_INTERFACE"'", &error);
89 dbus_connection_add_filter(bus, signal_filter, appdata, NULL);
90 }
91
92 /* if pos==NULL only the screen is refreshed, useful if e.g. */
93 /* the poi database changed */
94 int dbus_mm_set_position(appdata_t *appdata, pos_t *pos) {
95 osso_rpc_t retval;
96 osso_return_t ret;
97
98 if(pos)
99 ret = osso_rpc_run(appdata->osso_context,
100 MM_DBUS_SERVICE,
101 MM_DBUS_PATH,
102 MM_DBUS_INTERFACE,
103 "set_view_center",
104 &retval,
105 DBUS_TYPE_DOUBLE, (double)pos->lat,
106 DBUS_TYPE_DOUBLE, (double)pos->lon,
107 DBUS_TYPE_INVALID);
108 else
109 ret = osso_rpc_run(appdata->osso_context,
110 MM_DBUS_SERVICE,
111 MM_DBUS_PATH,
112 MM_DBUS_INTERFACE,
113 "set_view_center",
114 &retval,
115 DBUS_TYPE_INVALID);
116
117 osso_rpc_free_val(&retval);
118
119 if(ret != OSSO_OK)
120 errorf(_("Unable to communicate with Maemo-Mapper. "
121 "You need to have Maemo-Mapper installed "
122 "to use this feature."));
123
124 return(ret == OSSO_OK)?0:1;
125 }
126
127 #ifdef ENABLE_BROWSER_INTERFACE
128 int browser_url(appdata_t *appdata, char *url) {
129 osso_return_t ret;
130
131 #if 1
132 ret = osso_rpc_run_with_defaults(appdata->osso_context, "osso_browser",
133 OSSO_BROWSER_OPEN_NEW_WINDOW_REQ, NULL,
134 DBUS_TYPE_STRING, url,
135 DBUS_TYPE_BOOLEAN, FALSE, DBUS_TYPE_INVALID);
136 #else
137 osso_rpc_t retval;
138 ret = osso_rpc_run(appdata->osso_context,
139 OSSO_BROWSER_SERVICE,
140 OSSO_BROWSER_REQ_PATH,
141 OSSO_BROWSER_REQ_INTERFACE,
142 OSSO_BROWSER_OPEN_NEW_WINDOW_REQ,
143 &retval,
144 DBUS_TYPE_STRING, url,
145 DBUS_TYPE_BOOLEAN, FALSE,
146 DBUS_TYPE_INVALID);
147
148 osso_rpc_free_val(&retval);
149 #endif
150
151 if(ret != OSSO_OK)
152 errorf(_("Unable to display URL in browser!"));
153
154 return(ret == OSSO_OK)?0:1;
155 }
156 #endif