gtkplacessidebar.c 147 KB
Newer Older
1
/*
2 3
 *  GtkPlacesSidebar - sidebar widget for places in the filesystem
 *
4
 *  This code comes from Nautilus, GNOME’s file manager.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License as
 *  published by the Free Software Foundation; either version 2 of the
 *  License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this library; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  Authors : Mr Jamie McCracken (jamiemcc at blueyonder dot co dot uk)
 *            Cosimo Cecchi <cosimoc@gnome.org>
22
 *            Federico Mena Quintero <federico@gnome.org>
23 24
 *
 */
25

26 27 28 29 30 31
/* TODO:
 *
 * * Fix instances of "#if 0"
 *
 * * Fix FIXMEs
 *
32
 * * Grep for "NULL-GError" and see if they should be taken care of
33 34 35 36 37 38
 *
 * * Although we do g_mount_unmount_with_operation(), Nautilus used to do
 *   nautilus_file_operations_unmount_mount_full() to unmount a volume.  With
 *   that, Nautilus does the "volume has trash, empty it first?" dance.  Cosimo
 *   suggests that this logic should be part of GtkMountOperation, which can
 *   have Unix-specific code for emptying trash.
39
 *
40
 * * Sync nautilus commit 17a85b78acc78b573c2e1776b348ed348e19adb7
41
 *
42 43
 */

44
#include "config.h"
45

46 47
#include <gio/gio.h>

48
#include "gdk/gdkkeysyms.h"
49
#include "gtkbookmarksmanager.h"
50 51 52
#include "gtkcelllayout.h"
#include "gtkcellrenderertext.h"
#include "gtkcellrendererpixbuf.h"
53
#include "gtkfilesystem.h"
54 55 56
#include "gtkicontheme.h"
#include "gtkintl.h"
#include "gtkmain.h"
57
#include "gtkmarshalers.h"
58 59
#include "gtkmenuitem.h"
#include "gtkmountoperation.h"
60 61
#include "gtkplacessidebar.h"
#include "gtkscrolledwindow.h"
62
#include "gtkseparatormenuitem.h"
63
#include "gtksettings.h"
64
#include "gtktrashmonitor.h"
65 66
#include "gtktreeselection.h"
#include "gtktreednd.h"
67
#include "gtktypebuiltins.h"
68
#include "gtkwindow.h"
69

70 71 72 73 74 75 76
/**
 * SECTION:gtkplacessidebar
 * @Short_description: Sidebar that displays frequently-used places in the file system
 * @Title: GtkPlacesSidebar
 * @See_also: #GtkFileChooser
 *
 * #GtkPlacesSidebar is a widget that displays a list of frequently-used places in the
77
 * file system:  the user’s home directory, the user’s bookmarks, and volumes and drives.
78 79 80 81 82 83 84 85 86 87 88 89 90
 * This widget is used as a sidebar in #GtkFileChooser and may be used by file managers
 * and similar programs.
 *
 * The places sidebar displays drives and volumes, and will automatically mount
 * or unmount them when the user selects them.
 *
 * Applications can hook to various signals in the places sidebar to customize
 * its behavior.  For example, they can add extra commands to the context menu
 * of the sidebar.
 *
 * While bookmarks are completely in control of the user, the places sidebar also
 * allows individual applications to provide extra shortcut folders that are unique
 * to each application.  For example, a Paint program may want to add a shortcut
91
 * for a Clipart folder.  You can do this with gtk_places_sidebar_add_shortcut().
92 93 94 95 96 97 98 99
 *
 * To make use of the places sidebar, an application at least needs to connect
 * to the #GtkPlacesSidebar::open-location signal.  This is emitted when the
 * user selects in the sidebar a location to open.  The application should also
 * call gtk_places_sidebar_set_location() when it changes the currently-viewed
 * location.
 */

100 101
#define EJECT_BUTTON_XPAD 6
#define ICON_CELL_XPAD 6
102
#define TIMEOUT_EXPAND 500
103

Matthias Clasen's avatar
Matthias Clasen committed
104
/* These are used when a destination-side DND operation is taking place.
105
 * Normally, when a file is being hovered directly over a bookmark,
106
 * we’ll be in DROP_STATE_NORMAL.
107 108 109 110 111 112 113 114 115 116 117
 *
 * But when a file is being hovered between bookmarks, this means the user
 * may want to create a new bookmark for that file between those bookmarks.
 * In that case, the drop state will be *not* DROP_STATE_NORMAL.
 *
 * When the drop state is FADING_OUT, it means that the user is hovering
 * directly over an existing bookmark and an immediate drop will cause the
 * file being dragged to be dropped on the bookmark, instead of causing
 * a new bookmark to be created.
 */
typedef enum {
Matthias Clasen's avatar
Matthias Clasen committed
118 119 120 121
  DROP_STATE_NORMAL,
  DROP_STATE_NEW_BOOKMARK_FADING_IN,
  DROP_STATE_NEW_BOOKMARK_ARMED,
  DROP_STATE_NEW_BOOKMARK_FADING_OUT
122 123
} DropState;

124
struct _GtkPlacesSidebar {
Matthias Clasen's avatar
Matthias Clasen committed
125
  GtkScrolledWindow parent;
126

Matthias Clasen's avatar
Matthias Clasen committed
127 128 129 130 131 132
  GtkTreeView       *tree_view;
  GtkCellRenderer   *eject_icon_cell_renderer;
  GtkListStore      *store;
  GtkBookmarksManager     *bookmarks_manager;
  GVolumeMonitor    *volume_monitor;
  GtkTrashMonitor   *trash_monitor;
133
  GtkSettings       *gtk_settings;
134

Matthias Clasen's avatar
Matthias Clasen committed
135
  gulong trash_monitor_changed_id;
136

Matthias Clasen's avatar
Matthias Clasen committed
137 138
  gboolean devices_header_added;
  gboolean bookmarks_header_added;
139

Matthias Clasen's avatar
Matthias Clasen committed
140 141 142
  /* DND */
  GList     *drag_list; /* list of GFile */
  gint       drag_data_info;
143

Matthias Clasen's avatar
Matthias Clasen committed
144 145
  /* volume mounting - delayed open process */
  GtkPlacesOpenFlags go_to_after_mount_open_flags;
146

Matthias Clasen's avatar
Matthias Clasen committed
147 148
  GtkWidget *popup_menu;
  GSList *shortcuts;
149

Matthias Clasen's avatar
Matthias Clasen committed
150 151 152
  GDBusProxy *hostnamed_proxy;
  GCancellable *hostnamed_cancellable;
  gchar *hostname;
153

Matthias Clasen's avatar
Matthias Clasen committed
154
  GtkPlacesOpenFlags open_flags;
155

Matthias Clasen's avatar
Matthias Clasen committed
156 157 158 159 160
  DropState drop_state;
  gint new_bookmark_index;
  guint drag_leave_timeout_id;
  gchar *drop_target_uri;
  guint switch_location_timer;
161

Matthias Clasen's avatar
Matthias Clasen committed
162 163 164
  guint mounting               : 1;
  guint  drag_data_received    : 1;
  guint drop_occured           : 1;
165
  guint show_desktop_set       : 1;
Matthias Clasen's avatar
Matthias Clasen committed
166 167
  guint show_desktop           : 1;
  guint show_connect_to_server : 1;
168
  guint local_only             : 1;
169
};
170

171
struct _GtkPlacesSidebarClass {
Matthias Clasen's avatar
Matthias Clasen committed
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
  GtkScrolledWindowClass parent;

  void    (* open_location)          (GtkPlacesSidebar   *sidebar,
                                      GFile              *location,
                                      GtkPlacesOpenFlags  open_flags);
  void    (* populate_popup)         (GtkPlacesSidebar   *sidebar,
                                      GtkMenu            *menu,
                                      GFile              *selected_item,
                                      GVolume            *selected_volume);
  void    (* show_error_message)     (GtkPlacesSidebar   *sidebar,
                                      const gchar        *primary,
                                      const gchar        *secondary);
  void    (* show_connect_to_server) (GtkPlacesSidebar   *sidebar);
  GdkDragAction (* drag_action_requested)  (GtkPlacesSidebar   *sidebar,
                                      GdkDragContext     *context,
                                      GFile              *dest_file,
                                      GList              *source_file_list);
  GdkDragAction (* drag_action_ask)  (GtkPlacesSidebar   *sidebar,
                                      GdkDragAction       actions);
  void    (* drag_perform_drop)      (GtkPlacesSidebar   *sidebar,
                                      GFile              *dest_file,
                                      GList              *source_file_list,
                                      GdkDragAction       action);
195
};
196 197

