~mitya57/ubuntu/precise/nautilus/desktop-window-fixes

« back to all changes in this revision

Viewing changes to src/nautilus-history-sidebar.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2011-05-16 18:53:51 UTC
  • mfrom: (1.17.16 upstream) (2.2.10 experimental)
  • Revision ID: james.westby@ubuntu.com-20110516185351-9mpn1rya1t645ixq
Tags: 1:3.0.1.1-0ubuntu1
* Resynchronize on Debian using the GNOME3 ppa work, thanks to those who
  contributed there
* Known issues:
  - the indicator-application patch needs to be updated or dropped
    (design recommended to use a normal dialog for copies so maybe drop it)
  - the indicator-appmenu export patch needs to be updated
  - desktop icons are not displayed by default in GNOME3, you can set
    org.gnome.desktop.background show-desktop-icons to true in dconf-editor
    or using the gsettings command to get those back 
* New upstream version
* Remaining diffs:
* debian/changelog, debian/rules: set epoch number (which was added by error)
* debian/control.in:
  - Build-Depend on liblaunchpad-integration-dev, libappindicator-dev
  - Don't recommends desktop-base, don't suggests tracker
* debian/mount-archive.desktop:
* debian/mount-archive.desktop.in:
  - New nautilus context menu item to allow mounting zip, iso, etc
* debian/nautilus.gschema.override:
  - Change the default desktop icon configuration
* debian/nautilus-data.install:
  - Install Apport hook
* debian/nautilus.install:
  - Install mount-archive menu
* nautilus-desktop.desktop
* debian/source_nautilus.py:
  - Apport hook to list versions of files in /usr/lib/nautilus and reassign
    the crashes when there are not due to nautilus code directly
* debian/patches/00_do_not_require_unpackage_libexif.patch:
  - dropped, not required in Ubuntu since libexif is recent enough
* debian/patches/01_lpi.patch:
  - Launchpad changes.
* debian/patches/02_additional_marge_for_unity.patch:
  - ensure we don't move desktop icons when locking or unlocking the unity
    launcher 
* debian/patches/03_translations_list_update.patch:
  - Translate the mount-archive menu entry
* debian/patches/04_suppress_umount_in_ltsp.patch:
  - Don't list unmount and eject actions on LTSP clients
* debian/patches/05_desktop_menu_export.patch:
  - export the desktop menus for appmenu (lp #624274), commented for now
* debian/patches/06_never_exec_nonexec_launchers.patch:
  - Implement non-exec policy for .desktop handler.
* debian/patches/07_use_application_indicator.patch:
  - Use the application-indicator, needs to be updated
* debian/patches/08_fix_nautilus_desktop_autostart.patch
  - git commit, remove obsolete autostart code so that Nautilus windows
    can still be opened when desktop icons are shown
* debian/patches/09_no-initial-fade.patch:
  - Patch to disable the initial fade-in of the background without disabling 
    crossfades when the background is changed.
* debian/watch:
  - Watch unstable series
* Dropped:
* debian/patches/02_dont_set_default.patch:
  - deprecated in the new version
* debian/patches/03_menu_entry.patch:
  - no menu simplication needed with unity or gnome-shell
* debian/patches/17_disable_locked_automounting.patch:
  - the change is in the new upstream version
* debian/patches/82_gnome-app-install.patch:
  - don't use gnome-app-install it's deprecated
* debian/patches/90_git_audio_preview_url.patch:
  - the change is in the new version
* debian/patches/91_correct_rgba_use.patch:
  - the gtk rgba ubuntu specific work never landed no need to keep that one
* debian/patches/97_keyboard_nav_in_sidebar.patch:
  - the change is in the new version

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) 1999, 2000 Red Hat, Inc.
7
 
 *  Copyright (C) 2000, 2001 Eazel, Inc.
8
 
 *
9
 
 *  This library 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
 
 *  This library 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 library; if not, write to the Free Software
21
 
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
 
 *
23
 
 *  Authors: Elliot Lee <sopwith@redhat.com>
24
 
 *           Darin Adler <darin@bentspoon.com>
25
 
 *
26
 
 */
27
 
 
28
 
#include <config.h>
29
 
 
30
 
#include <eel/eel-debug.h>
31
 
#include <eel/eel-gtk-extensions.h>
32
 
#include <eel/eel-glib-extensions.h>
33
 
#include <eel/eel-preferences.h>
34
 
#include <gtk/gtk.h>
35
 
#include <glib/gi18n.h>
36
 
#include <libnautilus-private/nautilus-bookmark.h>
37
 
#include <libnautilus-private/nautilus-global-preferences.h>
38
 
#include <libnautilus-private/nautilus-sidebar-provider.h>
39
 
#include <libnautilus-private/nautilus-module.h>
40
 
#include <libnautilus-private/nautilus-signaller.h>
41
 
#include <libnautilus-private/nautilus-window-info.h>
42
 
#include <libnautilus-private/nautilus-window-slot-info.h>
43
 
 
44
 
#include "nautilus-history-sidebar.h"
45
 
 
46
 
#define NAUTILUS_HISTORY_SIDEBAR_CLASS(klass) \
47
 
  (G_TYPE_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_HISTORY_SIDEBAR, NautilusHistorySidebarClass))
48
 
#define NAUTILUS_IS_HISTORY_SIDEBAR(obj) \
49
 
  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NAUTILUS_TYPE_HISTORY_SIDEBAR))
50
 
#define NAUTILUS_IS_HISTORY_SIDEBAR_CLASS(klass) \
51
 
  (G_TYPE_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_HISTORY_SIDEBAR))
52
 
 
53
 
typedef struct {
54
 
        GtkScrolledWindowClass parent;
55
 
} NautilusHistorySidebarClass;
56
 
 
57
 
typedef struct {
58
 
        GObject parent;
59
 
} NautilusHistorySidebarProvider;
60
 
 
61
 
typedef struct {
62
 
        GObjectClass parent;
63
 
} NautilusHistorySidebarProviderClass;
64
 
 
65
 
 
66
 
enum {
67
 
        HISTORY_SIDEBAR_COLUMN_ICON,
68
 
        HISTORY_SIDEBAR_COLUMN_NAME,
69
 
        HISTORY_SIDEBAR_COLUMN_BOOKMARK,
70
 
        HISTORY_SIDEBAR_COLUMN_COUNT
71
 
};
72
 
 
73
 
static void  nautilus_history_sidebar_iface_init        (NautilusSidebarIface         *iface);
74
 
static void  sidebar_provider_iface_init                (NautilusSidebarProviderIface *iface);
75
 
static GType nautilus_history_sidebar_provider_get_type (void);
76
 
static void  nautilus_history_sidebar_style_set         (GtkWidget *widget,
77
 
                                                         GtkStyle  *previous_style);
78
 
 
79
 
G_DEFINE_TYPE_WITH_CODE (NautilusHistorySidebar, nautilus_history_sidebar, GTK_TYPE_SCROLLED_WINDOW,
80
 
                         G_IMPLEMENT_INTERFACE (NAUTILUS_TYPE_SIDEBAR,
81
 
                                                nautilus_history_sidebar_iface_init));
82
 
 
83
 
G_DEFINE_TYPE_WITH_CODE (NautilusHistorySidebarProvider, nautilus_history_sidebar_provider, G_TYPE_OBJECT,
84
 
                         G_IMPLEMENT_INTERFACE (NAUTILUS_TYPE_SIDEBAR_PROVIDER,
85
 
                                                sidebar_provider_iface_init));
86
 
 
87
 
static void
88
 
update_history (NautilusHistorySidebar *sidebar)
89
 
{
90
 
        GtkListStore         *store;
91
 
        GtkTreeSelection     *selection;
92
 
        NautilusBookmark     *bookmark;
93
 
        GdkPixbuf            *pixbuf;
94
 
        GtkTreeIter           iter;
95
 
        char *name;
96
 
        GList *l, *history;
97
 
        
98
 
        store = GTK_LIST_STORE (gtk_tree_view_get_model (sidebar->tree_view));
99
 
 
100
 
        gtk_list_store_clear (store);
101
 
 
102
 
        history = nautilus_window_info_get_history (sidebar->window);
103
 
        for (l = history; l != NULL; l = l->next) {
104
 
                bookmark = nautilus_bookmark_copy (l->data);
105
 
 
106
 
                pixbuf = nautilus_bookmark_get_pixbuf (bookmark, GTK_ICON_SIZE_MENU);
107
 
                name = nautilus_bookmark_get_name (bookmark);
108
 
                gtk_list_store_append (store, &iter);
109
 
                gtk_list_store_set (store, &iter,
110
 
                                    HISTORY_SIDEBAR_COLUMN_ICON, pixbuf,
111
 
                                    HISTORY_SIDEBAR_COLUMN_NAME, name,
112
 
                                    HISTORY_SIDEBAR_COLUMN_BOOKMARK, bookmark,
113
 
                                    -1);
114
 
                g_object_unref (bookmark);
115
 
 
116
 
                if (pixbuf != NULL) {
117
 
                        g_object_unref (pixbuf);
118
 
                }
119
 
                g_free (name);
120
 
        }
121
 
        eel_g_object_list_free (history);
122
 
 
123
 
        selection = GTK_TREE_SELECTION (gtk_tree_view_get_selection (sidebar->tree_view));
124
 
 
125
 
        if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter)) {
126
 
                gtk_tree_selection_select_iter (selection, &iter);
127
 
        }
