diff options
author | Jannis Pohlmann <jannis@xfce.org> | 2010-07-21 11:12:11 +0200 |
---|---|---|
committer | Jannis Pohlmann <jannis@xfce.org> | 2010-07-25 19:42:29 +0200 |
commit | ab265b25f13f70b35f3a2ceb2538053507af1883 (patch) | |
tree | b8cdaef1f0a3a85c515f9edf13bdb9b64acf797d /thunar-volman | |
parent | 0a3fd067c0dd3e97382faa8d6429bc6d0300a665 (diff) | |
download | thunar-volman-ab265b25f13f70b35f3a2ceb2538053507af1883.tar.gz |
Add support for detecting USB printers.
Diffstat (limited to 'thunar-volman')
-rw-r--r-- | thunar-volman/Makefile.am | 4 | ||||
-rw-r--r-- | thunar-volman/tvm-device.c | 2 | ||||
-rw-r--r-- | thunar-volman/tvm-usb-device.c | 81 | ||||
-rw-r--r-- | thunar-volman/tvm-usb-device.h | 35 |
4 files changed, 121 insertions, 1 deletions
diff --git a/thunar-volman/Makefile.am b/thunar-volman/Makefile.am index 9d9153d..7e73183 100644 --- a/thunar-volman/Makefile.am +++ b/thunar-volman/Makefile.am @@ -47,7 +47,9 @@ thunar_volman_SOURCES = \ tvm-prompt.c \ tvm-prompt.h \ tvm-run.c \ - tvm-run.h + tvm-run.h \ + tvm-usb-device.c \ + tvm-usb-device.h thunar_volman_CFLAGS = \ $(DBUS_CFLAGS) \ diff --git a/thunar-volman/tvm-device.c b/thunar-volman/tvm-device.c index 4da3aae..7249769 100644 --- a/thunar-volman/tvm-device.c +++ b/thunar-volman/tvm-device.c @@ -34,6 +34,7 @@ #include <thunar-volman/tvm-context.h> #include <thunar-volman/tvm-device.h> #include <thunar-volman/tvm-input-device.h> +#include <thunar-volman/tvm-usb-device.h> @@ -57,6 +58,7 @@ static TvmDeviceHandler subsystem_handlers[] = { { "block", tvm_block_device_added }, { "input", tvm_input_device_added }, + { "usb", tvm_usb_device_added }, #if 0 { "sound", tvm_sound_device_added }, { "video4linux", tvm_video_device_added }, diff --git a/thunar-volman/tvm-usb-device.c b/thunar-volman/tvm-usb-device.c new file mode 100644 index 0000000..8db2c2c --- /dev/null +++ b/thunar-volman/tvm-usb-device.c @@ -0,0 +1,81 @@ +/* vi:set et ai sw=2 sts=2 ts=2: */ +/*- + * Copyright (c) 2010 Jannis Pohlmann <jannis@xfce.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., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <gudev/gudev.h> + +#include <libxfce4util/libxfce4util.h> + +#include <thunar-volman/tvm-context.h> +#include <thunar-volman/tvm-device.h> +#include <thunar-volman/tvm-run.h> +#include <thunar-volman/tvm-usb-device.h> + + + +void +tvm_usb_device_added (TvmContext *context) +{ + const gchar *driver; + const gchar *enabled_property = NULL; + const gchar *command_property = NULL; + gboolean enabled; + gchar *command; + + g_return_if_fail (context != NULL); + + /* collect device information */ + driver = g_udev_device_get_property (context->device, "DRIVER"); + + if (g_strcmp0 (driver, "usblp") == 0) + { + enabled_property = "/autoprinter/enabled"; + command_property = "/autoprinter/command"; + } + + /* check if we have a device that we support */ + if (enabled_property != NULL && command_property != NULL) + { + /* check whether handling the printer or whatever is enabled */ + enabled = xfconf_channel_get_bool (context->channel, enabled_property, FALSE); + if (enabled) + { + /* fetch the command for the input device type and try to run it */ + command = xfconf_channel_get_string (context->channel, command_property, NULL); + if (command != NULL && *command != '\0') + { + tvm_run_command (context, NULL, command, context->error); + } + g_free (command); + } + } + else + { + /* return an error because we cannot handle the usb device */ + g_set_error (context->error, G_FILE_ERROR, G_FILE_ERROR_FAILED, + _("Unsupported USB device type")); + } + + /* finish processing the device */ + tvm_device_handler_finished (context); +} diff --git a/thunar-volman/tvm-usb-device.h b/thunar-volman/tvm-usb-device.h new file mode 100644 index 0000000..4b88002 --- /dev/null +++ b/thunar-volman/tvm-usb-device.h @@ -0,0 +1,35 @@ +/* vi:set et ai sw=2 sts=2 ts=2: */ +/*- + * Copyright (c) 2010 Jannis Pohlmann <jannis@xfce.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., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef __TVM_USB_DEVICE_H__ +#define __TVM_USB_DEVICE_H__ + +#include <glib.h> + +#include <thunar-volman/tvm-context.h> +#include <thunar-volman/tvm-device.h> + +G_BEGIN_DECLS + +void tvm_usb_device_added (TvmContext *context); + +G_END_DECLS + +#endif /* !__TVM_USB_DEVICE_H__ */ |