nautilus-view-frame.c 22.2 KB
Newer Older
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 3 4 5

/*
 *  Nautilus
 *
Elliot Lee's avatar
Elliot Lee committed
6
 *  Copyright (C) 1999, 2000 Red Hat, Inc.
7
 *  Copyright (C) 1999, 2000 Eazel, Inc.
8
 *
9
 *  Nautilus is free software; you can redistribute it and/or
10 11 12 13
 *  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.
 *
14
 *  Nautilus is distributed in the hope that it will be useful,
15 16 17
 *  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.
Elliot Lee's avatar
Elliot Lee committed
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program; if not, write to the Free Software
21
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
Elliot Lee's avatar
Elliot Lee committed
22
 *
23
 *  Author: Elliot Lee <sopwith@redhat.com>
Elliot Lee's avatar
Elliot Lee committed
24 25
 *
 */
26 27 28
/* ntl-view.c: Implementation of the object representing a data view,
   and its associated CORBA object for proxying requests into this
   object. */
Elliot Lee's avatar
Elliot Lee committed
29

30
#include <config.h>
31
#include "nautilus-view-frame-private.h"
32

33
#include "nautilus-application.h"
34
#include "nautilus-history-frame.h"
35
#include "nautilus-window.h"
36
#include <libnautilus-extensions/nautilus-gtk-extensions.h>
37
#include <libnautilus-extensions/nautilus-gtk-macros.h>
Elliot Lee's avatar
Elliot Lee committed
38 39
#include <gtk/gtksignal.h>
#include <gtk/gtk.h>
40
#include <libnautilus-extensions/nautilus-undo-manager.h>
41
#include <libnautilus/nautilus-view.h>
42
#include <libnautilus/nautilus-zoomable.h>
Elliot Lee's avatar
Elliot Lee committed
43 44

enum {
45 46 47 48 49 50 51 52 53
	OPEN_LOCATION,
	OPEN_LOCATION_IN_NEW_WINDOW,
	REPORT_LOCATION_CHANGE,
	REPORT_SELECTION_CHANGE,
	REPORT_STATUS,
	REPORT_LOAD_UNDERWAY,
	REPORT_LOAD_PROGRESS,
	REPORT_LOAD_COMPLETE,
	REPORT_LOAD_FAILED,
54
	TITLE_CHANGED,
55 56 57 58
	ZOOM_LEVEL_CHANGED,
	CLIENT_GONE,
	GET_HISTORY_LIST,
	LAST_SIGNAL
Elliot Lee's avatar
Elliot Lee committed
59 60
};

61 62 63 64
struct NautilusViewFrameDetails {
	char *title;
};

65 66 67
static void nautilus_view_frame_initialize       (NautilusViewFrame      *view);
static void nautilus_view_frame_destroy          (GtkObject              *view);
static void nautilus_view_frame_initialize_class (NautilusViewFrameClass *klass);
68 69

static guint signals[LAST_SIGNAL];
Elliot Lee's avatar
Elliot Lee committed
70

71
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusViewFrame, nautilus_view_frame, NAUTILUS_TYPE_GENEROUS_BIN)
Elliot Lee's avatar
Elliot Lee committed
72 73

