nautilus-adapter-factory-server.c 5.46 KB
Newer Older
Maciej Stachowiak's avatar
Maciej Stachowiak committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/* -*- 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>
 */

Maciej Stachowiak's avatar
Maciej Stachowiak committed
24
25
/* nautilus-adapter-factory-server.c - Server object for a factory to
 * create NautilusAdapter objects.
Maciej Stachowiak's avatar
Maciej Stachowiak committed
26
27
28
29
30
 */

#include <config.h>
#include "nautilus-adapter-factory-server.h"

Darin Adler's avatar
Darin Adler committed
31
#include "nautilus-adapter.h"
Maciej Stachowiak's avatar
Maciej Stachowiak committed
32
33
34
#include <bonobo/bonobo-control.h>
#include <bonobo/bonobo-main.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
Darin Adler's avatar
Darin Adler committed
35
#include <gtk/gtksignal.h>
Maciej Stachowiak's avatar
Maciej Stachowiak committed
36
#include <libgnome/gnome-i18n.h>
37
#include <libgnomeui/gnome-stock-icons.h>
Maciej Stachowiak's avatar
Maciej Stachowiak committed
38
#include <libnautilus-adapter/nautilus-adapter-factory.h>
Ramiro Estrugo's avatar
Ramiro Estrugo committed
39
#include <eel/eel-gtk-macros.h>
Darin Adler's avatar
Darin Adler committed
40
#include <libnautilus/nautilus-bonobo-ui.h>
Maciej Stachowiak's avatar
Maciej Stachowiak committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

static Nautilus_View
impl_Nautilus_ComponentAdapterFactory_create_adapter (PortableServer_Servant           servant,
						      const Bonobo_Unknown             component,
						      CORBA_Environment               *ev);

static void
impl_Nautilus_ComponentAdapterFactory__destroy       (BonoboObject                    *object, 
						      PortableServer_Servant           servant);

static Nautilus_ComponentAdapterFactory
impl_Nautilus_ComponentAdapterFactory__create        (NautilusAdapterFactoryServer    *bonobo_object,
						      CORBA_Environment               *ev);


56
57
static void nautilus_adapter_factory_server_class_init (NautilusAdapterFactoryServerClass *klass);
static void nautilus_adapter_factory_server_init       (NautilusAdapterFactoryServer      *server);
Maciej Stachowiak's avatar
Maciej Stachowiak committed
58
59
60
static void nautilus_adapter_factory_server_destroy          (GtkObject                      *object);


61
EEL_CLASS_BOILERPLATE (NautilusAdapterFactoryServer,
62
63
		       nautilus_adapter_factory_server,
		       BONOBO_OBJECT_TYPE)
Maciej Stachowiak's avatar
Maciej Stachowiak committed
64
65
     
static void
66
nautilus_adapter_factory_server_class_init (NautilusAdapterFactoryServerClass *klass)
Maciej Stachowiak's avatar
Maciej Stachowiak committed
67
68
69
70
71
72
73
74
75
76
77
{
	GtkObjectClass *object_class;
	
	g_assert (NAUTILUS_IS_ADAPTER_FACTORY_SERVER_CLASS (klass));

	object_class = GTK_OBJECT_CLASS (klass);
	
	object_class->destroy = nautilus_adapter_factory_server_destroy;
}

static void
78
nautilus_adapter_factory_server_init (NautilusAdapterFactoryServer *server)
Maciej Stachowiak's avatar
Maciej Stachowiak committed
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
{
	CORBA_Environment ev;

	CORBA_exception_init (&ev);
	
	g_assert (NAUTILUS_IS_ADAPTER_FACTORY_SERVER (server));

	bonobo_object_construct
		(BONOBO_OBJECT (server),
		 impl_Nautilus_ComponentAdapterFactory__create (server, &ev));
	
	CORBA_exception_free (&ev);
}

static void
nautilus_adapter_factory_server_destroy (GtkObject *object)
{
Ramiro Estrugo's avatar
Ramiro Estrugo committed
96
	EEL_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
Maciej Stachowiak's avatar
Maciej Stachowiak committed
97
98
}

