nautilus-adapter-load-strategy.c 6.68 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
/* -*- 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-load-strategy.h
 */


#include <config.h>

#include "nautilus-adapter-load-strategy.h"
#include "nautilus-adapter-stream-load-strategy.h"
#include "nautilus-adapter-file-load-strategy.h"
#include "nautilus-adapter-progressive-load-strategy.h"

#include <gtk/gtkobject.h>
Ramiro Estrugo's avatar
Ramiro Estrugo committed
39
40
#include <eel/eel-gtk-macros.h>
#include <eel/eel-gtk-extensions.h>
Maciej Stachowiak's avatar
Maciej Stachowiak committed
41
42
43
44
45
46
47
48
49
50
51
52
53



enum {
	REPORT_LOAD_UNDERWAY,
	REPORT_LOAD_PROGRESS,
	REPORT_LOAD_COMPLETE,
	REPORT_LOAD_FAILED,
	LAST_SIGNAL
};

static guint signals[LAST_SIGNAL];

54
55


56
57
static void nautilus_adapter_load_strategy_class_init (NautilusAdapterLoadStrategyClass *klass);
static void nautilus_adapter_load_strategy_init       (NautilusAdapterLoadStrategy      *strategy);
58
59
static void nautilus_adapter_load_strategy_destroy          (GtkObject                        *object);

60
EEL_CLASS_BOILERPLATE (NautilusAdapterLoadStrategy, nautilus_adapter_load_strategy, GTK_TYPE_OBJECT)
61

Ramiro Estrugo's avatar
Ramiro Estrugo committed
62
63
EEL_IMPLEMENT_MUST_OVERRIDE_SIGNAL (nautilus_adapter_load_strategy, load_location)
EEL_IMPLEMENT_MUST_OVERRIDE_SIGNAL (nautilus_adapter_load_strategy, stop_loading)
64
65

static void
66
nautilus_adapter_load_strategy_class_init (NautilusAdapterLoadStrategyClass *klass)
67
68
69
70
71
72
73
{
	GtkObjectClass *object_class;

	object_class = (GtkObjectClass *) klass;

	object_class->destroy = nautilus_adapter_load_strategy_destroy;

Ramiro Estrugo's avatar
Ramiro Estrugo committed
74
75
	EEL_ASSIGN_MUST_OVERRIDE_SIGNAL (klass, nautilus_adapter_load_strategy, load_location);
	EEL_ASSIGN_MUST_OVERRIDE_SIGNAL (klass, nautilus_adapter_load_strategy, stop_loading);
Maciej Stachowiak's avatar
Maciej Stachowiak committed
76
77
78


	signals[REPORT_LOAD_UNDERWAY] =
79
80
81
82
83
		g_signal_new ("report_load_underway",
		              G_TYPE_FROM_CLASS (object_class),
		              G_SIGNAL_RUN_LAST,
		              G_STRUCT_OFFSET (NautilusAdapterLoadStrategyClass, report_load_underway),
		              NULL, NULL,
84
		              gtk_marshal_VOID__VOID,
85
		              G_TYPE_NONE, 0);
Maciej Stachowiak's avatar
Maciej Stachowiak committed
86
	signals[REPORT_LOAD_PROGRESS] =
87
88
89
90
91
		g_signal_new ("report_load_progress",
		              G_TYPE_FROM_CLASS (object_class),
		              G_SIGNAL_RUN_LAST,
		              G_STRUCT_OFFSET (NautilusAdapterLoadStrategyClass, report_load_progress),
		              NULL, NULL,
92
		              eel_marshal_VOID__DOUBLE,
93
		              G_TYPE_NONE, 1, GTK_TYPE_DOUBLE);
Maciej Stachowiak's avatar
Maciej Stachowiak committed
94
	signals[REPORT_LOAD_COMPLETE] =
95
96
97
98
99
		g_signal_new ("report_load_complete",
		              G_TYPE_FROM_CLASS (object_class),
		              G_SIGNAL_RUN_LAST,
		              G_STRUCT_OFFSET (NautilusAdapterLoadStrategyClass, report_load_complete),
		              NULL, NULL,
100
		              gtk_marshal_VOID__VOID,
101
		              G_TYPE_NONE, 0);
Maciej Stachowiak's avatar
Maciej Stachowiak committed
102
	signals[REPORT_LOAD_FAILED] =
103
104
105
106
107
		g_signal_new ("report_load_failed",
		              G_TYPE_FROM_CLASS (object_class),
		              G_SIGNAL_RUN_LAST,
		              G_STRUCT_OFFSET (NautilusAdapterLoadStrategyClass, report_load_failed),
		              NULL, NULL,
108
		              gtk_marshal_VOID__VOID,
109
		              G_TYPE_NONE, 0);
110
111
112
}

static void
113
nautilus_adapter_load_strategy_init (NautilusAdapterLoadStrategy *strategy)
114
115
116
117
118
119
120
121
122
123
124
{

}

