2 * This file is part of maemo-mapper
4 * Copyright (C) 2006-2007 John Costigan.
6 * POI and GPS-Info code originally written by Cezary Jackiewicz.
8 * Default map data provided by http://www.openstreetmap.org/
10 * This program 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 2 of the License, or
13 * (at your option) any later version.
15 * This program 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 along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #define _(String) gettext(String)
38 #include <glib/gstdio.h>
42 #include <gdk/gdkkeysyms.h>
43 #include <dbus/dbus-glib.h>
44 #include <libgnomevfs/gnome-vfs.h>
45 #include <curl/multi.h>
46 #include <gconf/gconf-client.h>
50 #include <osso-helplib.h>
51 #include <osso-ic-dbus.h>
54 #include <hildon-widgets/hildon-program.h>
55 #include <hildon-widgets/hildon-controlbar.h>
56 #include <hildon-widgets/hildon-note.h>
57 #include <hildon-widgets/hildon-color-button.h>
58 #include <hildon-widgets/hildon-file-chooser-dialog.h>
59 #include <hildon-widgets/hildon-number-editor.h>
60 #include <hildon-widgets/hildon-banner.h>
61 #include <hildon-widgets/hildon-system-sound.h>
62 #include <hildon-widgets/hildon-input-mode-hint.h>
63 #include <device_symbols.h>
64 #include "maemo-osso.h"
73 #include "mapper-types.h"
78 #include "ui-common.h"
82 gfloat UNITS_CONVERT[] = {1.85200,1.15077945,1.f,};
84 GdkColor COLORABLE_DEFAULT[COLORABLE_ENUM_COUNT] = {
85 {0, 0x0000, 0x0000, 0xc000}
86 , /* COLORABLE_MARK */
87 {0, 0x6000, 0x6000, 0xf800}
88 , /* COLORABLE_MARK_VELOCITY */
89 {0, 0x8000, 0x8000, 0x8000}
90 , /* COLORABLE_MARK_OLD */
91 {0, 0xe000, 0x0000, 0x0000}
92 , /* COLORABLE_TRACK */
93 {0, 0xa000, 0x0000, 0x0000}
94 , /* COLORABLE_TRACK_MARK */
95 {0, 0x7000, 0x0000, 0x0000}
96 , /* COLORABLE_TRACK_BREAK */
97 {0, 0x0000, 0xa000, 0x0000}
98 , /* COLORABLE_ROUTE */
99 {0, 0x0000, 0x8000, 0x0000}
100 , /* COLORABLE_ROUTE_WAY */
101 {0, 0x0000, 0x6000, 0x0000}
102 , /* COLORABLE_ROUTE_BREAK */
103 {0, 0xa000, 0x0000, 0xa000} /* COLORABLE_POI */
107 * Set the connection state. This function controls all connection-related
110 void set_conn_state(ConnState new_conn_state)
112 printf("%s(%d)\n", __PRETTY_FUNCTION__, new_conn_state);
114 switch (_conn_state = new_conn_state) {
118 if (_connect_banner) {
119 gtk_widget_destroy(_connect_banner);
120 _connect_banner = NULL;
123 gtk_widget_destroy(_fix_banner);
133 gtk_widget_destroy(_fix_banner);
136 if (!_connect_banner)
137 _connect_banner = hildon_banner_show_animation(_window, NULL,
138 _("Searching for GPS receiver"));
145 if (_connect_banner) {
146 gtk_widget_destroy(_connect_banner);
147 _connect_banner = NULL;
150 _fix_banner = hildon_banner_show_progress(_window, NULL,
151 _("Establishing GPS fix"));
156 default:; /* to quell warning. */
159 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
163 * Save state and destroy all non-UI elements created by this program in
164 * preparation for exiting.
166 void mapper_destroy(void)
168 printf("%s()\n", __PRETTY_FUNCTION__);
171 g_source_remove(_curl_sid);
177 /* _program and widgets have already been destroyed. */
182 MACRO_PATH_FREE(_track);
183 MACRO_PATH_FREE(_route);
189 gint num_transfers, num_msgs;
191 /* First, remove all downloads from _pui_tree. */
192 g_tree_destroy(_pui_tree);
194 /* Finish up all downloads. */
195 while (CURLM_CALL_MULTI_PERFORM
196 == curl_multi_perform(_curl_multi, &num_transfers)
200 /* Close all finished files. */
201 while ((msg = curl_multi_info_read(_curl_multi, &num_msgs))) {
202 if (msg->msg == CURLMSG_DONE) {
203 /* This is a map download. */
204 ProgressUpdateInfo *pui =
205 g_hash_table_lookup(_pui_by_easy,
207 g_queue_push_head(_curl_easy_queue,
209 g_hash_table_remove(_pui_by_easy,
212 curl_multi_remove_handle(_curl_multi,
217 while ((curr = g_queue_pop_tail(_curl_easy_queue)))
218 curl_easy_cleanup(curr);
220 curl_multi_cleanup(_curl_multi);
223 g_queue_free(_curl_easy_queue);
224 g_tree_destroy(_downloading_tree);
225 g_hash_table_destroy(_pui_by_easy);
228 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
231 void set_var_defaults(void)
233 _conn_state = RCVR_OFF;
236 gint mapper_osso_init(void)
239 /* Initialize _osso. */
240 _osso = osso_initialize("org.tal.mapper", VERSION, TRUE, NULL);
242 g_printerr("osso_initialize failed.\n");
249 gint mapper_osso_cb_init(void)
252 if (OSSO_OK != osso_rpc_set_default_cb_f(_osso, dbus_cb_default, NULL)) {
253 g_printerr("osso_rpc_set_default_cb_f failed.\n");
260 void timezone_init(void)
266 localtime_r(&time1, &time2);
267 _gmtoffset = time2.tm_gmtoff;
270 gint main(gint argc, gchar * argv[])
272 printf("%s()\n", __PRETTY_FUNCTION__);
274 /* Initialize localization. */
275 setlocale(LC_ALL, "");
276 bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
277 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
278 textdomain(GETTEXT_PACKAGE);
282 if (mapper_osso_init()!=0)
285 gst_init(&argc, &argv);
286 gtk_init(&argc, &argv);
287 gconf_init(argc, argv, NULL);
289 curl_global_init(CURL_GLOBAL_NOTHING);
292 mapper_init(argc, argv);
293 if (mapper_osso_cb_init()!=0)
298 osso_deinitialize(_osso);
300 vprintf("%s(): return\n", __PRETTY_FUNCTION__);