]> err.no Git - mapper/blob - src/gps-browse.c
Map widget:
[mapper] / src / gps-browse.c
1 /*
2  * This file is part of mapper
3  *
4  * Copyright (C) 2007 Kaj-Michael Lang
5  * Copyright (C) 2006-2007 John Costigan.
6  *
7  * POI and GPS-Info code originally written by Cezary Jackiewicz.
8  *
9  * Default map data provided by http://www.openstreetmap.org/
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License along
22  * with this program; if not, write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  */
25
26 #include <config.h>
27 #include <unistd.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <strings.h>
31 #include <stddef.h>
32 #include <errno.h>
33 #include <sys/wait.h>
34 #include <glib/gstdio.h>
35 #include <gtk/gtk.h>
36 #include <fcntl.h>
37 #include <gconf/gconf-client.h>
38
39 #include <libintl.h>
40 #include <locale.h>
41
42 #include <sqlite3.h>
43
44 #ifdef WITH_HILDON_DBUS_BT
45 #include <bt-dbus.h>
46 #endif
47
48 #include "utils.h"
49 #include "mapper-types.h"
50 #include "dialogs.h"
51 #include "bluetooth-scan.h"
52
53 /**
54  * Scan for all bluetooth devices.  This method can take a few seconds,
55  * during which the UI will freeze.
56  */
57 gboolean scan_bluetooth(GtkWidget * widget, ScanInfo * scan_info)
58 {
59         GError *error = NULL;
60         GtkWidget *dialog;
61         GtkWidget *lst_devices;
62         GtkTreeViewColumn *column;
63         GtkCellRenderer *renderer;
64         printf("%s()\n", __PRETTY_FUNCTION__);
65
66         dialog = gtk_dialog_new_with_buttons(_("Select Bluetooth Device"),
67                                              GTK_WINDOW(scan_info->
68                                                         settings_dialog),
69                                              GTK_DIALOG_MODAL, GTK_STOCK_OK,
70                                              GTK_RESPONSE_ACCEPT,
71                                              GTK_STOCK_CANCEL,
72                                              GTK_RESPONSE_REJECT, NULL);
73
74         scan_info->scan_dialog = dialog;
75
76         scan_info->store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
77
78         gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 300);
79
80         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),
81                            lst_devices =
82                            gtk_tree_view_new_with_model(GTK_TREE_MODEL
83                                                         (scan_info->store)),
84                            TRUE, TRUE, 0);
85
86         g_object_unref(G_OBJECT(scan_info->store));
87
88         gtk_tree_selection_set_mode(gtk_tree_view_get_selection
89                                     (GTK_TREE_VIEW(lst_devices)),
90                                     GTK_SELECTION_SINGLE);
91         gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(lst_devices), TRUE);
92
93         renderer = gtk_cell_renderer_text_new();
94         column = gtk_tree_view_column_new_with_attributes(_("MAC"), renderer, "text",
95                                                      0, NULL);
96         gtk_tree_view_append_column(GTK_TREE_VIEW(lst_devices), column);
97
98         renderer = gtk_cell_renderer_text_new();
99         column = gtk_tree_view_column_new_with_attributes(_("Description"), renderer,
100                                                      "text", 1, NULL);
101         gtk_tree_view_append_column(GTK_TREE_VIEW(lst_devices), column);
102
103         gtk_widget_show_all(dialog);
104
105         scan_info->banner = hildon_banner_show_animation(dialog, NULL,
106                                                          _("Scanning for Bluetooth Devices"));
107
108         if (scan_start_search(scan_info)) {
109                 gtk_widget_destroy(scan_info->banner);
110                 popup_error(scan_info->settings_dialog,
111                             _("An error occurred while attempting to scan for "
112                               "bluetooth devices."));
113         } else
114                 while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
115                         GtkTreeIter iter;
116                         if (gtk_tree_selection_get_selected
117                             (gtk_tree_view_get_selection
118                              (GTK_TREE_VIEW(lst_devices)), NULL, &iter)) {
119                                 gchar *mac;
120                                 gtk_tree_model_get(GTK_TREE_MODEL
121                                                    (scan_info->store), &iter, 0,
122                                                    &mac, -1);
123                                 gtk_entry_set_text(GTK_ENTRY
124                                                    (scan_info->txt_rcvr_mac),
125                                                    mac);
126                                 break;
127                         } else
128                                 popup_error(dialog, _("Please select a bluetooth device from the list."));
129                 }
130
131         gtk_widget_destroy(dialog);
132
133 #ifdef WITH_HILDON_DBUS_BT
134         /* Clean up D-Bus. */
135         dbus_g_proxy_call(scan_info->req_proxy, BTSEARCH_STOP_SEARCH_REQ, &error, G_TYPE_INVALID, G_TYPE_INVALID);
136         g_object_unref(scan_info->req_proxy);
137         g_object_unref(scan_info->sig_proxy);
138 #endif
139
140         vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__);
141         return TRUE;
142 }