Blame lib/bluetooth-chooser.c

Packit Service fc05fa
/*
Packit Service fc05fa
 *
Packit Service fc05fa
 *  BlueZ - Bluetooth protocol stack for Linux
Packit Service fc05fa
 *
Packit Service fc05fa
 *  Copyright (C) 2005-2008  Marcel Holtmann <marcel@holtmann.org>
Packit Service fc05fa
 *  Copyright (C) 2006-2007  Bastien Nocera <hadess@hadess.net>
Packit Service fc05fa
 *
Packit Service fc05fa
 *
Packit Service fc05fa
 *  This library is free software; you can redistribute it and/or
Packit Service fc05fa
 *  modify it under the terms of the GNU Lesser General Public
Packit Service fc05fa
 *  License as published by the Free Software Foundation; either
Packit Service fc05fa
 *  version 2.1 of the License, or (at your option) any later version.
Packit Service fc05fa
 *
Packit Service fc05fa
 *  This library is distributed in the hope that it will be useful,
Packit Service fc05fa
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service fc05fa
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service fc05fa
 *  Lesser General Public License for more details.
Packit Service fc05fa
 *
Packit Service fc05fa
 *  You should have received a copy of the GNU Lesser General Public
Packit Service fc05fa
 *  License along with this library; if not, write to the Free Software
Packit Service fc05fa
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
Packit Service fc05fa
 *
Packit Service fc05fa
 */
Packit Service fc05fa
Packit Service fc05fa
/**
Packit Service fc05fa
 * SECTION:bluetooth-chooser
Packit Service fc05fa
 * @short_description: a Bluetooth chooser widget
Packit Service fc05fa
 * @stability: Stable
Packit Service fc05fa
 * @include: bluetooth-chooser.h
Packit Service fc05fa
 *
Packit Service fc05fa
 * A tree-like widget used to select Bluetooth devices.
Packit Service fc05fa
 **/
Packit Service fc05fa
Packit Service fc05fa
#ifdef HAVE_CONFIG_H
Packit Service fc05fa
#include <config.h>
Packit Service fc05fa
#endif
Packit Service fc05fa
Packit Service fc05fa
#include <gtk/gtk.h>
Packit Service fc05fa
Packit Service fc05fa
#include <glib/gi18n-lib.h>
Packit Service fc05fa
Packit Service fc05fa
#include "bluetooth-client.h"
Packit Service fc05fa
#include "bluetooth-client-private.h"
Packit Service fc05fa
#include "bluetooth-utils.h"
Packit Service fc05fa
#include "bluetooth-chooser.h"
Packit Service fc05fa
#include "bluetooth-chooser-private.h"
Packit Service fc05fa
#include "gnome-bluetooth-enum-types.h"
Packit Service fc05fa
#include "bluetooth-filter-widget.h"
Packit Service fc05fa
Packit Service fc05fa
enum {
Packit Service fc05fa
	SELECTED_DEVICE_CHANGED,
Packit Service fc05fa
	SELECTED_DEVICE_ACTIVATED,
Packit Service fc05fa
	LAST_SIGNAL
Packit Service fc05fa
};
Packit Service fc05fa
Packit Service fc05fa
static guint selection_table_signals[LAST_SIGNAL] = { 0 };
Packit Service fc05fa
Packit Service fc05fa
#define BLUETOOTH_CHOOSER_GET_PRIVATE(obj) \
Packit Service fc05fa
	(bluetooth_chooser_get_instance_private (obj))
Packit Service fc05fa
Packit Service fc05fa
typedef struct _BluetoothChooserPrivate BluetoothChooserPrivate;
Packit Service fc05fa
Packit Service fc05fa
struct _BluetoothChooserPrivate {
Packit Service fc05fa
	BluetoothClient *client;
Packit Service fc05fa
	GtkTreeSelection *selection;
Packit Service fc05fa
	GtkTreeModel *model, *filter, *adapter_model;
Packit Service fc05fa
Packit Service fc05fa
	gulong default_adapter_changed_id;
Packit Service fc05fa
Packit Service fc05fa
	/* Widgets/UI bits that can be shown or hidden */
Packit Service fc05fa
	GtkCellRenderer *bonded_cell;
Packit Service fc05fa
	GtkCellRenderer *connected_cell;
Packit Service fc05fa
	GtkWidget *treeview, *scrolled_window;
Packit Service fc05fa
	GtkWidget *search_hbox, *search_label, *spinner;
Packit Service fc05fa
	GtkWidget *filters_vbox;
Packit Service fc05fa
Packit Service fc05fa
	/* Current filter */
Packit Service fc05fa
	int device_type_filter;
Packit Service fc05fa
	GtkTreeModel *device_type_filter_model;
Packit Service fc05fa
	int device_category_filter;
Packit Service fc05fa
	char *device_service_filter;
Packit Service fc05fa
Packit Service fc05fa
	guint show_paired : 1;
Packit Service fc05fa
	guint show_connected : 1;
Packit Service fc05fa
	guint show_searching : 1;
Packit Service fc05fa
	guint show_device_type : 1;
Packit Service fc05fa
	guint show_device_category : 1;
Packit Service fc05fa
	guint disco_rq : 1;
Packit Service fc05fa
	guint internal_filter : 1;
Packit Service fc05fa
};
Packit Service fc05fa
Packit Service fc05fa
G_DEFINE_TYPE_WITH_PRIVATE(BluetoothChooser, bluetooth_chooser, GTK_TYPE_BOX)
Packit Service fc05fa
Packit Service fc05fa
enum {
Packit Service fc05fa
	DEVICE_TYPE_FILTER_COL_NAME = 0,
Packit Service fc05fa
	DEVICE_TYPE_FILTER_COL_MASK,
Packit Service fc05fa
	DEVICE_TYPE_FILTER_NUM_COLS
Packit Service fc05fa
};
Packit Service fc05fa
Packit Service fc05fa
enum {
Packit Service fc05fa
	TREEVIEW_COLUMN_DEVICE = 0,
Packit Service fc05fa
	TREEVIEW_COLUMN_TYPE = 1
Packit Service fc05fa
};
Packit Service fc05fa
Packit Service fc05fa
static void
Packit Service fc05fa
bonded_to_icon (GtkTreeViewColumn *column, GtkCellRenderer *cell,
Packit Service fc05fa
	      GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
Packit Service fc05fa
{
Packit Service fc05fa
	gboolean bonded;
Packit Service fc05fa
Packit Service fc05fa
	gtk_tree_model_get (model, iter, BLUETOOTH_COLUMN_PAIRED, &bonded, -1);
Packit Service fc05fa
Packit Service fc05fa
	g_object_set (cell, "icon-name", bonded ? "bluetooth-paired" : NULL, NULL);
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
static void
Packit Service fc05fa
connected_to_icon (GtkTreeViewColumn *column, GtkCellRenderer *cell,
Packit Service fc05fa
	      GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
Packit Service fc05fa
{
Packit Service fc05fa
	gboolean connected;
Packit Service fc05fa
Packit Service fc05fa
	gtk_tree_model_get (model, iter, BLUETOOTH_COLUMN_CONNECTED, &connected, -1);
Packit Service fc05fa
Packit Service fc05fa
	g_object_set (cell, "icon-name", connected ? "gtk-connected" : NULL, NULL);
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
static void
Packit Service fc05fa
type_to_text (GtkTreeViewColumn *column, GtkCellRenderer *cell,
Packit Service fc05fa
	      GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
Packit Service fc05fa
{
Packit Service fc05fa
	guint type;
Packit Service fc05fa
Packit Service fc05fa
	gtk_tree_model_get (model, iter, BLUETOOTH_COLUMN_TYPE, &type, -1);
Packit Service fc05fa
Packit Service fc05fa
	g_object_set (cell, "text", (type == 0) ? _("Unknown") : bluetooth_type_to_string (type), NULL);
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
static void
Packit Service fc05fa
alias_to_label (GtkTreeViewColumn *column, GtkCellRenderer *cell,
Packit Service fc05fa
		GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
Packit Service fc05fa
{
Packit Service fc05fa
	char *alias, *escaped, *label;
Packit Service fc05fa
	gboolean connected;
Packit Service fc05fa
Packit Service fc05fa
	gtk_tree_model_get (model, iter,
Packit Service fc05fa
			    BLUETOOTH_COLUMN_ALIAS, &alias,
Packit Service fc05fa
			    BLUETOOTH_COLUMN_CONNECTED, &connected,
Packit Service fc05fa
			    -1);
Packit Service fc05fa
Packit Service fc05fa
	if (connected == FALSE) {
Packit Service fc05fa
		g_object_set (cell, "text", alias, NULL);
Packit Service fc05fa
	} else {
Packit Service fc05fa
		escaped = g_markup_escape_text (alias, -1);
Packit Service fc05fa
		label = g_strdup_printf ("%s", escaped);
Packit Service fc05fa
		g_free (escaped);
Packit Service fc05fa
Packit Service fc05fa
		g_object_set (cell, "markup", label, NULL);
Packit Service fc05fa
		g_free (label);
Packit Service fc05fa
	}
Packit Service fc05fa
	g_free (alias);
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
static void
Packit Service fc05fa
set_search_label (BluetoothChooser *self, gboolean state)
Packit Service fc05fa
{
Packit Service fc05fa
	BluetoothChooserPrivate *priv = BLUETOOTH_CHOOSER_GET_PRIVATE(self);
Packit Service fc05fa
Packit Service fc05fa
	if (priv->show_searching == FALSE) {
Packit Service fc05fa
		/* Just making sure */
Packit Service fc05fa
		gtk_spinner_stop (GTK_SPINNER (priv->spinner));
Packit Service fc05fa
		return;
Packit Service fc05fa
	}
Packit Service fc05fa
	if (state == FALSE) {
Packit Service fc05fa
		gtk_spinner_stop (GTK_SPINNER (priv->spinner));
Packit Service fc05fa
		gtk_widget_hide (priv->spinner);
Packit Service fc05fa
		gtk_label_set_text (GTK_LABEL (priv->search_label), _("No adapters available"));
Packit Service fc05fa
	} else {
Packit Service fc05fa
		gtk_widget_show (priv->spinner);
Packit Service fc05fa
		gtk_spinner_start (GTK_SPINNER (priv->spinner));
Packit Service fc05fa
		gtk_label_set_text (GTK_LABEL (priv->search_label), _("Searching for devices…"));
Packit Service fc05fa
	}
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
/**
Packit Service fc05fa
 * bluetooth_chooser_start_discovery:
Packit Service fc05fa
 * @self: a #BluetoothChooser widget.
Packit Service fc05fa
 *
Packit Service fc05fa
 * Starts a discovery on the default Bluetooth adapter. Note that this will
Packit Service fc05fa
 * only work if the Search label is visible, as otherwise the user has no
Packit Service fc05fa
 * visual feedback that the process is on-going.
Packit Service fc05fa
 *
Packit Service fc05fa
 * See also: #BluetoothChooser:show-searching
Packit Service fc05fa
 **/
Packit Service fc05fa
void
Packit Service fc05fa
bluetooth_chooser_start_discovery (BluetoothChooser *self)
Packit Service fc05fa
{
Packit Service fc05fa
	BluetoothChooserPrivate *priv = BLUETOOTH_CHOOSER_GET_PRIVATE(self);
Packit Service fc05fa
Packit Service fc05fa
	g_return_if_fail (priv->show_searching);
Packit Service fc05fa
Packit Service fc05fa
	g_object_set (G_OBJECT (priv->client), "default-adapter-discovering", TRUE, NULL);
Packit Service fc05fa
	set_search_label (self, TRUE);
Packit Service fc05fa
	priv->disco_rq = TRUE;
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
/**
Packit Service fc05fa
 * bluetooth_chooser_stop_discovery:
Packit Service fc05fa
 * @self: a #BluetoothChooser widget.
Packit Service fc05fa
 *
Packit Service fc05fa
 * Stops a discovery started with #bluetooth_chooser_start_discovery.
Packit Service fc05fa
 **/
Packit Service fc05fa
void
Packit Service fc05fa
bluetooth_chooser_stop_discovery (BluetoothChooser *self)
Packit Service fc05fa
{
Packit Service fc05fa
	BluetoothChooserPrivate *priv = BLUETOOTH_CHOOSER_GET_PRIVATE(self);
Packit Service fc05fa
Packit Service fc05fa
	g_return_if_fail (priv->show_searching);
Packit Service fc05fa
Packit Service fc05fa
	priv->disco_rq = FALSE;
Packit Service fc05fa
	g_object_set (G_OBJECT (priv->client), "default-adapter-discovering", FALSE, NULL);
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
static char *
Packit Service fc05fa
bluetooth_chooser_get_selected_device_data (BluetoothChooser *self, guint column)
Packit Service fc05fa
{
Packit Service fc05fa
	BluetoothChooserPrivate *priv = BLUETOOTH_CHOOSER_GET_PRIVATE(self);
Packit Service fc05fa
	GtkTreeIter iter;
Packit Service fc05fa
	gchar *str;
Packit Service fc05fa
	gboolean selected;
Packit Service fc05fa
Packit Service fc05fa
	selected = gtk_tree_selection_get_selected (priv->selection, NULL, &iter);
Packit Service fc05fa
	if (selected == FALSE)
Packit Service fc05fa
		return NULL;
Packit Service fc05fa
Packit Service fc05fa
	gtk_tree_model_get (priv->filter, &iter, column, &str, -1);
Packit Service fc05fa
	return str;
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
/**
Packit Service fc05fa
 * bluetooth_chooser_get_selected_device:
Packit Service fc05fa
 * @self: a #BluetoothChooser widget.
Packit Service fc05fa
 *
Packit Service fc05fa
 * Returns the Bluetooth address for the currently selected device.
Packit Service fc05fa
 *
Packit Service fc05fa
 * Return value: the Bluetooth address for the currently selected device, or %NULL.
Packit Service fc05fa
 **/
Packit Service fc05fa
gchar *
Packit Service fc05fa
bluetooth_chooser_get_selected_device (BluetoothChooser *self)
Packit Service fc05fa
{
Packit Service fc05fa
	return bluetooth_chooser_get_selected_device_data (self, BLUETOOTH_COLUMN_ADDRESS);
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
/**
Packit Service fc05fa
 * bluetooth_chooser_get_selected_device_name:
Packit Service fc05fa
 * @self: a #BluetoothChooser widget.
Packit Service fc05fa
 *
Packit Service fc05fa
 * Returns the name for the currently selected device.
Packit Service fc05fa
 *
Packit Service fc05fa
 * Return value: the name for the currently selected device, or %NULL.
Packit Service fc05fa
 **/
Packit Service fc05fa
gchar *
Packit Service fc05fa
bluetooth_chooser_get_selected_device_name (BluetoothChooser *self)
Packit Service fc05fa
{
Packit Service fc05fa
	return bluetooth_chooser_get_selected_device_data (self, BLUETOOTH_COLUMN_NAME);
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
/**
Packit Service fc05fa
 * bluetooth_chooser_get_selected_device_icon:
Packit Service fc05fa
 * @self: a #BluetoothChooser widget.
Packit Service fc05fa
 *
Packit Service fc05fa
 * Returns the icon name to use to represent the currently selected device.
Packit Service fc05fa
 *
Packit Service fc05fa
 * Return value: the icon name to use to represent the currently selected device, or %NULL.
Packit Service fc05fa
 **/
Packit Service fc05fa
gchar *
Packit Service fc05fa
bluetooth_chooser_get_selected_device_icon (BluetoothChooser *self)
Packit Service fc05fa
{
Packit Service fc05fa
	return bluetooth_chooser_get_selected_device_data (self, BLUETOOTH_COLUMN_ICON);
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
/**
Packit Service fc05fa
 * bluetooth_chooser_get_selected_device_type:
Packit Service fc05fa
 * @self: a #BluetoothChooser widget.
Packit Service fc05fa
 *
Packit Service fc05fa
 * Returns the #BluetoothType of the device selected.
Packit Service fc05fa
 *
Packit Service fc05fa
 * Return value: the #BluetoothType of the device selected, or '0' if unknown.
Packit Service fc05fa
 **/
Packit Service fc05fa
BluetoothType
Packit Service fc05fa
bluetooth_chooser_get_selected_device_type (BluetoothChooser *self)
Packit Service fc05fa
{
Packit Service fc05fa
	BluetoothChooserPrivate *priv = BLUETOOTH_CHOOSER_GET_PRIVATE(self);
Packit Service fc05fa
	GtkTreeIter iter;
Packit Service fc05fa
	guint type;
Packit Service fc05fa
	gboolean selected;
Packit Service fc05fa
Packit Service fc05fa
	selected = gtk_tree_selection_get_selected (priv->selection, NULL, &iter);
Packit Service fc05fa
	if (selected == FALSE)
Packit Service fc05fa
		return 0;
Packit Service fc05fa
Packit Service fc05fa
	gtk_tree_model_get (priv->filter, &iter, BLUETOOTH_COLUMN_TYPE, &type, -1);
Packit Service fc05fa
	return type;
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
/**
Packit Service fc05fa
 * bluetooth_chooser_get_selected_device_is_connected:
Packit Service fc05fa
 * @self: a #BluetoothChooser widget.
Packit Service fc05fa
 *
Packit Service fc05fa
 * Returns whether the selected device is connected to this computer.
Packit Service fc05fa
 *
Packit Service fc05fa
 * Return value: whether the selected device is connected to this computer,
Packit Service fc05fa
 * will always be %FALSE if no devices are selected.
Packit Service fc05fa
 **/
Packit Service fc05fa
gboolean
Packit Service fc05fa
bluetooth_chooser_get_selected_device_is_connected (BluetoothChooser *self)
Packit Service fc05fa
{
Packit Service fc05fa
	BluetoothChooserPrivate *priv = BLUETOOTH_CHOOSER_GET_PRIVATE(self);
Packit Service fc05fa
	GtkTreeIter iter;
Packit Service fc05fa
	gboolean selected, connected;
Packit Service fc05fa
Packit Service fc05fa
	selected = gtk_tree_selection_get_selected (priv->selection, NULL, &iter);
Packit Service fc05fa
	if (selected == FALSE)
Packit Service fc05fa
		return 0;
Packit Service fc05fa
Packit Service fc05fa
	gtk_tree_model_get (priv->filter, &iter, BLUETOOTH_COLUMN_CONNECTED, &connected, -1);
Packit Service fc05fa
	return connected;
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
/**
Packit Service fc05fa
 * bluetooth_chooser_get_selected_device_info:
Packit Service fc05fa
 * @self: A #BluetoothChooser widget.
Packit Service fc05fa
 * @field: The identifier for the field to get data for.
Packit Service fc05fa
 * @value: An empty #GValue to set.
Packit Service fc05fa
 *
Packit Service fc05fa
 * Returns whether the @value has been set.
Packit Service fc05fa
 *
Packit Service fc05fa
 * Return value: %TRUE if the @value has been set.
Packit Service fc05fa
 **/
Packit Service fc05fa
gboolean
Packit Service fc05fa
bluetooth_chooser_get_selected_device_info (BluetoothChooser *self,
Packit Service fc05fa
					    const char *field,
Packit Service fc05fa
					    GValue *value)
Packit Service fc05fa
{
Packit Service fc05fa
	BluetoothChooserPrivate *priv = BLUETOOTH_CHOOSER_GET_PRIVATE(self);
Packit Service fc05fa
	GEnumClass *eclass;
Packit Service fc05fa
	GEnumValue *ev;
Packit Service fc05fa
	GtkTreeIter iter;
Packit Service fc05fa
Packit Service fc05fa
	g_return_val_if_fail (field != NULL, FALSE);
Packit Service fc05fa
Packit Service fc05fa
	if (gtk_tree_selection_get_selected (priv->selection, NULL, &iter) == FALSE)
Packit Service fc05fa
		return FALSE;
Packit Service fc05fa
Packit Service fc05fa
	eclass = g_type_class_ref (BLUETOOTH_TYPE_COLUMN);
Packit Service fc05fa
	ev = g_enum_get_value_by_nick (eclass, field);
Packit Service fc05fa
	if (ev == NULL) {
Packit Service fc05fa
		g_warning ("Unknown field '%s'", field);
Packit Service fc05fa
		g_type_class_unref (eclass);
Packit Service fc05fa
		return FALSE;
Packit Service fc05fa
	}
Packit Service fc05fa
Packit Service fc05fa
	gtk_tree_model_get_value (priv->filter, &iter, ev->value, value);
Packit Service fc05fa
Packit Service fc05fa
	g_type_class_unref (eclass);
Packit Service fc05fa
Packit Service fc05fa
	return TRUE;
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
/**
Packit Service fc05fa
 * bluetooth_chooser_dump_selected_device:
Packit Service fc05fa
 * @self: A #BluetoothChooser widget.
Packit Service fc05fa
 *
Packit Service fc05fa
 * Prints all the known attributes for the currently selected device
Packit Service fc05fa
 * on the standard output. Useful for debugging.
Packit Service fc05fa
 **/
Packit Service fc05fa
void
Packit Service fc05fa
bluetooth_chooser_dump_selected_device (BluetoothChooser *self)
Packit Service fc05fa
{
Packit Service fc05fa
	BluetoothChooserPrivate *priv = BLUETOOTH_CHOOSER_GET_PRIVATE(self);
Packit Service fc05fa
	GtkTreeIter iter;
Packit Service fc05fa
	GtkTreeModel *model;
Packit Service fc05fa
Packit Service fc05fa
	gtk_tree_selection_get_selected (priv->selection, &model, &iter);
Packit Service fc05fa
Packit Service fc05fa
	bluetooth_client_dump_device (model, &iter);
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
/**
Packit Service fc05fa
 * bluetooth_chooser_get_model:
Packit Service fc05fa
 * @self: A #BluetoothChooser widget.
Packit Service fc05fa
 *
Packit Service fc05fa
 * Returns the #BluetoothChooser's #GtkTreeModel.
Packit Service fc05fa
 *
Packit Service fc05fa
 * Return value: a #GtkTreeModel object.
Packit Service fc05fa
 **/
Packit Service fc05fa
GtkTreeModel *
Packit Service fc05fa
bluetooth_chooser_get_model (BluetoothChooser *self)
Packit Service fc05fa
{
Packit Service fc05fa
	BluetoothChooserPrivate *priv = BLUETOOTH_CHOOSER_GET_PRIVATE(self);
Packit Service fc05fa
Packit Service fc05fa
	return priv->model;
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
/**
Packit Service fc05fa
 * bluetooth_chooser_get_treeview:
Packit Service fc05fa
 * @self: A #BluetoothChooser widget.
Packit Service fc05fa
 *
Packit Service fc05fa
 * Returns the #GtkTreeView object for the #BluetoothChooser.
Packit Service fc05fa
 *
Packit Service fc05fa
 * Return value: a #GtkTreeView object.
Packit Service fc05fa
 **/
Packit Service fc05fa
GtkWidget *
Packit Service fc05fa
bluetooth_chooser_get_treeview (BluetoothChooser *self)
Packit Service fc05fa
{
Packit Service fc05fa
	BluetoothChooserPrivate *priv = BLUETOOTH_CHOOSER_GET_PRIVATE(self);
Packit Service fc05fa
Packit Service fc05fa
	return priv->treeview;
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
/**
Packit Service fc05fa
 * bluetooth_chooser_get_scrolled_window:
Packit Service fc05fa
 * @self: A #BluetoothChooser widget.
Packit Service fc05fa
 *
Packit Service fc05fa
 * Returns the #GtkScrolledWindow object for the #BluetoothChooser.
Packit Service fc05fa
 * This is useful to set a minimum height to the chooser using
Packit Service fc05fa
 * gtk_scrolled_window_set_min_content_height() or to join the
Packit Service fc05fa
 * chooser with a toolbar.
Packit Service fc05fa
 *
Packit Service fc05fa
 * Return value: (transfer none): a #GtkScrolledWindow object.
Packit Service fc05fa
 **/
Packit Service fc05fa
GtkWidget *
Packit Service fc05fa
bluetooth_chooser_get_scrolled_window (BluetoothChooser *self)
Packit Service fc05fa
{
Packit Service fc05fa
	BluetoothChooserPrivate *priv = BLUETOOTH_CHOOSER_GET_PRIVATE(self);
Packit Service fc05fa
Packit Service fc05fa
	return priv->scrolled_window;
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
static void
Packit Service fc05fa
device_model_row_changed (GtkTreeModel *model,
Packit Service fc05fa
			   GtkTreePath  *path,
Packit Service fc05fa
			   GtkTreeIter  *iter,
Packit Service fc05fa
			   gpointer      data)
Packit Service fc05fa
{
Packit Service fc05fa
	BluetoothChooser *self = BLUETOOTH_CHOOSER (data);
Packit Service fc05fa
	BluetoothChooserPrivate *priv = BLUETOOTH_CHOOSER_GET_PRIVATE(self);
Packit Service fc05fa
	char *address;
Packit Service fc05fa
Packit Service fc05fa
	/* Not the selection changing? */
Packit Service fc05fa
	if (gtk_tree_selection_path_is_selected (priv->selection, path) == FALSE)
Packit Service fc05fa
		return;
Packit Service fc05fa
Packit Service fc05fa
	g_object_notify (G_OBJECT (self), "device-selected");
Packit Service fc05fa
	address = bluetooth_chooser_get_selected_device (self);
Packit Service fc05fa
	g_signal_emit (G_OBJECT (self),
Packit Service fc05fa
		       selection_table_signals[SELECTED_DEVICE_CHANGED],
Packit Service fc05fa
		       0, address);
Packit Service fc05fa
	g_free (address);
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
static void
Packit Service fc05fa
select_browse_device_callback (GtkTreeSelection *selection, gpointer user_data)
Packit Service fc05fa
{
Packit Service fc05fa
	BluetoothChooser *self = user_data;
Packit Service fc05fa
	char *address;
Packit Service fc05fa
Packit Service fc05fa
	g_object_notify (G_OBJECT(self), "device-selected");
Packit Service fc05fa
	address = bluetooth_chooser_get_selected_device (self);
Packit Service fc05fa
	g_signal_emit (G_OBJECT (self),
Packit Service fc05fa
		       selection_table_signals[SELECTED_DEVICE_CHANGED],
Packit Service fc05fa
		       0, address);
Packit Service fc05fa
	g_free (address);
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
static void
Packit Service fc05fa
row_activated_cb (GtkTreeView       *tree_view,
Packit Service fc05fa
		  GtkTreePath       *path,
Packit Service fc05fa
		  GtkTreeViewColumn *column,
Packit Service fc05fa
		  BluetoothChooser  *self)
Packit Service fc05fa
{
Packit Service fc05fa
	char *address;
Packit Service fc05fa
Packit Service fc05fa
	address = bluetooth_chooser_get_selected_device (self);
Packit Service fc05fa
	g_signal_emit (G_OBJECT (self),
Packit Service fc05fa
		       selection_table_signals[SELECTED_DEVICE_ACTIVATED],
Packit Service fc05fa
		       0, address);
Packit Service fc05fa
	g_free (address);
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
static gboolean
Packit Service fc05fa
filter_type_func (GtkTreeModel *model, GtkTreeIter *iter, BluetoothChooserPrivate *priv)
Packit Service fc05fa
{
Packit Service fc05fa
	int type;
Packit Service fc05fa
Packit Service fc05fa
	if (priv->device_type_filter == BLUETOOTH_TYPE_ANY)
Packit Service fc05fa
		return TRUE;
Packit Service fc05fa
Packit Service fc05fa
	gtk_tree_model_get (model, iter, BLUETOOTH_COLUMN_TYPE, &type, -1);
Packit Service fc05fa
	return (type & priv->device_type_filter);
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
static gboolean
Packit Service fc05fa
filter_category_func (GtkTreeModel *model, GtkTreeIter *iter, BluetoothChooserPrivate *priv)
Packit Service fc05fa
{
Packit Service fc05fa
	gboolean bonded, trusted;
Packit Service fc05fa
Packit Service fc05fa
	if (priv->device_category_filter == BLUETOOTH_CATEGORY_ALL)
Packit Service fc05fa
		return TRUE;
Packit Service fc05fa
Packit Service fc05fa
	gtk_tree_model_get (model, iter,
Packit Service fc05fa
			    BLUETOOTH_COLUMN_PAIRED, &bonded,
Packit Service fc05fa
			    BLUETOOTH_COLUMN_TRUSTED, &trusted,
Packit Service fc05fa
			    -1);
Packit Service fc05fa
Packit Service fc05fa
	if (priv->device_category_filter == BLUETOOTH_CATEGORY_PAIRED)
Packit Service fc05fa
		return bonded;
Packit Service fc05fa
	if (priv->device_category_filter == BLUETOOTH_CATEGORY_TRUSTED)
Packit Service fc05fa
		return trusted;
Packit Service fc05fa
	if (priv->device_category_filter == BLUETOOTH_CATEGORY_NOT_PAIRED_OR_TRUSTED)
Packit Service fc05fa
		return (!bonded && !trusted);
Packit Service fc05fa
	if (priv->device_category_filter == BLUETOOTH_CATEGORY_PAIRED_OR_TRUSTED)
Packit Service fc05fa
		return (bonded || trusted);
Packit Service fc05fa
Packit Service fc05fa
	g_assert_not_reached ();
Packit Service fc05fa
Packit Service fc05fa
	return FALSE;
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
static gboolean
Packit Service fc05fa
filter_service_func (GtkTreeModel *model, GtkTreeIter *iter, BluetoothChooserPrivate *priv)
Packit Service fc05fa
{
Packit Service fc05fa
	char **services;
Packit Service fc05fa
	gboolean ret = FALSE;
Packit Service fc05fa
	guint i;
Packit Service fc05fa
Packit Service fc05fa
	if (priv->device_service_filter == NULL)
Packit Service fc05fa
		return TRUE;
Packit Service fc05fa
Packit Service fc05fa
	gtk_tree_model_get (model, iter,
Packit Service fc05fa
			    BLUETOOTH_COLUMN_UUIDS, &services,
Packit Service fc05fa
			    -1);
Packit Service fc05fa
	if (services == NULL) {
Packit Service fc05fa
		/* FIXME we need a way to discover the services here */
Packit Service fc05fa
		return FALSE;
Packit Service fc05fa
	}
Packit Service fc05fa
Packit Service fc05fa
	for (i = 0; services[i] != NULL; i++) {
Packit Service fc05fa
		if (g_str_equal (priv->device_service_filter, services[i]) != FALSE) {
Packit Service fc05fa
			ret = TRUE;
Packit Service fc05fa
			break;
Packit Service fc05fa
		}
Packit Service fc05fa
	}
Packit Service fc05fa
Packit Service fc05fa
	g_strfreev (services);
Packit Service fc05fa
Packit Service fc05fa
	return ret;
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
static gboolean
Packit Service fc05fa
filter_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
Packit Service fc05fa
{
Packit Service fc05fa
	BluetoothChooser *self = BLUETOOTH_CHOOSER (data);
Packit Service fc05fa
	BluetoothChooserPrivate *priv = BLUETOOTH_CHOOSER_GET_PRIVATE(self);
Packit Service fc05fa
Packit Service fc05fa
	return filter_type_func (model, iter, priv)
Packit Service fc05fa
		&& filter_category_func (model, iter, priv)
Packit Service fc05fa
		&& filter_service_func (model, iter, priv);
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
static void
Packit Service fc05fa
filter_type_changed_cb (GObject *object, GParamSpec *spec, gpointer user_data)
Packit Service fc05fa
{
Packit Service fc05fa
	BluetoothChooser *self = BLUETOOTH_CHOOSER (object);
Packit Service fc05fa
	BluetoothChooserPrivate *priv = BLUETOOTH_CHOOSER_GET_PRIVATE(self);
Packit Service fc05fa
Packit Service fc05fa
	if (priv->filter)
Packit Service fc05fa
		gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
static void
Packit Service fc05fa
filter_category_changed_cb (GObject *object, GParamSpec *spec, gpointer user_data)
Packit Service fc05fa
{
Packit Service fc05fa
	BluetoothChooser *self = BLUETOOTH_CHOOSER (object);
Packit Service fc05fa
	BluetoothChooserPrivate *priv = BLUETOOTH_CHOOSER_GET_PRIVATE(self);
Packit Service fc05fa
Packit Service fc05fa
	if (priv->filter)
Packit Service fc05fa
		gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
static void
Packit Service fc05fa
adapter_model_row_changed (GtkTreeModel *model,
Packit Service fc05fa
			   GtkTreePath  *path,
Packit Service fc05fa
			   GtkTreeIter  *iter,
Packit Service fc05fa
			   gpointer      data)
Packit Service fc05fa
{
Packit Service fc05fa
	BluetoothChooser *self = BLUETOOTH_CHOOSER (data);
Packit Service fc05fa
	BluetoothChooserPrivate *priv = BLUETOOTH_CHOOSER_GET_PRIVATE(self);
Packit Service fc05fa
	gboolean discovering, is_default, powered;
Packit Service fc05fa
Packit Service fc05fa
	/* Not an adapter changing? */
Packit Service fc05fa
	if (gtk_tree_path_get_depth (path) != 1)
Packit Service fc05fa
		return;
Packit Service fc05fa
Packit Service fc05fa
	gtk_tree_model_get (model, iter,
Packit Service fc05fa
			    BLUETOOTH_COLUMN_DEFAULT, &is_default,
Packit Service fc05fa
			    BLUETOOTH_COLUMN_DISCOVERING, &discovering,
Packit Service fc05fa
			    BLUETOOTH_COLUMN_POWERED, &powered,
Packit Service fc05fa
			    -1);
Packit Service fc05fa
Packit Service fc05fa
	if (is_default == FALSE)
Packit Service fc05fa
		return;
Packit Service fc05fa
	if (powered != FALSE && discovering == FALSE && priv->disco_rq != FALSE) {
Packit Service fc05fa
		g_object_set (G_OBJECT (priv->client), "default-adapter-discovering", TRUE, NULL);
Packit Service fc05fa
		set_search_label (self, TRUE);
Packit Service fc05fa
		return;
Packit Service fc05fa
	}
Packit Service fc05fa
	gtk_widget_set_sensitive (GTK_WIDGET (priv->treeview), powered);
Packit Service fc05fa
	set_search_label (self, discovering);
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
static void default_adapter_changed (GObject    *gobject,
Packit Service fc05fa
				     GParamSpec *arg1,
Packit Service fc05fa
				     gpointer    data)
Packit Service fc05fa
{
Packit Service fc05fa
	BluetoothChooser *self = BLUETOOTH_CHOOSER (data);
Packit Service fc05fa
	BluetoothChooserPrivate *priv = BLUETOOTH_CHOOSER_GET_PRIVATE(self);
Packit Service fc05fa
	char *adapter;
Packit Service fc05fa
Packit Service fc05fa
	g_object_get (gobject, "default-adapter", &adapter, NULL);
Packit Service fc05fa
Packit Service fc05fa
	if (adapter == NULL) {
Packit Service fc05fa
		gtk_widget_set_sensitive (GTK_WIDGET (priv->treeview), FALSE);
Packit Service fc05fa
		set_search_label (self, FALSE);
Packit Service fc05fa
		gtk_tree_view_set_model (GTK_TREE_VIEW(priv->treeview), NULL);
Packit Service fc05fa
	}
Packit Service fc05fa
Packit Service fc05fa
	if (priv->model) {
Packit Service fc05fa
		g_object_unref (priv->model);
Packit Service fc05fa
		priv->model = NULL;
Packit Service fc05fa
	}
Packit Service fc05fa
Packit Service fc05fa
	if (adapter == NULL)
Packit Service fc05fa
		return;
Packit Service fc05fa
Packit Service fc05fa
	g_free (adapter);
Packit Service fc05fa
Packit Service fc05fa
	priv->model = bluetooth_client_get_device_model (priv->client);
Packit Service fc05fa
	if (priv->model) {
Packit Service fc05fa
		priv->filter = gtk_tree_model_filter_new (priv->model, NULL);
Packit Service fc05fa
		gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (priv->filter),
Packit Service fc05fa
							filter_func, self, NULL);
Packit Service fc05fa
		gtk_tree_view_set_model (GTK_TREE_VIEW(priv->treeview), priv->filter);
Packit Service fc05fa
		g_signal_connect (priv->filter, "row-changed",
Packit Service fc05fa
				  G_CALLBACK (device_model_row_changed), self);
Packit Service fc05fa
		g_object_unref (priv->filter);
Packit Service fc05fa
		gtk_widget_set_sensitive (GTK_WIDGET (priv->treeview), TRUE);
Packit Service fc05fa
Packit Service fc05fa
		/* Start a discovery if it was requested before we
Packit Service fc05fa
		 * had an adapter available */
Packit Service fc05fa
		if (priv->disco_rq != FALSE) {
Packit Service fc05fa
			bluetooth_chooser_start_discovery (self);
Packit Service fc05fa
			set_search_label (self, TRUE);
Packit Service fc05fa
		}
Packit Service fc05fa
	}
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
static GtkWidget *
Packit Service fc05fa
create_treeview (BluetoothChooser *self)
Packit Service fc05fa
{
Packit Service fc05fa
	BluetoothChooserPrivate *priv = BLUETOOTH_CHOOSER_GET_PRIVATE(self);
Packit Service fc05fa
	GtkWidget *scrolled, *tree;
Packit Service fc05fa
	GtkCellRenderer *renderer;
Packit Service fc05fa
	GtkTreeViewColumn *column;
Packit Service fc05fa
Packit Service fc05fa
	/* Create the scrolled window */
Packit Service fc05fa
	scrolled = gtk_scrolled_window_new (NULL, NULL);
Packit Service fc05fa
Packit Service fc05fa
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(scrolled),
Packit Service fc05fa
					GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
Packit Service fc05fa
Packit Service fc05fa
	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(scrolled),
Packit Service fc05fa
					     GTK_SHADOW_OUT);
Packit Service fc05fa
Packit Service fc05fa
	/* Create the tree view */
Packit Service fc05fa
	tree = gtk_tree_view_new ();
Packit Service fc05fa
Packit Service fc05fa
	gtk_tree_view_set_headers_visible (GTK_TREE_VIEW(tree), TRUE);
Packit Service fc05fa
Packit Service fc05fa
	gtk_tree_view_set_rules_hint (GTK_TREE_VIEW(tree), TRUE);
Packit Service fc05fa
Packit Service fc05fa
	g_object_set (tree, "show-expanders", FALSE, NULL);
Packit Service fc05fa
Packit Service fc05fa
	g_signal_connect (G_OBJECT (tree), "row-activated",
Packit Service fc05fa
			  G_CALLBACK (row_activated_cb), self);
Packit Service fc05fa
Packit Service fc05fa
	column = gtk_tree_view_column_new ();
Packit Service fc05fa
Packit Service fc05fa
	gtk_tree_view_column_set_title (column, _("Device"));
Packit Service fc05fa
	gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN(column), TRUE);
Packit Service fc05fa
Packit Service fc05fa
	/* The type icon */
Packit Service fc05fa
	renderer = gtk_cell_renderer_pixbuf_new ();
Packit Service fc05fa
	gtk_tree_view_column_set_spacing (column, 4);
Packit Service fc05fa
	gtk_tree_view_column_pack_start (column, renderer, FALSE);
Packit Service fc05fa
	gtk_tree_view_column_set_attributes (column, renderer,
Packit Service fc05fa
					     "icon-name", BLUETOOTH_COLUMN_ICON, NULL);
Packit Service fc05fa
Packit Service fc05fa
	/* The device name */
Packit Service fc05fa
	renderer = gtk_cell_renderer_text_new ();
Packit Service fc05fa
	gtk_tree_view_column_pack_start (column, renderer, TRUE);
Packit Service fc05fa
	g_object_set (G_OBJECT (renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL);
Packit Service fc05fa
	gtk_tree_view_column_set_cell_data_func (column, renderer,
Packit Service fc05fa
						 alias_to_label, NULL, NULL);
Packit Service fc05fa
Packit Service fc05fa
	/* The connected icon */
Packit Service fc05fa
	priv->connected_cell = gtk_cell_renderer_pixbuf_new ();
Packit Service fc05fa
	gtk_tree_view_column_pack_start (column, priv->connected_cell, FALSE);
Packit Service fc05fa
Packit Service fc05fa
	gtk_tree_view_column_set_cell_data_func (column, priv->connected_cell,
Packit Service fc05fa
						 connected_to_icon, NULL, NULL);
Packit Service fc05fa
	g_object_set (G_OBJECT (priv->connected_cell), "visible", priv->show_connected, NULL);
Packit Service fc05fa
Packit Service fc05fa
	/* The bonded icon */
Packit Service fc05fa
	priv->bonded_cell = gtk_cell_renderer_pixbuf_new ();
Packit Service fc05fa
	gtk_tree_view_column_pack_end (column, priv->bonded_cell, FALSE);
Packit Service fc05fa
Packit Service fc05fa
	gtk_tree_view_column_set_cell_data_func (column, priv->bonded_cell,
Packit Service fc05fa
						 bonded_to_icon, NULL, NULL);
Packit Service fc05fa
	g_object_set (G_OBJECT (priv->bonded_cell), "visible", priv->show_paired, NULL);
Packit Service fc05fa
Packit Service fc05fa
	gtk_tree_view_append_column (GTK_TREE_VIEW(tree), column);
Packit Service fc05fa
Packit Service fc05fa
	gtk_tree_view_insert_column_with_data_func (GTK_TREE_VIEW(tree), -1,
Packit Service fc05fa
						    _("Type"), gtk_cell_renderer_text_new(),
Packit Service fc05fa
						    type_to_text, NULL, NULL);
Packit Service fc05fa
Packit Service fc05fa
	priv->selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(tree));
Packit Service fc05fa
Packit Service fc05fa
	gtk_tree_selection_set_mode (priv->selection, GTK_SELECTION_SINGLE);
Packit Service fc05fa
Packit Service fc05fa
	g_signal_connect (G_OBJECT(priv->selection), "changed",
Packit Service fc05fa
			  G_CALLBACK(select_browse_device_callback), self);
Packit Service fc05fa
Packit Service fc05fa
	/* Set the model, and filter */
Packit Service fc05fa
	priv->model = bluetooth_client_get_device_model (priv->client);
Packit Service fc05fa
	if (priv->model) {
Packit Service fc05fa
		priv->filter = gtk_tree_model_filter_new (priv->model, NULL);
Packit Service fc05fa
		gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (priv->filter),
Packit Service fc05fa
							filter_func, self, NULL);
Packit Service fc05fa
		gtk_tree_view_set_model (GTK_TREE_VIEW(tree), priv->filter);
Packit Service fc05fa
		g_signal_connect (priv->filter, "row-changed",
Packit Service fc05fa
				  G_CALLBACK (device_model_row_changed), self);
Packit Service fc05fa
		g_object_unref (priv->filter);
Packit Service fc05fa
	} else {
Packit Service fc05fa
		gtk_widget_set_sensitive (GTK_WIDGET (tree), FALSE);
Packit Service fc05fa
		set_search_label (self, FALSE);
Packit Service fc05fa
	}
Packit Service fc05fa
Packit Service fc05fa
	gtk_container_add (GTK_CONTAINER(scrolled), tree);
Packit Service fc05fa
	priv->treeview = tree;
Packit Service fc05fa
Packit Service fc05fa
	return scrolled;
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
static void
Packit Service fc05fa
bluetooth_chooser_init(BluetoothChooser *self)
Packit Service fc05fa
{
Packit Service fc05fa
	BluetoothChooserPrivate *priv = BLUETOOTH_CHOOSER_GET_PRIVATE(self);
Packit Service fc05fa
Packit Service fc05fa
	GtkWidget *vbox;
Packit Service fc05fa
	GtkWidget *hbox;
Packit Service fc05fa
Packit Service fc05fa
	gtk_widget_push_composite_child ();
Packit Service fc05fa
Packit Service fc05fa
	g_object_set (G_OBJECT (self), "orientation", GTK_ORIENTATION_VERTICAL, NULL);
Packit Service fc05fa
Packit Service fc05fa
	priv->client = bluetooth_client_new ();
Packit Service fc05fa
Packit Service fc05fa
	/* Setup the widget itself */
Packit Service fc05fa
	gtk_box_set_spacing (GTK_BOX(self), 18);
Packit Service fc05fa
	gtk_container_set_border_width (GTK_CONTAINER(self), 0);
Packit Service fc05fa
Packit Service fc05fa
	vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
Packit Service fc05fa
	gtk_widget_show (vbox);
Packit Service fc05fa
	gtk_box_pack_start (GTK_BOX (self), vbox, TRUE, TRUE, 0);
Packit Service fc05fa
Packit Service fc05fa
	/* The treeview label */
Packit Service fc05fa
	priv->search_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 24);
Packit Service fc05fa
	gtk_widget_set_name (priv->search_hbox, "search_hbox");
Packit Service fc05fa
	if (priv->show_searching)
Packit Service fc05fa
		gtk_widget_show (priv->search_hbox);
Packit Service fc05fa
	gtk_box_pack_end (GTK_BOX (vbox), priv->search_hbox, FALSE, TRUE, 0);
Packit Service fc05fa
	gtk_widget_set_no_show_all (priv->search_hbox, TRUE);
Packit Service fc05fa
Packit Service fc05fa
	/* Setup the adapter disco mode callback for the search button */
Packit Service fc05fa
	priv->adapter_model = bluetooth_client_get_adapter_model (priv->client);
Packit Service fc05fa
	g_signal_connect (priv->adapter_model, "row-changed",
Packit Service fc05fa
			  G_CALLBACK (adapter_model_row_changed), self);
Packit Service fc05fa
Packit Service fc05fa
	/* The searching label */
Packit Service fc05fa
	hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
Packit Service fc05fa
	gtk_widget_set_name (hbox, "searching label hbox");
Packit Service fc05fa
	priv->spinner = gtk_spinner_new ();
Packit Service fc05fa
	gtk_container_add (GTK_CONTAINER (hbox), priv->spinner);
Packit Service fc05fa
	gtk_widget_show (priv->spinner);
Packit Service fc05fa
	priv->search_label = gtk_label_new (_("Searching for devices…"));
Packit Service fc05fa
	gtk_container_add (GTK_CONTAINER (hbox), priv->search_label);
Packit Service fc05fa
	gtk_widget_show (priv->search_label);
Packit Service fc05fa
	gtk_widget_show (hbox);
Packit Service fc05fa
Packit Service fc05fa
	if (priv->show_searching) {
Packit Service fc05fa
		gboolean discovering;
Packit Service fc05fa
Packit Service fc05fa
		g_object_get (G_OBJECT (priv->client), "default-adapter-discovering", &discovering, NULL);
Packit Service fc05fa
		set_search_label (self, discovering);
Packit Service fc05fa
	}
Packit Service fc05fa
Packit Service fc05fa
	gtk_box_pack_start (GTK_BOX (priv->search_hbox), hbox, FALSE, TRUE, 0);
Packit Service fc05fa
Packit Service fc05fa
	/* The treeview */
Packit Service fc05fa
	priv->scrolled_window = create_treeview (self);
Packit Service fc05fa
	gtk_widget_show_all (priv->scrolled_window);
Packit Service fc05fa
	gtk_box_pack_start (GTK_BOX (vbox), priv->scrolled_window, TRUE, TRUE, 0);
Packit Service fc05fa
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
Packit Service fc05fa
	gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->scrolled_window), GTK_SHADOW_IN);
Packit Service fc05fa
Packit Service fc05fa
	/* The filters */
Packit Service fc05fa
	priv->device_type_filter_model = GTK_TREE_MODEL (gtk_list_store_new (DEVICE_TYPE_FILTER_NUM_COLS,
Packit Service fc05fa
						         G_TYPE_STRING, G_TYPE_INT));
Packit Service fc05fa
	priv->filters_vbox = bluetooth_filter_widget_new ();
Packit Service fc05fa
	gtk_widget_show (priv->filters_vbox);
Packit Service fc05fa
	gtk_box_pack_start (GTK_BOX (self), priv->filters_vbox, FALSE, TRUE, 0);
Packit Service fc05fa
	gtk_widget_set_no_show_all (priv->filters_vbox, TRUE);
Packit Service fc05fa
Packit Service fc05fa
	/* if filters are not visible hide the vbox */
Packit Service fc05fa
	if (!priv->show_device_type && !priv->show_device_category)
Packit Service fc05fa
		gtk_widget_hide (priv->filters_vbox);
Packit Service fc05fa
Packit Service fc05fa
	priv->default_adapter_changed_id = g_signal_connect (priv->client, "notify::default-adapter",
Packit Service fc05fa
							     G_CALLBACK (default_adapter_changed), self);
Packit Service fc05fa
Packit Service fc05fa
	g_signal_connect(self, "notify::device-type-filter",
Packit Service fc05fa
			 G_CALLBACK(filter_type_changed_cb), NULL);
Packit Service fc05fa
	g_signal_connect(self, "notify::device-category-filter",
Packit Service fc05fa
			 G_CALLBACK(filter_category_changed_cb), NULL);
Packit Service fc05fa
Packit Service fc05fa
	gtk_widget_pop_composite_child ();
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
static GObject *
Packit Service fc05fa
bluetooth_chooser_constructor (GType                  type,
Packit Service fc05fa
			       guint                  n_construct_params,
Packit Service fc05fa
			       GObjectConstructParam *construct_params)
Packit Service fc05fa
{
Packit Service fc05fa
	BluetoothChooser *self;
Packit Service fc05fa
	BluetoothChooserPrivate *priv;
Packit Service fc05fa
	GObject *object;
Packit Service fc05fa
Packit Service fc05fa
	object = G_OBJECT_CLASS (bluetooth_chooser_parent_class)->constructor (type,
Packit Service fc05fa
									       n_construct_params,
Packit Service fc05fa
									       construct_params);
Packit Service fc05fa
	self = BLUETOOTH_CHOOSER (object);
Packit Service fc05fa
	priv = BLUETOOTH_CHOOSER_GET_PRIVATE(self);
Packit Service fc05fa
Packit Service fc05fa
	if (priv->internal_filter) {
Packit Service fc05fa
		bluetooth_filter_widget_bind_filter (BLUETOOTH_FILTER_WIDGET (priv->filters_vbox), self);
Packit Service fc05fa
	}
Packit Service fc05fa
	return object;
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
static void
Packit Service fc05fa
bluetooth_chooser_finalize (GObject *object)
Packit Service fc05fa
{
Packit Service fc05fa
	BluetoothChooser *self = BLUETOOTH_CHOOSER (object);
Packit Service fc05fa
	BluetoothChooserPrivate *priv = BLUETOOTH_CHOOSER_GET_PRIVATE(self);
Packit Service fc05fa
Packit Service fc05fa
	if (priv->client) {
Packit Service fc05fa
		g_signal_handler_disconnect (G_OBJECT(priv->client), priv->default_adapter_changed_id);
Packit Service fc05fa
		priv->default_adapter_changed_id = 0;
Packit Service fc05fa
Packit Service fc05fa
		g_object_set (G_OBJECT (priv->client), "default-adapter-discovering", FALSE, NULL);
Packit Service fc05fa
		g_object_unref (priv->client);
Packit Service fc05fa
		priv->client = NULL;
Packit Service fc05fa
	}
Packit Service fc05fa
	if (priv->adapter_model) {
Packit Service fc05fa
		g_object_unref (priv->adapter_model);
Packit Service fc05fa
		priv->adapter_model = NULL;
Packit Service fc05fa
	}
Packit Service fc05fa
	if (priv->model != NULL) {
Packit Service fc05fa
		g_object_unref (priv->model);
Packit Service fc05fa
		priv->model = NULL;
Packit Service fc05fa
	}
Packit Service fc05fa
	g_free (priv->device_service_filter);
Packit Service fc05fa
Packit Service fc05fa
	G_OBJECT_CLASS(bluetooth_chooser_parent_class)->finalize(object);
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
enum {
Packit Service fc05fa
	PROP_0,
Packit Service fc05fa
	PROP_DEVICE_SELECTED,
Packit Service fc05fa
	PROP_SHOW_PAIRING,
Packit Service fc05fa
	PROP_SHOW_CONNECTED,
Packit Service fc05fa
	PROP_SHOW_SEARCHING,
Packit Service fc05fa
	PROP_SHOW_DEVICE_TYPE,
Packit Service fc05fa
	PROP_SHOW_DEVICE_TYPE_COLUMN,
Packit Service fc05fa
	PROP_SHOW_DEVICE_CATEGORY,
Packit Service fc05fa
	PROP_DEVICE_TYPE_FILTER,
Packit Service fc05fa
	PROP_DEVICE_CATEGORY_FILTER,
Packit Service fc05fa
	PROP_DEVICE_SERVICE_FILTER,
Packit Service fc05fa
	PROP_INTERNAL_FILTER
Packit Service fc05fa
};
Packit Service fc05fa
Packit Service fc05fa
static void
Packit Service fc05fa
bluetooth_chooser_set_property (GObject *object, guint prop_id,
Packit Service fc05fa
					 const GValue *value, GParamSpec *pspec)
Packit Service fc05fa
{
Packit Service fc05fa
	BluetoothChooser *self = BLUETOOTH_CHOOSER (object);
Packit Service fc05fa
	BluetoothChooserPrivate *priv = BLUETOOTH_CHOOSER_GET_PRIVATE (self);
Packit Service fc05fa
Packit Service fc05fa
	switch (prop_id) {
Packit Service fc05fa
	case PROP_DEVICE_SELECTED: {
Packit Service fc05fa
		const char *address;
Packit Service fc05fa
		char *selected;
Packit Service fc05fa
		GtkTreeIter iter;
Packit Service fc05fa
		gboolean cont;
Packit Service fc05fa
Packit Service fc05fa
		address = g_value_get_string (value);
Packit Service fc05fa
		if (address == NULL) {
Packit Service fc05fa
			gtk_tree_selection_unselect_all (priv->selection);
Packit Service fc05fa
			return;
Packit Service fc05fa
		}
Packit Service fc05fa
Packit Service fc05fa
		selected = bluetooth_chooser_get_selected_device (self);
Packit Service fc05fa
		if (g_strcmp0 (selected, address) == 0) {
Packit Service fc05fa
			g_free (selected);
Packit Service fc05fa
			return;
Packit Service fc05fa
		}
Packit Service fc05fa
		g_free (selected);
Packit Service fc05fa
Packit Service fc05fa
		cont = gtk_tree_model_get_iter_first (priv->filter, &iter);
Packit Service fc05fa
		while (cont == TRUE) {
Packit Service fc05fa
			char *iaddress;
Packit Service fc05fa
			gtk_tree_model_get (priv->filter, &iter,
Packit Service fc05fa
					    BLUETOOTH_COLUMN_ADDRESS, &iaddress, -1);
Packit Service fc05fa
			if (g_strcmp0 (iaddress, address) == 0) {
Packit Service fc05fa
				gtk_tree_selection_select_iter (priv->selection, &iter);
Packit Service fc05fa
				g_free (iaddress);
Packit Service fc05fa
				return;
Packit Service fc05fa
			}
Packit Service fc05fa
			g_free (iaddress);
Packit Service fc05fa
Packit Service fc05fa
			cont = gtk_tree_model_iter_next (priv->filter, &iter);
Packit Service fc05fa
		}
Packit Service fc05fa
		break;
Packit Service fc05fa
	}
Packit Service fc05fa
	case PROP_SHOW_PAIRING:
Packit Service fc05fa
		priv->show_paired = g_value_get_boolean (value);
Packit Service fc05fa
		if (priv->bonded_cell != NULL)
Packit Service fc05fa
			g_object_set (G_OBJECT (priv->bonded_cell), "visible", priv->show_paired, NULL);
Packit Service fc05fa
		break;
Packit Service fc05fa
	case PROP_SHOW_CONNECTED:
Packit Service fc05fa
		priv->show_connected = g_value_get_boolean (value);
Packit Service fc05fa
		if (priv->connected_cell != NULL)
Packit Service fc05fa
			g_object_set (G_OBJECT (priv->connected_cell), "visible", priv->show_connected, NULL);
Packit Service fc05fa
		break;
Packit Service fc05fa
	case PROP_SHOW_SEARCHING:
Packit Service fc05fa
		priv->show_searching = g_value_get_boolean (value);
Packit Service fc05fa
		g_object_set (G_OBJECT (priv->search_hbox), "visible", priv->show_searching, NULL);
Packit Service fc05fa
		break;
Packit Service fc05fa
	case PROP_SHOW_DEVICE_TYPE:
Packit Service fc05fa
		priv->show_device_type = g_value_get_boolean (value);
Packit Service fc05fa
		if (priv->internal_filter) {
Packit Service fc05fa
			if (priv->show_device_type || priv->show_device_category)
Packit Service fc05fa
				g_object_set (G_OBJECT (priv->filters_vbox), "visible", TRUE, NULL);
Packit Service fc05fa
			else
Packit Service fc05fa
				g_object_set (G_OBJECT (priv->filters_vbox), "visible", FALSE, NULL);
Packit Service fc05fa
		}
Packit Service fc05fa
		break;
Packit Service fc05fa
	case PROP_SHOW_DEVICE_TYPE_COLUMN: {
Packit Service fc05fa
		GtkTreeViewColumn *column;
Packit Service fc05fa
Packit Service fc05fa
		column = gtk_tree_view_get_column (GTK_TREE_VIEW (priv->treeview), TREEVIEW_COLUMN_TYPE);
Packit Service fc05fa
		gtk_tree_view_column_set_visible (column,
Packit Service fc05fa
						  g_value_get_boolean (value));
Packit Service fc05fa
Packit Service fc05fa
		column = gtk_tree_view_get_column (GTK_TREE_VIEW (priv->treeview), TREEVIEW_COLUMN_DEVICE);
Packit Service fc05fa
		if (g_value_get_boolean (value))
Packit Service fc05fa
			gtk_tree_view_column_set_title (column, _("Device"));
Packit Service fc05fa
		else
Packit Service fc05fa
			gtk_tree_view_column_set_title (column, _("Devices"));
Packit Service fc05fa
		break;
Packit Service fc05fa
		}
Packit Service fc05fa
	case PROP_SHOW_DEVICE_CATEGORY:
Packit Service fc05fa
		priv->show_device_category = g_value_get_boolean (value);
Packit Service fc05fa
		if (priv->internal_filter) {
Packit Service fc05fa
			if (priv->show_device_type || priv->show_device_category)
Packit Service fc05fa
				g_object_set (G_OBJECT (priv->filters_vbox), "visible", TRUE, NULL);
Packit Service fc05fa
			else
Packit Service fc05fa
				g_object_set (G_OBJECT (priv->filters_vbox), "visible", FALSE, NULL);
Packit Service fc05fa
		}
Packit Service fc05fa
		break;
Packit Service fc05fa
	case PROP_DEVICE_TYPE_FILTER:
Packit Service fc05fa
		priv->device_type_filter = g_value_get_int (value);
Packit Service fc05fa
		g_object_notify (object, "device-type-filter");
Packit Service fc05fa
		break;
Packit Service fc05fa
	case PROP_DEVICE_CATEGORY_FILTER:
Packit Service fc05fa
		priv->device_category_filter = g_value_get_enum (value);
Packit Service fc05fa
		g_object_notify (object, "device-category-filter");
Packit Service fc05fa
		break;
Packit Service fc05fa
	case PROP_DEVICE_SERVICE_FILTER:
Packit Service fc05fa
		g_free (priv->device_service_filter);
Packit Service fc05fa
		priv->device_service_filter = g_value_dup_string (value);
Packit Service fc05fa
		if (priv->filter)
Packit Service fc05fa
			gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
Packit Service fc05fa
		break;
Packit Service fc05fa
	case PROP_INTERNAL_FILTER:
Packit Service fc05fa
		priv->internal_filter = g_value_get_boolean (value);
Packit Service fc05fa
		g_object_set (G_OBJECT (priv->filters_vbox), "visible", priv->internal_filter, NULL);
Packit Service fc05fa
		break;
Packit Service fc05fa
	default:
Packit Service fc05fa
		G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
Packit Service fc05fa
		break;
Packit Service fc05fa
	}
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
static void
Packit Service fc05fa
bluetooth_chooser_get_property (GObject *object, guint prop_id,
Packit Service fc05fa
					 GValue *value, GParamSpec *pspec)
Packit Service fc05fa
{
Packit Service fc05fa
	BluetoothChooser *self = BLUETOOTH_CHOOSER(object);
Packit Service fc05fa
	BluetoothChooserPrivate *priv = BLUETOOTH_CHOOSER_GET_PRIVATE(self);
Packit Service fc05fa
Packit Service fc05fa
	switch (prop_id) {
Packit Service fc05fa
	case PROP_DEVICE_SELECTED:
Packit Service fc05fa
		g_value_take_string (value, bluetooth_chooser_get_selected_device (self));
Packit Service fc05fa
		break;
Packit Service fc05fa
	case PROP_SHOW_PAIRING:
Packit Service fc05fa
		g_value_set_boolean (value, priv->show_paired);
Packit Service fc05fa
		break;
Packit Service fc05fa
	case PROP_SHOW_CONNECTED:
Packit Service fc05fa
		g_value_set_boolean (value, priv->show_connected);
Packit Service fc05fa
		break;
Packit Service fc05fa
	case PROP_SHOW_SEARCHING:
Packit Service fc05fa
		g_value_set_boolean (value, priv->show_searching);
Packit Service fc05fa
		break;
Packit Service fc05fa
	case PROP_SHOW_DEVICE_TYPE:
Packit Service fc05fa
		g_value_set_boolean (value, priv->show_device_type);
Packit Service fc05fa
		break;
Packit Service fc05fa
	case PROP_SHOW_DEVICE_TYPE_COLUMN:
Packit Service fc05fa
		g_value_set_boolean (value,
Packit Service fc05fa
				     gtk_tree_view_column_get_visible (gtk_tree_view_get_column (GTK_TREE_VIEW (priv->treeview), TREEVIEW_COLUMN_TYPE)));
Packit Service fc05fa
		break;
Packit Service fc05fa
	case PROP_SHOW_DEVICE_CATEGORY:
Packit Service fc05fa
		g_value_set_boolean (value, priv->show_device_category);
Packit Service fc05fa
		break;
Packit Service fc05fa
	case PROP_DEVICE_TYPE_FILTER:
Packit Service fc05fa
		g_value_set_int (value, priv->device_type_filter);
Packit Service fc05fa
		break;
Packit Service fc05fa
	case PROP_DEVICE_CATEGORY_FILTER:
Packit Service fc05fa
		g_value_set_enum (value, priv->device_category_filter);
Packit Service fc05fa
		break;
Packit Service fc05fa
	case PROP_DEVICE_SERVICE_FILTER:
Packit Service fc05fa
		g_value_set_string (value, priv->device_service_filter);
Packit Service fc05fa
		break;
Packit Service fc05fa
	case PROP_INTERNAL_FILTER:
Packit Service fc05fa
		g_value_set_boolean (value, priv->internal_filter);
Packit Service fc05fa
		break;
Packit Service fc05fa
	default:
Packit Service fc05fa
		G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
Packit Service fc05fa
		break;
Packit Service fc05fa
	}
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
static void
Packit Service fc05fa
bluetooth_chooser_class_init (BluetoothChooserClass *klass)
Packit Service fc05fa
{
Packit Service fc05fa
	/* Use to calculate the maximum value for the
Packit Service fc05fa
	 * device-type-filter value */
Packit Service fc05fa
	guint i;
Packit Service fc05fa
	int max_filter_val;
Packit Service fc05fa
Packit Service fc05fa
	bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
Packit Service fc05fa
Packit Service fc05fa
	G_OBJECT_CLASS(klass)->constructor = bluetooth_chooser_constructor;
Packit Service fc05fa
	G_OBJECT_CLASS(klass)->finalize = bluetooth_chooser_finalize;
Packit Service fc05fa
Packit Service fc05fa
	G_OBJECT_CLASS(klass)->set_property = bluetooth_chooser_set_property;
Packit Service fc05fa
	G_OBJECT_CLASS(klass)->get_property = bluetooth_chooser_get_property;
Packit Service fc05fa
Packit Service fc05fa
	/**
Packit Service fc05fa
	 * BluetoothChooser::selected-device-changed:
Packit Service fc05fa
	 * @chooser: a #BluetoothChooser widget which received the signal
Packit Service fc05fa
	 * @address: the Bluetooth address for the currently selected device, or %NULL
Packit Service fc05fa
	 *
Packit Service fc05fa
	 * The #BluetoothChooser::selected-device-changed signal is launched when the
Packit Service fc05fa
	 * selected device is changed, it will be %NULL if a device was unselected.
Packit Service fc05fa
	 **/
Packit Service fc05fa
	selection_table_signals[SELECTED_DEVICE_CHANGED] =
Packit Service fc05fa
		g_signal_new ("selected-device-changed",
Packit Service fc05fa
			      G_TYPE_FROM_CLASS (klass),
Packit Service fc05fa
			      G_SIGNAL_RUN_LAST,
Packit Service fc05fa
			      G_STRUCT_OFFSET (BluetoothChooserClass, selected_device_changed),
Packit Service fc05fa
			      NULL, NULL,
Packit Service fc05fa
			      g_cclosure_marshal_VOID__STRING,
Packit Service fc05fa
			      G_TYPE_NONE, 1, G_TYPE_STRING);
Packit Service fc05fa
	/**
Packit Service fc05fa
	 * BluetoothChooser::selected-device-activated:
Packit Service fc05fa
	 * @chooser: a #BluetoothChooser widget which received the signal
Packit Service fc05fa
	 * @address: the Bluetooth address for the currently selected device, or %NULL
Packit Service fc05fa
	 *
Packit Service fc05fa
	 * The #BluetoothChooser::selected-device-activated signal is launched when a
Packit Service fc05fa
	 * device is double-clicked in the chooser.
Packit Service fc05fa
	 **/
Packit Service fc05fa
	selection_table_signals[SELECTED_DEVICE_ACTIVATED] =
Packit Service fc05fa
		g_signal_new ("selected-device-activated",
Packit Service fc05fa
			      G_TYPE_FROM_CLASS (klass),
Packit Service fc05fa
			      G_SIGNAL_RUN_LAST,
Packit Service fc05fa
			      G_STRUCT_OFFSET (BluetoothChooserClass, selected_device_activated),
Packit Service fc05fa
			      NULL, NULL,
Packit Service fc05fa
			      g_cclosure_marshal_VOID__STRING,
Packit Service fc05fa
			      G_TYPE_NONE, 1, G_TYPE_STRING);
Packit Service fc05fa
Packit Service fc05fa
	g_object_class_install_property (G_OBJECT_CLASS(klass),
Packit Service fc05fa
					 PROP_DEVICE_SELECTED, g_param_spec_string ("device-selected",
Packit Service fc05fa
										    "device-selected", "The Bluetooth address for the currently selected device, or %NULL", NULL, G_PARAM_READABLE | G_PARAM_WRITABLE));
Packit Service fc05fa
	g_object_class_install_property (G_OBJECT_CLASS(klass),
Packit Service fc05fa
					 PROP_SHOW_PAIRING, g_param_spec_boolean ("show-pairing",
Packit Service fc05fa
										  "show-pairing", "Whether to show the pairing column in the tree.", FALSE, G_PARAM_READWRITE));
Packit Service fc05fa
	g_object_class_install_property (G_OBJECT_CLASS(klass),
Packit Service fc05fa
					 PROP_SHOW_CONNECTED, g_param_spec_boolean ("show-connected",
Packit Service fc05fa
										    "show-connected", "Whether to show the connected column in the tree.", FALSE, G_PARAM_READWRITE));
Packit Service fc05fa
	g_object_class_install_property (G_OBJECT_CLASS(klass),
Packit Service fc05fa
					 PROP_SHOW_SEARCHING, g_param_spec_boolean ("show-searching",
Packit Service fc05fa
										    "show-searching",
Packit Service fc05fa
										    "Whether to show the Searching label , this is necessary if you want to programmatically start a discovery, using bluetooth_chooser_start_discovery()",
Packit Service fc05fa
										    FALSE, G_PARAM_READWRITE));
Packit Service fc05fa
	g_object_class_install_property (G_OBJECT_CLASS(klass),
Packit Service fc05fa
					 PROP_SHOW_DEVICE_TYPE, g_param_spec_boolean ("show-device-type",
Packit Service fc05fa
										      "show-device-type", "Whether to show the device type filter", TRUE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
Packit Service fc05fa
	g_object_class_install_property (G_OBJECT_CLASS(klass),
Packit Service fc05fa
					 PROP_SHOW_DEVICE_TYPE_COLUMN, g_param_spec_boolean ("show-device-type-column",
Packit Service fc05fa
											     "show-device-type-column", "Whether to show the device type column", TRUE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
Packit Service fc05fa
	g_object_class_install_property (G_OBJECT_CLASS(klass),
Packit Service fc05fa
					 PROP_SHOW_DEVICE_CATEGORY, g_param_spec_boolean ("show-device-category",
Packit Service fc05fa
											  "show-device-category", "Whether to show the device category filter", TRUE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
Packit Service fc05fa
	for (i = 0, max_filter_val = 0 ; i < _BLUETOOTH_TYPE_NUM_TYPES; i++)
Packit Service fc05fa
		max_filter_val += 1 << i;
Packit Service fc05fa
	g_object_class_install_property (G_OBJECT_CLASS(klass),
Packit Service fc05fa
					 PROP_DEVICE_TYPE_FILTER, g_param_spec_int ("device-type-filter",
Packit Service fc05fa
										    "device-type-filter", "A bitmask of #BluetoothType to show", BLUETOOTH_TYPE_ANY, max_filter_val, 1, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
Packit Service fc05fa
	g_object_class_install_property (G_OBJECT_CLASS(klass),
Packit Service fc05fa
					 PROP_DEVICE_CATEGORY_FILTER, g_param_spec_enum ("device-category-filter",
Packit Service fc05fa
											 "device-category-filter", "The #BluetoothCategory to show", BLUETOOTH_TYPE_CATEGORY, BLUETOOTH_CATEGORY_ALL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
Packit Service fc05fa
	g_object_class_install_property (G_OBJECT_CLASS(klass),
Packit Service fc05fa
					 PROP_DEVICE_SERVICE_FILTER, g_param_spec_string ("device-service-filter",
Packit Service fc05fa
											  "device-service-filter", "A string representing the service to filter for", NULL, G_PARAM_WRITABLE));
Packit Service fc05fa
	g_object_class_install_property (G_OBJECT_CLASS(klass),
Packit Service fc05fa
					 PROP_INTERNAL_FILTER, g_param_spec_boolean ("has-internal-device-filter",
Packit Service fc05fa
											  "has-internal-device-filter", "Whether the #BluetoothChooser should be constructed with a visible #BluetoothFilterWidget", TRUE, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
Packit Service fc05fa
}
Packit Service fc05fa
Packit Service fc05fa
/**
Packit Service fc05fa
 * bluetooth_chooser_new:
Packit Service fc05fa
 *
Packit Service fc05fa
 * Returns a new #BluetoothChooser widget.
Packit Service fc05fa
 *
Packit Service fc05fa
 * Return value: A #BluetoothChooser widget
Packit Service fc05fa
 **/
Packit Service fc05fa
GtkWidget *
Packit Service fc05fa
bluetooth_chooser_new (void)
Packit Service fc05fa
{
Packit Service fc05fa
	return g_object_new(BLUETOOTH_TYPE_CHOOSER, NULL);
Packit Service fc05fa
}
Packit Service fc05fa