summaryrefslogtreecommitdiff
path: root/src/library/TrashBranch.vala
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2014-07-23 09:06:59 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2014-07-23 09:06:59 +0200
commit4ea2cc3bd4a7d9b1c54a9d33e6a1cf82e7c8c21d (patch)
treed2e54377d14d604356c86862a326f64ae64dadd6 /src/library/TrashBranch.vala
Imported Upstream version 0.18.1upstream/0.18.1
Diffstat (limited to 'src/library/TrashBranch.vala')
-rw-r--r--src/library/TrashBranch.vala73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/library/TrashBranch.vala b/src/library/TrashBranch.vala
new file mode 100644
index 0000000..5ef8b3c
--- /dev/null
+++ b/src/library/TrashBranch.vala
@@ -0,0 +1,73 @@
+/* Copyright 2011-2014 Yorba Foundation
+ *
+ * This software is licensed under the GNU Lesser General Public License
+ * (version 2.1 or later). See the COPYING file in this distribution.
+ */
+
+public class Library.TrashBranch : Sidebar.RootOnlyBranch {
+ public TrashBranch() {
+ base (new Library.TrashSidebarEntry());
+ }
+}
+
+public class Library.TrashSidebarEntry : Sidebar.SimplePageEntry, Sidebar.InternalDropTargetEntry {
+ private static Icon? full_icon = null;
+ private static Icon? empty_icon = null;
+
+ public TrashSidebarEntry() {
+ foreach (MediaSourceCollection media_sources in MediaCollectionRegistry.get_instance().get_all())
+ media_sources.trashcan_contents_altered.connect(on_trashcan_contents_altered);
+ }
+
+ ~TrashSidebarEntry() {
+ foreach (MediaSourceCollection media_sources in MediaCollectionRegistry.get_instance().get_all())
+ media_sources.trashcan_contents_altered.disconnect(on_trashcan_contents_altered);
+ }
+
+ internal static void init() {
+ full_icon = new ThemedIcon(Resources.ICON_TRASH_FULL);
+ empty_icon = new ThemedIcon(Resources.ICON_TRASH_EMPTY);
+ }
+
+ internal static void terminate() {
+ full_icon = null;
+ empty_icon = null;
+ }
+
+ public override string get_sidebar_name() {
+ return TrashPage.NAME;
+ }
+
+ public override Icon? get_sidebar_icon() {
+ return get_current_icon();
+ }
+
+ private static Icon get_current_icon() {
+ foreach (MediaSourceCollection media_sources in MediaCollectionRegistry.get_instance().get_all()) {
+ if (media_sources.get_trashcan_count() > 0)
+ return full_icon;
+ }
+
+ return empty_icon;
+ }
+
+ public bool internal_drop_received(Gee.List<MediaSource> media) {
+ AppWindow.get_command_manager().execute(new TrashUntrashPhotosCommand(media, true));
+
+ return true;
+ }
+
+ public bool internal_drop_received_arbitrary(Gtk.SelectionData data) {
+ return false;
+ }
+
+ protected override Page create_page() {
+ return new TrashPage();
+ }
+
+ private void on_trashcan_contents_altered() {
+ sidebar_icon_changed(get_current_icon());
+ }
+}
+
+