summaryrefslogtreecommitdiff
path: root/src/nautilus-view-frame.c
blob: c53f1a57acdab892494fe0a7033cddcffd636fbd (plain)
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
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/*
 *  Nautilus
 *
 *  Copyright (C) 1999, 2000 Red Hat, Inc.
 *  Copyright (C) 1999, 2000, 2001 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; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  Authors: Elliot Lee <sopwith@redhat.com>
 *           Darin Adler <darin@bentspoon.com>
 *
 */

/* nautilus-view-frame.c: Widget and CORBA machinery for hosting a NautilusView */

#include <config.h>
#include "nautilus-view-frame.h"

#include "nautilus-application.h"
#include "nautilus-component-adapter-factory.h"
#include "nautilus-signaller.h"
#include "nautilus-view-frame-private.h"
#include "nautilus-window.h"
#include <bonobo/bonobo-control-frame.h>
#include <bonobo/bonobo-event-source.h>
#include <bonobo/bonobo-exception.h>
#include <bonobo/bonobo-zoomable-frame.h>
#include <bonobo/bonobo-zoomable.h>
#include <eel/eel-gtk-extensions.h>
#include <eel/eel-gtk-macros.h>
#include <eel/eel-marshal.h>
#include <gtk/gtkmain.h>
#include <gtk/gtksignal.h>
#include <libnautilus-private/nautilus-bonobo-extensions.h>
#include <libnautilus-private/nautilus-marshal.h>
#include <libnautilus-private/nautilus-undo-manager.h>
#include <libnautilus/nautilus-idle-queue.h>
#include <libnautilus/nautilus-view.h>
#include <nautilus-marshal.h>
#include <string.h>

enum {
	CHANGE_SELECTION,
	CHANGE_STATUS,
	FAILED,
	GET_HISTORY_LIST,
	GO_BACK,
	CLOSE_WINDOW,
	LOAD_COMPLETE,
	LOAD_PROGRESS_CHANGED,
	LOAD_UNDERWAY,
	OPEN_LOCATION,
	REPORT_LOCATION_CHANGE,
	REPORT_REDIRECT,
	TITLE_CHANGED,
	VIEW_LOADED,
	ZOOM_LEVEL_CHANGED,
	ZOOM_PARAMETERS_CHANGED,
	SHOW_HIDDEN_FILES_MODE_CHANGED,
	LAST_SIGNAL
};

typedef enum {
	VIEW_FRAME_EMPTY,
	VIEW_FRAME_NO_LOCATION,
	VIEW_FRAME_WAITING,
	VIEW_FRAME_UNDERWAY,
	VIEW_FRAME_LOADED,
	VIEW_FRAME_FAILED
} NautilusViewFrameState;

struct NautilusViewFrameDetails {
	NautilusViewFrameState state;
	char *title;
	char *label;
        char *view_iid;

        /* The view frame Bonobo objects. */
        BonoboObject *view_frame;
	BonoboEventSource *event_source;
	BonoboControlFrame *control_frame;
        BonoboZoomableFrame *zoomable_frame;

        /* The view CORBA object. */
        Nautilus_View view;

	/* The positionable CORBA object. */
	Nautilus_ScrollPositionable positionable;
	
	/* A container to connect our clients to. */
	BonoboUIContainer *ui_container;
        NautilusUndoManager *undo_manager;

	NautilusBonoboActivationHandle *activation_handle;

	NautilusIdleQueue *idle_queue;

	guint failed_idle_id;
	guint socket_gone_idle_id;

	/* zoom data */
	float zoom_level;
	float min_zoom_level;
	float max_zoom_level;
	gboolean has_min_zoom_level;
	gboolean has_max_zoom_level;
	GList *zoom_levels;

	Nautilus_WindowType 	     window_type;
	Nautilus_ShowHiddenFilesMode show_hidden_files_mode;
};

static void nautilus_view_frame_init       (NautilusViewFrame      *view);
static void nautilus_view_frame_class_init (NautilusViewFrameClass *klass);
static void send_history                   (NautilusViewFrame      *view);

static guint signals[LAST_SIGNAL];

EEL_CLASS_BOILERPLATE (NautilusViewFrame,
		       nautilus_view_frame,
		       GTK_TYPE_HBOX)

void
nautilus_view_frame_queue_incoming_call (PortableServer_Servant servant,
					 NautilusViewFrameFunction call,
					 gpointer callback_data,
					 GDestroyNotify destroy_callback_data)
{
	NautilusViewFrame *view;

	view = nautilus_view_frame_from_servant (servant);
	if (view == NULL) {
		if (destroy_callback_data != NULL) {
			(* destroy_callback_data) (callback_data);
		}
		return;
	}

	nautilus_idle_queue_add (view->details->idle_queue,
				 (GFunc) call,
				 view,
				 callback_data,
				 destroy_callback_data);
}

static void
nautilus_view_frame_init (NautilusViewFrame *view)
{
	GTK_WIDGET_SET_FLAGS (view, GTK_NO_WINDOW);

	view->details = g_new0 (NautilusViewFrameDetails, 1);

	view->details->idle_queue = nautilus_idle_queue_new ();

	g_signal_connect_object (nautilus_signaller_get_current (),
				 "history_list_changed",
				 G_CALLBACK (send_history),
				 view, G_CONNECT_SWAPPED);
	g_signal_connect_object (nautilus_icon_factory_get (),
				 "icons_changed",
				 G_CALLBACK (send_history),
				 view, G_CONNECT_SWAPPED);
}

static void
stop_activation (NautilusViewFrame *view)
{
	nautilus_bonobo_activate_cancel (view->details->activation_handle);
	view->details->activation_handle = NULL;
}

static void
destroy_view (NautilusViewFrame *view)
{
	BonoboUIEngine *engine;

	if (view->details->view == CORBA_OBJECT_NIL) {
		return;
	}
	
	g_free (view->details->view_iid);
	view->details->view_iid = NULL;

	if (view->details->positionable != CORBA_OBJECT_NIL) {
		bonobo_object_release_unref (view->details->positionable, NULL);
		view->details->positionable = CORBA_OBJECT_NIL;
	}
	
	CORBA_Object_release (view->details->view, NULL);
	view->details->view = CORBA_OBJECT_NIL;

	bonobo_object_unref (view->details->view_frame);
	view->details->view_frame = NULL;
	view->details->control_frame = NULL;
	view->details->zoomable_frame = NULL;

	engine = bonobo_ui_container_get_engine (view->details->ui_container);
	if (engine != NULL) {
		bonobo_ui_engine_deregister_dead_components (engine);
	}
	bonobo_object_unref (view->details->ui_container);
	view->details->ui_container = NULL;
}

