Revamp server-client API.
This commit is contained in:
		@ -18,29 +18,43 @@
 | 
			
		||||
 | 
			
		||||
lib_LTLIBRARIES = libeekboard.la
 | 
			
		||||
 | 
			
		||||
libeekboard_headers =					\
 | 
			
		||||
	eekboard.h					\
 | 
			
		||||
	eekboard-eekboard.h				\
 | 
			
		||||
	eekboard-context.h
 | 
			
		||||
libeekboard_private_headers = \
 | 
			
		||||
libeekboard_headers =				\
 | 
			
		||||
	eekboard-service.h			\
 | 
			
		||||
	eekboard-context-service.h		\
 | 
			
		||||
	eekboard-client.h			\
 | 
			
		||||
	eekboard-context.h			\
 | 
			
		||||
	eekboard-xklutil.h
 | 
			
		||||
libeekboard_private_headers =			\
 | 
			
		||||
	eekboard-marshalers.h
 | 
			
		||||
libeekboard_sources =				\
 | 
			
		||||
	eekboard-eekboard.c			\
 | 
			
		||||
	eekboard-context.c
 | 
			
		||||
	eekboard-service.c			\
 | 
			
		||||
	eekboard-context-service.c		\
 | 
			
		||||
	eekboard-client.c			\
 | 
			
		||||
	eekboard-context.c			\
 | 
			
		||||
	eekboard-xklutil.c
 | 
			
		||||
 | 
			
		||||
libeekboard_marshalers_sources =		\
 | 
			
		||||
	eekboard-marshalers.c		\
 | 
			
		||||
	eekboard-marshalers.c			\
 | 
			
		||||
	eekboard-marshalers.h
 | 
			
		||||
 | 
			
		||||
BUILT_SOURCES = \
 | 
			
		||||
BUILT_SOURCES =					\
 | 
			
		||||
	$(libeekboard_marshalers_sources)
 | 
			
		||||
 | 
			
		||||
libeekboard_la_SOURCES = \
 | 
			
		||||
	$(libeekboard_sources) \
 | 
			
		||||
libeekboard_la_SOURCES =			\
 | 
			
		||||
	$(libeekboard_sources)			\
 | 
			
		||||
	eekboard-marshalers.c
 | 
			
		||||
 | 
			
		||||
libeekboard_la_CFLAGS = -DEEKBOARD_COMPILATION=1 -I$(top_srcdir) $(GIO2_CFLAGS)
 | 
			
		||||
libeekboard_la_LIBADD = $(top_builddir)/eek/libeek.la $(GIO2_LIBS)
 | 
			
		||||
libeekboard_la_CFLAGS =					\
 | 
			
		||||
	-DEEKBOARD_COMPILATION=1			\
 | 
			
		||||
	-DKEYBOARDDIR=\"$(pkgdatadir)/keyboards\"	\
 | 
			
		||||
	-I$(top_srcdir)					\
 | 
			
		||||
	$(GIO2_CFLAGS)					\
 | 
			
		||||
	$(LIBXKLAVIER_CFLAGS)
 | 
			
		||||
libeekboard_la_LIBADD =				\
 | 
			
		||||
	$(top_builddir)/eek/libeek.la		\
 | 
			
		||||
	$(top_builddir)/eek/libeek-xkl.la	\
 | 
			
		||||
	$(GIO2_LIBS)				\
 | 
			
		||||
	$(LIBXKLAVIER_LIBS)
 | 
			
		||||
 | 
			
		||||
eekboarddir = $(includedir)/eekboard-$(EEK_API_VERSION)/eekboard
 | 
			
		||||
eekboard_HEADERS = $(libeekboard_headers)
 | 
			
		||||
 | 
			
		||||
@ -17,17 +17,17 @@
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * SECTION:eekboard-eekboard
 | 
			
		||||
 * SECTION:eekboard-client
 | 
			
		||||
 * @short_description: D-Bus proxy of eekboard-server
 | 
			
		||||
 *
 | 
			
		||||
 * The #EekboardEekboard class provides a client side access to eekboard-server.
 | 
			
		||||
 * The #EekboardClient class provides a client side access to eekboard-server.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifdef HAVE_CONFIG_H
 | 
			
		||||
#include "config.h"
 | 
			
		||||
#endif  /* HAVE_CONFIG_H */
 | 
			
		||||
 | 
			
		||||
#include "eekboard/eekboard-eekboard.h"
 | 
			
		||||
#include "eekboard/eekboard-client.h"
 | 
			
		||||
 | 
			
		||||
enum {
 | 
			
		||||
    DESTROYED,
 | 
			
		||||
@ -36,53 +36,53 @@ enum {
 | 
			
		||||
 | 
			
		||||
static guint signals[LAST_SIGNAL] = { 0, };
 | 
			
		||||
 | 
			
		||||
G_DEFINE_TYPE (EekboardEekboard, eekboard_eekboard, G_TYPE_DBUS_PROXY);
 | 
			
		||||
G_DEFINE_TYPE (EekboardClient, eekboard_client, G_TYPE_DBUS_PROXY);
 | 
			
		||||
 | 
			
		||||
#define EEKBOARD_EEKBOARD_GET_PRIVATE(obj)                               \
 | 
			
		||||
    (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EEKBOARD_TYPE_EEKBOARD, EekboardEekboardPrivate))
 | 
			
		||||
#define EEKBOARD_CLIENT_GET_PRIVATE(obj)                               \
 | 
			
		||||
    (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EEKBOARD_TYPE_CLIENT, EekboardClientPrivate))
 | 
			
		||||
 | 
			
		||||
struct _EekboardEekboardPrivate
 | 
			
		||||
