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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* Nautilus
*
* Copyright (C) 1999, 2000 Red Hat, Inc.
*
* This library 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 library 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 library; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Author: Elliot Lee <sopwith@redhat.com>
*
*/
/* ntl-view.c: Implementation of the object representing a data view,
and its associated CORBA object for proxying requests into this
object. */
#include <gtk/gtksignal.h>
#include <gtk/gtk.h>
#include "nautilus.h"
#include "ntl-view-private.h"
enum {
REQUEST_LOCATION_CHANGE,
REQUEST_SELECTION_CHANGE,
REQUEST_STATUS_CHANGE,
REQUEST_PROGRESS_CHANGE,
LAST_SIGNAL
};
enum {
ARG_0,
ARG_MAIN_WINDOW
};
static void nautilus_view_init (NautilusView *view);
static void nautilus_view_destroy (GtkObject *view);
static void nautilus_view_constructed(NautilusView *view);
static void nautilus_view_class_init (NautilusViewClass *klass);
static void nautilus_view_set_arg (GtkObject *object,
GtkArg *arg,
guint arg_id);
static void nautilus_view_get_arg (GtkObject *object,
GtkArg *arg,
guint arg_id);
static void nautilus_view_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void nautilus_view_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static guint nautilus_view_signals[LAST_SIGNAL];
GtkType
nautilus_view_get_type (void)
{
static GtkType view_type = 0;
if (!view_type) {
const GtkTypeInfo view_info = {
"NautilusView",
sizeof (NautilusView),
sizeof (NautilusViewClass),
(GtkClassInitFunc) nautilus_view_class_init,
(GtkObjectInitFunc) nautilus_view_init,
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL,
};
view_type = gtk_type_unique (gtk_bin_get_type(), &view_info);
}
return view_type;
}
#if 0
typedef void (*GtkSignal_NONE__BOXED_OBJECT_BOXED) (GtkObject * object,
gpointer arg1,
GtkObject *arg2,
gpointer arg3,
gpointer user_data);
static void
gtk_marshal_NONE__BOXED_OBJECT_BOXED (GtkObject * object,
GtkSignalFunc func,
gpointer func_data,
GtkArg * args)
{
GtkSignal_NONE__BOXED_OBJECT_BOXED rfunc;
rfunc = (GtkSignal_NONE__BOXED_OBJECT_BOXED) func;
(*rfunc) (object,
GTK_VALUE_BOXED (args[0]),
GTK_VALUE_OBJECT (args[1]),
GTK_VALUE_BOXED (args[2]),
func_data);
}
#endif
static void
nautilus_view_class_init (NautilusViewClass *klass)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
object_class = (GtkObjectClass*) klass;
object_class->destroy = nautilus_view_destroy;
object_class->set_arg = nautilus_view_set_arg;
object_class->get_arg = nautilus_view_get_arg;
widget_class = (GtkWidgetClass*) klass;
widget_class->size_request = nautilus_view_size_request;
widget_class->size_allocate = nautilus_view_size_allocate;
klass->servant_init_func = POA_Nautilus_ViewFrame__init;
klass->servant_destroy_func = POA_Nautilus_ViewFrame__fini;
klass->vepv = &impl_Nautilus_ViewFrame_vepv;
klass->parent_class = gtk_type_class (gtk_type_parent (object_class->type));
/* klass->request_location_change = NULL; */
/* klass->request_selection_change = NULL; */
/* klass->request_status_change = NULL; */
/* klass->request_progress_change = NULL; */
klass->view_constructed = nautilus_view_constructed;
nautilus_view_signals[REQUEST_LOCATION_CHANGE] = gtk_signal_new("request_location_change",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (NautilusViewClass,
request_location_change),
gtk_marshal_NONE__BOXED,
GTK_TYPE_NONE, 1, GTK_TYPE_BOXED);
nautilus_view_signals[REQUEST_SELECTION_CHANGE] = gtk_signal_new("request_selection_change",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (NautilusViewClass,
request_selection_change),
gtk_marshal_NONE__BOXED,
GTK_TYPE_NONE, 1, GTK_TYPE_BOXED);
nautilus_view_signals[REQUEST_STATUS_CHANGE] = gtk_signal_new("request_status_change",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (NautilusViewClass,
request_status_change),
gtk_marshal_NONE__BOXED,
GTK_TYPE_NONE, 1, GTK_TYPE_BOXED);
nautilus_view_signals[REQUEST_PROGRESS_CHANGE] = gtk_signal_new("request_progress_change",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (NautilusViewClass,
request_progress_change),
gtk_marshal_NONE__BOXED,
GTK_TYPE_NONE, 1, GTK_TYPE_BOXED);
gtk_object_class_add_signals (object_class, nautilus_view_signals, LAST_SIGNAL);
gtk_object_add_arg_type ("NautilusView::main_window",
GTK_TYPE_OBJECT,
GTK_ARG_READWRITE,
ARG_MAIN_WINDOW);
klass->num_construct_args++;
}
static void
nautilus_view_set_arg (GtkObject *object,
GtkArg *arg,
guint arg_id)
{
NautilusView *view;
view = NAUTILUS_VIEW(object);
switch(arg_id) {
case ARG_MAIN_WINDOW:
view->main_window = GTK_WIDGET(GTK_VALUE_OBJECT(*arg));
nautilus_view_construct_arg_set(view);
break;
}
}
static void
nautilus_view_get_arg (GtkObject *object,
GtkArg *arg,
guint arg_id)
{
switch(arg_id) {
case ARG_MAIN_WINDOW:
GTK_VALUE_OBJECT(*arg) = GTK_OBJECT(NAUTILUS_VIEW(object)->main_window);
break;
}
}
static void
nautilus_view_init (NautilusView *view)
{
GTK_WIDGET_SET_FLAGS (view, GTK_NO_WINDOW);
}
static void
nautilus_view_destroy_client(NautilusView *view)
{
if(!view->component_class)
return;
g_free(view->iid); view->iid = NULL;
gnome_object_destroy(GNOME_OBJECT(view->client_object)); view->client_object = NULL;
gtk_container_remove(GTK_CONTAINER(view), view->client_widget); view->client_widget = NULL;
if(view->component_class->destroy)
{
CORBA_Environment ev;
CORBA_exception_init(&ev);
view->component_class->destroy(view, &ev);
CORBA_exception_free(&ev);
}
gnome_object_destroy(view->view_frame); view->view_frame = NULL;
view->component_class = NULL;
view->component_data = NULL;
}
static void
nautilus_view_destroy(GtkObject *view)
{
NautilusViewClass *klass = NAUTILUS_VIEW_CLASS(view->klass);
NautilusView *nview = NAUTILUS_VIEW(view);
if(nview->timer_id)
g_source_remove(nview->timer_id);
nautilus_view_destroy_client(nview);
if(GTK_OBJECT_CLASS(klass->parent_class)->destroy)
GTK_OBJECT_CLASS(klass->parent_class)->destroy(view);
}
static void
nautilus_view_constructed(NautilusView *view)
{
}
void
nautilus_view_construct_arg_set(NautilusView *view)
{
guint nca;
NautilusViewClass *klass;
klass = NAUTILUS_VIEW_CLASS(((GtkObject *)view)->klass);
nca = klass->num_construct_args;
if(view->construct_arg_count >= nca)
return;
view->construct_arg_count++;
if((view->construct_arg_count >= nca)
&& klass->view_constructed)
klass->view_constructed(view);
}
static void
nautilus_view_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
GtkBin *bin;
bin = GTK_BIN (widget);
requisition->width = 0;
requisition->height = 0;
if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
{
GtkRequisition child_requisition;
gtk_widget_size_request (bin->child, &child_requisition);
requisition->width += child_requisition.width;
requisition->height += child_requisition.height;
}
}
static void
nautilus_view_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
GtkBin *bin;
GtkAllocation child_allocation;
widget->allocation = child_allocation = *allocation;
bin = GTK_BIN (widget);
if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
gtk_widget_size_allocate (bin->child, &child_allocation);
}
extern NautilusViewComponentType nautilus_view_component_type; /* ntl-view-nautilus.c */
extern NautilusViewComponentType bonobo_subdoc_component_type; /* ntl-view-bonobo-subdoc.c */
extern NautilusViewComponentType bonobo_control_component_type; /* ntl-view-bonobo-control.c */
static gboolean
nautilus_view_handle_client_destroy(GtkWidget *widget, NautilusView *view)
{
gtk_object_destroy(GTK_OBJECT(view));
return TRUE;
}
static void
nautilus_view_handle_client_destroy_2(GtkObject *object, CORBA_Object cobject, CORBA_Environment *ev, NautilusView *view)
{
/* ICK! */
if(NAUTILUS_IS_META_VIEW(view))
nautilus_window_remove_meta_view(NAUTILUS_WINDOW(view->main_window), view);
else if(NAUTILUS_IS_CONTENT_VIEW(view))
nautilus_window_set_content_view(NAUTILUS_WINDOW(view->main_window), NULL);
}
gboolean /* returns TRUE if successful */
nautilus_view_load_client(NautilusView *view, const char *iid)
{
CORBA_Object obj;
CORBA_Environment ev;
int i;
NautilusViewComponentType *component_types[] = {
&nautilus_view_component_type,
&bonobo_subdoc_component_type,
&bonobo_control_component_type,
NULL
};
g_return_val_if_fail(iid, FALSE);
CORBA_exception_init(&ev);
nautilus_view_destroy_client(view);
view->client_object = gnome_object_activate(iid, 0);
if(!view->client_object)
return FALSE;
view->view_frame = impl_Nautilus_ViewFrame__create(view, &ev);
/* Now figure out which type of embedded object it is: */
for(i = 0; component_types[i] && !view->component_class; i++)
{
obj = GNOME_Unknown_query_interface(gnome_object_corba_objref(GNOME_OBJECT(view->client_object)),
component_types[i]->primary_repoid, &ev);
if(ev._major != CORBA_NO_EXCEPTION)
obj = CORBA_OBJECT_NIL;
if(CORBA_Object_is_nil(obj, &ev))
continue;
if(component_types[i]->try_load(view, obj, &ev))
view->component_class = component_types[i];
GNOME_Unknown_unref(obj, &ev);
CORBA_Object_release(obj, &ev);
}
if (!view->component_class)
{
/* Nothing matched */
nautilus_view_destroy_client(view);
return FALSE;
}
view->iid = g_strdup(iid);
gtk_signal_connect_while_alive(GTK_OBJECT(view->client_object), "destroy",
GTK_SIGNAL_FUNC(nautilus_view_handle_client_destroy), view,
GTK_OBJECT(view));
gtk_signal_connect_while_alive(GTK_OBJECT(view->client_object), "object_gone",
GTK_SIGNAL_FUNC(nautilus_view_handle_client_destroy_2), view,
GTK_OBJECT(view));
gtk_signal_connect_while_alive(GTK_OBJECT(view->client_object), "system_exception",
GTK_SIGNAL_FUNC(nautilus_view_handle_client_destroy_2), view,
GTK_OBJECT(view));
gtk_container_add(GTK_CONTAINER(view), view->client_widget);
gtk_widget_show(view->client_widget);
CORBA_exception_free(&ev);
return TRUE;
}
void
nautilus_view_notify_location_change(NautilusView *view,
Nautilus_NavigationInfo *nav_context)
{
Nautilus_NavigationInfo real_nav_ctx;
CORBA_Environment ev;
g_return_if_fail(view);
g_return_if_fail(view->component_class);
real_nav_ctx = *nav_context;
g_assert(real_nav_ctx.requested_uri);
#define DEFAULT_STRING(x) if(!real_nav_ctx.x) real_nav_ctx.x = ""
if(!real_nav_ctx.actual_uri) real_nav_ctx.actual_uri = real_nav_ctx.requested_uri;
DEFAULT_STRING(content_type);
DEFAULT_STRING(referring_uri);
if(!real_nav_ctx.actual_referring_uri) real_nav_ctx.actual_referring_uri = real_nav_ctx.referring_uri;
DEFAULT_STRING(referring_content_type);
CORBA_exception_init(&ev);
if(view->component_class->notify_location_change)
view->component_class->notify_location_change(view, &real_nav_ctx, &ev);
CORBA_exception_free(&ev);
}
void
nautilus_view_notify_selection_change(NautilusView *view,
Nautilus_SelectionInfo *nav_context)
{
CORBA_Environment ev;
g_return_if_fail(view);
g_return_if_fail(view->component_class);
CORBA_exception_init(&ev);
if(view->component_class->notify_selection_change)
view->component_class->notify_selection_change(view, nav_context, &ev);
CORBA_exception_free(&ev);
}
void
nautilus_view_load_state(NautilusView *view, const char *config_path)
{
CORBA_Environment ev;
g_return_if_fail(view);
g_return_if_fail(view->component_class);
CORBA_exception_init(&ev);
if(view->component_class->load_state)
view->component_class->load_state(view, config_path, &ev);
CORBA_exception_free(&ev);
}
void
nautilus_view_save_state(NautilusView *view, const char *config_path)
{
CORBA_Environment ev;
g_return_if_fail(view);
g_return_if_fail(view->component_class);
CORBA_exception_init(&ev);
if(view->component_class->save_state)
view->component_class->save_state(view, config_path, &ev);
CORBA_exception_free(&ev);
}
void
nautilus_view_show_properties(NautilusView *view)
{
CORBA_Environment ev;
g_return_if_fail(view);
g_return_if_fail(view->component_class);
CORBA_exception_init(&ev);
if(view->component_class->show_properties)
view->component_class->show_properties(view, &ev);
CORBA_exception_free(&ev);
}
void
nautilus_view_stop_location_change(NautilusView *view)
{
CORBA_Environment ev;
g_return_if_fail(view);
g_return_if_fail(view->component_class);
CORBA_exception_init(&ev);
if(view->component_class->stop_location_change)
view->component_class->stop_location_change(view, &ev);
CORBA_exception_free(&ev);
}
const char *
nautilus_view_get_iid(NautilusView *view)
{
return view->iid;
}
CORBA_Object
nautilus_view_get_client_objref(NautilusView *view)
{
return view?gnome_object_corba_objref(GNOME_OBJECT(view->client_object)):NULL;
}
CORBA_Object
nautilus_view_get_objref(NautilusView *view)
{
return view?gnome_object_corba_objref(view->view_frame):NULL;
}
void
nautilus_view_request_location_change(NautilusView *view,
Nautilus_NavigationRequestInfo *loc)
{
gtk_signal_emit(GTK_OBJECT(view), nautilus_view_signals[REQUEST_LOCATION_CHANGE], loc);
}
void
nautilus_view_request_selection_change (NautilusView *view,
Nautilus_SelectionRequestInfo *loc)
{
gtk_signal_emit(GTK_OBJECT(view), nautilus_view_signals[REQUEST_SELECTION_CHANGE], loc);
}
void
nautilus_view_request_status_change (NautilusView *view,
Nautilus_StatusRequestInfo *loc)
{
gtk_signal_emit(GTK_OBJECT(view), nautilus_view_signals[REQUEST_STATUS_CHANGE], loc);
}
void
nautilus_view_request_progress_change(NautilusView *view,
Nautilus_ProgressRequestInfo *loc)
{
gtk_signal_emit(GTK_OBJECT(view), nautilus_view_signals[REQUEST_PROGRESS_CHANGE], loc);
}
static gboolean
check_object(NautilusView *view)
{
CORBA_Environment ev;
gboolean retval = TRUE;
CORBA_exception_init(&ev);
if(CORBA_Object_non_existent(gnome_object_corba_objref(GNOME_OBJECT(view->client_object)), &ev))
{
view->timer_id = 0;
gtk_object_destroy(GTK_OBJECT(view));
retval = FALSE;
}
CORBA_exception_free(&ev);
return retval;
}
void
nautilus_view_set_active_errors(NautilusView *view, gboolean enabled)
{
if(enabled)
{
if(!view->timer_id)
view->timer_id = g_timeout_add(1000, (GSourceFunc)check_object, view);
}
else
{
if(view->timer_id)
{
g_source_remove(view->timer_id);
view->timer_id = 0;
}
}
}
|