static void
shut_down (NautilusViewFrame *view)
{
	/* It's good to be in "failed" state while shutting down
	 * (makes operations all be quiet no-ops). But we don't want
	 * to send out a "failed" signal.
	 */
	view->details->state = VIEW_FRAME_FAILED;

	stop_activation (view);
	destroy_view (view);

	if (view->details->idle_queue != NULL) {
		nautilus_idle_queue_destroy (view->details->idle_queue);
		view->details->idle_queue = NULL;
	}

	if (view->details->failed_idle_id != 0) {
		g_source_remove (view->details->failed_idle_id);
		view->details->failed_idle_id = 0;
	}
	if (view->details->socket_gone_idle_id != 0) {
		g_source_remove (view->details->socket_gone_idle_id);
		view->details->socket_gone_idle_id = 0;
	}
}

static void
nautilus_view_frame_unrealize (GtkWidget *widget)
{
	shut_down (NAUTILUS_VIEW_FRAME (widget));
	EEL_CALL_PARENT (GTK_WIDGET_CLASS, unrealize, (widget));
}

static void
nautilus_view_frame_destroy (GtkObject *object)
{
	shut_down (NAUTILUS_VIEW_FRAME (object));
	EEL_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
}

static void
nautilus_view_frame_finalize (GObject *object)
{
	NautilusViewFrame *view;

	view = NAUTILUS_VIEW_FRAME (object);

	shut_down (view);

	g_free (view->details->title);
	g_free (view->details->label);
	g_free (view->details);
	
	EEL_CALL_PARENT (G_OBJECT_CLASS, finalize, (object));
}

static void
emit_zoom_parameters_changed (NautilusViewFrame *view)
{	
	eel_g_list_free_deep (view->details->zoom_levels);

	if (view->details->zoomable_frame) {
		view->details->min_zoom_level = bonobo_zoomable_frame_get_min_zoom_level (view->details->zoomable_frame);
		view->details->max_zoom_level = bonobo_zoomable_frame_get_max_zoom_level (view->details->zoomable_frame);
		view->details->has_min_zoom_level = bonobo_zoomable_frame_has_min_zoom_level (view->details->zoomable_frame);
		view->details->has_max_zoom_level = bonobo_zoomable_frame_has_max_zoom_level (view->details->zoomable_frame);
		view->details->zoom_levels = bonobo_zoomable_frame_get_preferred_zoom_levels (view->details->zoomable_frame);
		
		g_signal_emit (view, signals[ZOOM_PARAMETERS_CHANGED], 0);
	} else {
		view->details->min_zoom_level = 0.0;
		view->details->max_zoom_level = 0.0;
		view->details->has_min_zoom_level = FALSE;
		view->details->has_max_zoom_level = FALSE;
		view->details->zoom_levels = NULL;
	}
}

/* stimulus: successful activated_component call */
static void
view_frame_activated (NautilusViewFrame *view)
{
	g_assert (NAUTILUS_IS_VIEW_FRAME (view));
	
	switch (view->details->state) {
	case VIEW_FRAME_EMPTY:
		view->details->state = VIEW_FRAME_NO_LOCATION;
		g_signal_emit (view, signals[VIEW_LOADED], 0);
		emit_zoom_parameters_changed (view);
		send_history (view);
		return;
	case VIEW_FRAME_NO_LOCATION:
	case VIEW_FRAME_UNDERWAY:
	case VIEW_FRAME_LOADED:
	case VIEW_FRAME_WAITING:
	case VIEW_FRAME_FAILED:
		g_assert_not_reached ();
		return;
	}

	g_assert_not_reached ();
}

/* this corresponds to the load_location call stimulus */
static void
view_frame_wait (NautilusViewFrame *view)
{
	g_assert (NAUTILUS_IS_VIEW_FRAME (view));
	
	switch (view->details->state) {
	case VIEW_FRAME_EMPTY:
		g_warning ("tried to load location in an empty view frame");
		break;
	case VIEW_FRAME_NO_LOCATION:
	case VIEW_FRAME_UNDERWAY:
	case VIEW_FRAME_LOADED:
		view->details->state = VIEW_FRAME_WAITING;
		return;
	case VIEW_FRAME_WAITING:
		return;
	case VIEW_FRAME_FAILED:
		g_assert_not_reached ();
		return;
	}

	g_assert_not_reached ();
}

/* this corresponds to the load_underway and load_progress stimulus */
static void
view_frame_underway (NautilusViewFrame *view)
{
	g_assert (NAUTILUS_IS_VIEW_FRAME (view));
	
	switch (view->details->state) {
	case VIEW_FRAME_EMPTY:
		g_assert_not_reached ();
		return;
	case VIEW_FRAME_NO_LOCATION:
		g_warning ("got signal from a view frame with no location");
		return;
	case VIEW_FRAME_WAITING:
	case VIEW_FRAME_LOADED:
		view->details->state = VIEW_FRAME_UNDERWAY;
		g_signal_emit (view, signals[LOAD_UNDERWAY], 0);
		return;
	case VIEW_FRAME_UNDERWAY:
	case VIEW_FRAME_FAILED:
		return;
	}

	g_assert_not_reached ();
}

/* stimulus 
   - open_location call from component
   - report_selection_change
   - report_status
   - set_title 
*/
static void
view_frame_wait_is_over (NautilusViewFrame *view)
{
	g_assert (NAUTILUS_IS_VIEW_FRAME (view));
	
	switch (view->details->state) {
	case VIEW_FRAME_EMPTY:
	case VIEW_FRAME_FAILED:
		g_assert_not_reached ();
		return;
	case VIEW_FRAME_NO_LOCATION:
		g_warning ("got signal from a view frame with no location");
		return;
	case VIEW_FRAME_WAITING:
		view_frame_underway (view);
		return;
	case VIEW_FRAME_UNDERWAY:
	case VIEW_FRAME_LOADED:
		return;
	}

	g_assert_not_reached ();
}

/* stimulus: report_load_complete */
static void
view_frame_loaded (NautilusViewFrame *view)
{
	g_assert (NAUTILUS_IS_VIEW_FRAME (view));
	
	switch (view->details->state) {
	case VIEW_FRAME_EMPTY:
		g_assert_not_reached ();
		return;
	case VIEW_FRAME_NO_LOCATION:
		g_warning ("got signal from a view frame with no location");
		return;
	case VIEW_FRAME_WAITING:
		view_frame_underway (view);
		/* fall through */
	case VIEW_FRAME_UNDERWAY:
		view->details->state = VIEW_FRAME_LOADED;
		g_signal_emit (view, signals[LOAD_COMPLETE], 0);
		return;
	case VIEW_FRAME_LOADED:
	case VIEW_FRAME_FAILED:
		return;
	}

	g_assert_not_reached ();
}

/* stimulus: report_load_failed */
static void
view_frame_failed (NautilusViewFrame *view)
{
	g_assert (NAUTILUS_IS_VIEW_FRAME (view));
	
	switch (view->details->state) {
	case VIEW_FRAME_EMPTY:
	case VIEW_FRAME_LOADED:
	case VIEW_FRAME_NO_LOCATION:
	case VIEW_FRAME_UNDERWAY:
	case VIEW_FRAME_WAITING:
		view->details->state = VIEW_FRAME_FAILED;
		stop_activation (view);
		destroy_view (view);
		g_signal_emit (view, signals[FAILED], 0);
		return;
	case VIEW_FRAME_FAILED:
		return;
	}

	g_assert_not_reached ();
}

NautilusViewFrame *
nautilus_view_frame_new (BonoboUIContainer *ui_container,
                         NautilusUndoManager *undo_manager,
			 Nautilus_WindowType window_type)
{
	NautilusViewFrame *view_frame;
	
	view_frame = NAUTILUS_VIEW_FRAME (gtk_widget_new (nautilus_view_frame_get_type (), NULL));
	
	bonobo_object_ref (ui_container);
	view_frame->details->ui_container = ui_container;
	view_frame->details->undo_manager = undo_manager;
	view_frame->details->window_type = window_type;
	view_frame->details->show_hidden_files_mode = Nautilus_SHOW_HIDDEN_FILES_DEFAULT;
	return view_frame;
}

static void
emit_zoom_parameters_changed_callback (gpointer data,
				       gpointer callback_data)
{
	

	emit_zoom_parameters_changed (NAUTILUS_VIEW_FRAME (data));
}

static void
zoom_parameters_changed_callback (BonoboZoomableFrame *zframe,
				  NautilusViewFrame *view)
{
	g_assert (NAUTILUS_IS_VIEW_FRAME (view));

	nautilus_idle_queue_add	(view->details->idle_queue,
				 emit_zoom_parameters_changed_callback,
				 view,
				 NULL,
				 NULL);
}

static void
emit_zoom_level_changed_callback (gpointer data,
				  gpointer callback_data)
{
	NautilusViewFrame *view;
	
	view = NAUTILUS_VIEW_FRAME (data);
	
	view->details->zoom_level = bonobo_zoomable_frame_get_zoom_level (view->details->zoomable_frame);

	g_signal_emit (view,
			 signals[ZOOM_LEVEL_CHANGED], 0,
			 * (float *) callback_data);
}

static void
zoom_level_changed_callback (BonoboZoomableFrame *zframe,
			     float zoom_level,
			     NautilusViewFrame *view)
{
	float *copy;

	g_assert (NAUTILUS_IS_VIEW_FRAME (view));

	copy = g_new (float, 1);
	*copy = zoom_level;
	nautilus_idle_queue_add	(view->details->idle_queue,
				 emit_zoom_level_changed_callback,
				 view,
				 copy,
				 g_free);
}

enum {
	BONOBO_PROPERTY_TITLE,
	BONOBO_PROPERTY_HISTORY,
	BONOBO_PROPERTY_SELECTION,
	BONOBO_PROPERTY_WINDOW_TYPE,
	BONOBO_PROPERTY_SHOW_HIDDEN_FILES_MODE
};

static Nautilus_History *
get_history_list (NautilusViewFrame *view)
{
	Nautilus_History *history_list;
	
	history_list = NULL;
	g_signal_emit (view, 
		       signals[GET_HISTORY_LIST], 0,
		       &history_list);
  	return history_list;
}

static void
nautilus_view_frame_get_prop (BonoboPropertyBag *bag,
			      BonoboArg         *arg,
			      guint              arg_id,
			      CORBA_Environment *ev,
			      gpointer           user_data)
{
	NautilusViewFrame *view = user_data;

	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (user_data));

	switch (arg_id) {
	case BONOBO_PROPERTY_TITLE:
		BONOBO_ARG_SET_STRING (arg, view->details->title);
		break;

	case BONOBO_PROPERTY_HISTORY:
		CORBA_free (arg->_value);
		arg->_value = get_history_list (view);
		break;

	case BONOBO_PROPERTY_SELECTION:
		g_warning ("NautilusViewFrame: selection fetch not yet implemented");
		break;

	case BONOBO_PROPERTY_WINDOW_TYPE :
		BONOBO_ARG_SET_GENERAL (arg, view->details->window_type,
					TC_Nautilus_WindowType,
					Nautilus_WindowType,
					NULL);
		break;

	case BONOBO_PROPERTY_SHOW_HIDDEN_FILES_MODE :
		BONOBO_ARG_SET_GENERAL (arg, view->details->show_hidden_files_mode,
					TC_Nautilus_ShowHiddenFilesMode,
					Nautilus_ShowHiddenFilesMode,
					NULL);
		break;
	default:
		g_warning ("NautilusViewFrame: Unknown property idx %d", arg_id);
		break;
	}
}

static BonoboPropertyBag *
create_ambient_properties (NautilusViewFrame *view)
{
	BonoboPropertyBag *bag;

	bag = bonobo_property_bag_new (nautilus_view_frame_get_prop, NULL, view);
	
	bonobo_property_bag_add
		(bag,
		 "title",
		 BONOBO_PROPERTY_TITLE,
		 TC_CORBA_string,
		 NULL,
		 _("a title"),
		 BONOBO_PROPERTY_READABLE);

	bonobo_property_bag_add
		(bag,
		 "history",
		 BONOBO_PROPERTY_HISTORY,
		 TC_Nautilus_History,
		 NULL,
		 _("the browse history"),
		 BONOBO_PROPERTY_READABLE);

	bonobo_property_bag_add
		(bag,
		 "selection",
		 BONOBO_PROPERTY_SELECTION,
		 TC_Nautilus_URIList,
		 NULL,
		 _("the current selection"),
		 BONOBO_PROPERTY_READABLE);

	bonobo_property_bag_add
		(bag,
		 "window-type",
		 BONOBO_PROPERTY_WINDOW_TYPE,
		 TC_Nautilus_WindowType,
		 NULL,
		 _("the type of window the view is embedded in"),
		 BONOBO_PROPERTY_READABLE);

	bonobo_property_bag_add
		(bag,
		 "show-hidden-files-mode",
		 BONOBO_PROPERTY_SHOW_HIDDEN_FILES_MODE,
		 TC_Nautilus_ShowHiddenFilesMode,
		 NULL,
		 _("whether to show hidden files in the view"),
		 BONOBO_PROPERTY_READABLE);

	view->details->event_source = bag->es;

	return bag;
}

