Commit 06a87807 authored by J Shane Culpepper's avatar J Shane Culpepper
Browse files

Moving the inventory view to its new home to make way for the new

        * components/services/inventory/lib/Makefile.am:
        * components/services/inventory/lib/eazel-inventory-shared.c:
        (add_package_info), (read_proc_info), (add_info), (add_io_info),
        (add_hardware_info), (synchronize_configuration_metafile),
        (update_configuration_metafile), (create_configuration_metafile):
        * components/services/inventory/lib/eazel-inventory-shared.h:
        * components/services/inventory/nautilus-view/Makefile.am:
        *
        components/services/inventory/nautilus-view/nautilus-inventory-view
        .c: (generate_inventory_form), (gather_config_button_cb),
        (register_later_cb), (make_http_post_request), (go_to_uri),
        (get_home_uri), (update_now):

        Moving the inventory view to its new home to make way for the new
        bootstrap startup view.
parent f06ef2ca
2000-07-01 J Shane Culpepper <pepper@eazel.com>
* components/services/inventory/lib/Makefile.am:
* components/services/inventory/lib/eazel-inventory-shared.c:
(add_package_info), (read_proc_info), (add_info), (add_io_info),
(add_hardware_info), (synchronize_configuration_metafile),
(update_configuration_metafile), (create_configuration_metafile):
* components/services/inventory/lib/eazel-inventory-shared.h:
* components/services/inventory/nautilus-view/Makefile.am:
*
components/services/inventory/nautilus-view/nautilus-inventory-view
.c: (generate_inventory_form), (gather_config_button_cb),
(register_later_cb), (make_http_post_request), (go_to_uri),
(get_home_uri), (update_now):
Moving the inventory view to its new home to make way for the new
bootstrap startup view.
2000-07-01 J Shane Culpepper <pepper@eazel.com>
* components/services/inventory/nautilus-view/Makefile.am:
......
......@@ -10,13 +10,19 @@ INCLUDES = \
-I$(top_srcdir) \
-I$(top_builddir) \
-I$(top_srcdir)/components/services/trilobite \
-I/usr/include/rpm \
$(GNOME_CFLAGS) \
$(GCONF_CFLAGS) \
$(GHTTP_CFLAGS) \
$(WERROR) \
$(NULL)
noinst_LIBRARIES = libinventory_corba.a
noinst_LIBRARIES = libinventory.a libinventory_corba.a
libinventory_a_SOURCES = \
eazel-inventory-shared.h \
eazel-inventory-shared.c \
$(NULL)
## CORBA magic
......
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* Nautilus
* 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 <andy@eazel.com>
* J Shane Culpepper <pepper@eazel.com>
*
* The code responsible for the client inventory manipulation.
*
*/
#include <config.h>
#include <gdk/gdk.h>
#include <stdio.h>
#include <fcntl.h>
#include <time.h>
#include <unistd.h>
#include <rpm/rpmlib.h>
#include <gnome.h>
#include <gnome-xml/entities.h>
#include <gnome-xml/parser.h>
#include <gnome-xml/tree.h>
#include <libnautilus-extensions/nautilus-string.h>
#include "eazel-inventory-shared.h"
void add_package_info (xmlDocPtr configuration_metafile);
void add_hardware_info (xmlDocPtr configuration_metafile);
char *read_proc_info (const char *proc_filename);
void add_info (xmlNodePtr node_ptr,
char *data,
const char *tag,
const char *field_name);
void add_io_info (xmlNodePtr node_ptr,
char *io_data);
/* add package data from the package database to the passed in xml document */
void
add_package_info (xmlDocPtr configuration_metafile) {
char package_count_str[32];
char *package_name;
char *package_version;
char *package_release;
char *version_str;
xmlNodePtr packages_node;
xmlNodePtr current_package_node;
rpmdb rpm_db;
int current_offset;
int rpm_result;
int package_count;
package_count = 0;
/* open the rpm database for package lookups */
rpmReadConfigFiles (NULL, NULL);
rpm_result = rpmdbOpen ("", &rpm_db, O_RDONLY, 0644);
if (rpm_result != 0) {
g_message ("couldn't open package database: %d", rpm_result);
return;
}
/* add the PACKAGES node */
packages_node = xmlNewChild (configuration_metafile->root, NULL, "PACKAGES", NULL);
/* iterate through all of the installed packages */
current_offset = rpmdbFirstRecNum (rpm_db);
while (current_offset)
{
Header current_package = rpmdbGetRecord (rpm_db, current_offset);
headerGetEntry (current_package, RPMTAG_NAME, NULL, (void **) &package_name, NULL);
headerGetEntry (current_package, RPMTAG_VERSION, NULL, (void **) &package_version, NULL);
headerGetEntry(current_package, RPMTAG_RELEASE, NULL, (void **) &package_release, NULL);
/* add a node for this package */
current_package_node = xmlNewChild (packages_node, NULL, "PACKAGE", NULL);
package_count += 1;
version_str = g_strdup_printf ("%s-%s", package_version, package_release);
xmlSetProp (current_package_node, "name", package_name);
xmlSetProp (current_package_node, "version", version_str);
g_free (version_str);
headerFree (current_package);
current_offset = rpmdbNextRecNum (rpm_db, current_offset);
/* donate some time to gtk to handle updates, etc */
while (gtk_events_pending()) {
gtk_main_iteration();
}
}
/* update the count */
sprintf (package_count_str, "%d", package_count);
xmlSetProp (packages_node, "count", package_count_str);
/* close the package data base */
rpmdbClose (rpm_db);
}
/* utility routine to read a proc file into a string */
char*
read_proc_info (const char *proc_filename) {
FILE *thisFile;
char *result;
char buffer[256];
char *path_name;
GString *string_data;
path_name = g_strdup_printf ("/proc/%s", proc_filename);
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 */
void
add_info (xmlNodePtr node_ptr, char *data, const char *tag, const char *field_name) {
int index;
char **info_array;
char *field_data;
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) {
xmlNodePtr new_node;
new_node = xmlNewChild (node_ptr, NULL, tag, NULL);
xmlNodeSetContent (new_node, field_data);
}
g_strfreev (info_array);
}
/* utility routine to process io info */
void
add_io_info (xmlNodePtr node_ptr, char *io_data) {
int index;
char *temp_str;
xmlNodePtr new_node;
char **info_array;
/* parse the data into a string array */
info_array = g_strsplit (io_data, "\n", 64);
/* iterate through the data creating a record for each line */
for (index = 0; index < 64; index++) {
if (info_array[index] == NULL)
break;
new_node = xmlNewChild (node_ptr, NULL, "IORANGE", NULL);
temp_str = strchr (info_array[index], ':');
if (temp_str) {
*temp_str = '\0';
xmlSetProp (new_node, "RANGE", g_strstrip (info_array[index]));
xmlSetProp (new_node, "TYPE", g_strstrip (temp_str + 1));
}
}
g_strfreev (info_array);
}
/* add hardware info from the /proc directory to the passed in xml document */
void
add_hardware_info (xmlDocPtr configuration_metafile) {
xmlNodePtr cpu_node;
xmlNodePtr this_node;
xmlNodePtr hardware_node;
char *temp_string;
/* add the HARDWARE node */
hardware_node = xmlNewChild (configuration_metafile->root, NULL, "HARDWARE", NULL);
/* capture various information from the /proc filesystem */
/* first, capture memory info */
temp_string = read_proc_info ("meminfo");
add_info (hardware_node, temp_string, "MEMORYSIZE", "MemTotal");
add_info (hardware_node, temp_string, "SWAPSIZE", "SwapTotal");
g_free (temp_string);
/* now handle CPU info */
cpu_node = xmlNewChild (hardware_node, NULL, "CPU", NULL);
temp_string = read_proc_info ("cpuinfo");
add_info (cpu_node, temp_string, "TYPE", "processor");
add_info (cpu_node, temp_string, "VENDOR", "vendor_id");
add_info (cpu_node, temp_string, "FAMILY", "cpu family");
add_info (cpu_node, temp_string, "MODEL", "model");
add_info (cpu_node, temp_string, "MODELNAME", "model name");
add_info (cpu_node, temp_string, "STEPPING", "stepping");
add_info (cpu_node, temp_string, "SPEED", "cpu MHz");
add_info (cpu_node, temp_string, "CACHE", "cache size");
g_free (temp_string);
/* now handle IO port info */
this_node = xmlNewChild (hardware_node, NULL, "IOPORTS", NULL);
temp_string = read_proc_info ("ioports");
add_io_info (this_node, temp_string);
g_free (temp_string);
}
/* synchronize an existing metafile with the rpm database */
xmlDocPtr
synchronize_configuration_metafile () {
return NULL;
}
/* update_package_metafile is called during initialization time to create or
synchronize the packages metafile */
xmlDocPtr
update_configuration_metafile () {
return NULL;
}
/* create the configuration metafile and add package and hardware configuration info to it */
xmlDocPtr
create_configuration_metafile (void) {
/* create a new xml document */
time_t current_time;
xmlNodePtr container_node;
char *time_string;
char host_name[512];
xmlDocPtr configuration_metafile;
configuration_metafile = xmlNewDoc ("1.0");
gethostname (&host_name[0], 511);
container_node = xmlNewDocNode (configuration_metafile, NULL, "CONFIGURATION", NULL);
configuration_metafile->root = container_node;
time (&current_time);
time_string = g_strdup (ctime (&current_time));
time_string[strlen(time_string) - 1] = '\0';
xmlSetProp (container_node, "computer", host_name);
xmlSetProp (container_node, "date", time_string);
g_free (time_string);
/* FIXME bugzilla.eazel.com 732: need to set up nautilus version here */
/* add the package info */
add_package_info (configuration_metafile);
/* add the hardware info */
add_hardware_info (configuration_metafile);
return configuration_metafile;
}
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* Nautilus
* 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
*
* Authors: Andy Hertzfeld <andy@eazel.com>
* J Shane Culpepper <pepper@eazel.com>
*
* This is the header file for the service inventory stuff
*
*/
#ifndef EAZEL_INVENTORY_SHARED_H
#define EAZEL_INVENTORY_SHARED_H
#include <gnome-xml/entities.h>
#include <gnome-xml/parser.h>
#include <gnome-xml/tree.h>
xmlDocPtr create_configuration_metafile (void);
xmlDocPtr synchronize_configuration_metafile (void);
xmlDocPtr update_configuration_metafile (void);
#endif /* EAZEL_INVENTORY_SHARED_H */
......@@ -33,19 +33,20 @@ nautilus_inventory_view_SOURCES = \
main.c \
$(NULL)
nautilus_inventory_view_LDFLAGS = \
nautilus_inventory_view_LDADD = \
$(top_builddir)/components/services/inventory/lib/libinventory_corba.a \
$(top_builddir)/components/services/trilobite/libtrilobite/libtrilobite.la \
$(top_builddir)/libnautilus/libnautilus.la \
$(top_builddir)/libnautilus/libnautilus.la \
$(top_builddir)/libnautilus-extensions/libnautilus-extensions.la \
$(top_builddir)/cut-n-paste-code/widgets/e-paned/libe-paned.la \
$(top_builddir)/librsvg/librsvg.la \
$(BONOBO_LIBS) \
$(GNOMEUI_LIBS) \
$(GCONF_LIBS) \
$(VFS_LIBS) \
$(GHTTP_LIBS) \
$(OAF_LIBS) \
$(top_builddir)/cut-n-paste-code/widgets/e-paned/libe-paned.la \
$(top_builddir)/librsvg/librsvg.la \
$(BONOBO_LIBS) \
$(GNOMEUI_LIBS) \
$(GCONF_LIBS) \
$(VFS_LIBS) \
$(GHTTP_LIBS) \
$(OAF_LIBS) \
$(top_builddir)/components/services/inventory/lib/libinventory.a \
$(NULL)
EXTRA_DIST = $(oaf_DATA)
......@@ -23,6 +23,7 @@
#include <config.h>
#include <ghttp.h>
#include <gnome-xml/tree.h>
#include <libgnomevfs/gnome-vfs-utils.h>
#include <libnautilus-extensions/nautilus-background.h>
......@@ -37,57 +38,59 @@
#include <unistd.h>
#include "nautilus-inventory-view.h"
#include "eazel-inventory-shared.h"
/* A NautilusContentView's private information. */
struct _NautilusInventoryViewDetails {
char *uri;
char *auth_token;
NautilusView *nautilus_view;
GtkWidget *form;
GtkWidget *form_title;
GtkWidget *account_name;
GtkWidget *account_password;
GtkWidget *confirm_password;
GtkWidget *inventory_button;
GtkWidget *maintenance_button;
GtkWidget *feedback_text;
};
#define SERVICE_VIEW_DEFAULT_BACKGROUND_COLOR "rgb:BBBB/DDDD/FFFF"
#define SERVICE_DOMAIN_NAME "eazel24.eazel.com"
static void nautilus_inventory_view_initialize_class (NautilusInventoryViewClass *klass);
static void nautilus_inventory_view_initialize (NautilusInventoryView *view);
static void nautilus_inventory_view_destroy (GtkObject *object);
static void inventory_load_location_callback (NautilusView *nautilus_view,
const char *location,
NautilusInventoryView *view);
static void show_feedback (NautilusInventoryView *view,
char *error_message);
static void generate_inventory_form (NautilusInventoryView *view);
static void entry_changed_cb (GtkWidget *entry,
NautilusInventoryView *view);
static void inventory_button_cb (GtkWidget *button,
NautilusInventoryView *view);
static void maintenance_button_cb (GtkWidget *button,
NautilusInventoryView *view);
static void generate_form_title (NautilusInventoryView *view,
const char *title_text);
static void nautilus_inventory_view_initialize_class (NautilusInventoryViewClass *klass);
static void nautilus_inventory_view_initialize (NautilusInventoryView *view);
static void nautilus_inventory_view_destroy (GtkObject *object);
static void inventory_load_location_callback (NautilusView *nautilus_view,
const char *location,
NautilusInventoryView *view);
static void show_feedback (NautilusInventoryView *view,
char *error_message);
static void generate_inventory_form (NautilusInventoryView *view);
static void gather_config_button_cb (GtkWidget *button,
NautilusInventoryView *view);
static void register_later_cb (GtkWidget *button,
NautilusInventoryView *view);
static void go_to_uri (NautilusInventoryView *view,
char *uri);
static char *get_home_uri (void);
static void update_now (void);
static ghttp_request *make_http_post_request (char *uri,
char *post_body,
char *auth_token);
static void generate_form_title (NautilusInventoryView *view,
const char *title_text);
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusInventoryView, nautilus_inventory_view, GTK_TYPE_EVENT_BOX)
static void
generate_inventory_form (NautilusInventoryView *view) {
GtkTable *table;
char *message;
char *file_name;
GtkWidget *temp_widget;
GtkWidget *temp_box;
GtkWidget *inventory_label;
GtkWidget *maintenance_button;
GtkWidget *maintenance_label;
GtkWidget *config_button;
GtkWidget *config_label;
/* allocate a box to hold everything */
/* allocate a vbox as a container */
view->details->form = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (view), view->details->form);
gtk_widget_show (view->details->form);
......@@ -95,123 +98,172 @@ generate_inventory_form (NautilusInventoryView *view) {
/* setup the title */
generate_form_title (view, "Eazel Services Inventory");
/* initialize the parent form */
/* if we came from signup, add a congrats message */
/* FIXME bugzilla.eazel.com 727: get the text from a file or from the service */
if (nautilus_str_has_suffix (view->details->uri, "signup")) {
message = "Congratulations, you have successfully signed up with the Eazel service!";
temp_widget = gtk_label_new (message);
gtk_box_pack_start (GTK_BOX (view->details->form), temp_widget, 0, 0, 12);
gtk_widget_show (temp_widget);
}
/* make label containing text about uploading the configuration data */
/* FIXME bugzilla.eazel.com 727: It should get this text from a file or from the service */
temp_box = gtk_hbox_new (FALSE, 4);
gtk_box_pack_start (GTK_BOX (view->details->form), temp_box, 0, 0, 12);
gtk_widget_show (temp_box);
/* allocate a table to hold the inventory form */
table = GTK_TABLE (gtk_table_new (2, 2, FALSE));
/* username */
temp_widget = gtk_label_new ("User Name: ");
gtk_misc_set_alignment (GTK_MISC (temp_widget), 1.0, 0.5);
gtk_table_attach (table, temp_widget, 0,1, 0,1, GTK_FILL, GTK_FILL, 2,2);
gtk_widget_show (temp_widget);
view->details->account_name = gtk_entry_new_with_max_length (36);
gtk_table_attach (table, view->details->account_name, 1, 2, 0, 1, GTK_FILL, GTK_FILL, 4,4);
gtk_widget_show (view->details->account_name);
/* password */
temp_widget = gtk_label_new ("Password: ");
gtk_misc_set_alignment (GTK_MISC (temp_widget), 1.0, 0.5);
gtk_table_attach (table, temp_widget, 0,1, 1,2, GTK_FILL, GTK_FILL, 2,2);
file_name = nautilus_pixmap_file ("config-gather.png");
temp_widget = GTK_WIDGET (gnome_pixmap_new_from_file (file_name));
gtk_box_pack_start (GTK_BOX (temp_box), temp_widget, 0, 0, 8);
gtk_widget_show (temp_widget);
view->details->account_password = gtk_entry_new_with_max_length (36);
gtk_table_attach (table, view->details->account_password, 1, 2, 1, 2, GTK_FILL, GTK_FILL, 4,4);
gtk_entry_set_visibility (GTK_ENTRY (view->details->account_password), FALSE);
gtk_widget_show (view->details->account_password);
/* insert the table */
gtk_box_pack_start (GTK_BOX (view->details->form), GTK_WIDGET(table), 0, 0, 4);
gtk_widget_show (GTK_WIDGET(table));
/* attach a changed signal to the 2 entry fields, so we can enable the button when something is typed into both fields */
gtk_signal_connect (GTK_OBJECT (view->details->account_name), "changed", GTK_SIGNAL_FUNC (entry_changed_cb), view);
gtk_signal_connect (GTK_OBJECT (view->details->account_password), "changed", GTK_SIGNAL_FUNC (entry_changed_cb), view);
g_free (file_name);
/* allocate the command buttons - first the inventory button */
message = "With your permission, the Eazel service will gather data about the hardware and software configuration of your system so it can provide you with a customized software catalog with one-click installation. Your configuration data will be kept strictly confidential and will not be used for any other purpose. Click the button below to begin gathering the data.";
temp_widget = gtk_label_new (message);
gtk_label_set_line_wrap (GTK_LABEL(temp_widget), TRUE);
gtk_box_pack_start (GTK_BOX (temp_box), temp_widget, 0, 0, 12);
gtk_widget_show (temp_widget);
view->details->inventory_button = gtk_button_new ();
inventory_label = gtk_label_new (" Login to Eazel ");
gtk_widget_show (inventory_label);
gtk_container_add (GTK_CONTAINER (view->details->inventory_button), inventory_label);
/* add buttons for accepting and declining */
config_button = gtk_button_new ();
config_label = gtk_label_new (" Gather Configuration Data ");
gtk_widget_show (config_label);
gtk_container_add (GTK_CONTAINER (config_button), config_label);
temp_box = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (temp_box), view->details->inventory_button, FALSE, FALSE, 21);
gtk_box_pack_start (GTK_BOX (temp_box), config_button, FALSE, FALSE, 16);
gtk_signal_connect (GTK_OBJECT (view->details->inventory_button),
"clicked",
GTK_SIGNAL_FUNC (inventory_button_cb), view);