>From 1950bce008b1104bad774c053882e8a12e5994a3 Mon Sep 17 00:00:00 2001
From: Olivier Fourdan <ofour...@redhat.com>
Date: Thu, 25 Oct 2012 14:43:28 +0200
Subject: [PATCH 2/4] lib: add SVG image to device properties
---
libwacom/libwacom-database.c | 18 +++++++++++----
libwacom/libwacom.c | 46 +++++++++++++++++++++++++++++++++++++++++-
libwacom/libwacom.h | 7 ++++++
libwacom/libwacomint.h | 2 +
4 files changed, 67 insertions(+), 6 deletions(-)
diff --git a/libwacom/libwacom-database.c b/libwacom/libwacom-database.c
index d39305d..cc95851 100644
--- a/libwacom/libwacom-database.c
+++ b/libwacom/libwacom-database.c
@@ -319,12 +319,14 @@ libwacom_parse_buttons(WacomDevice *device,
}
static WacomDevice*
-libwacom_parse_tablet_keyfile(const char *path)
+libwacom_parse_tablet_keyfile(const char *datadir, const char *filename)
{
WacomDevice *device = NULL;
GKeyFile *keyfile;
GError *error = NULL;
gboolean rc;
+ char *path;
+ char *image;
char *class;
char *match;
char **styli_list;
@@ -332,6 +334,7 @@ libwacom_parse_tablet_keyfile(const char *path)
keyfile = g_key_file_new();
+ path = g_build_filename (datadir, filename, NULL);
rc = g_key_file_load_from_file(keyfile, path, G_KEY_FILE_NONE, &error);
if (!rc) {
@@ -358,7 +361,12 @@ libwacom_parse_tablet_keyfile(const char *path)
device->name = g_key_file_get_string(keyfile, DEVICE_GROUP, "Name", NULL);
device->width = g_key_file_get_integer(keyfile, DEVICE_GROUP, "Width", NULL);
device->height = g_key_file_get_integer(keyfile, DEVICE_GROUP, "Height", NULL);
-
+ image = g_key_file_get_string(keyfile, DEVICE_GROUP, "Image", NULL);
+ if (image) {
+ /* For the image, we store the full path to the SVG image */
+ device->image = g_build_filename (datadir, "images", image, NULL);
+ g_free (image);
+ }
class = g_key_file_get_string(keyfile, DEVICE_GROUP, "Class", NULL);
device->cls = libwacom_class_string_to_enum(class);
g_free(class);
@@ -445,6 +453,8 @@ libwacom_parse_tablet_keyfile(const char *path)
}
out:
+ if (path)
+ g_free(path);
if (keyfile)
g_key_file_free(keyfile);
if (error)
@@ -515,9 +525,7 @@ libwacom_database_new_for_path (const char *datadir)
WacomDevice *d;
const WacomMatch **matches, **match;
- path = g_build_filename (datadir, files[n]->d_name, NULL);
- d = libwacom_parse_tablet_keyfile(path);
- g_free(path);
+ d = libwacom_parse_tablet_keyfile(datadir, files[n]->d_name);
if (!d)
continue;
diff --git a/libwacom/libwacom.c b/libwacom/libwacom.c
index 4f8c5f9..88b95c8 100644
--- a/libwacom/libwacom.c
+++ b/libwacom/libwacom.c
@@ -290,6 +290,7 @@ libwacom_copy(const WacomDevice *device)
d->name = g_strdup (device->name);
d->width = device->width;
d->height = device->height;
+ d->image = g_strdup(device->image);
d->nmatches = device->nmatches;
d->matches = g_malloc((d->nmatches + 1) * sizeof(WacomMatch*));
for (i = 0; i < d->nmatches; i++)
@@ -333,6 +334,26 @@ compare_matches(WacomDevice *a, WacomDevice *b)
return 0;
}
+/* Compare images based on file name, stripping the full path */
+static gboolean
+libwacom_same_images (WacomDevice *a, WacomDevice *b)
+{
+ gchar *file1, *file2;
+
+ /* Conveniently handle the null case */
+ if (a->image == b->image)
+ return TRUE;
+
+ file1 = NULL;
+ file2 = NULL;
+ if (a->image != NULL)
+ file1 = g_path_get_basename (a->image);
+ if (b->image != NULL)
+ file2 = g_path_get_basename (b->image);
+
+ return (g_strcmp0 (file1, file2) == 0);
+}
+
int
libwacom_compare(WacomDevice *a, WacomDevice *b, WacomCompareFlags flags)
{
@@ -347,6 +368,9 @@ libwacom_compare(WacomDevice *a, WacomDevice *b, WacomCompareFlags flags)
if (a->width != b->width || a->height != b->height)
return 1;
+ if (!libwacom_same_images (a, b))
+ return 1;
+
if (a->cls != b->cls)
return 1;
@@ -537,6 +561,19 @@ static void print_styli_for_device (int fd, WacomDevice *device)
dprintf(fd, "\n");
}
+static void print_image_for_device (int fd, WacomDevice *device)
+{
+ const char *image_filename;
+ gchar *base_name;
+
+ image_filename = libwacom_get_image_filename(device);
+ if (image_filename) {
+ base_name = g_path_get_basename (image_filename);
+ dprintf(fd, "Image=%s\n", base_name);
+ g_free (base_name);
+ }
+}
+
static void print_supported_leds (int fd, WacomDevice *device)
{
char *leds_name[] = {
@@ -598,7 +635,7 @@ libwacom_print_device_description(int fd, WacomDevice *device)
{
const WacomMatch **match;
WacomClass class;
- const char *bus_name, *class_name;
+ const char *bus_name, *class_name, *image_filename;
class = libwacom_get_class(device);
switch(class) {
@@ -638,6 +675,7 @@ libwacom_print_device_description(int fd, WacomDevice *device)
dprintf(fd, "Class=%s\n", class_name);
dprintf(fd, "Width=%d\n", libwacom_get_width(device));
dprintf(fd, "Height=%d\n", libwacom_get_height(device));
+ print_image_for_device(fd, device);
print_styli_for_device(fd, device);
dprintf(fd, "\n");
@@ -666,6 +704,7 @@ libwacom_destroy(WacomDevice *device)
return;
g_free (device->name);
+ g_free (device->image);
for (i = 0; i < device->nmatches; i++) {
g_free (device->matches[i]->match);
@@ -724,6 +763,11 @@ const char* libwacom_get_name(WacomDevice *device)
return device->name;
}
+const char* libwacom_get_image_filename(WacomDevice *device)
+{
+ return device->image;
+}
+
int libwacom_get_product_id(WacomDevice *device)
{
g_return_val_if_fail(device->match >= 0, -1);
diff --git a/libwacom/libwacom.h b/libwacom/libwacom.h
index 8830db8..2dc38e4 100644
--- a/libwacom/libwacom.h
+++ b/libwacom/libwacom.h
@@ -330,6 +330,13 @@ const char* libwacom_get_name(WacomDevice *device);
/**
* @param device The tablet to query
+ * @return The full filename including path to the SVG image of the device
+ * if available, or NULL otherwise
+ */
+const char* libwacom_get_image_filename(WacomDevice *device);
+
+/**
+ * @param device The tablet to query
* @return The numeric vendor ID for this device
*/
int libwacom_get_vendor_id(WacomDevice *device);
diff --git a/libwacom/libwacomint.h b/libwacom/libwacomint.h
index 55436e9..b3dc36f 100644
--- a/libwacom/libwacomint.h
+++ b/libwacom/libwacomint.h
@@ -93,6 +93,8 @@ struct _WacomDevice {
int num_leds;
WacomStatusLEDs *status_leds;
+ char *image;
+
gint refcnt; /* for the db hashtable */
};
--
1.7.1
------------------------------------------------------------------------------
The Windows 8 Center - In partnership with Sourceforge
Your idea - your app - 30 days.
Get started!
http://windows8center.sourceforge.net/
what-html-developers-need-to-know-about-coding-windows-8-metro-style-apps/
_______________________________________________
Linuxwacom-devel mailing list
Linuxwacom-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel