[gnome-bluetooth] Add a private method to the chooser to remove the selected device



commit 20c573a41da896a3f27e822b5b08da10624dae17
Author: Joshua Lock <josh linux intel com>
Date:   Wed Sep 30 12:27:32 2009 +0100

    Add a private method to the chooser to remove the selected device
    
    Make the code for removing the a device shared by adding a private method
    to the BluetoothChooser.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=596845

 lib/bluetooth-chooser-private.h |    1 +
 lib/bluetooth-chooser.c         |   71 +++++++++++++++++++++++++++++++++++++++
 lib/gnome-bluetooth.symbols     |    1 +
 properties/adapter.c            |   64 +++-------------------------------
 4 files changed, 79 insertions(+), 58 deletions(-)
---
diff --git a/lib/bluetooth-chooser-private.h b/lib/bluetooth-chooser-private.h
index ee619aa..7a551cf 100644
--- a/lib/bluetooth-chooser-private.h
+++ b/lib/bluetooth-chooser-private.h
@@ -11,6 +11,7 @@ G_BEGIN_DECLS
 GtkTreeModel *bluetooth_chooser_get_model (BluetoothChooser *self);
 GtkTreeViewColumn *bluetooth_chooser_get_device_column (BluetoothChooser *self);
 GtkWidget *bluetooth_chooser_get_treeview (BluetoothChooser *self);
+gboolean bluetooth_chooser_remove_selected_device (BluetoothChooser *self);
 
 G_END_DECLS
 
diff --git a/lib/bluetooth-chooser.c b/lib/bluetooth-chooser.c
index 18af233..c61e5b0 100644
--- a/lib/bluetooth-chooser.c
+++ b/lib/bluetooth-chooser.c
@@ -340,6 +340,77 @@ bluetooth_chooser_get_selected_device_info (BluetoothChooser *self,
 	return TRUE;
 }
 
