[gnome-control-center/wip/gbsneto/new-keyboard-panel: 4/8] keyboard: add API to track whether a shortcut is modified



commit cee87ded572ee0bdc7cb8669737114e80b49be0c
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.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=769063

 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..6f2ad92 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_VALUE_DEFAULT,
   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-value-default");
 }
 
 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_VALUE_DEFAULT:
+    g_value_set_boolean (value, cc_keyboard_item_is_value_default (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_VALUE_DEFAULT,
+                                   g_param_spec_boolean ("is-value-default",
+                                                         "is value default",
+                                                         "is value default",
+                                                         TRUE,
+                                                         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_value_default:
+ * @self: a #CcKeyboardItem
+ *
+ * Retrieves whether the shortcut is the default value or not.
+ *
+ * Returns: %TRUE if the shortcut is the default value, %FALSE otherwise.
+ */
+gboolean
+cc_keyboard_item_is_value_default (CcKeyboardItem *self)
+{
+  GVariant *user_value;
+  gboolean is_value_default;
+
+  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_value_default = user_value == NULL;
+
+  g_clear_pointer (&user_value, g_variant_unref);
+
+  return is_value_default;
+}
+
+/**
+ * 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-value-default");
+}
+
 /*
  * 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..32ee3df 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_value_default (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]