Blame conf/dconf/main.c

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