static void
74
nautilus_view_frame_initialize_class (NautilusViewFrameClass *klass)
Elliot Lee's avatar
Elliot Lee committed
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
	GtkObjectClass *object_class;
	
	object_class = (GtkObjectClass*) klass;
	object_class->destroy = nautilus_view_frame_destroy;
	
	signals[OPEN_LOCATION] =
		gtk_signal_new ("open_location",
				GTK_RUN_LAST,
				object_class->type,
				GTK_SIGNAL_OFFSET (NautilusViewFrameClass, 
						   open_location),
				gtk_marshal_NONE__STRING,
				GTK_TYPE_NONE, 1, GTK_TYPE_STRING);
	signals[OPEN_LOCATION_IN_NEW_WINDOW] =
		gtk_signal_new ("open_location_in_new_window",
				GTK_RUN_LAST,
				object_class->type,
				GTK_SIGNAL_OFFSET (NautilusViewFrameClass, 
						   open_location_in_new_window),
				gtk_marshal_NONE__STRING,
				GTK_TYPE_NONE, 1, GTK_TYPE_STRING);
	signals[REPORT_LOCATION_CHANGE] =
		gtk_signal_new ("report_location_change",
				GTK_RUN_LAST,
				object_class->type,
				GTK_SIGNAL_OFFSET (NautilusViewFrameClass, 
						   report_location_change),
				gtk_marshal_NONE__STRING,
				GTK_TYPE_NONE, 1, GTK_TYPE_STRING);
	signals[REPORT_SELECTION_CHANGE] =
		gtk_signal_new ("report_selection_change",
				GTK_RUN_LAST,
				object_class->type,
				GTK_SIGNAL_OFFSET (NautilusViewFrameClass, 
						   report_selection_change),
				gtk_marshal_NONE__POINTER,
				GTK_TYPE_NONE, 1, GTK_TYPE_POINTER);
	signals[REPORT_STATUS] =
		gtk_signal_new ("report_status",
				GTK_RUN_LAST,
116
                    object_class->type,
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
				GTK_SIGNAL_OFFSET (NautilusViewFrameClass, 
						   report_status),
				gtk_marshal_NONE__STRING,
				GTK_TYPE_NONE, 1, GTK_TYPE_STRING);
	signals[REPORT_LOAD_UNDERWAY] =
		gtk_signal_new ("report_load_underway",
				GTK_RUN_LAST,
				object_class->type,
				GTK_SIGNAL_OFFSET (NautilusViewFrameClass, 
						   report_load_underway),
				gtk_marshal_NONE__NONE,
				GTK_TYPE_NONE, 0);
	signals[REPORT_LOAD_PROGRESS] =
		gtk_signal_new ("report_load_progress",
				GTK_RUN_LAST,
				object_class->type,
				GTK_SIGNAL_OFFSET (NautilusViewFrameClass, 
						   report_load_progress),
				nautilus_gtk_marshal_NONE__DOUBLE,
				GTK_TYPE_NONE, 1, GTK_TYPE_DOUBLE);
	signals[REPORT_LOAD_COMPLETE] =
		gtk_signal_new ("report_load_complete",
				GTK_RUN_LAST,
				object_class->type,
				GTK_SIGNAL_OFFSET (NautilusViewFrameClass, 
						   report_load_complete),
				gtk_marshal_NONE__NONE,
				GTK_TYPE_NONE, 0);
	signals[REPORT_LOAD_FAILED] =
		gtk_signal_new ("report_load_failed",
				GTK_RUN_LAST,
				object_class->type,
				GTK_SIGNAL_OFFSET (NautilusViewFrameClass, 
						   report_load_failed),
				gtk_marshal_NONE__NONE,
				GTK_TYPE_NONE, 0);
153 154
	signals[TITLE_CHANGED] =
		gtk_signal_new ("title_changed",
155 156 157
				GTK_RUN_LAST,
				object_class->type,
				GTK_SIGNAL_OFFSET (NautilusViewFrameClass, 
158 159 160
						   title_changed),
				gtk_marshal_NONE__NONE,
				GTK_TYPE_NONE, 0);
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
	
	signals[ZOOM_LEVEL_CHANGED] =
		gtk_signal_new ("zoom_level_changed",
				GTK_RUN_LAST,
				object_class->type,
				GTK_SIGNAL_OFFSET (NautilusViewFrameClass, 
						   zoom_level_changed),
				nautilus_gtk_marshal_NONE__DOUBLE,
				GTK_TYPE_NONE, 1, GTK_TYPE_DOUBLE);

	signals[CLIENT_GONE] =
		gtk_signal_new ("client_gone",
				GTK_RUN_LAST,
				object_class->type,
				GTK_SIGNAL_OFFSET (NautilusViewFrameClass, 
						   client_gone),
				gtk_marshal_NONE__NONE,
				GTK_TYPE_NONE, 0);
	
	signals[GET_HISTORY_LIST] =
		gtk_signal_new ("get_history_list",
				GTK_RUN_LAST,
				object_class->type,
				GTK_SIGNAL_OFFSET (NautilusViewFrameClass, 
						   get_history_list),
				nautilus_gtk_marshal_POINTER__NONE,
				GTK_TYPE_POINTER, 0);
	
	gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL);
