summaryrefslogtreecommitdiff
path: root/components/adapter/main.c
blob: 801c76afc327886bb5409ec4942a9987d15812bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* -*- 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>
 */

/* main.c - Main function and object activation function for component adapter
 */

#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-adapter-factory-server.h"

#include <libnautilus-extensions/nautilus-debug.h>
#include <libgnomevfs/gnome-vfs-init.h>

#define META_FACTORY_IID "OAFIID:nautilus_adapter_factory_generic_factory:8e62e106-807d-4d37-b14a-00dc82ecf88f"


#define FACTORY_OBJECT_IID    "OAFIID:nautilus_adapter_factory:fd24ecfc-0a6e-47ab-bc53-69d7487c6ad4"

static int object_count = 0;

static void
adapter_factory_object_destroyed (GtkObject *object)
{
	g_assert (GTK_IS_OBJECT (object));

	object_count--;
	if (object_count <= 0) {
		gtk_main_quit ();
	}
}

static BonoboObject *
adapter_factory_make_object (BonoboGenericFactory *factory, 
		    const char *iid, 
		    gpointer callback_data)
{
	NautilusAdapterFactoryServer *adapter;

	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, FACTORY_OBJECT_IID) != 0) {
		return 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.
	 */
	adapter = NAUTILUS_ADAPTER_FACTORY_SERVER (gtk_object_new (NAUTILUS_TYPE_ADAPTER_FACTORY_SERVER, NULL));


	/* 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 (adapter), "destroy",
			    adapter_factory_object_destroyed, NULL);

	return BONOBO_OBJECT (adapter);
}

int
main (int argc, char *argv[])
{
	CORBA_ORB orb;
	BonoboGenericFactory *factory;
	char *registration_id;

	if (g_getenv ("NAUTILUS_DEBUG") != NULL) {
		nautilus_make_warnings_and_criticals_stop_in_debugger
			(G_LOG_DOMAIN, g_log_domain_glib, "Gdk", "Gtk", "GnomeVFS", "GnomeUI", "Bonobo", "ORBit", NULL);
	}

	/* Initialize libraries. */
        gnome_init_with_popt_table ("nautilus-adapter", VERSION, 
				    argc, argv,
				    oaf_popt_options, 0, NULL); 
	g_thread_init (NULL);
	orb = oaf_init (argc, argv);
	gnome_vfs_init ();
	bonobo_init (orb, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL);

	/* Create the factory. */

	registration_id = oaf_make_registration_id (META_FACTORY_IID, g_getenv ("DISPLAY"));

	factory = bonobo_generic_factory_new_multi (registration_id, adapter_factory_make_object, NULL);

	g_free (registration_id);
	
	/* Loop until we have no more objects. */
	do {
		bonobo_main ();
	} while (object_count > 0);

	/* Let the factory go. */
	bonobo_object_unref (BONOBO_OBJECT (factory));

	return EXIT_SUCCESS;
}