nautilus-hardware-view.c 25.4 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */

/*
 *  Copyright (C) 2000 Eazel, Inc.
 *
 *  This library 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 2 of the
 *  License, or (at your option) any later version.
 *
 *  This library 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 library; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  Author: Andy Hertzfeld <andy@eazel.com>
21
 *          Shane Butler <shane_b@bigfoot.com>
22
23
24
25
26
27
28
29
30
31
 *
 */


/* hardware view - presents various views of the hardware configuration */

#include <config.h>
#include "nautilus-hardware-view.h"

#include <dirent.h>
32
33
34
35
#include <fcntl.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gnome.h>
#include <gtk/gtksignal.h>
Ramiro Estrugo's avatar
Ramiro Estrugo committed
36
#include <eel/eel-background.h>
37
38
39
#include <libnautilus-private/nautilus-directory-background.h>
#include <libnautilus-private/nautilus-file-utilities.h>
#include <libnautilus-private/nautilus-file.h>
Ramiro Estrugo's avatar
Ramiro Estrugo committed
40
41
42
43
44
#include <eel/eel-glib-extensions.h>
#include <eel/eel-gtk-extensions.h>
#include <eel/eel-gtk-macros.h>
#include <eel/eel-image.h>
#include <eel/eel-label.h>
45
#include <libnautilus-private/nautilus-metadata.h>
Ramiro Estrugo's avatar
Ramiro Estrugo committed
46
#include <eel/eel-string.h>
47
#include <libnautilus/libnautilus.h>
48
#include <limits.h>
49
#include <locale.h>
50
51
#include <sys/stat.h>
#include <sys/types.h>
52
53

struct _NautilusHardwareViewDetails {
Darin Adler's avatar
Darin Adler committed
54
        NautilusView *nautilus_view;
55
56
	BonoboPropertyBag *property_bag;
	        
57
        GtkWidget *form;
58
59
60
61
62
63
64
65
66
67
68
	
	EelLabel  *uptime_label;
	int timer_task;
	
	int cpu_count;
	int mem_size;
};

/* drag and drop properties */
enum {
	TARGET_COLOR
69
70
};

71
/* property bag properties */
72
enum {
73
74
	ICON_NAME,
	COMPONENT_INFO
75
76
77
78
79
80
};

static GtkTargetEntry hardware_dnd_target_table[] = {
	{ "application/x-color", 0, TARGET_COLOR },
};

81
82
83
84
85
86
87
static void nautilus_hardware_view_drag_data_received (GtkWidget                 *widget,
                                                       GdkDragContext            *context,
                                                       int                        x,
                                                       int                        y,
                                                       GtkSelectionData          *selection_data,
                                                       guint                      info,
                                                       guint                      time);
88
89
static void nautilus_hardware_view_class_init   (NautilusHardwareViewClass *klass);
static void nautilus_hardware_view_init         (NautilusHardwareView      *view);
90
91
92
93
static void nautilus_hardware_view_destroy            (GtkObject                 *object);
static void hardware_view_load_location_callback      (NautilusView              *view,
                                                       const char                *location,
                                                       NautilusHardwareView      *hardware_view);
94
95
static char* make_summary_string		      (NautilusHardwareView	 *hardware_view);
static int  update_uptime_text			      (gpointer			 callback_data);
96

97
EEL_CLASS_BOILERPLATE (NautilusHardwareView, nautilus_hardware_view, GTK_TYPE_EVENT_BOX)
98
99
100
101

#define HARDWARE_DEFAULT_BACKGROUND_COLOR  "rgb:DDDD/DDDD/BBBB"

static void
102
nautilus_hardware_view_class_init (NautilusHardwareViewClass *klass)
103
104
105
106
107
108
109
110
111
112
113
{
	GtkObjectClass *object_class;
	GtkWidgetClass *widget_class;
	
	object_class = GTK_OBJECT_CLASS (klass);
	widget_class = GTK_WIDGET_CLASS (klass);

	object_class->destroy = nautilus_hardware_view_destroy;
	widget_class->drag_data_received  = nautilus_hardware_view_drag_data_received;
}