128
 
}
129
 
 
130
 
static void
131
 
history_changed_callback (GObject *signaller,
132
 
                          NautilusHistorySidebar *sidebar)
133
 
{
134
 
        update_history (sidebar);
135
 
}
136
 
 
137
 
static void
138
 
open_selected_item (NautilusHistorySidebar *sidebar, 
139
 
                    GtkTreePath *path,
140
 
                    NautilusWindowOpenFlags flags)
141
 
{
142
 
        NautilusWindowSlotInfo *slot;
143
 
        GtkTreeModel *model;
144
 
        GtkTreeIter iter;
145
 
        NautilusBookmark *bookmark;
146
 
        GFile *location;
147
 
        
148
 
        model = gtk_tree_view_get_model (sidebar->tree_view);
149
 
        
150
 
        if (!gtk_tree_model_get_iter (model, &iter, path)) {
151
 
                return;
152
 
        }
153
 
        
154
 
        gtk_tree_model_get 
155
 
                (model, &iter, HISTORY_SIDEBAR_COLUMN_BOOKMARK, &bookmark, -1);
156
 
        
157
 
        /* Navigate to the clicked location. */
158
 
        location = nautilus_bookmark_get_location (NAUTILUS_BOOKMARK (bookmark));
159
 
        slot = nautilus_window_info_get_active_slot (sidebar->window);
160
 
        nautilus_window_slot_info_open_location
161
 
                (slot,
162
 
                 location, NAUTILUS_WINDOW_OPEN_ACCORDING_TO_MODE, 
163
 
                 flags, NULL);
164
 
        g_object_unref (location);
165
 
}
166
 
 
167
 
static void
168
 
row_activated_callback (GtkTreeView *tree_view,
169
 
                        GtkTreePath *path,
170
 
                        GtkTreeViewColumn *column,
171
 
                        gpointer user_data)
172
 
{
173
 
        NautilusHistorySidebar *sidebar;
174
 
        
175
 
        sidebar = NAUTILUS_HISTORY_SIDEBAR (user_data);
176
 
        g_assert (sidebar->tree_view == tree_view);
177
 
 
178
 
        open_selected_item (sidebar, path, 0);
179
 
}
180
 
 
181
 
static gboolean
182
 
button_press_event_callback (GtkWidget *widget,
183
 
                             GdkEventButton *event,
184
 
                             gpointer user_data)
185
 
{
186
 
        if (event->button == 2 && event->type == GDK_BUTTON_PRESS) {
187
 
                /* Open new tab on middle click. */
188
 
                NautilusHistorySidebar *sidebar;
189
 
                GtkTreePath *path;
190
 
 
191
 
                sidebar = NAUTILUS_HISTORY_SIDEBAR (user_data);
192
 
                g_assert (sidebar->tree_view == GTK_TREE_VIEW (widget));
193
 
 
194
 
                if (gtk_tree_view_get_path_at_pos (sidebar->tree_view,
195
 
                                                   event->x, event->y,
196
 
                                                   &path, NULL, NULL, NULL)) {
197
 
                        open_selected_item (sidebar, 
198
 
                                            path,
199
 
                                            NAUTILUS_WINDOW_OPEN_FLAG_NEW_TAB);
200
 
                        gtk_tree_path_free (path);
201
 
                }
202
 
        }
203
 
 
204
 
        return FALSE;
205
 
}
206
 
 
207
 
static void
208
 
update_click_policy (NautilusHistorySidebar *sidebar)
209
 
{
210
 
        int policy;
211
 
        
212
 
        policy = eel_preferences_get_enum (NAUTILUS_PREFERENCES_CLICK_POLICY);
213
 
        
214
 
        eel_gtk_tree_view_set_activate_on_single_click
215
 
                (sidebar->tree_view, policy == NAUTILUS_CLICK_POLICY_SINGLE);
216
 
}
217
 
 
218
 
static void
219
 