static void
create_corba_objects (NautilusViewFrame *view)
{
	CORBA_Environment ev;
	Bonobo_Control control;
	Bonobo_Zoomable zoomable;
	Nautilus_ScrollPositionable positionable;
	BonoboPropertyBag *bag;

	CORBA_exception_init (&ev);

	/* Create a view frame. */
	view->details->view_frame = nautilus_view_frame_create_corba_part (view);

	/* Create a control frame. */
	control = Bonobo_Unknown_queryInterface
		(view->details->view, "IDL:Bonobo/Control:1.0", &ev);
	g_assert (! BONOBO_EX (&ev));

	view->details->control_frame = bonobo_control_frame_new
		(BONOBO_OBJREF (view->details->ui_container));

	bag = create_ambient_properties (view);
	bonobo_control_frame_set_propbag (view->details->control_frame, bag);
	bonobo_object_unref (bag);

	bonobo_control_frame_bind_to_control (view->details->control_frame, control, NULL);

	bonobo_object_release_unref (control, NULL);

	/* Create a zoomable frame. */
	zoomable = Bonobo_Unknown_queryInterface
		(view->details->view, "IDL:Bonobo/Zoomable:1.0", &ev);
	if (!BONOBO_EX (&ev)
	    && !CORBA_Object_is_nil (zoomable, &ev)
	    && !BONOBO_EX (&ev)) {
		view->details->zoomable_frame = bonobo_zoomable_frame_new ();
		bonobo_zoomable_frame_bind_to_zoomable
			(view->details->zoomable_frame, zoomable, NULL);
		bonobo_object_release_unref (zoomable, NULL);
	}

	CORBA_exception_free (&ev);

	CORBA_exception_init (&ev);
	
	positionable = Bonobo_Unknown_queryInterface
		(view->details->view, "IDL:Nautilus/ScrollPositionable:1.0", &ev);
	if (!BONOBO_EX (&ev)
	    && !CORBA_Object_is_nil (positionable, &ev)
	    && !BONOBO_EX (&ev)) {
		view->details->positionable = positionable;
	}

	CORBA_exception_free (&ev);
	
	/* Aggregate all the interfaces into one object. */
	bonobo_object_add_interface (BONOBO_OBJECT (view->details->view_frame), 
	                             BONOBO_OBJECT (view->details->control_frame));
 	if (view->details->zoomable_frame != NULL) {
 		bonobo_object_add_interface (BONOBO_OBJECT (view->details->view_frame), 
 					     BONOBO_OBJECT (view->details->zoomable_frame));
 	}
	nautilus_undo_manager_add_interface (view->details->undo_manager,
					     BONOBO_OBJECT (view->details->view_frame));
}


static gboolean
view_frame_failed_callback (gpointer callback_data)
{
	NautilusViewFrame *view;

	view = NAUTILUS_VIEW_FRAME (callback_data);
	view->details->failed_idle_id = 0;
	view_frame_failed (view);
	return FALSE;
}

static void
queue_view_frame_failed (NautilusViewFrame *view)
{
	g_assert (NAUTILUS_IS_VIEW_FRAME (view));

	if (view->details->failed_idle_id == 0) {
		view->details->failed_idle_id =
			g_idle_add (view_frame_failed_callback, view);
	}
}

static gboolean
check_socket_gone_idle_callback (gpointer callback_data)
{
	NautilusViewFrame *frame;
	GtkWidget *widget;
	GList *children;

	frame = NAUTILUS_VIEW_FRAME (callback_data);
	
	frame->details->socket_gone_idle_id = 0;

	widget = bonobo_control_frame_get_widget (frame->details->control_frame);

	/* This relies on details of the BonoboControlFrame
	 * implementation, specifically that's there's one level of
	 * hierarchy between the widget returned by get_widget and the
	 * actual plug.
	 */
	children = gtk_container_get_children (GTK_CONTAINER (widget));
	g_list_free (children);

	/* If there's nothing inside the widget at all, that means
	 * that the socket went away because the remote plug went away.
	 */
	if (children == NULL) {
		view_frame_failed (frame);
	}

	return FALSE;
}

static void
check_socket_gone_callback (GtkContainer *container,
			    GtkWidget *widget,
			    gpointer callback_data)
{
	NautilusViewFrame *frame;

	frame = NAUTILUS_VIEW_FRAME (callback_data);

	/* There are two times the socket will be destroyed in Bonobo.
	 * One is when a local control decides to not use the socket.
	 * The other is when the remote plug goes away. The way to
	 * tell these apart is to wait until idle time. At idle time,
	 * if there's nothing in the container, then that means the
	 * real socket went away. If it was just the local control
	 * deciding not to use the socket, there will be another
	 * widget in there.
	 */
	if (frame->details->socket_gone_idle_id == 0) {
		frame->details->socket_gone_idle_id = g_idle_add
			(check_socket_gone_idle_callback, callback_data);
	}
}

static void
attach_view (NautilusViewFrame *view,
	     Bonobo_Unknown component)
{
	CORBA_Environment ev;
	GtkWidget *widget;
  	
	/* Either create an adapter or query for the Nautilus:View
	 * interface. Either way, we don't need to keep the original
	 * reference around once that happens.
	 */
	view->details->view = nautilus_component_adapter_factory_create_adapter 
		(nautilus_component_adapter_factory_get (), component);

	/* Handle case where we don't know how to host this component. */
  	if (view->details->view == CORBA_OBJECT_NIL) {
		view_frame_failed (view);
      		return;
    	}

	create_corba_objects (view);

	CORBA_exception_init (&ev);
	Bonobo_Unknown_unref (view->details->view, &ev);
	CORBA_exception_free (&ev);

	widget = bonobo_control_frame_get_widget (view->details->control_frame);

	g_signal_connect_object	(view->details->view_frame, "destroy",
				 G_CALLBACK (view_frame_failed), view, G_CONNECT_SWAPPED);
	g_signal_connect_object	(view->details->view_frame, "system_exception",
				 G_CALLBACK (queue_view_frame_failed), view, G_CONNECT_SWAPPED);
	g_signal_connect_object	(view->details->control_frame, "system_exception",
				 G_CALLBACK (queue_view_frame_failed), view, G_CONNECT_SWAPPED);
	g_signal_connect_object	(widget, "remove",
				 G_CALLBACK (check_socket_gone_callback), view, 0);

	if (view->details->zoomable_frame != NULL) {
		g_signal_connect_object	(view->details->zoomable_frame, "system_exception",
					 G_CALLBACK (queue_view_frame_failed), view, G_CONNECT_SWAPPED);
		g_signal_connect_object (view->details->zoomable_frame, "zoom_parameters_changed",
					 G_CALLBACK (zoom_parameters_changed_callback), view, 0);
		g_signal_connect_object (view->details->zoomable_frame, "zoom_level_changed",
					 G_CALLBACK (zoom_level_changed_callback), view, 0);
	}

	gtk_widget_show (widget);
	gtk_container_add (GTK_CONTAINER (view), widget);
	
	view_frame_activated (view);

	/* The frame might already be mapped when the view is activated.
	 * This means we won't get the mapped signal while its active, so
	 * activate it now.
	 */
	if (GTK_WIDGET_MAPPED (GTK_WIDGET (view))) {
		bonobo_control_frame_control_activate (view->details->control_frame);
	}
}

