~ubuntu-branches/ubuntu/raring/nautilus/raring

« back to all changes in this revision

Viewing changes to .pc/17_dont_allow_new_tab_on_desktop.patch/src/nautilus-desktop-window.c

  • Committer: Package Import Robot
  • Author(s): Sebastien Bacher, Jeremy Bicha
  • Date: 2012-01-31 13:45:01 UTC
  • mfrom: (1.17.25)
  • Revision ID: package-import@ubuntu.com-20120131134501-yn7mqny7fgzx9fao
Tags: 1:3.3.4-0ubuntu1
* New upstream version which fixes:
  - "Opening Popupmenu in Context of Folder with List-View impossible?"
    (lp: #126540)
  - "'Create folder in here' context menu option for nautilus" (lp: #61786)
  - the file count and the size count change in opposite direction.
    (lp: #503330)
  - the mounts in the place menu should have a properties entry.
    (lp: #846289)
  - add command line option to select file (lp: #575719)
  - Media in 'Places' side bar should have same context menu as in 
    'Computer' (lp: #230098)
* debian/nautilus-data.install:
  - updated, ui and icons have been moved into gresources
* debian/patches/05_desktop_menu_export.patch:
   - updated to correctly include the gresources desktop definition

[ Jeremy Bicha ]
* New upstream release.
* debian/control.in:
  - Bump minimum GTK and glib
* Refreshed patches
* Dropped upstream patches:
  - 17_dont_allow_new_tab_on_desktop.patch
  - 18_fix_crash_in_get_current_uri.patch
  - 19_lazily_initialize_notification_service.patch
  - git_sideplace_sorting.patch
  - git_next_row.patch
  - git_dont_document_browser_option.patch
  - git_browser_compat.patch
  - git_bookmarks_reordering.patch
  - git_listview_context_menus.patch
  - git_use_gtk_grid.patch

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
 
/*
4
 
 * Nautilus
5
 
 *
6
 
 * Copyright (C) 2000 Eazel, Inc.
7
 
 *
8
 
 * Nautilus is free software; you can redistribute it and/or
9
 
 * modify it under the terms of the GNU General Public License as
10
 
 * published by the Free Software Foundation; either version 2 of the
11
 
 * License, or (at your option) any later version.
12
 
 *
13
 
 * Nautilus is distributed in the hope that it will be useful,
14
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 
 * General Public License for more details.
17
 
 *
18
 
 * You should have received a copy of the GNU General Public License
19
 
 * along with this program; if not, write to the Free Software
20
 
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
 
 *
22
 
 * Authors: Darin Adler <darin@bentspoon.com>
23
 
 */
24
 
 
25
 
#include <config.h>
26
 
#include "nautilus-desktop-window.h"
27
 
#include "nautilus-window-private.h"
28
 
#include "nautilus-actions.h"
29
 
 
30
 
#include <X11/Xatom.h>
31
 
#include <gdk/gdkx.h>
32
 
#include <gtk/gtk.h>
33
 
#include <gio/gio.h>
34
 
#include <glib/gi18n.h>
35
 
 
36
 
#include <eel/eel-vfs-extensions.h>
37
 
#include <libnautilus-private/nautilus-file-utilities.h>
38
 
#include <libnautilus-private/nautilus-icon-names.h>
39
 
#include <libnautilus-private/nautilus-global-preferences.h>
40
 
#include <libnautilus-private/nautilus-ui-utilities.h>
41
 
 
42
 
struct NautilusDesktopWindowDetails {
43
 
        gulong size_changed_id;
44
 
 
45
 
        gboolean loaded;
46
 
};
47
 
 
48
 
static void
49
 
desktop_background_cb (GtkAction * action, gpointer user_data)
50
 
{
51
 
        g_spawn_command_line_async("gnome-control-center background", NULL);
52
 
        return;
53
 
}
54
 
 
55
 
static void
56
 
ubuntu_docs_cb (GtkAction * action, gpointer user_data)
57
 
{
58
 
        g_spawn_command_line_async("yelp", NULL);
59
 
        return;
60
 
}
61
 
 
62
 
static const GtkActionEntry desktop_entries[] = {
63
 
        /* name, stock id, label */ { "Change Desktop Background", NULL, N_("Change Desktop _Background"),
64
 
        /* accel, tooltip */          NULL, NULL,
65
 
                                                                  G_CALLBACK(desktop_background_cb)},
66
 
        /* name, stock id, label */ { "Ubuntu Documentation",      NULL, N_("Ubuntu Help"),
67
 
        /* accel, tooltip */          NULL, NULL,
68
 
                                                                  G_CALLBACK(ubuntu_docs_cb)}
69
 
};
70
 
 
71
 
static void set_wmspec_desktop_hint (GdkWindow *window);
72
 
 
73
 
G_DEFINE_TYPE (NautilusDesktopWindow, nautilus_desktop_window, 
74
 
               NAUTILUS_TYPE_WINDOW);
75
 
 
76
 
static void
77
 
nautilus_desktop_window_dispose (GObject *obj)
78
 
{
79
 
        NautilusDesktopWindow *window = NAUTILUS_DESKTOP_WINDOW (obj);
80
 
 
81
 
        g_signal_handlers_disconnect_by_func (nautilus_preferences,
82
 
                                              nautilus_desktop_window_update_directory,
83
 
                                              window);
84
 
 
85
 
        G_OBJECT_CLASS (nautilus_desktop_window_parent_class)->dispose (obj);
86
 
}
87
 
 
88
 
static void
89
 
nautilus_desktop_window_constructed (GObject *obj)
90
 
{
91
 
        GtkAction *action;
92
 
        AtkObject *accessible;
93
 
        NautilusDesktopWindow *window = NAUTILUS_DESKTOP_WINDOW (obj);
94
 
 
95
 
        G_OBJECT_CLASS (nautilus_desktop_window_parent_class)->constructed (obj);
96
 
        
97
 
        gtk_widget_hide (NAUTILUS_WINDOW (window)->details->statusbar);
98
 
        gtk_widget_hide (NAUTILUS_WINDOW (window)->details->menubar);
99
 
 
100
 
        /* Don't allow close action on desktop */
101
 
        action = gtk_action_group_get_action (NAUTILUS_WINDOW (window)->details->main_action_group,
102
 
                                              NAUTILUS_ACTION_CLOSE);
103
 
        gtk_action_set_sensitive (action, FALSE);
104
 
 
105
 
        UbuntuMenuProxy * proxy = ubuntu_menu_proxy_get();
106
 
        if (proxy != NULL) {
107
 
                ubuntu_menu_proxy_insert(proxy, GTK_WIDGET(window), NAUTILUS_WINDOW(window)->details->menubar, 0);
108
 
        }
109
 
 
110
 
        /* Add actions for the desktop */
111
 
        GtkActionGroup * desktop_agroup = gtk_action_group_new("DesktopActions");
112
 
        gtk_action_group_set_translation_domain(desktop_agroup, GETTEXT_PACKAGE);
113
 
        gtk_action_group_add_actions(desktop_agroup, desktop_entries, G_N_ELEMENTS(desktop_entries), window);
114
 
        gtk_ui_manager_insert_action_group(nautilus_window_get_ui_manager(NAUTILUS_WINDOW(window)),
115
 
                                           desktop_agroup, 0);
116
 
        g_object_unref(desktop_agroup);
117
 
 
118
 
        GtkUIManager * ui_manager = nautilus_window_get_ui_manager(NAUTILUS_WINDOW(window));
119
 
        const gchar * ui = nautilus_ui_string_get ("nautilus-desktop-window-ui.xml");
120
 
        if (ui != NULL) {
121
 
                gtk_ui_manager_add_ui_from_string (ui_manager, ui, -1, NULL);
122
 
        }
123
 
 
124
 
        /* Hide actions that don't make sense on the desktop */
125
 
        GList * agroups = gtk_ui_manager_get_action_groups(NAUTILUS_WINDOW(window)->details->ui_manager);
126
 
        while (agroups != NULL) {
127
 
                GtkActionGroup * agroup = GTK_ACTION_GROUP(agroups->data);
128
 
                const gchar * name = gtk_action_group_get_name(agroup);
129
 
 
130
 
                if (g_strcmp0(name, "LaunchpadIntegration") == 0) {
131
 
                        gtk_action_group_set_visible(agroup, FALSE);
132
 
                } else if (g_strcmp0(name, "SpatialActions") == 0) {
133
 
                        GtkAction * action = NULL;
134
 
 
135
 
                        action = gtk_action_group_get_action(agroup, "Close Parent Folders");
136
 
                        gtk_action_set_visible(action, FALSE);
137
 
 
138
 
                        action = gtk_action_group_get_action(agroup, "Close All Folders");
139
 
                        gtk_action_set_visible(action, FALSE);
140
 
                } else if (g_strcmp0(name, "ShellActions") == 0) {
141
 
                        GtkAction * action = NULL;
142
 
 
143
 
                        action = gtk_action_group_get_action(agroup, "Close All Windows");
144
 
                        gtk_action_set_visible(action, FALSE);
145
 
 
146
 
                        action = gtk_action_group_get_action(agroup, NAUTILUS_ACTION_CLOSE);
147
 
                        gtk_action_set_visible(action, FALSE);
148
 
 
149
 
                        action = gtk_action_group_get_action(agroup, NAUTILUS_ACTION_STOP);
150
 
                        gtk_action_set_visible(action, FALSE);
151
 
 
152
 
                        action = gtk_action_group_get_action(agroup, NAUTILUS_ACTION_RELOAD);
153
 
                        gtk_action_set_visible(action, FALSE);
154
 
 
155
 
                        action = gtk_action_group_get_action(agroup, "Preferences");
156
 
                        gtk_action_set_visible(action, FALSE);
157
 
 
158
 
                        action = gtk_action_group_get_action(agroup, "About Nautilus");
159
 
                        gtk_action_set_visible(action, FALSE);
160
 
 
161
 
                        action = gtk_action_group_get_action(agroup, "Up");
162
 
                        gtk_action_set_visible(action, FALSE);
163
 
 
164
 
                        action = gtk_action_group_get_action(agroup, "New Tab");
165
 
                        gtk_action_set_visible(action, FALSE);
166
 
 
167
 
                        action = gtk_action_group_get_action(agroup, NAUTILUS_ACTION_BACK);
168
 
                        gtk_action_set_visible(action, FALSE);
169
 
 
170
 
                        action = gtk_action_group_get_action(agroup, NAUTILUS_ACTION_FORWARD);
171
 
                        gtk_action_set_visible(action, FALSE);
172
 
 
173
 
                        action = gtk_action_group_get_action(agroup, NAUTILUS_ACTION_SHOW_HIDE_EXTRA_PANE);
174
 
                        gtk_action_set_visible(action, FALSE);
175
 
 
176
 
                        action = gtk_action_group_get_action(agroup, "SplitViewSameLocation");
177
 
                        gtk_action_set_visible(action, FALSE);
178
 
 
179
 
                        action = gtk_action_group_get_action(agroup, "Go to Location");
180
 
                        gtk_action_set_visible(action, FALSE);
181
 
 
182
 
                        action = gtk_action_group_get_action(agroup, "Search");
183
 
                        gtk_action_set_visible(action, FALSE);
184
 
 
185
 
                        action = gtk_action_group_get_action(agroup, "Add Bookmark");
186
 
                        gtk_action_set_visible(action, FALSE);
187
 
 
188
 
                        action = gtk_action_group_get_action(agroup, "Show Hide Sidebar");
189
 
                        gtk_action_set_visible(action, FALSE);
190
 
 
191
 
                        action = gtk_action_group_get_action(agroup, "Show Hide Statusbar");
192
 
                        gtk_action_set_visible(action, FALSE);
193
 
 
194
 
                        action = gtk_action_group_get_action(agroup, "Show Hide Toolbar");
195
 
                        gtk_action_set_visible(action, FALSE);
196
 
 
197
 
                        action = gtk_action_group_get_action(agroup, "Sidebar Places");
198
 
                        gtk_action_set_visible(action, FALSE);
199
 
 
200
 
                        action = gtk_action_group_get_action(agroup, "Sidebar Tree");
201
 
                        gtk_action_set_visible(action, FALSE);
202
 
 
203
 
                        action = gtk_action_group_get_action(agroup, "NautilusHelp");
204
 
                        gtk_action_set_visible(action, FALSE);
205
 
 
206
 
                        action = gtk_action_group_get_action(agroup, "NautilusHelpSearch");
207
 
                        gtk_action_set_visible(action, FALSE);
208
 
 
209
 
                        action = gtk_action_group_get_action(agroup, "NautilusHelpSort");
210
 
                        gtk_action_set_visible(action, FALSE);
211
 
 
212
 
                        action = gtk_action_group_get_action(agroup, "NautilusHelpLost");
213
 
                        gtk_action_set_visible(action, FALSE);
214
 
 
215
 
                        action = gtk_action_group_get_action(agroup, "NautilusHelpShare");
216
 
                        gtk_action_set_visible(action, FALSE);
217
 
                }
218
 
 
219
 
                agroups = g_list_next(agroups);
220
 
        }
221
 
 
222
 
        /* Set the accessible name so that it doesn't inherit the cryptic desktop URI. */
223
 
        accessible = gtk_widget_get_accessible (GTK_WIDGET (window));
224
 
 
225
 
        if (accessible) {
226
 
                atk_object_set_name (accessible, _("Desktop"));
227
 
        }
228
 
 
229
 
        /* Monitor the preference to have the desktop */
230
 
        /* point to the Unix home folder */
231
 
        g_signal_connect_swapped (nautilus_preferences, "changed::" NAUTILUS_PREFERENCES_DESKTOP_IS_HOME_DIR,
232
 
                                  G_CALLBACK (nautilus_desktop_window_update_directory),
233
 
                                  window);
234
 
}
235
 
 
236
 
static void
237
 
nautilus_desktop_window_init (NautilusDesktopWindow *window)
238
 
{
239
 
        window->details = G_TYPE_INSTANCE_GET_PRIVATE (window, NAUTILUS_TYPE_DESKTOP_WINDOW,
240
 
                                                       NautilusDesktopWindowDetails);
241
 
 
242
 
        gtk_window_move (GTK_WINDOW (window), 0, 0);
243
 
 
244
 
        /* shouldn't really be needed given our semantic type
245
 
         * of _NET_WM_TYPE_DESKTOP, but why not
246
 
         */
247
 
        gtk_window_set_resizable (GTK_WINDOW (window),
248
 
                                  FALSE);
249
 
 
250
 
        g_object_set_data (G_OBJECT (window), "is_desktop_window", 
251
 
                           GINT_TO_POINTER (1));
252
 
 
253
 
 
254
 
}
255
 
 
256
 
static gint
257
 
nautilus_desktop_window_delete_event (NautilusDesktopWindow *window)
258
 
{
259
 
        /* Returning true tells GTK+ not to delete the window. */
260
 
        return TRUE;
261
 
}
262
 
 
263
 
void
264
 
nautilus_desktop_window_update_directory (NautilusDesktopWindow *window)
265
 
{
266
 
        GFile *location;
267
 
 
268
 
        g_assert (NAUTILUS_IS_DESKTOP_WINDOW (window));
269
 
 
270
 
        window->details->loaded = FALSE;
271
 
        location = g_file_new_for_uri (EEL_DESKTOP_URI);
272
 
        nautilus_window_go_to (NAUTILUS_WINDOW (window), location);
273
 
        window->details->loaded = TRUE;
274
 
 
275
 
        g_object_unref (location);
276
 
}
277
 
 
278
 
static void
279
 
nautilus_desktop_window_screen_size_changed (GdkScreen             *screen,
280
 
                                             NautilusDesktopWindow *window)
281
 
{
282
 
        int width_request, height_request;
283
 
 
284
 
        width_request = gdk_screen_get_width (screen);
285
 
        height_request = gdk_screen_get_height (screen);
286
 
        
287
 
        g_object_set (window,
288
 
                      "width_request", width_request,
289
 
                      "height_request", height_request,
290
 
                      NULL);
291
 
}
292
 
 
293
 
NautilusDesktopWindow *
294
 
nautilus_desktop_window_new (GdkScreen *screen)
295
 
{
296
 
        NautilusDesktopWindow *window;
297
 
        int width_request, height_request;
298
 
 
299
 
        width_request = gdk_screen_get_width (screen);
300
 
        height_request = gdk_screen_get_height (screen);
301
 
 
302
 
        window = g_object_new (NAUTILUS_TYPE_DESKTOP_WINDOW,
303
 
                               "disable-chrome", TRUE,
304
 
                               "width_request", width_request,
305
 
                               "height_request", height_request,
306
 
                               "screen", screen,
307
 
                               NULL);
308
 
 
309
 
        /* Special sawmill setting*/
310
 
        gtk_window_set_wmclass (GTK_WINDOW (window), "desktop_window", "Nautilus");
311
 
 
312
 
        g_signal_connect (window, "delete_event", G_CALLBACK (nautilus_desktop_window_delete_event), NULL);
313
 
 
314
 
        /* Point window at the desktop folder.
315
 
         * Note that nautilus_desktop_window_init is too early to do this.
316
 
         */
317
 
        nautilus_desktop_window_update_directory (window);
318
 
 
319
 
        return window;
320
 
}
321
 
 
322
 
static void
323
 
map (GtkWidget *widget)
324
 
{
325
 
        /* Chain up to realize our children */
326
 
        GTK_WIDGET_CLASS (nautilus_desktop_window_parent_class)->map (widget);
327
 
        gdk_window_lower (gtk_widget_get_window (widget));
328
 
}
329
 
 
330
 
static void
331
 
unrealize (GtkWidget *widget)
332
 
{
333
 
        NautilusDesktopWindow *window;
334
 
        NautilusDesktopWindowDetails *details;
335
 
        GdkWindow *root_window;
336
 
 
337
 
        window = NAUTILUS_DESKTOP_WINDOW (widget);
338
 
        details = window->details;
339
 
 
340
 
        root_window = gdk_screen_get_root_window (
341
 
                                gtk_window_get_screen (GTK_WINDOW (window)));
342
 
 
343
 
        gdk_property_delete (root_window,
344
 
                             gdk_atom_intern ("NAUTILUS_DESKTOP_WINDOW_ID", TRUE));
345
 
 
346
 
        if (details->size_changed_id != 0) {
347
 
                g_signal_handler_disconnect (gtk_window_get_screen (GTK_WINDOW (window)),
348
 
                                             details->size_changed_id);
349
 
                details->size_changed_id = 0;
350
 
        }
351
 
 
352
 
        GTK_WIDGET_CLASS (nautilus_desktop_window_parent_class)->unrealize (widget);
353
 
}
354
 
 
355
 
static void
356
 
set_wmspec_desktop_hint (GdkWindow *window)
357
 
{
358
 
        GdkAtom atom;
359
 
 
360
 
        atom = gdk_atom_intern ("_NET_WM_WINDOW_TYPE_DESKTOP", FALSE);
361
 
        
362
 
        gdk_property_change (window,
363
 
                             gdk_atom_intern ("_NET_WM_WINDOW_TYPE", FALSE),
364
 
                             gdk_x11_xatom_to_atom (XA_ATOM), 32,
365
 
                             GDK_PROP_MODE_REPLACE, (guchar *) &atom, 1);
366
 
}
367
 
 
368
 
static void
369
 
set_desktop_window_id (NautilusDesktopWindow *window,
370
 
                       GdkWindow             *gdkwindow)
371
 
{
372
 
        /* Tuck the desktop windows xid in the root to indicate we own the desktop.
373
 
         */
374
 
        Window window_xid;
375
 
        GdkWindow *root_window;
376
 
 
377
 
        root_window = gdk_screen_get_root_window (
378
 
                                gtk_window_get_screen (GTK_WINDOW (window)));
379
 
 
380
 
        window_xid = GDK_WINDOW_XID (gdkwindow);
381
 
 
382
 
        gdk_property_change (root_window,
383
 
                             gdk_atom_intern ("NAUTILUS_DESKTOP_WINDOW_ID", FALSE),
384
 
                             gdk_x11_xatom_to_atom (XA_WINDOW), 32,
385
 
                             GDK_PROP_MODE_REPLACE, (guchar *) &window_xid, 1);
386
 
}
387
 
 
388
 
static void
389
 
realize (GtkWidget *widget)
390
 
{
391
 
        NautilusDesktopWindow *window;
392
 
        NautilusDesktopWindowDetails *details;
393
 
 
394
 
        window = NAUTILUS_DESKTOP_WINDOW (widget);
395
 
        details = window->details;
396
 
 
397
 
        /* Make sure we get keyboard events */
398
 
        gtk_widget_set_events (widget, gtk_widget_get_events (widget) 
399
 
                              | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK);
400
 
                              
401
 
        /* Do the work of realizing. */
402
 
        GTK_WIDGET_CLASS (nautilus_desktop_window_parent_class)->realize (widget);
403
 
 
404
 
        /* This is the new way to set up the desktop window */
405
 
        set_wmspec_desktop_hint (gtk_widget_get_window (widget));
406
 
 
407
 
        set_desktop_window_id (window, gtk_widget_get_window (widget));
408
 
 
409
 
        details->size_changed_id =
410
 
                g_signal_connect (gtk_window_get_screen (GTK_WINDOW (window)), "size_changed",
411
 
                                  G_CALLBACK (nautilus_desktop_window_screen_size_changed), window);
412
 
}
413
 
 
414
 
static NautilusIconInfo *
415
 
real_get_icon (NautilusWindow *window,
416
 
               NautilusWindowSlot *slot)
417
 
{
418
 
        return nautilus_icon_info_lookup_from_name (NAUTILUS_ICON_DESKTOP, 48);
419
 
}
420
 
 
421
 
static void
422
 
real_sync_title (NautilusWindow *window,
423
 
                 NautilusWindowSlot *slot)
424
 
{
425
 
        /* hardcode "Desktop" */
426
 
        gtk_window_set_title (GTK_WINDOW (window), _("Desktop"));
427
 
}
428
 
 
429
 
static void
430
 
real_window_close (NautilusWindow *window)
431
 
{
432
 
        /* stub, does nothing */
433
 
        return;
434
 
}
435
 
 
436
 
static void
437
 
nautilus_desktop_window_class_init (NautilusDesktopWindowClass *klass)
438
 
{
439
 
        GtkWidgetClass *wclass = GTK_WIDGET_CLASS (klass);
440
 
        NautilusWindowClass *nclass = NAUTILUS_WINDOW_CLASS (klass);
441
 
        GObjectClass *oclass = G_OBJECT_CLASS (klass);
442
 
 
443
 
        oclass->constructed = nautilus_desktop_window_constructed;
444
 
        oclass->dispose = nautilus_desktop_window_dispose;
445
 
 
446
 
        wclass->realize = realize;
447
 
        wclass->unrealize = unrealize;
448
 
        wclass->map = map;
449
 
 
450
 
        nclass->window_type = NAUTILUS_WINDOW_DESKTOP;
451
 
        nclass->sync_title = real_sync_title;
452
 
        nclass->get_icon = real_get_icon;
453
 
        nclass->close = real_window_close;
454
 
 
455
 
        g_type_class_add_private (klass, sizeof (NautilusDesktopWindowDetails));
456
 
}
457
 
 
458
 
gboolean
459
 
nautilus_desktop_window_loaded (NautilusDesktopWindow *window)
460
 
{
461
 
        return window->details->loaded;
462
 
}