enum {
Matthias Clasen's avatar
Matthias Clasen committed
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
  PLACES_SIDEBAR_COLUMN_ROW_TYPE,
  PLACES_SIDEBAR_COLUMN_URI,
  PLACES_SIDEBAR_COLUMN_DRIVE,
  PLACES_SIDEBAR_COLUMN_VOLUME,
  PLACES_SIDEBAR_COLUMN_MOUNT,
  PLACES_SIDEBAR_COLUMN_NAME,
  PLACES_SIDEBAR_COLUMN_GICON,
  PLACES_SIDEBAR_COLUMN_INDEX,
  PLACES_SIDEBAR_COLUMN_EJECT,
  PLACES_SIDEBAR_COLUMN_NO_EJECT,
  PLACES_SIDEBAR_COLUMN_BOOKMARK,
  PLACES_SIDEBAR_COLUMN_TOOLTIP,
  PLACES_SIDEBAR_COLUMN_SECTION_TYPE,
  PLACES_SIDEBAR_COLUMN_HEADING_TEXT,
  PLACES_SIDEBAR_COLUMN_COUNT
213 214 215
};

typedef enum {
Matthias Clasen's avatar
Matthias Clasen committed
216 217 218 219 220 221 222
  PLACES_BUILT_IN,
  PLACES_XDG_DIR,
  PLACES_MOUNTED_VOLUME,
  PLACES_BOOKMARK,
  PLACES_HEADING,
  PLACES_CONNECT_TO_SERVER,
  PLACES_DROP_FEEDBACK
223 224 225
} PlaceType;

typedef enum {
Matthias Clasen's avatar
Matthias Clasen committed
226 227 228 229
  SECTION_DEVICES,
  SECTION_BOOKMARKS,
  SECTION_COMPUTER,
  SECTION_NETWORK
230 231
} SectionType;

232
enum {
Matthias Clasen's avatar
Matthias Clasen committed
233 234 235 236 237 238 239 240
  OPEN_LOCATION,
  POPULATE_POPUP,
  SHOW_ERROR_MESSAGE,
  SHOW_CONNECT_TO_SERVER,
  DRAG_ACTION_REQUESTED,
  DRAG_ACTION_ASK,
  DRAG_PERFORM_DROP,
  LAST_SIGNAL
241 242
};

243
enum {
Matthias Clasen's avatar
Matthias Clasen committed
244 245 246 247
  PROP_LOCATION = 1,
  PROP_OPEN_FLAGS,
  PROP_SHOW_DESKTOP,
  PROP_SHOW_CONNECT_TO_SERVER,
248
  PROP_LOCAL_ONLY,
Matthias Clasen's avatar
Matthias Clasen committed
249
  NUM_PROPERTIES
250 251
};

252
/* Names for themed icons */
Matthias Clasen's avatar
Matthias Clasen committed
253
#define ICON_NAME_HOME     "user-home-symbolic"
254
#define ICON_NAME_DESKTOP  "user-desktop-symbolic"
Matthias Clasen's avatar
Matthias Clasen committed
255 256 257
#define ICON_NAME_FILESYSTEM     "drive-harddisk-symbolic"
#define ICON_NAME_EJECT    "media-eject-symbolic"
#define ICON_NAME_NETWORK  "network-workgroup-symbolic"
258
#define ICON_NAME_NETWORK_SERVER "network-server-symbolic"
259
#define ICON_NAME_FOLDER_NETWORK "folder-remote-symbolic"
260

261
#define ICON_NAME_FOLDER                "folder-symbolic"
262
#define ICON_NAME_FOLDER_DESKTOP  "user-desktop-symbolic"
Matthias Clasen's avatar
Matthias Clasen committed
263 264 265 266 267 268 269 270
#define ICON_NAME_FOLDER_DOCUMENTS      "folder-documents-symbolic"
#define ICON_NAME_FOLDER_DOWNLOAD       "folder-download-symbolic"
#define ICON_NAME_FOLDER_MUSIC    "folder-music-symbolic"
#define ICON_NAME_FOLDER_PICTURES       "folder-pictures-symbolic"
#define ICON_NAME_FOLDER_PUBLIC_SHARE   "folder-publicshare-symbolic"
#define ICON_NAME_FOLDER_TEMPLATES      "folder-templates-symbolic"
#define ICON_NAME_FOLDER_VIDEOS   "folder-videos-symbolic"
#define ICON_NAME_FOLDER_SAVED_SEARCH   "folder-saved-search-symbolic"
271

272
static guint places_sidebar_signals [LAST_SIGNAL] = { 0 };
273
static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
274

Matthias Clasen's avatar
Matthias Clasen committed
275 276 277 278 279 280 281 282 283 284 285 286
static void  open_selected_bookmark        (GtkPlacesSidebar   *sidebar,
                                            GtkTreeModel       *model,
                                            GtkTreeIter        *iter,
                                            GtkPlacesOpenFlags  open_flags);
static gboolean eject_or_unmount_bookmark  (GtkPlacesSidebar   *sidebar,
                                            GtkTreePath        *path);
static gboolean eject_or_unmount_selection (GtkPlacesSidebar   *sidebar);
static void  check_unmount_and_eject       (GMount             *mount,
                                            GVolume            *volume,
                                            GDrive             *drive,
                                            gboolean           *show_unmount,
                                            gboolean           *show_eject);
287 288 289

/* Identifiers for target types */
enum {
Matthias Clasen's avatar
Matthias Clasen committed
290 291
  GTK_TREE_MODEL_ROW,
  TEXT_URI_LIST
292 293 294
};

/* Target types for dragging from the shortcuts list */
295
static const GtkTargetEntry dnd_source_targets[] = {
Matthias Clasen's avatar
Matthias Clasen committed
296
  { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, GTK_TREE_MODEL_ROW }
297 298 299
};

/* Target types for dropping into the shortcuts list */
300
static const GtkTargetEntry dnd_drop_targets [] = {
Matthias Clasen's avatar
Matthias Clasen committed
301
  { "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, GTK_TREE_MODEL_ROW }
302 303 304 305
};

/* Drag and drop interface declarations */
typedef struct {
Matthias Clasen's avatar
Matthias Clasen committed
306
  GtkListStore parent;
307

Matthias Clasen's avatar
Matthias Clasen committed
308
  GtkPlacesSidebar *sidebar;
309
} ShortcutsModel;
310 311

typedef struct {
Matthias Clasen's avatar
Matthias Clasen committed
312
  GtkListStoreClass parent_class;
313
} ShortcutsModelClass;
314

315 316
#define SHORTCUTS_MODEL_TYPE (shortcuts_model_get_type ())
#define SHORTCUTS_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SHORTCUTS_MODEL_TYPE, ShortcutsModel))
317

318 319
static GType shortcuts_model_get_type (void);
static void shortcuts_model_drag_source_iface_init (GtkTreeDragSourceIface *iface);
320

Matthias Clasen's avatar
Matthias Clasen committed
321 322 323
G_DEFINE_TYPE_WITH_CODE (ShortcutsModel, shortcuts_model, GTK_TYPE_LIST_STORE,
                         G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_DRAG_SOURCE,
                                                shortcuts_model_drag_source_iface_init));
324

325
static GtkListStore *shortcuts_model_new (GtkPlacesSidebar *sidebar);
326

327
G_DEFINE_TYPE (GtkPlacesSidebar, gtk_places_sidebar, GTK_TYPE_SCROLLED_WINDOW);
328

329
static void
Matthias Clasen's avatar
Matthias Clasen committed
330 331 332
emit_open_location (GtkPlacesSidebar   *sidebar,
                    GFile              *location,
                    GtkPlacesOpenFlags  open_flags)
333
{
Matthias Clasen's avatar
Matthias Clasen committed
334 335
  if ((open_flags & sidebar->open_flags) == 0)
    open_flags = GTK_PLACES_OPEN_NORMAL;
336

Matthias Clasen's avatar
Matthias Clasen committed
337 338
  g_signal_emit (sidebar, places_sidebar_signals[OPEN_LOCATION], 0,
                 location, open_flags);
339 340
}

341
static void
Matthias Clasen's avatar
Matthias Clasen committed
342 343 344 345
emit_populate_popup (GtkPlacesSidebar *sidebar, 
                     GtkMenu          *menu,
                     GFile            *selected_item,
                     GVolume          *selected_volume)
346
{
Matthias Clasen's avatar
Matthias Clasen committed
347 348
  g_signal_emit (sidebar, places_sidebar_signals[POPULATE_POPUP], 0,
                 menu, selected_item, selected_volume);
349 350
}

351
static void
Matthias Clasen's avatar
Matthias Clasen committed
352 353 354
emit_show_error_message (GtkPlacesSidebar *sidebar,
                         const gchar      *primary,
                         const gchar      *secondary)
355
{
Matthias Clasen's avatar
Matthias Clasen committed
356 357
  g_signal_emit (sidebar, places_sidebar_signals[SHOW_ERROR_MESSAGE], 0,
                 primary, secondary);
358 359
}