114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* property bag property access routines */
static void
get_bonobo_properties (BonoboPropertyBag *bag,
			BonoboArg *arg,
			guint arg_id,
			CORBA_Environment *ev,
			gpointer callback_data)
{
	char *hardware_summary;
	
	switch (arg_id) {
        	case ICON_NAME:
                	BONOBO_ARG_SET_STRING (arg, "computer");					
                	break;
        	
        	case COMPONENT_INFO:
                	hardware_summary = make_summary_string ((NautilusHardwareView*) callback_data);
                	BONOBO_ARG_SET_STRING (arg, hardware_summary);					
                	g_free (hardware_summary);
                	break;
	
        	default:
                	g_warning ("Unhandled arg %d", arg_id);
                	break;
	}
}

/* there are no settable properties, so complain if someone tries to set one */
static void
set_bonobo_properties (BonoboPropertyBag *bag,
			const BonoboArg *arg,
			guint arg_id,
			CORBA_Environment *ev,
			gpointer callback_data)
{
                g_warning ("Bad Property set on hardware view: property ID %d", arg_id);
}
151

152
/* initialize ourselves by connecting to the load_location signal and allocating our subviews */
153
static void
154
nautilus_hardware_view_init (NautilusHardwareView *hardware_view)
155
{
Ramiro Estrugo's avatar
Ramiro Estrugo committed
156
  	EelBackground *background;
157
158
	hardware_view->details = g_new0 (NautilusHardwareViewDetails, 1);

Darin Adler's avatar
Darin Adler committed
159
	hardware_view->details->nautilus_view = nautilus_view_new (GTK_WIDGET (hardware_view));
160

161
	g_signal_connect (hardware_view->details->nautilus_view, 
162
			    "load_location",
163
			    G_CALLBACK (hardware_view_load_location_callback), 
164
165
166
167
			    hardware_view);

	hardware_view->details->form = NULL;

Ramiro Estrugo's avatar
Ramiro Estrugo committed
168
169
  	background = eel_get_widget_background (GTK_WIDGET (hardware_view));
  	eel_background_set_color (background, HARDWARE_DEFAULT_BACKGROUND_COLOR);
170
171
172
173

	/* prepare ourselves to receive dropped objects */
	gtk_drag_dest_set (GTK_WIDGET (hardware_view),
			   GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP, 
174
			   hardware_dnd_target_table, G_N_ELEMENTS (hardware_dnd_target_table), GDK_ACTION_COPY);
175
176
177
178
179
180
181
182
183
184
185
186
 
 	/* allocate a property bag to specify the name of the icon for this component */
	hardware_view->details->property_bag = bonobo_property_bag_new (get_bonobo_properties,  set_bonobo_properties, hardware_view);
	bonobo_control_set_properties (nautilus_view_get_bonobo_control (hardware_view->details->nautilus_view), hardware_view->details->property_bag);
	bonobo_property_bag_add (hardware_view->details->property_bag, "icon_name", ICON_NAME, BONOBO_ARG_STRING, NULL,
				 _("name of icon for the hardware view"), 0);
	bonobo_property_bag_add (hardware_view->details->property_bag, "summary_info", COMPONENT_INFO, BONOBO_ARG_STRING, NULL,
				 _("summary of hardware info"), 0);

	/* add the timer task to update the uptime */
	hardware_view->details->timer_task = gtk_timeout_add (60000, update_uptime_text, hardware_view); 

187
188
189
190
191
192
	gtk_widget_show_all (GTK_WIDGET (hardware_view));
}

static void
nautilus_hardware_view_destroy (GtkObject *object)
{
193
194
195
	NautilusHardwareView *hardware_view;

        hardware_view = NAUTILUS_HARDWARE_VIEW (object);
196

197
198
199
200
201
202
203
204
205
206
	/* free the property bag */
	if (hardware_view->details->property_bag != NULL) {
		bonobo_object_unref (BONOBO_OBJECT (hardware_view->details->property_bag));
	}
	
	/* remove the timer task */
	if (hardware_view->details->timer_task != 0) {
		gtk_timeout_remove (hardware_view->details->timer_task);
	}

207
208
	g_free (hardware_view->details);

Ramiro Estrugo's avatar
Ramiro Estrugo committed
209
	EEL_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
210
211
212
}

/* Component embedding support */
Darin Adler's avatar
Darin Adler committed
213
NautilusView *
214
nautilus_hardware_view_get_nautilus_view (NautilusHardwareView *hardware_view)
215
{
216
	return hardware_view->details->nautilus_view;
217
218
}