Elliot Lee's avatar
Elliot Lee committed
190 191 192
}

static void
193
nautilus_view_frame_initialize (NautilusViewFrame *view)
Elliot Lee's avatar
Elliot Lee committed
194
{
195
	GTK_WIDGET_SET_FLAGS (view, GTK_NO_WINDOW);
196 197

	view->details = g_new0 (NautilusViewFrameDetails, 1);
198 199 200
}

static void
201
nautilus_view_frame_destroy_client (NautilusViewFrame *view)
202
{
203 204 205
	CORBA_Environment ev;
	CORBA_exception_init(&ev);
	
206
	if (view->component_class == NULL) {
207 208 209
		return;
	}
	
210
	g_free (view->iid);
211 212 213 214
	view->iid = NULL;
	
	bonobo_object_unref (BONOBO_OBJECT (view->client_object));
	view->client_object = NULL;
215

216 217
	gtk_container_remove (GTK_CONTAINER(view), view->client_widget);
	view->client_widget = NULL;
218

219 220 221 222
	if (!CORBA_Object_is_nil (view->zoomable, &ev)) {
		Bonobo_Unknown_unref (view->zoomable, &ev);
		CORBA_Object_release (view->zoomable, &ev);
	}
223
	view->zoomable = CORBA_OBJECT_NIL;
224

225 226 227 228
	if (view->component_class->destroy != NULL) {
		view->component_class->destroy (view, &ev);
	}
	
229
	bonobo_object_unref (view->view_frame);
230

231 232 233 234 235 236
	view->view_frame = NULL;
	
	view->component_class = NULL;
	view->component_data = NULL;
	
	CORBA_exception_free(&ev);
237 238 239
}

static void
240
nautilus_view_frame_destroy (GtkObject *object)
241
{
242
	NautilusViewFrame *frame;
243

244 245
	frame = NAUTILUS_VIEW_FRAME (object);
	
246
	if (frame->timer_id != 0) {
247 248 249 250 251
		g_source_remove (frame->timer_id);
		frame->timer_id = 0;
	}
	
	nautilus_view_frame_destroy_client (frame);
252 253 254

	g_free (frame->details->title);
	g_free (frame->details);
255 256
	
	NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
257 258
}

259 260 261
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 */
Elliot Lee's avatar
Elliot Lee committed
262

263
static void
264
nautilus_view_frame_handle_client_destroy (GtkWidget *widget, NautilusViewFrame *view)
265
{
266 267
	/* FIXME: Is a destroy really sufficient here? Who does the unref? */
	gtk_object_destroy (GTK_OBJECT (view));
268 269 270
}

static void
271 272 273 274
nautilus_view_frame_handle_client_destroy_2 (GtkObject *object,
					     CORBA_Object cobject,
					     CORBA_Environment *ev,
					     NautilusViewFrame *view)
275
{
276
	gtk_signal_emit (object, signals[CLIENT_GONE]);
277 278 279 280 281 282
}

NautilusViewFrame *
nautilus_view_frame_new (BonoboUIHandler *ui_handler,
                         NautilusUndoManager *undo_manager)
{
283 284 285 286 287 288 289 290
	NautilusViewFrame *view_frame;
	
	view_frame = NAUTILUS_VIEW_FRAME (gtk_object_new (nautilus_view_frame_get_type (), NULL));
	
	view_frame->ui_handler = ui_handler;
	view_frame->undo_manager = undo_manager;
	
	return view_frame;
291 292
}