static void
nautilus_adapter_load_strategy_destroy (GtkObject *object)
{
	NautilusAdapterLoadStrategy *strategy;

	strategy = NAUTILUS_ADAPTER_LOAD_STRATEGY (object);

Ramiro Estrugo's avatar
Ramiro Estrugo committed
125
	EEL_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
126
127
128
129
130
131
}




NautilusAdapterLoadStrategy *
Maciej Stachowiak's avatar
Maciej Stachowiak committed
132
nautilus_adapter_load_strategy_get (Bonobo_Unknown  component)
133
134
135
136
137
138
139
140
{
	Bonobo_PersistStream persist_stream;
	Bonobo_PersistFile persist_file;
	Bonobo_ProgressiveDataSink progressive_data_sink;
	CORBA_Environment ev;

	CORBA_exception_init (&ev);

141
142
	progressive_data_sink = Bonobo_Unknown_queryInterface (component,
							       "IDL:Bonobo/ProgressiveDataSink:1.0", &ev);
143
144
145
146
147
	

	if (ev._major == CORBA_NO_EXCEPTION && !CORBA_Object_is_nil (progressive_data_sink, &ev)) {
		CORBA_exception_free (&ev);
		
Maciej Stachowiak's avatar
Maciej Stachowiak committed
148
		return nautilus_adapter_progressive_load_strategy_new (progressive_data_sink);
149
150
151
	}


152
153
	persist_stream = Bonobo_Unknown_queryInterface (component,
							"IDL:Bonobo/PersistStream:1.0", &ev);
154
155
156
157
	
	if (ev._major == CORBA_NO_EXCEPTION && !CORBA_Object_is_nil (persist_stream, &ev)) {
		CORBA_exception_free (&ev);
		
Maciej Stachowiak's avatar
Maciej Stachowiak committed
158
		return nautilus_adapter_stream_load_strategy_new (persist_stream);		
159
160
161
	}


162
163
	persist_file = Bonobo_Unknown_queryInterface (component,
						      "IDL:Bonobo/PersistFile:1.0", &ev);
164
165
166
167
	
	if (ev._major == CORBA_NO_EXCEPTION && !CORBA_Object_is_nil (persist_file, &ev)) {
		CORBA_exception_free (&ev);
		
Maciej Stachowiak's avatar
Maciej Stachowiak committed
168
		return nautilus_adapter_file_load_strategy_new (persist_file);		
169
170
171
172
173
174
175
176
177
178
179
180
181
182
	}

	CORBA_exception_free (&ev);

	return NULL;
}


void
nautilus_adapter_load_strategy_load_location (NautilusAdapterLoadStrategy *strategy,
					      const char                  *uri)
{
	g_return_if_fail (NAUTILUS_IS_ADAPTER_LOAD_STRATEGY (strategy));

Ramiro Estrugo's avatar
Ramiro Estrugo committed
183
	EEL_CALL_METHOD (NAUTILUS_ADAPTER_LOAD_STRATEGY_CLASS, strategy,
184
			      load_location, (strategy, uri));
185
186
187
188
189
190
191
192
}

void
nautilus_adapter_load_strategy_stop_loading  (NautilusAdapterLoadStrategy *strategy)
{

	g_return_if_fail (NAUTILUS_IS_ADAPTER_LOAD_STRATEGY (strategy));

Ramiro Estrugo's avatar
Ramiro Estrugo committed
193
	EEL_CALL_METHOD (NAUTILUS_ADAPTER_LOAD_STRATEGY_CLASS, strategy,
194
			      stop_loading, (strategy));
195
}
Maciej Stachowiak's avatar
Maciej Stachowiak committed
196
197
198
199
200
201
202


/* "protected" calls, should only be called by subclasses */

void
nautilus_adapter_load_strategy_report_load_underway  (NautilusAdapterLoadStrategy *strategy)
{
203
204
	g_signal_emit (G_OBJECT (strategy),
			 signals[REPORT_LOAD_UNDERWAY], 0);
Maciej Stachowiak's avatar
Maciej Stachowiak committed
205
206
207
208
209
210
}

void
nautilus_adapter_load_strategy_report_load_progress  (NautilusAdapterLoadStrategy *strategy,
						      double                       fraction_done)
{
211
212
	g_signal_emit (G_OBJECT (strategy),
			 signals[REPORT_LOAD_PROGRESS], 0,
Maciej Stachowiak's avatar
Maciej Stachowiak committed
213
214
215
216
217
218
			 fraction_done);
}

void
nautilus_adapter_load_strategy_report_load_complete  (NautilusAdapterLoadStrategy *strategy)
{
219
220
	g_signal_emit (G_OBJECT (strategy),
			 signals[REPORT_LOAD_COMPLETE], 0);
Maciej Stachowiak's avatar
Maciej Stachowiak committed
221
222
223
224
225
}

void
nautilus_adapter_load_strategy_report_load_failed    (NautilusAdapterLoadStrategy *strategy)
{
226
227
	g_signal_emit (G_OBJECT (strategy),
			 signals[REPORT_LOAD_FAILED], 0);
Maciej Stachowiak's avatar
Maciej Stachowiak committed
228
}