[gnome-control-center/wip/gbsneto/new-keyboard-panel: 12/15] keyboard: add API to track whether a shortcut is modified
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/gbsneto/new-keyboard-panel: 12/15] keyboard: add API to track whether a shortcut is modified
- Date: Thu, 21 Jul 2016 21:41:21 +0000 (UTC)
commit fff32bd6e66a5a58e925e0d8941490ea6e93666e
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Mon Jul 18 20:58:49 2016 -0300
keyboard: add API to track whether a shortcut is modified
The current keyboard item API does not track whether the
keyboard shortcut is modified or not. In order to properly
implement the Reset operation, the keyboard item must receive
this API and ideally handle it internally.
This patch adds the necessary API to CcKeyboardItem to track
whether the shortcut is modified.
panels/keyboard/cc-keyboard-item.c | 59 ++++++++++++++++++++++++++++++++++++
panels/keyboard/cc-keyboard-item.h | 4 ++
2 files changed, 63 insertions(+), 0 deletions(-)
---
diff --git a/panels/keyboard/cc-keyboard-item.c b/panels/keyboard/cc-keyboard-item.c
index 887bdc6..e8d5271 100644
--- a/panels/keyboard/cc-keyboard-item.c
+++ b/panels/keyboard/cc-keyboard-item.c
@@ -50,6 +50,7 @@ enum {
PROP_BINDING,
PROP_EDITABLE,
PROP_TYPE,
+ PROP_IS_MODIFIED,
PROP_COMMAND
};
@@ -155,6 +156,8 @@ _set_binding (CcKeyboardItem *item,
return;
settings_set_binding (item->settings, item->key, item->priv->binding);
+
+ g_object_notify (G_OBJECT (item), "is-modified");
}
static void
@@ -232,6 +235,9 @@ cc_keyboard_item_get_property (GObject *object,
case PROP_COMMAND:
g_value_set_string (value, self->command);
break;
+ case PROP_IS_MODIFIED:
+ g_value_set_boolean (value, cc_keyboard_item_is_modified (self));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -304,6 +310,14 @@ cc_keyboard_item_class_init (CcKeyboardItemClass *klass)
NULL,
G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_IS_MODIFIED,
+ g_param_spec_boolean ("is-modified",
+ "is-modified",
+ "is-modified",
+ FALSE,
+ G_PARAM_READABLE));
+
g_type_class_add_private (klass, sizeof (CcKeyboardItemPrivate));
}
@@ -508,6 +522,51 @@ cc_keyboard_item_is_hidden (CcKeyboardItem *item)
{
return item->priv->hidden;
}
+
+/**
+ * cc_keyboard_item_is_modified:
+ * @self: a #CcKeyboardItem
+ *
+ * Retrieves whether the shortcut is modified or not.
+ *
+ * Returns: %TRUE if the shortcut is modified, %FALSE otherwise.
+ */
+gboolean
+cc_keyboard_item_is_modified (CcKeyboardItem *self)
+{
+ GVariant *user_value;
+ gboolean is_modified;
+
+ g_return_val_if_fail (CC_IS_KEYBOARD_ITEM (self), FALSE);
+
+ /* When the shortcut is custom, we don't treat it as modified */
+ if (self->type == CC_KEYBOARD_ITEM_TYPE_GSETTINGS_PATH)
+ return FALSE;
+
+ user_value = g_settings_get_user_value (self->settings, self->key);
+ is_modified = user_value != NULL;
+
+ g_clear_pointer (&user_value, g_variant_unref);
+
+ return is_modified;
+}
+
+/**
+ * cc_keyboard_item_reset:
+ * @self: a #CcKeyboardItem
+ *
+ * Reset the keyboard binding to the default value.
+ */
+void
+cc_keyboard_item_reset (CcKeyboardItem *self)
+{
+ g_return_if_fail (CC_IS_KEYBOARD_ITEM (self));
+
+ g_settings_reset (self->settings, self->key);
+
+ g_object_notify (G_OBJECT (self), "is-modified");
+}
+
/*
* vim: sw=2 ts=8 cindent noai bs=2
*/
diff --git a/panels/keyboard/cc-keyboard-item.h b/panels/keyboard/cc-keyboard-item.h
index afe99b6..f2e258d 100644
--- a/panels/keyboard/cc-keyboard-item.h
+++ b/panels/keyboard/cc-keyboard-item.h
@@ -109,6 +109,10 @@ void cc_keyboard_item_set_hidden (CcKeyboardItem *item,
gboolean hidden);
gboolean cc_keyboard_item_is_hidden (CcKeyboardItem *item);
+gboolean cc_keyboard_item_is_modified (CcKeyboardItem *self);
+
+void cc_keyboard_item_reset (CcKeyboardItem *self);
+
G_END_DECLS
#endif /* __CC_KEYBOARD_ITEM_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]