219
static char * 
220
read_proc_info (const char* proc_filename)
221
222
223
224
{
	FILE *thisFile;
	char *result;
	char buffer[256];
225
	char* path_name;
226
227
	GString* string_data = g_string_new("");
	
228
229
230
231
232
        path_name = g_strdup_printf ("/proc/%s", proc_filename);	
	thisFile = fopen (path_name, "r");
	g_free (path_name);
	while (fgets (buffer, 255, thisFile) != NULL) {
		g_string_append (string_data, buffer);		
233
	}
234
	fclose (thisFile);
235
	
236
237
	result = string_data->str;
	g_string_free(string_data, FALSE);
238
239
240
241
242
243
244

	return result;
}

/* utility routine to extract information from a string and add it to an XML node */

static char*
245
extract_info (char* data, const char *field_name, int nth)
246
247
248
249
250
251
{
	int index;
	char **info_array;
	char *field_data = NULL;
	
	/* parse the data into a string array */
252
	info_array = g_strsplit (data, "\n", 32);
253
254
	/* iterate through the data isolating the field */
	for (index = 0; index < 32; index++) {
255
		if (info_array[index] == NULL) {
256
			break;
257
                }
Ramiro Estrugo's avatar
Ramiro Estrugo committed
258
		if (eel_str_has_prefix(info_array[index], field_name)) {
259
260
261
			if (nth > 0) {
                                nth--;
			} else {
262
263
264
265
266
				field_data = info_array[index] + strlen(field_name);
				field_data = strchr(field_data, ':') + 1;
				field_data =  g_strchug(field_data);
				break;
			}
267
268
269
270
		}
	}
	
	/* add the requested node if the field was found */
271
272
	field_data = g_strdup (field_data);
	g_strfreev (info_array);
273
274
275
276
277
	return field_data;
}

/* get descriptive text about the CPU */

278
279
static char *
get_CPU_description (int nth)
280
{
281
	char *proc_data;
282
283
        char *model, *speed, *cache_size; 
        char *localized_speed;
284
	char *result;
285
286
	char *p;
 	struct lconv *l;
287

288
289
290
291
292
        proc_data = read_proc_info ("cpuinfo");
	model = extract_info (proc_data, "model name", nth);
	speed = extract_info (proc_data, "cpu MHz", nth);
	cache_size = extract_info (proc_data, "cache size", nth);
	g_free (proc_data);
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
        
  	/* Hack to localize the decimal_point */
        p = speed == NULL ? NULL : strrchr (speed, '.');
        if (p == NULL) {
                localized_speed = g_strdup (speed);
        } else {
                *p = '\0';
                l = localeconv ();
                localized_speed = g_strconcat (speed, l->decimal_point,
                                               p + 1, NULL);
        }
        
        /* Remove the " KB" part so that it can be localized */
        if (cache_size != NULL) {
                p = strchr (cache_size, ' ');
                if (p != NULL) {
                        *p = '\0';
                }   
        }  	
312
        
313
314
315
316
317
        if (model == NULL || speed == NULL || cache_size == NULL) {
                result = NULL;
        } else {
                result = g_strdup_printf (_("%s CPU\n"
                                            "%s MHz\n"
318
319
                                            "%s K cache size"),
                                          model, localized_speed, cache_size);
320
        }
321
        
322
323
        g_free (model);
        g_free (speed);
324
        g_free (localized_speed);
325
        g_free (cache_size);
326
327
328
329
330

	return result;	
}

/* get descriptive information about main memory */
331
332
static char *
get_RAM_description (void)
333
{
334
335
336
	char *temp_str, *result;
	char *proc_data;
        gulong ram_size;
337

338
        proc_data = read_proc_info ("meminfo");
339

340
	temp_str = extract_info (proc_data, "MemTotal", 0);
341
342
343
344
345
346
        if (temp_str == NULL || strlen (temp_str) < 3) {
                g_free (temp_str);
                return NULL;
        }

        /* strip kbyte suffix */
347
	temp_str[strlen(temp_str) - 3] = '\0';
348

349
	ram_size = (strtoul (temp_str, NULL, 10) + 500) / 1000;
350
351
	if (ram_size >= 1000) {
		result = g_strdup_printf (_("%lu GB RAM"), ram_size / 1000);
352
	} else {
353
		result = g_strdup_printf (_("%lu MB RAM"), ram_size);
354
355
356
	}

 	g_free (temp_str);
357
358
359

	g_free (proc_data);

360
361
362
	return result;
}