293
gboolean /* returns TRUE if successful */
294
nautilus_view_frame_load_client (NautilusViewFrame *view, const char *iid)
295
{
296 297 298 299 300 301 302 303 304 305 306 307 308
	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 (NAUTILUS_IS_VIEW_FRAME (view), FALSE);

309 310
	nautilus_view_frame_destroy_client (view);

311
	if (iid == NULL) {
312
		return FALSE;
313
        }
314

315 316
	view->client_object = bonobo_object_activate (iid, 0);
	if (view->client_object == NULL) {
317
		return FALSE;
318 319 320
        }

	CORBA_exception_init (&ev);
321

322
	/* Start with a view frame interface. */
323
	view->view_frame = impl_Nautilus_ViewFrame__create(view, &ev);
324 325

	/* Add a zoomable frame interface. */
326
	view->zoomable_frame = impl_Nautilus_ZoomableFrame__create(view, &ev);
327 328
	bonobo_object_add_interface (BONOBO_OBJECT (view->view_frame), 
	                             BONOBO_OBJECT (view->zoomable_frame));
329 330

	/* Add a history frame interface. */
331 332 333
	view->history_frame = impl_Nautilus_HistoryFrame__create(view, &ev);
	bonobo_object_add_interface (BONOBO_OBJECT (view->view_frame), 
	                             BONOBO_OBJECT (view->history_frame));
334

335
	/* Add an undo context interface. */
336
	nautilus_undo_manager_add_interface
337
        	(view->undo_manager, BONOBO_OBJECT (view->view_frame));
338
	
339 340 341 342 343 344 345 346 347 348 349 350
	/* Get at our client's zoomable interface. */
	view->zoomable = bonobo_object_query_interface
		(BONOBO_OBJECT (view->client_object), 
		 "IDL:Nautilus/Zoomable:1.0");
	
	/* Now figure out which type of embedded object we have so we
	 * can host it appropriately:
	 */
	for (i = 0; component_types[i] != NULL && view->component_class == NULL; i++) {
		obj = Bonobo_Unknown_query_interface
			(bonobo_object_corba_objref (BONOBO_OBJECT (view->client_object)),
			 component_types[i]->primary_repoid, &ev);
351
		if (ev._major != CORBA_NO_EXCEPTION) {
352
        		obj = CORBA_OBJECT_NIL;
353
		}
354
		if (CORBA_Object_is_nil (obj, &ev)) {
355
			continue;
356
		}
357

358
      		if (component_types[i]->try_load (view, obj, &ev)) {
359
        		view->component_class = component_types[i];
360
		}
361 362 363

      		Bonobo_Unknown_unref (obj, &ev);
      		CORBA_Object_release (obj, &ev);
364
    	}
365

366 367 368
	/* Handle case where we don't know how to host this component. */
  	if (view->component_class == NULL) {
      		nautilus_view_frame_destroy_client (view);
369 370
      		return FALSE;
    	}
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
	
	view->iid = g_strdup (iid);

	gtk_signal_connect_while_alive
		(GTK_OBJECT (view->client_object), "destroy",
		 GTK_SIGNAL_FUNC (nautilus_view_frame_handle_client_destroy), view,
		 GTK_OBJECT (view));
	gtk_signal_connect_while_alive
		(GTK_OBJECT (view->client_object), "object_gone",
		 GTK_SIGNAL_FUNC (nautilus_view_frame_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_frame_handle_client_destroy_2), view,
		 GTK_OBJECT (view));
386
	gtk_container_add (GTK_CONTAINER (view), view->client_widget);
387 388
	gtk_widget_show (view->client_widget);
	CORBA_exception_free (&ev);
389

390
	return TRUE;
391
}
Elliot Lee's avatar
Elliot Lee committed
392

393 394 395 396 397 398 399
static void
set_up_for_new_location (NautilusViewFrame *view)
{
	g_free (view->details->title);
	view->details->title = NULL;
}

Maciej Stachowiak's avatar
Maciej Stachowiak committed
400
void
401 402
nautilus_view_frame_load_location (NautilusViewFrame *view,
                                   const char *location)