Maciej Stachowiak's avatar
Maciej Stachowiak committed
99
100
101
102
103
104
static void
adapter_object_destroyed (GtkObject *adapter, NautilusAdapterFactoryServer *server)
{
	bonobo_object_unref (BONOBO_OBJECT (server));
}

Maciej Stachowiak's avatar
Maciej Stachowiak committed
105
106
107
108
109
110

static Nautilus_View
impl_Nautilus_ComponentAdapterFactory_create_adapter (PortableServer_Servant  servant,
						      const Bonobo_Unknown    component,
						      CORBA_Environment      *ev)
{
Maciej Stachowiak's avatar
Maciej Stachowiak committed
111
112
	impl_POA_Nautilus_ComponentAdapterFactory *factory_servant;
	NautilusAdapter *adapter;
113
	NautilusView *adapter_view;
Maciej Stachowiak's avatar
Maciej Stachowiak committed
114
115
116
117
118
119
120
121
122

	factory_servant = (impl_POA_Nautilus_ComponentAdapterFactory *) servant;

	adapter = nautilus_adapter_new (component);

	if (adapter == NULL) {
		return CORBA_OBJECT_NIL;
	} else {
		bonobo_object_ref (BONOBO_OBJECT (factory_servant->bonobo_object));
123
124

		adapter_view = nautilus_adapter_get_nautilus_view (adapter);
Maciej Stachowiak's avatar
Maciej Stachowiak committed
125
		
126
		g_signal_connect (adapter_view, "destroy",
Maciej Stachowiak's avatar
Maciej Stachowiak committed
127
128
				    adapter_object_destroyed, factory_servant->bonobo_object);

129
130
		return CORBA_Object_duplicate
			(bonobo_object_corba_objref (BONOBO_OBJECT (adapter_view)), ev);
Maciej Stachowiak's avatar
Maciej Stachowiak committed
131
	}
Maciej Stachowiak's avatar
Maciej Stachowiak committed
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
}

static void
impl_Nautilus_ComponentAdapterFactory__destroy (BonoboObject           *object, 
						PortableServer_Servant  servant)
{
	PortableServer_ObjectId *object_id;
	CORBA_Environment ev;
	
	CORBA_exception_init (&ev);
	
	object_id = PortableServer_POA_servant_to_id (bonobo_poa (), servant, &ev);
	PortableServer_POA_deactivate_object (bonobo_poa (), object_id, &ev);
	CORBA_free (object_id);

	object->servant = NULL;
	
	POA_Nautilus_ComponentAdapterFactory__fini (servant, &ev);
	g_free (servant);

	CORBA_exception_free (&ev);
}

static Nautilus_ComponentAdapterFactory
impl_Nautilus_ComponentAdapterFactory__create (NautilusAdapterFactoryServer *bonobo_object,
					       CORBA_Environment            *ev)
{
	impl_POA_Nautilus_ComponentAdapterFactory *servant;
	
Darin Adler's avatar
Darin Adler committed
161
	impl_Nautilus_ComponentAdapterFactory_vepv.Bonobo_Unknown_epv = nautilus_bonobo_object_get_epv ();
Maciej Stachowiak's avatar
Maciej Stachowiak committed
162
163
164
165
166

	servant = g_new0 (impl_POA_Nautilus_ComponentAdapterFactory, 1);
	servant->servant.vepv = &impl_Nautilus_ComponentAdapterFactory_vepv;
	POA_Nautilus_ComponentAdapterFactory__init ((PortableServer_Servant) servant, ev);

167
	g_signal_connect (bonobo_object, "destroy",
168
			    G_CALLBACK (impl_Nautilus_ComponentAdapterFactory__destroy), servant);
Maciej Stachowiak's avatar
Maciej Stachowiak committed
169
170
171
172
	
	servant->bonobo_object = bonobo_object;
	return bonobo_object_activate_servant (BONOBO_OBJECT (bonobo_object), servant);
}