~ubuntu-branches/ubuntu/wily/caja/wily

« back to all changes in this revision

Viewing changes to .pc/0001_fix-desktop-icon-size.patch/src/file-manager/fm-desktop-icon-view.c

  • Committer: Package Import Robot
  • Author(s): John Paul Adrian Glaubitz, Martin Wimpress, John Paul Adrian Glaubitz
  • Date: 2015-08-10 13:39:55 UTC
  • mfrom: (1.2.1) (9.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20150810133955-b2uyptg7cf8rn8su
Tags: 1.10.3-1
[ Martin Wimpress ]
* New upstream release.
* debian/caja-common.install:
  + Add common files.
* debian/caja.install:
  + Remove common files.
* debian/libcaja-extension-dev.install:
  + Add usr/share/gtk-doc.
* debian/rules:
  + Add --enable-gtk-doc.
  + Remove dfsg suffix.
* debian/watch:
  + Remove dfsg suffix.

[ John Paul Adrian Glaubitz ]
* Fix spelling in debian/control (allows to -> allows one to).
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
 
 
3
 
/* fm-desktop-icon-view.c - implementation of icon view for managing the desktop.
4
 
 
5
 
   Copyright (C) 2000, 2001 Eazel, Inc.mou
6
 
 
7
 
   The Mate Library is free software; you can redistribute it and/or
8
 
   modify it under the terms of the GNU Library General Public License as
9
 
   published by the Free Software Foundation; either version 2 of the
10
 
   License, or (at your option) any later version.
11
 
 
12
 
   The Mate Library is distributed in the hope that it will be useful,
13
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 
   Library General Public License for more details.
16
 
 
17
 
   You should have received a copy of the GNU Library General Public
18
 
   License along with the Mate Library; see the file COPYING.LIB.  If not,
19
 
   write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20
 
   Boston, MA 02110-1301, USA.
21
 
 
22
 
   Authors: Mike Engber <engber@eazel.com>
23
 
            Gene Z. Ragan <gzr@eazel.com>
24
 
            Miguel de Icaza <miguel@ximian.com>
25
 
*/
26
 
 
27
 
#include <config.h>
28
 
#include "fm-icon-container.h"
29
 
#include "fm-desktop-icon-view.h"
30
 
#include "fm-actions.h"
31
 
 
32
 
#include <X11/Xatom.h>
33
 
#include <gtk/gtk.h>
34
 
#include <eel/eel-glib-extensions.h>
35
 
#include <eel/eel-gtk-extensions.h>
36
 
#include <eel/eel-vfs-extensions.h>
37
 
#include <fcntl.h>
38
 
#include <gdk/gdkx.h>
39
 
#include <glib/gi18n.h>
40
 
#include <libcaja-private/caja-desktop-icon-file.h>
41
 
#include <libcaja-private/caja-directory-background.h>
42
 
#include <libcaja-private/caja-directory-notify.h>
43
 
#include <libcaja-private/caja-file-changes-queue.h>
44
 
#include <libcaja-private/caja-file-operations.h>
45
 
#include <libcaja-private/caja-file-utilities.h>
46
 
#include <libcaja-private/caja-ui-utilities.h>
47
 
#include <libcaja-private/caja-global-preferences.h>
48
 
#include <libcaja-private/caja-view-factory.h>
49
 
#include <libcaja-private/caja-link.h>
50
 
#include <libcaja-private/caja-metadata.h>
51
 
#include <libcaja-private/caja-monitor.h>
52
 
#include <libcaja-private/caja-program-choosing.h>
53
 
#include <libcaja-private/caja-trash-monitor.h>
54
 
#include <limits.h>
55
 
#include <stddef.h>
56
 
#include <stdio.h>
57
 
#include <string.h>
58
 
#include <sys/stat.h>
59
 
#include <sys/types.h>
60
 
#include <unistd.h>
61
 
 
62
 
#if !GTK_CHECK_VERSION(3, 0, 0)
63
 
#define gtk_scrollable_get_hadjustment gtk_layout_get_hadjustment
64
 
#define gtk_scrollable_get_vadjustment gtk_layout_get_vadjustment
65
 
#define GTK_SCROLLABLE GTK_LAYOUT
66
 
#endif
67
 
 
68
 
/* Timeout to check the desktop directory for updates */
69
 
#define RESCAN_TIMEOUT 4
70
 
 
71
 
struct FMDesktopIconViewDetails
72
 
{
73
 
    GdkWindow *root_window;
74
 
    GtkActionGroup *desktop_action_group;
75
 
    guint desktop_merge_id;
76
 
 
77
 
    /* For the desktop rescanning
78
 
     */
79
 
    gulong delayed_init_signal;
80
 
    guint reload_desktop_timeout;
81
 
    gboolean pending_rescan;
82
 
};
83
 
 
84
 
static void     default_zoom_level_changed                        (gpointer                user_data);
85
 
static gboolean real_supports_auto_layout                         (FMIconView             *view);
86
 
static gboolean real_supports_scaling                             (FMIconView             *view);
87
 
static gboolean real_supports_keep_aligned                        (FMIconView             *view);
88
 
static gboolean real_supports_labels_beside_icons                 (FMIconView             *view);
89
 
static void     real_merge_menus                                  (FMDirectoryView        *view);
90
 
static void     real_update_menus                                 (FMDirectoryView        *view);
91
 
static gboolean real_supports_zooming                             (FMDirectoryView        *view);
92
 
static void     fm_desktop_icon_view_update_icon_container_fonts  (FMDesktopIconView      *view);
93
 
static void     font_changed_callback                             (gpointer                callback_data);
94
 
 
95
 
G_DEFINE_TYPE (FMDesktopIconView, fm_desktop_icon_view, FM_TYPE_ICON_VIEW)
96
 
 
97
 
static char *desktop_directory;
98
 
static time_t desktop_dir_modify_time;
99
 
 
100
 
static void
101
 
desktop_directory_changed_callback (gpointer callback_data)
102
 
{
103
 
    g_free (desktop_directory);
104
 
    desktop_directory = caja_get_desktop_directory ();
105
 
}
106
 
 
107
 
static CajaIconContainer *
108
 
get_icon_container (FMDesktopIconView *icon_view)
109
 
{
110
 
    g_return_val_if_fail (FM_IS_DESKTOP_ICON_VIEW (icon_view), NULL);
111
 
    g_return_val_if_fail (CAJA_IS_ICON_CONTAINER (gtk_bin_get_child (GTK_BIN (icon_view))), NULL);
112
 
 
113
 
    return CAJA_ICON_CONTAINER (gtk_bin_get_child (GTK_BIN (icon_view)));
114
 
}
115
 
 
116
 
static void
117
 
icon_container_set_workarea (CajaIconContainer *icon_container,
118
 
                             GdkScreen             *screen,
119
 
                             long                  *workareas,
120
 
                             int                    n_items)
121
 
{
122
 
    int left, right, top, bottom;
123
 
    int screen_width, screen_height;
124
 
    int i;
125
 
 
126
 
    left = right = top = bottom = 0;
127
 
 
128
 
    screen_width  = gdk_screen_get_width (screen);
129
 
    screen_height = gdk_screen_get_height (screen);
130
 
 
131
 
    for (i = 0; i < n_items; i += 4)
132
 
    {
133
 
        int x      = workareas [i];
134
 
        int y      = workareas [i + 1];
135
 
        int width  = workareas [i + 2];
136
 
        int height = workareas [i + 3];
137
 
 
138
 
        if ((x + width) > screen_width || (y + height) > screen_height)
139
 
            continue;
140
 
 
141
 
        left   = MAX (left, x);
142
 
        right  = MAX (right, screen_width - width - x);
143
 
        top    = MAX (top, y);
144
 
        bottom = MAX (bottom, screen_height - height - y);
145
 
    }
146
 
 
147
 
    caja_icon_container_set_margins (icon_container,
148
 
                                     left, right, top, bottom);
149
 
}
150
 
 
151
 
static void
152
 
net_workarea_changed (FMDesktopIconView *icon_view,
153
 
                      GdkWindow         *window)
154
 
{
155
 
    long *nworkareas = NULL;
156
 
    long *workareas = NULL;
157
 
    GdkAtom type_returned;
158
 
    int format_returned;
159
 
    int length_returned;
160
 
    CajaIconContainer *icon_container;
161
 
    GdkScreen *screen;
162
 
 
163
 
    g_return_if_fail (FM_IS_DESKTOP_ICON_VIEW (icon_view));
164
 
 
165
 
    icon_container = get_icon_container (icon_view);
166
 
 
167
 
    /* Find the number of desktops so we know how long the
168
 
     * workareas array is going to be (each desktop will have four
169
 
     * elements in the workareas array describing
170
 
     * x,y,width,height) */
171
 
    gdk_error_trap_push ();
172
 
    if (!gdk_property_get (window,
173
 
                           gdk_atom_intern ("_NET_NUMBER_OF_DESKTOPS", FALSE),
174
 
                           gdk_x11_xatom_to_atom (XA_CARDINAL),
175
 
                           0, 4, FALSE,
176
 
                           &type_returned,
177
 
                           &format_returned,
178
 
                           &length_returned,
179
 
                           (guchar **) &nworkareas))
180
 
    {
181
 
        g_warning("Can not calculate _NET_NUMBER_OF_DESKTOPS");
182
 
    }
183
 
    if (gdk_error_trap_pop()
184
 
            || nworkareas == NULL
185
 
            || type_returned != gdk_x11_xatom_to_atom (XA_CARDINAL)
186
 
            || format_returned != 32)
187
 
        g_warning("Can not calculate _NET_NUMBER_OF_DESKTOPS");
188
 
 
189
 
    /* Note : gdk_property_get() is broken (API documents admit
190
 
     * this).  As a length argument, it expects the number of
191
 
     * _bytes_ of data you require.  Internally, gdk_property_get
192
 
     * converts that value to a count of 32 bit (4 byte) elements.
193
 
     * However, the length returned is in bytes, but is calculated
194
 
     * via the count of returned elements * sizeof(long).  This
195
 
     * means on a 64 bit system, the number of bytes you have to
196
 
     * request does not correspond to the number of bytes you get
197
 
     * back, and is the reason for the workaround below.
198
 
     */
199
 
    gdk_error_trap_push ();
200
 
    if (nworkareas == NULL || (*nworkareas < 1)
201
 
            || !gdk_property_get (window,
202
 
                                  gdk_atom_intern ("_NET_WORKAREA", FALSE),
203
 
                                  gdk_x11_xatom_to_atom (XA_CARDINAL),
204
 
                                  0, ((*nworkareas) * 4 * 4), FALSE,
205
 
                                  &type_returned,
206
 
                                  &format_returned,
207
 
                                  &length_returned,
208
 
                                  (guchar **) &workareas))
209
 
    {
210
 
        g_warning("Can not get _NET_WORKAREA");
211
 
        workareas = NULL;
212
 
    }
213
 
 
214
 
    if (gdk_error_trap_pop ()
215
 
            || workareas == NULL
216
 
            || type_returned != gdk_x11_xatom_to_atom (XA_CARDINAL)
217
 
            || ((*nworkareas) * 4 * sizeof(long)) != length_returned
218
 
            || format_returned != 32)
219
 
    {
220
 
        g_warning("Can not determine workarea, guessing at layout");
221
 
        caja_icon_container_set_margins (icon_container,
222
 
                                         0, 0, 0, 0);
223
 
    }
224
 
    else
225
 
    {
226
 
        screen = gdk_window_get_screen (window);
227
 
 
228
 
        icon_container_set_workarea (
229
 
            icon_container, screen, workareas, length_returned / sizeof (long));
230
 
    }
231
 
 
232
 
    if (nworkareas != NULL)
233
 
        g_free (nworkareas);
234
 
 
235
 
    if (workareas != NULL)
236
 
        g_free (workareas);
237
 
}
238
 
 
239
 
static GdkFilterReturn
240
 
desktop_icon_view_property_filter (GdkXEvent *gdk_xevent,
241
 
                                   GdkEvent *event,
242
 
                                   gpointer data)
243
 
{
244
 
    XEvent *xevent = gdk_xevent;
245
 
    FMDesktopIconView *icon_view;
246
 
 
247
 
    icon_view = FM_DESKTOP_ICON_VIEW (data);
248
 
 
249
 
    switch (xevent->type)
250
 
    {
251
 
    case PropertyNotify:
252
 
        if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name ("_NET_WORKAREA"))
253
 
            net_workarea_changed (icon_view, event->any.window);
254
 
        break;
255
 
    default:
256
 
        break;
257
 
    }
258
 
 
259
 
    return GDK_FILTER_CONTINUE;
260
 
}
261
 
 
262
 