403
{
404 405 406 407
	CORBA_Environment ev;
	
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
	g_return_if_fail (view->component_class != NULL);
408 409

	set_up_for_new_location (view);
410 411 412 413 414 415 416 417 418
	
	if (view->component_class->load_location == NULL) {
		return;
	}
	
	CORBA_exception_init(&ev);
	/* ORBit does a bad job with Nautilus_URI, so it's not const char *. */
	view->component_class->load_location(view, (Nautilus_URI) location, &ev);
	CORBA_exception_free(&ev);
Elliot Lee's avatar
Elliot Lee committed
419 420
}

Maciej Stachowiak's avatar
Maciej Stachowiak committed
421
void
422
nautilus_view_frame_stop_loading (NautilusViewFrame *view)
Elliot Lee's avatar
Elliot Lee committed
423
{
424 425 426 427 428 429 430 431
	CORBA_Environment ev;
	
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
	g_return_if_fail (view->component_class != NULL);
	
	if (view->component_class->stop_loading == NULL) {
		return;
	}
432

433 434 435
	CORBA_exception_init(&ev);
	view->component_class->stop_loading(view, &ev);
	CORBA_exception_free(&ev);
Elliot Lee's avatar
Elliot Lee committed
436 437
}

Maciej Stachowiak's avatar
Maciej Stachowiak committed
438
void
439 440
nautilus_view_frame_selection_changed (NautilusViewFrame *view,
                                       GList *selection)
Elliot Lee's avatar
Elliot Lee committed
441
{
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
	Nautilus_URIList *uri_list;
	
	CORBA_Environment ev;
	
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
	g_return_if_fail (view->component_class != NULL);
	
	if (view->component_class->selection_changed == NULL) {
		return;
	}
	
	uri_list = nautilus_uri_list_from_g_list (selection);
	
	CORBA_exception_init(&ev);
	view->component_class->selection_changed(view, uri_list, &ev);
	CORBA_exception_free(&ev);
	
	CORBA_free (uri_list);
460
}
461

462
gboolean
463
nautilus_view_frame_is_zoomable (NautilusViewFrame *view)
464
{
465 466 467 468 469 470
	CORBA_Environment ev;
	gboolean is_zoomable;
	
	g_return_val_if_fail (NAUTILUS_IS_VIEW_FRAME (view), FALSE);
	
	CORBA_exception_init (&ev);
471
	is_zoomable = !CORBA_Object_is_nil (view->zoomable, &ev);
472 473 474
	CORBA_exception_free (&ev);
	
	return is_zoomable;
475 476 477
}

gdouble
478
nautilus_view_frame_get_zoom_level (NautilusViewFrame *view)
479
{
480 481 482 483 484 485 486 487 488 489 490 491
	CORBA_Environment ev;
	double level;
	
	g_return_val_if_fail (NAUTILUS_IS_VIEW_FRAME (view), 0);
	
	CORBA_exception_init (&ev);
	
	if (!CORBA_Object_is_nil (view->zoomable, &ev)) {
		level = Nautilus_Zoomable__get_zoom_level (view->zoomable, &ev);
	} else {
		level = 1.0;
	}
492

493 494 495
	CORBA_exception_free (&ev);
	
	return level;
496 497 498
}

void
499
nautilus_view_frame_set_zoom_level (NautilusViewFrame *view,
500
				    double zoom_level)
501
{
502 503 504 505 506 507 508 509 510 511 512 513 514
	CORBA_Environment ev;
	
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
	
	CORBA_exception_init (&ev);
	
	if (!CORBA_Object_is_nil (view->zoomable, &ev)) {
		Nautilus_Zoomable__set_zoom_level (view->zoomable, zoom_level, &ev);
	} else {
		/* do nothing */
	}
	
	CORBA_exception_free (&ev);
515 516 517
}

