2015-11-19 12:06:54 +00:00
|
|
|
|
/* GtkPlacesSidebar - sidebar widget for places in the filesystem
|
2011-09-07 20:17:26 +00:00
|
|
|
|
*
|
2015-11-19 12:06:54 +00:00
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
2011-09-06 22:53:30 +00:00
|
|
|
|
*
|
2015-11-19 12:06:54 +00:00
|
|
|
|
* 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
|
|
|
|
|
* Lesser General Public License for more details.
|
2011-09-06 22:53:30 +00:00
|
|
|
|
*
|
2015-11-19 12:06:54 +00:00
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2011-09-06 22:53:30 +00:00
|
|
|
|
*
|
2015-11-19 12:06:54 +00:00
|
|
|
|
* This code is originally from Nautilus.
|
2011-09-06 22:53:30 +00:00
|
|
|
|
*
|
2015-11-19 12:06:54 +00:00
|
|
|
|
* Authors : Mr Jamie McCracken (jamiemcc at blueyonder dot co dot uk)
|
|
|
|
|
* Cosimo Cecchi <cosimoc@gnome.org>
|
|
|
|
|
* Federico Mena Quintero <federico@gnome.org>
|
|
|
|
|
* Carlos Soriano <csoriano@gnome.org>
|
2011-09-06 22:53:30 +00:00
|
|
|
|
*/
|
2011-09-06 23:11:19 +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>
|
2017-08-10 20:30:36 +00:00
|
|
|
|
#ifdef HAVE_CLOUDPROVIDERS
|
2017-10-30 20:38:41 +00:00
|
|
|
|
#include <cloudproviders/cloudproviderscollector.h>
|
|
|
|
|
#include <cloudproviders/cloudprovidersaccount.h>
|
|
|
|
|
#include <cloudproviders/cloudprovidersprovider.h>
|
2017-08-10 20:30:36 +00:00
|
|
|
|
#endif
|
2011-10-06 14:20:32 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
#include "gtkplacessidebarprivate.h"
|
|
|
|
|
#include "gtksidebarrowprivate.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"
|
2013-10-03 16:30:39 +00:00
|
|
|
|
#include "gtkfilesystem.h"
|
2011-10-06 14:20:32 +00:00
|
|
|
|
#include "gtkicontheme.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 "gtkscrolledwindow.h"
|
2011-10-06 14:20:32 +00:00
|
|
|
|
#include "gtkseparatormenuitem.h"
|
2012-09-04 02:04:26 +00:00
|
|
|
|
#include "gtksettings.h"
|
2013-01-10 21:06:01 +00:00
|
|
|
|
#include "gtktrashmonitor.h"
|
2012-09-06 01:13:25 +00:00
|
|
|
|
#include "gtktypebuiltins.h"
|
2015-05-02 06:42:25 +00:00
|
|
|
|
#include "gtkpopover.h"
|
|
|
|
|
#include "gtkgrid.h"
|
|
|
|
|
#include "gtklabel.h"
|
|
|
|
|
#include "gtkbutton.h"
|
2015-05-06 21:07:17 +00:00
|
|
|
|
#include "gtklistbox.h"
|
|
|
|
|
#include "gtkselection.h"
|
2015-12-13 23:43:10 +00:00
|
|
|
|
#include "gtkdragdest.h"
|
2015-05-06 21:07:17 +00:00
|
|
|
|
#include "gtkdnd.h"
|
|
|
|
|
#include "gtkseparator.h"
|
|
|
|
|
#include "gtkentry.h"
|
2015-07-16 01:25:10 +00:00
|
|
|
|
#include "gtkgesturelongpress.h"
|
|
|
|
|
#include "gtkbox.h"
|
|
|
|
|
#include "gtkmodelbutton.h"
|
2017-11-18 13:18:11 +00:00
|
|
|
|
#include "gtkprivate.h"
|
2018-03-05 17:50:35 +00:00
|
|
|
|
#include "gtkeventcontrollerkey.h"
|
2019-05-29 17:10:46 +00:00
|
|
|
|
#include "gtkgestureclick.h"
|
2018-06-08 09:29:59 +00:00
|
|
|
|
#include "gtkgesturedrag.h"
|
2019-05-04 18:44:51 +00:00
|
|
|
|
#include "gtknative.h"
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2018-02-01 15:08:51 +00:00
|
|
|
|
/*< private >
|
|
|
|
|
* SECTION:gtkplacessidebar
|
|
|
|
|
* @Title: GtkPlacesSidebar
|
|
|
|
|
* @Short_description: The locations sidebar for the file selection widget
|
|
|
|
|
*
|
2013-01-18 23:18:25 +00:00
|
|
|
|
* #GtkPlacesSidebar is a widget that displays a list of frequently-used places in the
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* file system: the user’s home directory, the user’s bookmarks, and volumes and drives.
|
2013-01-18 23:18:25 +00:00
|
|
|
|
* This widget is used as a sidebar in #GtkFileChooser and may be used by file managers
|
|
|
|
|
* and similar programs.
|
|
|
|
|
*
|
|
|
|
|
* The places sidebar displays drives and volumes, and will automatically mount
|
|
|
|
|
* or unmount them when the user selects them.
|
|
|
|
|
*
|
|
|
|
|
* Applications can hook to various signals in the places sidebar to customize
|
|
|
|
|
* its behavior. For example, they can add extra commands to the context menu
|
|
|
|
|
* of the sidebar.
|
|
|
|
|
*
|
|
|
|
|
* While bookmarks are completely in control of the user, the places sidebar also
|
|
|
|
|
* allows individual applications to provide extra shortcut folders that are unique
|
|
|
|
|
* to each application. For example, a Paint program may want to add a shortcut
|
2013-01-19 01:28:58 +00:00
|
|
|
|
* for a Clipart folder. You can do this with gtk_places_sidebar_add_shortcut().
|
2013-01-18 23:18:25 +00:00
|
|
|
|
*
|
|
|
|
|
* To make use of the places sidebar, an application at least needs to connect
|
|
|
|
|
* to the #GtkPlacesSidebar::open-location signal. This is emitted when the
|
|
|
|
|
* user selects in the sidebar a location to open. The application should also
|
|
|
|
|
* call gtk_places_sidebar_set_location() when it changes the currently-viewed
|
|
|
|
|
* location.
|
2015-11-05 15:36:17 +00:00
|
|
|
|
*
|
|
|
|
|
* # CSS nodes
|
|
|
|
|
*
|
2017-03-02 13:05:46 +00:00
|
|
|
|
* GtkPlacesSidebar uses a single CSS node with name placessidebar and style
|
2015-11-05 15:36:17 +00:00
|
|
|
|
* class .sidebar.
|
2015-11-05 15:51:54 +00:00
|
|
|
|
*
|
|
|
|
|
* Among the children of the places sidebar, the following style classes can
|
|
|
|
|
* be used:
|
|
|
|
|
* - .sidebar-new-bookmark-row for the 'Add new bookmark' row
|
|
|
|
|
* - .sidebar-placeholder-row for a row that is a placeholder
|
|
|
|
|
* - .has-open-popup when a popup is open for a row
|
2013-01-18 23:18:25 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
/* These are used when a destination-side DND operation is taking place.
|
2015-06-11 16:55:24 +00:00
|
|
|
|
* Normally, when a common drag action is taking place, the state will be
|
|
|
|
|
* DROP_STATE_NEW_BOOKMARK_ARMED, however, if the client of GtkPlacesSidebar
|
|
|
|
|
* wants to show hints about the valid targets, we sill set it as
|
|
|
|
|
* DROP_STATE_NEW_BOOKMARK_ARMED_PERMANENT, so the sidebar will show drop hints
|
|
|
|
|
* until the client says otherwise
|
2013-04-19 16:00:36 +00:00
|
|
|
|
*/
|
|
|
|
|
typedef enum {
|
2013-11-09 22:28:02 +00:00
|
|
|
|
DROP_STATE_NORMAL,
|
|
|
|
|
DROP_STATE_NEW_BOOKMARK_ARMED,
|
2015-04-11 15:35:23 +00:00
|
|
|
|
DROP_STATE_NEW_BOOKMARK_ARMED_PERMANENT,
|
2013-04-19 16:00:36 +00:00
|
|
|
|
} DropState;
|
|
|
|
|
|
2011-09-07 19:58:19 +00:00
|
|
|
|
struct _GtkPlacesSidebar {
|
2019-05-28 22:11:14 +00:00
|
|
|
|
GtkWidget parent;
|
2013-01-10 21:06:01 +00:00
|
|
|
|
|
2019-05-28 22:11:14 +00:00
|
|
|
|
GtkWidget *swin;
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GtkWidget *list_box;
|
|
|
|
|
GtkWidget *new_bookmark_row;
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GtkBookmarksManager *bookmarks_manager;
|
2017-09-18 23:14:41 +00:00
|
|
|
|
|
2019-06-15 22:25:05 +00:00
|
|
|
|
GActionGroup *row_actions;
|
|
|
|
|
|
2017-08-10 20:30:36 +00:00
|
|
|
|
#ifdef HAVE_CLOUDPROVIDERS
|
2017-10-30 20:38:41 +00:00
|
|
|
|
CloudProvidersCollector *cloud_manager;
|
|
|
|
|
GList *unready_accounts;
|
2017-08-10 20:30:36 +00:00
|
|
|
|
#endif
|
2017-09-18 23:14:41 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GVolumeMonitor *volume_monitor;
|
|
|
|
|
GtkTrashMonitor *trash_monitor;
|
2013-11-14 20:02:00 +00:00
|
|
|
|
GtkSettings *gtk_settings;
|
2014-10-07 10:22:38 +00:00
|
|
|
|
GFile *current_location;
|
2013-01-10 21:06:01 +00:00
|
|
|
|
|
2015-05-02 06:42:25 +00:00
|
|
|
|
GtkWidget *rename_popover;
|
|
|
|
|
GtkWidget *rename_entry;
|
|
|
|
|
GtkWidget *rename_button;
|
|
|
|
|
GtkWidget *rename_error;
|
|
|
|
|
gchar *rename_uri;
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
gulong trash_monitor_changed_id;
|
2016-02-25 13:25:40 +00:00
|
|
|
|
GtkWidget *trash_row;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
/* DND */
|
|
|
|
|
GList *drag_list; /* list of GFile */
|
|
|
|
|
gint drag_data_info;
|
2015-04-11 15:35:23 +00:00
|
|
|
|
gboolean dragging_over;
|
2017-11-18 01:19:53 +00:00
|
|
|
|
GdkContentFormats *source_targets;
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GtkWidget *drag_row;
|
|
|
|
|
gint drag_row_height;
|
|
|
|
|
gint drag_row_x;
|
|
|
|
|
gint drag_row_y;
|
|
|
|
|
GtkWidget *row_placeholder;
|
|
|
|
|
DropState drop_state;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
/* volume mounting - delayed open process */
|
|
|
|
|
GtkPlacesOpenFlags go_to_after_mount_open_flags;
|
2014-09-04 03:29:51 +00:00
|
|
|
|
GCancellable *cancellable;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
GtkWidget *popover;
|
|
|
|
|
GtkSidebarRow *context_row;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GSList *shortcuts;
|
2012-12-07 19:42:39 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GDBusProxy *hostnamed_proxy;
|
|
|
|
|
GCancellable *hostnamed_cancellable;
|
|
|
|
|
gchar *hostname;
|
2011-10-04 14:22:11 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GtkPlacesOpenFlags open_flags;
|
2013-01-10 22:19:03 +00:00
|
|
|
|
|
2017-08-10 20:30:36 +00:00
|
|
|
|
GActionGroup *action_group;
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
guint mounting : 1;
|
|
|
|
|
guint drag_data_received : 1;
|
2016-03-11 03:46:02 +00:00
|
|
|
|
guint drop_occurred : 1;
|
2015-06-06 21:13:22 +00:00
|
|
|
|
guint show_recent_set : 1;
|
|
|
|
|
guint show_recent : 1;
|
2013-11-14 20:02:00 +00:00
|
|
|
|
guint show_desktop_set : 1;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
guint show_desktop : 1;
|
2014-04-07 22:43:28 +00:00
|
|
|
|
guint show_enter_location : 1;
|
2015-07-14 17:47:42 +00:00
|
|
|
|
guint show_other_locations : 1;
|
2015-07-03 16:49:00 +00:00
|
|
|
|
guint show_trash : 1;
|
2017-07-20 15:29:42 +00:00
|
|
|
|
guint show_starred_location : 1;
|
2013-11-09 23:28:12 +00:00
|
|
|
|
guint local_only : 1;
|
2015-07-16 23:27:01 +00:00
|
|
|
|
guint populate_all : 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 {
|
2019-05-28 22:11:14 +00:00
|
|
|
|
GtkWidgetClass parent_class;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
|
|
|
|
void (* open_location) (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GFile *location,
|
|
|
|
|
GtkPlacesOpenFlags open_flags);
|
|
|
|
|
void (* populate_popup) (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GtkMenu *menu,
|
|
|
|
|
GFile *selected_item,
|
|
|
|
|
GVolume *selected_volume);
|
|
|
|
|
void (* show_error_message) (GtkPlacesSidebar *sidebar,
|
|
|
|
|
const gchar *primary,
|
|
|
|
|
const gchar *secondary);
|
|
|
|
|
GdkDragAction (* drag_action_requested) (GtkPlacesSidebar *sidebar,
|
2018-06-29 17:34:14 +00:00
|
|
|
|
GdkDrag *drag,
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GFile *dest_file,
|
|
|
|
|
GList *source_file_list);
|
|
|
|
|
GdkDragAction (* drag_action_ask) (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GdkDragAction actions);
|
|
|
|
|
void (* drag_perform_drop) (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GFile *dest_file,
|
|
|
|
|
GList *source_file_list,
|
|
|
|
|
GdkDragAction action);
|
2014-04-07 22:43:28 +00:00
|
|
|
|
void (* show_enter_location) (GtkPlacesSidebar *sidebar);
|
2015-07-14 17:47:42 +00:00
|
|
|
|
|
2016-02-29 22:13:51 +00:00
|
|
|
|
void (* show_other_locations_with_flags) (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GtkPlacesOpenFlags open_flags);
|
|
|
|
|
|
2017-07-20 15:29:42 +00:00
|
|
|
|
void (* show_starred_location) (GtkPlacesSidebar *sidebar);
|
|
|
|
|
|
2016-02-15 18:09:54 +00:00
|
|
|
|
void (* mount) (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GMountOperation *mount_operation);
|
|
|
|
|
void (* unmount) (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GMountOperation *unmount_operation);
|
2011-09-07 19:58:19 +00:00
|
|
|
|
};
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2011-09-28 15:44:40 +00:00
|
|
|
|
enum {
|
2013-11-09 22:28:02 +00:00
|
|
|
|
OPEN_LOCATION,
|
|
|
|
|
SHOW_ERROR_MESSAGE,
|
2014-04-07 22:43:28 +00:00
|
|
|
|
SHOW_ENTER_LOCATION,
|
2013-11-09 22:28:02 +00:00
|
|
|
|
DRAG_ACTION_REQUESTED,
|
|
|
|
|
DRAG_ACTION_ASK,
|
|
|
|
|
DRAG_PERFORM_DROP,
|
2016-02-29 22:13:51 +00:00
|
|
|
|
SHOW_OTHER_LOCATIONS_WITH_FLAGS,
|
2017-07-20 15:29:42 +00:00
|
|
|
|
SHOW_STARRED_LOCATION,
|
2016-02-15 18:09:54 +00:00
|
|
|
|
MOUNT,
|
|
|
|
|
UNMOUNT,
|
2013-11-09 22:28:02 +00:00
|
|
|
|
LAST_SIGNAL
|
2011-09-28 15:44:40 +00:00
|
|
|
|
};
|
|
|
|
|
|
2013-01-21 23:21:00 +00:00
|
|
|
|
enum {
|
2013-11-09 22:28:02 +00:00
|
|
|
|
PROP_LOCATION = 1,
|
|
|
|
|
PROP_OPEN_FLAGS,
|
2015-06-06 21:13:22 +00:00
|
|
|
|
PROP_SHOW_RECENT,
|
2013-11-09 22:28:02 +00:00
|
|
|
|
PROP_SHOW_DESKTOP,
|
2014-04-07 22:43:28 +00:00
|
|
|
|
PROP_SHOW_ENTER_LOCATION,
|
2015-07-03 16:49:00 +00:00
|
|
|
|
PROP_SHOW_TRASH,
|
2017-07-20 15:29:42 +00:00
|
|
|
|
PROP_SHOW_STARRED_LOCATION,
|
2013-11-09 23:28:12 +00:00
|
|
|
|
PROP_LOCAL_ONLY,
|
2015-07-14 17:47:42 +00:00
|
|
|
|
PROP_SHOW_OTHER_LOCATIONS,
|
2013-11-09 22:28:02 +00:00
|
|
|
|
NUM_PROPERTIES
|
2013-01-21 23:21:00 +00:00
|
|
|
|
};
|
|
|
|
|
|
2011-10-04 13:14:33 +00:00
|
|
|
|
/* Names for themed icons */
|
2013-11-09 22:28:02 +00:00
|
|
|
|
#define ICON_NAME_HOME "user-home-symbolic"
|
2013-12-01 18:58:39 +00:00
|
|
|
|
#define ICON_NAME_DESKTOP "user-desktop-symbolic"
|
2013-11-09 22:28:02 +00:00
|
|
|
|
#define ICON_NAME_FILESYSTEM "drive-harddisk-symbolic"
|
|
|
|
|
#define ICON_NAME_EJECT "media-eject-symbolic"
|
|
|
|
|
#define ICON_NAME_NETWORK "network-workgroup-symbolic"
|
2013-04-20 23:14:59 +00:00
|
|
|
|
#define ICON_NAME_NETWORK_SERVER "network-server-symbolic"
|
2013-11-06 18:12:03 +00:00
|
|
|
|
#define ICON_NAME_FOLDER_NETWORK "folder-remote-symbolic"
|
2015-07-14 17:47:42 +00:00
|
|
|
|
#define ICON_NAME_OTHER_LOCATIONS "list-add-symbolic"
|
2011-10-04 13:14:33 +00:00
|
|
|
|
|
2013-11-06 18:12:03 +00:00
|
|
|
|
#define ICON_NAME_FOLDER "folder-symbolic"
|
2013-12-01 18:58:39 +00:00
|
|
|
|
#define ICON_NAME_FOLDER_DESKTOP "user-desktop-symbolic"
|
2013-11-09 22:28:02 +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
|
|
|
|
|
2011-10-06 14:20:32 +00:00
|
|
|
|
static guint places_sidebar_signals [LAST_SIGNAL] = { 0 };
|
2013-01-21 23:21:00 +00:00
|
|
|
|
static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
|
2011-09-28 15:44:40 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
static gboolean eject_or_unmount_bookmark (GtkSidebarRow *row);
|
|
|
|
|
static gboolean eject_or_unmount_selection (GtkPlacesSidebar *sidebar);
|
|
|
|
|
static void check_unmount_and_eject (GMount *mount,
|
|
|
|
|
GVolume *volume,
|
|
|
|
|
GDrive *drive,
|
|
|
|
|
gboolean *show_unmount,
|
|
|
|
|
gboolean *show_eject);
|
2019-05-29 17:10:46 +00:00
|
|
|
|
static void on_row_pressed (GtkGestureClick *gesture,
|
2018-06-08 09:29:59 +00:00
|
|
|
|
gint n_press,
|
|
|
|
|
gdouble x,
|
|
|
|
|
gdouble y,
|
|
|
|
|
GtkSidebarRow *row);
|
2019-05-29 17:10:46 +00:00
|
|
|
|
static void on_row_released (GtkGestureClick *gesture,
|
2018-06-08 09:29:59 +00:00
|
|
|
|
gint n_press,
|
|
|
|
|
gdouble x,
|
|
|
|
|
gdouble y,
|
|
|
|
|
GtkSidebarRow *row);
|
|
|
|
|
static void on_row_dragged (GtkGestureDrag *gesture,
|
|
|
|
|
gdouble x,
|
|
|
|
|
gdouble y,
|
|
|
|
|
GtkSidebarRow *row);
|
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
static void popup_menu_cb (GtkSidebarRow *row);
|
|
|
|
|
static void long_press_cb (GtkGesture *gesture,
|
|
|
|
|
gdouble x,
|
|
|
|
|
gdouble y,
|
|
|
|
|
GtkPlacesSidebar *sidebar);
|
2015-05-06 21:07:17 +00:00
|
|
|
|
static void stop_drop_feedback (GtkPlacesSidebar *sidebar);
|
2016-02-15 18:09:54 +00:00
|
|
|
|
static GMountOperation * get_mount_operation (GtkPlacesSidebar *sidebar);
|
|
|
|
|
static GMountOperation * get_unmount_operation (GtkPlacesSidebar *sidebar);
|
2015-05-06 21:07:17 +00:00
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
/* Identifiers for target types */
|
|
|
|
|
enum {
|
2015-05-06 21:07:17 +00:00
|
|
|
|
DND_UNKNOWN,
|
|
|
|
|
DND_GTK_SIDEBAR_ROW,
|
|
|
|
|
DND_TEXT_URI_LIST
|
2011-09-06 22:53:30 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Target types for dragging from the shortcuts list */
|
2017-11-16 23:28:53 +00:00
|
|
|
|
static const char *dnd_source_targets[] = {
|
|
|
|
|
"DND_GTK_SIDEBAR_ROW"
|
2011-09-06 22:53:30 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Target types for dropping into the shortcuts list */
|
2017-11-16 23:28:53 +00:00
|
|
|
|
static const char *dnd_drop_targets [] = {
|
|
|
|
|
"DND_GTK_SIDEBAR_ROW"
|
2011-09-06 22:53:30 +00:00
|
|
|
|
};
|
|
|
|
|
|
2019-05-28 22:11:14 +00:00
|
|
|
|
G_DEFINE_TYPE (GtkPlacesSidebar, gtk_places_sidebar, GTK_TYPE_WIDGET);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2011-09-28 15:44:40 +00:00
|
|
|
|
static void
|
2013-11-09 22:28:02 +00:00
|
|
|
|
emit_open_location (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GFile *location,
|
|
|
|
|
GtkPlacesOpenFlags open_flags)
|
2011-09-28 15:44:40 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
if ((open_flags & sidebar->open_flags) == 0)
|
|
|
|
|
open_flags = GTK_PLACES_OPEN_NORMAL;
|
2013-01-10 22:19:03 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_signal_emit (sidebar, places_sidebar_signals[OPEN_LOCATION], 0,
|
|
|
|
|
location, open_flags);
|
2011-09-28 15:44:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-10-04 21:47:31 +00:00
|
|
|
|
static void
|
2013-11-09 22:28:02 +00:00
|
|
|
|
emit_show_error_message (GtkPlacesSidebar *sidebar,
|
|
|
|
|
const gchar *primary,
|
|
|
|
|
const gchar *secondary)
|
2011-10-04 21:47:31 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_signal_emit (sidebar, places_sidebar_signals[SHOW_ERROR_MESSAGE], 0,
|
|
|
|
|
primary, secondary);
|
2011-10-04 21:47:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-04-07 22:43:28 +00:00
|
|
|
|
static void
|
|
|
|
|
emit_show_enter_location (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
|
|
|
|
g_signal_emit (sidebar, places_sidebar_signals[SHOW_ENTER_LOCATION], 0);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-29 22:13:51 +00:00
|
|
|
|
static void
|
|
|
|
|
emit_show_other_locations_with_flags (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GtkPlacesOpenFlags open_flags)
|
|
|
|
|
{
|
|
|
|
|
g_signal_emit (sidebar, places_sidebar_signals[SHOW_OTHER_LOCATIONS_WITH_FLAGS],
|
|
|
|
|
0, open_flags);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-20 15:29:42 +00:00
|
|
|
|
static void
|
|
|
|
|
emit_show_starred_location (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GtkPlacesOpenFlags open_flags)
|
|
|
|
|
{
|
|
|
|
|
g_signal_emit (sidebar, places_sidebar_signals[SHOW_STARRED_LOCATION], 0,
|
|
|
|
|
open_flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-02-15 18:09:54 +00:00
|
|
|
|
static void
|
|
|
|
|
emit_mount_operation (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GMountOperation *mount_op)
|
|
|
|
|
{
|
|
|
|
|
g_signal_emit (sidebar, places_sidebar_signals[MOUNT], 0, mount_op);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
emit_unmount_operation (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GMountOperation *mount_op)
|
|
|
|
|
{
|
|
|
|
|
g_signal_emit (sidebar, places_sidebar_signals[UNMOUNT], 0, mount_op);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-27 20:39:39 +00:00
|
|
|
|
static GdkDragAction
|
2012-12-03 23:09:57 +00:00
|
|
|
|
emit_drag_action_requested (GtkPlacesSidebar *sidebar,
|
2018-07-17 06:31:54 +00:00
|
|
|
|
GdkDrag *drag,
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GFile *dest_file,
|
|
|
|
|
GList *source_file_list)
|
2012-12-03 23:09:57 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GdkDragAction ret_action = 0;
|
2013-02-27 20:39:39 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_signal_emit (sidebar, places_sidebar_signals[DRAG_ACTION_REQUESTED], 0,
|
2018-07-17 06:31:54 +00:00
|
|
|
|
drag, dest_file, source_file_list, &ret_action);
|
2013-02-27 20:39:39 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
return ret_action;
|
2012-12-03 23:09:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-04 00:15:41 +00:00
|
|
|
|
static GdkDragAction
|
|
|
|
|
emit_drag_action_ask (GtkPlacesSidebar *sidebar,
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GdkDragAction actions)
|
2012-12-04 00:15:41 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GdkDragAction ret_action = 0;
|
2012-12-04 00:15:41 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_signal_emit (sidebar, places_sidebar_signals[DRAG_ACTION_ASK], 0,
|
|
|
|
|
actions, &ret_action);
|
2012-12-04 00:15:41 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
return ret_action;
|
2012-12-04 00:15:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-04 18:44:46 +00:00
|
|
|
|
static void
|
|
|
|
|
emit_drag_perform_drop (GtkPlacesSidebar *sidebar,
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GFile *dest_file,
|
|
|
|
|
GList *source_file_list,
|
|
|
|
|
GdkDragAction action)
|
2012-12-04 18:44:46 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_signal_emit (sidebar, places_sidebar_signals[DRAG_PERFORM_DROP], 0,
|
|
|
|
|
dest_file, source_file_list, action);
|
2012-12-04 18:44:46 +00:00
|
|
|
|
}
|
2015-05-06 21:07:17 +00:00
|
|
|
|
static void
|
|
|
|
|
list_box_header_func (GtkListBoxRow *row,
|
|
|
|
|
GtkListBoxRow *before,
|
|
|
|
|
gpointer user_data)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GtkPlacesSidebarSectionType row_section_type;
|
|
|
|
|
GtkPlacesSidebarSectionType before_section_type;
|
|
|
|
|
GtkWidget *separator;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
gtk_list_box_row_set_header (row, NULL);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
g_object_get (row, "section-type", &row_section_type, NULL);
|
|
|
|
|
if (before)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
g_object_get (before, "section-type", &before_section_type, NULL);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
before_section_type = SECTION_INVALID;
|
|
|
|
|
gtk_widget_set_margin_top (GTK_WIDGET (row), 4);
|
|
|
|
|
}
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
if (before && before_section_type != row_section_type)
|
|
|
|
|
{
|
|
|
|
|
separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
|
|
|
|
|
gtk_widget_set_margin_top (separator, 4);
|
|
|
|
|
gtk_widget_set_margin_bottom (separator, 4);
|
|
|
|
|
gtk_list_box_row_set_header (row, separator);
|
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
static GtkWidget*
|
|
|
|
|
add_place (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GtkPlacesSidebarPlaceType place_type,
|
|
|
|
|
GtkPlacesSidebarSectionType section_type,
|
|
|
|
|
const gchar *name,
|
2017-08-10 20:30:36 +00:00
|
|
|
|
GIcon *start_icon,
|
|
|
|
|
GIcon *end_icon,
|
2015-05-06 21:07:17 +00:00
|
|
|
|
const gchar *uri,
|
|
|
|
|
GDrive *drive,
|
|
|
|
|
GVolume *volume,
|
|
|
|
|
GMount *mount,
|
2017-08-10 20:30:36 +00:00
|
|
|
|
#ifdef HAVE_CLOUDPROVIDERS
|
2017-10-30 20:38:41 +00:00
|
|
|
|
CloudProvidersAccount *cloud_provider_account,
|
2017-08-10 20:30:36 +00:00
|
|
|
|
#else
|
|
|
|
|
gpointer *cloud_provider_account,
|
|
|
|
|
#endif
|
2015-05-06 21:07:17 +00:00
|
|
|
|
const gint index,
|
|
|
|
|
const gchar *tooltip)
|
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
gboolean show_eject, show_unmount;
|
|
|
|
|
gboolean show_eject_button;
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GtkWidget *row;
|
|
|
|
|
GtkWidget *eject_button;
|
2018-06-08 09:29:59 +00:00
|
|
|
|
GtkGesture *gesture;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
|
|
|
|
check_unmount_and_eject (mount, volume, drive,
|
|
|
|
|
&show_unmount, &show_eject);
|
|
|
|
|
|
|
|
|
|
if (show_unmount || show_eject)
|
|
|
|
|
g_assert (place_type != PLACES_BOOKMARK);
|
|
|
|
|
|
2016-02-18 09:53:35 +00:00
|
|
|
|
show_eject_button = (show_unmount || show_eject);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
row = g_object_new (GTK_TYPE_SIDEBAR_ROW,
|
|
|
|
|
"sidebar", sidebar,
|
2017-08-10 20:30:36 +00:00
|
|
|
|
"start-icon", start_icon,
|
|
|
|
|
"end-icon", end_icon,
|
2015-05-06 21:07:17 +00:00
|
|
|
|
"label", name,
|
2016-05-11 01:47:20 +00:00
|
|
|
|
"tooltip", tooltip,
|
2015-05-06 21:07:17 +00:00
|
|
|
|
"ejectable", show_eject_button,
|
|
|
|
|
"order-index", index,
|
|
|
|
|
"section-type", section_type,
|
|
|
|
|
"place-type", place_type,
|
|
|
|
|
"uri", uri,
|
|
|
|
|
"drive", drive,
|
|
|
|
|
"volume", volume,
|
|
|
|
|
"mount", mount,
|
2017-08-10 20:30:36 +00:00
|
|
|
|
#ifdef HAVE_CLOUDPROVIDERS
|
2017-10-30 20:38:41 +00:00
|
|
|
|
"cloud-provider-account", cloud_provider_account,
|
2017-08-10 20:30:36 +00:00
|
|
|
|
#endif
|
2015-05-06 21:07:17 +00:00
|
|
|
|
NULL);
|
2015-05-23 23:14:39 +00:00
|
|
|
|
|
2015-06-23 18:42:57 +00:00
|
|
|
|
eject_button = gtk_sidebar_row_get_eject_button (GTK_SIDEBAR_ROW (row));
|
|
|
|
|
|
|
|
|
|
g_signal_connect_swapped (eject_button, "clicked",
|
|
|
|
|
G_CALLBACK (eject_or_unmount_bookmark), row);
|
2018-06-08 09:29:59 +00:00
|
|
|
|
|
2019-05-29 17:10:46 +00:00
|
|
|
|
gesture = gtk_gesture_click_new ();
|
2018-06-08 09:29:59 +00:00
|
|
|
|
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0);
|
|
|
|
|
g_signal_connect (gesture, "pressed",
|
|
|
|
|
G_CALLBACK (on_row_pressed), row);
|
|
|
|
|
g_signal_connect (gesture, "released",
|
|
|
|
|
G_CALLBACK (on_row_released), row);
|
|
|
|
|
gtk_widget_add_controller (row, GTK_EVENT_CONTROLLER (gesture));
|
|
|
|
|
|
|
|
|
|
gesture = gtk_gesture_drag_new ();
|
|
|
|
|
g_signal_connect (gesture, "drag-update",
|
|
|
|
|
G_CALLBACK (on_row_dragged), row);
|
|
|
|
|
gtk_widget_add_controller (row, GTK_EVENT_CONTROLLER (gesture));
|
2015-05-06 21:07:17 +00:00
|
|
|
|
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (sidebar->list_box), GTK_WIDGET (row));
|
|
|
|
|
|
|
|
|
|
return row;
|
2011-09-06 22:53:30 +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
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
#define ICON_CASE(x) \
|
|
|
|
|
case G_USER_DIRECTORY_ ## x: \
|
|
|
|
|
return g_themed_icon_new_with_default_fallbacks (ICON_NAME_FOLDER_ ## x);
|
2011-10-04 22:40:08 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
switch (directory)
|
|
|
|
|
{
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
2013-12-01 18:58:39 +00:00
|
|
|
|
ICON_CASE (DESKTOP);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
ICON_CASE (DOCUMENTS);
|
|
|
|
|
ICON_CASE (DOWNLOAD);
|
|
|
|
|
ICON_CASE (MUSIC);
|
|
|
|
|
ICON_CASE (PICTURES);
|
|
|
|
|
ICON_CASE (PUBLIC_SHARE);
|
|
|
|
|
ICON_CASE (TEMPLATES);
|
|
|
|
|
ICON_CASE (VIDEOS);
|
2011-10-04 22:40:08 +00:00
|
|
|
|
|
2017-10-06 19:19:42 +00:00
|
|
|
|
case G_USER_N_DIRECTORIES:
|
2013-11-09 22:28:02 +00:00
|
|
|
|
default:
|
2014-06-19 12:11:22 +00:00
|
|
|
|
return g_themed_icon_new_with_default_fallbacks (ICON_NAME_FOLDER);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
|
|
|
|
#undef ICON_CASE
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2013-02-14 02:15:46 +00:00
|
|
|
|
recent_files_setting_is_enabled (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GtkSettings *settings;
|
|
|
|
|
gboolean enabled;
|
|
|
|
|
|
2015-05-30 13:20:27 +00:00
|
|
|
|
settings = gtk_widget_get_settings (GTK_WIDGET (sidebar));
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_object_get (settings, "gtk-recent-files-enabled", &enabled, NULL);
|
2013-02-14 02:15:46 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
return enabled;
|
2013-02-14 02:15:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
recent_scheme_is_supported (void)
|
2012-09-07 15:04:42 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
const gchar * const *supported;
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
supported = g_vfs_get_supported_uri_schemes (g_vfs_get_default ());
|
2015-05-30 13:20:27 +00:00
|
|
|
|
if (supported != NULL)
|
|
|
|
|
return g_strv_contains (supported, "recent");
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
|
|
|
|
return FALSE;
|
2011-10-04 22:40:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-14 02:15:46 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
should_show_recent (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
2015-06-06 21:13:22 +00:00
|
|
|
|
return recent_files_setting_is_enabled (sidebar) &&
|
|
|
|
|
((sidebar->show_recent_set && sidebar->show_recent) ||
|
|
|
|
|
(!sidebar->show_recent_set && recent_scheme_is_supported ()));
|
2013-02-14 02:15:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-14 18:19:56 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
path_is_home_dir (const gchar *path)
|
|
|
|
|
{
|
|
|
|
|
GFile *home_dir;
|
|
|
|
|
GFile *location;
|
|
|
|
|
const gchar *home_path;
|
|
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
|
|
home_path = g_get_home_dir ();
|
|
|
|
|
if (!home_path)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
home_dir = g_file_new_for_path (home_path);
|
|
|
|
|
location = g_file_new_for_path (path);
|
|
|
|
|
res = g_file_equal (home_dir, location);
|
|
|
|
|
|
|
|
|
|
g_object_unref (home_dir);
|
|
|
|
|
g_object_unref (location);
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-07 10:22:38 +00:00
|
|
|
|
static void
|
|
|
|
|
open_home (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
|
|
|
|
const gchar *home_path;
|
|
|
|
|
GFile *home_dir;
|
|
|
|
|
|
|
|
|
|
home_path = g_get_home_dir ();
|
|
|
|
|
if (!home_path)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
home_dir = g_file_new_for_path (home_path);
|
|
|
|
|
emit_open_location (sidebar, home_dir, 0);
|
|
|
|
|
|
|
|
|
|
g_object_unref (home_dir);
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
static void
|
|
|
|
|
add_special_dirs (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GList *dirs;
|
|
|
|
|
gint index;
|
|
|
|
|
|
|
|
|
|
dirs = NULL;
|
|
|
|
|
for (index = 0; index < G_USER_N_DIRECTORIES; index++)
|
|
|
|
|
{
|
|
|
|
|
const gchar *path;
|
|
|
|
|
GFile *root;
|
2017-08-10 20:30:36 +00:00
|
|
|
|
GIcon *start_icon;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
gchar *name;
|
|
|
|
|
gchar *mount_uri;
|
|
|
|
|
gchar *tooltip;
|
|
|
|
|
|
|
|
|
|
if (!_gtk_bookmarks_manager_get_is_xdg_dir_builtin (index))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
path = g_get_user_special_dir (index);
|
|
|
|
|
|
|
|
|
|
/* XDG resets special dirs to the home directory in case
|
|
|
|
|
* it's not finiding what it expects. We don't want the home
|
|
|
|
|
* to be added multiple times in that weird configuration.
|
|
|
|
|
*/
|
|
|
|
|
if (path == NULL ||
|
2014-05-14 18:19:56 +00:00
|
|
|
|
path_is_home_dir (path) ||
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_list_find_custom (dirs, path, (GCompareFunc) g_strcmp0) != NULL)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
root = g_file_new_for_path (path);
|
|
|
|
|
|
|
|
|
|
name = _gtk_bookmarks_manager_get_bookmark_label (sidebar->bookmarks_manager, root);
|
|
|
|
|
if (!name)
|
|
|
|
|
name = g_file_get_basename (root);
|
|
|
|
|
|
2017-08-10 20:30:36 +00:00
|
|
|
|
start_icon = special_directory_get_gicon (index);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
mount_uri = g_file_get_uri (root);
|
|
|
|
|
tooltip = g_file_get_parse_name (root);
|
|
|
|
|
|
|
|
|
|
add_place (sidebar, PLACES_XDG_DIR,
|
|
|
|
|
SECTION_COMPUTER,
|
2017-08-10 20:30:36 +00:00
|
|
|
|
name, start_icon, NULL, mount_uri,
|
|
|
|
|
NULL, NULL, NULL, NULL, 0,
|
2013-11-09 22:28:02 +00:00
|
|
|
|
tooltip);
|
|
|
|
|
g_free (name);
|
|
|
|
|
g_object_unref (root);
|
2017-08-10 20:30:36 +00:00
|
|
|
|
g_object_unref (start_icon);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_free (mount_uri);
|
|
|
|
|
g_free (tooltip);
|
|
|
|
|
|
|
|
|
|
dirs = g_list_prepend (dirs, (gchar *)path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_list_free (dirs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gchar *
|
2012-09-07 15:04:42 +00:00
|
|
|
|
get_home_directory_uri (void)
|
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
const gchar *home;
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
home = g_get_home_dir ();
|
|
|
|
|
if (!home)
|
|
|
|
|
return NULL;
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
2014-12-01 20:56:05 +00:00
|
|
|
|
return g_filename_to_uri (home, NULL, NULL);
|
2012-09-07 15:04:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
static gchar *
|
2012-09-07 15:04:42 +00:00
|
|
|
|
get_desktop_directory_uri (void)
|
2011-10-05 13:46:43 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
const gchar *name;
|
|
|
|
|
|
|
|
|
|
name = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
|
|
|
|
|
|
|
|
|
|
/* "To disable a directory, point it to the homedir."
|
|
|
|
|
* See http://freedesktop.org/wiki/Software/xdg-user-dirs
|
|
|
|
|
*/
|
2014-05-14 18:19:56 +00:00
|
|
|
|
if (path_is_home_dir (name))
|
2013-11-09 22:28:02 +00:00
|
|
|
|
return NULL;
|
2011-10-05 13:46:43 +00:00
|
|
|
|
|
2014-12-01 20:56:05 +00:00
|
|
|
|
return g_filename_to_uri (name, NULL, NULL);
|
2011-10-05 13:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-09 23:28:12 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
should_show_file (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GFile *file)
|
|
|
|
|
{
|
|
|
|
|
gchar *path;
|
|
|
|
|
|
|
|
|
|
if (!sidebar->local_only)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
path = g_file_get_path (file);
|
|
|
|
|
if (path)
|
|
|
|
|
{
|
|
|
|
|
g_free (path);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-10 00:01:27 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
file_is_shown (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GFile *file)
|
|
|
|
|
{
|
|
|
|
|
gchar *uri;
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GList *rows;
|
|
|
|
|
GList *l;
|
|
|
|
|
gboolean found = FALSE;
|
2013-11-10 00:01:27 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
rows = gtk_container_get_children (GTK_CONTAINER (sidebar->list_box));
|
|
|
|
|
l = rows;
|
|
|
|
|
while (l != NULL && !found)
|
2013-11-10 00:01:27 +00:00
|
|
|
|
{
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_object_get (l->data, "uri", &uri, NULL);
|
2013-11-10 00:01:27 +00:00
|
|
|
|
if (uri)
|
|
|
|
|
{
|
|
|
|
|
GFile *other;
|
|
|
|
|
other = g_file_new_for_uri (uri);
|
|
|
|
|
found = g_file_equal (file, other);
|
|
|
|
|
g_object_unref (other);
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_free (uri);
|
2013-11-10 00:01:27 +00:00
|
|
|
|
}
|
2015-05-06 21:07:17 +00:00
|
|
|
|
l = l->next;
|
2013-11-10 00:01:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
g_list_free (rows);
|
|
|
|
|
|
|
|
|
|
return found;
|
2013-11-10 00:01:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-03 11:52:52 +00:00
|
|
|
|
static void
|
|
|
|
|
on_app_shortcuts_query_complete (GObject *source,
|
|
|
|
|
GAsyncResult *result,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GtkPlacesSidebar *sidebar = data;
|
|
|
|
|
GFile *file = G_FILE (source);
|
|
|
|
|
GFileInfo *info;
|
|
|
|
|
|
|
|
|
|
info = g_file_query_info_finish (file, result, NULL);
|
|
|
|
|
|
2014-09-11 22:23:55 +00:00
|
|
|
|
if (info)
|
2014-09-03 11:52:52 +00:00
|
|
|
|
{
|
|
|
|
|
gchar *uri;
|
|
|
|
|
gchar *tooltip;
|
|
|
|
|
const gchar *name;
|
2017-08-10 20:30:36 +00:00
|
|
|
|
GIcon *start_icon;
|
2014-09-03 11:52:52 +00:00
|
|
|
|
int pos = 0;
|
|
|
|
|
|
|
|
|
|
name = g_file_info_get_display_name (info);
|
2017-08-10 20:30:36 +00:00
|
|
|
|
start_icon = g_file_info_get_symbolic_icon (info);
|
2014-09-03 11:52:52 +00:00
|
|
|
|
uri = g_file_get_uri (file);
|
|
|
|
|
tooltip = g_file_get_parse_name (file);
|
|
|
|
|
|
|
|
|
|
/* XXX: we could avoid this by using an ancillary closure
|
|
|
|
|
* with the index coming from add_application_shortcuts(),
|
|
|
|
|
* but in terms of algorithmic overhead, the application
|
|
|
|
|
* shortcuts is not going to be really big
|
|
|
|
|
*/
|
|
|
|
|
pos = g_slist_index (sidebar->shortcuts, file);
|
|
|
|
|
|
|
|
|
|
add_place (sidebar, PLACES_BUILT_IN,
|
|
|
|
|
SECTION_COMPUTER,
|
2017-08-10 20:30:36 +00:00
|
|
|
|
name, start_icon, NULL, uri,
|
|
|
|
|
NULL, NULL, NULL, NULL,
|
2014-09-03 11:52:52 +00:00
|
|
|
|
pos,
|
|
|
|
|
tooltip);
|
|
|
|
|
|
|
|
|
|
g_free (uri);
|
|
|
|
|
g_free (tooltip);
|
|
|
|
|
|
|
|
|
|
g_object_unref (info);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-07 19:42:39 +00:00
|
|
|
|
static void
|
|
|
|
|
add_application_shortcuts (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GSList *l;
|
2012-12-07 19:42:39 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
for (l = sidebar->shortcuts; l; l = l->next)
|
|
|
|
|
{
|
2014-09-03 11:52:52 +00:00
|
|
|
|
GFile *file = l->data;
|
2012-12-07 19:42:39 +00:00
|
|
|
|
|
2013-11-09 23:28:12 +00:00
|
|
|
|
if (!should_show_file (sidebar, file))
|
|
|
|
|
continue;
|
|
|
|
|
|
2013-11-10 00:01:27 +00:00
|
|
|
|
if (file_is_shown (sidebar, file))
|
|
|
|
|
continue;
|
|
|
|
|
|
2014-09-03 11:52:52 +00:00
|
|
|
|
g_file_query_info_async (file,
|
|
|
|
|
"standard::display-name,standard::symbolic-icon",
|
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
|
G_PRIORITY_DEFAULT,
|
2014-09-04 03:29:51 +00:00
|
|
|
|
sidebar->cancellable,
|
2014-09-03 11:52:52 +00:00
|
|
|
|
on_app_shortcuts_query_complete,
|
|
|
|
|
sidebar);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
2012-12-07 19:42:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-03 11:52:52 +00:00
|
|
|
|
typedef struct {
|
|
|
|
|
GtkPlacesSidebar *sidebar;
|
|
|
|
|
int index;
|
|
|
|
|
gboolean is_native;
|
|
|
|
|
} BookmarkQueryClosure;
|
|
|
|
|
|
|
|
|
|
static void
|
2014-10-05 17:39:15 +00:00
|
|
|
|
on_bookmark_query_info_complete (GObject *source,
|
2014-09-03 11:52:52 +00:00
|
|
|
|
GAsyncResult *result,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
BookmarkQueryClosure *clos = data;
|
|
|
|
|
GtkPlacesSidebar *sidebar = clos->sidebar;
|
|
|
|
|
GFile *root = G_FILE (source);
|
2014-09-11 22:25:24 +00:00
|
|
|
|
GError *error = NULL;
|
2014-09-03 11:52:52 +00:00
|
|
|
|
GFileInfo *info;
|
|
|
|
|
gchar *bookmark_name;
|
|
|
|
|
gchar *mount_uri;
|
|
|
|
|
gchar *tooltip;
|
2017-08-10 20:30:36 +00:00
|
|
|
|
GIcon *start_icon;
|
2014-09-03 11:52:52 +00:00
|
|
|
|
|
2014-09-11 22:25:24 +00:00
|
|
|
|
info = g_file_query_info_finish (root, result, &error);
|
|
|
|
|
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
|
|
|
|
goto out;
|
2014-09-03 11:52:52 +00:00
|
|
|
|
|
|
|
|
|
bookmark_name = _gtk_bookmarks_manager_get_bookmark_label (sidebar->bookmarks_manager, root);
|
|
|
|
|
if (bookmark_name == NULL && info != NULL)
|
|
|
|
|
bookmark_name = g_strdup (g_file_info_get_display_name (info));
|
|
|
|
|
else if (bookmark_name == NULL)
|
|
|
|
|
{
|
|
|
|
|
/* Don't add non-UTF-8 bookmarks */
|
|
|
|
|
bookmark_name = g_file_get_basename (root);
|
|
|
|
|
if (!g_utf8_validate (bookmark_name, -1, NULL))
|
|
|
|
|
{
|
|
|
|
|
g_free (bookmark_name);
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (info)
|
2017-08-10 20:30:36 +00:00
|
|
|
|
start_icon = g_object_ref (g_file_info_get_symbolic_icon (info));
|
2014-09-03 11:52:52 +00:00
|
|
|
|
else
|
2017-08-10 20:30:36 +00:00
|
|
|
|
start_icon = g_themed_icon_new_with_default_fallbacks (clos->is_native ? ICON_NAME_FOLDER : ICON_NAME_FOLDER_NETWORK);
|
2014-09-03 11:52:52 +00:00
|
|
|
|
|
|
|
|
|
mount_uri = g_file_get_uri (root);
|
|
|
|
|
tooltip = g_file_get_parse_name (root);
|
|
|
|
|
|
|
|
|
|
add_place (sidebar, PLACES_BOOKMARK,
|
|
|
|
|
SECTION_BOOKMARKS,
|
2017-08-10 20:30:36 +00:00
|
|
|
|
bookmark_name, start_icon, NULL, mount_uri,
|
|
|
|
|
NULL, NULL, NULL, NULL, clos->index,
|
2014-09-03 11:52:52 +00:00
|
|
|
|
tooltip);
|
|
|
|
|
|
|
|
|
|
g_free (mount_uri);
|
|
|
|
|
g_free (tooltip);
|
|
|
|
|
g_free (bookmark_name);
|
2017-08-10 20:30:36 +00:00
|
|
|
|
g_object_unref (start_icon);
|
2014-09-03 11:52:52 +00:00
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
g_clear_object (&info);
|
2014-09-11 22:25:24 +00:00
|
|
|
|
g_clear_error (&error);
|
2014-09-03 11:52:52 +00:00
|
|
|
|
g_slice_free (BookmarkQueryClosure, clos);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-14 17:47:42 +00:00
|
|
|
|
static gboolean
|
2015-10-14 19:42:16 +00:00
|
|
|
|
is_external_volume (GVolume *volume)
|
2015-07-14 17:47:42 +00:00
|
|
|
|
{
|
2015-10-14 19:42:16 +00:00
|
|
|
|
gboolean is_external;
|
2015-07-14 17:47:42 +00:00
|
|
|
|
GDrive *drive;
|
|
|
|
|
gchar *id;
|
|
|
|
|
|
|
|
|
|
drive = g_volume_get_drive (volume);
|
|
|
|
|
id = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_CLASS);
|
|
|
|
|
|
2015-10-14 19:42:16 +00:00
|
|
|
|
is_external = g_volume_can_eject (volume);
|
2015-07-14 17:47:42 +00:00
|
|
|
|
|
|
|
|
|
/* NULL volume identifier only happens on removable devices */
|
2015-10-14 19:42:16 +00:00
|
|
|
|
is_external |= !id;
|
2015-07-14 17:47:42 +00:00
|
|
|
|
|
|
|
|
|
if (drive)
|
2016-05-02 10:55:56 +00:00
|
|
|
|
is_external |= g_drive_is_removable (drive);
|
2015-07-14 17:47:42 +00:00
|
|
|
|
|
|
|
|
|
g_clear_object (&drive);
|
|
|
|
|
g_free (id);
|
|
|
|
|
|
2015-10-14 19:42:16 +00:00
|
|
|
|
return is_external;
|
2015-07-14 17:47:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-25 13:25:40 +00:00
|
|
|
|
static void
|
|
|
|
|
update_trash_icon (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
|
|
|
|
if (sidebar->trash_row)
|
2016-03-27 14:59:59 +00:00
|
|
|
|
{
|
|
|
|
|
GIcon *icon;
|
|
|
|
|
|
|
|
|
|
icon = _gtk_trash_monitor_get_icon (sidebar->trash_monitor);
|
2017-08-10 20:30:36 +00:00
|
|
|
|
gtk_sidebar_row_set_start_icon (GTK_SIDEBAR_ROW (sidebar->trash_row), icon);
|
2016-03-27 14:59:59 +00:00
|
|
|
|
g_object_unref (icon);
|
|
|
|
|
}
|
2016-02-25 13:25:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-10 20:30:36 +00:00
|
|
|
|
#ifdef HAVE_CLOUDPROVIDERS
|
2017-10-30 20:38:41 +00:00
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
create_cloud_provider_account_row (GtkPlacesSidebar *sidebar,
|
|
|
|
|
CloudProvidersAccount *account)
|
2017-08-10 20:30:36 +00:00
|
|
|
|
{
|
|
|
|
|
GIcon *end_icon;
|
2017-10-30 20:38:41 +00:00
|
|
|
|
GIcon *start_icon;
|
|
|
|
|
gchar *mount_uri;
|
|
|
|
|
gchar *name;
|
|
|
|
|
gchar *tooltip;
|
|
|
|
|
guint provider_account_status;
|
|
|
|
|
|
|
|
|
|
start_icon = cloud_providers_account_get_icon (account);
|
|
|
|
|
name = cloud_providers_account_get_name (account);
|
|
|
|
|
provider_account_status = cloud_providers_account_get_status (account);
|
|
|
|
|
mount_uri = cloud_providers_account_get_path (account);
|
|
|
|
|
if (start_icon != NULL
|
|
|
|
|
&& name != NULL
|
|
|
|
|
&& provider_account_status != CLOUD_PROVIDERS_ACCOUNT_STATUS_INVALID
|
|
|
|
|
&& mount_uri != NULL)
|
2017-08-10 20:30:36 +00:00
|
|
|
|
{
|
2017-10-30 20:38:41 +00:00
|
|
|
|
switch (provider_account_status)
|
|
|
|
|
{
|
|
|
|
|
case CLOUD_PROVIDERS_ACCOUNT_STATUS_IDLE:
|
|
|
|
|
end_icon = NULL;
|
|
|
|
|
break;
|
2017-08-10 20:30:36 +00:00
|
|
|
|
|
2017-10-30 20:38:41 +00:00
|
|
|
|
case CLOUD_PROVIDERS_ACCOUNT_STATUS_SYNCING:
|
|
|
|
|
end_icon = g_themed_icon_new ("emblem-synchronizing-symbolic");
|
|
|
|
|
break;
|
2017-08-10 20:30:36 +00:00
|
|
|
|
|
2017-10-30 20:38:41 +00:00
|
|
|
|
case CLOUD_PROVIDERS_ACCOUNT_STATUS_ERROR:
|
|
|
|
|
end_icon = g_themed_icon_new ("dialog-warning-symbolic");
|
|
|
|
|
break;
|
2017-08-10 20:30:36 +00:00
|
|
|
|
|
2017-10-30 20:38:41 +00:00
|
|
|
|
default:
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2017-08-10 20:30:36 +00:00
|
|
|
|
|
2017-10-30 20:38:41 +00:00
|
|
|
|
mount_uri = g_strconcat ("file://", mount_uri, NULL);
|
2017-08-10 20:30:36 +00:00
|
|
|
|
|
2017-10-30 20:38:41 +00:00
|
|
|
|
/* translators: %s is the name of a cloud provider for files */
|
|
|
|
|
tooltip = g_strdup_printf (_("Open %s"), name);
|
2017-08-10 20:30:36 +00:00
|
|
|
|
|
2017-10-30 20:38:41 +00:00
|
|
|
|
add_place (sidebar, PLACES_BUILT_IN,
|
|
|
|
|
SECTION_CLOUD,
|
|
|
|
|
name, start_icon, end_icon, mount_uri,
|
|
|
|
|
NULL, NULL, NULL, account, 0,
|
|
|
|
|
tooltip);
|
2017-08-10 20:30:36 +00:00
|
|
|
|
|
2017-10-30 20:38:41 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
else
|
2017-08-10 20:30:36 +00:00
|
|
|
|
{
|
2017-10-30 20:38:41 +00:00
|
|
|
|
return FALSE;
|
2017-08-10 20:30:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-10-30 20:38:41 +00:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
on_account_updated (GObject *object,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
CloudProvidersAccount *account = CLOUD_PROVIDERS_ACCOUNT (object);
|
|
|
|
|
GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (user_data);
|
|
|
|
|
|
|
|
|
|
if (create_cloud_provider_account_row (sidebar, account))
|
|
|
|
|
{
|
|
|
|
|
g_signal_handlers_disconnect_by_data (account, sidebar);
|
|
|
|
|
sidebar->unready_accounts = g_list_remove (sidebar->unready_accounts, account);
|
|
|
|
|
g_object_unref (account);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-10 20:30:36 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
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
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GList *mounts, *l, *ll;
|
|
|
|
|
GMount *mount;
|
|
|
|
|
GList *drives;
|
|
|
|
|
GDrive *drive;
|
|
|
|
|
GList *volumes;
|
|
|
|
|
GVolume *volume;
|
|
|
|
|
GSList *bookmarks, *sl;
|
|
|
|
|
gint index;
|
2016-10-15 20:24:42 +00:00
|
|
|
|
gchar *original_uri, *name, *identifier;
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GtkListBoxRow *selected;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
gchar *home_uri;
|
2017-08-10 20:30:36 +00:00
|
|
|
|
GIcon *start_icon;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GFile *root;
|
|
|
|
|
gchar *tooltip;
|
|
|
|
|
GList *network_mounts, *network_volumes;
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GIcon *new_bookmark_icon;
|
2017-08-10 20:30:36 +00:00
|
|
|
|
#ifdef HAVE_CLOUDPROVIDERS
|
2017-10-30 20:38:41 +00:00
|
|
|
|
GList *cloud_providers;
|
|
|
|
|
GList *cloud_providers_accounts;
|
|
|
|
|
CloudProvidersAccount *cloud_provider_account;
|
|
|
|
|
CloudProvidersProvider *cloud_provider;
|
2017-08-10 20:30:36 +00:00
|
|
|
|
#endif
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GtkStyleContext *context;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
|
|
|
|
/* save original selection */
|
2015-05-06 21:07:17 +00:00
|
|
|
|
selected = gtk_list_box_get_selected_row (GTK_LIST_BOX (sidebar->list_box));
|
|
|
|
|
if (selected)
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_object_get (selected, "uri", &original_uri, NULL);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
else
|
|
|
|
|
original_uri = NULL;
|
|
|
|
|
|
2014-10-05 17:34:28 +00:00
|
|
|
|
g_cancellable_cancel (sidebar->cancellable);
|
|
|
|
|
|
|
|
|
|
g_object_unref (sidebar->cancellable);
|
|
|
|
|
sidebar->cancellable = g_cancellable_new ();
|
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
/* Reset drag state, just in case we update the places while dragging or
|
|
|
|
|
* ending a drag */
|
|
|
|
|
stop_drop_feedback (sidebar);
|
|
|
|
|
gtk_container_foreach (GTK_CONTAINER (sidebar->list_box),
|
|
|
|
|
(GtkCallback) gtk_widget_destroy,
|
|
|
|
|
NULL);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
|
|
|
|
network_mounts = network_volumes = NULL;
|
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
/* add built-in places */
|
2013-11-09 22:28:02 +00:00
|
|
|
|
if (should_show_recent (sidebar))
|
|
|
|
|
{
|
2017-08-10 20:30:36 +00:00
|
|
|
|
start_icon = g_themed_icon_new_with_default_fallbacks ("document-open-recent-symbolic");
|
2013-11-09 22:28:02 +00:00
|
|
|
|
add_place (sidebar, PLACES_BUILT_IN,
|
|
|
|
|
SECTION_COMPUTER,
|
2017-08-10 20:30:36 +00:00
|
|
|
|
_("Recent"), start_icon, NULL, "recent:///",
|
|
|
|
|
NULL, NULL, NULL, NULL, 0,
|
2013-11-09 22:28:02 +00:00
|
|
|
|
_("Recent files"));
|
2017-08-10 20:30:36 +00:00
|
|
|
|
g_object_unref (start_icon);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-20 15:29:42 +00:00
|
|
|
|
if (sidebar->show_starred_location)
|
|
|
|
|
{
|
|
|
|
|
start_icon = g_themed_icon_new_with_default_fallbacks ("starred-symbolic");
|
|
|
|
|
add_place (sidebar, PLACES_STARRED_LOCATION,
|
|
|
|
|
SECTION_COMPUTER,
|
2018-02-15 09:10:18 +00:00
|
|
|
|
_("Starred"), start_icon, NULL, "starred:///",
|
2017-07-20 15:29:42 +00:00
|
|
|
|
NULL, NULL, NULL, NULL, 0,
|
2018-02-15 09:10:18 +00:00
|
|
|
|
_("Starred files"));
|
2017-07-20 15:29:42 +00:00
|
|
|
|
g_object_unref (start_icon);
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
/* home folder */
|
|
|
|
|
home_uri = get_home_directory_uri ();
|
2017-08-10 20:30:36 +00:00
|
|
|
|
start_icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_HOME);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
add_place (sidebar, PLACES_BUILT_IN,
|
|
|
|
|
SECTION_COMPUTER,
|
2017-08-10 20:30:36 +00:00
|
|
|
|
_("Home"), start_icon, NULL, home_uri,
|
|
|
|
|
NULL, NULL, NULL, NULL, 0,
|
2013-11-09 22:28:02 +00:00
|
|
|
|
_("Open your personal folder"));
|
2017-08-10 20:30:36 +00:00
|
|
|
|
g_object_unref (start_icon);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_free (home_uri);
|
|
|
|
|
|
|
|
|
|
/* desktop */
|
|
|
|
|
if (sidebar->show_desktop)
|
|
|
|
|
{
|
2016-10-15 20:24:42 +00:00
|
|
|
|
char *mount_uri = get_desktop_directory_uri ();
|
2013-12-19 16:22:02 +00:00
|
|
|
|
if (mount_uri)
|
|
|
|
|
{
|
2017-08-10 20:30:36 +00:00
|
|
|
|
start_icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_DESKTOP);
|
2013-12-19 16:22:02 +00:00
|
|
|
|
add_place (sidebar, PLACES_BUILT_IN,
|
|
|
|
|
SECTION_COMPUTER,
|
2017-08-10 20:30:36 +00:00
|
|
|
|
_("Desktop"), start_icon, NULL, mount_uri,
|
|
|
|
|
NULL, NULL, NULL, NULL, 0,
|
2013-12-19 16:22:02 +00:00
|
|
|
|
_("Open the contents of your desktop in a folder"));
|
2017-08-10 20:30:36 +00:00
|
|
|
|
g_object_unref (start_icon);
|
2013-12-19 16:22:02 +00:00
|
|
|
|
g_free (mount_uri);
|
|
|
|
|
}
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* XDG directories */
|
|
|
|
|
add_special_dirs (sidebar);
|
|
|
|
|
|
2014-04-07 22:43:28 +00:00
|
|
|
|
if (sidebar->show_enter_location)
|
|
|
|
|
{
|
2017-08-10 20:30:36 +00:00
|
|
|
|
start_icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_NETWORK_SERVER);
|
2014-04-07 22:43:28 +00:00
|
|
|
|
add_place (sidebar, PLACES_ENTER_LOCATION,
|
|
|
|
|
SECTION_COMPUTER,
|
2017-08-10 20:30:36 +00:00
|
|
|
|
_("Enter Location"), start_icon, NULL, NULL,
|
|
|
|
|
NULL, NULL, NULL, NULL, 0,
|
2014-04-07 22:43:28 +00:00
|
|
|
|
_("Manually enter a location"));
|
2017-08-10 20:30:36 +00:00
|
|
|
|
g_object_unref (start_icon);
|
2014-04-07 22:43:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
/* Trash */
|
2015-07-03 16:49:00 +00:00
|
|
|
|
if (!sidebar->local_only && sidebar->show_trash)
|
2013-11-09 23:28:12 +00:00
|
|
|
|
{
|
2017-08-10 20:30:36 +00:00
|
|
|
|
start_icon = _gtk_trash_monitor_get_icon (sidebar->trash_monitor);
|
2016-02-25 13:25:40 +00:00
|
|
|
|
sidebar->trash_row = add_place (sidebar, PLACES_BUILT_IN,
|
|
|
|
|
SECTION_COMPUTER,
|
2017-08-10 20:30:36 +00:00
|
|
|
|
_("Trash"), start_icon, NULL, "trash:///",
|
|
|
|
|
NULL, NULL, NULL, NULL, 0,
|
2016-02-25 13:25:40 +00:00
|
|
|
|
_("Open the trash"));
|
2016-02-26 10:54:53 +00:00
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (sidebar->trash_row),
|
|
|
|
|
(gpointer *) &sidebar->trash_row);
|
2017-08-10 20:30:36 +00:00
|
|
|
|
g_object_unref (start_icon);
|
2013-11-09 23:28:12 +00:00
|
|
|
|
}
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
|
|
|
|
/* Application-side shortcuts */
|
|
|
|
|
add_application_shortcuts (sidebar);
|
|
|
|
|
|
2017-08-10 20:30:36 +00:00
|
|
|
|
/* Cloud providers */
|
|
|
|
|
#ifdef HAVE_CLOUDPROVIDERS
|
2017-10-30 20:38:41 +00:00
|
|
|
|
cloud_providers = cloud_providers_collector_get_providers (sidebar->cloud_manager);
|
|
|
|
|
for (l = sidebar->unready_accounts; l != NULL; l = l->next)
|
2017-08-10 20:30:36 +00:00
|
|
|
|
{
|
2017-10-30 20:38:41 +00:00
|
|
|
|
g_signal_handlers_disconnect_by_data (l->data, sidebar);
|
|
|
|
|
}
|
|
|
|
|
g_list_free_full (sidebar->unready_accounts, g_object_unref);
|
|
|
|
|
sidebar->unready_accounts = NULL;
|
|
|
|
|
for (l = cloud_providers; l != NULL; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
cloud_provider = CLOUD_PROVIDERS_PROVIDER (l->data);
|
|
|
|
|
g_signal_connect_swapped (cloud_provider, "accounts-changed",
|
|
|
|
|
G_CALLBACK (update_places), sidebar);
|
|
|
|
|
cloud_providers_accounts = cloud_providers_provider_get_accounts (cloud_provider);
|
|
|
|
|
for (ll = cloud_providers_accounts; ll != NULL; ll = ll->next)
|
2017-08-10 20:30:36 +00:00
|
|
|
|
{
|
2017-10-30 20:38:41 +00:00
|
|
|
|
cloud_provider_account = CLOUD_PROVIDERS_ACCOUNT (ll->data);
|
|
|
|
|
if (!create_cloud_provider_account_row (sidebar, cloud_provider_account))
|
|
|
|
|
{
|
2017-08-10 20:30:36 +00:00
|
|
|
|
|
2017-10-30 20:38:41 +00:00
|
|
|
|
g_signal_connect (cloud_provider_account, "notify::name",
|
|
|
|
|
G_CALLBACK (on_account_updated), sidebar);
|
|
|
|
|
g_signal_connect (cloud_provider_account, "notify::status",
|
|
|
|
|
G_CALLBACK (on_account_updated), sidebar);
|
|
|
|
|
g_signal_connect (cloud_provider_account, "notify::status-details",
|
|
|
|
|
G_CALLBACK (on_account_updated), sidebar);
|
|
|
|
|
g_signal_connect (cloud_provider_account, "notify::path",
|
|
|
|
|
G_CALLBACK (on_account_updated), sidebar);
|
|
|
|
|
sidebar->unready_accounts = g_list_append (sidebar->unready_accounts,
|
|
|
|
|
g_object_ref (cloud_provider_account));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2017-08-10 20:30:36 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
/* go through all connected drives */
|
2015-05-06 21:07:17 +00:00
|
|
|
|
drives = g_volume_monitor_get_connected_drives (sidebar->volume_monitor);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
|
|
|
|
for (l = drives; l != NULL; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
drive = l->data;
|
|
|
|
|
|
|
|
|
|
volumes = g_drive_get_volumes (drive);
|
|
|
|
|
if (volumes != NULL)
|
|
|
|
|
{
|
|
|
|
|
for (ll = volumes; ll != NULL; ll = ll->next)
|
|
|
|
|
{
|
|
|
|
|
volume = ll->data;
|
|
|
|
|
identifier = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_CLASS);
|
|
|
|
|
|
|
|
|
|
if (g_strcmp0 (identifier, "network") == 0)
|
|
|
|
|
{
|
|
|
|
|
g_free (identifier);
|
|
|
|
|
network_volumes = g_list_prepend (network_volumes, volume);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
g_free (identifier);
|
|
|
|
|
|
2015-10-14 19:42:16 +00:00
|
|
|
|
if (sidebar->show_other_locations && !is_external_volume (volume))
|
2015-07-14 17:47:42 +00:00
|
|
|
|
{
|
|
|
|
|
g_object_unref (volume);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
mount = g_volume_get_mount (volume);
|
|
|
|
|
if (mount != NULL)
|
|
|
|
|
{
|
2016-10-15 20:24:42 +00:00
|
|
|
|
char *mount_uri;
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
/* Show mounted volume in the sidebar */
|
2017-08-10 20:30:36 +00:00
|
|
|
|
start_icon = g_mount_get_symbolic_icon (mount);
|
2013-11-09 22:28:02 +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);
|
|
|
|
|
|
|
|
|
|
add_place (sidebar, PLACES_MOUNTED_VOLUME,
|
2015-07-14 17:47:42 +00:00
|
|
|
|
SECTION_MOUNTS,
|
2017-08-10 20:30:36 +00:00
|
|
|
|
name, start_icon, NULL, mount_uri,
|
|
|
|
|
drive, volume, mount, NULL, 0, tooltip);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_object_unref (root);
|
|
|
|
|
g_object_unref (mount);
|
2017-08-10 20:30:36 +00:00
|
|
|
|
g_object_unref (start_icon);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
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.
|
|
|
|
|
*/
|
2017-08-10 20:30:36 +00:00
|
|
|
|
start_icon = g_volume_get_symbolic_icon (volume);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
name = g_volume_get_name (volume);
|
2014-08-22 15:07:41 +00:00
|
|
|
|
tooltip = g_strdup_printf (_("Mount and open “%s”"), name);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
|
|
|
|
add_place (sidebar, PLACES_MOUNTED_VOLUME,
|
2015-07-14 17:47:42 +00:00
|
|
|
|
SECTION_MOUNTS,
|
2017-08-10 20:30:36 +00:00
|
|
|
|
name, start_icon, NULL, NULL,
|
|
|
|
|
drive, volume, NULL, NULL, 0, tooltip);
|
|
|
|
|
g_object_unref (start_icon);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
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.
|
|
|
|
|
*/
|
2017-08-10 20:30:36 +00:00
|
|
|
|
start_icon = g_drive_get_symbolic_icon (drive);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
name = g_drive_get_name (drive);
|
2014-08-22 15:07:41 +00:00
|
|
|
|
tooltip = g_strdup_printf (_("Mount and open “%s”"), name);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
|
|
|
|
add_place (sidebar, PLACES_BUILT_IN,
|
2015-07-14 17:47:42 +00:00
|
|
|
|
SECTION_MOUNTS,
|
2017-08-10 20:30:36 +00:00
|
|
|
|
name, start_icon, NULL, NULL,
|
|
|
|
|
drive, NULL, NULL, NULL, 0, tooltip);
|
|
|
|
|
g_object_unref (start_icon);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_free (tooltip);
|
|
|
|
|
g_free (name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-14 17:47:42 +00:00
|
|
|
|
g_list_free_full (drives, g_object_unref);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2019-04-05 19:58:56 +00:00
|
|
|
|
/* add all network volumes that are not associated with a drive, and
|
|
|
|
|
* loop devices
|
|
|
|
|
*/
|
2015-05-06 21:07:17 +00:00
|
|
|
|
volumes = g_volume_monitor_get_volumes (sidebar->volume_monitor);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
for (l = volumes; l != NULL; l = l->next)
|
|
|
|
|
{
|
2019-04-05 19:58:56 +00:00
|
|
|
|
gboolean is_loop = FALSE;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
volume = l->data;
|
|
|
|
|
drive = g_volume_get_drive (volume);
|
|
|
|
|
if (drive != NULL)
|
|
|
|
|
{
|
|
|
|
|
g_object_unref (volume);
|
|
|
|
|
g_object_unref (drive);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
identifier = g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_CLASS);
|
|
|
|
|
|
|
|
|
|
if (g_strcmp0 (identifier, "network") == 0)
|
|
|
|
|
{
|
|
|
|
|
g_free (identifier);
|
|
|
|
|
network_volumes = g_list_prepend (network_volumes, volume);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2019-04-05 19:58:56 +00:00
|
|
|
|
else if (g_strcmp0 (identifier, "loop") == 0)
|
|
|
|
|
is_loop = TRUE;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_free (identifier);
|
|
|
|
|
|
2019-04-05 19:58:56 +00:00
|
|
|
|
if (sidebar->show_other_locations &&
|
|
|
|
|
!is_external_volume (volume) &&
|
|
|
|
|
!is_loop)
|
2015-07-14 17:47:42 +00:00
|
|
|
|
{
|
|
|
|
|
g_object_unref (volume);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
mount = g_volume_get_mount (volume);
|
|
|
|
|
if (mount != NULL)
|
|
|
|
|
{
|
2016-10-15 20:24:42 +00:00
|
|
|
|
char *mount_uri;
|
|
|
|
|
|
2017-08-10 20:30:36 +00:00
|
|
|
|
start_icon = g_mount_get_symbolic_icon (mount);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
root = g_mount_get_default_location (mount);
|
|
|
|
|
mount_uri = g_file_get_uri (root);
|
|
|
|
|
tooltip = g_file_get_parse_name (root);
|
|
|
|
|
name = g_mount_get_name (mount);
|
|
|
|
|
add_place (sidebar, PLACES_MOUNTED_VOLUME,
|
2015-07-14 17:47:42 +00:00
|
|
|
|
SECTION_MOUNTS,
|
2017-08-10 20:30:36 +00:00
|
|
|
|
name, start_icon, NULL, mount_uri,
|
|
|
|
|
NULL, volume, mount, NULL, 0, tooltip);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_object_unref (mount);
|
|
|
|
|
g_object_unref (root);
|
2017-08-10 20:30:36 +00:00
|
|
|
|
g_object_unref (start_icon);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
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 */
|
2017-08-10 20:30:36 +00:00
|
|
|
|
start_icon = g_volume_get_symbolic_icon (volume);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
name = g_volume_get_name (volume);
|
|
|
|
|
add_place (sidebar, PLACES_MOUNTED_VOLUME,
|
2015-07-14 17:47:42 +00:00
|
|
|
|
SECTION_MOUNTS,
|
2017-08-10 20:30:36 +00:00
|
|
|
|
name, start_icon, NULL, NULL,
|
|
|
|
|
NULL, volume, NULL, NULL, 0, name);
|
|
|
|
|
g_object_unref (start_icon);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_free (name);
|
2015-05-06 21:07:17 +00:00
|
|
|
|
}
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_object_unref (volume);
|
|
|
|
|
}
|
|
|
|
|
g_list_free (volumes);
|
|
|
|
|
|
2015-07-20 01:09:29 +00:00
|
|
|
|
/* file system root */
|
|
|
|
|
if (!sidebar->show_other_locations)
|
|
|
|
|
{
|
2017-08-10 20:30:36 +00:00
|
|
|
|
start_icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_FILESYSTEM);
|
2015-07-20 01:09:29 +00:00
|
|
|
|
add_place (sidebar, PLACES_BUILT_IN,
|
|
|
|
|
SECTION_MOUNTS,
|
2017-08-10 20:30:36 +00:00
|
|
|
|
sidebar->hostname, start_icon, NULL, "file:///",
|
|
|
|
|
NULL, NULL, NULL, NULL, 0,
|
2015-07-20 01:09:29 +00:00
|
|
|
|
_("Open the contents of the file system"));
|
2017-08-10 20:30:36 +00:00
|
|
|
|
g_object_unref (start_icon);
|
2015-07-20 01:09:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
/* add mounts that has no volume (/etc/mtab mounts, ftp, sftp,...) */
|
2015-05-06 21:07:17 +00:00
|
|
|
|
mounts = g_volume_monitor_get_mounts (sidebar->volume_monitor);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
|
|
|
|
for (l = mounts; l != NULL; l = l->next)
|
|
|
|
|
{
|
2016-10-15 20:24:42 +00:00
|
|
|
|
char *mount_uri;
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
mount = l->data;
|
|
|
|
|
if (g_mount_is_shadowed (mount))
|
|
|
|
|
{
|
|
|
|
|
g_object_unref (mount);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
volume = g_mount_get_volume (mount);
|
|
|
|
|
if (volume != NULL)
|
|
|
|
|
{
|
|
|
|
|
g_object_unref (volume);
|
|
|
|
|
g_object_unref (mount);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
root = g_mount_get_default_location (mount);
|
|
|
|
|
|
|
|
|
|
if (!g_file_is_native (root))
|
|
|
|
|
{
|
|
|
|
|
network_mounts = g_list_prepend (network_mounts, mount);
|
|
|
|
|
g_object_unref (root);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-10 20:30:36 +00:00
|
|
|
|
start_icon = g_mount_get_symbolic_icon (mount);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
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,
|
2017-08-10 20:30:36 +00:00
|
|
|
|
name, start_icon, NULL, mount_uri,
|
|
|
|
|
NULL, NULL, mount, NULL, 0, tooltip);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_object_unref (root);
|
|
|
|
|
g_object_unref (mount);
|
2017-08-10 20:30:36 +00:00
|
|
|
|
g_object_unref (start_icon);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_free (name);
|
|
|
|
|
g_free (mount_uri);
|
|
|
|
|
g_free (tooltip);
|
|
|
|
|
}
|
|
|
|
|
g_list_free (mounts);
|
|
|
|
|
|
|
|
|
|
/* add bookmarks */
|
|
|
|
|
bookmarks = _gtk_bookmarks_manager_list_bookmarks (sidebar->bookmarks_manager);
|
|
|
|
|
|
|
|
|
|
for (sl = bookmarks, index = 0; sl; sl = sl->next, index++)
|
|
|
|
|
{
|
2013-11-06 18:12:03 +00:00
|
|
|
|
gboolean is_native;
|
2014-09-03 11:52:52 +00:00
|
|
|
|
BookmarkQueryClosure *clos;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
|
|
|
|
root = sl->data;
|
2013-11-06 18:12:03 +00:00
|
|
|
|
is_native = g_file_is_native (root);
|
2011-10-03 15:27:41 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
if (_gtk_bookmarks_manager_get_is_builtin (sidebar->bookmarks_manager, root))
|
|
|
|
|
continue;
|
|
|
|
|
|
2013-11-06 18:12:03 +00:00
|
|
|
|
if (sidebar->local_only && !is_native)
|
|
|
|
|
continue;
|
|
|
|
|
|
2014-09-03 11:52:52 +00:00
|
|
|
|
clos = g_slice_new (BookmarkQueryClosure);
|
|
|
|
|
clos->sidebar = sidebar;
|
|
|
|
|
clos->index = index;
|
|
|
|
|
clos->is_native = is_native;
|
|
|
|
|
g_file_query_info_async (root,
|
|
|
|
|
"standard::display-name,standard::symbolic-icon",
|
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
|
G_PRIORITY_DEFAULT,
|
2014-09-04 03:29:51 +00:00
|
|
|
|
sidebar->cancellable,
|
2014-09-03 11:52:52 +00:00
|
|
|
|
on_bookmark_query_info_complete,
|
|
|
|
|
clos);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-31 21:57:04 +00:00
|
|
|
|
g_slist_free_full (bookmarks, g_object_unref);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
/* Add new bookmark row */
|
|
|
|
|
new_bookmark_icon = g_themed_icon_new ("bookmark-new-symbolic");
|
|
|
|
|
sidebar->new_bookmark_row = add_place (sidebar, PLACES_DROP_FEEDBACK,
|
|
|
|
|
SECTION_BOOKMARKS,
|
2017-08-10 20:30:36 +00:00
|
|
|
|
_("New bookmark"), new_bookmark_icon, NULL, NULL,
|
|
|
|
|
NULL, NULL, NULL, NULL, 0,
|
2015-05-06 21:07:17 +00:00
|
|
|
|
_("Add a new bookmark"));
|
|
|
|
|
context = gtk_widget_get_style_context (sidebar->new_bookmark_row);
|
|
|
|
|
gtk_style_context_add_class (context, "sidebar-new-bookmark-row");
|
|
|
|
|
g_object_unref (new_bookmark_icon);
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
/* network */
|
2013-11-09 23:28:12 +00:00
|
|
|
|
if (!sidebar->local_only)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
2013-11-09 23:28:12 +00:00
|
|
|
|
network_volumes = g_list_reverse (network_volumes);
|
|
|
|
|
for (l = network_volumes; l != NULL; l = l->next)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
2013-11-09 23:28:12 +00:00
|
|
|
|
volume = l->data;
|
|
|
|
|
mount = g_volume_get_mount (volume);
|
|
|
|
|
|
|
|
|
|
if (mount != NULL)
|
|
|
|
|
{
|
|
|
|
|
network_mounts = g_list_prepend (network_mounts, mount);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-08-10 20:30:36 +00:00
|
|
|
|
start_icon = g_volume_get_symbolic_icon (volume);
|
2013-11-09 23:28:12 +00:00
|
|
|
|
name = g_volume_get_name (volume);
|
2014-08-22 15:07:41 +00:00
|
|
|
|
tooltip = g_strdup_printf (_("Mount and open “%s”"), name);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2013-11-09 23:28:12 +00:00
|
|
|
|
add_place (sidebar, PLACES_MOUNTED_VOLUME,
|
2015-07-14 17:47:42 +00:00
|
|
|
|
SECTION_MOUNTS,
|
2017-08-10 20:30:36 +00:00
|
|
|
|
name, start_icon, NULL, NULL,
|
|
|
|
|
NULL, volume, NULL, NULL, 0, tooltip);
|
|
|
|
|
g_object_unref (start_icon);
|
2013-11-09 23:28:12 +00:00
|
|
|
|
g_free (name);
|
|
|
|
|
g_free (tooltip);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
network_mounts = g_list_reverse (network_mounts);
|
|
|
|
|
for (l = network_mounts; l != NULL; l = l->next)
|
|
|
|
|
{
|
2016-10-15 20:24:42 +00:00
|
|
|
|
char *mount_uri;
|
|
|
|
|
|
2013-11-09 23:28:12 +00:00
|
|
|
|
mount = l->data;
|
|
|
|
|
root = g_mount_get_default_location (mount);
|
2017-08-10 20:30:36 +00:00
|
|
|
|
start_icon = g_mount_get_symbolic_icon (mount);
|
2013-11-09 23:28:12 +00:00
|
|
|
|
mount_uri = g_file_get_uri (root);
|
|
|
|
|
name = g_mount_get_name (mount);
|
|
|
|
|
tooltip = g_file_get_parse_name (root);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
add_place (sidebar, PLACES_MOUNTED_VOLUME,
|
2015-07-14 17:47:42 +00:00
|
|
|
|
SECTION_MOUNTS,
|
2017-08-10 20:30:36 +00:00
|
|
|
|
name, start_icon, NULL, mount_uri,
|
|
|
|
|
NULL, NULL, mount, NULL, 0, tooltip);
|
2013-11-09 23:28:12 +00:00
|
|
|
|
g_object_unref (root);
|
2017-08-10 20:30:36 +00:00
|
|
|
|
g_object_unref (start_icon);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_free (name);
|
2013-11-09 23:28:12 +00:00
|
|
|
|
g_free (mount_uri);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_free (tooltip);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_list_free_full (network_volumes, g_object_unref);
|
|
|
|
|
g_list_free_full (network_mounts, g_object_unref);
|
|
|
|
|
|
2015-07-14 17:47:42 +00:00
|
|
|
|
/* Other locations */
|
|
|
|
|
if (sidebar->show_other_locations)
|
|
|
|
|
{
|
2017-08-10 20:30:36 +00:00
|
|
|
|
start_icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_OTHER_LOCATIONS);
|
2015-07-14 17:47:42 +00:00
|
|
|
|
|
|
|
|
|
add_place (sidebar, PLACES_OTHER_LOCATIONS,
|
|
|
|
|
SECTION_OTHER_LOCATIONS,
|
2017-08-10 20:30:36 +00:00
|
|
|
|
_("Other Locations"), start_icon, NULL, "other-locations:///",
|
|
|
|
|
NULL, NULL, NULL, NULL, 0, _("Show other locations"));
|
2015-07-14 17:47:42 +00:00
|
|
|
|
|
2017-08-10 20:30:36 +00:00
|
|
|
|
g_object_unref (start_icon);
|
2015-07-14 17:47:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-19 09:02:04 +00:00
|
|
|
|
gtk_widget_show (GTK_WIDGET (sidebar));
|
2015-05-06 21:07:17 +00:00
|
|
|
|
/* We want this hidden by default, but need to do it after the show_all call */
|
|
|
|
|
gtk_sidebar_row_hide (GTK_SIDEBAR_ROW (sidebar->new_bookmark_row), TRUE);
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
/* restore original selection */
|
|
|
|
|
if (original_uri)
|
|
|
|
|
{
|
|
|
|
|
GFile *restore;
|
|
|
|
|
|
|
|
|
|
restore = g_file_new_for_uri (original_uri);
|
|
|
|
|
gtk_places_sidebar_set_location (sidebar, restore);
|
|
|
|
|
g_object_unref (restore);
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_free (original_uri);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2015-05-06 21:07:17 +00:00
|
|
|
|
check_valid_drop_target (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GtkSidebarRow *row,
|
2018-07-17 06:31:54 +00:00
|
|
|
|
GdkDrag *drag)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GtkPlacesSidebarPlaceType place_type;
|
|
|
|
|
GtkPlacesSidebarSectionType section_type;
|
|
|
|
|
gboolean valid = FALSE;
|
2015-05-11 17:12:32 +00:00
|
|
|
|
gchar *uri;
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GFile *dest_file;
|
|
|
|
|
gint drag_action;
|
2015-05-11 17:12:32 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
if (row == NULL)
|
|
|
|
|
return FALSE;
|
2015-05-11 17:12:32 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
g_object_get (row,
|
|
|
|
|
"place-type", &place_type,
|
|
|
|
|
"section_type", §ion_type,
|
|
|
|
|
"uri", &uri,
|
|
|
|
|
NULL);
|
2015-05-11 17:12:32 +00:00
|
|
|
|
|
2017-07-20 15:29:42 +00:00
|
|
|
|
if (place_type == PLACES_STARRED_LOCATION)
|
|
|
|
|
{
|
|
|
|
|
g_free (uri);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
if (place_type == PLACES_CONNECT_TO_SERVER)
|
2015-06-23 20:06:30 +00:00
|
|
|
|
{
|
|
|
|
|
g_free (uri);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
if (place_type == PLACES_DROP_FEEDBACK)
|
2015-06-23 20:06:30 +00:00
|
|
|
|
{
|
|
|
|
|
g_free (uri);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
/* Disallow drops on recent:/// */
|
|
|
|
|
if (place_type == PLACES_BUILT_IN)
|
|
|
|
|
{
|
|
|
|
|
if (g_strcmp0 (uri, "recent:///") == 0)
|
2015-06-23 20:06:30 +00:00
|
|
|
|
{
|
|
|
|
|
g_free (uri);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Dragging a bookmark? */
|
|
|
|
|
if (sidebar->drag_data_received &&
|
2015-05-06 21:07:17 +00:00
|
|
|
|
sidebar->drag_data_info == DND_GTK_SIDEBAR_ROW)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
|
|
|
|
/* Don't allow reordering bookmarks into non-bookmark areas */
|
2015-05-06 21:07:17 +00:00
|
|
|
|
valid = section_type == SECTION_BOOKMARKS;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2015-05-06 21:07:17 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
/* Dragging a file */
|
2018-07-17 06:31:54 +00:00
|
|
|
|
if (drag)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
if (uri != NULL)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
dest_file = g_file_new_for_uri (uri);
|
2018-07-17 06:31:54 +00:00
|
|
|
|
drag_action = emit_drag_action_requested (sidebar, drag, dest_file, sidebar->drag_list);
|
2015-05-06 21:07:17 +00:00
|
|
|
|
valid = drag_action > 0;
|
|
|
|
|
|
|
|
|
|
g_object_unref (dest_file);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
valid = FALSE;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-05-06 21:07:17 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2018-05-15 22:59:01 +00:00
|
|
|
|
/* We cannot discern if it is valid or not because there is not drop
|
|
|
|
|
* available to ask the client.
|
2015-05-06 21:07:17 +00:00
|
|
|
|
* Simply make insensitive the drop targets we know are not valid for
|
|
|
|
|
* files, that are the ones remaining.
|
|
|
|
|
*/
|
|
|
|
|
valid = TRUE;
|
|
|
|
|
}
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_free (uri);
|
2015-05-06 21:07:17 +00:00
|
|
|
|
return valid;
|
|
|
|
|
}
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
static void
|
|
|
|
|
update_possible_drop_targets (GtkPlacesSidebar *sidebar,
|
|
|
|
|
gboolean dragging,
|
2018-07-17 06:31:54 +00:00
|
|
|
|
GdkDrag *drag)
|
2015-05-06 21:07:17 +00:00
|
|
|
|
{
|
|
|
|
|
GList *rows;
|
|
|
|
|
GList *l;
|
|
|
|
|
gboolean sensitive;
|
2013-02-27 20:04:33 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
rows = gtk_container_get_children (GTK_CONTAINER (sidebar->list_box));
|
2013-04-19 20:49:54 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
for (l = rows; l != NULL; l = l->next)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
2018-07-17 06:31:54 +00:00
|
|
|
|
sensitive = !dragging || check_valid_drop_target (sidebar, GTK_SIDEBAR_ROW (l->data), drag);
|
2015-06-23 20:06:30 +00:00
|
|
|
|
gtk_widget_set_sensitive (GTK_WIDGET (l->data), sensitive);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
2013-01-29 07:14:10 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
g_list_free (rows);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2015-05-06 21:07:17 +00:00
|
|
|
|
get_drag_data (GtkWidget *list_box,
|
2018-05-17 02:51:18 +00:00
|
|
|
|
GdkDrop *drop,
|
|
|
|
|
GtkListBoxRow *row)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GdkAtom target;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2018-05-17 02:51:18 +00:00
|
|
|
|
target = gtk_drag_dest_find_target (list_box, drop, NULL);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2017-11-15 17:13:31 +00:00
|
|
|
|
if (target == NULL)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
return FALSE;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2018-05-16 02:50:24 +00:00
|
|
|
|
if (row)
|
2018-05-17 02:51:18 +00:00
|
|
|
|
g_object_set_data_full (G_OBJECT (drop), "places-sidebar-row", g_object_ref (row), g_object_unref);
|
|
|
|
|
gtk_drag_get_data (list_box, drop, target);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
return TRUE;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2011-09-06 23:11:19 +00:00
|
|
|
|
free_drag_data (GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
sidebar->drag_data_received = FALSE;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
if (sidebar->drag_list)
|
|
|
|
|
{
|
|
|
|
|
g_list_free_full (sidebar->drag_list, g_object_unref);
|
|
|
|
|
sidebar->drag_list = NULL;
|
|
|
|
|
}
|
2013-04-20 19:41:08 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
static void
|
|
|
|
|
start_drop_feedback (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GtkSidebarRow *row,
|
2018-07-17 06:31:54 +00:00
|
|
|
|
GdkDrag *drag)
|
2013-04-20 19:41:08 +00:00
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
if (sidebar->drag_data_info != DND_GTK_SIDEBAR_ROW)
|
|
|
|
|
{
|
|
|
|
|
gtk_sidebar_row_reveal (GTK_SIDEBAR_ROW (sidebar->new_bookmark_row));
|
2015-06-23 20:06:30 +00:00
|
|
|
|
/* If the state is permanent, don't change it. The application controls it. */
|
2015-05-06 21:07:17 +00:00
|
|
|
|
if (sidebar->drop_state != DROP_STATE_NEW_BOOKMARK_ARMED_PERMANENT)
|
|
|
|
|
sidebar->drop_state = DROP_STATE_NEW_BOOKMARK_ARMED;
|
|
|
|
|
}
|
2013-04-20 19:41:08 +00:00
|
|
|
|
|
2018-07-17 06:31:54 +00:00
|
|
|
|
update_possible_drop_targets (sidebar, TRUE, drag);
|
2013-04-20 19:41:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-05-06 21:07:17 +00:00
|
|
|
|
stop_drop_feedback (GtkPlacesSidebar *sidebar)
|
2013-04-20 19:41:08 +00:00
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
update_possible_drop_targets (sidebar, FALSE, NULL);
|
2013-04-20 19:41:08 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
free_drag_data (sidebar);
|
2013-04-20 19:41:08 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
if (sidebar->drop_state != DROP_STATE_NEW_BOOKMARK_ARMED_PERMANENT &&
|
|
|
|
|
sidebar->new_bookmark_row != NULL)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
gtk_sidebar_row_hide (GTK_SIDEBAR_ROW (sidebar->new_bookmark_row), FALSE);
|
|
|
|
|
sidebar->drop_state = DROP_STATE_NORMAL;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
if (sidebar->drag_row != NULL)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
gtk_widget_show (sidebar->drag_row);
|
|
|
|
|
sidebar->drag_row = NULL;
|
|
|
|
|
}
|
2013-04-20 15:42:04 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
if (sidebar->row_placeholder != NULL)
|
|
|
|
|
{
|
|
|
|
|
gtk_widget_destroy (sidebar->row_placeholder);
|
|
|
|
|
sidebar->row_placeholder = NULL;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
2015-05-06 21:07:17 +00:00
|
|
|
|
|
|
|
|
|
sidebar->dragging_over = FALSE;
|
|
|
|
|
sidebar->drag_data_info = DND_UNKNOWN;
|
2013-04-19 22:22:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-11 11:53:18 +00:00
|
|
|
|
static void
|
2015-05-06 21:07:17 +00:00
|
|
|
|
drag_begin_callback (GtkWidget *widget,
|
2018-06-29 17:34:14 +00:00
|
|
|
|
GdkDrag *drag,
|
2015-05-06 21:07:17 +00:00
|
|
|
|
gpointer user_data)
|
2015-04-11 11:53:18 +00:00
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (user_data);
|
|
|
|
|
GtkAllocation allocation;
|
|
|
|
|
GtkWidget *drag_widget;
|
|
|
|
|
|
|
|
|
|
gtk_widget_get_allocation (sidebar->drag_row, &allocation);
|
|
|
|
|
gtk_widget_hide (sidebar->drag_row);
|
|
|
|
|
|
|
|
|
|
drag_widget = GTK_WIDGET (gtk_sidebar_row_clone (GTK_SIDEBAR_ROW (sidebar->drag_row)));
|
|
|
|
|
sidebar->drag_row_height = allocation.height;
|
2018-02-23 10:08:53 +00:00
|
|
|
|
gtk_widget_set_size_request (drag_widget, allocation.width, allocation.height);
|
2015-05-11 17:12:32 +00:00
|
|
|
|
|
2018-02-23 10:08:53 +00:00
|
|
|
|
gtk_widget_set_opacity (drag_widget, 0.8);
|
2015-05-06 21:07:17 +00:00
|
|
|
|
|
2018-06-29 17:34:14 +00:00
|
|
|
|
gtk_drag_set_icon_widget (drag,
|
2018-02-23 10:08:53 +00:00
|
|
|
|
drag_widget,
|
2015-05-06 21:07:17 +00:00
|
|
|
|
sidebar->drag_row_x,
|
|
|
|
|
sidebar->drag_row_y);
|
2013-04-19 16:25:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
static GtkWidget *
|
|
|
|
|
create_placeholder_row (GtkPlacesSidebar *sidebar)
|
2013-04-19 16:25:03 +00:00
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
return g_object_new (GTK_TYPE_SIDEBAR_ROW,
|
|
|
|
|
"placeholder", TRUE,
|
|
|
|
|
NULL);
|
2013-04-19 16:25:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
static gboolean
|
2018-05-17 02:51:18 +00:00
|
|
|
|
drag_motion_callback (GtkWidget *widget,
|
|
|
|
|
GdkDrop *drop,
|
|
|
|
|
gint x,
|
|
|
|
|
gint y,
|
|
|
|
|
gpointer user_data)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
|
|
|
|
gint action;
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GtkListBoxRow *row;
|
|
|
|
|
GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (user_data);
|
|
|
|
|
GtkPlacesSidebarPlaceType place_type;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
gchar *drop_target_uri = NULL;
|
2015-05-06 21:07:17 +00:00
|
|
|
|
gint row_index;
|
|
|
|
|
gint row_placeholder_index;
|
2018-07-17 06:31:54 +00:00
|
|
|
|
GdkDrag *drag;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-04-11 15:35:23 +00:00
|
|
|
|
sidebar->dragging_over = TRUE;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
action = 0;
|
2015-05-06 21:07:17 +00:00
|
|
|
|
row = gtk_list_box_get_row_at_y (GTK_LIST_BOX (sidebar->list_box), y);
|
2018-07-17 06:31:54 +00:00
|
|
|
|
drag = gdk_drop_get_drag (drop);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
gtk_list_box_drag_unhighlight_row (GTK_LIST_BOX (sidebar->list_box));
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
/* Nothing to do if no drag data */
|
|
|
|
|
if (!sidebar->drag_data_received &&
|
2018-05-17 02:51:18 +00:00
|
|
|
|
!get_drag_data (sidebar->list_box, drop, row))
|
2015-05-06 21:07:17 +00:00
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
/* Nothing to do if the target is not valid drop destination */
|
2018-07-17 06:31:54 +00:00
|
|
|
|
if (!check_valid_drop_target (sidebar, GTK_SIDEBAR_ROW (row), drag))
|
2013-11-09 22:28:02 +00:00
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
|
|
if (sidebar->drag_data_received &&
|
2015-05-06 21:07:17 +00:00
|
|
|
|
sidebar->drag_data_info == DND_GTK_SIDEBAR_ROW)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
|
|
|
|
/* Dragging bookmarks always moves them to another position in the bookmarks list */
|
|
|
|
|
action = GDK_ACTION_MOVE;
|
2015-05-06 21:07:17 +00:00
|
|
|
|
if (sidebar->row_placeholder == NULL)
|
|
|
|
|
{
|
|
|
|
|
sidebar->row_placeholder = create_placeholder_row (sidebar);
|
|
|
|
|
gtk_widget_show (sidebar->row_placeholder);
|
|
|
|
|
g_object_ref_sink (sidebar->row_placeholder);
|
|
|
|
|
}
|
|
|
|
|
else if (GTK_WIDGET (row) == sidebar->row_placeholder)
|
|
|
|
|
{
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (gtk_widget_get_parent (sidebar->row_placeholder) != NULL)
|
|
|
|
|
{
|
|
|
|
|
gtk_container_remove (GTK_CONTAINER (sidebar->list_box),
|
|
|
|
|
sidebar->row_placeholder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (row != NULL)
|
|
|
|
|
{
|
|
|
|
|
gint dest_y, dest_x;
|
|
|
|
|
|
|
|
|
|
g_object_get (row, "order-index", &row_index, NULL);
|
|
|
|
|
g_object_get (sidebar->row_placeholder, "order-index", &row_placeholder_index, NULL);
|
|
|
|
|
/* We order the bookmarks sections based on the bookmark index that we
|
|
|
|
|
* set on the row as order-index property, but we have to deal with
|
|
|
|
|
* the placeholder row wanting to be between two consecutive bookmarks,
|
|
|
|
|
* with two consecutive order-index values which is the usual case.
|
|
|
|
|
* For that, in the list box sort func we give priority to the placeholder row,
|
|
|
|
|
* that means that if the index-order is the same as another bookmark
|
|
|
|
|
* the placeholder row goes before. However if we want to show it after
|
|
|
|
|
* the current row, for instance when the cursor is in the lower half
|
|
|
|
|
* of the row, we need to increase the order-index.
|
|
|
|
|
*/
|
2015-06-23 20:06:30 +00:00
|
|
|
|
row_placeholder_index = row_index;
|
|
|
|
|
gtk_widget_translate_coordinates (widget, GTK_WIDGET (row),
|
|
|
|
|
x, y,
|
|
|
|
|
&dest_x, &dest_y);
|
2015-05-06 21:07:17 +00:00
|
|
|
|
|
2015-06-23 20:06:30 +00:00
|
|
|
|
if (dest_y > sidebar->drag_row_height / 2 && row_index > 0)
|
|
|
|
|
row_placeholder_index++;
|
2015-05-06 21:07:17 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* If the user is dragging over an area that has no row, place the row
|
2015-06-23 20:06:30 +00:00
|
|
|
|
* placeholder in the last position
|
|
|
|
|
*/
|
2015-05-06 21:07:17 +00:00
|
|
|
|
row_placeholder_index = G_MAXINT32;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_set (sidebar->row_placeholder, "order-index", row_placeholder_index, NULL);
|
|
|
|
|
|
|
|
|
|
gtk_list_box_prepend (GTK_LIST_BOX (sidebar->list_box),
|
|
|
|
|
sidebar->row_placeholder);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
gtk_list_box_drag_highlight_row (GTK_LIST_BOX (sidebar->list_box), row);
|
|
|
|
|
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_object_get (row,
|
2015-05-06 21:07:17 +00:00
|
|
|
|
"place-type", &place_type,
|
|
|
|
|
"uri", &drop_target_uri,
|
|
|
|
|
NULL);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
/* URIs are being dragged. See if the caller wants to handle a
|
|
|
|
|
* file move/copy operation itself, or if we should only try to
|
|
|
|
|
* create bookmarks out of the dragged URIs.
|
|
|
|
|
*/
|
|
|
|
|
if (sidebar->drag_list != NULL)
|
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
if (place_type == PLACES_DROP_FEEDBACK)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
|
|
|
|
action = GDK_ACTION_COPY;
|
|
|
|
|
}
|
2015-05-06 21:07:17 +00:00
|
|
|
|
else
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
/* uri may be NULL for unmounted volumes, for example, so we don't allow drops there */
|
2013-11-09 22:28:02 +00:00
|
|
|
|
if (drop_target_uri != NULL)
|
|
|
|
|
{
|
|
|
|
|
GFile *dest_file = g_file_new_for_uri (drop_target_uri);
|
|
|
|
|
|
2018-07-17 06:31:54 +00:00
|
|
|
|
action = emit_drag_action_requested (sidebar, drag, dest_file, sidebar->drag_list);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
|
|
|
|
g_object_unref (dest_file);
|
2015-05-06 21:07:17 +00:00
|
|
|
|
}
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-06-23 20:06:30 +00:00
|
|
|
|
|
|
|
|
|
g_free (drop_target_uri);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2013-01-26 00:01:42 +00:00
|
|
|
|
out:
|
2018-07-17 06:31:54 +00:00
|
|
|
|
start_drop_feedback (sidebar, GTK_SIDEBAR_ROW (row), drag);
|
2013-04-20 19:41:08 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
g_signal_stop_emission_by_name (sidebar->list_box, "drag-motion");
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2018-05-17 02:51:18 +00:00
|
|
|
|
gdk_drop_status (drop, action);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
return TRUE;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-01-21 23:59:23 +00:00
|
|
|
|
/* Takes an array of URIs and turns it into a list of GFile */
|
2012-10-20 19:00:50 +00:00
|
|
|
|
static GList *
|
2013-11-09 22:28:02 +00:00
|
|
|
|
build_file_list_from_uris (const gchar **uris)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GList *result;
|
|
|
|
|
gint i;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
result = NULL;
|
2015-10-29 12:56:18 +00:00
|
|
|
|
for (i = 0; uris && uris[i]; i++)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
|
|
|
|
GFile *file;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
file = g_file_new_for_uri (uris[i]);
|
|
|
|
|
result = g_list_prepend (result, file);
|
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
return g_list_reverse (result);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
/* Reorders the bookmark to the specified position */
|
2011-09-06 22:53:30 +00:00
|
|
|
|
static void
|
2011-09-06 23:11:19 +00:00
|
|
|
|
reorder_bookmarks (GtkPlacesSidebar *sidebar,
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GtkSidebarRow *row,
|
2013-11-09 22:28:02 +00:00
|
|
|
|
gint new_position)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
gchar *uri;
|
|
|
|
|
GFile *file;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
g_object_get (row, "uri", &uri, NULL);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
file = g_file_new_for_uri (uri);
|
2015-06-16 14:25:33 +00:00
|
|
|
|
_gtk_bookmarks_manager_reorder_bookmark (sidebar->bookmarks_manager, file, new_position, NULL);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_object_unref (file);
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_free (uri);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-02-05 20:44:58 +00:00
|
|
|
|
/* Creates bookmarks for the specified files at the given position in the bookmarks list */
|
|
|
|
|
static void
|
|
|
|
|
drop_files_as_bookmarks (GtkPlacesSidebar *sidebar,
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GList *files,
|
|
|
|
|
gint position)
|
2013-02-05 20:44:58 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GList *l;
|
2013-02-05 20:44:58 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
for (l = files; l; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
GFile *f = G_FILE (l->data);
|
|
|
|
|
GFileInfo *info = g_file_query_info (f,
|
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_TYPE,
|
|
|
|
|
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
2013-02-05 20:44:58 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
if (info)
|
|
|
|
|
{
|
|
|
|
|
if (_gtk_file_info_consider_as_directory (info))
|
2015-06-16 14:25:33 +00:00
|
|
|
|
_gtk_bookmarks_manager_insert_bookmark (sidebar->bookmarks_manager, f, position++, NULL);
|
2013-05-22 22:22:28 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_object_unref (info);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-02-05 20:44:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
static void
|
2015-05-06 21:07:17 +00:00
|
|
|
|
drag_data_get_callback (GtkWidget *widget,
|
2018-06-29 17:34:14 +00:00
|
|
|
|
GdkDrag *drag,
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GtkSelectionData *data,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (user_data);
|
|
|
|
|
GdkAtom target = gtk_selection_data_get_target (data);
|
|
|
|
|
|
2017-12-14 04:39:03 +00:00
|
|
|
|
if (target == g_intern_static_string ("DND_GTK_SIDEBAR_ROW"))
|
2015-05-06 21:07:17 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_selection_data_set (data,
|
|
|
|
|
target,
|
|
|
|
|
8,
|
|
|
|
|
(void*)&sidebar->drag_row,
|
|
|
|
|
sizeof (gpointer));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
drag_data_received_callback (GtkWidget *list_box,
|
2018-05-16 02:50:24 +00:00
|
|
|
|
GdkDrop *drop,
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GtkSelectionData *selection_data,
|
2015-05-06 21:07:17 +00:00
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
gint target_order_index;
|
|
|
|
|
GtkPlacesSidebarPlaceType target_place_type;
|
|
|
|
|
GtkPlacesSidebarSectionType target_section_type;
|
|
|
|
|
gchar *target_uri;
|
|
|
|
|
GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (user_data);
|
|
|
|
|
GtkListBoxRow *target_row;
|
2018-05-16 02:50:24 +00:00
|
|
|
|
GdkDragAction real_action;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
|
|
|
|
if (!sidebar->drag_data_received)
|
|
|
|
|
{
|
2017-11-16 21:50:37 +00:00
|
|
|
|
if (gtk_selection_data_targets_include_uri (selection_data))
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
|
|
|
|
gchar **uris;
|
|
|
|
|
|
|
|
|
|
uris = gtk_selection_data_get_uris (selection_data);
|
2015-05-06 21:07:17 +00:00
|
|
|
|
/* Free spurious drag data from previous drags if present */
|
|
|
|
|
if (sidebar->drag_list != NULL)
|
|
|
|
|
g_list_free_full (sidebar->drag_list, g_object_unref);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
sidebar->drag_list = build_file_list_from_uris ((const char **) uris);
|
|
|
|
|
g_strfreev (uris);
|
2017-11-16 21:50:37 +00:00
|
|
|
|
sidebar->drag_data_info = DND_TEXT_URI_LIST;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sidebar->drag_list = NULL;
|
2017-12-14 04:39:03 +00:00
|
|
|
|
if (gtk_selection_data_get_target (selection_data) == g_intern_static_string ("DND_GTK_SIDEBAR_ROW"))
|
2017-11-16 21:50:37 +00:00
|
|
|
|
sidebar->drag_data_info = DND_GTK_SIDEBAR_ROW;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
|
|
|
|
sidebar->drag_data_received = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
g_signal_stop_emission_by_name (list_box, "drag-data-received");
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2016-03-11 03:46:02 +00:00
|
|
|
|
if (!sidebar->drop_occurred)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2018-05-16 02:50:24 +00:00
|
|
|
|
target_row = g_object_get_data (G_OBJECT (drop), "places-sidebar-row");
|
2015-05-06 21:07:17 +00:00
|
|
|
|
if (target_row == NULL)
|
|
|
|
|
return;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_object_get (target_row,
|
2015-05-06 21:07:17 +00:00
|
|
|
|
"place-type", &target_place_type,
|
|
|
|
|
"section-type", &target_section_type,
|
|
|
|
|
"order-index", &target_order_index,
|
|
|
|
|
"uri", &target_uri,
|
|
|
|
|
NULL);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2018-05-16 02:50:24 +00:00
|
|
|
|
real_action = 0;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2018-07-17 06:31:54 +00:00
|
|
|
|
if (!check_valid_drop_target (sidebar, GTK_SIDEBAR_ROW (target_row), gdk_drop_get_drag (drop)))
|
2015-05-06 21:07:17 +00:00
|
|
|
|
goto out;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
if (sidebar->drag_data_info == DND_GTK_SIDEBAR_ROW)
|
|
|
|
|
{
|
2015-07-24 08:25:01 +00:00
|
|
|
|
GtkWidget **source_row;
|
2015-05-06 21:07:17 +00:00
|
|
|
|
/* A bookmark got reordered */
|
|
|
|
|
if (target_section_type != SECTION_BOOKMARKS)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
goto out;
|
|
|
|
|
|
2015-07-24 08:25:01 +00:00
|
|
|
|
source_row = (void*) gtk_selection_data_get_data (selection_data);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2017-10-07 15:17:20 +00:00
|
|
|
|
if (sidebar->row_placeholder != NULL)
|
|
|
|
|
g_object_get (sidebar->row_placeholder, "order-index", &target_order_index, NULL);
|
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
reorder_bookmarks (sidebar, GTK_SIDEBAR_ROW (*source_row), target_order_index);
|
2018-05-16 02:50:24 +00:00
|
|
|
|
real_action = GDK_ACTION_MOVE;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Dropping URIs! */
|
|
|
|
|
gchar **uris;
|
|
|
|
|
GList *source_file_list;
|
|
|
|
|
|
|
|
|
|
/* file transfer requested */
|
2018-05-16 02:50:24 +00:00
|
|
|
|
real_action = gdk_drop_get_actions (drop);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2018-05-16 02:50:24 +00:00
|
|
|
|
if (!gdk_drag_action_is_unique (real_action))
|
|
|
|
|
real_action = emit_drag_action_ask (sidebar, real_action);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
|
|
|
|
if (real_action > 0)
|
|
|
|
|
{
|
|
|
|
|
GFile *dest_file;
|
|
|
|
|
|
|
|
|
|
uris = gtk_selection_data_get_uris (selection_data);
|
|
|
|
|
source_file_list = build_file_list_from_uris ((const gchar **) uris);
|
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
if (target_place_type == PLACES_DROP_FEEDBACK)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
drop_files_as_bookmarks (sidebar, source_file_list, target_order_index);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
2015-05-06 21:07:17 +00:00
|
|
|
|
else
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
dest_file = g_file_new_for_uri (target_uri);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
|
|
|
|
emit_drag_perform_drop (sidebar, dest_file, source_file_list, real_action);
|
|
|
|
|
|
|
|
|
|
g_object_unref (dest_file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_list_free_full (source_file_list, g_object_unref);
|
|
|
|
|
g_strfreev (uris);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
|
|
|
|
out:
|
2016-03-11 03:46:02 +00:00
|
|
|
|
sidebar->drop_occurred = FALSE;
|
2018-05-16 02:50:24 +00:00
|
|
|
|
g_object_set_data (G_OBJECT (drop), "places-sidebar-row", NULL);
|
|
|
|
|
gdk_drop_finish (drop, real_action);
|
2015-05-06 21:07:17 +00:00
|
|
|
|
stop_drop_feedback (sidebar);
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_free (target_uri);
|
2015-05-06 21:07:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
drag_end_callback (GtkWidget *widget,
|
2018-06-29 17:34:14 +00:00
|
|
|
|
GdkDrag *drag,
|
2015-05-06 21:07:17 +00:00
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
stop_drop_feedback (GTK_PLACES_SIDEBAR (user_data));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* This functions is called every time the drag source leaves
|
|
|
|
|
* the sidebar widget.
|
|
|
|
|
* The problem is that, we start showing hints for drop when the source
|
|
|
|
|
* start being above the sidebar or when the application request so show
|
|
|
|
|
* drop hints, but at some moment we need to restore to normal
|
|
|
|
|
* state.
|
|
|
|
|
* One could think that here we could simply call stop_drop_feedback,
|
|
|
|
|
* but that's not true, because this function is called also before drag_drop,
|
|
|
|
|
* which needs the data from the drag so we cannot free the drag data here.
|
|
|
|
|
* So now one could think we could just do nothing here, and wait for
|
|
|
|
|
* drag-end or drag-failed signals and just stop_drop_feedback there. But that
|
|
|
|
|
* is also not true, since when the drag comes from a diferent widget than the
|
|
|
|
|
* sidebar, when the drag stops the last drag signal we receive is drag-leave.
|
|
|
|
|
* So here what we will do is restore the state of the sidebar as if no drag
|
|
|
|
|
* is being done (and if the application didnt request for permanent hints with
|
|
|
|
|
* gtk_places_sidebar_show_drop_hints) and we will free the drag data next time
|
|
|
|
|
* we build new drag data in drag_data_received.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
2018-05-15 22:59:01 +00:00
|
|
|
|
drag_leave_callback (GtkWidget *widget,
|
|
|
|
|
GdkDrop *drop,
|
|
|
|
|
gpointer user_data)
|
2015-05-06 21:07:17 +00:00
|
|
|
|
{
|
|
|
|
|
GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (user_data);
|
|
|
|
|
|
|
|
|
|
if (sidebar->drop_state != DROP_STATE_NEW_BOOKMARK_ARMED_PERMANENT)
|
|
|
|
|
{
|
2018-07-17 06:31:54 +00:00
|
|
|
|
update_possible_drop_targets (sidebar, FALSE, gdk_drop_get_drag (drop));
|
2015-05-06 21:07:17 +00:00
|
|
|
|
gtk_sidebar_row_hide (GTK_SIDEBAR_ROW (sidebar->new_bookmark_row), FALSE);
|
|
|
|
|
sidebar->drop_state = DROP_STATE_NORMAL;
|
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
sidebar->drag_data_received = FALSE;
|
|
|
|
|
sidebar->dragging_over = FALSE;
|
|
|
|
|
sidebar->drag_data_info = DND_UNKNOWN;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2018-05-17 02:51:18 +00:00
|
|
|
|
drag_drop_callback (GtkWidget *list_box,
|
|
|
|
|
GdkDrop *drop,
|
|
|
|
|
gint x,
|
|
|
|
|
gint y,
|
|
|
|
|
gpointer user_data)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
gboolean retval = FALSE;
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (user_data);
|
2018-05-16 02:50:24 +00:00
|
|
|
|
GtkListBoxRow *row;
|
2013-04-20 15:42:04 +00:00
|
|
|
|
|
2018-05-16 02:50:24 +00:00
|
|
|
|
row = gtk_list_box_get_row_at_y (GTK_LIST_BOX (sidebar->list_box), y);
|
2016-03-11 03:46:02 +00:00
|
|
|
|
sidebar->drop_occurred = TRUE;
|
2018-05-17 02:51:18 +00:00
|
|
|
|
retval = get_drag_data (sidebar->list_box, drop, row);
|
2015-05-06 21:07:17 +00:00
|
|
|
|
g_signal_stop_emission_by_name (sidebar->list_box, "drag-drop");
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
return retval;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-11-09 22:28:02 +00:00
|
|
|
|
check_unmount_and_eject (GMount *mount,
|
|
|
|
|
GVolume *volume,
|
|
|
|
|
GDrive *drive,
|
|
|
|
|
gboolean *show_unmount,
|
|
|
|
|
gboolean *show_eject)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
*show_unmount = FALSE;
|
|
|
|
|
*show_eject = FALSE;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
if (drive != NULL)
|
|
|
|
|
*show_eject = g_drive_can_eject (drive);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-11-09 22:28:02 +00:00
|
|
|
|
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) &&
|
|
|
|
|
!g_drive_is_media_check_automatic (drive) &&
|
|
|
|
|
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);
|
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-14 23:56:53 +00:00
|
|
|
|
typedef struct {
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GtkWidget *add_shortcut_item;
|
|
|
|
|
GtkWidget *remove_item;
|
|
|
|
|
GtkWidget *rename_item;
|
|
|
|
|
GtkWidget *separator_item;
|
|
|
|
|
GtkWidget *mount_item;
|
|
|
|
|
GtkWidget *unmount_item;
|
|
|
|
|
GtkWidget *eject_item;
|
|
|
|
|
GtkWidget *rescan_item;
|
|
|
|
|
GtkWidget *start_item;
|
|
|
|
|
GtkWidget *stop_item;
|
2015-07-16 01:25:10 +00:00
|
|
|
|
} PopoverData;
|
2012-12-14 23:56:53 +00:00
|
|
|
|
|
|
|
|
|
static void
|
2015-07-16 01:25:10 +00:00
|
|
|
|
check_popover_sensitivity (GtkSidebarRow *row,
|
|
|
|
|
PopoverData *data)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
|
|
|
|
gboolean show_mount;
|
|
|
|
|
gboolean show_unmount;
|
|
|
|
|
gboolean show_eject;
|
|
|
|
|
gboolean show_rescan;
|
|
|
|
|
gboolean show_start;
|
|
|
|
|
gboolean show_stop;
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GtkPlacesSidebarPlaceType type;
|
|
|
|
|
GDrive *drive;
|
|
|
|
|
GVolume *volume;
|
|
|
|
|
GMount *mount;
|
2019-06-15 22:25:05 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar;
|
2015-07-16 01:25:10 +00:00
|
|
|
|
GAction *action;
|
2015-05-06 21:07:17 +00:00
|
|
|
|
|
|
|
|
|
g_object_get (row,
|
2015-07-16 01:25:10 +00:00
|
|
|
|
"sidebar", &sidebar,
|
2015-05-06 21:07:17 +00:00
|
|
|
|
"place-type", &type,
|
|
|
|
|
"drive", &drive,
|
|
|
|
|
"volume", &volume,
|
|
|
|
|
"mount", &mount,
|
|
|
|
|
NULL);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
gtk_widget_set_visible (data->add_shortcut_item, (type == PLACES_MOUNTED_VOLUME));
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2019-06-15 22:25:05 +00:00
|
|
|
|
action = g_action_map_lookup_action (G_ACTION_MAP (sidebar->row_actions), "remove");
|
2015-07-16 01:25:10 +00:00
|
|
|
|
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), (type == PLACES_BOOKMARK));
|
2019-06-15 22:25:05 +00:00
|
|
|
|
action = g_action_map_lookup_action (G_ACTION_MAP (sidebar->row_actions), "rename");
|
2015-07-16 01:25:10 +00:00
|
|
|
|
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), (type == PLACES_BOOKMARK ||
|
|
|
|
|
type == PLACES_XDG_DIR));
|
2019-06-15 22:25:05 +00:00
|
|
|
|
action = g_action_map_lookup_action (G_ACTION_MAP (sidebar->row_actions), "open");
|
2015-09-02 02:05:46 +00:00
|
|
|
|
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), !gtk_list_box_row_is_selected (GTK_LIST_BOX_ROW (row)));
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
check_visibility (mount, volume, drive,
|
2013-11-09 22:28:02 +00:00
|
|
|
|
&show_mount, &show_unmount, &show_eject, &show_rescan, &show_start, &show_stop);
|
|
|
|
|
|
|
|
|
|
gtk_widget_set_visible (data->separator_item, show_mount || show_unmount || show_eject);
|
|
|
|
|
gtk_widget_set_visible (data->mount_item, show_mount);
|
|
|
|
|
gtk_widget_set_visible (data->unmount_item, show_unmount);
|
|
|
|
|
gtk_widget_set_visible (data->eject_item, show_eject);
|
|
|
|
|
gtk_widget_set_visible (data->rescan_item, show_rescan);
|
|
|
|
|
gtk_widget_set_visible (data->start_item, show_start);
|
|
|
|
|
gtk_widget_set_visible (data->stop_item, show_stop);
|
|
|
|
|
|
|
|
|
|
/* Adjust start/stop items to reflect the type of the drive */
|
2015-07-16 01:25:10 +00:00
|
|
|
|
g_object_set (data->start_item, "text", _("_Start"), NULL);
|
|
|
|
|
g_object_set (data->stop_item, "text", _("_Stop"), NULL);
|
2015-05-06 21:07:17 +00:00
|
|
|
|
if ((show_start || show_stop) && drive != NULL)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
switch (g_drive_get_start_stop_type (drive))
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
|
|
|
|
case G_DRIVE_START_STOP_TYPE_SHUTDOWN:
|
|
|
|
|
/* start() for type G_DRIVE_START_STOP_TYPE_SHUTDOWN is normally not used */
|
2015-07-16 01:25:10 +00:00
|
|
|
|
g_object_set (data->start_item, "text", _("_Power On"), NULL);
|
|
|
|
|
g_object_set (data->stop_item, "text", _("_Safely Remove Drive"), NULL);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case G_DRIVE_START_STOP_TYPE_NETWORK:
|
2015-07-16 01:25:10 +00:00
|
|
|
|
g_object_set (data->start_item, "text", _("_Connect Drive"), NULL);
|
|
|
|
|
g_object_set (data->stop_item, "text", _("_Disconnect Drive"), NULL);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case G_DRIVE_START_STOP_TYPE_MULTIDISK:
|
2015-07-16 01:25:10 +00:00
|
|
|
|
g_object_set (data->start_item, "text", _("_Start Multi-disk Device"), NULL);
|
|
|
|
|
g_object_set (data->stop_item, "text", _("_Stop Multi-disk Device"), NULL);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case G_DRIVE_START_STOP_TYPE_PASSWORD:
|
|
|
|
|
/* stop() for type G_DRIVE_START_STOP_TYPE_PASSWORD is normally not used */
|
2015-07-16 01:25:10 +00:00
|
|
|
|
g_object_set (data->start_item, "text", _("_Unlock Device"), NULL);
|
|
|
|
|
g_object_set (data->stop_item, "text", _("_Lock Device"), NULL);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
case G_DRIVE_START_STOP_TYPE_UNKNOWN:
|
|
|
|
|
/* uses defaults set above */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-06-23 20:06:30 +00:00
|
|
|
|
|
|
|
|
|
if (drive)
|
|
|
|
|
g_object_unref (drive);
|
|
|
|
|
if (volume)
|
|
|
|
|
g_object_unref (volume);
|
|
|
|
|
if (mount)
|
|
|
|
|
g_object_unref (mount);
|
2015-07-16 01:25:10 +00:00
|
|
|
|
|
|
|
|
|
g_object_unref (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,
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GAsyncResult *res,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkPlacesSidebar *sidebar;
|
|
|
|
|
GError *error;
|
|
|
|
|
gchar *primary;
|
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
|
|
sidebar = GTK_PLACES_SIDEBAR (user_data);
|
|
|
|
|
|
|
|
|
|
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));
|
2014-08-22 15:07:41 +00:00
|
|
|
|
primary = g_strdup_printf (_("Unable to start “%s”"), name);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_free (name);
|
|
|
|
|
emit_show_error_message (sidebar, primary, error->message);
|
|
|
|
|
g_free (primary);
|
|
|
|
|
}
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-10-29 20:28:12 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
static void
|
|
|
|
|
volume_mount_cb (GObject *source_object,
|
|
|
|
|
GAsyncResult *result,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
2018-07-22 11:47:46 +00:00
|
|
|
|
GtkSidebarRow *row = GTK_SIDEBAR_ROW (user_data);
|
|
|
|
|
GtkPlacesSidebar *sidebar;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GVolume *volume;
|
|
|
|
|
GError *error;
|
|
|
|
|
gchar *primary;
|
|
|
|
|
gchar *name;
|
|
|
|
|
GMount *mount;
|
|
|
|
|
|
|
|
|
|
volume = G_VOLUME (source_object);
|
2018-07-22 11:47:46 +00:00
|
|
|
|
g_object_get (row, "sidebar", &sidebar, NULL);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
|
|
|
|
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));
|
2018-07-23 21:35:01 +00:00
|
|
|
|
if (g_str_has_prefix (error->message, "Error unlocking"))
|
|
|
|
|
/* Translators: This means that unlocking an encrypted storage
|
|
|
|
|
* device failed. %s is the name of the device.
|
|
|
|
|
*/
|
|
|
|
|
primary = g_strdup_printf (_("Error unlocking “%s”"), name);
|
|
|
|
|
else
|
|
|
|
|
primary = g_strdup_printf (_("Unable to access “%s”"), name);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_free (name);
|
|
|
|
|
emit_show_error_message (sidebar, primary, error->message);
|
|
|
|
|
g_free (primary);
|
|
|
|
|
}
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sidebar->mounting = FALSE;
|
2018-07-22 11:47:46 +00:00
|
|
|
|
gtk_sidebar_row_set_busy (row, FALSE);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
|
|
|
|
mount = g_volume_get_mount (volume);
|
|
|
|
|
if (mount != NULL)
|
|
|
|
|
{
|
|
|
|
|
GFile *location;
|
|
|
|
|
|
|
|
|
|
location = g_mount_get_default_location (mount);
|
|
|
|
|
emit_open_location (sidebar, location, sidebar->go_to_after_mount_open_flags);
|
|
|
|
|
|
|
|
|
|
g_object_unref (G_OBJECT (location));
|
|
|
|
|
g_object_unref (G_OBJECT (mount));
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-22 11:47:46 +00:00
|
|
|
|
g_object_unref (row);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_object_unref (sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2018-07-22 11:47:46 +00:00
|
|
|
|
mount_volume (GtkSidebarRow *row,
|
|
|
|
|
GVolume *volume)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2018-07-22 11:47:46 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GMountOperation *mount_op;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2018-07-22 11:47:46 +00:00
|
|
|
|
g_object_get (row, "sidebar", &sidebar, NULL);
|
|
|
|
|
|
2016-02-15 18:09:54 +00:00
|
|
|
|
mount_op = get_mount_operation (sidebar);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_mount_operation_set_password_save (mount_op, G_PASSWORD_SAVE_FOR_SESSION);
|
2011-10-06 14:20:32 +00:00
|
|
|
|
|
2018-07-22 11:47:46 +00:00
|
|
|
|
g_object_ref (row);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_object_ref (sidebar);
|
2018-07-22 11:47:46 +00:00
|
|
|
|
g_volume_mount (volume, 0, mount_op, NULL, volume_mount_cb, row);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-20 23:14:59 +00:00
|
|
|
|
static void
|
2018-07-22 11:47:46 +00:00
|
|
|
|
open_drive (GtkSidebarRow *row,
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GDrive *drive,
|
|
|
|
|
GtkPlacesOpenFlags open_flags)
|
2013-04-20 23:14:59 +00:00
|
|
|
|
{
|
2018-07-22 11:47:46 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar;
|
|
|
|
|
|
|
|
|
|
g_object_get (row, "sidebar", &sidebar, NULL);
|
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
if (drive != NULL &&
|
|
|
|
|
(g_drive_can_start (drive) || g_drive_can_start_degraded (drive)))
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
|
|
|
|
GMountOperation *mount_op;
|
2013-04-20 23:14:59 +00:00
|
|
|
|
|
2018-07-22 11:47:46 +00:00
|
|
|
|
gtk_sidebar_row_set_busy (row, TRUE);
|
2016-02-15 18:09:54 +00:00
|
|
|
|
mount_op = get_mount_operation (sidebar);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_drive_start (drive, G_DRIVE_START_NONE, mount_op, NULL, drive_start_from_bookmark_cb, NULL);
|
|
|
|
|
g_object_unref (mount_op);
|
|
|
|
|
}
|
2015-05-06 21:07:17 +00:00
|
|
|
|
}
|
2013-04-20 23:14:59 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
static void
|
2018-07-22 11:47:46 +00:00
|
|
|
|
open_volume (GtkSidebarRow *row,
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GVolume *volume,
|
|
|
|
|
GtkPlacesOpenFlags open_flags)
|
|
|
|
|
{
|
2018-07-22 11:47:46 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar;
|
|
|
|
|
|
|
|
|
|
g_object_get (row, "sidebar", &sidebar, NULL);
|
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
if (volume != NULL && !sidebar->mounting)
|
|
|
|
|
{
|
|
|
|
|
sidebar->mounting = TRUE;
|
|
|
|
|
sidebar->go_to_after_mount_open_flags = open_flags;
|
2018-07-22 11:47:46 +00:00
|
|
|
|
gtk_sidebar_row_set_busy (row, TRUE);
|
|
|
|
|
mount_volume (row, volume);
|
2015-05-06 21:07:17 +00:00
|
|
|
|
}
|
2013-04-20 23:14:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-05-06 21:07:17 +00:00
|
|
|
|
open_uri (GtkPlacesSidebar *sidebar,
|
|
|
|
|
const gchar *uri,
|
|
|
|
|
GtkPlacesOpenFlags open_flags)
|
2013-04-20 23:14:59 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GFile *location;
|
2013-04-20 23:14:59 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
location = g_file_new_for_uri (uri);
|
|
|
|
|
emit_open_location (sidebar, location, open_flags);
|
|
|
|
|
g_object_unref (location);
|
2013-04-20 23:14:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
static void
|
2015-05-06 21:07:17 +00:00
|
|
|
|
open_row (GtkSidebarRow *row,
|
|
|
|
|
GtkPlacesOpenFlags open_flags)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
|
|
|
|
gchar *uri;
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GDrive *drive;
|
|
|
|
|
GVolume *volume;
|
|
|
|
|
GtkPlacesSidebarPlaceType place_type;
|
|
|
|
|
GtkPlacesSidebar *sidebar;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
g_object_get (row,
|
|
|
|
|
"sidebar", &sidebar,
|
|
|
|
|
"uri", &uri,
|
|
|
|
|
"place-type", &place_type,
|
|
|
|
|
"drive", &drive,
|
|
|
|
|
"volume", &volume,
|
|
|
|
|
NULL);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-07-14 17:47:42 +00:00
|
|
|
|
if (place_type == PLACES_OTHER_LOCATIONS)
|
2016-02-29 22:13:51 +00:00
|
|
|
|
{
|
|
|
|
|
emit_show_other_locations_with_flags (sidebar, open_flags);
|
|
|
|
|
}
|
2017-07-20 15:29:42 +00:00
|
|
|
|
else if (place_type == PLACES_STARRED_LOCATION)
|
|
|
|
|
{
|
|
|
|
|
emit_show_starred_location (sidebar, open_flags);
|
|
|
|
|
}
|
2015-07-14 17:47:42 +00:00
|
|
|
|
else if (uri != NULL)
|
2016-02-29 22:13:51 +00:00
|
|
|
|
{
|
|
|
|
|
open_uri (sidebar, uri, open_flags);
|
|
|
|
|
}
|
2014-04-07 22:43:28 +00:00
|
|
|
|
else if (place_type == PLACES_ENTER_LOCATION)
|
2016-02-29 22:13:51 +00:00
|
|
|
|
{
|
|
|
|
|
emit_show_enter_location (sidebar);
|
|
|
|
|
}
|
2015-05-06 21:07:17 +00:00
|
|
|
|
else if (volume != NULL)
|
2016-02-29 22:13:51 +00:00
|
|
|
|
{
|
2018-07-22 11:47:46 +00:00
|
|
|
|
open_volume (row, volume, open_flags);
|
2016-02-29 22:13:51 +00:00
|
|
|
|
}
|
2015-05-06 21:07:17 +00:00
|
|
|
|
else if (drive != NULL)
|
2016-02-29 22:13:51 +00:00
|
|
|
|
{
|
2018-07-22 11:47:46 +00:00
|
|
|
|
open_drive (row, drive, open_flags);
|
2016-02-29 22:13:51 +00:00
|
|
|
|
}
|
2015-06-23 20:06:30 +00:00
|
|
|
|
|
|
|
|
|
g_object_unref (sidebar);
|
|
|
|
|
if (drive)
|
|
|
|
|
g_object_unref (drive);
|
|
|
|
|
if (volume)
|
|
|
|
|
g_object_unref (volume);
|
|
|
|
|
g_free (uri);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
/* Callback used for the "Open" menu items in the context menu */
|
2011-09-06 22:53:30 +00:00
|
|
|
|
static void
|
2015-07-16 01:25:10 +00:00
|
|
|
|
open_shortcut_cb (GSimpleAction *action,
|
|
|
|
|
GVariant *parameter,
|
|
|
|
|
gpointer data)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2015-07-16 01:25:10 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar = data;
|
|
|
|
|
GtkPlacesOpenFlags flags;
|
2013-01-10 22:19:03 +00:00
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
flags = (GtkPlacesOpenFlags)g_variant_get_int32 (parameter);
|
|
|
|
|
open_row (sidebar->context_row, flags);
|
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
|
2015-07-16 01:25:10 +00:00
|
|
|
|
add_shortcut_cb (GSimpleAction *action,
|
|
|
|
|
GVariant *parameter,
|
|
|
|
|
gpointer data)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2015-07-16 01:25:10 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar = data;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
gchar *uri;
|
|
|
|
|
gchar *name;
|
|
|
|
|
GFile *location;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
g_object_get (sidebar->context_row,
|
2015-06-23 20:06:30 +00:00
|
|
|
|
"uri", &uri,
|
|
|
|
|
"label", &name,
|
|
|
|
|
NULL);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2015-06-23 20:06:30 +00:00
|
|
|
|
if (uri != NULL)
|
|
|
|
|
{
|
|
|
|
|
location = g_file_new_for_uri (uri);
|
|
|
|
|
if (_gtk_bookmarks_manager_insert_bookmark (sidebar->bookmarks_manager, location, -1, NULL))
|
|
|
|
|
_gtk_bookmarks_manager_set_bookmark_label (sidebar->bookmarks_manager, location, name, NULL);
|
|
|
|
|
g_object_unref (location);
|
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_free (uri);
|
|
|
|
|
g_free (name);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-02 06:42:25 +00:00
|
|
|
|
static void
|
|
|
|
|
rename_entry_changed (GtkEntry *entry,
|
|
|
|
|
GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GtkPlacesSidebarPlaceType type;
|
2015-05-02 06:42:25 +00:00
|
|
|
|
gchar *name;
|
|
|
|
|
gchar *uri;
|
|
|
|
|
const gchar *new_name;
|
|
|
|
|
gboolean found = FALSE;
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GList *rows;
|
|
|
|
|
GList *l;
|
2015-05-02 06:42:25 +00:00
|
|
|
|
|
2019-02-28 19:31:36 +00:00
|
|
|
|
new_name = gtk_editable_get_text (GTK_EDITABLE (sidebar->rename_entry));
|
2015-05-02 06:42:25 +00:00
|
|
|
|
|
|
|
|
|
if (strcmp (new_name, "") == 0)
|
|
|
|
|
{
|
|
|
|
|
gtk_widget_set_sensitive (sidebar->rename_button, FALSE);
|
|
|
|
|
gtk_label_set_label (GTK_LABEL (sidebar->rename_error), "");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-07-07 01:59:10 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
rows = gtk_container_get_children (GTK_CONTAINER (sidebar->list_box));
|
2015-07-07 01:59:10 +00:00
|
|
|
|
for (l = rows; l && !found; l = l->next)
|
2015-05-06 21:07:17 +00:00
|
|
|
|
{
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_object_get (l->data,
|
2015-05-06 21:07:17 +00:00
|
|
|
|
"place-type", &type,
|
|
|
|
|
"uri", &uri,
|
2015-06-23 20:06:30 +00:00
|
|
|
|
"label", &name,
|
|
|
|
|
NULL);
|
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
if ((type == PLACES_XDG_DIR || type == PLACES_BOOKMARK) &&
|
|
|
|
|
strcmp (uri, sidebar->rename_uri) != 0 &&
|
|
|
|
|
strcmp (new_name, name) == 0)
|
|
|
|
|
found = TRUE;
|
|
|
|
|
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_free (uri);
|
|
|
|
|
g_free (name);
|
2015-05-06 21:07:17 +00:00
|
|
|
|
}
|
2015-07-07 01:59:10 +00:00
|
|
|
|
g_list_free (rows);
|
2015-05-02 06:42:25 +00:00
|
|
|
|
|
|
|
|
|
gtk_widget_set_sensitive (sidebar->rename_button, !found);
|
|
|
|
|
gtk_label_set_label (GTK_LABEL (sidebar->rename_error),
|
|
|
|
|
found ? _("This name is already taken") : "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
do_rename (GtkButton *button,
|
|
|
|
|
GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
2015-09-24 13:54:15 +00:00
|
|
|
|
gchar *new_text;
|
2015-05-02 06:42:25 +00:00
|
|
|
|
GFile *file;
|
|
|
|
|
|
2019-02-28 19:31:36 +00:00
|
|
|
|
new_text = g_strdup (gtk_editable_get_text (GTK_EDITABLE (sidebar->rename_entry)));
|
2015-05-02 06:42:25 +00:00
|
|
|
|
|
|
|
|
|
file = g_file_new_for_uri (sidebar->rename_uri);
|
|
|
|
|
if (!_gtk_bookmarks_manager_has_bookmark (sidebar->bookmarks_manager, file))
|
|
|
|
|
_gtk_bookmarks_manager_insert_bookmark (sidebar->bookmarks_manager, file, -1, NULL);
|
|
|
|
|
|
|
|
|
|
_gtk_bookmarks_manager_set_bookmark_label (sidebar->bookmarks_manager, file, new_text, NULL);
|
|
|
|
|
|
|
|
|
|
g_object_unref (file);
|
2015-09-24 13:54:15 +00:00
|
|
|
|
g_free (new_text);
|
2015-05-02 06:42:25 +00:00
|
|
|
|
|
|
|
|
|
g_clear_pointer (&sidebar->rename_uri, g_free);
|
|
|
|
|
|
2015-09-23 14:13:48 +00:00
|
|
|
|
if (sidebar->rename_popover)
|
2016-08-10 17:18:27 +00:00
|
|
|
|
gtk_popover_popdown (GTK_POPOVER (sidebar->rename_popover));
|
2015-09-23 14:13:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
on_rename_popover_destroy (GtkWidget *rename_popover,
|
|
|
|
|
GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
|
|
|
|
if (sidebar)
|
|
|
|
|
{
|
|
|
|
|
sidebar->rename_popover = NULL;
|
|
|
|
|
sidebar->rename_entry = NULL;
|
|
|
|
|
sidebar->rename_button = NULL;
|
|
|
|
|
sidebar->rename_error = NULL;
|
|
|
|
|
}
|
2015-05-02 06:42:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
create_rename_popover (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *popover;
|
|
|
|
|
GtkWidget *grid;
|
|
|
|
|
GtkWidget *label;
|
|
|
|
|
GtkWidget *entry;
|
|
|
|
|
GtkWidget *button;
|
|
|
|
|
GtkWidget *error;
|
|
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
|
|
if (sidebar->rename_popover)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
popover = gtk_popover_new (GTK_WIDGET (sidebar));
|
2015-09-23 14:13:48 +00:00
|
|
|
|
/* Clean sidebar pointer when its destroyed, most of the times due to its
|
|
|
|
|
* relative_to associated row being destroyed */
|
|
|
|
|
g_signal_connect (popover, "destroy", G_CALLBACK (on_rename_popover_destroy), sidebar);
|
2015-05-02 06:42:25 +00:00
|
|
|
|
gtk_popover_set_position (GTK_POPOVER (popover), GTK_POS_RIGHT);
|
|
|
|
|
grid = gtk_grid_new ();
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (popover), grid);
|
|
|
|
|
g_object_set (grid,
|
|
|
|
|
"margin", 10,
|
|
|
|
|
"row-spacing", 6,
|
|
|
|
|
"column-spacing", 6,
|
|
|
|
|
NULL);
|
|
|
|
|
entry = gtk_entry_new ();
|
2015-04-17 04:14:28 +00:00
|
|
|
|
gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
|
2015-05-02 06:42:25 +00:00
|
|
|
|
g_signal_connect (entry, "changed", G_CALLBACK (rename_entry_changed), sidebar);
|
|
|
|
|
str = g_strdup_printf ("<b>%s</b>", _("Name"));
|
|
|
|
|
label = gtk_label_new (str);
|
|
|
|
|
gtk_widget_set_halign (label, GTK_ALIGN_START);
|
|
|
|
|
gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
|
|
|
|
|
gtk_label_set_mnemonic_widget (GTK_LABEL (label), entry);
|
|
|
|
|
g_free (str);
|
|
|
|
|
button = gtk_button_new_with_mnemonic (_("_Rename"));
|
|
|
|
|
gtk_style_context_add_class (gtk_widget_get_style_context (button), "suggested-action");
|
|
|
|
|
g_signal_connect (button, "clicked", G_CALLBACK (do_rename), sidebar);
|
|
|
|
|
error = gtk_label_new ("");
|
|
|
|
|
gtk_widget_set_halign (error, GTK_ALIGN_START);
|
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 2, 1);
|
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), entry, 0, 1, 1, 1);
|
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), button,1, 1, 1, 1);
|
|
|
|
|
gtk_grid_attach (GTK_GRID (grid), error, 0, 2, 2, 1);
|
2015-04-17 04:14:28 +00:00
|
|
|
|
gtk_popover_set_default_widget (GTK_POPOVER (popover), button);
|
2015-05-02 06:42:25 +00:00
|
|
|
|
|
|
|
|
|
sidebar->rename_popover = popover;
|
|
|
|
|
sidebar->rename_entry = entry;
|
|
|
|
|
sidebar->rename_button = button;
|
|
|
|
|
sidebar->rename_error = error;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-04 22:26:51 +00:00
|
|
|
|
/* Style the row differently while we show a popover for it.
|
|
|
|
|
* Otherwise, the popover is 'pointing to nothing'. Since the
|
|
|
|
|
* main popover and the rename popover interleave their hiding
|
|
|
|
|
* and showing, we have to count to ensure that we don't loose
|
|
|
|
|
* the state before the last popover is gone.
|
|
|
|
|
*
|
|
|
|
|
* This would be nicer as a state, but reusing hover for this
|
|
|
|
|
* interferes with the normal handling of this state, so just
|
|
|
|
|
* use a style class.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
update_popover_shadowing (GtkWidget *row,
|
|
|
|
|
gboolean shown)
|
|
|
|
|
{
|
|
|
|
|
GtkStyleContext *context;
|
|
|
|
|
gint count;
|
|
|
|
|
|
|
|
|
|
count = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (row), "popover-count"));
|
|
|
|
|
count = shown ? count + 1 : count - 1;
|
|
|
|
|
g_object_set_data (G_OBJECT (row), "popover-count", GINT_TO_POINTER (count));
|
|
|
|
|
|
|
|
|
|
context = gtk_widget_get_style_context (row);
|
|
|
|
|
if (count > 0)
|
|
|
|
|
gtk_style_context_add_class (context, "has-open-popup");
|
|
|
|
|
else
|
|
|
|
|
gtk_style_context_remove_class (context, "has-open-popup");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
set_prelight (GtkPopover *popover)
|
|
|
|
|
{
|
|
|
|
|
update_popover_shadowing (gtk_popover_get_relative_to (popover), TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
unset_prelight (GtkPopover *popover)
|
|
|
|
|
{
|
|
|
|
|
update_popover_shadowing (gtk_popover_get_relative_to (popover), FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
setup_popover_shadowing (GtkWidget *popover)
|
|
|
|
|
{
|
|
|
|
|
g_signal_connect (popover, "map", G_CALLBACK (set_prelight), NULL);
|
|
|
|
|
g_signal_connect (popover, "unmap", G_CALLBACK (unset_prelight), NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-02 06:42:25 +00:00
|
|
|
|
static void
|
2015-05-06 21:07:17 +00:00
|
|
|
|
show_rename_popover (GtkSidebarRow *row)
|
2015-05-02 06:42:25 +00:00
|
|
|
|
{
|
|
|
|
|
gchar *name;
|
|
|
|
|
gchar *uri;
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar;
|
2015-05-02 06:42:25 +00:00
|
|
|
|
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_object_get (row,
|
|
|
|
|
"sidebar", &sidebar,
|
|
|
|
|
"label", &name,
|
|
|
|
|
"uri", &uri,
|
|
|
|
|
NULL);
|
2015-05-02 06:42:25 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
create_rename_popover (sidebar);
|
2015-05-02 06:42:25 +00:00
|
|
|
|
|
|
|
|
|
if (sidebar->rename_uri)
|
|
|
|
|
g_free (sidebar->rename_uri);
|
2015-07-05 02:32:06 +00:00
|
|
|
|
sidebar->rename_uri = g_strdup (uri);
|
2015-05-02 06:42:25 +00:00
|
|
|
|
|
2019-02-28 19:31:36 +00:00
|
|
|
|
gtk_editable_set_text (GTK_EDITABLE (sidebar->rename_entry), name);
|
2015-05-06 21:07:17 +00:00
|
|
|
|
gtk_popover_set_relative_to (GTK_POPOVER (sidebar->rename_popover), GTK_WIDGET (row));
|
2015-09-04 22:26:51 +00:00
|
|
|
|
setup_popover_shadowing (sidebar->rename_popover);
|
2015-05-02 06:42:25 +00:00
|
|
|
|
|
2016-08-10 17:18:27 +00:00
|
|
|
|
gtk_popover_popup (GTK_POPOVER (sidebar->rename_popover));
|
2015-05-02 06:42:25 +00:00
|
|
|
|
gtk_widget_grab_focus (sidebar->rename_entry);
|
2015-06-23 20:06:30 +00:00
|
|
|
|
|
|
|
|
|
g_free (name);
|
|
|
|
|
g_free (uri);
|
|
|
|
|
g_object_unref (sidebar);
|
2015-05-02 06:42:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
static void
|
2015-05-06 21:07:17 +00:00
|
|
|
|
rename_bookmark (GtkSidebarRow *row)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GtkPlacesSidebarPlaceType type;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_object_get (row, "place-type", &type, NULL);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
if (type != PLACES_BOOKMARK && type != PLACES_XDG_DIR)
|
|
|
|
|
return;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
show_rename_popover (row);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-16 01:25:10 +00:00
|
|
|
|
rename_shortcut_cb (GSimpleAction *action,
|
|
|
|
|
GVariant *parameter,
|
|
|
|
|
gpointer data)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2015-07-16 01:25:10 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar = data;
|
|
|
|
|
|
|
|
|
|
rename_bookmark (sidebar->context_row);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-05-06 21:07:17 +00:00
|
|
|
|
remove_bookmark (GtkSidebarRow *row)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GtkPlacesSidebarPlaceType type;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
gchar *uri;
|
|
|
|
|
GFile *file;
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_object_get (row,
|
|
|
|
|
"sidebar", &sidebar,
|
|
|
|
|
"place-type", &type,
|
|
|
|
|
"uri", &uri,
|
|
|
|
|
NULL);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2015-07-07 03:21:51 +00:00
|
|
|
|
if (type == PLACES_BOOKMARK)
|
2015-06-23 20:06:30 +00:00
|
|
|
|
{
|
|
|
|
|
file = g_file_new_for_uri (uri);
|
|
|
|
|
_gtk_bookmarks_manager_remove_bookmark (sidebar->bookmarks_manager, file, NULL);
|
|
|
|
|
g_object_unref (file);
|
|
|
|
|
}
|
2012-09-10 19:43:30 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_free (uri);
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_object_unref (sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-16 01:25:10 +00:00
|
|
|
|
remove_shortcut_cb (GSimpleAction *action,
|
|
|
|
|
GVariant *parameter,
|
|
|
|
|
gpointer data)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2015-07-16 01:25:10 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar = data;
|
|
|
|
|
|
|
|
|
|
remove_bookmark (sidebar->context_row);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-16 01:25:10 +00:00
|
|
|
|
mount_shortcut_cb (GSimpleAction *action,
|
|
|
|
|
GVariant *parameter,
|
|
|
|
|
gpointer data)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2015-07-16 01:25:10 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar = data;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GVolume *volume;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
g_object_get (sidebar->context_row,
|
2015-06-23 20:06:30 +00:00
|
|
|
|
"volume", &volume,
|
|
|
|
|
NULL);
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
if (volume != NULL)
|
2018-07-22 11:47:46 +00:00
|
|
|
|
mount_volume (sidebar->context_row, volume);
|
2015-06-23 20:06:30 +00:00
|
|
|
|
|
|
|
|
|
g_object_unref (volume);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
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
|
2013-11-09 22:28:02 +00:00
|
|
|
|
unmount_mount_cb (GObject *source_object,
|
|
|
|
|
GAsyncResult *result,
|
|
|
|
|
gpointer user_data)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (user_data);
|
|
|
|
|
GMount *mount;
|
|
|
|
|
GError *error;
|
2012-10-30 00:53:41 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
mount = G_MOUNT (source_object);
|
2012-10-30 00:53:41 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
error = NULL;
|
|
|
|
|
if (!g_mount_unmount_with_operation_finish (mount, result, &error))
|
|
|
|
|
{
|
|
|
|
|
if (error->code != G_IO_ERROR_FAILED_HANDLED)
|
|
|
|
|
{
|
|
|
|
|
gchar *name;
|
|
|
|
|
gchar *primary;
|
2012-10-30 00:53:41 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
name = g_mount_get_name (mount);
|
2014-08-22 15:07:41 +00:00
|
|
|
|
primary = g_strdup_printf (_("Unable to unmount “%s”"), name);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_free (name);
|
|
|
|
|
emit_show_error_message (sidebar, primary, error->message);
|
|
|
|
|
g_free (primary);
|
|
|
|
|
}
|
2012-10-30 00:53:41 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
2012-10-30 00:53:41 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_object_unref (sidebar);
|
2012-10-30 00:53:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-15 18:09:54 +00:00
|
|
|
|
static GMountOperation *
|
|
|
|
|
get_mount_operation (GtkPlacesSidebar *sidebar)
|
2014-11-29 18:33:02 +00:00
|
|
|
|
{
|
2016-02-15 18:09:54 +00:00
|
|
|
|
GMountOperation *mount_op;
|
2014-11-29 18:33:02 +00:00
|
|
|
|
|
2019-05-20 04:47:50 +00:00
|
|
|
|
mount_op = gtk_mount_operation_new (GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (sidebar))));
|
2014-11-29 18:33:02 +00:00
|
|
|
|
|
2016-02-15 18:09:54 +00:00
|
|
|
|
emit_mount_operation (sidebar, mount_op);
|
2012-10-30 00:53:41 +00:00
|
|
|
|
|
2016-02-15 18:09:54 +00:00
|
|
|
|
return mount_op;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-01-21 21:48:52 +00:00
|
|
|
|
static GMountOperation *
|
|
|
|
|
get_unmount_operation (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GMountOperation *mount_op;
|
2013-01-21 21:48:52 +00:00
|
|
|
|
|
2019-05-20 04:47:50 +00:00
|
|
|
|
mount_op = gtk_mount_operation_new (GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (sidebar))));
|
2016-02-15 18:09:54 +00:00
|
|
|
|
|
|
|
|
|
emit_unmount_operation (sidebar, mount_op);
|
2013-01-21 21:48:52 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
return mount_op;
|
2013-01-21 21:48:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-07 10:22:38 +00:00
|
|
|
|
/* Returns TRUE if file1 is prefix of file2 or if both files have the
|
|
|
|
|
* same path
|
|
|
|
|
*/
|
|
|
|
|
static gboolean
|
|
|
|
|
file_prefix_or_same (GFile *file1,
|
|
|
|
|
GFile *file2)
|
|
|
|
|
{
|
2014-10-12 01:55:39 +00:00
|
|
|
|
return g_file_has_prefix (file1, file2) ||
|
|
|
|
|
g_file_equal (file1, file2);
|
2014-10-07 10:22:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
is_current_location_on_volume (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GMount *mount,
|
|
|
|
|
GVolume *volume,
|
|
|
|
|
GDrive *drive)
|
|
|
|
|
{
|
2014-10-12 01:55:39 +00:00
|
|
|
|
gboolean current_location_on_volume;
|
|
|
|
|
GFile *mount_default_location;
|
2014-10-07 10:22:38 +00:00
|
|
|
|
GMount *mount_for_volume;
|
|
|
|
|
GList *volumes_for_drive;
|
|
|
|
|
GList *volume_for_drive;
|
|
|
|
|
|
|
|
|
|
current_location_on_volume = FALSE;
|
|
|
|
|
|
|
|
|
|
if (sidebar->current_location != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (mount != NULL)
|
|
|
|
|
{
|
|
|
|
|
mount_default_location = g_mount_get_default_location (mount);
|
|
|
|
|
current_location_on_volume = file_prefix_or_same (sidebar->current_location,
|
|
|
|
|
mount_default_location);
|
|
|
|
|
|
|
|
|
|
g_object_unref (mount_default_location);
|
|
|
|
|
}
|
|
|
|
|
/* This code path is probably never reached since mount always exists,
|
|
|
|
|
* and if it doesn't exists we don't offer a way to eject a volume or
|
|
|
|
|
* drive in the UI. Do it for defensive programming
|
|
|
|
|
*/
|
|
|
|
|
else if (volume != NULL)
|
|
|
|
|
{
|
|
|
|
|
mount_for_volume = g_volume_get_mount (volume);
|
|
|
|
|
if (mount_for_volume != NULL)
|
|
|
|
|
{
|
|
|
|
|
mount_default_location = g_mount_get_default_location (mount_for_volume);
|
|
|
|
|
current_location_on_volume = file_prefix_or_same (sidebar->current_location,
|
|
|
|
|
mount_default_location);
|
|
|
|
|
|
|
|
|
|
g_object_unref (mount_default_location);
|
|
|
|
|
g_object_unref (mount_for_volume);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* This code path is probably never reached since mount always exists,
|
|
|
|
|
* and if it doesn't exists we don't offer a way to eject a volume or
|
|
|
|
|
* drive in the UI. Do it for defensive programming
|
|
|
|
|
*/
|
|
|
|
|
else if (drive != NULL)
|
|
|
|
|
{
|
|
|
|
|
volumes_for_drive = g_drive_get_volumes (drive);
|
|
|
|
|
for (volume_for_drive = volumes_for_drive; volume_for_drive != NULL; volume_for_drive = volume_for_drive->next)
|
|
|
|
|
{
|
|
|
|
|
mount_for_volume = g_volume_get_mount (volume_for_drive->data);
|
|
|
|
|
if (mount_for_volume != NULL)
|
|
|
|
|
{
|
|
|
|
|
mount_default_location = g_mount_get_default_location (mount_for_volume);
|
|
|
|
|
current_location_on_volume = file_prefix_or_same (sidebar->current_location,
|
|
|
|
|
mount_default_location);
|
|
|
|
|
|
|
|
|
|
g_object_unref (mount_default_location);
|
|
|
|
|
g_object_unref (mount_for_volume);
|
|
|
|
|
|
|
|
|
|
if (current_location_on_volume)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-10-12 01:55:39 +00:00
|
|
|
|
g_list_free_full (volumes_for_drive, g_object_unref);
|
2014-10-07 10:22:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return current_location_on_volume;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
static void
|
2013-11-09 22:28:02 +00:00
|
|
|
|
do_unmount (GMount *mount,
|
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
if (mount != NULL)
|
|
|
|
|
{
|
|
|
|
|
GMountOperation *mount_op;
|
2012-10-30 00:53:41 +00:00
|
|
|
|
|
2014-10-07 10:22:38 +00:00
|
|
|
|
if (is_current_location_on_volume (sidebar, mount, NULL, NULL))
|
|
|
|
|
open_home (sidebar);
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
mount_op = get_unmount_operation (sidebar);
|
|
|
|
|
g_mount_unmount_with_operation (mount,
|
|
|
|
|
0,
|
|
|
|
|
mount_op,
|
|
|
|
|
NULL,
|
|
|
|
|
unmount_mount_cb,
|
|
|
|
|
g_object_ref (sidebar));
|
|
|
|
|
g_object_unref (mount_op);
|
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-16 01:25:10 +00:00
|
|
|
|
unmount_shortcut_cb (GSimpleAction *action,
|
|
|
|
|
GVariant *parameter,
|
|
|
|
|
gpointer data)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2015-07-24 08:25:01 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar = data;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GMount *mount;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
g_object_get (sidebar->context_row,
|
2015-06-23 20:06:30 +00:00
|
|
|
|
"mount", &mount,
|
|
|
|
|
NULL);
|
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
do_unmount (mount, sidebar);
|
2015-06-23 20:06:30 +00:00
|
|
|
|
|
|
|
|
|
if (mount)
|
|
|
|
|
g_object_unref (mount);
|
2012-09-07 15:04:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 02:52:01 +00:00
|
|
|
|
static void
|
|
|
|
|
drive_stop_cb (GObject *source_object,
|
|
|
|
|
GAsyncResult *res,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkPlacesSidebar *sidebar;
|
|
|
|
|
GError *error;
|
|
|
|
|
gchar *primary;
|
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
|
|
sidebar = user_data;
|
|
|
|
|
|
|
|
|
|
error = NULL;
|
|
|
|
|
if (!g_drive_stop_finish (G_DRIVE (source_object), res, &error))
|
|
|
|
|
{
|
|
|
|
|
if (error->code != G_IO_ERROR_FAILED_HANDLED)
|
|
|
|
|
{
|
|
|
|
|
name = g_drive_get_name (G_DRIVE (source_object));
|
2014-08-22 15:07:41 +00:00
|
|
|
|
primary = g_strdup_printf (_("Unable to stop “%s”"), name);
|
2014-01-28 02:52:01 +00:00
|
|
|
|
g_free (name);
|
|
|
|
|
emit_show_error_message (sidebar, primary, error->message);
|
|
|
|
|
g_free (primary);
|
|
|
|
|
}
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_unref (sidebar);
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-06 22:53:30 +00:00
|
|
|
|
static void
|
2013-11-09 22:28:02 +00:00
|
|
|
|
drive_eject_cb (GObject *source_object,
|
|
|
|
|
GAsyncResult *res,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkPlacesSidebar *sidebar;
|
|
|
|
|
GError *error;
|
|
|
|
|
gchar *primary;
|
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
|
|
sidebar = user_data;
|
|
|
|
|
|
|
|
|
|
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));
|
2014-08-22 15:07:41 +00:00
|
|
|
|
primary = g_strdup_printf (_("Unable to eject “%s”"), name);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_free (name);
|
|
|
|
|
emit_show_error_message (sidebar, primary, error->message);
|
|
|
|
|
g_free (primary);
|
|
|
|
|
}
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_unref (sidebar);
|
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
static void
|
|
|
|
|
volume_eject_cb (GObject *source_object,
|
|
|
|
|
GAsyncResult *res,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkPlacesSidebar *sidebar;
|
|
|
|
|
GError *error;
|
|
|
|
|
gchar *primary;
|
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
|
|
sidebar = user_data;
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
emit_show_error_message (sidebar, primary, error->message);
|
|
|
|
|
g_free (primary);
|
|
|
|
|
}
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_unref (sidebar);
|
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
static void
|
|
|
|
|
mount_eject_cb (GObject *source_object,
|
|
|
|
|
GAsyncResult *res,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkPlacesSidebar *sidebar;
|
|
|
|
|
GError *error;
|
|
|
|
|
gchar *primary;
|
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
|
|
sidebar = user_data;
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
emit_show_error_message (sidebar, primary, error->message);
|
|
|
|
|
g_free (primary);
|
|
|
|
|
}
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_unref (sidebar);
|
|
|
|
|
}
|
2011-10-06 14:20:32 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
static void
|
|
|
|
|
do_eject (GMount *mount,
|
|
|
|
|
GVolume *volume,
|
|
|
|
|
GDrive *drive,
|
|
|
|
|
GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
|
|
|
|
GMountOperation *mount_op;
|
|
|
|
|
|
|
|
|
|
mount_op = get_unmount_operation (sidebar);
|
2014-10-07 10:22:38 +00:00
|
|
|
|
|
|
|
|
|
if (is_current_location_on_volume (sidebar, mount, volume, drive))
|
|
|
|
|
open_home (sidebar);
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
if (mount != NULL)
|
|
|
|
|
g_mount_eject_with_operation (mount, 0, mount_op, NULL, mount_eject_cb,
|
|
|
|
|
g_object_ref (sidebar));
|
2014-10-07 10:22:38 +00:00
|
|
|
|
/* This code path is probably never reached since mount always exists,
|
|
|
|
|
* and if it doesn't exists we don't offer a way to eject a volume or
|
|
|
|
|
* drive in the UI. Do it for defensive programming
|
|
|
|
|
*/
|
2013-11-09 22:28:02 +00:00
|
|
|
|
else if (volume != NULL)
|
|
|
|
|
g_volume_eject_with_operation (volume, 0, mount_op, NULL, volume_eject_cb,
|
|
|
|
|
g_object_ref (sidebar));
|
2014-10-07 10:22:38 +00:00
|
|
|
|
/* This code path is probably never reached since mount always exists,
|
|
|
|
|
* and if it doesn't exists we don't offer a way to eject a volume or
|
|
|
|
|
* drive in the UI. Do it for defensive programming
|
|
|
|
|
*/
|
2013-11-09 22:28:02 +00:00
|
|
|
|
else if (drive != NULL)
|
2014-01-28 02:52:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (g_drive_can_stop (drive))
|
|
|
|
|
g_drive_stop (drive, 0, mount_op, NULL, drive_stop_cb,
|
|
|
|
|
g_object_ref (sidebar));
|
|
|
|
|
else
|
|
|
|
|
g_drive_eject_with_operation (drive, 0, mount_op, NULL, drive_eject_cb,
|
|
|
|
|
g_object_ref (sidebar));
|
|
|
|
|
}
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_object_unref (mount_op);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-16 01:25:10 +00:00
|
|
|
|
eject_shortcut_cb (GSimpleAction *action,
|
|
|
|
|
GVariant *parameter,
|
|
|
|
|
gpointer data)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2015-07-16 01:25:10 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar = data;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GMount *mount;
|
|
|
|
|
GVolume *volume;
|
|
|
|
|
GDrive *drive;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
g_object_get (sidebar->context_row,
|
2015-05-06 21:07:17 +00:00
|
|
|
|
"mount", &mount,
|
|
|
|
|
"volume", &volume,
|
|
|
|
|
"drive", &drive,
|
|
|
|
|
NULL);
|
2011-10-06 14:20:32 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
do_eject (mount, volume, drive, sidebar);
|
2015-06-23 20:06:30 +00:00
|
|
|
|
|
|
|
|
|
if (mount)
|
|
|
|
|
g_object_unref (mount);
|
|
|
|
|
if (volume)
|
|
|
|
|
g_object_unref (volume);
|
|
|
|
|
if (drive)
|
|
|
|
|
g_object_unref (drive);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
static gboolean
|
2015-05-06 21:07:17 +00:00
|
|
|
|
eject_or_unmount_bookmark (GtkSidebarRow *row)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
gboolean can_unmount, can_eject;
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GMount *mount;
|
|
|
|
|
GVolume *volume;
|
|
|
|
|
GDrive *drive;
|
|
|
|
|
gboolean ret;
|
|
|
|
|
GtkPlacesSidebar *sidebar;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
g_object_get (row,
|
|
|
|
|
"sidebar", &sidebar,
|
|
|
|
|
"mount", &mount,
|
|
|
|
|
"volume", &volume,
|
|
|
|
|
"drive", &drive,
|
|
|
|
|
NULL);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
ret = FALSE;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_object_unref (sidebar);
|
|
|
|
|
if (mount)
|
|
|
|
|
g_object_unref (mount);
|
|
|
|
|
if (volume)
|
|
|
|
|
g_object_unref (volume);
|
|
|
|
|
if (drive)
|
|
|
|
|
g_object_unref (drive);
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
return ret;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2011-09-06 23:11:19 +00:00
|
|
|
|
eject_or_unmount_selection (GtkPlacesSidebar *sidebar)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
gboolean ret;
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GtkListBoxRow *row;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
row = gtk_list_box_get_selected_row (GTK_LIST_BOX (sidebar->list_box));
|
|
|
|
|
ret = eject_or_unmount_bookmark (GTK_SIDEBAR_ROW (row));
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
return ret;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2013-11-09 22:28:02 +00:00
|
|
|
|
drive_poll_for_media_cb (GObject *source_object,
|
|
|
|
|
GAsyncResult *res,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkPlacesSidebar *sidebar;
|
|
|
|
|
GError *error;
|
|
|
|
|
gchar *primary;
|
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
|
|
sidebar = GTK_PLACES_SIDEBAR (user_data);
|
|
|
|
|
|
|
|
|
|
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));
|
2014-08-22 15:07:41 +00:00
|
|
|
|
primary = g_strdup_printf (_("Unable to poll “%s” for media changes"), name);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_free (name);
|
|
|
|
|
emit_show_error_message (sidebar, primary, error->message);
|
|
|
|
|
g_free (primary);
|
|
|
|
|
}
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 02:47:14 +00:00
|
|
|
|
g_object_unref (sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-16 01:25:10 +00:00
|
|
|
|
rescan_shortcut_cb (GSimpleAction *action,
|
|
|
|
|
GVariant *parameter,
|
|
|
|
|
gpointer data)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2015-07-16 01:25:10 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar = data;
|
2015-06-23 20:06:30 +00:00
|
|
|
|
GDrive *drive;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
g_object_get (sidebar->context_row,
|
2015-06-23 20:06:30 +00:00
|
|
|
|
"drive", &drive,
|
|
|
|
|
NULL);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
if (drive != NULL)
|
2015-06-23 20:06:30 +00:00
|
|
|
|
{
|
|
|
|
|
g_drive_poll_for_media (drive, NULL, drive_poll_for_media_cb, g_object_ref (sidebar));
|
|
|
|
|
g_object_unref (drive);
|
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
drive_start_cb (GObject *source_object,
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GAsyncResult *res,
|
|
|
|
|
gpointer user_data)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar;
|
|
|
|
|
GError *error;
|
|
|
|
|
gchar *primary;
|
|
|
|
|
gchar *name;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
sidebar = GTK_PLACES_SIDEBAR (user_data);
|
2011-10-06 14:20:32 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
error = NULL;
|
2014-01-28 02:48:18 +00:00
|
|
|
|
if (!g_drive_start_finish (G_DRIVE (source_object), res, &error))
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
|
|
|
|
if (error->code != G_IO_ERROR_FAILED_HANDLED)
|
|
|
|
|
{
|
|
|
|
|
name = g_drive_get_name (G_DRIVE (source_object));
|
2014-08-22 15:07:41 +00:00
|
|
|
|
primary = g_strdup_printf (_("Unable to start “%s”"), name);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_free (name);
|
|
|
|
|
emit_show_error_message (sidebar, primary, error->message);
|
|
|
|
|
g_free (primary);
|
|
|
|
|
}
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
}
|
2011-10-06 14:20:32 +00:00
|
|
|
|
|
2014-01-28 02:47:14 +00:00
|
|
|
|
g_object_unref (sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-16 01:25:10 +00:00
|
|
|
|
start_shortcut_cb (GSimpleAction *action,
|
|
|
|
|
GVariant *parameter,
|
|
|
|
|
gpointer data)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2015-07-16 01:25:10 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar = data;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GDrive *drive;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
g_object_get (sidebar->context_row,
|
2015-06-23 20:06:30 +00:00
|
|
|
|
"drive", &drive,
|
|
|
|
|
NULL);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
if (drive != NULL)
|
|
|
|
|
{
|
|
|
|
|
GMountOperation *mount_op;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2016-02-15 18:09:54 +00:00
|
|
|
|
mount_op = get_mount_operation (sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2014-01-28 02:47:14 +00:00
|
|
|
|
g_drive_start (drive, G_DRIVE_START_NONE, mount_op, NULL, drive_start_cb, g_object_ref (sidebar));
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_object_unref (mount_op);
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_object_unref (drive);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-16 01:25:10 +00:00
|
|
|
|
stop_shortcut_cb (GSimpleAction *action,
|
|
|
|
|
GVariant *parameter,
|
|
|
|
|
gpointer data)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2015-07-16 01:25:10 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar = data;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GDrive *drive;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
g_object_get (sidebar->context_row,
|
2015-06-23 20:06:30 +00:00
|
|
|
|
"drive", &drive,
|
|
|
|
|
NULL);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
if (drive != NULL)
|
|
|
|
|
{
|
|
|
|
|
GMountOperation *mount_op;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
mount_op = get_unmount_operation (sidebar);
|
|
|
|
|
g_drive_stop (drive, G_MOUNT_UNMOUNT_NONE, mount_op, NULL, drive_stop_cb,
|
|
|
|
|
g_object_ref (sidebar));
|
2013-01-21 22:06:42 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_object_unref (mount_op);
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_object_unref (drive);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2018-03-05 17:50:35 +00:00
|
|
|
|
on_key_pressed (GtkEventControllerKey *controller,
|
|
|
|
|
guint keyval,
|
|
|
|
|
guint keycode,
|
|
|
|
|
GdkModifierType state,
|
|
|
|
|
GtkPlacesSidebar *sidebar)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
guint modifiers;
|
|
|
|
|
GtkListBoxRow *row;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2018-03-05 17:50:35 +00:00
|
|
|
|
row = gtk_list_box_get_selected_row (GTK_LIST_BOX (sidebar->list_box));
|
|
|
|
|
if (row)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
2018-03-05 17:50:35 +00:00
|
|
|
|
modifiers = gtk_accelerator_get_default_mod_mask ();
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
2018-03-05 17:50:35 +00:00
|
|
|
|
if (keyval == GDK_KEY_Return ||
|
|
|
|
|
keyval == GDK_KEY_KP_Enter ||
|
|
|
|
|
keyval == GDK_KEY_ISO_Enter ||
|
|
|
|
|
keyval == GDK_KEY_space)
|
|
|
|
|
{
|
|
|
|
|
GtkPlacesOpenFlags open_flags = GTK_PLACES_OPEN_NORMAL;
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
2018-03-05 17:50:35 +00:00
|
|
|
|
if ((state & modifiers) == GDK_SHIFT_MASK)
|
|
|
|
|
open_flags = GTK_PLACES_OPEN_NEW_TAB;
|
|
|
|
|
else if ((state & modifiers) == GDK_CONTROL_MASK)
|
|
|
|
|
open_flags = GTK_PLACES_OPEN_NEW_WINDOW;
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
2018-03-05 17:50:35 +00:00
|
|
|
|
open_row (GTK_SIDEBAR_ROW (row), open_flags);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2018-03-05 17:50:35 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2018-03-05 17:50:35 +00:00
|
|
|
|
if (keyval == GDK_KEY_Down &&
|
|
|
|
|
(state & modifiers) == GDK_MOD1_MASK)
|
|
|
|
|
return eject_or_unmount_selection (sidebar);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2018-03-05 17:50:35 +00:00
|
|
|
|
if ((keyval == GDK_KEY_Delete ||
|
|
|
|
|
keyval == GDK_KEY_KP_Delete) &&
|
|
|
|
|
(state & modifiers) == 0)
|
|
|
|
|
{
|
|
|
|
|
remove_bookmark (GTK_SIDEBAR_ROW (row));
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2015-07-15 05:44:31 +00:00
|
|
|
|
|
2018-03-05 17:50:35 +00:00
|
|
|
|
if ((keyval == GDK_KEY_F2) &&
|
|
|
|
|
(state & modifiers) == 0)
|
|
|
|
|
{
|
|
|
|
|
rename_bookmark (GTK_SIDEBAR_ROW (row));
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2015-07-15 05:44:31 +00:00
|
|
|
|
|
2018-03-05 17:50:35 +00:00
|
|
|
|
if ((keyval == GDK_KEY_Menu) ||
|
|
|
|
|
((keyval == GDK_KEY_F10) &&
|
|
|
|
|
(state & modifiers) == GDK_SHIFT_MASK))
|
|
|
|
|
{
|
|
|
|
|
popup_menu_cb (GTK_SIDEBAR_ROW (row));
|
|
|
|
|
return TRUE;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
static GActionEntry entries[] = {
|
|
|
|
|
{ "open", open_shortcut_cb, "i", NULL, NULL },
|
2015-09-13 16:44:17 +00:00
|
|
|
|
{ "open-other", open_shortcut_cb, "i", NULL, NULL },
|
2015-07-16 01:25:10 +00:00
|
|
|
|
{ "bookmark", add_shortcut_cb, NULL, NULL, NULL },
|
|
|
|
|
{ "remove", remove_shortcut_cb, NULL, NULL, NULL },
|
|
|
|
|
{ "rename", rename_shortcut_cb, NULL, NULL, NULL },
|
|
|
|
|
{ "mount", mount_shortcut_cb, NULL, NULL, NULL },
|
|
|
|
|
{ "unmount", unmount_shortcut_cb, NULL, NULL, NULL },
|
|
|
|
|
{ "eject", eject_shortcut_cb, NULL, NULL, NULL },
|
|
|
|
|
{ "rescan", rescan_shortcut_cb, NULL, NULL, NULL },
|
|
|
|
|
{ "start", start_shortcut_cb, NULL, NULL, NULL },
|
|
|
|
|
{ "stop", stop_shortcut_cb, NULL, NULL, NULL },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
add_actions (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
2019-06-15 22:25:05 +00:00
|
|
|
|
sidebar->row_actions = G_ACTION_GROUP (g_simple_action_group_new ());
|
|
|
|
|
g_action_map_add_action_entries (G_ACTION_MAP (sidebar->row_actions),
|
2015-07-16 01:25:10 +00:00
|
|
|
|
entries, G_N_ELEMENTS (entries),
|
|
|
|
|
sidebar);
|
2019-06-15 22:25:05 +00:00
|
|
|
|
gtk_widget_insert_action_group (GTK_WIDGET (sidebar), "row", sidebar->row_actions);
|
2015-07-16 01:25:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
|
append_separator (GtkWidget *box)
|
2011-10-05 12:28:14 +00:00
|
|
|
|
{
|
2015-07-16 01:25:10 +00:00
|
|
|
|
GtkWidget *separator;
|
2011-10-05 12:28:14 +00:00
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
separator = g_object_new (GTK_TYPE_SEPARATOR,
|
|
|
|
|
"orientation", GTK_ORIENTATION_HORIZONTAL,
|
|
|
|
|
"visible", TRUE,
|
|
|
|
|
"margin-top", 6,
|
|
|
|
|
"margin-bottom", 6,
|
|
|
|
|
NULL);
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), separator);
|
2011-10-05 12:28:14 +00:00
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
return separator;
|
2011-10-05 12:28:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
static GtkWidget *
|
|
|
|
|
add_button (GtkWidget *box,
|
|
|
|
|
const gchar *label,
|
|
|
|
|
const gchar *action)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GtkWidget *item;
|
2015-05-06 21:07:17 +00:00
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
item = g_object_new (GTK_TYPE_MODEL_BUTTON,
|
|
|
|
|
"visible", TRUE,
|
|
|
|
|
"action-name", action,
|
|
|
|
|
"text", label,
|
|
|
|
|
NULL);
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), item);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
return item;
|
|
|
|
|
}
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
static GtkWidget *
|
|
|
|
|
add_open_button (GtkWidget *box,
|
|
|
|
|
const gchar *label,
|
|
|
|
|
GtkPlacesOpenFlags flags)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *item;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
item = g_object_new (GTK_TYPE_MODEL_BUTTON,
|
|
|
|
|
"visible", TRUE,
|
2015-09-13 16:44:17 +00:00
|
|
|
|
"action-name", flags == GTK_PLACES_OPEN_NORMAL ? "row.open" : "row.open-other",
|
2015-07-16 01:25:10 +00:00
|
|
|
|
"action-target", g_variant_new_int32 (flags),
|
|
|
|
|
"text", label,
|
|
|
|
|
NULL);
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (box), item);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
return item;
|
|
|
|
|
}
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-09-23 14:13:48 +00:00
|
|
|
|
static void
|
|
|
|
|
on_row_popover_destroy (GtkWidget *row_popover,
|
|
|
|
|
GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
|
|
|
|
if (sidebar)
|
|
|
|
|
sidebar->popover = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-10 20:30:36 +00:00
|
|
|
|
#ifdef HAVE_CLOUDPROVIDERS
|
|
|
|
|
static void
|
|
|
|
|
build_popup_menu_using_gmenu (GtkSidebarRow *row)
|
|
|
|
|
{
|
2017-10-30 20:38:41 +00:00
|
|
|
|
CloudProvidersAccount *cloud_provider_account;
|
2017-08-10 20:30:36 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar;
|
|
|
|
|
GMenuModel *cloud_provider_menu;
|
|
|
|
|
GActionGroup *cloud_provider_action_group;
|
|
|
|
|
|
|
|
|
|
g_object_get (row,
|
|
|
|
|
"sidebar", &sidebar,
|
2017-10-30 20:38:41 +00:00
|
|
|
|
"cloud-provider-account", &cloud_provider_account,
|
2017-08-10 20:30:36 +00:00
|
|
|
|
NULL);
|
|
|
|
|
|
2017-10-30 20:38:41 +00:00
|
|
|
|
/* Cloud provider account */
|
2017-08-10 20:30:36 +00:00
|
|
|
|
if (cloud_provider_account)
|
|
|
|
|
{
|
|
|
|
|
GMenu *menu = g_menu_new ();
|
|
|
|
|
GMenuItem *item;
|
|
|
|
|
item = g_menu_item_new (_("_Open"), "row.open");
|
|
|
|
|
g_menu_item_set_action_and_target_value (item, "row.open",
|
|
|
|
|
g_variant_new_int32 (GTK_PLACES_OPEN_NORMAL));
|
|
|
|
|
g_menu_append_item (menu, item);
|
2017-10-30 20:47:07 +00:00
|
|
|
|
if (sidebar->open_flags & GTK_PLACES_OPEN_NEW_TAB)
|
|
|
|
|
{
|
|
|
|
|
item = g_menu_item_new (_("Open in New _Tab"), "row.open-other");
|
|
|
|
|
g_menu_item_set_action_and_target_value (item, "row.open-other", g_variant_new_int32(GTK_PLACES_OPEN_NEW_TAB));
|
|
|
|
|
g_menu_append_item (menu, item);
|
|
|
|
|
}
|
|
|
|
|
if (sidebar->open_flags & GTK_PLACES_OPEN_NEW_WINDOW)
|
|
|
|
|
{
|
|
|
|
|
item = g_menu_item_new (_("Open in New _Window"), "row.open-other");
|
|
|
|
|
g_menu_item_set_action_and_target_value (item, "row.open-other", g_variant_new_int32(GTK_PLACES_OPEN_NEW_WINDOW));
|
|
|
|
|
g_menu_append_item (menu, item);
|
|
|
|
|
}
|
2017-10-30 20:38:41 +00:00
|
|
|
|
cloud_provider_menu = cloud_providers_account_get_menu_model (cloud_provider_account);
|
|
|
|
|
cloud_provider_action_group = cloud_providers_account_get_action_group (cloud_provider_account);
|
|
|
|
|
if (cloud_provider_menu != NULL && cloud_provider_action_group != NULL)
|
|
|
|
|
{
|
|
|
|
|
g_menu_append_section (menu, NULL, cloud_provider_menu);
|
|
|
|
|
gtk_widget_insert_action_group (GTK_WIDGET (sidebar),
|
|
|
|
|
"cloudprovider",
|
|
|
|
|
G_ACTION_GROUP (cloud_provider_action_group));
|
|
|
|
|
}
|
2017-08-10 20:30:36 +00:00
|
|
|
|
add_actions (sidebar);
|
|
|
|
|
if (sidebar->popover)
|
|
|
|
|
gtk_widget_destroy (sidebar->popover);
|
|
|
|
|
|
|
|
|
|
sidebar->popover = gtk_popover_new_from_model (GTK_WIDGET (sidebar),
|
|
|
|
|
G_MENU_MODEL (menu));
|
2017-10-30 20:38:41 +00:00
|
|
|
|
g_signal_connect (sidebar->popover, "destroy",
|
|
|
|
|
G_CALLBACK (on_row_popover_destroy), sidebar);
|
2017-08-10 20:30:36 +00:00
|
|
|
|
g_object_unref (sidebar);
|
|
|
|
|
g_object_unref (cloud_provider_account);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
/* Constructs the popover for the sidebar row if needed */
|
|
|
|
|
static void
|
|
|
|
|
create_row_popover (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GtkSidebarRow *row)
|
|
|
|
|
{
|
|
|
|
|
PopoverData data;
|
|
|
|
|
GtkWidget *box;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2017-08-10 20:30:36 +00:00
|
|
|
|
#ifdef HAVE_CLOUDPROVIDERS
|
2017-10-30 20:38:41 +00:00
|
|
|
|
CloudProvidersAccount *cloud_provider_account;
|
2017-08-10 20:30:36 +00:00
|
|
|
|
|
2017-10-30 20:38:41 +00:00
|
|
|
|
g_object_get (row, "cloud-provider-account", &cloud_provider_account, NULL);
|
2017-08-10 20:30:36 +00:00
|
|
|
|
|
|
|
|
|
if (cloud_provider_account)
|
2017-10-30 20:38:41 +00:00
|
|
|
|
{
|
|
|
|
|
build_popup_menu_using_gmenu (row);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-08-10 20:30:36 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
sidebar->popover = gtk_popover_new (GTK_WIDGET (sidebar));
|
2015-09-23 14:13:48 +00:00
|
|
|
|
/* Clean sidebar pointer when its destroyed, most of the times due to its
|
|
|
|
|
* relative_to associated row being destroyed */
|
|
|
|
|
g_signal_connect (sidebar->popover, "destroy", G_CALLBACK (on_row_popover_destroy), sidebar);
|
2015-09-04 22:26:51 +00:00
|
|
|
|
setup_popover_shadowing (sidebar->popover);
|
2015-07-16 01:25:10 +00:00
|
|
|
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
|
|
|
|
g_object_set (box, "margin", 10, NULL);
|
|
|
|
|
gtk_widget_show (box);
|
|
|
|
|
gtk_container_add (GTK_CONTAINER (sidebar->popover), box);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
add_open_button (box, _("_Open"), GTK_PLACES_OPEN_NORMAL);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
if (sidebar->open_flags & GTK_PLACES_OPEN_NEW_TAB)
|
|
|
|
|
add_open_button (box, _("Open in New _Tab"), GTK_PLACES_OPEN_NEW_TAB);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
if (sidebar->open_flags & GTK_PLACES_OPEN_NEW_WINDOW)
|
|
|
|
|
add_open_button (box, _("Open in New _Window"), GTK_PLACES_OPEN_NEW_WINDOW);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
append_separator (box);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
data.add_shortcut_item = add_button (box, _("_Add Bookmark"), "row.bookmark");
|
|
|
|
|
data.remove_item = add_button (box, _("_Remove"), "row.remove");
|
|
|
|
|
data.rename_item = add_button (box, _("Rename…"), "row.rename");
|
2015-06-23 20:06:30 +00:00
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
data.separator_item = append_separator (box);
|
|
|
|
|
|
|
|
|
|
data.mount_item = add_button (box, _("_Mount"), "row.mount");
|
|
|
|
|
data.unmount_item = add_button (box, _("_Unmount"), "row.unmount");
|
|
|
|
|
data.eject_item = add_button (box, _("_Eject"), "row.eject");
|
|
|
|
|
data.rescan_item = add_button (box, _("_Detect Media"), "row.rescan");
|
|
|
|
|
data.start_item = add_button (box, _("_Start"), "row.start");
|
|
|
|
|
data.stop_item = add_button (box, _("_Stop"), "row.stop");
|
|
|
|
|
|
|
|
|
|
/* Update everything! */
|
|
|
|
|
check_popover_sensitivity (row, &data);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-16 01:25:10 +00:00
|
|
|
|
show_row_popover (GtkSidebarRow *row)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar;
|
|
|
|
|
|
|
|
|
|
g_object_get (row, "sidebar", &sidebar, NULL);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
if (sidebar->popover)
|
|
|
|
|
gtk_widget_destroy (sidebar->popover);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
create_row_popover (sidebar, row);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
gtk_popover_set_relative_to (GTK_POPOVER (sidebar->popover), GTK_WIDGET (row));
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
sidebar->context_row = row;
|
2016-08-10 17:18:27 +00:00
|
|
|
|
gtk_popover_popup (GTK_POPOVER (sidebar->popover));
|
2015-06-23 20:06:30 +00:00
|
|
|
|
|
|
|
|
|
g_object_unref (sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-20 19:51:07 +00:00
|
|
|
|
static void
|
2015-05-06 21:07:17 +00:00
|
|
|
|
on_row_activated (GtkListBox *list_box,
|
|
|
|
|
GtkListBoxRow *row,
|
|
|
|
|
gpointer user_data)
|
2013-04-20 19:51:07 +00:00
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GtkSidebarRow *selected_row;
|
2013-04-20 19:51:07 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
/* Avoid to open a location if the user is dragging. Changing the location
|
|
|
|
|
* while dragging usually makes clients changing the view of the files, which
|
2015-06-23 20:06:30 +00:00
|
|
|
|
* is confusing while the user has the attention on the drag
|
|
|
|
|
*/
|
2015-05-06 21:07:17 +00:00
|
|
|
|
if (GTK_PLACES_SIDEBAR (user_data)->dragging_over)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
return;
|
2013-04-20 19:51:07 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
selected_row = GTK_SIDEBAR_ROW (gtk_list_box_get_selected_row (list_box));
|
|
|
|
|
open_row (selected_row, 0);
|
2013-04-20 19:51:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-08 09:29:59 +00:00
|
|
|
|
static void
|
2019-05-29 17:10:46 +00:00
|
|
|
|
on_row_pressed (GtkGestureClick *gesture,
|
|
|
|
|
gint n_press,
|
|
|
|
|
gdouble x,
|
|
|
|
|
gdouble y,
|
|
|
|
|
GtkSidebarRow *row)
|
2018-06-08 09:29:59 +00:00
|
|
|
|
{
|
|
|
|
|
GtkPlacesSidebar *sidebar;
|
|
|
|
|
GtkPlacesSidebarSectionType section_type;
|
|
|
|
|
GtkPlacesSidebarPlaceType row_type;
|
|
|
|
|
|
|
|
|
|
g_object_get (row,
|
|
|
|
|
"sidebar", &sidebar,
|
|
|
|
|
"section_type", §ion_type,
|
|
|
|
|
"place-type", &row_type,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
if (section_type == SECTION_BOOKMARKS)
|
|
|
|
|
{
|
|
|
|
|
sidebar->drag_row = GTK_WIDGET (row);
|
|
|
|
|
sidebar->drag_row_x = (gint)x;
|
|
|
|
|
sidebar->drag_row_y = (gint)y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_object_unref (sidebar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2019-05-29 17:10:46 +00:00
|
|
|
|
on_row_released (GtkGestureClick *gesture,
|
|
|
|
|
gint n_press,
|
|
|
|
|
gdouble x,
|
|
|
|
|
gdouble y,
|
|
|
|
|
GtkSidebarRow *row)
|
2015-05-06 21:07:17 +00:00
|
|
|
|
{
|
|
|
|
|
GtkPlacesSidebar *sidebar;
|
|
|
|
|
GtkPlacesSidebarSectionType section_type;
|
2018-01-16 05:15:22 +00:00
|
|
|
|
GtkPlacesSidebarPlaceType row_type;
|
2018-06-08 09:29:59 +00:00
|
|
|
|
guint button, state;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2018-01-16 05:15:22 +00:00
|
|
|
|
g_object_get (row,
|
2015-06-23 20:06:30 +00:00
|
|
|
|
"sidebar", &sidebar,
|
|
|
|
|
"section_type", §ion_type,
|
2018-01-16 05:15:22 +00:00
|
|
|
|
"place-type", &row_type,
|
2015-06-23 20:06:30 +00:00
|
|
|
|
NULL);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2018-06-08 09:29:59 +00:00
|
|
|
|
button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture));
|
|
|
|
|
gtk_get_current_event_state (&state);
|
|
|
|
|
|
|
|
|
|
if (row)
|
2016-11-10 20:16:05 +00:00
|
|
|
|
{
|
2018-06-08 09:29:59 +00:00
|
|
|
|
if (button == 2)
|
2018-01-16 05:15:22 +00:00
|
|
|
|
{
|
2018-06-08 09:29:59 +00:00
|
|
|
|
GtkPlacesOpenFlags open_flags = GTK_PLACES_OPEN_NORMAL;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2018-06-08 09:29:59 +00:00
|
|
|
|
open_flags = (state & GDK_CONTROL_MASK) ?
|
|
|
|
|
GTK_PLACES_OPEN_NEW_WINDOW :
|
|
|
|
|
GTK_PLACES_OPEN_NEW_TAB;
|
|
|
|
|
|
|
|
|
|
open_row (GTK_SIDEBAR_ROW (row), open_flags);
|
|
|
|
|
gtk_gesture_set_state (GTK_GESTURE (gesture),
|
|
|
|
|
GTK_EVENT_SEQUENCE_CLAIMED);
|
2018-01-16 05:15:22 +00:00
|
|
|
|
}
|
2018-06-08 09:29:59 +00:00
|
|
|
|
else if (button == 3)
|
|
|
|
|
{
|
|
|
|
|
if (row_type != PLACES_CONNECT_TO_SERVER)
|
|
|
|
|
show_row_popover (GTK_SIDEBAR_ROW (row));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
on_row_dragged (GtkGestureDrag *gesture,
|
|
|
|
|
gdouble x,
|
|
|
|
|
gdouble y,
|
|
|
|
|
GtkSidebarRow *row)
|
|
|
|
|
{
|
|
|
|
|
GtkPlacesSidebar *sidebar;
|
|
|
|
|
|
|
|
|
|
g_object_get (row, "sidebar", &sidebar, NULL);
|
2015-04-11 11:53:18 +00:00
|
|
|
|
|
2018-06-08 09:29:59 +00:00
|
|
|
|
if (sidebar->drag_row == NULL || sidebar->dragging_over)
|
|
|
|
|
{
|
2018-01-16 05:15:22 +00:00
|
|
|
|
g_object_unref (sidebar);
|
2018-06-08 09:29:59 +00:00
|
|
|
|
return;
|
2018-01-16 05:15:22 +00:00
|
|
|
|
}
|
2015-04-11 11:53:18 +00:00
|
|
|
|
|
2018-06-08 09:29:59 +00:00
|
|
|
|
if (gtk_drag_check_threshold (GTK_WIDGET (row), 0, 0, x, y))
|
|
|
|
|
{
|
|
|
|
|
gdouble start_x, start_y;
|
|
|
|
|
gint drag_x, drag_y;
|
2015-04-11 11:53:18 +00:00
|
|
|
|
|
2018-06-08 09:29:59 +00:00
|
|
|
|
gtk_gesture_drag_get_start_point (gesture, &start_x, &start_y);
|
|
|
|
|
gtk_widget_translate_coordinates (GTK_WIDGET (row),
|
|
|
|
|
GTK_WIDGET (sidebar),
|
|
|
|
|
start_x, start_y,
|
|
|
|
|
&drag_x, &drag_y);
|
2015-04-11 11:53:18 +00:00
|
|
|
|
|
2018-06-08 09:29:59 +00:00
|
|
|
|
sidebar->dragging_over = TRUE;
|
2018-01-16 05:15:22 +00:00
|
|
|
|
|
2018-07-03 18:37:31 +00:00
|
|
|
|
gtk_drag_begin (GTK_WIDGET (sidebar),
|
|
|
|
|
gtk_gesture_get_device (GTK_GESTURE (gesture)),
|
|
|
|
|
sidebar->source_targets, GDK_ACTION_MOVE,
|
|
|
|
|
drag_x, drag_y);
|
2015-05-06 21:07:17 +00:00
|
|
|
|
}
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2018-06-08 09:29:59 +00:00
|
|
|
|
g_object_unref (sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-15 05:44:31 +00:00
|
|
|
|
static void
|
|
|
|
|
popup_menu_cb (GtkSidebarRow *row)
|
|
|
|
|
{
|
|
|
|
|
GtkPlacesSidebarPlaceType row_type;
|
|
|
|
|
|
|
|
|
|
g_object_get (row, "place-type", &row_type, NULL);
|
|
|
|
|
|
|
|
|
|
if (row_type != PLACES_CONNECT_TO_SERVER)
|
2015-07-16 01:25:10 +00:00
|
|
|
|
show_row_popover (row);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
long_press_cb (GtkGesture *gesture,
|
|
|
|
|
gdouble x,
|
|
|
|
|
gdouble y,
|
|
|
|
|
GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *row;
|
|
|
|
|
|
|
|
|
|
row = GTK_WIDGET (gtk_list_box_get_row_at_y (GTK_LIST_BOX (sidebar->list_box), y));
|
|
|
|
|
if (GTK_IS_SIDEBAR_ROW (row))
|
|
|
|
|
popup_menu_cb (GTK_SIDEBAR_ROW (row));
|
2015-07-15 05:44:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-07 15:04:42 +00:00
|
|
|
|
static gint
|
2015-05-06 21:07:17 +00:00
|
|
|
|
list_box_sort_func (GtkListBoxRow *row1,
|
|
|
|
|
GtkListBoxRow *row2,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkPlacesSidebarSectionType section_type_1, section_type_2;
|
|
|
|
|
GtkPlacesSidebarPlaceType place_type_1, place_type_2;
|
2015-06-23 20:06:30 +00:00
|
|
|
|
gchar *label_1, *label_2;
|
2015-05-06 21:07:17 +00:00
|
|
|
|
gint index_1, index_2;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
gint retval = 0;
|
|
|
|
|
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_object_get (row1,
|
2015-05-06 21:07:17 +00:00
|
|
|
|
"label", &label_1,
|
|
|
|
|
"place-type", &place_type_1,
|
|
|
|
|
"section-type", §ion_type_1,
|
|
|
|
|
"order-index", &index_1,
|
|
|
|
|
NULL);
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_object_get (row2,
|
2015-05-06 21:07:17 +00:00
|
|
|
|
"label", &label_2,
|
|
|
|
|
"place-type", &place_type_2,
|
|
|
|
|
"section-type", §ion_type_2,
|
|
|
|
|
"order-index", &index_2,
|
|
|
|
|
NULL);
|
2015-03-04 20:12:40 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
/* Always last position for "connect to server" */
|
|
|
|
|
if (place_type_1 == PLACES_CONNECT_TO_SERVER)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
|
|
|
|
retval = 1;
|
|
|
|
|
}
|
2015-05-06 21:07:17 +00:00
|
|
|
|
else if (place_type_2 == PLACES_CONNECT_TO_SERVER)
|
2014-12-05 03:26:14 +00:00
|
|
|
|
{
|
|
|
|
|
retval = -1;
|
|
|
|
|
}
|
2015-05-06 21:07:17 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (section_type_1 == section_type_2)
|
|
|
|
|
{
|
2015-08-21 13:00:07 +00:00
|
|
|
|
if ((section_type_1 == SECTION_COMPUTER &&
|
|
|
|
|
place_type_1 == place_type_2 &&
|
|
|
|
|
place_type_1 == PLACES_XDG_DIR) ||
|
|
|
|
|
section_type_1 == SECTION_MOUNTS)
|
2015-05-06 21:07:17 +00:00
|
|
|
|
{
|
|
|
|
|
retval = g_utf8_collate (label_1, label_2);
|
|
|
|
|
}
|
|
|
|
|
else if ((place_type_1 == PLACES_BOOKMARK || place_type_2 == PLACES_DROP_FEEDBACK) &&
|
|
|
|
|
(place_type_1 == PLACES_DROP_FEEDBACK || place_type_2 == PLACES_BOOKMARK))
|
|
|
|
|
{
|
|
|
|
|
retval = index_1 - index_2;
|
|
|
|
|
}
|
|
|
|
|
/* We order the bookmarks sections based on the bookmark index that we
|
|
|
|
|
* set on the row as a order-index property, but we have to deal with
|
|
|
|
|
* the placeholder row wanted to be between two consecutive bookmarks,
|
|
|
|
|
* with two consecutive order-index values which is the usual case.
|
|
|
|
|
* For that, in the list box sort func we give priority to the placeholder row,
|
|
|
|
|
* that means that if the index-order is the same as another bookmark
|
|
|
|
|
* the placeholder row goes before. However if we want to show it after
|
|
|
|
|
* the current row, for instance when the cursor is in the lower half
|
|
|
|
|
* of the row, we need to increase the order-index.
|
|
|
|
|
*/
|
|
|
|
|
else if (place_type_1 == PLACES_BOOKMARK_PLACEHOLDER && place_type_2 == PLACES_BOOKMARK)
|
|
|
|
|
{
|
|
|
|
|
if (index_1 == index_2)
|
|
|
|
|
retval = index_1 - index_2 - 1;
|
|
|
|
|
else
|
|
|
|
|
retval = index_1 - index_2;
|
|
|
|
|
}
|
|
|
|
|
else if (place_type_1 == PLACES_BOOKMARK && place_type_2 == PLACES_BOOKMARK_PLACEHOLDER)
|
|
|
|
|
{
|
|
|
|
|
if (index_1 == index_2)
|
|
|
|
|
retval = index_1 - index_2 + 1;
|
|
|
|
|
else
|
|
|
|
|
retval = index_1 - index_2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Order by section. That means the order in the enum of section types
|
|
|
|
|
* define the actual order of them in the list */
|
|
|
|
|
retval = section_type_1 - section_type_2;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_free (label_1);
|
|
|
|
|
g_free (label_2);
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
return retval;
|
2012-09-07 15:04:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
update_hostname (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GVariant *variant;
|
|
|
|
|
gsize len;
|
|
|
|
|
const gchar *hostname;
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
if (sidebar->hostnamed_proxy == NULL)
|
|
|
|
|
return;
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
variant = g_dbus_proxy_get_cached_property (sidebar->hostnamed_proxy,
|
|
|
|
|
"PrettyHostname");
|
|
|
|
|
if (variant == NULL)
|
|
|
|
|
return;
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_variant_unref (variant);
|
2012-09-07 15:04:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
hostname_proxy_new_cb (GObject *source_object,
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GAsyncResult *res,
|
|
|
|
|
gpointer user_data)
|
2012-09-07 15:04:42 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar = user_data;
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
GDBusProxy *proxy;
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
|
|
|
|
|
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
2014-09-11 22:27:33 +00:00
|
|
|
|
{
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-01-21 21:38:23 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
sidebar->hostnamed_proxy = proxy;
|
|
|
|
|
g_clear_object (&sidebar->hostnamed_cancellable);
|
2013-05-02 12:21:42 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
if (error != NULL)
|
|
|
|
|
{
|
|
|
|
|
g_debug ("Failed to create D-Bus proxy: %s", error->message);
|
|
|
|
|
g_error_free (error);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_signal_connect_swapped (sidebar->hostnamed_proxy,
|
|
|
|
|
"g-properties-changed",
|
|
|
|
|
G_CALLBACK (update_hostname),
|
|
|
|
|
sidebar);
|
|
|
|
|
update_hostname (sidebar);
|
2012-09-07 15:04:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-07 22:46:28 +00:00
|
|
|
|
static void
|
|
|
|
|
create_volume_monitor (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_assert (sidebar->volume_monitor == NULL);
|
|
|
|
|
|
|
|
|
|
sidebar->volume_monitor = g_volume_monitor_get ();
|
|
|
|
|
|
|
|
|
|
g_signal_connect_object (sidebar->volume_monitor, "volume_added",
|
|
|
|
|
G_CALLBACK (update_places), sidebar, G_CONNECT_SWAPPED);
|
|
|
|
|
g_signal_connect_object (sidebar->volume_monitor, "volume_removed",
|
|
|
|
|
G_CALLBACK (update_places), sidebar, G_CONNECT_SWAPPED);
|
|
|
|
|
g_signal_connect_object (sidebar->volume_monitor, "volume_changed",
|
|
|
|
|
G_CALLBACK (update_places), sidebar, G_CONNECT_SWAPPED);
|
|
|
|
|
g_signal_connect_object (sidebar->volume_monitor, "mount_added",
|
|
|
|
|
G_CALLBACK (update_places), sidebar, G_CONNECT_SWAPPED);
|
|
|
|
|
g_signal_connect_object (sidebar->volume_monitor, "mount_removed",
|
|
|
|
|
G_CALLBACK (update_places), sidebar, G_CONNECT_SWAPPED);
|
|
|
|
|
g_signal_connect_object (sidebar->volume_monitor, "mount_changed",
|
|
|
|
|
G_CALLBACK (update_places), sidebar, G_CONNECT_SWAPPED);
|
|
|
|
|
g_signal_connect_object (sidebar->volume_monitor, "drive_disconnected",
|
|
|
|
|
G_CALLBACK (update_places), sidebar, G_CONNECT_SWAPPED);
|
|
|
|
|
g_signal_connect_object (sidebar->volume_monitor, "drive_connected",
|
|
|
|
|
G_CALLBACK (update_places), sidebar, G_CONNECT_SWAPPED);
|
|
|
|
|
g_signal_connect_object (sidebar->volume_monitor, "drive_changed",
|
|
|
|
|
G_CALLBACK (update_places), sidebar, G_CONNECT_SWAPPED);
|
2011-09-07 22:46:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-14 20:02:00 +00:00
|
|
|
|
static void
|
|
|
|
|
shell_shows_desktop_changed (GtkSettings *settings,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkPlacesSidebar *sidebar = user_data;
|
2015-06-16 14:54:24 +00:00
|
|
|
|
gboolean show_desktop;
|
2013-11-14 20:02:00 +00:00
|
|
|
|
|
|
|
|
|
g_assert (settings == sidebar->gtk_settings);
|
|
|
|
|
|
|
|
|
|
/* Check if the user explicitly set this and, if so, don't change it. */
|
|
|
|
|
if (sidebar->show_desktop_set)
|
|
|
|
|
return;
|
|
|
|
|
|
2015-06-16 14:54:24 +00:00
|
|
|
|
g_object_get (settings, "gtk-shell-shows-desktop", &show_desktop, NULL);
|
2013-11-14 20:02:00 +00:00
|
|
|
|
|
2015-06-16 14:54:24 +00:00
|
|
|
|
if (show_desktop != sidebar->show_desktop)
|
2013-11-14 20:02:00 +00:00
|
|
|
|
{
|
2015-06-16 14:54:24 +00:00
|
|
|
|
sidebar->show_desktop = show_desktop;
|
2013-11-14 20:02:00 +00:00
|
|
|
|
update_places (sidebar);
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (sidebar), properties[PROP_SHOW_DESKTOP]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-03 14:44:46 +00:00
|
|
|
|
static void
|
2013-11-09 22:28:02 +00:00
|
|
|
|
gtk_places_sidebar_init (GtkPlacesSidebar *sidebar)
|
2011-10-03 14:44:46 +00:00
|
|
|
|
{
|
2017-11-18 01:19:53 +00:00
|
|
|
|
GdkContentFormats *target_list;
|
2015-06-16 14:54:24 +00:00
|
|
|
|
gboolean show_desktop;
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GtkStyleContext *context;
|
2018-04-20 17:58:06 +00:00
|
|
|
|
GtkEventController *controller;
|
2018-03-09 05:36:22 +00:00
|
|
|
|
GtkGesture *gesture;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2014-09-04 03:29:51 +00:00
|
|
|
|
sidebar->cancellable = g_cancellable_new ();
|
|
|
|
|
|
2015-07-03 16:49:00 +00:00
|
|
|
|
sidebar->show_trash = TRUE;
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
create_volume_monitor (sidebar);
|
|
|
|
|
|
|
|
|
|
sidebar->open_flags = GTK_PLACES_OPEN_NORMAL;
|
|
|
|
|
|
|
|
|
|
sidebar->bookmarks_manager = _gtk_bookmarks_manager_new ((GtkBookmarksChangedFunc)update_places, sidebar);
|
|
|
|
|
|
|
|
|
|
sidebar->trash_monitor = _gtk_trash_monitor_get ();
|
|
|
|
|
sidebar->trash_monitor_changed_id = g_signal_connect_swapped (sidebar->trash_monitor, "trash-state-changed",
|
2016-02-25 13:25:40 +00:00
|
|
|
|
G_CALLBACK (update_trash_icon), sidebar);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2019-05-28 22:11:14 +00:00
|
|
|
|
sidebar->swin = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
|
gtk_widget_set_parent (sidebar->swin, GTK_WIDGET (sidebar));
|
|
|
|
|
gtk_widget_set_size_request (sidebar->swin, 140, 280);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2019-05-28 22:11:14 +00:00
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sidebar->swin),
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GTK_POLICY_NEVER,
|
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
2019-05-28 22:11:14 +00:00
|
|
|
|
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sidebar->swin), GTK_SHADOW_IN);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-11-05 15:36:17 +00:00
|
|
|
|
context = gtk_widget_get_style_context (GTK_WIDGET (sidebar));
|
|
|
|
|
gtk_style_context_add_class (context, GTK_STYLE_CLASS_SIDEBAR);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
/* list box */
|
|
|
|
|
sidebar->list_box = gtk_list_box_new ();
|
|
|
|
|
|
|
|
|
|
gtk_list_box_set_header_func (GTK_LIST_BOX (sidebar->list_box),
|
|
|
|
|
list_box_header_func, sidebar, NULL);
|
|
|
|
|
gtk_list_box_set_sort_func (GTK_LIST_BOX (sidebar->list_box),
|
|
|
|
|
list_box_sort_func, NULL, NULL);
|
2015-07-19 21:39:23 +00:00
|
|
|
|
gtk_list_box_set_selection_mode (GTK_LIST_BOX (sidebar->list_box), GTK_SELECTION_SINGLE);
|
|
|
|
|
gtk_list_box_set_activate_on_single_click (GTK_LIST_BOX (sidebar->list_box), TRUE);
|
|
|
|
|
|
|
|
|
|
g_signal_connect (sidebar->list_box, "row-activated",
|
|
|
|
|
G_CALLBACK (on_row_activated), sidebar);
|
2018-03-05 17:50:35 +00:00
|
|
|
|
|
2018-04-20 17:58:06 +00:00
|
|
|
|
controller = gtk_event_controller_key_new ();
|
|
|
|
|
g_signal_connect (controller, "key-pressed",
|
2018-03-05 17:50:35 +00:00
|
|
|
|
G_CALLBACK (on_key_pressed), sidebar);
|
2018-04-20 17:58:06 +00:00
|
|
|
|
gtk_widget_add_controller (sidebar->list_box, controller);
|
2015-05-06 21:07:17 +00:00
|
|
|
|
|
2018-03-09 05:36:22 +00:00
|
|
|
|
gesture = gtk_gesture_long_press_new ();
|
|
|
|
|
gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (gesture), TRUE);
|
|
|
|
|
g_signal_connect (gesture, "pressed",
|
2015-07-16 01:25:10 +00:00
|
|
|
|
G_CALLBACK (long_press_cb), sidebar);
|
2018-03-09 05:36:22 +00:00
|
|
|
|
gtk_widget_add_controller (GTK_WIDGET (sidebar), GTK_EVENT_CONTROLLER (gesture));
|
2015-07-16 01:25:10 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
/* DND support */
|
|
|
|
|
gtk_drag_dest_set (sidebar->list_box,
|
2013-11-09 22:28:02 +00:00
|
|
|
|
0,
|
2017-11-14 21:32:23 +00:00
|
|
|
|
NULL,
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK);
|
2017-11-18 01:19:53 +00:00
|
|
|
|
target_list = gdk_content_formats_new (dnd_drop_targets, G_N_ELEMENTS (dnd_drop_targets));
|
2017-11-20 02:54:42 +00:00
|
|
|
|
target_list = gtk_content_formats_add_uri_targets (target_list);
|
2015-05-06 21:07:17 +00:00
|
|
|
|
gtk_drag_dest_set_target_list (sidebar->list_box, target_list);
|
2017-11-18 01:19:53 +00:00
|
|
|
|
gdk_content_formats_unref (target_list);
|
|
|
|
|
sidebar->source_targets = gdk_content_formats_new (dnd_source_targets, G_N_ELEMENTS (dnd_source_targets));
|
2017-11-20 02:54:42 +00:00
|
|
|
|
sidebar->source_targets = gtk_content_formats_add_text_targets (sidebar->source_targets);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
g_signal_connect (sidebar->list_box, "drag-begin",
|
|
|
|
|
G_CALLBACK (drag_begin_callback), sidebar);
|
|
|
|
|
g_signal_connect (sidebar->list_box, "drag-motion",
|
2013-11-09 22:28:02 +00:00
|
|
|
|
G_CALLBACK (drag_motion_callback), sidebar);
|
2015-05-06 21:07:17 +00:00
|
|
|
|
g_signal_connect (sidebar->list_box, "drag-data-get",
|
|
|
|
|
G_CALLBACK (drag_data_get_callback), sidebar);
|
|
|
|
|
g_signal_connect (sidebar->list_box, "drag-data-received",
|
2013-11-09 22:28:02 +00:00
|
|
|
|
G_CALLBACK (drag_data_received_callback), sidebar);
|
2015-05-06 21:07:17 +00:00
|
|
|
|
g_signal_connect (sidebar->list_box, "drag-drop",
|
2013-11-09 22:28:02 +00:00
|
|
|
|
G_CALLBACK (drag_drop_callback), sidebar);
|
2015-05-06 21:07:17 +00:00
|
|
|
|
g_signal_connect (sidebar->list_box, "drag-end",
|
|
|
|
|
G_CALLBACK (drag_end_callback), sidebar);
|
|
|
|
|
g_signal_connect (sidebar->list_box, "drag-leave",
|
|
|
|
|
G_CALLBACK (drag_leave_callback), sidebar);
|
|
|
|
|
sidebar->drag_row = NULL;
|
|
|
|
|
sidebar->row_placeholder = NULL;
|
|
|
|
|
sidebar->dragging_over = FALSE;
|
|
|
|
|
sidebar->drag_data_info = DND_UNKNOWN;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2019-05-28 22:11:14 +00:00
|
|
|
|
gtk_container_add (GTK_CONTAINER (sidebar->swin), sidebar->list_box);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
|
|
|
|
sidebar->hostname = g_strdup (_("Computer"));
|
|
|
|
|
sidebar->hostnamed_cancellable = g_cancellable_new ();
|
|
|
|
|
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",
|
|
|
|
|
sidebar->hostnamed_cancellable,
|
|
|
|
|
hostname_proxy_new_cb,
|
|
|
|
|
sidebar);
|
|
|
|
|
|
|
|
|
|
sidebar->drop_state = DROP_STATE_NORMAL;
|
|
|
|
|
|
2013-11-14 20:02:00 +00:00
|
|
|
|
/* Don't bother trying to trace this across hierarchy changes... */
|
|
|
|
|
sidebar->gtk_settings = gtk_settings_get_default ();
|
|
|
|
|
g_signal_connect (sidebar->gtk_settings, "notify::gtk-shell-shows-desktop",
|
|
|
|
|
G_CALLBACK (shell_shows_desktop_changed), sidebar);
|
2015-06-16 14:54:24 +00:00
|
|
|
|
g_object_get (sidebar->gtk_settings, "gtk-shell-shows-desktop", &show_desktop, NULL);
|
|
|
|
|
sidebar->show_desktop = show_desktop;
|
2013-11-14 20:02:00 +00:00
|
|
|
|
|
2017-08-10 20:30:36 +00:00
|
|
|
|
/* Cloud providers */
|
|
|
|
|
#ifdef HAVE_CLOUDPROVIDERS
|
2017-10-30 20:38:41 +00:00
|
|
|
|
sidebar->cloud_manager = cloud_providers_collector_dup_singleton ();
|
2017-08-10 20:30:36 +00:00
|
|
|
|
g_signal_connect_swapped (sidebar->cloud_manager,
|
2017-10-30 20:38:41 +00:00
|
|
|
|
"providers-changed",
|
2017-08-10 20:30:36 +00:00
|
|
|
|
G_CALLBACK (update_places),
|
|
|
|
|
sidebar);
|
|
|
|
|
#endif
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
/* populate the sidebar */
|
|
|
|
|
update_places (sidebar);
|
2015-07-16 01:25:10 +00:00
|
|
|
|
|
|
|
|
|
add_actions (sidebar);
|
2011-10-03 14:44:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-01-10 21:06:01 +00:00
|
|
|
|
static void
|
2013-11-09 22:28:02 +00:00
|
|
|
|
gtk_places_sidebar_set_property (GObject *obj,
|
|
|
|
|
guint property_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
2013-01-10 21:06:01 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (obj);
|
2013-01-10 21:06:01 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
switch (property_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_LOCATION:
|
|
|
|
|
gtk_places_sidebar_set_location (sidebar, g_value_get_object (value));
|
|
|
|
|
break;
|
2011-10-04 16:34:44 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
case PROP_OPEN_FLAGS:
|
|
|
|
|
gtk_places_sidebar_set_open_flags (sidebar, g_value_get_flags (value));
|
|
|
|
|
break;
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2015-06-06 21:13:22 +00:00
|
|
|
|
case PROP_SHOW_RECENT:
|
|
|
|
|
gtk_places_sidebar_set_show_recent (sidebar, g_value_get_boolean (value));
|
|
|
|
|
break;
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
case PROP_SHOW_DESKTOP:
|
|
|
|
|
gtk_places_sidebar_set_show_desktop (sidebar, g_value_get_boolean (value));
|
|
|
|
|
break;
|
|
|
|
|
|
2014-04-07 22:43:28 +00:00
|
|
|
|
case PROP_SHOW_ENTER_LOCATION:
|
|
|
|
|
gtk_places_sidebar_set_show_enter_location (sidebar, g_value_get_boolean (value));
|
|
|
|
|
break;
|
|
|
|
|
|
2015-07-14 17:47:42 +00:00
|
|
|
|
case PROP_SHOW_OTHER_LOCATIONS:
|
|
|
|
|
gtk_places_sidebar_set_show_other_locations (sidebar, g_value_get_boolean (value));
|
|
|
|
|
break;
|
|
|
|
|
|
2015-07-03 16:49:00 +00:00
|
|
|
|
case PROP_SHOW_TRASH:
|
|
|
|
|
gtk_places_sidebar_set_show_trash (sidebar, g_value_get_boolean (value));
|
|
|
|
|
break;
|
|
|
|
|
|
2017-07-20 15:29:42 +00:00
|
|
|
|
case PROP_SHOW_STARRED_LOCATION:
|
|
|
|
|
gtk_places_sidebar_set_show_starred_location (sidebar, g_value_get_boolean (value));
|
|
|
|
|
break;
|
|
|
|
|
|
2013-11-09 23:28:12 +00:00
|
|
|
|
case PROP_LOCAL_ONLY:
|
|
|
|
|
gtk_places_sidebar_set_local_only (sidebar, g_value_get_boolean (value));
|
|
|
|
|
break;
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-01-21 23:21:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_places_sidebar_get_property (GObject *obj,
|
2013-11-09 22:28:02 +00:00
|
|
|
|
guint property_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (obj);
|
|
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_LOCATION:
|
|
|
|
|
g_value_take_object (value, gtk_places_sidebar_get_location (sidebar));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_OPEN_FLAGS:
|
|
|
|
|
g_value_set_flags (value, gtk_places_sidebar_get_open_flags (sidebar));
|
|
|
|
|
break;
|
|
|
|
|
|
2015-06-06 21:13:22 +00:00
|
|
|
|
case PROP_SHOW_RECENT:
|
|
|
|
|
g_value_set_boolean (value, gtk_places_sidebar_get_show_recent (sidebar));
|
|
|
|
|
break;
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
case PROP_SHOW_DESKTOP:
|
|
|
|
|
g_value_set_boolean (value, gtk_places_sidebar_get_show_desktop (sidebar));
|
|
|
|
|
break;
|
|
|
|
|
|
2014-04-07 22:43:28 +00:00
|
|
|
|
case PROP_SHOW_ENTER_LOCATION:
|
|
|
|
|
g_value_set_boolean (value, gtk_places_sidebar_get_show_enter_location (sidebar));
|
|
|
|
|
break;
|
|
|
|
|
|
2015-07-14 17:47:42 +00:00
|
|
|
|
case PROP_SHOW_OTHER_LOCATIONS:
|
|
|
|
|
g_value_set_boolean (value, gtk_places_sidebar_get_show_other_locations (sidebar));
|
|
|
|
|
break;
|
|
|
|
|
|
2015-07-03 16:49:00 +00:00
|
|
|
|
case PROP_SHOW_TRASH:
|
|
|
|
|
g_value_set_boolean (value, gtk_places_sidebar_get_show_trash (sidebar));
|
|
|
|
|
break;
|
|
|
|
|
|
2017-07-20 15:29:42 +00:00
|
|
|
|
case PROP_SHOW_STARRED_LOCATION:
|
|
|
|
|
g_value_set_boolean (value, gtk_places_sidebar_get_show_starred_location (sidebar));
|
|
|
|
|
break;
|
|
|
|
|
|
2013-11-09 23:28:12 +00:00
|
|
|
|
case PROP_LOCAL_ONLY:
|
|
|
|
|
g_value_set_boolean (value, gtk_places_sidebar_get_local_only (sidebar));
|
|
|
|
|
break;
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-01-21 23:21:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar;
|
2017-10-30 20:38:41 +00:00
|
|
|
|
#ifdef HAVE_CLOUDPROVIDERS
|
|
|
|
|
GList *l;
|
|
|
|
|
#endif
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
sidebar = GTK_PLACES_SIDEBAR (object);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2014-09-04 03:29:51 +00:00
|
|
|
|
if (sidebar->cancellable)
|
|
|
|
|
{
|
|
|
|
|
g_cancellable_cancel (sidebar->cancellable);
|
|
|
|
|
g_object_unref (sidebar->cancellable);
|
|
|
|
|
sidebar->cancellable = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
free_drag_data (sidebar);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +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
|
|
|
|
|
2015-07-16 01:25:10 +00:00
|
|
|
|
if (sidebar->popover)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
2015-07-16 01:25:10 +00:00
|
|
|
|
gtk_widget_destroy (sidebar->popover);
|
|
|
|
|
sidebar->popover = NULL;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
2012-12-14 23:56:53 +00:00
|
|
|
|
|
2015-07-05 02:32:06 +00:00
|
|
|
|
if (sidebar->rename_popover)
|
|
|
|
|
{
|
|
|
|
|
gtk_widget_destroy (sidebar->rename_popover);
|
|
|
|
|
sidebar->rename_popover = NULL;
|
|
|
|
|
sidebar->rename_entry = NULL;
|
|
|
|
|
sidebar->rename_button = NULL;
|
|
|
|
|
sidebar->rename_error = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
if (sidebar->trash_monitor)
|
|
|
|
|
{
|
|
|
|
|
g_signal_handler_disconnect (sidebar->trash_monitor, sidebar->trash_monitor_changed_id);
|
|
|
|
|
sidebar->trash_monitor_changed_id = 0;
|
|
|
|
|
g_clear_object (&sidebar->trash_monitor);
|
|
|
|
|
}
|
2013-01-10 21:06:01 +00:00
|
|
|
|
|
2016-02-26 10:01:38 +00:00
|
|
|
|
if (sidebar->trash_row)
|
|
|
|
|
{
|
2016-02-26 10:54:53 +00:00
|
|
|
|
g_object_remove_weak_pointer (G_OBJECT (sidebar->trash_row),
|
|
|
|
|
(gpointer *) &sidebar->trash_row);
|
2016-02-26 10:01:38 +00:00
|
|
|
|
sidebar->trash_row = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
if (sidebar->volume_monitor != NULL)
|
|
|
|
|
{
|
|
|
|
|
g_signal_handlers_disconnect_by_func (sidebar->volume_monitor,
|
|
|
|
|
update_places, sidebar);
|
|
|
|
|
g_clear_object (&sidebar->volume_monitor);
|
|
|
|
|
}
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
if (sidebar->hostnamed_cancellable != NULL)
|
|
|
|
|
{
|
|
|
|
|
g_cancellable_cancel (sidebar->hostnamed_cancellable);
|
|
|
|
|
g_clear_object (&sidebar->hostnamed_cancellable);
|
|
|
|
|
}
|
2012-09-07 15:04:42 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_clear_object (&sidebar->hostnamed_proxy);
|
|
|
|
|
g_free (sidebar->hostname);
|
|
|
|
|
sidebar->hostname = NULL;
|
2013-01-21 21:38:23 +00:00
|
|
|
|
|
2013-11-14 20:02:00 +00:00
|
|
|
|
if (sidebar->gtk_settings)
|
|
|
|
|
{
|
|
|
|
|
g_signal_handlers_disconnect_by_func (sidebar->gtk_settings, shell_shows_desktop_changed, sidebar);
|
2013-11-15 02:30:47 +00:00
|
|
|
|
sidebar->gtk_settings = NULL;
|
2013-11-14 20:02:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-02 06:42:25 +00:00
|
|
|
|
g_clear_object (&sidebar->current_location);
|
|
|
|
|
g_clear_pointer (&sidebar->rename_uri, g_free);
|
2014-10-12 01:55:39 +00:00
|
|
|
|
|
2015-07-21 23:10:04 +00:00
|
|
|
|
if (sidebar->source_targets)
|
|
|
|
|
{
|
2017-11-18 01:19:53 +00:00
|
|
|
|
gdk_content_formats_unref (sidebar->source_targets);
|
2015-07-21 23:10:04 +00:00
|
|
|
|
sidebar->source_targets = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 01:00:12 +00:00
|
|
|
|
g_slist_free_full (sidebar->shortcuts, g_object_unref);
|
|
|
|
|
sidebar->shortcuts = NULL;
|
|
|
|
|
|
2017-09-12 21:15:27 +00:00
|
|
|
|
#ifdef HAVE_CLOUDPROVIDERS
|
2017-10-30 20:38:41 +00:00
|
|
|
|
for (l = cloud_providers_collector_get_providers (sidebar->cloud_manager);
|
|
|
|
|
l != NULL; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
g_signal_handlers_disconnect_by_data (l->data, sidebar);
|
|
|
|
|
}
|
|
|
|
|
for (l = sidebar->unready_accounts; l != NULL; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
g_signal_handlers_disconnect_by_data (l->data, sidebar);
|
|
|
|
|
}
|
|
|
|
|
g_list_free_full (sidebar->unready_accounts, g_object_unref);
|
|
|
|
|
sidebar->unready_accounts = NULL;
|
2017-09-12 21:15:27 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
G_OBJECT_CLASS (gtk_places_sidebar_parent_class)->dispose (object);
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-30 20:38:41 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_places_sidebar_finalize (GObject *object)
|
|
|
|
|
{
|
2019-05-28 22:11:14 +00:00
|
|
|
|
GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (object);
|
2017-10-30 20:38:41 +00:00
|
|
|
|
|
2019-06-15 22:25:05 +00:00
|
|
|
|
g_clear_object (&sidebar->row_actions);
|
|
|
|
|
|
2019-05-28 22:11:14 +00:00
|
|
|
|
#ifdef HAVE_CLOUDPROVIDERS
|
2017-10-30 20:38:41 +00:00
|
|
|
|
g_clear_object (&sidebar->cloud_manager);
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-05-28 22:11:14 +00:00
|
|
|
|
g_clear_pointer (&sidebar->swin, gtk_widget_unparent);
|
|
|
|
|
|
2017-10-30 20:38:41 +00:00
|
|
|
|
G_OBJECT_CLASS (gtk_places_sidebar_parent_class)->finalize (object);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-28 22:11:14 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_places_sidebar_measure (GtkWidget *widget,
|
|
|
|
|
GtkOrientation orientation,
|
|
|
|
|
int for_size,
|
|
|
|
|
int *minimum,
|
|
|
|
|
int *natural,
|
|
|
|
|
int *minimum_baseline,
|
|
|
|
|
int *natural_baseline)
|
|
|
|
|
{
|
|
|
|
|
GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (widget);
|
|
|
|
|
|
|
|
|
|
gtk_widget_measure (sidebar->swin,
|
|
|
|
|
orientation,
|
|
|
|
|
for_size,
|
|
|
|
|
minimum, natural,
|
|
|
|
|
minimum_baseline, natural_baseline);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-04 18:44:51 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_places_sidebar_size_allocate (GtkWidget *widget,
|
|
|
|
|
int width,
|
|
|
|
|
int height,
|
|
|
|
|
int baseline)
|
|
|
|
|
{
|
|
|
|
|
GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (widget);
|
|
|
|
|
|
2019-05-28 22:11:14 +00:00
|
|
|
|
gtk_widget_size_allocate (sidebar->swin,
|
|
|
|
|
&(GtkAllocation) { 0, 0, width, height },
|
|
|
|
|
baseline);
|
2019-05-04 18:44:51 +00:00
|
|
|
|
|
|
|
|
|
if (sidebar->rename_popover)
|
|
|
|
|
gtk_native_check_resize (GTK_NATIVE (sidebar->rename_popover));
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
2015-11-05 15:36:17 +00:00
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
|
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gobject_class->dispose = gtk_places_sidebar_dispose;
|
2017-10-30 20:38:41 +00:00
|
|
|
|
gobject_class->finalize = gtk_places_sidebar_finalize;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
gobject_class->set_property = gtk_places_sidebar_set_property;
|
|
|
|
|
gobject_class->get_property = gtk_places_sidebar_get_property;
|
|
|
|
|
|
2019-05-28 22:11:14 +00:00
|
|
|
|
widget_class->measure = gtk_places_sidebar_measure;
|
2019-05-04 18:44:51 +00:00
|
|
|
|
widget_class->size_allocate = gtk_places_sidebar_size_allocate;
|
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2013-11-09 22:28:02 +00:00
|
|
|
|
* GtkPlacesSidebar::open-location:
|
|
|
|
|
* @sidebar: the object which received the signal.
|
2014-05-26 16:41:21 +00:00
|
|
|
|
* @location: (type Gio.File): #GFile to which the caller should switch.
|
2013-11-09 22:28:02 +00:00
|
|
|
|
* @open_flags: a single value from #GtkPlacesOpenFlags specifying how the @location should be opened.
|
|
|
|
|
*
|
|
|
|
|
* The places sidebar emits this signal when the user selects a location
|
|
|
|
|
* in it. The calling application should display the contents of that
|
|
|
|
|
* location; for example, a file manager should show a list of files in
|
|
|
|
|
* the specified location.
|
|
|
|
|
*/
|
|
|
|
|
places_sidebar_signals [OPEN_LOCATION] =
|
|
|
|
|
g_signal_new (I_("open-location"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkPlacesSidebarClass, open_location),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
_gtk_marshal_VOID__OBJECT_FLAGS,
|
|
|
|
|
G_TYPE_NONE, 2,
|
|
|
|
|
G_TYPE_OBJECT,
|
|
|
|
|
GTK_TYPE_PLACES_OPEN_FLAGS);
|
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2013-11-09 22:28:02 +00:00
|
|
|
|
* GtkPlacesSidebar::show-error-message:
|
|
|
|
|
* @sidebar: the object which received the signal.
|
|
|
|
|
* @primary: primary message with a summary of the error to show.
|
|
|
|
|
* @secondary: secondary message with details of the error to show.
|
|
|
|
|
*
|
|
|
|
|
* The places sidebar emits this signal when it needs the calling
|
|
|
|
|
* application to present an error message. Most of these messages
|
|
|
|
|
* refer to mounting or unmounting media, for example, when a drive
|
|
|
|
|
* cannot be started for some reason.
|
|
|
|
|
*/
|
|
|
|
|
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);
|
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2014-04-07 22:43:28 +00:00
|
|
|
|
* GtkPlacesSidebar::show-enter-location:
|
|
|
|
|
* @sidebar: the object which received the signal.
|
|
|
|
|
*
|
|
|
|
|
* The places sidebar emits this signal when it needs the calling
|
|
|
|
|
* application to present an way to directly enter a location.
|
|
|
|
|
* For example, the application may bring up a dialog box asking for
|
|
|
|
|
* a URL like "http://http.example.com".
|
|
|
|
|
*/
|
|
|
|
|
places_sidebar_signals [SHOW_ENTER_LOCATION] =
|
|
|
|
|
g_signal_new (I_("show-enter-location"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkPlacesSidebarClass, show_enter_location),
|
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
|
NULL,
|
2014-04-07 22:43:28 +00:00
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2013-11-09 22:28:02 +00:00
|
|
|
|
* GtkPlacesSidebar::drag-action-requested:
|
|
|
|
|
* @sidebar: the object which received the signal.
|
2018-05-15 22:59:01 +00:00
|
|
|
|
* @drop: (type Gdk.Drop): #GdkDrop with information about the drag operation
|
2014-05-26 16:41:21 +00:00
|
|
|
|
* @dest_file: (type Gio.File): #GFile with the tentative location that is being hovered for a drop
|
|
|
|
|
* @source_file_list: (type GLib.List) (element-type GFile) (transfer none):
|
|
|
|
|
* List of #GFile that are being dragged
|
2013-11-09 22:28:02 +00:00
|
|
|
|
*
|
|
|
|
|
* When the user starts a drag-and-drop operation and the sidebar needs
|
|
|
|
|
* to ask the application for which drag action to perform, then the
|
|
|
|
|
* sidebar will emit this signal.
|
|
|
|
|
*
|
|
|
|
|
* The application can evaluate the @context for customary actions, or
|
|
|
|
|
* it can check the type of the files indicated by @source_file_list against the
|
|
|
|
|
* possible actions for the destination @dest_file.
|
|
|
|
|
*
|
|
|
|
|
* The drag action to use must be the return value of the signal handler.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: The drag action to use, for example, #GDK_ACTION_COPY
|
2013-11-09 22:28:02 +00:00
|
|
|
|
* or #GDK_ACTION_MOVE, or 0 if no action is allowed here (i.e. drops
|
|
|
|
|
* are not allowed in the specified @dest_file).
|
|
|
|
|
*/
|
|
|
|
|
places_sidebar_signals [DRAG_ACTION_REQUESTED] =
|
|
|
|
|
g_signal_new (I_("drag-action-requested"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkPlacesSidebarClass, drag_action_requested),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
_gtk_marshal_INT__OBJECT_OBJECT_POINTER,
|
|
|
|
|
G_TYPE_INT, 3,
|
2018-07-17 06:31:54 +00:00
|
|
|
|
GDK_TYPE_DRAG,
|
2013-11-09 22:28:02 +00:00
|
|
|
|
G_TYPE_OBJECT,
|
|
|
|
|
G_TYPE_POINTER /* GList of GFile */ );
|
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2013-11-09 22:28:02 +00:00
|
|
|
|
* GtkPlacesSidebar::drag-action-ask:
|
|
|
|
|
* @sidebar: the object which received the signal.
|
|
|
|
|
* @actions: Possible drag actions that need to be asked for.
|
|
|
|
|
*
|
|
|
|
|
* The places sidebar emits this signal when it needs to ask the application
|
|
|
|
|
* to pop up a menu to ask the user for which drag action to perform.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: the final drag action that the sidebar should pass to the drag side
|
2013-11-09 22:28:02 +00:00
|
|
|
|
* of the drag-and-drop operation.
|
|
|
|
|
*/
|
|
|
|
|
places_sidebar_signals [DRAG_ACTION_ASK] =
|
|
|
|
|
g_signal_new (I_("drag-action-ask"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkPlacesSidebarClass, drag_action_ask),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
_gtk_marshal_INT__INT,
|
|
|
|
|
G_TYPE_INT, 1,
|
|
|
|
|
G_TYPE_INT);
|
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2013-11-09 22:28:02 +00:00
|
|
|
|
* GtkPlacesSidebar::drag-perform-drop:
|
|
|
|
|
* @sidebar: the object which received the signal.
|
2014-05-26 16:41:21 +00:00
|
|
|
|
* @dest_file: (type Gio.File): Destination #GFile.
|
|
|
|
|
* @source_file_list: (type GLib.List) (element-type GFile) (transfer none):
|
|
|
|
|
* #GList of #GFile that got dropped.
|
2013-11-09 22:28:02 +00:00
|
|
|
|
* @action: Drop action to perform.
|
|
|
|
|
*
|
|
|
|
|
* The places sidebar emits this signal when the user completes a
|
|
|
|
|
* drag-and-drop operation and one of the sidebar's items is the
|
|
|
|
|
* destination. This item is in the @dest_file, and the
|
|
|
|
|
* @source_file_list has the list of files that are dropped into it and
|
|
|
|
|
* which should be copied/moved/etc. based on the specified @action.
|
|
|
|
|
*/
|
|
|
|
|
places_sidebar_signals [DRAG_PERFORM_DROP] =
|
|
|
|
|
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__OBJECT_POINTER_INT,
|
|
|
|
|
G_TYPE_NONE, 3,
|
|
|
|
|
G_TYPE_OBJECT,
|
|
|
|
|
G_TYPE_POINTER, /* GList of GFile */
|
|
|
|
|
G_TYPE_INT);
|
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2016-02-29 22:13:51 +00:00
|
|
|
|
* GtkPlacesSidebar::show-other-locations-with-flags:
|
|
|
|
|
* @sidebar: the object which received the signal.
|
|
|
|
|
* @open_flags: a single value from #GtkPlacesOpenFlags specifying how it should be opened.
|
|
|
|
|
*
|
|
|
|
|
* The places sidebar emits this signal when it needs the calling
|
|
|
|
|
* application to present a way to show other locations e.g. drives
|
|
|
|
|
* and network access points.
|
|
|
|
|
* For example, the application may bring up a page showing persistent
|
|
|
|
|
* volumes and discovered network addresses.
|
|
|
|
|
*/
|
|
|
|
|
places_sidebar_signals [SHOW_OTHER_LOCATIONS_WITH_FLAGS] =
|
|
|
|
|
g_signal_new (I_("show-other-locations-with-flags"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkPlacesSidebarClass, show_other_locations_with_flags),
|
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
|
NULL,
|
2016-02-29 22:13:51 +00:00
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
|
GTK_TYPE_PLACES_OPEN_FLAGS);
|
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2016-02-15 18:09:54 +00:00
|
|
|
|
* GtkPlacesSidebar::mount:
|
|
|
|
|
* @sidebar: the object which received the signal.
|
|
|
|
|
* @mount_operation: the #GMountOperation that is going to start.
|
|
|
|
|
*
|
|
|
|
|
* The places sidebar emits this signal when it starts a new operation
|
|
|
|
|
* because the user clicked on some location that needs mounting.
|
|
|
|
|
* In this way the application using the #GtkPlacesSidebar can track the
|
|
|
|
|
* progress of the operation and, for example, show a notification.
|
|
|
|
|
*/
|
|
|
|
|
places_sidebar_signals [MOUNT] =
|
|
|
|
|
g_signal_new (I_("mount"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkPlacesSidebarClass, mount),
|
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
|
NULL,
|
2016-02-15 18:09:54 +00:00
|
|
|
|
G_TYPE_NONE,
|
|
|
|
|
1,
|
|
|
|
|
G_TYPE_MOUNT_OPERATION);
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2016-02-15 18:09:54 +00:00
|
|
|
|
* GtkPlacesSidebar::unmount:
|
|
|
|
|
* @sidebar: the object which received the signal.
|
|
|
|
|
* @mount_operation: the #GMountOperation that is going to start.
|
|
|
|
|
*
|
|
|
|
|
* The places sidebar emits this signal when it starts a new operation
|
|
|
|
|
* because the user for example ejected some drive or unmounted a mount.
|
|
|
|
|
* In this way the application using the #GtkPlacesSidebar can track the
|
|
|
|
|
* progress of the operation and, for example, show a notification.
|
|
|
|
|
*/
|
|
|
|
|
places_sidebar_signals [UNMOUNT] =
|
|
|
|
|
g_signal_new (I_("unmount"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkPlacesSidebarClass, unmount),
|
|
|
|
|
NULL, NULL,
|
2016-08-29 14:00:17 +00:00
|
|
|
|
NULL,
|
2016-02-15 18:09:54 +00:00
|
|
|
|
G_TYPE_NONE,
|
|
|
|
|
1,
|
|
|
|
|
G_TYPE_MOUNT_OPERATION);
|
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2017-07-20 15:29:42 +00:00
|
|
|
|
* GtkPlacesSidebar::show-starred-location:
|
2017-12-21 19:00:28 +00:00
|
|
|
|
* @sidebar: the object which received the signal
|
|
|
|
|
* @flags: the flags for the operation
|
2017-07-20 15:29:42 +00:00
|
|
|
|
*
|
|
|
|
|
* The places sidebar emits this signal when it needs the calling
|
|
|
|
|
* application to present a way to show the starred files. In GNOME,
|
|
|
|
|
* starred files are implemented by setting the nao:predefined-tag-favorite
|
|
|
|
|
* tag in the tracker database.
|
|
|
|
|
*/
|
|
|
|
|
places_sidebar_signals [SHOW_STARRED_LOCATION] =
|
|
|
|
|
g_signal_new (I_("show-starred-location"),
|
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkPlacesSidebarClass, show_starred_location),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
|
GTK_TYPE_PLACES_OPEN_FLAGS);
|
2015-07-14 17:47:42 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
properties[PROP_LOCATION] =
|
|
|
|
|
g_param_spec_object ("location",
|
|
|
|
|
P_("Location to Select"),
|
|
|
|
|
P_("The location to highlight in the sidebar"),
|
|
|
|
|
G_TYPE_FILE,
|
2017-11-18 13:18:11 +00:00
|
|
|
|
GTK_PARAM_READWRITE);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
properties[PROP_OPEN_FLAGS] =
|
|
|
|
|
g_param_spec_flags ("open-flags",
|
|
|
|
|
P_("Open Flags"),
|
|
|
|
|
P_("Modes in which the calling application can open locations selected in the sidebar"),
|
|
|
|
|
GTK_TYPE_PLACES_OPEN_FLAGS,
|
|
|
|
|
GTK_PLACES_OPEN_NORMAL,
|
2017-11-18 13:18:11 +00:00
|
|
|
|
GTK_PARAM_READWRITE);
|
2015-06-06 21:13:22 +00:00
|
|
|
|
properties[PROP_SHOW_RECENT] =
|
|
|
|
|
g_param_spec_boolean ("show-recent",
|
|
|
|
|
P_("Show recent files"),
|
|
|
|
|
P_("Whether the sidebar includes a builtin shortcut for recent files"),
|
|
|
|
|
TRUE,
|
2017-11-18 13:18:11 +00:00
|
|
|
|
GTK_PARAM_READWRITE);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
properties[PROP_SHOW_DESKTOP] =
|
|
|
|
|
g_param_spec_boolean ("show-desktop",
|
2016-10-03 16:20:03 +00:00
|
|
|
|
P_("Show “Desktop”"),
|
2013-11-09 22:28:02 +00:00
|
|
|
|
P_("Whether the sidebar includes a builtin shortcut to the Desktop folder"),
|
2013-11-26 18:54:44 +00:00
|
|
|
|
TRUE,
|
2017-11-18 13:18:11 +00:00
|
|
|
|
GTK_PARAM_READWRITE);
|
2014-04-07 22:43:28 +00:00
|
|
|
|
properties[PROP_SHOW_ENTER_LOCATION] =
|
|
|
|
|
g_param_spec_boolean ("show-enter-location",
|
2016-10-03 16:20:03 +00:00
|
|
|
|
P_("Show “Enter Location”"),
|
2014-04-07 22:43:28 +00:00
|
|
|
|
P_("Whether the sidebar includes a builtin shortcut to manually enter a location"),
|
|
|
|
|
FALSE,
|
2017-11-18 13:18:11 +00:00
|
|
|
|
GTK_PARAM_READWRITE);
|
2013-11-09 23:28:12 +00:00
|
|
|
|
properties[PROP_LOCAL_ONLY] =
|
|
|
|
|
g_param_spec_boolean ("local-only",
|
|
|
|
|
P_("Local Only"),
|
|
|
|
|
P_("Whether the sidebar only includes local files"),
|
|
|
|
|
FALSE,
|
2017-11-18 13:18:11 +00:00
|
|
|
|
GTK_PARAM_READWRITE);
|
2015-07-03 16:49:00 +00:00
|
|
|
|
properties[PROP_SHOW_TRASH] =
|
|
|
|
|
g_param_spec_boolean ("show-trash",
|
2016-10-03 16:20:03 +00:00
|
|
|
|
P_("Show “Trash”"),
|
2015-07-24 15:27:38 +00:00
|
|
|
|
P_("Whether the sidebar includes a builtin shortcut to the Trash location"),
|
2015-07-03 16:49:00 +00:00
|
|
|
|
TRUE,
|
2017-11-18 13:18:11 +00:00
|
|
|
|
GTK_PARAM_READWRITE);
|
2015-07-14 17:47:42 +00:00
|
|
|
|
properties[PROP_SHOW_OTHER_LOCATIONS] =
|
|
|
|
|
g_param_spec_boolean ("show-other-locations",
|
2016-10-03 16:20:03 +00:00
|
|
|
|
P_("Show “Other locations”"),
|
2015-07-14 17:47:42 +00:00
|
|
|
|
P_("Whether the sidebar includes an item to show external locations"),
|
|
|
|
|
FALSE,
|
2017-11-18 13:18:11 +00:00
|
|
|
|
GTK_PARAM_READWRITE);
|
2017-07-20 15:29:42 +00:00
|
|
|
|
properties[PROP_SHOW_STARRED_LOCATION] =
|
|
|
|
|
g_param_spec_boolean ("show-starred-location",
|
2017-11-05 20:16:59 +00:00
|
|
|
|
P_("Show “Starred Location”"),
|
2017-07-20 15:29:42 +00:00
|
|
|
|
P_("Whether the sidebar includes an item to show starred files"),
|
|
|
|
|
FALSE,
|
2017-11-18 13:18:11 +00:00
|
|
|
|
GTK_PARAM_READWRITE);
|
2017-07-20 15:29:42 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
|
2015-11-05 15:36:17 +00:00
|
|
|
|
|
2017-11-18 03:49:57 +00:00
|
|
|
|
gtk_widget_class_set_css_name (widget_class, I_("placessidebar"));
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2013-01-19 01:28:58 +00:00
|
|
|
|
* gtk_places_sidebar_new:
|
|
|
|
|
*
|
2013-09-17 05:28:39 +00:00
|
|
|
|
* Creates a new #GtkPlacesSidebar widget.
|
|
|
|
|
*
|
|
|
|
|
* The application should connect to at least the
|
|
|
|
|
* #GtkPlacesSidebar::open-location signal to be notified
|
2013-01-19 01:28:58 +00:00
|
|
|
|
* when the user makes a selection in the sidebar.
|
2013-09-17 05:28:39 +00:00
|
|
|
|
*
|
|
|
|
|
* Returns: a newly created #GtkPlacesSidebar
|
2013-01-19 01:28:58 +00:00
|
|
|
|
*/
|
2011-09-06 22:53:30 +00:00
|
|
|
|
GtkWidget *
|
2011-09-07 22:40:49 +00:00
|
|
|
|
gtk_places_sidebar_new (void)
|
2011-09-06 22:53:30 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
return GTK_WIDGET (g_object_new (gtk_places_sidebar_get_type (), NULL));
|
2011-09-06 22:53:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2013-01-10 22:19:03 +00:00
|
|
|
|
* gtk_places_sidebar_set_open_flags:
|
|
|
|
|
* @sidebar: a places sidebar
|
|
|
|
|
* @flags: Bitmask of modes in which the calling application can open locations
|
|
|
|
|
*
|
|
|
|
|
* Sets the way in which the calling application can open new locations from
|
|
|
|
|
* the places sidebar. For example, some applications only open locations
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* “directly” into their main view, while others may support opening locations
|
2013-01-10 22:19:03 +00:00
|
|
|
|
* in a new notebook tab or a new window.
|
|
|
|
|
*
|
|
|
|
|
* This function is used to tell the places @sidebar about the ways in which the
|
|
|
|
|
* application can open new locations, so that the sidebar can display (or not)
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* the “Open in new tab” and “Open in new window” menu items as appropriate.
|
2013-01-10 22:19:03 +00:00
|
|
|
|
*
|
|
|
|
|
* When the #GtkPlacesSidebar::open-location signal is emitted, its flags
|
|
|
|
|
* argument will be set to one of the @flags that was passed in
|
|
|
|
|
* gtk_places_sidebar_set_open_flags().
|
|
|
|
|
*
|
|
|
|
|
* Passing 0 for @flags will cause #GTK_PLACES_OPEN_NORMAL to always be sent
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* to callbacks for the “open-location” signal.
|
2013-01-10 22:19:03 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
2013-11-09 22:28:02 +00:00
|
|
|
|
gtk_places_sidebar_set_open_flags (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GtkPlacesOpenFlags flags)
|
2013-01-10 22:19:03 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
|
2013-01-10 22:19:03 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
if (sidebar->open_flags != flags)
|
|
|
|
|
{
|
|
|
|
|
sidebar->open_flags = flags;
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (sidebar), properties[PROP_OPEN_FLAGS]);
|
|
|
|
|
}
|
2013-01-21 23:21:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2013-09-17 05:28:39 +00:00
|
|
|
|
* gtk_places_sidebar_get_open_flags:
|
|
|
|
|
* @sidebar: a #GtkPlacesSidebar
|
|
|
|
|
*
|
|
|
|
|
* Gets the open flags.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the #GtkPlacesOpenFlags of @sidebar
|
|
|
|
|
*/
|
2013-01-21 23:21:00 +00:00
|
|
|
|
GtkPlacesOpenFlags
|
|
|
|
|
gtk_places_sidebar_get_open_flags (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar), 0);
|
2013-01-21 23:21:00 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
return sidebar->open_flags;
|
2013-01-10 22:19:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2013-01-11 00:12:15 +00:00
|
|
|
|
* gtk_places_sidebar_set_location:
|
2011-09-07 22:55:21 +00:00
|
|
|
|
* @sidebar: a places sidebar
|
2017-11-22 19:19:27 +00:00
|
|
|
|
* @location: (nullable): location to select, or %NULL for no current path
|
2011-09-07 22:55:21 +00:00
|
|
|
|
*
|
2013-01-11 00:12:15 +00:00
|
|
|
|
* Sets the location that is being shown in the widgets surrounding the
|
|
|
|
|
* @sidebar, for example, in a folder view in a file manager. In turn, the
|
|
|
|
|
* @sidebar 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
|
2013-11-09 22:28:02 +00:00
|
|
|
|
gtk_places_sidebar_set_location (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GFile *location)
|
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GList *children;
|
|
|
|
|
GList *child;
|
|
|
|
|
gchar *row_uri;
|
|
|
|
|
gchar *uri;
|
2015-06-23 20:06:30 +00:00
|
|
|
|
gboolean found = FALSE;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
|
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
gtk_list_box_unselect_all (GTK_LIST_BOX (sidebar->list_box));
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2014-10-07 10:22:38 +00:00
|
|
|
|
if (sidebar->current_location != NULL)
|
|
|
|
|
g_object_unref (sidebar->current_location);
|
2015-01-28 23:25:32 +00:00
|
|
|
|
sidebar->current_location = location;
|
|
|
|
|
if (sidebar->current_location != NULL)
|
|
|
|
|
g_object_ref (sidebar->current_location);
|
2014-10-07 10:22:38 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
if (location == NULL)
|
2015-05-06 21:07:17 +00:00
|
|
|
|
goto out;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
|
|
|
|
uri = g_file_get_uri (location);
|
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
children = gtk_container_get_children (GTK_CONTAINER (sidebar->list_box));
|
2015-06-23 20:06:30 +00:00
|
|
|
|
for (child = children; child != NULL && !found; child = child->next)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_object_get (child->data, "uri", &row_uri, NULL);
|
2015-05-06 21:07:17 +00:00
|
|
|
|
if (row_uri != NULL && g_strcmp0 (row_uri, uri) == 0)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
gtk_list_box_select_row (GTK_LIST_BOX (sidebar->list_box),
|
|
|
|
|
GTK_LIST_BOX_ROW (child->data));
|
2015-06-23 20:06:30 +00:00
|
|
|
|
found = TRUE;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
2015-06-23 20:06:30 +00:00
|
|
|
|
|
|
|
|
|
g_free (row_uri);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_free (uri);
|
2015-05-06 21:07:17 +00:00
|
|
|
|
g_list_free (children);
|
2013-01-21 23:21:00 +00:00
|
|
|
|
|
|
|
|
|
out:
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (sidebar), properties[PROP_LOCATION]);
|
2011-09-07 22:55:21 +00:00
|
|
|
|
}
|
2011-10-04 14:22:11 +00:00
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2013-01-11 00:12:15 +00:00
|
|
|
|
* gtk_places_sidebar_get_location:
|
2012-12-18 02:05:23 +00:00
|
|
|
|
* @sidebar: a places sidebar
|
|
|
|
|
*
|
2017-11-22 19:19:27 +00:00
|
|
|
|
* Gets the currently selected location in the @sidebar. This can be %NULL when
|
2013-01-11 00:12:15 +00:00
|
|
|
|
* nothing is selected, for example, when gtk_places_sidebar_set_location() has
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* been called with a location that is not among the sidebar’s list of places to
|
2013-01-11 00:12:15 +00:00
|
|
|
|
* show.
|
|
|
|
|
*
|
2019-02-05 08:52:38 +00:00
|
|
|
|
* You can use this function to get the selection in the @sidebar.
|
2012-12-18 02:05:23 +00:00
|
|
|
|
*
|
2017-11-22 19:19:27 +00:00
|
|
|
|
* Returns: (nullable) (transfer full): a #GFile with the selected location, or
|
2015-12-28 20:14:08 +00:00
|
|
|
|
* %NULL if nothing is visually selected.
|
2012-12-18 02:05:23 +00:00
|
|
|
|
*/
|
|
|
|
|
GFile *
|
2013-01-11 00:12:15 +00:00
|
|
|
|
gtk_places_sidebar_get_location (GtkPlacesSidebar *sidebar)
|
2012-12-18 02:05:23 +00:00
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GtkListBoxRow *selected;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GFile *file;
|
2012-12-18 02:05:23 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_return_val_if_fail (sidebar != NULL, NULL);
|
2012-12-18 02:05:23 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
file = NULL;
|
2015-05-06 21:07:17 +00:00
|
|
|
|
selected = gtk_list_box_get_selected_row (GTK_LIST_BOX (sidebar->list_box));
|
2012-12-18 02:05:23 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
if (selected)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
|
|
|
|
gchar *uri;
|
2012-12-18 02:05:23 +00:00
|
|
|
|
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_object_get (selected, "uri", &uri, NULL);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
file = g_file_new_for_uri (uri);
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_free (uri);
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
2012-12-18 02:05:23 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
return file;
|
2012-12-18 02:05:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-27 01:13:00 +00:00
|
|
|
|
gchar *
|
|
|
|
|
gtk_places_sidebar_get_location_title (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
|
|
|
|
GtkListBoxRow *selected;
|
|
|
|
|
gchar *title;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (sidebar != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
title = NULL;
|
|
|
|
|
selected = gtk_list_box_get_selected_row (GTK_LIST_BOX (sidebar->list_box));
|
|
|
|
|
|
|
|
|
|
if (selected)
|
|
|
|
|
g_object_get (selected, "label", &title, NULL);
|
|
|
|
|
|
|
|
|
|
return title;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2015-06-06 21:13:22 +00:00
|
|
|
|
* gtk_places_sidebar_set_show_recent:
|
|
|
|
|
* @sidebar: a places sidebar
|
|
|
|
|
* @show_recent: whether to show an item for recent files
|
|
|
|
|
*
|
|
|
|
|
* Sets whether the @sidebar should show an item for recent files.
|
|
|
|
|
* The default value for this option is determined by the desktop
|
|
|
|
|
* environment, but this function can be used to override it on a
|
|
|
|
|
* per-application basis.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_places_sidebar_set_show_recent (GtkPlacesSidebar *sidebar,
|
|
|
|
|
gboolean show_recent)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
|
|
|
|
|
|
|
|
|
|
sidebar->show_recent_set = TRUE;
|
|
|
|
|
|
|
|
|
|
show_recent = !!show_recent;
|
|
|
|
|
if (sidebar->show_recent != show_recent)
|
|
|
|
|
{
|
|
|
|
|
sidebar->show_recent = show_recent;
|
|
|
|
|
update_places (sidebar);
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (sidebar), properties[PROP_SHOW_RECENT]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2015-06-06 21:13:22 +00:00
|
|
|
|
* gtk_places_sidebar_get_show_recent:
|
|
|
|
|
* @sidebar: a places sidebar
|
|
|
|
|
*
|
|
|
|
|
* Returns the value previously set with gtk_places_sidebar_set_show_recent()
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the sidebar will display a builtin shortcut for recent files
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_places_sidebar_get_show_recent (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar), FALSE);
|
|
|
|
|
|
|
|
|
|
return sidebar->show_recent;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 19:37:45 +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
|
|
|
|
|
*
|
2013-11-14 20:02:00 +00:00
|
|
|
|
* Sets whether the @sidebar should show an item for the Desktop folder.
|
|
|
|
|
* The default value for this option is determined by the desktop
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* environment and the user’s configuration, but this function can be
|
2013-11-14 20:02:00 +00:00
|
|
|
|
* used to override it on a per-application basis.
|
2011-10-04 14:47:41 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
2013-11-09 22:28:02 +00:00
|
|
|
|
gtk_places_sidebar_set_show_desktop (GtkPlacesSidebar *sidebar,
|
|
|
|
|
gboolean show_desktop)
|
2011-10-04 14:47:41 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
|
2011-10-04 14:47:41 +00:00
|
|
|
|
|
2013-11-14 20:02:00 +00:00
|
|
|
|
/* Don't bother disconnecting from the GtkSettings -- it will just
|
|
|
|
|
* complicate things. Besides, it's highly unlikely that this will
|
|
|
|
|
* change while we're running, but we can ignore it if it does.
|
|
|
|
|
*/
|
|
|
|
|
sidebar->show_desktop_set = TRUE;
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
show_desktop = !!show_desktop;
|
|
|
|
|
if (sidebar->show_desktop != show_desktop)
|
|
|
|
|
{
|
|
|
|
|
sidebar->show_desktop = show_desktop;
|
|
|
|
|
update_places (sidebar);
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (sidebar), properties[PROP_SHOW_DESKTOP]);
|
|
|
|
|
}
|
2013-01-21 23:21:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2013-01-21 23:21:00 +00:00
|
|
|
|
* gtk_places_sidebar_get_show_desktop:
|
|
|
|
|
* @sidebar: a places sidebar
|
|
|
|
|
*
|
|
|
|
|
* Returns the value previously set with gtk_places_sidebar_set_show_desktop()
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: %TRUE if the sidebar will display a builtin shortcut to the desktop folder.
|
2013-01-21 23:21:00 +00:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_places_sidebar_get_show_desktop (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar), FALSE);
|
2013-01-21 23:21:00 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
return sidebar->show_desktop;
|
2011-10-04 14:47:41 +00:00
|
|
|
|
}
|
2012-09-11 19:33:47 +00:00
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2014-04-07 22:43:28 +00:00
|
|
|
|
* gtk_places_sidebar_set_show_enter_location:
|
|
|
|
|
* @sidebar: a places sidebar
|
2015-07-25 16:11:05 +00:00
|
|
|
|
* @show_enter_location: whether to show an item to enter a location
|
|
|
|
|
*
|
|
|
|
|
* Sets whether the @sidebar should show an item for entering a location;
|
|
|
|
|
* this is off by default. An application may want to turn this on if manually
|
|
|
|
|
* entering URLs is an expected user action.
|
2014-04-07 22:43:28 +00:00
|
|
|
|
*
|
2015-07-25 16:11:05 +00:00
|
|
|
|
* If you enable this, you should connect to the
|
|
|
|
|
* #GtkPlacesSidebar::show-enter-location signal.
|
2014-04-07 22:43:28 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_places_sidebar_set_show_enter_location (GtkPlacesSidebar *sidebar,
|
2015-06-23 20:06:30 +00:00
|
|
|
|
gboolean show_enter_location)
|
2014-04-07 22:43:28 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
|
|
|
|
|
|
|
|
|
|
show_enter_location = !!show_enter_location;
|
|
|
|
|
if (sidebar->show_enter_location != show_enter_location)
|
|
|
|
|
{
|
|
|
|
|
sidebar->show_enter_location = show_enter_location;
|
|
|
|
|
update_places (sidebar);
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (sidebar), properties[PROP_SHOW_ENTER_LOCATION]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2014-04-07 22:43:28 +00:00
|
|
|
|
* gtk_places_sidebar_get_show_enter_location:
|
|
|
|
|
* @sidebar: a places sidebar
|
|
|
|
|
*
|
|
|
|
|
* Returns the value previously set with gtk_places_sidebar_set_show_enter_location()
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the sidebar will display an “Enter Location” item.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_places_sidebar_get_show_enter_location (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar), FALSE);
|
|
|
|
|
|
|
|
|
|
return sidebar->show_enter_location;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2015-07-14 17:47:42 +00:00
|
|
|
|
* gtk_places_sidebar_set_show_other_locations:
|
|
|
|
|
* @sidebar: a places sidebar
|
|
|
|
|
* @show_other_locations: whether to show an item for the Other Locations view
|
|
|
|
|
*
|
2015-07-25 16:11:05 +00:00
|
|
|
|
* Sets whether the @sidebar should show an item for the application to show
|
|
|
|
|
* an Other Locations view; this is off by default. When set to %TRUE, persistent
|
|
|
|
|
* devices such as hard drives are hidden, otherwise they are shown in the sidebar.
|
|
|
|
|
* An application may want to turn this on if it implements a way for the user to
|
|
|
|
|
* see and interact with drives and network servers directly.
|
|
|
|
|
*
|
|
|
|
|
* If you enable this, you should connect to the
|
2016-10-23 16:46:24 +00:00
|
|
|
|
* #GtkPlacesSidebar::show-other-locations-with-flags signal.
|
2015-07-14 17:47:42 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_places_sidebar_set_show_other_locations (GtkPlacesSidebar *sidebar,
|
|
|
|
|
gboolean show_other_locations)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
|
|
|
|
|
|
|
|
|
|
show_other_locations = !!show_other_locations;
|
|
|
|
|
if (sidebar->show_other_locations != show_other_locations)
|
|
|
|
|
{
|
|
|
|
|
sidebar->show_other_locations = show_other_locations;
|
|
|
|
|
update_places (sidebar);
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (sidebar), properties[PROP_SHOW_OTHER_LOCATIONS]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2015-07-14 17:47:42 +00:00
|
|
|
|
* gtk_places_sidebar_get_show_other_locations:
|
|
|
|
|
* @sidebar: a places sidebar
|
|
|
|
|
*
|
|
|
|
|
* Returns the value previously set with gtk_places_sidebar_set_show_other_locations()
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the sidebar will display an “Other Locations” item.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_places_sidebar_get_show_other_locations (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar), FALSE);
|
|
|
|
|
|
|
|
|
|
return sidebar->show_other_locations;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2015-07-03 16:49:00 +00:00
|
|
|
|
* gtk_places_sidebar_set_show_trash:
|
|
|
|
|
* @sidebar: a places sidebar
|
|
|
|
|
* @show_trash: whether to show an item for the Trash location
|
|
|
|
|
*
|
|
|
|
|
* Sets whether the @sidebar should show an item for the Trash location.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_places_sidebar_set_show_trash (GtkPlacesSidebar *sidebar,
|
|
|
|
|
gboolean show_trash)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
|
|
|
|
|
|
|
|
|
|
show_trash = !!show_trash;
|
|
|
|
|
if (sidebar->show_trash != show_trash)
|
|
|
|
|
{
|
|
|
|
|
sidebar->show_trash = show_trash;
|
|
|
|
|
update_places (sidebar);
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (sidebar), properties[PROP_SHOW_TRASH]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2015-07-03 16:49:00 +00:00
|
|
|
|
* gtk_places_sidebar_get_show_trash:
|
|
|
|
|
* @sidebar: a places sidebar
|
|
|
|
|
*
|
|
|
|
|
* Returns the value previously set with gtk_places_sidebar_set_show_trash()
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the sidebar will display a “Trash” item.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_places_sidebar_get_show_trash (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar), TRUE);
|
|
|
|
|
|
|
|
|
|
return sidebar->show_trash;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2013-11-09 23:28:12 +00:00
|
|
|
|
* gtk_places_sidebar_set_local_only:
|
|
|
|
|
* @sidebar: a places sidebar
|
|
|
|
|
* @local_only: whether to show only local files
|
|
|
|
|
*
|
|
|
|
|
* Sets whether the @sidebar should only show local files.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_places_sidebar_set_local_only (GtkPlacesSidebar *sidebar,
|
|
|
|
|
gboolean local_only)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
|
|
|
|
|
|
|
|
|
|
local_only = !!local_only;
|
|
|
|
|
if (sidebar->local_only != local_only)
|
|
|
|
|
{
|
|
|
|
|
sidebar->local_only = local_only;
|
|
|
|
|
update_places (sidebar);
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (sidebar), properties[PROP_LOCAL_ONLY]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2013-11-09 23:28:12 +00:00
|
|
|
|
* gtk_places_sidebar_get_local_only:
|
|
|
|
|
* @sidebar: a places sidebar
|
|
|
|
|
*
|
|
|
|
|
* Returns the value previously set with gtk_places_sidebar_set_local_only().
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: %TRUE if the sidebar will only show local files.
|
2013-11-09 23:28:12 +00:00
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_places_sidebar_get_local_only (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar), FALSE);
|
|
|
|
|
|
|
|
|
|
return sidebar->local_only;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-07 19:42:39 +00:00
|
|
|
|
static GSList *
|
2013-11-09 22:28:02 +00:00
|
|
|
|
find_shortcut_link (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GFile *location)
|
2012-12-07 19:42:39 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GSList *l;
|
2012-12-07 19:42:39 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
for (l = sidebar->shortcuts; l; l = l->next)
|
|
|
|
|
{
|
|
|
|
|
GFile *shortcut;
|
2012-12-07 19:42:39 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
shortcut = G_FILE (l->data);
|
|
|
|
|
if (g_file_equal (shortcut, location))
|
|
|
|
|
return l;
|
|
|
|
|
}
|
2012-12-07 19:42:39 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
return NULL;
|
2012-12-07 19:42:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2013-01-11 02:07:27 +00:00
|
|
|
|
* gtk_places_sidebar_add_shortcut:
|
|
|
|
|
* @sidebar: a places sidebar
|
|
|
|
|
* @location: location to add as an application-specific shortcut
|
|
|
|
|
*
|
|
|
|
|
* Applications may want to present some folders in the places sidebar if
|
|
|
|
|
* they could be immediately useful to users. For example, a drawing
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* program could add a “/usr/share/clipart” location when the sidebar is
|
|
|
|
|
* being used in an “Insert Clipart” dialog box.
|
2013-01-11 02:07:27 +00:00
|
|
|
|
*
|
|
|
|
|
* This function adds the specified @location to a special place for immutable
|
|
|
|
|
* shortcuts. The shortcuts are application-specific; they are not shared
|
|
|
|
|
* across applications, and they are not persistent. If this function
|
|
|
|
|
* is called multiple times with different locations, then they are added
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* to the sidebar’s list in the same order as the function is called.
|
2013-01-11 02:07:27 +00:00
|
|
|
|
*/
|
2012-12-11 21:29:11 +00:00
|
|
|
|
void
|
2013-11-09 22:28:02 +00:00
|
|
|
|
gtk_places_sidebar_add_shortcut (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GFile *location)
|
2012-12-07 19:42:39 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
|
|
|
|
|
g_return_if_fail (G_IS_FILE (location));
|
2012-12-07 19:42:39 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_object_ref (location);
|
|
|
|
|
sidebar->shortcuts = g_slist_append (sidebar->shortcuts, location);
|
2012-12-07 19:42:39 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
update_places (sidebar);
|
2012-12-07 19:42:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2013-01-11 02:07:27 +00:00
|
|
|
|
* gtk_places_sidebar_remove_shortcut:
|
|
|
|
|
* @sidebar: a places sidebar
|
|
|
|
|
* @location: location to remove
|
|
|
|
|
*
|
|
|
|
|
* Removes an application-specific shortcut that has been previously been
|
|
|
|
|
* inserted with gtk_places_sidebar_add_shortcut(). If the @location is not a
|
|
|
|
|
* shortcut in the sidebar, then nothing is done.
|
|
|
|
|
*/
|
2012-12-11 21:29:11 +00:00
|
|
|
|
void
|
2013-11-09 22:28:02 +00:00
|
|
|
|
gtk_places_sidebar_remove_shortcut (GtkPlacesSidebar *sidebar,
|
|
|
|
|
GFile *location)
|
2012-12-07 19:42:39 +00:00
|
|
|
|
{
|
2013-11-09 22:28:02 +00:00
|
|
|
|
GSList *link;
|
|
|
|
|
GFile *shortcut;
|
2012-12-07 19:42:39 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
|
|
|
|
|
g_return_if_fail (G_IS_FILE (location));
|
2012-12-07 19:42:39 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
link = find_shortcut_link (sidebar, location);
|
|
|
|
|
if (!link)
|
2015-06-23 20:06:30 +00:00
|
|
|
|
return;
|
2012-12-07 19:42:39 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
shortcut = G_FILE (link->data);
|
|
|
|
|
g_object_unref (shortcut);
|
2012-12-07 19:42:39 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
sidebar->shortcuts = g_slist_delete_link (sidebar->shortcuts, link);
|
|
|
|
|
update_places (sidebar);
|
2012-12-07 19:42:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2013-01-11 02:07:27 +00:00
|
|
|
|
* gtk_places_sidebar_list_shortcuts:
|
|
|
|
|
* @sidebar: a places sidebar
|
|
|
|
|
*
|
2013-09-17 05:28:39 +00:00
|
|
|
|
* Gets the list of shortcuts.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: (element-type GFile) (transfer full):
|
2013-09-17 05:28:39 +00:00
|
|
|
|
* A #GSList of #GFile of the locations that have been added as
|
|
|
|
|
* application-specific shortcuts with gtk_places_sidebar_add_shortcut().
|
2015-06-23 20:06:30 +00:00
|
|
|
|
* To free this list, you can use
|
2014-01-27 19:55:18 +00:00
|
|
|
|
* |[<!-- language="C" -->
|
2013-01-11 02:07:27 +00:00
|
|
|
|
* g_slist_free_full (list, (GDestroyNotify) g_object_unref);
|
|
|
|
|
* ]|
|
|
|
|
|
*/
|
2012-12-07 19:42:39 +00:00
|
|
|
|
GSList *
|
|
|
|
|
gtk_places_sidebar_list_shortcuts (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
2014-12-08 14:15:07 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar), NULL);
|
2012-12-07 19:42:39 +00:00
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
return g_slist_copy_deep (sidebar->shortcuts, (GCopyFunc) g_object_ref, NULL);
|
2012-12-07 19:42:39 +00:00
|
|
|
|
}
|
2012-12-10 22:00:42 +00:00
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2013-01-11 02:07:27 +00:00
|
|
|
|
* gtk_places_sidebar_get_nth_bookmark:
|
|
|
|
|
* @sidebar: a places sidebar
|
|
|
|
|
* @n: index of the bookmark to query
|
|
|
|
|
*
|
|
|
|
|
* This function queries the bookmarks added by the user to the places sidebar,
|
|
|
|
|
* and returns one of them. This function is used by #GtkFileChooser to implement
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* the “Alt-1”, “Alt-2”, etc. shortcuts, which activate the cooresponding bookmark.
|
2013-01-11 02:07:27 +00:00
|
|
|
|
*
|
2015-12-28 20:14:08 +00:00
|
|
|
|
* Returns: (nullable) (transfer full): The bookmark specified by the index @n, or
|
|
|
|
|
* %NULL if no such index exist. Note that the indices start at 0, even though
|
|
|
|
|
* the file chooser starts them with the keyboard shortcut "Alt-1".
|
2013-01-11 02:07:27 +00:00
|
|
|
|
*/
|
2012-12-10 22:00:42 +00:00
|
|
|
|
GFile *
|
2013-11-09 22:28:02 +00:00
|
|
|
|
gtk_places_sidebar_get_nth_bookmark (GtkPlacesSidebar *sidebar,
|
|
|
|
|
gint n)
|
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GList *rows;
|
|
|
|
|
GList *l;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
int k;
|
|
|
|
|
GFile *file;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar), NULL);
|
|
|
|
|
|
|
|
|
|
file = NULL;
|
2015-05-06 21:07:17 +00:00
|
|
|
|
rows = gtk_container_get_children (GTK_CONTAINER (sidebar->list_box));
|
|
|
|
|
l = rows;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
k = 0;
|
|
|
|
|
while (l != NULL)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
GtkPlacesSidebarPlaceType place_type;
|
|
|
|
|
gchar *uri;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_object_get (l->data,
|
2015-05-06 21:07:17 +00:00
|
|
|
|
"place-type", &place_type,
|
|
|
|
|
"uri", &uri,
|
|
|
|
|
NULL);
|
|
|
|
|
if (place_type == PLACES_BOOKMARK)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
if (k == n)
|
2013-11-09 22:28:02 +00:00
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
file = g_file_new_for_uri (uri);
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_free (uri);
|
2015-05-06 21:07:17 +00:00
|
|
|
|
break;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
2015-05-06 21:07:17 +00:00
|
|
|
|
k++;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
2015-06-23 20:06:30 +00:00
|
|
|
|
g_free (uri);
|
2015-05-06 21:07:17 +00:00
|
|
|
|
l = l->next;
|
2013-11-09 22:28:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-06 21:07:17 +00:00
|
|
|
|
g_list_free (rows);
|
|
|
|
|
|
2013-11-09 22:28:02 +00:00
|
|
|
|
return file;
|
2012-12-10 22:00:42 +00:00
|
|
|
|
}
|
2015-04-11 15:35:23 +00:00
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2015-04-11 15:35:23 +00:00
|
|
|
|
* gtk_places_sidebar_set_drop_targets_visible:
|
|
|
|
|
* @sidebar: a places sidebar.
|
|
|
|
|
* @visible: whether to show the valid targets or not.
|
2018-05-15 22:59:01 +00:00
|
|
|
|
* @drop: #GdkDrop used to ask the source about the action that wants to
|
2015-07-21 19:05:06 +00:00
|
|
|
|
* perform, so hints are more accurate.
|
|
|
|
|
*
|
|
|
|
|
* Make the GtkPlacesSidebar show drop targets, so it can show the available
|
|
|
|
|
* drop targets and a "new bookmark" row. This improves the Drag-and-Drop
|
|
|
|
|
* experience of the user and allows applications to show all available
|
|
|
|
|
* drop targets at once.
|
2015-04-11 15:35:23 +00:00
|
|
|
|
*
|
2015-07-21 19:05:06 +00:00
|
|
|
|
* This needs to be called when the application is aware of an ongoing drag
|
|
|
|
|
* that might target the sidebar. The drop-targets-visible state will be unset
|
|
|
|
|
* automatically if the drag finishes in the GtkPlacesSidebar. You only need
|
|
|
|
|
* to unset the state when the drag ends on some other widget on your application.
|
2015-04-11 15:35:23 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_places_sidebar_set_drop_targets_visible (GtkPlacesSidebar *sidebar,
|
|
|
|
|
gboolean visible,
|
2018-07-17 06:31:54 +00:00
|
|
|
|
GdkDrag *drag)
|
2015-04-11 15:35:23 +00:00
|
|
|
|
{
|
2018-07-17 06:31:54 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
|
|
|
|
|
g_return_if_fail (GDK_IS_DRAG (drag));
|
|
|
|
|
|
2015-04-11 15:35:23 +00:00
|
|
|
|
if (visible)
|
|
|
|
|
{
|
|
|
|
|
sidebar->drop_state = DROP_STATE_NEW_BOOKMARK_ARMED_PERMANENT;
|
2018-07-17 06:31:54 +00:00
|
|
|
|
start_drop_feedback (sidebar, NULL, drag);
|
2015-04-11 15:35:23 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (sidebar->drop_state == DROP_STATE_NEW_BOOKMARK_ARMED_PERMANENT ||
|
|
|
|
|
sidebar->drop_state == DROP_STATE_NEW_BOOKMARK_ARMED)
|
|
|
|
|
{
|
|
|
|
|
if (!sidebar->dragging_over)
|
|
|
|
|
{
|
2015-05-06 21:07:17 +00:00
|
|
|
|
sidebar->drop_state = DROP_STATE_NORMAL;
|
|
|
|
|
stop_drop_feedback (sidebar);
|
2015-04-11 15:35:23 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* In case this is called while we are dragging we need to mark the
|
|
|
|
|
* drop state as no permanent so the leave timeout can do its job.
|
|
|
|
|
* This will only happen in applications that call this in a wrong
|
|
|
|
|
* time */
|
|
|
|
|
sidebar->drop_state = DROP_STATE_NEW_BOOKMARK_ARMED;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-20 15:29:42 +00:00
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2017-07-20 15:29:42 +00:00
|
|
|
|
* gtk_places_sidebar_set_show_starred_location:
|
|
|
|
|
* @sidebar: a places sidebar
|
|
|
|
|
* @show_starred_location: whether to show an item for Starred files
|
|
|
|
|
*
|
|
|
|
|
* If you enable this, you should connect to the
|
|
|
|
|
* #GtkPlacesSidebar::show-starred-location signal.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_places_sidebar_set_show_starred_location (GtkPlacesSidebar *sidebar,
|
|
|
|
|
gboolean show_starred_location)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
|
|
|
|
|
|
|
|
|
|
show_starred_location = !!show_starred_location;
|
|
|
|
|
if (sidebar->show_starred_location != show_starred_location)
|
|
|
|
|
{
|
|
|
|
|
sidebar->show_starred_location = show_starred_location;
|
|
|
|
|
update_places (sidebar);
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (sidebar), properties[PROP_SHOW_STARRED_LOCATION]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 19:37:45 +00:00
|
|
|
|
/*
|
2017-07-20 15:29:42 +00:00
|
|
|
|
* gtk_places_sidebar_get_show_starred_location:
|
|
|
|
|
* @sidebar: a places sidebar
|
|
|
|
|
*
|
|
|
|
|
* Returns the value previously set with gtk_places_sidebar_set_show_starred_location()
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the sidebar will display a Starred item.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
gtk_places_sidebar_get_show_starred_location (GtkPlacesSidebar *sidebar)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar), FALSE);
|
|
|
|
|
|
|
|
|
|
return sidebar->show_starred_location;
|
|
|
|
|
}
|