static void
263
 
fm_desktop_icon_view_dispose (GObject *object)
264
 
{
265
 
    FMDesktopIconView *icon_view;
266
 
    GtkUIManager *ui_manager;
267
 
 
268
 
    icon_view = FM_DESKTOP_ICON_VIEW (object);
269
 
 
270
 
    /* Remove desktop rescan timeout. */
271
 
    if (icon_view->details->reload_desktop_timeout != 0)
272
 
    {
273
 
        g_source_remove (icon_view->details->reload_desktop_timeout);
274
 
        icon_view->details->reload_desktop_timeout = 0;
275
 
    }
276
 
 
277
 
    ui_manager = fm_directory_view_get_ui_manager (FM_DIRECTORY_VIEW (icon_view));
278
 
    if (ui_manager != NULL)
279
 
    {
280
 
        caja_ui_unmerge_ui (ui_manager,
281
 
                            &icon_view->details->desktop_merge_id,
282
 
                            &icon_view->details->desktop_action_group);
283
 
    }
284
 
 
285
 
    g_signal_handlers_disconnect_by_func (caja_icon_view_preferences,
286
 
                                          default_zoom_level_changed,
287
 
                                          icon_view);
288
 
    g_signal_handlers_disconnect_by_func (caja_preferences,
289
 
                                          font_changed_callback,
290
 
                                          icon_view);
291
 
 
292
 
    g_signal_handlers_disconnect_by_func (mate_lockdown_preferences,
293
 
                                          fm_directory_view_update_menus,
294
 
                                          icon_view);
295
 
    g_signal_handlers_disconnect_by_func (caja_preferences,
296
 
                                          desktop_directory_changed_callback,
297
 
                                          NULL);
298
 
 
299
 
    G_OBJECT_CLASS (fm_desktop_icon_view_parent_class)->dispose (object);
300
 
}
301
 
 
302
 
