1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
6 * Copyright (C) 2000 Eazel, Inc.
8 * Nautilus is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
13 * Nautilus is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
24 /* nautilus-shell.h: Server side of the Nautilus:Shell CORBA object
25 * that represents the shell across processes.
29 #include "nautilus-shell.h"
31 #include "nautilus-desktop-window.h"
32 #include "nautilus-main.h"
33 #include "nautilus-window-private.h"
34 #include <eel/eel-glib-extensions.h>
35 #include <eel/eel-gtk-extensions.h>
36 #include <eel/eel-gtk-macros.h>
37 #include <eel/eel-stock-dialogs.h>
38 #include <eel/eel-string.h>
39 #include <gtk/gtkframe.h>
40 #include <gtk/gtkhbox.h>
41 #include <gtk/gtklabel.h>
42 #include <gtk/gtkmain.h>
43 #include <gtk/gtksignal.h>
44 #include <glib/gi18n.h>
45 #include <libgnomeui/gnome-stock-icons.h>
46 #include <libgnomeui/gnome-uidefs.h>
47 #include <libnautilus-private/nautilus-file-utilities.h>
48 #include <libnautilus-private/nautilus-global-preferences.h>
51 /* Keep window from shrinking down ridiculously small; numbers are somewhat arbitrary */
52 #define APPLICATION_WINDOW_MIN_WIDTH 300
53 #define APPLICATION_WINDOW_MIN_HEIGHT 100
55 #define START_STATE_CONFIG "start-state"
57 struct NautilusShellDetails
{
58 NautilusApplication
*application
;
61 static void finalize (GObject
*shell
);
62 static void corba_open_windows (PortableServer_Servant servant
,
63 const Nautilus_URIList
*list
,
64 const CORBA_char
*startup_id
,
65 const CORBA_char
*geometry
,
66 CORBA_boolean browser_window
,
67 CORBA_Environment
*ev
);
68 static void corba_open_default_window (PortableServer_Servant servant
,
69 const CORBA_char
*startup_id
,
70 const CORBA_char
*geometry
,
71 CORBA_boolean browser_window
,
72 CORBA_Environment
*ev
);
73 static void corba_load_session (PortableServer_Servant servant
,
74 const CORBA_char
*filename
,
75 CORBA_Environment
*ev
);
76 static void corba_start_desktop (PortableServer_Servant servant
,
77 CORBA_Environment
*ev
);
78 static void corba_stop_desktop (PortableServer_Servant servant
,
79 CORBA_Environment
*ev
);
80 static void corba_quit (PortableServer_Servant servant
,
81 CORBA_Environment
*ev
);
82 static void corba_restart (PortableServer_Servant servant
,
83 CORBA_Environment
*ev
);
85 BONOBO_CLASS_BOILERPLATE_FULL (NautilusShell
, nautilus_shell
,
87 BonoboObject
, BONOBO_OBJECT_TYPE
)
90 nautilus_shell_class_init (NautilusShellClass
*klass
)
92 G_OBJECT_CLASS (klass
)->finalize
= finalize
;
94 klass
->epv
.open_windows
= corba_open_windows
;
95 klass
->epv
.open_default_window
= corba_open_default_window
;
96 klass
->epv
.load_session
= corba_load_session
;
97 klass
->epv
.start_desktop
= corba_start_desktop
;
98 klass
->epv
.stop_desktop
= corba_stop_desktop
;
99 klass
->epv
.quit
= corba_quit
;
100 klass
->epv
.restart
= corba_restart
;
104 nautilus_shell_instance_init (NautilusShell
*shell
)
106 shell
->details
= g_new0 (NautilusShellDetails
, 1);
110 finalize (GObject
*object
)
112 NautilusShell
*shell
;
114 shell
= NAUTILUS_SHELL (object
);
115 g_free (shell
->details
);
117 EEL_CALL_PARENT (G_OBJECT_CLASS
, finalize
, (object
));
121 nautilus_shell_new (NautilusApplication
*application
)
123 NautilusShell
*shell
;
125 shell
= NAUTILUS_SHELL (g_object_new (NAUTILUS_TYPE_SHELL
, NULL
));
126 shell
->details
->application
= application
;
131 open_window (NautilusShell
*shell
, const char *uri
, const char *startup_id
,
132 const char *geometry
, gboolean browser_window
)
135 NautilusWindow
*window
;
137 if (browser_window
||
138 eel_preferences_get_boolean (NAUTILUS_PREFERENCES_ALWAYS_USE_BROWSER
)) {
139 window
= nautilus_application_create_navigation_window (shell
->details
->application
,
141 gdk_screen_get_default ());
143 nautilus_window_go_home (window
);
145 location
= g_file_new_for_uri (uri
);
146 nautilus_window_go_to (window
, location
);
147 g_object_unref (location
);
151 location
= g_file_new_for_path (g_get_home_dir ());
153 location
= g_file_new_for_uri (uri
);
156 window
= nautilus_application_present_spatial_window (shell
->details
->application
,
160 gdk_screen_get_default ());
161 g_object_unref (location
);
164 if (geometry
!= NULL
&& !GTK_WIDGET_VISIBLE (window
)) {
165 eel_gtk_window_set_initial_geometry_from_string (GTK_WINDOW (window
),
167 APPLICATION_WINDOW_MIN_WIDTH
,
168 APPLICATION_WINDOW_MIN_HEIGHT
,
174 NautilusShell
*shell
;
178 gboolean browser_window
;
182 open_windows_at_idle (gpointer _data
)
184 OpenWindowData
*data
= _data
;
188 if (data
->uris
== NULL
) {
189 /* Open a window pointing at the default location. */
190 open_window (data
->shell
, NULL
, data
->startup_id
,
191 data
->geometry
, data
->browser_window
);
193 /* Open windows at each requested location. */
194 for (l
= data
->uris
; l
!= NULL
; l
= l
->next
) {
195 uri
= (char *)l
->data
;
196 open_window (data
->shell
, uri
, data
->startup_id
,
197 data
->geometry
, data
->browser_window
);
202 g_free (data
->startup_id
);
203 g_free (data
->geometry
);
204 g_list_free (data
->uris
);
210 corba_open_windows (PortableServer_Servant servant
,
211 const Nautilus_URIList
*list
,
212 const CORBA_char
*startup_id
,
213 const CORBA_char
*geometry
,
214 CORBA_boolean browser_window
,
215 CORBA_Environment
*ev
)
217 OpenWindowData
*data
;
220 data
= g_new0 (OpenWindowData
, 1);
222 data
->shell
= NAUTILUS_SHELL (bonobo_object_from_servant (servant
));
223 data
->startup_id
= g_strdup (startup_id
);
224 data
->geometry
= g_strdup (geometry
);
225 data
->browser_window
= browser_window
;
227 for (i
= 0; i
< list
->_length
; i
++) {
228 g_assert (list
->_buffer
[i
] != NULL
);
229 data
->uris
= g_list_prepend (data
->uris
,
230 g_strdup (list
->_buffer
[i
]));
232 data
->uris
= g_list_reverse (data
->uris
);
234 g_idle_add (open_windows_at_idle
, data
);
239 corba_open_default_window (PortableServer_Servant servant
,
240 const CORBA_char
*startup_id
,
241 const CORBA_char
*geometry
,
242 CORBA_boolean browser_window
,
243 CORBA_Environment
*ev
)
245 OpenWindowData
*data
;
247 data
= g_new0 (OpenWindowData
, 1);
249 data
->shell
= NAUTILUS_SHELL (bonobo_object_from_servant (servant
));
250 data
->startup_id
= g_strdup (startup_id
);
251 data
->geometry
= g_strdup (geometry
);
252 data
->browser_window
= browser_window
;
254 g_idle_add (open_windows_at_idle
, data
);
258 NautilusShell
*shell
;
263 load_session_at_idle (gpointer _data
)
265 NautilusApplication
*application
;
266 LoadSessionData
*data
= _data
;
268 application
= NAUTILUS_APPLICATION (data
->shell
->details
->application
);
269 nautilus_application_load_session (application
, data
->filename
);
271 g_free (data
->filename
);
277 corba_load_session (PortableServer_Servant servant
,
278 const CORBA_char
*filename
,
279 CORBA_Environment
*ev
)
281 LoadSessionData
*data
;
283 data
= g_new0 (LoadSessionData
, 1);
284 data
->shell
= NAUTILUS_SHELL (bonobo_object_from_servant (servant
));
285 data
->filename
= g_strdup (filename
);
287 g_idle_add (load_session_at_idle
, data
);
291 NautilusShell
*shell
;
295 start_desktop_at_idle (gpointer _data
)
297 StartDesktopData
*data
= _data
;
298 NautilusApplication
*application
;
300 application
= NAUTILUS_APPLICATION (data
->shell
->details
->application
);
301 nautilus_application_open_desktop (application
);
309 corba_start_desktop (PortableServer_Servant servant
,
310 CORBA_Environment
*ev
)
312 StartDesktopData
*data
;
314 data
= g_new0 (StartDesktopData
, 1);
315 data
->shell
= NAUTILUS_SHELL (bonobo_object_from_servant (servant
));
317 g_idle_add (start_desktop_at_idle
, data
);
321 stop_desktop_at_idle (gpointer data
)
323 nautilus_application_close_desktop ();
328 corba_stop_desktop (PortableServer_Servant servant
,
329 CORBA_Environment
*ev
)
331 g_idle_add (stop_desktop_at_idle
, NULL
);
335 quit_at_idle (gpointer data
)
337 nautilus_main_event_loop_quit (TRUE
);
343 corba_quit (PortableServer_Servant servant
,
344 CORBA_Environment
*ev
)
346 g_idle_add (quit_at_idle
, NULL
);
350 restart_at_idle (gpointer data
)
354 filename
= nautilus_application_save_session_to_file ();
355 if (filename
!= NULL
) {
356 nautilus_main_event_loop_quit (TRUE
);
357 g_setenv ("_NAUTILUS_RESTART_SESSION_FILENAME", filename
, 1);
360 g_message ("Could not save session. Not restarting.");
368 corba_restart (PortableServer_Servant servant
,
369 CORBA_Environment
*ev
)
371 g_idle_add (restart_at_idle
, NULL
);