static void
activation_callback (NautilusBonoboActivationHandle *handle,
		     Bonobo_Unknown activated_object,
		     gpointer callback_data)
{
	NautilusViewFrame *view;

	view = NAUTILUS_VIEW_FRAME (callback_data);
	g_assert (view->details->activation_handle == handle);

	view->details->activation_handle = NULL;

	if (activated_object == CORBA_OBJECT_NIL) {
		view_frame_failed (view);
	} else {
		attach_view (view, activated_object);
	}
}

void
nautilus_view_frame_load_view (NautilusViewFrame *view, 
			       const char *view_iid)
{
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
	g_return_if_fail (view_iid != NULL);

	if (view->details->state == VIEW_FRAME_FAILED) {
		return;
	}

	g_return_if_fail (view->details->state == VIEW_FRAME_EMPTY);
	g_assert (view->details->view_iid == NULL);
	g_assert (view->details->activation_handle == NULL);

	view->details->view_iid = g_strdup (view_iid);
	view->details->activation_handle = nautilus_bonobo_activate_from_id
		(view_iid, activation_callback, view);
}

void
nautilus_view_frame_load_location (NautilusViewFrame *view,
                                   const char *location)
{
	CORBA_Environment ev;
	
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));

	if (view->details->state == VIEW_FRAME_FAILED) {
		return;
	}

	g_free (view->details->title);
	view->details->title = NULL;
	g_signal_emit (view, signals[TITLE_CHANGED], 0);

	view_frame_wait (view);
	
	CORBA_exception_init (&ev);
	Nautilus_View_load_location (view->details->view, location, &ev);
	if (BONOBO_EX (&ev)) {
		view_frame_failed (view);
	}
	CORBA_exception_free (&ev);
}

void
nautilus_view_frame_stop (NautilusViewFrame *view)
{
	CORBA_Environment ev;
	
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));

	if (view->details->state == VIEW_FRAME_FAILED) {
		return;
	}
	
	stop_activation (view);

	if (view->details->view != CORBA_OBJECT_NIL) {
		CORBA_exception_init (&ev);
		Nautilus_View_stop_loading (view->details->view, &ev);
		if (BONOBO_EX (&ev)) {
			view_frame_failed (view);
		}
		CORBA_exception_free (&ev);
	}
}

void
nautilus_view_frame_selection_changed (NautilusViewFrame *view,
                                       GList *selection)
{
	BonoboArg *arg;
	CORBA_Environment ev;
	Nautilus_URIList *uri_list;
	
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
	
	if (view->details->view == CORBA_OBJECT_NIL) {
		return;
	}

	if (!bonobo_event_source_has_listener
	    (view->details->event_source,
	     "Bonobo/Property:change:selection")) {
		return;
	}

	uri_list = nautilus_uri_list_from_g_list (selection);
	
	CORBA_exception_init (&ev);

	arg = bonobo_arg_new_from (TC_Nautilus_URIList, uri_list);
	CORBA_free (uri_list);
	
	bonobo_event_source_notify_listeners
		(view->details->event_source,
		 "Bonobo/Property:change:selection", arg, &ev);
	
	CORBA_free (arg);

	if (BONOBO_EX (&ev)) {
		view_frame_failed (view);
	}

	CORBA_exception_free (&ev);
}

void
nautilus_view_frame_title_changed (NautilusViewFrame *view,
				   const char *title)
{
	BonoboArg arg;
	CORBA_Environment ev;
	
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
	
	if (view->details->view == CORBA_OBJECT_NIL) {
		return;
	}

	CORBA_exception_init (&ev);

	arg._type = TC_CORBA_string;
	arg._value = &title;

	bonobo_event_source_notify_listeners
		(view->details->event_source,
		 "Bonobo/Property:change:title", &arg, &ev);

	if (BONOBO_EX (&ev)) {
		view_frame_failed (view);
	}

	CORBA_exception_free (&ev);
}

gboolean
nautilus_view_frame_get_is_zoomable (NautilusViewFrame *view)
{
	g_return_val_if_fail (NAUTILUS_IS_VIEW_FRAME (view), FALSE);

	return view->details->zoomable_frame != NULL;
}

float
nautilus_view_frame_get_zoom_level (NautilusViewFrame *view)
{
	g_return_val_if_fail (NAUTILUS_IS_VIEW_FRAME (view), 0.0);

	if (view->details->zoomable_frame == NULL) {
		return 0.0;
	}

	return view->details->zoom_level;
}

void
nautilus_view_frame_set_zoom_level (NautilusViewFrame *view,
				    float zoom_level)
{
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));

	if (view->details->zoomable_frame == NULL) {
		return;
	}

	bonobo_zoomable_frame_set_zoom_level (view->details->zoomable_frame, zoom_level);
}

float
nautilus_view_frame_get_min_zoom_level (NautilusViewFrame *view)
{
	g_return_val_if_fail (NAUTILUS_IS_VIEW_FRAME (view), 0.0);

	if (view->details->zoomable_frame == NULL) {
		return 0.0;
	}

	return view->details->min_zoom_level;
}

float
nautilus_view_frame_get_max_zoom_level (NautilusViewFrame *view)
{
	g_return_val_if_fail (NAUTILUS_IS_VIEW_FRAME (view), 0.0);
	
	if (view->details->zoomable_frame == NULL) {
		return 0.0;
	}

	return view->details->max_zoom_level;
}

