2011-09-06 22:53:30 +00:00
|
|
|
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
|
|
|
|
|
|
|
|
|
|
/*
|
2011-09-07 20:17:26 +00:00
|
|
|
|
* GtkPlacesSidebar - sidebar widget for places in the filesystem
|
|
|
|
|
*
|
|
|
|
|
* This code comes from Nautilus, GNOME's file manager.
|
2011-09-06 22:53:30 +00:00
|
|
|
|
*
|
|
|
|
|
* 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>
|
2012-09-11 20:45:56 +00:00
|
|
|
|
* Federico Mena Quintero <federico@gnome.org>
|
2011-09-06 22:53:30 +00:00
|
|
|
|
*
|
|
|
|
|
*/
|
2011-09-06 23:11:19 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
/* TODO:
|
|
|
|
|
*
|
|
|
|
|
* * Fix instances of "#if DO_NOT_COMPILE"
|
|
|
|
|
*
|
|
|
|
|
* * Fix instances of "#if 0"
|
|
|
|
|
*
|
|
|
|
|
* * Fix FIXMEs
|
|
|
|
|
*
|
2012-09-11 20:17:03 +00:00
|
|
|
|
* * Grep for "NULL-GError" and see if they should be taken care of
|
2012-10-30 00:57:24 +00:00
|
|
|
|
*
|
|
|
|
|
* * 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.
|
2012-12-03 23:37:11 +00:00
|
|
|
|
*
|
|
|
|
|
* * Nautilus needs to connect to "drag-action-requested", and call
|
|
|
|
|
* nautilus_drag_default_drop_action_for_icons().
|
2012-12-04 00:15:41 +00:00
|
|
|
|
*
|
|
|
|
|
* * Nautilus needs to connect to "drag-action-ask", and return the
|
|
|
|
|
* appropriate action after running a popup menu. It needs to call
|
|
|
|
|
* nautilus_drag_drop_action_ask().
|
2012-12-04 18:52:44 +00:00
|
|
|
|
*
|
|
|
|
|
* * Nautilus needs to connect to "drag-perform-drop", and call
|
|
|
|
|
* nautilus_file_operations_copy_move() as appropriate.
|
|
|
|
|
* nautilus_file_operations_copy_move (uris, NULL, drop_uri,
|
|
|
|
|
* real_action, GTK_WIDGET (tree_view),
|
|
|
|
|
* NULL, NULL);
|
2012-09-07 15:04:42 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2011-09-06 23:15:59 +00:00
|
|
|
|
#include "config.h"
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2011-10-06 14:20:32 +00:00
|
|
|
|
#include <gio/gio.h>
|
|
|
|
|
|
2011-09-06 23:15:59 +00:00
|
|
|
|
#include "gdk/gdkkeysyms.h"
|
2011-10-03 14:44:46 +00:00
|
|
|
|
#include "gtkbookmarksmanager.h"
|
2011-10-06 14:20:32 +00:00
|
|
|
|
#include "gtkcelllayout.h"
|
|
|
|
|
#include "gtkcellrenderertext.h"
|
|
|
|
|
#include "gtkcellrendererpixbuf.h"
|
2012-11-21 18:08:23 +00:00
|
|
|
|
#include "gtkfilechooserprivate.h"
|
2011-10-06 14:20:32 +00:00
|
|
|
|
#include "gtkicontheme.h"
|
|
|
|
|
#include "gtkimagemenuitem.h"
|
|
|
|
|
#include "gtkintl.h"
|
|
|
|
|
#include "gtkmain.h"
|
2011-09-28 15:44:40 +00:00
|
|
|
|
#include "gtkmarshalers.h"
|
2011-10-06 14:20:32 +00:00
|
|
|
|
#include "gtkmenuitem.h"
|
|
|
|
|
#include "gtkmountoperation.h"
|
2011-09-06 23:15:59 +00:00
|
|
|
|
#include "gtkplacessidebar.h"
|
|
|
|
|
#include "gtkscrolledwindow.h"
|
2011-10-06 14:20:32 +00:00
|
|
|
|
#include "gtkseparatormenuitem.h"
|
2012-09-04 02:04:26 +00:00
|
|
|
|
#include "gtksettings.h"
|
|
|
|
|
#include "gtkstock.h"
|
2011-10-06 14:20:32 +00:00
|
|
|
|
#include "gtktreeselection.h"
|
|
|
|
|
#include "gtktreednd.h"
|
2012-09-06 01:13:25 +00:00
|
|
|
|
#include "gtktypebuiltins.h"
|
2011-10-06 14:20:32 +00:00
|
|
|
|
#include "gtkwindow.h"
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
#define EJECT_BUTTON_XPAD 6
|
|
|
|
|
#define ICON_CELL_XPAD 6
|
|
|
|
|
|
2011-10-06 13:18:09 +00:00
|
|
|
|
#define DO_NOT_COMPILE 0
|
|
|
|
|
|
2011-09-07 19:58:19 +00:00
|
|
|
|
struct _GtkPlacesSidebar {
|
2011-09-06 22:53:30 +00:00
|
|
|
|
GtkScrolledWindow parent;
|
|
|
|
|
GtkTreeView *tree_view;
|
|
|
|
|
GtkCellRenderer *eject_icon_cell_renderer;
|
|
|
|
|
char *uri;
|
|
|
|
|
GtkListStore *store;
|
2011-10-03 14:44:46 +00:00
|
|
|
|
GtkBookmarksManager *bookmarks_manager;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
GVolumeMonitor *volume_monitor;
|
|
|
|
|
|
|
|
|
|
gboolean devices_header_added;
|
|
|
|
|
gboolean bookmarks_header_added;
|
|
|
|
|
|
|
|
|
|
/* DnD */
|
|
|
|
|
GList *drag_list;
|
|
|
|
|
gboolean drag_data_received;
|
|
|
|
|
int drag_data_info;
|
|
|
|
|
gboolean drop_occured;
|
|
|
|
|
|
|
|
|
|
GtkWidget *popup_menu;
|
|
|
|
|
GtkWidget *popup_menu_open_in_new_tab_item;
|
|
|
|
|
GtkWidget *popup_menu_add_shortcut_item;
|
|
|
|
|
GtkWidget *popup_menu_remove_item;
|
|
|
|
|
GtkWidget *popup_menu_rename_item;
|
|
|
|
|
GtkWidget *popup_menu_separator_item;
|
|
|
|
|
GtkWidget *popup_menu_mount_item;
|
|
|
|
|
GtkWidget *popup_menu_unmount_item;
|
|
|
|
|
GtkWidget *popup_menu_eject_item;
|
|
|
|
|
GtkWidget *popup_menu_rescan_item;
|
|
|
|
|
GtkWidget *popup_menu_empty_trash_item;
|
|
|
|
|
GtkWidget *popup_menu_start_item;
|
|
|
|
|
GtkWidget *popup_menu_stop_item;
|
2012-09-07 15:04:42 +00:00
|
|
|
|
GtkWidget *popup_menu_properties_separator_item;
|
|
|
|
|
GtkWidget *popup_menu_properties_item;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
/* volume mounting - delayed open process */
|
|
|
|
|
gboolean mounting;
|
2011-09-28 15:22:05 +00:00
|
|
|
|
GtkPlacesOpenMode go_to_after_mount_open_mode;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
GDBusProxy *hostnamed_proxy;
|
|
|
|
|
char *hostname;
|
2011-10-04 14:22:11 +00:00
|
|
|
|
|
|
|
|
|
guint multiple_tabs_supported : 1;
|
|
|
|
|
guint multiple_windows_supported : 1;
|
2011-10-04 14:47:41 +00:00
|
|
|
|
guint show_desktop : 1;
|
2012-09-11 19:33:47 +00:00
|
|
|
|
guint show_properties : 1;
|
|
|
|
|
guint show_trash : 1;
|
2012-09-11 20:44:29 +00:00
|
|
|
|
guint trash_is_full : 1;
|
2012-11-21 02:04:20 +00:00
|
|
|
|
guint show_cwd : 1;
|
2012-12-04 18:57:48 +00:00
|
|
|
|
guint accept_uri_drops : 1;
|
2011-09-07 19:58:19 +00:00
|
|
|
|
};
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2011-09-07 19:58:19 +00:00
|
|
|
|
struct _GtkPlacesSidebarClass {
|
2011-09-06 22:53:30 +00:00
|
|
|
|
GtkScrolledWindowClass parent;
|
2011-09-28 15:44:40 +00:00
|
|
|
|
|
2012-09-11 20:44:29 +00:00
|
|
|
|
void (* location_selected) (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GFile *location,
|
|
|
|
|
GtkPlacesOpenMode open_mode);
|
2012-10-22 23:21:17 +00:00
|
|
|
|
void (* show_file_properties) (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GFile *file);
|
2012-09-11 20:44:29 +00:00
|
|
|
|
void (* empty_trash_requested) (GtkPlacesSidebar *sidebar);
|
|
|
|
|
void (* show_error_message) (GtkPlacesSidebar *sidebar,
|
|
|
|
|
const char *primary,
|
|
|
|
|
const char *secondary);
|
2012-12-03 23:09:57 +00:00
|
|
|
|
void (* drag_action_requested) (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GdkDragContext *context,
|
|
|
|
|
const char *uri,
|
|
|
|
|
GList *uri_list,
|
|
|
|
|
int *action);
|
2012-12-04 00:15:41 +00:00
|
|
|
|
GdkDragAction (* drag_action_ask) (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GdkDragAction actions);
|
2012-12-04 18:44:46 +00:00
|
|
|
|
void (* drag_perform_drop) (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GList *uris,
|
|
|
|
|
const char *drop_uri,
|
|
|
|
|
GdkDragAction action);
|
2011-09-07 19:58:19 +00:00
|
|
|
|
};
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
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,
|
2012-09-07 15:04:42 +00:00
|
|
|
|
PLACES_SIDEBAR_COLUMN_GICON,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
PLACES_SIDEBAR_COLUMN_INDEX,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_EJECT,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_NO_EJECT,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_BOOKMARK,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_TOOLTIP,
|
2012-09-07 15:04:42 +00:00
|
|
|
|
PLACES_SIDEBAR_COLUMN_EJECT_GICON,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
PLACES_SIDEBAR_COLUMN_SECTION_TYPE,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_HEADING_TEXT,
|
|
|
|
|
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_COUNT
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
|
PLACES_BUILT_IN,
|
2012-09-07 15:04:42 +00:00
|
|
|
|
PLACES_XDG_DIR,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
PLACES_MOUNTED_VOLUME,
|
|
|
|
|
PLACES_BOOKMARK,
|
|
|
|
|
PLACES_HEADING,
|
|
|
|
|
} PlaceType;
|
|
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
|
SECTION_DEVICES,
|
|
|
|
|
SECTION_BOOKMARKS,
|
|
|
|
|
SECTION_COMPUTER,
|
|
|
|
|
SECTION_NETWORK,
|
|
|
|
|
} SectionType;
|
|
|
|
|
|
2011-09-28 15:44:40 +00:00
|
|
|
|
enum {
|
|
|
|
|
LOCATION_SELECTED,
|
2012-10-22 23:21:17 +00:00
|
|
|
|
SHOW_FILE_PROPERTIES,
|
2012-09-11 20:44:29 +00:00
|
|
|
|
EMPTY_TRASH_REQUESTED,
|
2011-10-04 21:47:31 +00:00
|
|
|
|
SHOW_ERROR_MESSAGE,
|
2012-12-03 23:09:57 +00:00
|
|
|
|
DRAG_ACTION_REQUESTED,
|
2012-12-04 00:15:41 +00:00
|
|
|
|
DRAG_ACTION_ASK,
|
2012-12-04 18:44:46 +00:00
|
|
|
|
DRAG_PERFORM_DROP,
|
2011-09-28 15:44:40 +00:00
|
|
|
|
LAST_SIGNAL,
|
|
|
|
|
};
|
|
|
|
|
|
2011-10-04 13:14:33 +00:00
|
|
|
|
/* Names for themed icons */
|
2012-09-11 21:05:29 +00:00
|
|
|
|
#define ICON_NAME_HOME "user-home-symbolic"
|
2011-10-04 13:14:33 +00:00
|
|
|
|
#define ICON_NAME_DESKTOP "user-desktop"
|
2012-09-11 21:05:29 +00:00
|
|
|
|
#define ICON_NAME_FILESYSTEM "drive-harddisk-symbolic"
|
2011-10-04 13:14:33 +00:00
|
|
|
|
#define ICON_NAME_EJECT "media-eject-symbolic"
|
2012-09-11 21:05:29 +00:00
|
|
|
|
#define ICON_NAME_NETWORK "network-workgroup-symbolic"
|
|
|
|
|
#define ICON_NAME_TRASH "user-trash-symbolic"
|
|
|
|
|
#define ICON_NAME_TRASH_FULL "user-trash-full-symbolic"
|
2011-10-04 13:14:33 +00:00
|
|
|
|
|
2011-10-04 22:40:08 +00:00
|
|
|
|
#define ICON_NAME_FOLDER_DESKTOP "user-desktop"
|
2012-09-11 21:05:29 +00:00
|
|
|
|
#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"
|
2011-10-04 22:40:08 +00:00
|
|
|
|
|
2012-11-21 18:08:23 +00:00
|
|
|
|
/* Settings keys */
|
|
|
|
|
#define SETTINGS_KEY_STARTUP_MODE "startup-mode"
|
|
|
|
|
|
2011-10-06 14:20:32 +00:00
|
|
|
|
static guint places_sidebar_signals [LAST_SIGNAL] = { 0 };
|
2011-09-28 15:44:40 +00:00
|
|
|
|
|
2011-09-06 23:11:19 +00:00
|
|
|
|
static void open_selected_bookmark (GtkPlacesSidebar *sidebar,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter,
|
2011-09-28 15:22:05 +00:00
|
|
|
|
GtkPlacesOpenMode open_mode);
|
2011-09-06 23:11:19 +00:00
|
|
|
|
static void gtk_places_sidebar_style_set (GtkWidget *widget,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
GtkStyle *previous_style);
|
2011-09-06 23:11:19 +00:00
|
|
|
|
static gboolean eject_or_unmount_bookmark (GtkPlacesSidebar *sidebar,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
GtkTreePath *path);
|
2011-09-06 23:11:19 +00:00
|
|
|
|
static gboolean eject_or_unmount_selection (GtkPlacesSidebar *sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
static void check_unmount_and_eject (GMount *mount,
|
|
|
|
|
GVolume *volume,
|
|
|
|
|
GDrive *drive,
|
|
|
|
|
gboolean *show_unmount,
|
|
|
|
|
gboolean *show_eject);
|
|
|
|
|
|
2012-11-21 19:13:01 +00:00
|
|
|
|
static void check_popup_sensitivity (GtkPlacesSidebar *sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
/* Identifiers for target types */
|
|
|
|
|
enum {
|
2012-09-07 15:04:42 +00:00
|
|
|
|
GTK_TREE_MODEL_ROW,
|
|
|
|
|
TEXT_URI_LIST
|
2011-09-06 22:53:30 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Target types for dragging from the shortcuts list */
|
2011-09-28 14:28:47 +00:00
|
|
|
|
static const GtkTargetEntry dnd_source_targets[] = {
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{ "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, GTK_TREE_MODEL_ROW }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Target types for dropping into the shortcuts list */
|
2011-09-28 14:28:47 +00:00
|
|
|
|
static const GtkTargetEntry dnd_drop_targets [] = {
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{ "GTK_TREE_MODEL_ROW", GTK_TARGET_SAME_WIDGET, GTK_TREE_MODEL_ROW },
|
|
|
|
|
{ "text/uri-list", 0, TEXT_URI_LIST }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Drag and drop interface declarations */
|
|
|
|
|
typedef struct {
|
2012-09-07 15:04:42 +00:00
|
|
|
|
GtkListStore parent;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar;
|
|
|
|
|
} ShortcutsModel;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
typedef struct {
|
2012-09-07 15:04:42 +00:00
|
|
|
|
GtkListStoreClass parent_class;
|
|
|
|
|
} ShortcutsModelClass;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
#define SHORTCUTS_MODEL_TYPE (shortcuts_model_get_type ())
|
|
|
|
|
#define SHORTCUTS_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SHORTCUTS_MODEL_TYPE, ShortcutsModel))
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
static GType shortcuts_model_get_type (void);
|
|
|
|
|
static void shortcuts_model_drag_source_iface_init (GtkTreeDragSourceIface *iface);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (ShortcutsModel,
|
|
|
|
|
shortcuts_model,
|
|
|
|
|
GTK_TYPE_LIST_STORE,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_DRAG_SOURCE,
|
2012-09-07 15:04:42 +00:00
|
|
|
|
shortcuts_model_drag_source_iface_init));
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
static GtkListStore *shortcuts_model_new (GtkPlacesSidebar *sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2011-09-06 23:11:19 +00:00
|
|
|
|
G_DEFINE_TYPE (GtkPlacesSidebar, gtk_places_sidebar, GTK_TYPE_SCROLLED_WINDOW);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2011-09-28 15:44:40 +00:00
|
|
|
|
static void
|
|
|
|
|
emit_location_selected (GtkPlacesSidebar *sidebar, GFile *location, GtkPlacesOpenMode open_mode)
|
|
|
|
|
{
|
2011-10-04 14:22:11 +00:00
|
|
|
|
if ((!sidebar->multiple_tabs_supported && open_mode == GTK_PLACES_OPEN_MODE_NEW_TAB)
|
|
|
|
|
|| (!sidebar->multiple_windows_supported && open_mode == GTK_PLACES_OPEN_MODE_NEW_WINDOW))
|
|
|
|
|
open_mode = GTK_PLACES_OPEN_MODE_NORMAL;
|
|
|
|
|
|
2011-09-28 15:44:40 +00:00
|
|
|
|
g_signal_emit (sidebar, places_sidebar_signals[LOCATION_SELECTED], 0,
|
|
|
|
|
location, open_mode);
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-22 23:21:17 +00:00
|
|
|
|
static void
|
|
|
|
|
emit_show_file_properties (GtkPlacesSidebar *sidebar, GFile *file)
|
|
|
|
|
{
|
|
|
|
|
g_signal_emit (sidebar, places_sidebar_signals[SHOW_FILE_PROPERTIES], 0,
|
|
|
|
|
file);
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-11 20:44:29 +00:00
|
|
|
|
static void
|
|
|
|
|
emit_empty_trash_requested (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
|
|
|
|
g_signal_emit (sidebar, places_sidebar_signals[EMPTY_TRASH_REQUESTED], 0);
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-04 21:47:31 +00:00
|
|
|
|
static void
|
|
|
|
|
emit_show_error_message (GtkPlacesSidebar *sidebar, const char *primary, const char *secondary)
|
|
|
|
|
{
|
|
|
|
|
g_signal_emit (sidebar, places_sidebar_signals[SHOW_ERROR_MESSAGE], 0,
|
|
|
|
|
primary, secondary);
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-03 23:09:57 +00:00
|
|
|
|
static void
|
|
|
|
|
emit_drag_action_requested (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GdkDragContext *context,
|
|
|
|
|
const char *uri,
|
|
|
|
|
GList *uri_list,
|
|
|
|
|
int *action)
|
|
|
|
|
{
|
|
|
|
|
g_signal_emit (sidebar, places_sidebar_signals[DRAG_ACTION_REQUESTED], 0,
|
|
|
|
|
context,
|
|
|
|
|
uri,
|
|
|
|
|
uri_list,
|
|
|
|
|
action);
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-04 00:15:41 +00:00
|
|
|
|
static GdkDragAction
|
|
|
|
|
emit_drag_action_ask (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GdkDragAction actions)
|
|
|
|
|
{
|
|
|
|
|
GdkDragAction ret_action;
|
|
|
|
|
|
|
|
|
|
ret_action = 0;
|
|
|
|
|
|
|
|
|
|
g_signal_emit (sidebar, places_sidebar_signals[DRAG_ACTION_ASK], 0,
|
|
|
|
|
actions,
|
|
|
|
|
&ret_action);
|
|
|
|
|
return ret_action;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-04 18:44:46 +00:00
|
|
|
|
static void
|
|
|
|
|
emit_drag_perform_drop (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GList *uris,
|
|
|
|
|
const char *drop_uri,
|
|
|
|
|
GdkDragAction action)
|
|
|
|
|
{
|
|
|
|
|
g_signal_emit (sidebar, places_sidebar_signals[DRAG_PERFORM_DROP], 0,
|
|
|
|
|
uris,
|
|
|
|
|
drop_uri,
|
|
|
|
|
action);
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-04 11:02:09 +00:00
|
|
|
|
static gint
|
|
|
|
|
get_icon_size (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
|
|
|
|
GtkSettings *settings;
|
|
|
|
|
gint width, height;
|
|
|
|
|
|
|
|
|
|
settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (sidebar)));
|
|
|
|
|
|
|
|
|
|
if (gtk_icon_size_lookup_for_settings (settings, GTK_ICON_SIZE_MENU, &width, &height))
|
|
|
|
|
return MAX (width, height);
|
|
|
|
|
else
|
|
|
|
|
return 16;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-04 11:05:41 +00:00
|
|
|
|
#if 0
|
|
|
|
|
/* FIXME: remove this? Let's allow the user to bookmark whatever he damn well pleases */
|
2011-09-06 22:53:30 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
is_built_in_bookmark (NautilusFile *file)
|
|
|
|
|
{
|
|
|
|
|
gboolean built_in;
|
|
|
|
|
gint idx;
|
|
|
|
|
|
|
|
|
|
if (nautilus_file_is_home (file)) {
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
if (nautilus_file_is_desktop_directory (file) &&
|
|
|
|
|
!g_settings_get_boolean (gnome_background_preferences, NAUTILUS_PREFERENCES_SHOW_DESKTOP)) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
built_in = FALSE;
|
|
|
|
|
|
|
|
|
|
for (idx = 0; idx < G_USER_N_DIRECTORIES; idx++) {
|
|
|
|
|
/* PUBLIC_SHARE and TEMPLATES are not in our built-in list */
|
|
|
|
|
if (nautilus_file_is_user_special_directory (file, idx)) {
|
|
|
|
|
if (idx != G_USER_DIRECTORY_PUBLIC_SHARE && idx != G_USER_DIRECTORY_TEMPLATES) {
|
|
|
|
|
built_in = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return built_in;
|
|
|
|
|
}
|
2011-10-04 11:05:41 +00:00
|
|
|
|
#endif
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
static GtkTreeIter
|
2011-09-06 23:11:19 +00:00
|
|
|
|
add_heading (GtkPlacesSidebar *sidebar,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
SectionType section_type,
|
|
|
|
|
const gchar *title)
|
|
|
|
|
{
|
2012-09-07 15:04:42 +00:00
|
|
|
|
GtkTreeIter iter;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
gtk_list_store_append (sidebar->store, &iter);
|
|
|
|
|
gtk_list_store_set (sidebar->store, &iter,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_ROW_TYPE, PLACES_HEADING,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
PLACES_SIDEBAR_COLUMN_SECTION_TYPE, section_type,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
PLACES_SIDEBAR_COLUMN_HEADING_TEXT, title,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_EJECT, FALSE,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_NO_EJECT, TRUE,
|
|
|
|
|
-1);
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
return iter;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-09-06 23:11:19 +00:00
|
|
|
|
check_heading_for_section (GtkPlacesSidebar *sidebar,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
static void
|
2011-09-06 23:11:19 +00:00
|
|
|
|
add_place (GtkPlacesSidebar *sidebar,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
PlaceType place_type,
|
|
|
|
|
SectionType section_type,
|
|
|
|
|
const char *name,
|
|
|
|
|
GIcon *icon,
|
|
|
|
|
const char *uri,
|
|
|
|
|
GDrive *drive,
|
|
|
|
|
GVolume *volume,
|
|
|
|
|
GMount *mount,
|
|
|
|
|
const int index,
|
|
|
|
|
const char *tooltip)
|
|
|
|
|
{
|
2012-09-07 15:04:42 +00:00
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
GIcon *eject;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (show_eject_button) {
|
2012-09-07 15:04:42 +00:00
|
|
|
|
eject = g_themed_icon_new_with_default_fallbacks ("media-eject-symbolic");
|
2011-09-06 22:53:30 +00:00
|
|
|
|
} else {
|
|
|
|
|
eject = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_list_store_append (sidebar->store, &iter);
|
|
|
|
|
gtk_list_store_set (sidebar->store, &iter,
|
2012-09-07 15:04:42 +00:00
|
|
|
|
PLACES_SIDEBAR_COLUMN_GICON, icon,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
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,
|
2012-09-07 15:04:42 +00:00
|
|
|
|
PLACES_SIDEBAR_COLUMN_EJECT_GICON, eject,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
PLACES_SIDEBAR_COLUMN_SECTION_TYPE, section_type,
|
|
|
|
|
-1);
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
if (eject != NULL) {
|
|
|
|
|
g_object_unref (eject);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
typedef struct {
|
|
|
|
|
const gchar *location;
|
|
|
|
|
const gchar *last_uri;
|
|
|
|
|
GtkPlacesSidebar *sidebar;
|
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
} RestoreLocationData;
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
restore_selection_foreach (GtkTreeModel *model,
|
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gpointer user_data)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2012-09-07 15:04:42 +00:00
|
|
|
|
RestoreLocationData *data = user_data;
|
|
|
|
|
gchar *uri;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
gtk_tree_model_get (model, iter,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_URI, &uri,
|
|
|
|
|
-1);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
if (g_strcmp0 (uri, data->last_uri) == 0 ||
|
|
|
|
|
g_strcmp0 (uri, data->location) == 0) {
|
|
|
|
|
data->path = gtk_tree_path_copy (path);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
|
|
|
|
g_free (uri);
|
|
|
|
|
|
|
|
|
|
return (data->path != NULL);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
static void
|
|
|
|
|
sidebar_update_restore_selection (GtkPlacesSidebar *sidebar,
|
|
|
|
|
const gchar *location,
|
|
|
|
|
const gchar *last_uri)
|
2011-10-03 16:08:25 +00:00
|
|
|
|
{
|
2012-09-07 15:04:42 +00:00
|
|
|
|
RestoreLocationData data;
|
|
|
|
|
GtkTreeSelection *selection;
|
2011-10-03 16:08:25 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
data.location = location;
|
|
|
|
|
data.last_uri = last_uri;
|
|
|
|
|
data.sidebar = sidebar;
|
|
|
|
|
data.path = NULL;
|
2011-10-03 16:08:25 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
gtk_tree_model_foreach (GTK_TREE_MODEL (sidebar->store),
|
|
|
|
|
restore_selection_foreach, &data);
|
|
|
|
|
|
|
|
|
|
if (data.path != NULL) {
|
|
|
|
|
selection = gtk_tree_view_get_selection (sidebar->tree_view);
|
|
|
|
|
gtk_tree_selection_select_path (selection, data.path);
|
|
|
|
|
gtk_tree_path_free (data.path);
|
|
|
|
|
}
|
2011-10-03 16:08:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-10-04 22:40:08 +00:00
|
|
|
|
static GIcon *
|
2012-09-07 15:04:42 +00:00
|
|
|
|
special_directory_get_gicon (GUserDirectory directory)
|
2011-10-04 22:40:08 +00:00
|
|
|
|
{
|
2012-09-07 15:04:42 +00:00
|
|
|
|
#define ICON_CASE(x) \
|
|
|
|
|
case G_USER_DIRECTORY_ ## x: \
|
|
|
|
|
return g_themed_icon_new (ICON_NAME_FOLDER_ ## x);
|
2011-10-04 22:40:08 +00:00
|
|
|
|
|
|
|
|
|
switch (directory) {
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
2011-10-04 22:40:08 +00:00
|
|
|
|
ICON_CASE (DOCUMENTS);
|
|
|
|
|
ICON_CASE (DOWNLOAD);
|
|
|
|
|
ICON_CASE (MUSIC);
|
|
|
|
|
ICON_CASE (PICTURES);
|
|
|
|
|
ICON_CASE (PUBLIC_SHARE);
|
|
|
|
|
ICON_CASE (TEMPLATES);
|
|
|
|
|
ICON_CASE (VIDEOS);
|
|
|
|
|
|
|
|
|
|
default:
|
2012-09-07 15:04:42 +00:00
|
|
|
|
return g_themed_icon_new ("folder-symbolic");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#undef ICON_CASE
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
recent_is_supported (void)
|
|
|
|
|
{
|
|
|
|
|
const char * const *supported;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
supported = g_vfs_get_supported_uri_schemes (g_vfs_get_default ());
|
|
|
|
|
if (!supported) {
|
|
|
|
|
return FALSE;
|
2011-10-04 22:40:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
for (i = 0; supported[i] != NULL; i++) {
|
|
|
|
|
if (strcmp ("recent", supported[i]) == 0) {
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return FALSE;
|
2011-10-04 22:40:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
static void
|
|
|
|
|
add_special_dirs (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
|
|
|
|
GList *dirs;
|
|
|
|
|
int index;
|
|
|
|
|
|
|
|
|
|
dirs = NULL;
|
|
|
|
|
for (index = 0; index < G_USER_N_DIRECTORIES; index++) {
|
|
|
|
|
const char *path;
|
|
|
|
|
GFile *root;
|
|
|
|
|
GIcon *icon;
|
|
|
|
|
char *name;
|
|
|
|
|
char *mount_uri;
|
|
|
|
|
char *tooltip;
|
|
|
|
|
|
|
|
|
|
if (index == G_USER_DIRECTORY_DESKTOP ||
|
|
|
|
|
index == G_USER_DIRECTORY_TEMPLATES ||
|
|
|
|
|
index == G_USER_DIRECTORY_PUBLIC_SHARE) {
|
|
|
|
|
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 = 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, (char *)path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_list_free (dirs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
|
get_home_directory_uri (void)
|
|
|
|
|
{
|
|
|
|
|
const char *home;
|
|
|
|
|
|
|
|
|
|
home = g_get_home_dir ();
|
|
|
|
|
if (!home)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
return g_strconcat ("file://", home, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
|
get_desktop_directory_uri (void)
|
2011-10-05 13:46:43 +00:00
|
|
|
|
{
|
|
|
|
|
const char *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 ())) {
|
|
|
|
|
return NULL;
|
|
|
|
|
} else {
|
2012-09-07 15:04:42 +00:00
|
|
|
|
return g_strconcat ("file://", name, NULL);
|
2011-10-05 13:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
static void
|
2011-09-06 23:11:19 +00:00
|
|
|
|
update_places (GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
GtkTreeIter last_iter;
|
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
GVolumeMonitor *volume_monitor;
|
|
|
|
|
GList *mounts, *l, *ll;
|
|
|
|
|
GMount *mount;
|
|
|
|
|
GList *drives;
|
|
|
|
|
GDrive *drive;
|
|
|
|
|
GList *volumes;
|
|
|
|
|
GVolume *volume;
|
2011-10-03 15:27:41 +00:00
|
|
|
|
GSList *bookmarks, *sl;
|
|
|
|
|
int index;
|
2012-11-24 17:18:23 +00:00
|
|
|
|
char *original_uri, *mount_uri, *name, *last_uri, *identifier;
|
2012-11-21 02:04:20 +00:00
|
|
|
|
char *home_uri;
|
2011-10-03 15:27:41 +00:00
|
|
|
|
char *bookmark_name;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
GIcon *icon;
|
|
|
|
|
GFile *root;
|
|
|
|
|
char *tooltip;
|
2012-09-07 15:04:42 +00:00
|
|
|
|
GList *network_mounts, *network_volumes;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
model = NULL;
|
|
|
|
|
last_uri = NULL;
|
|
|
|
|
|
|
|
|
|
selection = gtk_tree_view_get_selection (sidebar->tree_view);
|
|
|
|
|
if (gtk_tree_selection_get_selected (selection, &model, &last_iter)) {
|
|
|
|
|
gtk_tree_model_get (model,
|
|
|
|
|
&last_iter,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_URI, &last_uri, -1);
|
|
|
|
|
}
|
|
|
|
|
gtk_list_store_clear (sidebar->store);
|
|
|
|
|
|
|
|
|
|
sidebar->devices_header_added = FALSE;
|
|
|
|
|
sidebar->bookmarks_header_added = FALSE;
|
|
|
|
|
|
2012-11-24 17:18:23 +00:00
|
|
|
|
original_uri = g_strdup (sidebar->uri);
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
|
|
|
|
network_mounts = network_volumes = NULL;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
volume_monitor = sidebar->volume_monitor;
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
/* add built in bookmarks */
|
|
|
|
|
|
|
|
|
|
add_heading (sidebar, SECTION_COMPUTER,
|
|
|
|
|
_("Places"));
|
|
|
|
|
|
|
|
|
|
if (recent_is_supported ()) {
|
|
|
|
|
mount_uri = "recent:///"; /* No need to strdup */
|
|
|
|
|
icon = g_themed_icon_new ("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);
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-21 02:04:20 +00:00
|
|
|
|
/* compute the $HOME URI here; we'll use it when we generate the $CWD item as well as the $HOME item */
|
|
|
|
|
|
|
|
|
|
home_uri = get_home_directory_uri ();
|
|
|
|
|
|
|
|
|
|
/* cwd */
|
|
|
|
|
if (sidebar->show_cwd) {
|
|
|
|
|
char *cwd;
|
|
|
|
|
GFile *home_file;
|
|
|
|
|
|
|
|
|
|
cwd = g_get_current_dir ();
|
|
|
|
|
root = g_file_new_for_path (cwd);
|
|
|
|
|
g_free (cwd);
|
|
|
|
|
|
|
|
|
|
home_file = g_file_new_for_uri (home_uri);
|
|
|
|
|
|
|
|
|
|
if (!g_file_equal (home_file, root)) {
|
|
|
|
|
GFileInfo *info;
|
|
|
|
|
|
|
|
|
|
info = g_file_query_info (root,
|
|
|
|
|
"standard::display-name,standard::icon",
|
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL); /* NULL-GError */
|
|
|
|
|
|
|
|
|
|
/* FIXME: we are getting file info synchronously. We may want to do it async at some point. */
|
|
|
|
|
if (info) {
|
|
|
|
|
bookmark_name = g_strdup (g_file_info_get_display_name (info));
|
|
|
|
|
icon = g_file_info_get_icon (info); /* FIXME: use symbolic icon */
|
|
|
|
|
mount_uri = g_file_get_uri (root);
|
|
|
|
|
tooltip = g_file_get_parse_name (root);
|
|
|
|
|
|
|
|
|
|
add_place (sidebar, PLACES_BUILT_IN,
|
|
|
|
|
SECTION_COMPUTER,
|
|
|
|
|
bookmark_name, icon, mount_uri,
|
|
|
|
|
NULL, NULL, NULL, 0,
|
|
|
|
|
tooltip);
|
|
|
|
|
|
|
|
|
|
g_free (mount_uri);
|
|
|
|
|
g_free (tooltip);
|
|
|
|
|
g_free (bookmark_name);
|
|
|
|
|
|
|
|
|
|
g_object_unref (info);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_unref (home_file);
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
/* home folder */
|
|
|
|
|
icon = g_themed_icon_new (ICON_NAME_HOME);
|
|
|
|
|
add_place (sidebar, PLACES_BUILT_IN,
|
|
|
|
|
SECTION_COMPUTER,
|
|
|
|
|
_("Home"), icon,
|
2012-11-21 02:04:20 +00:00
|
|
|
|
home_uri, NULL, NULL, NULL, 0,
|
2012-09-07 15:04:42 +00:00
|
|
|
|
_("Open your personal folder"));
|
|
|
|
|
g_object_unref (icon);
|
2012-11-21 02:04:20 +00:00
|
|
|
|
g_free (home_uri);
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
|
|
|
|
if (sidebar->show_desktop) {
|
|
|
|
|
/* desktop */
|
|
|
|
|
mount_uri = get_desktop_directory_uri ();
|
|
|
|
|
icon = g_themed_icon_new (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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* XDG directories */
|
|
|
|
|
add_special_dirs (sidebar);
|
|
|
|
|
|
2012-09-11 19:33:47 +00:00
|
|
|
|
if (sidebar->show_trash) {
|
|
|
|
|
mount_uri = "trash:///"; /* No need to strdup */
|
2012-09-11 20:44:29 +00:00
|
|
|
|
icon = g_themed_icon_new (sidebar->trash_is_full ? ICON_NAME_TRASH_FULL : ICON_NAME_TRASH);
|
2012-09-11 19:33:47 +00:00
|
|
|
|
add_place (sidebar, PLACES_BUILT_IN,
|
|
|
|
|
SECTION_COMPUTER,
|
|
|
|
|
_("Trash"), icon, mount_uri,
|
|
|
|
|
NULL, NULL, NULL, 0,
|
|
|
|
|
_("Open the trash"));
|
|
|
|
|
g_object_unref (icon);
|
|
|
|
|
}
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
|
|
|
|
/* go through all connected drives */
|
2011-09-06 22:53:30 +00:00
|
|
|
|
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;
|
2012-09-07 15:04:42 +00:00
|
|
|
|
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);
|
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
mount = g_volume_get_mount (volume);
|
|
|
|
|
if (mount != NULL) {
|
|
|
|
|
/* Show mounted volume in the sidebar */
|
2012-09-07 15:04:42 +00:00
|
|
|
|
icon = g_mount_get_symbolic_icon (mount);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
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);
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
add_place (sidebar, PLACES_MOUNTED_VOLUME,
|
|
|
|
|
SECTION_DEVICES,
|
|
|
|
|
name, icon, mount_uri,
|
|
|
|
|
drive, volume, mount, 0, tooltip);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
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.
|
|
|
|
|
*/
|
2012-09-07 15:04:42 +00:00
|
|
|
|
icon = g_volume_get_symbolic_icon (volume);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
name = g_volume_get_name (volume);
|
|
|
|
|
tooltip = g_strdup_printf (_("Mount and open %s"), name);
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
add_place (sidebar, PLACES_MOUNTED_VOLUME,
|
|
|
|
|
SECTION_DEVICES,
|
|
|
|
|
name, icon, NULL,
|
|
|
|
|
drive, volume, NULL, 0, tooltip);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
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.
|
|
|
|
|
*/
|
2012-09-07 15:04:42 +00:00
|
|
|
|
icon = g_drive_get_symbolic_icon (drive);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
name = g_drive_get_name (drive);
|
|
|
|
|
tooltip = g_strdup_printf (_("Mount and open %s"), name);
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
add_place (sidebar, PLACES_BUILT_IN,
|
|
|
|
|
SECTION_DEVICES,
|
|
|
|
|
name, icon, NULL,
|
|
|
|
|
drive, NULL, NULL, 0, tooltip);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
mount = g_volume_get_mount (volume);
|
|
|
|
|
if (mount != NULL) {
|
2012-09-07 15:04:42 +00:00
|
|
|
|
icon = g_mount_get_symbolic_icon (mount);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
root = g_mount_get_default_location (mount);
|
|
|
|
|
mount_uri = g_file_get_uri (root);
|
|
|
|
|
tooltip = g_file_get_parse_name (root);
|
|
|
|
|
g_object_unref (root);
|
|
|
|
|
name = g_mount_get_name (mount);
|
2012-09-07 15:04:42 +00:00
|
|
|
|
add_place (sidebar, PLACES_MOUNTED_VOLUME,
|
|
|
|
|
SECTION_DEVICES,
|
|
|
|
|
name, icon, mount_uri,
|
|
|
|
|
NULL, volume, mount, 0, tooltip);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
g_object_unref (mount);
|
|
|
|
|
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 */
|
2012-09-07 15:04:42 +00:00
|
|
|
|
icon = g_volume_get_symbolic_icon (volume);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
name = g_volume_get_name (volume);
|
2012-09-07 15:04:42 +00:00
|
|
|
|
add_place (sidebar, PLACES_MOUNTED_VOLUME,
|
|
|
|
|
SECTION_DEVICES,
|
|
|
|
|
name, icon, NULL,
|
|
|
|
|
NULL, volume, NULL, 0, name);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
g_object_unref (icon);
|
|
|
|
|
g_free (name);
|
|
|
|
|
}
|
|
|
|
|
g_object_unref (volume);
|
|
|
|
|
}
|
|
|
|
|
g_list_free (volumes);
|
2011-09-06 23:11:19 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
/* file system root */
|
|
|
|
|
|
|
|
|
|
mount_uri = "file:///"; /* No need to strdup */
|
|
|
|
|
icon = g_themed_icon_new (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);
|
2012-10-19 17:12:19 +00:00
|
|
|
|
g_object_unref (root);
|
2012-09-07 15:04:42 +00:00
|
|
|
|
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);
|
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
/* add bookmarks */
|
|
|
|
|
|
2011-10-03 15:27:41 +00:00
|
|
|
|
bookmarks = _gtk_bookmarks_manager_list_bookmarks (sidebar->bookmarks_manager);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2011-10-06 14:20:32 +00:00
|
|
|
|
for (sl = bookmarks, index = 0; sl; sl = sl->next, index++) {
|
2012-09-07 19:36:05 +00:00
|
|
|
|
GFileInfo *info;
|
|
|
|
|
|
2011-10-03 15:27:41 +00:00
|
|
|
|
root = sl->data;
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
/* FIXME: remove this? If we *do* show bookmarks for nonexistent files, the user will eventually clean them up */
|
2011-09-06 22:53:30 +00:00
|
|
|
|
if (nautilus_bookmark_uri_known_not_to_exist (bookmark)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2011-10-03 15:27:41 +00:00
|
|
|
|
#endif
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2011-10-03 15:27:41 +00:00
|
|
|
|
#if 0
|
|
|
|
|
/* FIXME: remove this? Let's allow the user to bookmark whatever he damn well pleases */
|
|
|
|
|
NautilusFile *file;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
file = nautilus_file_get (root);
|
|
|
|
|
|
|
|
|
|
if (is_built_in_bookmark (file)) {
|
|
|
|
|
g_object_unref (root);
|
|
|
|
|
nautilus_file_unref (file);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
nautilus_file_unref (file);
|
2011-10-03 15:27:41 +00:00
|
|
|
|
#endif
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-09-07 19:36:05 +00:00
|
|
|
|
/* 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::icon",
|
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL); /* NULL-GError */
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-09-07 19:36:05 +00:00
|
|
|
|
if (info) {
|
|
|
|
|
bookmark_name = _gtk_bookmarks_manager_get_bookmark_label (sidebar->bookmarks_manager, root);
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
2012-09-07 19:36:05 +00:00
|
|
|
|
if (bookmark_name == NULL)
|
|
|
|
|
bookmark_name = g_strdup (g_file_info_get_display_name (info));
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-10-19 17:26:40 +00:00
|
|
|
|
/* FIXME: in commit 0ed400b9c1692e42498bff3c10780073ec137f63, nautilus added the ability
|
|
|
|
|
* to get a symbolic icon for bookmarks. We don't have that machinery. Should we
|
|
|
|
|
* just copy that code?
|
|
|
|
|
*/
|
2012-09-07 19:36:05 +00:00
|
|
|
|
icon = g_file_info_get_icon (info);
|
|
|
|
|
|
|
|
|
|
mount_uri = g_file_get_uri (root);
|
|
|
|
|
tooltip = g_file_get_parse_name (root);
|
|
|
|
|
|
|
|
|
|
add_place (sidebar, PLACES_BOOKMARK,
|
|
|
|
|
SECTION_BOOKMARKS,
|
|
|
|
|
bookmark_name, icon, mount_uri,
|
|
|
|
|
NULL, NULL, NULL, index,
|
|
|
|
|
tooltip);
|
|
|
|
|
|
|
|
|
|
g_free (mount_uri);
|
|
|
|
|
g_free (tooltip);
|
|
|
|
|
g_free (bookmark_name);
|
|
|
|
|
|
|
|
|
|
g_object_unref (info);
|
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-10-05 14:53:09 +00:00
|
|
|
|
g_slist_foreach (bookmarks, (GFunc) g_object_unref, NULL);
|
|
|
|
|
g_slist_free (bookmarks);
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
/* network */
|
|
|
|
|
add_heading (sidebar, SECTION_NETWORK,
|
|
|
|
|
_("Network"));
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
mount_uri = "network:///"; /* No need to strdup */
|
|
|
|
|
icon = g_themed_icon_new (ICON_NAME_NETWORK);
|
|
|
|
|
add_place (sidebar, PLACES_BUILT_IN,
|
|
|
|
|
SECTION_NETWORK,
|
|
|
|
|
_("Browse Network"), icon,
|
|
|
|
|
mount_uri, NULL, NULL, NULL, 0,
|
|
|
|
|
_("Browse the contents of the network"));
|
|
|
|
|
g_object_unref (icon);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
network_volumes = g_list_reverse (network_volumes);
|
|
|
|
|
for (l = network_volumes; l != NULL; l = l->next) {
|
|
|
|
|
volume = l->data;
|
|
|
|
|
mount = g_volume_get_mount (volume);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
if (mount != NULL) {
|
|
|
|
|
network_mounts = g_list_prepend (network_mounts, mount);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
continue;
|
2012-09-07 15:04:42 +00:00
|
|
|
|
} else {
|
|
|
|
|
icon = g_volume_get_symbolic_icon (volume);
|
|
|
|
|
name = g_volume_get_name (volume);
|
|
|
|
|
tooltip = g_strdup_printf (_("Mount and open %s"), name);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
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);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
g_list_free_full (network_volumes, g_object_unref);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
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);
|
2012-09-07 15:04:42 +00:00
|
|
|
|
icon = g_mount_get_symbolic_icon (mount);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
mount_uri = g_file_get_uri (root);
|
|
|
|
|
name = g_mount_get_name (mount);
|
|
|
|
|
tooltip = g_file_get_parse_name (root);
|
2012-09-07 15:04:42 +00:00
|
|
|
|
add_place (sidebar, PLACES_MOUNTED_VOLUME,
|
|
|
|
|
SECTION_NETWORK,
|
|
|
|
|
name, icon, mount_uri,
|
|
|
|
|
NULL, NULL, mount, 0, tooltip);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
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_full (network_mounts, g_object_unref);
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
/* restore selection */
|
2012-11-24 17:18:23 +00:00
|
|
|
|
sidebar_update_restore_selection (sidebar, original_uri, last_uri);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-11-24 17:18:23 +00:00
|
|
|
|
g_free (original_uri);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
g_free (last_uri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
mount_added_callback (GVolumeMonitor *volume_monitor,
|
|
|
|
|
GMount *mount,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
update_places (sidebar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
mount_removed_callback (GVolumeMonitor *volume_monitor,
|
|
|
|
|
GMount *mount,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
update_places (sidebar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
mount_changed_callback (GVolumeMonitor *volume_monitor,
|
|
|
|
|
GMount *mount,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
update_places (sidebar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
volume_added_callback (GVolumeMonitor *volume_monitor,
|
|
|
|
|
GVolume *volume,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
update_places (sidebar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
volume_removed_callback (GVolumeMonitor *volume_monitor,
|
|
|
|
|
GVolume *volume,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
update_places (sidebar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
volume_changed_callback (GVolumeMonitor *volume_monitor,
|
|
|
|
|
GVolume *volume,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
update_places (sidebar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
drive_disconnected_callback (GVolumeMonitor *volume_monitor,
|
|
|
|
|
GDrive *drive,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
update_places (sidebar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
drive_connected_callback (GVolumeMonitor *volume_monitor,
|
|
|
|
|
GDrive *drive,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
update_places (sidebar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
drive_changed_callback (GVolumeMonitor *volume_monitor,
|
|
|
|
|
GDrive *drive,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
update_places (sidebar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2011-09-06 23:11:19 +00:00
|
|
|
|
over_eject_button (GtkPlacesSidebar *sidebar,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
gint x,
|
|
|
|
|
gint y,
|
|
|
|
|
GtkTreePath **path)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeViewColumn *column;
|
|
|
|
|
int width, x_offset, hseparator;
|
|
|
|
|
int 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);
|
|
|
|
|
|
2011-10-04 11:02:09 +00:00
|
|
|
|
eject_button_size = get_icon_size (sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
/* This is kinda weird, but we have to do it to workaround gtk+ 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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
if (*path != NULL) {
|
|
|
|
|
gtk_tree_path_free (*path);
|
|
|
|
|
*path = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2011-09-06 23:11:19 +00:00
|
|
|
|
clicked_eject_button (GtkPlacesSidebar *sidebar,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
GtkTreePath **path)
|
|
|
|
|
{
|
|
|
|
|
GdkEvent *event = gtk_get_current_event ();
|
|
|
|
|
GdkEventButton *button_event = (GdkEventButton *) event;
|
|
|
|
|
|
|
|
|
|
if ((event->type == GDK_BUTTON_PRESS || event->type == GDK_BUTTON_RELEASE) &&
|
|
|
|
|
over_eject_button (sidebar, button_event->x, button_event->y, path)) {
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Computes the appropriate row and position for dropping */
|
|
|
|
|
static gboolean
|
2012-09-07 15:04:42 +00:00
|
|
|
|
compute_drop_position (GtkTreeView *tree_view,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
int x,
|
|
|
|
|
int y,
|
|
|
|
|
GtkTreePath **path,
|
|
|
|
|
GtkTreeViewDropPosition *pos,
|
2012-09-07 15:04:42 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
PlaceType place_type;
|
|
|
|
|
SectionType section_type;
|
|
|
|
|
|
|
|
|
|
if (!gtk_tree_view_get_dest_row_at_pos (tree_view,
|
2012-09-07 15:04:42 +00:00
|
|
|
|
x, y,
|
|
|
|
|
path, pos)) {
|
2011-09-06 22:53:30 +00:00
|
|
|
|
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, §ion_type,
|
|
|
|
|
-1);
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
if (section_type != SECTION_BOOKMARKS &&
|
|
|
|
|
place_type == PLACES_HEADING) {
|
2011-09-06 22:53:30 +00:00
|
|
|
|
/* never drop on headings, but special case the bookmarks heading,
|
2012-09-07 15:04:42 +00:00
|
|
|
|
* so we can drop bookmarks in between it and the first item when
|
|
|
|
|
* reordering.
|
2011-09-06 22:53:30 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
gtk_tree_path_free (*path);
|
|
|
|
|
*path = NULL;
|
2011-09-06 23:11:19 +00:00
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (section_type != SECTION_BOOKMARKS &&
|
|
|
|
|
sidebar->drag_data_received &&
|
|
|
|
|
sidebar->drag_data_info == GTK_TREE_MODEL_ROW) {
|
|
|
|
|
/* don't allow dropping bookmarks into non-bookmark areas */
|
|
|
|
|
gtk_tree_path_free (*path);
|
|
|
|
|
*path = NULL;
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
if (sidebar->drag_data_received &&
|
|
|
|
|
sidebar->drag_data_info == GTK_TREE_MODEL_ROW) {
|
|
|
|
|
/* bookmark rows can only be reordered */
|
2011-09-06 22:53:30 +00:00
|
|
|
|
*pos = GTK_TREE_VIEW_DROP_AFTER;
|
|
|
|
|
} else {
|
|
|
|
|
*pos = GTK_TREE_VIEW_DROP_INTO_OR_BEFORE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
get_drag_data (GtkTreeView *tree_view,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GdkDragContext *context,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
unsigned int time)
|
|
|
|
|
{
|
|
|
|
|
GdkAtom target;
|
|
|
|
|
|
2011-09-06 23:11:19 +00:00
|
|
|
|
target = gtk_drag_dest_find_target (GTK_WIDGET (tree_view),
|
|
|
|
|
context,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
if (target == GDK_NONE) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_drag_get_data (GTK_WIDGET (tree_view),
|
|
|
|
|
context, target, time);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-09-06 23:11:19 +00:00
|
|
|
|
free_drag_data (GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
sidebar->drag_data_received = FALSE;
|
|
|
|
|
|
|
|
|
|
if (sidebar->drag_list) {
|
2012-12-03 22:45:25 +00:00
|
|
|
|
g_list_free_full (sidebar->drag_list, g_free);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
sidebar->drag_list = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
drag_motion_callback (GtkTreeView *tree_view,
|
|
|
|
|
GdkDragContext *context,
|
|
|
|
|
int x,
|
|
|
|
|
int y,
|
|
|
|
|
unsigned int time,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
GtkTreeViewDropPosition pos;
|
|
|
|
|
int action;
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
char *uri;
|
|
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
|
|
if (!sidebar->drag_data_received) {
|
|
|
|
|
if (!get_drag_data (tree_view, context, time)) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
path = NULL;
|
|
|
|
|
res = compute_drop_position (tree_view, x, y, &path, &pos, sidebar);
|
|
|
|
|
|
|
|
|
|
if (!res) {
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-03 23:37:11 +00:00
|
|
|
|
if (pos == GTK_TREE_VIEW_DROP_AFTER) {
|
2011-09-06 22:53:30 +00:00
|
|
|
|
if (sidebar->drag_data_received &&
|
|
|
|
|
sidebar->drag_data_info == GTK_TREE_MODEL_ROW) {
|
|
|
|
|
action = GDK_ACTION_MOVE;
|
|
|
|
|
} else {
|
|
|
|
|
action = 0;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2012-12-03 23:37:11 +00:00
|
|
|
|
action = 0;
|
2012-12-04 18:57:48 +00:00
|
|
|
|
if (sidebar->accept_uri_drops) {
|
|
|
|
|
if (sidebar->drag_list != NULL) {
|
|
|
|
|
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_URI, &uri,
|
|
|
|
|
-1);
|
|
|
|
|
emit_drag_action_requested (sidebar, context, uri, sidebar->drag_list, &action);
|
|
|
|
|
g_free (uri);
|
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (action != 0) {
|
|
|
|
|
gtk_tree_view_set_drag_dest_row (tree_view, path, pos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (path != NULL) {
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
g_signal_stop_emission_by_name (tree_view, "drag-motion");
|
|
|
|
|
|
2012-12-03 23:37:11 +00:00
|
|
|
|
gdk_drag_status (context, action, time);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
drag_leave_callback (GtkTreeView *tree_view,
|
|
|
|
|
GdkDragContext *context,
|
|
|
|
|
unsigned int time,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
free_drag_data (sidebar);
|
2012-09-07 15:04:42 +00:00
|
|
|
|
gtk_tree_view_set_drag_dest_row (tree_view, NULL, 0);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
g_signal_stop_emission_by_name (tree_view, "drag-leave");
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-20 19:00:50 +00:00
|
|
|
|
/* Takes an array of URIs and turns it into a list of string URIs */
|
|
|
|
|
static GList *
|
2012-12-04 18:52:44 +00:00
|
|
|
|
build_uri_list (const char **uris)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
GList *result;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
result = NULL;
|
|
|
|
|
for (i = 0; uris[i]; i++) {
|
2012-10-20 19:00:50 +00:00
|
|
|
|
char *uri;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-10-20 19:00:50 +00:00
|
|
|
|
uri = g_strdup (uris[i]);
|
|
|
|
|
result = g_list_prepend (result, uri);
|
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
return g_list_reverse (result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2011-09-06 23:11:19 +00:00
|
|
|
|
get_selected_iter (GtkPlacesSidebar *sidebar,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
GtkTreeIter *iter)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
|
|
|
|
|
selection = gtk_tree_view_get_selection (sidebar->tree_view);
|
|
|
|
|
|
|
|
|
|
return gtk_tree_selection_get_selected (selection, NULL, iter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Reorders the selected bookmark to the specified position */
|
|
|
|
|
static void
|
2011-09-06 23:11:19 +00:00
|
|
|
|
reorder_bookmarks (GtkPlacesSidebar *sidebar,
|
2012-10-20 19:00:50 +00:00
|
|
|
|
int new_position)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeIter iter;
|
2012-09-11 20:17:03 +00:00
|
|
|
|
char *uri;
|
|
|
|
|
GFile *file;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
/* Get the selected path */
|
2012-09-07 15:04:42 +00:00
|
|
|
|
if (!get_selected_iter (sidebar, &iter)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (sidebar->store), &iter,
|
2012-09-11 20:17:03 +00:00
|
|
|
|
PLACES_SIDEBAR_COLUMN_URI, &uri,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
-1);
|
|
|
|
|
|
2012-09-11 20:17:03 +00:00
|
|
|
|
file = g_file_new_for_uri (uri);
|
|
|
|
|
_gtk_bookmarks_manager_reorder_bookmark (sidebar->bookmarks_manager, file, new_position, NULL); /* NULL-GError */
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-09-11 20:17:03 +00:00
|
|
|
|
g_object_unref (file);
|
|
|
|
|
g_free (uri);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
drag_data_received_callback (GtkWidget *widget,
|
|
|
|
|
GdkDragContext *context,
|
|
|
|
|
int x,
|
|
|
|
|
int y,
|
|
|
|
|
GtkSelectionData *selection_data,
|
|
|
|
|
unsigned int info,
|
|
|
|
|
unsigned int time,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeView *tree_view;
|
|
|
|
|
GtkTreePath *tree_path;
|
|
|
|
|
GtkTreeViewDropPosition tree_pos;
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
int position;
|
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
PlaceType place_type;
|
|
|
|
|
SectionType section_type;
|
|
|
|
|
gboolean success;
|
|
|
|
|
|
|
|
|
|
tree_view = GTK_TREE_VIEW (widget);
|
|
|
|
|
|
|
|
|
|
if (!sidebar->drag_data_received) {
|
|
|
|
|
if (gtk_selection_data_get_target (selection_data) != GDK_NONE &&
|
|
|
|
|
info == TEXT_URI_LIST) {
|
2012-10-20 19:00:50 +00:00
|
|
|
|
char **uris;
|
|
|
|
|
|
|
|
|
|
uris = gtk_selection_data_get_uris (selection_data);
|
2012-12-04 18:52:44 +00:00
|
|
|
|
sidebar->drag_list = build_uri_list ((const char **) uris);
|
2012-10-20 19:00:50 +00:00
|
|
|
|
g_strfreev (uris);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
} else {
|
|
|
|
|
sidebar->drag_list = NULL;
|
|
|
|
|
}
|
|
|
|
|
sidebar->drag_data_received = TRUE;
|
|
|
|
|
sidebar->drag_data_info = info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_signal_stop_emission_by_name (widget, "drag-data-received");
|
|
|
|
|
|
|
|
|
|
if (!sidebar->drop_occured) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Compute position */
|
2012-09-07 15:04:42 +00:00
|
|
|
|
success = compute_drop_position (tree_view, x, y, &tree_path, &tree_pos, sidebar);
|
|
|
|
|
if (!success) {
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
success = FALSE;
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
if (tree_pos == GTK_TREE_VIEW_DROP_AFTER) {
|
2011-09-06 22:53:30 +00:00
|
|
|
|
model = gtk_tree_view_get_model (tree_view);
|
|
|
|
|
|
|
|
|
|
if (!gtk_tree_model_get_iter (model, &iter, tree_path)) {
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, &iter,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_SECTION_TYPE, §ion_type,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_ROW_TYPE, &place_type,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_INDEX, &position,
|
|
|
|
|
-1);
|
|
|
|
|
|
|
|
|
|
if (section_type != SECTION_BOOKMARKS) {
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tree_pos == GTK_TREE_VIEW_DROP_AFTER && place_type != PLACES_HEADING) {
|
|
|
|
|
/* heading already has position 0 */
|
|
|
|
|
position++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (info) {
|
|
|
|
|
case GTK_TREE_MODEL_ROW:
|
|
|
|
|
reorder_bookmarks (sidebar, position);
|
|
|
|
|
success = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
GdkDragAction real_action;
|
2012-12-04 18:52:44 +00:00
|
|
|
|
char **uris;
|
|
|
|
|
GList *uri_list;
|
2012-10-20 19:00:50 +00:00
|
|
|
|
char *drop_uri;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
/* file transfer requested */
|
|
|
|
|
real_action = gdk_drag_context_get_selected_action (context);
|
|
|
|
|
|
2012-12-04 00:15:41 +00:00
|
|
|
|
if (real_action == GDK_ACTION_ASK)
|
|
|
|
|
real_action = emit_drag_action_ask (sidebar, gdk_drag_context_get_actions (context));
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
if (real_action > 0) {
|
|
|
|
|
model = gtk_tree_view_get_model (tree_view);
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_get_iter (model, &iter, tree_path);
|
|
|
|
|
gtk_tree_model_get (model, &iter,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_URI, &drop_uri,
|
|
|
|
|
-1);
|
|
|
|
|
|
|
|
|
|
switch (info) {
|
|
|
|
|
case TEXT_URI_LIST:
|
2012-12-04 18:52:44 +00:00
|
|
|
|
uris = gtk_selection_data_get_uris (selection_data);
|
|
|
|
|
uri_list = build_uri_list ((const char **) uris);
|
|
|
|
|
emit_drag_perform_drop (sidebar, uri_list, drop_uri, real_action);
|
|
|
|
|
g_list_free_full (uri_list, g_free);
|
|
|
|
|
g_strfreev (uris);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
success = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
case GTK_TREE_MODEL_ROW:
|
|
|
|
|
success = FALSE;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (drop_uri);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
sidebar->drop_occured = FALSE;
|
|
|
|
|
free_drag_data (sidebar);
|
|
|
|
|
gtk_drag_finish (context, success, FALSE, time);
|
|
|
|
|
|
|
|
|
|
gtk_tree_path_free (tree_path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
drag_drop_callback (GtkTreeView *tree_view,
|
|
|
|
|
GdkDragContext *context,
|
|
|
|
|
int x,
|
|
|
|
|
int y,
|
|
|
|
|
unsigned int time,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
gboolean retval = FALSE;
|
|
|
|
|
sidebar->drop_occured = TRUE;
|
|
|
|
|
retval = get_drag_data (tree_view, context, time);
|
|
|
|
|
g_signal_stop_emission_by_name (tree_view, "drag-drop");
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Callback used when the file list's popup menu is detached */
|
|
|
|
|
static void
|
|
|
|
|
bookmarks_popup_menu_detach_cb (GtkWidget *attach_widget,
|
|
|
|
|
GtkMenu *menu)
|
|
|
|
|
{
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar;
|
|
|
|
|
|
|
|
|
|
sidebar = GTK_PLACES_SIDEBAR (attach_widget);
|
|
|
|
|
g_assert (GTK_IS_PLACES_SIDEBAR (sidebar));
|
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
sidebar->popup_menu = NULL;
|
|
|
|
|
sidebar->popup_menu_add_shortcut_item = NULL;
|
|
|
|
|
sidebar->popup_menu_remove_item = NULL;
|
|
|
|
|
sidebar->popup_menu_rename_item = NULL;
|
|
|
|
|
sidebar->popup_menu_separator_item = NULL;
|
|
|
|
|
sidebar->popup_menu_mount_item = NULL;
|
|
|
|
|
sidebar->popup_menu_unmount_item = NULL;
|
|
|
|
|
sidebar->popup_menu_eject_item = NULL;
|
|
|
|
|
sidebar->popup_menu_rescan_item = NULL;
|
|
|
|
|
sidebar->popup_menu_start_item = NULL;
|
|
|
|
|
sidebar->popup_menu_stop_item = NULL;
|
|
|
|
|
sidebar->popup_menu_empty_trash_item = NULL;
|
2012-09-07 15:04:42 +00:00
|
|
|
|
sidebar->popup_menu_properties_separator_item = NULL;
|
|
|
|
|
sidebar->popup_menu_properties_item = NULL;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
check_unmount_and_eject (GMount *mount,
|
|
|
|
|
GVolume *volume,
|
|
|
|
|
GDrive *drive,
|
|
|
|
|
gboolean *show_unmount,
|
|
|
|
|
gboolean *show_eject)
|
|
|
|
|
{
|
|
|
|
|
*show_unmount = FALSE;
|
|
|
|
|
*show_eject = FALSE;
|
|
|
|
|
|
|
|
|
|
if (drive != NULL) {
|
|
|
|
|
*show_eject = g_drive_can_eject (drive);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (volume != NULL) {
|
|
|
|
|
*show_eject |= g_volume_can_eject (volume);
|
|
|
|
|
}
|
|
|
|
|
if (mount != NULL) {
|
|
|
|
|
*show_eject |= g_mount_can_eject (mount);
|
|
|
|
|
*show_unmount = g_mount_can_unmount (mount) && !*show_eject;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
check_visibility (GMount *mount,
|
|
|
|
|
GVolume *volume,
|
|
|
|
|
GDrive *drive,
|
|
|
|
|
gboolean *show_mount,
|
|
|
|
|
gboolean *show_unmount,
|
|
|
|
|
gboolean *show_eject,
|
|
|
|
|
gboolean *show_rescan,
|
|
|
|
|
gboolean *show_start,
|
|
|
|
|
gboolean *show_stop)
|
|
|
|
|
{
|
|
|
|
|
*show_mount = FALSE;
|
|
|
|
|
*show_rescan = FALSE;
|
|
|
|
|
*show_start = FALSE;
|
|
|
|
|
*show_stop = FALSE;
|
|
|
|
|
|
|
|
|
|
check_unmount_and_eject (mount, volume, drive, show_unmount, show_eject);
|
|
|
|
|
|
|
|
|
|
if (drive != NULL) {
|
|
|
|
|
if (g_drive_is_media_removable (drive) &&
|
2011-09-06 23:11:19 +00:00
|
|
|
|
!g_drive_is_media_check_automatic (drive) &&
|
2011-09-06 22:53:30 +00:00
|
|
|
|
g_drive_can_poll_for_media (drive))
|
|
|
|
|
*show_rescan = TRUE;
|
|
|
|
|
|
|
|
|
|
*show_start = g_drive_can_start (drive) || g_drive_can_start_degraded (drive);
|
|
|
|
|
*show_stop = g_drive_can_stop (drive);
|
|
|
|
|
|
|
|
|
|
if (*show_stop)
|
|
|
|
|
*show_unmount = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (volume != NULL) {
|
|
|
|
|
if (mount == NULL)
|
|
|
|
|
*show_mount = g_volume_can_mount (volume);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2012-11-21 19:13:01 +00:00
|
|
|
|
check_popup_sensitivity (GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeIter iter;
|
2011-09-06 23:11:19 +00:00
|
|
|
|
PlaceType type;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
GDrive *drive = NULL;
|
|
|
|
|
GVolume *volume = NULL;
|
|
|
|
|
GMount *mount = NULL;
|
2012-09-07 15:04:42 +00:00
|
|
|
|
GFile *location;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
gboolean show_mount;
|
|
|
|
|
gboolean show_unmount;
|
|
|
|
|
gboolean show_eject;
|
|
|
|
|
gboolean show_rescan;
|
|
|
|
|
gboolean show_start;
|
|
|
|
|
gboolean show_stop;
|
|
|
|
|
gboolean show_empty_trash;
|
2012-09-07 15:04:42 +00:00
|
|
|
|
gboolean show_properties;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
char *uri = NULL;
|
2011-09-06 23:11:19 +00:00
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
type = PLACES_BUILT_IN;
|
|
|
|
|
|
|
|
|
|
if (sidebar->popup_menu == NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (get_selected_iter (sidebar, &iter)) {
|
2012-09-07 15:04:42 +00:00
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (sidebar->store), &iter,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
PLACES_SIDEBAR_COLUMN_ROW_TYPE, &type,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_DRIVE, &drive,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_VOLUME, &volume,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_MOUNT, &mount,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_URI, &uri,
|
|
|
|
|
-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_widget_set_visible (sidebar->popup_menu_add_shortcut_item, (type == PLACES_MOUNTED_VOLUME));
|
|
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive (sidebar->popup_menu_remove_item, (type == PLACES_BOOKMARK));
|
|
|
|
|
gtk_widget_set_sensitive (sidebar->popup_menu_rename_item, (type == PLACES_BOOKMARK));
|
2012-09-11 20:44:29 +00:00
|
|
|
|
gtk_widget_set_sensitive (sidebar->popup_menu_empty_trash_item, sidebar->trash_is_full);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
check_visibility (mount, volume, drive,
|
|
|
|
|
&show_mount, &show_unmount, &show_eject, &show_rescan, &show_start, &show_stop);
|
|
|
|
|
|
2012-09-11 19:33:47 +00:00
|
|
|
|
if (sidebar->show_trash) {
|
|
|
|
|
show_empty_trash = ((uri != NULL) &&
|
|
|
|
|
(!strcmp (uri, "trash:///")));
|
|
|
|
|
} else
|
|
|
|
|
show_empty_trash = FALSE;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
/* Only show properties for local mounts */
|
2012-09-11 19:33:47 +00:00
|
|
|
|
if (sidebar->show_properties) {
|
|
|
|
|
show_properties = (mount != NULL);
|
|
|
|
|
if (mount != NULL) {
|
|
|
|
|
location = g_mount_get_default_location (mount);
|
|
|
|
|
show_properties = g_file_is_native (location);
|
|
|
|
|
g_object_unref (location);
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
show_properties = FALSE;
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
gtk_widget_set_visible (sidebar->popup_menu_separator_item,
|
|
|
|
|
show_mount || show_unmount || show_eject || show_empty_trash);
|
|
|
|
|
gtk_widget_set_visible (sidebar->popup_menu_mount_item, show_mount);
|
|
|
|
|
gtk_widget_set_visible (sidebar->popup_menu_unmount_item, show_unmount);
|
|
|
|
|
gtk_widget_set_visible (sidebar->popup_menu_eject_item, show_eject);
|
|
|
|
|
gtk_widget_set_visible (sidebar->popup_menu_rescan_item, show_rescan);
|
|
|
|
|
gtk_widget_set_visible (sidebar->popup_menu_start_item, show_start);
|
|
|
|
|
gtk_widget_set_visible (sidebar->popup_menu_stop_item, show_stop);
|
|
|
|
|
gtk_widget_set_visible (sidebar->popup_menu_empty_trash_item, show_empty_trash);
|
2012-09-07 15:04:42 +00:00
|
|
|
|
gtk_widget_set_visible (sidebar->popup_menu_properties_separator_item, show_properties);
|
|
|
|
|
gtk_widget_set_visible (sidebar->popup_menu_properties_item, show_properties);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
/* Adjust start/stop items to reflect the type of the drive */
|
|
|
|
|
gtk_menu_item_set_label (GTK_MENU_ITEM (sidebar->popup_menu_start_item), _("_Start"));
|
|
|
|
|
gtk_menu_item_set_label (GTK_MENU_ITEM (sidebar->popup_menu_stop_item), _("_Stop"));
|
|
|
|
|
if ((show_start || show_stop) && drive != NULL) {
|
|
|
|
|
switch (g_drive_get_start_stop_type (drive)) {
|
|
|
|
|
case G_DRIVE_START_STOP_TYPE_SHUTDOWN:
|
|
|
|
|
/* start() for type G_DRIVE_START_STOP_TYPE_SHUTDOWN is normally not used */
|
|
|
|
|
gtk_menu_item_set_label (GTK_MENU_ITEM (sidebar->popup_menu_start_item), _("_Power On"));
|
|
|
|
|
gtk_menu_item_set_label (GTK_MENU_ITEM (sidebar->popup_menu_stop_item), _("_Safely Remove Drive"));
|
|
|
|
|
break;
|
|
|
|
|
case G_DRIVE_START_STOP_TYPE_NETWORK:
|
|
|
|
|
gtk_menu_item_set_label (GTK_MENU_ITEM (sidebar->popup_menu_start_item), _("_Connect Drive"));
|
|
|
|
|
gtk_menu_item_set_label (GTK_MENU_ITEM (sidebar->popup_menu_stop_item), _("_Disconnect Drive"));
|
|
|
|
|
break;
|
|
|
|
|
case G_DRIVE_START_STOP_TYPE_MULTIDISK:
|
|
|
|
|
gtk_menu_item_set_label (GTK_MENU_ITEM (sidebar->popup_menu_start_item), _("_Start Multi-disk Device"));
|
|
|
|
|
gtk_menu_item_set_label (GTK_MENU_ITEM (sidebar->popup_menu_stop_item), _("_Stop Multi-disk Device"));
|
|
|
|
|
break;
|
|
|
|
|
case G_DRIVE_START_STOP_TYPE_PASSWORD:
|
|
|
|
|
/* stop() for type G_DRIVE_START_STOP_TYPE_PASSWORD is normally not used */
|
|
|
|
|
gtk_menu_item_set_label (GTK_MENU_ITEM (sidebar->popup_menu_start_item), _("_Unlock Drive"));
|
|
|
|
|
gtk_menu_item_set_label (GTK_MENU_ITEM (sidebar->popup_menu_stop_item), _("_Lock Drive"));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
case G_DRIVE_START_STOP_TYPE_UNKNOWN:
|
|
|
|
|
/* uses defaults set above */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
g_free (uri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Callback used when the selection in the shortcuts tree changes */
|
|
|
|
|
static void
|
|
|
|
|
bookmarks_selection_changed_cb (GtkTreeSelection *selection,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2012-11-21 19:13:01 +00:00
|
|
|
|
check_popup_sensitivity (sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2012-10-29 20:28:12 +00:00
|
|
|
|
drive_start_from_bookmark_cb (GObject *source_object,
|
|
|
|
|
GAsyncResult *res,
|
|
|
|
|
gpointer user_data)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar;
|
2012-10-29 20:28:12 +00:00
|
|
|
|
GError *error;
|
|
|
|
|
char *primary;
|
|
|
|
|
char *name;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2011-09-06 23:11:19 +00:00
|
|
|
|
sidebar = GTK_PLACES_SIDEBAR (user_data);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-10-29 20:28:12 +00:00
|
|
|
|
error = NULL;
|
|
|
|
|
if (!g_drive_poll_for_media_finish (G_DRIVE (source_object), res, &error)) {
|
|
|
|
|
if (error->code != G_IO_ERROR_FAILED_HANDLED) {
|
|
|
|
|
name = g_drive_get_name (G_DRIVE (source_object));
|
|
|
|
|
primary = g_strdup_printf (_("Unable to start %s"), name);
|
|
|
|
|
g_free (name);
|
|
|
|
|
emit_show_error_message (sidebar, primary, error->message);
|
|
|
|
|
g_free (primary);
|
|
|
|
|
}
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-24 16:59:48 +00:00
|
|
|
|
static void
|
|
|
|
|
change_location_and_notify (GtkPlacesSidebar *sidebar, GFile *location, GtkPlacesOpenMode open_mode)
|
|
|
|
|
{
|
|
|
|
|
g_free (sidebar->uri);
|
|
|
|
|
sidebar->uri = NULL;
|
|
|
|
|
|
|
|
|
|
if (location)
|
|
|
|
|
sidebar->uri = g_file_get_uri (location);
|
|
|
|
|
|
|
|
|
|
emit_location_selected (sidebar, location, open_mode);
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-29 20:28:12 +00:00
|
|
|
|
/* Callback from g_volume_mount() */
|
|
|
|
|
static void
|
|
|
|
|
volume_mount_cb (GObject *source_object, GAsyncResult *result, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (user_data);
|
|
|
|
|
GVolume *volume;
|
|
|
|
|
GError *error;
|
|
|
|
|
char *primary;
|
|
|
|
|
char *name;
|
|
|
|
|
GMount *mount;
|
|
|
|
|
|
|
|
|
|
volume = G_VOLUME (source_object);
|
|
|
|
|
|
|
|
|
|
error = NULL;
|
|
|
|
|
if (!g_volume_mount_finish (volume, result, &error)) {
|
|
|
|
|
if (error->code != G_IO_ERROR_FAILED_HANDLED &&
|
|
|
|
|
error->code != G_IO_ERROR_ALREADY_MOUNTED) {
|
|
|
|
|
name = g_volume_get_name (G_VOLUME (source_object));
|
|
|
|
|
primary = g_strdup_printf (_("Unable to access “%s”"), name);
|
|
|
|
|
g_free (name);
|
|
|
|
|
emit_show_error_message (sidebar, primary, error->message);
|
|
|
|
|
g_free (primary);
|
|
|
|
|
}
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
sidebar->mounting = FALSE;
|
|
|
|
|
|
|
|
|
|
mount = g_volume_get_mount (volume);
|
|
|
|
|
if (mount != NULL) {
|
2011-09-28 15:44:40 +00:00
|
|
|
|
GFile *location;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2011-09-28 15:44:40 +00:00
|
|
|
|
location = g_mount_get_default_location (mount);
|
2012-11-24 16:59:48 +00:00
|
|
|
|
change_location_and_notify (sidebar, location, sidebar->go_to_after_mount_open_mode);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
g_object_unref (G_OBJECT (location));
|
|
|
|
|
g_object_unref (G_OBJECT (mount));
|
|
|
|
|
}
|
2012-10-29 20:28:12 +00:00
|
|
|
|
|
|
|
|
|
g_object_unref (sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-10-29 20:28:12 +00:00
|
|
|
|
/* This was nautilus_file_operations_mount_volume_full() */
|
2011-09-06 22:53:30 +00:00
|
|
|
|
static void
|
2012-10-29 20:28:12 +00:00
|
|
|
|
mount_volume (GtkPlacesSidebar *sidebar, GVolume *volume)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2012-10-29 20:28:12 +00:00
|
|
|
|
GMountOperation *mount_op;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-10-29 20:28:12 +00:00
|
|
|
|
mount_op = gtk_mount_operation_new (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (sidebar))));
|
|
|
|
|
g_mount_operation_set_password_save (mount_op, G_PASSWORD_SAVE_FOR_SESSION);
|
2011-10-06 14:20:32 +00:00
|
|
|
|
|
2012-10-29 20:28:12 +00:00
|
|
|
|
g_object_ref (sidebar);
|
|
|
|
|
g_volume_mount (volume, 0, mount_op, NULL, volume_mount_cb, sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-09-06 23:11:19 +00:00
|
|
|
|
open_selected_bookmark (GtkPlacesSidebar *sidebar,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter,
|
2011-09-28 15:22:05 +00:00
|
|
|
|
GtkPlacesOpenMode open_mode)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
GFile *location;
|
|
|
|
|
char *uri;
|
|
|
|
|
|
|
|
|
|
if (!iter) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter, PLACES_SIDEBAR_COLUMN_URI, &uri, -1);
|
|
|
|
|
|
|
|
|
|
if (uri != NULL) {
|
|
|
|
|
location = g_file_new_for_uri (uri);
|
2012-11-24 16:59:48 +00:00
|
|
|
|
change_location_and_notify (sidebar, location, open_mode);
|
2011-09-06 23:11:19 +00:00
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
g_object_unref (location);
|
|
|
|
|
g_free (uri);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
GDrive *drive;
|
|
|
|
|
GVolume *volume;
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_DRIVE, &drive,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_VOLUME, &volume,
|
|
|
|
|
-1);
|
|
|
|
|
|
|
|
|
|
if (volume != NULL && !sidebar->mounting) {
|
|
|
|
|
sidebar->mounting = TRUE;
|
|
|
|
|
|
2011-09-28 15:22:05 +00:00
|
|
|
|
sidebar->go_to_after_mount_open_mode = open_mode;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-10-29 20:28:12 +00:00
|
|
|
|
mount_volume (sidebar, volume);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
} else if (volume == NULL && drive != NULL &&
|
|
|
|
|
(g_drive_can_start (drive) || g_drive_can_start_degraded (drive))) {
|
|
|
|
|
GMountOperation *mount_op;
|
|
|
|
|
|
|
|
|
|
mount_op = gtk_mount_operation_new (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (sidebar))));
|
2011-10-06 14:20:32 +00:00
|
|
|
|
g_drive_start (drive, G_DRIVE_START_NONE, mount_op, NULL, drive_start_from_bookmark_cb, sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
g_object_unref (mount_op);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (drive != NULL)
|
|
|
|
|
g_object_unref (drive);
|
|
|
|
|
if (volume != NULL)
|
|
|
|
|
g_object_unref (volume);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-09-06 23:11:19 +00:00
|
|
|
|
open_shortcut_from_menu (GtkPlacesSidebar *sidebar,
|
2011-09-28 15:22:05 +00:00
|
|
|
|
GtkPlacesOpenMode open_mode)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
GtkTreeIter iter;
|
2012-09-07 15:04:42 +00:00
|
|
|
|
GtkTreePath *path = NULL;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
model = gtk_tree_view_get_model (sidebar->tree_view);
|
|
|
|
|
gtk_tree_view_get_cursor (sidebar->tree_view, &path, NULL);
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
if (path != NULL && gtk_tree_model_get_iter (model, &iter, path)) {
|
|
|
|
|
open_selected_bookmark (sidebar, model, &iter, open_mode);
|
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-09-28 15:44:40 +00:00
|
|
|
|
open_shortcut_cb (GtkMenuItem *item,
|
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2011-09-28 15:44:40 +00:00
|
|
|
|
open_shortcut_from_menu (sidebar, GTK_PLACES_OPEN_MODE_NORMAL);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-09-28 15:44:40 +00:00
|
|
|
|
open_shortcut_in_new_window_cb (GtkMenuItem *item,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2011-09-28 15:44:40 +00:00
|
|
|
|
open_shortcut_from_menu (sidebar, GTK_PLACES_OPEN_MODE_NEW_WINDOW);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-09-28 15:44:40 +00:00
|
|
|
|
open_shortcut_in_new_tab_cb (GtkMenuItem *item,
|
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2011-09-28 15:44:40 +00:00
|
|
|
|
open_shortcut_from_menu (sidebar, GTK_PLACES_OPEN_MODE_NEW_TAB);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-04 22:16:49 +00:00
|
|
|
|
/* Add bookmark for the selected item - just used from mount points */
|
2011-09-06 22:53:30 +00:00
|
|
|
|
static void
|
2012-12-04 22:16:49 +00:00
|
|
|
|
add_shortcut_cb (GtkMenuItem *item,
|
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
char *uri;
|
2012-09-07 15:04:42 +00:00
|
|
|
|
char *name;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
GFile *location;
|
|
|
|
|
|
|
|
|
|
model = gtk_tree_view_get_model (sidebar->tree_view);
|
|
|
|
|
|
|
|
|
|
if (get_selected_iter (sidebar, &iter)) {
|
2012-09-07 15:04:42 +00:00
|
|
|
|
gtk_tree_model_get (model, &iter,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_URI, &uri,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_NAME, &name,
|
|
|
|
|
-1);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
if (uri == NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
location = g_file_new_for_uri (uri);
|
2012-12-04 22:16:49 +00:00
|
|
|
|
if (_gtk_bookmarks_manager_insert_bookmark (sidebar->bookmarks_manager, location, -1, NULL))
|
|
|
|
|
_gtk_bookmarks_manager_set_bookmark_label (sidebar->bookmarks_manager, location, name, NULL);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
g_object_unref (location);
|
|
|
|
|
g_free (uri);
|
2012-09-07 15:04:42 +00:00
|
|
|
|
g_free (name);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Rename the selected bookmark */
|
|
|
|
|
static void
|
2011-09-06 23:11:19 +00:00
|
|
|
|
rename_selected_bookmark (GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
GtkTreeViewColumn *column;
|
|
|
|
|
GtkCellRenderer *cell;
|
|
|
|
|
GList *renderers;
|
|
|
|
|
PlaceType type;
|
2011-09-06 23:11:19 +00:00
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
if (get_selected_iter (sidebar, &iter)) {
|
2012-09-07 15:04:42 +00:00
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (sidebar->store), &iter,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
PLACES_SIDEBAR_COLUMN_ROW_TYPE, &type,
|
|
|
|
|
-1);
|
|
|
|
|
|
|
|
|
|
if (type != PLACES_BOOKMARK) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (sidebar->store), &iter);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
column = gtk_tree_view_get_column (GTK_TREE_VIEW (sidebar->tree_view), 0);
|
|
|
|
|
renderers = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column));
|
|
|
|
|
cell = g_list_nth_data (renderers, 6);
|
|
|
|
|
g_list_free (renderers);
|
|
|
|
|
g_object_set (cell, "editable", TRUE, NULL);
|
|
|
|
|
gtk_tree_view_set_cursor_on_cell (GTK_TREE_VIEW (sidebar->tree_view),
|
|
|
|
|
path, column, cell, TRUE);
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
rename_shortcut_cb (GtkMenuItem *item,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
rename_selected_bookmark (sidebar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Removes the selected bookmarks */
|
|
|
|
|
static void
|
2011-09-06 23:11:19 +00:00
|
|
|
|
remove_selected_bookmarks (GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeIter iter;
|
2011-09-06 23:11:19 +00:00
|
|
|
|
PlaceType type;
|
2012-09-10 19:43:30 +00:00
|
|
|
|
char *uri;
|
|
|
|
|
GFile *file;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
if (!get_selected_iter (sidebar, &iter)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-09-06 23:11:19 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (sidebar->store), &iter,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
PLACES_SIDEBAR_COLUMN_ROW_TYPE, &type,
|
|
|
|
|
-1);
|
|
|
|
|
|
|
|
|
|
if (type != PLACES_BOOKMARK) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (sidebar->store), &iter,
|
2012-09-10 19:43:30 +00:00
|
|
|
|
PLACES_SIDEBAR_COLUMN_URI, &uri,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
-1);
|
|
|
|
|
|
2012-09-10 19:43:30 +00:00
|
|
|
|
file = g_file_new_for_uri (uri);
|
|
|
|
|
_gtk_bookmarks_manager_remove_bookmark (sidebar->bookmarks_manager, file, NULL); /* NULL-GError */
|
|
|
|
|
|
|
|
|
|
g_object_unref (file);
|
|
|
|
|
g_free (uri);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
remove_shortcut_cb (GtkMenuItem *item,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
remove_selected_bookmarks (sidebar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
mount_shortcut_cb (GtkMenuItem *item,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
GVolume *volume;
|
|
|
|
|
|
|
|
|
|
if (!get_selected_iter (sidebar, &iter)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (sidebar->store), &iter,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
PLACES_SIDEBAR_COLUMN_VOLUME, &volume,
|
|
|
|
|
-1);
|
|
|
|
|
|
|
|
|
|
if (volume != NULL) {
|
2012-10-29 20:28:12 +00:00
|
|
|
|
mount_volume (sidebar, volume);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
g_object_unref (volume);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-30 00:53:41 +00:00
|
|
|
|
/* Callback used from g_mount_unmount_with_operation() */
|
2011-09-06 22:53:30 +00:00
|
|
|
|
static void
|
2012-10-30 00:53:41 +00:00
|
|
|
|
unmount_mount_cb (GObject *source_object,
|
|
|
|
|
GAsyncResult *result,
|
|
|
|
|
gpointer user_data)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2012-10-30 00:53:41 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (user_data);
|
|
|
|
|
GMount *mount;
|
|
|
|
|
GError *error;
|
|
|
|
|
|
|
|
|
|
mount = G_MOUNT (source_object);
|
|
|
|
|
|
|
|
|
|
error = NULL;
|
|
|
|
|
if (!g_mount_unmount_with_operation_finish (mount, result, &error)) {
|
|
|
|
|
if (error->code != G_IO_ERROR_FAILED_HANDLED) {
|
|
|
|
|
char *name;
|
|
|
|
|
char *primary;
|
|
|
|
|
|
|
|
|
|
name = g_mount_get_name (mount);
|
|
|
|
|
primary = g_strdup_printf (_("Unable to unmount %s"), name);
|
|
|
|
|
g_free (name);
|
|
|
|
|
emit_show_error_message (sidebar, primary, error->message);
|
|
|
|
|
g_free (primary);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* FIXME: we need to switch to a path that is available now - $HOME? */
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2011-10-03 16:38:26 +00:00
|
|
|
|
g_object_unref (sidebar);
|
2012-10-30 00:53:41 +00:00
|
|
|
|
g_object_unref (mount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
show_unmount_progress_cb (GMountOperation *op,
|
|
|
|
|
const gchar *message,
|
|
|
|
|
gint64 time_left,
|
|
|
|
|
gint64 bytes_left,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
/* FIXME: These are just libnotify notifications, but GTK+ doesn't do notifications right now.
|
|
|
|
|
* Should we just call D-Bus directly?
|
|
|
|
|
*/
|
|
|
|
|
#if DO_NOT_COMPILE
|
|
|
|
|
NautilusApplication *app = NAUTILUS_APPLICATION (g_application_get_default ());
|
|
|
|
|
|
|
|
|
|
if (bytes_left == 0) {
|
|
|
|
|
nautilus_application_notify_unmount_done (app, message);
|
|
|
|
|
} else {
|
|
|
|
|
nautilus_application_notify_unmount_show (app, message);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
show_unmount_progress_aborted_cb (GMountOperation *op,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
/* FIXME: These are just libnotify notifications, but GTK+ doesn't do notifications right now.
|
|
|
|
|
* Should we just call D-Bus directly?
|
|
|
|
|
*/
|
|
|
|
|
#if DO_NOT_COMPILE
|
|
|
|
|
NautilusApplication *app = NAUTILUS_APPLICATION (g_application_get_default ());
|
|
|
|
|
nautilus_application_notify_unmount_done (app, NULL);
|
|
|
|
|
#endif
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
do_unmount (GMount *mount,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
if (mount != NULL) {
|
2012-10-30 00:53:41 +00:00
|
|
|
|
GMountOperation *mount_op;
|
|
|
|
|
|
|
|
|
|
g_object_ref (mount);
|
|
|
|
|
|
|
|
|
|
mount_op = gtk_mount_operation_new (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (sidebar))));
|
|
|
|
|
|
|
|
|
|
g_mount_unmount_with_operation (mount,
|
|
|
|
|
0,
|
|
|
|
|
mount_op,
|
|
|
|
|
NULL,
|
|
|
|
|
unmount_mount_cb,
|
|
|
|
|
g_object_ref (sidebar));
|
|
|
|
|
g_signal_connect (mount_op, "show-unmount-progress",
|
|
|
|
|
G_CALLBACK (show_unmount_progress_cb), sidebar);
|
|
|
|
|
g_signal_connect (mount_op, "aborted",
|
|
|
|
|
G_CALLBACK (show_unmount_progress_aborted_cb), sidebar);
|
|
|
|
|
g_object_unref (mount_op);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-09-06 23:11:19 +00:00
|
|
|
|
do_unmount_selection (GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
GMount *mount;
|
|
|
|
|
|
|
|
|
|
if (!get_selected_iter (sidebar, &iter)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (sidebar->store), &iter,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
PLACES_SIDEBAR_COLUMN_MOUNT, &mount,
|
|
|
|
|
-1);
|
|
|
|
|
|
|
|
|
|
if (mount != NULL) {
|
|
|
|
|
do_unmount (mount, sidebar);
|
|
|
|
|
g_object_unref (mount);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2012-09-07 15:04:42 +00:00
|
|
|
|
unmount_shortcut_cb (GtkMenuItem *item,
|
|
|
|
|
GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
|
|
|
|
do_unmount_selection (sidebar);
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
static void
|
|
|
|
|
drive_eject_cb (GObject *source_object,
|
|
|
|
|
GAsyncResult *res,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
2011-10-03 16:38:26 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
GError *error;
|
|
|
|
|
char *primary;
|
|
|
|
|
char *name;
|
|
|
|
|
|
2011-10-03 16:38:26 +00:00
|
|
|
|
sidebar = user_data;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
error = NULL;
|
|
|
|
|
if (!g_drive_eject_with_operation_finish (G_DRIVE (source_object), res, &error)) {
|
|
|
|
|
if (error->code != G_IO_ERROR_FAILED_HANDLED) {
|
|
|
|
|
name = g_drive_get_name (G_DRIVE (source_object));
|
|
|
|
|
primary = g_strdup_printf (_("Unable to eject %s"), name);
|
|
|
|
|
g_free (name);
|
2011-10-04 21:47:31 +00:00
|
|
|
|
emit_show_error_message (sidebar, primary, error->message);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
g_free (primary);
|
|
|
|
|
}
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
2011-10-06 14:20:32 +00:00
|
|
|
|
|
|
|
|
|
g_object_unref (sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
volume_eject_cb (GObject *source_object,
|
|
|
|
|
GAsyncResult *res,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
2011-10-03 16:38:26 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
GError *error;
|
|
|
|
|
char *primary;
|
|
|
|
|
char *name;
|
|
|
|
|
|
2011-10-03 16:38:26 +00:00
|
|
|
|
sidebar = user_data;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
error = NULL;
|
|
|
|
|
if (!g_volume_eject_with_operation_finish (G_VOLUME (source_object), res, &error)) {
|
|
|
|
|
if (error->code != G_IO_ERROR_FAILED_HANDLED) {
|
|
|
|
|
name = g_volume_get_name (G_VOLUME (source_object));
|
|
|
|
|
primary = g_strdup_printf (_("Unable to eject %s"), name);
|
|
|
|
|
g_free (name);
|
2011-10-04 21:47:31 +00:00
|
|
|
|
emit_show_error_message (sidebar, primary, error->message);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
g_free (primary);
|
|
|
|
|
}
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
2011-10-06 14:20:32 +00:00
|
|
|
|
|
|
|
|
|
g_object_unref (sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
mount_eject_cb (GObject *source_object,
|
|
|
|
|
GAsyncResult *res,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
2011-10-03 16:38:26 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
GError *error;
|
|
|
|
|
char *primary;
|
|
|
|
|
char *name;
|
|
|
|
|
|
2011-10-03 16:38:26 +00:00
|
|
|
|
sidebar = user_data;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
error = NULL;
|
|
|
|
|
if (!g_mount_eject_with_operation_finish (G_MOUNT (source_object), res, &error)) {
|
|
|
|
|
if (error->code != G_IO_ERROR_FAILED_HANDLED) {
|
|
|
|
|
name = g_mount_get_name (G_MOUNT (source_object));
|
|
|
|
|
primary = g_strdup_printf (_("Unable to eject %s"), name);
|
|
|
|
|
g_free (name);
|
2011-10-04 21:47:31 +00:00
|
|
|
|
emit_show_error_message (sidebar, primary, error->message);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
g_free (primary);
|
|
|
|
|
}
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
2011-10-06 14:20:32 +00:00
|
|
|
|
|
|
|
|
|
g_object_unref (sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
do_eject (GMount *mount,
|
|
|
|
|
GVolume *volume,
|
|
|
|
|
GDrive *drive,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
GMountOperation *mount_op;
|
|
|
|
|
|
|
|
|
|
mount_op = gtk_mount_operation_new (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (sidebar))));
|
|
|
|
|
if (mount != NULL) {
|
|
|
|
|
g_mount_eject_with_operation (mount, 0, mount_op, NULL, mount_eject_cb,
|
2011-10-03 16:38:26 +00:00
|
|
|
|
g_object_ref (sidebar));
|
2011-09-06 22:53:30 +00:00
|
|
|
|
} else if (volume != NULL) {
|
|
|
|
|
g_volume_eject_with_operation (volume, 0, mount_op, NULL, volume_eject_cb,
|
2011-10-03 16:38:26 +00:00
|
|
|
|
g_object_ref (sidebar));
|
2011-09-06 22:53:30 +00:00
|
|
|
|
} else if (drive != NULL) {
|
|
|
|
|
g_drive_eject_with_operation (drive, 0, mount_op, NULL, drive_eject_cb,
|
2011-10-03 16:38:26 +00:00
|
|
|
|
g_object_ref (sidebar));
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
|
|
|
|
g_signal_connect (mount_op, "show-unmount-progress",
|
|
|
|
|
G_CALLBACK (show_unmount_progress_cb), sidebar);
|
|
|
|
|
g_signal_connect (mount_op, "aborted",
|
|
|
|
|
G_CALLBACK (show_unmount_progress_aborted_cb), sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
g_object_unref (mount_op);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
eject_shortcut_cb (GtkMenuItem *item,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
GMount *mount;
|
|
|
|
|
GVolume *volume;
|
|
|
|
|
GDrive *drive;
|
|
|
|
|
|
|
|
|
|
if (!get_selected_iter (sidebar, &iter)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (sidebar->store), &iter,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
PLACES_SIDEBAR_COLUMN_MOUNT, &mount,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_VOLUME, &volume,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_DRIVE, &drive,
|
|
|
|
|
-1);
|
|
|
|
|
|
|
|
|
|
do_eject (mount, volume, drive, sidebar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2011-09-06 23:11:19 +00:00
|
|
|
|
eject_or_unmount_bookmark (GtkPlacesSidebar *sidebar,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
GtkTreePath *path)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
gboolean can_unmount, can_eject;
|
|
|
|
|
GMount *mount;
|
|
|
|
|
GVolume *volume;
|
|
|
|
|
GDrive *drive;
|
|
|
|
|
gboolean ret;
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
model = GTK_TREE_MODEL (sidebar->store);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
if (!path) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
if (!gtk_tree_model_get_iter (model, &iter, path)) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, &iter,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_MOUNT, &mount,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_VOLUME, &volume,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_DRIVE, &drive,
|
|
|
|
|
-1);
|
|
|
|
|
|
|
|
|
|
ret = FALSE;
|
|
|
|
|
|
|
|
|
|
check_unmount_and_eject (mount, volume, drive, &can_unmount, &can_eject);
|
|
|
|
|
/* if we can eject, it has priority over unmount */
|
|
|
|
|
if (can_eject) {
|
|
|
|
|
do_eject (mount, volume, drive, sidebar);
|
|
|
|
|
ret = TRUE;
|
|
|
|
|
} else if (can_unmount) {
|
|
|
|
|
do_unmount (mount, sidebar);
|
|
|
|
|
ret = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mount != NULL)
|
|
|
|
|
g_object_unref (mount);
|
|
|
|
|
if (volume != NULL)
|
|
|
|
|
g_object_unref (volume);
|
|
|
|
|
if (drive != NULL)
|
|
|
|
|
g_object_unref (drive);
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2011-09-06 23:11:19 +00:00
|
|
|
|
eject_or_unmount_selection (GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
|
|
if (!get_selected_iter (sidebar, &iter)) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (sidebar->store), &iter);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
if (path == NULL) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret = eject_or_unmount_bookmark (sidebar, path);
|
|
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
drive_poll_for_media_cb (GObject *source_object,
|
|
|
|
|
GAsyncResult *res,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
2011-10-06 14:20:32 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
GError *error;
|
|
|
|
|
char *primary;
|
|
|
|
|
char *name;
|
|
|
|
|
|
2011-10-06 14:20:32 +00:00
|
|
|
|
sidebar = GTK_PLACES_SIDEBAR (user_data);
|
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
error = NULL;
|
|
|
|
|
if (!g_drive_poll_for_media_finish (G_DRIVE (source_object), res, &error)) {
|
|
|
|
|
if (error->code != G_IO_ERROR_FAILED_HANDLED) {
|
|
|
|
|
name = g_drive_get_name (G_DRIVE (source_object));
|
|
|
|
|
primary = g_strdup_printf (_("Unable to poll %s for media changes"), name);
|
|
|
|
|
g_free (name);
|
2011-10-04 21:47:31 +00:00
|
|
|
|
emit_show_error_message (sidebar, primary, error->message);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
g_free (primary);
|
|
|
|
|
}
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
2011-10-06 14:20:32 +00:00
|
|
|
|
|
|
|
|
|
/* FIXME: drive_stop_cb() gets a reffed sidebar, and unrefs it. Do we need to do the same here? */
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
rescan_shortcut_cb (GtkMenuItem *item,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
GDrive *drive;
|
|
|
|
|
|
|
|
|
|
if (!get_selected_iter (sidebar, &iter)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (sidebar->store), &iter,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
PLACES_SIDEBAR_COLUMN_DRIVE, &drive,
|
|
|
|
|
-1);
|
|
|
|
|
|
|
|
|
|
if (drive != NULL) {
|
2011-10-06 14:20:32 +00:00
|
|
|
|
g_drive_poll_for_media (drive, NULL, drive_poll_for_media_cb, sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
g_object_unref (drive);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
drive_start_cb (GObject *source_object,
|
|
|
|
|
GAsyncResult *res,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
2011-10-06 14:20:32 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
GError *error;
|
|
|
|
|
char *primary;
|
|
|
|
|
char *name;
|
|
|
|
|
|
2011-10-06 14:20:32 +00:00
|
|
|
|
sidebar = GTK_PLACES_SIDEBAR (user_data);
|
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
error = NULL;
|
|
|
|
|
if (!g_drive_poll_for_media_finish (G_DRIVE (source_object), res, &error)) {
|
|
|
|
|
if (error->code != G_IO_ERROR_FAILED_HANDLED) {
|
|
|
|
|
name = g_drive_get_name (G_DRIVE (source_object));
|
|
|
|
|
primary = g_strdup_printf (_("Unable to start %s"), name);
|
|
|
|
|
g_free (name);
|
2011-10-04 21:47:31 +00:00
|
|
|
|
emit_show_error_message (sidebar, primary, error->message);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
g_free (primary);
|
|
|
|
|
}
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
2011-10-06 14:20:32 +00:00
|
|
|
|
|
|
|
|
|
/* FIXME: drive_stop_cb() gets a reffed sidebar, and unrefs it. Do we need to do the same here? */
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
start_shortcut_cb (GtkMenuItem *item,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
GDrive *drive;
|
|
|
|
|
|
|
|
|
|
if (!get_selected_iter (sidebar, &iter)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (sidebar->store), &iter,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
PLACES_SIDEBAR_COLUMN_DRIVE, &drive,
|
|
|
|
|
-1);
|
|
|
|
|
|
|
|
|
|
if (drive != NULL) {
|
|
|
|
|
GMountOperation *mount_op;
|
|
|
|
|
|
|
|
|
|
mount_op = gtk_mount_operation_new (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (sidebar))));
|
|
|
|
|
|
2011-10-06 14:20:32 +00:00
|
|
|
|
g_drive_start (drive, G_DRIVE_START_NONE, mount_op, NULL, drive_start_cb, sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
g_object_unref (mount_op);
|
|
|
|
|
}
|
|
|
|
|
g_object_unref (drive);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
drive_stop_cb (GObject *source_object,
|
|
|
|
|
GAsyncResult *res,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
2011-10-03 16:38:26 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
GError *error;
|
|
|
|
|
char *primary;
|
|
|
|
|
char *name;
|
|
|
|
|
|
2011-10-03 16:38:26 +00:00
|
|
|
|
sidebar = user_data;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
error = NULL;
|
|
|
|
|
if (!g_drive_poll_for_media_finish (G_DRIVE (source_object), res, &error)) {
|
|
|
|
|
if (error->code != G_IO_ERROR_FAILED_HANDLED) {
|
|
|
|
|
name = g_drive_get_name (G_DRIVE (source_object));
|
|
|
|
|
primary = g_strdup_printf (_("Unable to stop %s"), name);
|
|
|
|
|
g_free (name);
|
2011-10-04 21:47:31 +00:00
|
|
|
|
emit_show_error_message (sidebar, primary, error->message);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
g_free (primary);
|
|
|
|
|
}
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
2011-10-06 14:20:32 +00:00
|
|
|
|
|
|
|
|
|
g_object_unref (sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
stop_shortcut_cb (GtkMenuItem *item,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
GDrive *drive;
|
|
|
|
|
|
|
|
|
|
if (!get_selected_iter (sidebar, &iter)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (sidebar->store), &iter,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
PLACES_SIDEBAR_COLUMN_DRIVE, &drive,
|
|
|
|
|
-1);
|
|
|
|
|
|
|
|
|
|
if (drive != NULL) {
|
|
|
|
|
GMountOperation *mount_op;
|
|
|
|
|
|
|
|
|
|
mount_op = gtk_mount_operation_new (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (sidebar))));
|
|
|
|
|
g_drive_stop (drive, G_MOUNT_UNMOUNT_NONE, mount_op, NULL, drive_stop_cb,
|
2011-10-03 16:38:26 +00:00
|
|
|
|
g_object_ref (sidebar));
|
2011-09-06 22:53:30 +00:00
|
|
|
|
g_object_unref (mount_op);
|
|
|
|
|
}
|
|
|
|
|
g_object_unref (drive);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2012-09-11 20:44:29 +00:00
|
|
|
|
empty_trash_cb (GtkMenuItem *item,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2012-09-11 20:44:29 +00:00
|
|
|
|
emit_empty_trash_requested (sidebar);
|
2012-09-11 19:33:47 +00:00
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
static gboolean
|
2011-09-06 23:11:19 +00:00
|
|
|
|
find_prev_or_next_row (GtkPlacesSidebar *sidebar,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gboolean go_up)
|
|
|
|
|
{
|
2012-09-07 15:04:42 +00:00
|
|
|
|
GtkTreeModel *model = GTK_TREE_MODEL (sidebar->store);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
gboolean res;
|
2012-09-07 15:04:42 +00:00
|
|
|
|
int place_type;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
if (go_up) {
|
|
|
|
|
res = gtk_tree_model_iter_previous (model, iter);
|
|
|
|
|
} else {
|
|
|
|
|
res = gtk_tree_model_iter_next (model, iter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
|
gtk_tree_model_get (model, iter,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_ROW_TYPE, &place_type,
|
|
|
|
|
-1);
|
|
|
|
|
if (place_type == PLACES_HEADING) {
|
|
|
|
|
if (go_up) {
|
|
|
|
|
res = gtk_tree_model_iter_previous (model, iter);
|
|
|
|
|
} else {
|
|
|
|
|
res = gtk_tree_model_iter_next (model, iter);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2011-09-06 23:11:19 +00:00
|
|
|
|
find_prev_row (GtkPlacesSidebar *sidebar, GtkTreeIter *iter)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
return find_prev_or_next_row (sidebar, iter, TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2011-09-06 23:11:19 +00:00
|
|
|
|
find_next_row (GtkPlacesSidebar *sidebar, GtkTreeIter *iter)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
return find_prev_or_next_row (sidebar, iter, FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
static void
|
|
|
|
|
properties_cb (GtkMenuItem *item,
|
|
|
|
|
GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
GtkTreePath *path = NULL;
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
char *uri;
|
|
|
|
|
|
|
|
|
|
model = gtk_tree_view_get_model (sidebar->tree_view);
|
|
|
|
|
gtk_tree_view_get_cursor (sidebar->tree_view, &path, NULL);
|
|
|
|
|
|
|
|
|
|
if (path == NULL || !gtk_tree_model_get_iter (model, &iter, path)) {
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, &iter, PLACES_SIDEBAR_COLUMN_URI, &uri, -1);
|
|
|
|
|
|
|
|
|
|
if (uri != NULL) {
|
2012-10-22 23:21:17 +00:00
|
|
|
|
GFile *file;
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
2012-10-22 23:21:17 +00:00
|
|
|
|
file = g_file_new_for_uri (uri);
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
2012-10-22 23:21:17 +00:00
|
|
|
|
emit_show_file_properties (sidebar, file);
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
2012-10-22 23:21:17 +00:00
|
|
|
|
g_object_unref (file);
|
2012-09-07 15:04:42 +00:00
|
|
|
|
g_free (uri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
gtk_places_sidebar_focus (GtkWidget *widget,
|
|
|
|
|
GtkDirectionType direction)
|
|
|
|
|
{
|
|
|
|
|
GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (widget);
|
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
|
|
res = get_selected_iter (sidebar, &iter);
|
|
|
|
|
|
|
|
|
|
if (!res) {
|
|
|
|
|
gtk_tree_model_get_iter_first (GTK_TREE_MODEL (sidebar->store), &iter);
|
|
|
|
|
res = find_next_row (sidebar, &iter);
|
|
|
|
|
if (res) {
|
|
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (sidebar->store), &iter);
|
|
|
|
|
gtk_tree_view_set_cursor (sidebar->tree_view, path, NULL, FALSE);
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return GTK_WIDGET_CLASS (gtk_places_sidebar_parent_class)->focus (widget, direction);
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
/* Handler for GtkWidget::key-press-event on the shortcuts list */
|
|
|
|
|
static gboolean
|
|
|
|
|
bookmarks_key_press_event_cb (GtkWidget *widget,
|
|
|
|
|
GdkEventKey *event,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2012-09-07 15:04:42 +00:00
|
|
|
|
guint modifiers;
|
|
|
|
|
GtkTreeIter selected_iter;
|
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
|
|
|
|
|
if (!get_selected_iter (sidebar, &selected_iter)) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
modifiers = gtk_accelerator_get_default_mod_mask ();
|
|
|
|
|
|
|
|
|
|
if ((event->keyval == GDK_KEY_Return ||
|
|
|
|
|
event->keyval == GDK_KEY_KP_Enter ||
|
|
|
|
|
event->keyval == GDK_KEY_ISO_Enter ||
|
|
|
|
|
event->keyval == GDK_KEY_space)) {
|
|
|
|
|
|
|
|
|
|
GtkPlacesOpenMode open_mode = GTK_PLACES_OPEN_MODE_NORMAL;
|
|
|
|
|
|
|
|
|
|
if ((event->state & modifiers) == GDK_SHIFT_MASK) {
|
|
|
|
|
open_mode = GTK_PLACES_OPEN_MODE_NEW_TAB;
|
|
|
|
|
} else if ((event->state & modifiers) == GDK_CONTROL_MASK) {
|
|
|
|
|
open_mode = GTK_PLACES_OPEN_MODE_NEW_WINDOW;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
open_selected_bookmark (sidebar, GTK_TREE_MODEL (sidebar->store),
|
|
|
|
|
&selected_iter, open_mode);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (event->keyval == GDK_KEY_Down &&
|
|
|
|
|
(event->state & modifiers) == GDK_MOD1_MASK) {
|
|
|
|
|
return eject_or_unmount_selection (sidebar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (event->keyval == GDK_KEY_Up) {
|
|
|
|
|
if (find_prev_row (sidebar, &selected_iter)) {
|
|
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (sidebar->store), &selected_iter);
|
|
|
|
|
gtk_tree_view_set_cursor (sidebar->tree_view, path, NULL, FALSE);
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
}
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (event->keyval == GDK_KEY_Down) {
|
|
|
|
|
if (find_next_row (sidebar, &selected_iter)) {
|
|
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (sidebar->store), &selected_iter);
|
|
|
|
|
gtk_tree_view_set_cursor (sidebar->tree_view, path, NULL, FALSE);
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
}
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((event->keyval == GDK_KEY_Delete
|
|
|
|
|
|| event->keyval == GDK_KEY_KP_Delete)
|
|
|
|
|
&& (event->state & modifiers) == 0) {
|
|
|
|
|
remove_selected_bookmarks (sidebar);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((event->keyval == GDK_KEY_F2)
|
|
|
|
|
&& (event->state & modifiers) == 0) {
|
|
|
|
|
rename_selected_bookmark (sidebar);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-10-05 12:28:14 +00:00
|
|
|
|
static GtkMenuItem *
|
|
|
|
|
append_menu_separator (GtkMenu *menu)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *menu_item;
|
|
|
|
|
|
|
|
|
|
menu_item = gtk_separator_menu_item_new ();
|
|
|
|
|
gtk_widget_show (menu_item);
|
|
|
|
|
gtk_menu_shell_insert (GTK_MENU_SHELL (menu), menu_item, -1);
|
|
|
|
|
|
|
|
|
|
return GTK_MENU_ITEM (menu_item);
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
/* Constructs the popup menu for the file list if needed */
|
|
|
|
|
static void
|
2011-09-06 23:11:19 +00:00
|
|
|
|
bookmarks_build_popup_menu (GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
GtkWidget *item;
|
2011-09-06 23:11:19 +00:00
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
if (sidebar->popup_menu) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sidebar->popup_menu = gtk_menu_new ();
|
|
|
|
|
gtk_menu_attach_to_widget (GTK_MENU (sidebar->popup_menu),
|
|
|
|
|
GTK_WIDGET (sidebar),
|
|
|
|
|
bookmarks_popup_menu_detach_cb);
|
2011-09-06 23:11:19 +00:00
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
item = gtk_image_menu_item_new_with_mnemonic (_("_Open"));
|
|
|
|
|
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
|
|
|
|
|
gtk_image_new_from_stock (GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU));
|
|
|
|
|
g_signal_connect (item, "activate",
|
|
|
|
|
G_CALLBACK (open_shortcut_cb), sidebar);
|
|
|
|
|
gtk_widget_show (item);
|
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (sidebar->popup_menu), item);
|
|
|
|
|
|
|
|
|
|
item = gtk_menu_item_new_with_mnemonic (_("Open in New _Tab"));
|
|
|
|
|
sidebar->popup_menu_open_in_new_tab_item = item;
|
|
|
|
|
g_signal_connect (item, "activate",
|
|
|
|
|
G_CALLBACK (open_shortcut_in_new_tab_cb), sidebar);
|
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (sidebar->popup_menu), item);
|
|
|
|
|
|
2011-10-06 14:20:32 +00:00
|
|
|
|
if (sidebar->multiple_tabs_supported) {
|
2011-09-06 22:53:30 +00:00
|
|
|
|
gtk_widget_show (item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
item = gtk_menu_item_new_with_mnemonic (_("Open in New _Window"));
|
|
|
|
|
g_signal_connect (item, "activate",
|
|
|
|
|
G_CALLBACK (open_shortcut_in_new_window_cb), sidebar);
|
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (sidebar->popup_menu), item);
|
|
|
|
|
|
2011-10-04 14:22:11 +00:00
|
|
|
|
if (sidebar->multiple_windows_supported) {
|
2011-09-06 22:53:30 +00:00
|
|
|
|
gtk_widget_show (item);
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-05 12:28:14 +00:00
|
|
|
|
append_menu_separator (GTK_MENU (sidebar->popup_menu));
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
item = gtk_menu_item_new_with_mnemonic (_("_Add Bookmark"));
|
|
|
|
|
sidebar->popup_menu_add_shortcut_item = item;
|
|
|
|
|
g_signal_connect (item, "activate",
|
|
|
|
|
G_CALLBACK (add_shortcut_cb), sidebar);
|
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (sidebar->popup_menu), item);
|
|
|
|
|
|
|
|
|
|
item = gtk_image_menu_item_new_with_label (_("Remove"));
|
|
|
|
|
sidebar->popup_menu_remove_item = item;
|
|
|
|
|
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
|
|
|
|
|
gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_MENU));
|
|
|
|
|
g_signal_connect (item, "activate",
|
|
|
|
|
G_CALLBACK (remove_shortcut_cb), sidebar);
|
|
|
|
|
gtk_widget_show (item);
|
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (sidebar->popup_menu), item);
|
2011-09-06 23:11:19 +00:00
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
item = gtk_menu_item_new_with_label (_("Rename..."));
|
|
|
|
|
sidebar->popup_menu_rename_item = item;
|
|
|
|
|
g_signal_connect (item, "activate",
|
|
|
|
|
G_CALLBACK (rename_shortcut_cb), sidebar);
|
|
|
|
|
gtk_widget_show (item);
|
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (sidebar->popup_menu), item);
|
2011-09-06 23:11:19 +00:00
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
/* Mount/Unmount/Eject menu items */
|
|
|
|
|
|
2011-10-05 12:28:14 +00:00
|
|
|
|
sidebar->popup_menu_separator_item = GTK_WIDGET (append_menu_separator (GTK_MENU (sidebar->popup_menu)));
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
item = gtk_menu_item_new_with_mnemonic (_("_Mount"));
|
|
|
|
|
sidebar->popup_menu_mount_item = item;
|
|
|
|
|
g_signal_connect (item, "activate",
|
|
|
|
|
G_CALLBACK (mount_shortcut_cb), sidebar);
|
|
|
|
|
gtk_widget_show (item);
|
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (sidebar->popup_menu), item);
|
|
|
|
|
|
|
|
|
|
item = gtk_menu_item_new_with_mnemonic (_("_Unmount"));
|
|
|
|
|
sidebar->popup_menu_unmount_item = item;
|
|
|
|
|
g_signal_connect (item, "activate",
|
|
|
|
|
G_CALLBACK (unmount_shortcut_cb), sidebar);
|
|
|
|
|
gtk_widget_show (item);
|
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (sidebar->popup_menu), item);
|
|
|
|
|
|
|
|
|
|
item = gtk_menu_item_new_with_mnemonic (_("_Eject"));
|
|
|
|
|
sidebar->popup_menu_eject_item = item;
|
|
|
|
|
g_signal_connect (item, "activate",
|
|
|
|
|
G_CALLBACK (eject_shortcut_cb), sidebar);
|
|
|
|
|
gtk_widget_show (item);
|
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (sidebar->popup_menu), item);
|
|
|
|
|
|
|
|
|
|
item = gtk_menu_item_new_with_mnemonic (_("_Detect Media"));
|
|
|
|
|
sidebar->popup_menu_rescan_item = item;
|
|
|
|
|
g_signal_connect (item, "activate",
|
|
|
|
|
G_CALLBACK (rescan_shortcut_cb), sidebar);
|
|
|
|
|
gtk_widget_show (item);
|
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (sidebar->popup_menu), item);
|
|
|
|
|
|
|
|
|
|
item = gtk_menu_item_new_with_mnemonic (_("_Start"));
|
|
|
|
|
sidebar->popup_menu_start_item = item;
|
|
|
|
|
g_signal_connect (item, "activate",
|
|
|
|
|
G_CALLBACK (start_shortcut_cb), sidebar);
|
|
|
|
|
gtk_widget_show (item);
|
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (sidebar->popup_menu), item);
|
|
|
|
|
|
|
|
|
|
item = gtk_menu_item_new_with_mnemonic (_("_Stop"));
|
|
|
|
|
sidebar->popup_menu_stop_item = item;
|
|
|
|
|
g_signal_connect (item, "activate",
|
|
|
|
|
G_CALLBACK (stop_shortcut_cb), sidebar);
|
|
|
|
|
gtk_widget_show (item);
|
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (sidebar->popup_menu), item);
|
|
|
|
|
|
|
|
|
|
/* Empty Trash menu item */
|
|
|
|
|
|
|
|
|
|
item = gtk_menu_item_new_with_mnemonic (_("Empty _Trash"));
|
|
|
|
|
sidebar->popup_menu_empty_trash_item = item;
|
|
|
|
|
g_signal_connect (item, "activate",
|
2012-09-11 19:33:47 +00:00
|
|
|
|
G_CALLBACK (empty_trash_cb), sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
gtk_widget_show (item);
|
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (sidebar->popup_menu), item);
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
|
|
|
|
/* Properties menu item */
|
|
|
|
|
|
2012-09-11 19:33:47 +00:00
|
|
|
|
sidebar->popup_menu_properties_separator_item = GTK_WIDGET (append_menu_separator (GTK_MENU (sidebar->popup_menu)));
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
|
|
|
|
item = gtk_menu_item_new_with_mnemonic (_("_Properties"));
|
|
|
|
|
sidebar->popup_menu_properties_item = item;
|
|
|
|
|
g_signal_connect (item, "activate",
|
|
|
|
|
G_CALLBACK (properties_cb), sidebar);
|
|
|
|
|
gtk_widget_show (item);
|
|
|
|
|
gtk_menu_shell_append (GTK_MENU_SHELL (sidebar->popup_menu), item);
|
|
|
|
|
|
2012-11-21 19:13:01 +00:00
|
|
|
|
/* Update everything! */
|
|
|
|
|
|
|
|
|
|
check_popup_sensitivity (sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-09-06 23:11:19 +00:00
|
|
|
|
bookmarks_update_popup_menu (GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2011-09-06 23:11:19 +00:00
|
|
|
|
bookmarks_build_popup_menu (sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-09-06 23:11:19 +00:00
|
|
|
|
bookmarks_popup_menu (GtkPlacesSidebar *sidebar,
|
2011-10-05 13:11:14 +00:00
|
|
|
|
GdkEventButton *event)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2011-10-05 13:11:14 +00:00
|
|
|
|
int button;
|
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
bookmarks_update_popup_menu (sidebar);
|
2011-10-05 13:11:14 +00:00
|
|
|
|
|
|
|
|
|
/* The event button needs to be 0 if we're popping up this menu from
|
|
|
|
|
* a button release, else a 2nd click outside the menu with any button
|
|
|
|
|
* other than the one that invoked the menu will be ignored (instead
|
|
|
|
|
* of dismissing the menu). This is a subtle fragility of the GTK menu code.
|
|
|
|
|
*/
|
|
|
|
|
if (event) {
|
|
|
|
|
if (event->type == GDK_BUTTON_RELEASE)
|
|
|
|
|
button = 0;
|
|
|
|
|
else
|
|
|
|
|
button = event->button;
|
|
|
|
|
} else {
|
|
|
|
|
button = 0;
|
|
|
|
|
}
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
2011-10-05 13:11:14 +00:00
|
|
|
|
gtk_menu_popup (GTK_MENU (sidebar->popup_menu), /* menu */
|
|
|
|
|
NULL, /* parent_menu_shell */
|
|
|
|
|
NULL, /* parent_menu_item */
|
|
|
|
|
NULL, /* popup_position_func */
|
|
|
|
|
NULL, /* popup_position_user_data */
|
|
|
|
|
button, /* button */
|
2011-10-06 14:20:32 +00:00
|
|
|
|
event ? event->time : gtk_get_current_event_time ()); /* activate_time */
|
2011-10-05 13:11:14 +00:00
|
|
|
|
|
2011-10-06 14:20:32 +00:00
|
|
|
|
g_object_ref_sink (sidebar->popup_menu); /* FIXME: is this right? It was gtk_object_sink() */
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Callback used for the GtkWidget::popup-menu signal of the shortcuts list */
|
|
|
|
|
static gboolean
|
|
|
|
|
bookmarks_popup_menu_cb (GtkWidget *widget,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
bookmarks_popup_menu (sidebar, NULL);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
bookmarks_button_release_event_cb (GtkWidget *widget,
|
|
|
|
|
GdkEventButton *event,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
GtkTreeView *tree_view;
|
2012-09-07 15:04:42 +00:00
|
|
|
|
gboolean ret = FALSE;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
|
|
path = NULL;
|
|
|
|
|
|
|
|
|
|
if (event->type != GDK_BUTTON_RELEASE) {
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (clicked_eject_button (sidebar, &path)) {
|
|
|
|
|
eject_or_unmount_bookmark (sidebar, path);
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tree_view = GTK_TREE_VIEW (widget);
|
|
|
|
|
model = gtk_tree_view_get_model (tree_view);
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
if (event->window != gtk_tree_view_get_bin_window (tree_view)) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
res = gtk_tree_view_get_path_at_pos (tree_view, (int) event->x, (int) event->y,
|
|
|
|
|
&path, NULL, NULL, NULL);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
if (!res || path == NULL) {
|
|
|
|
|
return FALSE;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
res = gtk_tree_model_get_iter (model, &iter, path);
|
|
|
|
|
if (!res) {
|
2011-09-06 22:53:30 +00:00
|
|
|
|
gtk_tree_path_free (path);
|
2012-09-07 15:04:42 +00:00
|
|
|
|
return FALSE;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
if (event->button == 1) {
|
|
|
|
|
open_selected_bookmark (sidebar, model, &iter, 0);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
} else if (event->button == 2) {
|
2011-09-28 15:22:05 +00:00
|
|
|
|
GtkPlacesOpenMode open_mode = GTK_PLACES_OPEN_MODE_NORMAL;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
open_mode = ((event->state & GDK_CONTROL_MASK) ?
|
|
|
|
|
GTK_PLACES_OPEN_MODE_NEW_WINDOW :
|
|
|
|
|
GTK_PLACES_OPEN_MODE_NEW_TAB);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2011-09-28 15:22:05 +00:00
|
|
|
|
open_selected_bookmark (sidebar, model, &iter, open_mode);
|
2012-09-07 15:04:42 +00:00
|
|
|
|
ret = TRUE;
|
|
|
|
|
} else if (event->button == 3) {
|
|
|
|
|
PlaceType row_type;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
gtk_tree_model_get (model, &iter,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_ROW_TYPE, &row_type,
|
|
|
|
|
-1);
|
|
|
|
|
|
|
|
|
|
if (row_type != PLACES_HEADING) {
|
|
|
|
|
bookmarks_popup_menu (sidebar, event);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
gtk_tree_path_free (path);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
bookmarks_edited (GtkCellRenderer *cell,
|
|
|
|
|
gchar *path_string,
|
|
|
|
|
gchar *new_text,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
GtkTreeIter iter;
|
2012-09-10 20:03:13 +00:00
|
|
|
|
char *uri;
|
|
|
|
|
GFile *file;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
g_object_set (cell, "editable", FALSE, NULL);
|
2011-09-06 23:11:19 +00:00
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
path = gtk_tree_path_new_from_string (path_string);
|
2012-09-07 15:04:42 +00:00
|
|
|
|
gtk_tree_model_get_iter (GTK_TREE_MODEL (sidebar->store), &iter, path);
|
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (sidebar->store), &iter,
|
2012-09-10 20:03:13 +00:00
|
|
|
|
PLACES_SIDEBAR_COLUMN_URI, &uri,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
-1);
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
2012-09-10 20:03:13 +00:00
|
|
|
|
file = g_file_new_for_uri (uri);
|
2012-09-11 20:02:01 +00:00
|
|
|
|
_gtk_bookmarks_manager_set_bookmark_label (sidebar->bookmarks_manager, file, new_text, NULL); /* NULL-GError */
|
2012-09-10 20:03:13 +00:00
|
|
|
|
|
|
|
|
|
g_object_unref (file);
|
|
|
|
|
g_free (uri);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
bookmarks_editing_canceled (GtkCellRenderer *cell,
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
g_object_set (cell, "editable", FALSE, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
tree_selection_func (GtkTreeSelection *selection,
|
|
|
|
|
GtkTreeModel *model,
|
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
gboolean path_currently_selected,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
PlaceType row_type;
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_get_iter (model, &iter, path);
|
|
|
|
|
gtk_tree_model_get (model, &iter,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_ROW_TYPE, &row_type,
|
|
|
|
|
-1);
|
|
|
|
|
|
|
|
|
|
if (row_type == PLACES_HEADING) {
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
icon_cell_renderer_func (GtkTreeViewColumn *column,
|
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
|
GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
PlaceType type;
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_ROW_TYPE, &type,
|
|
|
|
|
-1);
|
|
|
|
|
|
|
|
|
|
if (type == PLACES_HEADING) {
|
|
|
|
|
g_object_set (cell,
|
|
|
|
|
"visible", FALSE,
|
|
|
|
|
NULL);
|
|
|
|
|
} else {
|
|
|
|
|
g_object_set (cell,
|
|
|
|
|
"visible", TRUE,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
padding_cell_renderer_func (GtkTreeViewColumn *column,
|
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
|
GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
PlaceType type;
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_ROW_TYPE, &type,
|
|
|
|
|
-1);
|
|
|
|
|
|
|
|
|
|
if (type == PLACES_HEADING) {
|
|
|
|
|
g_object_set (cell,
|
|
|
|
|
"visible", FALSE,
|
|
|
|
|
"xpad", 0,
|
|
|
|
|
"ypad", 0,
|
|
|
|
|
NULL);
|
|
|
|
|
} else {
|
|
|
|
|
g_object_set (cell,
|
|
|
|
|
"visible", TRUE,
|
|
|
|
|
"xpad", 3,
|
|
|
|
|
"ypad", 3,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
heading_cell_renderer_func (GtkTreeViewColumn *column,
|
|
|
|
|
GtkCellRenderer *cell,
|
|
|
|
|
GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
PlaceType type;
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_ROW_TYPE, &type,
|
|
|
|
|
-1);
|
|
|
|
|
|
|
|
|
|
if (type == PLACES_HEADING) {
|
|
|
|
|
g_object_set (cell,
|
|
|
|
|
"visible", TRUE,
|
|
|
|
|
NULL);
|
|
|
|
|
} else {
|
|
|
|
|
g_object_set (cell,
|
|
|
|
|
"visible", FALSE,
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
static gint
|
|
|
|
|
places_sidebar_sort_func (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter_a,
|
|
|
|
|
GtkTreeIter *iter_b,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
SectionType section_type_a, section_type_b;
|
|
|
|
|
PlaceType place_type_a, place_type_b;
|
|
|
|
|
gint retval = 0;
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter_a,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_SECTION_TYPE, §ion_type_a,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_ROW_TYPE, &place_type_a,
|
|
|
|
|
-1);
|
|
|
|
|
gtk_tree_model_get (model, iter_b,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_SECTION_TYPE, §ion_type_b,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_ROW_TYPE, &place_type_b,
|
|
|
|
|
-1);
|
|
|
|
|
|
|
|
|
|
/* fall back to the default order if we're not in the
|
|
|
|
|
* XDG part of the computer section.
|
|
|
|
|
*/
|
|
|
|
|
if ((section_type_a == section_type_b) &&
|
|
|
|
|
(section_type_a == SECTION_COMPUTER) &&
|
|
|
|
|
(place_type_a == place_type_b) &&
|
|
|
|
|
(place_type_a == PLACES_XDG_DIR)) {
|
|
|
|
|
gchar *name_a, *name_b;
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter_a,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_NAME, &name_a,
|
|
|
|
|
-1);
|
|
|
|
|
gtk_tree_model_get (model, iter_b,
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_NAME, &name_b,
|
|
|
|
|
-1);
|
|
|
|
|
|
|
|
|
|
retval = g_utf8_collate (name_a, name_b);
|
|
|
|
|
|
|
|
|
|
g_free (name_a);
|
|
|
|
|
g_free (name_b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
update_hostname (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
|
|
|
|
GVariant *variant;
|
|
|
|
|
gsize len;
|
|
|
|
|
const gchar *hostname;
|
|
|
|
|
|
|
|
|
|
if (sidebar->hostnamed_proxy == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
variant = g_dbus_proxy_get_cached_property (sidebar->hostnamed_proxy,
|
|
|
|
|
"PrettyHostname");
|
|
|
|
|
if (variant == NULL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hostname = g_variant_get_string (variant, &len);
|
|
|
|
|
if (len > 0 &&
|
|
|
|
|
g_strcmp0 (sidebar->hostname, hostname) != 0) {
|
|
|
|
|
g_free (sidebar->hostname);
|
|
|
|
|
sidebar->hostname = g_strdup (hostname);
|
|
|
|
|
update_places (sidebar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_variant_unref (variant);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
hostname_proxy_new_cb (GObject *source_object,
|
|
|
|
|
GAsyncResult *res,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkPlacesSidebar *sidebar = user_data;
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
|
|
sidebar->hostnamed_proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
|
|
|
|
|
if (error != NULL) {
|
|
|
|
|
g_debug ("Failed to create D-Bus proxy: %s", error->message);
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_signal_connect_swapped (sidebar->hostnamed_proxy,
|
|
|
|
|
"g-properties-changed",
|
|
|
|
|
G_CALLBACK (update_hostname),
|
|
|
|
|
sidebar);
|
|
|
|
|
update_hostname (sidebar);
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-07 22:46:28 +00:00
|
|
|
|
static void
|
|
|
|
|
create_volume_monitor (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
|
|
|
|
g_assert (sidebar->volume_monitor == NULL);
|
|
|
|
|
|
|
|
|
|
sidebar->volume_monitor = g_volume_monitor_get ();
|
|
|
|
|
|
|
|
|
|
g_signal_connect_object (sidebar->volume_monitor, "volume_added",
|
|
|
|
|
G_CALLBACK (volume_added_callback), sidebar, 0);
|
|
|
|
|
g_signal_connect_object (sidebar->volume_monitor, "volume_removed",
|
|
|
|
|
G_CALLBACK (volume_removed_callback), sidebar, 0);
|
|
|
|
|
g_signal_connect_object (sidebar->volume_monitor, "volume_changed",
|
|
|
|
|
G_CALLBACK (volume_changed_callback), sidebar, 0);
|
|
|
|
|
g_signal_connect_object (sidebar->volume_monitor, "mount_added",
|
|
|
|
|
G_CALLBACK (mount_added_callback), sidebar, 0);
|
|
|
|
|
g_signal_connect_object (sidebar->volume_monitor, "mount_removed",
|
|
|
|
|
G_CALLBACK (mount_removed_callback), sidebar, 0);
|
|
|
|
|
g_signal_connect_object (sidebar->volume_monitor, "mount_changed",
|
|
|
|
|
G_CALLBACK (mount_changed_callback), sidebar, 0);
|
|
|
|
|
g_signal_connect_object (sidebar->volume_monitor, "drive_disconnected",
|
|
|
|
|
G_CALLBACK (drive_disconnected_callback), sidebar, 0);
|
|
|
|
|
g_signal_connect_object (sidebar->volume_monitor, "drive_connected",
|
|
|
|
|
G_CALLBACK (drive_connected_callback), sidebar, 0);
|
|
|
|
|
g_signal_connect_object (sidebar->volume_monitor, "drive_changed",
|
|
|
|
|
G_CALLBACK (drive_changed_callback), sidebar, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-03 14:44:46 +00:00
|
|
|
|
static void
|
|
|
|
|
bookmarks_changed_cb (gpointer data)
|
|
|
|
|
{
|
2011-10-06 14:20:32 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (data);
|
|
|
|
|
|
2011-10-03 14:44:46 +00:00
|
|
|
|
update_places (sidebar);
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-04 16:34:44 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
tree_view_button_press_callback (GtkWidget *tree_view,
|
|
|
|
|
GdkEventButton *event,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
GtkTreeViewColumn *column;
|
|
|
|
|
|
|
|
|
|
if (event->button == 1 && event->type == GDK_BUTTON_PRESS) {
|
|
|
|
|
if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (tree_view),
|
|
|
|
|
event->x, event->y,
|
|
|
|
|
&path,
|
|
|
|
|
&column,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL)) {
|
|
|
|
|
gtk_tree_view_row_activated (GTK_TREE_VIEW (tree_view), path, column);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
tree_view_set_activate_on_single_click (GtkTreeView *tree_view)
|
|
|
|
|
{
|
|
|
|
|
g_signal_connect (tree_view, "button_press_event",
|
|
|
|
|
G_CALLBACK (tree_view_button_press_callback),
|
|
|
|
|
NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
static void
|
2011-09-06 23:11:19 +00:00
|
|
|
|
gtk_places_sidebar_init (GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeView *tree_view;
|
|
|
|
|
GtkTreeViewColumn *col;
|
|
|
|
|
GtkCellRenderer *cell;
|
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
|
2012-10-29 17:52:34 +00:00
|
|
|
|
gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (sidebar)), GTK_STYLE_CLASS_SIDEBAR);
|
|
|
|
|
|
2011-09-07 22:46:28 +00:00
|
|
|
|
create_volume_monitor (sidebar);
|
2011-09-06 23:11:19 +00:00
|
|
|
|
|
2011-10-03 14:44:46 +00:00
|
|
|
|
sidebar->bookmarks_manager = _gtk_bookmarks_manager_new (bookmarks_changed_cb, sidebar);
|
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sidebar),
|
|
|
|
|
GTK_POLICY_NEVER,
|
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
|
|
|
|
gtk_scrolled_window_set_hadjustment (GTK_SCROLLED_WINDOW (sidebar), NULL);
|
|
|
|
|
gtk_scrolled_window_set_vadjustment (GTK_SCROLLED_WINDOW (sidebar), NULL);
|
|
|
|
|
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sidebar), GTK_SHADOW_IN);
|
|
|
|
|
|
|
|
|
|
gtk_style_context_set_junction_sides (gtk_widget_get_style_context (GTK_WIDGET (sidebar)),
|
|
|
|
|
GTK_JUNCTION_RIGHT | GTK_JUNCTION_LEFT);
|
|
|
|
|
|
|
|
|
|
/* tree view */
|
|
|
|
|
tree_view = GTK_TREE_VIEW (gtk_tree_view_new ());
|
|
|
|
|
gtk_tree_view_set_headers_visible (tree_view, FALSE);
|
|
|
|
|
|
|
|
|
|
col = GTK_TREE_VIEW_COLUMN (gtk_tree_view_column_new ());
|
|
|
|
|
|
|
|
|
|
/* initial padding */
|
|
|
|
|
cell = gtk_cell_renderer_text_new ();
|
|
|
|
|
gtk_tree_view_column_pack_start (col, cell, FALSE);
|
|
|
|
|
g_object_set (cell,
|
|
|
|
|
"xpad", 6,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
/* headings */
|
|
|
|
|
cell = gtk_cell_renderer_text_new ();
|
|
|
|
|
gtk_tree_view_column_pack_start (col, cell, FALSE);
|
|
|
|
|
gtk_tree_view_column_set_attributes (col, cell,
|
|
|
|
|
"text", PLACES_SIDEBAR_COLUMN_HEADING_TEXT,
|
|
|
|
|
NULL);
|
|
|
|
|
g_object_set (cell,
|
|
|
|
|
"weight", PANGO_WEIGHT_BOLD,
|
|
|
|
|
"weight-set", TRUE,
|
|
|
|
|
"ypad", 6,
|
|
|
|
|
"xpad", 0,
|
|
|
|
|
NULL);
|
|
|
|
|
gtk_tree_view_column_set_cell_data_func (col, cell,
|
|
|
|
|
heading_cell_renderer_func,
|
|
|
|
|
sidebar, NULL);
|
|
|
|
|
|
|
|
|
|
/* icon padding */
|
|
|
|
|
cell = gtk_cell_renderer_text_new ();
|
|
|
|
|
gtk_tree_view_column_pack_start (col, cell, FALSE);
|
|
|
|
|
gtk_tree_view_column_set_cell_data_func (col, cell,
|
|
|
|
|
padding_cell_renderer_func,
|
|
|
|
|
sidebar, NULL);
|
|
|
|
|
|
|
|
|
|
/* icon renderer */
|
|
|
|
|
cell = gtk_cell_renderer_pixbuf_new ();
|
2012-09-07 15:04:42 +00:00
|
|
|
|
g_object_set (cell, "follow-state", TRUE, NULL);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
gtk_tree_view_column_pack_start (col, cell, FALSE);
|
|
|
|
|
gtk_tree_view_column_set_attributes (col, cell,
|
2012-09-07 15:04:42 +00:00
|
|
|
|
"gicon", PLACES_SIDEBAR_COLUMN_GICON,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
NULL);
|
|
|
|
|
gtk_tree_view_column_set_cell_data_func (col, cell,
|
|
|
|
|
icon_cell_renderer_func,
|
|
|
|
|
sidebar, NULL);
|
|
|
|
|
|
|
|
|
|
/* eject text renderer */
|
|
|
|
|
cell = gtk_cell_renderer_text_new ();
|
|
|
|
|
gtk_tree_view_column_pack_start (col, cell, TRUE);
|
|
|
|
|
gtk_tree_view_column_set_attributes (col, cell,
|
|
|
|
|
"text", PLACES_SIDEBAR_COLUMN_NAME,
|
|
|
|
|
"visible", PLACES_SIDEBAR_COLUMN_EJECT,
|
|
|
|
|
NULL);
|
|
|
|
|
g_object_set (cell,
|
|
|
|
|
"ellipsize", PANGO_ELLIPSIZE_END,
|
|
|
|
|
"ellipsize-set", TRUE,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
/* eject icon renderer */
|
|
|
|
|
cell = gtk_cell_renderer_pixbuf_new ();
|
|
|
|
|
sidebar->eject_icon_cell_renderer = cell;
|
|
|
|
|
g_object_set (cell,
|
|
|
|
|
"mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE,
|
|
|
|
|
"stock-size", GTK_ICON_SIZE_MENU,
|
|
|
|
|
"xpad", EJECT_BUTTON_XPAD,
|
|
|
|
|
/* align right, because for some reason gtk+ expands
|
|
|
|
|
this even though we tell it not to. */
|
|
|
|
|
"xalign", 1.0,
|
2012-09-07 15:04:42 +00:00
|
|
|
|
"follow-state", TRUE,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
NULL);
|
|
|
|
|
gtk_tree_view_column_pack_start (col, cell, FALSE);
|
|
|
|
|
gtk_tree_view_column_set_attributes (col, cell,
|
|
|
|
|
"visible", PLACES_SIDEBAR_COLUMN_EJECT,
|
2012-09-07 15:04:42 +00:00
|
|
|
|
"gicon", PLACES_SIDEBAR_COLUMN_EJECT_GICON,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
/* normal text renderer */
|
|
|
|
|
cell = gtk_cell_renderer_text_new ();
|
|
|
|
|
gtk_tree_view_column_pack_start (col, cell, TRUE);
|
|
|
|
|
g_object_set (G_OBJECT (cell), "editable", FALSE, NULL);
|
|
|
|
|
gtk_tree_view_column_set_attributes (col, cell,
|
|
|
|
|
"text", PLACES_SIDEBAR_COLUMN_NAME,
|
|
|
|
|
"visible", PLACES_SIDEBAR_COLUMN_NO_EJECT,
|
|
|
|
|
"editable-set", PLACES_SIDEBAR_COLUMN_BOOKMARK,
|
|
|
|
|
NULL);
|
|
|
|
|
g_object_set (cell,
|
|
|
|
|
"ellipsize", PANGO_ELLIPSIZE_END,
|
|
|
|
|
"ellipsize-set", TRUE,
|
|
|
|
|
NULL);
|
|
|
|
|
|
2011-09-06 23:11:19 +00:00
|
|
|
|
g_signal_connect (cell, "edited",
|
2011-09-06 22:53:30 +00:00
|
|
|
|
G_CALLBACK (bookmarks_edited), sidebar);
|
2011-09-06 23:11:19 +00:00
|
|
|
|
g_signal_connect (cell, "editing-canceled",
|
2011-09-06 22:53:30 +00:00
|
|
|
|
G_CALLBACK (bookmarks_editing_canceled), sidebar);
|
|
|
|
|
|
|
|
|
|
/* this is required to align the eject buttons to the right */
|
2011-10-04 14:20:42 +00:00
|
|
|
|
gtk_tree_view_column_set_max_width (GTK_TREE_VIEW_COLUMN (col), 24);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
gtk_tree_view_append_column (tree_view, col);
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
sidebar->store = shortcuts_model_new (sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
gtk_tree_view_set_tooltip_column (tree_view, PLACES_SIDEBAR_COLUMN_TOOLTIP);
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sidebar->store),
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_NAME,
|
|
|
|
|
GTK_SORT_ASCENDING);
|
|
|
|
|
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (sidebar->store),
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_NAME,
|
|
|
|
|
places_sidebar_sort_func,
|
|
|
|
|
sidebar, NULL);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
gtk_tree_view_set_model (tree_view, GTK_TREE_MODEL (sidebar->store));
|
2011-09-06 22:53:30 +00:00
|
|
|
|
gtk_container_add (GTK_CONTAINER (sidebar), GTK_WIDGET (tree_view));
|
|
|
|
|
gtk_widget_show (GTK_WIDGET (tree_view));
|
2012-09-07 15:04:42 +00:00
|
|
|
|
gtk_tree_view_set_enable_search (tree_view, FALSE);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
gtk_widget_show (GTK_WIDGET (sidebar));
|
|
|
|
|
sidebar->tree_view = tree_view;
|
|
|
|
|
|
|
|
|
|
gtk_tree_view_set_search_column (tree_view, PLACES_SIDEBAR_COLUMN_NAME);
|
|
|
|
|
selection = gtk_tree_view_get_selection (tree_view);
|
|
|
|
|
gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE);
|
|
|
|
|
|
|
|
|
|
gtk_tree_selection_set_select_function (selection,
|
|
|
|
|
tree_selection_func,
|
|
|
|
|
sidebar,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
gtk_tree_view_enable_model_drag_source (GTK_TREE_VIEW (tree_view),
|
|
|
|
|
GDK_BUTTON1_MASK,
|
2011-09-28 14:28:47 +00:00
|
|
|
|
dnd_source_targets, G_N_ELEMENTS (dnd_source_targets),
|
2011-09-06 22:53:30 +00:00
|
|
|
|
GDK_ACTION_MOVE);
|
|
|
|
|
gtk_drag_dest_set (GTK_WIDGET (tree_view),
|
|
|
|
|
0,
|
2011-09-28 14:28:47 +00:00
|
|
|
|
dnd_drop_targets, G_N_ELEMENTS (dnd_drop_targets),
|
2011-09-06 22:53:30 +00:00
|
|
|
|
GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK);
|
|
|
|
|
|
|
|
|
|
g_signal_connect (tree_view, "key-press-event",
|
|
|
|
|
G_CALLBACK (bookmarks_key_press_event_cb), sidebar);
|
|
|
|
|
|
|
|
|
|
g_signal_connect (tree_view, "drag-motion",
|
|
|
|
|
G_CALLBACK (drag_motion_callback), sidebar);
|
|
|
|
|
g_signal_connect (tree_view, "drag-leave",
|
|
|
|
|
G_CALLBACK (drag_leave_callback), sidebar);
|
|
|
|
|
g_signal_connect (tree_view, "drag-data-received",
|
|
|
|
|
G_CALLBACK (drag_data_received_callback), sidebar);
|
|
|
|
|
g_signal_connect (tree_view, "drag-drop",
|
|
|
|
|
G_CALLBACK (drag_drop_callback), sidebar);
|
|
|
|
|
|
|
|
|
|
g_signal_connect (selection, "changed",
|
|
|
|
|
G_CALLBACK (bookmarks_selection_changed_cb), sidebar);
|
|
|
|
|
g_signal_connect (tree_view, "popup-menu",
|
|
|
|
|
G_CALLBACK (bookmarks_popup_menu_cb), sidebar);
|
|
|
|
|
g_signal_connect (tree_view, "button-release-event",
|
|
|
|
|
G_CALLBACK (bookmarks_button_release_event_cb), sidebar);
|
|
|
|
|
|
2011-10-04 16:34:44 +00:00
|
|
|
|
tree_view_set_activate_on_single_click (sidebar->tree_view);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
sidebar->hostname = g_strdup (_("Computer"));
|
|
|
|
|
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
|
|
|
|
|
G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES,
|
|
|
|
|
NULL,
|
|
|
|
|
"org.freedesktop.hostname1",
|
|
|
|
|
"/org/freedesktop/hostname1",
|
|
|
|
|
"org.freedesktop.hostname1",
|
|
|
|
|
NULL,
|
|
|
|
|
hostname_proxy_new_cb,
|
|
|
|
|
sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-09-06 23:11:19 +00:00
|
|
|
|
gtk_places_sidebar_dispose (GObject *object)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2011-09-06 23:11:19 +00:00
|
|
|
|
sidebar = GTK_PLACES_SIDEBAR (object);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
sidebar->tree_view = NULL;
|
|
|
|
|
|
|
|
|
|
g_free (sidebar->uri);
|
|
|
|
|
sidebar->uri = NULL;
|
|
|
|
|
|
|
|
|
|
free_drag_data (sidebar);
|
|
|
|
|
|
2011-10-03 14:44:46 +00:00
|
|
|
|
if (sidebar->bookmarks_manager != NULL) {
|
|
|
|
|
_gtk_bookmarks_manager_free (sidebar->bookmarks_manager);
|
|
|
|
|
sidebar->bookmarks_manager = NULL;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_clear_object (&sidebar->store);
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
|
|
|
|
if (sidebar->volume_monitor != NULL) {
|
|
|
|
|
g_signal_handlers_disconnect_by_func (sidebar->volume_monitor,
|
|
|
|
|
volume_added_callback, sidebar);
|
|
|
|
|
g_signal_handlers_disconnect_by_func (sidebar->volume_monitor,
|
|
|
|
|
volume_removed_callback, sidebar);
|
|
|
|
|
g_signal_handlers_disconnect_by_func (sidebar->volume_monitor,
|
|
|
|
|
volume_changed_callback, sidebar);
|
|
|
|
|
g_signal_handlers_disconnect_by_func (sidebar->volume_monitor,
|
|
|
|
|
mount_added_callback, sidebar);
|
|
|
|
|
g_signal_handlers_disconnect_by_func (sidebar->volume_monitor,
|
|
|
|
|
mount_removed_callback, sidebar);
|
|
|
|
|
g_signal_handlers_disconnect_by_func (sidebar->volume_monitor,
|
|
|
|
|
mount_changed_callback, sidebar);
|
|
|
|
|
g_signal_handlers_disconnect_by_func (sidebar->volume_monitor,
|
|
|
|
|
drive_disconnected_callback, sidebar);
|
|
|
|
|
g_signal_handlers_disconnect_by_func (sidebar->volume_monitor,
|
|
|
|
|
drive_connected_callback, sidebar);
|
|
|
|
|
g_signal_handlers_disconnect_by_func (sidebar->volume_monitor,
|
|
|
|
|
drive_changed_callback, sidebar);
|
|
|
|
|
|
|
|
|
|
g_clear_object (&sidebar->volume_monitor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_clear_object (&sidebar->hostnamed_proxy);
|
|
|
|
|
g_free (sidebar->hostname);
|
|
|
|
|
sidebar->hostname = NULL;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2011-09-06 23:11:19 +00:00
|
|
|
|
G_OBJECT_CLASS (gtk_places_sidebar_parent_class)->dispose (object);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-09-06 23:11:19 +00:00
|
|
|
|
gtk_places_sidebar_class_init (GtkPlacesSidebarClass *class)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2011-09-28 15:44:40 +00:00
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
|
|
2011-10-06 14:20:32 +00:00
|
|
|
|
gobject_class = (GObjectClass *) class;
|
2011-09-28 15:44:40 +00:00
|
|
|
|
|
|
|
|
|
gobject_class->dispose = gtk_places_sidebar_dispose;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GTK_WIDGET_CLASS (class)->style_set = gtk_places_sidebar_style_set;
|
2012-09-07 15:04:42 +00:00
|
|
|
|
GTK_WIDGET_CLASS (class)->focus = gtk_places_sidebar_focus;
|
2011-09-28 15:44:40 +00:00
|
|
|
|
|
2011-10-04 21:47:31 +00:00
|
|
|
|
/* FIXME: add docstrings for the signals */
|
|
|
|
|
|
2011-09-28 15:44:40 +00:00
|
|
|
|
places_sidebar_signals [LOCATION_SELECTED] =
|
|
|
|
|
g_signal_new (I_("location-selected"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkPlacesSidebarClass, location_selected),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
_gtk_marshal_VOID__OBJECT_ENUM,
|
|
|
|
|
G_TYPE_NONE, 2,
|
|
|
|
|
G_TYPE_OBJECT,
|
2012-09-06 01:13:25 +00:00
|
|
|
|
GTK_TYPE_PLACES_OPEN_MODE);
|
2011-10-03 16:51:46 +00:00
|
|
|
|
|
2012-10-22 23:21:17 +00:00
|
|
|
|
places_sidebar_signals [SHOW_FILE_PROPERTIES] =
|
|
|
|
|
g_signal_new (I_("show-file-properties"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkPlacesSidebarClass, show_file_properties),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
_gtk_marshal_VOID__OBJECT,
|
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
|
G_TYPE_OBJECT);
|
|
|
|
|
|
2012-09-11 20:44:29 +00:00
|
|
|
|
places_sidebar_signals [EMPTY_TRASH_REQUESTED] =
|
|
|
|
|
g_signal_new (I_("empty-trash-requested"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkPlacesSidebarClass, empty_trash_requested),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
_gtk_marshal_VOID__VOID,
|
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
2011-10-04 21:47:31 +00:00
|
|
|
|
places_sidebar_signals [SHOW_ERROR_MESSAGE] =
|
|
|
|
|
g_signal_new (I_("show-error-message"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkPlacesSidebarClass, show_error_message),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
_gtk_marshal_VOID__STRING_STRING,
|
|
|
|
|
G_TYPE_NONE, 2,
|
|
|
|
|
G_TYPE_STRING,
|
|
|
|
|
G_TYPE_STRING);
|
2012-12-03 23:09:57 +00:00
|
|
|
|
|
|
|
|
|
places_sidebar_signals [DRAG_ACTION_REQUESTED] =
|
|
|
|
|
g_signal_new (I_("drag-action-requested"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkPlacesSidebarClass, drag_action_requested),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
_gtk_marshal_VOID__OBJECT_STRING_POINTER_POINTER,
|
|
|
|
|
G_TYPE_NONE, 4,
|
|
|
|
|
GDK_TYPE_DRAG_CONTEXT,
|
|
|
|
|
G_TYPE_STRING,
|
|
|
|
|
G_TYPE_POINTER, /* FIXME: (GList *) is there something friendlier to language bindings? */
|
|
|
|
|
G_TYPE_POINTER /* FIXME: (inout int) is there something friendlier to language bindings? */);
|
2012-12-04 00:15:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
places_sidebar_signals [DRAG_ACTION_ASK] =
|
|
|
|
|
g_signal_new (I_("drag-action-ask"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
2012-12-04 23:37:45 +00:00
|
|
|
|
G_SIGNAL_RUN_LAST,
|
2012-12-04 00:15:41 +00:00
|
|
|
|
G_STRUCT_OFFSET (GtkPlacesSidebarClass, drag_action_ask),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
_gtk_marshal_INT__INT,
|
|
|
|
|
G_TYPE_INT, 1,
|
|
|
|
|
G_TYPE_INT);
|
2012-12-04 18:44:46 +00:00
|
|
|
|
|
|
|
|
|
places_sidebar_signals [DRAG_ACTION_ASK] =
|
|
|
|
|
g_signal_new (I_("drag-perform-drop"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkPlacesSidebarClass, drag_perform_drop),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
_gtk_marshal_VOID__POINTER_STRING_INT,
|
|
|
|
|
G_TYPE_NONE, 3,
|
|
|
|
|
G_TYPE_POINTER, /* FIXME: (GList *) is there something friendlier to language bindings? */
|
|
|
|
|
G_TYPE_STRING,
|
|
|
|
|
G_TYPE_INT);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-09-06 23:11:19 +00:00
|
|
|
|
gtk_places_sidebar_style_set (GtkWidget *widget,
|
2011-09-06 22:53:30 +00:00
|
|
|
|
GtkStyle *previous_style)
|
|
|
|
|
{
|
2011-09-06 23:11:19 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2011-09-06 23:11:19 +00:00
|
|
|
|
sidebar = GTK_PLACES_SIDEBAR (widget);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
update_places (sidebar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GtkWidget *
|
2011-09-07 22:40:49 +00:00
|
|
|
|
gtk_places_sidebar_new (void)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2011-09-07 22:40:49 +00:00
|
|
|
|
return GTK_WIDGET (g_object_new (gtk_places_sidebar_get_type (), NULL));
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
/* Drag and drop interfaces */
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
/* GtkTreeDragSource::row_draggable implementation for the shortcuts model */
|
2011-09-06 22:53:30 +00:00
|
|
|
|
static gboolean
|
2012-09-07 15:04:42 +00:00
|
|
|
|
shortcuts_model_row_draggable (GtkTreeDragSource *drag_source,
|
|
|
|
|
GtkTreePath *path)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
PlaceType place_type;
|
|
|
|
|
SectionType section_type;
|
|
|
|
|
|
|
|
|
|
model = GTK_TREE_MODEL (drag_source);
|
|
|
|
|
|
|
|
|
|
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, §ion_type,
|
|
|
|
|
-1);
|
|
|
|
|
|
|
|
|
|
if (place_type != PLACES_HEADING && section_type == SECTION_BOOKMARKS)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Fill the GtkTreeDragSourceIface vtable */
|
|
|
|
|
static void
|
2012-09-07 15:04:42 +00:00
|
|
|
|
shortcuts_model_class_init (ShortcutsModelClass *klass)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
static void
|
|
|
|
|
shortcuts_model_init (ShortcutsModel *model)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2012-09-07 15:04:42 +00:00
|
|
|
|
model->sidebar = NULL;
|
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
static void
|
|
|
|
|
shortcuts_model_drag_source_iface_init (GtkTreeDragSourceIface *iface)
|
|
|
|
|
{
|
|
|
|
|
iface->row_draggable = shortcuts_model_row_draggable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GtkListStore *
|
|
|
|
|
shortcuts_model_new (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
|
|
|
|
ShortcutsModel *model;
|
|
|
|
|
GType model_types[PLACES_SIDEBAR_COLUMN_COUNT] = {
|
|
|
|
|
G_TYPE_INT,
|
|
|
|
|
G_TYPE_STRING,
|
|
|
|
|
G_TYPE_DRIVE,
|
|
|
|
|
G_TYPE_VOLUME,
|
|
|
|
|
G_TYPE_MOUNT,
|
|
|
|
|
G_TYPE_STRING,
|
|
|
|
|
G_TYPE_ICON,
|
|
|
|
|
G_TYPE_INT,
|
|
|
|
|
G_TYPE_BOOLEAN,
|
|
|
|
|
G_TYPE_BOOLEAN,
|
|
|
|
|
G_TYPE_BOOLEAN,
|
|
|
|
|
G_TYPE_STRING,
|
|
|
|
|
G_TYPE_ICON,
|
|
|
|
|
G_TYPE_INT,
|
|
|
|
|
G_TYPE_STRING
|
|
|
|
|
};
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
model = g_object_new (shortcuts_model_get_type (), NULL);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
model->sidebar = sidebar;
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
gtk_list_store_set_column_types (GTK_LIST_STORE (model),
|
|
|
|
|
PLACES_SIDEBAR_COLUMN_COUNT,
|
|
|
|
|
model_types);
|
|
|
|
|
|
|
|
|
|
return GTK_LIST_STORE (model);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
2011-09-07 22:55:21 +00:00
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Public methods for GtkPlacesSidebar */
|
|
|
|
|
|
2011-09-07 22:55:21 +00:00
|
|
|
|
/**
|
2012-11-24 16:41:11 +00:00
|
|
|
|
* gtk_places_sidebar_set_current_location:
|
2011-09-07 22:55:21 +00:00
|
|
|
|
* @sidebar: a places sidebar
|
2012-11-24 16:41:11 +00:00
|
|
|
|
* @location: location to select, or #NULL for no current path
|
2011-09-07 22:55:21 +00:00
|
|
|
|
*
|
2012-11-24 16:41:11 +00:00
|
|
|
|
* Sets the location that is being shown in the widgets surrounding the @sidebar. In turn,
|
|
|
|
|
* it will highlight that location if it is being shown in the list of places, or it will
|
|
|
|
|
* unhighlight everything if the location is not among the places in the list.
|
2011-09-07 22:55:21 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
2012-11-24 16:41:11 +00:00
|
|
|
|
gtk_places_sidebar_set_current_location (GtkPlacesSidebar *sidebar, GFile *location)
|
2011-09-07 22:55:21 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
gboolean valid;
|
|
|
|
|
char *iter_uri;
|
2012-11-24 16:41:11 +00:00
|
|
|
|
char *uri;
|
2011-09-07 22:55:21 +00:00
|
|
|
|
|
2011-09-30 13:10:57 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
|
|
|
|
|
|
|
|
|
|
selection = gtk_tree_view_get_selection (sidebar->tree_view);
|
|
|
|
|
|
2012-11-24 16:41:11 +00:00
|
|
|
|
if (location == NULL) {
|
2011-09-30 13:10:57 +00:00
|
|
|
|
g_free (sidebar->uri);
|
|
|
|
|
sidebar->uri = NULL;
|
|
|
|
|
|
|
|
|
|
gtk_tree_selection_unselect_all (selection);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-24 16:41:11 +00:00
|
|
|
|
uri = g_file_get_uri (location);
|
|
|
|
|
|
2011-09-30 13:10:57 +00:00
|
|
|
|
if (sidebar->uri == NULL || strcmp (sidebar->uri, uri) != 0) {
|
2011-09-07 22:55:21 +00:00
|
|
|
|
g_free (sidebar->uri);
|
|
|
|
|
sidebar->uri = g_strdup (uri);
|
|
|
|
|
|
|
|
|
|
/* set selection if any place matches the uri */
|
|
|
|
|
gtk_tree_selection_unselect_all (selection);
|
2012-09-07 15:04:42 +00:00
|
|
|
|
valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (sidebar->store), &iter);
|
2011-09-07 22:55:21 +00:00
|
|
|
|
|
|
|
|
|
while (valid) {
|
2012-09-07 15:04:42 +00:00
|
|
|
|
gtk_tree_model_get (GTK_TREE_MODEL (sidebar->store), &iter,
|
2011-09-07 22:55:21 +00:00
|
|
|
|
PLACES_SIDEBAR_COLUMN_URI, &iter_uri,
|
|
|
|
|
-1);
|
|
|
|
|
if (iter_uri != NULL) {
|
|
|
|
|
if (strcmp (iter_uri, uri) == 0) {
|
|
|
|
|
g_free (iter_uri);
|
|
|
|
|
gtk_tree_selection_select_iter (selection, &iter);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
g_free (iter_uri);
|
|
|
|
|
}
|
2012-09-07 15:04:42 +00:00
|
|
|
|
valid = gtk_tree_model_iter_next (GTK_TREE_MODEL (sidebar->store), &iter);
|
2011-09-07 22:55:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-11-24 16:41:11 +00:00
|
|
|
|
|
|
|
|
|
g_free (uri);
|
2011-09-07 22:55:21 +00:00
|
|
|
|
}
|
2011-10-04 14:22:11 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_places_sidebar_set_multiple_tabs_supported:
|
|
|
|
|
* @sidebar: a places sidebar
|
|
|
|
|
* @supported: whether the appliacation supports multiple notebook tabs for file browsing
|
|
|
|
|
*
|
2011-10-04 14:47:41 +00:00
|
|
|
|
* Sets whether the calling appliacation supports multiple tabs for file
|
|
|
|
|
* browsing; this is off by default. When @supported is #TRUE, the context menu
|
|
|
|
|
* for the @sidebar's items will show items relevant to opening folders in new
|
|
|
|
|
* tabs.
|
2011-10-04 14:22:11 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_places_sidebar_set_multiple_tabs_supported (GtkPlacesSidebar *sidebar, gboolean supported)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
|
|
|
|
|
|
|
|
|
|
sidebar->multiple_tabs_supported = !!supported;
|
2011-10-06 14:20:32 +00:00
|
|
|
|
bookmarks_popup_menu_detach_cb (GTK_WIDGET (sidebar), NULL);
|
2011-10-04 14:22:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_places_sidebar_set_multiple_windows_supported:
|
|
|
|
|
* @sidebar: a places sidebar
|
|
|
|
|
* @supported: whether the appliacation supports multiple windows for file browsing
|
|
|
|
|
*
|
2011-10-04 14:47:41 +00:00
|
|
|
|
* Sets whether the calling appliacation supports multiple windows for file
|
|
|
|
|
* browsing; this is off by default. When @supported is #TRUE, the context menu
|
|
|
|
|
* for the @sidebar's items will show items relevant to opening folders in new
|
|
|
|
|
* windows.
|
2011-10-04 14:22:11 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_places_sidebar_set_multiple_windows_supported (GtkPlacesSidebar *sidebar, gboolean supported)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
|
|
|
|
|
|
|
|
|
|
sidebar->multiple_windows_supported = !!supported;
|
2011-10-06 14:20:32 +00:00
|
|
|
|
bookmarks_popup_menu_detach_cb (GTK_WIDGET (sidebar), NULL);
|
2011-10-04 14:22:11 +00:00
|
|
|
|
}
|
2011-10-04 14:47:41 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_places_sidebar_set_show_desktop:
|
|
|
|
|
* @sidebar: a places sidebar
|
|
|
|
|
* @show_desktop: whether to show an item for the Desktop folder
|
|
|
|
|
*
|
|
|
|
|
* Sets whether the @sidebar should show an item for the Desktop folder; this is off by default.
|
|
|
|
|
* An application may want to turn this on if the desktop environment actually supports the
|
|
|
|
|
* notion of a desktop.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_places_sidebar_set_show_desktop (GtkPlacesSidebar *sidebar, gboolean show_desktop)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
|
|
|
|
|
|
|
|
|
|
sidebar->show_desktop = !!show_desktop;
|
|
|
|
|
update_places (sidebar);
|
|
|
|
|
}
|
2012-09-11 19:33:47 +00:00
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gtk_places_sidebar_set_show_properties (GtkPlacesSidebar *sidebar, gboolean show_properties)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
|
|
|
|
|
|
|
|
|
|
sidebar->show_properties = !!show_properties;
|
2012-11-21 19:13:01 +00:00
|
|
|
|
check_popup_sensitivity (sidebar);
|
2012-09-11 19:33:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gtk_places_sidebar_set_show_trash (GtkPlacesSidebar *sidebar, gboolean show_trash)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
|
|
|
|
|
|
|
|
|
|
sidebar->show_trash = !!show_trash;
|
|
|
|
|
update_places (sidebar);
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-11 20:44:29 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_places_sidebar_set_trash_is_full (GtkPlacesSidebar *sidebar, gboolean is_full)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
|
|
|
|
|
|
|
|
|
|
sidebar->trash_is_full = !!is_full;
|
|
|
|
|
update_places (sidebar);
|
2012-11-21 19:13:01 +00:00
|
|
|
|
check_popup_sensitivity (sidebar);
|
2012-09-11 20:44:29 +00:00
|
|
|
|
}
|
2012-11-21 02:04:20 +00:00
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gtk_places_sidebar_set_show_cwd (GtkPlacesSidebar *sidebar, gboolean show_cwd)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
|
|
|
|
|
|
|
|
|
|
sidebar->show_cwd = !!show_cwd;
|
|
|
|
|
update_places (sidebar);
|
|
|
|
|
}
|
2012-12-04 18:57:48 +00:00
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gtk_places_sidebar_set_accept_uri_drops (GtkPlacesSidebar *sidebar, gboolean accept_uri_drops)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
|
|
|
|
|
|
|
|
|
|
sidebar->accept_uri_drops = !!accept_uri_drops;
|
|
|
|
|
}
|