363
364
static char *
get_IDE_description (const char *device)
365
366
{
        char *temp_str, *num_str, *result;
367
        GString *string_data = g_string_new("");
368
        char *proc_file;
369
        gulong capacity;
370
371

        /* Read model information string */
372
373
374
375
376
377
        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);
378
379
        
        /* Read media type */
380
381
382
        proc_file = g_strdup_printf ("%s/media", device);
        temp_str = read_proc_info (proc_file);
        g_free (proc_file);
383
384
        
        /* If a hard disk, get the size */
385
386
        if (strcmp (temp_str, "disk\n") == 0) {
                g_free (temp_str);
387

388
389
390
                proc_file = g_strdup_printf ("%s/capacity", device);
                temp_str = read_proc_info (proc_file);
                temp_str[strlen (temp_str) - 1] = '\0';
391

392
393
394
395
396
397
398
                 /* NOTE: this should be 
		  *  capacity = strtoul (...)
		  *  num_str = gnome_vfs_format_file_size_for_display (512 * numsectors);   
		  *               
		  *  (512 bytes per sector)
		  *
		  *  but with large disks we overflow an unsigned long, which is the
399
		  *  the type that gnome_vfs uses (Darin: Not true, gnome-vfs uses 64-bit integers).  
400
401
402
403
404
405
406
407
408
409
		  *
		  *  ALSO, in keeping with disk manufacturer convention, disk sizes
		  *  are quoted in powers of 10 (i.e., MB is 10^6, GB is 10^9).
		  *  (see http://www.maxtor.com/technology/Digi_vs_Deci.html
		  *  So as to not confuse the user too much, we will follow the
		  *  same convention.)
		  *
		  */
   
		capacity = (512 * (strtoul (temp_str, NULL, 10) / 1000)) / 1000;
410
411
		if (capacity >= 1000) {
			num_str = g_strdup_printf (_("%lu GB"), capacity / 1000);
412
		} else {
413
			num_str = g_strdup_printf (_("%lu MB"), capacity);
414
415
		}
             
416
417
418
419
		g_string_append (string_data, "\n");
                g_string_append (string_data, num_str);
                g_free (temp_str);
                g_free (proc_file);
420
        } else {
421
                g_free (temp_str);
422
423
        }
        
424
425
        result = string_data->str;
        g_string_free (string_data, FALSE);
426
427
428
429
430
        
        return result;
}


431
432
/* shared utility to allocate a title for a form */

433
static void
434
435
436
setup_form_title (NautilusHardwareView *view,
                  const char *image_name,
                  const char *title_text)
437
438
439
440
{
	GtkWidget *temp_widget;
	char *file_name;	
	GtkWidget *temp_container = gtk_hbox_new(FALSE, 0);
441

442
443
444
	gtk_box_pack_start (GTK_BOX(view->details->form), temp_container, 0, 0, 4);	
	gtk_widget_show(temp_container);
	
445
	if (image_name != NULL) {
446
 		file_name = gnome_pixmap_file (image_name);
447
		if (file_name != NULL) {
Ramiro Estrugo's avatar
Ramiro Estrugo committed
448
			temp_widget = eel_image_new (file_name);
449
			gtk_box_pack_start (GTK_BOX(temp_container), temp_widget, 0, 0, 8);		
450
			gtk_widget_show (temp_widget);
451
452
			g_free (file_name);
		}
453
454
	}
	
Ramiro Estrugo's avatar
Ramiro Estrugo committed
455
456
 	temp_widget = eel_label_new (title_text);
	eel_label_make_larger (EEL_LABEL (temp_widget), 10);
457

458
459
460
461
	gtk_box_pack_start (GTK_BOX (temp_container), temp_widget, 0, 0, 8);			 	
	gtk_widget_show (temp_widget);
}

462
463
464
465
466
467
468
469
470
471
472
473
474
/* utility to add an element to the hardware view */
static void
add_element_to_table (GtkWidget *table, GtkWidget *element, int element_index)
{
	int column_pos, row_pos;
	
	column_pos = element_index % 3;
	row_pos = element_index / 3;
  	
	gtk_table_attach (GTK_TABLE (table),element,
			  column_pos, column_pos + 1, row_pos ,row_pos + 1, 
			  GTK_FILL, GTK_FILL, 12, 12);
}
475

476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
/* uptime the uptime label with the current uptime */
static int
update_uptime_text (gpointer callback_data)
{
	char *uptime_data, *uptime_text;
	double uptime_seconds;
	int uptime_days, uptime_hours, uptime_minutes;
	
	uptime_data = read_proc_info ("uptime");
	uptime_seconds = atof (uptime_data);
	
	uptime_days = uptime_seconds / 86400;
	uptime_hours = (uptime_seconds - (uptime_days * 86400)) / 3600;
	uptime_minutes = (uptime_seconds - (uptime_days * 86400) - (uptime_hours * 3600)) / 60;
	
	uptime_text = g_strdup_printf (_("Uptime is %d days, %d hours, %d minutes"), uptime_days, uptime_hours, uptime_minutes);
	eel_label_set_text (NAUTILUS_HARDWARE_VIEW (callback_data)->details->uptime_label, uptime_text);
	g_free (uptime_text);
	
	g_free (uptime_data);
	return TRUE;
}

499
/* set up the widgetry for the overview page */
500
501
static void
setup_overview_form (NautilusHardwareView *view)
502
503
{
	char  *file_name, *temp_text;
504
	GtkWidget *temp_widget, *pixmap_widget, *temp_box;
505
	GtkWidget *table;
506
	int element_index;
507
	DIR *directory;
508
509
        struct dirent* entry;
        char *device, *proc_file, *ide_media;
510
511
512
513
514
515
516
	
	/* 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 */	
517
	setup_form_title (view, NULL, _("Hardware Overview"));
518

519
520
521
522
523
524
	/* allocate a table to hold the elements */
	table =  gtk_table_new (3, 3, FALSE);	
	gtk_box_pack_start (GTK_BOX (view->details->form), table, 0, 0, 2);	
	gtk_widget_show (GTK_WIDGET(table));
   	element_index = 0;
	
525
526
   	view->details->cpu_count = 0;
	while( (temp_text = get_CPU_description (view->details->cpu_count)) != NULL ) {
Eskil Heyn Olsen's avatar
Eskil Heyn Olsen committed
527
		temp_box = gtk_vbox_new(FALSE, 4);
528
		add_element_to_table (table, temp_box, element_index++);
Eskil Heyn Olsen's avatar
Eskil Heyn Olsen committed
529
530
531
		gtk_widget_show (temp_box);

		file_name = nautilus_pixmap_file ("cpu.png");
Ramiro Estrugo's avatar
Ramiro Estrugo committed
532
                temp_widget = eel_image_new (file_name);
533
		gtk_box_pack_start (GTK_BOX(temp_box), temp_widget, 0, 0, 0);		
534
		gtk_widget_show (temp_widget);
535
		g_free (file_name);
Eskil Heyn Olsen's avatar
Eskil Heyn Olsen committed
536
		
Ramiro Estrugo's avatar
Ramiro Estrugo committed
537
538
		temp_widget = eel_label_new (temp_text);
		eel_label_make_larger (EEL_LABEL (temp_widget), 2);
Eskil Heyn Olsen's avatar
Eskil Heyn Olsen committed
539
540
541
		g_free(temp_text);
		gtk_box_pack_start(GTK_BOX(temp_box), temp_widget, 0, 0, 0 );			
		gtk_widget_show (temp_widget);
542

543
		view->details->cpu_count++;
Eskil Heyn Olsen's avatar
Eskil Heyn Olsen committed
544
545
546
547
	}

	/* set up the memory info */
       	temp_box = gtk_vbox_new(FALSE, 4);
548
	add_element_to_table (table, temp_box, element_index++);
Eskil Heyn Olsen's avatar
Eskil Heyn Olsen committed
549
550
551
	gtk_widget_show (temp_box);

 	file_name = nautilus_pixmap_file ("memory_chip.gif");
Ramiro Estrugo's avatar
Ramiro Estrugo committed
552
  	temp_widget = eel_image_new (file_name);
Eskil Heyn Olsen's avatar
Eskil Heyn Olsen committed
553
554
555
556
	gtk_box_pack_start(GTK_BOX(temp_box), temp_widget, 0, 0, 0);		
  	gtk_widget_show(temp_widget);
  	g_free (file_name);
	
557
	temp_text = get_RAM_description ();
Ramiro Estrugo's avatar
Ramiro Estrugo committed
558
559
	temp_widget = eel_label_new (temp_text);
	eel_label_make_larger (EEL_LABEL (temp_widget), 2);
560
	g_free (temp_text);
561
	gtk_box_pack_start (GTK_BOX(temp_box), temp_widget, 0, 0, 0 );			
Eskil Heyn Olsen's avatar
Eskil Heyn Olsen committed
562
563
 	gtk_widget_show (temp_widget);
	
564
565
566
567
568
569
570
        /* 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);
571
				add_element_to_table (table, temp_box, element_index++);
572
573
574
575
576
577
578
579
580
581
                                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")) {
582
                                        file_name = nautilus_pixmap_file("i-harddisk.png");
583
                                } else if(!strcmp(ide_media, "cdrom\n")) {
584
                                        file_name = nautilus_pixmap_file("CD_drive.png");
585
586
                                } else {
                                        /* some other device ... still set an icon */
587
                                        file_name = nautilus_pixmap_file("i-harddisk.png");
588
                                }