gboolean
nautilus_view_frame_get_has_min_zoom_level (NautilusViewFrame *view)
{
	g_return_val_if_fail (NAUTILUS_IS_VIEW_FRAME (view), FALSE);
	
	if (view->details->zoomable_frame == NULL) {
		return FALSE;
	}

	return view->details->has_min_zoom_level;
}

gboolean
nautilus_view_frame_get_has_max_zoom_level (NautilusViewFrame *view)
{
	g_return_val_if_fail (NAUTILUS_IS_VIEW_FRAME (view), FALSE);
	
	if (view->details->zoomable_frame == NULL) {
		return FALSE;
	}

	return view->details->has_max_zoom_level;
}

gboolean
nautilus_view_frame_get_is_continuous (NautilusViewFrame *view)
{
	g_return_val_if_fail (NAUTILUS_IS_VIEW_FRAME (view), FALSE);
	
	if (view->details->zoomable_frame == NULL) {
		return FALSE;
	}

	return bonobo_zoomable_frame_is_continuous (view->details->zoomable_frame);
}

gboolean
nautilus_view_frame_get_can_zoom_in (NautilusViewFrame *view)
{       
	return !view->details->has_max_zoom_level ||
                (view->details->zoom_level
                 < view->details->max_zoom_level);

}

gboolean
nautilus_view_frame_get_can_zoom_out (NautilusViewFrame *view)
{       
	return !view->details->has_min_zoom_level ||
                (view->details->zoom_level
                 > view->details->min_zoom_level);
}


GList *
nautilus_view_frame_get_preferred_zoom_levels (NautilusViewFrame *view)
{
	g_return_val_if_fail (NAUTILUS_IS_VIEW_FRAME (view), NULL);

	if (view->details->zoomable_frame == NULL) {
		return NULL;
	}

	return bonobo_zoomable_frame_get_preferred_zoom_levels (view->details->zoomable_frame);
}

void
nautilus_view_frame_zoom_in (NautilusViewFrame *view)
{
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
 
	if (view->details->zoomable_frame == NULL) {
		return;
	}

	bonobo_zoomable_frame_zoom_in (view->details->zoomable_frame);
}

void
nautilus_view_frame_zoom_out (NautilusViewFrame *view)
{
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
	
	if (view->details->zoomable_frame == NULL) {
		return;
	}

	bonobo_zoomable_frame_zoom_out (view->details->zoomable_frame);
}

void
nautilus_view_frame_zoom_to_fit (NautilusViewFrame *view)
{
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
	
	if (view->details->zoomable_frame == NULL) {
		return;
	}

	bonobo_zoomable_frame_zoom_to_fit (view->details->zoomable_frame);
}

char *
nautilus_view_frame_get_first_visible_file (NautilusViewFrame *view)
{
	Nautilus_URI uri;
	char *ret;

	g_return_val_if_fail (NAUTILUS_IS_VIEW_FRAME (view), NULL);

	ret = NULL;
	if (view->details->positionable) {
		CORBA_Environment ev;
		
		CORBA_exception_init (&ev);
		uri = Nautilus_ScrollPositionable_get_first_visible_file (view->details->positionable, &ev);
		ret = g_strdup (uri);
		CORBA_free (uri);
		CORBA_exception_free (&ev);
	}

	return ret;
}

void
nautilus_view_frame_scroll_to_file (NautilusViewFrame *view,
				    const char        *uri)
{
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));

	if (view->details->positionable) {
		CORBA_Environment ev;
		
		CORBA_exception_init (&ev);

		Nautilus_ScrollPositionable_scroll_to_file (view->details->positionable,
							    uri,
							    &ev);
		CORBA_exception_free (&ev);
	}
}


const char *
nautilus_view_frame_get_view_iid (NautilusViewFrame *view)
{
	g_return_val_if_fail (NAUTILUS_IS_VIEW_FRAME (view), NULL);

	return view->details->view_iid;
}

void
nautilus_view_frame_open_location (NautilusViewFrame *view,
				   const char *location,
				   Nautilus_ViewFrame_OpenMode mode,
				   Nautilus_ViewFrame_OpenFlags flags,
				   GList *selection)
{
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));

	if (view->details->state == VIEW_FRAME_FAILED) {
		return;
	}

	view_frame_wait_is_over (view);
	g_signal_emit (view,
		       signals[OPEN_LOCATION], 0,
		       location, mode, flags, selection);
}

void
nautilus_view_frame_report_location_change (NautilusViewFrame *view,
					    const char *location,
					    GList *selection,
					    const char *title)
{
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));

	if (view->details->state == VIEW_FRAME_FAILED) {
		return;
	}

	g_free (view->details->title);
	view->details->title = g_strdup (title);

	view_frame_wait_is_over (view);
	g_signal_emit (view,
		       signals[REPORT_LOCATION_CHANGE], 0,
		       location, selection, title);
}

void
nautilus_view_frame_report_redirect (NautilusViewFrame *view,
				     const char *from_location,
				     const char *to_location,
				     GList *selection,
				     const char *title)
{
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));

	if (view->details->state == VIEW_FRAME_FAILED) {
		return;
	}

	g_free (view->details->title);
	view->details->title = g_strdup (title);

	view_frame_wait_is_over (view);
	g_signal_emit (view,
		       signals[REPORT_REDIRECT], 0,
		       from_location, to_location, selection, title);
}

void
nautilus_view_frame_report_selection_change (NautilusViewFrame *view,
                                             GList *selection)
{
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));

	if (view->details->state == VIEW_FRAME_FAILED) {
		return;
	}

	view_frame_wait_is_over (view);
	g_signal_emit (view,
			 signals[CHANGE_SELECTION], 0, selection);
}

void
nautilus_view_frame_report_status (NautilusViewFrame *view,
                                   const char *status)
{
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));

	if (view->details->state == VIEW_FRAME_FAILED) {
		return;
	}

	view_frame_wait_is_over (view);
	g_signal_emit (view,
		       signals[CHANGE_STATUS], 0, status);
}

void
nautilus_view_frame_report_load_underway (NautilusViewFrame *view)
{
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
	
	view_frame_underway (view);
}

void
nautilus_view_frame_report_load_progress (NautilusViewFrame *view,
                                          double fraction_done)
{
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));

	if (view->details->state == VIEW_FRAME_FAILED) {
		return;
	}

	view_frame_underway (view);
	g_signal_emit (view,
		       signals[LOAD_PROGRESS_CHANGED], 0);
}

