Skip to content

Commit

Permalink
refactor(linux): Reformat file
Browse files Browse the repository at this point in the history
  • Loading branch information
ermshiperete committed Sep 14, 2023
1 parent 38b8cf7 commit 71c6bfb
Showing 1 changed file with 72 additions and 80 deletions.
152 changes: 72 additions & 80 deletions linux/ibus-keyman/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,125 +23,117 @@

#include <ibus.h>
#include <locale.h>
#include <stdlib.h>
#include <stdio.h>
#include "keymanutil.h"
#include <stdlib.h>
#include "engine.h"
#include "keyman-service.h"
#include "keymanutil.h"

static IBusBus *bus = NULL;
static IBusBus *bus = NULL;
static IBusFactory *factory = NULL;

/* options */
static gboolean xml = FALSE;
static gboolean xml = FALSE;
static gboolean ibus = FALSE;
gboolean testing = FALSE;

static const GOptionEntry entries[] =
{
{ "xml", 'x', 0, G_OPTION_ARG_NONE, &xml, "generate xml for engines", NULL },
{ "ibus", 'i', 0, G_OPTION_ARG_NONE, &ibus, "component is executed by ibus", NULL },
{ "testing", 0, 0, G_OPTION_ARG_NONE, &testing, "component is executed by integration testing", NULL},
{ NULL },
gboolean testing = FALSE;

static const GOptionEntry entries[] = {
{"xml", 'x', 0, G_OPTION_ARG_NONE, &xml, "generate xml for engines", NULL},
{"ibus", 'i', 0, G_OPTION_ARG_NONE, &ibus, "component is executed by ibus", NULL},
{"testing", 0, 0, G_OPTION_ARG_NONE, &testing, "component is executed by integration testing", NULL},
{NULL},
};

// Add an environment variable to see debug messages: export G_MESSAGES_DEBUG=all

static void
ibus_disconnected_cb (IBusBus *unused_bus,
gpointer unused_data)
{
g_debug ("bus disconnected");
KeymanService *service = km_service_get_default(NULL);
g_clear_object(&service);
ibus_disconnected_cb(IBusBus *unused_bus, gpointer unused_data) {
g_debug("bus disconnected");
KeymanService *service = km_service_get_default(NULL);
g_clear_object(&service);

g_object_unref(factory);
g_object_unref(bus);
g_object_unref(factory);
g_object_unref(bus);

ibus_quit ();
ibus_quit();
}


static void
start_component (void)
{
GList *engines, *p;
IBusComponent *component;
start_component(void) {
GList *engines, *p;
IBusComponent *component;

ibus_init ();
ibus_init();

bus = ibus_bus_new ();
g_signal_connect (bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL);
bus = ibus_bus_new();
g_signal_connect(bus, "disconnected", G_CALLBACK(ibus_disconnected_cb), NULL);

component = ibus_keyman_get_component ();
component = ibus_keyman_get_component();

factory = ibus_factory_new (ibus_bus_get_connection (bus));
factory = ibus_factory_new(ibus_bus_get_connection(bus));

engines = ibus_component_get_engines (component);
for (p = engines; p != NULL; p = p->next) {
IBusEngineDesc *engine = (IBusEngineDesc *)p->data;
#if IBUS_CHECK_VERSION(1,3,99)
const gchar *engine_name = ibus_engine_desc_get_name (engine);
engines = ibus_component_get_engines(component);
for (p = engines; p != NULL; p = p->next) {
IBusEngineDesc *engine = (IBusEngineDesc *)p->data;
#if IBUS_CHECK_VERSION(1, 3, 99)
const gchar *engine_name = ibus_engine_desc_get_name(engine);
#else
const gchar *engine_name = engine->name;
#endif /* !IBUS_CHECK_VERSION(1,3,99) */
ibus_factory_add_engine (factory, engine_name, IBUS_TYPE_KEYMAN_ENGINE);
}

if (ibus) {
ibus_bus_request_name (bus, "org.freedesktop.IBus.Keyman", 0);
}
else {
ibus_bus_register_component (bus, component);
}

g_object_unref (component);
km_service_get_default(NULL); // initialise dbus service

ibus_main ();
const gchar *engine_name = engine->name;
#endif /* !IBUS_CHECK_VERSION(1,3,99) */
ibus_factory_add_engine(factory, engine_name, IBUS_TYPE_KEYMAN_ENGINE);
}

if (ibus) {
ibus_bus_request_name(bus, "org.freedesktop.IBus.Keyman", 0);
} else {
ibus_bus_register_component(bus, component);
}

g_object_unref(component);
km_service_get_default(NULL); // initialise dbus service

ibus_main();
}

static void
print_engines_xml (void)
{
IBusComponent *component;
GString *output;
print_engines_xml(void) {
IBusComponent *component;
GString *output;

ibus_init ();
ibus_init();

component = ibus_keyman_get_component ();
output = g_string_new ("");
component = ibus_keyman_get_component();
output = g_string_new("");

ibus_component_output_engines (component, output, 0);
ibus_component_output_engines(component, output, 0);

fprintf (stdout, "%s", output->str);
fprintf(stdout, "%s", output->str);

g_string_free (output, TRUE);
g_object_unref(component);
g_string_free(output, TRUE);
g_object_unref(component);
}

int
main (gint argc, gchar **argv)
{
GError *error = NULL;
GOptionContext *context;
main(gint argc, gchar **argv) {
GError *error = NULL;
GOptionContext *context;

setlocale (LC_ALL, "");
setlocale(LC_ALL, "");

context = g_option_context_new ("- ibus Keyman engine component");
context = g_option_context_new("- ibus Keyman engine component");

g_option_context_add_main_entries (context, entries, "ibus-keyman");
g_option_context_add_main_entries(context, entries, "ibus-keyman");

if (!g_option_context_parse (context, &argc, &argv, &error)) {
g_print ("Option parsing failed: %s\n", error->message);
exit (-1);
}
if (!g_option_context_parse(context, &argc, &argv, &error)) {
g_print("Option parsing failed: %s\n", error->message);
exit(-1);
}

if (xml) {
print_engines_xml ();
exit (0);
}
if (xml) {
print_engines_xml();
exit(0);
}

start_component ();
return 0;
start_component();
return 0;
}

0 comments on commit 71c6bfb

Please sign in to comment.