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
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* Nautilus
*
* Copyright (C) 1999 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-window.c: Implementation of the main window object */
#include "config.h"
#include <gnome.h>
#include "nautilus.h"
static void nautilus_window_class_init (NautilusWindowClass *klass);
static void nautilus_window_init (NautilusWindow *window);
static void nautilus_window_destroy (NautilusWindow *window);
static void nautilus_window_back (NautilusWindow *window);
static void nautilus_window_fwd (NautilusWindow *window);
static void nautilus_window_set_arg (GtkObject *object,
GtkArg *arg,
guint arg_id);
static void nautilus_window_get_arg (GtkObject *object,
GtkArg *arg,
guint arg_id);
static void nautilus_window_close (GtkWidget *widget,
GtkWidget *window);
static void nautilus_window_real_request_location_change (NautilusWindow *window,
Nautilus_NavigationRequestInfo *loc,
GtkWidget *requesting_view);
static void nautilus_window_real_request_selection_change(NautilusWindow *window,
Nautilus_SelectionRequestInfo *loc,
GtkWidget *requesting_view);
#define CONTENTS_AS_HBOX
/* six seconds */
#define STATUSBAR_CLEAR_TIMEOUT 6000
GtkType
nautilus_window_get_type(void)
{
static guint window_type = 0;
if (!window_type)
{
GtkTypeInfo window_info = {
"NautilusWindow",
sizeof(NautilusWindow),
sizeof(NautilusWindowClass),
(GtkClassInitFunc) nautilus_window_class_init,
(GtkObjectInitFunc) nautilus_window_init
};
window_type = gtk_type_unique (gnome_app_get_type(), &window_info);
}
return window_type;
}
typedef void (*GtkSignal_NONE__BOXED_OBJECT) (GtkObject * object,
gpointer arg1,
GtkObject *arg2,
gpointer user_data);
static void
gtk_marshal_NONE__BOXED_OBJECT (GtkObject * object,
GtkSignalFunc func,
gpointer func_data,
GtkArg * args)
{
GtkSignal_NONE__BOXED_OBJECT rfunc;
rfunc = (GtkSignal_NONE__BOXED_OBJECT) func;
(*rfunc) (object,
GTK_VALUE_BOXED (args[0]),
GTK_VALUE_OBJECT (args[1]),
func_data);
}
enum {
ARG_0,
ARG_APP_ID,
ARG_CONTENT_VIEW
};
static void
nautilus_window_class_init (NautilusWindowClass *klass)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
int i;
object_class = (GtkObjectClass*) klass;
object_class->destroy = (void (*)(GtkObject *))nautilus_window_destroy;
object_class->get_arg = nautilus_window_get_arg;
object_class->set_arg = nautilus_window_set_arg;
widget_class = (GtkWidgetClass*) klass;
klass->parent_class = gtk_type_class (gtk_type_parent (object_class->type));
klass->request_location_change = nautilus_window_real_request_location_change;
klass->request_selection_change = nautilus_window_real_request_selection_change;
i = 0;
klass->window_signals[i++] = gtk_signal_new("request_location_change",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (NautilusWindowClass, request_location_change),
gtk_marshal_NONE__BOXED_OBJECT,
GTK_TYPE_NONE, 2, GTK_TYPE_BOXED, GTK_TYPE_OBJECT);
klass->window_signals[i++] = gtk_signal_new("request_selection_change",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (NautilusWindowClass, request_selection_change),
gtk_marshal_NONE__BOXED_OBJECT,
GTK_TYPE_NONE, 2, GTK_TYPE_BOXED, GTK_TYPE_OBJECT);
gtk_object_class_add_signals (object_class, klass->window_signals, i);
gtk_object_add_arg_type ("NautilusWindow::app_id",
GTK_TYPE_STRING,
GTK_ARG_READWRITE|GTK_ARG_CONSTRUCT,
ARG_APP_ID);
gtk_object_add_arg_type ("NautilusWindow::content_view",
GTK_TYPE_OBJECT,
GTK_ARG_READWRITE,
ARG_CONTENT_VIEW);
}
static gboolean
nautilus_window_clear_status(NautilusWindow *window)
{
gtk_statusbar_pop(GTK_STATUSBAR(GNOME_APP(window)->statusbar), window->statusbar_ctx);
window->statusbar_clear_id = 0;
return FALSE;
}
static void
nautilus_window_set_status(NautilusWindow *window, const char *txt)
{
if(window->statusbar_clear_id)
g_source_remove(window->statusbar_clear_id);
gtk_statusbar_pop(GTK_STATUSBAR(GNOME_APP(window)->statusbar), window->statusbar_ctx);
if(txt)
{
window->statusbar_clear_id = g_timeout_add(STATUSBAR_CLEAR_TIMEOUT, (GSourceFunc)nautilus_window_clear_status, window);
gtk_statusbar_push(GTK_STATUSBAR(GNOME_APP(window)->statusbar), window->statusbar_ctx, txt);
}
else
window->statusbar_clear_id = 0;
}
static void
gtk_option_menu_do_resize(GtkWidget *widget, GtkAllocation *size_alloc, GtkWidget *optmenu)
{
gtk_widget_set_usize(optmenu, size_alloc->width, -1);
}
static void
nautilus_window_constructed(NautilusWindow *window)
{
GnomeApp *app;
GnomeUIInfo dummy_menu[] = {
GNOMEUIINFO_END
};
GnomeUIInfo main_menu[] = {
GNOMEUIINFO_SUBTREE_STOCK(N_("_Actions"), dummy_menu, GNOME_STOCK_MENU_JUMP_TO),
GNOMEUIINFO_END
};
GtkWidget *menu_hbox, *menubar, *wtmp, *statusbar;
GtkAccelGroup *ag;
app = GNOME_APP(window);
ag = gtk_accel_group_new();
gtk_object_set_data(GTK_OBJECT(app), "GtkAccelGroup", ag);
gtk_window_add_accel_group(GTK_WINDOW(app), ag);
menu_hbox = gtk_hbox_new(FALSE, GNOME_PAD);
menubar = gtk_menu_bar_new();
gtk_box_pack_end(GTK_BOX(menu_hbox), menubar, TRUE, TRUE, GNOME_PAD_BIG);
gnome_app_fill_menu_with_data(GTK_MENU_SHELL(menubar), main_menu, ag, TRUE, 0, window);
window->option_cvtype = gtk_option_menu_new();
gtk_box_pack_end(GTK_BOX(menu_hbox), window->option_cvtype, TRUE, TRUE, GNOME_PAD_BIG);
gtk_widget_show(window->option_cvtype);
window->menu_cvtype = gtk_menu_new();
gtk_option_menu_set_menu(GTK_OPTION_MENU(window->option_cvtype), window->menu_cvtype);
gtk_signal_connect_while_alive(GTK_OBJECT(window->menu_cvtype), "size_allocate",
GTK_SIGNAL_FUNC(gtk_option_menu_do_resize), window->option_cvtype,
GTK_OBJECT(window->option_cvtype));
wtmp = gtk_menu_item_new_with_label(_("View as blank space"));
gtk_container_add(GTK_CONTAINER(window->menu_cvtype), wtmp);
gtk_widget_show(wtmp);
gtk_option_menu_set_history(GTK_OPTION_MENU(window->option_cvtype), 0);
gtk_widget_queue_resize(window->menu_cvtype);
/* A hacked-up version of gnome_app_set_menu() */
{
GtkWidget *dock_item;
GnomeDockItemBehavior behavior;
behavior = (GNOME_DOCK_ITEM_BEH_EXCLUSIVE
| GNOME_DOCK_ITEM_BEH_NEVER_VERTICAL);
if (!gnome_preferences_get_menubar_detachable())
behavior |= GNOME_DOCK_ITEM_BEH_LOCKED;
dock_item = gnome_dock_item_new (GNOME_APP_MENUBAR_NAME,
behavior);
gtk_container_add (GTK_CONTAINER (dock_item), GTK_WIDGET (menu_hbox));
app->menubar = GTK_WIDGET (menubar);
/* To have menubar relief agree with the toolbar (and have the relief outside of
* smaller handles), substitute the dock item's relief for the menubar's relief,
* but don't change the size of the menubar in the process. */
gtk_menu_bar_set_shadow_type (GTK_MENU_BAR (app->menubar), GTK_SHADOW_NONE);
if (gnome_preferences_get_menubar_relief ()) {
guint border_width;
gtk_container_set_border_width (GTK_CONTAINER (dock_item), 2);
border_width = GTK_CONTAINER (app->menubar)->border_width;
if (border_width >= 2)
border_width -= 2;
gtk_container_set_border_width (GTK_CONTAINER (app->menubar),
border_width);
} else
gnome_dock_item_set_shadow_type (GNOME_DOCK_ITEM (dock_item), GTK_SHADOW_NONE);
if (app->layout != NULL)
gnome_dock_layout_add_item (app->layout,
GNOME_DOCK_ITEM (dock_item),
GNOME_DOCK_TOP,
0, 0, 0);
else
gnome_dock_add_item(GNOME_DOCK(app->dock),
GNOME_DOCK_ITEM (dock_item),
GNOME_DOCK_TOP,
0, 0, 0, TRUE);
gtk_widget_show (menubar);
gtk_widget_show (dock_item);
}
gtk_widget_show (menu_hbox);
gnome_app_set_statusbar(app, (statusbar = gtk_statusbar_new()));
window->statusbar_ctx = gtk_statusbar_get_context_id(GTK_STATUSBAR(statusbar), "IhateGtkStatusbar");
gnome_app_install_menu_hints(app, main_menu); /* This needs a statusbar in order to work */
wtmp = gnome_stock_pixmap_widget(GTK_WIDGET(window), GNOME_STOCK_PIXMAP_BACK);
window->btn_back = gtk_button_new();
gtk_button_set_relief(GTK_BUTTON(window->btn_back), GTK_RELIEF_NONE);
gtk_widget_set_sensitive(window->btn_back, FALSE);
gtk_container_add(GTK_CONTAINER(window->btn_back), wtmp);
gtk_signal_connect(GTK_OBJECT(window->btn_back), "clicked", nautilus_window_back, NULL);
wtmp = gnome_stock_pixmap_widget(GTK_WIDGET(window), GNOME_STOCK_PIXMAP_FORWARD);
window->btn_fwd = gtk_button_new();
gtk_button_set_relief(GTK_BUTTON(window->btn_fwd), GTK_RELIEF_NONE);
gtk_widget_set_sensitive(window->btn_fwd, FALSE);
gtk_container_add(GTK_CONTAINER(window->btn_fwd), wtmp);
gtk_signal_connect(GTK_OBJECT(window->btn_fwd), "clicked", nautilus_window_fwd, NULL);
gtk_box_pack_start(GTK_BOX(menu_hbox), window->btn_back, FALSE, FALSE, GNOME_PAD_SMALL);
gtk_box_pack_start(GTK_BOX(menu_hbox), window->btn_fwd, FALSE, FALSE, GNOME_PAD_SMALL);
gtk_widget_show_all(window->btn_back);
gtk_widget_show_all(window->btn_fwd);
gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, FALSE);
#ifdef CONTENTS_AS_HBOX
window->content_hbox = gtk_hbox_new(FALSE, GNOME_PAD_SMALL);
#else
window->content_hbox = gtk_hpaned_new();
#endif
gnome_app_set_contents(app, window->content_hbox);
window->meta_notebook = gtk_notebook_new();
gtk_widget_show(window->meta_notebook);
#ifdef CONTENTS_AS_HBOX
gtk_box_pack_end(GTK_BOX(window->content_hbox), window->meta_notebook, FALSE, FALSE, GNOME_PAD);
#else
gtk_paned_pack2(GTK_PANED(window->content_hbox), window->meta_notebook, TRUE, TRUE);
#endif
gtk_widget_show_all(window->content_hbox);
}
static void
nautilus_window_set_arg (GtkObject *object,
GtkArg *arg,
guint arg_id)
{
GnomeApp *app = (GnomeApp *) object;
char *old_app_name;
GtkWidget *new_cv;
NautilusWindow *window = (NautilusWindow *) object;
switch(arg_id) {
case ARG_APP_ID:
if(!GTK_VALUE_STRING(*arg))
return;
old_app_name = app->name;
g_free(app->name);
app->name = g_strdup(GTK_VALUE_STRING(*arg));
g_assert(app->name);
g_free(app->prefix);
app->prefix = g_strconcat("/", app->name, "/", NULL);
if(!old_app_name)
nautilus_window_constructed(NAUTILUS_WINDOW(object));
break;
case ARG_CONTENT_VIEW:
new_cv = GTK_WIDGET(GTK_VALUE_OBJECT(*arg));
if(window->content_view)
{
gtk_widget_ref(GTK_WIDGET(window->content_view));
gtk_container_remove(GTK_CONTAINER(window->content_hbox), GTK_WIDGET(window->content_view));
#ifdef CONTENTS_AS_HBOX
gtk_box_pack_start(GTK_BOX(window->content_hbox), new_cv, TRUE, TRUE, GNOME_PAD);
#else
gtk_paned_pack1(GTK_PANED(window->content_hbox), new_cv, TRUE, FALSE);
#endif
gtk_widget_unref(GTK_WIDGET(window->content_view));
}
else
#ifdef CONTENTS_AS_HBOX
gtk_box_pack_start(GTK_BOX(window->content_hbox), new_cv, TRUE, TRUE, GNOME_PAD);
#else
gtk_paned_pack1(GTK_PANED(window->content_hbox), new_cv, TRUE, FALSE);
#endif
gtk_widget_queue_resize(window->content_hbox);
window->content_view = new_cv;
break;
}
}
static void
nautilus_window_get_arg (GtkObject *object,
GtkArg *arg,
guint arg_id)
{
GnomeApp *app = (GnomeApp *) object;
switch(arg_id) {
case ARG_APP_ID:
GTK_VALUE_STRING(*arg) = app->name;
break;
case ARG_CONTENT_VIEW:
GTK_VALUE_OBJECT(*arg) = GTK_OBJECT(((NautilusWindow *)object)->content_view);
break;
}
}
static void
nautilus_window_init (NautilusWindow *window)
{
}
static void nautilus_window_destroy (NautilusWindow *window)
{
g_slist_free(window->meta_views);
g_free(window->current_uri);
g_free(window->actual_current_uri);
g_free(window->current_content_type);
g_slist_foreach(window->uris_prev, (GFunc)g_free, NULL);
g_slist_foreach(window->uris_next, (GFunc)g_free, NULL);
g_slist_free(window->uris_prev);
g_slist_free(window->uris_next);
if(window->statusbar_clear_id)
g_source_remove(window->statusbar_clear_id);
}
GtkWidget *
nautilus_window_new(const char *app_id)
{
return GTK_WIDGET (gtk_object_new (nautilus_window_get_type(), "app_id", app_id, NULL));
}
static void
nautilus_window_close (GtkWidget *widget,
GtkWidget *window)
{
gtk_widget_destroy(window);
}
void
nautilus_window_set_content_view(NautilusWindow *window, NautilusView *content_view)
{
gtk_object_set(GTK_OBJECT(window), "content_view", content_view, NULL);
gtk_widget_show(GTK_WIDGET(content_view));
}
static gboolean
nautilus_window_send_show_properties(GtkWidget *dockitem, GdkEventButton *event, NautilusView *meta_view)
{
if(event->button != 3)
return FALSE;
gtk_signal_emit_stop_by_name(GTK_OBJECT(dockitem), "button_press_event");
gtk_signal_emit_by_name(GTK_OBJECT(meta_view), "show_properties");
return TRUE;
}
void
nautilus_window_add_meta_view(NautilusWindow *window, NautilusView *meta_view)
{
GtkWidget *label;
const char *desc;
char cbuf[32];
g_return_if_fail(!g_slist_find(window->meta_views, meta_view));
g_return_if_fail(NAUTILUS_IS_META_VIEW(meta_view));
desc = nautilus_meta_view_get_description(NAUTILUS_META_VIEW(meta_view));
if(!desc)
{
desc = cbuf;
g_snprintf(cbuf, sizeof(cbuf), "%p", meta_view);
}
label = gtk_label_new(desc);
gtk_widget_show(label);
gtk_signal_connect(GTK_OBJECT(label), "button_press_event",
GTK_SIGNAL_FUNC(nautilus_window_send_show_properties), meta_view);
gtk_notebook_prepend_page(GTK_NOTEBOOK(window->meta_notebook), GTK_WIDGET(meta_view), label);
gtk_widget_show(GTK_WIDGET(meta_view));
window->meta_views = g_slist_prepend(window->meta_views, meta_view);
}
void
nautilus_window_remove_meta_view(NautilusWindow *window, NautilusView *meta_view)
{
gint pagenum;
g_return_if_fail(g_slist_find(window->meta_views, meta_view));
window->meta_views = g_slist_remove(window->meta_views, meta_view);
pagenum = gtk_notebook_page_num(GTK_NOTEBOOK(window->meta_notebook), GTK_WIDGET(meta_view));
g_return_if_fail(pagenum >= 0);
gtk_notebook_remove_page(GTK_NOTEBOOK(window->meta_notebook), pagenum);
}
void
nautilus_window_request_selection_change(NautilusWindow *window,
Nautilus_SelectionRequestInfo *loc,
GtkWidget *requesting_view)
{
NautilusWindowClass *klass;
GtkObject *obj;
obj = GTK_OBJECT(window);
klass = NAUTILUS_WINDOW_CLASS(obj->klass);
gtk_signal_emit(obj, klass->window_signals[1], loc, requesting_view);
}
void
nautilus_window_request_location_change(NautilusWindow *window,
Nautilus_NavigationRequestInfo *loc,
GtkWidget *requesting_view)
{
NautilusWindowClass *klass;
GtkObject *obj;
obj = GTK_OBJECT(window);
klass = NAUTILUS_WINDOW_CLASS(obj->klass);
gtk_signal_emit(obj, klass->window_signals[0], loc, requesting_view);
}
static void
nautilus_window_change_location(NautilusWindow *window,
Nautilus_NavigationRequestInfo *loc,
GtkWidget *requesting_view,
gboolean is_back)
{
guint signum;
GSList *cur;
GSList *discard_views, *keep_views, *notfound_views;
NautilusNavigationInfo loci_spot, *loci;
loci = nautilus_navinfo_new(&loci_spot, loc, window->current_uri, window->actual_current_uri, window->current_content_type,
requesting_view);
if(!loci)
{
char cbuf[1024];
g_snprintf(cbuf, sizeof(cbuf), _("Cannot load %s"), loc->requested_uri);
nautilus_window_set_status(window, cbuf);
return;
}
/* Update history */
if(is_back)
{
window->uris_next = g_slist_prepend(window->uris_next, window->uris_prev->data);
window->uris_prev = g_slist_remove(window->uris_prev, window->uris_prev->data);
}
else
{
char *append_val;
if(window->uris_next && !strcmp(loc->requested_uri, window->uris_next->data))
{
append_val = window->uris_next->data;
window->uris_next = g_slist_remove(window->uris_next, window->uris_next->data);
}
else
{
append_val = g_strdup(loc->requested_uri);
g_slist_foreach(window->uris_next, (GFunc)g_free, NULL);
g_slist_free(window->uris_next); window->uris_next = NULL;
}
window->uris_prev = g_slist_prepend(window->uris_prev, append_val);
}
gtk_widget_set_sensitive(window->btn_back, window->uris_prev?TRUE:FALSE);
gtk_widget_set_sensitive(window->btn_fwd, window->uris_next?TRUE:FALSE);
signum = gtk_signal_lookup("notify_location_change", nautilus_view_get_type());
/* If we need to load a different IID, do that before sending the location change request */
if(strcmp(NAUTILUS_VIEW(window->content_view)->iid, loci->content_iid)) {
NautilusView *new_view;
if(requesting_view == window->content_view)
requesting_view = NULL;
new_view = NAUTILUS_VIEW(gtk_widget_new(nautilus_content_view_get_type(), "main_window", window, NULL));
nautilus_view_load_client(new_view, loci->content_iid);
nautilus_window_set_content_view(window, new_view);
}
loci->navinfo.content_view = NAUTILUS_VIEW(window->content_view)->view_client;
if(requesting_view != window->content_view)
gtk_signal_emit(GTK_OBJECT(window->content_view), signum, loci);
notfound_views = keep_views = discard_views = NULL;
for(cur = window->meta_views; cur; cur = cur->next)
{
NautilusView *view = cur->data;
if(g_slist_find_custom(loci->meta_iids, view->iid, (GCompareFunc)strcmp))
{
if(requesting_view != ((GtkWidget *)view))
gtk_signal_emit(GTK_OBJECT(view), signum, loci);
}
else
{
if(((GtkWidget *)view) == requesting_view)
requesting_view = NULL;
discard_views = g_slist_prepend(discard_views, view);
}
}
for(cur = loci->meta_iids; cur; cur = cur->next)
{
GSList *curview;
for(curview = window->meta_views; curview; curview = curview->next)
{
if(!strcmp(NAUTILUS_VIEW(curview->data)->iid, cur->data))
break;
}
if(!curview)
{
NautilusView *view;
view = NAUTILUS_VIEW(gtk_widget_new(nautilus_meta_view_get_type(), "main_window", window, NULL));
nautilus_view_load_client(view, cur->data);
nautilus_window_add_meta_view(window, view);
gtk_signal_emit(GTK_OBJECT(view), signum, loci, window->content_view);
}
}
for(cur = discard_views; cur; cur = cur->next)
nautilus_window_remove_meta_view(window, cur->data);
g_slist_free(discard_views);
g_free(window->current_content_type);
window->current_content_type = g_strdup(loci->navinfo.content_type);
g_free(window->current_uri);
window->current_uri = g_strdup(loci->navinfo.requested_uri);
g_free(window->actual_current_uri);
window->actual_current_uri = g_strdup(loci->navinfo.actual_uri);
nautilus_navinfo_free(loci);
}
static void nautilus_window_real_request_selection_change(NautilusWindow *window,
Nautilus_SelectionRequestInfo *loc,
GtkWidget *requesting_view)
{
GSList *cur;
guint signum;
Nautilus_SelectionInfo selinfo;
signum = gtk_signal_lookup("notify_selection_change", nautilus_view_get_type());
selinfo.selected_uri = loc->selected_uri;
selinfo.content_view = NAUTILUS_VIEW(window->content_view)->view_client;
if(((GtkWidget *)window->content_view) != requesting_view)
gtk_signal_emit(GTK_OBJECT(window->content_view), signum, &selinfo);
for(cur = window->meta_views; cur; cur = cur->next)
{
if(cur->data != requesting_view)
gtk_signal_emit(GTK_OBJECT(window->content_view), signum, &selinfo);
}
}
static void
nautilus_window_real_request_location_change (NautilusWindow *window,
Nautilus_NavigationRequestInfo *loc,
GtkWidget *requesting_view)
{
nautilus_window_change_location(window, loc, requesting_view, FALSE);
}
void
nautilus_window_save_state(NautilusWindow *window, const char *config_path)
{
GSList *cur;
int n;
guint signum;
char cbuf[1024];
gnome_config_push_prefix(config_path);
if(window->content_view)
{
gnome_config_set_string("content_view_type", NAUTILUS_VIEW(window->content_view)->iid);
g_snprintf(cbuf, sizeof(cbuf), "%s/Content_View/", config_path);
gnome_config_push_prefix(cbuf);
gtk_signal_emit(GTK_OBJECT(window->content_view), signum, cbuf);
gnome_config_pop_prefix();
}
else
gnome_config_set_string("content_view_type", "NONE");
n = g_slist_length(window->meta_views);
signum = gtk_signal_lookup("save_state", nautilus_view_get_type());
for(n = 0, cur = window->meta_views; cur; cur = cur->next, n++)
{
if(!NAUTILUS_VIEW(cur->data)->iid)
{
continue;
n--;
}
g_snprintf(cbuf, sizeof(cbuf), "meta_view_%d_type=0", n);
gnome_config_set_string(cbuf, NAUTILUS_VIEW(cur->data)->iid);
g_snprintf(cbuf, sizeof(cbuf), "%s/Meta_View_%d/", config_path, n);
gnome_config_push_prefix(cbuf);
gtk_signal_emit(GTK_OBJECT(cur->data), signum, cbuf);
gnome_config_pop_prefix();
}
gnome_config_set_int("num_meta_views", n);
gnome_config_pop_prefix();
}
void
nautilus_window_set_initial_state(NautilusWindow *window)
{
GSList *cur;
GtkRequisition sreq;
GdkGeometry geo;
NautilusView *view;
/* Remove old stuff */
for(cur = window->meta_views; cur; cur = cur->next)
nautilus_window_remove_meta_view(window, NAUTILUS_VIEW(cur->data));
view = NAUTILUS_VIEW(gtk_widget_new(nautilus_content_view_get_type(), "main_window", window, NULL));
nautilus_view_load_client(view, "control:clock");
nautilus_window_set_content_view(window, view);
view = NAUTILUS_VIEW(gtk_widget_new(nautilus_meta_view_get_type(), "main_window", window, NULL));
nautilus_view_load_client(view, "control:clock");
nautilus_window_add_meta_view(window, view);
gtk_widget_size_request(GTK_WIDGET(window), &sreq);
gtk_widget_size_request(GTK_WIDGET(window->content_hbox), &sreq);
gtk_widget_size_request(GTK_WIDGET(window->meta_notebook), &sreq);
geo.min_width = window->meta_notebook->requisition.width + MAX(400, GTK_WIDGET(window->content_view)->requisition.width);
geo.min_height = window->meta_notebook->requisition.height + MAX(200, GTK_WIDGET(window->content_view)->requisition.height);
geo.base_width = geo.min_width;
geo.base_height = geo.min_height;
gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geo,
GDK_HINT_BASE_SIZE|GDK_HINT_MIN_SIZE);
gtk_window_set_default_size(GTK_WINDOW(window), geo.min_width, geo.min_height);
#ifndef CONTENTS_AS_HBOX
gtk_paned_set_position(GTK_PANED(window->content_hbox), MAX(400, GTK_WIDGET(window->content_view)->requisition.width));
#endif
}
void
nautilus_window_load_state(NautilusWindow *window, const char *config_path)
{
char *vtype;
GSList *cur;
int i, n;
guint signum;
char cbuf[1024];
/* Remove old stuff */
for(cur = window->meta_views; cur; cur = cur->next)
nautilus_window_remove_meta_view(window, NAUTILUS_VIEW(cur->data));
nautilus_window_set_content_view(window, NULL);
/* Load new stuff */
gnome_config_push_prefix(config_path);
vtype = gnome_config_get_string("content_view_type=NONE");
signum = gtk_signal_lookup("load_state", nautilus_view_get_type());
if(vtype && strcmp(vtype, "NONE")) /* Create new content view */
{
GtkWidget *w;
w = gtk_widget_new(nautilus_content_view_get_type(), "main_window", window, NULL);
nautilus_view_load_client(NAUTILUS_VIEW(w), vtype);
nautilus_window_set_content_view(window, NAUTILUS_VIEW(w));
g_snprintf(cbuf, sizeof(cbuf), "%s/Content_View/", config_path);
gnome_config_push_prefix(cbuf);
gtk_signal_emit(GTK_OBJECT(w), signum, cbuf);
gnome_config_pop_prefix();
gtk_widget_show(w);
}
g_free(vtype);
n = gnome_config_get_int("num_meta_views=0");
for(i = 0; i < n; n++)
{
GtkWidget *nvw;
g_snprintf(cbuf, sizeof(cbuf), "%s/meta_view_%d_type=0", config_path, i);
vtype = gnome_config_get_string(cbuf);
nvw = gtk_widget_new(nautilus_meta_view_get_type(), "main_window", window, NULL);
nautilus_view_load_client(NAUTILUS_VIEW(nvw), vtype);
g_snprintf(cbuf, sizeof(cbuf), "%s/Meta_View_%d/", config_path, i);
gnome_config_push_prefix(cbuf);
gtk_signal_emit(GTK_OBJECT(cur->data), signum, cbuf);
gnome_config_pop_prefix();
nautilus_window_add_meta_view(window, NAUTILUS_VIEW(nvw));
}
gnome_config_pop_prefix();
}
static void
nautilus_window_back (NautilusWindow *window)
{
Nautilus_NavigationRequestInfo nri;
g_assert(window->uris_prev);
memset(&nri, 0, sizeof(nri));
nri.requested_uri = window->uris_prev->data;
nri.new_window_default = nri.new_window_suggested = nri.new_window_enforced = Nautilus_V_FALSE;
nautilus_window_change_location(window, &nri, NULL, TRUE);
}
static void
nautilus_window_fwd (NautilusWindow *window)
{
Nautilus_NavigationRequestInfo nri;
g_assert(window->uris_next);
memset(&nri, 0, sizeof(nri));
nri.requested_uri = window->uris_next->data;
nri.new_window_default = nri.new_window_suggested = nri.new_window_enforced = Nautilus_V_FALSE;
nautilus_window_change_location(window, &nri, NULL, FALSE);
}
|