static void
303
 
fm_desktop_icon_view_class_init (FMDesktopIconViewClass *class)
304
 
{
305
 
    G_OBJECT_CLASS (class)->dispose = fm_desktop_icon_view_dispose;
306
 
 
307
 
    FM_DIRECTORY_VIEW_CLASS (class)->merge_menus = real_merge_menus;
308
 
    FM_DIRECTORY_VIEW_CLASS (class)->update_menus = real_update_menus;
309
 
    FM_DIRECTORY_VIEW_CLASS (class)->supports_zooming = real_supports_zooming;
310
 
 
311
 
    FM_ICON_VIEW_CLASS (class)->supports_auto_layout = real_supports_auto_layout;
312
 
    FM_ICON_VIEW_CLASS (class)->supports_scaling = real_supports_scaling;
313
 
    FM_ICON_VIEW_CLASS (class)->supports_keep_aligned = real_supports_keep_aligned;
314
 
    FM_ICON_VIEW_CLASS (class)->supports_labels_beside_icons = real_supports_labels_beside_icons;
315
 
 
316
 
    g_type_class_add_private (class, sizeof (FMDesktopIconViewDetails));
317
 
}
318
 
 
319
 
static void
320
 
fm_desktop_icon_view_handle_middle_click (CajaIconContainer *icon_container,
321
 
        GdkEventButton *event,
322
 
        FMDesktopIconView *desktop_icon_view)