360 361 362
static void
emit_show_connect_to_server (GtkPlacesSidebar *sidebar)
{
Matthias Clasen's avatar
Matthias Clasen committed
363
  g_signal_emit (sidebar, places_sidebar_signals[SHOW_CONNECT_TO_SERVER], 0);
364 365
}

366
static GdkDragAction
367
emit_drag_action_requested (GtkPlacesSidebar *sidebar,
Matthias Clasen's avatar
Matthias Clasen committed
368 369 370
                            GdkDragContext   *context,
                            GFile            *dest_file,
                            GList            *source_file_list)
371
{
Matthias Clasen's avatar
Matthias Clasen committed
372
  GdkDragAction ret_action = 0;
373

Matthias Clasen's avatar
Matthias Clasen committed
374 375
  g_signal_emit (sidebar, places_sidebar_signals[DRAG_ACTION_REQUESTED], 0,
                 context, dest_file, source_file_list, &ret_action);
376

Matthias Clasen's avatar
Matthias Clasen committed
377
  return ret_action;
378 379
}

380 381
static GdkDragAction
emit_drag_action_ask (GtkPlacesSidebar *sidebar,
Matthias Clasen's avatar
Matthias Clasen committed
382
                      GdkDragAction     actions)
383
{
Matthias Clasen's avatar
Matthias Clasen committed
384
  GdkDragAction ret_action = 0;
385

Matthias Clasen's avatar
Matthias Clasen committed
386 387
  g_signal_emit (sidebar, places_sidebar_signals[DRAG_ACTION_ASK], 0,
                 actions, &ret_action);
388

Matthias Clasen's avatar
Matthias Clasen committed
389
  return ret_action;
390 391
}

392 393
static void
emit_drag_perform_drop (GtkPlacesSidebar *sidebar,
Matthias Clasen's avatar
Matthias Clasen committed
394 395 396
                        GFile            *dest_file,
                        GList            *source_file_list,
                        GdkDragAction     action)
397
{
Matthias Clasen's avatar
Matthias Clasen committed
398 399
  g_signal_emit (sidebar, places_sidebar_signals[DRAG_PERFORM_DROP], 0,
                 dest_file, source_file_list, action);
400 401
}

402 403 404
static gint
get_icon_size (GtkPlacesSidebar *sidebar)
{
Matthias Clasen's avatar
Matthias Clasen committed
405
  gint width, height;
406

Matthias Clasen's avatar
Matthias Clasen committed
407 408 409 410
  if (gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height))
    return MAX (width, height);
  else
    return 16;
411 412
}

413
static GtkTreeIter
414
add_heading (GtkPlacesSidebar *sidebar,
Matthias Clasen's avatar
Matthias Clasen committed
415 416
             SectionType       section_type,
             const gchar      *title)
417
{
Matthias Clasen's avatar
Matthias Clasen committed
418
  GtkTreeIter iter;
419

Matthias Clasen's avatar
Matthias Clasen committed
420 421 422 423 424 425 426 427
  gtk_list_store_append (sidebar->store, &iter);
  gtk_list_store_set (sidebar->store, &iter,
                      PLACES_SIDEBAR_COLUMN_ROW_TYPE, PLACES_HEADING,
                      PLACES_SIDEBAR_COLUMN_SECTION_TYPE, section_type,
                      PLACES_SIDEBAR_COLUMN_HEADING_TEXT, title,
                      PLACES_SIDEBAR_COLUMN_EJECT, FALSE,
                      PLACES_SIDEBAR_COLUMN_NO_EJECT, TRUE,
                      -1);
428

Matthias Clasen's avatar
Matthias Clasen committed
429
  return iter;
430 431 432
}

static void
433
check_heading_for_section (GtkPlacesSidebar *sidebar,
Matthias Clasen's avatar
Matthias Clasen committed
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
                           SectionType       section_type)
{
  switch (section_type)
    {
    case SECTION_DEVICES:
      if (!sidebar->devices_header_added)
        {
          add_heading (sidebar, SECTION_DEVICES, _("Devices"));
          sidebar->devices_header_added = TRUE;
        }
      break;

    case SECTION_BOOKMARKS:
      if (!sidebar->bookmarks_header_added)
        {
          add_heading (sidebar, SECTION_BOOKMARKS, _("Bookmarks"));
          sidebar->bookmarks_header_added = TRUE;
        }
      break;

    default:
      break;
  }
457 458
}

459
static void
460
add_place (GtkPlacesSidebar *sidebar,
Matthias Clasen's avatar
Matthias Clasen committed
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
           PlaceType         place_type,
           SectionType       section_type,
           const gchar      *name,
           GIcon            *icon,
           const gchar      *uri,
           GDrive           *drive,
           GVolume          *volume,
           GMount           *mount,
           const gint        index,
           const gchar      *tooltip)
{
  GtkTreeIter iter;
  gboolean show_eject, show_unmount;
  gboolean show_eject_button;

  check_heading_for_section (sidebar, section_type);

  check_unmount_and_eject (mount, volume, drive,
                           &show_unmount, &show_eject);

  if (show_unmount || show_eject)
    g_assert (place_type != PLACES_BOOKMARK);

  if (mount == NULL)
    show_eject_button = FALSE;
  else
    show_eject_button = (show_unmount || show_eject);

  gtk_list_store_append (sidebar->store, &iter);
  gtk_list_store_set (sidebar->store, &iter,
                      PLACES_SIDEBAR_COLUMN_GICON, icon,
                      PLACES_SIDEBAR_COLUMN_NAME, name,
                      PLACES_SIDEBAR_COLUMN_URI, uri,
                      PLACES_SIDEBAR_COLUMN_DRIVE, drive,
                      PLACES_SIDEBAR_COLUMN_VOLUME, volume,
                      PLACES_SIDEBAR_COLUMN_MOUNT, mount,
                      PLACES_SIDEBAR_COLUMN_ROW_TYPE, place_type,
                      PLACES_SIDEBAR_COLUMN_INDEX, index,
                      PLACES_SIDEBAR_COLUMN_EJECT, show_eject_button,
                      PLACES_SIDEBAR_COLUMN_NO_EJECT, !show_eject_button,
                      PLACES_SIDEBAR_COLUMN_BOOKMARK, place_type != PLACES_BOOKMARK,
                      PLACES_SIDEBAR_COLUMN_TOOLTIP, tooltip,
                      PLACES_SIDEBAR_COLUMN_SECTION_TYPE, section_type,
                      -1);
505 506
}

507
static GIcon *
508
special_directory_get_gicon (GUserDirectory directory)
509
{
Matthias Clasen's avatar
Matthias Clasen committed
510 511 512
#define ICON_CASE(x)                      \
  case G_USER_DIRECTORY_ ## x:                                    \
          return g_themed_icon_new_with_default_fallbacks (ICON_NAME_FOLDER_ ## x);
513

Matthias Clasen's avatar
Matthias Clasen committed
514 515
  switch (directory)
    {
516

517
    ICON_CASE (DESKTOP);
Matthias Clasen's avatar
Matthias Clasen committed
518 519 520 521 522 523 524
    ICON_CASE (DOCUMENTS);
    ICON_CASE (DOWNLOAD);
    ICON_CASE (MUSIC);
    ICON_CASE (PICTURES);
    ICON_CASE (PUBLIC_SHARE);
    ICON_CASE (TEMPLATES);
    ICON_CASE (VIDEOS);
525

Matthias Clasen's avatar
Matthias Clasen committed
526 527 528
    default:
      return g_themed_icon_new_with_default_fallbacks ("folder-symbolic");
    }
529 530 531 532 533

#undef ICON_CASE
}

static gboolean
534 535
recent_files_setting_is_enabled (GtkPlacesSidebar *sidebar)
{
Matthias Clasen's avatar
Matthias Clasen committed
536 537 538 539 540 541 542
  GtkSettings *settings;
  gboolean enabled;

  if (gtk_widget_has_screen (GTK_WIDGET (sidebar)))
    settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (sidebar)));
  else
    settings = gtk_settings_get_default ();
543

Matthias Clasen's avatar
Matthias Clasen committed
544
  g_object_get (settings, "gtk-recent-files-enabled", &enabled, NULL);
545

Matthias Clasen's avatar
Matthias Clasen committed
546
  return enabled;
547 548 549 550
}

static gboolean
recent_scheme_is_supported (void)
551
{
Matthias Clasen's avatar
Matthias Clasen committed
552 553
  const gchar * const *supported;
  gint i;
554

Matthias Clasen's avatar
Matthias Clasen committed
555 556 557
  supported = g_vfs_get_supported_uri_schemes (g_vfs_get_default ());
  if (supported == NULL)
    return FALSE;
558

Matthias Clasen's avatar
Matthias Clasen committed
559 560 561 562 563 564 565
  for (i = 0; supported[i] != NULL; i++)
    {
      if (strcmp ("recent", supported[i]) == 0)
        return TRUE;
    }

  return FALSE;
566 567
}