click_policy_changed_callback (gpointer user_data)
220
 
{
221
 
        NautilusHistorySidebar *sidebar;
222
 
        
223
 
        sidebar = NAUTILUS_HISTORY_SIDEBAR (user_data);
224
 
 
225
 
        update_click_policy (sidebar);
226
 
}
227
 
 
228
 
static void
229
 
nautilus_history_sidebar_init (NautilusHistorySidebar *sidebar)
230
 
{
231
 
        GtkTreeView       *tree_view;
232
 
        GtkTreeViewColumn *col;
233
 
        GtkCellRenderer   *cell;
234
 
        GtkListStore      *store;
235
 
        GtkTreeSelection  *selection;
236
 
        
237
 
        tree_view = GTK_TREE_VIEW (gtk_tree_view_new ());
238
 
        gtk_tree_view_set_headers_visible (tree_view, FALSE);
239
 
        gtk_widget_show (GTK_WIDGET (tree_view));
240
 
 
241
 
        col = GTK_TREE_VIEW_COLUMN (gtk_tree_view_column_new ());
242
 
        
243
 
        cell = gtk_cell_renderer_pixbuf_new ();
244
 
        gtk_tree_view_column_pack_start (col, cell, FALSE);
245
 
        gtk_tree_view_column_set_attributes (col, cell,
246
 
                                             "pixbuf", HISTORY_SIDEBAR_COLUMN_ICON,
247
 
                                             NULL);
248
 
        
249
 
        cell = gtk_cell_renderer_text_new ();
250
 
        gtk_tree_view_column_pack_start (col, cell, TRUE);
251
 
        gtk_tree_view_column_set_attributes (col, cell,
252
 
                                             "text", HISTORY_SIDEBAR_COLUMN_NAME,
253
 
                                             NULL);
254
 
 
255
 
        gtk_tree_view_column_set_fixed_width (col, NAUTILUS_ICON_SIZE_SMALLER);
256
 
        gtk_tree_view_append_column (tree_view, col);
257
 
        
258
 
        store = gtk_list_store_new (HISTORY_SIDEBAR_COLUMN_COUNT,
259
 
                                    GDK_TYPE_PIXBUF,
260
 
                                    G_TYPE_STRING,
261
 
                                    NAUTILUS_TYPE_BOOKMARK);
262
 
 
263
 
        gtk_tree_view_set_model (tree_view, GTK_TREE_MODEL (store));
264
 
        g_object_unref (store);
265
 
        
266
 
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sidebar),
267
 
                                        GTK_POLICY_AUTOMATIC,
268
 
                                        GTK_POLICY_AUTOMATIC);
269
 
        gtk_scrolled_window_set_hadjustment (GTK_SCROLLED_WINDOW (sidebar), NULL);
270
 
        gtk_scrolled_window_set_vadjustment (GTK_SCROLLED_WINDOW (sidebar), NULL);
271
 
        gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sidebar), GTK_SHADOW_IN);
272
 
        gtk_container_add (GTK_CONTAINER (sidebar), GTK_WIDGET (tree_view));
273
 
        gtk_widget_show (GTK_WIDGET (sidebar));
274
 
        
275
 
        sidebar->tree_view = tree_view;
276
 
 
277
 
        selection = gtk_tree_view_get_selection (tree_view);
278
 
        gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);  
279
 
 
280
 
        g_signal_connect_object
281
 
                (tree_view, "row_activated", 
282
 
                 G_CALLBACK (row_activated_callback), sidebar, 0);
283
 
        
284
 
        g_signal_connect_object (nautilus_signaller_get_current (),
285
 
                                 "history_list_changed",
286
 
                                 G_CALLBACK (history_changed_callback), sidebar, 0);
287
 
 
288
 
        g_signal_connect (tree_view, "button-press-event", 
289
 
                          G_CALLBACK (button_press_event_callback), sidebar);
290
 
 
291
 
        eel_preferences_add_callback (NAUTILUS_PREFERENCES_CLICK_POLICY,
292
 
                                      click_policy_changed_callback,
293
 
                                      sidebar);
294
 
        update_click_policy (sidebar);
295
 
}
296
 
 
297
 
static void
298
 
nautilus_history_sidebar_finalize (GObject *object)
299
 
