nautilus-application.c 3.25 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, 2000 Red Hat, Inc.
 *  Copyright (C) 2000 Eazel, 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>,
 *
 */

27
#include "nautilus.h"
28
#include <libnautilus/libnautilus.h>
29 30
#include "file-manager/fm-directory-view-icons.h"
#include "file-manager/fm-directory-view-list.h"
31 32 33

static int window_count = 0;

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

static BonoboObject *
nautilus_make_object(BonoboGenericFactory *gfact, const char *goad_id, gpointer closure)
{
        FMDirectoryView *dir_view;
        NautilusContentViewFrame *view_frame;
        
        g_return_val_if_fail (strcmp (goad_id, "ntl_file_manager_icon_view") == 0 ||
			      strcmp (goad_id, "ntl_file_manager_list_view") == 0, NULL);
        
        if (strcmp (goad_id, "ntl_file_manager_icon_view") == 0)
                 dir_view = FM_DIRECTORY_VIEW (gtk_object_new (fm_directory_view_icons_get_type (), NULL));
        else
                 dir_view = FM_DIRECTORY_VIEW (gtk_object_new (fm_directory_view_list_get_type (), NULL));
        
        g_return_val_if_fail(dir_view, NULL);
        
        view_frame = fm_directory_view_get_view_frame (dir_view);
        
53
        return BONOBO_OBJECT (view_frame);
54 55 56
}


57 58 59 60 61 62 63 64 65 66 67
/**
 * nautilus_app_exiting:
 * 
 * Called after the main event loop has finished, just before the
 * program ends. Don't call from anywhere else.
 **/
void
nautilus_app_exiting()
{
  /* Do those things that gotta be done just once before quitting */
  nautilus_prefs_save();
68
  nautilus_bookmarks_exiting();
69 70
}

71
void
72
nautilus_app_init(const char *initial_url)
73 74 75
{
  NautilusWindow *mainwin;

76
  nautilus_navinfo_init();
77
  nautilus_prefs_load();
78

79 80 81
  /* Create our CORBA objects */
  bonobo_generic_factory_new_multi("ntl_file_manager_factory", nautilus_make_object, NULL);

82 83 84
  /* Set default configuration */
  mainwin = nautilus_app_create_window();
  bonobo_activate();
85
  nautilus_window_set_initial_state(mainwin, initial_url);
86 87 88 89 90 91 92 93
}

static void
nautilus_app_destroy_window(GtkObject *obj)
{
  window_count--;

  if(window_count <= 0)
94 95 96
    {
      gtk_main_quit();
    }
97 98 99 100 101 102 103 104 105 106 107
}

NautilusWindow *
nautilus_app_create_window(void)
{
  GtkWidget *win = gtk_widget_new(nautilus_window_get_type(), "app_id", "nautilus", NULL);

  window_count++;

  gtk_signal_connect(GTK_OBJECT(win), "destroy", nautilus_app_destroy_window, NULL);

108 109 110 111
  /* Do not yet show the window. It will be shown later on if it can
   * successfully display its initial uri. Otherwise it will be destroyed
   * without ever having seen the light of day.
   */
112 113 114

  return NAUTILUS_WINDOW(win);
}