2009-01-16 15:02:06 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006-2009 Openismus GmbH
|
|
|
|
*
|
2007-03-18 05:34:24 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2007-03-18 05:34:24 +00:00
|
|
|
*/
|
|
|
|
|
2013-05-07 12:03:52 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2009-01-16 15:02:06 +00:00
|
|
|
#include "gtkimcontextmultipress.h"
|
2008-05-27 23:55:28 +00:00
|
|
|
#include <string.h>
|
2008-12-10 11:58:37 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
#include <gtk/gtkimmodule.h>
|
2007-03-18 05:34:24 +00:00
|
|
|
|
|
|
|
#define AUTOMATIC_COMPOSE_TIMEOUT 1 /* seconds */
|
|
|
|
#define CONFIGURATION_FILENAME MULTIPRESS_CONFDIR G_DIR_SEPARATOR_S "im-multipress.conf"
|
|
|
|
|
2009-01-16 15:02:06 +00:00
|
|
|
/* This contains rows of characters that can be entered by pressing
|
|
|
|
* a particular key repeatedly. Each row has one key (such as GDK_a),
|
|
|
|
* and an array of character strings, such as "a".
|
2007-03-18 05:34:24 +00:00
|
|
|
*/
|
2009-01-16 15:02:06 +00:00
|
|
|
typedef struct
|
2007-03-18 05:34:24 +00:00
|
|
|
{
|
2009-01-16 15:02:06 +00:00
|
|
|
gchar **characters; /* array of strings */
|
|
|
|
gsize n_characters; /* number of strings in the array */
|
|
|
|
}
|
|
|
|
KeySequence;
|
|
|
|
|
|
|
|
static GObjectClass *im_context_multipress_parent_class = NULL;
|
|
|
|
static GType im_context_multipress_type = 0;
|
2007-03-18 05:34:24 +00:00
|
|
|
|
2009-01-16 15:02:06 +00:00
|
|
|
static void im_context_multipress_class_init (GtkImContextMultipressClass *klass);
|
|
|
|
static void im_context_multipress_init (GtkImContextMultipress *self);
|
|
|
|
static void im_context_multipress_finalize (GObject *obj);
|
2007-03-18 05:34:24 +00:00
|
|
|
|
2009-01-16 15:02:06 +00:00
|
|
|
static void load_config (GtkImContextMultipress *self);
|
2007-03-18 05:34:24 +00:00
|
|
|
|
2009-01-16 15:02:06 +00:00
|
|
|
static gboolean vfunc_filter_keypress (GtkIMContext *context,
|
|
|
|
GdkEventKey *event);
|
|
|
|
static void vfunc_reset (GtkIMContext *context);
|
|
|
|
static void vfunc_get_preedit_string (GtkIMContext *context,
|
|
|
|
gchar **str,
|
|
|
|
PangoAttrList **attrs,
|
|
|
|
gint *cursor_pos);
|
2007-03-18 05:34:24 +00:00
|
|
|
|
2008-12-10 11:58:37 +00:00
|
|
|
/* Notice that we have a *_register_type(GTypeModule*) function instead of a
|
|
|
|
* *_get_type() function, because we must use g_type_module_register_type(),
|
|
|
|
* providing the GTypeModule* that was provided to im_context_init(). That
|
|
|
|
* is also why we are not using G_DEFINE_TYPE().
|
2007-03-18 05:34:24 +00:00
|
|
|
*/
|
2008-12-10 11:58:37 +00:00
|
|
|
void
|
2007-03-18 05:34:24 +00:00
|
|
|
gtk_im_context_multipress_register_type (GTypeModule* type_module)
|
|
|
|
{
|
2009-11-06 00:21:09 +00:00
|
|
|
const GTypeInfo im_context_multipress_info =
|
2009-01-16 15:02:06 +00:00
|
|
|
{
|
|
|
|
sizeof (GtkImContextMultipressClass),
|
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) &im_context_multipress_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof (GtkImContextMultipress),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) &im_context_multipress_init,
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
im_context_multipress_type =
|
2008-12-10 11:58:37 +00:00
|
|
|
g_type_module_register_type (type_module,
|
|
|
|
GTK_TYPE_IM_CONTEXT,
|
|
|
|
"GtkImContextMultipress",
|
|
|
|
&im_context_multipress_info, 0);
|
2007-03-18 05:34:24 +00:00
|
|
|
}
|
|
|
|
|
2008-12-10 11:58:37 +00:00
|
|
|
GType
|
|
|
|
gtk_im_context_multipress_get_type (void)
|
2007-03-18 05:34:24 +00:00
|
|
|
{
|
2009-01-16 15:02:06 +00:00
|
|
|
g_assert (im_context_multipress_type != 0);
|
|
|
|
|
|
|
|
return im_context_multipress_type;
|
2007-03-18 05:34:24 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 15:02:06 +00:00
|
|
|
static void
|
|
|
|
key_sequence_free (gpointer value)
|
2007-03-18 05:34:24 +00:00
|
|
|
{
|
2009-01-16 15:02:06 +00:00
|
|
|
KeySequence *seq = value;
|
2007-03-18 05:34:24 +00:00
|
|
|
|
2009-01-16 15:02:06 +00:00
|
|
|
if (seq != NULL)
|
|
|
|
{
|
|
|
|
g_strfreev (seq->characters);
|
|
|
|
g_slice_free (KeySequence, seq);
|
2007-03-18 05:34:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-10 11:58:37 +00:00
|
|
|
static void
|
2009-01-16 15:02:06 +00:00
|
|
|
im_context_multipress_class_init (GtkImContextMultipressClass *klass)
|
2007-03-18 05:34:24 +00:00
|
|
|
{
|
2009-01-16 15:02:06 +00:00
|
|
|
GtkIMContextClass *im_context_class;
|
2007-03-18 05:34:24 +00:00
|
|
|
|
|
|
|
/* Set this so we can use it later: */
|
2009-01-16 15:02:06 +00:00
|
|
|
im_context_multipress_parent_class = g_type_class_peek_parent (klass);
|
2007-03-18 05:34:24 +00:00
|
|
|
|
|
|
|
/* Specify our vfunc implementations: */
|
|
|
|
im_context_class = GTK_IM_CONTEXT_CLASS (klass);
|
2009-01-16 15:02:06 +00:00
|
|
|
im_context_class->filter_keypress = &vfunc_filter_keypress;
|
|
|
|
im_context_class->reset = &vfunc_reset;
|
|
|
|
im_context_class->get_preedit_string = &vfunc_get_preedit_string;
|
2007-03-18 05:34:24 +00:00
|
|
|
|
2009-01-16 15:02:06 +00:00
|
|
|
G_OBJECT_CLASS (klass)->finalize = &im_context_multipress_finalize;
|
2007-03-18 05:34:24 +00:00
|
|
|
}
|
|
|
|
|
2008-12-10 11:58:37 +00:00
|
|
|
static void
|
2009-01-16 15:02:06 +00:00
|
|
|
im_context_multipress_init (GtkImContextMultipress *self)
|
2007-03-18 05:34:24 +00:00
|
|
|
{
|
2009-01-16 15:02:06 +00:00
|
|
|
self->key_sequences = g_hash_table_new_full (&g_direct_hash, &g_direct_equal,
|
|
|
|
NULL, &key_sequence_free);
|
|
|
|
load_config (self);
|
2007-03-18 05:34:24 +00:00
|
|
|
}
|
|
|
|
|
2008-12-10 11:58:37 +00:00
|
|
|
static void
|
2009-01-16 15:02:06 +00:00
|
|
|
im_context_multipress_finalize (GObject *obj)
|
2007-03-18 05:34:24 +00:00
|
|
|
{
|
2009-01-16 15:02:06 +00:00
|
|
|
GtkImContextMultipress *self;
|
2007-03-18 05:34:24 +00:00
|
|
|
|
2009-01-16 15:02:06 +00:00
|
|
|
self = GTK_IM_CONTEXT_MULTIPRESS (obj);
|
2007-03-18 05:34:24 +00:00
|
|
|
|
2009-01-16 15:02:06 +00:00
|
|
|
/* Release the configuration data: */
|
|
|
|
if (self->key_sequences != NULL)
|
2007-03-18 05:34:24 +00:00
|
|
|
{
|
2009-01-16 15:02:06 +00:00
|
|
|
g_hash_table_destroy (self->key_sequences);
|
|
|
|
self->key_sequences = NULL;
|
2007-03-18 05:34:24 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 15:02:06 +00:00
|
|
|
(*im_context_multipress_parent_class->finalize) (obj);
|
2007-03-18 05:34:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-16 15:02:06 +00:00
|
|
|
GtkIMContext *
|
|
|
|
gtk_im_context_multipress_new (void)
|
2007-03-18 05:34:24 +00:00
|
|
|
{
|
2008-12-10 11:58:37 +00:00
|
|
|
return (GtkIMContext *)g_object_new (GTK_TYPE_IM_CONTEXT_MULTIPRESS, NULL);
|
2007-03-18 05:34:24 +00:00
|
|
|
}
|
|
|
|
|
2008-12-10 11:58:37 +00:00
|
|
|
static void
|
2007-03-18 05:34:24 +00:00
|
|
|
cancel_automatic_timeout_commit (GtkImContextMultipress *multipress_context)
|
|
|
|
{
|
|
|
|
if (multipress_context->timeout_id)
|
2008-12-10 11:58:37 +00:00
|
|
|
g_source_remove (multipress_context->timeout_id);
|
2007-03-18 05:34:24 +00:00
|
|
|
|
|
|
|
multipress_context->timeout_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-10 11:58:37 +00:00
|
|
|
/* Clear the compose buffer, so we are ready to compose the next character.
|
2007-03-18 05:34:24 +00:00
|
|
|
*/
|
2008-12-10 11:58:37 +00:00
|
|
|
static void
|
2007-03-18 05:34:24 +00:00
|
|
|
clear_compose_buffer (GtkImContextMultipress *multipress_context)
|
|
|
|
{
|
|
|
|
multipress_context->key_last_entered = 0;
|
|
|
|
multipress_context->compose_count = 0;
|
|
|
|
|
|
|
|
multipress_context->tentative_match = NULL;
|
2008-12-10 11:58:37 +00:00
|
|
|
cancel_automatic_timeout_commit (multipress_context);
|
|
|
|
|
|
|
|
g_signal_emit_by_name (multipress_context, "preedit-changed");
|
|
|
|
g_signal_emit_by_name (multipress_context, "preedit-end");
|
2007-03-18 05:34:24 +00:00
|
|
|
}
|
|
|
|
|
2008-12-10 11:58:37 +00:00
|
|
|
/* Finish composing, provide the character, and clear our compose buffer.
|
2007-03-18 05:34:24 +00:00
|
|
|
*/
|
2008-12-10 11:58:37 +00:00
|
|
|
static void
|
|
|
|
accept_character (GtkImContextMultipress *multipress_context, const gchar *characters)
|
2007-03-18 05:34:24 +00:00
|
|
|
{
|
2008-12-10 11:58:37 +00:00
|
|
|
/* Clear the compose buffer, so we are ready to compose the next character.
|
|
|
|
* Note that if we emit "preedit-changed" after "commit", there's a segfault/
|
|
|
|
* invalid-write with GtkTextView in gtk_text_layout_free_line_display(), when
|
|
|
|
* destroying a PangoLayout (this can also be avoided by not using any Pango
|
|
|
|
* attributes in get_preedit_string(). */
|
2007-03-18 05:34:24 +00:00
|
|
|
clear_compose_buffer (multipress_context);
|
|
|
|
|
2008-12-10 11:58:37 +00:00
|
|
|
/* Provide the character to GTK+ */
|
2007-03-18 05:34:24 +00:00
|
|
|
g_signal_emit_by_name (multipress_context, "commit", characters);
|
|
|
|
}
|
|
|
|
|
2008-12-10 11:58:37 +00:00
|
|
|
static gboolean
|
2007-03-18 05:34:24 +00:00
|
|
|
on_timeout (gpointer data)
|
|
|
|
{
|
2008-12-10 11:58:37 +00:00
|
|
|
GtkImContextMultipress *multipress_context;
|
2007-03-18 05:34:24 +00:00
|
|
|
|
2012-07-30 08:37:32 +00:00
|
|
|
gdk_threads_enter ();
|
2007-03-18 05:34:24 +00:00
|
|
|
|
2008-12-10 11:58:37 +00:00
|
|
|
multipress_context = GTK_IM_CONTEXT_MULTIPRESS (data);
|
2007-03-18 05:34:24 +00:00
|
|
|
|
2008-12-10 11:58:37 +00:00
|
|
|
/* A certain amount of time has passed, so we will assume that the user
|
|
|
|
* really wants the currently chosen character */
|
2007-03-18 05:34:24 +00:00
|
|
|
accept_character (multipress_context, multipress_context->tentative_match);
|
|
|
|
|
|
|
|
multipress_context->timeout_id = 0;
|
|
|
|
|
2012-07-30 08:37:32 +00:00
|
|
|
gdk_threads_leave ();
|
2007-03-18 05:34:24 +00:00
|
|
|
|
2012-01-31 00:12:27 +00:00
|
|
|
return G_SOURCE_REMOVE; /* don't call me again */
|
2007-03-18 05:34:24 +00:00
|
|
|
}
|
|
|
|
|
2008-12-10 11:58:37 +00:00
|
|
|
static gboolean
|
2007-03-18 05:34:24 +00:00
|
|
|
vfunc_filter_keypress (GtkIMContext *context, GdkEventKey *event)
|
|
|
|
{
|
2009-01-16 15:02:06 +00:00
|
|
|
GtkIMContextClass *parent;
|
2008-12-10 11:58:37 +00:00
|
|
|
GtkImContextMultipress *multipress_context;
|
2007-03-18 05:34:24 +00:00
|
|
|
|
2008-12-10 11:58:37 +00:00
|
|
|
multipress_context = GTK_IM_CONTEXT_MULTIPRESS (context);
|
2007-03-18 05:34:24 +00:00
|
|
|
|
2007-06-17 09:48:28 +00:00
|
|
|
if (event->type == GDK_KEY_PRESS)
|
2007-03-18 05:34:24 +00:00
|
|
|
{
|
2009-01-16 15:02:06 +00:00
|
|
|
KeySequence *possible;
|
|
|
|
|
|
|
|
/* Check whether the current key is the same as previously entered, because
|
|
|
|
* if it is not then we should accept the previous one, and start a new
|
|
|
|
* character. */
|
|
|
|
if (multipress_context->compose_count > 0
|
|
|
|
&& multipress_context->key_last_entered != event->keyval
|
|
|
|
&& multipress_context->tentative_match != NULL)
|
|
|
|
{
|
|
|
|
/* Accept the previously chosen character. This wipes
|
|
|
|
* the compose_count and key_last_entered. */
|
|
|
|
accept_character (multipress_context,
|
|
|
|
multipress_context->tentative_match);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Decide what character this key press would choose: */
|
|
|
|
possible = g_hash_table_lookup (multipress_context->key_sequences,
|
|
|
|
GUINT_TO_POINTER (event->keyval));
|
|
|
|
if (possible != NULL)
|
|
|
|
{
|
|
|
|
if (multipress_context->compose_count == 0)
|
|
|
|
g_signal_emit_by_name (multipress_context, "preedit-start");
|
|
|
|
|
|
|
|
/* Check whether we are at the end of a compose sequence, with no more
|
|
|
|
* possible characters. Cycle back to the start if necessary. */
|
|
|
|
if (multipress_context->compose_count >= possible->n_characters)
|
|
|
|
multipress_context->compose_count = 0;
|
|
|
|
|
|
|
|
/* Store the last key pressed in the compose sequence. */
|
|
|
|
multipress_context->key_last_entered = event->keyval;
|
|
|
|
|
|
|
|
/* Get the possible match for this number of presses of the key.
|
|
|
|
* compose_count starts at 1, so that 0 can mean not composing. */
|
|
|
|
multipress_context->tentative_match =
|
|
|
|
possible->characters[multipress_context->compose_count++];
|
|
|
|
|
|
|
|
/* Indicate the current possible character. This will cause our
|
|
|
|
* vfunc_get_preedit_string() vfunc to be called, which will provide
|
|
|
|
* the current possible character for the user to see. */
|
|
|
|
g_signal_emit_by_name (multipress_context, "preedit-changed");
|
|
|
|
|
|
|
|
/* Cancel any outstanding timeout, so we can start the timer again: */
|
|
|
|
cancel_automatic_timeout_commit (multipress_context);
|
|
|
|
|
|
|
|
/* Create a timeout that will cause the currently chosen character to
|
|
|
|
* be committed, if nothing happens for a certain amount of time: */
|
|
|
|
multipress_context->timeout_id =
|
|
|
|
g_timeout_add_seconds (AUTOMATIC_COMPOSE_TIMEOUT,
|
|
|
|
&on_timeout, multipress_context);
|
|
|
|
|
|
|
|
return TRUE; /* key handled */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
guint32 keyval_uchar;
|
|
|
|
|
|
|
|
/* Just accept all other keypresses directly, but commit the
|
|
|
|
* current preedit content first. */
|
|
|
|
if (multipress_context->compose_count > 0
|
|
|
|
&& multipress_context->tentative_match != NULL)
|
|
|
|
{
|
|
|
|
accept_character (multipress_context,
|
|
|
|
multipress_context->tentative_match);
|
|
|
|
}
|
|
|
|
keyval_uchar = gdk_keyval_to_unicode (event->keyval);
|
|
|
|
|
|
|
|
/* Convert to a string for accept_character(). */
|
|
|
|
if (keyval_uchar != 0)
|
|
|
|
{
|
|
|
|
/* max length of UTF-8 sequence = 6 + 1 for NUL termination */
|
|
|
|
gchar keyval_utf8[7];
|
|
|
|
gint length;
|
|
|
|
|
|
|
|
length = g_unichar_to_utf8 (keyval_uchar, keyval_utf8);
|
|
|
|
keyval_utf8[length] = '\0';
|
|
|
|
|
|
|
|
accept_character (multipress_context, keyval_utf8);
|
|
|
|
|
|
|
|
return TRUE; /* key handled */
|
|
|
|
}
|
|
|
|
}
|
2007-03-18 05:34:24 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 15:02:06 +00:00
|
|
|
parent = (GtkIMContextClass *)im_context_multipress_parent_class;
|
|
|
|
|
|
|
|
/* The default implementation just returns FALSE, but it is generally
|
|
|
|
* a good idea to call the base class implementation: */
|
2007-03-18 05:34:24 +00:00
|
|
|
if (parent->filter_keypress)
|
2009-01-16 15:02:06 +00:00
|
|
|
return (*parent->filter_keypress) (context, event);
|
|
|
|
|
|
|
|
return FALSE;
|
2007-03-18 05:34:24 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 15:02:06 +00:00
|
|
|
static void
|
2007-03-18 05:34:24 +00:00
|
|
|
vfunc_reset (GtkIMContext *context)
|
|
|
|
{
|
2009-01-16 15:02:06 +00:00
|
|
|
clear_compose_buffer (GTK_IM_CONTEXT_MULTIPRESS (context));
|
2007-03-18 05:34:24 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 15:02:06 +00:00
|
|
|
static void
|
2007-03-18 05:34:24 +00:00
|
|
|
vfunc_get_preedit_string (GtkIMContext *context,
|
2008-12-10 11:58:37 +00:00
|
|
|
gchar **str,
|
|
|
|
PangoAttrList **attrs,
|
|
|
|
gint *cursor_pos)
|
2007-03-18 05:34:24 +00:00
|
|
|
{
|
|
|
|
gsize len_bytes = 0;
|
|
|
|
gsize len_utf8_chars = 0;
|
|
|
|
|
2009-01-16 15:02:06 +00:00
|
|
|
/* Show the user what character he will get if he accepts: */
|
|
|
|
if (str != NULL)
|
2007-03-18 05:34:24 +00:00
|
|
|
{
|
2009-01-16 15:02:06 +00:00
|
|
|
const gchar *match;
|
|
|
|
|
|
|
|
match = GTK_IM_CONTEXT_MULTIPRESS (context)->tentative_match;
|
|
|
|
|
|
|
|
if (match == NULL)
|
|
|
|
match = ""; /* *str must not be NUL */
|
|
|
|
|
|
|
|
len_bytes = strlen (match); /* byte count */
|
|
|
|
len_utf8_chars = g_utf8_strlen (match, len_bytes); /* character count */
|
|
|
|
|
|
|
|
*str = g_strndup (match, len_bytes);
|
2007-03-18 05:34:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Underline it, to show the user that he is in compose mode: */
|
2009-01-16 15:02:06 +00:00
|
|
|
if (attrs != NULL)
|
2007-03-18 05:34:24 +00:00
|
|
|
{
|
|
|
|
*attrs = pango_attr_list_new ();
|
2008-12-10 11:58:37 +00:00
|
|
|
|
2009-01-16 15:02:06 +00:00
|
|
|
if (len_bytes > 0)
|
2008-12-10 11:58:37 +00:00
|
|
|
{
|
2009-01-16 15:02:06 +00:00
|
|
|
PangoAttribute *attr;
|
|
|
|
|
|
|
|
attr = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE);
|
2008-12-10 11:58:37 +00:00
|
|
|
attr->start_index = 0;
|
2007-03-18 05:34:24 +00:00
|
|
|
attr->end_index = len_bytes;
|
2008-12-10 11:58:37 +00:00
|
|
|
pango_attr_list_insert (*attrs, attr);
|
|
|
|
}
|
2009-01-16 15:02:06 +00:00
|
|
|
}
|
2007-03-18 05:34:24 +00:00
|
|
|
|
|
|
|
if (cursor_pos)
|
|
|
|
*cursor_pos = len_utf8_chars;
|
|
|
|
}
|
|
|
|
|
2009-01-16 15:02:06 +00:00
|
|
|
/* Open the configuration file and fill in the key_sequences hash table
|
|
|
|
* with key/character-list pairs taken from the [keys] group of the file.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
load_config (GtkImContextMultipress *self)
|
2007-03-18 05:34:24 +00:00
|
|
|
{
|
2008-12-10 11:58:37 +00:00
|
|
|
GKeyFile *key_file;
|
2009-01-16 15:02:06 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
gchar **keys;
|
|
|
|
gsize n_keys = 0;
|
|
|
|
gsize i;
|
2007-03-18 05:34:24 +00:00
|
|
|
|
|
|
|
key_file = g_key_file_new ();
|
2009-01-16 15:02:06 +00:00
|
|
|
|
|
|
|
if (!g_key_file_load_from_file (key_file, CONFIGURATION_FILENAME,
|
|
|
|
G_KEY_FILE_NONE, &error))
|
2007-03-18 05:34:24 +00:00
|
|
|
{
|
2009-01-16 15:02:06 +00:00
|
|
|
g_warning ("Error while trying to open the %s configuration file: %s",
|
|
|
|
CONFIGURATION_FILENAME, error->message);
|
2007-03-18 05:34:24 +00:00
|
|
|
g_error_free (error);
|
2009-01-16 15:02:06 +00:00
|
|
|
g_key_file_free (key_file);
|
|
|
|
return;
|
2007-03-18 05:34:24 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 15:02:06 +00:00
|
|
|
keys = g_key_file_get_keys (key_file, "keys", &n_keys, &error);
|
2007-03-18 05:34:24 +00:00
|
|
|
|
2009-01-16 15:02:06 +00:00
|
|
|
if (error != NULL)
|
2007-03-18 05:34:24 +00:00
|
|
|
{
|
2009-01-16 15:02:06 +00:00
|
|
|
g_warning ("Error while trying to read the %s configuration file: %s",
|
|
|
|
CONFIGURATION_FILENAME, error->message);
|
2007-03-18 05:34:24 +00:00
|
|
|
g_error_free (error);
|
2009-01-16 15:02:06 +00:00
|
|
|
g_key_file_free (key_file);
|
|
|
|
return;
|
2007-03-18 05:34:24 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 15:02:06 +00:00
|
|
|
for (i = 0; i < n_keys; ++i)
|
2007-03-18 05:34:24 +00:00
|
|
|
{
|
2009-01-16 15:02:06 +00:00
|
|
|
KeySequence *seq;
|
|
|
|
guint keyval;
|
2007-03-18 05:34:24 +00:00
|
|
|
|
2009-01-16 15:02:06 +00:00
|
|
|
keyval = gdk_keyval_from_name (keys[i]);
|
2007-03-18 05:34:24 +00:00
|
|
|
|
2010-09-08 17:35:51 +00:00
|
|
|
if (keyval == GDK_KEY_VoidSymbol)
|
2007-03-18 05:34:24 +00:00
|
|
|
{
|
2009-01-16 15:02:06 +00:00
|
|
|
g_warning ("Error while trying to read the %s configuration file: "
|
|
|
|
"invalid key name \"%s\"",
|
|
|
|
CONFIGURATION_FILENAME, keys[i]);
|
|
|
|
continue;
|
2007-03-18 05:34:24 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 15:02:06 +00:00
|
|
|
seq = g_slice_new (KeySequence);
|
|
|
|
seq->characters = g_key_file_get_string_list (key_file, "keys", keys[i],
|
|
|
|
&seq->n_characters, &error);
|
|
|
|
if (error != NULL)
|
|
|
|
{
|
|
|
|
g_warning ("Error while trying to read the %s configuration file: %s",
|
|
|
|
CONFIGURATION_FILENAME, error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
error = NULL;
|
|
|
|
g_slice_free (KeySequence, seq);
|
|
|
|
continue;
|
|
|
|
}
|
2007-03-18 05:34:24 +00:00
|
|
|
|
2009-01-16 15:02:06 +00:00
|
|
|
/* Ownership of the KeySequence is taken over by the hash table */
|
|
|
|
g_hash_table_insert (self->key_sequences, GUINT_TO_POINTER (keyval), seq);
|
2007-03-18 05:34:24 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 15:02:06 +00:00
|
|
|
g_strfreev (keys);
|
2007-03-18 05:34:24 +00:00
|
|
|
g_key_file_free (key_file);
|
|
|
|
}
|