Add command-line option to specify D-Bus type and address.
This commit is contained in:
		@ -19,10 +19,15 @@
 | 
				
			|||||||
#include "config.h"
 | 
					#include "config.h"
 | 
				
			||||||
#endif  /* HAVE_CONFIG_H */
 | 
					#endif  /* HAVE_CONFIG_H */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include <stdlib.h>
 | 
				
			||||||
#include <glib/gi18n.h>
 | 
					#include <glib/gi18n.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "eekboard/eekboard.h"
 | 
					#include "eekboard/eekboard.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static gboolean opt_system = FALSE;
 | 
				
			||||||
 | 
					static gboolean opt_session = FALSE;
 | 
				
			||||||
 | 
					static gchar *opt_address = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static gchar *opt_set_keyboard = NULL;
 | 
					static gchar *opt_set_keyboard = NULL;
 | 
				
			||||||
static gint opt_set_group = -1;
 | 
					static gint opt_set_group = -1;
 | 
				
			||||||
static gboolean opt_show_keyboard = FALSE;
 | 
					static gboolean opt_show_keyboard = FALSE;
 | 
				
			||||||
@ -32,6 +37,12 @@ static gint opt_release_key = -1;
 | 
				
			|||||||
static gboolean opt_listen = FALSE;
 | 
					static gboolean opt_listen = FALSE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const GOptionEntry options[] = {
 | 
					static const GOptionEntry options[] = {
 | 
				
			||||||
 | 
					    {"system", 'y', 0, G_OPTION_ARG_NONE, &opt_system,
 | 
				
			||||||
 | 
					     N_("Connect to the system bus")},
 | 
				
			||||||
 | 
					    {"session", 'e', 0, G_OPTION_ARG_NONE, &opt_session,
 | 
				
			||||||
 | 
					     N_("Connect to the session bus")},
 | 
				
			||||||
 | 
					    {"address", 'a', 0, G_OPTION_ARG_STRING, &opt_address,
 | 
				
			||||||
 | 
					     N_("Connect to the given D-Bus address")},
 | 
				
			||||||
    {"set-keyboard", '\0', 0, G_OPTION_ARG_STRING, &opt_set_keyboard,
 | 
					    {"set-keyboard", '\0', 0, G_OPTION_ARG_STRING, &opt_set_keyboard,
 | 
				
			||||||
     N_("Upload keyboard description from an XML file")},
 | 
					     N_("Upload keyboard description from an XML file")},
 | 
				
			||||||
    {"set-group", '\0', 0, G_OPTION_ARG_INT, &opt_set_group,
 | 
					    {"set-group", '\0', 0, G_OPTION_ARG_INT, &opt_set_group,
 | 
				
			||||||
@ -66,6 +77,7 @@ main (int argc, char **argv)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    EekboardEekboard *eekboard = NULL;
 | 
					    EekboardEekboard *eekboard = NULL;
 | 
				
			||||||
    EekboardContext *context = NULL;
 | 
					    EekboardContext *context = NULL;
 | 
				
			||||||
 | 
					    GBusType bus_type;
 | 
				
			||||||
    GDBusConnection *connection = NULL;
 | 
					    GDBusConnection *connection = NULL;
 | 
				
			||||||
    GError *error;
 | 
					    GError *error;
 | 
				
			||||||
    GOptionContext *option_context;
 | 
					    GOptionContext *option_context;
 | 
				
			||||||
@ -80,17 +92,45 @@ main (int argc, char **argv)
 | 
				
			|||||||
    g_option_context_parse (option_context, &argc, &argv, NULL);
 | 
					    g_option_context_parse (option_context, &argc, &argv, NULL);
 | 
				
			||||||
    g_option_context_free (option_context);
 | 
					    g_option_context_free (option_context);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (opt_system)
 | 
				
			||||||
 | 
					        bus_type = G_BUS_TYPE_SYSTEM;
 | 
				
			||||||
 | 
					    else if (opt_address)
 | 
				
			||||||
 | 
					        bus_type = G_BUS_TYPE_NONE;
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					        bus_type = G_BUS_TYPE_SESSION;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    switch (bus_type) {
 | 
				
			||||||
 | 
					    case G_BUS_TYPE_SYSTEM:
 | 
				
			||||||
 | 
					    case G_BUS_TYPE_SESSION:
 | 
				
			||||||
        error = NULL;
 | 
					        error = NULL;
 | 
				
			||||||
        connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
 | 
					        connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
 | 
				
			||||||
    if (error) {
 | 
					        if (connection == NULL) {
 | 
				
			||||||
        g_printerr ("%s\n", error->message);
 | 
					            g_printerr (_("Can't connect to the bus: %s\n"), error->message);
 | 
				
			||||||
        retval = 1;
 | 
					            exit (1);
 | 
				
			||||||
        goto out;
 | 
					        }
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					    case G_BUS_TYPE_NONE:
 | 
				
			||||||
 | 
					        error = NULL;
 | 
				
			||||||
 | 
					        connection = g_dbus_connection_new_for_address_sync (opt_address,
 | 
				
			||||||
 | 
					                                                             0,
 | 
				
			||||||
 | 
					                                                             NULL,
 | 
				
			||||||
 | 
					                                                             NULL,
 | 
				
			||||||
 | 
					                                                             &error);
 | 
				
			||||||
 | 
					        if (connection == NULL) {
 | 
				
			||||||
 | 
					            g_printerr (_("Can't connect to the bus at %s: %s\n"),
 | 
				
			||||||
 | 
					                        opt_address,
 | 
				
			||||||
 | 
					                        error->message);
 | 
				
			||||||
 | 
					            exit (1);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					    default:
 | 
				
			||||||
 | 
					        g_assert_not_reached ();
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    eekboard = eekboard_eekboard_new (connection, NULL);
 | 
					    eekboard = eekboard_eekboard_new (connection, NULL);
 | 
				
			||||||
    if (!eekboard) {
 | 
					    if (eekboard == NULL) {
 | 
				
			||||||
        g_printerr ("Can't create eekboard\n");
 | 
					        g_printerr (_("Can't create eekboard proxy\n"));
 | 
				
			||||||
        retval = 1;
 | 
					        retval = 1;
 | 
				
			||||||
        goto out;
 | 
					        goto out;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -98,8 +138,8 @@ main (int argc, char **argv)
 | 
				
			|||||||
    context = eekboard_eekboard_create_context (eekboard,
 | 
					    context = eekboard_eekboard_create_context (eekboard,
 | 
				
			||||||
                                                "eekboard-client",
 | 
					                                                "eekboard-client",
 | 
				
			||||||
                                                NULL);
 | 
					                                                NULL);
 | 
				
			||||||
    if (!context) {
 | 
					    if (context == NULL) {
 | 
				
			||||||
        g_printerr ("Can't create context\n");
 | 
					        g_printerr (_("Can't create context\n"));
 | 
				
			||||||
        retval = 1;
 | 
					        retval = 1;
 | 
				
			||||||
        goto out;
 | 
					        goto out;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -117,7 +157,7 @@ main (int argc, char **argv)
 | 
				
			|||||||
        error = NULL;
 | 
					        error = NULL;
 | 
				
			||||||
        input = g_file_read (file, NULL, &error);
 | 
					        input = g_file_read (file, NULL, &error);
 | 
				
			||||||
        if (error) {
 | 
					        if (error) {
 | 
				
			||||||
            g_printerr ("Can't read file %s: %s\n",
 | 
					            g_printerr (_("Can't read file %s: %s\n"),
 | 
				
			||||||
                        opt_set_keyboard, error->message);
 | 
					                        opt_set_keyboard, error->message);
 | 
				
			||||||
            retval = 1;
 | 
					            retval = 1;
 | 
				
			||||||
            goto out;
 | 
					            goto out;
 | 
				
			||||||
 | 
				
			|||||||
@ -27,12 +27,22 @@
 | 
				
			|||||||
#include "eekboard/eekboard.h"
 | 
					#include "eekboard/eekboard.h"
 | 
				
			||||||
#include "desktop-client.h"
 | 
					#include "desktop-client.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static gboolean opt_system = FALSE;
 | 
				
			||||||
 | 
					static gboolean opt_session = FALSE;
 | 
				
			||||||
 | 
					static gchar *opt_address = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef HAVE_CSPI
 | 
					#ifdef HAVE_CSPI
 | 
				
			||||||
gboolean opt_focus = FALSE;
 | 
					gboolean opt_focus = FALSE;
 | 
				
			||||||
gboolean opt_keystroke = FALSE;
 | 
					gboolean opt_keystroke = FALSE;
 | 
				
			||||||
#endif  /* HAVE_CSPI */
 | 
					#endif  /* HAVE_CSPI */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const GOptionEntry options[] = {
 | 
					static const GOptionEntry options[] = {
 | 
				
			||||||
 | 
					    {"system", 'y', 0, G_OPTION_ARG_NONE, &opt_system,
 | 
				
			||||||
 | 
					     N_("Connect to the system bus")},
 | 
				
			||||||
 | 
					    {"session", 'e', 0, G_OPTION_ARG_NONE, &opt_session,
 | 
				
			||||||
 | 
					     N_("Connect to the session bus")},
 | 
				
			||||||
 | 
					    {"address", 'a', 0, G_OPTION_ARG_STRING, &opt_address,
 | 
				
			||||||
 | 
					     N_("Connect to the given D-Bus address")},
 | 
				
			||||||
#ifdef HAVE_CSPI
 | 
					#ifdef HAVE_CSPI
 | 
				
			||||||
    {"listen-focus", 'f', 0, G_OPTION_ARG_NONE, &opt_focus,
 | 
					    {"listen-focus", 'f', 0, G_OPTION_ARG_NONE, &opt_focus,
 | 
				
			||||||
     N_("Listen focus change events with AT-SPI")},
 | 
					     N_("Listen focus change events with AT-SPI")},
 | 
				
			||||||
@ -62,6 +72,7 @@ main (int argc, char **argv)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    EekboardDesktopClient *client;
 | 
					    EekboardDesktopClient *client;
 | 
				
			||||||
    EekboardContext *context;
 | 
					    EekboardContext *context;
 | 
				
			||||||
 | 
					    GBusType bus_type;
 | 
				
			||||||
    GDBusConnection *connection;
 | 
					    GDBusConnection *connection;
 | 
				
			||||||
    GError *error;
 | 
					    GError *error;
 | 
				
			||||||
    GConfClient *gconfc;
 | 
					    GConfClient *gconfc;
 | 
				
			||||||
@ -78,12 +89,42 @@ main (int argc, char **argv)
 | 
				
			|||||||
    g_option_context_parse (option_context, &argc, &argv, NULL);
 | 
					    g_option_context_parse (option_context, &argc, &argv, NULL);
 | 
				
			||||||
    g_option_context_free (option_context);
 | 
					    g_option_context_free (option_context);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (opt_system)
 | 
				
			||||||
 | 
					        bus_type = G_BUS_TYPE_SYSTEM;
 | 
				
			||||||
 | 
					    else if (opt_address)
 | 
				
			||||||
 | 
					        bus_type = G_BUS_TYPE_NONE;
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					        bus_type = G_BUS_TYPE_SESSION;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    switch (bus_type) {
 | 
				
			||||||
 | 
					    case G_BUS_TYPE_SYSTEM:
 | 
				
			||||||
 | 
					    case G_BUS_TYPE_SESSION:
 | 
				
			||||||
        error = NULL;
 | 
					        error = NULL;
 | 
				
			||||||
        connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
 | 
					        connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
 | 
				
			||||||
    if (error) {
 | 
					        if (connection == NULL) {
 | 
				
			||||||
        g_printerr ("%s\n", error->message);
 | 
					            g_printerr ("Can't connect to the bus: %s\n", error->message);
 | 
				
			||||||
            exit (1);
 | 
					            exit (1);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					    case G_BUS_TYPE_NONE:
 | 
				
			||||||
 | 
					        error = NULL;
 | 
				
			||||||
 | 
					        connection = g_dbus_connection_new_for_address_sync (opt_address,
 | 
				
			||||||
 | 
					                                                             0,
 | 
				
			||||||
 | 
					                                                             NULL,
 | 
				
			||||||
 | 
					                                                             NULL,
 | 
				
			||||||
 | 
					                                                             &error);
 | 
				
			||||||
 | 
					        if (connection == NULL) {
 | 
				
			||||||
 | 
					            g_printerr ("Can't connect to the bus at %s: %s\n",
 | 
				
			||||||
 | 
					                        opt_address,
 | 
				
			||||||
 | 
					                        error->message);
 | 
				
			||||||
 | 
					            exit (1);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					    default:
 | 
				
			||||||
 | 
					        g_assert_not_reached ();
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    client = eekboard_desktop_client_new (connection);
 | 
					    client = eekboard_desktop_client_new (connection);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    gconfc = gconf_client_get_default ();
 | 
					    gconfc = gconf_client_get_default ();
 | 
				
			||||||
@ -114,7 +155,7 @@ main (int argc, char **argv)
 | 
				
			|||||||
                exit (1);
 | 
					                exit (1);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            g_printerr ("Desktop accessibility support is disabled");
 | 
					            g_printerr ("Desktop accessibility support is disabled\n");
 | 
				
			||||||
            exit (1);
 | 
					            exit (1);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -31,6 +31,20 @@
 | 
				
			|||||||
#include "server-server.h"
 | 
					#include "server-server.h"
 | 
				
			||||||
#include "eek/eek.h"
 | 
					#include "eek/eek.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static gboolean opt_system = FALSE;
 | 
				
			||||||
 | 
					static gboolean opt_session = FALSE;
 | 
				
			||||||
 | 
					static gchar *opt_address = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static const GOptionEntry options[] = {
 | 
				
			||||||
 | 
					    {"system", 'y', 0, G_OPTION_ARG_NONE, &opt_system,
 | 
				
			||||||
 | 
					     N_("Connect to the system bus")},
 | 
				
			||||||
 | 
					    {"session", 'e', 0, G_OPTION_ARG_NONE, &opt_session,
 | 
				
			||||||
 | 
					     N_("Connect to the session bus")},
 | 
				
			||||||
 | 
					    {"address", 'a', 0, G_OPTION_ARG_STRING, &opt_address,
 | 
				
			||||||
 | 
					     N_("Connect to the given D-Bus address")},
 | 
				
			||||||
 | 
					    {NULL}
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
on_name_acquired (GDBusConnection *connection,
 | 
					on_name_acquired (GDBusConnection *connection,
 | 
				
			||||||
                  const gchar     *name,
 | 
					                  const gchar     *name,
 | 
				
			||||||
@ -50,6 +64,7 @@ int
 | 
				
			|||||||
main (int argc, char **argv)
 | 
					main (int argc, char **argv)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ServerServer *server;
 | 
					    ServerServer *server;
 | 
				
			||||||
 | 
					    GBusType bus_type;
 | 
				
			||||||
    GDBusConnection *connection;
 | 
					    GDBusConnection *connection;
 | 
				
			||||||
    GError *error;
 | 
					    GError *error;
 | 
				
			||||||
    GMainLoop *loop;
 | 
					    GMainLoop *loop;
 | 
				
			||||||
@ -75,17 +90,46 @@ main (int argc, char **argv)
 | 
				
			|||||||
    g_type_class_ref (EEK_TYPE_SYMBOL);
 | 
					    g_type_class_ref (EEK_TYPE_SYMBOL);
 | 
				
			||||||
    g_type_class_ref (EEK_TYPE_KEYSYM);
 | 
					    g_type_class_ref (EEK_TYPE_KEYSYM);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (opt_system)
 | 
				
			||||||
 | 
					        bus_type = G_BUS_TYPE_SYSTEM;
 | 
				
			||||||
 | 
					    else if (opt_address)
 | 
				
			||||||
 | 
					        bus_type = G_BUS_TYPE_NONE;
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					        bus_type = G_BUS_TYPE_SESSION;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    switch (bus_type) {
 | 
				
			||||||
 | 
					    case G_BUS_TYPE_SYSTEM:
 | 
				
			||||||
 | 
					    case G_BUS_TYPE_SESSION:
 | 
				
			||||||
        error = NULL;
 | 
					        error = NULL;
 | 
				
			||||||
        connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
 | 
					        connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
 | 
				
			||||||
    if (error) {
 | 
					        if (connection == NULL) {
 | 
				
			||||||
        g_printerr ("%s\n", error->message);
 | 
					            g_printerr ("Can't connect to the bus: %s\n", error->message);
 | 
				
			||||||
            exit (1);
 | 
					            exit (1);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					    case G_BUS_TYPE_NONE:
 | 
				
			||||||
 | 
					        error = NULL;
 | 
				
			||||||
 | 
					        connection = g_dbus_connection_new_for_address_sync (opt_address,
 | 
				
			||||||
 | 
					                                                             0,
 | 
				
			||||||
 | 
					                                                             NULL,
 | 
				
			||||||
 | 
					                                                             NULL,
 | 
				
			||||||
 | 
					                                                             &error);
 | 
				
			||||||
 | 
					        if (connection == NULL) {
 | 
				
			||||||
 | 
					            g_printerr ("Can't connect to the bus at %s: %s\n",
 | 
				
			||||||
 | 
					                        opt_address,
 | 
				
			||||||
 | 
					                        error->message);
 | 
				
			||||||
 | 
					            exit (1);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					    default:
 | 
				
			||||||
 | 
					        g_assert_not_reached ();
 | 
				
			||||||
 | 
					        break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    server = server_server_new (SERVER_SERVER_PATH, connection);
 | 
					    server = server_server_new (SERVER_SERVER_PATH, connection);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (server == NULL) {
 | 
					    if (server == NULL) {
 | 
				
			||||||
        g_printerr ("Can't create server server\n");
 | 
					        g_printerr ("Can't create server\n");
 | 
				
			||||||
        exit (1);
 | 
					        exit (1);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user