Re: [Nautilus-list] Hardware overview



Opps. Thats better. ;P
- Shane

On Sat, 2 Sep 2000, SHANE BUTLER wrote:

> Hello,
> 
> Please find attached patch that adds IDE devices to the hardware overview.
> 
> Changes made include:
> - added func get_IDE_description() which gets info on an ide device
> - some changes in setup_overview_form() to call the above / add gui bits
> - added a new (useless) place holder, setup_IDE_form()
> - added a uri handler in nautilus_hardware_view_load_uri() to catch IDE,
> and call the above placeholder
> 
> It will require you to set the icons up ... I have suggested i-cdrom.png
> for CD-ROMs, and i-blockdev.png for Hard Disks (and other devices
> ie. default).  (To change this, see lines 433, 435, and 438).  I would
> assume that they may have to be copied to the
> nautilus/components/hardware/icons/ dir and the Makefile edited as well,
> but I'm not exactly sure on the workings of nautilus_pixmap_file() (These
> files exist in nautilus/icons/ already).
> 
> Also, I couldn't work out how to format the capacity of a hdd.  My disk is
> a 20G, which shows up about 40,000,000 .  This is about line 300 if
> someone knows how to fix this.
> 
> Please exercise caution when using this, as I have not been able to fully
> test it (Nautilus wouldn't compile, right now I'm running eazel-preview-1
> / nautilus-0.1.0).  Therefore, I'm not 100% sure that all the gtk stuff
> works.
> 
> Enjoy,
> 
> - Shane
> shane_b bigfoot com
> sbutle deakin edu au
> 
> 
> 
> 
> _______________________________________________
> Nautilus-list mailing list
> Nautilus-list lists eazel com
> http://www.eazel.com/mailman/listinfo/nautilus-list
> 
--- nautilus-hardware-view.c	Sat Aug  5 07:27:30 2000
+++ new.c	Fri Sep  1 12:45:59 2000
@@ -269,6 +269,50 @@
 	return result;
 }
 
+/* get desciptive info about an IDE device : by Shane Butler <shane_b bigfoot com> */
+static char*
+get_IDE_description(char *device)
+{
+char *temp_str, *result;
+GString* string_data = g_string_new("");
+char *proc_file;
+
+	/* Read model information string */
+	proc_file = g_strdup_printf("%s/model", device);
+	temp_str = read_proc_info(proc_file);
+	temp_str[strlen(temp_str) - 1] = '\0';
+	g_string_append(string_data, temp_str);
+	g_free(temp_str);
+	g_free(proc_file);
+
+	/* Read media type */
+	proc_file = g_strdup_printf("%s/media", device);
+	temp_str = read_proc_info(proc_file);
+	g_free(proc_file);
+
+	/* If a hard disk, get the size */
+	if(!strcmp(temp_str, "disk\n")) {
+		g_free(temp_str);
+
+		proc_file = g_strdup_printf("%s/capacity", device);
+		temp_str = read_proc_info(proc_file);
+		temp_str[strlen(temp_str) - 1] = '\0';
+		//FIXME: Format temp_str to make sense
+		g_string_append(string_data, "\n");
+		g_string_append(string_data, temp_str);
+		g_string_append(string_data, "M Capacity");
+		g_free(temp_str);
+		g_free(proc_file);
+	} else {
+		g_free(temp_str);
+	}
+
+	result = strdup(string_data->str);
+	g_string_free(string_data, TRUE);
+
+	return result;
+}
+
 /* shared utility to allocate a title for a form */
 
 static void
@@ -311,6 +355,9 @@
 	GtkWidget *temp_widget, *temp_box;
 	GtkWidget *container_box;
 	int cpunum = 0;
+	DIR *directory;
+	struct dirent* entry;
+	char *device, *proc_file, *ide_media;
 	
 	/* allocate a vbox as the container */	
 	view->details->form = gtk_vbox_new(FALSE,0);
@@ -364,7 +411,50 @@
 	g_free(temp_text);
 	gtk_box_pack_start(GTK_BOX(temp_box), temp_widget, 0, 0, 0 );			
  	gtk_widget_show (temp_widget);
-	
+
+	/* Set up ide devices : by Shane Butler <shane_b bigfoot com> */
+	/* Open the ide devices directory */
+	if((directory = opendir("/proc/ide/")) != NULL) {
+		while((entry = readdir(directory)) != NULL) {
+			/* Scan though each entry for actual device dirs */
+			if(!strncmp(entry->d_name, "hd", 2)) {
+				temp_box = gtk_vbox_new(FALSE, 4);
+				gtk_box_pack_start (GTK_BOX (container_box), temp_box, 0, 0, 24);
+				gtk_widget_show(temp_box);
+
+				device = g_strdup_printf("ide/%s", entry->d_name);
+
+				proc_file = g_strdup_printf("%s/media", device);
+				ide_media = read_proc_info(proc_file);
+				g_free(proc_file);
+
+				/* Set the icon depending on the type of device */
+				if(!strcmp(ide_media, "disk\n")) {
+					file_name = nautilus_pixmap_file("i-blockdev.png");
+				} else if(!strcmp(ide_media, "cdrom\n")) {
+					file_name = nautilus_pixmap_file("i-cdrom.png");
+				} else {
+					/* some other device ... still set an icon */
+					file_name = nautilus_pixmap_file("i-blockdev.png");
+				}
+				temp_widget = GTK_WIDGET (gnome_pixmap_new_from_file(file_name));
+				gtk_box_pack_start(GTK_BOX(temp_box), temp_widget, 0, 0, 0);
+				gtk_widget_show(temp_widget);
+				g_free(file_name);
+				g_free(ide_media);
+
+				temp_text = get_IDE_description(device);
+				temp_widget = gtk_label_new(temp_text);
+				g_free(temp_text);
+				gtk_box_pack_start(GTK_BOX(temp_box), temp_widget, 0, 0, 0);
+				gtk_widget_show(temp_widget);
+
+				g_free(device);
+			}
+		}
+		closedir(directory);
+	}
+
 }
 
 /* set up the widgetry for the CPU page */
@@ -413,6 +503,29 @@
  	gtk_widget_show (temp_widget);
 }
 
+/* set up the widgetry for the IDE page */
+
+static void setup_IDE_form(NautilusHardwareView *view)
+{
+	char *message;
+	GtkWidget *temp_widget;
+	
+	/* allocate a vbox as the container */	
+	view->details->form = gtk_vbox_new(FALSE,0);
+	gtk_container_add (GTK_CONTAINER (view), view->details->form);	
+	gtk_widget_show(view->details->form);
+
+	/* set up the title */	
+	setup_form_title(view, NULL, "IDE");
+	
+	message = "This is a placeholder for the IDE page.";
+	temp_widget = gtk_label_new (message);
+ 	gtk_label_set_line_wrap(GTK_LABEL(temp_widget), TRUE);
+	
+	gtk_box_pack_start(GTK_BOX(view->details->form), temp_widget, 0, 0, 12);			
+ 	gtk_widget_show (temp_widget);
+}
+
 /* utility for checking uri */
 static gboolean is_location(char *document_str, const char *place_str)
 {
@@ -446,6 +559,8 @@
 		setup_CPU_form(view);
 	else if (is_location(document_name, "RAM"))
 		setup_RAM_form(view);
+	else if (is_location(document_name, "IDE"))
+		setup_IDE_form(view);
 	else
 		setup_overview_form(view); /* if we don't understand it, go to the overview */
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]