nautilus-spatial-window.c 21.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/* -*- 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 */

Elliot Lee's avatar
Elliot Lee committed
27 28 29
#include "config.h"
#include <gnome.h>
#include "nautilus.h"
30
#include "explorer-location-bar.h"
31
#include "ntl-window-private.h"
Elliot Lee's avatar
Elliot Lee committed
32

33 34
static int window_count = 0;

35
/* Stuff for handling the CORBA interface */
36 37 38 39 40 41 42 43 44 45 46 47
typedef struct {
  POA_Nautilus_ViewWindow servant;
  gpointer gnome_object;

  NautilusWindow *window;
} impl_POA_Nautilus_ViewWindow;

static POA_Nautilus_ViewWindow__epv impl_Nautilus_ViewWindow_epv =
{
  NULL
};

48
static PortableServer_ServantBase__epv base_epv = { NULL, NULL, NULL };
49 50 51 52 53 54 55 56

static POA_Nautilus_ViewWindow__vepv impl_Nautilus_ViewWindow_vepv =
{
   &base_epv,
   NULL,
   &impl_Nautilus_ViewWindow_epv
};

57

58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
static void
impl_Nautilus_ViewWindow__destroy(GnomeObject *obj, impl_POA_Nautilus_ViewWindow *servant)
{
   PortableServer_ObjectId *objid;
   CORBA_Environment ev;

   CORBA_exception_init(&ev);

   objid = PortableServer_POA_servant_to_id(bonobo_poa(), servant, &ev);
   PortableServer_POA_deactivate_object(bonobo_poa(), objid, &ev);
   CORBA_free(objid);
   obj->servant = NULL;

   POA_Nautilus_ViewWindow__fini((PortableServer_Servant) servant, &ev);
   g_free(servant);
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
   CORBA_exception_free(&ev);
}

static GnomeObject *
impl_Nautilus_ViewWindow__create(NautilusWindow *window)
{
   GnomeObject *retval;
   impl_POA_Nautilus_ViewWindow *newservant;
   CORBA_Environment ev;

   CORBA_exception_init(&ev);

   newservant = g_new0(impl_POA_Nautilus_ViewWindow, 1);
   newservant->servant.vepv = &impl_Nautilus_ViewWindow_vepv;
   newservant->window = window;
   POA_Nautilus_ViewWindow__init((PortableServer_Servant) newservant, &ev);

   retval = gnome_object_new_from_servant(newservant);

   gtk_signal_connect(GTK_OBJECT(retval), "destroy", GTK_SIGNAL_FUNC(impl_Nautilus_ViewWindow__destroy), newservant);
   CORBA_exception_free(&ev);

   return retval;
}

Elliot Lee's avatar
Elliot Lee committed
99 100
static void nautilus_window_class_init (NautilusWindowClass *klass);
static void nautilus_window_init (NautilusWindow *window);
101
static void nautilus_window_destroy (NautilusWindow *window);
102 103
static void nautilus_window_back (GtkWidget *btn, NautilusWindow *window);
static void nautilus_window_fwd (GtkWidget *btn, NautilusWindow *window);
Elliot Lee's avatar
Elliot Lee committed
104
static void nautilus_window_set_arg (GtkObject      *object,
105 106
                                     GtkArg         *arg,
                                     guint	      arg_id);
Elliot Lee's avatar
Elliot Lee committed
107
static void nautilus_window_get_arg (GtkObject      *object,
108 109
                                     GtkArg         *arg,
                                     guint	      arg_id);
110 111
static void nautilus_window_goto_uri_cb (GtkWidget *widget,
                                         const char *uri,
112
                                         GtkWidget *window);
Elliot Lee's avatar
Elliot Lee committed
113

114 115
#undef CONTENTS_AS_HBOX

116 117
/* milliseconds */
#define STATUSBAR_CLEAR_TIMEOUT 5000
118

119 120 121 122 123 124 125 126 127 128 129 130
/* menu definitions */

static void
file_menu_close_cb (GtkWidget *widget,
	       gpointer data)
{
	GtkWidget *window;

	window = GTK_WIDGET (data);
	gtk_widget_destroy(window);
}

