modules/gimpinputdevicestore.[ch] improved error handling.
2007-02-13 Sven Neumann <sven@gimp.org> * modules/gimpinputdevicestore.[ch] * modules/controller_linux_input.c: improved error handling. svn path=/trunk/; revision=21911
This commit is contained in:

committed by
Sven Neumann

parent
345fe7b5bc
commit
4db2ed0b82
@ -1,3 +1,8 @@
|
|||||||
|
2007-02-13 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
|
* modules/gimpinputdevicestore.[ch]
|
||||||
|
* modules/controller_linux_input.c: improved error handling.
|
||||||
|
|
||||||
2007-02-13 Sven Neumann <sven@gimp.org>
|
2007-02-13 Sven Neumann <sven@gimp.org>
|
||||||
|
|
||||||
* modules/gimpinputdevicestore.c: keep devices sorted alphabetically.
|
* modules/gimpinputdevicestore.c: keep devices sorted alphabetically.
|
||||||
|
@ -598,9 +598,19 @@ linux_input_set_device (ControllerLinuxInput *controller,
|
|||||||
|
|
||||||
g_free (filename);
|
g_free (filename);
|
||||||
}
|
}
|
||||||
else
|
else if (controller->store)
|
||||||
{
|
{
|
||||||
g_object_set (controller, "state", _("Device not available"), NULL);
|
GError *error = gimp_input_device_store_get_error (controller->store);
|
||||||
|
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
g_object_set (controller, "state", error->message, NULL);
|
||||||
|
g_error_free (error);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_object_set (controller, "state", _("Device not available"), NULL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -43,6 +43,12 @@ enum
|
|||||||
NUM_COLUMNS
|
NUM_COLUMNS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
PROP_0,
|
||||||
|
PROP_CONSTRUCT_ERROR
|
||||||
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
DEVICE_ADDED,
|
DEVICE_ADDED,
|
||||||
@ -54,9 +60,10 @@ typedef struct _GimpInputDeviceStoreClass GimpInputDeviceStoreClass;
|
|||||||
|
|
||||||
struct _GimpInputDeviceStore
|
struct _GimpInputDeviceStore
|
||||||
{
|
{
|
||||||
GtkListStore parent_instance;
|
GtkListStore parent_instance;
|
||||||
|
|
||||||
LibHalContext *context;
|
LibHalContext *context;
|
||||||
|
GError *error;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -74,7 +81,6 @@ struct _GimpInputDeviceStoreClass
|
|||||||
static void gimp_input_device_store_class_init (GimpInputDeviceStoreClass *klass);
|
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_init (GimpInputDeviceStore *store);
|
||||||
static void gimp_input_device_store_finalize (GObject *object);
|
static void gimp_input_device_store_finalize (GObject *object);
|
||||||
|
|
||||||
static gboolean gimp_input_device_store_add (GimpInputDeviceStore *store,
|
static gboolean gimp_input_device_store_add (GimpInputDeviceStore *store,
|
||||||
const gchar *udi);
|
const gchar *udi);
|
||||||
static gboolean gimp_input_device_store_remove (GimpInputDeviceStore *store,
|
static gboolean gimp_input_device_store_remove (GimpInputDeviceStore *store,
|
||||||
@ -153,21 +159,17 @@ gimp_input_device_store_class_init (GimpInputDeviceStoreClass *klass)
|
|||||||
static void
|
static void
|
||||||
gimp_input_device_store_init (GimpInputDeviceStore *store)
|
gimp_input_device_store_init (GimpInputDeviceStore *store)
|
||||||
{
|
{
|
||||||
DBusGConnection *connection;
|
|
||||||
GType types[] = { G_TYPE_STRING, G_TYPE_STRING };
|
GType types[] = { G_TYPE_STRING, G_TYPE_STRING };
|
||||||
GError *error = NULL;
|
DBusGConnection *connection;
|
||||||
|
DBusError dbus_error;
|
||||||
|
|
||||||
gtk_list_store_set_column_types (GTK_LIST_STORE (store),
|
gtk_list_store_set_column_types (GTK_LIST_STORE (store),
|
||||||
G_N_ELEMENTS (types), types);
|
G_N_ELEMENTS (types), types);
|
||||||
|
|
||||||
connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
|
connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &store->error);
|
||||||
|
|
||||||
if (! connection)
|
if (! connection)
|
||||||
{
|
return;
|
||||||
g_printerr (error->message);
|
|
||||||
g_error_free (error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
store->context = libhal_ctx_new ();
|
store->context = libhal_ctx_new ();
|
||||||
|
|
||||||
@ -175,7 +177,9 @@ gimp_input_device_store_init (GimpInputDeviceStore *store)
|
|||||||
dbus_g_connection_get_connection (connection));
|
dbus_g_connection_get_connection (connection));
|
||||||
dbus_g_connection_unref (connection);
|
dbus_g_connection_unref (connection);
|
||||||
|
|
||||||
if (libhal_ctx_init (store->context, NULL))
|
dbus_error_init (&dbus_error);
|
||||||
|
|
||||||
|
if (libhal_ctx_init (store->context, &dbus_error))
|
||||||
{
|
{
|
||||||
char **devices;
|
char **devices;
|
||||||
int i, num_devices;
|
int i, num_devices;
|
||||||
@ -189,11 +193,27 @@ gimp_input_device_store_init (GimpInputDeviceStore *store)
|
|||||||
libhal_free_string_array (devices);
|
libhal_free_string_array (devices);
|
||||||
|
|
||||||
libhal_ctx_set_user_data (store->context, store);
|
libhal_ctx_set_user_data (store->context, store);
|
||||||
|
|
||||||
libhal_ctx_set_device_added (store->context,
|
libhal_ctx_set_device_added (store->context,
|
||||||
gimp_input_device_store_device_added);
|
gimp_input_device_store_device_added);
|
||||||
libhal_ctx_set_device_removed (store->context,
|
libhal_ctx_set_device_removed (store->context,
|
||||||
gimp_input_device_store_device_removed);
|
gimp_input_device_store_device_removed);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (dbus_error_is_set (&dbus_error))
|
||||||
|
{
|
||||||
|
dbus_set_g_error (&store->error, &dbus_error);
|
||||||
|
dbus_error_free (&dbus_error);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_set_error (&store->error, 0, 0, "Unable to connect to hald");
|
||||||
|
}
|
||||||
|
|
||||||
|
libhal_ctx_free (store->context);
|
||||||
|
store->context = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -208,6 +228,12 @@ gimp_input_device_store_finalize (GObject *object)
|
|||||||
store->context = NULL;
|
store->context = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (store->error)
|
||||||
|
{
|
||||||
|
g_error_free (store->error);
|
||||||
|
store->error = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -385,6 +411,9 @@ gimp_input_device_store_get_device_file (GimpInputDeviceStore *store,
|
|||||||
g_return_val_if_fail (GIMP_IS_INPUT_DEVICE_STORE (store), NULL);
|
g_return_val_if_fail (GIMP_IS_INPUT_DEVICE_STORE (store), NULL);
|
||||||
g_return_val_if_fail (udi != NULL, NULL);
|
g_return_val_if_fail (udi != NULL, NULL);
|
||||||
|
|
||||||
|
if (! store->context)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if (gimp_input_device_store_lookup (store, udi, &iter))
|
if (gimp_input_device_store_lookup (store, udi, &iter))
|
||||||
{
|
{
|
||||||
char *str = libhal_device_get_property_string (store->context,
|
char *str = libhal_device_get_property_string (store->context,
|
||||||
@ -404,6 +433,14 @@ gimp_input_device_store_get_device_file (GimpInputDeviceStore *store,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GError *
|
||||||
|
gimp_input_device_store_get_error (GimpInputDeviceStore *store)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (GIMP_IS_INPUT_DEVICE_STORE (store), NULL);
|
||||||
|
|
||||||
|
return store->error ? g_error_copy (store->error) : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
GType
|
GType
|
||||||
@ -413,7 +450,7 @@ gimp_input_device_store_get_type (GTypeModule *module)
|
|||||||
}
|
}
|
||||||
|
|
||||||
GtkListStore *
|
GtkListStore *
|
||||||
gimp_input_device_store_new (void)
|
gimp_input_device_store_new (GError **error)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -425,4 +462,10 @@ gimp_input_device_store_get_device_file (GimpInputDeviceStore *store,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GError *
|
||||||
|
gimp_input_device_store_get_error (GimpInputDeviceStore *store)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -32,12 +32,13 @@ typedef struct _GimpInputDeviceStore GimpInputDeviceStore;
|
|||||||
|
|
||||||
extern GType gimp_input_device_store_type;
|
extern GType gimp_input_device_store_type;
|
||||||
|
|
||||||
GType gimp_input_device_store_get_type (GTypeModule *module);
|
GType gimp_input_device_store_get_type (GTypeModule *module);
|
||||||
|
|
||||||
|
|
||||||
GimpInputDeviceStore * gimp_input_device_store_new (void);
|
GimpInputDeviceStore * gimp_input_device_store_new (void);
|
||||||
gchar * gimp_input_device_store_get_device_file (GimpInputDeviceStore *store,
|
gchar * gimp_input_device_store_get_device_file (GimpInputDeviceStore *store,
|
||||||
const gchar *udi);
|
const gchar *udi);
|
||||||
|
GError * gimp_input_device_store_get_error (GimpInputDeviceStore *store);
|
||||||
|
|
||||||
|
|
||||||
#endif /* __GIMP_INPUT_DEVICE_STORE_H__ */
|
#endif /* __GIMP_INPUT_DEVICE_STORE_H__ */
|
||||||
|
Reference in New Issue
Block a user