568 569 570
static gboolean
should_show_recent (GtkPlacesSidebar *sidebar)
{
Matthias Clasen's avatar
Matthias Clasen committed
571
  return recent_files_setting_is_enabled (sidebar) && recent_scheme_is_supported ();
572 573
}

574 575 576
static void
add_special_dirs (GtkPlacesSidebar *sidebar)
{
Matthias Clasen's avatar
Matthias Clasen committed
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632
  GList *dirs;
  gint index;

  dirs = NULL;
  for (index = 0; index < G_USER_N_DIRECTORIES; index++)
    {
      const gchar *path;
      GFile *root;
      GIcon *icon;
      gchar *name;
      gchar *mount_uri;
      gchar *tooltip;

      if (!_gtk_bookmarks_manager_get_is_xdg_dir_builtin (index))
        continue;

      path = g_get_user_special_dir (index);

      /* XDG resets special dirs to the home directory in case
       * it's not finiding what it expects. We don't want the home
       * to be added multiple times in that weird configuration.
       */
      if (path == NULL ||
          g_strcmp0 (path, g_get_home_dir ()) == 0 ||
          g_list_find_custom (dirs, path, (GCompareFunc) g_strcmp0) != NULL)
        continue;
          

      root = g_file_new_for_path (path);

      name = _gtk_bookmarks_manager_get_bookmark_label (sidebar->bookmarks_manager, root);
      if (!name)
        name = g_file_get_basename (root);

      icon = special_directory_get_gicon (index);
      mount_uri = g_file_get_uri (root);
      tooltip = g_file_get_parse_name (root);

      add_place (sidebar, PLACES_XDG_DIR,
                 SECTION_COMPUTER,
                 name, icon, mount_uri,
                 NULL, NULL, NULL, 0,
                 tooltip);
      g_free (name);
      g_object_unref (root);
      g_object_unref (icon);
      g_free (mount_uri);
      g_free (tooltip);

      dirs = g_list_prepend (dirs, (gchar *)path);
    }

  g_list_free (dirs);
}

static gchar *
633 634
get_home_directory_uri (void)
{
Matthias Clasen's avatar
Matthias Clasen committed
635
  const gchar *home;
636

Matthias Clasen's avatar
Matthias Clasen committed
637 638 639
  home = g_get_home_dir ();
  if (!home)
    return NULL;
640

Matthias Clasen's avatar
Matthias Clasen committed
641
  return g_strconcat ("file://", home, NULL);
642 643
}

Matthias Clasen's avatar
Matthias Clasen committed
644
static gchar *
645
get_desktop_directory_uri (void)
646
{
Matthias Clasen's avatar
Matthias Clasen committed
647 648 649 650 651 652 653 654 655
  const gchar *name;

  name = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);

  /* "To disable a directory, point it to the homedir."
   * See http://freedesktop.org/wiki/Software/xdg-user-dirs
   */
  if (g_strcmp0 (name, g_get_home_dir ()) == 0)
    return NULL;
656

Matthias Clasen's avatar
Matthias Clasen committed
657
  return g_strconcat ("file://", name, NULL);
658 659
}

660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678
static gboolean
should_show_file (GtkPlacesSidebar *sidebar,
                  GFile            *file)
{
  gchar *path;

  if (!sidebar->local_only)
    return TRUE;

  path = g_file_get_path (file);
  if (path)
    {
      g_free (path);
      return TRUE;
    }

  return FALSE;
}

679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705
static gboolean
file_is_shown (GtkPlacesSidebar *sidebar,
               GFile            *file)
{
  GtkTreeIter iter;
  gchar *uri;

  if (!gtk_tree_model_get_iter_first (GTK_TREE_MODEL (sidebar->store), &iter))
    return FALSE;

  do
    {
      gtk_tree_model_get (GTK_TREE_MODEL (sidebar->store), &iter,
                          PLACES_SIDEBAR_COLUMN_URI, &uri,
                          -1);
      if (uri)
        {
          GFile *other;
          gboolean found;
          other = g_file_new_for_uri (uri);
          g_free (uri);
          found = g_file_equal (file, other);
          g_object_unref (other);
          if (found)
            return TRUE;
        }
    }
706
  while (gtk_tree_model_iter_next (GTK_TREE_MODEL (sidebar->store), &iter));
707 708 709 710

  return FALSE;
}

711 712 713
static void
add_application_shortcuts (GtkPlacesSidebar *sidebar)
{
Matthias Clasen's avatar
Matthias Clasen committed
714
  GSList *l;
715

Matthias Clasen's avatar
Matthias Clasen committed
716 717 718 719
  for (l = sidebar->shortcuts; l; l = l->next)
    {
      GFile *file;
      GFileInfo *info;
720

Matthias Clasen's avatar
Matthias Clasen committed
721
      file = G_FILE (l->data);
722

723 724 725
      if (!should_show_file (sidebar, file))
        continue;

726 727 728
      if (file_is_shown (sidebar, file))
        continue;

Matthias Clasen's avatar
Matthias Clasen committed
729 730 731 732 733 734
      /* FIXME: we are getting file info synchronously.  We may want to do it async at some point. */
      info = g_file_query_info (file,
                                "standard::display-name,standard::symbolic-icon",
                                G_FILE_QUERY_INFO_NONE,
                                NULL,
                                NULL); /* NULL-GError */
735

Matthias Clasen's avatar
Matthias Clasen committed
736 737 738 739 740 741
      if (info)
        {
          gchar *uri;
          gchar *tooltip;
          const gchar *name;
          GIcon *icon;
742

Matthias Clasen's avatar
Matthias Clasen committed
743 744 745 746
          name = g_file_info_get_display_name (info);
          icon = g_file_info_get_symbolic_icon (info);
          uri = g_file_get_uri (file);
          tooltip = g_file_get_parse_name (file);
747

Matthias Clasen's avatar
Matthias Clasen committed
748 749 750 751 752
          add_place (sidebar, PLACES_BUILT_IN,
                     SECTION_COMPUTER,
                     name, icon, uri,
                     NULL, NULL, NULL, 0,
                     tooltip);
753

Matthias Clasen's avatar
Matthias Clasen committed
754 755
          g_free (uri);
          g_free (tooltip);
756

Matthias Clasen's avatar
Matthias Clasen committed
757 758 759
          g_object_unref (info);
        }
    }
760 761
}

762 763
static gboolean
get_selected_iter (GtkPlacesSidebar *sidebar,
Matthias Clasen's avatar
Matthias Clasen committed
764
                   GtkTreeIter      *iter)
765
{
Matthias Clasen's avatar
Matthias Clasen committed
766
  GtkTreeSelection *selection;
767

Matthias Clasen's avatar
Matthias Clasen committed
768
  selection = gtk_tree_view_get_selection (sidebar->tree_view);
769

Matthias Clasen's avatar
Matthias Clasen committed
770
  return gtk_tree_selection_get_selected (selection, NULL, iter);
771 772
}

773
static void
774
update_places (GtkPlacesSidebar *sidebar)
775
{
Matthias Clasen's avatar
Matthias Clasen committed
776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840
  GtkTreeIter iter;
  GVolumeMonitor *volume_monitor;
  GList *mounts, *l, *ll;
  GMount *mount;
  GList *drives;
  GDrive *drive;
  GList *volumes;
  GVolume *volume;
  GSList *bookmarks, *sl;
  gint index;
  gchar *original_uri, *mount_uri, *name, *identifier;
  gchar *home_uri;
  gchar *bookmark_name;
  GIcon *icon;
  GFile *root;
  gchar *tooltip;
  GList *network_mounts, *network_volumes;

  /* save original selection */
  if (get_selected_iter (sidebar, &iter))
    gtk_tree_model_get (GTK_TREE_MODEL (sidebar->store),
                        &iter,
                        PLACES_SIDEBAR_COLUMN_URI, &original_uri, -1);
  else
    original_uri = NULL;

  gtk_list_store_clear (sidebar->store);

  sidebar->devices_header_added = FALSE;
  sidebar->bookmarks_header_added = FALSE;

  network_mounts = network_volumes = NULL;
  volume_monitor = sidebar->volume_monitor;

  /* add built-in bookmarks */

  add_heading (sidebar, SECTION_COMPUTER, _("Places"));

  if (should_show_recent (sidebar))
    {
      mount_uri = "recent:///";
      icon = g_themed_icon_new_with_default_fallbacks ("document-open-recent-symbolic");
      add_place (sidebar, PLACES_BUILT_IN,
                 SECTION_COMPUTER,
                 _("Recent"), icon, mount_uri,
                 NULL, NULL, NULL, 0,
                 _("Recent files"));
      g_object_unref (icon);
    }

  /* home folder */
  home_uri = get_home_directory_uri ();
  icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_HOME);
  add_place (sidebar, PLACES_BUILT_IN,
             SECTION_COMPUTER,
             _("Home"), icon, home_uri,
             NULL, NULL, NULL, 0,
             _("Open your personal folder"));
  g_object_unref (icon);
  g_free (home_uri);

  /* desktop */
  if (sidebar->show_desktop)
    {
      mount_uri = get_desktop_directory_uri ();
841 842 843 844 845 846 847 848 849 850 851
      if (mount_uri)
        {
          icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_DESKTOP);
          add_place (sidebar, PLACES_BUILT_IN,
                     SECTION_COMPUTER,
                     _("Desktop"), icon, mount_uri,
                     NULL, NULL, NULL, 0,
                     _("Open the contents of your desktop in a folder"));
          g_object_unref (icon);
          g_free (mount_uri);
        }
Matthias Clasen's avatar
Matthias Clasen committed
852 853 854 855 856 857
    }

  /* XDG directories */
  add_special_dirs (sidebar);

  /* Trash */
858 859 860 861 862 863 864 865 866 867 868
  if (!sidebar->local_only)
    {
      mount_uri = "trash:///"; /* No need to strdup */
      icon = _gtk_trash_monitor_get_icon (sidebar->trash_monitor);
      add_place (sidebar, PLACES_BUILT_IN,
                 SECTION_COMPUTER,
                 _("Trash"), icon, mount_uri,
                 NULL, NULL, NULL, 0,
                 _("Open the trash"));
      g_object_unref (icon);
    }
Matthias Clasen's avatar
Matthias Clasen committed
869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091

  /* Application-side shortcuts */
  add_application_shortcuts (sidebar);

  /* go through all connected drives */
  drives = g_volume_monitor_get_connected_drives (volume_monitor);

  for (l = drives; l != NULL; l = l->next)
    {
      drive = l->data;

      volumes = g_drive_get_volumes (drive);
      if (volumes != NULL)
        {
          for (ll = volumes; ll != NULL; ll = ll->next)
            {
              volume = ll->data;
              identifier = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_CLASS);

              if (g_strcmp0 (identifier, "network") == 0)
                {
                  g_free (identifier);
                  network_volumes = g_list_prepend (network_volumes, volume);
                  continue;
                }
              g_free (identifier);

              mount = g_volume_get_mount (volume);
              if (mount != NULL)
                {
                  /* Show mounted volume in the sidebar */
                  icon = g_mount_get_symbolic_icon (mount);
                  root = g_mount_get_default_location (mount);
                  mount_uri = g_file_get_uri (root);
                  name = g_mount_get_name (mount);
                  tooltip = g_file_get_parse_name (root);

                  add_place (sidebar, PLACES_MOUNTED_VOLUME,
                             SECTION_DEVICES,
                             name, icon, mount_uri,
                             drive, volume, mount, 0, tooltip);
                  g_object_unref (root);
                  g_object_unref (mount);
                  g_object_unref (icon);
                  g_free (tooltip);
                  g_free (name);
                  g_free (mount_uri);
                }
              else
                {
                  /* Do show the unmounted volumes in the sidebar;
                   * this is so the user can mount it (in case automounting
                   * is off).
                   *
                   * Also, even if automounting is enabled, this gives a visual
                   * cue that the user should remember to yank out the media if
                   * he just unmounted it.
                   */
                  icon = g_volume_get_symbolic_icon (volume);
                  name = g_volume_get_name (volume);
                  tooltip = g_strdup_printf (_("Mount and open %s"), name);

                  add_place (sidebar, PLACES_MOUNTED_VOLUME,
                             SECTION_DEVICES,
                             name, icon, NULL,
                             drive, volume, NULL, 0, tooltip);
                  g_object_unref (icon);
                  g_free (name);
                  g_free (tooltip);
                }
              g_object_unref (volume);
            }
          g_list_free (volumes);
        }
      else
        {
          if (g_drive_is_media_removable (drive) && !g_drive_is_media_check_automatic (drive))
            {
              /* If the drive has no mountable volumes and we cannot detect media change.. we
               * display the drive in the sidebar so the user can manually poll the drive by
               * right clicking and selecting "Rescan..."
               *
               * This is mainly for drives like floppies where media detection doesn't
               * work.. but it's also for human beings who like to turn off media detection
               * in the OS to save battery juice.
               */
              icon = g_drive_get_symbolic_icon (drive);
              name = g_drive_get_name (drive);
              tooltip = g_strdup_printf (_("Mount and open %s"), name);

              add_place (sidebar, PLACES_BUILT_IN,
                         SECTION_DEVICES,
                         name, icon, NULL,
                         drive, NULL, NULL, 0, tooltip);
              g_object_unref (icon);
              g_free (tooltip);
              g_free (name);
            }
        }
      g_object_unref (drive);
    }
  g_list_free (drives);

  /* add all volumes that is not associated with a drive */
  volumes = g_volume_monitor_get_volumes (volume_monitor);
  for (l = volumes; l != NULL; l = l->next)
    {
      volume = l->data;
      drive = g_volume_get_drive (volume);
      if (drive != NULL)
        {
          g_object_unref (volume);
          g_object_unref (drive);
          continue;
        }

      identifier = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_CLASS);

      if (g_strcmp0 (identifier, "network") == 0)
        {
          g_free (identifier);
          network_volumes = g_list_prepend (network_volumes, volume);
          continue;
        }
      g_free (identifier);

      mount = g_volume_get_mount (volume);
      if (mount != NULL)
        {
          icon = g_mount_get_symbolic_icon (mount);
          root = g_mount_get_default_location (mount);
          mount_uri = g_file_get_uri (root);
          tooltip = g_file_get_parse_name (root);
          name = g_mount_get_name (mount);
          add_place (sidebar, PLACES_MOUNTED_VOLUME,
                     SECTION_DEVICES,
                     name, icon, mount_uri,
                     NULL, volume, mount, 0, tooltip);
          g_object_unref (mount);
          g_object_unref (root);
          g_object_unref (icon);
          g_free (name);
          g_free (tooltip);
          g_free (mount_uri);
        }
      else
        {
          /* see comment above in why we add an icon for an unmounted mountable volume */
          icon = g_volume_get_symbolic_icon (volume);
          name = g_volume_get_name (volume);
          add_place (sidebar, PLACES_MOUNTED_VOLUME,
                     SECTION_DEVICES,
                     name, icon, NULL,
                     NULL, volume, NULL, 0, name);
          g_object_unref (icon);
          g_free (name);
        } 
      g_object_unref (volume);
    }
  g_list_free (volumes);

  /* file system root */

  mount_uri = "file:///"; /* No need to strdup */
  icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_FILESYSTEM);
  add_place (sidebar, PLACES_BUILT_IN,
             SECTION_DEVICES,
             sidebar->hostname, icon, mount_uri,
             NULL, NULL, NULL, 0,
             _("Open the contents of the file system"));
  g_object_unref (icon);

  /* add mounts that has no volume (/etc/mtab mounts, ftp, sftp,...) */
  mounts = g_volume_monitor_get_mounts (volume_monitor);

  for (l = mounts; l != NULL; l = l->next)
    {
      mount = l->data;
      if (g_mount_is_shadowed (mount))
        {
          g_object_unref (mount);
          continue;
        }
      volume = g_mount_get_volume (mount);
      if (volume != NULL)
        {
          g_object_unref (volume);
          g_object_unref (mount);
          continue;
        }
      root = g_mount_get_default_location (mount);

      if (!g_file_is_native (root))
        {
          network_mounts = g_list_prepend (network_mounts, mount);
          g_object_unref (root);
          continue;
        }

      icon = g_mount_get_symbolic_icon (mount);
      mount_uri = g_file_get_uri (root);
      name = g_mount_get_name (mount);
      tooltip = g_file_get_parse_name (root);
      add_place (sidebar, PLACES_MOUNTED_VOLUME,
                 SECTION_COMPUTER,
                 name, icon, mount_uri,
                 NULL, NULL, mount, 0, tooltip);
      g_object_unref (root);
      g_object_unref (mount);
      g_object_unref (icon);
      g_free (name);
      g_free (mount_uri);
      g_free (tooltip);
    }
  g_list_free (mounts);

  /* add bookmarks */

  bookmarks = _gtk_bookmarks_manager_list_bookmarks (sidebar->bookmarks_manager);

  for (sl = bookmarks, index = 0; sl; sl = sl->next, index++)
    {
      GFileInfo *info;
1092
      gboolean is_native;
Matthias Clasen's avatar
Matthias Clasen committed
1093 1094

      root = sl->data;
1095
      is_native = g_file_is_native (root);
1096 1097

#if 0
Matthias Clasen's avatar
Matthias Clasen committed
1098 1099 1100
      /* FIXME: remove this?  If we *do* show bookmarks for nonexistent files, the user will eventually clean them up */
      if (!nautilus_bookmark_get_exists (bookmark))
        continue;
1101
#endif
1102

Matthias Clasen's avatar
Matthias Clasen committed
1103 1104 1105
      if (_gtk_bookmarks_manager_get_is_builtin (sidebar->bookmarks_manager, root))
        continue;

1106 1107 1108
      if (sidebar->local_only && !is_native)
        continue;

Matthias Clasen's avatar
Matthias Clasen committed
1109 1110 1111 1112 1113 1114 1115
      /* FIXME: we are getting file info synchronously.  We may want to do it async at some point. */
      info = g_file_query_info (root,
                                "standard::display-name,standard::symbolic-icon",
                                G_FILE_QUERY_INFO_NONE,
                                NULL,
                                NULL); /* NULL-GError */

1116 1117 1118 1119
      bookmark_name = _gtk_bookmarks_manager_get_bookmark_label (sidebar->bookmarks_manager, root);
      if (bookmark_name == NULL && info != NULL)
        bookmark_name = g_strdup (g_file_info_get_display_name (info));
      else if (bookmark_name == NULL)
Matthias Clasen's avatar
Matthias Clasen committed
1120
        {
1121 1122 1123 1124 1125 1126 1127 1128
          /* Don't add non-UTF-8 bookmarks */
          bookmark_name = g_file_get_basename (root);
          if (!g_utf8_validate (bookmark_name, -1, NULL))
            {
              g_free (bookmark_name);
              continue;
            }
        }
Matthias Clasen's avatar
Matthias Clasen committed
1129

1130 1131 1132 1133
      if (info)
        icon = g_object_ref (g_file_info_get_symbolic_icon (info));
      else
        icon = g_themed_icon_new_with_default_fallbacks (is_native ? ICON_NAME_FOLDER : ICON_NAME_FOLDER_NETWORK);
Matthias Clasen's avatar
Matthias Clasen committed
1134

1135 1136
      mount_uri = g_file_get_uri (root);
      tooltip = g_file_get_parse_name (root);
Matthias Clasen's avatar
Matthias Clasen committed
1137

1138 1139 1140 1141 1142
      add_place (sidebar, PLACES_BOOKMARK,
                 SECTION_BOOKMARKS,
                 bookmark_name, icon, mount_uri,
                 NULL, NULL, NULL, index,
                 tooltip);
Matthias Clasen's avatar
Matthias Clasen committed
1143

1144 1145 1146
      g_free (mount_uri);
      g_free (tooltip);
      g_free (bookmark_name);
Matthias Clasen's avatar
Matthias Clasen committed
1147

1148 1149
      if (info)
        g_object_unref (info);
Matthias Clasen's avatar
Matthias Clasen committed
1150 1151 1152 1153 1154 1155
    }

  g_slist_foreach (bookmarks, (GFunc) g_object_unref, NULL);
  g_slist_free (bookmarks);

  /* network */
