2008-05-05 Paolo Borelli <pborelli@katamail.com>
[nautilus.git] / src / nautilus-shell.c
blob46905685c3c31cc8e55eaa94ed199c797b448346
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
3 /*
4 * Nautilus
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.
28 #include <config.h>
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>
49 #include <stdlib.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,
86 Nautilus_Shell,
87 BonoboObject, BONOBO_OBJECT_TYPE)
89 static void
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;
103 static void
104 nautilus_shell_instance_init (NautilusShell *shell)
106 shell->details = g_new0 (NautilusShellDetails, 1);
109 static void
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));
120 NautilusShell *
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;
127 return shell;
130 static void
131 open_window (NautilusShell *shell, const char *uri, const char *startup_id,
132 const char *geometry, gboolean browser_window)
134 GFile *location;
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,
140 startup_id,
141 gdk_screen_get_default ());
142 if (uri == NULL) {
143 nautilus_window_go_home (window);
144 } else {
145 location = g_file_new_for_uri (uri);
146 nautilus_window_go_to (window, location);
147 g_object_unref (location);
149 } else {
150 if (uri == NULL) {
151 location = g_file_new_for_path (g_get_home_dir ());
152 } else {
153 location = g_file_new_for_uri (uri);
156 window = nautilus_application_present_spatial_window (shell->details->application,
157 NULL,
158 startup_id,
159 location,
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),
166 geometry,
167 APPLICATION_WINDOW_MIN_WIDTH,
168 APPLICATION_WINDOW_MIN_HEIGHT,
169 FALSE);
173 typedef struct {
174 NautilusShell *shell;
175 char *startup_id;
176 char *geometry;
177 GList *uris;
178 gboolean browser_window;
179 } OpenWindowData;
181 static gboolean
182 open_windows_at_idle (gpointer _data)
184 OpenWindowData *data = _data;
185 char *uri;
186 GList *l;
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);
192 } else {
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);
198 g_free (uri);
202 g_free (data->startup_id);
203 g_free (data->geometry);
204 g_list_free (data->uris);
205 g_free (data);
206 return FALSE;
209 static void
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;
218 guint i;
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);
238 static void
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);
257 typedef struct {
258 NautilusShell *shell;
259 char *filename;
260 } LoadSessionData;
262 static gboolean
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);
272 g_free (data);
273 return FALSE;
276 static void
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);
290 typedef struct {
291 NautilusShell *shell;
292 } StartDesktopData;
294 static gboolean
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);
303 g_free (data);
304 return FALSE;
308 static void
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);
320 static gboolean
321 stop_desktop_at_idle (gpointer data)
323 nautilus_application_close_desktop ();
324 return FALSE;
327 static void
328 corba_stop_desktop (PortableServer_Servant servant,
329 CORBA_Environment *ev)
331 g_idle_add (stop_desktop_at_idle, NULL);
334 static gboolean
335 quit_at_idle (gpointer data)
337 nautilus_main_event_loop_quit (TRUE);
338 return FALSE;
342 static void
343 corba_quit (PortableServer_Servant servant,
344 CORBA_Environment *ev)
346 g_idle_add (quit_at_idle, NULL);
349 static gboolean
350 restart_at_idle (gpointer data)
352 char *filename;
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);
358 g_free (filename);
359 } else {
360 g_message ("Could not save session. Not restarting.");
364 return FALSE;
367 static void
368 corba_restart (PortableServer_Servant servant,
369 CORBA_Environment *ev)
371 g_idle_add (restart_at_idle, NULL);