Bug Summary

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