Commit f06f9edf authored by Andy Hertzfeld's avatar Andy Hertzfeld

added new hardware view component, plus renamed link files


        added new hardware view component, plus renamed link files
parent a40e983f
2000-04-24 Andy Hertzfeld <andy@eazel.com>
changed link file suffix to .link
* data/top/Computer-ntl.xml: removed file
* data/top/Computer.link: new file
* data/top/Makefile.am: adjusted accordingly
* data/top/Services-ntl.xml: removed file
* data/top/Services.link: added file
* libnautilus-extensions/nautilus-link.c,h:
changed suffix from "ntl-link" to "link"
made links more transparent in list view
* libnautilus-extensions/nautilus-file.c:
make nautilus_file_get_string_attribute know about links
* src/file-manager/fm-directory-view.c:
map filename for links in status bar
added hardware view component for novice home directory. Use /proc as source of info,
but will probably move to libgtop
* configure.in: added hardware view component's directories
* nautilus-clean.sh: added component to list to be cleaned
* components/Makefile.am: added hardware view component
* components/hardware/.cvsignore: ignore generated files
* components/hardware/Makefile.am: makefile for new component
* components/hardware/main.c: standard component bonobo glue
* components/hardware/nautilus-hardware-view.c: the actual code
* components/hardware/nautilus-hardware-view.h: definitions for the component
* components/hardware/nautilus-hardware-view.oafinfo: activation file
* components/hardware/icons/.cvsignore: ignore generate files
* components/hardware/icons/Makefile.am: icons to use in the hardware view
* components/hardware/icons/cpu.png: cpu image
* components/hardware/icons/memory_chip.gif: memory image
* src/ntl-uri-map.c: we still have to kludge here to add new protocols
* components/rpmview/nautilus-rpm-view.c:
changed default background color of package view
2000-04-23 J. Shane Culpepper <pepper@eazel.com>
*components/services/install/eazel-install.c
*components/services/install/Makefile.am
......
......@@ -13,6 +13,7 @@ RPMVIEW_COMPONENT_SUBDIRS = rpmview
endif
SUBDIRS = \
hardware \
help \
history \
html \
......
.deps
.libs
Makefile
Makefile.in
nautilus-hardware-view
SUBDIRS=icons
CPPFLAGS = \
-DPREFIX=\"$(prefix)\"
-DG_LOG_DOMAIN=\"Nautilus-Hardware\"
INCLUDES = \
-I$(top_srcdir) \
-I$(top_builddir) \
$(GCONF_CFLAGS) \
$(GNOMEUI_CFLAGS) \
$(WERROR)
oafdir = $(datadir)/oaf
oaf_DATA = \
nautilus-hardware-view.oafinfo
bin_PROGRAMS = \
nautilus-hardware-view
nautilus_hardware_view_SOURCES = \
nautilus-hardware-view.c \
nautilus-hardware-view.h \
main.c
nautilus_hardware_view_LDFLAGS = \
$(top_builddir)/nautilus-widgets/libnautilus-widgets.la \
$(top_builddir)/libnautilus/libnautilus.la \
$(top_builddir)/libnautilus-extensions/libnautilus-extensions.la \
$(top_builddir)/librsvg/librsvg.la \
$(BONOBO_LIBS) \
$(GNOMEUI_LIBS) \
$(GCONF_LIBS) \
$(VFS_LIBS) \
$(GNORBA_LIBS)
EXTRA_DIST = $(oaf_DATA)
<oaf_info>
<oaf_server iid="OAFIID:nautilus_hardware_view_factory:20000422-2250" type="exe" location="nautilus-hardware-view">
<oaf_attribute name="repo_ids" type="stringv">
<item value="IDL:GNOME/GenericFactory:1.0"/>
</oaf_attribute>
<oaf_attribute name="description" type="string" value="Factory for hardware view"/>
</oaf_server>
<oaf_server iid="OAFIID:nautilus_hardware_view:20000422-2250" type="factory" location="OAFIID:nautilus_hardware_view_factory:20000422-2250">
<oaf_attribute name="repo_ids" type="stringv">
<item value="IDL:Bonobo/Control:1.0"/>
<item value="IDL:Bonobo/Unknown:1.0"/>
<item value="IDL:Nautilus/ContentView:1.0"/>
<item value="IDL:Nautilus/View:1.0"/>
</oaf_attribute>
<oaf_attribute name="description" type="string" value="hardware view"/>
</oaf_server>
</oaf_info>
<oaf_info>
<oaf_server iid="OAFIID:nautilus_hardware_view_factory:20000422-2250" type="exe" location="nautilus-hardware-view">
<oaf_attribute name="repo_ids" type="stringv">
<item value="IDL:GNOME/GenericFactory:1.0"/>
</oaf_attribute>
<oaf_attribute name="description" type="string" value="Factory for hardware view"/>
</oaf_server>
<oaf_server iid="OAFIID:nautilus_hardware_view:20000422-2250" type="factory" location="OAFIID:nautilus_hardware_view_factory:20000422-2250">
<oaf_attribute name="repo_ids" type="stringv">
<item value="IDL:Bonobo/Control:1.0"/>
<item value="IDL:Bonobo/Unknown:1.0"/>
<item value="IDL:Nautilus/ContentView:1.0"/>
<item value="IDL:Nautilus/View:1.0"/>
</oaf_attribute>
<oaf_attribute name="description" type="string" value="hardware view"/>
</oaf_server>
</oaf_info>
<oaf_info>
<oaf_server iid="OAFIID:nautilus_hardware_view_factory:20000422-2250" type="exe" location="nautilus-hardware-view">
<oaf_attribute name="repo_ids" type="stringv">
<item value="IDL:GNOME/GenericFactory:1.0"/>
</oaf_attribute>
<oaf_attribute name="description" type="string" value="Factory for hardware view"/>
</oaf_server>
<oaf_server iid="OAFIID:nautilus_hardware_view:20000422-2250" type="factory" location="OAFIID:nautilus_hardware_view_factory:20000422-2250">
<oaf_attribute name="repo_ids" type="stringv">
<item value="IDL:Bonobo/Control:1.0"/>
<item value="IDL:Bonobo/Unknown:1.0"/>
<item value="IDL:Nautilus/ContentView:1.0"/>
<item value="IDL:Nautilus/View:1.0"/>
</oaf_attribute>
<oaf_attribute name="description" type="string" value="hardware view"/>
</oaf_server>
</oaf_info>
icondir = $(datadir)/pixmaps/nautilus
icon_DATA = \
cpu.png \
memory_chip.gif
EXTRA_DIST = $(icon_DATA)
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
* Copyright (C) 2000 Eazel, Inc
*
* This program 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 program 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 program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: Andy Hertzfeld
*/
/* main.c - main function and object activation function for the hardware view component. */
#include <config.h>
#include "nautilus-hardware-view.h"
#include <gnome.h>
#include <libgnomevfs/gnome-vfs.h>
#include <liboaf/liboaf.h>
#include <bonobo.h>
static int object_count = 0;
static void
hardware_view_object_destroyed(GtkObject *obj)
{
object_count--;
if (object_count <= 0) {
gtk_main_quit ();
}
}
static BonoboObject *
hardware_view_make_object (BonoboGenericFactory *factory,
const char *goad_id,
void *closure)
{
NautilusHardwareView *hardware_view;
NautilusViewFrame *view_frame;
if (strcmp (goad_id, "OAFIID:nautilus_hardware_view:20000422-2250")) {
return NULL;
}
hardware_view = NAUTILUS_HARDWARE_VIEW (gtk_object_new (NAUTILUS_TYPE_HARDWARE_VIEW, NULL));
object_count++;
gtk_signal_connect (GTK_OBJECT (hardware_view), "destroy", hardware_view_object_destroyed, NULL);
view_frame = NAUTILUS_VIEW_FRAME (nautilus_hardware_view_get_view_frame (hardware_view));
return BONOBO_OBJECT (view_frame);
}
int main(int argc, char *argv[])
{
BonoboGenericFactory *factory;
CORBA_ORB orb;
CORBA_Environment ev;
CORBA_exception_init(&ev);
gnome_init_with_popt_table("nautilus-hardware-view", VERSION,
argc, argv,
oaf_popt_options, 0, NULL);
orb = oaf_init (argc, argv);
bonobo_init (orb, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL);
/* initialize gnome-vfs, etc */
g_thread_init (NULL);
gnome_vfs_init ();
factory = bonobo_generic_factory_new_multi ("OAFIID:nautilus_hardware_view_factory:20000422-2250",
hardware_view_make_object, NULL);
do {
bonobo_main ();
} while (object_count > 0);
return 0;
}
/* -*- 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>
*
*/
/* hardware view - presents various views of the hardware configuration */
#include <config.h>
#include "nautilus-hardware-view.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <dirent.h>
#include <libnautilus/libnautilus.h>
#include <libnautilus-extensions/nautilus-background.h>
#include <libnautilus-extensions/nautilus-directory-background.h>
#include <libnautilus-extensions/nautilus-file.h>
#include <libnautilus-extensions/nautilus-file-utilities.h>
#include <libnautilus-extensions/nautilus-glib-extensions.h>
#include <libnautilus-extensions/nautilus-gtk-extensions.h>
#include <libnautilus-extensions/nautilus-gtk-macros.h>
#include <libnautilus-extensions/nautilus-metadata.h>
#include <libnautilus-extensions/nautilus-string.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gtk/gtksignal.h>
#include <gnome.h>
#include <libgnomevfs/gnome-vfs.h>
#include <libgnorba/gnorba.h>
#include <limits.h>
struct _NautilusHardwareViewDetails {
char *uri;
NautilusContentViewFrame *view_frame;
GtkWidget *form;
};
enum {
TARGET_URI_LIST,
TARGET_COLOR,
TARGET_GNOME_URI_LIST
};
static GtkTargetEntry hardware_dnd_target_table[] = {
{ "text/uri-list", 0, TARGET_URI_LIST },
{ "application/x-color", 0, TARGET_COLOR },
{ "special/x-gnome-icon-list", 0, TARGET_GNOME_URI_LIST }
};
static void nautilus_hardware_view_drag_data_received (GtkWidget *widget,
GdkDragContext *context,
int x,
int y,
GtkSelectionData *selection_data,
guint info,
guint time);
static void nautilus_hardware_view_initialize_class (NautilusHardwareViewClass *klass);
static void nautilus_hardware_view_initialize (NautilusHardwareView *view);
static void nautilus_hardware_view_destroy (GtkObject *object);
static void hardware_view_notify_location_change_callback (NautilusContentViewFrame *view,
Nautilus_NavigationInfo *navinfo,
NautilusHardwareView *hardware_view);
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusHardwareView, nautilus_hardware_view, GTK_TYPE_EVENT_BOX)
#define HARDWARE_DEFAULT_BACKGROUND_COLOR "rgb:DDDD/DDDD/BBBB"
static void
nautilus_hardware_view_initialize_class (NautilusHardwareViewClass *klass)
{
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;
}
/* initialize ourselves by connecting to the location change signal and allocating our subviews */
static void
nautilus_hardware_view_initialize (NautilusHardwareView *hardware_view)
{
NautilusBackground *background;
hardware_view->details = g_new0 (NautilusHardwareViewDetails, 1);
hardware_view->details->view_frame = nautilus_content_view_frame_new (GTK_WIDGET (hardware_view));
gtk_signal_connect (GTK_OBJECT (hardware_view->details->view_frame),
"notify_location_change",
GTK_SIGNAL_FUNC (hardware_view_notify_location_change_callback),
hardware_view);
hardware_view->details->form = NULL;
background = nautilus_get_widget_background (GTK_WIDGET (hardware_view));
nautilus_background_set_color (background, HARDWARE_DEFAULT_BACKGROUND_COLOR);
/* 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,
hardware_dnd_target_table, NAUTILUS_N_ELEMENTS (hardware_dnd_target_table), GDK_ACTION_COPY);
gtk_widget_show_all (GTK_WIDGET (hardware_view));
}
static void
nautilus_hardware_view_destroy (GtkObject *object)
{
NautilusHardwareView *hardware_view = NAUTILUS_HARDWARE_VIEW (object);
bonobo_object_unref (BONOBO_OBJECT (hardware_view->details->view_frame));
g_free (hardware_view->details->uri);
g_free (hardware_view->details);
NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
}
/* Component embedding support */
NautilusContentViewFrame *
nautilus_hardware_view_get_view_frame (NautilusHardwareView *hardware_view)
{
return hardware_view->details->view_frame;
}
static char*
read_proc_info(const gchar* proc_filename)
{
FILE *thisFile;
char *result;
char buffer[256];
char* path_name = g_strdup_printf("/proc/%s", proc_filename);
GString* string_data = g_string_new("");
thisFile = fopen( path_name, "r");
while (fgets(buffer, 255, thisFile) != NULL) {
g_string_append(string_data, buffer);
}
fclose(thisFile);
result = strdup(string_data->str);
g_string_free(string_data, TRUE);
g_free(path_name);
return result;
}
/* utility routine to extract information from a string and add it to an XML node */
static char*
extract_info(gchar* data, const gchar *field_name)
{
int index;
char **info_array;
char *field_data = NULL;
/* parse the data into a string array */
info_array = g_strsplit(data, "\n", 32);
/* iterate through the data isolating the field */
for (index = 0; index < 32; index++) {
if (info_array[index] == NULL)
break;
if (nautilus_str_has_prefix(info_array[index], field_name)) {
field_data = info_array[index] + strlen(field_name);
field_data = strchr(field_data, ':') + 1;
field_data = g_strchug(field_data);
break;
}
}
/* add the requested node if the field was found */
if (field_data == NULL)
return NULL;
field_data = strdup(field_data);
g_strfreev(info_array);
return field_data;
}
/* get descriptive text about the CPU */
static char*
get_CPU_description()
{
char *temp_str, *result;
GString* string_data = g_string_new("");
char* proc_data = read_proc_info("cpuinfo");
temp_str = extract_info(proc_data, "model name");
g_string_append(string_data, temp_str);
g_string_append(string_data, " CPU\n");
g_free(temp_str);
temp_str = extract_info(proc_data, "cpu MHz");
g_string_append(string_data, temp_str);
g_string_append(string_data, " MHz\n");
g_free(temp_str);
temp_str = extract_info(proc_data, "cache size");
g_string_append(string_data, temp_str);
g_string_append(string_data, " cache size\n");
g_free(temp_str);
g_free(proc_data);
result = strdup(string_data->str);
g_string_free(string_data, TRUE);
return result;
}
/* get descriptive information about main memory */
static char*
get_RAM_description()
{
char *temp_str, *num_str, *result;
GString* string_data = g_string_new("");
char* proc_data = read_proc_info("meminfo");
temp_str = extract_info(proc_data, "MemTotal");
/* strip kbyte suffix */
temp_str[strlen(temp_str) - 3] = '\0';
num_str = gnome_vfs_file_size_to_string (1000 * atoi(temp_str));
g_string_append(string_data, num_str);
g_string_append(string_data, " RAM");
g_free(num_str);
g_free(temp_str);
g_free(proc_data);
result = strdup(string_data->str);
g_string_free(string_data, TRUE);
return result;
}
/* shared utility to allocate a title for a form */
static void setup_form_title(NautilusHardwareView *view, const char* image_name, const char* title_text)
{
GtkWidget *temp_widget;
char *file_name;
GtkWidget *temp_container = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start (GTK_BOX(view->details->form), temp_container, 0, 0, 4);
gtk_widget_show(temp_container);
if (image_name) {
file_name = gnome_pixmap_file (image_name);
temp_widget = GTK_WIDGET (gnome_pixmap_new_from_file (file_name));
gtk_box_pack_start(GTK_BOX(temp_container), temp_widget, 0, 0, 8);
gtk_widget_show(temp_widget);
g_free (file_name);
}
temp_widget = gtk_label_new (title_text);
/* FIXME: don't use hardwired font like this */
nautilus_gtk_widget_set_font_by_name (temp_widget,
"-*-helvetica-medium-r-normal-*-18-*-*-*-*-*-*-*"); ;
gtk_box_pack_start (GTK_BOX (temp_container), temp_widget, 0, 0, 8);
gtk_widget_show (temp_widget);
}
/* set up the widgetry for the overview page */
static void setup_overview_form(NautilusHardwareView *view)
{
char *file_name, *temp_text;
GtkWidget *temp_widget, *temp_box;
GtkWidget *container_box;
/* 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, "Hardware Overview");
/* allocate a horizontal box */
container_box = gtk_hbox_new(FALSE, 0);
gtk_box_pack_start (GTK_BOX (view->details->form), container_box, 0, 0, 2);
gtk_widget_show (GTK_WIDGET(container_box));
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);
file_name = gnome_pixmap_file ("nautilus/cpu.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);
temp_text = get_CPU_description();
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);
/* set up the memory info */
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);
file_name = gnome_pixmap_file ("nautilus/memory_chip.gif");
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);
temp_text = get_RAM_description();
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);
}
/* set up the widgetry for the CPU page */
static void setup_CPU_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);