1156
  if (!sidebar->local_only)
Matthias Clasen's avatar
Matthias Clasen committed
1157
    {
1158 1159 1160 1161 1162
      add_heading (sidebar, SECTION_NETWORK, _("Network"));

      mount_uri = "network:///";
      icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_NETWORK);
      add_place (sidebar, PLACES_BUILT_IN,
Matthias Clasen's avatar
Matthias Clasen committed
1163
                 SECTION_NETWORK,
1164
                 _("Browse Network"), icon, mount_uri,
Matthias Clasen's avatar
Matthias Clasen committed
1165
                 NULL, NULL, NULL, 0,
1166
                 _("Browse the contents of the network"));
Matthias Clasen's avatar
Matthias Clasen committed
1167 1168
      g_object_unref (icon);

1169
      if (sidebar->show_connect_to_server)
Matthias Clasen's avatar
Matthias Clasen committed
1170
        {
1171 1172 1173 1174 1175 1176 1177
          icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_NETWORK_SERVER);
          add_place (sidebar, PLACES_CONNECT_TO_SERVER,
                     SECTION_NETWORK,
                     _("Connect to Server"), icon, NULL,
                     NULL, NULL, NULL, 0,
                     _("Connect to a network server address"));
          g_object_unref (icon);
Matthias Clasen's avatar
Matthias Clasen committed
1178
        }
1179 1180 1181

      network_volumes = g_list_reverse (network_volumes);
      for (l = network_volumes; l != NULL; l = l->next)
Matthias Clasen's avatar
Matthias Clasen committed
1182
        {
1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195
          volume = l->data;
          mount = g_volume_get_mount (volume);

          if (mount != NULL)
            {
              network_mounts = g_list_prepend (network_mounts, mount);
              continue;
            }
          else
            {
              icon = g_volume_get_symbolic_icon (volume);
              name = g_volume_get_name (volume);
              tooltip = g_strdup_printf (_("Mount and open %s"), name);
Matthias Clasen's avatar
Matthias Clasen committed
1196

1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215
              add_place (sidebar, PLACES_MOUNTED_VOLUME,
                         SECTION_NETWORK,
                         name, icon, NULL,
                         NULL, volume, NULL, 0, tooltip);
              g_object_unref (icon);
              g_free (name);
              g_free (tooltip);
            }
        }

      network_mounts = g_list_reverse (network_mounts);
      for (l = network_mounts; l != NULL; l = l->next)
        {
          mount = l->data;
          root = g_mount_get_default_location (mount);
          icon = g_mount_get_symbolic_icon (mount);
          mount_uri = g_file_get_uri (root);
          name = g_mount_get_name (mount);
          tooltip = g_file_get_parse_name (root);
Matthias Clasen's avatar
Matthias Clasen committed
1216 1217
          add_place (sidebar, PLACES_MOUNTED_VOLUME,
                     SECTION_NETWORK,
1218 1219 1220
                     name, icon, mount_uri,
                     NULL, NULL, mount, 0, tooltip);
          g_object_unref (root);
Matthias Clasen's avatar
Matthias Clasen committed
1221 1222
          g_object_unref (icon);
          g_free (name);
1223
          g_free (mount_uri);
Matthias Clasen's avatar
Matthias Clasen committed
1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241
          g_free (tooltip);
        }
    }

  g_list_free_full (network_volumes, g_object_unref);
  g_list_free_full (network_mounts, g_object_unref);

  /* restore original selection */
  if (original_uri)
    {
      GFile *restore;

      restore = g_file_new_for_uri (original_uri);
      gtk_places_sidebar_set_location (sidebar, restore);
      g_object_unref (restore);

      g_free (original_uri);
    }
1242 1243 1244
}

static gboolean
Matthias Clasen's avatar
Matthias Clasen committed
1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293
over_eject_button (GtkPlacesSidebar  *sidebar,
                   gint               x,
                   gint               y,
                   GtkTreePath      **path)
{
  GtkTreeViewColumn *column;
  gint width, x_offset, hseparator;
  gint eject_button_size;
  gboolean show_eject;
  GtkTreeIter iter;
  GtkTreeModel *model;

  *path = NULL;
  model = gtk_tree_view_get_model (sidebar->tree_view);

  if (gtk_tree_view_get_path_at_pos (sidebar->tree_view,
                                     x, y, path, &column, NULL, NULL))
    {
      gtk_tree_model_get_iter (model, &iter, *path);
      gtk_tree_model_get (model, &iter,
                          PLACES_SIDEBAR_COLUMN_EJECT, &show_eject,
                          -1);

      if (!show_eject)
        goto out;

      gtk_widget_style_get (GTK_WIDGET (sidebar->tree_view),
                            "horizontal-separator", &hseparator,
                            NULL);

      /* Reload cell attributes for this particular row */
      gtk_tree_view_column_cell_set_cell_data (column,
                                               model, &iter, FALSE, FALSE);

      gtk_tree_view_column_cell_get_position (column,
                                              sidebar->eject_icon_cell_renderer,
                                              &x_offset, &width);

      eject_button_size = get_icon_size (sidebar);

      /* This is kinda weird, but we have to do it to workaround expanding
       * the eject cell renderer (even thought we told it not to) and we
       * then had to set it right-aligned
       */
      x_offset += width - hseparator - EJECT_BUTTON_XPAD - eject_button_size;

      if (x - x_offset >= 0 && x - x_offset <= eject_button_size)
        return TRUE;
    }
1294 1295

 out:
Matthias Clasen's avatar
Matthias Clasen committed
1296
  g_clear_pointer (path, gtk_tree_path_free);
1297

Matthias Clasen's avatar
Matthias Clasen committed
1298
  return FALSE;
1299 1300 1301
}

static gboolean
Matthias Clasen's avatar
Matthias Clasen committed
1302 1303
clicked_eject_button (GtkPlacesSidebar  *sidebar,
                      GtkTreePath      **path)
1304
{
Matthias Clasen's avatar
Matthias Clasen committed
1305 1306
  GdkEvent *event = gtk_get_current_event ();
  GdkEventButton *button_event = (GdkEventButton *) event;
1307

Matthias Clasen's avatar
Matthias Clasen committed
1308 1309 1310
  if ((event->type == GDK_BUTTON_PRESS || event->type == GDK_BUTTON_RELEASE) &&
       over_eject_button (sidebar, button_event->x, button_event->y, path))
    return TRUE;
1311

Matthias Clasen's avatar
Matthias Clasen committed
1312
  return FALSE;
1313 1314
}

1315 1316 1317
static gboolean
pos_is_into_or_before (GtkTreeViewDropPosition pos)
{
Matthias Clasen's avatar
Matthias Clasen committed
1318
  return (pos == GTK_TREE_VIEW_DROP_BEFORE || pos == GTK_TREE_VIEW_DROP_INTO_OR_BEFORE);
1319 1320
}

1321 1322
/* Computes the appropriate row and position for dropping */
static gboolean
Matthias Clasen's avatar
Matthias Clasen committed
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420
compute_drop_position (GtkTreeView              *tree_view,
                       gint                      x,
                       gint                      y,
                       GtkTreePath             **path,
                       GtkTreeViewDropPosition  *pos,
                       GtkPlacesSidebar         *sidebar)
{
  GtkTreeModel *model;
  GtkTreeIter iter;
  PlaceType place_type;
  SectionType section_type;
  gboolean drop_possible;

  if (!gtk_tree_view_get_dest_row_at_pos (tree_view, x, y, path, pos))
    return FALSE;

  model = gtk_tree_view_get_model (tree_view);

  gtk_tree_model_get_iter (model, &iter, *path);
  gtk_tree_model_get (model, &iter,
                      PLACES_SIDEBAR_COLUMN_ROW_TYPE, &place_type,
                      PLACES_SIDEBAR_COLUMN_SECTION_TYPE, &section_type,
                      -1);

  drop_possible = TRUE;

  /* Normalize drops on the feedback row */
  if (place_type == PLACES_DROP_FEEDBACK)
    {
      *pos = GTK_TREE_VIEW_DROP_INTO_OR_BEFORE;
      goto out;
    }

  /* Never drop on headings, but special case the bookmarks heading,
   * so we can drop bookmarks in between it and the first bookmark.
   */
  if (place_type == PLACES_HEADING && section_type != SECTION_BOOKMARKS)
    drop_possible = FALSE;

  /* Dragging a bookmark? */
  if (sidebar->drag_data_received &&
      sidebar->drag_data_info == GTK_TREE_MODEL_ROW)
    {
      /* Don't allow reordering bookmarks into non-bookmark areas */
      if (section_type != SECTION_BOOKMARKS)
        drop_possible = FALSE;

      /* Bookmarks can only be reordered.  Disallow dropping directly
       * into them; only allow dropping between them.
       */
      if (place_type == PLACES_HEADING)
        {
          if (pos_is_into_or_before (*pos))
            drop_possible = FALSE;
          else
            *pos = GTK_TREE_VIEW_DROP_AFTER;
        }
      else
        {
          if (pos_is_into_or_before (*pos))
            *pos = GTK_TREE_VIEW_DROP_BEFORE;
          else
            *pos = GTK_TREE_VIEW_DROP_AFTER;
        }
    }
  else
    { 
      /* Dragging a file */

      /* Outside the bookmarks section, URIs can only be dropped
       * directly into places items.  Inside the bookmarks section,
       * they can be dropped between items (to create new bookmarks)
       * or in items themselves (to request a move/copy file
       * operation).
       */
      if (section_type != SECTION_BOOKMARKS)
        *pos = GTK_TREE_VIEW_DROP_INTO_OR_BEFORE;
      else
        {
          if (place_type == PLACES_HEADING)
            {
              if (pos_is_into_or_before (*pos))
                drop_possible = FALSE;
              else
                *pos = GTK_TREE_VIEW_DROP_AFTER;
            }
        }
    }

  /* Disallow drops on recent:/// */
  if (place_type == PLACES_BUILT_IN)
    {
      gchar *uri;

      gtk_tree_model_get (model, &iter,
                          PLACES_SIDEBAR_COLUMN_URI, &uri,
                          -1);

1421
      if (g_strcmp0 (uri, "recent:///") == 0)
Matthias Clasen's avatar
Matthias Clasen committed
1422 1423 1424 1425
        drop_possible = FALSE;

      g_free (uri);
    }
1426

1427 1428
out:

Matthias Clasen's avatar
Matthias Clasen committed
1429 1430 1431 1432 1433 1434
  if (!drop_possible)
    {
      gtk_tree_path_free (*path);
      *path = NULL;
      return FALSE;
    }
1435

Matthias Clasen's avatar
Matthias Clasen committed
1436
  return TRUE;
1437 1438 1439
}

static gboolean
Matthias Clasen's avatar
Matthias Clasen committed
1440 1441 1442
get_drag_data (GtkTreeView    *tree_view,
               GdkDragContext *context,
               guint           time)
1443
{
Matthias Clasen's avatar
Matthias Clasen committed
1444
  GdkAtom target;
1445

Matthias Clasen's avatar
Matthias Clasen committed
1446 1447 1448
  target = gtk_drag_dest_find_target (GTK_WIDGET (tree_view),
                                      context,
                                      NULL);
1449

Matthias Clasen's avatar
Matthias Clasen committed
1450 1451
  if (target == GDK_NONE)
    return FALSE;
1452

Matthias Clasen's avatar
Matthias Clasen committed
1453 1454
  gtk_drag_get_data (GTK_WIDGET (tree_view),
                     context, target, time);
1455

Matthias Clasen's avatar
Matthias Clasen committed
1456
  return TRUE;
1457 1458
}

1459 1460 1461
static void
remove_switch_location_timer (GtkPlacesSidebar *sidebar)
{
Matthias Clasen's avatar
Matthias Clasen committed
1462 1463 1464 1465 1466
  if (sidebar->switch_location_timer != 0)
    {
      g_source_remove (sidebar->switch_location_timer);
      sidebar->switch_location_timer = 0;
    }
1467 1468
}

1469
static void
1470
free_drag_data (GtkPlacesSidebar *sidebar)
1471
{
Matthias Clasen's avatar
Matthias Clasen committed
1472
  sidebar->drag_data_received = FALSE;
1473

Matthias Clasen's avatar
Matthias Clasen committed
1474 1475 1476 1477 1478
  if (sidebar->drag_list)
    {
      g_list_free_full (sidebar->drag_list, g_object_unref);
      sidebar->drag_list = NULL;
    }
1479

Matthias Clasen's avatar
Matthias Clasen committed
1480
  remove_switch_location_timer (sidebar);
1481

Matthias Clasen's avatar
Matthias Clasen committed
1482 1483
  g_free (sidebar->drop_target_uri);
  sidebar->drop_target_uri = NULL;
1484 1485 1486 1487 1488
}

static gboolean
switch_location_timer (gpointer user_data)
{
Matthias Clasen's avatar
Matthias Clasen committed
1489 1490
  GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (user_data);
  GFile *location;
1491

Matthias Clasen's avatar
Matthias Clasen committed
1492
  sidebar->switch_location_timer = 0;
1493

Matthias Clasen's avatar
Matthias Clasen committed
1494 1495 1496
  location = g_file_new_for_uri (sidebar->drop_target_uri);
  emit_open_location (sidebar, location, 0);
  g_object_unref (location);
1497

Matthias Clasen's avatar
Matthias Clasen committed
1498
  return FALSE;
1499 1500 1501
}

static void
Matthias Clasen's avatar
Matthias Clasen committed
1502 1503
check_switch_location_timer (GtkPlacesSidebar *sidebar,
                             const gchar      *uri)
1504
{
Matthias Clasen's avatar
Matthias Clasen committed
1505 1506 1507 1508
  if (g_strcmp0 (uri, sidebar->drop_target_uri) == 0)
    return;

  remove_switch_location_timer (sidebar);
1509

Matthias Clasen's avatar
Matthias Clasen committed
1510 1511
  g_free (sidebar->drop_target_uri);
  sidebar->drop_target_uri = NULL;
1512

Matthias Clasen's avatar
Matthias Clasen committed
1513 1514 1515 1516 1517 1518
  if (uri != NULL)
    {
      sidebar->drop_target_uri = g_strdup (uri);
      sidebar->switch_location_timer = gdk_threads_add_timeout (TIMEOUT_EXPAND, switch_location_timer, sidebar);
      g_source_set_name_by_id (sidebar->switch_location_timer, "[gtk+] switch_location_timer");
    }
1519 1520
}

