Blame conf/memconf/main.c

Packit Service 1d8f1c
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
Packit Service 1d8f1c
/* vim:set et sts=4: */
Packit Service 1d8f1c
/* ibus - The Input Bus
Packit Service 1d8f1c
 * Copyright (c) 2010, Google Inc. All rights reserved.
Packit Service 1d8f1c
 * Copyright (C) 2010 Peng Huang <shawn.p.huang@gmail.com>
Packit Service 1d8f1c
 *
Packit Service 1d8f1c
 * This library is free software; you can redistribute it and/or
Packit Service 1d8f1c
 * modify it under the terms of the GNU Lesser General Public
Packit Service 1d8f1c
 * License as published by the Free Software Foundation; either
Packit Service 1d8f1c
 * version 2.1 of the License, or (at your option) any later version.
Packit Service 1d8f1c
 *
Packit Service 1d8f1c
 * This library is distributed in the hope that it will be useful,
Packit Service 1d8f1c
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 1d8f1c
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 1d8f1c
 * Lesser General Public License for more details.
Packit Service 1d8f1c
 *
Packit Service 1d8f1c
 * You should have received a copy of the GNU Lesser General Public
Packit Service 1d8f1c
 * License along with this library; if not, write to the Free Software
Packit Service 1d8f1c
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
Packit Service 1d8f1c
 * USA
Packit Service 1d8f1c
 */
Packit Service 1d8f1c
#include <ibus.h>
Packit Service 1d8f1c
#include <stdlib.h>
Packit Service 1d8f1c
#include <locale.h>
Packit Service 1d8f1c
#include "config.h"
Packit Service 1d8f1c
Packit Service 1d8f1c
static IBusBus *bus = NULL;
Packit Service 1d8f1c
static IBusConfigMemconf *config = NULL;
Packit Service 1d8f1c
Packit Service 1d8f1c
/* options */
Packit Service 1d8f1c
static gboolean ibus = FALSE;
Packit Service 1d8f1c
static gboolean verbose = FALSE;
Packit Service 1d8f1c
Packit Service 1d8f1c
static const GOptionEntry entries[] =
Packit Service 1d8f1c
{
Packit Service 1d8f1c
    { "ibus", 'i', 0, G_OPTION_ARG_NONE, &ibus, "component is executed by ibus", NULL },
Packit Service 1d8f1c
    { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "verbose", NULL },
Packit Service 1d8f1c
    { NULL },
Packit Service 1d8f1c
};
Packit Service 1d8f1c
Packit Service 1d8f1c
Packit Service 1d8f1c
static void
Packit Service 1d8f1c
ibus_disconnected_cb (IBusBus  *bus,
Packit Service 1d8f1c
                      gpointer  user_data)
Packit Service 1d8f1c
{
Packit Service 1d8f1c
    ibus_quit ();
Packit Service 1d8f1c
}
Packit Service 1d8f1c
Packit Service 1d8f1c
static void
Packit Service 1d8f1c
ibus_memconf_start (void)
Packit Service 1d8f1c
{
Packit Service 1d8f1c
    ibus_init ();
Packit Service 1d8f1c
    bus = ibus_bus_new ();
Packit Service 1d8f1c
    if (!ibus_bus_is_connected (bus)) {
Packit Service 1d8f1c
        exit (-1);
Packit Service 1d8f1c
    }
Packit Service 1d8f1c
    g_signal_connect (bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL);
Packit Service 1d8f1c
    config = ibus_config_memconf_new (ibus_bus_get_connection (bus));
Packit Service 1d8f1c
    ibus_bus_request_name (bus, IBUS_SERVICE_CONFIG, 0);
Packit Service 1d8f1c
    ibus_main ();
Packit Service 1d8f1c
}
Packit Service 1d8f1c
Packit Service 1d8f1c
gint
Packit Service 1d8f1c
main (gint argc, gchar **argv)
Packit Service 1d8f1c
{
Packit Service 1d8f1c
    GError *error = NULL;
Packit Service 1d8f1c
    GOptionContext *context;
Packit Service 1d8f1c
Packit Service 1d8f1c
    setlocale (LC_ALL, "");
Packit Service 1d8f1c
Packit Service 1d8f1c
    context = g_option_context_new ("- ibus memconf component");
Packit Service 1d8f1c
Packit Service 1d8f1c
    g_option_context_add_main_entries (context, entries, "ibus-memconf");
Packit Service 1d8f1c
Packit Service 1d8f1c
    if (!g_option_context_parse (context, &argc, &argv, &error)) {
Packit Service 1d8f1c
        g_print ("Option parsing failed: %s\n", error->message);
Packit Service 1d8f1c
        exit (-1);
Packit Service 1d8f1c
    }
Packit Service 1d8f1c
Packit Service 1d8f1c
    ibus_memconf_start ();
Packit Service 1d8f1c
Packit Service 1d8f1c
    return 0;
Packit Service 1d8f1c
}