void
nautilus_view_frame_report_load_complete (NautilusViewFrame *view)
{
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));

	view_frame_loaded (view);
}

void
nautilus_view_frame_report_load_failed (NautilusViewFrame *view)
{
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));

	view_frame_failed (view);
}

/* return the Bonobo_Control CORBA object associated with the view frame */
Bonobo_Control
nautilus_view_frame_get_control (NautilusViewFrame *view)
{
	if (view->details->control_frame == NULL) {
		return CORBA_OBJECT_NIL;
	}
	return bonobo_control_frame_get_control (view->details->control_frame);
}

void
nautilus_view_frame_go_back (NautilusViewFrame *view)
{
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));

	g_signal_emit (view, signals[GO_BACK], 0);
}

void
nautilus_view_frame_close_window (NautilusViewFrame *view)
{
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));

	g_signal_emit (view, signals[CLOSE_WINDOW], 0);
}

Nautilus_ShowHiddenFilesMode
nautilus_view_frame_get_show_hidden_files_mode	(NautilusViewFrame   *view)
{
	g_return_val_if_fail (NAUTILUS_IS_VIEW_FRAME (view), 0);

	return view->details->show_hidden_files_mode;
}


void
nautilus_view_frame_set_show_hidden_files_mode (NautilusViewFrame *view,
                                                Nautilus_ShowHiddenFilesMode mode,
						gboolean from_view)
{
	CORBA_Environment ev;
	
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
	view->details->show_hidden_files_mode = mode;
	if (from_view) {
		/* The call was from the the view, propagate to the window */
		g_signal_emit (view, signals[SHOW_HIDDEN_FILES_MODE_CHANGED], 0);
	} else if (view->details->event_source) {
		/* The call was from the window, propagate to all views */
		CORBA_exception_init (&ev);
		
		bonobo_event_source_notify_listeners
			(view->details->event_source,
			 "Bonobo/Property:change:show-hidden-files-mode", NULL, &ev);
		
		if (BONOBO_EX (&ev)) {
			g_warning ("show hidden mode notification failed");
		}

		CORBA_exception_free (&ev);
	}
}

void
nautilus_view_frame_set_title (NautilusViewFrame *view,
                               const char *title)
{
	gboolean changed;

	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));
	g_return_if_fail (title != NULL);

	if (view->details->state == VIEW_FRAME_FAILED) {
		return;
	}

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

	g_free (view->details->title);
	view->details->title = g_strdup (title);

	view_frame_wait_is_over (view);
	if (changed) {
		g_signal_emit (view, signals[TITLE_CHANGED], 0);
	}
}

char *
nautilus_view_frame_get_title (NautilusViewFrame *view)
{
	g_return_val_if_fail (NAUTILUS_IS_VIEW_FRAME (view), NULL);

	return g_strdup (view->details->title);
}

char *
nautilus_view_frame_get_label (NautilusViewFrame *view)
{
	g_return_val_if_fail (NAUTILUS_IS_VIEW_FRAME (view), NULL);

	return g_strdup (view->details->label);
}

void
nautilus_view_frame_set_label (NautilusViewFrame *view,
                               const char *label)
{
	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));

	g_free (view->details->label);
	view->details->label = g_strdup (label);
}

/* Activate the underlying control frame whenever the view is mapped.
 * This causes the view to merge its menu items, for example. For
 * sidebar panels, it might be a little late to merge them at map
 * time. What's a better time?
 */
static void
nautilus_view_frame_map (GtkWidget *view_as_widget)
{
	NautilusViewFrame *view;

	view = NAUTILUS_VIEW_FRAME (view_as_widget);

	EEL_CALL_PARENT (GTK_WIDGET_CLASS, map, (view_as_widget));

	if (view->details->control_frame != NULL) {
		bonobo_control_frame_control_activate (view->details->control_frame);
	}
}

static void
send_history (NautilusViewFrame *view)
{
	Nautilus_History *history;
	CORBA_Environment ev;
	BonoboArg *arg;

	g_return_if_fail (NAUTILUS_IS_VIEW_FRAME (view));

	if (view->details->view == CORBA_OBJECT_NIL) {
		return;
	}

	if (!bonobo_event_source_has_listener
	    (view->details->event_source,
	     "Bonobo/Property:change:history")) {
		return;
	}

	history = get_history_list (view);
	if (history == CORBA_OBJECT_NIL) {
		return;
	}

	CORBA_exception_init (&ev);

	arg = bonobo_arg_new_from (TC_Nautilus_History, history);

	CORBA_free (history);
	
	bonobo_event_source_notify_listeners
		(view->details->event_source,
		 "Bonobo/Property:change:history", arg, &ev);
	
	CORBA_free (arg);

	if (BONOBO_EX (&ev)) {
		view_frame_failed (view);
	}

	CORBA_exception_free (&ev);
}

gboolean
nautilus_view_frame_get_is_view_loaded (NautilusViewFrame *view)
{
	g_return_val_if_fail (NAUTILUS_IS_VIEW_FRAME (view), FALSE);
	
	switch (view->details->state) {
	case VIEW_FRAME_EMPTY:
	case VIEW_FRAME_FAILED:
		return FALSE;
	case VIEW_FRAME_NO_LOCATION:
	case VIEW_FRAME_WAITING:
	case VIEW_FRAME_UNDERWAY:
	case VIEW_FRAME_LOADED:
		return TRUE;
	}

	g_assert_not_reached ();
	return FALSE;
}