gdouble
518
nautilus_view_frame_get_min_zoom_level (NautilusViewFrame *view)
519
{
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
	CORBA_Environment ev;
	double level;
	
	g_return_val_if_fail (NAUTILUS_IS_VIEW_FRAME (view), 0);
	
	CORBA_exception_init (&ev);
	
	if (!CORBA_Object_is_nil (view->zoomable, &ev)) {
		level = Nautilus_Zoomable__get_min_zoom_level (view->zoomable, &ev);
	} else {
		level = 1.0;
	}
	
	CORBA_exception_free (&ev);
	
	return level;
536 537
}

538
double
539
nautilus_view_frame_get_max_zoom_level (NautilusViewFrame *view)
540
{
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556
	CORBA_Environment ev;
	double level;
	
	g_return_val_if_fail (NAUTILUS_IS_VIEW_FRAME (view), 0);
	
	CORBA_exception_init (&ev);
	
	if (!CORBA_Object_is_nil (view->zoomable, &ev)) {
		level = Nautilus_Zoomable__get_max_zoom_level (view->zoomable, &ev);
	} else {
		level = 1.0;
	}
	
	CORBA_exception_free (&ev);
	
	return level;
557 558
}

559 560 561
GList *
nautilus_view_frame_get_preferred_zoom_levels (NautilusViewFrame *view)
{
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581
	CORBA_Environment ev;
	GList *levels;
	Nautilus_ZoomLevelList *zoom_levels;
	
	g_return_val_if_fail (NAUTILUS_IS_VIEW_FRAME (view), 0);
	
	CORBA_exception_init (&ev);
	
	if (!CORBA_Object_is_nil (view->zoomable, &ev)) {
		zoom_levels = Nautilus_Zoomable__get_preferred_zoom_levels (view->zoomable, &ev);
		levels = nautilus_g_list_from_ZoomLevelList (zoom_levels);
		CORBA_free (zoom_levels);
		
	} else {
		levels = NULL;
	}
	
	CORBA_exception_free (&ev);
	
	return levels;
582 583
}

584
void
585
nautilus_view_frame_zoom_in (NautilusViewFrame *view)
586
{
587 588 589 590 591 592 593 594 595 596 597 598 599
	CORBA_Environment ev;
	
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
	
	CORBA_exception_init (&ev);
	
	if (!CORBA_Object_is_nil (view->zoomable, &ev)) {
		Nautilus_Zoomable_zoom_in (view->zoomable, &ev);
	} else {
		/* do nothing */
	}
	
	CORBA_exception_free (&ev);
600 601 602
}

void
603
nautilus_view_frame_zoom_out (NautilusViewFrame *view)
604
{
605 606 607 608 609 610 611 612 613 614 615 616 617
	CORBA_Environment ev;
	
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
	
	CORBA_exception_init (&ev);
	
	if (!CORBA_Object_is_nil (view->zoomable, &ev)) {
		Nautilus_Zoomable_zoom_out (view->zoomable, &ev);
	} else {
		/* do nothing */
	}
	
	CORBA_exception_free (&ev);
618 619 620
}

void
621
nautilus_view_frame_zoom_to_fit (NautilusViewFrame *view)
622
{
623 624 625 626 627 628 629 630 631 632 633 634 635
	CORBA_Environment ev;
	
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
	
	CORBA_exception_init (&ev);
	
	if (!CORBA_Object_is_nil (view->zoomable, &ev)) {
		Nautilus_Zoomable_zoom_to_fit (view->zoomable, &ev);
	} else {
		/* do nothing */
	}
	
	CORBA_exception_free (&ev);
636 637
}

638
const char *
639
nautilus_view_frame_get_iid(NautilusViewFrame *view)
640
{
641 642
	g_return_val_if_fail (NAUTILUS_IS_VIEW_FRAME (view), NULL);
	return view->iid;
643 644 645
}

CORBA_Object
646
nautilus_view_frame_get_client_objref (NautilusViewFrame *view)
647
{
648 649
	g_return_val_if_fail (view == NULL || NAUTILUS_IS_VIEW_FRAME (view), CORBA_OBJECT_NIL);
	return view == NULL ? CORBA_OBJECT_NIL : bonobo_object_corba_objref (BONOBO_OBJECT (view->client_object));
650 651 652
}

