|
Packit |
8fb625 |
/*
|
|
Packit |
8fb625 |
*
|
|
Packit |
8fb625 |
* BlueZ - Bluetooth protocol stack for Linux
|
|
Packit |
8fb625 |
*
|
|
Packit |
8fb625 |
* Copyright (C) 2005-2008 Marcel Holtmann <marcel@holtmann.org>
|
|
Packit |
8fb625 |
* Copyright (C) 2006-2007 Bastien Nocera <hadess@hadess.net>
|
|
Packit |
8fb625 |
*
|
|
Packit |
8fb625 |
*
|
|
Packit |
8fb625 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
8fb625 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
8fb625 |
* License as published by the Free Software Foundation; either
|
|
Packit |
8fb625 |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
8fb625 |
*
|
|
Packit |
8fb625 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
8fb625 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
8fb625 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
8fb625 |
* Lesser General Public License for more details.
|
|
Packit |
8fb625 |
*
|
|
Packit |
8fb625 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
8fb625 |
* License along with this library; if not, write to the Free Software
|
|
Packit |
8fb625 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit |
8fb625 |
*
|
|
Packit |
8fb625 |
*/
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
#ifdef HAVE_CONFIG_H
|
|
Packit |
8fb625 |
#include <config.h>
|
|
Packit |
8fb625 |
#endif
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
#include <gtk/gtk.h>
|
|
Packit |
8fb625 |
#include <glib/gi18n-lib.h>
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
#include "bluetooth-filter-widget.h"
|
|
Packit |
8fb625 |
#include "bluetooth-client.h"
|
|
Packit |
8fb625 |
#include "bluetooth-utils.h"
|
|
Packit |
8fb625 |
#include "gnome-bluetooth-enum-types.h"
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
#define BLUETOOTH_FILTER_WIDGET_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), \
|
|
Packit |
8fb625 |
BLUETOOTH_TYPE_FILTER_WIDGET, BluetoothFilterWidgetPrivate))
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
typedef struct _BluetoothFilterWidgetPrivate BluetoothFilterWidgetPrivate;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
struct _BluetoothFilterWidgetPrivate {
|
|
Packit |
8fb625 |
GtkWidget *device_type_label, *device_type;
|
|
Packit |
8fb625 |
GtkWidget *device_category_label, *device_category;
|
|
Packit |
8fb625 |
GtkWidget *title;
|
|
Packit |
8fb625 |
GtkWidget *chooser;
|
|
Packit |
8fb625 |
GtkTreeModel *filter;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
/* Current filter */
|
|
Packit |
8fb625 |
int device_type_filter;
|
|
Packit |
8fb625 |
GtkTreeModel *device_type_filter_model;
|
|
Packit |
8fb625 |
int device_category_filter;
|
|
Packit |
8fb625 |
char *device_service_filter;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
guint show_device_type : 1;
|
|
Packit |
8fb625 |
guint show_device_category : 1;
|
|
Packit |
8fb625 |
};
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
G_DEFINE_TYPE(BluetoothFilterWidget, bluetooth_filter_widget, GTK_TYPE_BOX)
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
enum {
|
|
Packit |
8fb625 |
DEVICE_TYPE_FILTER_COL_NAME = 0,
|
|
Packit |
8fb625 |
DEVICE_TYPE_FILTER_COL_MASK,
|
|
Packit |
8fb625 |
DEVICE_TYPE_FILTER_NUM_COLS
|
|
Packit |
8fb625 |
};
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static const char *
|
|
Packit |
8fb625 |
bluetooth_device_category_to_string (int type)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
switch (type) {
|
|
Packit |
8fb625 |
case BLUETOOTH_CATEGORY_ALL:
|
|
Packit |
8fb625 |
return N_("All categories");
|
|
Packit |
8fb625 |
case BLUETOOTH_CATEGORY_PAIRED:
|
|
Packit |
8fb625 |
return N_("Paired");
|
|
Packit |
8fb625 |
case BLUETOOTH_CATEGORY_TRUSTED:
|
|
Packit |
8fb625 |
return N_("Trusted");
|
|
Packit |
8fb625 |
case BLUETOOTH_CATEGORY_NOT_PAIRED_OR_TRUSTED:
|
|
Packit |
8fb625 |
return N_("Not paired or trusted");
|
|
Packit |
8fb625 |
case BLUETOOTH_CATEGORY_PAIRED_OR_TRUSTED:
|
|
Packit |
8fb625 |
return N_("Paired or trusted");
|
|
Packit |
8fb625 |
default:
|
|
Packit |
8fb625 |
return N_("Unknown");
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
set_combobox_from_filter (BluetoothFilterWidget *self)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
BluetoothFilterWidgetPrivate *priv = BLUETOOTH_FILTER_WIDGET_GET_PRIVATE(self);
|
|
Packit |
8fb625 |
GtkTreeIter iter;
|
|
Packit |
8fb625 |
gboolean cont;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
/* Look for an exact matching filter first */
|
|
Packit |
8fb625 |
cont = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->device_type_filter_model),
|
|
Packit |
8fb625 |
&iter);
|
|
Packit |
8fb625 |
while (cont != FALSE) {
|
|
Packit |
8fb625 |
int mask;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
gtk_tree_model_get (GTK_TREE_MODEL (priv->device_type_filter_model), &iter,
|
|
Packit |
8fb625 |
DEVICE_TYPE_FILTER_COL_MASK, &mask, -1);
|
|
Packit |
8fb625 |
if (mask == priv->device_type_filter) {
|
|
Packit |
8fb625 |
gtk_combo_box_set_active_iter (GTK_COMBO_BOX(priv->device_type), &iter);
|
|
Packit |
8fb625 |
return;
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
cont = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->device_type_filter_model), &iter);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
/* Then a fuzzy match */
|
|
Packit |
8fb625 |
cont = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->device_type_filter_model),
|
|
Packit |
8fb625 |
&iter);
|
|
Packit |
8fb625 |
while (cont != FALSE) {
|
|
Packit |
8fb625 |
int mask;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
gtk_tree_model_get (GTK_TREE_MODEL (priv->device_type_filter_model), &iter,
|
|
Packit |
8fb625 |
DEVICE_TYPE_FILTER_COL_MASK, &mask,
|
|
Packit |
8fb625 |
-1);
|
|
Packit |
8fb625 |
if (mask & priv->device_type_filter) {
|
|
Packit |
8fb625 |
gtk_combo_box_set_active_iter (GTK_COMBO_BOX(priv->device_type), &iter);
|
|
Packit |
8fb625 |
return;
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
cont = gtk_tree_model_iter_next (GTK_TREE_MODEL (priv->device_type_filter_model), &iter);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
/* Then just set the any then */
|
|
Packit |
8fb625 |
gtk_tree_model_get_iter_first (GTK_TREE_MODEL (priv->device_type_filter_model), &iter);
|
|
Packit |
8fb625 |
gtk_combo_box_set_active_iter (GTK_COMBO_BOX(priv->device_type), &iter);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
filter_category_changed_cb (GtkComboBox *widget, gpointer data)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
BluetoothFilterWidget *self = BLUETOOTH_FILTER_WIDGET (data);
|
|
Packit |
8fb625 |
BluetoothFilterWidgetPrivate *priv = BLUETOOTH_FILTER_WIDGET_GET_PRIVATE(self);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
priv->device_category_filter = gtk_combo_box_get_active (GTK_COMBO_BOX(priv->device_category));
|
|
Packit |
8fb625 |
if (priv->filter)
|
|
Packit |
8fb625 |
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
|
|
Packit |
8fb625 |
g_object_notify (G_OBJECT(self), "device-category-filter");
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
filter_type_changed_cb (GtkComboBox *widget, gpointer data)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
BluetoothFilterWidget *self = BLUETOOTH_FILTER_WIDGET (data);
|
|
Packit |
8fb625 |
BluetoothFilterWidgetPrivate *priv = BLUETOOTH_FILTER_WIDGET_GET_PRIVATE(self);
|
|
Packit |
8fb625 |
GtkTreeIter iter;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
if (gtk_combo_box_get_active_iter (widget, &iter) == FALSE)
|
|
Packit |
8fb625 |
return;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
gtk_tree_model_get (GTK_TREE_MODEL (priv->device_type_filter_model), &iter,
|
|
Packit |
8fb625 |
DEVICE_TYPE_FILTER_COL_MASK, &(priv->device_type_filter),
|
|
Packit |
8fb625 |
-1);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
if (priv->filter)
|
|
Packit |
8fb625 |
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
|
|
Packit |
8fb625 |
g_object_notify (G_OBJECT(self), "device-type-filter");
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
/**
|
|
Packit |
8fb625 |
* bluetooth_filter_widget_set_title:
|
|
Packit |
8fb625 |
* @self: a #BluetoothFilterWidget.
|
|
Packit |
8fb625 |
* @title: Title for the #BluetoothFilterWidget.
|
|
Packit |
8fb625 |
*
|
|
Packit |
8fb625 |
* Used to set a different title for the #BluetoothFilterWidget than the default.
|
|
Packit |
8fb625 |
*
|
|
Packit |
8fb625 |
**/
|
|
Packit |
8fb625 |
void
|
|
Packit |
8fb625 |
bluetooth_filter_widget_set_title (BluetoothFilterWidget *self, gchar *title)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
BluetoothFilterWidgetPrivate *priv = BLUETOOTH_FILTER_WIDGET_GET_PRIVATE(self);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
gtk_label_set_text (GTK_LABEL (priv->title), title);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
bluetooth_filter_widget_bind_chooser_single (BluetoothFilterWidget *self,
|
|
Packit |
8fb625 |
BluetoothChooser *chooser,
|
|
Packit |
8fb625 |
const char *property)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
/* NOTE: We are binding the chooser as the source so that all of its
|
|
Packit |
8fb625 |
* properties are pushed to the filter.
|
|
Packit |
8fb625 |
* The bindings will be automatically removed when one of the
|
|
Packit |
8fb625 |
* objects goes away */
|
|
Packit |
8fb625 |
g_object_bind_property ((gpointer) chooser, property,
|
|
Packit |
8fb625 |
(gpointer) self, property,
|
|
Packit |
8fb625 |
G_BINDING_BIDIRECTIONAL);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
/**
|
|
Packit |
8fb625 |
* bluetooth_filter_widget_bind_filter:
|
|
Packit |
8fb625 |
* @self: a #BluetoothFilterWidget.
|
|
Packit |
8fb625 |
* @chooser: The #BluetoothChooser widget to bind the filter to.
|
|
Packit |
8fb625 |
*
|
|
Packit |
8fb625 |
* Binds a #BluetoothFilterWidget to a #BluetoothChooser such that changing the
|
|
Packit |
8fb625 |
* #BluetoothFilterWidget results in filters being applied on the #BluetoothChooser.
|
|
Packit |
8fb625 |
* Any properties set on a bound #BluetoothChooser will also be set on the
|
|
Packit |
8fb625 |
* #BluetoothFilterWidget.
|
|
Packit |
8fb625 |
*
|
|
Packit |
8fb625 |
**/
|
|
Packit |
8fb625 |
void
|
|
Packit |
8fb625 |
bluetooth_filter_widget_bind_filter (BluetoothFilterWidget *self, BluetoothChooser *chooser)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
bluetooth_filter_widget_bind_chooser_single (self, chooser, "device-type-filter");
|
|
Packit |
8fb625 |
bluetooth_filter_widget_bind_chooser_single (self, chooser, "device-category-filter");
|
|
Packit |
8fb625 |
bluetooth_filter_widget_bind_chooser_single (self, chooser, "show-device-type");
|
|
Packit |
8fb625 |
bluetooth_filter_widget_bind_chooser_single (self, chooser, "show-device-category");
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
bluetooth_filter_widget_init(BluetoothFilterWidget *self)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
BluetoothFilterWidgetPrivate *priv = BLUETOOTH_FILTER_WIDGET_GET_PRIVATE(self);
|
|
Packit |
8fb625 |
guint i;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
GtkWidget *label;
|
|
Packit |
8fb625 |
GtkWidget *alignment;
|
|
Packit |
8fb625 |
GtkWidget *table;
|
|
Packit |
8fb625 |
GtkCellRenderer *renderer;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
gtk_widget_push_composite_child ();
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_object_set (G_OBJECT (self), "orientation", GTK_ORIENTATION_VERTICAL, NULL);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
gtk_box_set_homogeneous (GTK_BOX (self), FALSE);
|
|
Packit |
8fb625 |
gtk_box_set_spacing (GTK_BOX (self), 6);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
priv->title = gtk_label_new ("");
|
|
Packit |
8fb625 |
/* This is the title of the filter section of the Bluetooth device chooser.
|
|
Packit |
8fb625 |
* It used to say Show Only Bluetooth Devices With... */
|
|
Packit |
8fb625 |
bluetooth_filter_widget_set_title (self, _("Show:"));
|
|
Packit |
8fb625 |
gtk_widget_show (priv->title);
|
|
Packit |
8fb625 |
gtk_box_pack_start (GTK_BOX (self), priv->title, TRUE, TRUE, 0);
|
|
Packit |
8fb625 |
gtk_misc_set_alignment (GTK_MISC (priv->title), 0, 0.5);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
alignment = gtk_alignment_new (0.5, 0.5, 1, 1);
|
|
Packit |
8fb625 |
gtk_widget_show (alignment);
|
|
Packit |
8fb625 |
gtk_box_pack_start (GTK_BOX (self), alignment, TRUE, TRUE, 0);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
table = gtk_grid_new ();
|
|
Packit |
8fb625 |
gtk_widget_show (table);
|
|
Packit |
8fb625 |
gtk_container_add (GTK_CONTAINER (alignment), table);
|
|
Packit |
8fb625 |
gtk_grid_set_row_spacing (GTK_GRID (table), 6);
|
|
Packit |
8fb625 |
gtk_grid_set_column_spacing (GTK_GRID (table), 12);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
/* The device category filter */
|
|
Packit |
8fb625 |
label = gtk_label_new_with_mnemonic (_("Device _category:"));
|
|
Packit |
8fb625 |
gtk_widget_set_no_show_all (label, TRUE);
|
|
Packit |
8fb625 |
gtk_widget_show (label);
|
|
Packit |
8fb625 |
gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
|
|
Packit |
8fb625 |
gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
|
|
Packit |
8fb625 |
priv->device_category_label = label;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
priv->device_category = gtk_combo_box_text_new ();
|
|
Packit |
8fb625 |
gtk_widget_set_no_show_all (priv->device_category, TRUE);
|
|
Packit |
8fb625 |
gtk_widget_show (priv->device_category);
|
|
Packit |
8fb625 |
gtk_grid_attach (GTK_GRID (table), priv->device_category, 1, 0, 1, 1);
|
|
Packit |
8fb625 |
gtk_widget_set_tooltip_text (priv->device_category, _("Select the device category to filter"));
|
|
Packit |
8fb625 |
for (i = 0; i < BLUETOOTH_CATEGORY_NUM_CATEGORIES; i++) {
|
|
Packit |
8fb625 |
gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (priv->device_category),
|
|
Packit |
8fb625 |
_(bluetooth_device_category_to_string (i)));
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
g_signal_connect (G_OBJECT (priv->device_category), "changed",
|
|
Packit |
8fb625 |
G_CALLBACK (filter_category_changed_cb), self);
|
|
Packit |
8fb625 |
gtk_combo_box_set_active (GTK_COMBO_BOX (priv->device_category), priv->device_category_filter);
|
|
Packit |
8fb625 |
if (priv->show_device_category) {
|
|
Packit |
8fb625 |
gtk_widget_show (priv->device_category_label);
|
|
Packit |
8fb625 |
gtk_widget_show (priv->device_category);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
/* The device type filter */
|
|
Packit |
8fb625 |
label = gtk_label_new_with_mnemonic (_("Device _type:"));
|
|
Packit |
8fb625 |
gtk_widget_set_no_show_all (label, TRUE);
|
|
Packit |
8fb625 |
gtk_widget_show (label);
|
|
Packit |
8fb625 |
gtk_grid_attach (GTK_GRID (table), label, 0, 1, 1, 1);
|
|
Packit |
8fb625 |
gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
|
|
Packit |
8fb625 |
priv->device_type_label = label;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
priv->device_type_filter_model = GTK_TREE_MODEL (gtk_list_store_new (DEVICE_TYPE_FILTER_NUM_COLS,
|
|
Packit |
8fb625 |
G_TYPE_STRING, G_TYPE_INT));
|
|
Packit |
8fb625 |
priv->device_type = gtk_combo_box_new_with_model (priv->device_type_filter_model);
|
|
Packit |
8fb625 |
renderer = gtk_cell_renderer_text_new ();
|
|
Packit |
8fb625 |
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (priv->device_type), renderer, TRUE);
|
|
Packit |
8fb625 |
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (priv->device_type), renderer, "text", DEVICE_TYPE_FILTER_COL_NAME);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
gtk_widget_set_no_show_all (priv->device_type, TRUE);
|
|
Packit |
8fb625 |
gtk_widget_show (priv->device_type);
|
|
Packit |
8fb625 |
gtk_grid_attach (GTK_GRID (table), priv->device_type, 1, 1, 1, 1);
|
|
Packit |
8fb625 |
gtk_widget_set_tooltip_text (priv->device_type, _("Select the device type to filter"));
|
|
Packit |
8fb625 |
gtk_list_store_insert_with_values (GTK_LIST_STORE (priv->device_type_filter_model), NULL, G_MAXUINT32,
|
|
Packit |
8fb625 |
DEVICE_TYPE_FILTER_COL_NAME, _(bluetooth_type_to_filter_string (BLUETOOTH_TYPE_ANY)),
|
|
Packit |
8fb625 |
DEVICE_TYPE_FILTER_COL_MASK, BLUETOOTH_TYPE_ANY,
|
|
Packit |
8fb625 |
-1);
|
|
Packit |
8fb625 |
gtk_list_store_insert_with_values (GTK_LIST_STORE (priv->device_type_filter_model), NULL, G_MAXUINT32,
|
|
Packit |
8fb625 |
DEVICE_TYPE_FILTER_COL_NAME, _("Input devices (mice, keyboards, etc.)"),
|
|
Packit |
8fb625 |
DEVICE_TYPE_FILTER_COL_MASK, BLUETOOTH_TYPE_INPUT,
|
|
Packit |
8fb625 |
-1);
|
|
Packit |
8fb625 |
gtk_list_store_insert_with_values (GTK_LIST_STORE (priv->device_type_filter_model), NULL, G_MAXUINT32,
|
|
Packit |
8fb625 |
DEVICE_TYPE_FILTER_COL_NAME, _("Headphones, headsets and other audio devices"),
|
|
Packit |
8fb625 |
DEVICE_TYPE_FILTER_COL_MASK, BLUETOOTH_TYPE_AUDIO,
|
|
Packit |
8fb625 |
-1);
|
|
Packit |
8fb625 |
/* The types match the types used in bluetooth-client.h */
|
|
Packit |
8fb625 |
for (i = 1; i < _BLUETOOTH_TYPE_NUM_TYPES; i++) {
|
|
Packit |
8fb625 |
int mask = 1 << i;
|
|
Packit |
8fb625 |
if (mask & BLUETOOTH_TYPE_INPUT || mask & BLUETOOTH_TYPE_AUDIO)
|
|
Packit |
8fb625 |
continue;
|
|
Packit |
8fb625 |
gtk_list_store_insert_with_values (GTK_LIST_STORE (priv->device_type_filter_model), NULL, G_MAXUINT32,
|
|
Packit |
8fb625 |
DEVICE_TYPE_FILTER_COL_NAME, _(bluetooth_type_to_filter_string (mask)),
|
|
Packit |
8fb625 |
DEVICE_TYPE_FILTER_COL_MASK, mask,
|
|
Packit |
8fb625 |
-1);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
g_signal_connect (G_OBJECT (priv->device_type), "changed",
|
|
Packit |
8fb625 |
G_CALLBACK(filter_type_changed_cb), self);
|
|
Packit |
8fb625 |
set_combobox_from_filter (self);
|
|
Packit |
8fb625 |
if (priv->show_device_type) {
|
|
Packit |
8fb625 |
gtk_widget_show (priv->device_type_label);
|
|
Packit |
8fb625 |
gtk_widget_show (priv->device_type);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
/* The services filter */
|
|
Packit |
8fb625 |
priv->device_service_filter = NULL;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
gtk_widget_pop_composite_child ();
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
bluetooth_filter_widget_finalize (GObject *object)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
BluetoothFilterWidgetPrivate *priv = BLUETOOTH_FILTER_WIDGET_GET_PRIVATE(object);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_free (priv->device_service_filter);
|
|
Packit |
8fb625 |
priv->device_service_filter = NULL;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
G_OBJECT_CLASS(bluetooth_filter_widget_parent_class)->finalize(object);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
bluetooth_filter_widget_dispose (GObject *object)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
BluetoothFilterWidgetPrivate *priv = BLUETOOTH_FILTER_WIDGET_GET_PRIVATE(object);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
if (priv->chooser) {
|
|
Packit |
8fb625 |
g_object_unref (priv->chooser);
|
|
Packit |
8fb625 |
priv->chooser = NULL;
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
G_OBJECT_CLASS(bluetooth_filter_widget_parent_class)->dispose(object);
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
enum {
|
|
Packit |
8fb625 |
PROP_0,
|
|
Packit |
8fb625 |
PROP_SHOW_DEVICE_TYPE,
|
|
Packit |
8fb625 |
PROP_SHOW_DEVICE_CATEGORY,
|
|
Packit |
8fb625 |
PROP_DEVICE_TYPE_FILTER,
|
|
Packit |
8fb625 |
PROP_DEVICE_CATEGORY_FILTER,
|
|
Packit |
8fb625 |
PROP_DEVICE_SERVICE_FILTER
|
|
Packit |
8fb625 |
};
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
bluetooth_filter_widget_set_property (GObject *object, guint prop_id,
|
|
Packit |
8fb625 |
const GValue *value, GParamSpec *pspec)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
BluetoothFilterWidgetPrivate *priv = BLUETOOTH_FILTER_WIDGET_GET_PRIVATE(object);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
switch (prop_id) {
|
|
Packit |
8fb625 |
case PROP_SHOW_DEVICE_TYPE:
|
|
Packit |
8fb625 |
priv->show_device_type = g_value_get_boolean (value);
|
|
Packit |
8fb625 |
g_object_set (G_OBJECT (priv->device_type_label), "visible", priv->show_device_type, NULL);
|
|
Packit |
8fb625 |
g_object_set (G_OBJECT (priv->device_type), "visible", priv->show_device_type, NULL);
|
|
Packit |
8fb625 |
break;
|
|
Packit |
8fb625 |
case PROP_SHOW_DEVICE_CATEGORY:
|
|
Packit |
8fb625 |
priv->show_device_category = g_value_get_boolean (value);
|
|
Packit |
8fb625 |
g_object_set (G_OBJECT (priv->device_category_label), "visible", priv->show_device_category, NULL);
|
|
Packit |
8fb625 |
g_object_set (G_OBJECT (priv->device_category), "visible", priv->show_device_category, NULL);
|
|
Packit |
8fb625 |
break;
|
|
Packit |
8fb625 |
case PROP_DEVICE_TYPE_FILTER:
|
|
Packit |
8fb625 |
priv->device_type_filter = g_value_get_int (value);
|
|
Packit |
8fb625 |
set_combobox_from_filter (BLUETOOTH_FILTER_WIDGET (object));
|
|
Packit |
8fb625 |
break;
|
|
Packit |
8fb625 |
case PROP_DEVICE_CATEGORY_FILTER:
|
|
Packit |
8fb625 |
priv->device_category_filter = g_value_get_enum (value);
|
|
Packit |
8fb625 |
gtk_combo_box_set_active (GTK_COMBO_BOX(priv->device_category), priv->device_category_filter);
|
|
Packit |
8fb625 |
break;
|
|
Packit |
8fb625 |
case PROP_DEVICE_SERVICE_FILTER:
|
|
Packit |
8fb625 |
g_free (priv->device_service_filter);
|
|
Packit |
8fb625 |
priv->device_service_filter = g_value_dup_string (value);
|
|
Packit |
8fb625 |
if (priv->filter)
|
|
Packit |
8fb625 |
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
|
|
Packit |
8fb625 |
break;
|
|
Packit |
8fb625 |
default:
|
|
Packit |
8fb625 |
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
Packit |
8fb625 |
break;
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
bluetooth_filter_widget_get_property (GObject *object, guint prop_id,
|
|
Packit |
8fb625 |
GValue *value, GParamSpec *pspec)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
BluetoothFilterWidgetPrivate *priv = BLUETOOTH_FILTER_WIDGET_GET_PRIVATE(object);
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
switch (prop_id) {
|
|
Packit |
8fb625 |
case PROP_SHOW_DEVICE_TYPE:
|
|
Packit |
8fb625 |
g_value_set_boolean (value, priv->show_device_type);
|
|
Packit |
8fb625 |
break;
|
|
Packit |
8fb625 |
case PROP_SHOW_DEVICE_CATEGORY:
|
|
Packit |
8fb625 |
g_value_set_boolean (value, priv->show_device_category);
|
|
Packit |
8fb625 |
break;
|
|
Packit |
8fb625 |
case PROP_DEVICE_TYPE_FILTER:
|
|
Packit |
8fb625 |
g_value_set_int (value, priv->device_type_filter);
|
|
Packit |
8fb625 |
break;
|
|
Packit |
8fb625 |
case PROP_DEVICE_CATEGORY_FILTER:
|
|
Packit |
8fb625 |
g_value_set_enum (value, priv->device_category_filter);
|
|
Packit |
8fb625 |
break;
|
|
Packit |
8fb625 |
case PROP_DEVICE_SERVICE_FILTER:
|
|
Packit |
8fb625 |
g_value_set_string (value, priv->device_service_filter);
|
|
Packit |
8fb625 |
break;
|
|
Packit |
8fb625 |
default:
|
|
Packit |
8fb625 |
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
Packit |
8fb625 |
break;
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
static void
|
|
Packit |
8fb625 |
bluetooth_filter_widget_class_init (BluetoothFilterWidgetClass *klass)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
/* Use to calculate the maximum value for the
|
|
Packit |
8fb625 |
* device-type-filter value */
|
|
Packit |
8fb625 |
guint i;
|
|
Packit |
8fb625 |
int max_filter_val;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_type_class_add_private(klass, sizeof(BluetoothFilterWidgetPrivate));
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
G_OBJECT_CLASS(klass)->dispose = bluetooth_filter_widget_dispose;
|
|
Packit |
8fb625 |
G_OBJECT_CLASS(klass)->finalize = bluetooth_filter_widget_finalize;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
G_OBJECT_CLASS(klass)->set_property = bluetooth_filter_widget_set_property;
|
|
Packit |
8fb625 |
G_OBJECT_CLASS(klass)->get_property = bluetooth_filter_widget_get_property;
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
g_object_class_install_property (G_OBJECT_CLASS(klass),
|
|
Packit |
8fb625 |
PROP_SHOW_DEVICE_TYPE, g_param_spec_boolean ("show-device-type",
|
|
Packit |
8fb625 |
"show-device-type", "Whether to show the device type filter", TRUE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
|
Packit |
8fb625 |
g_object_class_install_property (G_OBJECT_CLASS(klass),
|
|
Packit |
8fb625 |
PROP_SHOW_DEVICE_CATEGORY, g_param_spec_boolean ("show-device-category",
|
|
Packit |
8fb625 |
"show-device-category", "Whether to show the device category filter", TRUE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
|
Packit |
8fb625 |
for (i = 0, max_filter_val = 0 ; i < _BLUETOOTH_TYPE_NUM_TYPES; i++)
|
|
Packit |
8fb625 |
max_filter_val += 1 << i;
|
|
Packit |
8fb625 |
g_object_class_install_property (G_OBJECT_CLASS(klass),
|
|
Packit |
8fb625 |
PROP_DEVICE_TYPE_FILTER, g_param_spec_int ("device-type-filter",
|
|
Packit |
8fb625 |
"device-type-filter", "A bitmask of #BluetoothType to show", 1, max_filter_val, 1, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
|
Packit |
8fb625 |
g_object_class_install_property (G_OBJECT_CLASS(klass),
|
|
Packit |
8fb625 |
PROP_DEVICE_CATEGORY_FILTER, g_param_spec_enum ("device-category-filter",
|
|
Packit |
8fb625 |
"device-category-filter", "The #BluetoothCategory to show", BLUETOOTH_TYPE_CATEGORY, BLUETOOTH_CATEGORY_ALL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
|
|
Packit |
8fb625 |
g_object_class_install_property (G_OBJECT_CLASS(klass),
|
|
Packit |
8fb625 |
PROP_DEVICE_SERVICE_FILTER, g_param_spec_string ("device-service-filter",
|
|
Packit |
8fb625 |
"device-service-filter", "A string representing the service to filter for", NULL, G_PARAM_WRITABLE));
|
|
Packit |
8fb625 |
}
|
|
Packit |
8fb625 |
|
|
Packit |
8fb625 |
/**
|
|
Packit |
8fb625 |
* bluetooth_filter_widget_new:
|
|
Packit |
8fb625 |
*
|
|
Packit |
8fb625 |
* Creates a new #BluetoothFilterWidget which can be bound to a #BluetoothChooser to
|
|
Packit |
8fb625 |
* control filtering of that #BluetoothChooser.
|
|
Packit |
8fb625 |
* Usually used in conjunction with a #BluetoothChooser which has the "has-internal-filter"
|
|
Packit |
8fb625 |
* property set to FALSE.
|
|
Packit |
8fb625 |
*
|
|
Packit |
8fb625 |
* Return value: A #BluetoothFilterWidget widget
|
|
Packit |
8fb625 |
*
|
|
Packit |
8fb625 |
* Note: Must call bluetooth_filter_widget_bind_filter () to bind the #BluetoothFilterWidget
|
|
Packit |
8fb625 |
* to a #BluetoothChooser.
|
|
Packit |
8fb625 |
**/
|
|
Packit |
8fb625 |
GtkWidget *
|
|
Packit |
8fb625 |
bluetooth_filter_widget_new (void)
|
|
Packit |
8fb625 |
{
|
|
Packit |
8fb625 |
return g_object_new(BLUETOOTH_TYPE_FILTER_WIDGET,
|
|
Packit |
8fb625 |
NULL);
|
|
Packit |
8fb625 |
}
|