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)
39 #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>
47 #include <libxml/parser.h>
51 #include <osso-helplib.h>
52 #include <osso-ic-dbus.h>
55 #include <hildon-widgets/hildon-program.h>
56 #include <hildon-widgets/hildon-controlbar.h>
57 #include <hildon-widgets/hildon-note.h>
58 #include <hildon-widgets/hildon-color-button.h>
59 #include <hildon-widgets/hildon-file-chooser-dialog.h>
60 #include <hildon-widgets/hildon-number-editor.h>
61 #include <hildon-widgets/hildon-banner.h>
62 #include <hildon-widgets/hildon-system-sound.h>
63 #include <hildon-widgets/hildon-input-mode-hint.h>
64 #include <device_symbols.h>
78 #include "mapper-types.h"
80 #include "ui-common.h"
85 gfloat UNITS_CONVERT[] = {
91 GdkColor COLORABLE_DEFAULT[COLORABLE_ENUM_COUNT] = {
92 {0, 0x0000, 0x0000, 0xc000}
93 , /* COLORABLE_MARK */
94 {0, 0x6000, 0x6000, 0xf800}
95 , /* COLORABLE_MARK_VELOCITY */
96 {0, 0x8000, 0x8000, 0x8000}
97 , /* COLORABLE_MARK_OLD */
98 {0, 0xe000, 0x0000, 0x0000}
99 , /* COLORABLE_TRACK */
100 {0, 0xa000, 0x0000, 0x0000}
101 , /* COLORABLE_TRACK_MARK */
102 {0, 0x7000, 0x0000, 0x0000}
103 , /* COLORABLE_TRACK_BREAK */
104 {0, 0x0000, 0xa000, 0x0000}
105 , /* COLORABLE_ROUTE */
106 {0, 0x0000, 0x8000, 0x0000}
107 , /* COLORABLE_ROUTE_WAY */
108 {0, 0x0000, 0x6000, 0x0000}
109 , /* COLORABLE_ROUTE_BREAK */
110 {0, 0xa000, 0x0000, 0xa000} /* COLORABLE_POI */
114 * Set the connection state. This function controls all connection-related
117 void set_conn_state(ConnState new_conn_state)
119 printf("%s(%d)\n", __PRETTY_FUNCTION__, new_conn_state);
121 switch (_conn_state = new_conn_state) {
124 if (_connect_banner) {
125 gtk_widget_destroy(_connect_banner);
126 _connect_banner = NULL;
129 gtk_widget_destroy(_fix_banner);
135 gtk_widget_destroy(_fix_banner);
138 if (!_connect_banner)
140 hildon_banner_show_animation(_window, NULL,
142 ("Searching for GPS receiver"));
145 if (_connect_banner) {
146 gtk_widget_destroy(_connect_banner);
147 _connect_banner = NULL;
151 hildon_banner_show_progress(_window, NULL,
153 ("Establishing GPS fix"));
155 default:; /* to quell warning. */
158 vprintf("%s(): return\n", __PRETTY_FUNCTION__);
162 * Save state and destroy all non-UI elements created by this program in
163 * preparation for exiting.
165 void maemo_mapper_destroy(void)
167 printf("%s()\n", __PRETTY_FUNCTION__);
170 g_source_remove(_curl_sid);
175 /* _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 main(gint argc, gchar * argv[])
238 printf("%s()\n", __PRETTY_FUNCTION__);
240 /* Initialize localization. */
241 setlocale(LC_ALL, "");
242 bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
243 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
244 textdomain(GETTEXT_PACKAGE);
249 /* Initialize _osso. */
250 _osso = osso_initialize("com.gnuite.maemo_mapper", VERSION, TRUE, NULL);
252 g_printerr("osso_initialize failed.\n");
259 gtk_init(&argc, &argv);
263 gconf_init(argc, argv, NULL);
265 /* Init Gnome-VFS. */
269 curl_global_init(CURL_GLOBAL_NOTHING);
271 maemo_mapper_init(argc, argv);
274 if (OSSO_OK != osso_rpc_set_default_cb_f(_osso, dbus_cb_default, NULL)) {
275 g_printerr("osso_rpc_set_default_cb_f failed.\n");
282 maemo_mapper_destroy();
285 osso_deinitialize(_osso);
288 vprintf("%s(): return\n", __PRETTY_FUNCTION__);