init
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
This commit is contained in:
30
Telegram/ThirdParty/nimf/modules/services/nim/Makefile.am
vendored
Normal file
30
Telegram/ThirdParty/nimf/modules/services/nim/Makefile.am
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
moduledir = $(libdir)/nimf/modules/services
|
||||
module_LTLIBRARIES = libnimf-nim.la
|
||||
|
||||
libnimf_nim_la_SOURCES = \
|
||||
nimf-nim.c \
|
||||
nimf-nim.h \
|
||||
nimf-nim-ic.c \
|
||||
nimf-nim-ic.h \
|
||||
nimf-connection.c \
|
||||
nimf-connection.h \
|
||||
$(NULL)
|
||||
|
||||
libnimf_nim_la_CFLAGS = \
|
||||
$(EXTRA_CFLAGS) \
|
||||
-I$(top_srcdir)/libnimf \
|
||||
-DG_LOG_DOMAIN=\"nimf\" \
|
||||
$(NIMF_NIM_DEPS_CFLAGS)
|
||||
|
||||
libnimf_nim_la_LDFLAGS = -avoid-version -module $(NIMF_NIM_DEPS_LIBS)
|
||||
libnimf_nim_la_LIBADD = $(top_builddir)/libnimf/libnimf.la
|
||||
|
||||
DISTCLEANFILES = Makefile.in
|
||||
|
||||
install-data-hook:
|
||||
chmod -x $(DESTDIR)$(moduledir)/libnimf-nim.so
|
||||
rm -f $(DESTDIR)$(moduledir)/libnimf-nim.la
|
||||
|
||||
uninstall-hook:
|
||||
rm -f $(DESTDIR)$(moduledir)/libnimf-nim.so
|
||||
-rmdir -p $(DESTDIR)$(moduledir)
|
||||
124
Telegram/ThirdParty/nimf/modules/services/nim/nimf-connection.c
vendored
Normal file
124
Telegram/ThirdParty/nimf/modules/services/nim/nimf-connection.c
vendored
Normal file
@@ -0,0 +1,124 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
|
||||
/*
|
||||
* nimf-connection.c
|
||||
* This file is part of Nimf.
|
||||
*
|
||||
* Copyright (C) 2015-2019 Hodong Kim <cogniti@gmail.com>
|
||||
*
|
||||
* Nimf 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Nimf 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 program; If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "nimf-connection.h"
|
||||
#include "nimf-events.h"
|
||||
#include "nimf-service-ic.h"
|
||||
#include <string.h>
|
||||
#include "nimf-nim-ic.h"
|
||||
|
||||
G_DEFINE_TYPE (NimfConnection, nimf_connection, G_TYPE_OBJECT);
|
||||
|
||||
void
|
||||
nimf_connection_change_engine_by_id (NimfConnection *connection,
|
||||
const gchar *engine_id)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
GHashTableIter iter;
|
||||
gpointer im;
|
||||
|
||||
g_hash_table_iter_init (&iter, connection->ics);
|
||||
|
||||
while (g_hash_table_iter_next (&iter, NULL, &im))
|
||||
{
|
||||
if (NIMF_NIM_IC (im)->icid == connection->nim->last_focused_icid)
|
||||
nimf_service_ic_change_engine_by_id (im, engine_id);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nimf_connection_change_engine (NimfConnection *connection,
|
||||
const gchar *engine_id,
|
||||
const gchar *method_id)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
GHashTableIter iter;
|
||||
gpointer im;
|
||||
|
||||
g_hash_table_iter_init (&iter, connection->ics);
|
||||
|
||||
while (g_hash_table_iter_next (&iter, NULL, &im))
|
||||
{
|
||||
if (NIMF_NIM_IC (im)->icid == connection->nim->last_focused_icid)
|
||||
nimf_service_ic_change_engine (im, engine_id, method_id);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
nimf_connection_init (NimfConnection *connection)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
connection->result = nimf_result_new ();
|
||||
connection->ics = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL,
|
||||
(GDestroyNotify) g_object_unref);
|
||||
}
|
||||
|
||||
static void
|
||||
nimf_connection_finalize (GObject *object)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfConnection *connection = NIMF_CONNECTION (object);
|
||||
|
||||
if (connection->source)
|
||||
{
|
||||
g_source_destroy (connection->source);
|
||||
g_source_unref (connection->source);
|
||||
}
|
||||
|
||||
if (connection->socket_connection)
|
||||
g_object_unref (connection->socket_connection);
|
||||
|
||||
nimf_result_unref (connection->result);
|
||||
g_hash_table_unref (connection->ics);
|
||||
|
||||
G_OBJECT_CLASS (nimf_connection_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
nimf_connection_class_init (NimfConnectionClass *class)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
||||
object_class->finalize = nimf_connection_finalize;
|
||||
}
|
||||
|
||||
NimfConnection *
|
||||
nimf_connection_new ()
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
return g_object_new (NIMF_TYPE_CONNECTION, NULL);
|
||||
}
|
||||
|
||||
guint16
|
||||
nimf_connection_get_id (NimfConnection *connection)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
g_return_val_if_fail (NIMF_IS_CONNECTION (connection), 0);
|
||||
|
||||
return connection->id;
|
||||
}
|
||||
70
Telegram/ThirdParty/nimf/modules/services/nim/nimf-connection.h
vendored
Normal file
70
Telegram/ThirdParty/nimf/modules/services/nim/nimf-connection.h
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
|
||||
/*
|
||||
* nimf-connection.h
|
||||
* This file is part of Nimf.
|
||||
*
|
||||
* Copyright (C) 2015-2019 Hodong Kim <cogniti@gmail.com>
|
||||
*
|
||||
* Nimf 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Nimf 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 program; If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __NIMF_CONNECTION_H__
|
||||
#define __NIMF_CONNECTION_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
#include "nimf-nim.h"
|
||||
#include "nimf-message-private.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define NIMF_TYPE_CONNECTION (nimf_connection_get_type ())
|
||||
#define NIMF_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NIMF_TYPE_CONNECTION, NimfConnection))
|
||||
#define NIMF_CONNECTION_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), NIMF_TYPE_CONNECTION, NimfConnectionClass))
|
||||
#define NIMF_IS_CONNECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NIMF_TYPE_CONNECTION))
|
||||
#define NIMF_IS_CONNECTION_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), NIMF_TYPE_CONNECTION))
|
||||
#define NIMF_CONNECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NIMF_TYPE_CONNECTION, NimfConnectionClass))
|
||||
|
||||
typedef struct _NimfConnection NimfConnection;
|
||||
typedef struct _NimfConnectionClass NimfConnectionClass;
|
||||
|
||||
struct _NimfConnection
|
||||
{
|
||||
GObject parent_instance;
|
||||
|
||||
guint16 id;
|
||||
NimfNim *nim;
|
||||
GSocket *socket;
|
||||
NimfResult *result;
|
||||
GSource *source;
|
||||
GSocketConnection *socket_connection;
|
||||
GHashTable *ics;
|
||||
};
|
||||
|
||||
struct _NimfConnectionClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
GType nimf_connection_get_type (void) G_GNUC_CONST;
|
||||
NimfConnection *nimf_connection_new (void);
|
||||
guint16 nimf_connection_get_id (NimfConnection *connection);
|
||||
void nimf_connection_change_engine_by_id
|
||||
(NimfConnection *connection,
|
||||
const gchar *engine_id);
|
||||
void nimf_connection_change_engine (NimfConnection *connection,
|
||||
const gchar *engine_id,
|
||||
const gchar *method_id);
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __NIMF_CONNECTION_H__ */
|
||||
211
Telegram/ThirdParty/nimf/modules/services/nim/nimf-nim-ic.c
vendored
Normal file
211
Telegram/ThirdParty/nimf/modules/services/nim/nimf-nim-ic.c
vendored
Normal file
@@ -0,0 +1,211 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
|
||||
/*
|
||||
* nimf-nim-ic.c
|
||||
* This file is part of Nimf.
|
||||
*
|
||||
* Copyright (C) 2015-2019 Hodong Kim <cogniti@gmail.com>
|
||||
*
|
||||
* Nimf 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Nimf 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 program; If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "nimf-nim-ic.h"
|
||||
#include <string.h>
|
||||
#include "nimf-connection.h"
|
||||
#include "nimf-message-private.h"
|
||||
|
||||
G_DEFINE_TYPE (NimfNimIC, nimf_nim_ic, NIMF_TYPE_SERVICE_IC);
|
||||
|
||||
void
|
||||
nimf_nim_ic_emit_commit (NimfServiceIC *ic,
|
||||
const gchar *text)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfNimIC *nic = NIMF_NIM_IC (ic);
|
||||
|
||||
nimf_send_message (nic->connection->socket, nic->icid, NIMF_MESSAGE_COMMIT,
|
||||
(gchar *) text, strlen (text) + 1, NULL);
|
||||
nimf_result_iteration_until (nic->connection->result, NULL, nic->icid,
|
||||
NIMF_MESSAGE_COMMIT_REPLY);
|
||||
}
|
||||
|
||||
void nimf_nim_ic_emit_preedit_start (NimfServiceIC *ic)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfNimIC *nic = NIMF_NIM_IC (ic);
|
||||
|
||||
nimf_send_message (nic->connection->socket, nic->icid,
|
||||
NIMF_MESSAGE_PREEDIT_START, NULL, 0, NULL);
|
||||
nimf_result_iteration_until (nic->connection->result, NULL, nic->icid,
|
||||
NIMF_MESSAGE_PREEDIT_START_REPLY);
|
||||
}
|
||||
|
||||
void
|
||||
nimf_nim_ic_emit_preedit_changed (NimfServiceIC *ic,
|
||||
const gchar *preedit_string,
|
||||
NimfPreeditAttr **attrs,
|
||||
gint cursor_pos)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfNimIC *nic = NIMF_NIM_IC (ic);
|
||||
gchar *data;
|
||||
gsize data_len;
|
||||
gint str_len = strlen (preedit_string);
|
||||
gint n_attr = 0;
|
||||
gint i;
|
||||
|
||||
while (attrs[n_attr] != NULL)
|
||||
n_attr++;
|
||||
|
||||
data_len = str_len + 1 + n_attr * sizeof (NimfPreeditAttr) + sizeof (gint);
|
||||
data = g_strndup (preedit_string, data_len - 1);
|
||||
|
||||
for (i = 0; attrs[i] != NULL; i++)
|
||||
*(NimfPreeditAttr *)
|
||||
(data + str_len + 1 + i * sizeof (NimfPreeditAttr)) = *attrs[i];
|
||||
|
||||
*(gint *) (data + data_len - sizeof (gint)) = cursor_pos;
|
||||
|
||||
nimf_send_message (nic->connection->socket, nic->icid,
|
||||
NIMF_MESSAGE_PREEDIT_CHANGED, data, data_len, g_free);
|
||||
nimf_result_iteration_until (nic->connection->result, NULL, nic->icid,
|
||||
NIMF_MESSAGE_PREEDIT_CHANGED_REPLY);
|
||||
}
|
||||
|
||||
void nimf_nim_ic_emit_preedit_end (NimfServiceIC *ic)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfNimIC *nic = NIMF_NIM_IC (ic);
|
||||
|
||||
nimf_send_message (nic->connection->socket, nic->icid,
|
||||
NIMF_MESSAGE_PREEDIT_END, NULL, 0, NULL);
|
||||
nimf_result_iteration_until (nic->connection->result, NULL, nic->icid,
|
||||
NIMF_MESSAGE_PREEDIT_END_REPLY);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nimf_nim_ic_emit_retrieve_surrounding (NimfServiceIC *ic)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfNimIC *nic = NIMF_NIM_IC (ic);
|
||||
|
||||
nimf_send_message (nic->connection->socket, nic->icid,
|
||||
NIMF_MESSAGE_RETRIEVE_SURROUNDING, NULL, 0, NULL);
|
||||
nimf_result_iteration_until (nic->connection->result, NULL, nic->icid,
|
||||
NIMF_MESSAGE_RETRIEVE_SURROUNDING_REPLY);
|
||||
|
||||
if (nic->connection->result->reply == NULL)
|
||||
return FALSE;
|
||||
|
||||
return *(gboolean *) (nic->connection->result->reply->data);
|
||||
}
|
||||
|
||||
gboolean
|
||||
nimf_nim_ic_emit_delete_surrounding (NimfServiceIC *ic,
|
||||
gint offset,
|
||||
gint n_chars)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfNimIC *nic = NIMF_NIM_IC (ic);
|
||||
|
||||
gint *data = g_malloc (2 * sizeof (gint));
|
||||
data[0] = offset;
|
||||
data[1] = n_chars;
|
||||
|
||||
nimf_send_message (nic->connection->socket, nic->icid,
|
||||
NIMF_MESSAGE_DELETE_SURROUNDING,
|
||||
data, 2 * sizeof (gint), g_free);
|
||||
nimf_result_iteration_until (nic->connection->result, NULL, nic->icid,
|
||||
NIMF_MESSAGE_DELETE_SURROUNDING_REPLY);
|
||||
|
||||
if (nic->connection->result->reply == NULL)
|
||||
return FALSE;
|
||||
|
||||
return *(gboolean *) (nic->connection->result->reply->data);
|
||||
}
|
||||
|
||||
void nimf_nim_ic_emit_beep (NimfServiceIC *ic)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfNimIC *nic = NIMF_NIM_IC (ic);
|
||||
|
||||
nimf_send_message (nic->connection->socket, nic->icid,
|
||||
NIMF_MESSAGE_BEEP, NULL, 0, NULL);
|
||||
nimf_result_iteration_until (nic->connection->result, NULL, nic->icid,
|
||||
NIMF_MESSAGE_BEEP_REPLY);
|
||||
}
|
||||
|
||||
const gchar *
|
||||
nimf_nim_ic_get_service_id (NimfServiceIC *ic)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfService *service = NIMF_SERVICE (NIMF_NIM_IC (ic)->connection->nim);
|
||||
|
||||
return nimf_service_get_id (service);
|
||||
}
|
||||
|
||||
NimfNimIC *
|
||||
nimf_nim_ic_new (guint16 icid,
|
||||
NimfConnection *connection)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfNimIC *nic = g_object_new (NIMF_TYPE_NIM_IC, NULL);
|
||||
|
||||
nic->connection = connection;
|
||||
nic->icid = icid;
|
||||
|
||||
return nic;
|
||||
}
|
||||
|
||||
static void
|
||||
nimf_nim_ic_init (NimfNimIC *nic)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
}
|
||||
|
||||
static void
|
||||
nimf_nim_ic_finalize (GObject *object)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
G_OBJECT_CLASS (nimf_nim_ic_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
nimf_nim_ic_class_init (NimfNimICClass *class)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
||||
NimfServiceICClass *service_im_class = NIMF_SERVICE_IC_CLASS (class);
|
||||
|
||||
object_class->finalize = nimf_nim_ic_finalize;
|
||||
|
||||
service_im_class->emit_commit = nimf_nim_ic_emit_commit;
|
||||
service_im_class->emit_preedit_start = nimf_nim_ic_emit_preedit_start;
|
||||
service_im_class->emit_preedit_changed = nimf_nim_ic_emit_preedit_changed;
|
||||
service_im_class->emit_preedit_end = nimf_nim_ic_emit_preedit_end;
|
||||
service_im_class->emit_retrieve_surrounding = nimf_nim_ic_emit_retrieve_surrounding;
|
||||
service_im_class->emit_delete_surrounding = nimf_nim_ic_emit_delete_surrounding;
|
||||
service_im_class->emit_beep = nimf_nim_ic_emit_beep;
|
||||
service_im_class->get_service_id = nimf_nim_ic_get_service_id;
|
||||
}
|
||||
58
Telegram/ThirdParty/nimf/modules/services/nim/nimf-nim-ic.h
vendored
Normal file
58
Telegram/ThirdParty/nimf/modules/services/nim/nimf-nim-ic.h
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
|
||||
/*
|
||||
* nimf-nim-ic.h
|
||||
* This file is part of Nimf.
|
||||
*
|
||||
* Copyright (C) 2015-2019 Hodong Kim <cogniti@gmail.com>
|
||||
*
|
||||
* Nimf 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Nimf 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 program; If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __NIMF_NIM_IC_H__
|
||||
#define __NIMF_NIM_IC_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
#include "nimf-service-ic.h"
|
||||
#include "nimf-connection.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define NIMF_TYPE_NIM_IC (nimf_nim_ic_get_type ())
|
||||
#define NIMF_NIM_IC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NIMF_TYPE_NIM_IC, NimfNimIC))
|
||||
#define NIMF_NIM_IC_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), NIMF_TYPE_NIM_IC, NimfNimICClass))
|
||||
#define NIMF_IS_NIM_IC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NIMF_TYPE_NIM_IC))
|
||||
#define NIMF_IS_NIM_IC_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), NIMF_TYPE_NIM_IC))
|
||||
#define NIMF_NIM_IC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NIMF_TYPE_NIM_IC, NimfNimICClass))
|
||||
|
||||
typedef struct _NimfNimIC NimfNimIC;
|
||||
typedef struct _NimfNimICClass NimfNimICClass;
|
||||
|
||||
struct _NimfNimICClass
|
||||
{
|
||||
NimfServiceICClass parent_class;
|
||||
};
|
||||
|
||||
struct _NimfNimIC
|
||||
{
|
||||
NimfServiceIC parent_instance;
|
||||
NimfConnection *connection;
|
||||
guint16 icid;
|
||||
};
|
||||
|
||||
GType nimf_nim_ic_get_type (void) G_GNUC_CONST;
|
||||
NimfNimIC *nimf_nim_ic_new (guint16 icid, NimfConnection *connection);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __NIMF_NIM_IC_H__ */
|
||||
380
Telegram/ThirdParty/nimf/modules/services/nim/nimf-nim.c
vendored
Normal file
380
Telegram/ThirdParty/nimf/modules/services/nim/nimf-nim.c
vendored
Normal file
@@ -0,0 +1,380 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
|
||||
/*
|
||||
* nimf-nim.c
|
||||
* This file is part of Nimf.
|
||||
*
|
||||
* Copyright (C) 2015-2019 Hodong Kim <cogniti@gmail.com>
|
||||
*
|
||||
* Nimf 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Nimf 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 program; If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "nimf-nim.h"
|
||||
#include "nimf-nim-ic.h"
|
||||
#include "nimf-message-private.h"
|
||||
#include "nimf-connection.h"
|
||||
#include <gio/gunixsocketaddress.h>
|
||||
#include <glib.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include "nimf-utils.h"
|
||||
|
||||
G_DEFINE_DYNAMIC_TYPE (NimfNim, nimf_nim, NIMF_TYPE_SERVICE);
|
||||
|
||||
static const gchar *
|
||||
nimf_nim_get_id (NimfService *service)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
g_return_val_if_fail (NIMF_IS_SERVICE (service), NULL);
|
||||
|
||||
return NIMF_NIM (service)->id;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
on_incoming (GSocket *socket,
|
||||
GIOCondition condition,
|
||||
NimfConnection *connection)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfMessage *message;
|
||||
gboolean retval;
|
||||
nimf_message_unref (connection->result->reply);
|
||||
connection->result->is_dispatched = TRUE;
|
||||
|
||||
if (condition & (G_IO_HUP | G_IO_ERR))
|
||||
{
|
||||
g_debug (G_STRLOC ": condition & (G_IO_HUP | G_IO_ERR)");
|
||||
|
||||
g_socket_close (socket, NULL);
|
||||
|
||||
GHashTableIter iter;
|
||||
gpointer ic;
|
||||
|
||||
g_hash_table_iter_init (&iter, connection->ics);
|
||||
|
||||
while (g_hash_table_iter_next (&iter, NULL, &ic))
|
||||
nimf_service_ic_reset (ic);
|
||||
|
||||
connection->result->reply = NULL;
|
||||
g_hash_table_remove (connection->nim->connections,
|
||||
GUINT_TO_POINTER (nimf_connection_get_id (connection)));
|
||||
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
message = nimf_recv_message (socket);
|
||||
connection->result->reply = message;
|
||||
|
||||
if (G_UNLIKELY (message == NULL))
|
||||
{
|
||||
g_critical (G_STRLOC ": NULL message");
|
||||
return G_SOURCE_CONTINUE;
|
||||
}
|
||||
|
||||
NimfNimIC *nic;
|
||||
guint16 icid = message->header->icid;
|
||||
|
||||
nic = g_hash_table_lookup (connection->ics, GUINT_TO_POINTER (icid));
|
||||
|
||||
switch (message->header->type)
|
||||
{
|
||||
case NIMF_MESSAGE_CREATE_CONTEXT:
|
||||
nic = nimf_nim_ic_new (icid, connection);
|
||||
g_hash_table_insert (connection->ics, GUINT_TO_POINTER (icid), nic);
|
||||
nimf_send_message (socket, icid, NIMF_MESSAGE_CREATE_CONTEXT_REPLY,
|
||||
NULL, 0, NULL);
|
||||
break;
|
||||
case NIMF_MESSAGE_DESTROY_CONTEXT:
|
||||
g_hash_table_remove (connection->ics, GUINT_TO_POINTER (icid));
|
||||
nimf_send_message (socket, icid, NIMF_MESSAGE_DESTROY_CONTEXT_REPLY,
|
||||
NULL, 0, NULL);
|
||||
break;
|
||||
case NIMF_MESSAGE_FILTER_EVENT:
|
||||
nimf_message_ref (message);
|
||||
retval = nimf_service_ic_filter_event (NIMF_SERVICE_IC (nic), (NimfEvent *) message->data);
|
||||
nimf_message_unref (message);
|
||||
nimf_send_message (socket, icid, NIMF_MESSAGE_FILTER_EVENT_REPLY,
|
||||
&retval, sizeof (gboolean), NULL);
|
||||
break;
|
||||
case NIMF_MESSAGE_RESET:
|
||||
nimf_service_ic_reset (NIMF_SERVICE_IC (nic));
|
||||
nimf_send_message (socket, icid, NIMF_MESSAGE_RESET_REPLY,
|
||||
NULL, 0, NULL);
|
||||
break;
|
||||
case NIMF_MESSAGE_FOCUS_IN:
|
||||
nimf_service_ic_focus_in (NIMF_SERVICE_IC (nic));
|
||||
nimf_send_message (socket, icid, NIMF_MESSAGE_FOCUS_IN_REPLY,
|
||||
NULL, 0, NULL);
|
||||
connection->nim->last_focused_conn_id = connection->id;
|
||||
connection->nim->last_focused_icid = icid;
|
||||
break;
|
||||
case NIMF_MESSAGE_FOCUS_OUT:
|
||||
nimf_service_ic_focus_out (NIMF_SERVICE_IC (nic));
|
||||
nimf_send_message (socket, icid, NIMF_MESSAGE_FOCUS_OUT_REPLY,
|
||||
NULL, 0, NULL);
|
||||
break;
|
||||
case NIMF_MESSAGE_SET_SURROUNDING:
|
||||
{
|
||||
nimf_message_ref (message);
|
||||
gchar *data = message->data;
|
||||
guint16 data_len = message->header->data_len;
|
||||
|
||||
gint str_len = data_len - 1 - 2 * sizeof (gint);
|
||||
gint cursor_index = *(gint *) (data + data_len - sizeof (gint));
|
||||
|
||||
nimf_service_ic_set_surrounding (NIMF_SERVICE_IC (nic), data, str_len, cursor_index);
|
||||
nimf_message_unref (message);
|
||||
nimf_send_message (socket, icid,
|
||||
NIMF_MESSAGE_SET_SURROUNDING_REPLY, NULL, 0, NULL);
|
||||
}
|
||||
break;
|
||||
case NIMF_MESSAGE_SET_CURSOR_LOCATION:
|
||||
nimf_message_ref (message);
|
||||
nimf_service_ic_set_cursor_location (NIMF_SERVICE_IC (nic), (NimfRectangle *) message->data);
|
||||
nimf_message_unref (message);
|
||||
nimf_send_message (socket, icid, NIMF_MESSAGE_SET_CURSOR_LOCATION_REPLY,
|
||||
NULL, 0, NULL);
|
||||
break;
|
||||
case NIMF_MESSAGE_SET_USE_PREEDIT:
|
||||
nimf_message_ref (message);
|
||||
nimf_service_ic_set_use_preedit (NIMF_SERVICE_IC (nic), *(gboolean *) message->data);
|
||||
nimf_message_unref (message);
|
||||
nimf_send_message (socket, icid, NIMF_MESSAGE_SET_USE_PREEDIT_REPLY,
|
||||
NULL, 0, NULL);
|
||||
break;
|
||||
case NIMF_MESSAGE_PREEDIT_START_REPLY:
|
||||
case NIMF_MESSAGE_PREEDIT_CHANGED_REPLY:
|
||||
case NIMF_MESSAGE_PREEDIT_END_REPLY:
|
||||
case NIMF_MESSAGE_COMMIT_REPLY:
|
||||
case NIMF_MESSAGE_RETRIEVE_SURROUNDING_REPLY:
|
||||
case NIMF_MESSAGE_DELETE_SURROUNDING_REPLY:
|
||||
case NIMF_MESSAGE_BEEP_REPLY:
|
||||
break;
|
||||
default:
|
||||
g_warning ("Unknown message type: %d", message->header->type);
|
||||
break;
|
||||
}
|
||||
|
||||
return G_SOURCE_CONTINUE;
|
||||
}
|
||||
|
||||
static guint16
|
||||
nimf_nim_add_connection (NimfNim *nim,
|
||||
NimfConnection *connection)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
guint16 id;
|
||||
|
||||
do
|
||||
id = nim->next_id++;
|
||||
while (id == 0 || g_hash_table_contains (nim->connections,
|
||||
GUINT_TO_POINTER (id)));
|
||||
connection->id = id;
|
||||
connection->nim = nim;
|
||||
g_hash_table_insert (nim->connections, GUINT_TO_POINTER (id), connection);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
on_new_connection (GSocketService *service,
|
||||
GSocketConnection *socket_connection,
|
||||
GObject *source_object,
|
||||
NimfNim *nim)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfConnection *connection;
|
||||
connection = nimf_connection_new ();
|
||||
connection->socket = g_socket_connection_get_socket (socket_connection);
|
||||
nimf_nim_add_connection (nim, connection);
|
||||
|
||||
connection->source = g_socket_create_source (connection->socket, G_IO_IN, NULL);
|
||||
connection->socket_connection = g_object_ref (socket_connection);
|
||||
g_source_set_can_recurse (connection->source, TRUE);
|
||||
g_source_set_callback (connection->source,
|
||||
(GSourceFunc) on_incoming,
|
||||
connection, NULL);
|
||||
g_source_attach (connection->source, NULL);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void nimf_nim_change_engine (NimfService *service,
|
||||
const gchar *engine_id,
|
||||
const gchar *method_id)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfNim *nim = NIMF_NIM (service);
|
||||
|
||||
if (nim->last_focused_conn_id > 0)
|
||||
{
|
||||
NimfConnection *connection;
|
||||
connection = g_hash_table_lookup (nim->connections,
|
||||
GUINT_TO_POINTER (nim->last_focused_conn_id));
|
||||
if (connection)
|
||||
nimf_connection_change_engine (connection, engine_id, method_id);
|
||||
}
|
||||
}
|
||||
|
||||
static void nimf_nim_change_engine_by_id (NimfService *service,
|
||||
const gchar *engine_id)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfNim *nim = NIMF_NIM (service);
|
||||
|
||||
if (nim->last_focused_conn_id > 0)
|
||||
{
|
||||
NimfConnection *connection;
|
||||
connection = g_hash_table_lookup (nim->connections,
|
||||
GUINT_TO_POINTER (nim->last_focused_conn_id));
|
||||
if (connection)
|
||||
nimf_connection_change_engine_by_id (connection, engine_id);
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean nimf_nim_is_active (NimfService *service)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
return NIMF_NIM (service)->active;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
nimf_nim_start (NimfService *service)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfNim *nim = NIMF_NIM (service);
|
||||
|
||||
if (nim->active)
|
||||
return TRUE;
|
||||
|
||||
GSocketAddress *address;
|
||||
gchar *path;
|
||||
GError *error = NULL;
|
||||
|
||||
nim->service = g_socket_service_new ();
|
||||
path = nimf_get_socket_path ();
|
||||
address = g_unix_socket_address_new_with_type (path, -1,
|
||||
G_UNIX_SOCKET_ADDRESS_PATH);
|
||||
g_socket_listener_add_address (G_SOCKET_LISTENER (nim->service), address,
|
||||
G_SOCKET_TYPE_STREAM,
|
||||
G_SOCKET_PROTOCOL_DEFAULT,
|
||||
NULL, NULL, &error);
|
||||
g_object_unref (address);
|
||||
g_chmod (path, 0600);
|
||||
g_free (path);
|
||||
|
||||
if (error)
|
||||
{
|
||||
g_critical (G_STRLOC ": %s: %s", G_STRFUNC, error->message);
|
||||
g_clear_error (&error);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_signal_connect (nim->service, "incoming",
|
||||
G_CALLBACK (on_new_connection), nim);
|
||||
g_socket_service_start (nim->service);
|
||||
|
||||
return nim->active = TRUE;
|
||||
}
|
||||
|
||||
static void nimf_nim_stop (NimfService *service)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfNim *nim = NIMF_NIM (service);
|
||||
|
||||
if (!nim->active)
|
||||
return;
|
||||
|
||||
g_socket_service_stop (nim->service);
|
||||
|
||||
nim->active = FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
nimf_nim_init (NimfNim *nim)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
nim->id = g_strdup ("nimf-nim");
|
||||
nim->connections = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL,
|
||||
(GDestroyNotify) g_object_unref);
|
||||
}
|
||||
|
||||
static void nimf_nim_finalize (GObject *object)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
NimfService *service = NIMF_SERVICE (object);
|
||||
NimfNim *nim = NIMF_NIM (object);
|
||||
|
||||
if (nimf_nim_is_active (service))
|
||||
nimf_nim_stop (service);
|
||||
|
||||
if (nim->service != NULL)
|
||||
g_object_unref (nim->service);
|
||||
|
||||
g_hash_table_unref (nim->connections);
|
||||
g_free (nim->id);
|
||||
|
||||
G_OBJECT_CLASS (nimf_nim_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
nimf_nim_class_init (NimfNimClass *class)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
||||
NimfServiceClass *service_class = NIMF_SERVICE_CLASS (class);
|
||||
|
||||
service_class->get_id = nimf_nim_get_id;
|
||||
service_class->start = nimf_nim_start;
|
||||
service_class->stop = nimf_nim_stop;
|
||||
service_class->is_active = nimf_nim_is_active;
|
||||
service_class->change_engine = nimf_nim_change_engine;
|
||||
service_class->change_engine_by_id = nimf_nim_change_engine_by_id;
|
||||
|
||||
object_class->finalize = nimf_nim_finalize;
|
||||
}
|
||||
|
||||
static void
|
||||
nimf_nim_class_finalize (NimfNimClass *class)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
}
|
||||
|
||||
void module_register_type (GTypeModule *type_module)
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
nimf_nim_register_type (type_module);
|
||||
}
|
||||
|
||||
GType module_get_type ()
|
||||
{
|
||||
g_debug (G_STRLOC ": %s", G_STRFUNC);
|
||||
|
||||
return nimf_nim_get_type ();
|
||||
}
|
||||
63
Telegram/ThirdParty/nimf/modules/services/nim/nimf-nim.h
vendored
Normal file
63
Telegram/ThirdParty/nimf/modules/services/nim/nimf-nim.h
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
|
||||
/*
|
||||
* nimf-nim.h
|
||||
* This file is part of Nimf.
|
||||
*
|
||||
* Copyright (C) 2015-2019 Hodong Kim <cogniti@gmail.com>
|
||||
*
|
||||
* Nimf 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Nimf 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 program; If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __NIMF_NIM_H__
|
||||
#define __NIMF_NIM_H__
|
||||
|
||||
#include "config.h"
|
||||
#include <nimf.h>
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define NIMF_TYPE_NIM (nimf_nim_get_type ())
|
||||
#define NIMF_NIM(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), NIMF_TYPE_NIM, NimfNim))
|
||||
#define NIMF_NIM_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), NIMF_TYPE_NIM, NimfNimClass))
|
||||
#define NIMF_IS_NIM(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), NIMF_TYPE_NIM))
|
||||
#define NIMF_IS_NIM_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), NIMF_TYPE_NIM))
|
||||
#define NIMF_NIM_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), NIMF_TYPE_NIM, NimfNimClass))
|
||||
|
||||
typedef struct _NimfNim NimfNim;
|
||||
typedef struct _NimfNimClass NimfNimClass;
|
||||
|
||||
struct _NimfNim
|
||||
{
|
||||
NimfService parent_instance;
|
||||
|
||||
gchar *id;
|
||||
gboolean active;
|
||||
GHashTable *connections;
|
||||
guint16 next_id;
|
||||
guint16 last_focused_conn_id;
|
||||
guint16 last_focused_icid;
|
||||
GSocketService *service;
|
||||
};
|
||||
|
||||
struct _NimfNimClass
|
||||
{
|
||||
NimfServiceClass parent_class;
|
||||
};
|
||||
|
||||
GType nimf_nim_get_type (void) G_GNUC_CONST;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __NIMF_NIM_H__ */
|
||||
Reference in New Issue
Block a user