aboutsummaryrefslogtreecommitdiff
path: root/src/udev-mgr.c
diff options
context:
space:
mode:
authorKen VanDine <ken.vandine@canonical.com>2011-08-25 15:25:38 -0400
committerKen VanDine <ken.vandine@canonical.com>2011-08-25 15:25:38 -0400
commit52d107cad5d839603a4a24a285166d5d78742d7e (patch)
tree2d78e18f7e0bcb68e0714038f9e6a18755582dc5 /src/udev-mgr.c
parentce36ed0c35e58f0244a090250ab7f96b8e5915ac (diff)
parentdb495e787761164191314d4d8fe79c70de075a75 (diff)
downloadayatana-indicator-session-52d107cad5d839603a4a24a285166d5d78742d7e.tar.gz
ayatana-indicator-session-52d107cad5d839603a4a24a285166d5d78742d7e.tar.bz2
ayatana-indicator-session-52d107cad5d839603a4a24a285166d5d78742d7e.zip
Import upstream version 0.3.3.1
Diffstat (limited to 'src/udev-mgr.c')
-rw-r--r--src/udev-mgr.c73
1 files changed, 53 insertions, 20 deletions
diff --git a/src/udev-mgr.c b/src/udev-mgr.c
index 7e51383..edc2262 100644
--- a/src/udev-mgr.c
+++ b/src/udev-mgr.c
@@ -49,7 +49,10 @@ static void debug_device (UdevMgr* self,
GUdevDevice* device,
UdevMgrDeviceAction action);
-
+static gchar* format_device_name (UdevMgr* self,
+ const gchar* brand,
+ const gchar* generic,
+ const gchar* branded) G_GNUC_WARN_UNUSED_RESULT;
struct _UdevMgr
{
GObject parent_instance;
@@ -233,7 +236,7 @@ udev_mgr_handle_webcam (UdevMgr* self,
product);
dbusmenu_menuitem_property_set (self->webcam_item,
DBUSMENU_MENUITEM_PROP_LABEL,
- _("Webcams"));
+ _("Webcam"));
}
else {
if (g_hash_table_lookup (self->webcams_present, product) != NULL){
@@ -245,13 +248,11 @@ udev_mgr_handle_webcam (UdevMgr* self,
manufacturer = g_udev_device_get_property (device, "ID_VENDOR");
if (manufacturer != NULL){
- gchar* lowered = g_ascii_strdown (manufacturer, -1);
- lowered[0] = g_ascii_toupper (lowered[0]);
- gchar* label = g_strdup_printf(_("%s Webcam"), lowered);
- g_free (lowered);
+ gchar * label = format_device_name(self, manufacturer, _("Webcam"), _("%s Webcam"));
dbusmenu_menuitem_property_set (self->webcam_item,
DBUSMENU_MENUITEM_PROP_LABEL,
label);
+ g_free(label);
}
g_hash_table_insert (self->webcams_present,
@@ -307,7 +308,8 @@ debug_device (UdevMgr* self,
g_debug("%s", propstr);
}*/
}
-
+// TODO SCSI is not dynamic right ?
+// i.e. just need to handle startup scan.
static void udev_mgr_handle_scsi_device (UdevMgr* self,
GUdevDevice* device,
UdevMgrDeviceAction action)
@@ -315,7 +317,19 @@ static void udev_mgr_handle_scsi_device (UdevMgr* self,
const gchar* type = NULL;
type = g_udev_device_get_property (device, "TYPE");
// apparently anything thats type 3 and SCSI is a Scanner
- if (g_strcmp0 (type, "6") == 0){
+ if (g_strcmp0 (type, "6") == 0 && action == ADD){
+
+ const gchar* manufacturer = NULL;
+ manufacturer = g_udev_device_get_property (device, "ID_VENDOR");
+
+ if (manufacturer != NULL){
+ gchar * label = format_device_name(self, manufacturer, _("Scanner"), _("%s Scanner"));
+ dbusmenu_menuitem_property_set (self->scanner_item,
+ DBUSMENU_MENUITEM_PROP_LABEL,
+ label);
+ g_free(label);
+ }
+
gchar* random_scanner_name = g_strdup_printf("%p--scanner", self);
g_hash_table_insert (self->scanners_present,
random_scanner_name,
@@ -361,7 +375,7 @@ static void udev_mgr_handle_scsi_device (UdevMgr* self,
g_hash_table_remove (self->scanners_present, vendor);
dbusmenu_menuitem_property_set (self->scanner_item,
DBUSMENU_MENUITEM_PROP_LABEL,
- _("Scanners"));
+ _("Scanner"));
}
}
@@ -374,13 +388,11 @@ static void udev_mgr_handle_scsi_device (UdevMgr* self,
manufacturer = g_udev_device_get_property (device, "ID_VENDOR");
if (manufacturer != NULL){
- gchar* lowered = g_ascii_strdown (manufacturer, -1);
- lowered[0] = g_ascii_toupper (lowered[0]);
- gchar* label = g_strdup_printf(_("%s Scanner"), lowered);
- g_free (lowered);
+ gchar * label = format_device_name(self, manufacturer, _("Scanner"), _("%s Scanner"));
dbusmenu_menuitem_property_set (self->scanner_item,
DBUSMENU_MENUITEM_PROP_LABEL,
label);
+ g_free(label);
}
g_hash_table_insert (self->scanners_present,
g_strdup(vendor),
@@ -397,7 +409,7 @@ udev_mgr_check_if_usb_device_is_supported (UdevMgr* self,
UdevMgrDeviceAction action)
{
const gchar* vendor = NULL;
- debug_device (self, device, action);
+ //debug_device (self, device, action);
vendor = g_udev_device_get_property (device, "ID_VENDOR_ID");
@@ -430,7 +442,7 @@ udev_mgr_check_if_usb_device_is_supported (UdevMgr* self,
g_hash_table_remove (self->scanners_present, vendor);
dbusmenu_menuitem_property_set (self->scanner_item,
DBUSMENU_MENUITEM_PROP_LABEL,
- _("Scanners"));
+ _("Scanner"));
}
}
else{
@@ -442,14 +454,11 @@ udev_mgr_check_if_usb_device_is_supported (UdevMgr* self,
manufacturer = g_udev_device_get_property (device, "ID_VENDOR");
if (manufacturer != NULL){
-
- gchar* lowered = g_ascii_strdown (manufacturer, -1);
- lowered[0] = g_ascii_toupper (lowered[0]);
- gchar* label = g_strdup_printf(_("%s Scanner"), lowered);
- g_free (lowered);
+ gchar * label = format_device_name(self, manufacturer, _("Scanner"), _("%s Scanner"));
dbusmenu_menuitem_property_set (self->scanner_item,
DBUSMENU_MENUITEM_PROP_LABEL,
label);
+ g_free(label);
}
g_hash_table_insert (self->scanners_present,
@@ -502,3 +511,27 @@ UdevMgr* udev_mgr_new (DbusmenuMenuitem* scanner,
}
return mgr;
}
+
+static gchar* format_device_name (UdevMgr* self,
+ const gchar* brand,
+ const gchar* generic,
+ const gchar* branded)
+{
+ // We don't want to accommodate long names
+ if (strlen(brand) > 7)
+ return g_strdup(generic);
+
+ gint i = 0;
+
+ // If it contains something other than an alphabetic entry ignore it.
+ for(i = 0; i < sizeof(brand); i++){
+ if ( !g_ascii_isalpha (brand[i]) )
+ return g_strdup(generic);
+ }
+
+ gchar* lowered = g_ascii_strdown (brand, -1);
+ lowered[0] = g_ascii_toupper (lowered[0]);
+ gchar* label = g_strdup_printf(branded, lowered);
+ g_free (lowered);
+ return label;
+}