323
 
{
324
 
    XButtonEvent x_event;
325
 
 
326
 
    /* During a mouse click we have the pointer and keyboard grab.
327
 
     * We will send a fake event to the root window which will cause it
328
 
     * to try to get the grab so we need to let go ourselves.
329
 
     */
330
 
    gdk_pointer_ungrab (GDK_CURRENT_TIME);
331
 
    gdk_keyboard_ungrab (GDK_CURRENT_TIME);
332
 
 
333
 
    /* Stop the event because we don't want anyone else dealing with it. */
334
 
    gdk_flush ();
335
 
    g_signal_stop_emission_by_name (icon_container, "middle_click");
336
 
 
337
 
    /* build an X event to represent the middle click. */
338
 
    x_event.type = ButtonPress;
339
 
    x_event.send_event = True;
340
 
    x_event.display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
341
 
    x_event.window = GDK_ROOT_WINDOW ();
342
 
    x_event.root = GDK_ROOT_WINDOW ();
343
 
    x_event.subwindow = 0;
344
 
    x_event.time = event->time;
345
 
    x_event.x = event->x;
346
 
    x_event.y = event->y;
347
 
    x_event.x_root = event->x_root;
348
 
    x_event.y_root = event->y_root;
349
 
    x_event.state = event->state;
350
 
    x_event.button = event->button;
351
 
    x_event.same_screen = True;
352
 
 
353
 
    /* Send it to the root window, the window manager will handle it. */
354
 
    XSendEvent (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), GDK_ROOT_WINDOW (), True,
355
 
                ButtonPressMask, (XEvent *) &x_event);
356
 
}
357
 
 
358
 
static void
359
 
unrealized_callback (GtkWidget *widget, FMDesktopIconView *desktop_icon_view)
360
 
{
361
 
    g_return_if_fail (desktop_icon_view->details->root_window != NULL);
362
 
 
363
 
    /* Remove the property filter */
364
 
    gdk_window_remove_filter (desktop_icon_view->details->root_window,
365
 
                              desktop_icon_view_property_filter,
366
 
                              desktop_icon_view);
367
 
    desktop_icon_view->details->root_window = NULL;
368
 
}
369
 
 
370
 
static void
371
 
realized_callback (GtkWidget *widget, FMDesktopIconView *desktop_icon_view)
372
 
{
373
 
    GdkWindow *root_window;
374
 
    GdkScreen *screen;
375
 
    GtkAllocation allocation;
376
 
 
377
 
    g_return_if_fail (desktop_icon_view->details->root_window == NULL);
378
 
 
379
 
    screen = gtk_widget_get_screen (widget);
380
 
 
381
 
    /* Ugly HACK for the problem that the views realize at the
382
 
     * wrong size and then get resized. (This is a problem with
383
 
     * MateComponentPlug.) This was leading to problems where initial
384
 
     * layout was done at 60x60 stacking all desktop icons in
385
 
     * the top left corner.
386
 
     */
387
 
    allocation.x = 0;
388
 
    allocation.y = 0;
389
 
    allocation.width = gdk_screen_get_width (screen);
390
 
    allocation.height = gdk_screen_get_height (screen);
391
 
    gtk_widget_size_allocate (GTK_WIDGET(get_icon_container(desktop_icon_view)),
392
 
                              &allocation);
393
 
 
394
 
    root_window = gdk_screen_get_root_window (screen);
395
 
 
396
 
    desktop_icon_view->details->root_window = root_window;
397
 
 
398
 
    /* Read out the workarea geometry and update the icon container accordingly */
399
 
    net_workarea_changed (desktop_icon_view, root_window);
400
 
 
401
 
    /* Setup the property filter */
402
 
    gdk_window_set_events (root_window, GDK_PROPERTY_CHANGE_MASK);
403
 
    gdk_window_add_filter (root_window,
404
 
                           desktop_icon_view_property_filter,
405
 
                           desktop_icon_view);
406
 
}
407
 
 
408
 
static CajaZoomLevel
409
 
get_default_zoom_level (void)
410
 