131 132 133 134
static void
file_menu_new_window_cb (GtkWidget *widget,
	       gpointer data)
{
135 136 137 138 139 140 141 142 143 144 145
  GtkWidget *current_mainwin;
  GtkWidget *new_mainwin;
  
  current_mainwin = (GtkWidget *)(data);

  new_mainwin = gtk_widget_new(nautilus_window_get_type(), "app_id", "nautilus", NULL);

  nautilus_window_goto_uri(NAUTILUS_WINDOW(new_mainwin), 
                           nautilus_window_get_requested_uri(NAUTILUS_WINDOW(current_mainwin)));

  gtk_widget_show(new_mainwin);
146 147
}

148 149 150 151 152 153 154 155
static void
file_menu_exit_cb (GtkWidget *widget,
	       gpointer data)
{
	gtk_main_quit();
}

static GnomeUIInfo file_menu_info[] = {
156 157 158 159 160 161 162
	{
	    GNOME_APP_UI_ITEM,
	    N_("New Window"), N_("Create a new window"),
	    file_menu_new_window_cb, NULL, NULL,
	    GNOME_APP_PIXMAP_NONE, NULL,
	    'N', GDK_CONTROL_MASK, NULL
	},
163 164 165 166 167 168
	GNOMEUIINFO_MENU_CLOSE_ITEM(file_menu_close_cb,NULL),
	GNOMEUIINFO_SEPARATOR,
	GNOMEUIINFO_MENU_EXIT_ITEM(file_menu_exit_cb,NULL),
	GNOMEUIINFO_END
};

169 170 171
/* FIXME: These all need implementation, though we might end up doing that
 * separately for each content view (and merging with the insensitive items here)
 */
172 173 174 175 176 177 178 179
static GnomeUIInfo edit_menu_info[] = {
	GNOMEUIINFO_MENU_UNDO_ITEM(NULL, NULL),
	GNOMEUIINFO_SEPARATOR,
	GNOMEUIINFO_MENU_CUT_ITEM(NULL, NULL),
	GNOMEUIINFO_MENU_COPY_ITEM(NULL, NULL),
	GNOMEUIINFO_MENU_PASTE_ITEM(NULL, NULL),
	GNOMEUIINFO_MENU_CLEAR_ITEM(NULL, NULL),
	GNOMEUIINFO_SEPARATOR,
180
	/* Didn't use standard SELECT_ALL_ITEM 'cuz it didn't have accelerator */
181 182 183 184 185 186 187 188 189 190
	{
	    GNOME_APP_UI_ITEM,
	    N_("Select All"), NULL,
	    NULL, NULL, NULL,
	    GNOME_APP_PIXMAP_NONE, NULL,
	    'A', GDK_CONTROL_MASK, NULL
	},
	GNOMEUIINFO_END
};

191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
/* FIXME: This needs implementation. */
static GnomeUIInfo bookmarks_menu_info[] = {
        {
            GNOME_APP_UI_ITEM,
            N_("Add Bookmark"), N_("Create a new bookmark for the current location"),
            NULL, NULL, NULL,
            GNOME_APP_PIXMAP_NONE, NULL,
            0, 0, NULL
        },
        {
            GNOME_APP_UI_ITEM,
            N_("Edit Bookmarks..."), N_("Open the bookmark-editing window"),
            NULL, NULL, NULL,
            GNOME_APP_PIXMAP_NONE, NULL,
            0, 0, NULL
        },
	GNOMEUIINFO_SEPARATOR,
	GNOMEUIINFO_END
};

/* FIXME: This needs implementation. */
212 213 214 215 216 217 218 219 220 221 222
static GnomeUIInfo help_menu_info[] = {
        {
            GNOME_APP_UI_ITEM,
            N_("About Nautilus..."), N_("Info about the Nautilus program"),
            NULL, NULL, NULL,
            GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_ABOUT,
            0, 0, NULL
        },
	GNOMEUIINFO_END
};

