Commit 605184fa authored by Maciej Stachowiak's avatar Maciej Stachowiak

Completed bugzilla task 763, Test component needed for failure

	cases. Two new components called "Content Loser" and "Sidebar
	Loser" will fail on startup based on environment variables or in
	response to menu or toolbar items (Darin suggested using silly
	names, though not these specific ones).

	* components/loser/README: Some docs on making the new components
	fail.

	* components/loser/content/main.c,
	components/loser/content/nautilus-content-loser.c,
	components/loser/content/nautilus-content-loser.h: New content
	view which fails on demand.
	* components/loser/content/nautilus-content-loser.oafinfo: oaf
	activation record for it.

	* components/loser/sidebar/main.c,
	components/loser/sidebar/nautilus-sidebar-loser.c,
	components/loser/sidebar/nautilus-sidebar-loser.h: New sidebar
	panel that fails on demand.
	* components/loser/sidebar/nautilus-sidebar-loser.oafinfo: oaf
	activation record for it.

	* components/Makefile.am, components/loser/Makefile.am,
	components/loser/content/Makefile.am,
	components/loser/sidebar/Makefile.am, configure.in: Added loser
	components to build.

	* nautilus-clean.sh: Added loser components to nautilus-clean.sh
parent ec50954e
2000-05-22 Maciej Stachowiak <mjs@eazel.com>
Completed bugzilla task 763, Test component needed for failure
cases. Two new components called "Content Loser" and "Sidebar
Loser" will fail on startup based on environment variables or in
response to menu or toolbar items (Darin suggested using silly
names, though not these specific ones).
* components/loser/README: Some docs on making the new components
fail.
* components/loser/content/main.c,
components/loser/content/nautilus-content-loser.c,
components/loser/content/nautilus-content-loser.h: New content
view which fails on demand.
* components/loser/content/nautilus-content-loser.oafinfo: oaf
activation record for it.
* components/loser/sidebar/main.c,
components/loser/sidebar/nautilus-sidebar-loser.c,
components/loser/sidebar/nautilus-sidebar-loser.h: New sidebar
panel that fails on demand.
* components/loser/sidebar/nautilus-sidebar-loser.oafinfo: oaf
activation record for it.
* components/Makefile.am, components/loser/Makefile.am,
components/loser/content/Makefile.am,
components/loser/sidebar/Makefile.am, configure.in: Added loser
components to build.
* nautilus-clean.sh: Added loser components to nautilus-clean.sh
2000-05-22 J Shane Culpepper <pepper@eazel.com>
* components/services/install/lib/eazel-install-rpm-glue.c:
......
......@@ -17,6 +17,7 @@ SUBDIRS = \
help \
history \
html \
loser \
music \
notes \
$(RPMVIEW_COMPONENT_SUBDIRS) \
......
NULL=
SUBDIRS =\
content sidebar\
$(NULL)
EXTRA_DIST=\
README \
$(NULL)
To make the content and sidebar "loser" components fail, you must set
some environment variables.
To pick where the component will fail, set either
NAUTILUS_CONTENT_LOSER_PLACE or NAUTILUS_SIDEBAR_LOSER_PLACE to one of
the following values:
pre-init
post-init
post-factory-init
pre-make-object
post-make-object
pre-underway
pre-load
pre-done
post-done
pre-merge
post-merge
Also set either NAUTILUS_CONTENT_LOSER_MODE or
NAUTILUS_SIDEBAR_LOSER_MODE to one of:
hang
exit
error-exit
CPPFLAGS = \
-DPREFIX=\"$(prefix)\"
-DG_LOG_DOMAIN=\"Nautilus-Test\"
INCLUDES = \
-I$(top_srcdir) \
-I$(top_builddir) \
$(GCONF_CFLAGS) \
$(GNOMEUI_CFLAGS) \
$(WERROR)
oafdir = $(datadir)/oaf
oaf_DATA = \
nautilus-content-loser.oafinfo
bin_PROGRAMS = \
nautilus-content-loser
nautilus_content_loser_SOURCES = \
nautilus-content-loser.h \
nautilus-content-loser.c \
main.c
nautilus_content_loser_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 \
$(GNOMEUI_LIBS) \
$(BONOBO_LIBS) \
$(GCONF_LIBS) \
$(VFS_LIBS) \
$(OAF_LIBS)
EXTRA_DIST = $(oaf_DATA)
<oaf_info>
<oaf_server iid="OAFIID:nautilus_content_loser_factory:adf30e75-3b63-4360-8784-a8e239390a69" type="exe" location="nautilus-content-loser">
<oaf_attribute name="repo_ids" type="stringv">
<item value="IDL:GNOME/GenericFactory:1.0"/>
</oaf_attribute>
<oaf_attribute name="name" type="string" value="Nautilus content loser factory"/>
<oaf_attribute name="description" type="string" value="Nautilus content loser component's factory"/>
</oaf_server>
<oaf_server iid="OAFIID:nautilus_content_loser:95901458-c68b-43aa-aaca-870ced11062d" type="factory" location="OAFIID:nautilus_content_loser_factory:adf30e75-3b63-4360-8784-a8e239390a69">
<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="name" type="string" value="Nautilus Content Loser"/>
<oaf_attribute name="description" type="string" value="Nautilus content view that fails on command"/>
<oaf_attribute name="bonobo:supported_uri_schemes" type="stringv">
<item value="*"/>
</oaf_attribute>
<oaf_attribute name="nautilus:view_as_name" type="string" value="Content Loser"/>
</oaf_server>
</oaf_info>
<oaf_info>
<oaf_server iid="OAFIID:nautilus_content_loser_factory:adf30e75-3b63-4360-8784-a8e239390a69" type="exe" location="nautilus-content-loser">
<oaf_attribute name="repo_ids" type="stringv">
<item value="IDL:GNOME/GenericFactory:1.0"/>
</oaf_attribute>
<oaf_attribute name="name" type="string" value="Nautilus content loser factory"/>
<oaf_attribute name="description" type="string" value="Nautilus content loser component's factory"/>
</oaf_server>
<oaf_server iid="OAFIID:nautilus_content_loser:95901458-c68b-43aa-aaca-870ced11062d" type="factory" location="OAFIID:nautilus_content_loser_factory:adf30e75-3b63-4360-8784-a8e239390a69">
<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="name" type="string" value="Nautilus Content Loser"/>
<oaf_attribute name="description" type="string" value="Nautilus content view that fails on command"/>
<oaf_attribute name="bonobo:supported_uri_schemes" type="stringv">
<item value="*"/>
</oaf_attribute>
<oaf_attribute name="nautilus:view_as_name" type="string" value="Content Loser"/>
</oaf_server>
</oaf_info>
<oaf_info>
<oaf_server iid="OAFIID:nautilus_content_loser_factory:adf30e75-3b63-4360-8784-a8e239390a69" type="exe" location="nautilus-content-loser">
<oaf_attribute name="repo_ids" type="stringv">
<item value="IDL:GNOME/GenericFactory:1.0"/>
</oaf_attribute>
<oaf_attribute name="name" type="string" value="Nautilus content loser factory"/>
<oaf_attribute name="description" type="string" value="Nautilus content loser component's factory"/>
</oaf_server>
<oaf_server iid="OAFIID:nautilus_content_loser:95901458-c68b-43aa-aaca-870ced11062d" type="factory" location="OAFIID:nautilus_content_loser_factory:adf30e75-3b63-4360-8784-a8e239390a69">
<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="name" type="string" value="Nautilus Content Loser"/>
<oaf_attribute name="description" type="string" value="Nautilus content view that fails on command"/>
<oaf_attribute name="bonobo:supported_uri_schemes" type="stringv">
<item value="*"/>
</oaf_attribute>
<oaf_attribute name="nautilus:view_as_name" type="string" value="Content Loser"/>
</oaf_server>
</oaf_info>
/* -*- 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: Maciej Stachowiak
*/
/* main.c - main function and object activation function for loser
content view component that fails on command. */
#include <config.h>
#include "nautilus-content-loser.h"
#include <gnome.h>
#include <liboaf/liboaf.h>
#include <bonobo.h>
static int object_count = 0;
static void
loser_object_destroyed(GtkObject *obj)
{
object_count--;
if (object_count <= 0) {
gtk_main_quit ();
}
}
static BonoboObject *
loser_make_object (BonoboGenericFactory *factory,
const char *iid,
void *closure)
{
NautilusContentLoser *view;
NautilusViewFrame *view_frame;
nautilus_content_loser_maybe_fail ("pre-make-object");
puts ("Checking IID!");
if (strcmp (iid, "OAFIID:nautilus_content_loser:95901458-c68b-43aa-aaca-870ced11062d")) {
return NULL;
}
puts ("Trying to make object!");
view = NAUTILUS_CONTENT_LOSER (gtk_object_new (NAUTILUS_TYPE_CONTENT_LOSER, NULL));
object_count++;
view_frame = NAUTILUS_VIEW_FRAME (nautilus_content_loser_get_view_frame (view));
gtk_signal_connect (GTK_OBJECT (view_frame), "destroy", loser_object_destroyed, NULL);
nautilus_content_loser_maybe_fail ("post-make-object");
return BONOBO_OBJECT (view_frame);
}
int main(int argc, char *argv[])
{
BonoboGenericFactory *factory;
CORBA_ORB orb;
CORBA_Environment ev;
CORBA_exception_init(&ev);
puts ("In component.");
nautilus_content_loser_maybe_fail ("pre-init");
gnome_init_with_popt_table("nautilus-content-loser", VERSION,
argc, argv,
oaf_popt_options, 0, NULL);
orb = oaf_init (argc, argv);
bonobo_init (orb, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL);
nautilus_content_loser_maybe_fail ("post-init");
factory = bonobo_generic_factory_new_multi ("OAFIID:nautilus_content_loser_factory:adf30e75-3b63-4360-8784-a8e239390a69", loser_make_object, NULL);
nautilus_content_loser_maybe_fail ("post-factory-init");
puts ("About to do main loop.");
do {
bonobo_main ();
} while (object_count > 0);
return 0;
}
/* -*- 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: Maciej Stachowiak <mjs@eazel.com>
*/
/* nautilus-content-loser.c - loser content view component. This
component fails on demand, either controlled by env variables
during startup, or using toolbar buttons or menu items. */
#include <config.h>
#include "nautilus-content-loser.h"
#include <bonobo/bonobo-control.h>
#include <gtk/gtksignal.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <libgnome/gnome-i18n.h>
#include <libgnomeui/gnome-stock.h>
#include <libnautilus/nautilus-bonobo-ui.h>
#include <libnautilus-extensions/nautilus-gtk-macros.h>
#include <stdio.h>
#include <stdlib.h>
/* A NautilusContentViewFrame's private information. */
struct NautilusContentLoserDetails {
char *uri;
NautilusContentViewFrame *view_frame;
};
static void nautilus_content_loser_initialize_class (NautilusContentLoserClass *klass);
static void nautilus_content_loser_initialize (NautilusContentLoser *view);
static void nautilus_content_loser_destroy (GtkObject *object);
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusContentLoser, nautilus_content_loser, GTK_TYPE_LABEL)
static void loser_notify_location_change_callback (NautilusContentViewFrame *view_frame,
Nautilus_NavigationInfo *navinfo,
NautilusContentLoser *view);
static void loser_merge_bonobo_items_callback (BonoboObject *control,
gboolean state,
gpointer user_data);
static void nautilus_content_loser_fail (void);
static void ensure_fail_env (void);
static void
nautilus_content_loser_initialize_class (NautilusContentLoserClass *klass)
{
GtkObjectClass *object_class;
object_class = GTK_OBJECT_CLASS (klass);
object_class->destroy = nautilus_content_loser_destroy;
}
static void
nautilus_content_loser_initialize (NautilusContentLoser *view)
{
view->details = g_new0 (NautilusContentLoserDetails, 1);
gtk_label_set_text (GTK_LABEL (view), g_strdup ("(none)"));
view->details->view_frame = nautilus_content_view_frame_new (GTK_WIDGET (view));
gtk_signal_connect (GTK_OBJECT (view->details->view_frame),
"notify_location_change",
GTK_SIGNAL_FUNC (loser_notify_location_change_callback),
view);
/*
* Get notified when our bonobo control is activated so we
* can merge menu & toolbar items into Nautilus's UI.
*/
gtk_signal_connect (GTK_OBJECT (nautilus_view_frame_get_bonobo_control
(NAUTILUS_VIEW_FRAME (view->details->view_frame))),
"activate",
loser_merge_bonobo_items_callback,
view);
gtk_widget_show (GTK_WIDGET (view));
}
static void
nautilus_content_loser_destroy (GtkObject *object)
{
NautilusContentLoser *view;
view = NAUTILUS_CONTENT_LOSER (object);
bonobo_object_unref (BONOBO_OBJECT (view->details->view_frame));
g_free (view->details->uri);
g_free (view->details);
NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
}
/**
* nautilus_content_loser_get_view_frame:
*
* Return the NautilusViewFrame object associated with this view; this
* is needed to export the view via CORBA/Bonobo.
* @view: NautilusContentLoser to get the view_frame from..
*
**/
NautilusContentViewFrame *
nautilus_content_loser_get_view_frame (NautilusContentLoser *view)
{
return view->details->view_frame;
}
/**
* nautilus_content_loser_load_uri:
*
* Load the resource pointed to by the specified URI.
* @view: NautilusContentLoser to get the view_frame from.
*
**/
void
nautilus_content_loser_load_uri (NautilusContentLoser *view,
const char *uri)
{
char *label_text;
g_free (view->details->uri);
view->details->uri = g_strdup (uri);
label_text = g_strdup_printf (_("%s\n\nThis is a Nautilus content view that fails on demand."), uri);
gtk_label_set_text (GTK_LABEL (view), label_text);
g_free (label_text);
}
static void
loser_notify_location_change_callback (NautilusContentViewFrame *view_frame,
Nautilus_NavigationInfo *navinfo,
NautilusContentLoser *view)
{
Nautilus_ProgressRequestInfo request;
g_assert (view_frame == view->details->view_frame);
memset(&request, 0, sizeof(request));
nautilus_content_loser_maybe_fail ("pre-underway");
/*
* It's mandatory to send a PROGRESS_UNDERWAY message once the
* component starts loading, otherwise nautilus will assume it
* failed. In a real component, this will probably happen in
* some sort of callback from whatever loading mechanism it is
* using to load the data; this component loads no data, so it
* gives the progrss update here.
*/
request.type = Nautilus_PROGRESS_UNDERWAY;
request.amount = 0.0;
nautilus_view_frame_request_progress_change (NAUTILUS_VIEW_FRAME (view_frame), &request);
nautilus_content_loser_maybe_fail ("pre-load");
/* Do the actual load. */
nautilus_content_loser_load_uri (view, navinfo->actual_uri);
/*
* It's mandatory to send a PROGRESS_DONE_OK message once the
* component is done loading successfully, or
* PROGRESS_DONE_ERROR if it completes unsuccessfully. In a
* real component, this will probably happen in some sort of
* callback from whatever loading mechanism it is using to
* load the data; this component loads no data, so it gives
* the progrss upodate here.
*/
nautilus_content_loser_maybe_fail ("pre-done");
request.type = Nautilus_PROGRESS_DONE_OK;
request.amount = 100.0;
nautilus_view_frame_request_progress_change (NAUTILUS_VIEW_FRAME (view_frame), &request);
nautilus_content_loser_maybe_fail ("post-done");
}
static void
bonobo_loser_callback (BonoboUIHandler *ui_handler, gpointer user_data, const char *path)
{
NautilusContentLoser *view;
char *label_text;
g_assert (NAUTILUS_IS_CONTENT_LOSER (user_data));
view = NAUTILUS_CONTENT_LOSER (user_data);
if (strcmp (path, "/File/Kill Content View") == 0) {
label_text = g_strdup_printf ("%s\n\nYou selected the Kill Content View menu item.", view->details->uri);
nautilus_content_loser_fail ();
} else {
g_assert (strcmp (path, "/Main/Kill Content View") == 0);
label_text = g_strdup_printf (_("%s\n\nYou clicked the Kill Content View toolbar button."), view->details->uri);
nautilus_content_loser_fail ();
}
gtk_label_set_text (GTK_LABEL (view), label_text);
g_free (label_text);
}
static void
loser_merge_bonobo_items_callback (BonoboObject *control, gboolean state, gpointer user_data)
{
NautilusContentLoser *view;
BonoboUIHandler *local_ui_handler;
GdkPixbuf *pixbuf;
BonoboUIHandlerPixmapType pixmap_type;
char *path;
nautilus_content_loser_maybe_fail ("pre-merge");
g_assert (NAUTILUS_IS_CONTENT_LOSER (user_data));
view = NAUTILUS_CONTENT_LOSER (user_data);
local_ui_handler = bonobo_control_get_ui_handler (BONOBO_CONTROL (control));
if (state) {
/* Tell the Nautilus window to merge our bonobo_ui_handler items with its ones */
bonobo_ui_handler_set_container (local_ui_handler,
bonobo_control_get_remote_ui_handler (BONOBO_CONTROL (control)));
/* Load test pixbuf */
pixbuf = gdk_pixbuf_new_from_file ("/gnome/share/pixmaps/nautilus/i-directory-24.png");
if (pixbuf != NULL)
pixmap_type = BONOBO_UI_HANDLER_PIXMAP_PIXBUF_DATA;
else
pixmap_type = BONOBO_UI_HANDLER_PIXMAP_NONE;
/* Create our loser menu item. */
path = bonobo_ui_handler_build_path (NULL,
"File",
"Kill Content View",
NULL);
bonobo_ui_handler_menu_new_item
(local_ui_handler, /* BonoboUIHandler */
path, /* menu item path, must start with /some-existing-menu-path and be otherwise unique */
_("_Kill Content View"), /* menu item user-displayed label */
_("Kill the Loser content view"), /* hint that appears in status bar */
bonobo_ui_handler_menu_get_pos
(local_ui_handler,
NAUTILUS_MENU_PATH_NEW_WINDOW_ITEM) + 1, /* position within menu; -1 means last */
pixmap_type, /* pixmap type */
pixbuf, /* pixmap data */
'M', /* accelerator key, couldn't bear the thought of using Control-S for anything except Save */
GDK_CONTROL_MASK, /* accelerator key modifiers */
bonobo_loser_callback, /* callback function */
view); /* callback function data */
g_free (path);
/* Create our loser toolbar button. */
path = bonobo_ui_handler_build_path (NAUTILUS_TOOLBAR_PATH_MAIN_TOOLBAR,
"Kill Content View",
NULL);
bonobo_ui_handler_toolbar_new_item
(local_ui_handler, /* BonoboUIHandler */
path, /* button path, must start with /some-existing-toolbar-path and be otherwise unique */
_("Kill Content View"), /* button user-displayed label */
_("Kill the Loser content view."), /* hint that appears in status bar */
-1, /* position, -1 means last */
pixmap_type, /* pixmap type */
pixbuf, /* pixmap data */
0, /* accelerator key */
0, /* accelerator key modifiers */
bonobo_loser_callback, /* callback function */
view); /* callback function's data */
g_free (path);
} else {
/* Do nothing. */
}
nautilus_content_loser_maybe_fail ("post-merge");
/*
* Note that we do nothing if state is FALSE. Nautilus content views are activated
* when installed, but never explicitly deactivated. When the view changes to another,
* the content view object is destroyed, which ends up calling bonobo_ui_handler_unset_container,
* which removes its merged menu & toolbar items.
*/
}
static char *failure_mode = NULL;
static char *failure_point = NULL;
static gboolean env_checked = FALSE;
void
nautilus_content_loser_maybe_fail (const char *location)
{
ensure_fail_env ();
if (strcasecmp (location, failure_point) == 0) {
nautilus_content_loser_fail ();
}
}