{
411
 
    static gboolean auto_storage_added = FALSE;
412
 
    static CajaZoomLevel default_zoom_level = CAJA_ZOOM_LEVEL_STANDARD;
413
 
 
414
 
    if (!auto_storage_added)
415
 
    {
416
 
        auto_storage_added = TRUE;
417
 
        eel_g_settings_add_auto_enum (caja_icon_view_preferences,
418
 
                                      CAJA_PREFERENCES_ICON_VIEW_DEFAULT_ZOOM_LEVEL,
419
 
                                      (int *) &default_zoom_level);
420
 
    }
421
 
 
422
 
    return CLAMP (default_zoom_level, CAJA_ZOOM_LEVEL_SMALLEST, CAJA_ZOOM_LEVEL_LARGEST);
423
 
}
424
 
 
425
 
static void
426
 
default_zoom_level_changed (gpointer user_data)
427
 
{
428
 
    CajaZoomLevel new_level;
429
 
    FMDesktopIconView *desktop_icon_view;
430
 
 
431
 
    desktop_icon_view = FM_DESKTOP_ICON_VIEW (user_data);
432
 
    new_level = get_default_zoom_level ();
433
 
 
434
 
    caja_icon_container_set_zoom_level (get_icon_container (desktop_icon_view),
435
 
                                        new_level);
436
 
}
437
 
 
438
 
static gboolean
439
 
do_desktop_rescan (gpointer data)
440
 
{
441
 
    FMDesktopIconView *desktop_icon_view;
442
 
    struct stat buf;
443
 
 
444
 
    desktop_icon_view = FM_DESKTOP_ICON_VIEW (data);
445
 
    if (desktop_icon_view->details->pending_rescan)
446
 
    {
447
 
        return TRUE;
448
 
    }
449
 
 
450
 
    if (stat (desktop_directory, &buf) == -1)
451
 
    {
452
 
        return TRUE;
453
 
    }
454
 
 
455
 
    if (buf.st_ctime == desktop_dir_modify_time)
456
 
    {
457
 
        return TRUE;
458
 
    }
459
 
 
460
 
    desktop_icon_view->details->pending_rescan = TRUE;
461
 
 
462
 
    caja_directory_force_reload (
463
 
        fm_directory_view_get_model (
464
 
            FM_DIRECTORY_VIEW (desktop_icon_view)));
465
 
    return TRUE;
466
 
}
467
 
 
468
 
static void
469
 
done_loading (CajaDirectory *model,
470
 
              FMDesktopIconView *desktop_icon_view)
471
 
{
472
 
    struct stat buf;
473
 
 
474
 
    desktop_icon_view->details->pending_rescan = FALSE;
475
 
    if (stat (desktop_directory, &buf) == -1)
476
 
    {
477
 
        return;
478
 
    }
479
 
 
480
 
    desktop_dir_modify_time = buf.st_ctime;
481
 
}
482
 
 
483
 
/* This function is used because the CajaDirectory model does not
484
 
 * exist always in the desktop_icon_view, so we wait until it has been
485
 
 * instantiated.
486
 
 */
487
 
static void
488
 
delayed_init (FMDesktopIconView *desktop_icon_view)
489
 
{
490
 
    /* Keep track of the load time. */
491
 
    g_signal_connect_object (fm_directory_view_get_model (FM_DIRECTORY_VIEW (desktop_icon_view)),
492
 
                             "done_loading",
493
 
                             G_CALLBACK (done_loading), desktop_icon_view, 0);
494
 
 
495
 
    /* Monitor desktop directory. */
496
 
    desktop_icon_view->details->reload_desktop_timeout =
497
 
        g_timeout_add_seconds (RESCAN_TIMEOUT, do_desktop_rescan, desktop_icon_view);
498
 
 
499
 
    g_signal_handler_disconnect (desktop_icon_view,
500
 
                                 desktop_icon_view->details->delayed_init_signal);
501
 
 
502
 
    desktop_icon_view->details->delayed_init_signal = 0;
503
 
}
504
 
 
505
 
static void
506
 
font_changed_callback (gpointer callback_data)
507
 
{
508
 
    g_return_if_fail (FM_IS_DESKTOP_ICON_VIEW (callback_data));
509
 
 
510
 
    fm_desktop_icon_view_update_icon_container_fonts (FM_DESKTOP_ICON_VIEW (callback_data));
511
 
}
512
 
 
513
 
static void
514
 
fm_desktop_icon_view_update_icon_container_fonts (FMDesktopIconView *icon_view)
515
 
{
516
 
    CajaIconContainer *icon_container;
517
 
    char *font;
518
 
 
519
 
    icon_container = get_icon_container (icon_view);
520
 
    g_assert (icon_container != NULL);
521
 
 
522
 
    font = g_settings_get_string (caja_desktop_preferences, CAJA_PREFERENCES_DESKTOP_FONT);
523
 
 
524
 
    caja_icon_container_set_font (icon_container, font);
525
 
 
526
 
    g_free (font);
527
 
}
528
 
 
529
 
static void
530
 
fm_desktop_icon_view_init (FMDesktopIconView *desktop_icon_view)
531
 