223 224
static GnomeUIInfo main_menu[] = {
	GNOMEUIINFO_MENU_FILE_TREE (file_menu_info),
225
	GNOMEUIINFO_MENU_EDIT_TREE (edit_menu_info),
226
	GNOMEUIINFO_SUBTREE(N_("_Bookmarks"), bookmarks_menu_info),
227
	GNOMEUIINFO_MENU_HELP_TREE (help_menu_info),
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
	GNOMEUIINFO_END
};

/* toolbar definitions */

static GnomeUIInfo toolbar_info[] = {
	GNOMEUIINFO_ITEM_STOCK
		(N_("Back"), N_("Go to the previously visited directory"),
		 nautilus_window_back, GNOME_STOCK_PIXMAP_BACK),
	GNOMEUIINFO_ITEM_STOCK
		(N_("Forward"), N_("Go to the next directory"),
		 nautilus_window_fwd, GNOME_STOCK_PIXMAP_FORWARD),
	GNOMEUIINFO_END
};

Elliot Lee's avatar
Elliot Lee committed
243 244 245 246 247 248 249
GtkType
nautilus_window_get_type(void)
{
  static guint window_type = 0;

  if (!window_type)
    {
250 251
      GtkTypeInfo window_info =
      {
Elliot Lee's avatar
Elliot Lee committed
252 253 254 255
	"NautilusWindow",
	sizeof(NautilusWindow),
	sizeof(NautilusWindowClass),
	(GtkClassInitFunc) nautilus_window_class_init,
256 257 258 259
	(GtkObjectInitFunc) nautilus_window_init,
        NULL,
        NULL,
        NULL
Elliot Lee's avatar
Elliot Lee committed
260 261 262 263 264 265 266 267
      };

      window_type = gtk_type_unique (gnome_app_get_type(), &window_info);
    }

  return window_type;
}

Elliot Lee's avatar
Elliot Lee committed
268 269
typedef void (*GtkSignal_NONE__BOXED_OBJECT) (GtkObject * object,
					       gpointer arg1,
Elliot Lee's avatar
Elliot Lee committed
270 271 272
					       GtkObject *arg2,
					       gpointer user_data);
static void 
Elliot Lee's avatar
Elliot Lee committed
273
gtk_marshal_NONE__BOXED_OBJECT (GtkObject * object,
Elliot Lee's avatar
Elliot Lee committed
274 275 276 277
			       GtkSignalFunc func,
			       gpointer func_data,
			       GtkArg * args)
{
Elliot Lee's avatar
Elliot Lee committed
278 279
  GtkSignal_NONE__BOXED_OBJECT rfunc;
  rfunc = (GtkSignal_NONE__BOXED_OBJECT) func;
Elliot Lee's avatar
Elliot Lee committed
280
  (*rfunc) (object,
Elliot Lee's avatar
Elliot Lee committed
281
	    GTK_VALUE_BOXED (args[0]),
Elliot Lee's avatar
Elliot Lee committed
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
	    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;
300
  object_class->destroy = (void (*)(GtkObject *))nautilus_window_destroy;
Elliot Lee's avatar
Elliot Lee committed
301 302 303 304 305 306 307
  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;
Elliot Lee's avatar
Elliot Lee committed
308
  klass->request_selection_change = nautilus_window_real_request_selection_change;
Elliot Lee's avatar
Elliot Lee committed
309
  klass->request_status_change = nautilus_window_real_request_status_change;
Elliot Lee's avatar
Elliot Lee committed
310 311 312 313 314 315

  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),
Elliot Lee's avatar
Elliot Lee committed
316 317 318 319 320 321 322 323
					      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);
Elliot Lee's avatar
Elliot Lee committed
324 325 326 327 328 329
  klass->window_signals[i++] = gtk_signal_new("request_status_change",
					      GTK_RUN_LAST,
					      object_class->type,
					      GTK_SIGNAL_OFFSET (NautilusWindowClass, request_status_change),
					      gtk_marshal_NONE__BOXED_OBJECT,
					      GTK_TYPE_NONE, 2, GTK_TYPE_BOXED, GTK_TYPE_OBJECT);
Elliot Lee's avatar
Elliot Lee committed
330 331 332 333 334 335 336 337 338 339
  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);
