nautilus-adapter-embeddable-embed-strategy.c 5.64 KB
Newer Older
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
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
161
162
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */

/*
 * Nautilus
 *
 * Copyright (C) 2000 Eazel, Inc.
 *
 * Nautilus 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.
 *
 * Nautilus 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; see the file COPYING.  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-adapter-embeddable-embed-strategy.c - 
 */


#include <config.h>

#include "nautilus-adapter-embeddable-embed-strategy.h"
#include "nautilus-adapter-embed-strategy-private.h"

#include <gtk/gtkobject.h>
#include <libnautilus-extensions/nautilus-gtk-macros.h>
#include <libnautilus/nautilus-view.h>
#include <bonobo.h>

struct NautilusAdapterEmbeddableEmbedStrategyDetails {
	BonoboObjectClient *embeddable_wrapper;
	BonoboContainer    *container;
      	BonoboClientSite   *client_site;
	BonoboViewFrame    *view_frame;
	GtkWidget          *client_widget;
};


static void nautilus_adapter_embeddable_embed_strategy_initialize_class (NautilusAdapterEmbeddableEmbedStrategyClass *klass);
static void nautilus_adapter_embeddable_embed_strategy_initialize       (NautilusAdapterEmbeddableEmbedStrategy      *strategy);
static void nautilus_adapter_embeddable_embed_strategy_destroy          (GtkObject                              *object);

static GtkWidget *nautilus_adapter_embeddable_embed_strategy_get_widget (NautilusAdapterEmbedStrategy *strategy);


NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusAdapterEmbeddableEmbedStrategy, nautilus_adapter_embeddable_embed_strategy, NAUTILUS_TYPE_ADAPTER_EMBED_STRATEGY)


static void
nautilus_adapter_embeddable_embed_strategy_initialize_class (NautilusAdapterEmbeddableEmbedStrategyClass *klass)
{
	GtkObjectClass                    *object_class;
	NautilusAdapterEmbedStrategyClass *adapter_embed_strategy_class;

	object_class = GTK_OBJECT_CLASS (klass);

	object_class->destroy = nautilus_adapter_embeddable_embed_strategy_destroy;

	adapter_embed_strategy_class = NAUTILUS_ADAPTER_EMBED_STRATEGY_CLASS (klass);

	adapter_embed_strategy_class->get_widget = nautilus_adapter_embeddable_embed_strategy_get_widget;
}

static void
nautilus_adapter_embeddable_embed_strategy_initialize (NautilusAdapterEmbeddableEmbedStrategy *strategy)
{
	strategy->details = g_new0 (NautilusAdapterEmbeddableEmbedStrategyDetails, 1);
}

static void
nautilus_adapter_embeddable_embed_strategy_destroy (GtkObject *object)
{
	NautilusAdapterEmbeddableEmbedStrategy *strategy;

	strategy = NAUTILUS_ADAPTER_EMBEDDABLE_EMBED_STRATEGY (object);

 	if (strategy->details->embeddable_wrapper != NULL) {
		bonobo_object_unref (BONOBO_OBJECT (strategy->details->embeddable_wrapper));
	}
 	if (strategy->details->view_frame != NULL) {
		bonobo_object_unref (BONOBO_OBJECT (strategy->details->view_frame));
	}
 	if (strategy->details->client_site != NULL) {
		bonobo_object_unref (BONOBO_OBJECT (strategy->details->client_site));
	}
 	if (strategy->details->container != NULL) {
		bonobo_object_unref (BONOBO_OBJECT (strategy->details->container));
	}

	g_free (strategy->details);

	NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
}


static void
activate_uri_callback (BonoboControlFrame *frame,
		       const char *uri, 
		       gboolean relative,
		       NautilusAdapterEmbeddableEmbedStrategy *strategy)
{
	/* FIXME: ignoring `relative' parameter as the concept is kind
           of broken. */

	nautilus_adapter_embed_strategy_emit_open_location (NAUTILUS_ADAPTER_EMBED_STRATEGY (strategy), 
							    uri);
}


NautilusAdapterEmbedStrategy *
nautilus_adapter_embeddable_embed_strategy_new (Bonobo_Embeddable  embeddable,
						Bonobo_UIHandler   uih)
{
	NautilusAdapterEmbeddableEmbedStrategy *strategy;

	strategy = NAUTILUS_ADAPTER_EMBEDDABLE_EMBED_STRATEGY (gtk_type_new (NAUTILUS_TYPE_ADAPTER_EMBEDDABLE_EMBED_STRATEGY));

	strategy->details->embeddable_wrapper = bonobo_object_client_from_corba (embeddable);

	strategy->details->container = bonobo_container_new ();
      	strategy->details->client_site = bonobo_client_site_new (strategy->details->container);

	bonobo_client_site_bind_embeddable (strategy->details->client_site, strategy->details->embeddable_wrapper);
	bonobo_container_add (strategy->details->container, BONOBO_OBJECT (strategy->details->client_site));

	strategy->details->view_frame = bonobo_client_site_new_view (strategy->details->client_site, uih);
	strategy->details->client_widget = bonobo_view_frame_get_wrapper (strategy->details->view_frame);

     	bonobo_wrapper_set_visibility (BONOBO_WRAPPER (strategy->details->client_widget), FALSE);
	bonobo_view_frame_set_covered (strategy->details->view_frame, FALSE); 

	gtk_signal_connect (GTK_OBJECT (strategy->details->view_frame),
			    "activate_uri", GTK_SIGNAL_FUNC (activate_uri_callback), strategy);

	gtk_widget_show (strategy->details->client_widget);

	return NAUTILUS_ADAPTER_EMBED_STRATEGY (strategy);
}


static GtkWidget *
nautilus_adapter_embeddable_embed_strategy_get_widget (NautilusAdapterEmbedStrategy *abstract_strategy)
{
	NautilusAdapterEmbeddableEmbedStrategy *strategy;

	strategy = NAUTILUS_ADAPTER_EMBEDDABLE_EMBED_STRATEGY (abstract_strategy);
	return strategy->details->client_widget;
}