589
                                
Ramiro Estrugo's avatar
Ramiro Estrugo committed
590
				pixmap_widget = eel_image_new (file_name);
591
				gtk_box_pack_start (GTK_BOX(temp_box), pixmap_widget, 0, 0, 0);
592
				gtk_widget_show(pixmap_widget);
593
594
				g_free(file_name);
				g_free(ide_media);
595
                                
596
				temp_text = get_IDE_description (device);
Ramiro Estrugo's avatar
Ramiro Estrugo committed
597
598
599
				temp_widget = eel_label_new (temp_text);
				eel_label_make_larger (EEL_LABEL (temp_widget), 2);
				eel_label_set_justify (EEL_LABEL (temp_widget), GTK_JUSTIFY_CENTER);
600

601
				g_free(temp_text);
602
603
                                gtk_box_pack_start(GTK_BOX(temp_box), temp_widget, 0, 0, 0);
                                gtk_widget_show(temp_widget);
604
   
605
606
607
608
609
                                g_free(device);
                        }
                }
                closedir(directory);
        }
610
611
612
613
614
615
616
617
618
619

	/* allocate the uptime label */
	view->details->uptime_label = EEL_LABEL (eel_label_new (""));
	eel_label_make_larger (view->details->uptime_label, 2);
	eel_label_set_justify (view->details->uptime_label, GTK_JUSTIFY_LEFT);

	gtk_box_pack_end (GTK_BOX (view->details->form), GTK_WIDGET (view->details->uptime_label), 0, 0, GNOME_PAD);
	update_uptime_text (view);
	gtk_widget_show(GTK_WIDGET (view->details->uptime_label));
	
620
621
}

622
623
#ifdef ENABLE_SUBVIEWS

624
625
/* set up the widgetry for the CPU page */

626
static void
627
setup_CPU_form (NautilusHardwareView *view)
628
629
630
631
632
633
634
635
636
637
{
	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 */	
638
	setup_form_title (view, NULL, "CPU");
639
	
640
	message = _("This is a placeholder for the CPU page.");
Ramiro Estrugo's avatar
Ramiro Estrugo committed
641
642
643
	temp_widget = eel_label_new (message);
	eel_label_make_larger (EEL_LABEL (temp_widget), 2);
 	eel_label_set_wrap(EEL_LABEL(temp_widget), TRUE);
644
645
646
647
648
649
650
	
	gtk_box_pack_start(GTK_BOX(view->details->form), temp_widget, 0, 0, 12);			
 	gtk_widget_show (temp_widget);
}

/* set up the widgetry for the RAM page */