CORBA_Object
653
nautilus_view_frame_get_objref (NautilusViewFrame *view)
654
{
655 656
	g_return_val_if_fail (view == NULL || NAUTILUS_IS_VIEW_FRAME (view), CORBA_OBJECT_NIL);
	return view == NULL ? CORBA_OBJECT_NIL : bonobo_object_corba_objref (view->view_frame);
657
}
Maciej Stachowiak's avatar
Maciej Stachowiak committed
658

659 660 661 662
void
nautilus_view_frame_open_location (NautilusViewFrame *view,
                                   const char *location)
{
663 664
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
	gtk_signal_emit (GTK_OBJECT (view), signals[OPEN_LOCATION], location);
665 666 667 668 669 670
}

void
nautilus_view_frame_open_location_in_new_window (NautilusViewFrame *view,
                                                 const char *location)
{
671 672
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
	gtk_signal_emit (GTK_OBJECT (view), signals[OPEN_LOCATION_IN_NEW_WINDOW], location);
673 674 675 676 677 678
}

void
nautilus_view_frame_report_location_change (NautilusViewFrame *view,
                                            const char *location)
{
679
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
680 681 682 683 684

	set_up_for_new_location (view);

	gtk_signal_emit (GTK_OBJECT (view),
			 signals[REPORT_LOCATION_CHANGE], location);
685 686 687 688 689 690
}

void
nautilus_view_frame_report_selection_change (NautilusViewFrame *view,
                                             GList *selection)
{
691 692
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
	gtk_signal_emit (GTK_OBJECT (view), signals[REPORT_SELECTION_CHANGE], selection);
693 694 695 696 697 698
}

void
nautilus_view_frame_report_status (NautilusViewFrame *view,
                                   const char *status)
{
699 700
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
	gtk_signal_emit (GTK_OBJECT (view), signals[REPORT_STATUS], status);
701
}
Maciej Stachowiak's avatar
Maciej Stachowiak committed
702 703

void
704
nautilus_view_frame_report_load_underway (NautilusViewFrame *view)
Maciej Stachowiak's avatar
Maciej Stachowiak committed
705
{
706 707
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
	gtk_signal_emit (GTK_OBJECT (view), signals[REPORT_LOAD_UNDERWAY]);
Maciej Stachowiak's avatar
Maciej Stachowiak committed
708 709 710
}

void
711 712
nautilus_view_frame_report_load_progress (NautilusViewFrame *view,
                                          double fraction_done)
Maciej Stachowiak's avatar
Maciej Stachowiak committed
713
{
714 715
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
	gtk_signal_emit (GTK_OBJECT (view), signals[REPORT_LOAD_PROGRESS], fraction_done);
Maciej Stachowiak's avatar
Maciej Stachowiak committed
716 717 718
}

void
719
nautilus_view_frame_report_load_complete (NautilusViewFrame *view)
Maciej Stachowiak's avatar
Maciej Stachowiak committed
720
{
721 722
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
	gtk_signal_emit (GTK_OBJECT (view), signals[REPORT_LOAD_COMPLETE]);
Maciej Stachowiak's avatar
Maciej Stachowiak committed
723 724 725
}

void
726
nautilus_view_frame_report_load_failed (NautilusViewFrame *view)
Maciej Stachowiak's avatar
Maciej Stachowiak committed
727
{
728 729
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
	gtk_signal_emit (GTK_OBJECT (view), signals[REPORT_LOAD_FAILED]);
Maciej Stachowiak's avatar
Maciej Stachowiak committed
730 731
}

Darin Adler's avatar
Darin Adler committed
732
void
733 734
nautilus_view_frame_set_title (NautilusViewFrame *view,
                               const char *title)
Darin Adler's avatar
Darin Adler committed
735
{
736
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753
	g_return_if_fail (title != NULL);

	/* Only do work if the title actually changed. */
	if (view->details->title != NULL
	    && strcmp (view->details->title, title) == 0) {
		return;
	}

	g_free (view->details->title);
	view->details->title = g_strdup (title);
	gtk_signal_emit (GTK_OBJECT (view), signals[TITLE_CHANGED]);
}