340
  impl_Nautilus_ViewWindow_vepv.GNOME_Unknown_epv = gnome_object_get_epv();
Elliot Lee's avatar
Elliot Lee committed
341 342
}

343 344 345 346 347 348 349 350
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;
}

351
void
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
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;
}

367
void
368
nautilus_window_goto_uri(NautilusWindow *window, const char *uri)
369 370 371 372
{
  Nautilus_NavigationRequestInfo navinfo;

  memset(&navinfo, 0, sizeof(navinfo));
373
  navinfo.requested_uri = (char *)uri;
374
  navinfo.new_window_default = navinfo.new_window_suggested = Nautilus_V_FALSE;
Elliot Lee's avatar
Elliot Lee committed
375
  navinfo.new_window_enforced = Nautilus_V_UNKNOWN;
376

377
  nautilus_window_request_location_change(window, &navinfo, NULL);
378 379
}

380
static void
381 382
nautilus_window_goto_uri_cb (GtkWidget *widget,
                          const char *uri,
383 384
                          GtkWidget *window)
{
385
  nautilus_window_goto_uri(NAUTILUS_WINDOW(window), uri);
386 387
}

388 389 390 391 392 393 394
const char *
nautilus_window_get_requested_uri (NautilusWindow *window)
{
  return window->ni->requested_uri;
}


Elliot Lee's avatar
Elliot Lee committed
395
static void
396
gtk_option_menu_do_resize(GtkWidget *widget, GtkWidget *child, GtkWidget *optmenu)
Elliot Lee's avatar
Elliot Lee committed
397
{
398 399 400 401
  GtkRequisition req;
  gtk_widget_size_request(widget, &req);

  gtk_widget_set_usize(optmenu, req.width, -1);
Elliot Lee's avatar
Elliot Lee committed
402 403
}

