keyboard: Don't update binding by hand

Let the CcKeyboardItem update keyval, keymask, etc. for us when
we set the binding value, instead of having us do it by hand.
This commit is contained in:
Bastien Nocera 2011-02-16 01:28:04 +00:00
parent 5c755904e1
commit 6b5fa49cc6
2 changed files with 28 additions and 26 deletions

View file

@ -30,6 +30,7 @@
#include <gconf/gconf-client.h>
#include "cc-keyboard-item.h"
#include "eggaccelerators.h"
#define CC_KEYBOARD_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CC_TYPE_KEYBOARD_ITEM, CcKeyboardItemPrivate))
@ -56,6 +57,30 @@ static void cc_keyboard_item_finalize (GObject *object);
G_DEFINE_TYPE (CcKeyboardItem, cc_keyboard_item, G_TYPE_OBJECT)
static gboolean
binding_from_string (const char *str,
guint *accelerator_key,
guint *keycode,
EggVirtualModifierType *accelerator_mods)
{
g_return_val_if_fail (accelerator_key != NULL, FALSE);
if (str == NULL || strcmp (str, "disabled") == 0)
{
*accelerator_key = 0;
*keycode = 0;
*accelerator_mods = 0;
return TRUE;
}
egg_accelerator_parse_virtual (str, accelerator_key, keycode, accelerator_mods);
if (*accelerator_key == 0)
return FALSE;
else
return TRUE;
}
static void
_set_description (CcKeyboardItem *item,
const char *value)
@ -78,6 +103,7 @@ _set_binding (CcKeyboardItem *item,
{
g_free (item->binding);
item->binding = g_strdup (value);
binding_from_string (item->binding, &item->keyval, &item->keycode, &item->mask);
}
const char *
@ -382,6 +408,7 @@ cc_keyboard_item_load_from_gconf (CcKeyboardItem *item,
(GConfClientNotifyFunc) &keybinding_key_changed,
item, NULL, NULL);
item->binding = gconf_client_get_string (client, item->gconf_key, NULL);
binding_from_string (item->binding, &item->keyval, &item->keycode, &item->mask);
gconf_entry_free (entry);
g_object_unref (client);
@ -438,6 +465,7 @@ cc_keyboard_item_load_from_gconf_dir (CcKeyboardItem *item,
item, NULL, NULL);
item->binding = gconf_client_get_string (client, item->binding_gconf_key, NULL);
binding_from_string (item->binding, &item->keyval, &item->keycode, &item->mask);
gconf_entry_free (entry);
g_object_unref (client);

View file

@ -182,30 +182,6 @@ should_show_key (const KeyListEntry *entry)
return FALSE;
}
static gboolean
binding_from_string (const char *str,
guint *accelerator_key,
guint *keycode,
EggVirtualModifierType *accelerator_mods)
{
g_return_val_if_fail (accelerator_key != NULL, FALSE);
if (str == NULL || strcmp (str, "disabled") == 0)
{
*accelerator_key = 0;
*keycode = 0;
*accelerator_mods = 0;
return TRUE;
}
egg_accelerator_parse_virtual (str, accelerator_key, keycode, accelerator_mods);
if (*accelerator_key == 0)
return FALSE;
else
return TRUE;
}
static gboolean
keybinding_key_changed_foreach (GtkTreeModel *model,
GtkTreePath *path,
@ -232,7 +208,6 @@ item_changed (CcKeyboardItem *item,
gpointer user_data)
{
/* update the model */
binding_from_string (item->binding, &item->keyval, &item->keycode, &item->mask);
gtk_tree_model_foreach (item->model, (GtkTreeModelForeachFunc) keybinding_key_changed_foreach, item);
}
@ -292,7 +267,6 @@ append_section (GtkBuilder *builder,
item->model = shortcut_model;
item->group = group;
binding_from_string (item->binding, &item->keyval, &item->keycode, &item->mask);
g_signal_connect (G_OBJECT (item), "notify",
G_CALLBACK (item_changed), NULL);