static void
nautilus_view_frame_class_init (NautilusViewFrameClass *class)
{
	G_OBJECT_CLASS (class)->finalize = nautilus_view_frame_finalize;
	GTK_OBJECT_CLASS (class)->destroy = nautilus_view_frame_destroy;
	GTK_WIDGET_CLASS (class)->unrealize = nautilus_view_frame_unrealize;
	GTK_WIDGET_CLASS (class)->map = nautilus_view_frame_map;
	
	signals[CHANGE_SELECTION] = g_signal_new
		("change_selection",
		 G_TYPE_FROM_CLASS (class),
		 G_SIGNAL_RUN_LAST,
		 G_STRUCT_OFFSET (NautilusViewFrameClass, 
				  change_selection),
		 NULL, NULL,
		 g_cclosure_marshal_VOID__POINTER,
		 G_TYPE_NONE, 1, G_TYPE_POINTER);
	signals[CHANGE_STATUS] = g_signal_new
		("change_status",
		 G_TYPE_FROM_CLASS (class),
		 G_SIGNAL_RUN_LAST,
		 G_STRUCT_OFFSET (NautilusViewFrameClass, 
				  change_status),
		 NULL, NULL,
		 g_cclosure_marshal_VOID__STRING,
		 G_TYPE_NONE, 1, G_TYPE_STRING);
	signals[FAILED] = g_signal_new
		("failed",
		 G_TYPE_FROM_CLASS (class),
		 G_SIGNAL_RUN_LAST,
		 G_STRUCT_OFFSET (NautilusViewFrameClass, 
				  failed),
		 NULL, NULL,
		 g_cclosure_marshal_VOID__VOID,
		 G_TYPE_NONE, 0);
	signals[GET_HISTORY_LIST] = g_signal_new
		("get_history_list",
		 G_TYPE_FROM_CLASS (class),
		 G_SIGNAL_RUN_LAST,
		 G_STRUCT_OFFSET (NautilusViewFrameClass, 
				  get_history_list),
		 NULL, NULL,
		 nautilus_marshal_POINTER__VOID,
		 G_TYPE_POINTER, 0);
	signals[GO_BACK] = g_signal_new
		("go_back",
		 G_TYPE_FROM_CLASS (class),
		 G_SIGNAL_RUN_LAST,
		 G_STRUCT_OFFSET (NautilusViewFrameClass, 
				  go_back),
		 NULL, NULL,
		 g_cclosure_marshal_VOID__VOID,
		 G_TYPE_NONE, 0);
	signals[CLOSE_WINDOW] = g_signal_new
		("close_window",
		 G_TYPE_FROM_CLASS (class),
		 G_SIGNAL_RUN_LAST,
		 G_STRUCT_OFFSET (NautilusViewFrameClass, 
				  close_window),
		 NULL, NULL,
		 g_cclosure_marshal_VOID__VOID,
		 G_TYPE_NONE, 0);
	signals[LOAD_COMPLETE] = g_signal_new
		("load_complete",
		 G_TYPE_FROM_CLASS (class),
		 G_SIGNAL_RUN_LAST,
		 G_STRUCT_OFFSET (NautilusViewFrameClass, 
				  load_complete),
		 NULL, NULL,
		 g_cclosure_marshal_VOID__VOID,
		 G_TYPE_NONE, 0);
	signals[LOAD_PROGRESS_CHANGED] = g_signal_new
		("load_progress_changed",
		 G_TYPE_FROM_CLASS (class),
		 G_SIGNAL_RUN_LAST,
		 G_STRUCT_OFFSET (NautilusViewFrameClass, 
				  load_progress_changed),
		 NULL, NULL,
		 g_cclosure_marshal_VOID__VOID,
		 G_TYPE_NONE, 0);
	signals[LOAD_UNDERWAY] = g_signal_new
		("load_underway",
		 G_TYPE_FROM_CLASS (class),
		 G_SIGNAL_RUN_LAST,
		 G_STRUCT_OFFSET (NautilusViewFrameClass, 
				  load_underway),
		 NULL, NULL,
		 g_cclosure_marshal_VOID__VOID,
		 G_TYPE_NONE, 0);
	signals[OPEN_LOCATION] = g_signal_new
		("open_location",
		 G_TYPE_FROM_CLASS (class),
		 G_SIGNAL_RUN_LAST,
		 G_STRUCT_OFFSET (NautilusViewFrameClass, 
				  open_location),
		 NULL, NULL,
		 eel_marshal_VOID__STRING_LONG_LONG_POINTER,
		 G_TYPE_NONE, 4, G_TYPE_STRING, G_TYPE_LONG, G_TYPE_LONG, G_TYPE_POINTER);
	signals[REPORT_LOCATION_CHANGE] = g_signal_new
		("report_location_change",
		 G_TYPE_FROM_CLASS (class),
		 G_SIGNAL_RUN_LAST,
		 G_STRUCT_OFFSET (NautilusViewFrameClass, 
				  report_location_change),
		 NULL, NULL,
		 eel_marshal_VOID__STRING_POINTER_STRING,
		 G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_STRING);
	signals[REPORT_REDIRECT] = g_signal_new
		("report_redirect",
		 G_TYPE_FROM_CLASS (class),
		 G_SIGNAL_RUN_LAST,
		 G_STRUCT_OFFSET (NautilusViewFrameClass, 
				  report_redirect),
		 NULL, NULL,
		 eel_marshal_VOID__STRING_STRING_POINTER_STRING,
		 G_TYPE_NONE, 4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_STRING);
	signals[SHOW_HIDDEN_FILES_MODE_CHANGED] = g_signal_new
		("show_hidden_files_mode_changed",
		 G_TYPE_FROM_CLASS (class),
		 G_SIGNAL_RUN_LAST,
		 G_STRUCT_OFFSET (NautilusViewFrameClass, 
				  show_hidden_files_mode_changed),
		 NULL, NULL,
		 g_cclosure_marshal_VOID__VOID,
		 G_TYPE_NONE, 0);
	signals[TITLE_CHANGED] = g_signal_new
		("title_changed",
		 G_TYPE_FROM_CLASS (class),
		 G_SIGNAL_RUN_LAST,
		 G_STRUCT_OFFSET (NautilusViewFrameClass, 
				  title_changed),
		 NULL, NULL,
		 g_cclosure_marshal_VOID__VOID,
		 G_TYPE_NONE, 0);
	signals[VIEW_LOADED] = g_signal_new
		("view_loaded",
		 G_TYPE_FROM_CLASS (class),
		 G_SIGNAL_RUN_LAST,
		 G_STRUCT_OFFSET (NautilusViewFrameClass, 
				  view_loaded),
		 NULL, NULL,
		 g_cclosure_marshal_VOID__VOID,
		 G_TYPE_NONE, 0);
	signals[ZOOM_LEVEL_CHANGED] = g_signal_new
		("zoom_level_changed",
		 G_TYPE_FROM_CLASS (class),
		 G_SIGNAL_RUN_LAST,
		 G_STRUCT_OFFSET (NautilusViewFrameClass, 
				  zoom_level_changed),
		 NULL, NULL,
		 g_cclosure_marshal_VOID__VOID,
		 G_TYPE_NONE, 0);
	signals[ZOOM_PARAMETERS_CHANGED] = g_signal_new
		("zoom_parameters_changed",
		 G_TYPE_FROM_CLASS (class),
		 G_SIGNAL_RUN_LAST,
		 G_STRUCT_OFFSET (NautilusViewFrameClass, 
				  zoom_parameters_changed),
		 NULL, NULL,
		 g_cclosure_marshal_VOID__VOID,
		 G_TYPE_NONE, 0);
}