diff --git a/lib/domain/libimagtodo/src/iter.rs b/lib/domain/libimagtodo/src/iter.rs new file mode 100644 index 00000000..c2871c5a --- /dev/null +++ b/lib/domain/libimagtodo/src/iter.rs @@ -0,0 +1,48 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015-2018 Matthias Beyer and contributors +// +// 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; version +// 2.1 of the License. +// +// 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. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + +use libimagstore::storeid::StoreIdIterator; +use libimagstore::storeid::StoreId; + +pub struct TaskIdIterator(StoreIdIterator); + +impl TaskIdIterator { + + pub fn new(inner: StoreIdIterator) -> Self { + TaskIdIterator(inner) + } + +} + +impl Iterator for TaskIdIterator { + type Item = StoreId; + + fn next(&mut self) -> Option { + loop { + match self.0.next() { + None => return None, + Some(n) => if n.is_in_collection(&["todo", "taskwarrior"]) { + return Some(n) + }, // else continue + } + } + } + +} + diff --git a/lib/domain/libimagtodo/src/lib.rs b/lib/domain/libimagtodo/src/lib.rs index 0654af64..09927b79 100644 --- a/lib/domain/libimagtodo/src/lib.rs +++ b/lib/domain/libimagtodo/src/lib.rs @@ -51,4 +51,5 @@ module_entry_path_mod!("todo"); pub mod error; pub mod task; pub mod taskstore; +pub mod iter; diff --git a/lib/domain/libimagtodo/src/taskstore.rs b/lib/domain/libimagtodo/src/taskstore.rs index f128f036..103532ca 100644 --- a/lib/domain/libimagtodo/src/taskstore.rs +++ b/lib/domain/libimagtodo/src/taskstore.rs @@ -28,13 +28,14 @@ use task_hookrs::task::Task as TTask; use task_hookrs::import::{import_task, import_tasks}; use libimagstore::store::{FileLockEntry, Store}; -use libimagstore::storeid::{IntoStoreId, StoreIdIterator}; +use libimagstore::storeid::IntoStoreId; use module_path::ModuleEntryPath; use error::TodoErrorKind as TEK; use error::TodoError as TE; use error::Result; use error::ResultExt; +use iter::TaskIdIterator; /// Task struct containing a `FileLockEntry` pub trait TaskStore<'a> { @@ -46,7 +47,7 @@ pub trait TaskStore<'a> { fn retrieve_task_from_string(&'a self, s: String) -> Result>; fn delete_tasks_by_imports(&self, r: R) -> Result<()>; fn delete_task_by_uuid(&self, uuid: Uuid) -> Result<()>; - fn all_tasks(&self) -> Result; + fn all_tasks(&self) -> Result; fn new_from_twtask(&'a self, task: TTask) -> Result>; } @@ -167,8 +168,9 @@ impl<'a> TaskStore<'a> for Store { .chain_err(|| TEK::StoreError) } - fn all_tasks(&self) -> Result { - self.retrieve_for_module("todo/taskwarrior") + fn all_tasks(&self) -> Result { + self.entries() + .map(|i| TaskIdIterator::new(i.without_store())) .chain_err(|| TEK::StoreError) }