summaryrefslogtreecommitdiff
path: root/usb.c
diff options
context:
space:
mode:
authorSimon Quigley <tsimonq2@ubuntu.com>2017-06-19 14:38:31 -0500
committerSimon Quigley <tsimonq2@ubuntu.com>2017-06-19 14:38:31 -0500
commita08438bda21b3e0d7db2db2360d040841970104d (patch)
treef8a13a1e368bfbd14fe2d9492d6d5824eb5712ce /usb.c
parent8c1612d32c5682a86216adb8c8d11ce715fe5475 (diff)
Import Upstream version 0.3.7pre
Diffstat (limited to 'usb.c')
-rw-r--r--usb.c165
1 files changed, 104 insertions, 61 deletions
diff --git a/usb.c b/usb.c
index e69c6d84..712f4356 100644
--- a/usb.c
+++ b/usb.c
@@ -1,6 +1,7 @@
/*
* Hardware Information, version 0.3
- * Copyright (C) 2003 Leandro Pereira <leandro@linuxmag.com.br>
+ * Copyright (C) 2003-2004 Leandro Pereira <leandro@linuxmag.com.br>
+ * USB support rewritten by Christophe Grosjean <christopheg@wanadoo.fr>
*
* May be modified and/or distributed under the terms of GNU GPL version 2.
*/
@@ -38,12 +39,92 @@ gboolean usb_update(gpointer data)
return TRUE;
}
+
+
+ USBDevice *hi_scan_usb(void)
+ {
+ FILE *proc_usb;
+ gint n=0;
+ USBDevice *usb_dev = NULL, *usb = NULL;
+ struct stat st;
+ gchar buffer[128];
+
+ if (stat("/proc/bus/usb/devices", &st)) return NULL;
+
+ proc_usb = fopen("/proc/bus/usb/devices", "r");
+ while(fgets(buffer, 128, proc_usb)){
+ int lg = strlen(buffer);
+ if (lg>0 && buffer[lg-1] == '\n'){
+ buffer[lg-1]=0;
+ }
+ if (strstr(buffer, "Manufacturer=")) {
+ gchar *buf = buffer;
+
+ for (;*buf; buf++) {
+ if (*buf == '=') {
+ if (usb){
+ usb->vendor = g_strdup(buf+1);
+ }
+ break;
+ }
+ }
+ } else if (strstr(buffer, "Product=")) {
+ gchar *buf = buffer;
+ for (; *buf; buf++) {
+ if (*buf == '=') {
+ if (usb_dev){
+ usb_dev->product = g_strdup(buf+1);
+ }
+ }
+ }
+ } else if (!strncmp(buffer, "D: Ve", 6)) {
+ gchar *buf = buffer;
+ gfloat version;
+ gint class_id;
+
+ usb_dev = g_new0(USBDevice, 1);
+ usb_dev->next = usb;
+ usb = usb_dev;
+
+ buf+=4;
+
+ sscanf(buf, "Ver= %f Cls= %d", &version, &class_id);
+
+ usb_dev->version = version;
+ usb_dev->class_id= class_id;
+
+ walk_until('(');
+ buf[6]=0;
+ usb_dev->class = g_strdup(buf+1);
+
+ n++;
+ } else if (!strncmp(buffer, "P: Ve", 6)) {
+ gchar *buf = buffer;
+ gint vendor_id, prod_id;
+ gfloat rev;
+
+ buf+=4;
+
+ sscanf(buf, "Vendor= %x ProdID= %x Rev= %f",
+ &vendor_id, &prod_id, &rev);
+ if (usb_dev){
+ usb_dev->vendor_id = vendor_id;
+ usb_dev->prod_id = prod_id;
+ usb_dev->revision = rev;
+ }
+ }
+ }
+ fclose(proc_usb);
+ return usb;
+ }
+
+#if 0
USBDevice *hi_scan_usb(void)
{
FILE *proc_usb;
gchar buffer[64];
gint n=0;
- USBDevice *usb_dev, *usb;
+ USBDevice *usb_dev = NULL, *usb = NULL;
struct stat st;
usb = NULL;
@@ -55,7 +136,7 @@ USBDevice *hi_scan_usb(void)
if (strstr(buffer, "Manufacturer=")) {
gchar *buf = buffer;
gboolean lock = FALSE;
- gpointer start, end;
+ gpointer start = NULL, end = NULL;
for (; buf != NULL; buf++) {
if (lock && *buf == '\n') {
@@ -75,7 +156,7 @@ USBDevice *hi_scan_usb(void)
} else if (strstr(buffer, "Product=")) {
gchar *buf = buffer;
gboolean lock = FALSE;
- gpointer start, end;
+ gpointer start = NULL, end = NULL;
for (; buf != NULL; buf++) {
if (lock && *buf == '\n') {
@@ -136,81 +217,43 @@ USBDevice *hi_scan_usb(void)
return usb;
}
+#endif
void hi_show_usb_info(MainWindow *mainwindow, USBDevice *device)
{
- GtkWidget *hbox, *vbox, *label;
gchar *buf;
-#ifdef GTK2
- GtkWidget *pixmap;
-
- pixmap = gtk_image_new_from_file(IMG_PREFIX "usb.png");
- gtk_widget_show(pixmap);
-#endif
if(!device) return;
- hbox = gtk_hbox_new(FALSE, 2);
- gtk_container_set_border_width(GTK_CONTAINER(hbox), 4);
- gtk_widget_show(hbox);
-
- if(mainwindow->framec)
- gtk_widget_destroy(mainwindow->framec);
-
- gtk_container_add(GTK_CONTAINER(mainwindow->frame), hbox);
- mainwindow->framec = hbox;
+ detail_window_set_icon(mainwindow->det_window, IMG_PREFIX "usb.png");
- gtk_frame_set_label(GTK_FRAME(mainwindow->frame), _("USB Device"));
+ gtk_window_set_title(GTK_WINDOW(mainwindow->det_window->window), _("USB Device"));
-#ifdef GTK2
- gtk_box_pack_start(GTK_BOX(hbox), pixmap, FALSE, FALSE, 0);
-#endif
- vbox = gtk_vbox_new(FALSE, 2);
- gtk_widget_show(vbox);
- gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0);
+ detail_window_set_dev_name(mainwindow->det_window, device->product);
+ detail_window_set_dev_type(mainwindow->det_window, device->vendor ?
+ device->vendor : "");
-#ifdef GTK2
- buf = g_strdup_printf("<b>%s</b>", device->product);
- label = gtk_label_new(buf);
- gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
- gtk_label_set_selectable(GTK_LABEL(label), TRUE);
-
+ buf = g_strdup_printf("%s (%d)", device->class, device->class_id);
+ detail_window_append_info(mainwindow->det_window, _("Class"), buf);
g_free(buf);
-#else
- label = gtk_label_new(device->product);
-#endif
- gtk_widget_show(label);
- gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
-
- if (device->vendor) {
- buf = g_strdup_printf(_("Manufacturer: %s"), device->vendor);
- label = gtk_label_new(buf);
- gtk_widget_show(label);
- gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
- g_free(buf);
- }
-
- buf = g_strdup_printf(_("Class: %s (%d)"), device->class, device->class_id);
- label = gtk_label_new(buf);
- gtk_widget_show(label);
- gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
+
+ detail_window_append_separator(mainwindow->det_window);
+
+ buf = g_strdup_printf("%.2f", device->version);
+ detail_window_append_info(mainwindow->det_window, _("Version"), buf);
g_free(buf);
- buf = g_strdup_printf(_("Version: %.2f, Revision: %.2f"), device->version, device->revision);
- label = gtk_label_new(buf);
- gtk_widget_show(label);
- gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
+ buf = g_strdup_printf("%.2f", device->revision);
+ detail_window_append_info(mainwindow->det_window, _("Revision"), buf);
g_free(buf);
if(!device->prod_id) return;
+
+ detail_window_append_separator(mainwindow->det_window);
- buf = g_strdup_printf(_("Vendor ID: 0x%X, Product ID: 0x%X"),
- device->vendor_id, device->prod_id);
- label = gtk_label_new(buf);
- gtk_widget_show(label);
- gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
- g_free(buf);
+ detail_window_append_info_int(mainwindow->det_window, _("Vendor ID"), device->vendor_id, TRUE);
+ detail_window_append_info_int(mainwindow->det_window, _("Product ID"), device->prod_id, TRUE);
}