Elliot Lee's avatar
Elliot Lee committed
404 405 406 407
static void
nautilus_window_constructed(NautilusWindow *window)
{
  GnomeApp *app;
Elliot Lee's avatar
Elliot Lee committed
408
  GtkWidget *location_bar_box, *statusbar;
Elliot Lee's avatar
Elliot Lee committed
409

410 411
  g_message("XXX Constructed.\n");
  
Elliot Lee's avatar
Elliot Lee committed
412 413
  app = GNOME_APP(window);

414
  /* set up menu bar */
415
  gnome_app_create_menus_with_data(app, main_menu, window);
416

417 418 419 420 421 422 423 424 425 426 427 428
  /* desensitize the items that haven't yet been implemented
   * FIXME: these all need to be implemented. I'm using hardwired numbers
   * rather than enum symbols here just 'cuz the enums aren't needed (I think)
   * once we've implemented things. If it turns out they are, we'll define 'em.
   */

  gtk_widget_set_sensitive(edit_menu_info[0].widget, FALSE); /* Undo */
  gtk_widget_set_sensitive(edit_menu_info[2].widget, FALSE); /* Cut */
  gtk_widget_set_sensitive(edit_menu_info[3].widget, FALSE); /* Copy */
  gtk_widget_set_sensitive(edit_menu_info[4].widget, FALSE); /* Paste */
  gtk_widget_set_sensitive(edit_menu_info[5].widget, FALSE); /* Clear */
  gtk_widget_set_sensitive(edit_menu_info[7].widget, FALSE); /* Select All */
429

430 431
  gtk_widget_set_sensitive(bookmarks_menu_info[0].widget, FALSE); /* Add Bookmark */
  gtk_widget_set_sensitive(bookmarks_menu_info[1].widget, FALSE); /* Edit Bookmarks */
432

433
  gtk_widget_set_sensitive(help_menu_info[0].widget, FALSE); /* About */
434

435
  /* set up toolbar */
436

437
  gnome_app_create_toolbar_with_data(app, toolbar_info, window);
438 439 440
  window->btn_back = toolbar_info[0].widget;
  window->btn_fwd = toolbar_info[1].widget;

441
  /* set up location bar */
Elliot Lee's avatar
Elliot Lee committed
442

Elliot Lee's avatar
Elliot Lee committed
443 444
  window->option_cvtype = gtk_option_menu_new();
  window->menu_cvtype = gtk_menu_new();
445 446 447
  /* FIXME: Add in placeholder item for now; rework this when we get the right views showing up.
   * Since menu doesn't yet work, make it insensitive.
   */
448 449 450
  gtk_container_add(GTK_CONTAINER(window->menu_cvtype), 
  	gtk_menu_item_new_with_label(_("View as (placeholder)")));
  gtk_widget_set_sensitive(window->option_cvtype, FALSE);
451 452 453 454

  location_bar_box = gtk_hbox_new(FALSE, GNOME_PAD);
  gtk_container_set_border_width(GTK_CONTAINER(location_bar_box), GNOME_PAD_SMALL);

455 456 457 458 459
  window->ent_uri = explorer_location_bar_new();
  gtk_signal_connect(GTK_OBJECT(window->ent_uri), "location_changed",
                     nautilus_window_goto_uri_cb, window);
  gtk_box_pack_start(GTK_BOX(location_bar_box), window->ent_uri, TRUE, TRUE, GNOME_PAD);
  gnome_app_add_docked(app, location_bar_box, "uri-entry",
460 461 462
  					   GNOME_DOCK_ITEM_BEH_LOCKED|GNOME_DOCK_ITEM_BEH_EXCLUSIVE|GNOME_DOCK_ITEM_BEH_NEVER_VERTICAL,
                       GNOME_DOCK_TOP, 2, 0, 0);

463
  gtk_widget_show_all(window->menu_cvtype);
Elliot Lee's avatar
Elliot Lee committed
464
  gtk_option_menu_set_menu(GTK_OPTION_MENU(window->option_cvtype), window->menu_cvtype);
465
  gtk_option_menu_set_history(GTK_OPTION_MENU(window->option_cvtype), 0);
466
  gtk_box_pack_end(GTK_BOX(location_bar_box), window->option_cvtype, FALSE, FALSE, GNOME_PAD_BIG);
467
  gtk_widget_show(window->option_cvtype);
468
  gtk_widget_show_all(location_bar_box);
469

470 471 472 473
  /* For mysterious reasons, connecting these signals before laying out the menu
   * and option menu ends up making the option menu not know how to size itself (i.e, 
   * it is zero-width unless you turn on expand and fill). So we do it here afterwards.
   */
474 475 476 477
  gtk_signal_connect_while_alive(GTK_OBJECT(window->menu_cvtype), "add",
                                 GTK_SIGNAL_FUNC(gtk_option_menu_do_resize), window->option_cvtype,
                                 GTK_OBJECT(window->option_cvtype));
  gtk_signal_connect_while_alive(GTK_OBJECT(window->menu_cvtype), "remove",
Elliot Lee's avatar
Elliot Lee committed
478 479
                                 GTK_SIGNAL_FUNC(gtk_option_menu_do_resize), window->option_cvtype,
                                 GTK_OBJECT(window->option_cvtype));
480

481
  /* set up status bar */
Elliot Lee's avatar
Elliot Lee committed
482

483 484 485 486
  /* FIXME: The text in the statusbar is jammed up against the left edge of the frame.
   * This looks ugly, but appears to be "standard appearance" in GTK.
   * I haven't found a good workaround yet.
   */
487 488
  gnome_app_set_statusbar(app, (statusbar = gtk_statusbar_new()));
  window->statusbar_ctx = gtk_statusbar_get_context_id(GTK_STATUSBAR(statusbar), "IhateGtkStatusbar");
Elliot Lee's avatar
Elliot Lee committed
489 490 491
  gnome_app_install_menu_hints(app, main_menu); /* This has to go here
                                                   after the statusbar
                                                   creation */
492

493
  /* set up window contents and policy */
Elliot Lee's avatar
Elliot Lee committed
494 495

  gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, FALSE);
Elliot Lee's avatar
Elliot Lee committed
496
  gtk_window_set_default_size(GTK_WINDOW(window), 650, 400);
Elliot Lee's avatar
Elliot Lee committed
497

498 499 500
#ifdef CONTENTS_AS_HBOX
  window->content_hbox = gtk_hbox_new(FALSE, GNOME_PAD_SMALL);