651
static void
652
setup_RAM_form (NautilusHardwareView *view)
653
654
655
656
657
658
659
660
661
662
{
	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 */	
663
	setup_form_title (view, NULL, "RAM");
664
	
665
	message = _("This is a placeholder for the RAM page.");
Ramiro Estrugo's avatar
Ramiro Estrugo committed
666
667
668
	temp_widget = eel_label_new (message);
	eel_label_make_larger (EEL_LABEL (temp_widget), 2);
 	eel_label_set_wrap(EEL_LABEL(temp_widget), TRUE);
669
670
671
672
673
	
	gtk_box_pack_start(GTK_BOX(view->details->form), temp_widget, 0, 0, 12);			
 	gtk_widget_show (temp_widget);
}

674
675
/* set up the widgetry for the IDE page */

676
static void
677
setup_IDE_form (NautilusHardwareView *view)
678
679
680
681
682
683
684
685
686
687
{
        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 */  
688
        setup_form_title (view, NULL, "IDE");
689
        
690
        message = _("This is a placeholder for the IDE page.");
Ramiro Estrugo's avatar
Ramiro Estrugo committed
691
692
693
        temp_widget = eel_label_new (message);
	eel_label_make_larger (EEL_LABEL (temp_widget), 2);
        eel_label_set_wrap(EEL_LABEL(temp_widget), TRUE);
694
695
696
697
698
699
        
        gtk_box_pack_start(GTK_BOX(view->details->form), temp_widget, 0, 0, 12);            
        gtk_widget_show (temp_widget);
}


700
/* utility for checking uri */
701
702
static gboolean
is_location (const char *document_str, const char *place_str)
703
{
704
	return document_str && strncmp(document_str + 1, place_str, strlen (place_str)) == 0;
705
706
}

707
708
#endif /* ENABLE_SUBVIEWS */

709
710
711
712
713
/* load the uri by casing out on the path */

void
nautilus_hardware_view_load_uri (NautilusHardwareView *view, const char *uri)
{
714
715
716
#ifdef ENABLE_SUBVIEWS
	const char *document_name;
#endif
717
718
719
	
	/* dispose of any old form that was installed */
	if (view->details->form != NULL) {
720
		gtk_widget_destroy (view->details->form);
721
722
723
		view->details->form = NULL;	
	}
		
724
725
726
#ifndef ENABLE_SUBVIEWS
        setup_overview_form (view);
#else
727
	/* extract the document part of the uri */
728
	document_name = strchr (uri, ':');
729
730
	
	/* load the appropriate form, based on the uri and the registration state */
731
732
733
734
735
736
737
738
	if (is_location (document_name, "overview")) {
		setup_overview_form (view);
	} else if (is_location (document_name, "CPU")) {
		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);
739
	} else {
740
		setup_overview_form (view); /* if we don't understand it, go to the overview */
741
        }
742
#endif
743
744
}

745
746
747
748
749
750
751
752
753
754
755
/* Create a string summarizing the most important hardware attributes */
static char *
make_summary_string (NautilusHardwareView *hardware_view)
{
	if (hardware_view->details->cpu_count == 1) {
		return g_strdup ("1 CPU");
	} else {
		return g_strdup_printf ("%d CPUs", hardware_view->details->cpu_count);
	}
}

756
static void
757
758
759
hardware_view_load_location_callback (NautilusView *view, 
                                      const char *location, 
                                      NautilusHardwareView *hardware_view)
760
{
761
	nautilus_view_report_load_underway (hardware_view->details->nautilus_view);
762
	nautilus_view_set_title (hardware_view->details->nautilus_view, _("Hardware"));	
763
764
	nautilus_hardware_view_load_uri (hardware_view, location);
	nautilus_view_report_load_complete (hardware_view->details->nautilus_view);
765
766
767
768
769
770
771
772
773
774
775
776
777
778
}

/* handle drag and drop */

static void  
nautilus_hardware_view_drag_data_received (GtkWidget *widget, GdkDragContext *context,
					 int x, int y,
					 GtkSelectionData *selection_data, guint info, guint time)
{
	g_return_if_fail (NAUTILUS_IS_HARDWARE_VIEW (widget));

	switch (info) {
        case TARGET_COLOR:
                /* Let the background change based on the dropped color. */
Ramiro Estrugo's avatar
Ramiro Estrugo committed
779
                eel_background_receive_dropped_color (eel_get_widget_background (widget),
780
781
782
783
784
785
786
787
                                                           widget, x, y, selection_data);
                break;
                
        default:
                g_warning ("unknown drop type");
                break;
        }
}