1521 1522 1523
static void
remove_drop_bookmark_feedback_row (GtkPlacesSidebar *sidebar)
{
Matthias Clasen's avatar
Matthias Clasen committed
1524 1525 1526 1527
  if (sidebar->drop_state != DROP_STATE_NORMAL)
    {
      gboolean success;
      GtkTreeIter iter;
1528

Matthias Clasen's avatar
Matthias Clasen committed
1529 1530 1531
      success = gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (sidebar->store), &iter, NULL, sidebar->new_bookmark_index);
      g_assert (success);
      gtk_list_store_remove (sidebar->store, &iter);
1532

Matthias Clasen's avatar
Matthias Clasen committed
1533 1534
      sidebar->drop_state = DROP_STATE_NORMAL;
    }
1535 1536
}

1537
static void
Matthias Clasen's avatar
Matthias Clasen committed
1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590
start_drop_feedback (GtkPlacesSidebar        *sidebar,
                     GtkTreePath             *path,
                     GtkTreeViewDropPosition  pos,
                     gboolean                 drop_as_bookmarks)
{
  if (drop_as_bookmarks)
    {
      gint new_bookmark_index;
      GtkTreePath *new_path;
      gboolean need_feedback_row;

      new_bookmark_index = gtk_tree_path_get_indices (path)[0];
      if (pos == GTK_TREE_VIEW_DROP_AFTER)
        new_bookmark_index++;

      if (sidebar->drop_state == DROP_STATE_NORMAL)
        need_feedback_row = TRUE;
      else
        {
          /* Feedback row already exists; remove it if its position needs to change */
          if (sidebar->new_bookmark_index == new_bookmark_index)
            need_feedback_row = FALSE;
          else
            {
              if (sidebar->new_bookmark_index < new_bookmark_index)
                new_bookmark_index--; /* since the removal of the old feedback row pushed items one position up */

                remove_drop_bookmark_feedback_row (sidebar);
                need_feedback_row = TRUE;
            }
        }

      if (need_feedback_row)
        {
          GtkTreeIter iter;

          sidebar->new_bookmark_index = new_bookmark_index;
          gtk_list_store_insert_with_values (sidebar->store, &iter, sidebar->new_bookmark_index,
                                             PLACES_SIDEBAR_COLUMN_ROW_TYPE, PLACES_DROP_FEEDBACK,
                                             PLACES_SIDEBAR_COLUMN_SECTION_TYPE, SECTION_BOOKMARKS,
                                             PLACES_SIDEBAR_COLUMN_NAME, _("New bookmark"),
                                             PLACES_SIDEBAR_COLUMN_NO_EJECT, TRUE,
                                             -1);
        }

      new_path = gtk_tree_path_new_from_indices (sidebar->new_bookmark_index, -1);
      gtk_tree_view_set_drag_dest_row (sidebar->tree_view, new_path, GTK_TREE_VIEW_DROP_INTO_OR_BEFORE);
      gtk_tree_path_free (new_path);

      sidebar->drop_state = DROP_STATE_NEW_BOOKMARK_ARMED;
    }
  else
    gtk_tree_view_set_drag_dest_row (sidebar->tree_view, path, pos);
1591 1592 1593 1594 1595
}

static void
stop_drop_feedback (GtkPlacesSidebar *sidebar)
{
Matthias Clasen's avatar
Matthias Clasen committed
1596
  gtk_tree_view_set_drag_dest_row (sidebar->tree_view, NULL, 0);
1597 1598
}

1599
static gboolean
Matthias Clasen's avatar
Matthias Clasen committed
1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678
drag_motion_callback (GtkTreeView      *tree_view,
                      GdkDragContext   *context,
                      gint              x,
                      gint              y,
                      guint             time,
                      GtkPlacesSidebar *sidebar)
{
  GtkTreePath *path;
  GtkTreeViewDropPosition pos;
  gint action;
  GtkTreeIter iter;
  gboolean res;
  gboolean drop_as_bookmarks;
  gchar *drop_target_uri = NULL;

  action = 0;
  drop_as_bookmarks = FALSE;
  path = NULL;

  if (!sidebar->drag_data_received)
    {
      if (!get_drag_data (tree_view, context, time))
        goto out;
    }

  res = compute_drop_position (tree_view, x, y, &path, &pos, sidebar);
  if (!res)
    goto out;

  if (sidebar->drag_data_received &&
      sidebar->drag_data_info == GTK_TREE_MODEL_ROW)
    {
      /* Dragging bookmarks always moves them to another position in the bookmarks list */
      action = GDK_ACTION_MOVE;
    }
  else
    {
      /* URIs are being dragged.  See if the caller wants to handle a
       * file move/copy operation itself, or if we should only try to
       * create bookmarks out of the dragged URIs.
       */
      if (sidebar->drag_list != NULL)
        {
          SectionType section_type;
          PlaceType place_type;

          gtk_tree_model_get_iter (GTK_TREE_MODEL (sidebar->store), &iter, path);
          gtk_tree_model_get (GTK_TREE_MODEL (sidebar->store),
                              &iter,
                              PLACES_SIDEBAR_COLUMN_SECTION_TYPE, &section_type,
                              PLACES_SIDEBAR_COLUMN_ROW_TYPE, &place_type,
                              -1);

          if (place_type == PLACES_DROP_FEEDBACK ||
              (section_type == SECTION_BOOKMARKS &&
               (pos == GTK_TREE_VIEW_DROP_BEFORE || pos == GTK_TREE_VIEW_DROP_AFTER)))
            {
              action = GDK_ACTION_COPY;
              drop_as_bookmarks = TRUE;
            }

          if (!drop_as_bookmarks)
            {
              gtk_tree_model_get (GTK_TREE_MODEL (sidebar->store),
                                  &iter,
                                  PLACES_SIDEBAR_COLUMN_URI, &drop_target_uri,
                                  -1);

              if (drop_target_uri != NULL)
                {
                  GFile *dest_file = g_file_new_for_uri (drop_target_uri);

                  action = emit_drag_action_requested (sidebar, context, dest_file, sidebar->drag_list);

                  g_object_unref (dest_file);
                } /* uri may be NULL for unmounted volumes, for example, so we don't allow drops there */
            }
        }
    }
1679

1680
 out:
Matthias Clasen's avatar
Matthias Clasen committed
1681 1682 1683 1684 1685 1686 1687 1688 1689 1690
  if (action != 0)
    {
      check_switch_location_timer (sidebar, drop_target_uri);
      start_drop_feedback (sidebar, path, pos, drop_as_bookmarks);
    }
  else
    {
      remove_switch_location_timer (sidebar);
      stop_drop_feedback (sidebar);
    }
1691

Matthias Clasen's avatar
Matthias Clasen committed
1692
  g_free (drop_target_uri);
1693

Matthias Clasen's avatar
Matthias Clasen committed
1694 1695
  if (path != NULL)
          gtk_tree_path_free (path);
1696

Matthias Clasen's avatar
Matthias Clasen committed
1697
  g_signal_stop_emission_by_name (tree_view, "drag-motion");
1698

Matthias Clasen's avatar
Matthias Clasen committed
1699
  gdk_drag_status (context, action, time);
1700

Matthias Clasen's avatar
Matthias Clasen committed
1701
  return TRUE;
1702 1703
}

1704 1705 1706
static gboolean
drag_leave_timeout_cb (gpointer data)
{
Matthias Clasen's avatar
Matthias Clasen committed
1707
  GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (data);
1708

Matthias Clasen's avatar
Matthias Clasen committed
1709 1710 1711
  free_drag_data (sidebar);
  stop_drop_feedback (sidebar);
  remove_drop_bookmark_feedback_row (sidebar);
1712

Matthias Clasen's avatar
Matthias Clasen committed
1713 1714
  sidebar->drag_leave_timeout_id = 0;
  return FALSE;
1715 1716
}

1717
static void
Matthias Clasen's avatar
Matthias Clasen committed
1718 1719 1720 1721
drag_leave_callback (GtkTreeView      *tree_view,
                     GdkDragContext   *context,
                     guint             time,
                     GtkPlacesSidebar *sidebar)
1722
{
Matthias Clasen's avatar
Matthias Clasen committed
1723 1724
  if (sidebar->drag_leave_timeout_id)
    g_source_remove (sidebar->drag_leave_timeout_id);
1725

Matthias Clasen's avatar
Matthias Clasen committed
1726 1727
  sidebar->drag_leave_timeout_id = gdk_threads_add_timeout (500, drag_leave_timeout_cb, sidebar);
  g_source_set_name_by_id (sidebar->drag_leave_timeout_id, "[gtk+] drag_leave_timeout_cb");
1728

Matthias Clasen's avatar
Matthias Clasen committed
1729
  remove_switch_location_timer (sidebar);
1730

Matthias Clasen's avatar
Matthias Clasen committed
1731
  g_signal_stop_emission_by_name (tree_view, "drag-leave");
1732 1733
}

1734
/* Takes an array of URIs and turns it into a list of GFile */