[gnome-bluetooth] Make BluetoothInput a singleton



commit c96dfa6813be347f37cf53479c9d32ab011af47a
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Feb 17 15:17:29 2010 +0000

    Make BluetoothInput a singleton

 wizard/bluetooth-input.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)
---
diff --git a/wizard/bluetooth-input.c b/wizard/bluetooth-input.c
index 776e595..449c9d8 100644
--- a/wizard/bluetooth-input.c
+++ b/wizard/bluetooth-input.c
@@ -256,14 +256,24 @@ static void bluetooth_input_init(BluetoothInput *input)
 /**
  * bluetooth_input_new:
  *
- * Return value: a reference to the #BluetoothInput singleton. Unref the object when done.
+ * Return value: a reference to the #BluetoothInput singleton or %NULL when XInput is not supported. Unref the object when done.
  **/
 BluetoothInput *bluetooth_input_new(void)
 {
+	static BluetoothInput *bluetooth_input = NULL;
+
+	if (bluetooth_input != NULL)
+		return g_object_ref (bluetooth_input);
+
 	if (supports_xinput_devices () == FALSE) {
 		g_warning ("XInput not supported, input device helper disabled");
 		return NULL;
 	}
-	return BLUETOOTH_INPUT (g_object_new (BLUETOOTH_TYPE_INPUT, NULL));
+
+	bluetooth_input = BLUETOOTH_INPUT (g_object_new (BLUETOOTH_TYPE_INPUT, NULL));
+	g_object_add_weak_pointer (G_OBJECT (bluetooth_input),
+				   (gpointer) &bluetooth_input);
+
+	return bluetooth_input;
 }
 



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