struct _EekboardClientPrivate
 | 
			
		||||
{
 | 
			
		||||
    GHashTable *context_hash;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
eekboard_eekboard_real_destroyed (EekboardEekboard *self)
 | 
			
		||||
eekboard_client_real_destroyed (EekboardClient *self)
 | 
			
		||||
{
 | 
			
		||||
    EekboardEekboardPrivate *priv = EEKBOARD_EEKBOARD_GET_PRIVATE(self);
 | 
			
		||||
    EekboardClientPrivate *priv = EEKBOARD_CLIENT_GET_PRIVATE(self);
 | 
			
		||||
 | 
			
		||||
    // g_debug ("eekboard_eekboard_real_destroyed");
 | 
			
		||||
    // g_debug ("eekboard_client_real_destroyed");
 | 
			
		||||
    g_hash_table_remove_all (priv->context_hash);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
eekboard_eekboard_dispose (GObject *object)
 | 
			
		||||
eekboard_client_dispose (GObject *object)
 | 
			
		||||
{
 | 
			
		||||
    EekboardEekboardPrivate *priv = EEKBOARD_EEKBOARD_GET_PRIVATE(object);
 | 
			
		||||
    EekboardClientPrivate *priv = EEKBOARD_CLIENT_GET_PRIVATE(object);
 | 
			
		||||
 | 
			
		||||
    if (priv->context_hash) {
 | 
			
		||||
        g_hash_table_destroy (priv->context_hash);
 | 
			
		||||
        priv->context_hash = NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    G_OBJECT_CLASS (eekboard_eekboard_parent_class)->dispose (object);
 | 
			
		||||
    G_OBJECT_CLASS (eekboard_client_parent_class)->dispose (object);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
eekboard_eekboard_class_init (EekboardEekboardClass *klass)
 | 
			
		||||
eekboard_client_class_init (EekboardClientClass *klass)
 | 
			
		||||
{
 | 
			
		||||
    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 | 
			
		||||
 | 
			
		||||
    g_type_class_add_private (gobject_class,
 | 
			
		||||
                              sizeof (EekboardEekboardPrivate));
 | 
			
		||||
                              sizeof (EekboardClientPrivate));
 | 
			
		||||
 | 
			
		||||
    klass->destroyed = eekboard_eekboard_real_destroyed;
 | 
			
		||||
    klass->destroyed = eekboard_client_real_destroyed;
 | 
			
		||||
 | 
			
		||||
    gobject_class->dispose = eekboard_eekboard_dispose;
 | 
			
		||||
    gobject_class->dispose = eekboard_client_dispose;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * EekboardEekboard::destroyed:
 | 
			
		||||
     * @eekboard: an #EekboardEekboard
 | 
			
		||||
     * EekboardClient::destroyed:
 | 
			
		||||
     * @eekboard: an #EekboardClient
 | 
			
		||||
     *
 | 
			
		||||
     * The ::destroyed signal is emitted each time the name of remote
 | 
			
		||||
     * end is vanished.
 | 
			
		||||
@ -91,7 +91,7 @@ eekboard_eekboard_class_init (EekboardEekboardClass *klass)
 | 
			
		||||
        g_signal_new (I_("destroyed"),
 | 
			
		||||
                      G_TYPE_FROM_CLASS(gobject_class),
 | 
			
		||||
                      G_SIGNAL_RUN_LAST,
 | 
			
		||||
                      G_STRUCT_OFFSET(EekboardEekboardClass, destroyed),
 | 
			
		||||
                      G_STRUCT_OFFSET(EekboardClientClass, destroyed),
 | 
			
		||||
                      NULL,
 | 
			
		||||
                      NULL,
 | 
			
		||||
                      g_cclosure_marshal_VOID__VOID,
 | 
			
		||||
@ -100,11 +100,11 @@ eekboard_eekboard_class_init (EekboardEekboardClass *klass)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
eekboard_eekboard_init (EekboardEekboard *self)
 | 
			
		||||
eekboard_client_init (EekboardClient *self)
 | 
			
		||||
{
 | 
			
		||||
    EekboardEekboardPrivate *priv;
 | 
			
		||||
    EekboardClientPrivate *priv;
 | 
			
		||||
 | 
			
		||||
    priv = self->priv = EEKBOARD_EEKBOARD_GET_PRIVATE(self);
 | 
			
		||||
    priv = self->priv = EEKBOARD_CLIENT_GET_PRIVATE(self);
 | 
			
		||||
    priv->context_hash =
 | 
			
		||||
        g_hash_table_new_full (g_str_hash,
 | 
			
		||||
                               g_str_equal,
 | 
			
		||||
@ -117,19 +117,19 @@ eekboard_name_vanished_callback (GDBusConnection *connection,
 | 
			
		||||
                                 const gchar     *name,
 | 
			
		||||
                                 gpointer         user_data)
 | 
			
		||||
{
 | 
			
		||||
    EekboardEekboard *eekboard = user_data;
 | 
			
		||||
    EekboardClient *eekboard = user_data;
 | 
			
		||||
    g_signal_emit_by_name (eekboard, "destroyed", NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * eekboard_eekboard_new:
 | 
			
		||||
 * eekboard_client_new:
 | 
			
		||||
 * @connection: a #GDBusConnection
 | 
			
		||||
 * @cancellable: a #GCancellable
 | 
			
		||||
 *
 | 
			
		||||
 * Create a D-Bus proxy of eekboard-eekboard.
 | 
			
		||||
 */
 | 
			
		||||
EekboardEekboard *
 | 
			
		||||
eekboard_eekboard_new (GDBusConnection *connection,
 | 
			
		||||
EekboardClient *
 | 
			
		||||
eekboard_client_new (GDBusConnection *connection,
 | 
			
		||||
                       GCancellable    *cancellable)
 | 
			
		||||
{
 | 
			
		||||
    GInitable *initable;
 | 
			
		||||
@ -139,16 +139,16 @@ eekboard_eekboard_new (GDBusConnection *connection,
 | 
			
		||||
 | 
			
		||||
    error = NULL;
 | 
			
		||||
    initable =
 | 
			
		||||
        g_initable_new (EEKBOARD_TYPE_EEKBOARD,
 | 
			
		||||
        g_initable_new (EEKBOARD_TYPE_CLIENT,
 | 
			
		||||
                        cancellable,
 | 
			
		||||
                        &error,
 | 
			
		||||
                        "g-connection", connection,
 | 
			
		||||
                        "g-name", "org.fedorahosted.Eekboard.Server",
 | 
			
		||||
                        "g-interface-name", "org.fedorahosted.Eekboard.Server",
 | 
			
		||||
                        "g-object-path", "/org/fedorahosted/Eekboard/Server",
 | 
			
		||||
                        "g-name", "org.fedorahosted.Eekboard",
 | 
			
		||||
                        "g-interface-name", "org.fedorahosted.Eekboard",
 | 
			
		||||
                        "g-object-path", "/org/fedorahosted/Eekboard",
 | 
			
		||||
                        NULL);
 | 
			
		||||
    if (initable != NULL) {
 | 
			
		||||
        EekboardEekboard *eekboard = EEKBOARD_EEKBOARD (initable);
 | 
			
		||||
        EekboardClient *eekboard = EEKBOARD_CLIENT (initable);
 | 
			
		||||
        gchar *name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY(eekboard));
 | 
			
		||||
        if (name_owner == NULL) {
 | 
			
		||||
            g_object_unref (eekboard);
 | 
			
		||||
@ -174,16 +174,16 @@ static void
 | 
			
		||||
on_context_destroyed (EekboardContext *context,
 | 
			
		||||
                      gpointer         user_data)
 | 
			
		||||
{
 | 
			
		||||
    EekboardEekboard *eekboard = user_data;
 | 
			
		||||
    EekboardEekboardPrivate *priv = EEKBOARD_EEKBOARD_GET_PRIVATE(eekboard);
 | 
			
		||||
    EekboardClient *eekboard = user_data;
 | 
			
		||||
    EekboardClientPrivate *priv = EEKBOARD_CLIENT_GET_PRIVATE(eekboard);
 | 
			
		||||
 | 
			
		||||
    g_hash_table_remove (priv->context_hash,
 | 
			
		||||
                         g_dbus_proxy_get_object_path (G_DBUS_PROXY(context)));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * eekboard_eekboard_create_context:
 | 
			
		||||
 * @eekboard: an #EekboardEekboard
 | 
			
		||||
 * eekboard_client_create_context:
 | 
			
		||||
 * @eekboard: an #EekboardClient
 | 
			
		||||
 * @client_name: name of the client
 | 
			
		||||
 * @cancellable: a #GCancellable
 | 
			
		||||
 *
 | 
			
		||||
@ -192,14 +192,14 @@ on_context_destroyed (EekboardContext *context,
 | 
			
		||||
 * Return value: (transfer full): a newly created #EekboardContext.
 | 
			
		||||
 */
 | 
			
		||||
EekboardContext *
 | 
			
		||||
eekboard_eekboard_create_context (EekboardEekboard *eekboard,
 | 
			
		||||
eekboard_client_create_context (EekboardClient *eekboard,
 | 
			
		||||
                                  const gchar      *client_name,
 | 
			
		||||
                                  GCancellable     *cancellable)
 | 
			
		||||
{
 | 
			
		||||
    GVariant *variant;
 | 
			
		||||
    const gchar *object_path;
 | 
			
		||||
    EekboardContext *context;
 | 
			
		||||
    EekboardEekboardPrivate *priv;
 | 
			
		||||
    EekboardClientPrivate *priv;
 | 
			
		||||
    GError *error;
 | 
			
		||||
    GDBusConnection *connection;
 | 
			
		||||
 | 
			
		||||
@ -225,7 +225,7 @@ eekboard_eekboard_create_context (EekboardEekboard *eekboard,
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    priv = EEKBOARD_EEKBOARD_GET_PRIVATE(eekboard);
 | 
			
		||||
    priv = EEKBOARD_CLIENT_GET_PRIVATE(eekboard);
 | 
			
		||||
    g_hash_table_insert (priv->context_hash,
 | 
			
		||||
                         g_strdup (object_path),
 | 
			
		||||
                         g_object_ref (context));
 | 
			
		||||
@ -250,19 +250,19 @@ eekboard_async_ready_callback (GObject      *source_object,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * eekboard_eekboard_push_context:
 | 
			
		||||
 * @eekboard: an #EekboardEekboard
 | 
			
		||||
 * eekboard_client_push_context:
 | 
			
		||||
 * @eekboard: an #EekboardClient
 | 
			
		||||
 * @context: an #EekboardContext
 | 
			
		||||
 * @cancellable: a #GCancellable
 | 
			
		||||
 *
 | 
			
		||||
 * Enable the input context @context and disable the others.
 | 
			
		||||
 */
 | 
			
		||||
void
 | 
			
		||||
eekboard_eekboard_push_context (EekboardEekboard *eekboard,
 | 
			
		||||
eekboard_client_push_context (EekboardClient *eekboard,
 | 
			
		||||
                                EekboardContext  *context,
 | 
			
		||||
                                GCancellable     *cancellable)
 | 
			
		||||
{
 | 
			
		||||
    EekboardEekboardPrivate *priv;
 | 
			
		||||
    EekboardClientPrivate *priv;
 | 
			
		||||
    const gchar *object_path;
 | 
			
		||||
 | 
			
		||||
    g_return_if_fail (EEKBOARD_IS_EEKBOARD(eekboard));
 | 
			
		||||
@ -270,7 +270,7 @@ eekboard_eekboard_push_context (EekboardEekboard *eekboard,
 | 
			
		||||
 | 
			
		||||
    object_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY(context));
 | 
			
		||||
 | 
			
		||||
    priv = EEKBOARD_EEKBOARD_GET_PRIVATE(eekboard);
 | 
			
		||||
    priv = EEKBOARD_CLIENT_GET_PRIVATE(eekboard);
 | 
			
		||||
    context = g_hash_table_lookup (priv->context_hash, object_path);
 | 
			
		||||
    if (!context)
 | 
			
		||||
        return;
 | 
			
		||||
@ -287,14 +287,14 @@ eekboard_eekboard_push_context (EekboardEekboard *eekboard,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * eekboard_eekboard_pop_context:
 | 
			
		||||
 * @eekboard: an #EekboardEekboard
 | 
			
		||||
 * eekboard_client_pop_context:
 | 
			
		||||
 * @eekboard: an #EekboardClient
 | 
			
		||||
 * @cancellable: a #GCancellable
 | 
			
		||||
 *
 | 
			
		||||
 * Disable the current input context and enable the previous one.
 | 
			
		||||
 */
 | 
			
		||||
void
 | 
			
		||||
eekboard_eekboard_pop_context (EekboardEekboard *eekboard,
 | 
			
		||||
eekboard_client_pop_context (EekboardClient *eekboard,
 | 
			
		||||
                               GCancellable     *cancellable)
 | 
			
		||||
{
 | 
			
		||||
    g_return_if_fail (EEKBOARD_IS_EEKBOARD(eekboard));
 | 
			
		||||
@ -310,25 +310,25 @@ eekboard_eekboard_pop_context (EekboardEekboard *eekboard,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * eekboard_eekboard_destroy_context:
 | 
			
		||||
 * @eekboard: an #EekboardEekboard
 | 
			
		||||
 * eekboard_client_destroy_context:
 | 
			
		||||
 * @eekboard: an #EekboardClient
 | 
			
		||||
 * @context: an #EekboardContext
 | 
			
		||||
 * @cancellable: a #GCancellable
 | 
			
		||||
 *
 | 
			
		||||
 * Remove @context from @eekboard.
 | 
			
		||||
 */
 | 
			
		||||
void
 | 
			
		||||
eekboard_eekboard_destroy_context (EekboardEekboard *eekboard,
 | 
			
		||||
eekboard_client_destroy_context (EekboardClient *eekboard,
 | 
			
		||||
                                   EekboardContext  *context,
 | 
			
		||||
                                   GCancellable     *cancellable)
 | 
			
		||||
{
 | 
			
		||||
    EekboardEekboardPrivate *priv;
 | 
			
		||||
    EekboardClientPrivate *priv;
 | 
			
		||||
    const gchar *object_path;
 | 
			
		||||
 | 
			
		||||
    g_return_if_fail (EEKBOARD_IS_EEKBOARD(eekboard));
 | 
			
		||||
    g_return_if_fail (EEKBOARD_IS_CONTEXT(context));
 | 
			
		||||
 | 
			
		||||
    priv = EEKBOARD_EEKBOARD_GET_PRIVATE(eekboard);
 | 
			
		||||
    priv = EEKBOARD_CLIENT_GET_PRIVATE(eekboard);
 | 
			
		||||
 | 
			
		||||
    object_path = g_dbus_proxy_get_object_path (G_DBUS_PROXY(context));
 | 
			
		||||
    g_hash_table_remove (priv->context_hash, object_path);
 | 
			
		||||
							
								
								
									
										75
									
								
								eekboard/eekboard-client.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										75
									
								
								eekboard/eekboard-client.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,75 @@
 | 
			
		||||
/* 
 | 
			
		||||
 * Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
 | 
			
		||||
 * Copyright (C) 2010-2011 Red Hat, Inc.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
 * (at your option) any later version.
 | 
			
		||||
 *
 | 
			
		||||
 * This program 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 General Public License for more details.
 | 
			
		||||
 *
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
#ifndef EEKBOARD_CLIENT_H
 | 
			
		||||
#define EEKBOARD_CLIENT_H 1
 | 
			
		||||
 | 
			
		||||
#define __EEKBOARD_CLIENT_H_INSIDE__ 1
 | 
			
		||||
 | 
			
		||||
#include <gio/gio.h>
 | 
			
		||||
#include "eekboard/eekboard-context.h"
 | 
			
		||||
 | 
			
		||||
G_BEGIN_DECLS
 | 
			
		||||
 | 
			
		||||
#define EEKBOARD_TYPE_CLIENT (eekboard_client_get_type())
 | 
			
		||||
#define EEKBOARD_CLIENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EEKBOARD_TYPE_CLIENT, EekboardClient))
 | 
			
		||||
#define EEKBOARD_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EEKBOARD_TYPE_CLIENT, EekboardClientClass))
 | 
			
		||||
#define EEKBOARD_IS_EEKBOARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EEKBOARD_TYPE_CLIENT))
 | 
			
		||||
#define EEKBOARD_IS_EEKBOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EEKBOARD_TYPE_CLIENT))
 | 
			
		||||
#define EEKBOARD_CLIENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EEKBOARD_TYPE_CLIENT, EekboardClientClass))
 | 
			
		||||
 | 
			
		||||
typedef struct _EekboardClient EekboardClient;
 | 
			
		||||
typedef struct _EekboardClientClass EekboardClientClass;
 | 
			
		||||
typedef struct _EekboardClientPrivate EekboardClientPrivate;
 | 
			
		||||
 | 
			
		||||
struct _EekboardClient {
 | 
			
		||||
    /*< private >*/
 | 
			
		||||
    GDBusProxy parent;
 | 
			
		||||
 | 
			
		||||
    EekboardClientPrivate *priv;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct _EekboardClientClass {
 | 
			
		||||
    /*< private >*/
 | 
			
		||||
    GDBusProxyClass parent_class;
 | 
			
		||||
 | 
			
		||||
    /* signals */
 | 
			
		||||
    void (* destroyed) (EekboardClient *self);
 | 
			
		||||
 | 
			
		||||
    /*< private >*/
 | 
			
		||||
    /* padding */
 | 
			
		||||
    gpointer pdummy[23];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
GType            eekboard_client_get_type        (void) G_GNUC_CONST;
 | 
			
		||||
 | 
			
		||||
EekboardClient  *eekboard_client_new             (GDBusConnection *connection,
 | 
			
		||||
                                                  GCancellable    *cancellable);
 | 
			
		||||
EekboardContext *eekboard_client_create_context  (EekboardClient  *eekboard,
 | 
			
		||||
                                                  const gchar     *client_name,
 | 
			
		||||
                                                  GCancellable    *cancellable);
 | 
			
		||||
void             eekboard_client_push_context    (EekboardClient  *eekboard,
 | 
			
		||||
                                                  EekboardContext *context,
 | 
			
		||||
                                                  GCancellable    *cancellable);
 | 
			
		||||
void             eekboard_client_pop_context     (EekboardClient  *eekboard,
 | 
			
		||||
                                                  GCancellable    *cancellable);
 | 
			
		||||
void             eekboard_client_destroy_context (EekboardClient  *eekboard,
 | 
			
		||||
                                                  EekboardContext *context,
 | 
			
		||||
                                                  GCancellable    *cancellable);
 | 
			
		||||
 | 
			
		||||
G_END_DECLS
 | 
			
		||||
#endif  /* EEKBOARD_CLIENT_H */
 | 
			
		||||
							
								
								
									
										904
									
								
								eekboard/eekboard-context-service.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										904
									
								
								eekboard/eekboard-context-service.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,904 @@
 | 
			
		||||
/* 
 | 
			
		||||
 * Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
 | 
			
		||||
 * Copyright (C) 2010-2011 Red Hat, Inc.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
 * (at your option) any later version.
 | 
			
		||||
 *
 | 
			
		||||
 * This program 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 General Public License for more details.
 | 
			
		||||
 *
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
#ifdef HAVE_CONFIG_H
 | 
			
		||||
#include "config.h"
 | 
			
		||||
#endif  /* HAVE_CONFIG_H */
 | 
			
		||||
 | 
			
		||||
#include "eekboard/eekboard-context-service.h"
 | 
			
		||||
#include "eekboard/eekboard-xklutil.h"
 | 
			
		||||
#include "eek/eek-xkl.h"
 | 
			
		||||
 | 
			
		||||
#define CSW 640
 | 
			
		||||
#define CSH 480
 | 
			
		||||
 | 
			
		||||
enum {
 | 
			
		||||
    PROP_0,
 | 
			
		||||
    PROP_OBJECT_PATH,
 | 
			
		||||
    PROP_CONNECTION,
 | 
			
		||||
    PROP_CLIENT_NAME,
 | 
			
		||||
    PROP_KEYBOARD,
 | 
			
		||||
    PROP_VISIBLE,
 | 
			
		||||
    PROP_FULLSCREEN,
 | 
			
		||||
    PROP_LAST
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
enum {
 | 
			
		||||
    ENABLED,
 | 
			
		||||
    DISABLED,
 | 
			
		||||
    LAST_SIGNAL
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static guint signals[LAST_SIGNAL] = { 0, };
 | 
			
		||||
 | 
			
		||||
#define EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(obj)                       \
 | 
			
		||||
    (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EEKBOARD_TYPE_CONTEXT_SERVICE, EekboardContextServicePrivate))
 | 
			
		||||
 | 
			
		||||
struct _EekboardContextServicePrivate {
 | 
			
		||||
    GDBusConnection *connection;
 | 
			
		||||
    GDBusNodeInfo *introspection_data;
 | 
			
		||||
    guint registration_id;
 | 
			
		||||
    char *object_path;
 | 
			
		||||
    char *client_name;
 | 
			
		||||
 | 
			
		||||
    gboolean enabled;
 | 
			
		||||
    gboolean visible;
 | 
			
		||||
    gboolean fullscreen;
 | 
			
		||||
 | 
			
		||||
    EekKeyboard *keyboard;
 | 
			
		||||
    GHashTable *keyboard_hash;
 | 
			
		||||
 | 
			
		||||
    gulong key_pressed_handler;
 | 
			
		||||
    gulong key_released_handler;
 | 
			
		||||
 | 
			
		||||
    EekKey *repeat_key;
 | 
			
		||||
    guint repeat_timeout_id;
 | 
			
		||||
    gboolean repeat_triggered;
 | 
			
		||||
 | 
			
		||||
    GSettings *settings;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
G_DEFINE_TYPE (EekboardContextService, eekboard_context_service, G_TYPE_OBJECT);
 | 
			
		||||
 | 
			
		||||
static const gchar introspection_xml[] =
 | 
			
		||||
    "<node>"
 | 
			
		||||
    "  <interface name='org.fedorahosted.Eekboard.Context'>"
 | 
			
		||||
    "    <method name='AddKeyboard'>"
 | 
			
		||||
    "      <arg direction='in' type='s' name='keyboard'/>"
 | 
			
		||||
    "      <arg direction='out' type='u' name='keyboard_id'/>"
 | 
			
		||||
    "    </method>"
 | 
			
		||||
    "    <method name='RemoveKeyboard'>"
 | 
			
		||||
    "      <arg direction='in' type='u' name='keyboard_id'/>"
 | 
			
		||||
    "    </method>"
 | 
			
		||||
    "    <method name='SetKeyboard'>"
 | 
			
		||||
    "      <arg type='u' name='keyboard_id'/>"
 | 
			
		||||
    "    </method>"
 | 
			
		||||
    "    <method name='SetFullscreen'>"
 | 
			
		||||
    "      <arg type='b' name='fullscreen'/>"
 | 
			
		||||
    "    </method>"
 | 
			
		||||
    "    <method name='ShowKeyboard'/>"
 | 
			
		||||
    "    <method name='HideKeyboard'/>"
 | 
			
		||||
    "    <method name='SetGroup'>"
 | 
			
		||||
    "      <arg type='i' name='group'/>"
 | 
			
		||||
    "    </method>"
 | 
			
		||||
    "    <method name='PressKeycode'>"
 | 
			
		||||
    "      <arg type='u' name='keycode'/>"
 | 
			
		||||
    "    </method>"
 | 
			
		||||
    "    <method name='ReleaseKeycode'>"
 | 
			
		||||
    "      <arg type='u' name='keycode'/>"
 | 
			
		||||
    "    </method>"
 | 
			
		||||
    /* signals */
 | 
			
		||||
    "    <signal name='Enabled'/>"
 | 
			
		||||
    "    <signal name='Disabled'/>"
 | 
			
		||||
    "    <signal name='KeyPressed'>"
 | 
			
		||||
    "      <arg type='s' name='keyname'/>"
 | 
			
		||||
    "      <arg type='v' name='symbol'/>"
 | 
			
		||||
    "      <arg type='u' name='modifiers'/>"
 | 
			
		||||
    "    </signal>"
 | 
			
		||||
    "    <signal name='VisibilityChanged'>"
 | 
			
		||||
    "      <arg type='b' name='visible'/>"
 | 
			
		||||
    "    </signal>"
 | 
			
		||||
    "    <signal name='KeyboardChanged'>"
 | 
			
		||||
    "      <arg type='u' name='keyboard_id'/>"
 | 
			
		||||
    "    </signal>"
 | 
			
		||||
    "    <signal name='GroupChanged'>"
 | 
			
		||||
    "      <arg type='i' name='group'/>"
 | 
			
		||||
    "    </signal>"
 | 
			
		||||
    "  </interface>"
 | 
			
		||||
    "</node>";
 | 
			
		||||
 | 
			
		||||
static void connect_keyboard_signals (EekboardContextService *context);
 | 
			
		||||
static void disconnect_keyboard_signals
 | 
			
		||||
                                     (EekboardContextService *context);
 | 
			
		||||
static void handle_method_call       (GDBusConnection        *connection,
 | 
			
		||||
                                      const gchar            *sender,
 | 
			
		||||
                                      const gchar            *object_path,
 | 
			
		||||
                                      const gchar            *interface_name,
 | 
			
		||||
                                      const gchar            *method_name,
 | 
			
		||||
                                      GVariant               *parameters,
 | 
			
		||||
                                      GDBusMethodInvocation  *invocation,
 | 
			
		||||
                                      gpointer                user_data);
 | 
			
		||||
static void emit_visibility_changed_signal
 | 
			
		||||
                                     (EekboardContextService *context,
 | 
			
		||||
                                      gboolean                visible);
 | 
			
		||||
 | 
			
		||||
static const GDBusInterfaceVTable interface_vtable =
 | 
			
		||||
{
 | 
			
		||||
  handle_method_call,
 | 
			
		||||
  NULL,
 | 
			
		||||
  NULL
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static EekKeyboard *
 | 
			
		||||
eekboard_context_service_real_create_keyboard (EekboardContextService *self,
 | 
			
		||||
                                               const gchar            *keyboard_type)
 | 
			
		||||
{
 | 
			
		||||
    EekKeyboard *keyboard;
 | 
			
		||||
    EekLayout *layout;
 | 
			
		||||
 | 
			
		||||
    if (g_str_has_prefix (keyboard_type, "xkb:")) {
 | 
			
		||||
        XklConfigRec *rec =
 | 
			
		||||
            eekboard_xkl_config_rec_from_string (&keyboard_type[4]);
 | 
			
		||||
 | 
			
		||||
        layout = eek_xkl_layout_new ();
 | 
			
		||||
        if (!eek_xkl_layout_set_config (EEK_XKL_LAYOUT(layout), rec)) {
 | 
			
		||||
            g_object_unref (layout);
 | 
			
		||||
            return NULL;
 | 
			
		||||
        }
 | 
			
		||||
    } else {
 | 
			
		||||
        gchar *path;
 | 
			
		||||
        GFile *file;
 | 
			
		||||
        GFileInputStream *input;
 | 
			
		||||
        GError *error;
 | 
			
		||||
 | 
			
		||||
        path = g_strdup_printf ("%s/%s.xml", KEYBOARDDIR, keyboard_type);
 | 
			
		||||
        file = g_file_new_for_path (path);
 | 
			
		||||
        g_free (path);
 | 
			
		||||
 | 
			
		||||
        error = NULL;
 | 
			
		||||
        input = g_file_read (file, NULL, &error);
 | 
			
		||||
        if (input == NULL) {
 | 
			
		||||
            g_object_unref (file);
 | 
			
		||||
            return NULL;
 | 
			
		||||
        }
 | 
			
		||||
        layout = eek_xml_layout_new (G_INPUT_STREAM(input));
 | 
			
		||||
    }
 | 
			
		||||
    keyboard = eek_keyboard_new (layout, CSW, CSH);
 | 
			
		||||
    g_object_unref (layout);
 | 
			
		||||
 | 
			
		||||
    return keyboard;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
eekboard_context_service_set_property (GObject      *object,
 | 
			
		||||
                                       guint         prop_id,
 | 
			
		||||
                                       const GValue *value,
 | 
			
		||||
                                       GParamSpec   *pspec)
 | 
			
		||||
{
 | 
			
		||||
    EekboardContextService *context = EEKBOARD_CONTEXT_SERVICE(object);
 | 
			
		||||
    EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context);
 | 
			
		||||
    GDBusConnection *connection;
 | 
			
		||||
    gboolean was_visible;
 | 
			
		||||
 | 
			
		||||
    switch (prop_id) {
 | 
			
		||||
    case PROP_OBJECT_PATH:
 | 
			
		||||
        if (priv->object_path)
 | 
			
		||||
            g_free (priv->object_path);
 | 
			
		||||
        priv->object_path = g_strdup (g_value_get_string (value));
 | 
			
		||||
        break;
 | 
			
		||||
    case PROP_CONNECTION:
 | 
			
		||||
        connection = g_value_get_object (value);
 | 
			
		||||
        if (priv->connection)
 | 
			
		||||
            g_object_unref (priv->connection);
 | 
			
		||||
        priv->connection = g_object_ref (connection);
 | 
			
		||||
        break;
 | 
			
		||||
    case PROP_CLIENT_NAME:
 | 
			
		||||
        if (priv->client_name)
 | 
			
		||||
            g_free (priv->client_name);
 | 
			
		||||
        priv->client_name = g_strdup (g_value_get_string (value));
 | 
			
		||||
        break;
 | 
			
		||||
    case PROP_KEYBOARD:
 | 
			
		||||
        if (priv->keyboard)
 | 
			
		||||
            g_object_unref (priv->keyboard);
 | 
			
		||||
        priv->keyboard = g_value_get_object (value);
 | 
			
		||||
        break;
 | 
			
		||||
    case PROP_VISIBLE:
 | 
			
		||||
        was_visible = priv->visible;
 | 
			
		||||
        priv->visible = g_value_get_boolean (value);
 | 
			
		||||
        if (was_visible != priv->visible)
 | 
			
		||||
            emit_visibility_changed_signal (EEKBOARD_CONTEXT_SERVICE(object),
 | 
			
		||||
                                            priv->visible);
 | 
			
		||||
        break;
 | 
			
		||||
    case PROP_FULLSCREEN:
 | 
			
		||||
        priv->fullscreen = g_value_get_boolean (value);
 | 
			
		||||
        break;
 | 
			
		||||
    default:
 | 
			
		||||
        g_object_set_property (object,
 | 
			
		||||
                               g_param_spec_get_name (pspec),
 | 
			
		||||
                               value);
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
eekboard_context_service_get_property (GObject    *object,
 | 
			
		||||
                                       guint       prop_id,
 | 
			
		||||
                                       GValue     *value,
 | 
			
		||||
                                       GParamSpec *pspec)
 | 
			
		||||
{
 | 
			
		||||
    EekboardContextService *context = EEKBOARD_CONTEXT_SERVICE(object);
 | 
			
		||||
    EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context);
 | 
			
		||||
 | 
			
		||||
    switch (prop_id) {
 | 
			
		||||
    case PROP_OBJECT_PATH:
 | 
			
		||||
        g_value_set_string (value, priv->object_path);
 | 
			
		||||
        break;
 | 
			
		||||
    case PROP_CONNECTION:
 | 
			
		||||
        g_value_set_object (value, priv->connection);
 | 
			
		||||
        break;
 | 
			
		||||
    case PROP_CLIENT_NAME:
 | 
			
		||||
        g_value_set_string (value, priv->client_name);
 | 
			
		||||
        break;
 | 
			
		||||
    case PROP_KEYBOARD:
 | 
			
		||||
        g_value_set_object (value, priv->keyboard);
 | 
			
		||||
        break;
 | 
			
		||||
    case PROP_VISIBLE:
 | 
			
		||||
        g_value_set_boolean (value, priv->visible);
 | 
			
		||||
        break;
 | 
			
		||||
    case PROP_FULLSCREEN:
 | 
			
		||||
        g_value_set_boolean (value, priv->fullscreen);
 | 
			
		||||
        break;
 | 
			
		||||
    default:
 | 
			
		||||
        g_object_set_property (object,
 | 
			
		||||
                               g_param_spec_get_name (pspec),
 | 
			
		||||
                               value);
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
eekboard_context_service_dispose (GObject *object)
 | 
			
		||||
{
 | 
			
		||||
    EekboardContextService *context = EEKBOARD_CONTEXT_SERVICE(object);
 | 
			
		||||
    EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context);
 | 
			
		||||
 | 
			
		||||
    if (priv->keyboard_hash) {
 | 
			
		||||
        g_hash_table_destroy (priv->keyboard_hash);
 | 
			
		||||
        priv->keyboard_hash = NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (priv->connection) {
 | 
			
		||||
        if (priv->registration_id > 0) {
 | 
			
		||||
            g_dbus_connection_unregister_object (priv->connection,
 | 
			
		||||
                                                 priv->registration_id);
 | 
			
		||||
            priv->registration_id = 0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        g_object_unref (priv->connection);
 | 
			
		||||
        priv->connection = NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (priv->introspection_data) {
 | 
			
		||||
        g_dbus_node_info_unref (priv->introspection_data);
 | 
			
		||||
        priv->introspection_data = NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    G_OBJECT_CLASS (eekboard_context_service_parent_class)->dispose (object);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
eekboard_context_service_finalize (GObject *object)
 | 
			
		||||
{
 | 
			
		||||
    EekboardContextService *context = EEKBOARD_CONTEXT_SERVICE(object);
 | 
			
		||||
    EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context);
 | 
			
		||||
 | 
			
		||||
    g_free (priv->object_path);
 | 
			
		||||
    g_free (priv->client_name);
 | 
			
		||||
 | 
			
		||||
    G_OBJECT_CLASS (eekboard_context_service_parent_class)->finalize (object);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
eekboard_context_service_constructed (GObject *object)
 | 
			
		||||
{
 | 
			
		||||
    EekboardContextService *context = EEKBOARD_CONTEXT_SERVICE (object);
 | 
			
		||||
    EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context);
 | 
			
		||||
 | 
			
		||||
    if (priv->connection && priv->object_path) {
 | 
			
		||||
        GError *error = NULL;
 | 
			
		||||
 | 
			
		||||
        priv->registration_id = g_dbus_connection_register_object
 | 
			
		||||
            (priv->connection,
 | 
			
		||||
             priv->object_path,
 | 
			
		||||
             priv->introspection_data->interfaces[0],
 | 
			
		||||
             &interface_vtable,
 | 
			
		||||
             context,
 | 
			
		||||
             NULL,
 | 
			
		||||
             &error);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
eekboard_context_service_class_init (EekboardContextServiceClass *klass)
 | 
			
		||||
{
 | 
			
		||||
    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 | 
			
		||||
    GParamSpec *pspec;
 | 
			
		||||
 | 
			
		||||
    g_type_class_add_private (gobject_class,
 | 
			
		||||
                              sizeof (EekboardContextServicePrivate));
 | 
			
		||||
 | 
			
		||||
    klass->create_keyboard = eekboard_context_service_real_create_keyboard;
 | 
			
		||||
    klass->show_keyboard = NULL;
 | 
			
		||||
    klass->hide_keyboard = NULL;
 | 
			
		||||
 | 
			
		||||
    gobject_class->constructed = eekboard_context_service_constructed;
 | 
			
		||||
    gobject_class->set_property = eekboard_context_service_set_property;
 | 
			
		||||
    gobject_class->get_property = eekboard_context_service_get_property;
 | 
			
		||||
    gobject_class->dispose = eekboard_context_service_dispose;
 | 
			
		||||
    gobject_class->finalize = eekboard_context_service_finalize;
 | 
			
		||||
 | 
			
		||||
    signals[ENABLED] =
 | 
			
		||||
        g_signal_new (I_("enabled"),
 | 
			
		||||
                      G_TYPE_FROM_CLASS(gobject_class),
 | 
			
		||||
                      G_SIGNAL_RUN_LAST,
 | 
			
		||||
                      G_STRUCT_OFFSET(EekboardContextServiceClass, enabled),
 | 
			
		||||
                      NULL,
 | 
			
		||||
                      NULL,
 | 
			
		||||
                      g_cclosure_marshal_VOID__VOID,
 | 
			
		||||
                      G_TYPE_NONE,
 | 
			
		||||
                      0);
 | 
			
		||||
 | 
			
		||||
    signals[DISABLED] =
 | 
			
		||||
        g_signal_new (I_("disabled"),
 | 
			
		||||
                      G_TYPE_FROM_CLASS(gobject_class),
 | 
			
		||||
                      G_SIGNAL_RUN_LAST,
 | 
			
		||||
                      G_STRUCT_OFFSET(EekboardContextServiceClass, disabled),
 | 
			
		||||
                      NULL,
 | 
			
		||||
                      NULL,
 | 
			
		||||
                      g_cclosure_marshal_VOID__VOID,
 | 
			
		||||
                      G_TYPE_NONE,
 | 
			
		||||
                      0);
 | 
			
		||||
 | 
			
		||||
    pspec = g_param_spec_string ("object-path",
 | 
			
		||||
                                 "Object-path",
 | 
			
		||||
                                 "Object-path",
 | 
			
		||||
                                 NULL,
 | 
			
		||||
                                 G_PARAM_CONSTRUCT | G_PARAM_READWRITE);
 | 
			
		||||
    g_object_class_install_property (gobject_class,
 | 
			
		||||
                                     PROP_OBJECT_PATH,
 | 
			
		||||
                                     pspec);
 | 
			
		||||
 | 
			
		||||
    pspec = g_param_spec_object ("connection",
 | 
			
		||||
                                 "Connection",
 | 
			
		||||
                                 "Connection",
 | 
			
		||||
                                 G_TYPE_DBUS_CONNECTION,
 | 
			
		||||
                                 G_PARAM_CONSTRUCT | G_PARAM_READWRITE);
 | 
			
		||||
    g_object_class_install_property (gobject_class,
 | 
			
		||||
                                     PROP_CONNECTION,
 | 
			
		||||
                                     pspec);
 | 
			
		||||
 | 
			
		||||
    pspec = g_param_spec_string ("client-name",
 | 
			
		||||
                                 "Client-name",
 | 
			
		||||
                                 "Client-name",
 | 
			
		||||
                                 NULL,
 | 
			
		||||
                                 G_PARAM_READWRITE);
 | 
			
		||||
    g_object_class_install_property (gobject_class,
 | 
			
		||||
                                     PROP_CLIENT_NAME,
 | 
			
		||||
                                     pspec);
 | 
			
		||||
 | 
			
		||||
    pspec = g_param_spec_object ("keyboard",
 | 
			
		||||
                                 "Keyboard",
 | 
			
		||||
                                 "Keyboard",
 | 
			
		||||
                                 EEK_TYPE_KEYBOARD,
 | 
			
		||||
                                 G_PARAM_READWRITE);
 | 
			
		||||
    g_object_class_install_property (gobject_class,
 | 
			
		||||
                                     PROP_KEYBOARD,
 | 
			
		||||
                                     pspec);
 | 
			
		||||
 | 
			
		||||
    pspec = g_param_spec_boolean ("visible",
 | 
			
		||||
                                  "Visible",
 | 
			
		||||
                                  "Visible",
 | 
			
		||||
                                  FALSE,
 | 
			
		||||
                                  G_PARAM_READWRITE);
 | 
			
		||||
    g_object_class_install_property (gobject_class,
 | 
			
		||||
                                     PROP_VISIBLE,
 | 
			
		||||
                                     pspec);
 | 
			
		||||
 | 
			
		||||
    pspec = g_param_spec_boolean ("fullscreen",
 | 
			
		||||
                                  "Fullscreen",
 | 
			
		||||
                                  "Fullscreen",
 | 
			
		||||
                                  FALSE,
 | 
			
		||||
                                  G_PARAM_READWRITE);
 | 
			
		||||
    g_object_class_install_property (gobject_class,
 | 
			
		||||
                                     PROP_FULLSCREEN,
 | 
			
		||||
                                     pspec);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
eekboard_context_service_init (EekboardContextService *context)
 | 
			
		||||
{
 | 
			
		||||
    EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context);
 | 
			
		||||
    GError *error;
 | 
			
		||||
 | 
			
		||||
    error = NULL;
 | 
			
		||||
    priv->introspection_data =
 | 
			
		||||
        g_dbus_node_info_new_for_xml (introspection_xml, &error);
 | 
			
		||||
    g_assert (priv->introspection_data != NULL);
 | 
			
		||||
 | 
			
		||||
    priv->keyboard_hash =
 | 
			
		||||
        g_hash_table_new_full (g_direct_hash,
 | 
			
		||||
                               g_direct_equal,
 | 
			
		||||
                               NULL,
 | 
			
		||||
                               (GDestroyNotify)g_object_unref);
 | 
			
		||||
 | 
			
		||||
    priv->settings = g_settings_new ("org.fedorahosted.eekboard");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
disconnect_keyboard_signals (EekboardContextService *context)
 | 
			
		||||
{
 | 
			
		||||
    EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context);
 | 
			
		||||
 | 
			
		||||
    if (g_signal_handler_is_connected (priv->keyboard,
 | 
			
		||||
                                       priv->key_pressed_handler))
 | 
			
		||||
        g_signal_handler_disconnect (priv->keyboard,
 | 
			
		||||
                                     priv->key_pressed_handler);
 | 
			
		||||
    if (g_signal_handler_is_connected (priv->keyboard,
 | 
			
		||||
                                       priv->key_released_handler))
 | 
			
		||||
        g_signal_handler_disconnect (priv->keyboard,
 | 
			
		||||
                                     priv->key_released_handler);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
emit_visibility_changed_signal (EekboardContextService *context,
 | 
			
		||||
                                gboolean                visible)
 | 
			
		||||
{
 | 
			
		||||
    EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context);
 | 
			
		||||
 | 
			
		||||
    if (priv->connection && priv->enabled) {
 | 
			
		||||
        GError *error = NULL;
 | 
			
		||||
        g_dbus_connection_emit_signal (priv->connection,
 | 
			
		||||
                                       NULL,
 | 
			
		||||
                                       priv->object_path,
 | 
			
		||||
                                       EEKBOARD_CONTEXT_SERVICE_INTERFACE,
 | 
			
		||||
                                       "VisibilityChanged",
 | 
			
		||||
                                       g_variant_new ("(b)", visible),
 | 
			
		||||
                                       &error);
 | 
			
		||||
        g_assert_no_error (error);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
emit_group_changed_signal (EekboardContextService *context,
 | 
			
		||||
                           gint                    group)
 | 
			
		||||
{
 | 
			
		||||
    EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context);
 | 
			
		||||
 | 
			
		||||
    if (priv->connection && priv->enabled) {
 | 
			
		||||
        GError *error = NULL;
 | 
			
		||||
        g_dbus_connection_emit_signal (priv->connection,
 | 
			
		||||
                                       NULL,
 | 
			
		||||
                                       priv->object_path,
 | 
			
		||||
                                       EEKBOARD_CONTEXT_SERVICE_INTERFACE,
 | 
			
		||||
                                       "GroupChanged",
 | 
			
		||||
                                       g_variant_new ("(i)", group),
 | 
			
		||||
                                       &error);
 | 
			
		||||
        g_assert_no_error (error);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
emit_key_pressed_dbus_signal (EekboardContextService *context,
 | 
			
		||||
                              EekKey                 *key)
 | 
			
		||||
{
 | 
			
		||||
    EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context);
 | 
			
		||||
 | 
			
		||||
    if (priv->connection && priv->enabled) {
 | 
			
		||||
        const gchar *keyname = eek_element_get_name (EEK_ELEMENT(key));
 | 
			
		||||
        EekSymbol *symbol = eek_key_get_symbol_with_fallback (key, 0, 0);
 | 
			
		||||
        guint modifiers = eek_keyboard_get_modifiers (priv->keyboard);
 | 
			
		||||
        GVariant *variant;
 | 
			
		||||
        GError *error;
 | 
			
		||||
 | 
			
		||||
        variant = eek_serializable_serialize (EEK_SERIALIZABLE(symbol));
 | 
			
		||||
 | 
			
		||||
        error = NULL;
 | 
			
		||||
        g_dbus_connection_emit_signal (priv->connection,
 | 
			
		||||
                                       NULL,
 | 
			
		||||
                                       priv->object_path,
 | 
			
		||||
                                       EEKBOARD_CONTEXT_SERVICE_INTERFACE,
 | 
			
		||||
                                       "KeyPressed",
 | 
			
		||||
                                       g_variant_new ("(svu)",
 | 
			
		||||
                                                      keyname,
 | 
			
		||||
                                                      variant,
 | 
			
		||||
                                                      modifiers),
 | 
			
		||||
                                       &error);
 | 
			
		||||
        g_variant_unref (variant);
 | 
			
		||||
        g_assert_no_error (error);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static gboolean on_repeat_timeout (EekboardContextService *context);
 | 
			
		||||
 | 
			
		||||
static gboolean
 | 
			
		||||
on_repeat_timeout (EekboardContextService *context)
 | 
			
		||||
{
 | 
			
		||||
    EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context);
 | 
			
		||||
    gint delay = g_settings_get_int (priv->settings, "repeat-interval");
 | 
			
		||||
 | 
			
		||||
    emit_key_pressed_dbus_signal (context, priv->repeat_key);
 | 
			
		||||
 | 
			
		||||
    priv->repeat_timeout_id =
 | 
			
		||||
        g_timeout_add (delay,
 | 
			
		||||
                       (GSourceFunc)on_repeat_timeout,
 | 
			
		||||
                       context);
 | 
			
		||||
 | 
			
		||||
    return FALSE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static gboolean
 | 
			
		||||
on_repeat_timeout_init (EekboardContextService *context)
 | 
			
		||||
{
 | 
			
		||||
    EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context);
 | 
			
		||||
 | 
			
		||||
    emit_key_pressed_dbus_signal (context, priv->repeat_key);
 | 
			
		||||
 | 
			
		||||
    /* FIXME: clear modifiers for further key repeat; better not
 | 
			
		||||
       depend on modifier behavior is LATCH */
 | 
			
		||||
    eek_keyboard_set_modifiers (priv->keyboard, 0);
 | 
			
		||||
    
 | 
			
		||||
    /* reschedule repeat timeout only when "repeat" option is set */
 | 
			
		||||
    if (g_settings_get_boolean (priv->settings, "repeat")) {
 | 
			
		||||
        gint delay = g_settings_get_int (priv->settings, "repeat-interval");
 | 
			
		||||
        priv->repeat_timeout_id =
 | 
			
		||||
            g_timeout_add (delay,
 | 
			
		||||
                           (GSourceFunc)on_repeat_timeout,
 | 
			
		||||
                           context);
 | 
			
		||||
    } else
 | 
			
		||||
        priv->repeat_timeout_id = 0;
 | 
			
		||||
 | 
			
		||||
    return FALSE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
on_key_pressed (EekKeyboard *keyboard,
 | 
			
		||||
                EekKey      *key,
 | 
			
		||||
                gpointer     user_data)
 | 
			
		||||
{
 | 
			
		||||
    EekboardContextService *context = user_data;
 | 
			
		||||
    EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context);
 | 
			
		||||
    gint delay = g_settings_get_int (priv->settings, "repeat-delay");
 | 
			
		||||
 | 
			
		||||
    if (priv->repeat_timeout_id) {
 | 
			
		||||
        g_source_remove (priv->repeat_timeout_id);
 | 
			
		||||
        priv->repeat_timeout_id = 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    priv->repeat_key = key;
 | 
			
		||||
    priv->repeat_timeout_id =
 | 
			
		||||
        g_timeout_add (delay,
 | 
			
		||||
                       (GSourceFunc)on_repeat_timeout_init,
 | 
			
		||||
                       context);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
on_key_released (EekKeyboard *keyboard,
 | 
			
		||||
                 EekKey      *key,
 | 
			
		||||
                 gpointer     user_data)
 | 
			
		||||
{
 | 
			
		||||
    EekboardContextService *context = user_data;
 | 
			
		||||
    EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context);
 | 
			
		||||
 | 
			
		||||
    if (priv->repeat_timeout_id > 0) {
 | 
			
		||||
        g_source_remove (priv->repeat_timeout_id);
 | 
			
		||||
        priv->repeat_timeout_id = 0;
 | 
			
		||||
 | 
			
		||||
        /* KeyPressed signal has not been emitted in repeat handler */
 | 
			
		||||
        emit_key_pressed_dbus_signal (context, priv->repeat_key);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
connect_keyboard_signals (EekboardContextService *context)
 | 
			
		||||
{
 | 
			
		||||
    EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context);
 | 
			
		||||
 | 
			
		||||
    priv->key_pressed_handler =
 | 
			
		||||
        g_signal_connect (priv->keyboard, "key-pressed",
 | 
			
		||||
                          G_CALLBACK(on_key_pressed),
 | 
			
		||||
                          context);
 | 
			
		||||
    priv->key_released_handler =
 | 
			
		||||
        g_signal_connect (priv->keyboard, "key-released",
 | 
			
		||||
                          G_CALLBACK(on_key_released),
 | 
			
		||||
                          context);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
handle_method_call (GDBusConnection       *connection,
 | 
			
		||||
                    const gchar           *sender,
 | 
			
		||||
                    const gchar           *object_path,
 | 
			
		||||
                    const gchar           *interface_name,
 | 
			
		||||
                    const gchar           *method_name,
 | 
			
		||||
                    GVariant              *parameters,
 | 
			
		||||
                    GDBusMethodInvocation *invocation,
 | 
			
		||||
                    gpointer               user_data)
 | 
			
		||||
{
 | 
			
		||||
    EekboardContextService *context = user_data;
 | 
			
		||||
    EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context);
 | 
			
		||||
    EekboardContextServiceClass *klass = EEKBOARD_CONTEXT_SERVICE_GET_CLASS(context);
 | 
			
		||||
    
 | 
			
		||||
    if (g_strcmp0 (method_name, "AddKeyboard") == 0) {
 | 
			
		||||
        const gchar *keyboard_type;
 | 
			
		||||
        static guint keyboard_id = 0;
 | 
			
		||||
        EekKeyboard *keyboard;
 | 
			
		||||
 | 
			
		||||
        g_variant_get (parameters, "(&s)", &keyboard_type);
 | 
			
		||||
        keyboard = klass->create_keyboard (context, keyboard_type);
 | 
			
		||||
 | 
			
		||||
        if (keyboard == NULL) {
 | 
			
		||||
            g_dbus_method_invocation_return_error (invocation,
 | 
			
		||||
                                                   G_IO_ERROR,
 | 
			
		||||
                                                   G_IO_ERROR_FAILED_HANDLED,
 | 
			
		||||
                                                   "can't create a keyboard");
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        eek_keyboard_set_modifier_behavior (keyboard,
 | 
			
		||||
                                            EEK_MODIFIER_BEHAVIOR_LATCH);
 | 
			
		||||
 | 
			
		||||
        keyboard_id++;
 | 
			
		||||
        g_hash_table_insert (priv->keyboard_hash,
 | 
			
		||||
                             GUINT_TO_POINTER(keyboard_id),
 | 
			
		||||
                             keyboard);
 | 
			
		||||
        g_object_set_data (G_OBJECT(keyboard),
 | 
			
		||||
                           "keyboard-id",
 | 
			
		||||
                           GUINT_TO_POINTER(keyboard_id));
 | 
			
		||||
        g_dbus_method_invocation_return_value (invocation,
 | 
			
		||||
                                               g_variant_new ("(u)",
 | 
			
		||||
                                                              keyboard_id));
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (g_strcmp0 (method_name, "RemoveKeyboard") == 0) {
 | 
			
		||||
        guint keyboard_id, current_keyboard_id;
 | 
			
		||||
 | 
			
		||||
        g_variant_get (parameters, "(u)", &keyboard_id);
 | 
			
		||||
 | 
			
		||||
        current_keyboard_id =
 | 
			
		||||
            GPOINTER_TO_UINT (g_object_get_data (G_OBJECT(priv->keyboard),
 | 
			
		||||
                                                 "keyboard-id"));
 | 
			
		||||
        if (keyboard_id == current_keyboard_id) {
 | 
			
		||||
            disconnect_keyboard_signals (context);
 | 
			
		||||
            priv->keyboard = NULL;
 | 
			
		||||
            g_object_notify (G_OBJECT(context), "keyboard");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        g_hash_table_remove (priv->keyboard_hash,
 | 
			
		||||
                             GUINT_TO_POINTER(keyboard_id));
 | 
			
		||||
        g_dbus_method_invocation_return_value (invocation, NULL);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (g_strcmp0 (method_name, "SetKeyboard") == 0) {
 | 
			
		||||
        EekKeyboard *keyboard;
 | 
			
		||||
        guint keyboard_id;
 | 
			
		||||
        gint group;
 | 
			
		||||
 | 
			
		||||
        g_variant_get (parameters, "(u)", &keyboard_id);
 | 
			
		||||
 | 
			
		||||
        keyboard = g_hash_table_lookup (priv->keyboard_hash,
 | 
			
		||||
                                        GUINT_TO_POINTER(keyboard_id));
 | 
			
		||||
        if (!keyboard) {
 | 
			
		||||
            g_dbus_method_invocation_return_error (invocation,
 | 
			
		||||
                                                   G_IO_ERROR,
 | 
			
		||||
                                                   G_IO_ERROR_FAILED_HANDLED,
 | 
			
		||||
                                                   "no such keyboard");
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (keyboard == priv->keyboard) {
 | 
			
		||||
            g_dbus_method_invocation_return_value (invocation, NULL);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (priv->keyboard)
 | 
			
		||||
            disconnect_keyboard_signals (context);
 | 
			
		||||
 | 
			
		||||
        priv->keyboard = keyboard;
 | 
			
		||||
        connect_keyboard_signals (context);
 | 
			
		||||
 | 
			
		||||
        g_dbus_method_invocation_return_value (invocation, NULL);
 | 
			
		||||
 | 
			
		||||
        group = eek_element_get_group (EEK_ELEMENT(priv->keyboard));
 | 
			
		||||
        emit_group_changed_signal (context, group);
 | 
			
		||||
 | 
			
		||||
        g_object_notify (G_OBJECT(context), "keyboard");
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (g_strcmp0 (method_name, "SetFullscreen") == 0) {
 | 
			
		||||
        gboolean fullscreen;
 | 
			
		||||
 | 
			
		||||
        g_variant_get (parameters, "(b)", &fullscreen);
 | 
			
		||||
 | 
			
		||||
        if (priv->fullscreen == fullscreen) {
 | 
			
		||||
            g_dbus_method_invocation_return_value (invocation, NULL);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        priv->fullscreen = fullscreen;
 | 
			
		||||
        g_dbus_method_invocation_return_value (invocation, NULL);
 | 
			
		||||
 | 
			
		||||
        g_object_notify (G_OBJECT(context), "fullscreen");
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (g_strcmp0 (method_name, "SetGroup") == 0) {
 | 
			
		||||
        gint group;
 | 
			
		||||
 | 
			
		||||
        if (!priv->keyboard) {
 | 
			
		||||
            g_dbus_method_invocation_return_error (invocation,
 | 
			
		||||
                                                   G_IO_ERROR,
 | 
			
		||||
                                                   G_IO_ERROR_FAILED_HANDLED,
 | 
			
		||||
                                                   "keyboard is not set");
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        g_variant_get (parameters, "(i)", &group);
 | 
			
		||||
        eek_element_set_group (EEK_ELEMENT(priv->keyboard), group);
 | 
			
		||||
        g_dbus_method_invocation_return_value (invocation, NULL);
 | 
			
		||||
        emit_group_changed_signal (context, group);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (g_strcmp0 (method_name, "ShowKeyboard") == 0) {
 | 
			
		||||
        if (!priv->keyboard) {
 | 
			
		||||
            g_dbus_method_invocation_return_error (invocation,
 | 
			
		||||
                                                   G_IO_ERROR,
 | 
			
		||||
                                                   G_IO_ERROR_FAILED_HANDLED,
 | 
			
		||||
                                                   "keyboard is not set");
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (klass->show_keyboard)
 | 
			
		||||
            klass->show_keyboard (context);
 | 
			
		||||
        g_dbus_method_invocation_return_value (invocation, NULL);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (g_strcmp0 (method_name, "HideKeyboard") == 0) {
 | 
			
		||||
        if (klass->hide_keyboard)
 | 
			
		||||
            klass->hide_keyboard (context);
 | 
			
		||||
        g_dbus_method_invocation_return_value (invocation, NULL);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (g_strcmp0 (method_name, "PressKeycode") == 0 ||
 | 
			
		||||
        g_strcmp0 (method_name, "ReleaseKeycode") == 0) {
 | 
			
		||||
        EekKey *key;
 | 
			
		||||
        guint keycode;
 | 
			
		||||
 | 
			
		||||
        if (!priv->keyboard) {
 | 
			
		||||
            g_dbus_method_invocation_return_error (invocation,
 | 
			
		||||
                                                   G_IO_ERROR,
 | 
			
		||||
                                                   G_IO_ERROR_FAILED_HANDLED,
 | 
			
		||||
                                                   "keyboard is not set");
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        g_variant_get (parameters, "(u)", &keycode);
 | 
			
		||||
        key = eek_keyboard_find_key_by_keycode (priv->keyboard, keycode);
 | 
			
		||||
 | 
			
		||||
        if (!key) {
 | 
			
		||||
            g_dbus_method_invocation_return_error (invocation,
 | 
			
		||||
                                                   G_IO_ERROR,
 | 
			
		||||
                                                   G_IO_ERROR_FAILED_HANDLED,
 | 
			
		||||
                                                   "key for %u is not found",
 | 
			
		||||
                                                   keycode);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (g_strcmp0 (method_name, "PressKeycode") == 0) {
 | 
			
		||||
            g_signal_handler_block (priv->keyboard,
 | 
			
		||||
                                    priv->key_pressed_handler);
 | 
			
		||||
            g_signal_emit_by_name (key, "pressed");
 | 
			
		||||
            g_signal_handler_unblock (priv->keyboard,
 | 
			
		||||
                                      priv->key_pressed_handler);
 | 
			
		||||
        } else {
 | 
			
		||||
            g_signal_handler_block (priv->keyboard,
 | 
			
		||||
                                    priv->key_released_handler);
 | 
			
		||||
            g_signal_emit_by_name (key, "released");
 | 
			
		||||
            g_signal_handler_unblock (priv->keyboard,
 | 
			
		||||
                                      priv->key_released_handler);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        g_dbus_method_invocation_return_value (invocation, NULL);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    g_return_if_reached ();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
eekboard_context_service_enable (EekboardContextService *context)
 | 
			
		||||
{
 | 
			
		||||
    EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context);
 | 
			
		||||
    GError *error;
 | 
			
		||||
 | 
			
		||||
    g_return_if_fail (EEKBOARD_IS_CONTEXT_SERVICE(context));
 | 
			
		||||
    g_return_if_fail (priv->connection);
 | 
			
		||||
 | 
			
		||||
    if (!priv->enabled) {
 | 
			
		||||
        priv->enabled = TRUE;
 | 
			
		||||
 | 
			
		||||
        error = NULL;
 | 
			
		||||
        g_dbus_connection_emit_signal (priv->connection,
 | 
			
		||||
                                       NULL,
 | 
			
		||||
                                       priv->object_path,
 | 
			
		||||
                                       EEKBOARD_CONTEXT_SERVICE_INTERFACE,
 | 
			
		||||
                                       "Enabled",
 | 
			
		||||
                                       NULL,
 | 
			
		||||
                                       &error);
 | 
			
		||||
        g_assert_no_error (error);
 | 
			
		||||
        g_signal_emit_by_name (context, "enabled", NULL);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
eekboard_context_service_disable (EekboardContextService *context)
 | 
			
		||||
{
 | 
			
		||||
    EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context);
 | 
			
		||||
    GError *error;
 | 
			
		||||
 | 
			
		||||
    g_return_if_fail (EEKBOARD_IS_CONTEXT_SERVICE(context));
 | 
			
		||||
    g_return_if_fail (priv->connection);
 | 
			
		||||
 | 
			
		||||
    if (priv->enabled) {
 | 
			
		||||
        priv->enabled = FALSE;
 | 
			
		||||
 | 
			
		||||
        error = NULL;
 | 
			
		||||
        g_dbus_connection_emit_signal (priv->connection,
 | 
			
		||||
                                       NULL,
 | 
			
		||||
                                       priv->object_path,
 | 
			
		||||
                                       EEKBOARD_CONTEXT_SERVICE_INTERFACE,
 | 
			
		||||
                                       "Disabled",
 | 
			
		||||
                                       NULL,
 | 
			
		||||
                                       &error);
 | 
			
		||||
        g_assert_no_error (error);
 | 
			
		||||
        g_signal_emit_by_name (context, "disabled", NULL);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const EekKeyboard *
 | 
			
		||||
eekboard_context_service_get_keyboard (EekboardContextService *context)
 | 
			
		||||
{
 | 
			
		||||
    EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context);
 | 
			
		||||
    return priv->keyboard;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gboolean
 | 
			
		||||
eekboard_context_service_get_fullscreen (EekboardContextService *context)
 | 
			
		||||
{
 | 
			
		||||
    EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context);
 | 
			
		||||
    return priv->fullscreen;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const gchar *
 | 
			
		||||
eekboard_context_service_get_client_name (EekboardContextService *context)
 | 
			
		||||
{
 | 
			
		||||
    EekboardContextServicePrivate *priv = EEKBOARD_CONTEXT_SERVICE_GET_PRIVATE(context);
 | 
			
		||||
    return priv->client_name;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										81
									
								
								eekboard/eekboard-context-service.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										81
									
								
								eekboard/eekboard-context-service.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,81 @@
 | 
			
		||||
/* 
 | 
			
		||||
 * Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
 | 
			
		||||
 * Copyright (C) 2010-2011 Red Hat, Inc.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
 * (at your option) any later version.
 | 
			
		||||
 *
 | 
			
		||||
 * This program 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 General Public License for more details.
 | 
			
		||||
 *
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
#if !defined(__EEKBOARD_SERVICE_H_INSIDE__) && !defined(EEKBOARD_COMPILATION)
 | 
			
		||||
#error "Only <eekboard/eekboard-service.h> can be included directly."
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef EEKBOARD_CONTEXT_SERVICE_H
 | 
			
		||||
#define EEKBOARD_CONTEXT_SERVICE_H 1
 | 
			
		||||
 | 
			
		||||
#include <eek/eek.h>
 | 
			
		||||
 | 
			
		||||
G_BEGIN_DECLS
 | 
			
		||||
 | 
			
		||||
#define EEKBOARD_CONTEXT_SERVICE_PATH "/org/fedorahosted/Eekboard/Context_%d"
 | 
			
		||||
#define EEKBOARD_CONTEXT_SERVICE_INTERFACE "org.fedorahosted.Eekboard.Context"
 | 
			
		||||
 | 
			
		||||
#define EEKBOARD_TYPE_CONTEXT_SERVICE (eekboard_context_service_get_type())
 | 
			
		||||
#define EEKBOARD_CONTEXT_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EEKBOARD_TYPE_CONTEXT_SERVICE, EekboardContextService))
 | 
			
		||||
#define EEKBOARD_CONTEXT_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EEKBOARD_TYPE_CONTEXT_SERVICE, EekboardContextServiceClass))
 | 
			
		||||
#define EEKBOARD_IS_CONTEXT_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EEKBOARD_TYPE_CONTEXT_SERVICE))
 | 
			
		||||
#define EEKBOARD_IS_CONTEXT_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EEKBOARD_TYPE_CONTEXT_SERVICE))
 | 
			
		||||
#define EEKBOARD_CONTEXT_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EEKBOARD_TYPE_CONTEXT_SERVICE, EekboardContextServiceClass))
 | 
			
		||||
 | 
			
		||||
typedef struct _EekboardContextService EekboardContextService;
 | 
			
		||||
typedef struct _EekboardContextServiceClass EekboardContextServiceClass;
 | 
			
		||||
typedef struct _EekboardContextServicePrivate EekboardContextServicePrivate;
 | 
			
		||||
 | 
			
		||||
struct _EekboardContextService {
 | 
			
		||||
    GObject parent;
 | 
			
		||||
 | 
			
		||||
    EekboardContextServicePrivate *priv;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct _EekboardContextServiceClass {
 | 
			
		||||
    /*< private >*/
 | 
			
		||||
    GObjectClass parent_class;
 | 
			
		||||
 | 
			
		||||
    EekKeyboard *(*create_keyboard)    (EekboardContextService *self,
 | 
			
		||||
                                        const gchar            *keyboard_type);
 | 
			
		||||
    void         (*show_keyboard)      (EekboardContextService *self);
 | 
			
		||||
    void         (*hide_keyboard)      (EekboardContextService *self);
 | 
			
		||||
 | 
			
		||||
    /* signals */
 | 
			
		||||
    void         (*enabled)            (EekboardContextService *self);
 | 
			
		||||
    void         (*disabled)           (EekboardContextService *self);
 | 
			
		||||
 | 
			
		||||
    /*< private >*/
 | 
			
		||||
    /* padding */
 | 
			
		||||
    gpointer pdummy[24];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
GType              eekboard_context_service_get_type
 | 
			
		||||
                   (void) G_GNUC_CONST;
 | 
			
		||||
void               eekboard_context_service_enable
 | 
			
		||||
                   (EekboardContextService *context);
 | 
			
		||||
void               eekboard_context_service_disable
 | 
			
		||||
                   (EekboardContextService *context);
 | 
			
		||||
const EekKeyboard *eekboard_context_service_get_keyboard
 | 
			
		||||
                   (EekboardContextService *context);
 | 
			
		||||
gboolean           eekboard_context_service_get_fullscreen
 | 
			
		||||
                   (EekboardContextService *context);
 | 
			
		||||
const gchar *      eekboard_context_service_get_client_name
 | 
			
		||||
                   (EekboardContextService *context);
 | 
			
		||||
 | 
			
		||||
G_END_DECLS
 | 
			
		||||
#endif  /* EEKBOARD_CONTEXT_SERVICE_H */
 | 
			
		||||
@ -45,7 +45,7 @@ static guint signals[LAST_SIGNAL] = { 0, };
 | 
			
		||||
 | 
			
		||||
enum {
 | 
			
		||||
    PROP_0,
 | 
			
		||||
    PROP_KEYBOARD_VISIBLE,
 | 
			
		||||
    PROP_VISIBLE,
 | 
			
		||||
    PROP_LAST
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -56,7 +56,7 @@ G_DEFINE_TYPE (EekboardContext, eekboard_context, G_TYPE_DBUS_PROXY);
 | 
			
		||||
 | 
			
		||||
struct _EekboardContextPrivate
 | 
			
		||||
{
 | 
			
		||||
    gboolean keyboard_visible;
 | 
			
		||||
    gboolean visible;
 | 
			
		||||
    gboolean enabled;
 | 
			
		||||
    gboolean fullscreen;
 | 
			
		||||
    gint group;
 | 
			
		||||
@ -99,13 +99,13 @@ eekboard_context_real_g_signal (GDBusProxy  *self,
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (g_strcmp0 (signal_name, "KeyboardVisibilityChanged") == 0) {
 | 
			
		||||
        gboolean keyboard_visible = FALSE;
 | 
			
		||||
    if (g_strcmp0 (signal_name, "VisibilityChanged") == 0) {
 | 
			
		||||
        gboolean visible = FALSE;
 | 
			
		||||
 | 
			
		||||
        g_variant_get (parameters, "(b)", &keyboard_visible);
 | 
			
		||||
        if (keyboard_visible != priv->keyboard_visible) {
 | 
			
		||||
            priv->keyboard_visible = keyboard_visible;
 | 
			
		||||
            g_object_notify (G_OBJECT(context), "keyboard-visible");
 | 
			
		||||
        g_variant_get (parameters, "(b)", &visible);
 | 
			
		||||
        if (visible != priv->visible) {
 | 
			
		||||
            priv->visible = visible;
 | 
			
		||||
            g_object_notify (G_OBJECT(context), "visible");
 | 
			
		||||
        }
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
@ -159,8 +159,8 @@ eekboard_context_get_property (GObject    *object,
 | 
			
		||||
{
 | 
			
		||||
    EekboardContextPrivate *priv = EEKBOARD_CONTEXT_GET_PRIVATE(object);
 | 
			
		||||
    switch (prop_id) {
 | 
			
		||||
    case PROP_KEYBOARD_VISIBLE:
 | 
			
		||||
        g_value_set_boolean (value, priv->keyboard_visible);
 | 
			
		||||
    case PROP_VISIBLE:
 | 
			
		||||
        g_value_set_boolean (value, priv->visible);
 | 
			
		||||
        break;
 | 
			
		||||
    default:
 | 
			
		||||
        g_object_get_property (object,
 | 
			
		||||
@ -190,17 +190,17 @@ eekboard_context_class_init (EekboardContextClass *klass)
 | 
			
		||||
    gobject_class->get_property = eekboard_context_get_property;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * EekboardContext:keyboard-visible:
 | 
			
		||||
     * EekboardContext:visible:
 | 
			
		||||
     *
 | 
			
		||||
     * Flag to indicate if keyboard is visible or not.
 | 
			
		||||
     */
 | 
			
		||||
    pspec = g_param_spec_boolean ("keyboard-visible",
 | 
			
		||||
                                  "Keyboard-visible",
 | 
			
		||||
    pspec = g_param_spec_boolean ("visible",
 | 
			
		||||
                                  "visible",
 | 
			
		||||
                                  "Flag that indicates if keyboard is visible",
 | 
			
		||||
                                  FALSE,
 | 
			
		||||
                                  G_PARAM_READABLE);
 | 
			
		||||
    g_object_class_install_property (gobject_class,
 | 
			
		||||
                                     PROP_KEYBOARD_VISIBLE,
 | 
			
		||||
                                     PROP_VISIBLE,
 | 
			
		||||
                                     pspec);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@ -321,7 +321,7 @@ eekboard_context_new (GDBusConnection *connection,
 | 
			
		||||
        g_initable_new (EEKBOARD_TYPE_CONTEXT,
 | 
			
		||||
                        cancellable,
 | 
			
		||||
                        &error,
 | 
			
		||||
                        "g-name", "org.fedorahosted.Eekboard.Server",
 | 
			
		||||
                        "g-name", "org.fedorahosted.Eekboard",
 | 
			
		||||
                        "g-connection", connection,
 | 
			
		||||
                        "g-interface-name", "org.fedorahosted.Eekboard.Context",
 | 
			
		||||
                        "g-object-path", object_path,
 | 
			
		||||
@ -563,7 +563,7 @@ eekboard_context_hide_keyboard (EekboardContext *context,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * eekboard_context_press_key:
 | 
			
		||||
 * eekboard_context_press_keycode:
 | 
			
		||||
 * @context: an #EekboardContext
 | 
			
		||||
 * @keycode: keycode number
 | 
			
		||||
 * @cancellable: a #GCancellable
 | 
			
		||||
@ -571,9 +571,9 @@ eekboard_context_hide_keyboard (EekboardContext *context,
 | 
			
		||||
 * Tell eekboard-server that a key identified by @keycode is pressed.
 | 
			
		||||
 */
 | 
			
		||||
void
 | 
			
		||||
eekboard_context_press_key (EekboardContext *context,
 | 
			
		||||
                            guint            keycode,
 | 
			
		||||
                            GCancellable    *cancellable)
 | 
			
		||||
eekboard_context_press_keycode (EekboardContext *context,
 | 
			
		||||
                                guint            keycode,
 | 
			
		||||
                                GCancellable    *cancellable)
 | 
			
		||||
{
 | 
			
		||||
    EekboardContextPrivate *priv;
 | 
			
		||||
 | 
			
		||||
@ -584,7 +584,7 @@ eekboard_context_press_key (EekboardContext *context,
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
    g_dbus_proxy_call (G_DBUS_PROXY(context),
 | 
			
		||||
                       "PressKey",
 | 
			
		||||
                       "PressKeycode",
 | 
			
		||||
                       g_variant_new ("(u)", keycode),
 | 
			
		||||
                       G_DBUS_CALL_FLAGS_NONE,
 | 
			
		||||
                       -1,
 | 
			
		||||
@ -594,15 +594,15 @@ eekboard_context_press_key (EekboardContext *context,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * eekboard_context_release_key:
 | 
			
		||||
 * @context: an #EekboardContext
 | 
			
		||||
 * eekboard_context_release_keycode:
 | 
			
		||||
 * @Context: an #EekboardContext
 | 
			
		||||
 * @keycode: keycode number
 | 
			
		||||
 * @cancellable: a #GCancellable
 | 
			
		||||
 *
 | 
			
		||||
 * Tell eekboard-server that a key identified by @keycode is released.
 | 
			
		||||
 */
 | 
			
		||||
void
 | 
			
		||||
eekboard_context_release_key (EekboardContext *context,
 | 
			
		||||
eekboard_context_release_keycode (EekboardContext *context,
 | 
			
		||||
                              guint            keycode,
 | 
			
		||||
                              GCancellable    *cancellable)
 | 
			
		||||
{
 | 
			
		||||
@ -615,7 +615,7 @@ eekboard_context_release_key (EekboardContext *context,
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
    g_dbus_proxy_call (G_DBUS_PROXY(context),
 | 
			
		||||
                       "ReleaseKey",
 | 
			
		||||
                       "ReleaseKeycode",
 | 
			
		||||
                       g_variant_new ("(u)", keycode),
 | 
			
		||||
                       G_DBUS_CALL_FLAGS_NONE,
 | 
			
		||||
                       -1,
 | 
			
		||||
@ -625,20 +625,20 @@ eekboard_context_release_key (EekboardContext *context,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * eekboard_context_is_keyboard_visible:
 | 
			
		||||
 * eekboard_context_is_visible:
 | 
			
		||||
 * @context: an #EekboardContext
 | 
			
		||||
 *
 | 
			
		||||
 * Check if keyboard is visible.
 | 
			
		||||
 */
 | 
			
		||||
gboolean
 | 
			
		||||
eekboard_context_is_keyboard_visible (EekboardContext *context)
 | 
			
		||||
eekboard_context_is_visible (EekboardContext *context)
 | 
			
		||||
{
 | 
			
		||||
    EekboardContextPrivate *priv;
 | 
			
		||||
 | 
			
		||||
    g_assert (EEKBOARD_IS_CONTEXT(context));
 | 
			
		||||
 | 
			
		||||
    priv = EEKBOARD_CONTEXT_GET_PRIVATE (context);
 | 
			
		||||
    return priv->enabled && priv->keyboard_visible;
 | 
			
		||||
    return priv->enabled && priv->visible;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 | 
			
		||||
@ -15,9 +15,8 @@
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#if !defined(__EEKBOARD_H_INSIDE__) && !defined(EEKBOARD_COMPILATION)
 | 
			
		||||
#error "Only <eekboard/eekboard.h> can be included directly."
 | 
			
		||||
#if !defined(__EEKBOARD_CLIENT_H_INSIDE__) && !defined(EEKBOARD_COMPILATION)
 | 
			
		||||
#error "Only <eekboard/eekboard-client.h> can be included directly."
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef EEKBOARD_CONTEXT_H
 | 
			
		||||
@ -100,12 +99,12 @@ void             eekboard_context_set_group      (EekboardContext *context,
 | 
			
		||||
                                                  GCancellable    *cancellable);
 | 
			
		||||
gint             eekboard_context_get_group      (EekboardContext *context,
 | 
			
		||||
                                                  GCancellable    *cancellable);
 | 
			
		||||
void             eekboard_context_press_key      (EekboardContext *context,
 | 
			
		||||
                                                  guint            keycode,
 | 
			
		||||
                                                  GCancellable    *cancellable);
 | 
			
		||||
void             eekboard_context_release_key    (EekboardContext *context,
 | 
			
		||||
void             eekboard_context_press_keycode  (EekboardContext *context,
 | 
			
		||||
                                                  guint            keycode,
 | 
			
		||||
                                                  GCancellable    *cancellable);
 | 
			
		||||
void             eekboard_context_release_keycode (EekboardContext *context,
 | 
			
		||||
                                                   guint            keycode,
 | 
			
		||||
                                                   GCancellable    *cancellable);
 | 
			
		||||
gboolean         eekboard_context_is_keyboard_visible
 | 
			
		||||
                                                 (EekboardContext *context);
 | 
			
		||||
void             eekboard_context_set_enabled    (EekboardContext *context,
 | 
			
		||||
 | 
			
		||||
@ -1,81 +0,0 @@
 | 
			
		||||
/* 
 | 
			
		||||
 * Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
 | 
			
		||||
 * Copyright (C) 2010-2011 Red Hat, Inc.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
 * (at your option) any later version.
 | 
			
		||||
 *
 | 
			
		||||
 * This program 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 General Public License for more details.
 | 
			
		||||
 *
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#if !defined(__EEKBOARD_H_INSIDE__) && !defined(EEKBOARD_COMPILATION)
 | 
			
		||||
#error "Only <eekboard/eekboard.h> can be included directly."
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifndef EEKBOARD_EEKBOARD_H
 | 
			
		||||
#define EEKBOARD_EEKBOARD_H 1
 | 
			
		||||
 | 
			
		||||
#include <gio/gio.h>
 | 
			
		||||
#include "eekboard/eekboard-context.h"
 | 
			
		||||
 | 
			
		||||
G_BEGIN_DECLS
 | 
			
		||||
 | 
			
		||||
#define EEKBOARD_TYPE_EEKBOARD (eekboard_eekboard_get_type())
 | 
			
		||||
#define EEKBOARD_EEKBOARD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EEKBOARD_TYPE_EEKBOARD, EekboardEekboard))
 | 
			
		||||
#define EEKBOARD_EEKBOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EEKBOARD_TYPE_EEKBOARD, EekboardEekboardClass))
 | 
			
		||||
#define EEKBOARD_IS_EEKBOARD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EEKBOARD_TYPE_EEKBOARD))
 | 
			
		||||
#define EEKBOARD_IS_EEKBOARD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EEKBOARD_TYPE_EEKBOARD))
 | 
			
		||||
#define EEKBOARD_EEKBOARD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EEKBOARD_TYPE_EEKBOARD, EekboardEekboardClass))
 | 
			
		||||
 | 
			
		||||
typedef struct _EekboardEekboard EekboardEekboard;
 | 
			
		||||
typedef struct _EekboardEekboardClass EekboardEekboardClass;
 | 
			
		||||
typedef struct _EekboardEekboardPrivate EekboardEekboardPrivate;
 | 
			
		||||
 | 
			
		||||
struct _EekboardEekboard {
 | 
			
		||||
    /*< private >*/
 | 
			
		||||
    GDBusProxy parent;
 | 
			
		||||
 | 
			
		||||
    EekboardEekboardPrivate *priv;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct _EekboardEekboardClass {
 | 
			
		||||
    /*< private >*/
 | 
			
		||||
    GDBusProxyClass parent_class;
 | 
			
		||||
 | 
			
		||||
    /* signals */
 | 
			
		||||
    void (* destroyed) (EekboardEekboard *self);
 | 
			
		||||
 | 
			
		||||
    /*< private >*/
 | 
			
		||||
    /* padding */
 | 
			
		||||
    gpointer pdummy[23];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
GType             eekboard_eekboard_get_type    (void) G_GNUC_CONST;
 | 
			
		||||
 | 
			
		||||
EekboardEekboard *eekboard_eekboard_new         (GDBusConnection  *connection,
 | 
			
		||||
                                                 GCancellable     *cancellable);
 | 
			
		||||
EekboardContext  *eekboard_eekboard_create_context
 | 
			
		||||
                                                (EekboardEekboard *eekboard,
 | 
			
		||||
                                                 const gchar      *client_name,
 | 
			
		||||
                                                 GCancellable     *cancellable);
 | 
			
		||||
void              eekboard_eekboard_push_context
 | 
			
		||||
                                                (EekboardEekboard *eekboard,
 | 
			
		||||
                                                 EekboardContext  *context,
 | 
			
		||||
                                                 GCancellable     *cancellable);
 | 
			
		||||
void              eekboard_eekboard_pop_context (EekboardEekboard *eekboard,
 | 
			
		||||
                                                 GCancellable     *cancellable);
 | 
			
		||||
void              eekboard_eekboard_destroy_context
 | 
			
		||||
                                                (EekboardEekboard *eekboard,
 | 
			
		||||
                                                 EekboardContext  *context,
 | 
			
		||||
                                                 GCancellable     *cancellable);
 | 
			
		||||
 | 
			
		||||
G_END_DECLS
 | 
			
		||||
#endif  /* EEKBOARD_EEKBOARD_H */
 | 
			
		||||
							
								
								
									
										471
									
								
								eekboard/eekboard-service.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										471
									
								
								eekboard/eekboard-service.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,471 @@
 | 
			
		||||
/* 
 | 
			
		||||
 * Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
 | 
			
		||||
 * Copyright (C) 2010-2011 Red Hat, Inc.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
 * (at your option) any later version.
 | 
			
		||||
 *
 | 
			
		||||
 * This program 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 General Public License for more details.
 | 
			
		||||
 *
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
#ifdef HAVE_CONFIG_H
 | 
			
		||||
#include "config.h"
 | 
			
		||||
#endif  /* HAVE_CONFIG_H */
 | 
			
		||||
 | 
			
		||||
#include "eekboard/eekboard-service.h"
 | 
			
		||||
 | 
			
		||||
enum {
 | 
			
		||||
    PROP_0,
 | 
			
		||||
    PROP_OBJECT_PATH,
 | 
			
		||||
    PROP_CONNECTION,
 | 
			
		||||
    PROP_LAST
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
enum {
 | 
			
		||||
    DESTROYED,
 | 
			
		||||
    LAST_SIGNAL
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static guint signals[LAST_SIGNAL] = { 0, };
 | 
			
		||||
 | 
			
		||||
#define EEKBOARD_SERVICE_GET_PRIVATE(obj)                               \
 | 
			
		||||
    (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EEKBOARD_TYPE_SERVICE, EekboardServicePrivate))
 | 
			
		||||
 | 
			
		||||
struct _EekboardServicePrivate {
 | 
			
		||||
    GDBusConnection *connection;
 | 
			
		||||
    GDBusNodeInfo *introspection_data;
 | 
			
		||||
    guint registration_id;
 | 
			
		||||
    char *object_path;
 | 
			
		||||
 | 
			
		||||
    GHashTable *context_hash;
 | 
			
		||||
    GSList *context_stack;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
G_DEFINE_TYPE (EekboardService, eekboard_service, G_TYPE_OBJECT);
 | 
			
		||||
 | 
			
		||||
static const gchar introspection_xml[] =
 | 
			
		||||
    "<node>"
 | 
			
		||||
    "  <interface name='org.fedorahosted.Eekboard'>"
 | 
			
		||||
    "    <method name='CreateContext'>"
 | 
			
		||||
    "      <arg direction='in' type='s' name='client_name'/>"
 | 
			
		||||
    "      <arg direction='out' type='s' name='object_path'/>"
 | 
			
		||||
    "    </method>"
 | 
			
		||||
    "    <method name='PushContext'>"
 | 
			
		||||
    "      <arg direction='in' type='s' name='object_path'/>"
 | 
			
		||||
    "    </method>"
 | 
			
		||||
    "    <method name='PopContext'/>"
 | 
			
		||||
    "    <method name='DestroyContext'>"
 | 
			
		||||
    "      <arg direction='in' type='s' name='object_path'/>"
 | 
			
		||||
    "    </method>"
 | 
			
		||||
    "    <method name='Destroy'/>"
 | 
			
		||||
    /* signals */
 | 
			
		||||
    "  </interface>"
 | 
			
		||||
    "</node>";
 | 
			
		||||
 | 
			
		||||
static void handle_method_call (GDBusConnection       *connection,
 | 
			
		||||
                                const gchar           *sender,
 | 
			
		||||
                                const gchar           *object_path,
 | 
			
		||||
                                const gchar           *interface_name,
 | 
			
		||||
                                const gchar           *method_name,
 | 
			
		||||
                                GVariant              *parameters,
 | 
			
		||||
                                GDBusMethodInvocation *invocation,
 | 
			
		||||
                                gpointer               user_data);
 | 
			
		||||
 | 
			
		||||
static const GDBusInterfaceVTable interface_vtable =
 | 
			
		||||
{
 | 
			
		||||
  handle_method_call,
 | 
			
		||||
  NULL,
 | 
			
		||||
  NULL
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
eekboard_service_set_property (GObject      *object,
 | 
			
		||||
                               guint         prop_id,
 | 
			
		||||
                               const GValue *value,
 | 
			
		||||
                               GParamSpec   *pspec)
 | 
			
		||||
{
 | 
			
		||||
    EekboardService *service = EEKBOARD_SERVICE(object);
 | 
			
		||||
    EekboardServicePrivate *priv = EEKBOARD_SERVICE_GET_PRIVATE(service);
 | 
			
		||||
    GDBusConnection *connection;
 | 
			
		||||
 | 
			
		||||
    switch (prop_id) {
 | 
			
		||||
    case PROP_OBJECT_PATH:
 | 
			
		||||
        if (priv->object_path)
 | 
			
		||||
            g_free (priv->object_path);
 | 
			
		||||
        priv->object_path = g_strdup (g_value_get_string (value));
 | 
			
		||||
        break;
 | 
			
		||||
    case PROP_CONNECTION:
 | 
			
		||||
        connection = g_value_get_object (value);
 | 
			
		||||
        if (priv->connection)
 | 
			
		||||
            g_object_unref (priv->connection);
 | 
			
		||||
        priv->connection = g_object_ref (connection);
 | 
			
		||||
        break;
 | 
			
		||||
    default:
 | 
			
		||||
        g_object_set_property (object,
 | 
			
		||||
                               g_param_spec_get_name (pspec),
 | 
			
		||||
                               value);
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
eekboard_service_get_property (GObject    *object,
 | 
			
		||||
                               guint       prop_id,
 | 
			
		||||
                               GValue     *value,
 | 
			
		||||
                               GParamSpec *pspec)
 | 
			
		||||
{
 | 
			
		||||
    EekboardService *service = EEKBOARD_SERVICE(object);
 | 
			
		||||
    EekboardServicePrivate *priv = EEKBOARD_SERVICE_GET_PRIVATE(service);
 | 
			
		||||
 | 
			
		||||
    switch (prop_id) {
 | 
			
		||||
    case PROP_OBJECT_PATH:
 | 
			
		||||
        g_value_set_string (value, priv->object_path);
 | 
			
		||||
        break;
 | 
			
		||||
    case PROP_CONNECTION:
 | 
			
		||||
        g_value_set_object (value, priv->connection);
 | 
			
		||||
        break;
 | 
			
		||||
    default:
 | 
			
		||||
        g_object_set_property (object,
 | 
			
		||||
                               g_param_spec_get_name (pspec),
 | 
			
		||||
                               value);
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
eekboard_service_dispose (GObject *object)
 | 
			
		||||
{
 | 
			
		||||
    EekboardService *service = EEKBOARD_SERVICE(object);
 | 
			
		||||
    EekboardServicePrivate *priv = EEKBOARD_SERVICE_GET_PRIVATE(service);
 | 
			
		||||
    GSList *head;
 | 
			
		||||
 | 
			
		||||
    if (priv->context_hash) {
 | 
			
		||||
        g_hash_table_destroy (priv->context_hash);
 | 
			
		||||
        priv->context_hash = NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for (head = priv->context_stack; head; head = priv->context_stack) {
 | 
			
		||||
        g_object_unref (head->data);
 | 
			
		||||
        priv->context_stack = g_slist_next (head);
 | 
			
		||||
        g_slist_free1 (head);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (priv->connection) {
 | 
			
		||||
        if (priv->registration_id > 0) {
 | 
			
		||||
            g_dbus_connection_unregister_object (priv->connection,
 | 
			
		||||
                                                 priv->registration_id);
 | 
			
		||||
            priv->registration_id = 0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        g_object_unref (priv->connection);
 | 
			
		||||
        priv->connection = NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (priv->introspection_data) {
 | 
			
		||||
        g_dbus_node_info_unref (priv->introspection_data);
 | 
			
		||||
        priv->introspection_data = NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    G_OBJECT_CLASS (eekboard_service_parent_class)->dispose (object);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
eekboard_service_finalize (GObject *object)
 | 
			
		||||
{
 | 
			
		||||
    EekboardServicePrivate *priv = EEKBOARD_SERVICE_GET_PRIVATE(object);
 | 
			
		||||
 | 
			
		||||
    g_free (priv->object_path);
 | 
			
		||||
 | 
			
		||||
    G_OBJECT_CLASS (eekboard_service_parent_class)->finalize (object);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
eekboard_service_constructed (GObject *object)
 | 
			
		||||
{
 | 
			
		||||
    EekboardServicePrivate *priv = EEKBOARD_SERVICE_GET_PRIVATE(object);
 | 
			
		||||
    if (priv->connection && priv->object_path) {
 | 
			
		||||
        GError *error = NULL;
 | 
			
		||||
 | 
			
		||||
        priv->registration_id = g_dbus_connection_register_object
 | 
			
		||||
            (priv->connection,
 | 
			
		||||
             priv->object_path,
 | 
			
		||||
             priv->introspection_data->interfaces[0],
 | 
			
		||||
             &interface_vtable,
 | 
			
		||||
             object,
 | 
			
		||||
             NULL,
 | 
			
		||||
             &error);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
eekboard_service_class_init (EekboardServiceClass *klass)
 | 
			
		||||
{
 | 
			
		||||
    GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 | 
			
		||||
    GParamSpec *pspec;
 | 
			
		||||
 | 
			
		||||
    g_type_class_add_private (gobject_class,
 | 
			
		||||
                              sizeof (EekboardServicePrivate));
 | 
			
		||||
 | 
			
		||||
    klass->create_context = NULL;
 | 
			
		||||
 | 
			
		||||
    gobject_class->constructed = eekboard_service_constructed;
 | 
			
		||||
    gobject_class->set_property = eekboard_service_set_property;
 | 
			
		||||
    gobject_class->get_property = eekboard_service_get_property;
 | 
			
		||||
    gobject_class->dispose = eekboard_service_dispose;
 | 
			
		||||
    gobject_class->finalize = eekboard_service_finalize;
 | 
			
		||||
 | 
			
		||||
    signals[DESTROYED] =
 | 
			
		||||
        g_signal_new (I_("destroyed"),
 | 
			
		||||
                      G_TYPE_FROM_CLASS(gobject_class),
 | 
			
		||||
                      G_SIGNAL_RUN_LAST,
 | 
			
		||||
                      0,
 | 
			
		||||
                      NULL,
 | 
			
		||||
                      NULL,
 | 
			
		||||
                      g_cclosure_marshal_VOID__VOID,
 | 
			
		||||
                      G_TYPE_NONE,
 | 
			
		||||
                      0);
 | 
			
		||||
 | 
			
		||||
    pspec = g_param_spec_string ("object-path",
 | 
			
		||||
                                 "Object-path",
 | 
			
		||||
                                 "Object-path",
 | 
			
		||||
                                 NULL,
 | 
			
		||||
                                 G_PARAM_CONSTRUCT | G_PARAM_READWRITE);
 | 
			
		||||
    g_object_class_install_property (gobject_class,
 | 
			
		||||
                                     PROP_OBJECT_PATH,
 | 
			
		||||
                                     pspec);
 | 
			
		||||
 | 
			
		||||
    pspec = g_param_spec_object ("connection",
 | 
			
		||||
                                 "Connection",
 | 
			
		||||
                                 "Connection",
 | 
			
		||||
                                 G_TYPE_DBUS_CONNECTION,
 | 
			
		||||
                                 G_PARAM_CONSTRUCT | G_PARAM_READWRITE);
 | 
			
		||||
    g_object_class_install_property (gobject_class,
 | 
			
		||||
                                     PROP_CONNECTION,
 | 
			
		||||
                                     pspec);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
eekboard_service_init (EekboardService *service)
 | 
			
		||||
{
 | 
			
		||||
    EekboardServicePrivate *priv;
 | 
			
		||||
    GError *error;
 | 
			
		||||
 | 
			
		||||
    priv = service->priv = EEKBOARD_SERVICE_GET_PRIVATE(service);
 | 
			
		||||
 | 
			
		||||
    error = NULL;
 | 
			
		||||
    priv->introspection_data =
 | 
			
		||||
        g_dbus_node_info_new_for_xml (introspection_xml, &error);
 | 
			
		||||
    g_assert (priv->introspection_data != NULL);
 | 
			
		||||
 | 
			
		||||
    priv->context_hash =
 | 
			
		||||
        g_hash_table_new_full (g_str_hash,
 | 
			
		||||
                               g_str_equal,
 | 
			
		||||
                               (GDestroyNotify)g_free,
 | 
			
		||||
                               (GDestroyNotify)g_object_unref);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
remove_context_from_stack (EekboardService        *service,
 | 
			
		||||
                           EekboardContextService *context)
 | 
			
		||||
{
 | 
			
		||||
    EekboardServicePrivate *priv = EEKBOARD_SERVICE_GET_PRIVATE(service);
 | 
			
		||||
    GSList *head;
 | 
			
		||||
 | 
			
		||||
    head = g_slist_find (priv->context_stack, context);
 | 
			
		||||
    if (head) {
 | 
			
		||||
        priv->context_stack = g_slist_remove_link (priv->context_stack, head);
 | 
			
		||||
        g_object_unref (head->data);
 | 
			
		||||
        g_slist_free1 (head);
 | 
			
		||||
    }
 | 
			
		||||
    if (priv->context_stack)
 | 
			
		||||
        eekboard_context_service_enable (priv->context_stack->data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
service_name_vanished_callback (GDBusConnection *connection,
 | 
			
		||||
                                const gchar     *name,
 | 
			
		||||
                                gpointer         user_data)
 | 
			
		||||
{
 | 
			
		||||
    EekboardService *service = user_data;
 | 
			
		||||
    EekboardServicePrivate *priv = EEKBOARD_SERVICE_GET_PRIVATE(service);
 | 
			
		||||
    GSList *head;
 | 
			
		||||
    GHashTableIter iter;
 | 
			
		||||
    gpointer k, v;
 | 
			
		||||
 | 
			
		||||
    g_hash_table_iter_init (&iter, priv->context_hash);
 | 
			
		||||
    while (g_hash_table_iter_next (&iter, &k, &v)) {
 | 
			
		||||
        const gchar *owner = g_object_get_data (G_OBJECT(v), "owner");
 | 
			
		||||
        if (g_strcmp0 (owner, name) == 0)
 | 
			
		||||
            g_hash_table_iter_remove (&iter);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for (head = priv->context_stack; head; ) {
 | 
			
		||||
        const gchar *owner = g_object_get_data (G_OBJECT(head->data), "owner");
 | 
			
		||||
        GSList *next = g_slist_next (head);
 | 
			
		||||
 | 
			
		||||
        if (g_strcmp0 (owner, name) == 0) {
 | 
			
		||||
            priv->context_stack =
 | 
			
		||||
                g_slist_remove_link (priv->context_stack, head);
 | 
			
		||||
            g_object_unref (head->data);
 | 
			
		||||
            g_slist_free1 (head);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        head = next;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (priv->context_stack)
 | 
			
		||||
        eekboard_context_service_enable (priv->context_stack->data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
handle_method_call (GDBusConnection       *connection,
 | 
			
		||||
                    const gchar           *sender,
 | 
			
		||||
                    const gchar           *object_path,
 | 
			
		||||
                    const gchar           *interface_name,
 | 
			
		||||
                    const gchar           *method_name,
 | 
			
		||||
                    GVariant              *parameters,
 | 
			
		||||
                    GDBusMethodInvocation *invocation,
 | 
			
		||||
                    gpointer               user_data)
 | 
			
		||||
{
 | 
			
		||||
    EekboardService *service = user_data;
 | 
			
		||||
    EekboardServicePrivate *priv = EEKBOARD_SERVICE_GET_PRIVATE(service);
 | 
			
		||||
    EekboardServiceClass *klass = EEKBOARD_SERVICE_GET_CLASS(service);
 | 
			
		||||
 | 
			
		||||
    if (g_strcmp0 (method_name, "CreateContext") == 0) {
 | 
			
		||||
        const gchar *client_name;
 | 
			
		||||
        gchar *object_path;
 | 
			
		||||
        static gint context_id = 0;
 | 
			
		||||
        EekboardContextService *context;
 | 
			
		||||
 | 
			
		||||
        g_variant_get (parameters, "(&s)", &client_name);
 | 
			
		||||
        object_path = g_strdup_printf (EEKBOARD_CONTEXT_SERVICE_PATH, context_id++);
 | 
			
		||||
        g_assert (klass->create_context);
 | 
			
		||||
        context = klass->create_context (service, client_name, object_path);
 | 
			
		||||
        g_object_set_data (G_OBJECT(context), "owner", g_strdup (sender));
 | 
			
		||||
        g_hash_table_insert (priv->context_hash,
 | 
			
		||||
                             object_path,
 | 
			
		||||
                             context);
 | 
			
		||||
 | 
			
		||||
        /* the vanished callback is called when clients are disconnected */
 | 
			
		||||
        g_bus_watch_name_on_connection (priv->connection,
 | 
			
		||||
                                        sender,
 | 
			
		||||
                                        G_BUS_NAME_WATCHER_FLAGS_NONE,
 | 
			
		||||
                                        NULL,
 | 
			
		||||
                                        service_name_vanished_callback,
 | 
			
		||||
                                        service,
 | 
			
		||||
                                        NULL);
 | 
			
		||||
        g_dbus_method_invocation_return_value (invocation,
 | 
			
		||||
                                               g_variant_new ("(s)",
 | 
			
		||||
                                                              object_path));
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (g_strcmp0 (method_name, "PushContext") == 0) {
 | 
			
		||||
        const gchar *object_path;
 | 
			
		||||
        EekboardContextService *context;
 | 
			
		||||
 | 
			
		||||
        g_variant_get (parameters, "(&s)", &object_path);
 | 
			
		||||
        context = g_hash_table_lookup (priv->context_hash, object_path);
 | 
			
		||||
        if (!context) {
 | 
			
		||||
            g_dbus_method_invocation_return_error (invocation,
 | 
			
		||||
                                                   G_IO_ERROR,
 | 
			
		||||
                                                   G_IO_ERROR_FAILED_HANDLED,
 | 
			
		||||
                                                   "context not found");
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        if (priv->context_stack)
 | 
			
		||||
            eekboard_context_service_disable (priv->context_stack->data);
 | 
			
		||||
        priv->context_stack = g_slist_prepend (priv->context_stack,
 | 
			
		||||
                                               g_object_ref (context));
 | 
			
		||||
        eekboard_context_service_enable (context);
 | 
			
		||||
 | 
			
		||||
        g_dbus_method_invocation_return_value (invocation, NULL);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (g_strcmp0 (method_name, "PopContext") == 0) {
 | 
			
		||||
        if (priv->context_stack) {
 | 
			
		||||
            EekboardContextService *context = priv->context_stack->data;
 | 
			
		||||
            gchar *object_path;
 | 
			
		||||
            const gchar *owner;
 | 
			
		||||
 | 
			
		||||
            g_object_get (G_OBJECT(context), "object-path", &object_path, NULL);
 | 
			
		||||
            owner = g_object_get_data (G_OBJECT(context), "owner");
 | 
			
		||||
            if (g_strcmp0 (owner, sender) != 0) {
 | 
			
		||||
                g_dbus_method_invocation_return_error
 | 
			
		||||
                    (invocation,
 | 
			
		||||
                     G_IO_ERROR,
 | 
			
		||||
                     G_IO_ERROR_FAILED_HANDLED,
 | 
			
		||||
                     "context at %s not owned by %s",
 | 
			
		||||
                     object_path, sender);
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            g_free (object_path);
 | 
			
		||||
                
 | 
			
		||||
            eekboard_context_service_disable (context);
 | 
			
		||||
            priv->context_stack = g_slist_next (priv->context_stack);
 | 
			
		||||
            if (priv->context_stack)
 | 
			
		||||
                eekboard_context_service_enable (priv->context_stack->data);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        g_dbus_method_invocation_return_value (invocation, NULL);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (g_strcmp0 (method_name, "DestroyContext") == 0) {
 | 
			
		||||
        EekboardContextService *context;
 | 
			
		||||
        const gchar *object_path;
 | 
			
		||||
        const gchar *owner;
 | 
			
		||||
 | 
			
		||||
        g_variant_get (parameters, "(&s)", &object_path);
 | 
			
		||||
        context = g_hash_table_lookup (priv->context_hash, object_path);
 | 
			
		||||
        if (!context) {
 | 
			
		||||
            g_dbus_method_invocation_return_error (invocation,
 | 
			
		||||
                                                   G_IO_ERROR,
 | 
			
		||||
                                                   G_IO_ERROR_FAILED_HANDLED,
 | 
			
		||||
                                                   "context not found");
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        owner = g_object_get_data (G_OBJECT(context), "owner");
 | 
			
		||||
        if (g_strcmp0 (owner, sender) != 0) {
 | 
			
		||||
            g_dbus_method_invocation_return_error
 | 
			
		||||
                (invocation,
 | 
			
		||||
                 G_IO_ERROR,
 | 
			
		||||
                 G_IO_ERROR_FAILED_HANDLED,
 | 
			
		||||
                 "the context at %s not owned by %s",
 | 
			
		||||
                 object_path, sender);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        remove_context_from_stack (service, context);
 | 
			
		||||
        g_hash_table_remove (priv->context_hash, object_path);
 | 
			
		||||
        g_dbus_method_invocation_return_value (invocation, NULL);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (g_strcmp0 (method_name, "Destroy") == 0) {
 | 
			
		||||
        g_signal_emit_by_name (service, "destroyed", NULL);
 | 
			
		||||
        g_dbus_method_invocation_return_value (invocation, NULL);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    g_return_if_reached ();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
EekboardService *
 | 
			
		||||
eekboard_service_new (const gchar     *object_path,
 | 
			
		||||
                      GDBusConnection *connection)
 | 
			
		||||
{
 | 
			
		||||
    return g_object_new (EEKBOARD_TYPE_SERVICE,
 | 
			
		||||
                         "object-path", object_path,
 | 
			
		||||
                         "connection", connection,
 | 
			
		||||
                         NULL);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										66
									
								
								eekboard/eekboard-service.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								eekboard/eekboard-service.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,66 @@
 | 
			
		||||
/* 
 | 
			
		||||
 * Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
 | 
			
		||||
 * Copyright (C) 2010-2011 Red Hat, Inc.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
 * (at your option) any later version.
 | 
			
		||||
 *
 | 
			
		||||
 * This program 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 General Public License for more details.
 | 
			
		||||
 *
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
#ifndef EEKBOARD_SERVICE_H
 | 
			
		||||
#define EEKBOARD_SERVICE_H 1
 | 
			
		||||
 | 
			
		||||
#define __EEKBOARD_SERVICE_H_INSIDE__ 1
 | 
			
		||||
 | 
			
		||||
#include "eekboard/eekboard-context-service.h"
 | 
			
		||||
 | 
			
		||||
G_BEGIN_DECLS
 | 
			
		||||
 | 
			
		||||
#define EEKBOARD_SERVICE_PATH "/org/fedorahosted/Eekboard"
 | 
			
		||||
#define EEKBOARD_SERVICE_INTERFACE "org.fedorahosted.Eekboard"
 | 
			
		||||
 | 
			
		||||
#define EEKBOARD_TYPE_SERVICE (eekboard_service_get_type())
 | 
			
		||||
#define EEKBOARD_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EEKBOARD_TYPE_SERVICE, EekboardService))
 | 
			
		||||
#define EEKBOARD_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EEKBOARD_TYPE_SERVICE, EekboardServiceClass))
 | 
			
		||||
#define EEKBOARD_IS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EEKBOARD_TYPE_SERVICE))
 | 
			
		||||
#define EEKBOARD_IS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EEKBOARD_TYPE_SERVICE))
 | 
			
		||||
#define EEKBOARD_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EEKBOARD_TYPE_SERVICE, EekboardServiceClass))
 | 
			
		||||
 | 
			
		||||
typedef struct _EekboardService EekboardService;
 | 
			
		||||
typedef struct _EekboardServiceClass EekboardServiceClass;
 | 
			
		||||
typedef struct _EekboardServicePrivate EekboardServicePrivate;
 | 
			
		||||
 | 
			
		||||
struct _EekboardService {
 | 
			
		||||
    GObject parent;
 | 
			
		||||
 | 
			
		||||
    EekboardServicePrivate *priv;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct _EekboardServiceClass {
 | 
			
		||||
    /*< private >*/
 | 
			
		||||
    GObjectClass parent_class;
 | 
			
		||||
 | 
			
		||||
    /*< public >*/
 | 
			
		||||
    EekboardContextService *(*create_context) (EekboardService *self,
 | 
			
		||||
                                               const gchar     *client_name,
 | 
			
		||||
                                               const gchar     *object_path);
 | 
			
		||||
 | 
			
		||||
    /*< private >*/
 | 
			
		||||
    /* padding */
 | 
			
		||||
    gpointer pdummy[24];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
GType             eekboard_service_get_type (void) G_GNUC_CONST;
 | 
			
		||||
EekboardService * eekboard_service_new      (const gchar     *object_path,
 | 
			
		||||
                                             GDBusConnection *connection);
 | 
			
		||||
 | 
			
		||||
G_END_DECLS
 | 
			
		||||
#endif  /* EEKBOARD_SERVICE_H */
 | 
			
		||||
							
								
								
									
										168
									
								
								eekboard/eekboard-xklutil.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										168
									
								
								eekboard/eekboard-xklutil.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,168 @@
 | 
			
		||||
/* 
 | 
			
		||||
 * Copyright (C) 2011 Daiki Ueno <ueno@unixuser.org>
 | 
			
		||||
 * Copyright (C) 2011 Red Hat, Inc.
 | 
			
		||||
 * 
 | 
			
		||||
 * 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
 | 
			
		||||
 * License along with this library; if not, write to the Free Software
 | 
			
		||||
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 | 
			
		||||
 * 02110-1301 USA
 | 
			
		||||
 */
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include "eekboard/eekboard-xklutil.h"
 | 
			
		||||
 | 
			
		||||
XklConfigRec *
 | 
			
		||||
eekboard_xkl_config_rec_from_string (const gchar *layouts)
 | 
			
		||||
{
 | 
			
		||||
    XklConfigRec *rec;
 | 
			
		||||
    gchar **strv, **l, **v;
 | 
			
		||||
    gint i;
 | 
			
		||||
 | 
			
		||||
    strv = g_strsplit (layouts, "/", -1);
 | 
			
		||||
    g_return_val_if_fail (g_strv_length (strv) == 3, NULL);
 | 
			
		||||
    
 | 
			
		||||
    l = g_strsplit (strv[1], ";", -1);
 | 
			
		||||
    v = g_strdupv (l);
 | 
			
		||||
    for (i = 0; l[i]; i++) {
 | 
			
		||||
        gchar *layout = l[i], *variant = v[i],
 | 
			
		||||
            *variant_start, *variant_end;
 | 
			
		||||
 | 
			
		||||
        variant_start = strchr (layout, '(');
 | 
			
		||||
        variant_end = strrchr (layout, ')');
 | 
			
		||||
        if (variant_start && variant_end) {
 | 
			
		||||
            *variant_start++ = '\0';
 | 
			
		||||
            g_strlcpy (variant, variant_start,
 | 
			
		||||
                       variant_end - variant_start + 1);
 | 
			
		||||
        } else
 | 
			
		||||
            *variant = '\0';
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    rec = xkl_config_rec_new ();
 | 
			
		||||
    rec->model = g_strdup (strv[0]);
 | 
			
		||||
    rec->layouts = l;
 | 
			
		||||
    rec->variants = v;
 | 
			
		||||
    rec->options = g_strsplit (strv[2], ";", -1);
 | 
			
		||||
    g_strfreev (strv);
 | 
			
		||||
 | 
			
		||||
    return rec;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
gchar *
 | 
			
		||||
eekboard_xkl_config_rec_to_string (XklConfigRec *rec)
 | 
			
		||||
{
 | 
			
		||||
    gchar **strv, **sp, **lp, **vp, *p;
 | 
			
		||||
    gint n_layouts;
 | 
			
		||||
    GString *str;
 | 
			
		||||
 | 
			
		||||
    n_layouts = g_strv_length (rec->layouts);
 | 
			
		||||
    strv = g_malloc0_n (n_layouts + 2, sizeof (gchar *));
 | 
			
		||||
    for (sp = strv, lp = rec->layouts, vp = rec->variants; *lp; sp++, lp++) {
 | 
			
		||||
        if (*vp != NULL && **vp != '\0')
 | 
			
		||||
            *sp = g_strdup_printf ("%s(%s)", *lp, *vp++);
 | 
			
		||||
        else
 | 
			
		||||
            *sp = g_strdup_printf ("%s", *lp);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* MODEL/L0(V0);L1(V1);...;Ln(Vn)/O0;O1;...;On */
 | 
			
		||||
    str = g_string_new (rec->model);
 | 
			
		||||
 | 
			
		||||
    g_string_append_c (str, '/');
 | 
			
		||||
    p = g_strjoinv (";", strv);
 | 
			
		||||
    g_strfreev (strv);
 | 
			
		||||
    g_string_append (str, p);
 | 
			
		||||
    g_free (p);
 | 
			
		||||
 | 
			
		||||
    g_string_append_c (str, '/');
 | 
			
		||||
    p = g_strjoinv (";", rec->options);
 | 
			
		||||
    g_string_append (str, p);
 | 
			
		||||
    g_free (p);
 | 
			
		||||
 | 
			
		||||
    return g_string_free (str,FALSE);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static XklConfigItem *
 | 
			
		||||
xkl_config_item_copy (const XklConfigItem *item)
 | 
			
		||||
{
 | 
			
		||||
    XklConfigItem *_item = xkl_config_item_new ();
 | 
			
		||||
    memcpy (_item->name,
 | 
			
		||||
            item->name,
 | 
			
		||||
            sizeof (item->name));
 | 
			
		||||
    memcpy (_item->short_description,
 | 
			
		||||
            item->short_description,
 | 
			
		||||
            sizeof (item->short_description));
 | 
			
		||||
    memcpy (_item->description,
 | 
			
		||||
            item->description,
 | 
			
		||||
            sizeof (item->description));
 | 
			
		||||
    return _item;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
prepend_item (XklConfigRegistry   *registry,
 | 
			
		||||
              const XklConfigItem *item,
 | 
			
		||||
              gpointer             data)
 | 
			
		||||
{
 | 
			
		||||
    GSList **list = data;
 | 
			
		||||
    XklConfigItem *_item = xkl_config_item_copy (item);
 | 
			
		||||
    *list = g_slist_prepend (*list, _item);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static gint
 | 
			
		||||
compare_item_by_name (gconstpointer a, gconstpointer b)
 | 
			
		||||
{
 | 
			
		||||
    const XklConfigItem *ia = a, *ib = b;
 | 
			
		||||
    return g_strcmp0 (ia->name, ib->name);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GSList *
 | 
			
		||||
eekboard_xkl_list_models (XklConfigRegistry *registry)
 | 
			
		||||
{
 | 
			
		||||
    GSList *list = NULL;
 | 
			
		||||
    xkl_config_registry_foreach_model (registry, prepend_item, &list);
 | 
			
		||||
    return g_slist_sort (list, compare_item_by_name);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GSList *
 | 
			
		||||
eekboard_xkl_list_layouts (XklConfigRegistry *registry)
 | 
			
		||||
{
 | 
			
		||||
    GSList *list = NULL;
 | 
			
		||||
    xkl_config_registry_foreach_layout (registry, prepend_item, &list);
 | 
			
		||||
    return g_slist_sort (list, compare_item_by_name);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GSList *
 | 
			
		||||
eekboard_xkl_list_option_groups (XklConfigRegistry *registry)
 | 
			
		||||
{
 | 
			
		||||
    GSList *list = NULL;
 | 
			
		||||
    xkl_config_registry_foreach_option_group (registry, prepend_item, &list);
 | 
			
		||||
    return g_slist_sort (list, compare_item_by_name);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GSList *
 | 
			
		||||
eekboard_xkl_list_layout_variants (XklConfigRegistry *registry,
 | 
			
		||||
                                   const gchar       *layout)
 | 
			
		||||
{
 | 
			
		||||
    GSList *list = NULL;
 | 
			
		||||
    xkl_config_registry_foreach_layout_variant (registry,
 | 
			
		||||
                                                layout,
 | 
			
		||||
                                                prepend_item,
 | 
			
		||||
                                                &list);
 | 
			
		||||
    return g_slist_sort (list, compare_item_by_name);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GSList *
 | 
			
		||||
eekboard_xkl_list_options (XklConfigRegistry *registry,
 | 
			
		||||
                           const gchar       *group)
 | 
			
		||||
{
 | 
			
		||||
    GSList *list = NULL;
 | 
			
		||||
    xkl_config_registry_foreach_option (registry, group, prepend_item, &list);
 | 
			
		||||
    return g_slist_sort (list, compare_item_by_name);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										39
									
								
								eekboard/eekboard-xklutil.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								eekboard/eekboard-xklutil.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,39 @@
 | 
			
		||||
/* 
 | 
			
		||||
 * Copyright (C) 2011 Daiki Ueno <ueno@unixuser.org>
 | 
			
		||||
 * Copyright (C) 2011 Red Hat, Inc.
 | 
			
		||||
 * 
 | 
			
		||||
 * 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
 | 
			
		||||
 * License along with this library; if not, write to the Free Software
 | 
			
		||||
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 | 
			
		||||
 * 02110-1301 USA
 | 
			
		||||
 */
 | 
			
		||||
#ifndef EEKBOARD_XKLUTIL_H
 | 
			
		||||
#define EEKBOARD_XKLUTIL_H 1
 | 
			
		||||
 | 
			
		||||
#include <libxklavier/xklavier.h>
 | 
			
		||||
 | 
			
		||||
G_BEGIN_DECLS
 | 
			
		||||
 | 
			
		||||
XklConfigRec *eekboard_xkl_config_rec_from_string (const gchar       *layouts);
 | 
			
		||||
gchar        *eekboard_xkl_config_rec_to_string   (XklConfigRec      *rec);
 | 
			
		||||
 | 
			
		||||
GSList       *eekboard_xkl_list_models            (XklConfigRegistry *registry);
 | 
			
		||||
GSList       *eekboard_xkl_list_layouts           (XklConfigRegistry *registry);
 | 
			
		||||
GSList       *eekboard_xkl_list_option_groups     (XklConfigRegistry *registry);
 | 
			
		||||
GSList       *eekboard_xkl_list_layout_variants   (XklConfigRegistry *registry,
 | 
			
		||||
                                                   const gchar       *layout);
 | 
			
		||||
GSList       *eekboard_xkl_list_options           (XklConfigRegistry *registry,
 | 
			
		||||
                                                   const gchar       *group);
 | 
			
		||||
 | 
			
		||||
G_END_DECLS
 | 
			
		||||
#endif  /* EEKBOARD_XKLUTIL_H */
 | 
			
		||||
@ -1,26 +0,0 @@
 | 
			
		||||
/* 
 | 
			
		||||
 * Copyright (C) 2011 Daiki Ueno <ueno@unixuser.org>
 | 
			
		||||
 * Copyright (C) 2011 Red Hat, Inc.
 | 
			
		||||
 * 
 | 
			
		||||
 * This program is free software: you can redistribute it and/or modify
 | 
			
		||||
 * it under the terms of the GNU General Public License as published by
 | 
			
		||||
 * the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
 * (at your option) any later version.
 | 
			
		||||
 *
 | 
			
		||||
 * This program 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 General Public License for more details.
 | 
			
		||||
 *
 | 
			
		||||
 * You should have received a copy of the GNU General Public License
 | 
			
		||||
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
#ifndef EEKBOARD_H
 | 
			
		||||
#define EEKBOARD_H 1
 | 
			
		||||
 | 
			
		||||
#define __EEKBOARD_H_INSIDE__ 1
 | 
			
		||||
 | 
			
		||||
#include "eekboard/eekboard-eekboard.h"
 | 
			
		||||
#include "eekboard/eekboard-context.h"
 | 
			
		||||
 | 
			
		||||
#endif  /* EEKBOARD_H */
 | 
			
		||||
		Reference in New Issue
	
	Block a user