{
532
 
    CajaIconContainer *icon_container;
533
 
    GtkAllocation allocation;
534
 
    GtkAdjustment *hadj, *vadj;
535
 
 
536
 
    desktop_icon_view->details = G_TYPE_INSTANCE_GET_PRIVATE (desktop_icon_view,
537
 
                                                              FM_TYPE_DESKTOP_ICON_VIEW,
538
 
                                                              FMDesktopIconViewDetails);
539
 
 
540
 
    if (desktop_directory == NULL)
541
 
    {
542
 
        g_signal_connect_swapped (caja_preferences, "changed::" CAJA_PREFERENCES_DESKTOP_IS_HOME_DIR,
543
 
                                  G_CALLBACK(desktop_directory_changed_callback),
544
 
                                  NULL);
545
 
        desktop_directory_changed_callback (NULL);
546
 
    }
547
 
 
548
 
    fm_icon_view_filter_by_screen (FM_ICON_VIEW (desktop_icon_view), TRUE);
549
 
    icon_container = get_icon_container (desktop_icon_view);
550
 
    caja_icon_container_set_use_drop_shadows (icon_container, TRUE);
551
 
    fm_icon_container_set_sort_desktop (FM_ICON_CONTAINER (icon_container), TRUE);
552
 
 
553
 
    /* Do a reload on the desktop if we don't have FAM, a smarter
554
 
     * way to keep track of the items on the desktop.
555
 
     */
556
 
    if (!caja_monitor_active ())
557
 
    {
558
 
        desktop_icon_view->details->delayed_init_signal = g_signal_connect_object
559
 
                (desktop_icon_view, "begin_loading",
560
 
                 G_CALLBACK (delayed_init), desktop_icon_view, 0);
561
 
    }
562
 
 
563
 
    caja_icon_container_set_is_fixed_size (icon_container, TRUE);
564
 
    caja_icon_container_set_is_desktop (icon_container, TRUE);
565
 
    caja_icon_container_set_store_layout_timestamps (icon_container, TRUE);
566
 
 
567
 
    /* Set allocation to be at 0, 0 */
568
 
    gtk_widget_get_allocation (GTK_WIDGET (icon_container), &allocation);
569
 
    allocation.x = 0;
570
 
    allocation.y = 0;
571
 
    gtk_widget_set_allocation (GTK_WIDGET (icon_container), &allocation);
572
 
 
573
 
    gtk_widget_queue_resize (GTK_WIDGET (icon_container));
574
 
 
575
 
    hadj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (icon_container));
576
 
    vadj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (icon_container));
577
 
 
578
 
    gtk_adjustment_set_value (hadj, 0);
579
 
    gtk_adjustment_set_value (vadj, 0);
580
 
 
581
 
    gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (desktop_icon_view),
582
 
                                         GTK_SHADOW_NONE);
583
 
 
584
 
    fm_directory_view_ignore_hidden_file_preferences
585
 
    (FM_DIRECTORY_VIEW (desktop_icon_view));
586
 
 
587
 
    fm_directory_view_set_show_foreign (FM_DIRECTORY_VIEW (desktop_icon_view),
588
 
                                        FALSE);
589
 
 
590
 
    /* Set our default layout mode */
591
 
    caja_icon_container_set_layout_mode (icon_container,
592
 
                                         gtk_widget_get_direction (GTK_WIDGET(icon_container)) == GTK_TEXT_DIR_RTL ?
593
 
                                         CAJA_ICON_LAYOUT_T_B_R_L :
594
 
                                         CAJA_ICON_LAYOUT_T_B_L_R);
595
 
 
596
 
    g_signal_connect_object (icon_container, "middle_click",
597
 
                             G_CALLBACK (fm_desktop_icon_view_handle_middle_click), desktop_icon_view, 0);
598
 
    g_signal_connect_object (desktop_icon_view, "realize",
599
 
                             G_CALLBACK (realized_callback), desktop_icon_view, 0);
600
 
    g_signal_connect_object (desktop_icon_view, "unrealize",
601
 
                             G_CALLBACK (unrealized_callback), desktop_icon_view, 0);
602
 
 
603
 
    g_signal_connect_swapped (caja_icon_view_preferences,
604
 
                              "changed::" CAJA_PREFERENCES_ICON_VIEW_DEFAULT_ZOOM_LEVEL,
605
 
                              G_CALLBACK (default_zoom_level_changed),
606
 
                              desktop_icon_view);
607
 
 
608
 
    g_signal_connect_swapped (caja_desktop_preferences,
609
 
                              "changed::" CAJA_PREFERENCES_DESKTOP_FONT,
610
 
                              G_CALLBACK (font_changed_callback),
611
 
                              desktop_icon_view);
612
 
 
613
 
    default_zoom_level_changed (desktop_icon_view);
614
 
    fm_desktop_icon_view_update_icon_container_fonts (desktop_icon_view);
615
 
 
616
 
    g_signal_connect_swapped (mate_lockdown_preferences,
617
 
                              "changed::" CAJA_PREFERENCES_LOCKDOWN_COMMAND_LINE,
618
 
                              G_CALLBACK (fm_directory_view_update_menus),
619
 
                              desktop_icon_view);