+static gboolean
+show_confirm_dialog(const char *name)
+{
+	GtkWidget *dialog;
+	gint response;
+
+	dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
+					 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
+					 _("Remove '%s' from the list of devices?"), name);
+	g_object_set (G_OBJECT (dialog), "secondary-text",
+		      _("If you remove the device, you will have to set it up again before next use."),
+		      NULL);
+
+	gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+	gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_REMOVE, GTK_RESPONSE_ACCEPT);
+
+	response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+	gtk_widget_destroy (dialog);
+
+	if (response == GTK_RESPONSE_ACCEPT)
+		return TRUE;
+
+	return FALSE;
+}
+
+/**
+ * bluetooth_chooser_remove_selected_device:
+ * @self: A #BluetoothChooser widget.
+ *
+ * Return value: %TRUE if the selected device was correctly removed.
+ **/
+gboolean
+bluetooth_chooser_remove_selected_device (BluetoothChooser *self)
+{
+	BluetoothChooserPrivate *priv = BLUETOOTH_CHOOSER_GET_PRIVATE(self);
+	GtkTreeIter iter;
+	gboolean ret = FALSE;
+	GError *err = NULL;
+	gchar *name;
+	DBusGProxy *device, *adapter;
+
+	if (gtk_tree_selection_get_selected (priv->selection, NULL, &iter) == FALSE)
+		return FALSE;
+
+	gtk_tree_model_get (priv->filter, &iter,
+			    BLUETOOTH_COLUMN_PROXY, &device,
+			    BLUETOOTH_COLUMN_ALIAS, &name, -1);
+
+	adapter = bluetooth_client_get_default_adapter(priv->client);
+
+	if (show_confirm_dialog (name) != FALSE) {
+		const gchar *device_path;
+
+		device_path = dbus_g_proxy_get_path (device);
+
+		if (dbus_g_proxy_call (adapter, "RemoveDevice", &err,
+				       DBUS_TYPE_G_OBJECT_PATH, device_path,
+				       G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
+			g_warning ("Failed to remove device %s: %s", name,
+				   err->message);
+			g_error_free (err);
+		} else {
+			ret = TRUE;
+		}
+		g_object_unref (adapter);
+	}
+
+	return ret;
+}
+
 /**
  * bluetooth_chooser_get_model:
  * @self: A BluetoothChooser widget.
diff --git a/lib/gnome-bluetooth.symbols b/lib/gnome-bluetooth.symbols
index 6f4fdbb..ccc97bf 100644
--- a/lib/gnome-bluetooth.symbols
+++ b/lib/gnome-bluetooth.symbols
@@ -11,6 +11,7 @@ bluetooth_chooser_get_model
 bluetooth_chooser_get_device_column
 bluetooth_chooser_start_discovery
 bluetooth_chooser_stop_discovery
+bluetooth_chooser_remove_selected_device
 bluetooth_chooser_button_get_type
 bluetooth_chooser_button_new
 bluetooth_chooser_button_available
diff --git a/properties/adapter.c b/properties/adapter.c
index 92d5181..d350962 100644
--- a/properties/adapter.c
+++ b/properties/adapter.c
@@ -35,6 +35,7 @@
 #include <bluetooth-client-private.h>
 #include <bluetooth-killswitch.h>
 #include <bluetooth-chooser.h>
+#include <bluetooth-chooser-private.h>
 #include <bluetooth-plugin-manager.h>
 
 #include "adapter.h"
@@ -169,75 +170,22 @@ static void wizard_callback(GtkWidget *button, gpointer user_data)
 		g_printerr("Couldn't execute command: %s\n", command);
 }
 
-static gboolean show_confirm_dialog(const char *name)
-{
-	GtkWidget *dialog;
-	gint response;
-
-	dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
-					 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
-					 _("Remove '%s' from the list of devices?"), name);
-	g_object_set (G_OBJECT (dialog), "secondary-text",
-		      _("If you remove the device, you will have to set it up again before next use."),
-		      NULL);
-
-	gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
-	gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_REMOVE, GTK_RESPONSE_ACCEPT);
-
-	response = gtk_dialog_run (GTK_DIALOG (dialog));
-
-	gtk_widget_destroy (dialog);
-
-	if (response == GTK_RESPONSE_ACCEPT)
-		return TRUE;
-
-	return FALSE;
-}
-
 static void remove_callback(GtkWidget *button, gpointer user_data)
 {
 	adapter_data *adapter = user_data;
-	GValue value = { 0, };
-	DBusGProxy *device;
-	const char *path;
-	char *address, *name;
+	char *address;
 
-	if (bluetooth_chooser_get_selected_device_info (BLUETOOTH_CHOOSER (adapter->chooser),
-							"proxy", &value) == FALSE) {
-		return;
-	}
 	address = bluetooth_chooser_get_selected_device (BLUETOOTH_CHOOSER (adapter->chooser));
-	name = bluetooth_chooser_get_selected_device_name (BLUETOOTH_CHOOSER (adapter->chooser));
-	if (address == NULL || name == NULL) {
-		g_value_unset (&value);
+	if (address == NULL) {
 		g_free (address);
-		g_free (name);
 		return;
 	}
-	device = g_value_dup_object (&value);
-	g_value_unset (&value);
-
-	if (device == NULL)
-		return;
 
-	path = dbus_g_proxy_get_path(device);
-
-	if (show_confirm_dialog (name) == TRUE) {
-		GError *err = NULL;
-		if (dbus_g_proxy_call (adapter->proxy, "RemoveDevice", &err,
-				       DBUS_TYPE_G_OBJECT_PATH, path,
-				       G_TYPE_INVALID, G_TYPE_INVALID) == FALSE) {
-			g_warning ("Failed to remove device %s: %s", address,
-				   err->message);
-			g_error_free (err);
-		} else {
-			bluetooth_plugin_manager_device_deleted (address);
-		}
-	}
+	if (bluetooth_chooser_remove_selected_device (BLUETOOTH_CHOOSER (adapter->chooser)))
+		bluetooth_plugin_manager_device_deleted (address);
+		
 
 	g_free (address);
-	g_free (name);
-	g_object_unref(device);
 }
 
 static void disconnect_callback(GtkWidget *button, gpointer user_data)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]