{
300
 
        NautilusHistorySidebar *sidebar;
301
 
        
302
 
        sidebar = NAUTILUS_HISTORY_SIDEBAR (object);
303
 
 
304
 
        eel_preferences_remove_callback (NAUTILUS_PREFERENCES_CLICK_POLICY,
305
 
                                         click_policy_changed_callback,
306
 
                                         sidebar);
307
 
 
308
 
        G_OBJECT_CLASS (nautilus_history_sidebar_parent_class)->finalize (object);
309
 
}
310
 
 
311
 
static void
312
 
nautilus_history_sidebar_class_init (NautilusHistorySidebarClass *class)
313
 
{
314
 
        G_OBJECT_CLASS (class)->finalize = nautilus_history_sidebar_finalize;
315
 
 
316
 
        GTK_WIDGET_CLASS (class)->style_set = nautilus_history_sidebar_style_set;
317
 
}
318
 
 
319
 
static const char *
320
 
nautilus_history_sidebar_get_sidebar_id (NautilusSidebar *sidebar)
321
 
{
322
 
        return NAUTILUS_HISTORY_SIDEBAR_ID;
323
 
}
324
 
 
325
 
static char *
326
 
nautilus_history_sidebar_get_tab_label (NautilusSidebar *sidebar)
327
 
{
328
 
        return g_strdup (_("History"));
329
 
}
330
 
 
331
 
static char *
332
 
nautilus_history_sidebar_get_tab_tooltip (NautilusSidebar *sidebar)
333
 
{
334
 
        return g_strdup (_("Show History"));
335
 
}
336
 
 
337
 
static GdkPixbuf *
338
 
nautilus_history_sidebar_get_tab_icon (NautilusSidebar *sidebar)
339
 
{
340
 
        return NULL;
341
 
}
342
 
 
343
 
static void
344
 
nautilus_history_sidebar_is_visible_changed (NautilusSidebar *sidebar,
345
 
                                             gboolean         is_visible)
346
 
{
347
 
        /* Do nothing */
348
 
}
349
 
 
350
 
static void
351
 
nautilus_history_sidebar_iface_init (NautilusSidebarIface *iface)
352
 
{
353
 
        iface->get_sidebar_id = nautilus_history_sidebar_get_sidebar_id;
354
 
        iface->get_tab_label = nautilus_history_sidebar_get_tab_label;
355
 
        iface->get_tab_tooltip = nautilus_history_sidebar_get_tab_tooltip;
356
 
        iface->get_tab_icon = nautilus_history_sidebar_get_tab_icon;
357
 
        iface->is_visible_changed = nautilus_history_sidebar_is_visible_changed;
358
 
}
359
 
 
360
 
static void
361
 
nautilus_history_sidebar_set_parent_window (NautilusHistorySidebar *sidebar,
362
 
                                            NautilusWindowInfo *window)
363
 
{
364
 
        sidebar->window = window;
365
 
        update_history (sidebar);
366
 
}
367
 
 
368
 
static void
369
 
nautilus_history_sidebar_style_set (GtkWidget *widget,
370
 
                                   GtkStyle  *previous_style)
371
 
{
372
 
        NautilusHistorySidebar *sidebar;
373
 
 
374
 
        sidebar = NAUTILUS_HISTORY_SIDEBAR (widget);
375
 
 
376
 
        update_history (sidebar);
377
 
}
378
 
 
379
 
static NautilusSidebar *
380
 
nautilus_history_sidebar_create (NautilusSidebarProvider *provider,
381
 
                                 NautilusWindowInfo *window)
382
 
{
383
 
        NautilusHistorySidebar *sidebar;
384
 
        
385
 
        sidebar = g_object_new (nautilus_history_sidebar_get_type (), NULL);
386
 
        nautilus_history_sidebar_set_parent_window (sidebar, window);
387
 
        g_object_ref_sink (sidebar);
388
 
 
389
 
        return NAUTILUS_SIDEBAR (sidebar);
390
 
}
391
 
 
392
 
static void 
393
 
sidebar_provider_iface_init (NautilusSidebarProviderIface *iface)
394
 
{
395
 
        iface->create = nautilus_history_sidebar_create;
396
 
}
397
 
 
398
 
static void
399
 
nautilus_history_sidebar_provider_init (NautilusHistorySidebarProvider *sidebar)
400
 
{
401
 
}
402
 
 
403
 
static void
404
 
nautilus_history_sidebar_provider_class_init (NautilusHistorySidebarProviderClass *class)
405
 
{
406
 
}
407
 
 
408
 
void
409
 
nautilus_history_sidebar_register (void)
410
 
{
411
 
        nautilus_module_add_type (nautilus_history_sidebar_provider_get_type ());
412
 
}
413