aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConor Curran <conor.curran@canonical.com>2011-07-27 16:15:36 +0100
committerConor Curran <conor.curran@canonical.com>2011-07-27 16:15:36 +0100
commitb4fd0a59df355527593522e66120a12778af11b2 (patch)
tree14d045b3a3659b2a73bd7a426bae94d8c5bb8cef
parentb806cc0e1da3010055c196de59eff15ced2a51b5 (diff)
downloadayatana-indicator-session-b4fd0a59df355527593522e66120a12778af11b2.tar.gz
ayatana-indicator-session-b4fd0a59df355527593522e66120a12778af11b2.tar.bz2
ayatana-indicator-session-b4fd0a59df355527593522e66120a12778af11b2.zip
refactor with a more generic utility function
-rw-r--r--src/device-menu-mgr.c3
-rw-r--r--src/udev-mgr.c50
2 files changed, 32 insertions, 21 deletions
diff --git a/src/device-menu-mgr.c b/src/device-menu-mgr.c
index 063045e..2c559ee 100644
--- a/src/device-menu-mgr.c
+++ b/src/device-menu-mgr.c
@@ -555,7 +555,6 @@ device_menu_mgr_build_static_items (DeviceMenuMgr* self)
dbusmenu_menuitem_child_add_position (self->root_item,
scanners_menuitem,
8);
- //tmp
dbusmenu_menuitem_property_set_bool (scanners_menuitem,
DBUSMENU_MENUITEM_PROP_VISIBLE,
FALSE);
@@ -683,7 +682,7 @@ device_menu_mgr_build_static_items (DeviceMenuMgr* self)
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);
+ self->udev_mgr = udev_mgr_new (scanners_menuitem, webcam_menuitem);
}
diff --git a/src/udev-mgr.c b/src/udev-mgr.c
index 8a5f539..80e49dd 100644
--- a/src/udev-mgr.c
+++ b/src/udev-mgr.c
@@ -34,9 +34,8 @@ static void udev_mgr_uevent_cb (GUdevClient *client,
gchar *action,
GUdevDevice *device,
gpointer user_data);
-/*static gboolean udev_mgr_compare_models (gconstpointer data1,
- gconstpointer data2);
-*/
+static void udev_mgr_update_menuitems (UdevMgr* self);
+
struct _UdevMgr
{
GObject parent_instance;
@@ -44,6 +43,7 @@ struct _UdevMgr
DbusmenuMenuitem* webcam_item;
GUdevClient* client;
GHashTable* supported_scanners;
+ gint scanners_present;
};
const char *subsystems[1] = {"usb"};
@@ -63,15 +63,11 @@ udev_mgr_init (UdevMgr* self)
{
self->client = NULL;
self->supported_scanners = NULL;
-
+ self->scanners_present = 0;
+
self->client = g_udev_client_new (subsystems);
self->supported_scanners = g_hash_table_new (g_str_hash, g_str_equal);
populate_usb_scanners(self->supported_scanners);
- GList* devices_available = g_udev_client_query_by_subsystem (self->client,
- usb_subsystem);
-
- g_list_foreach (devices_available, udevice_mgr_device_list_iterator, self);
- g_list_free (devices_available);
g_signal_connect (G_OBJECT (self->client),
"uevent",
G_CALLBACK (udev_mgr_uevent_cb),
@@ -101,9 +97,7 @@ udevice_mgr_device_list_iterator (gpointer data, gpointer userdata)
UdevMgr* self = UDEV_MGR (userdata);
GUdevDevice* device = G_UDEV_DEVICE (data);
-
- const gchar* name = g_udev_device_get_name (device);
-
+
const gchar* vendor = NULL;
const gchar* product = NULL;
GList* vendor_list = NULL;
@@ -126,13 +120,22 @@ udevice_mgr_device_list_iterator (gpointer data, gpointer userdata)
g_debug ("CANT FIND THE MODEL %s FOR VENDOR %s", product, vendor);
}
else{
- dbusmenu_menuitem
+ self->scanners_present += 1;
g_debug ("WE HAVE A SUCCESSFUL MATCH!");
- }
+ }
}
+ g_debug ("JUST SET SCANNERS TO TRUE");
g_object_unref (device);
}
+
+static void udev_mgr_update_menuitems (UdevMgr* self)
+{
+ dbusmenu_menuitem_property_set_bool (self->scanner_item,
+ DBUSMENU_MENUITEM_PROP_VISIBLE,
+ self->scanners_present > 0);
+}
+
static void udev_mgr_uevent_cb (GUdevClient *client,
gchar *action,
GUdevDevice *device,
@@ -178,12 +181,12 @@ static void udev_mgr_uevent_cb (GUdevClient *client,
}
}
-/*static gboolean
-udev_mgr_compare_models (gconstpointer data1,
- gconstpointer data2)
+static gboolean
+udev_mgr_is_this_a_supported_scanner (UdevMgr* self,
+ GUdevDevice *device)
{
- return FALSE;
-}*/
+
+}
UdevMgr* udev_mgr_new (DbusmenuMenuitem* scanner,
DbusmenuMenuitem* webcam)
@@ -191,5 +194,14 @@ UdevMgr* udev_mgr_new (DbusmenuMenuitem* scanner,
UdevMgr* mgr = g_object_new (UDEV_TYPE_MGR, NULL);
mgr->scanner_item = scanner;
mgr->webcam_item = webcam;
+
+ GList* devices_available = g_udev_client_query_by_subsystem (mgr->client,
+ usb_subsystem);
+
+ g_list_foreach (devices_available,
+ udevice_mgr_device_list_iterator,
+ mgr);
+ g_list_free (devices_available);
+ udev_mgr_update_menuitems (mgr);
return mgr;
}