char *
nautilus_view_frame_get_title (NautilusViewFrame *view)
{
	return g_strdup (view->details->title);
Darin Adler's avatar
Darin Adler committed
754 755
}

756
void
757 758
nautilus_view_frame_zoom_level_changed (NautilusViewFrame *view,
                                        double level)
759
{
760 761
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
	gtk_signal_emit (GTK_OBJECT (view), signals[ZOOM_LEVEL_CHANGED], level);
762 763
}

764
static gboolean
765
check_object (gpointer data)
766
{
767 768 769 770 771 772 773
	NautilusViewFrame *view;
	CORBA_Environment ev;
	gboolean ok;

	view = NAUTILUS_VIEW_FRAME (data);
	g_assert (!view->checking);

774
	CORBA_exception_init (&ev);
775 776 777
	view->checking++;
	ok = TRUE;
	if (CORBA_Object_non_existent (bonobo_object_corba_objref (BONOBO_OBJECT (view->client_object)), &ev)) {
778 779 780
		/* FIXME bugzilla.eazel.com 1840: Is a destroy really sufficient here? Who does the unref? 
		 * See bug 1840 for one bad case this destroy is involved in.
		 */
781 782
		gtk_object_destroy (GTK_OBJECT (view));

783 784 785 786
		view->timer_id = 0;
		ok = FALSE;
	}
	view->checking--;
787
	CORBA_exception_free (&ev);
788 789
	
	return ok;
790 791 792
}

void
793 794 795
nautilus_view_frame_set_active_errors (NautilusViewFrame *view, gboolean enabled)
{
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
796 797 798
	if (enabled) {
		if (view->timer_id == 0) {
			/* FIXME: Is a hard-coded 2-second timeout acceptable? */
799 800 801
			view->timer_id = g_timeout_add (2000, check_object, view);
		}
	} else {
802 803
		if (view->timer_id != 0) {
			g_source_remove (view->timer_id);
804 805 806
			view->timer_id = 0;
		}
	}
807
}
Darin Adler's avatar
Darin Adler committed
808 809 810 811

char *
nautilus_view_frame_get_label (NautilusViewFrame *view)
{
812 813
	g_return_val_if_fail (NAUTILUS_IS_VIEW_FRAME (view), NULL);
	return g_strdup (view->label);
Darin Adler's avatar
Darin Adler committed
814 815 816 817 818 819
}

void
nautilus_view_frame_set_label (NautilusViewFrame *view,
                               const char *label)
{
820 821 822
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
	g_free (view->label);
	view->label = g_strdup (label);
Darin Adler's avatar
Darin Adler committed
823
}
Darin Adler's avatar
Darin Adler committed
824 825 826 827 828

/* Calls activate on the underlying control frame. */
void
nautilus_view_frame_activate (NautilusViewFrame *view)
{
829 830 831 832 833 834
	BonoboControlFrame *control_frame;
	
	control_frame = BONOBO_CONTROL_FRAME (bonobo_object_query_local_interface 
					      (view->view_frame, "IDL:Bonobo/ControlFrame:1.0"));
	bonobo_control_frame_control_activate (control_frame);
	bonobo_object_unref (BONOBO_OBJECT (control_frame));
Darin Adler's avatar
Darin Adler committed
835
}
836 837


838
Nautilus_History *
839 840
nautilus_view_frame_get_history_list (NautilusViewFrame *view)
{
841 842
	Nautilus_History *history_list;
	
843
	g_return_val_if_fail (NAUTILUS_IS_VIEW_FRAME (view), NULL);
844 845 846
	
	/* Sent out signal to get the history list. */
	history_list = NULL;
847 848 849 850 851
	gtk_signal_emit (GTK_OBJECT (view), 
  			 signals[GET_HISTORY_LIST],
			 &history_list);
  	return history_list;
}