From 76d7de16d24e97aa6b58472b21b3a8e8bb795af5 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 19 Jul 2011 11:21:02 +0100 Subject: add the udev mgr files --- src/udev-mgr.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/udev-mgr.h (limited to 'src/udev-mgr.h') diff --git a/src/udev-mgr.h b/src/udev-mgr.h new file mode 100644 index 0000000..77d62f1 --- /dev/null +++ b/src/udev-mgr.h @@ -0,0 +1,52 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ +/* + * udev-mgr.c + * Copyright (C) Conor Curran 2011 + * + * udev-mgr.c 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 3 of the License, or + * (at your option) any later version. + * + * udev-mgr.c 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, see . + + */ + +#ifndef _UDEV_MGR_H_ +#define _UDEV_MGR_H_ + +#include + +G_BEGIN_DECLS + +#define UDEV_TYPE_MGR (udev_mgr_get_type ()) +#define UDEV_MGR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), UDEV_TYPE_MGR, UdevMgr)) +#define UDEV_MGR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), UDEV_TYPE_MGR, UdevMgrClass)) +#define UDEV_IS_MGR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), UDEV_TYPE_MGR)) +#define UDEV_IS_MGR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), UDEV_TYPE_MGR)) +#define UDEV_MGR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), UDEV_TYPE_MGR, UdevMgrClass)) + +typedef struct _UdevMgrClass UdevMgrClass; +typedef struct _UdevMgr UdevMgr; + +struct _UdevMgrClass +{ + GObjectClass parent_class; +}; + +struct _UdevMgr +{ + GObject parent_instance; +}; + +GType udev_mgr_get_type (void) G_GNUC_CONST; + +G_END_DECLS + +#endif /* _UDEV_MGR_H_ */ -- cgit v1.2.3 From 66af46666904be8c2b056fc32d2bf258bf31b91f Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 19 Jul 2011 13:18:54 +0100 Subject: system added to device menu, more tidying as we go --- src/device-menu-mgr.c | 185 ++++++++++++++++++++++++++++++++++++++++++-------- src/session-service.c | 4 +- src/udev-mgr.c | 36 +++++----- src/udev-mgr.h | 35 +++++----- 4 files changed, 191 insertions(+), 69 deletions(-) (limited to 'src/udev-mgr.h') diff --git a/src/device-menu-mgr.c b/src/device-menu-mgr.c index 0114b92..b8a2050 100644 --- a/src/device-menu-mgr.c +++ b/src/device-menu-mgr.c @@ -17,6 +17,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include + #include "device-menu-mgr.h" #include "gconf-helper.h" #include "dbus-shared-names.h" @@ -24,6 +26,7 @@ with this program. If not, see . #include "lock-helper.h" #include "upower-client.h" + #define UP_ADDRESS "org.freedesktop.UPower" #define UP_OBJECT "/org/freedesktop/UPower" #define UP_INTERFACE "org.freedesktop.UPower" @@ -39,12 +42,13 @@ struct _DeviceMenuMgr static GConfClient *gconf_client = NULL; static DbusmenuMenuitem *lock_menuitem = NULL; +static DbusmenuMenuitem *system_settings_menuitem = NULL; static DBusGProxyCall * suspend_call = NULL; static DBusGProxyCall * hibernate_call = NULL; static DbusmenuMenuitem * hibernate_mi = NULL; -static DbusmenuMenuitem * suspend_mi = NULL; +//static DbusmenuMenuitem * suspend_mi = NULL; static DbusmenuMenuitem * logout_mi = NULL; static DbusmenuMenuitem * restart_mi = NULL; static DbusmenuMenuitem * shutdown_mi = NULL; @@ -64,15 +68,19 @@ static void device_menu_mgr_rebuild_items (DeviceMenuMgr *self); static void lock_if_possible (DeviceMenuMgr* self); static void machine_sleep_with_context (DeviceMenuMgr* self, gchar* type); +static void show_system_settings_with_context (DbusmenuMenuitem * mi, + guint timestamp, + gchar * type); + static void machine_sleep_from_hibernate (DbusmenuMenuitem * mi, guint timestamp, gpointer userdata); -static void +/*static void machine_sleep_from_suspend (DbusmenuMenuitem * mi, guint timestamp, gpointer userdata); - +*/ G_DEFINE_TYPE (DeviceMenuMgr, device_menu_mgr, G_TYPE_OBJECT); static void @@ -100,7 +108,8 @@ device_menu_mgr_class_init (DeviceMenuMgrClass *klass) object_class->finalize = device_menu_mgr_finalize; } - +// TODO +// Is this needed anymore static void lockdown_changed (GConfClient *client, guint cnxd_id, @@ -167,14 +176,14 @@ sleep_response (DBusGProxy * proxy, DBusGProxyCall * call, gpointer data) return; } -static void +/*static void machine_sleep_from_suspend (DbusmenuMenuitem * mi, guint timestamp, gpointer userdata) { DeviceMenuMgr* self = DEVICE_MENU_MGR (userdata); machine_sleep_with_context (self, "Suspend"); -} +}*/ static void machine_sleep_from_hibernate (DbusmenuMenuitem * mi, @@ -208,6 +217,9 @@ machine_sleep_with_context (DeviceMenuMgr* self, gchar* type) } /* A response to getting the suspend property */ +// TODO +// Is this needed anymore + static void suspend_prop_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) { @@ -234,6 +246,9 @@ suspend_prop_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) } /* Response to getting the hibernate property */ +// TODO +// Is this needed anymore + static void hibernate_prop_cb (DBusGProxy * proxy, DBusGProxyCall * call, gpointer userdata) { @@ -392,6 +407,7 @@ setup_up (DeviceMenuMgr* self) { static void show_dialog (DbusmenuMenuitem * mi, guint timestamp, gchar * type) { + gchar * helper = g_build_filename(LIBEXECDIR, "gtk-logout-helper", NULL); gchar * dialog_line = g_strdup_printf("%s --%s", helper, type); g_free(helper); @@ -403,16 +419,50 @@ show_dialog (DbusmenuMenuitem * mi, guint timestamp, gchar * type) g_warning("Unable to show dialog: %s", error->message); g_error_free(error); } + g_free(dialog_line); +} + +static void +show_system_settings_with_context (DbusmenuMenuitem * mi, + guint timestamp, + gchar * type) +{ + gchar * control_centre_command = g_strdup_printf("%s %s", + "gnome-control-center", + type); - g_free(dialog_line); + g_debug("Command centre exec call '%s'", control_centre_command); - return; + GError * error = NULL; + if (!g_spawn_command_line_async(control_centre_command, &error)) + { + g_warning("Unable to show dialog: %s", error->message); + g_error_free(error); + } + g_free(control_centre_command); } - static void -device_menu_mgr_rebuild_items (DeviceMenuMgr* self) +device_menu_mgr_build_static_items (DeviceMenuMgr* self) { + system_settings_menuitem = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (system_settings_menuitem, + DBUSMENU_MENUITEM_PROP_LABEL, + _("System Settings...")); + g_signal_connect (G_OBJECT(system_settings_menuitem), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(show_system_settings_with_context), ""); + + dbusmenu_menuitem_child_add_position(self->root_item, + system_settings_menuitem, + 0); + + DbusmenuMenuitem * separator1 = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (separator1, + DBUSMENU_MENUITEM_PROP_TYPE, + DBUSMENU_CLIENT_TYPES_SEPARATOR); + dbusmenu_menuitem_child_append (self->root_item, separator1); + gboolean can_lockscreen; /* Make sure we have a valid GConf client, and build one @@ -423,6 +473,99 @@ device_menu_mgr_rebuild_items (DeviceMenuMgr* self) LOCKDOWN_KEY_SCREENSAVER, NULL); /* Lock screen item */ + if (can_lockscreen) { + lock_menuitem = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (lock_menuitem, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Lock Screen")); + + gchar * shortcut = gconf_client_get_string(gconf_client, KEY_LOCK_SCREEN, NULL); + if (shortcut != NULL) { + g_debug("Lock screen shortcut: %s", shortcut); + dbusmenu_menuitem_property_set_shortcut_string(lock_menuitem, shortcut); + g_free(shortcut); + } + else { + g_debug("Unable to get lock screen shortcut."); + } + + g_signal_connect (G_OBJECT(lock_menuitem), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(lock_screen), NULL); + dbusmenu_menuitem_child_append(self->root_item, lock_menuitem); + } + + logout_mi = dbusmenu_menuitem_new(); + + if (supress_confirmations()) { + dbusmenu_menuitem_property_set (logout_mi, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Log Out")); + } + else { + dbusmenu_menuitem_property_set (logout_mi, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Log Out\342\200\246")); + } + dbusmenu_menuitem_property_set_bool (logout_mi, + DBUSMENU_MENUITEM_PROP_VISIBLE, + show_logout()); + dbusmenu_menuitem_child_append(self->root_item, logout_mi); + g_signal_connect( G_OBJECT(logout_mi), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(show_dialog), "logout"); + + if (can_hibernate && allow_hibernate) { + hibernate_mi = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set (hibernate_mi, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Hibernate")); + dbusmenu_menuitem_child_append(self->root_item, hibernate_mi); + g_signal_connect (G_OBJECT(hibernate_mi), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(machine_sleep_from_hibernate), self); + } + + shutdown_mi = dbusmenu_menuitem_new(); + + if (supress_confirmations()) { + dbusmenu_menuitem_property_set (shutdown_mi, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Shut Down")); + } + else { + dbusmenu_menuitem_property_set (shutdown_mi, + DBUSMENU_MENUITEM_PROP_LABEL, + _("Shut Down\342\200\246")); + } + dbusmenu_menuitem_property_set_bool (shutdown_mi, + DBUSMENU_MENUITEM_PROP_VISIBLE, + show_shutdown()); + dbusmenu_menuitem_child_append (self->root_item, shutdown_mi); + g_signal_connect (G_OBJECT(shutdown_mi), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK(show_dialog), "shutdown"); + + RestartShutdownLogoutMenuItems * restart_shutdown_logout_mi = g_new0 (RestartShutdownLogoutMenuItems, 1); + restart_shutdown_logout_mi->logout_mi = logout_mi; + restart_shutdown_logout_mi->shutdown_mi = shutdown_mi; + + update_menu_entries(restart_shutdown_logout_mi); +} + + +static void +device_menu_mgr_rebuild_items (DeviceMenuMgr* self) +{ + //gboolean can_lockscreen; + + /* Make sure we have a valid GConf client, and build one + if needed */ + //device_menu_mgr_ensure_gconf_client (self); + + /*can_lockscreen = !gconf_client_get_bool ( gconf_client, + LOCKDOWN_KEY_SCREENSAVER, + NULL); if (can_lockscreen) { lock_menuitem = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set (lock_menuitem, @@ -444,8 +587,6 @@ device_menu_mgr_rebuild_items (DeviceMenuMgr* self) dbusmenu_menuitem_child_append(self->root_item, lock_menuitem); } - /* Start going through the session based items. */ - logout_mi = dbusmenu_menuitem_new(); if (supress_confirmations()) { dbusmenu_menuitem_property_set (logout_mi, @@ -487,22 +628,6 @@ device_menu_mgr_rebuild_items (DeviceMenuMgr* self) G_CALLBACK(machine_sleep_from_hibernate), self); } - restart_mi = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set (restart_mi, - DBUSMENU_MENUITEM_PROP_TYPE, - RESTART_ITEM_TYPE); - if (supress_confirmations()) { - dbusmenu_menuitem_property_set (restart_mi, - RESTART_ITEM_LABEL, - _("Restart")); - } else { - dbusmenu_menuitem_property_set (restart_mi, - RESTART_ITEM_LABEL, - _("Restart\342\200\246")); - } - dbusmenu_menuitem_property_set_bool (restart_mi, - DBUSMENU_MENUITEM_PROP_VISIBLE, - show_restart()); dbusmenu_menuitem_child_append(self->root_item, restart_mi); g_signal_connect (G_OBJECT(restart_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, @@ -533,7 +658,7 @@ device_menu_mgr_rebuild_items (DeviceMenuMgr* self) update_menu_entries(restart_shutdown_logout_mi); - return; + return;*/ } /* When the directory changes we need to figure out how our menu @@ -631,6 +756,6 @@ DeviceMenuMgr* device_menu_mgr_new (SessionDbus* session_dbus) { DeviceMenuMgr* device_mgr = g_object_new (DEVICE_TYPE_MENU_MGR, NULL); device_mgr->session_dbus_interface = session_dbus; - device_menu_mgr_rebuild_items (device_mgr); + device_menu_mgr_build_static_items (device_mgr); return device_mgr; } diff --git a/src/session-service.c b/src/session-service.c index 8bdd0c1..e043d65 100644 --- a/src/session-service.c +++ b/src/session-service.c @@ -76,10 +76,10 @@ static GMainLoop * mainloop = NULL; void service_shutdown (IndicatorService * service, gpointer user_data) { - if (mainloop != NULL) { + /*if (mainloop != NULL) { g_debug("Service shutdown"); g_main_loop_quit(mainloop); - } + }*/ return; } diff --git a/src/udev-mgr.c b/src/udev-mgr.c index 045c603..75f760d 100644 --- a/src/udev-mgr.c +++ b/src/udev-mgr.c @@ -1,25 +1,23 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ /* - * udev-mgr.c - * Copyright (C) Conor Curran 2011 - * - * udev-mgr.c 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 3 of the License, or - * (at your option) any later version. - * - * udev-mgr.c 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, see . - - */ +Copyright 2011 Canonical Ltd. -#include "udev-mgr.h" +Authors: + Conor Curran + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, 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, see . +*/ + +#include "udev-mgr.h" G_DEFINE_TYPE (UdevMgr, udev_mgr, G_TYPE_OBJECT); diff --git a/src/udev-mgr.h b/src/udev-mgr.h index 77d62f1..1c5ae73 100644 --- a/src/udev-mgr.h +++ b/src/udev-mgr.h @@ -1,22 +1,21 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ /* - * udev-mgr.c - * Copyright (C) Conor Curran 2011 - * - * udev-mgr.c 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 3 of the License, or - * (at your option) any later version. - * - * udev-mgr.c 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, see . - - */ +Copyright 2011 Canonical Ltd. + +Authors: + Conor Curran + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, 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, see . +*/ #ifndef _UDEV_MGR_H_ #define _UDEV_MGR_H_ -- cgit v1.2.3 From 6dce39846999951353c2e866019a79d568c99dfa Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 25 Jul 2011 18:42:24 +0100 Subject: the beginnings of the udev work --- configure.ac | 2 ++ src/device-menu-mgr.c | 8 +++--- src/udev-mgr.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++---- src/udev-mgr.h | 14 ++++++++--- 4 files changed, 80 insertions(+), 12 deletions(-) (limited to 'src/udev-mgr.h') diff --git a/configure.ac b/configure.ac index 369f12b..e32ac4a 100644 --- a/configure.ac +++ b/configure.ac @@ -58,12 +58,14 @@ AS_IF([test "x$with_gtk" = x3], [PKG_CHECK_MODULES(SESSIONSERVICE, dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION dbusmenu-gtk3-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION dbus-glib-1 + gudev-1.0 gio-unix-2.0 indicator3-0.4 >= $INDICATOR_REQUIRED_VERSION) ], [test "x$with_gtk" = x2], [PKG_CHECK_MODULES(SESSIONSERVICE, dbusmenu-glib-0.4 >= $DBUSMENUGLIB_REQUIRED_VERSION dbusmenu-gtk-0.4 >= $DBUSMENUGTK_REQUIRED_VERSION + gudev-1.0 dbus-glib-1 gio-unix-2.0 indicator-0.4 >= $INDICATOR_REQUIRED_VERSION) diff --git a/src/device-menu-mgr.c b/src/device-menu-mgr.c index 324b3f1..063045e 100644 --- a/src/device-menu-mgr.c +++ b/src/device-menu-mgr.c @@ -27,7 +27,7 @@ with this program. If not, see . #include "lock-helper.h" #include "upower-client.h" #include "apt-watcher.h" - +#include "udev-mgr.h" #define UP_ADDRESS "org.freedesktop.UPower" #define UP_OBJECT "/org/freedesktop/UPower" @@ -41,6 +41,7 @@ struct _DeviceMenuMgr DbusmenuMenuitem* root_item; SessionDbus* session_dbus_interface; AptWatcher* apt_watcher; + UdevMgr* udev_mgr; }; static GConfClient *gconf_client = NULL; @@ -214,7 +215,6 @@ machine_sleep_with_context (DeviceMenuMgr* self, gchar* type) screensaver_throttle(type); lock_if_possible (self); - dbus_g_proxy_begin_call(up_main_proxy, type, sleep_response, @@ -681,7 +681,9 @@ device_menu_mgr_build_static_items (DeviceMenuMgr* self) restart_shutdown_logout_mi->logout_mi = logout_mi; restart_shutdown_logout_mi->shutdown_mi = shutdown_mi; - update_menu_entries(restart_shutdown_logout_mi); + update_menu_entries(restart_shutdown_logout_mi); + // Time to create the udev mgr and hand it the static relevant items. + self->udev_mgr = udev_mgr_new (webcam_menuitem, scanners_menuitem); } diff --git a/src/udev-mgr.c b/src/udev-mgr.c index 6575ca5..b5c1936 100644 --- a/src/udev-mgr.c +++ b/src/udev-mgr.c @@ -18,21 +18,63 @@ with this program. If not, see . */ #include "udev-mgr.h" +#include + +static void udevice_mgr_device_list_iterator (gpointer data, + gpointer userdata); +static void udev_mgr_uevent_cb (GUdevClient *client, + gchar *action, + GUdevDevice *device, + gpointer user_data); +struct _UdevMgr +{ + GObject parent_instance; + DbusmenuMenuitem* scanner_item; + DbusmenuMenuitem* webcam_item; + GUdevClient* client; +}; G_DEFINE_TYPE (UdevMgr, udev_mgr, G_TYPE_OBJECT); static void -udev_mgr_init (UdevMgr *object) +udev_mgr_init (UdevMgr* self) +{ + self->client = NULL; + const gchar *subsystems[1] = {"usb"}; + self->client = g_udev_client_new (subsystems); + const gchar* usb_subsystem = "usb"; + + GList* devices_available = g_udev_client_query_by_subsystem (self->client, + usb_subsystem); + + if (FALSE){ + g_list_foreach (devices_available, udevice_mgr_device_list_iterator, self); + } + //g_list_free (devices_available); + if (FALSE){ + g_signal_connect (G_OBJECT (self->client), + "u-event", + G_CALLBACK (udev_mgr_uevent_cb), + self); + } +} + +static void +udevice_mgr_device_list_iterator (gpointer data, gpointer userdata) { - /* TODO: Add initialization code here */ + g_return_if_fail (G_UDEV_IS_DEVICE (data)); + GUdevDevice* device = G_UDEV_DEVICE (data); + const gchar* name = g_udev_device_get_name (device); + + g_debug ("UDEV MGR - the name of the device = %s", name); + // for now tidy up here. + g_object_unref (device); } static void udev_mgr_finalize (GObject *object) { - /* TODO: Add deinitalization code here */ - G_OBJECT_CLASS (udev_mgr_parent_class)->finalize (object); } @@ -40,7 +82,23 @@ static void udev_mgr_class_init (UdevMgrClass *klass) { GObjectClass* object_class = G_OBJECT_CLASS (klass); - object_class->finalize = udev_mgr_finalize; } +static void udev_mgr_uevent_cb (GUdevClient *client, + gchar *action, + GUdevDevice *device, + gpointer user_data) +{ + g_debug ("just received a UEVENT with an action : %s", action); + g_return_if_fail (UDEV_IS_MGR (user_data)); +} + +UdevMgr* udev_mgr_new (DbusmenuMenuitem* scanner, + DbusmenuMenuitem* webcam) +{ + UdevMgr* mgr = g_object_new (UDEV_TYPE_MGR, NULL); + mgr->scanner_item = scanner; + mgr->webcam_item = webcam; + return mgr; +} diff --git a/src/udev-mgr.h b/src/udev-mgr.h index 1c5ae73..323364a 100644 --- a/src/udev-mgr.h +++ b/src/udev-mgr.h @@ -21,6 +21,14 @@ with this program. If not, see . #define _UDEV_MGR_H_ #include +#include + +#include +#if GTK_CHECK_VERSION(3, 0, 0) +#include +#else +#include +#endif G_BEGIN_DECLS @@ -39,12 +47,10 @@ struct _UdevMgrClass GObjectClass parent_class; }; -struct _UdevMgr -{ - GObject parent_instance; -}; GType udev_mgr_get_type (void) G_GNUC_CONST; +UdevMgr* udev_mgr_new (DbusmenuMenuitem* scanner_item, + DbusmenuMenuitem* webcam_item); G_END_DECLS -- cgit v1.2.3 From 764a81d40737fdb3acb76103c7c895b77e18d300 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 27 Jul 2011 17:23:28 +0100 Subject: convenience method added to handle the insertion and startup detection of scanners --- src/udev-mgr.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++----------- src/udev-mgr.h | 5 ++++ 2 files changed, 71 insertions(+), 15 deletions(-) (limited to 'src/udev-mgr.h') diff --git a/src/udev-mgr.c b/src/udev-mgr.c index 80e49dd..f4b357d 100644 --- a/src/udev-mgr.c +++ b/src/udev-mgr.c @@ -35,7 +35,10 @@ static void udev_mgr_uevent_cb (GUdevClient *client, GUdevDevice *device, gpointer user_data); static void udev_mgr_update_menuitems (UdevMgr* self); - +static void udev_mgr_check_if_device_is_supported (UdevMgr* self, + GUdevDevice *device, + UdevMgrDeviceAction action); + struct _UdevMgr { GObject parent_instance; @@ -43,10 +46,10 @@ struct _UdevMgr DbusmenuMenuitem* webcam_item; GUdevClient* client; GHashTable* supported_scanners; - gint scanners_present; + GHashTable* scanners_present; }; -const char *subsystems[1] = {"usb"}; +const char *subsystems[2] = {"usb", "scsi"}; const gchar* usb_subsystem = "usb"; G_DEFINE_TYPE (UdevMgr, udev_mgr, G_TYPE_OBJECT); @@ -63,21 +66,23 @@ udev_mgr_init (UdevMgr* self) { self->client = NULL; self->supported_scanners = NULL; - self->scanners_present = 0; - + self->scanners_present = NULL; + self->client = g_udev_client_new (subsystems); self->supported_scanners = g_hash_table_new (g_str_hash, g_str_equal); + self->scanners_present = g_hash_table_new (g_str_hash, g_str_equal); + populate_usb_scanners(self->supported_scanners); g_signal_connect (G_OBJECT (self->client), "uevent", G_CALLBACK (udev_mgr_uevent_cb), self); } - static void udev_mgr_finalize (GObject *object) { + // TODO tidy up hashtables. G_OBJECT_CLASS (udev_mgr_parent_class)->finalize (object); } @@ -97,8 +102,9 @@ udevice_mgr_device_list_iterator (gpointer data, gpointer userdata) UdevMgr* self = UDEV_MGR (userdata); GUdevDevice* device = G_UDEV_DEVICE (data); - - const gchar* vendor = NULL; + udev_mgr_check_if_device_is_supported (self, device, ADD); + + /*const gchar* vendor = NULL; const gchar* product = NULL; GList* vendor_list = NULL; @@ -124,7 +130,7 @@ udevice_mgr_device_list_iterator (gpointer data, gpointer userdata) g_debug ("WE HAVE A SUCCESSFUL MATCH!"); } } - g_debug ("JUST SET SCANNERS TO TRUE"); + g_debug ("JUST SET SCANNERS TO TRUE");*/ g_object_unref (device); } @@ -133,7 +139,7 @@ static void udev_mgr_update_menuitems (UdevMgr* self) { dbusmenu_menuitem_property_set_bool (self->scanner_item, DBUSMENU_MENUITEM_PROP_VISIBLE, - self->scanners_present > 0); + g_hash_table_size (self->scanners_present) > 0); } static void udev_mgr_uevent_cb (GUdevClient *client, @@ -142,9 +148,15 @@ static void udev_mgr_uevent_cb (GUdevClient *client, gpointer user_data) { g_return_if_fail (UDEV_IS_MGR (user_data)); - + UdevMgr* self = UDEV_MGR (user_data); g_debug ("just received a UEVENT with an action : %s", action); + + UdevMgrDeviceAction udev_mgr_action = ADD; + if (g_strcmp0 (action, "remove") == 0){ + udev_mgr_action = REMOVE; + } + udev_mgr_check_if_device_is_supported (self, device, udev_mgr_action); const gchar* vendor; const gchar* product; const gchar* number; @@ -178,14 +190,53 @@ static void udev_mgr_uevent_cb (GUdevClient *client, strcat(propstr, " "); strcat(propstr, g_udev_device_get_property(device, *iter)); g_debug("%s", propstr); - } + } } -static gboolean -udev_mgr_is_this_a_supported_scanner (UdevMgr* self, - GUdevDevice *device) +static void +udev_mgr_check_if_device_is_supported (UdevMgr* self, + GUdevDevice *device, + UdevMgrDeviceAction action) { + const gchar* vendor = NULL; + vendor = g_udev_device_get_property (device, "ID_VENDOR_ID"); + if (vendor == NULL) + return; + + GList* vendor_list = NULL; + vendor_list = g_hash_table_lookup (self->supported_scanners, + (gpointer)vendor); + if (vendor_list == NULL) + return; + + const gchar* model_id = NULL; + model_id = g_udev_device_get_property (device, "ID_MODEL_ID"); + + if (model_id == NULL) + return; + + GList* model_entry = NULL; + model_entry = g_list_find_custom(vendor_list, model_id, (GCompareFunc)g_strcmp0); + + if (model_entry != NULL){ + if (action == REMOVE){ + // TODO handle the case where its removed + // remove it if present from the hash and call update_menuitems + } + else{ + g_hash_table_insert (self->scanners_present, + g_strdup(vendor), + g_strdup(model_id)); + } + } + // DEBUG purposes. + if (model_entry == NULL){ + g_debug ("CANT FIND THE MODEL %s FOR VENDOR %s", model_id, vendor); + } + else{ + g_debug ("WE HAVE A SUCCESSFUL MATCH!"); + } } UdevMgr* udev_mgr_new (DbusmenuMenuitem* scanner, diff --git a/src/udev-mgr.h b/src/udev-mgr.h index 323364a..5119803 100644 --- a/src/udev-mgr.h +++ b/src/udev-mgr.h @@ -52,6 +52,11 @@ GType udev_mgr_get_type (void) G_GNUC_CONST; UdevMgr* udev_mgr_new (DbusmenuMenuitem* scanner_item, DbusmenuMenuitem* webcam_item); +typedef enum { + ADD, + REMOVE +}UdevMgrDeviceAction; + G_END_DECLS #endif /* _UDEV_MGR_H_ */ -- cgit v1.2.3