620
 
 
621
 
}
622
 
 
623
 
static void
624
 
action_new_launcher_callback (GtkAction *action, gpointer data)
625
 
{
626
 
    char *desktop_directory;
627
 
 
628
 
    g_assert (FM_DIRECTORY_VIEW (data));
629
 
 
630
 
    desktop_directory = caja_get_desktop_directory ();
631
 
 
632
 
    caja_launch_application_from_command (gtk_widget_get_screen (GTK_WIDGET (data)),
633
 
                                          "mate-desktop-item-edit",
634
 
                                          "mate-desktop-item-edit",
635
 
                                          FALSE,
636
 
                                          "--create-new", desktop_directory, NULL);
637
 
    g_free (desktop_directory);
638
 
 
639
 
}
640
 
 
641
 
static void
642
 
action_change_background_callback (GtkAction *action,
643
 
                                   gpointer data)
644
 
{
645
 
    g_assert (FM_DIRECTORY_VIEW (data));
646
 
 
647
 
    caja_launch_application_from_command (gtk_widget_get_screen (GTK_WIDGET (data)),
648
 
                                          _("Background"),
649
 
                                          "mate-appearance-properties",
650
 
                                          FALSE,
651
 
                                          "--show-page=background", NULL);
652
 
}
653
 
 
654
 
static void
655
 
action_empty_trash_conditional_callback (GtkAction *action,
656
 
        gpointer data)
657
 
{
658
 
    g_assert (FM_IS_DIRECTORY_VIEW (data));
659
 
 
660
 
    caja_file_operations_empty_trash (GTK_WIDGET (data));
661
 
}
662
 
 
663
 
static gboolean
664
 
trash_link_is_selection (FMDirectoryView *view)
665
 
{
666
 
    GList *selection;
667
 
    CajaDesktopLink *link;
668
 
    gboolean result;
669
 
 
670
 
    result = FALSE;
671
 
 
672
 
    selection = fm_directory_view_get_selection (view);
673
 
 
674
 
    if (eel_g_list_exactly_one_item (selection) &&
675
 
            CAJA_IS_DESKTOP_ICON_FILE (selection->data))
676
 
    {
677
 
        link = caja_desktop_icon_file_get_link (CAJA_DESKTOP_ICON_FILE (selection->data));
678
 
        /* link may be NULL if the link was recently removed (unmounted) */
679
 
        if (link != NULL &&
680
 
                caja_desktop_link_get_link_type (link) == CAJA_DESKTOP_LINK_TRASH)
681
 
        {
682
 
            result = TRUE;
683
 
        }
684
 
        if (link)
685
 
        {
686
 
            g_object_unref (link);
687
 
        }
688
 
    }
689
 
 
690
 
    caja_file_list_free (selection);
691
 
 
692
 
    return result;
693
 
}
694
 
 
695
 
static void
696
 
real_update_menus (FMDirectoryView *view)
697
 
{
698
 
    FMDesktopIconView *desktop_view;
699
 
    char *label;
700
 
    gboolean disable_command_line;
701
 
    gboolean include_empty_trash;
702
 
    GtkAction *action;
703
 
 
704
 
    g_assert (FM_IS_DESKTOP_ICON_VIEW (view));
705
 
 
706
 
    FM_DIRECTORY_VIEW_CLASS (fm_desktop_icon_view_parent_class)->update_menus (view);
707
 
 
708
 
    desktop_view = FM_DESKTOP_ICON_VIEW (view);
709
 
 
710
 
    /* New Launcher */
711
 
    disable_command_line = g_settings_get_boolean (mate_lockdown_preferences, CAJA_PREFERENCES_LOCKDOWN_COMMAND_LINE);
712
 
    action = gtk_action_group_get_action (desktop_view->details->desktop_action_group,
713
 
                                          FM_ACTION_NEW_LAUNCHER_DESKTOP);
714
 
    gtk_action_set_visible (action,
715
 
                            !disable_command_line);
716
 
 
717
 
    /* Empty Trash */
718
 
    include_empty_trash = trash_link_is_selection (view);
719
 
    action = gtk_action_group_get_action (desktop_view->details->desktop_action_group,
720
 
                                          FM_ACTION_EMPTY_TRASH_CONDITIONAL);
721
 
    gtk_action_set_visible (action,
722
 
                            include_empty_trash);
723
 
    if (include_empty_trash)
724
 
    {
725
 
        label = g_strdup (_("E_mpty Trash"));
726
 
        g_object_set (action , "label", label, NULL);
727
 
        gtk_action_set_sensitive (action,
728
 
                                  !caja_trash_monitor_is_empty ());
729
 
        g_free (label);
730
 
    }
731
 
}
732
 
 
733
 
static const GtkActionEntry desktop_view_entries[] =
734
 
