diff options
author | Alexandru Pandelea <alexandru.pandelea@gmail.com> | 2017-07-20 16:29:42 +0100 |
---|---|---|
committer | Carlos Garnacho <carlosg@gnome.org> | 2017-11-05 21:02:04 +0100 |
commit | 2421e745b9adaf1b96ad01d9535a89e22775b110 (patch) | |
tree | 36fbf4f9468d46710a9e24918f6ebc7c18ac4718 /gtk/gtkplacessidebar.c | |
parent | 807cac2c79347a5eec2f6bb6fa44f2fc488ab96a (diff) | |
download | gtk+-2421e745b9adaf1b96ad01d9535a89e22775b110.tar.gz |
placessidebar: add starred location item
Add an item for showing all files marked as favorite. This item will
open all files that have the nao:predefined-tag-favorite tag
https://bugzilla.gnome.org/show_bug.cgi?id=785176
Diffstat (limited to 'gtk/gtkplacessidebar.c')
-rw-r--r-- | gtk/gtkplacessidebar.c | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/gtk/gtkplacessidebar.c b/gtk/gtkplacessidebar.c index 21c2ad3b90..016436b352 100644 --- a/gtk/gtkplacessidebar.c +++ b/gtk/gtkplacessidebar.c @@ -186,6 +186,7 @@ struct _GtkPlacesSidebar { guint show_enter_location : 1; guint show_other_locations : 1; guint show_trash : 1; + guint show_starred_location : 1; guint local_only : 1; guint populate_all : 1; }; @@ -218,6 +219,8 @@ struct _GtkPlacesSidebarClass { void (* show_other_locations_with_flags) (GtkPlacesSidebar *sidebar, GtkPlacesOpenFlags open_flags); + void (* show_starred_location) (GtkPlacesSidebar *sidebar); + void (* mount) (GtkPlacesSidebar *sidebar, GMountOperation *mount_operation); void (* unmount) (GtkPlacesSidebar *sidebar, @@ -233,6 +236,7 @@ enum { DRAG_ACTION_ASK, DRAG_PERFORM_DROP, SHOW_OTHER_LOCATIONS_WITH_FLAGS, + SHOW_STARRED_LOCATION, MOUNT, UNMOUNT, LAST_SIGNAL @@ -245,6 +249,7 @@ enum { PROP_SHOW_DESKTOP, PROP_SHOW_ENTER_LOCATION, PROP_SHOW_TRASH, + PROP_SHOW_STARRED_LOCATION, PROP_LOCAL_ONLY, PROP_SHOW_OTHER_LOCATIONS, PROP_POPULATE_ALL, @@ -353,6 +358,15 @@ emit_show_other_locations_with_flags (GtkPlacesSidebar *sidebar, } static void +emit_show_starred_location (GtkPlacesSidebar *sidebar, + GtkPlacesOpenFlags open_flags) +{ + g_signal_emit (sidebar, places_sidebar_signals[SHOW_STARRED_LOCATION], 0, + open_flags); +} + + +static void emit_mount_operation (GtkPlacesSidebar *sidebar, GMountOperation *mount_op) { @@ -1017,6 +1031,17 @@ update_places (GtkPlacesSidebar *sidebar) g_object_unref (start_icon); } + if (sidebar->show_starred_location) + { + start_icon = g_themed_icon_new_with_default_fallbacks ("starred-symbolic"); + add_place (sidebar, PLACES_STARRED_LOCATION, + SECTION_COMPUTER, + _("Starred"), start_icon, NULL, "favorites:///", + NULL, NULL, NULL, NULL, 0, + _("Favorite files")); + g_object_unref (start_icon); + } + /* home folder */ home_uri = get_home_directory_uri (); start_icon = g_themed_icon_new_with_default_fallbacks (ICON_NAME_HOME); @@ -1506,6 +1531,12 @@ check_valid_drop_target (GtkPlacesSidebar *sidebar, "uri", &uri, NULL); + if (place_type == PLACES_STARRED_LOCATION) + { + g_free (uri); + return FALSE; + } + if (place_type == PLACES_CONNECT_TO_SERVER) { g_free (uri); @@ -2453,6 +2484,10 @@ open_row (GtkSidebarRow *row, { emit_show_other_locations_with_flags (sidebar, open_flags); } + else if (place_type == PLACES_STARRED_LOCATION) + { + emit_show_starred_location (sidebar, open_flags); + } else if (uri != NULL) { open_uri (sidebar, uri, open_flags); @@ -4130,6 +4165,10 @@ gtk_places_sidebar_set_property (GObject *obj, gtk_places_sidebar_set_show_trash (sidebar, g_value_get_boolean (value)); break; + case PROP_SHOW_STARRED_LOCATION: + gtk_places_sidebar_set_show_starred_location (sidebar, g_value_get_boolean (value)); + break; + case PROP_LOCAL_ONLY: gtk_places_sidebar_set_local_only (sidebar, g_value_get_boolean (value)); break; @@ -4186,6 +4225,10 @@ gtk_places_sidebar_get_property (GObject *obj, g_value_set_boolean (value, gtk_places_sidebar_get_show_trash (sidebar)); break; + case PROP_SHOW_STARRED_LOCATION: + g_value_set_boolean (value, gtk_places_sidebar_get_show_starred_location (sidebar)); + break; + case PROP_LOCAL_ONLY: g_value_set_boolean (value, gtk_places_sidebar_get_local_only (sidebar)); break; @@ -4576,6 +4619,26 @@ gtk_places_sidebar_class_init (GtkPlacesSidebarClass *class) 1, G_TYPE_MOUNT_OPERATION); + /** + * GtkPlacesSidebar::show-starred-location: + * @sidebar: the object which received the signal. + * + * 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. + * + * Since: 3.22.26 + */ + 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); properties[PROP_LOCATION] = g_param_spec_object ("location", @@ -4626,6 +4689,13 @@ gtk_places_sidebar_class_init (GtkPlacesSidebarClass *class) P_("Whether the sidebar includes an item to show external locations"), FALSE, G_PARAM_READWRITE); + properties[PROP_SHOW_STARRED_LOCATION] = + g_param_spec_boolean ("show-starred-location", + P_("Show 'Starred Location'"), + P_("Whether the sidebar includes an item to show starred files"), + FALSE, + G_PARAM_READWRITE); + /** * GtkPlacesSidebar:populate-all: @@ -5332,3 +5402,46 @@ gtk_places_sidebar_set_drop_targets_visible (GtkPlacesSidebar *sidebar, } } } + +/** + * 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. + * + * Since: 3.22.26 + */ +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]); + } +} + +/** + * 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. + * + * Since: 3.22.26 + */ +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; +} |