#else
Elliot Lee's avatar
Elliot Lee committed
501
  window->content_hbox = gtk_hpaned_new();
502
#endif
Elliot Lee's avatar
Elliot Lee committed
503 504
  gnome_app_set_contents(app, window->content_hbox);

505 506 507
  window->meta_notebook = gtk_notebook_new();
  gtk_widget_show(window->meta_notebook);
#ifdef CONTENTS_AS_HBOX
508
  gtk_box_pack_start(GTK_BOX(window->content_hbox), window->meta_notebook, FALSE, FALSE, GNOME_PAD);
Elliot Lee's avatar
Elliot Lee committed
509
#else
510
  gtk_paned_pack1(GTK_PANED(window->content_hbox), window->meta_notebook, TRUE, TRUE);
Elliot Lee's avatar
Elliot Lee committed
511
#endif
512
  gtk_widget_show_all(window->content_hbox);
513 514


515 516 517 518 519
  /* CORBA stuff */
  window->ntl_viewwindow = impl_Nautilus_ViewWindow__create(window);
  window->uih = gnome_ui_handler_new();
  gnome_ui_handler_set_app(window->uih, app);
  gnome_object_add_interface(GNOME_OBJECT(window->uih), window->ntl_viewwindow);
Elliot Lee's avatar
Elliot Lee committed
520 521 522 523 524 525 526 527 528
}

static void
nautilus_window_set_arg (GtkObject      *object,
			  GtkArg         *arg,
			  guint	      arg_id)
{
  GnomeApp *app = (GnomeApp *) object;
  char *old_app_name;
529
  NautilusView *new_cv;
Elliot Lee's avatar
Elliot Lee committed
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546
  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:
547
    new_cv = NAUTILUS_VIEW(GTK_VALUE_OBJECT(*arg));
Elliot Lee's avatar
Elliot Lee committed
548 549 550 551
    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));
552
#ifdef CONTENTS_AS_HBOX
553
	gtk_box_pack_end(GTK_BOX(window->content_hbox), GTK_WIDGET(new_cv), TRUE, TRUE, GNOME_PAD);
Elliot Lee's avatar
Elliot Lee committed
554
#else
555
        gtk_paned_pack2(GTK_PANED(window->content_hbox), GTK_WIDGET(new_cv), TRUE, FALSE);
Elliot Lee's avatar
Elliot Lee committed
556 557 558 559
#endif
	gtk_widget_unref(GTK_WIDGET(window->content_view));
      }
    else
560
#ifdef CONTENTS_AS_HBOX
561
      gtk_box_pack_end(GTK_BOX(window->content_hbox), GTK_WIDGET(new_cv), TRUE, TRUE, GNOME_PAD);
Elliot Lee's avatar
Elliot Lee committed
562
#else
563
      gtk_paned_pack2(GTK_PANED(window->content_hbox), GTK_WIDGET(new_cv), TRUE, FALSE);
Elliot Lee's avatar
Elliot Lee committed
564
#endif
565 566

    gtk_widget_queue_resize(window->content_hbox);
Elliot Lee's avatar
Elliot Lee committed
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
    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)
{
592
  window_count++;
Elliot Lee's avatar
Elliot Lee committed
593 594
}

595 596 597
static void nautilus_window_destroy (NautilusWindow *window)
{
  g_slist_free(window->meta_views);
598 599
  CORBA_free(window->ni);
  CORBA_free(window->si);
600 601 602 603 604 605 606
  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);
607 608 609 610 611

  if(--window_count <= 0) 
    {
      gtk_main_quit();
    }
612 613
}

Elliot Lee's avatar
Elliot Lee committed
614 615 616 617 618 619 620
GtkWidget *
nautilus_window_new(const char *app_id)
{
  return GTK_WIDGET (gtk_object_new (nautilus_window_get_type(), "app_id", app_id, NULL));
}

