summaryrefslogtreecommitdiff
path: root/components/sample/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'components/sample/main.c')
-rw-r--r--components/sample/main.c91
1 files changed, 60 insertions, 31 deletions
diff --git a/components/sample/main.c b/components/sample/main.c
index 763a8f628..c92d9a336 100644
--- a/components/sample/main.c
+++ b/components/sample/main.c
@@ -1,4 +1,5 @@
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+
/*
* Copyright (C) 2000 Eazel, Inc
*
@@ -17,25 +18,34 @@
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
- * Author: Maciej Stachowiak
+ * Author: Maciej Stachowiak <mjs@eazel.com>
*/
-/* main.c - main function and object activation function for sample
- content view component. */
+/* main.c - Main function and object activation function for sample
+ * view component.
+ */
#include <config.h>
+#include <stdlib.h>
+#include <gtk/gtkmain.h>
+#include <libgnome/gnome-defs.h> /* must come before gnome-init.h */
+#include <libgnomeui/gnome-init.h> /* must come before liboaf.h */
+#include <liboaf/liboaf.h>
+#include <bonobo/bonobo-generic-factory.h>
+#include <bonobo/bonobo-main.h>
#include "nautilus-sample-content-view.h"
-#include <gnome.h>
-#include <liboaf/liboaf.h>
-#include <bonobo.h>
+#define FACTORY_IID "OAFIID:nautilus_sample_content_view_factory:3df6b028-be44-4a18-95c3-7720f50ca0c5"
+#define VIEW_IID "OAFIID:nautilus_sample_content_view:45c746bc-7d64-4346-90d5-6410463b43ae"
static int object_count = 0;
static void
-sample_object_destroyed(GtkObject *obj)
+sample_object_destroyed (GtkObject *object)
{
+ g_assert (GTK_IS_OBJECT (object));
+
object_count--;
if (object_count <= 0) {
gtk_main_quit ();
@@ -45,47 +55,66 @@ sample_object_destroyed(GtkObject *obj)
static BonoboObject *
sample_make_object (BonoboGenericFactory *factory,
const char *iid,
- void *closure)
+ gpointer callback_data)
{
- NautilusSampleContentView *view;
- NautilusView *nautilus_view;
+ NautilusSampleContentView *widget;
+ NautilusView *view;
- if (strcmp (iid, "OAFIID:nautilus_sample_content_view:45c746bc-7d64-4346-90d5-6410463b43ae")) {
+ g_assert (BONOBO_IS_GENERIC_FACTORY (factory));
+ g_assert (iid != NULL);
+ g_assert (callback_data == NULL);
+
+ /* Check that this is the one type of object we know how to
+ * create.
+ */
+ if (strcmp (iid, VIEW_IID) != 0) {
return NULL;
}
- view = NAUTILUS_SAMPLE_CONTENT_VIEW (gtk_object_new (NAUTILUS_TYPE_SAMPLE_CONTENT_VIEW, NULL));
-
+ /* Create the view. The way this sample is set up, we create a
+ * widget which makes the NautilusView object as part of it's
+ * initialization. This is a bit backwards as it's the view
+ * that owns the widget.
+ */
+ widget = NAUTILUS_SAMPLE_CONTENT_VIEW (gtk_object_new (NAUTILUS_TYPE_SAMPLE_CONTENT_VIEW, NULL));
+ view = nautilus_sample_content_view_get_nautilus_view (widget);
+
+ /* Connect a handler that will get us out of the main loop
+ * when there are no more objects outstanding.
+ */
object_count++;
+ gtk_signal_connect (GTK_OBJECT (view), "destroy",
+ sample_object_destroyed, NULL);
- nautilus_view = nautilus_sample_content_view_get_nautilus_view (view);
-
- gtk_signal_connect (GTK_OBJECT (nautilus_view), "destroy", sample_object_destroyed, NULL);
-
- return BONOBO_OBJECT (nautilus_view);
+ return BONOBO_OBJECT (view);
}
-int main(int argc, char *argv[])
+int
+main (int argc, char *argv[])
{
- BonoboGenericFactory *factory;
CORBA_ORB orb;
- CORBA_Environment ev;
-
- CORBA_exception_init(&ev);
-
- gnome_init_with_popt_table("nautilus-sample-content-view", VERSION,
- argc, argv,
- oaf_popt_options, 0, NULL);
+ BonoboGenericFactory *factory;
+ /* Initialize libraries. */
+ gnome_init_with_popt_table ("nautilus-sample-content-view", VERSION,
+ argc, argv,
+ oaf_popt_options, 0, NULL);
orb = oaf_init (argc, argv);
-
bonobo_init (orb, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL);
- factory = bonobo_generic_factory_new_multi ("OAFIID:nautilus_sample_content_view_factory:3df6b028-be44-4a18-95c3-7720f50ca0c5", sample_make_object, NULL);
-
+ /* Create the factory. */
+ factory = bonobo_generic_factory_new_multi (FACTORY_IID, sample_make_object, NULL);
+
+ /* Loop until we have no more objects. */
do {
bonobo_main ();
} while (object_count > 0);
+
+ /* Let the factory go. */
+ bonobo_object_unref (BONOBO_OBJECT (factory));
+
+ /* Finalize libraries. */
+ bonobo_shutdown ();
- return 0;
+ return EXIT_SUCCESS;
}