summaryrefslogtreecommitdiff
path: root/src/library/ImportQueueBranch.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/ImportQueueBranch.vala
Imported Upstream version 0.18.1upstream/0.18.1
Diffstat (limited to 'src/library/ImportQueueBranch.vala')
-rw-r--r--src/library/ImportQueueBranch.vala74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/library/ImportQueueBranch.vala b/src/library/ImportQueueBranch.vala
new file mode 100644
index 0000000..32a3e0d
--- /dev/null
+++ b/src/library/ImportQueueBranch.vala
@@ -0,0 +1,74 @@
+/* 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.ImportQueueBranch : Sidebar.RootOnlyBranch {
+ private Library.ImportQueueSidebarEntry entry;
+
+ public ImportQueueBranch() {
+ // can't pass to base() an object that was allocated in declaration; see
+ // https://bugzilla.gnome.org/show_bug.cgi?id=646286
+ base (new Library.ImportQueueSidebarEntry());
+
+ entry = (Library.ImportQueueSidebarEntry) get_root();
+
+ // only attach signals to the page when it's created
+ entry.page_created.connect(on_page_created);
+ entry.destroying_page.connect(on_destroying_page);
+
+ // don't use entry.get_page() or get_queue_page() because (a) we don't want to
+ // create the page during initialization, and (b) we know there's no import activity
+ // at this moment
+ set_show_branch(false);
+ }
+
+ ~ImportQueueBranch() {
+ entry.page_created.disconnect(on_page_created);
+ entry.destroying_page.disconnect(on_destroying_page);
+ }
+
+ public ImportQueuePage get_queue_page() {
+ return (ImportQueuePage) entry.get_page();
+ }
+
+ private void on_page_created() {
+ get_queue_page().batch_added.connect(on_batch_added_or_removed);
+ get_queue_page().batch_removed.connect(on_batch_added_or_removed);
+ }
+
+ private void on_destroying_page() {
+ get_queue_page().batch_added.disconnect(on_batch_added_or_removed);
+ get_queue_page().batch_removed.disconnect(on_batch_added_or_removed);
+ }
+
+ private void on_batch_added_or_removed() {
+ set_show_branch(get_queue_page().get_batch_count() > 0);
+ }
+
+ public void enqueue_and_schedule(BatchImport batch_import, bool allow_user_cancel) {
+ // want to display the branch before passing to the page because this might result in the
+ // page being created, and want it all hooked up in the tree prior to creating the page
+ set_show_branch(true);
+ get_queue_page().enqueue_and_schedule(batch_import, allow_user_cancel);
+ }
+}
+
+public class Library.ImportQueueSidebarEntry : Sidebar.SimplePageEntry {
+ public ImportQueueSidebarEntry() {
+ }
+
+ public override string get_sidebar_name() {
+ return ImportQueuePage.NAME;
+ }
+
+ public override Icon? get_sidebar_icon() {
+ return new ThemedIcon(Resources.ICON_IMPORTING);
+ }
+
+ protected override Page create_page() {
+ return new ImportQueuePage();
+ }
+}
+