Commit 899346d1 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

check for libhal if Linux Input support is enabled.

2007-02-11  Sven Neumann  <sven@gimp.org>

	* configure.in: check for libhal if Linux Input support is 
enabled.

	* modules/Makefile.am
	* modules/gimpinputdevicestore.[ch]: added class derived from
	GtkListStore that keeps a list of devices with capability
	"input.mouse".

	* modules/controller_linux_input.c: for now, just instantiate a
	GimpInputDeviceStore.


svn path=/trunk/; revision=21891
parent b1093d65
2007-02-11 Sven Neumann <sven@gimp.org>
* configure.in: check for libhal if Linux Input support is enabled.
* modules/Makefile.am
* modules/gimpinputdevicestore.[ch]: added class derived from
GtkListStore that keeps a list of devices with capability
"input.mouse".
* modules/controller_linux_input.c: for now, just instantiate a
GimpInputDeviceStore.
2007-02-11 Michael Natterer <mitch@gimp.org>
 
* app/core/gimpcontainer.c (gimp_container_deserialize): plug leak
......@@ -57,6 +57,7 @@ m4_define([gnomeui_required_version], [2.10.0])
m4_define([gnome_keyring_required_version], [0.4.5])
m4_define([libcurl_required_version], [7.15.1])
m4_define([dbus_glib_required_version], [0.70])
m4_define([libhal_required_version], [0.5.8])
AC_INIT([GIMP], [gimp_version],
......@@ -1310,28 +1311,6 @@ if test "x$have_gnome_keyring" = xyes; then
fi
###############################
# Check for D-Bus glib bindings
###############################
PKG_CHECK_MODULES(DBUS_GLIB, dbus-glib-1 >= dbus_glib_required_version,
have_dbus_glib=yes,
AC_MSG_RESULT([no])
have_dbus_glib=no)
if test "x$have_dbus_glib" = xyes; then
AC_PATH_PROG(DBUS_BINDING_TOOL, dbus-binding-tool, no)
if test x$DBUS_BINDING_TOOL = xno; then
AC_MSG_WARN(Could not find dbus-binding-tool in your PATH)
have_dbus_glib="no (dbus-binding-tool not found)"
fi
fi
if test "x$have_dbus_glib" = xyes; then
AC_DEFINE(HAVE_DBUS_GLIB, 1,
[Define to 1 if D-Bus GLib bindings are available])
GIMP_COMMAND='gimp-gimp_app_version'
fi
###################
......@@ -1408,7 +1387,7 @@ fi
#######################
# Check for linux input
# Check for Linux Input
#######################
AC_ARG_WITH(linux-input, [ --without-linux-input don't build linux input event controller module])
......@@ -1421,6 +1400,49 @@ fi
AM_CONDITIONAL(HAVE_LINUX_INPUT, test $have_linux_input = yes)
###############################
# Check for D-Bus GLib bindings
###############################
PKG_CHECK_MODULES(DBUS_GLIB, dbus-glib-1 >= dbus_glib_required_version,
have_dbus_glib=yes,
AC_MSG_RESULT([no])
have_dbus_glib=no)
if test "x$have_dbus_glib" = xyes; then
AC_PATH_PROG(DBUS_BINDING_TOOL, dbus-binding-tool, no)
if test x$DBUS_BINDING_TOOL = xno; then
AC_MSG_WARN([Could not find dbus-binding-tool in your PATH])
have_dbus_glib="no (dbus-binding-tool not found)"
fi
fi
if test "x$have_dbus_glib" = xyes; then
AC_DEFINE(HAVE_DBUS_GLIB, 1,
[Define to 1 if D-Bus GLib bindings are available])
GIMP_COMMAND='gimp-gimp_app_version'
fi
###############################################
# Check for libhal (Hardware Abstraction Layer)
###############################################
have_libhal=no
if test "x$have_linux_input" = xyes && test "x$have_dbus_glib" = xyes; then
PKG_CHECK_MODULES(HAL, hal >= libhal_required_version,
have_libhal=yes,
AC_MSG_RESULT([no])
have_libhal="no (libhal not found)"
)
fi
if test "x$have_libhal" = xyes; then
AC_DEFINE(HAVE_LIBHAL, 1, [Define to 1 if libhal is available])
fi
############################################################
# GIF compression: Allow builder to specify at compile time
# which compression style she wants to use for GIFs.
......@@ -1964,7 +1986,7 @@ Plug-In Features:
Optional Modules:
ALSA (MIDI Input): $have_alsa
Linux Input: $have_linux_input
Linux Input: $have_linux_input (HAL support: $have_libhal)
Color Correction: $have_lcms
Soft Proof: $have_lcms
]);
......@@ -86,9 +86,14 @@ libcdisplay_proof_la_SOURCES = cdisplay_proof.c
libcdisplay_proof_la_LDFLAGS = -avoid-version -module $(no_undefined)
libcdisplay_proof_la_LIBADD = $(cdisplay_libadd) $(LIBLCMS)
libcontroller_linux_input_la_SOURCES = controller_linux_input.c
libcontroller_linux_input_la_SOURCES = \
gimpinputdevicestore.c \
gimpinputdevicestore.h \
controller_linux_input.c
libcontroller_linux_input_la_CFLAGS = $(DBUS_GLIB_CFLAGS) $(HAL_CFLAGS)
libcontroller_linux_input_la_LDFLAGS = -avoid-version -module $(no_undefined)
libcontroller_linux_input_la_LIBADD = $(controller_libadd)
libcontroller_linux_input_la_LIBADD = \
$(controller_libadd) $(DBUS_GLIB_LIBS) $(HAL_LIBS)
libcontroller_midi_la_SOURCES = controller_midi.c
libcontroller_midi_la_CFLAGS = $(ALSA_CFLAGS)
......
......@@ -41,6 +41,8 @@
#define GIMP_ENABLE_CONTROLLER_UNDER_CONSTRUCTION
#include "libgimpwidgets/gimpcontroller.h"
#include "gimpinputdevicestore.h"
#include "libgimp/libgimp-intl.h"
......@@ -142,6 +144,7 @@ struct _ControllerLinuxInputClass
GType linux_input_get_type (GTypeModule *module);
static void linux_input_class_init (ControllerLinuxInputClass *klass);
static void linux_input_init (ControllerLinuxInput *controller);
static void linux_input_dispose (GObject *object);
static void linux_input_set_property (GObject *object,
guint property_id,
......@@ -210,7 +213,7 @@ linux_input_get_type (GTypeModule *module)
NULL, /* class_data */
sizeof (ControllerLinuxInput),
0, /* n_preallocs */
NULL /* instance_init */
(GInstanceInitFunc) linux_input_init
};
controller_type = g_type_module_register_type (module,
......@@ -250,6 +253,12 @@ linux_input_class_init (ControllerLinuxInputClass *klass)
controller_class->get_event_blurb = linux_input_get_event_blurb;
}
static void
linux_input_init (ControllerLinuxInput *controller)
{
gimp_input_device_store_new ();
}
static void
linux_input_dispose (GObject *object)
{
......
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpinputdevicestore.c
* Copyright (C) 2007 Sven Neumann <sven@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <string.h>
#include <gtk/gtk.h>
#ifdef HAVE_LIBHAL
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <hal/libhal.h>
#endif
#include "gimpinputdevicestore.h"
#ifdef HAVE_LIBHAL
enum
{
COLUMN_UDI,
COLUMN_LABEL,
NUM_COLUMNS
};
typedef GtkListStoreClass GimpInputDeviceStoreClass;
struct _GimpInputDeviceStore
{
GtkListStore parent_instance;
LibHalContext *context;
};
static void gimp_input_device_store_class_init (GimpInputDeviceStoreClass *klass);
static void gimp_input_device_store_init (GimpInputDeviceStore *store);
static void gimp_input_device_store_finalize (GObject *object);
static void gimp_input_device_store_add (GimpInputDeviceStore *store,
const gchar *udi);
static void gimp_input_device_store_remove (GimpInputDeviceStore *store,
const gchar *udi);
static void gimp_input_device_store_device_added (LibHalContext *ctx,
const char *udi);
static void gimp_input_device_store_device_removed (LibHalContext *ctx,
const char *udi);
G_DEFINE_TYPE (GimpInputDeviceStore,
gimp_input_device_store, GTK_TYPE_LIST_STORE)
static void
gimp_input_device_store_class_init (GimpInputDeviceStoreClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gimp_input_device_store_finalize;
}
static void
gimp_input_device_store_init (GimpInputDeviceStore *store)
{
DBusGConnection *connection;
GType types[] = { G_TYPE_STRING, G_TYPE_STRING };
GError *error = NULL;
gtk_list_store_set_column_types (GTK_LIST_STORE (store),
G_N_ELEMENTS (types), types);
connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
if (! connection)
{
g_printerr (error->message);
g_error_free (error);
return;
}
store->context = libhal_ctx_new ();
libhal_ctx_set_dbus_connection (store->context,
dbus_g_connection_get_connection (connection));
dbus_g_connection_unref (connection);
if (libhal_ctx_init (store->context, NULL))
{
char **devices;
int i, num_devices;
devices = libhal_find_device_by_capability (store->context, "input.mouse",
&num_devices, NULL);
for (i = 0; i < num_devices; i++)
gimp_input_device_store_add (store, devices[i]);
libhal_free_string_array (devices);
libhal_ctx_set_user_data (store->context, store);
libhal_ctx_set_device_added (store->context,
gimp_input_device_store_device_added);
libhal_ctx_set_device_removed (store->context,
gimp_input_device_store_device_removed);
}
}
static void
gimp_input_device_store_finalize (GObject *object)
{
GimpInputDeviceStore *store = GIMP_INPUT_DEVICE_STORE (object);
if (store->context)
{
libhal_ctx_shutdown (store->context, NULL);
libhal_ctx_free (store->context);
store->context = NULL;
}
G_OBJECT_CLASS (gimp_input_device_store_parent_class)->finalize (object);
}
static gboolean
gimp_input_device_store_lookup (GimpInputDeviceStore *store,
GtkTreeIter *iter,
const gchar *udi)
{
GtkTreeModel *model = GTK_TREE_MODEL (store);
gboolean iter_valid;
for (iter_valid = gtk_tree_model_get_iter_first (model, iter);
iter_valid;
iter_valid = gtk_tree_model_iter_next (model, iter))
{
gchar *this;
gtk_tree_model_get (model, iter,
COLUMN_UDI, &this,
-1);
if (strcmp (this, udi) == 0)
{
g_free (this);
break;
}
g_free (this);
}
return iter_valid;
}
static void
gimp_input_device_store_add (GimpInputDeviceStore *store,
const gchar *udi)
{
char **caps;
gint i;
caps = libhal_device_get_property_strlist (store->context,
udi, "info.capabilities",
NULL);
for (i = 0; caps && caps[i]; i++)
{
char *str;
if (strcmp (caps[i], "input.mouse"))
continue;
str = libhal_device_get_property_string (store->context,
udi, "input.product",
NULL);
if (str)
{
GtkTreeIter iter;
gtk_list_store_append (GTK_LIST_STORE (store), &iter);
g_printerr ("%s\n", str);
gtk_list_store_set (GTK_LIST_STORE (store), &iter,
COLUMN_UDI, udi,
COLUMN_LABEL, str,
-1);
libhal_free_string (str);
}
}
libhal_free_string_array (caps);
}
static void
gimp_input_device_store_remove (GimpInputDeviceStore *store,
const gchar *udi)
{
GtkTreeIter iter;
if (gimp_input_device_store_lookup (store, &iter, udi))
gtk_list_store_remove (GTK_LIST_STORE (store), &iter);
}
static void
gimp_input_device_store_device_added (LibHalContext *ctx,
const char *udi)
{
GimpInputDeviceStore *store = libhal_ctx_get_user_data (ctx);
gimp_input_device_store_add (store, udi);
}
static void
gimp_input_device_store_device_removed (LibHalContext *ctx,
const char *udi)
{
GimpInputDeviceStore *store = libhal_ctx_get_user_data (ctx);
gimp_input_device_store_remove (store, udi);
}
GtkListStore *
gimp_input_device_store_new (void)
{
return g_object_new (GIMP_TYPE_INPUT_DEVICE_STORE, NULL);
}
gchar *
gimp_input_device_store_get_device_file (GimpInputDeviceStore *store,
const gchar *udi)
{
GtkTreeIter iter;
g_return_val_if_fail (GIMP_IS_INPUT_DEVICE_STORE (store), NULL);
g_return_val_if_fail (udi != NULL, NULL);
if (gimp_input_device_store_lookup (store, &iter, udi))
{
char *str = libhal_device_get_property_string (store->context,
udi, "linux.device_file",
NULL);
if (str)
{
gchar *retval = g_strdup (str);
libhal_free_string (str);
return retval;
}
}
return NULL;
}
#else
GType
gimp_input_device_store_get_type (void)
{
return G_TYPE_NONE;
}
GtkListStore *
gimp_input_device_store_new (void)
{
return NULL;
}
gchar *
gimp_input_device_store_get_device_file (GimpInputDeviceStore *store,
const gchar *udi)
{
return NULL;
}
#endif
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimpinputdevicestore.h
* Copyright (C) 2007 Sven Neumann <sven@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_INPUT_DEVICE_STORE_H__
#define __GIMP_INPUT_DEVICE_STORE_H__
#define GIMP_TYPE_INPUT_DEVICE_STORE (gimp_input_device_store_get_type ())
#define GIMP_INPUT_DEVICE_STORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_INPUT_DEVICE_STORE, GimpInputDeviceStore))
#define GIMP_IS_INPUT_DEVICE_STORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_INPUT_DEVICE_STORE))
typedef struct _GimpInputDeviceStore GimpInputDeviceStore;
GType gimp_input_device_store_get_type (void) G_GNUC_CONST;
GtkListStore * gimp_input_device_store_new (void);
gchar * gimp_input_device_store_get_device_file (GimpInputDeviceStore *store,
const gchar *udi);
#endif /* __GIMP_INPUT_DEVICE_STORE_H__ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment