From: Kaj-Michael Lang Date: Tue, 24 Jul 2007 11:26:48 +0000 (+0300) Subject: Fix duplicate functions. Use common scan_bluetooth in gps-browse.c X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0427b3b82749f17ad337c2d147c80108422b6c8b;p=mapper Fix duplicate functions. Use common scan_bluetooth in gps-browse.c Start idle scanning function in bt-bluez.c --- diff --git a/src/bt-bluez.c b/src/bt-bluez.c index 8097c63..0f7a643 100644 --- a/src/bt-bluez.c +++ b/src/bt-bluez.c @@ -35,9 +35,10 @@ struct sockaddr_rc _rcvr_addr = { 0 }; -gint scan_start_search() +gint scan_start_search(ScanInfo * scan_info) { - return 0; +scan_info->sid = g_idle_add((GSourceFunc) scan_bluetooth_idle, scan_info); +return 0; } /** @@ -265,86 +266,4 @@ gboolean scan_bluetooth_idle(ScanInfo * scan_info) return FALSE; } -/** - * Scan for all bluetooth devices. This method can take a few seconds, - * during which the UI will freeze. - */ -gboolean scan_bluetooth(GtkWidget * widget, ScanInfo * scan_info) -{ - /* Do an hci_inquiry for our boy. */ - GtkWidget *dialog; - GtkWidget *lst_devices; - GtkTreeViewColumn *column; - GtkCellRenderer *renderer; - printf("%s()\n", __PRETTY_FUNCTION__); - - dialog = gtk_dialog_new_with_buttons(_("Select Bluetooth Device"), - GTK_WINDOW(scan_info-> - settings_dialog), - GTK_DIALOG_MODAL, GTK_STOCK_OK, - GTK_RESPONSE_ACCEPT, - GTK_STOCK_CANCEL, - GTK_RESPONSE_REJECT, NULL); - - scan_info->scan_dialog = dialog; - - scan_info->banner = hildon_banner_show_animation(dialog, NULL, - _ - ("Scanning Bluetooth Devices")); - - scan_info->store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING); - - scan_info->sid = - g_idle_add((GSourceFunc) scan_bluetooth_idle, scan_info); - - gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 300); - - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), - lst_devices = - gtk_tree_view_new_with_model(GTK_TREE_MODEL - (scan_info->store)), - TRUE, TRUE, 0); - - g_object_unref(G_OBJECT(scan_info->store)); - - gtk_tree_selection_set_mode(gtk_tree_view_get_selection - (GTK_TREE_VIEW(lst_devices)), - GTK_SELECTION_SINGLE); - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(lst_devices), TRUE); - - renderer = gtk_cell_renderer_text_new(); - column = gtk_tree_view_column_new_with_attributes(_("MAC"), renderer, "text", 0, NULL); - gtk_tree_view_append_column(GTK_TREE_VIEW(lst_devices), column); - - renderer = gtk_cell_renderer_text_new(); - column = gtk_tree_view_column_new_with_attributes(_("Description"), renderer, "text", 1, NULL); - gtk_tree_view_append_column(GTK_TREE_VIEW(lst_devices), column); - - gtk_widget_show_all(dialog); - - while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) { - GtkTreeIter iter; - if (gtk_tree_selection_get_selected - (gtk_tree_view_get_selection(GTK_TREE_VIEW(lst_devices)), - NULL, &iter)) { - gchar *mac; - gtk_tree_model_get(GTK_TREE_MODEL(scan_info->store), - &iter, 0, &mac, -1); - gtk_entry_set_text(GTK_ENTRY(scan_info->txt_rcvr_mac), - mac); - break; - } else - popup_error(dialog, - _ - ("Please select a bluetooth device from the list.")); - } - - if (scan_info->sid) - g_source_remove(scan_info->sid); - gtk_widget_destroy(dialog); - - vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__); - return TRUE; -} - #endif diff --git a/src/gps-browse.c b/src/gps-browse.c index cdf0b93..73e5486 100644 --- a/src/gps-browse.c +++ b/src/gps-browse.c @@ -26,7 +26,7 @@ * Scan for all bluetooth devices. This method can take a few seconds, * during which the UI will freeze. */ -static gboolean scan_bluetooth(GtkWidget * widget, ScanInfo * scan_info) +gboolean scan_bluetooth(GtkWidget * widget, ScanInfo * scan_info) { GError *error = NULL; GtkWidget *dialog; @@ -63,22 +63,19 @@ static gboolean scan_bluetooth(GtkWidget * widget, ScanInfo * scan_info) gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(lst_devices), TRUE); renderer = gtk_cell_renderer_text_new(); - column = - gtk_tree_view_column_new_with_attributes(_("MAC"), renderer, "text", + column = gtk_tree_view_column_new_with_attributes(_("MAC"), renderer, "text", 0, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(lst_devices), column); renderer = gtk_cell_renderer_text_new(); - column = - gtk_tree_view_column_new_with_attributes(_("Description"), renderer, + column = gtk_tree_view_column_new_with_attributes(_("Description"), renderer, "text", 1, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(lst_devices), column); gtk_widget_show_all(dialog); scan_info->banner = hildon_banner_show_animation(dialog, NULL, - _ - ("Scanning for Bluetooth Devices")); + _("Scanning for Bluetooth Devices")); if (scan_start_search(scan_info)) { gtk_widget_destroy(scan_info->banner); @@ -86,8 +83,7 @@ static gboolean scan_bluetooth(GtkWidget * widget, ScanInfo * scan_info) _("An error occurred while attempting to scan for " "bluetooth devices.")); } else - while (GTK_RESPONSE_ACCEPT == - gtk_dialog_run(GTK_DIALOG(dialog))) { + while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) { GtkTreeIter iter; if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection @@ -101,9 +97,7 @@ static gboolean scan_bluetooth(GtkWidget * widget, ScanInfo * scan_info) mac); break; } else - popup_error(dialog, - _ - ("Please select a bluetooth device from the list.")); + popup_error(dialog, _("Please select a bluetooth device from the list.")); } gtk_widget_destroy(dialog);