static gboolean
621
nautilus_window_send_show_properties(GtkWidget *dockitem, GdkEventButton *event, NautilusView *meta_view)
Elliot Lee's avatar
Elliot Lee committed
622 623 624 625 626 627
{
  if(event->button != 3)
    return FALSE;

  gtk_signal_emit_stop_by_name(GTK_OBJECT(dockitem), "button_press_event");

628
  gtk_signal_emit_by_name(GTK_OBJECT(meta_view), "show_properties");
Elliot Lee's avatar
Elliot Lee committed
629 630 631 632

  return TRUE;
}

633 634 635 636 637 638 639
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));
}

Elliot Lee's avatar
Elliot Lee committed
640
void
641
nautilus_window_add_meta_view(NautilusWindow *window, NautilusView *meta_view)
Elliot Lee's avatar
Elliot Lee committed
642 643
{
  GtkWidget *label;
644 645
  const char *desc;
  char cbuf[32];
Elliot Lee's avatar
Elliot Lee committed
646

647 648
  g_return_if_fail(!g_slist_find(window->meta_views, meta_view));
  g_return_if_fail(NAUTILUS_IS_META_VIEW(meta_view));
Elliot Lee's avatar
Elliot Lee committed
649

650
  desc = nautilus_meta_view_get_label(NAUTILUS_META_VIEW(meta_view));
651 652 653 654 655 656
  if(!desc)
    {
      desc = cbuf;
      g_snprintf(cbuf, sizeof(cbuf), "%p", meta_view);
    }
  label = gtk_label_new(desc);
Elliot Lee's avatar
Elliot Lee committed
657
  gtk_widget_show(label);
658 659 660 661
  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));
Elliot Lee's avatar
Elliot Lee committed
662

663
  window->meta_views = g_slist_prepend(window->meta_views, meta_view);
Elliot Lee's avatar
Elliot Lee committed
664 665 666
}

void
667
nautilus_window_remove_meta_view(NautilusWindow *window, NautilusView *meta_view)
Elliot Lee's avatar
Elliot Lee committed
668 669 670
{
  gint pagenum;

671
  g_return_if_fail(g_slist_find(window->meta_views, meta_view));
Elliot Lee's avatar
Elliot Lee committed
672

673
  window->meta_views = g_slist_remove(window->meta_views, meta_view);
Elliot Lee's avatar
Elliot Lee committed
674

675
  pagenum = gtk_notebook_page_num(GTK_NOTEBOOK(window->meta_notebook), GTK_WIDGET(meta_view));
Elliot Lee's avatar
Elliot Lee committed
676 677 678

  g_return_if_fail(pagenum >= 0);

679
  gtk_notebook_remove_page(GTK_NOTEBOOK(window->meta_notebook), pagenum);
Elliot Lee's avatar
Elliot Lee committed
680 681
}

682
static void
683
nautilus_window_back (GtkWidget *btn, NautilusWindow *window)
684
{
Elliot Lee's avatar
Elliot Lee committed
685
  Nautilus_NavigationRequestInfo nri;
686 687 688

  g_assert(window->uris_prev);

Elliot Lee's avatar
Elliot Lee committed
689
  memset(&nri, 0, sizeof(nri));
690
  nri.requested_uri = window->uris_prev->data;
Elliot Lee's avatar
Elliot Lee committed
691
  nri.new_window_default = nri.new_window_suggested = nri.new_window_enforced = Nautilus_V_FALSE;
692

Elliot Lee's avatar
Elliot Lee committed
693
  nautilus_window_change_location(window, &nri, NULL, TRUE);
694 695 696
}

static void
697
nautilus_window_fwd (GtkWidget *btn, NautilusWindow *window)
698
{
Elliot Lee's avatar
Elliot Lee committed
699
  Nautilus_NavigationRequestInfo nri;
700 701 702

  g_assert(window->uris_next);

Elliot Lee's avatar
Elliot Lee committed
703
  memset(&nri, 0, sizeof(nri));
704
  nri.requested_uri = window->uris_next->data;
Elliot Lee's avatar
Elliot Lee committed
705 706
  nri.new_window_default = nri.new_window_suggested = nri.new_window_enforced = Nautilus_V_FALSE;
  nautilus_window_change_location(window, &nri, NULL, FALSE);
Elliot Lee's avatar
Elliot Lee committed
707
}