|
Packit Service |
fc05fa |
/*
|
|
Packit Service |
fc05fa |
*
|
|
Packit Service |
fc05fa |
* Copyright (C) 2013 Bastien Nocera <hadess@hadess.net>
|
|
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 |
#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-settings-row.h"
|
|
Packit Service |
fc05fa |
#include "bluetooth-enums.h"
|
|
Packit Service |
fc05fa |
#include "bluetooth-utils.h"
|
|
Packit Service |
fc05fa |
#include "gnome-bluetooth-enum-types.h"
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
#define BLUETOOTH_SETTINGS_ROW_GET_PRIVATE(obj) \
|
|
Packit Service |
fc05fa |
(bluetooth_settings_row_get_instance_private (obj))
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
typedef struct _BluetoothSettingsRowPrivate BluetoothSettingsRowPrivate;
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
struct _BluetoothSettingsRowPrivate {
|
|
Packit Service |
fc05fa |
/* Widget */
|
|
Packit Service |
fc05fa |
GtkWidget *label;
|
|
Packit Service |
fc05fa |
GtkWidget *status;
|
|
Packit Service |
fc05fa |
GtkWidget *spinner;
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
/* Properties */
|
|
Packit Service |
fc05fa |
GDBusProxy *proxy;
|
|
Packit Service |
fc05fa |
gboolean paired;
|
|
Packit Service |
fc05fa |
gboolean trusted;
|
|
Packit Service |
fc05fa |
BluetoothType type;
|
|
Packit Service |
fc05fa |
gboolean connected;
|
|
Packit Service |
fc05fa |
char *name;
|
|
Packit Service |
fc05fa |
char *bdaddr;
|
|
Packit Service |
fc05fa |
gboolean legacy_pairing;
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
gboolean pairing;
|
|
Packit Service |
fc05fa |
};
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
enum {
|
|
Packit Service |
fc05fa |
PROP_0,
|
|
Packit Service |
fc05fa |
PROP_PROXY,
|
|
Packit Service |
fc05fa |
PROP_PAIRED,
|
|
Packit Service |
fc05fa |
PROP_TRUSTED,
|
|
Packit Service |
fc05fa |
PROP_TYPE,
|
|
Packit Service |
fc05fa |
PROP_CONNECTED,
|
|
Packit Service |
fc05fa |
PROP_NAME,
|
|
Packit Service |
fc05fa |
PROP_ADDRESS,
|
|
Packit Service |
fc05fa |
PROP_PAIRING,
|
|
Packit Service |
fc05fa |
PROP_LEGACY_PAIRING
|
|
Packit Service |
fc05fa |
};
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
G_DEFINE_TYPE_WITH_PRIVATE(BluetoothSettingsRow, bluetooth_settings_row, GTK_TYPE_LIST_BOX_ROW)
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
static void
|
|
Packit Service |
fc05fa |
label_might_change (BluetoothSettingsRow *self)
|
|
Packit Service |
fc05fa |
{
|
|
Packit Service |
fc05fa |
BluetoothSettingsRowPrivate *priv = BLUETOOTH_SETTINGS_ROW_GET_PRIVATE (self);
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
if (!priv->paired && !priv->trusted)
|
|
Packit Service |
fc05fa |
gtk_label_set_text (GTK_LABEL (priv->status), _("Not Set Up"));
|
|
Packit Service |
fc05fa |
else if (priv->connected)
|
|
Packit Service |
fc05fa |
gtk_label_set_text (GTK_LABEL (priv->status), _("Connected"));
|
|
Packit Service |
fc05fa |
else
|
|
Packit Service |
fc05fa |
gtk_label_set_text (GTK_LABEL (priv->status), _("Disconnected"));
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
if (priv->pairing)
|
|
Packit Service |
fc05fa |
gtk_widget_show (priv->spinner);
|
|
Packit Service |
fc05fa |
else
|
|
Packit Service |
fc05fa |
gtk_widget_show (priv->status);
|
|
Packit Service |
fc05fa |
}
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
static void
|
|
Packit Service |
fc05fa |
bluetooth_settings_row_init (BluetoothSettingsRow *self)
|
|
Packit Service |
fc05fa |
{
|
|
Packit Service |
fc05fa |
BluetoothSettingsRowPrivate *priv = BLUETOOTH_SETTINGS_ROW_GET_PRIVATE (self);
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
gtk_widget_init_template (GTK_WIDGET (self));
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
/* Placeholder text and spinner */
|
|
Packit Service |
fc05fa |
g_object_bind_property (priv->spinner, "visible",
|
|
Packit Service |
fc05fa |
priv->status, "visible", G_BINDING_INVERT_BOOLEAN | G_BINDING_BIDIRECTIONAL);
|
|
Packit Service |
fc05fa |
g_object_bind_property (priv->spinner, "active",
|
|
Packit Service |
fc05fa |
priv->status, "visible", G_BINDING_INVERT_BOOLEAN | G_BINDING_BIDIRECTIONAL);
|
|
Packit Service |
fc05fa |
}
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
static void
|
|
Packit Service |
fc05fa |
bluetooth_settings_row_finalize (GObject *object)
|
|
Packit Service |
fc05fa |
{
|
|
Packit Service |
fc05fa |
BluetoothSettingsRow *self = BLUETOOTH_SETTINGS_ROW (object);
|
|
Packit Service |
fc05fa |
BluetoothSettingsRowPrivate *priv = BLUETOOTH_SETTINGS_ROW_GET_PRIVATE (self);
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
g_clear_object (&priv->proxy);
|
|
Packit Service |
fc05fa |
g_clear_pointer (&priv->name, g_free);
|
|
Packit Service |
fc05fa |
g_clear_pointer (&priv->bdaddr, g_free);
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
G_OBJECT_CLASS(bluetooth_settings_row_parent_class)->finalize(object);
|
|
Packit Service |
fc05fa |
}
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
static void
|
|
Packit Service |
fc05fa |
bluetooth_settings_row_get_property (GObject *object,
|
|
Packit Service |
fc05fa |
guint property_id,
|
|
Packit Service |
fc05fa |
GValue *value,
|
|
Packit Service |
fc05fa |
GParamSpec *pspec)
|
|
Packit Service |
fc05fa |
{
|
|
Packit Service |
fc05fa |
BluetoothSettingsRow *self = BLUETOOTH_SETTINGS_ROW (object);
|
|
Packit Service |
fc05fa |
BluetoothSettingsRowPrivate *priv = BLUETOOTH_SETTINGS_ROW_GET_PRIVATE (self);
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
switch (property_id) {
|
|
Packit Service |
fc05fa |
case PROP_PROXY:
|
|
Packit Service |
fc05fa |
g_value_set_object (value, priv->proxy);
|
|
Packit Service |
fc05fa |
break;
|
|
Packit Service |
fc05fa |
case PROP_PAIRED:
|
|
Packit Service |
fc05fa |
g_value_set_boolean (value, priv->paired);
|
|
Packit Service |
fc05fa |
break;
|
|
Packit Service |
fc05fa |
case PROP_TRUSTED:
|
|
Packit Service |
fc05fa |
g_value_set_boolean (value, priv->trusted);
|
|
Packit Service |
fc05fa |
break;
|
|
Packit Service |
fc05fa |
case PROP_TYPE:
|
|
Packit Service |
fc05fa |
g_value_set_flags (value, priv->type);
|
|
Packit Service |
fc05fa |
break;
|
|
Packit Service |
fc05fa |
case PROP_CONNECTED:
|
|
Packit Service |
fc05fa |
g_value_set_boolean (value, priv->connected);
|
|
Packit Service |
fc05fa |
break;
|
|
Packit Service |
fc05fa |
case PROP_NAME:
|
|
Packit Service |
fc05fa |
g_value_set_string (value, priv->name);
|
|
Packit Service |
fc05fa |
break;
|
|
Packit Service |
fc05fa |
case PROP_ADDRESS:
|
|
Packit Service |
fc05fa |
g_value_set_string (value, priv->bdaddr);
|
|
Packit Service |
fc05fa |
break;
|
|
Packit Service |
fc05fa |
case PROP_PAIRING:
|
|
Packit Service |
fc05fa |
g_value_set_boolean (value, priv->pairing);
|
|
Packit Service |
fc05fa |
break;
|
|
Packit Service |
fc05fa |
case PROP_LEGACY_PAIRING:
|
|
Packit Service |
fc05fa |
g_value_set_boolean (value, priv->legacy_pairing);
|
|
Packit Service |
fc05fa |
break;
|
|
Packit Service |
fc05fa |
default:
|
|
Packit Service |
fc05fa |
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
|
|
Packit Service |
fc05fa |
break;
|
|
Packit Service |
fc05fa |
}
|
|
Packit Service |
fc05fa |
}
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
static void
|
|
Packit Service |
fc05fa |
update_row (BluetoothSettingsRow *self)
|
|
Packit Service |
fc05fa |
{
|
|
Packit Service |
fc05fa |
BluetoothSettingsRowPrivate *priv = BLUETOOTH_SETTINGS_ROW_GET_PRIVATE (self);
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
if (priv->name == NULL) {
|
|
Packit Service |
fc05fa |
gtk_label_set_text (GTK_LABEL (priv->label),
|
|
Packit Service |
fc05fa |
bluetooth_type_to_string (priv->type));
|
|
Packit Service |
fc05fa |
gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE);
|
|
Packit Service |
fc05fa |
} else {
|
|
Packit Service |
fc05fa |
gtk_label_set_text (GTK_LABEL (priv->label), priv->name);
|
|
Packit Service |
fc05fa |
gtk_widget_set_sensitive (GTK_WIDGET (self), TRUE);
|
|
Packit Service |
fc05fa |
}
|
|
Packit Service |
fc05fa |
}
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
static void
|
|
Packit Service |
fc05fa |
bluetooth_settings_row_set_property (GObject *object,
|
|
Packit Service |
fc05fa |
guint property_id,
|
|
Packit Service |
fc05fa |
const GValue *value,
|
|
Packit Service |
fc05fa |
GParamSpec *pspec)
|
|
Packit Service |
fc05fa |
{
|
|
Packit Service |
fc05fa |
BluetoothSettingsRow *self = BLUETOOTH_SETTINGS_ROW (object);
|
|
Packit Service |
fc05fa |
BluetoothSettingsRowPrivate *priv = BLUETOOTH_SETTINGS_ROW_GET_PRIVATE (self);
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
switch (property_id) {
|
|
Packit Service |
fc05fa |
case PROP_PROXY:
|
|
Packit Service |
fc05fa |
g_clear_object (&priv->proxy);
|
|
Packit Service |
fc05fa |
priv->proxy = g_value_dup_object (value);
|
|
Packit Service |
fc05fa |
break;
|
|
Packit Service |
fc05fa |
case PROP_PAIRED:
|
|
Packit Service |
fc05fa |
priv->paired = g_value_get_boolean (value);
|
|
Packit Service |
fc05fa |
label_might_change (self);
|
|
Packit Service |
fc05fa |
break;
|
|
Packit Service |
fc05fa |
case PROP_TRUSTED:
|
|
Packit Service |
fc05fa |
priv->trusted = g_value_get_boolean (value);
|
|
Packit Service |
fc05fa |
label_might_change (self);
|
|
Packit Service |
fc05fa |
break;
|
|
Packit Service |
fc05fa |
case PROP_TYPE:
|
|
Packit Service |
fc05fa |
priv->type = g_value_get_flags (value);
|
|
Packit Service |
fc05fa |
update_row (self);
|
|
Packit Service |
fc05fa |
break;
|
|
Packit Service |
fc05fa |
case PROP_CONNECTED:
|
|
Packit Service |
fc05fa |
priv->connected = g_value_get_boolean (value);
|
|
Packit Service |
fc05fa |
label_might_change (self);
|
|
Packit Service |
fc05fa |
break;
|
|
Packit Service |
fc05fa |
case PROP_NAME:
|
|
Packit Service |
fc05fa |
g_free (priv->name);
|
|
Packit Service |
fc05fa |
priv->name = g_value_dup_string (value);
|
|
Packit Service |
fc05fa |
update_row (self);
|
|
Packit Service |
fc05fa |
break;
|
|
Packit Service |
fc05fa |
case PROP_ADDRESS:
|
|
Packit Service |
fc05fa |
g_free (priv->bdaddr);
|
|
Packit Service |
fc05fa |
priv->bdaddr = g_value_dup_string (value);
|
|
Packit Service |
fc05fa |
break;
|
|
Packit Service |
fc05fa |
case PROP_PAIRING:
|
|
Packit Service |
fc05fa |
priv->pairing = g_value_get_boolean (value);
|
|
Packit Service |
fc05fa |
label_might_change (self);
|
|
Packit Service |
fc05fa |
break;
|
|
Packit Service |
fc05fa |
case PROP_LEGACY_PAIRING:
|
|
Packit Service |
fc05fa |
priv->legacy_pairing = g_value_get_boolean (value);
|
|
Packit Service |
fc05fa |
break;
|
|
Packit Service |
fc05fa |
default:
|
|
Packit Service |
fc05fa |
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
|
|
Packit Service |
fc05fa |
break;
|
|
Packit Service |
fc05fa |
}
|
|
Packit Service |
fc05fa |
}
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
static void
|
|
Packit Service |
fc05fa |
bluetooth_settings_row_class_init (BluetoothSettingsRowClass *klass)
|
|
Packit Service |
fc05fa |
{
|
|
Packit Service |
fc05fa |
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
Packit Service |
fc05fa |
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
object_class->finalize = bluetooth_settings_row_finalize;
|
|
Packit Service |
fc05fa |
object_class->get_property = bluetooth_settings_row_get_property;
|
|
Packit Service |
fc05fa |
object_class->set_property = bluetooth_settings_row_set_property;
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
g_object_class_install_property (object_class, PROP_PROXY,
|
|
Packit Service |
fc05fa |
g_param_spec_object ("proxy", NULL,
|
|
Packit Service |
fc05fa |
"The D-Bus object path of the device",
|
|
Packit Service |
fc05fa |
G_TYPE_DBUS_PROXY, G_PARAM_READWRITE));
|
|
Packit Service |
fc05fa |
g_object_class_install_property (object_class, PROP_PAIRED,
|
|
Packit Service |
fc05fa |
g_param_spec_boolean ("paired", NULL,
|
|
Packit Service |
fc05fa |
"Paired",
|
|
Packit Service |
fc05fa |
FALSE, G_PARAM_READWRITE));
|
|
Packit Service |
fc05fa |
g_object_class_install_property (object_class, PROP_TRUSTED,
|
|
Packit Service |
fc05fa |
g_param_spec_boolean ("trusted", NULL,
|
|
Packit Service |
fc05fa |
"Trusted",
|
|
Packit Service |
fc05fa |
FALSE, G_PARAM_READWRITE));
|
|
Packit Service |
fc05fa |
g_object_class_install_property (object_class, PROP_TYPE,
|
|
Packit Service |
fc05fa |
g_param_spec_flags ("type", NULL,
|
|
Packit Service |
fc05fa |
"Type",
|
|
Packit Service |
fc05fa |
BLUETOOTH_TYPE_TYPE, BLUETOOTH_TYPE_ANY, G_PARAM_READWRITE));
|
|
Packit Service |
fc05fa |
g_object_class_install_property (object_class, PROP_CONNECTED,
|
|
Packit Service |
fc05fa |
g_param_spec_boolean ("connected", NULL,
|
|
Packit Service |
fc05fa |
"Connected",
|
|
Packit Service |
fc05fa |
FALSE, G_PARAM_READWRITE));
|
|
Packit Service |
fc05fa |
g_object_class_install_property (object_class, PROP_NAME,
|
|
Packit Service |
fc05fa |
g_param_spec_string ("name", NULL,
|
|
Packit Service |
fc05fa |
"Name",
|
|
Packit Service |
fc05fa |
NULL, G_PARAM_READWRITE));
|
|
Packit Service |
fc05fa |
g_object_class_install_property (object_class, PROP_ADDRESS,
|
|
Packit Service |
fc05fa |
g_param_spec_string ("address", NULL,
|
|
Packit Service |
fc05fa |
"Address",
|
|
Packit Service |
fc05fa |
NULL, G_PARAM_READWRITE));
|
|
Packit Service |
fc05fa |
g_object_class_install_property (object_class, PROP_PAIRING,
|
|
Packit Service |
fc05fa |
g_param_spec_boolean ("pairing", NULL,
|
|
Packit Service |
fc05fa |
"Pairing",
|
|
Packit Service |
fc05fa |
FALSE, G_PARAM_READWRITE));
|
|
Packit Service |
fc05fa |
g_object_class_install_property (object_class, PROP_LEGACY_PAIRING,
|
|
Packit Service |
fc05fa |
g_param_spec_boolean ("legacy-pairing", NULL,
|
|
Packit Service |
fc05fa |
"Legacy pairing",
|
|
Packit Service |
fc05fa |
FALSE, G_PARAM_READWRITE));
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
/* Bind class to template */
|
|
Packit Service |
fc05fa |
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/bluetooth/bluetooth-settings-row.ui");
|
|
Packit Service |
fc05fa |
gtk_widget_class_bind_template_child_private (widget_class, BluetoothSettingsRow, label);
|
|
Packit Service |
fc05fa |
gtk_widget_class_bind_template_child_private (widget_class, BluetoothSettingsRow, spinner);
|
|
Packit Service |
fc05fa |
gtk_widget_class_bind_template_child_private (widget_class, BluetoothSettingsRow, status);
|
|
Packit Service |
fc05fa |
}
|
|
Packit Service |
fc05fa |
|
|
Packit Service |
fc05fa |
/**
|
|
Packit Service |
fc05fa |
* bluetooth_settings_row_new:
|
|
Packit Service |
fc05fa |
*
|
|
Packit Service |
fc05fa |
* Returns a new #BluetoothSettingsRow widget.
|
|
Packit Service |
fc05fa |
*
|
|
Packit Service |
fc05fa |
* Return value: A #BluetoothSettingsRow widget
|
|
Packit Service |
fc05fa |
**/
|
|
Packit Service |
fc05fa |
GtkWidget *
|
|
Packit Service |
fc05fa |
bluetooth_settings_row_new (void)
|
|
Packit Service |
fc05fa |
{
|
|
Packit Service |
fc05fa |
return g_object_new (BLUETOOTH_TYPE_SETTINGS_ROW, NULL);
|
|
Packit Service |
fc05fa |
}
|