Bug Summary

File:src/baul-application.c
Warning:line 2185, column 5
Value stored to 'exit_with_last_window' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name baul-application.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/rootdir/src -fcoverage-compilation-dir=/rootdir/src -resource-dir /usr/lib/llvm-19/lib/clang/19 -D HAVE_CONFIG_H -I . -I .. -I .. -I ../libbaul-private -I /usr/include/glib-2.0 -I /usr/lib/x86_64-linux-gnu/glib-2.0/include -I /usr/include/sysprof-6 -I /usr/include/cafe-desktop-2.0 -I /usr/include/ctk-3.0 -I /usr/include/pango-1.0 -I /usr/include/harfbuzz -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/libmount -I /usr/include/blkid -I /usr/include/fribidi -I /usr/include/cairo -I /usr/include/pixman-1 -I /usr/include/gdk-pixbuf-2.0 -I /usr/include/x86_64-linux-gnu -I /usr/include/webp -I /usr/include/gio-unix-2.0 -I /usr/include/atk-1.0 -I /usr/include/at-spi2-atk/2.0 -I /usr/include/at-spi-2.0 -I /usr/include/dbus-1.0 -I /usr/lib/x86_64-linux-gnu/dbus-1.0/include -I /usr/include/startup-notification-1.0 -I /usr/include/dconf -I /usr/include/cail-3.0 -I /usr/include/libxml2 -I /usr/include/exempi-2.0 -D DATADIR="/usr/share" -D LIBDIR="/usr/lib" -D BAUL_DATADIR="/usr/share/baul" -D CAFELOCALEDIR="/usr/share/locale" -D UIDIR="/usr/share/baul/ui" -D BAUL_PIXMAPDIR="/usr/share/pixmaps/baul" -D PREFIX="/usr" -D SYSCONFDIR="/usr/etc" -D VERSION="2.0.0" -D G_DISABLE_DEPRECATED -D GDK_PIXBUF_DISABLE_DEPRECATED -internal-isystem /usr/lib/llvm-19/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -analyzer-checker deadcode.DeadStores -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2025-01-27-072242-27568-1 -x c baul-application.c
1/*
2 * Baul
3 *
4 * Copyright (C) 1999, 2000 Red Hat, Inc.
5 * Copyright (C) 2000, 2001 Eazel, Inc.
6 *
7 * Baul is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
11 *
12 * Baul is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 * Authors: Elliot Lee <sopwith@redhat.com>,
22 * Darin Adler <darin@bentspoon.com>,
23 * Cosimo Cecchi <cosimoc@gnome.org>
24 *
25 */
26
27#include <config.h>
28#include <fcntl.h>
29#include <string.h>
30#include <unistd.h>
31#include <fcntl.h>
32
33#include <libxml/xmlsave.h>
34#include <glib/gstdio.h>
35#include <glib/gi18n.h>
36#include <gio/gio.h>
37#include <cdk/cdkx.h>
38#include <ctk/ctk.h>
39#include <libnotify/notify.h>
40#include <sys/types.h>
41#include <sys/stat.h>
42#define CAFE_DESKTOP_USE_UNSTABLE_API
43#include <libcafe-desktop/cafe-bg.h>
44
45#include <eel/eel-ctk-extensions.h>
46#include <eel/eel-ctk-macros.h>
47#include <eel/eel-stock-dialogs.h>
48
49#include <libbaul-private/baul-debug-log.h>
50#include <libbaul-private/baul-file-utilities.h>
51#include <libbaul-private/baul-global-preferences.h>
52#include <libbaul-private/baul-lib-self-check-functions.h>
53#include <libbaul-private/baul-extensions.h>
54#include <libbaul-private/baul-module.h>
55#include <libbaul-private/baul-desktop-link-monitor.h>
56#include <libbaul-private/baul-directory-private.h>
57#include <libbaul-private/baul-signaller.h>
58#include <libbaul-extension/baul-menu-provider.h>
59#include <libbaul-private/baul-autorun.h>
60
61#if ENABLE_EMPTY_VIEW1
62#include "file-manager/fm-empty-view.h"
63#endif /* ENABLE_EMPTY_VIEW */
64#include "file-manager/fm-desktop-icon-view.h"
65#include "file-manager/fm-icon-view.h"
66#include "file-manager/fm-list-view.h"
67#include "file-manager/fm-tree-view.h"
68#include "file-manager/fm-widget-view.h"
69
70#include "baul-application.h"
71#include "baul-information-panel.h"
72#include "baul-history-sidebar.h"
73#include "baul-places-sidebar.h"
74#include "baul-self-check-functions.h"
75#include "baul-notes-viewer.h"
76#include "baul-emblem-sidebar.h"
77#include "baul-image-properties-page.h"
78#include "baul-desktop-window.h"
79#include "baul-spatial-window.h"
80#include "baul-navigation-window.h"
81#include "baul-window-slot.h"
82#include "baul-navigation-window-slot.h"
83#include "baul-window-bookmarks.h"
84#include "libbaul-private/baul-file-operations.h"
85#include "baul-window-private.h"
86#include "baul-window-manage-views.h"
87#include "baul-freedesktop-dbus.h"
88
89/* Keep window from shrinking down ridiculously small; numbers are somewhat arbitrary */
90#define APPLICATION_WINDOW_MIN_WIDTH300 300
91#define APPLICATION_WINDOW_MIN_HEIGHT100 100
92
93#define BAUL_ACCEL_MAP_SAVE_DELAY30 30
94
95/* Keeps track of all the desktop windows. */
96static GList *baul_application_desktop_windows;
97
98/* Keeps track of all the object windows */
99static GList *baul_application_spatial_window_list;
100
101/* The saving of the accelerator map was requested */
102static gboolean save_of_accel_map_requested = FALSE(0);
103
104/* File Manager DBus Interface */
105static BaulFreedesktopDBus *fdb_manager = NULL((void*)0);
106
107static char * baul_application_get_session_data (BaulApplication *self);
108void baul_application_quit (BaulApplication *self);
109
110struct _BaulApplicationPrivate {
111 GVolumeMonitor *volume_monitor;
112 gboolean no_desktop;
113 gboolean force_desktop;
114 gboolean autostart;
115 gchar *geometry;
116};
117
118G_DEFINE_TYPE_WITH_PRIVATE (BaulApplication, baul_application, CTK_TYPE_APPLICATION)static void baul_application_init (BaulApplication *self); static
void baul_application_class_init (BaulApplicationClass *klass
); static GType baul_application_get_type_once (void); static
gpointer baul_application_parent_class = ((void*)0); static gint
BaulApplication_private_offset; static void baul_application_class_intern_init
(gpointer klass) { baul_application_parent_class = g_type_class_peek_parent
(klass); if (BaulApplication_private_offset != 0) g_type_class_adjust_private_offset
(klass, &BaulApplication_private_offset); baul_application_class_init
((BaulApplicationClass*) klass); } __attribute__ ((__unused__
)) static inline gpointer baul_application_get_instance_private
(BaulApplication *self) { return (((gpointer) ((guint8*) (self
) + (glong) (BaulApplication_private_offset)))); } GType baul_application_get_type
(void) { static GType static_g_define_type_id = 0; if ((__extension__
({ _Static_assert (sizeof *(&static_g_define_type_id) ==
sizeof (gpointer), "Expression evaluates to false"); (void) (
0 ? (gpointer) * (&static_g_define_type_id) : ((void*)0))
; (!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id
) == sizeof (gpointer), "Expression evaluates to false"); __typeof__
(*(&static_g_define_type_id)) gapg_temp_newval; __typeof__
((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id
); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5)
; gapg_temp_newval; })) && g_once_init_enter_pointer (
&static_g_define_type_id)); })) ) { GType g_define_type_id
= baul_application_get_type_once (); (__extension__ ({ _Static_assert
(sizeof *(&static_g_define_type_id) == sizeof (gpointer)
, "Expression evaluates to false"); 0 ? (void) (*(&static_g_define_type_id
) = (g_define_type_id)) : (void) 0; g_once_init_leave_pointer
((&static_g_define_type_id), (gpointer) (guintptr) (g_define_type_id
)); })) ; } return static_g_define_type_id; } __attribute__ (
(__noinline__)) static GType baul_application_get_type_once (
void) { GType g_define_type_id = g_type_register_static_simple
((ctk_application_get_type ()), g_intern_static_string ("BaulApplication"
), sizeof (BaulApplicationClass), (GClassInitFunc)(void (*)(void
)) baul_application_class_intern_init, sizeof (BaulApplication
), (GInstanceInitFunc)(void (*)(void)) baul_application_init,
(GTypeFlags) 0); { {{ BaulApplication_private_offset = g_type_add_instance_private
(g_define_type_id, sizeof (BaulApplicationPrivate)); };} } return
g_define_type_id; }
;
119
120GList *
121baul_application_get_spatial_window_list (void)
122{
123 return baul_application_spatial_window_list;
124}
125
126static void
127startup_volume_mount_cb (GObject *source_object,
128 GAsyncResult *res,
129 gpointer user_data G_GNUC_UNUSED__attribute__ ((__unused__)))
130{
131 g_volume_mount_finish (G_VOLUME (source_object)((((GVolume*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((source_object)), ((g_volume_get_type ()))))))
, res, NULL((void*)0));
132}
133
134static void
135automount_all_volumes (BaulApplication *application)
136{
137 GList *volumes, *l;
138
139 if (g_settings_get_boolean (baul_media_preferences, BAUL_PREFERENCES_MEDIA_AUTOMOUNT"automount"))
140 {
141 /* automount all mountable volumes at start-up */
142
143 GVolume *volume = NULL((void*)0);
144 GMount *mount = NULL((void*)0);
145
146 volumes = g_volume_monitor_get_volumes (application->priv->volume_monitor);
147
148 for (l = volumes; l != NULL((void*)0); l = l->next)
149 {
150 volume = l->data;
151
152 if (!g_volume_should_automount (volume) ||
153 !g_volume_can_mount (volume))
154 {
155 continue;
156 }
157
158 mount = g_volume_get_mount (volume);
159 if (mount != NULL((void*)0))
160 {
161 g_object_unref (mount);
162 continue;
163 }
164
165 /* pass NULL as GMountOperation to avoid user interaction */
166 g_volume_mount (volume, 0, NULL((void*)0), NULL((void*)0), startup_volume_mount_cb, NULL((void*)0));
167 }
168 g_list_free_full (volumes, g_object_unref);
169 }
170
171}
172
173static void
174smclient_save_state_cb (EggSMClient *client G_GNUC_UNUSED__attribute__ ((__unused__)),
175 GKeyFile *state_file,
176 BaulApplication *application)
177{
178 char *data;
179 data = baul_application_get_session_data (application);
180
181 if (data != NULL((void*)0))
182 {
183 g_key_file_set_string (state_file,
184 "Baul",
185 "documents",
186 data);
187 }
188 g_free (data);
189}
190
191static void
192smclient_quit_cb (EggSMClient *client G_GNUC_UNUSED__attribute__ ((__unused__)),
193 BaulApplication *application)
194{
195 baul_application_quit (application);
196}
197
198static void
199baul_application_smclient_initialize (BaulApplication *self)
200{
201 g_signal_connect (self->smclient, "save_state",g_signal_connect_data ((self->smclient), ("save_state"), (
((GCallback) (smclient_save_state_cb))), (self), ((void*)0), (
GConnectFlags) 0)
202 G_CALLBACK (smclient_save_state_cb),g_signal_connect_data ((self->smclient), ("save_state"), (
((GCallback) (smclient_save_state_cb))), (self), ((void*)0), (
GConnectFlags) 0)
203 self)g_signal_connect_data ((self->smclient), ("save_state"), (
((GCallback) (smclient_save_state_cb))), (self), ((void*)0), (
GConnectFlags) 0)
;
204 g_signal_connect (self->smclient, "quit",g_signal_connect_data ((self->smclient), ("quit"), (((GCallback
) (smclient_quit_cb))), (self), ((void*)0), (GConnectFlags) 0
)
205 G_CALLBACK (smclient_quit_cb),g_signal_connect_data ((self->smclient), ("quit"), (((GCallback
) (smclient_quit_cb))), (self), ((void*)0), (GConnectFlags) 0
)
206 self)g_signal_connect_data ((self->smclient), ("quit"), (((GCallback
) (smclient_quit_cb))), (self), ((void*)0), (GConnectFlags) 0
)
;
207
208 /* TODO: Should connect to quit_requested and block logout on active transfer? */
209}
210
211void
212baul_application_smclient_startup (BaulApplication *self)
213{
214 g_assert (self->smclient == NULL)do { if (self->smclient == ((void*)0)) ; else g_assertion_message_expr
(((gchar*) 0), "baul-application.c", 214, ((const char*) (__func__
)), "self->smclient == NULL"); } while (0)
;
215 self->smclient = egg_sm_client_get ();
216}
217
218static void
219baul_empty_callback_to_ensure_read() {
220/*do nothing, just exist to suppress runtime error*/
221}
222
223static void
224open_window (BaulApplication *application,
225 GFile *location,
226 CdkScreen *screen,
227 const char *geometry,
228 gboolean browser_window)
229{
230 BaulApplication *self = BAUL_APPLICATION (application)((((BaulApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((application)), (baul_application_get_type())))))
;
231 BaulWindow *window;
232 gchar *uri;
233
234 uri = g_file_get_uri (location);
235 g_debug ("Opening new window at uri %s", uri);
236
237 /*monitor the preference to use browser or spatial windows */
238 /*connect before trying to read or this preference won't be read by root or after change*/
239 g_signal_connect_swapped(baul_preferences, "changed::"BAUL_PREFERENCES_ALWAYS_USE_BROWSER,g_signal_connect_data ((baul_preferences), ("changed::""always-use-browser"
), (((GCallback) (baul_empty_callback_to_ensure_read))), (self
), ((void*)0), G_CONNECT_SWAPPED)
240 G_CALLBACK (baul_empty_callback_to_ensure_read),g_signal_connect_data ((baul_preferences), ("changed::""always-use-browser"
), (((GCallback) (baul_empty_callback_to_ensure_read))), (self
), ((void*)0), G_CONNECT_SWAPPED)
241 self)g_signal_connect_data ((baul_preferences), ("changed::""always-use-browser"
), (((GCallback) (baul_empty_callback_to_ensure_read))), (self
), ((void*)0), G_CONNECT_SWAPPED)
;
242
243 if (browser_window ||g_settings_get_boolean (baul_preferences, BAUL_PREFERENCES_ALWAYS_USE_BROWSER"always-use-browser")) {
244 window = baul_application_create_navigation_window (application,
245 screen);
246 } else {
247 window = baul_application_get_spatial_window (application,
248 NULL((void*)0),
249 NULL((void*)0),
250 location,
251 screen,
252 NULL((void*)0));
253 }
254
255 baul_window_go_to (window, location);
256
257 if (geometry != NULL((void*)0) && !ctk_widget_get_visible (CTK_WIDGET (window)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_widget_get_type ()))))))
)) {
258 /* never maximize windows opened from shell if a
259 * custom geometry has been requested. */
260 ctk_window_unmaximize (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
);
261 eel_ctk_window_set_initial_geometry_from_string (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
,
262 geometry,
263 APPLICATION_WINDOW_MIN_WIDTH300,
264 APPLICATION_WINDOW_MIN_HEIGHT100,
265 FALSE(0));
266 }
267
268 g_free (uri);
269}
270
271static void
272open_tabs (BaulApplication *application,
273 GFile **locations,
274 guint n_files,
275 CdkScreen *screen,
276 const char *geometry,
277 gboolean browser_window)
278{
279 BaulApplication *self = BAUL_APPLICATION (application)((((BaulApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((application)), (baul_application_get_type())))))
;
280 BaulWindow *window;
281 gchar *uri = NULL((void*)0);
282
283 /* monitor the preference to use browser or spatial windows */
284 /* connect before trying to read or this preference won't be read by root or after change */
285 g_signal_connect_swapped (baul_preferences,g_signal_connect_data ((baul_preferences), ("changed::""always-use-browser"
), (((GCallback) (baul_empty_callback_to_ensure_read))), (self
), ((void*)0), G_CONNECT_SWAPPED)
286 "changed::"BAUL_PREFERENCES_ALWAYS_USE_BROWSER,g_signal_connect_data ((baul_preferences), ("changed::""always-use-browser"
), (((GCallback) (baul_empty_callback_to_ensure_read))), (self
), ((void*)0), G_CONNECT_SWAPPED)
287 G_CALLBACK (baul_empty_callback_to_ensure_read),g_signal_connect_data ((baul_preferences), ("changed::""always-use-browser"
), (((GCallback) (baul_empty_callback_to_ensure_read))), (self
), ((void*)0), G_CONNECT_SWAPPED)
288 self)g_signal_connect_data ((baul_preferences), ("changed::""always-use-browser"
), (((GCallback) (baul_empty_callback_to_ensure_read))), (self
), ((void*)0), G_CONNECT_SWAPPED)
;
289
290 if (browser_window ||g_settings_get_boolean (baul_preferences, BAUL_PREFERENCES_ALWAYS_USE_BROWSER"always-use-browser")) {
291 window = baul_application_create_navigation_window (application, screen);
292 } else {
293 window = baul_application_get_spatial_window (application,
294 NULL((void*)0),
295 NULL((void*)0),
296 locations[0],
297 screen,
298 NULL((void*)0));
299 }
300
301 /* open all locations */
302 uri = g_file_get_uri (locations[0]);
303 g_debug ("Opening new tab at uri %s\n", uri);
304 baul_window_go_to (window, locations[0]);
305 g_free (uri);
306 for (int i = 1; i< n_files;i++) {
307 /* open tabs in reverse order because each
308 * tab is opened before the previous one */
309 guint tab = n_files-i;
310 uri = g_file_get_uri (locations[tab]);
311 g_debug ("Opening new tab at uri %s\n", uri);
312 baul_window_go_to_tab (window, locations[tab]);
313 g_free (uri);
314 }
315
316 if (geometry != NULL((void*)0) && !ctk_widget_get_visible (CTK_WIDGET (window)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_widget_get_type ()))))))
)) {
317 /* never maximize windows opened from shell if a
318 * custom geometry has been requested. */
319 ctk_window_unmaximize (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
);
320 eel_ctk_window_set_initial_geometry_from_string (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
,
321 geometry,
322 APPLICATION_WINDOW_MIN_WIDTH300,
323 APPLICATION_WINDOW_MIN_HEIGHT100,
324 FALSE(0));
325 }
326}
327
328static void
329open_windows (BaulApplication *application,
330 GFile **files,
331 CdkScreen *screen,
332 const char *geometry,
333 guint n_files,
334 gboolean browser_window,
335 gboolean open_in_tabs)
336{
337 guint i;
338
339 if (files == NULL((void*)0) || files[0] == NULL((void*)0)) {
340 /* Open a window pointing at the default location. */
341 open_window (application, NULL((void*)0), screen, geometry, browser_window);
342 } else {
343 if (open_in_tabs) {
344 /* Open one window with one tab at each requested location */
345 open_tabs (application, files, n_files, screen, geometry, browser_window);
346 } else {
347 /* Open windows at each requested location. */
348 i = 0;
349 while (i < n_files) {
350 open_window (application, files[i], screen, geometry, browser_window);
351 i++ ;
352 }
353 }
354 }
355}
356
357static void
358baul_application_open (GApplication *app,
359 GFile **files,
360 gint n_files,
361 const gchar *options)
362{
363 BaulApplication *self = BAUL_APPLICATION (app)((((BaulApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((app)), (baul_application_get_type())))))
;
364 gboolean browser_window = FALSE(0);
365 gboolean open_in_tabs = FALSE(0);
366 const gchar *geometry = NULL((void*)0);
367 const char splitter = '=';
368
369 g_debug ("Open called on the GApplication instance; %d files", n_files);
370
371 /* Check if local command line passed --browser, --geometry or --tabs */
372 if (strlen (options) > 0) {
373 gchar** splitedOptions = g_strsplit (options, &splitter, 3);
374 sscanf (splitedOptions[0], "%d", &browser_window);
375 if (strcmp (splitedOptions[1], "NULL") != 0) {
376 geometry = splitedOptions[1];
377 }
378 sscanf (splitedOptions[2], "%d", &open_in_tabs);
379
380 open_windows (self, files,
381 cdk_screen_get_default (),
382 geometry,
383 n_files,
384 browser_window,
385 open_in_tabs);
386
387 /* Reset this or 3ed and later invocations will use same
388 * geometry even if the user has resized open window */
389 self->priv->geometry = NULL((void*)0);
390 g_strfreev (splitedOptions);
391 }
392 else
393 open_windows (self, files,
394 cdk_screen_get_default (),
395 geometry,
396 n_files,
397 browser_window,
398 open_in_tabs);
399}
400
401void
402baul_application_open_location (BaulApplication *application,
403 GFile *location,
404 GFile *selection,
405 const char *startup_id G_GNUC_UNUSED__attribute__ ((__unused__)),
406 const gboolean open_in_tabs)
407{
408 BaulWindow *window;
409 GList *sel_list = NULL((void*)0);
410
411 window = baul_application_create_navigation_window (application, cdk_screen_get_default ());
412
413 if (selection != NULL((void*)0)) {
414 sel_list = g_list_prepend (NULL((void*)0), g_object_ref (selection)((__typeof__ (selection)) (g_object_ref) (selection)));
415 }
416
417 baul_window_slot_open_location_full (baul_window_get_active_slot (window), location,
418 open_in_tabs, BAUL_WINDOW_OPEN_FLAG_NEW_WINDOW,
419 sel_list, NULL((void*)0), NULL((void*)0));
420
421 if (sel_list != NULL((void*)0)) {
422 baul_file_list_free (sel_list);
423 }
424}
425
426void
427baul_application_quit (BaulApplication *self)
428{
429 GApplication *app = G_APPLICATION (self)((((GApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((self)), ((g_application_get_type ()))))))
;
430 GList *windows;
431
432 windows = ctk_application_get_windows (CTK_APPLICATION (app)((((CtkApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((app)), ((ctk_application_get_type ()))))))
);
433 g_list_foreach (windows, (GFunc) ctk_widget_destroy, NULL((void*)0));
434 /* we have been asked to force quit */
435 g_application_quit (G_APPLICATION (self)((((GApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((self)), ((g_application_get_type ()))))))
);
436}
437
438static void
439baul_application_init (BaulApplication *application)
440{
441 GSimpleAction *action;
442 application->priv = baul_application_get_instance_private (application);
443 action = g_simple_action_new ("quit", NULL((void*)0));
444
445 g_action_map_add_action (G_ACTION_MAP (application)((((GActionMap*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((application)), ((g_action_map_get_type ()))))))
, G_ACTION (action)((((GAction*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((action)), ((g_action_get_type ()))))))
);
446
447 g_signal_connect_swapped (action, "activate",g_signal_connect_data ((action), ("activate"), (((GCallback) (
baul_application_quit))), (application), ((void*)0), G_CONNECT_SWAPPED
)
448 G_CALLBACK (baul_application_quit), application)g_signal_connect_data ((action), ("activate"), (((GCallback) (
baul_application_quit))), (application), ((void*)0), G_CONNECT_SWAPPED
)
;
449
450 g_object_unref (action);
451}
452
453static void
454baul_application_finalize (GObject *object)
455{
456 BaulApplication *application;
457
458 application = BAUL_APPLICATION (object)((((BaulApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((object)), (baul_application_get_type())))))
;
459
460 baul_bookmarks_exiting ();
461
462 if (application->volume_monitor)
463 {
464 g_object_unref (application->priv->volume_monitor);
465 application->priv->volume_monitor = NULL((void*)0);
466 }
467
468 g_free (application->priv->geometry);
469
470 if (application->ss_watch_id > 0)
471 {
472 g_bus_unwatch_name (application->ss_watch_id);
473 }
474
475 if (application->volume_queue != NULL((void*)0))
476 {
477 g_list_free_full (application->volume_queue, g_object_unref);
478 application->volume_queue = NULL((void*)0);
479 }
480
481 if (application->automount_idle_id != 0)
482 {
483 g_source_remove (application->automount_idle_id);
484 application->automount_idle_id = 0;
485 }
486
487 if (fdb_manager != NULL((void*)0))
488 {
489 g_object_unref (fdb_manager);
490 fdb_manager = NULL((void*)0);
491 }
492
493 if (application->ss_proxy != NULL((void*)0))
494 {
495 g_object_unref (application->ss_proxy);
496 application->ss_proxy = NULL((void*)0);
497 }
498
499 notify_uninit ();
500
501 G_OBJECT_CLASS (baul_application_parent_class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass
*) ((baul_application_parent_class)), (((GType) ((20) <<
(2))))))))
->finalize (object);
502}
503
504static gboolean
505check_required_directories (BaulApplication *application)
506{
507 char *user_directory;
508 char *desktop_directory;
509 GSList *directories;
510 gboolean ret;
511
512 g_assert (BAUL_IS_APPLICATION (application))do { if ((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((application)); GType __t = (baul_application_get_type())
; gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class
&& __inst->g_class->g_type == __t) __r = (!(0)
); else __r = g_type_check_instance_is_a (__inst, __t); __r; }
))))) ; else g_assertion_message_expr (((gchar*) 0), "baul-application.c"
, 512, ((const char*) (__func__)), "BAUL_IS_APPLICATION (application)"
); } while (0)
;
513
514 ret = TRUE(!(0));
515
516 user_directory = baul_get_user_directory ();
517 desktop_directory = baul_get_desktop_directory ();
518
519 directories = NULL((void*)0);
520
521 if (!g_file_test (user_directory, G_FILE_TEST_IS_DIR))
522 {
523 directories = g_slist_prepend (directories, user_directory);
524 }
525
526 if (!g_file_test (desktop_directory, G_FILE_TEST_IS_DIR))
527 {
528 directories = g_slist_prepend (directories, desktop_directory);
529 }
530
531 if (directories != NULL((void*)0))
532 {
533 int failed_count;
534 GString *directories_as_string;
535 GSList *l;
536 char *error_string;
537 const char *detail_string;
538 CtkDialog *dialog;
539
540 ret = FALSE(0);
541
542 failed_count = g_slist_length (directories);
543
544 directories_as_string = g_string_new ((const char *)directories->data);
545 for (l = directories->next; l != NULL((void*)0); l = l->next)
546 {
547 g_string_append_printf (directories_as_string, ", %s", (const char *)l->data);
548 }
549
550 if (failed_count == 1)
551 {
552 error_string = g_strdup_printf (_("Baul could not create the required folder \"%s\".")gettext ("Baul could not create the required folder \"%s\"."),
553 directories_as_string->str);
554 detail_string = _("Before running Baul, please create the following folder, or "gettext ("Before running Baul, please create the following folder, or "
"set permissions such that Baul can create it.")
555 "set permissions such that Baul can create it.")gettext ("Before running Baul, please create the following folder, or "
"set permissions such that Baul can create it.")
;
556 }
557 else
558 {
559 error_string = g_strdup_printf (_("Baul could not create the following required folders: "gettext ("Baul could not create the following required folders: "
"%s.")
560 "%s.")gettext ("Baul could not create the following required folders: "
"%s.")
, directories_as_string->str);
561 detail_string = _("Before running Baul, please create these folders, or "gettext ("Before running Baul, please create these folders, or "
"set permissions such that Baul can create them.")
562 "set permissions such that Baul can create them.")gettext ("Before running Baul, please create these folders, or "
"set permissions such that Baul can create them.")
;
563 }
564
565 dialog = eel_show_error_dialog (error_string, detail_string, NULL((void*)0));
566 /* We need the main event loop so the user has a chance to see the dialog. */
567
568 ctk_application_add_window (CTK_APPLICATION (application)((((CtkApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((application)), ((ctk_application_get_type ()))))))
,
569 CTK_WINDOW (dialog)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((dialog)), ((ctk_window_get_type ()))))))
);
570
571 g_string_free (directories_as_string, TRUE)(__builtin_constant_p ((!(0))) ? (((!(0))) ? (g_string_free) (
(directories_as_string), ((!(0)))) : g_string_free_and_steal (
directories_as_string)) : (g_string_free) ((directories_as_string
), ((!(0)))))
;
572 g_free (error_string);
573 }
574
575 g_slist_free (directories);
576 g_free (user_directory);
577 g_free (desktop_directory);
578
579 return ret;
580}
581
582static void
583menu_provider_items_updated_handler (BaulMenuProvider *provider G_GNUC_UNUSED__attribute__ ((__unused__)),
584 CtkWidget *parent_window G_GNUC_UNUSED__attribute__ ((__unused__)),
585 gpointer data G_GNUC_UNUSED__attribute__ ((__unused__)))
586{
587
588 g_signal_emit_by_name (baul_signaller_get_current (),
589 "popup_menu_changed");
590}
591
592static void
593menu_provider_init_callback (void)
594{
595 GList *providers;
596 GList *l;
597
598 providers = baul_extensions_get_for_type (BAUL_TYPE_MENU_PROVIDER(baul_menu_provider_get_type ()));
599
600 for (l = providers; l != NULL((void*)0); l = l->next)
601 {
602 BaulMenuProvider *provider = BAUL_MENU_PROVIDER (l->data)((((BaulMenuProvider*) (void *) g_type_check_instance_cast ((
GTypeInstance*) ((l->data)), ((baul_menu_provider_get_type
()))))))
;
603
604 g_signal_connect_after (G_OBJECT (provider), "items_updated",g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((provider)), (((GType) ((20) << (2)
)))))))), ("items_updated"), ((GCallback)menu_provider_items_updated_handler
), (((void*)0)), ((void*)0), G_CONNECT_AFTER)
605 (GCallback)menu_provider_items_updated_handler,g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((provider)), (((GType) ((20) << (2)
)))))))), ("items_updated"), ((GCallback)menu_provider_items_updated_handler
), (((void*)0)), ((void*)0), G_CONNECT_AFTER)
606 NULL)g_signal_connect_data ((((((GObject*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((provider)), (((GType) ((20) << (2)
)))))))), ("items_updated"), ((GCallback)menu_provider_items_updated_handler
), (((void*)0)), ((void*)0), G_CONNECT_AFTER)
;
607 }
608
609 baul_module_extension_list_free (providers);
610}
611
612static gboolean
613automount_all_volumes_idle_cb (gpointer data)
614{
615 BaulApplication *application = BAUL_APPLICATION (data)((((BaulApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((data)), (baul_application_get_type())))))
;
616
617 automount_all_volumes (application);
618
619 application->automount_idle_id = 0;
620 return FALSE(0);
621}
622
623static void
624selection_get_cb (CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)),
625 CtkSelectionData *selection_data G_GNUC_UNUSED__attribute__ ((__unused__)),
626 guint info G_GNUC_UNUSED__attribute__ ((__unused__)),
627 guint time G_GNUC_UNUSED__attribute__ ((__unused__)))
628{
629 /* No extra targets atm */
630}
631
632static CtkWidget *
633get_desktop_manager_selection (CdkDisplay *display)
634{
635 char selection_name[32];
636 CdkAtom selection_atom;
637 Window selection_owner;
638 CtkWidget *selection_widget;
639
640 g_snprintf (selection_name, sizeof (selection_name), "_NET_DESKTOP_MANAGER_S0");
641 selection_atom = cdk_atom_intern (selection_name, FALSE(0));
642
643 selection_owner = XGetSelectionOwner (CDK_DISPLAY_XDISPLAY (display)(cdk_x11_display_get_xdisplay (display)),
644 cdk_x11_atom_to_xatom_for_display (display,
645 selection_atom));
646 if (selection_owner != None0L)
647 {
648 return NULL((void*)0);
649 }
650
651 selection_widget = ctk_invisible_new_for_screen (cdk_display_get_default_screen (display));
652 /* We need this for cdk_x11_get_server_time() */
653 ctk_widget_add_events (selection_widget, CDK_PROPERTY_CHANGE_MASK);
654
655 if (ctk_selection_owner_set_for_display (display,
656 selection_widget,
657 selection_atom,
658 cdk_x11_get_server_time (ctk_widget_get_window (selection_widget))))
659 {
660
661 g_signal_connect (selection_widget, "selection_get",g_signal_connect_data ((selection_widget), ("selection_get"),
(((GCallback) (selection_get_cb))), (((void*)0)), ((void*)0)
, (GConnectFlags) 0)
662 G_CALLBACK (selection_get_cb), NULL)g_signal_connect_data ((selection_widget), ("selection_get"),
(((GCallback) (selection_get_cb))), (((void*)0)), ((void*)0)
, (GConnectFlags) 0)
;
663 return selection_widget;
664 }
665
666 ctk_widget_destroy (selection_widget);
667
668 return NULL((void*)0);
669}
670
671static void
672desktop_unrealize_cb (CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)),
673 CtkWidget *selection_widget)
674{
675 ctk_widget_destroy (selection_widget);
676}
677
678static gboolean
679selection_clear_event_cb (CtkWidget *widget G_GNUC_UNUSED__attribute__ ((__unused__)),
680 CdkEventSelection *event G_GNUC_UNUSED__attribute__ ((__unused__)),
681 BaulDesktopWindow *window)
682{
683 ctk_widget_destroy (CTK_WIDGET (window)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_widget_get_type ()))))))
);
684
685 baul_application_desktop_windows =
686 g_list_remove (baul_application_desktop_windows, window);
687
688 return TRUE(!(0));
689}
690
691static void
692baul_application_create_desktop_windows (BaulApplication *application)
693{
694 CdkDisplay *display;
695 CtkWidget *selection_widget;
696
697 g_return_if_fail (baul_application_desktop_windows == NULL)do { if ((baul_application_desktop_windows == ((void*)0))) { }
else { g_return_if_fail_warning (((gchar*) 0), ((const char*
) (__func__)), "baul_application_desktop_windows == NULL"); return
; } } while (0)
;
698 g_return_if_fail (BAUL_IS_APPLICATION (application))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((application)); GType __t = (baul_application_get_type())
; gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class
&& __inst->g_class->g_type == __t) __r = (!(0)
); else __r = g_type_check_instance_is_a (__inst, __t); __r; }
)))))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const
char*) (__func__)), "BAUL_IS_APPLICATION (application)"); return
; } } while (0)
;
699 display = cdk_display_get_default ();
700
701 selection_widget = get_desktop_manager_selection (display);
702
703 if (selection_widget != NULL((void*)0))
704 {
705 BaulDesktopWindow *window;
706
707 window = baul_desktop_window_new (application, cdk_display_get_default_screen (display));
708
709 g_signal_connect (selection_widget, "selection_clear_event",g_signal_connect_data ((selection_widget), ("selection_clear_event"
), (((GCallback) (selection_clear_event_cb))), (window), ((void
*)0), (GConnectFlags) 0)
710 G_CALLBACK (selection_clear_event_cb), window)g_signal_connect_data ((selection_widget), ("selection_clear_event"
), (((GCallback) (selection_clear_event_cb))), (window), ((void
*)0), (GConnectFlags) 0)
;
711
712 g_signal_connect (window, "unrealize",g_signal_connect_data ((window), ("unrealize"), (((GCallback)
(desktop_unrealize_cb))), (selection_widget), ((void*)0), (GConnectFlags
) 0)
713 G_CALLBACK (desktop_unrealize_cb), selection_widget)g_signal_connect_data ((window), ("unrealize"), (((GCallback)
(desktop_unrealize_cb))), (selection_widget), ((void*)0), (GConnectFlags
) 0)
;
714
715 /* We realize it immediately so that the BAUL_DESKTOP_WINDOW_ID
716 property is set so cafe-settings-daemon doesn't try to set the
717 background. And we do a cdk_display_flush() to be sure X gets it. */
718 ctk_widget_realize (CTK_WIDGET (window)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_widget_get_type ()))))))
);
719 cdk_display_flush (display);
720
721 baul_application_desktop_windows =
722 g_list_prepend (baul_application_desktop_windows, window);
723 ctk_application_add_window (CTK_APPLICATION (application)((((CtkApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((application)), ((ctk_application_get_type ()))))))
,
724 CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
);
725 }
726}
727
728void
729baul_application_open_desktop (BaulApplication *application)
730{
731 if (baul_application_desktop_windows == NULL((void*)0))
732 {
733 baul_application_create_desktop_windows (application);
734 }
735}
736static void
737baul_application_close_desktop (void)
738{
739 if (baul_application_desktop_windows != NULL((void*)0))
740 {
741 g_list_free_full (baul_application_desktop_windows, (GDestroyNotify) ctk_widget_destroy);
742 baul_application_desktop_windows = NULL((void*)0);
743 }
744}
745
746void
747baul_application_close_all_navigation_windows (BaulApplication *self)
748{
749 GList *list_copy;
750 GList *l;
751 list_copy = g_list_copy (ctk_application_get_windows (CTK_APPLICATION (self)((((CtkApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((self)), ((ctk_application_get_type ()))))))
));
752 /* First hide all window to get the feeling of quick response */
753 for (l = list_copy; l != NULL((void*)0); l = l->next)
754 {
755 BaulWindow *window;
756
757 window = BAUL_WINDOW (l->data)((((BaulWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((l->data)), (baul_window_get_type())))))
;
758
759 if (BAUL_IS_NAVIGATION_WINDOW (window)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) (
(window)); GType __t = (baul_navigation_window_get_type()); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))
)
760 {
761 ctk_widget_hide (CTK_WIDGET (window)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_widget_get_type ()))))))
);
762 }
763 }
764
765 for (l = list_copy; l != NULL((void*)0); l = l->next)
766 {
767 BaulWindow *window;
768
769 window = BAUL_WINDOW (l->data)((((BaulWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((l->data)), (baul_window_get_type())))))
;
770
771 if (BAUL_IS_NAVIGATION_WINDOW (window)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) (
(window)); GType __t = (baul_navigation_window_get_type()); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))
)
772 {
773 baul_window_close (window);
774 }
775 }
776 g_list_free (list_copy);
777}
778
779static BaulSpatialWindow *
780baul_application_get_existing_spatial_window (GFile *location)
781{
782 GList *l;
783 BaulWindowSlot *slot;
784 GFile *window_location = NULL((void*)0);
785
786 for (l = baul_application_get_spatial_window_list ();
787 l != NULL((void*)0); l = l->next) {
788 slot = BAUL_WINDOW (l->data)((((BaulWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((l->data)), (baul_window_get_type())))))
->details->active_pane->active_slot;
789
790 window_location = slot->pending_location;
791
792 if (window_location == NULL((void*)0)) {
793 window_location = slot->location;
794 }
795
796 if (window_location != NULL((void*)0)) {
797 if (g_file_equal (location, window_location)) {
798 return BAUL_SPATIAL_WINDOW (l->data)((((BaulSpatialWindow*) (void *) g_type_check_instance_cast (
(GTypeInstance*) ((l->data)), (baul_spatial_window_get_type
())))))
;
799 }
800 }
801 }
802
803 return NULL((void*)0);
804}
805
806static BaulSpatialWindow *
807find_parent_spatial_window (BaulSpatialWindow *window)
808{
809 BaulFile *file;
810 BaulFile *parent_file;
811 BaulWindowSlot *slot;
812 GFile *location;
813
814 slot = BAUL_WINDOW (window)((((BaulWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), (baul_window_get_type())))))
->details->active_pane->active_slot;
815
816 location = slot->location;
817 if (location == NULL((void*)0))
818 {
819 return NULL((void*)0);
820 }
821 file = baul_file_get (location);
822
823 if (!file)
824 {
825 return NULL((void*)0);
826 }
827
828 parent_file = baul_file_get_parent (file);
829 baul_file_unref (file);
830 while (parent_file)
831 {
832 BaulSpatialWindow *parent_window;
833
834 location = baul_file_get_location (parent_file);
835 parent_window = baul_application_get_existing_spatial_window (location);
836 g_object_unref (location);
837
838 /* Stop at the desktop directory if it's not explicitely opened
839 * in a spatial window of its own.
840 */
841 if (baul_file_is_desktop_directory (parent_file) && !parent_window)
842 {
843 baul_file_unref (parent_file);
844 return NULL((void*)0);
845 }
846
847 if (parent_window)
848 {
849 baul_file_unref (parent_file);
850 return parent_window;
851 }
852 file = parent_file;
853 parent_file = baul_file_get_parent (file);
854 baul_file_unref (file);
855 }
856
857 return NULL((void*)0);
858}
859
860void
861baul_application_close_parent_windows (BaulSpatialWindow *window)
862{
863 BaulSpatialWindow *parent_window;
864 BaulSpatialWindow *new_parent_window;
865
866 g_return_if_fail (BAUL_IS_SPATIAL_WINDOW (window))do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((window)); GType __t = (baul_spatial_window_get_type()); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; })))))) { }
else { g_return_if_fail_warning (((gchar*) 0), ((const char*
) (__func__)), "BAUL_IS_SPATIAL_WINDOW (window)"); return; } }
while (0)
;
867
868 parent_window = find_parent_spatial_window (window);
869
870 while (parent_window)
871 {
872
873 new_parent_window = find_parent_spatial_window (parent_window);
874 baul_window_close (BAUL_WINDOW (parent_window)((((BaulWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((parent_window)), (baul_window_get_type())))))
);
875 parent_window = new_parent_window;
876 }
877}
878
879void
880baul_application_close_all_spatial_windows (void)
881{
882 GList *list_copy;
883 GList *l;
884
885 list_copy = g_list_copy (baul_application_spatial_window_list);
886 /* First hide all window to get the feeling of quick response */
887 for (l = list_copy; l != NULL((void*)0); l = l->next)
888 {
889 BaulWindow *window;
890
891 window = BAUL_WINDOW (l->data)((((BaulWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((l->data)), (baul_window_get_type())))))
;
892
893 if (BAUL_IS_SPATIAL_WINDOW (window)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) (
(window)); GType __t = (baul_spatial_window_get_type()); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))
)
894 {
895 ctk_widget_hide (CTK_WIDGET (window)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_widget_get_type ()))))))
);
896 }
897 }
898
899 for (l = list_copy; l != NULL((void*)0); l = l->next)
900 {
901 BaulWindow *window;
902
903 window = BAUL_WINDOW (l->data)((((BaulWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((l->data)), (baul_window_get_type())))))
;
904
905 if (BAUL_IS_SPATIAL_WINDOW (window)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) (
(window)); GType __t = (baul_spatial_window_get_type()); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))
)
906 {
907 baul_window_close (window);
908 }
909 }
910 g_list_free (list_copy);
911}
912
913static gboolean
914baul_window_delete_event_callback (CtkWidget *widget,
915 CdkEvent *event G_GNUC_UNUSED__attribute__ ((__unused__)),
916 gpointer user_data G_GNUC_UNUSED__attribute__ ((__unused__)))
917{
918 BaulWindow *window;
919
920 window = BAUL_WINDOW (widget)((((BaulWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((widget)), (baul_window_get_type())))))
;
921 baul_window_close (window);
922
923 return TRUE(!(0));
924}
925
926
927static BaulWindow *
928create_window (BaulApplication *application,
929 GType window_type,
930 CdkScreen *screen)
931{
932 BaulWindow *window;
933
934 g_return_val_if_fail (BAUL_IS_APPLICATION (application), NULL)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((application)); GType __t = (baul_application_get_type())
; gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class
&& __inst->g_class->g_type == __t) __r = (!(0)
); else __r = g_type_check_instance_is_a (__inst, __t); __r; }
)))))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const
char*) (__func__)), "BAUL_IS_APPLICATION (application)"); return
(((void*)0)); } } while (0)
;
935
936 window = BAUL_WINDOW (ctk_widget_new (window_type,((((BaulWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((ctk_widget_new (window_type, "app", application, "screen"
, screen, ((void*)0)))), (baul_window_get_type())))))
937 "app", application,((((BaulWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((ctk_widget_new (window_type, "app", application, "screen"
, screen, ((void*)0)))), (baul_window_get_type())))))
938 "screen", screen,((((BaulWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((ctk_widget_new (window_type, "app", application, "screen"
, screen, ((void*)0)))), (baul_window_get_type())))))
939 NULL))((((BaulWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((ctk_widget_new (window_type, "app", application, "screen"
, screen, ((void*)0)))), (baul_window_get_type())))))
;
940 g_signal_connect_data (window, "delete_event",
941 G_CALLBACK (baul_window_delete_event_callback)((GCallback) (baul_window_delete_event_callback)), NULL((void*)0), NULL((void*)0),
942 G_CONNECT_AFTER);
943
944 ctk_application_add_window (CTK_APPLICATION (application)((((CtkApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((application)), ((ctk_application_get_type ()))))))
,
945 CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
);
946
947 /* Do not yet show the window. It will be shown later on if it can
948 * successfully display its initial URI. Otherwise it will be destroyed
949 * without ever having seen the light of day.
950 */
951
952 return window;
953}
954
955static void
956spatial_window_destroyed_callback (void *user_data G_GNUC_UNUSED__attribute__ ((__unused__)),
957 GObject *window)
958{
959 baul_application_spatial_window_list = g_list_remove (baul_application_spatial_window_list, window);
960
961}
962
963BaulWindow *
964baul_application_get_spatial_window (BaulApplication *application,
965 BaulWindow *requesting_window,
966 const char *startup_id G_GNUC_UNUSED__attribute__ ((__unused__)),
967 GFile *location,
968 CdkScreen *screen,
969 gboolean *existing)
970{
971 BaulWindow *window;
972 gchar *uri;
973
974 g_return_val_if_fail (BAUL_IS_APPLICATION (application), NULL)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((application)); GType __t = (baul_application_get_type())
; gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class
&& __inst->g_class->g_type == __t) __r = (!(0)
); else __r = g_type_check_instance_is_a (__inst, __t); __r; }
)))))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const
char*) (__func__)), "BAUL_IS_APPLICATION (application)"); return
(((void*)0)); } } while (0)
;
975 window = BAUL_WINDOW((((BaulWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((baul_application_get_existing_spatial_window (location))
), (baul_window_get_type())))))
976 (baul_application_get_existing_spatial_window (location))((((BaulWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((baul_application_get_existing_spatial_window (location))
), (baul_window_get_type())))))
;
977
978 if (window != NULL((void*)0)) {
979 if (existing != NULL((void*)0)) {
980 *existing = TRUE(!(0));
981 }
982
983 return window;
984 }
985
986 if (existing != NULL((void*)0)) {
987 *existing = FALSE(0);
988 }
989 window = create_window (application, BAUL_TYPE_SPATIAL_WINDOWbaul_spatial_window_get_type(), screen);
990
991 if (requesting_window)
992 {
993 /* Center the window over the requesting window by default */
994 int orig_x, orig_y, orig_width, orig_height;
995 int new_x, new_y, new_width, new_height;
996
997 ctk_window_get_position (CTK_WINDOW (requesting_window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((requesting_window)), ((ctk_window_get_type ()))))))
,
998 &orig_x, &orig_y);
999 ctk_window_get_size (CTK_WINDOW (requesting_window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((requesting_window)), ((ctk_window_get_type ()))))))
,
1000 &orig_width, &orig_height);
1001 ctk_window_get_default_size (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
,
1002 &new_width, &new_height);
1003
1004 new_x = orig_x + (orig_width - new_width) / 2;
1005 new_y = orig_y + (orig_height - new_height) / 2;
1006
1007 if (orig_width - new_width < 10)
1008 {
1009 new_x += 10;
1010 new_y += 10;
1011 }
1012
1013 ctk_window_move (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
, new_x, new_y);
1014 }
1015
1016 baul_application_spatial_window_list = g_list_prepend (baul_application_spatial_window_list, window);
1017 g_object_weak_ref (G_OBJECT (window)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), (((GType) ((20) << (2))))))))
,
1018 spatial_window_destroyed_callback, NULL((void*)0));
1019
1020 uri = g_file_get_uri (location);
1021 baul_debug_log (FALSE(0), BAUL_DEBUG_LOG_DOMAIN_USER"USER",
1022 "present NEW spatial window=%p: %s",
1023 window, uri);
1024 g_free (uri);
1025
1026 return window;
1027}
1028
1029BaulWindow *
1030baul_application_create_navigation_window (BaulApplication *application,
1031 CdkScreen *screen)
1032{
1033 BaulWindow *window;
1034 char *geometry_string;
1035 gboolean maximized;
1036
1037 g_return_val_if_fail (BAUL_IS_APPLICATION (application), NULL)do { if (((((__extension__ ({ GTypeInstance *__inst = (GTypeInstance
*) ((application)); GType __t = (baul_application_get_type())
; gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class
&& __inst->g_class->g_type == __t) __r = (!(0)
); else __r = g_type_check_instance_is_a (__inst, __t); __r; }
)))))) { } else { g_return_if_fail_warning (((gchar*) 0), ((const
char*) (__func__)), "BAUL_IS_APPLICATION (application)"); return
(((void*)0)); } } while (0)
;
1038 window = create_window (application, BAUL_TYPE_NAVIGATION_WINDOWbaul_navigation_window_get_type(), screen);
1039
1040 maximized = g_settings_get_boolean (baul_window_state,
1041 BAUL_WINDOW_STATE_MAXIMIZED"maximized");
1042 if (maximized)
1043 {
1044 ctk_window_maximize (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
);
1045 }
1046 else
1047 {
1048 ctk_window_unmaximize (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
);
1049 }
1050
1051 geometry_string = g_settings_get_string (baul_window_state,
1052 BAUL_WINDOW_STATE_GEOMETRY"geometry");
1053 if (geometry_string != NULL((void*)0) &&
1054 geometry_string[0] != 0)
1055 {
1056 eel_ctk_window_set_initial_geometry_from_string
1057 (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
,
1058 geometry_string,
1059 BAUL_NAVIGATION_WINDOW_MIN_WIDTH200,
1060 BAUL_NAVIGATION_WINDOW_MIN_HEIGHT200,
1061 TRUE(!(0)));
1062 }
1063 g_free (geometry_string);
1064
1065 baul_debug_log (FALSE(0), BAUL_DEBUG_LOG_DOMAIN_USER"USER",
1066 "create new navigation window=%p",
1067 window);
1068
1069 return window;
1070}
1071
1072/* callback for showing or hiding the desktop based on the user's preference */
1073static void
1074desktop_changed_callback (gpointer user_data)
1075{
1076 BaulApplication *application;
1077
1078 application = BAUL_APPLICATION (user_data)((((BaulApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((user_data)), (baul_application_get_type())))))
;
1079 if (g_settings_get_boolean (cafe_background_preferences, CAFE_BG_KEY_SHOW_DESKTOP"show-desktop-icons"))
1080 {
1081 baul_application_open_desktop (application);
1082 }
1083 else
1084 {
1085 baul_application_close_desktop ();
1086 }
1087}
1088
1089static gboolean
1090window_can_be_closed (BaulWindow *window)
1091{
1092 if (!BAUL_IS_DESKTOP_WINDOW (window)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) (
(window)); GType __t = (baul_desktop_window_get_type()); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))
)
1093 {
1094 return TRUE(!(0));
1095 }
1096
1097 return FALSE(0);
1098}
1099
1100static void
1101check_screen_lock_and_mount (BaulApplication *application,
1102 GVolume *volume)
1103{
1104 if (application->screensaver_active)
1105 {
1106 /* queue the volume, to mount it after the screensaver state changed */
1107 g_debug ("Queuing volume %p", volume);
1108 application->volume_queue = g_list_prepend (application->volume_queue,
1109 g_object_ref (volume)((__typeof__ (volume)) (g_object_ref) (volume)));
1110 } else {
1111 /* mount it immediately */
1112 baul_file_operations_mount_volume (NULL((void*)0), volume, TRUE(!(0)));
1113 }
1114}
1115
1116static void
1117volume_removed_callback (GVolumeMonitor *monitor G_GNUC_UNUSED__attribute__ ((__unused__)),
1118 GVolume *volume,
1119 BaulApplication *application)
1120{
1121 g_debug ("Volume %p removed, removing from the queue", volume);
1122
1123 /* clear it from the queue, if present */
1124 application->volume_queue =
1125 g_list_remove (application->volume_queue, volume);
1126}
1127
1128static void
1129volume_added_callback (GVolumeMonitor *monitor G_GNUC_UNUSED__attribute__ ((__unused__)),
1130 GVolume *volume,
1131 BaulApplication *application)
1132{
1133 if (g_settings_get_boolean (baul_media_preferences, BAUL_PREFERENCES_MEDIA_AUTOMOUNT"automount") &&
1134 g_volume_should_automount (volume) &&
1135 g_volume_can_mount (volume))
1136 {
1137 check_screen_lock_and_mount (application, volume);
1138 }
1139 else
1140 {
1141 /* Allow baul_autorun() to run. When the mount is later
1142 * added programmatically (i.e. for a blank CD),
1143 * baul_autorun() will be called by mount_added_callback(). */
1144 baul_allow_autorun_for_volume (volume);
1145 baul_allow_autorun_for_volume_finish (volume);
1146 }
1147}
1148
1149static void
1150drive_eject_cb (GObject *source_object,
1151 GAsyncResult *res,
1152 gpointer user_data G_GNUC_UNUSED__attribute__ ((__unused__)))
1153{
1154 GError *error;
1155 error = NULL((void*)0);
1156
1157 if (!g_drive_eject_with_operation_finish (G_DRIVE (source_object)((((GDrive*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((source_object)), ((g_drive_get_type ()))))))
, res, &error))
1158 {
1159 if (error->code != G_IO_ERROR_FAILED_HANDLED)
1160 {
1161 char *primary;
1162 char *name;
1163
1164 name = g_drive_get_name (G_DRIVE (source_object)((((GDrive*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((source_object)), ((g_drive_get_type ()))))))
);
1165 primary = g_strdup_printf (_("Unable to eject %s")gettext ("Unable to eject %s"), name);
1166 g_free (name);
1167 eel_show_error_dialog (primary,
1168 error->message,
1169 NULL((void*)0));
1170 g_free (primary);
1171 }
1172 g_error_free (error);
1173 }
1174}
1175
1176static void
1177drive_eject_button_pressed (GDrive *drive,
1178 BaulApplication *application G_GNUC_UNUSED__attribute__ ((__unused__)))
1179{
1180 GMountOperation *mount_op;
1181
1182 mount_op = ctk_mount_operation_new (NULL((void*)0));
1183 g_drive_eject_with_operation (drive, 0, mount_op, NULL((void*)0), drive_eject_cb, NULL((void*)0));
1184 g_object_unref (mount_op);
1185}
1186
1187static void
1188drive_listen_for_eject_button (GDrive *drive, BaulApplication *application)
1189{
1190 g_signal_connect (drive,g_signal_connect_data ((drive), ("eject-button"), (((GCallback
) (drive_eject_button_pressed))), (application), ((void*)0), (
GConnectFlags) 0)
1191 "eject-button",g_signal_connect_data ((drive), ("eject-button"), (((GCallback
) (drive_eject_button_pressed))), (application), ((void*)0), (
GConnectFlags) 0)
1192 G_CALLBACK (drive_eject_button_pressed),g_signal_connect_data ((drive), ("eject-button"), (((GCallback
) (drive_eject_button_pressed))), (application), ((void*)0), (
GConnectFlags) 0)
1193 application)g_signal_connect_data ((drive), ("eject-button"), (((GCallback
) (drive_eject_button_pressed))), (application), ((void*)0), (
GConnectFlags) 0)
;
1194}
1195
1196static void
1197drive_connected_callback (GVolumeMonitor *monitor G_GNUC_UNUSED__attribute__ ((__unused__)),
1198 GDrive *drive,
1199 BaulApplication *application)
1200{
1201 drive_listen_for_eject_button (drive, application);
1202}
1203
1204static void
1205autorun_show_window (GMount *mount, gpointer user_data)
1206{
1207 GFile *location;
1208 BaulApplication *application = user_data;
1209 BaulWindow *window;
1210
1211 location = g_mount_get_root (mount);
1212
1213 /* There should probably be an easier way to do this */
1214 if (g_settings_get_boolean (baul_preferences, BAUL_PREFERENCES_ALWAYS_USE_BROWSER"always-use-browser")) {
1215 window = baul_application_create_navigation_window (application,
1216 cdk_screen_get_default ());
1217 }
1218 else
1219 {
1220 window = baul_application_get_spatial_window (application,
1221 NULL((void*)0),
1222 NULL((void*)0),
1223 location,
1224 cdk_screen_get_default (),
1225 NULL((void*)0));
1226 }
1227
1228 baul_window_go_to (window, location);
1229
1230 g_object_unref (location);
1231}
1232
1233static void
1234mount_added_callback (GVolumeMonitor *monitor G_GNUC_UNUSED__attribute__ ((__unused__)),
1235 GMount *mount,
1236 BaulApplication *application)
1237{
1238 BaulDirectory *directory;
1239 GFile *root;
1240 gchar *uri;
1241
1242 root = g_mount_get_root (mount);
1243 uri = g_file_get_uri (root);
1244
1245 g_debug ("Added mount at uri %s", uri);
1246 g_free (uri);
1247
1248 directory = baul_directory_get_existing (root);
1249 g_object_unref (root);
1250 if (directory != NULL((void*)0)) {
1251 baul_directory_force_reload (directory);
1252 baul_directory_unref (directory);
1253 }
1254 baul_autorun (mount, autorun_show_window, application);
1255}
1256
1257static BaulWindowSlot *
1258get_first_navigation_slot (GList *slot_list)
1259{
1260 GList *l;
1261
1262 for (l = slot_list; l != NULL((void*)0); l = l->next)
1263 {
1264 if (BAUL_IS_NAVIGATION_WINDOW_SLOT (l->data)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) (
(l->data)); GType __t = ((baul_navigation_window_slot_get_type
())); gboolean __r; if (!__inst) __r = (0); else if (__inst->
g_class && __inst->g_class->g_type == __t) __r =
(!(0)); else __r = g_type_check_instance_is_a (__inst, __t);
__r; }))))
)
1265 {
1266 return l->data;
1267 }
1268 }
1269
1270 return NULL((void*)0);
1271}
1272
1273/* We redirect some slots and close others */
1274static gboolean
1275should_close_slot_with_mount (BaulWindow *window,
1276 BaulWindowSlot *slot,
1277 GMount *mount)
1278{
1279 if (BAUL_IS_SPATIAL_WINDOW (window)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) (
(window)); GType __t = (baul_spatial_window_get_type()); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))
)
1280 {
1281 return TRUE(!(0));
1282 }
1283 return baul_navigation_window_slot_should_close_with_mount (BAUL_NAVIGATION_WINDOW_SLOT (slot)((((BaulNavigationWindowSlot*) (void *) g_type_check_instance_cast
((GTypeInstance*) ((slot)), ((baul_navigation_window_slot_get_type
()))))))
,
1284 mount);
1285}
1286
1287/* Called whenever a mount is unmounted. Check and see if there are
1288 * any windows open displaying contents on the mount. If there are,
1289 * close them. It would also be cool to save open window and position
1290 * info.
1291 *
1292 * This is also called on pre_unmount.
1293 */
1294static void
1295mount_removed_callback (GVolumeMonitor *monitor G_GNUC_UNUSED__attribute__ ((__unused__)),
1296 GMount *mount,
1297 BaulApplication *application)
1298{
1299 GList *window_list, *node, *close_list;
1300 BaulWindow *window;
1301 BaulWindowSlot *slot;
1302 BaulWindowSlot *force_no_close_slot;
1303 GFile *root, *computer;
1304 gboolean unclosed_slot;
1305
1306 close_list = NULL((void*)0);
1307 force_no_close_slot = NULL((void*)0);
1308 unclosed_slot = FALSE(0);
1309
1310 /* Check and see if any of the open windows are displaying contents from the unmounted mount */
1311 window_list = ctk_application_get_windows (CTK_APPLICATION (application)((((CtkApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((application)), ((ctk_application_get_type ()))))))
);
1312 root = g_mount_get_root (mount);
1313 /* Construct a list of windows to be closed. Do not add the non-closable windows to the list. */
1314 for (node = window_list; node != NULL((void*)0); node = node->next)
1315 {
1316 window = BAUL_WINDOW (node->data)((((BaulWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((node->data)), (baul_window_get_type())))))
;
1317 if (window != NULL((void*)0) && window_can_be_closed (window))
1318 {
1319 GList *l;
1320 GList *lp;
1321 GFile *location;
1322
1323 for (lp = window->details->panes; lp != NULL((void*)0); lp = lp->next)
1324 {
1325 BaulWindowPane *pane;
1326 pane = (BaulWindowPane*) lp->data;
1327 for (l = pane->slots; l != NULL((void*)0); l = l->next)
1328 {
1329 slot = l->data;
1330 location = slot->location;
1331 if (g_file_has_prefix (location, root) ||
1332 g_file_equal (location, root))
1333 {
1334 close_list = g_list_prepend (close_list, slot);
1335
1336 if (!should_close_slot_with_mount (window, slot, mount))
1337 {
1338 /* We'll be redirecting this, not closing */
1339 unclosed_slot = TRUE(!(0));
1340 }
1341 }
1342 else
1343 {
1344 unclosed_slot = TRUE(!(0));
1345 }
1346 } /* for all slots */
1347 } /* for all panes */
1348 }
1349 }
1350
1351 if (baul_application_desktop_windows == NULL((void*)0) &&
1352 !unclosed_slot)
1353 {
1354 /* We are trying to close all open slots. Keep one navigation slot open. */
1355 force_no_close_slot = get_first_navigation_slot (close_list);
1356 }
1357
1358 /* Handle the windows in the close list. */
1359 for (node = close_list; node != NULL((void*)0); node = node->next)
1360 {
1361 slot = node->data;
1362 window = slot->pane->window;
1363
1364 if (should_close_slot_with_mount (window, slot, mount) &&
1365 slot != force_no_close_slot)
1366 {
1367 baul_window_slot_close (slot);
1368 }
1369 else
1370 {
1371 computer = g_file_new_for_uri ("computer:///");
1372 baul_window_slot_go_to (slot, computer, FALSE)baul_window_slot_open_location_full(slot, computer, BAUL_WINDOW_OPEN_ACCORDING_TO_MODE
, ((0) ? BAUL_WINDOW_OPEN_FLAG_NEW_TAB : 0), ((void*)0), ((void
*)0), ((void*)0))
;
1373 g_object_unref(computer);
1374 }
1375 }
1376
1377 g_list_free (close_list);
1378}
1379
1380static char *
1381baul_application_get_session_data (BaulApplication *self)
1382{
1383 xmlDocPtr doc;
1384 xmlNodePtr root_node, history_node;
1385 GList *l, *window_list;
1386
1387 char *data;
1388 unsigned n_processed;
1389 xmlSaveCtxtPtr ctx;
1390 xmlBufferPtr buffer;
1391
1392 doc = xmlNewDoc ("1.0");
1393
1394 root_node = xmlNewNode (NULL((void*)0), "session");
1395 xmlDocSetRootElement (doc, root_node);
1396
1397 history_node = xmlNewChild (root_node, NULL((void*)0), "history", NULL((void*)0));
1398
1399 n_processed = 0;
1400 for (l = baul_get_history_list (); l != NULL((void*)0); l = l->next) {
1401 BaulBookmark *bookmark;
1402 xmlNodePtr bookmark_node;
1403 GIcon *icon;
1404 char *tmp;
1405
1406 bookmark = l->data;
1407
1408 bookmark_node = xmlNewChild (history_node, NULL((void*)0), "bookmark", NULL((void*)0));
1409
1410 tmp = baul_bookmark_get_name (bookmark);
1411 xmlNewProp (bookmark_node, "name", tmp);
1412 g_free (tmp);
1413
1414 icon = baul_bookmark_get_icon (bookmark);
1415
1416 tmp = g_icon_to_string (icon);
1417 g_object_unref (icon);
1418 if (tmp) {
1419 xmlNewProp (bookmark_node, "icon", tmp);
1420 g_free (tmp);
1421 }
1422
1423 tmp = baul_bookmark_get_uri (bookmark);
1424 xmlNewProp (bookmark_node, "uri", tmp);
1425 g_free (tmp);
1426
1427 if (baul_bookmark_get_has_custom_name (bookmark)) {
1428 xmlNewProp (bookmark_node, "has_custom_name", "TRUE");
1429 }
1430
1431 if (++n_processed > 50) { /* prevent history list from growing arbitrarily large. */
1432 break;
1433 }
1434 }
1435 window_list = ctk_application_get_windows (CTK_APPLICATION (self)((((CtkApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((self)), ((ctk_application_get_type ()))))))
);
1436 for (l = window_list; l != NULL((void*)0); l = l->next) {
1437 xmlNodePtr win_node, slot_node;
1438 BaulWindow *window;
1439 GList *slots, *m;
1440 char *tmp;
1441 BaulWindowSlot *active_slot;
1442 BaulWindowSlot *slot = NULL((void*)0);
1443
1444 window = l->data;
1445
1446 slots = baul_window_get_slots (window);
1447 active_slot = baul_window_get_active_slot (window);
1448
1449 /* store one slot as window location. Otherwise
1450 * older Baul versions will bail when reading the file. */
1451 tmp = baul_window_slot_get_location_uri (active_slot);
1452
1453 if (eel_uri_is_desktop (tmp)) {
1454 g_list_free (slots);
1455 g_free (tmp);
1456 continue;
1457 }
1458
1459 win_node = xmlNewChild (root_node, NULL((void*)0), "window", NULL((void*)0));
1460
1461 xmlNewProp (win_node, "location", tmp);
1462 g_free (tmp);
1463
1464 xmlNewProp (win_node, "type", BAUL_IS_NAVIGATION_WINDOW (window)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) (
(window)); GType __t = (baul_navigation_window_get_type()); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))
? "navigation" : "spatial");
1465
1466 if (BAUL_IS_NAVIGATION_WINDOW (window)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) (
(window)); GType __t = (baul_navigation_window_get_type()); gboolean
__r; if (!__inst) __r = (0); else if (__inst->g_class &&
__inst->g_class->g_type == __t) __r = (!(0)); else __r
= g_type_check_instance_is_a (__inst, __t); __r; }))))
) { /* spatial windows store their state as file metadata */
1467 CdkWindow *cdk_window;
1468
1469 tmp = eel_ctk_window_get_geometry_string (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
);
1470 xmlNewProp (win_node, "geometry", tmp);
1471 g_free (tmp);
1472
1473 cdk_window = ctk_widget_get_window (CTK_WIDGET (window)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_widget_get_type ()))))))
);
1474
1475 if (cdk_window &&
1476 cdk_window_get_state (cdk_window) & CDK_WINDOW_STATE_MAXIMIZED) {
1477 xmlNewProp (win_node, "maximized", "TRUE");
1478 }
1479
1480 if (cdk_window &&
1481 cdk_window_get_state (cdk_window) & CDK_WINDOW_STATE_STICKY) {
1482 xmlNewProp (win_node, "sticky", "TRUE");
1483 }
1484
1485 if (cdk_window &&
1486 cdk_window_get_state (cdk_window) & CDK_WINDOW_STATE_ABOVE) {
1487 xmlNewProp (win_node, "keep-above", "TRUE");
1488 }
1489 }
1490
1491 for (m = slots; m != NULL((void*)0); m = m->next) {
1492 slot = BAUL_WINDOW_SLOT (m->data)((((BaulWindowSlot*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((m->data)), ((baul_window_slot_get_type()))))))
;
1493
1494 slot_node = xmlNewChild (win_node, NULL((void*)0), "slot", NULL((void*)0));
1495
1496 tmp = baul_window_slot_get_location_uri (slot);
1497 xmlNewProp (slot_node, "location", tmp);
1498 g_free (tmp);
1499
1500 if (slot == active_slot) {
1501 xmlNewProp (slot_node, "active", "TRUE");
1502 }
1503 }
1504
1505 g_list_free (slots);
1506 }
1507
1508 buffer = xmlBufferCreate ();
1509 xmlIndentTreeOutput(*(__xmlIndentTreeOutput())) = 1;
1510 ctx = xmlSaveToBuffer (buffer, "UTF-8", XML_SAVE_FORMAT);
1511 if (xmlSaveDoc (ctx, doc) < 0 ||
1512 xmlSaveFlush (ctx) < 0) {
1513 g_message ("failed to save session");
1514 }
1515
1516 xmlSaveClose(ctx);
1517 data = g_strndup (buffer->content, buffer->use);
1518 xmlBufferFree (buffer);
1519
1520 xmlFreeDoc (doc);
1521
1522 return data;
1523}
1524
1525static void
1526baul_application_load_session (BaulApplication *application)
1527
1528{
1529 xmlDocPtr doc;
1530 gboolean bail;
1531 xmlNodePtr root_node;
1532 GKeyFile *state_file;
1533 char *data;
1534 baul_application_smclient_initialize (application);
1535 if (!egg_sm_client_is_resumed (application->smclient))
1536 {
1537 return;
1538 }
1539
1540 state_file = egg_sm_client_get_state_file (application->smclient);
1541 if (!state_file)
1542 {
1543 return;
1544 }
1545
1546 data = g_key_file_get_string (state_file,
1547 "Baul",
1548 "documents",
1549 NULL((void*)0));
1550 if (data == NULL((void*)0))
1551 {
1552 return;
1553 }
1554
1555 bail = TRUE(!(0));
1556
1557 doc = xmlReadMemory (data, strlen (data), NULL((void*)0), "UTF-8", 0);
1558 if (doc != NULL((void*)0) && (root_node = xmlDocGetRootElement (doc)) != NULL((void*)0))
1559 {
1560 xmlNodePtr node;
1561
1562 bail = FALSE(0);
1563
1564 for (node = root_node->children; node != NULL((void*)0); node = node->next)
1565 {
1566
1567 if (g_strcmp0 (node->name, "text") == 0)
1568 {
1569 continue;
1570 }
1571 else if (g_strcmp0 (node->name, "history") == 0)
1572 {
1573 xmlNodePtr bookmark_node;
1574 gboolean emit_change;
1575
1576 emit_change = FALSE(0);
1577
1578 for (bookmark_node = node->children; bookmark_node != NULL((void*)0); bookmark_node = bookmark_node->next)
1579 {
1580 if (g_strcmp0 (bookmark_node->name, "text") == 0)
1581 {
1582 continue;
1583 }
1584 else if (g_strcmp0 (bookmark_node->name, "bookmark") == 0)
1585 {
1586 xmlChar *name, *icon_str, *uri;
1587 gboolean has_custom_name;
1588 GIcon *icon;
1589 GFile *location;
1590
1591 uri = xmlGetProp (bookmark_node, "uri");
1592 name = xmlGetProp (bookmark_node, "name");
1593 has_custom_name = xmlHasProp (bookmark_node, "has_custom_name") ? TRUE(!(0)) : FALSE(0);
1594 icon_str = xmlGetProp (bookmark_node, "icon");
1595 icon = NULL((void*)0);
1596 if (icon_str)
1597 {
1598 icon = g_icon_new_for_string (icon_str, NULL((void*)0));
1599 }
1600 location = g_file_new_for_uri (uri);
1601
1602 emit_change |= baul_add_to_history_list_no_notify (location, name, has_custom_name, icon);
1603
1604 g_object_unref (location);
1605
1606 if (icon)
1607 {
1608 g_object_unref (icon);
1609 }
1610 xmlFree (name);
1611 xmlFree (uri);
1612 xmlFree (icon_str);
1613 }
1614 else
1615 {
1616 g_message ("unexpected bookmark node %s while parsing session data", bookmark_node->name);
1617 bail = TRUE(!(0));
1618 continue;
1619 }
1620 }
1621
1622 if (emit_change)
1623 {
1624 baul_send_history_list_changed ();
1625 }
1626 }
1627
1628 else if (g_strcmp0 (node->name, "window") == 0)
1629
1630 {
1631 BaulWindow *window;
1632 xmlChar *type, *location_uri;
1633 xmlNodePtr slot_node;
1634 GFile *location;
1635
1636 type = xmlGetProp (node, "type");
1637 if (type == NULL((void*)0))
1638 {
1639 g_message ("empty type node while parsing session data");
1640 bail = TRUE(!(0));
1641 continue;
1642 }
1643
1644 location_uri = xmlGetProp (node, "location");
1645 if (location_uri == NULL((void*)0))
1646 {
1647 g_message ("empty location node while parsing session data");
1648 bail = TRUE(!(0));
1649 xmlFree (type);
1650 continue;
1651 }
1652
1653 if (g_strcmp0 (type, "navigation") == 0)
1654 {
1655 xmlChar *geometry;
1656 int i;
1657
1658 window = baul_application_create_navigation_window (application, cdk_screen_get_default ());
1659 geometry = xmlGetProp (node, "geometry");
1660 if (geometry != NULL((void*)0))
1661 {
1662 eel_ctk_window_set_initial_geometry_from_string
1663 (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
,
1664 geometry,
1665 BAUL_NAVIGATION_WINDOW_MIN_WIDTH200,
1666 BAUL_NAVIGATION_WINDOW_MIN_HEIGHT200,
1667 FALSE(0));
1668 }
1669 xmlFree (geometry);
1670
1671 if (xmlHasProp (node, "maximized"))
1672 {
1673 ctk_window_maximize (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
);
1674 }
1675 else
1676 {
1677 ctk_window_unmaximize (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
);
1678 }
1679
1680 if (xmlHasProp (node, "sticky"))
1681 {
1682 ctk_window_stick (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
);
1683 }
1684 else
1685 {
1686 ctk_window_unstick (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
);
1687 }
1688
1689 if (xmlHasProp (node, "keep-above"))
1690 {
1691 ctk_window_set_keep_above (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
, TRUE(!(0)));
1692 }
1693 else
1694 {
1695 ctk_window_set_keep_above (CTK_WINDOW (window)((((CtkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((window)), ((ctk_window_get_type ()))))))
, FALSE(0));
1696 }
1697
1698 for (i = 0, slot_node = node->children; slot_node != NULL((void*)0); slot_node = slot_node->next)
1699 {
1700 if (g_strcmp0 (slot_node->name, "slot") == 0)
1701 {
1702 xmlChar *slot_uri;
1703
1704 slot_uri = xmlGetProp (slot_node, "location");
1705 if (slot_uri != NULL((void*)0))
1706 {
1707 BaulWindowSlot *slot;
1708
1709 if (i == 0)
1710 {
1711 slot = window->details->active_pane->active_slot;
1712 }
1713 else
1714 {
1715 slot = baul_window_open_slot (window->details->active_pane, BAUL_WINDOW_OPEN_SLOT_APPEND);
1716 }
1717
1718 location = g_file_new_for_uri (slot_uri);
1719 baul_window_slot_open_location (slot, location, FALSE(0));
1720
1721 if (xmlHasProp (slot_node, "active"))
1722 {
1723 baul_window_set_active_slot (slot->pane->window, slot);
1724 }
1725
1726 i++;
1727 }
1728 xmlFree (slot_uri);
1729 }
1730 }
1731
1732 if (i == 0)
1733 {
1734 /* This may be an old session file */
1735 location = g_file_new_for_uri (location_uri);
1736 baul_window_slot_open_location (window->details->active_pane->active_slot, location, FALSE(0));
1737 g_object_unref (location);
1738 }
1739 }
1740 else if (g_strcmp0 (type, "spatial") == 0)
1741 {
1742 location = g_file_new_for_uri (location_uri);
1743 window = baul_application_get_spatial_window (application, NULL((void*)0), NULL((void*)0),
1744 location, cdk_screen_get_default (),
1745 NULL((void*)0));
1746
1747 baul_window_go_to (window, location);
1748
1749 g_object_unref (location);
1750 }
1751 else
1752 {
1753 g_message ("unknown window type \"%s\" while parsing session data", type);
1754 bail = TRUE(!(0));
1755 }
1756
1757 xmlFree (type);
1758 xmlFree (location_uri);
1759 }
1760 else
1761 {
1762 g_message ("unexpected node %s while parsing session data", node->name);
1763 bail = TRUE(!(0));
1764 continue;
1765 }
1766 }
1767 }
1768
1769 if (doc != NULL((void*)0))
1770 {
1771 xmlFreeDoc (doc);
1772 }
1773
1774 g_free (data);
1775
1776 if (bail)
1777 {
1778 g_message ("failed to load session");
1779 }
1780}
1781
1782static gboolean
1783do_cmdline_sanity_checks (BaulApplication *self,
1784 gboolean perform_self_check,
1785 gboolean version G_GNUC_UNUSED__attribute__ ((__unused__)),
1786 gboolean kill_shell,
1787 gchar **remaining)
1788{
1789 gboolean retval = FALSE(0);
1790
1791 if (perform_self_check && (remaining != NULL((void*)0) || kill_shell)) {
1792 g_printerr ("%s\n",
1793 _("--check cannot be used with other options.")gettext ("--check cannot be used with other options."));
1794 goto out;
1795 }
1796
1797 if (kill_shell && remaining != NULL((void*)0)) {
1798 g_printerr ("%s\n",
1799 _("--quit cannot be used with URIs.")gettext ("--quit cannot be used with URIs."));
1800 goto out;
1801 }
1802
1803 if (self->priv->geometry != NULL((void*)0) &&
1804 remaining != NULL((void*)0) && remaining[0] != NULL((void*)0) && remaining[1] != NULL((void*)0)) {
1805 g_printerr ("%s\n",
1806 _("--geometry cannot be used with more than one URI.")gettext ("--geometry cannot be used with more than one URI."));
1807 goto out;
1808 }
1809
1810 retval = TRUE(!(0));
1811
1812 out:
1813 return retval;
1814}
1815
1816static void
1817do_perform_self_checks (gint *exit_status)
1818{
1819#ifndef BAUL_OMIT_SELF_CHECK
1820 /* Run the checks (each twice) for baul and libbaul-private. */
1821
1822 baul_run_self_checks ();
1823 baul_run_lib_self_checks ();
1824 eel_exit_if_self_checks_failed ();
1825
1826 baul_run_self_checks ();
1827 baul_run_lib_self_checks ();
1828 eel_exit_if_self_checks_failed ();
1829#endif
1830
1831 *exit_status = EXIT_SUCCESS0;
1832}
1833
1834static gboolean
1835running_in_cafe (void)
1836{
1837 return (g_strcmp0 (g_getenv ("XDG_CURRENT_DESKTOP"), "CAFE") == 0)
1838 || (g_strcmp0 (g_getenv ("XDG_SESSION_DESKTOP"), "cafe") == 0)
1839 || (g_strcmp0 (g_getenv ("DESKTOP_SESSION"), "cafe") == 0);
1840}
1841
1842static gboolean
1843running_as_root (void)
1844{
1845 return geteuid () == 0;
1846}
1847
1848static gboolean
1849baul_application_local_command_line (GApplication *application,
1850 gchar ***arguments,
1851 gint *exit_status)
1852{
1853 gboolean perform_self_check = FALSE(0);
1854 gboolean version = FALSE(0);
1855 gboolean browser_window = FALSE(0);
1856 gboolean open_in_tabs = FALSE(0);
1857 gboolean kill_shell = FALSE(0);
1858 const gchar *autostart_id;
1859 gboolean no_default_window = FALSE(0);
1860 gchar **remaining = NULL((void*)0);
1861 BaulApplication *self = BAUL_APPLICATION (application)((((BaulApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((application)), (baul_application_get_type())))))
;
1862
1863 /*First set these FALSE */
1864 self->priv->force_desktop = FALSE(0);
1865 self->priv->no_desktop = FALSE(0);
1866
1867 const GOptionEntry options[] = {
1868#ifndef BAUL_OMIT_SELF_CHECK
1869 { "check", 'c', 0, G_OPTION_ARG_NONE, &perform_self_check,
1870 N_("Perform a quick set of self-check tests.")("Perform a quick set of self-check tests."), NULL((void*)0) },
1871#endif
1872 { "version", '\0', 0, G_OPTION_ARG_NONE, &version,
1873 N_("Show the version of the program.")("Show the version of the program."), NULL((void*)0) },
1874 { "geometry", 'g', 0, G_OPTION_ARG_STRING, &self->priv->geometry,
1875 N_("Create the initial window with the given geometry.")("Create the initial window with the given geometry."), N_("GEOMETRY")("GEOMETRY") },
1876 { "no-default-window", 'n', 0, G_OPTION_ARG_NONE, &no_default_window,
1877 N_("Only create windows for explicitly specified URIs.")("Only create windows for explicitly specified URIs."), NULL((void*)0) },
1878 { "no-desktop", '\0', 0, G_OPTION_ARG_NONE, &self->priv->no_desktop,
1879 N_("Do not manage the desktop (ignore the preference set in the preferences dialog).")("Do not manage the desktop (ignore the preference set in the preferences dialog)."
)
, NULL((void*)0) },
1880 { "force-desktop", '\0', 0, G_OPTION_ARG_NONE, &self->priv->force_desktop,
1881 N_("Manage the desktop regardless of set preferences or environment (on new startup only)")("Manage the desktop regardless of set preferences or environment (on new startup only)"
)
, NULL((void*)0) },
1882 { "tabs", 't', 0, G_OPTION_ARG_NONE, &open_in_tabs,
1883 N_("Open URIs in tabs.")("Open URIs in tabs."), NULL((void*)0) },
1884 { "browser", '\0', 0, G_OPTION_ARG_NONE, &browser_window,
1885 N_("Open a browser window.")("Open a browser window."), NULL((void*)0) },
1886 { "quit", 'q', 0, G_OPTION_ARG_NONE, &kill_shell,
1887 N_("Quit Baul.")("Quit Baul."), NULL((void*)0) },
1888 { G_OPTION_REMAINING"", 0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining, NULL((void*)0), N_("[URI...]")("[URI...]") },
1889
1890 { NULL((void*)0) }
1891 };
1892 GOptionContext *context;
1893 GError *error = NULL((void*)0);
1894 gint argc = 0;
1895 gchar **argv = NULL((void*)0);
1896
1897 *exit_status = EXIT_SUCCESS0;
1898
1899 context = g_option_context_new (_("\n\nBrowse the file system with the file manager")gettext ("\n\nBrowse the file system with the file manager"));
1900 g_option_context_add_main_entries (context, options, NULL((void*)0));
1901 g_option_context_add_group (context, ctk_get_option_group (TRUE(!(0))));
1902
1903 g_option_context_add_group (context, egg_sm_client_get_option_group ());
1904
1905
1906 /* we need to do this here, as parsing the EggSMClient option context,
1907 * unsets this variable.
1908 */
1909 autostart_id = g_getenv ("DESKTOP_AUTOSTART_ID");
1910 if (autostart_id != NULL((void*)0) && *autostart_id != '\0') {
1911 no_default_window = TRUE(!(0));
1912 self->priv->autostart = TRUE(!(0));
1913 }
1914
1915
1916 argv = *arguments;
1917 argc = g_strv_length (argv);
1918
1919 if (!g_option_context_parse (context, &argc, &argv, &error)) {
1920 g_printerr ("Could not parse arguments: %s\n", error->message);
1921 g_error_free (error);
1922
1923 *exit_status = EXIT_FAILURE1;
1924 goto out;
1925 }
1926
1927 if (version) {
1928 g_print ("CAFE baul " PACKAGE_VERSION"2.0.0" "\n");
1929 goto out;
1930 }
1931
1932 if (!do_cmdline_sanity_checks (self, perform_self_check,
1933 version, kill_shell, remaining)) {
1934 *exit_status = EXIT_FAILURE1;
1935 goto out;
1936 }
1937
1938 if (perform_self_check) {
1939 do_perform_self_checks (exit_status);
1940 goto out;
1941 }
1942
1943 g_debug ("Parsing local command line, no_default_window %d, quit %d, "
1944 "self checks %d, no_desktop %d",
1945 no_default_window, kill_shell, perform_self_check, self->priv->no_desktop);
1946
1947 g_application_register (application, NULL((void*)0), &error);
1948
1949 if (error != NULL((void*)0)) {
1950 g_printerr ("Could not register the application: %s\n", error->message);
1951 g_error_free (error);
1952
1953 *exit_status = EXIT_FAILURE1;
1954 goto out;
1955 }
1956
1957 if (kill_shell) {
1958 g_debug ("Killing application, as requested");
1959 g_action_group_activate_action (G_ACTION_GROUP (application)((((GActionGroup*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((application)), ((g_action_group_get_type ()))))))
,
1960 "quit", NULL((void*)0));
1961 goto out;
1962 }
1963
1964 /* Initialize and load session info if available */
1965 /* Load session if and only if autostarted */
1966 /* This avoids errors on command line invocation */
1967 if (autostart_id != NULL((void*)0) && self->smclient != NULL((void*)0) ) {
1968 baul_application_load_session (self);
1969 }
1970
1971 GFile **files;
1972 gint idx, len;
1973
1974 len = 0;
1975 files = NULL((void*)0);
1976
1977 /* Convert args to GFiles */
1978 if (remaining != NULL((void*)0)) {
1979 GPtrArray *file_array;
1980 GFile *file = NULL((void*)0);
1981
1982 file_array = g_ptr_array_new ();
1983
1984 for (idx = 0; remaining[idx] != NULL((void*)0); idx++) {
1985 file = g_file_new_for_commandline_arg (remaining[idx]);
1986 if (file != NULL((void*)0)) {
1987 g_ptr_array_add (file_array, file);
1988 }
1989 }
1990
1991 len = file_array->len;
1992 files = (GFile **) g_ptr_array_free (file_array, FALSE(0));
1993 g_strfreev (remaining);
1994 }
1995
1996 if (files == NULL((void*)0) && !no_default_window) {
1997 files = g_malloc0 (2 * sizeof (GFile *));
1998 len = 1;
1999
2000 files[0] = g_file_new_for_path (g_get_home_dir ());
2001 files[1] = NULL((void*)0);
2002 }
2003
2004 /*Set up --geometry, --browser and --tabs options */
2005 /*Invoke "Open" to create new windows */
2006 if (len > 0) {
2007 gchar* concatOptions = g_malloc0(64);
2008 if (self->priv->geometry == NULL((void*)0)) {
2009 g_snprintf (concatOptions, 64, "%d=NULL=%d", browser_window, open_in_tabs);
2010 } else {
2011 g_snprintf (concatOptions, 64, "%d=%s=%d", browser_window, self->priv->geometry, open_in_tabs);
2012 }
2013 g_application_open (application, files, len, concatOptions);
2014 g_free (concatOptions);
2015 }
2016
2017 if (files)
2018 for (idx = 0; idx < len; idx++) {
2019 g_object_unref (files[idx]);
2020 }
2021 g_free (files);
2022
2023 out:
2024 g_option_context_free (context);
2025
2026 return TRUE(!(0));
2027}
2028
2029static void
2030load_custom_css (CtkCssProvider *provider,
2031 const gchar *filename,
2032 guint priority)
2033{
2034 GError *error = NULL((void*)0);
2035 gchar *path = g_build_filename (BAUL_DATADIR"/usr/share/baul", filename, NULL((void*)0));
2036
2037 if (provider)
2038 g_object_ref (provider)((__typeof__ (provider)) (g_object_ref) (provider));
2039 else
2040 provider = ctk_css_provider_new ();
2041
2042 ctk_css_provider_load_from_path (provider, path, &error);
2043
2044 if (error != NULL((void*)0)) {
2045 g_warning ("Can't parse Baul' CSS custom description '%s': %s\n",
2046 filename, error->message);
2047 g_error_free (error);
2048 } else {
2049 ctk_style_context_add_provider_for_screen (cdk_screen_get_default (),
2050 CTK_STYLE_PROVIDER (provider)((((CtkStyleProvider*) (void *) g_type_check_instance_cast ((
GTypeInstance*) ((provider)), ((ctk_style_provider_get_type (
)))))))
,
2051 priority);
2052 }
2053
2054 g_object_unref (provider);
2055 g_free (path);
2056}
2057
2058static void
2059reload_theme_css (CtkSettings *settings,
2060 GParamSpec *unused G_GNUC_UNUSED__attribute__ ((__unused__)),
2061 CtkCssProvider *provider)
2062{
2063 gchar *theme_name;
2064 gchar *css_theme_name;
2065 gchar *path;
2066
2067 g_object_get (settings, "ctk-theme-name", &theme_name, NULL((void*)0));
2068 css_theme_name = g_strconcat ("baul-desktop-", theme_name, ".css", NULL((void*)0));
2069 path = g_build_filename (BAUL_DATADIR"/usr/share/baul", css_theme_name, NULL((void*)0));
2070
2071 if (g_file_test (path, G_FILE_TEST_EXISTS))
2072 load_custom_css (provider, css_theme_name, CTK_STYLE_PROVIDER_PRIORITY_APPLICATION600);
2073 else /* just empty the provider */
2074 ctk_css_provider_load_from_data (provider, "", 0, NULL((void*)0));
2075
2076 g_free (path);
2077 g_free (css_theme_name);
2078 g_free (theme_name);
2079}
2080
2081static void
2082init_icons_and_styles (void)
2083{
2084 CtkSettings *settings = ctk_settings_get_default ();
2085 CtkCssProvider *provider;
2086
2087 g_object_set (settings, "ctk-button-images", TRUE(!(0)), NULL((void*)0));
2088 g_object_set (settings, "ctk-menu-images", TRUE(!(0)), NULL((void*)0));
2089
2090 /* add our custom CSS provider */
2091 load_custom_css (NULL((void*)0), "baul.css", CTK_STYLE_PROVIDER_PRIORITY_THEME200);
2092 /* add our desktop CSS provider, ensures the desktop background does not get covered */
2093 load_custom_css (NULL((void*)0), "baul-desktop.css", CTK_STYLE_PROVIDER_PRIORITY_APPLICATION600);
2094 /* add theme-specific desktop CSS */
2095 provider = ctk_css_provider_new ();
2096 reload_theme_css (settings, NULL((void*)0), provider);
2097 g_signal_connect_data (settings, "notify::ctk-theme-name", G_CALLBACK (reload_theme_css)((GCallback) (reload_theme_css)),
2098 provider, (GClosureNotify) g_object_unref, 0);
2099
2100 /* initialize search path for custom icons */
2101 ctk_icon_theme_append_search_path (ctk_icon_theme_get_default (),
2102 BAUL_DATADIR"/usr/share/baul" G_DIR_SEPARATOR_S"/" "icons");
2103}
2104
2105static void
2106init_desktop (BaulApplication *self)
2107{
2108 /* Initialize the desktop link monitor singleton */
2109 baul_desktop_link_monitor_get ();
2110
2111 if (!self->priv->no_desktop &&
2112 !g_settings_get_boolean (cafe_background_preferences,
2113 CAFE_BG_KEY_SHOW_DESKTOP"show-desktop-icons")) {
2114 self->priv->no_desktop = TRUE(!(0));
2115 }
2116
2117 if (running_as_root () || !running_in_cafe ())
2118 {
2119 /* do not manage desktop when running as root or on other desktops unless forced */
2120 self->priv->no_desktop = TRUE(!(0));
2121 }
2122
2123 if (!self->priv->no_desktop || self->priv->force_desktop) {
2124 baul_application_open_desktop (self);
2125 }
2126
2127 /* Monitor the preference to show or hide the desktop */
2128 g_signal_connect_swapped (cafe_background_preferences, "changed::" CAFE_BG_KEY_SHOW_DESKTOP,g_signal_connect_data ((cafe_background_preferences), ("changed::"
"show-desktop-icons"), (((GCallback) (desktop_changed_callback
))), (self), ((void*)0), G_CONNECT_SWAPPED)
2129 G_CALLBACK (desktop_changed_callback),g_signal_connect_data ((cafe_background_preferences), ("changed::"
"show-desktop-icons"), (((GCallback) (desktop_changed_callback
))), (self), ((void*)0), G_CONNECT_SWAPPED)
2130 self)g_signal_connect_data ((cafe_background_preferences), ("changed::"
"show-desktop-icons"), (((GCallback) (desktop_changed_callback
))), (self), ((void*)0), G_CONNECT_SWAPPED)
;
2131}
2132
2133static gboolean
2134baul_application_save_accel_map (gpointer data G_GNUC_UNUSED__attribute__ ((__unused__)))
2135{
2136 if (save_of_accel_map_requested) {
2137 char *accel_map_filename;
2138 accel_map_filename = baul_get_accel_map_file ();
2139 if (accel_map_filename) {
2140 ctk_accel_map_save (accel_map_filename);
2141 g_free (accel_map_filename);
2142 }
2143 save_of_accel_map_requested = FALSE(0);
2144 }
2145
2146 return FALSE(0);
2147}
2148
2149static void
2150queue_accel_map_save_callback (CtkAccelMap *object G_GNUC_UNUSED__attribute__ ((__unused__)),
2151 gchar *accel_path G_GNUC_UNUSED__attribute__ ((__unused__)),
2152 guint accel_key G_GNUC_UNUSED__attribute__ ((__unused__)),
2153 CdkModifierType accel_mods G_GNUC_UNUSED__attribute__ ((__unused__)),
2154 gpointer user_data G_GNUC_UNUSED__attribute__ ((__unused__)))
2155{
2156 if (!save_of_accel_map_requested) {
2157 save_of_accel_map_requested = TRUE(!(0));
2158 g_timeout_add_seconds (BAUL_ACCEL_MAP_SAVE_DELAY30,
2159 baul_application_save_accel_map, NULL((void*)0));
2160 }
2161}
2162
2163static void
2164init_ctk_accels (void)
2165{
2166 char *accel_map_filename;
2167
2168 /* load accelerator map, and register save callback */
2169 accel_map_filename = baul_get_accel_map_file ();
2170 if (accel_map_filename) {
2171 ctk_accel_map_load (accel_map_filename);
2172 g_free (accel_map_filename);
2173 }
2174
2175 g_signal_connect (ctk_accel_map_get (), "changed",g_signal_connect_data ((ctk_accel_map_get ()), ("changed"), (
((GCallback) (queue_accel_map_save_callback))), (((void*)0)),
((void*)0), (GConnectFlags) 0)
2176 G_CALLBACK (queue_accel_map_save_callback), NULL)g_signal_connect_data ((ctk_accel_map_get ()), ("changed"), (
((GCallback) (queue_accel_map_save_callback))), (((void*)0)),
((void*)0), (GConnectFlags) 0)
;
2177}
2178
2179
2180static void
2181baul_application_startup (GApplication *app)
2182{
2183 BaulApplication *self = BAUL_APPLICATION (app)((((BaulApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((app)), (baul_application_get_type())))))
;
2184 gboolean exit_with_last_window;
2185 exit_with_last_window = TRUE(!(0));
Value stored to 'exit_with_last_window' is never read
2186
2187 /* chain up to the CTK+ implementation early, so ctk_init()
2188 * is called for us.
2189 */
2190 G_APPLICATION_CLASS (baul_application_parent_class)((((GApplicationClass*) (void *) g_type_check_class_cast ((GTypeClass
*) ((baul_application_parent_class)), ((g_application_get_type
()))))))
->startup (app);
2191
2192 /* Start the File Manager DBus Interface */
2193 fdb_manager = baul_freedesktop_dbus_new (self);
2194
2195 /* Initialize preferences. This is needed so that proper
2196 * defaults are available before any preference peeking
2197 * happens.
2198 */
2199 baul_global_preferences_init ();
2200
2201 /* initialize the session manager client */
2202 baul_application_smclient_startup (self);
2203
2204 /* register views */
2205 fm_icon_view_register ();
2206 fm_desktop_icon_view_register ();
2207 fm_list_view_register ();
2208 fm_compact_view_register ();
2209 fm_widget_view_register ();
2210#if ENABLE_EMPTY_VIEW1
2211 fm_empty_view_register ();
2212#endif /* ENABLE_EMPTY_VIEW */
2213
2214 /* register sidebars */
2215 baul_places_sidebar_register ();
2216 baul_information_panel_register ();
2217 fm_tree_view_register ();
2218 baul_history_sidebar_register ();
2219 baul_notes_viewer_register (); /* also property page */
2220 baul_emblem_sidebar_register ();
2221
2222 /* register property pages */
2223 baul_image_properties_page_register ();
2224
2225 /* initialize theming */
2226 init_icons_and_styles ();
2227 init_ctk_accels ();
2228
2229 /* initialize baul modules */
2230 baul_module_setup ();
2231
2232 /* attach menu-provider module callback */
2233 menu_provider_init_callback ();
2234
2235 /* Initialize notifications for eject operations */
2236 notify_init (GETTEXT_PACKAGE"baul");
2237
2238 /* Watch for unmounts so we can close open windows */
2239 /* TODO-gio: This should be using the UNMOUNTED feature of GFileMonitor instead */
2240 self->priv->volume_monitor = g_volume_monitor_get ();
2241 g_signal_connect_object ( self->priv->volume_monitor, "mount_removed",
2242 G_CALLBACK (mount_removed_callback)((GCallback) (mount_removed_callback)), self, 0);
2243 g_signal_connect_object ( self->priv->volume_monitor, "mount_pre_unmount",
2244 G_CALLBACK (mount_removed_callback)((GCallback) (mount_removed_callback)), self, 0);
2245 g_signal_connect_object ( self->priv->volume_monitor, "mount_added",
2246 G_CALLBACK (mount_added_callback)((GCallback) (mount_added_callback)), self, 0);
2247 g_signal_connect_object ( self->priv->volume_monitor, "volume_added",
2248 G_CALLBACK (volume_added_callback)((GCallback) (volume_added_callback)), self, 0);
2249 g_signal_connect_object ( self->priv->volume_monitor, "volume_removed",
2250 G_CALLBACK (volume_removed_callback)((GCallback) (volume_removed_callback)), self, 0);
2251 g_signal_connect_object ( self->priv->volume_monitor, "drive_connected",
2252 G_CALLBACK (drive_connected_callback)((GCallback) (drive_connected_callback)), self, 0);
2253
2254 /* listen for eject button presses */
2255 self->automount_idle_id =
2256 g_idle_add_full (G_PRIORITY_LOW300,
2257 automount_all_volumes_idle_cb,
2258 self, NULL((void*)0));
2259
2260 /* Check the user's ~/.baul directories and post warnings
2261 * if there are problems.
2262 */
2263 check_required_directories (self);
2264 init_desktop (self);
2265
2266 /* exit_with_last_window is already set to TRUE, and we need to keep that value
2267 * on other desktops, running from the command line, or when running baul as root.
2268 * Otherwise, we read the value from the configuration.
2269 */
2270
2271 if (running_in_cafe () && !running_as_root())
2272 {
2273 GApplication *instance;
2274
2275 exit_with_last_window = g_settings_get_boolean (baul_preferences,
2276 BAUL_PREFERENCES_EXIT_WITH_LAST_WINDOW"exit-with-last-window");
2277 /*Keep this inside the running as cafe/not as root block */
2278 /*So other desktop don't get unkillable baul instances holding open */
2279 instance = g_application_get_default ();
2280 if (exit_with_last_window == FALSE(0)){
2281 g_application_hold (G_APPLICATION (instance)((((GApplication*) (void *) g_type_check_instance_cast ((GTypeInstance
*) ((instance)), ((g_application_get_type ()))))))
);
2282 }
2283 }
2284
2285}
2286
2287static void
2288baul_application_quit_mainloop (GApplication *app)
2289{
2290 baul_icon_info_clear_caches ();
2291 baul_application_save_accel_map (NULL((void*)0));
2292
2293 G_APPLICATION_CLASS (baul_application_parent_class)((((GApplicationClass*) (void *) g_type_check_class_cast ((GTypeClass
*) ((baul_application_parent_class)), ((g_application_get_type
()))))))
->quit_mainloop (app);
2294}
2295
2296static void
2297baul_application_class_init (BaulApplicationClass *class)
2298{
2299 GObjectClass *object_class;
2300 GApplicationClass *application_class;
2301
2302 object_class = G_OBJECT_CLASS (class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass
*) ((class)), (((GType) ((20) << (2))))))))
;
2303 object_class->finalize = baul_application_finalize;
2304
2305 application_class = G_APPLICATION_CLASS (class)((((GApplicationClass*) (void *) g_type_check_class_cast ((GTypeClass
*) ((class)), ((g_application_get_type ()))))))
;
2306 application_class->startup = baul_application_startup;
2307 application_class->quit_mainloop = baul_application_quit_mainloop;
2308 application_class->open = baul_application_open;
2309 application_class->local_command_line = baul_application_local_command_line;
2310
2311}
2312
2313BaulApplication *
2314baul_application_new (void)
2315{
2316 return g_object_new (BAUL_TYPE_APPLICATIONbaul_application_get_type(),
2317 "application-id", "org.cafe.Baul",
2318 "register-session", TRUE(!(0)),
2319 "flags", G_APPLICATION_HANDLES_OPEN,
2320 NULL((void*)0));
2321}
2322