{
735
 
    /* name, stock id */
736
 
    {
737
 
        "New Launcher Desktop", NULL,
738
 
        /* label, accelerator */
739
 
        N_("Create L_auncher..."), NULL,
740
 
        /* tooltip */
741
 
        N_("Create a new launcher"),
742
 
        G_CALLBACK (action_new_launcher_callback)
743
 
    },
744
 
    /* name, stock id */
745
 
    {
746
 
        "Change Background", NULL,
747
 
        /* label, accelerator */
748
 
        N_("Change Desktop _Background"), NULL,
749
 
        /* tooltip */
750
 
        N_("Show a window that lets you set your desktop background's pattern or color"),
751
 
        G_CALLBACK (action_change_background_callback)
752
 
    },
753
 
    /* name, stock id */
754
 
    {
755
 
        "Empty Trash Conditional", NULL,
756
 
        /* label, accelerator */
757
 
        N_("Empty Trash"), NULL,
758
 
        /* tooltip */
759
 
        N_("Delete all items in the Trash"),
760
 
        G_CALLBACK (action_empty_trash_conditional_callback)
761
 
    },
762
 
};
763
 
 
764
 
static void
765
 
real_merge_menus (FMDirectoryView *view)
766
 
{
767
 
    FMDesktopIconView *desktop_view;
768
 
    GtkUIManager *ui_manager;
769
 
    GtkActionGroup *action_group;
770
 
    const char *ui;
771
 
 
772
 
    FM_DIRECTORY_VIEW_CLASS (fm_desktop_icon_view_parent_class)->merge_menus (view);
773
 
 
774
 
    desktop_view = FM_DESKTOP_ICON_VIEW (view);
775
 
 
776
 
    ui_manager = fm_directory_view_get_ui_manager (view);
777
 
 
778
 
    action_group = gtk_action_group_new ("DesktopViewActions");
779
 
    gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
780
 
    desktop_view->details->desktop_action_group = action_group;
781
 
    gtk_action_group_add_actions (action_group,
782
 
                                  desktop_view_entries, G_N_ELEMENTS (desktop_view_entries),
783
 
                                  view);
784
 
 
785
 
    gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
786
 
    g_object_unref (action_group); /* owned by ui manager */
787
 
 
788
 
    ui = caja_ui_string_get ("caja-desktop-icon-view-ui.xml");
789
 
    desktop_view->details->desktop_merge_id =
790
 
        gtk_ui_manager_add_ui_from_string (ui_manager, ui, -1, NULL);
791
 
}
792
 
 
793
 
static gboolean
794
 
real_supports_auto_layout (FMIconView *view)
795
 
{
796
 
    /* Can't use auto-layout on the desktop, because doing so
797
 
     * would cause all sorts of complications involving the
798
 
     * fixed-size window.
799
 
     */
800
 
    return FALSE;
801
 
}
802
 
 
803
 
static gboolean
804
 
real_supports_scaling (FMIconView *view)
805
 
{
806
 
    return TRUE;
807
 
}
808
 
 
809
 
static gboolean
810
 
real_supports_keep_aligned (FMIconView *view)
811
 
{
812
 
    return TRUE;
813
 
}
814
 
 
815
 
static gboolean
816
 
real_supports_labels_beside_icons (FMIconView *view)
817
 
{
818
 
    return FALSE;
819
 
}
820
 
 
821
 
static gboolean
822
 
real_supports_zooming (FMDirectoryView *view)
823
 
{
824
 
    /* Can't zoom on the desktop, because doing so would cause all
825
 
     * sorts of complications involving the fixed-size window.
826
 
     */
827
 
    return FALSE;
828
 
}
829
 
 
830
 
static CajaView *
831
 
fm_desktop_icon_view_create (CajaWindowSlotInfo *slot)
832
 
{
833
 
    FMIconView *view;
834
 
 
835
 
    view = g_object_new (FM_TYPE_DESKTOP_ICON_VIEW,
836
 
                         "window-slot", slot,
837
 
                         NULL);
838
 
    return CAJA_VIEW (view);
839
 
}
840
 
 
841
 
static gboolean
842
 
fm_desktop_icon_view_supports_uri (const char *uri,
843
 
                                   GFileType file_type,
844
 
                                   const char *mime_type)
845
 
{
846
 
    if (g_str_has_prefix (uri, EEL_DESKTOP_URI))
847
 
    {
848
 
        return TRUE;
849
 
    }
850
 
 
851
 
    return FALSE;
852
 
}
853
 
 
854
 
static CajaViewInfo fm_desktop_icon_view =
855
 
{
856
 
    FM_DESKTOP_ICON_VIEW_ID,
857
 
    "Desktop View",
858
 
    "_Desktop",
859
 
    N_("The desktop view encountered an error."),
860
 
    N_("The desktop view encountered an error while starting up."),
861
 
    "Display this location with the desktop view.",
862
 
    fm_desktop_icon_view_create,
863
 
    fm_desktop_icon_view_supports_uri
864
 
};
865
 
 
866
 
void
867
 
fm_desktop_icon_view_register (void)
868
 
{
869
 
    fm_desktop_icon_view.error_label = _(fm_desktop_icon_view.error_label);
870
 
    fm_desktop_icon_view.startup_error_label = _(fm_desktop_icon_view.startup_error_label);
871
 
 
872
 
    caja_view_factory_register (&fm_desktop_icon_view);
873
 
}