summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-12-08 13:28:26 +0100
committerMatthias Beyer <mail@beyermatthias.de>2019-12-08 13:48:47 +0100
commit75ab0c1408ae400a40e80277c7fbdd82e0a8c474 (patch)
tree4da6d2eddf21d7cfbdf485120e36f104a99e237c
parentc58b0d323e0def63d545f4823d2ec7597fc133f7 (diff)
Add "is"-flag setting when creating bookmark
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--lib/domain/libimagbookmark/Cargo.toml1
-rw-r--r--lib/domain/libimagbookmark/src/bookmark.rs37
-rw-r--r--lib/domain/libimagbookmark/src/lib.rs2
-rw-r--r--lib/domain/libimagbookmark/src/store.rs8
4 files changed, 47 insertions, 1 deletions
diff --git a/lib/domain/libimagbookmark/Cargo.toml b/lib/domain/libimagbookmark/Cargo.toml
index 4f766009..eb441965 100644
--- a/lib/domain/libimagbookmark/Cargo.toml
+++ b/lib/domain/libimagbookmark/Cargo.toml
@@ -28,6 +28,7 @@ libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore"
libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" }
libimagentrylink = { version = "0.10.0", path = "../../../lib/entry/libimagentrylink" }
libimagentryurl = { version = "0.10.0", path = "../../../lib/entry/libimagentryurl" }
+libimagentryutil = { version = "0.10.0", path = "../../../lib/entry/libimagentryutil" }
[dependencies.uuid]
version = "0.7"
diff --git a/lib/domain/libimagbookmark/src/bookmark.rs b/lib/domain/libimagbookmark/src/bookmark.rs
new file mode 100644
index 00000000..d16df969
--- /dev/null
+++ b/lib/domain/libimagbookmark/src/bookmark.rs
@@ -0,0 +1,37 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 Matthias Beyer <mail@beyermatthias.de> 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 failure::Fallible as Result;
+
+use libimagentryutil::isa::Is;
+use libimagentryutil::isa::IsKindHeaderPathProvider;
+use libimagstore::store::Entry;
+
+provide_kindflag_path!(pub IsBookmark, "bookmark.is_bookmark");
+
+pub trait Bookmark {
+ fn is_bookmark(&self) -> Result<bool>;
+}
+
+impl Bookmark for Entry {
+ fn is_bookmark(&self) -> Result<bool> {
+ self.is::<IsBookmark>()
+ }
+}
+
diff --git a/lib/domain/libimagbookmark/src/lib.rs b/lib/domain/libimagbookmark/src/lib.rs
index 455a2a3f..1f4900b0 100644
--- a/lib/domain/libimagbookmark/src/lib.rs
+++ b/lib/domain/libimagbookmark/src/lib.rs
@@ -43,11 +43,13 @@ extern crate regex;
#[macro_use] extern crate failure;
#[macro_use] extern crate libimagstore;
+#[macro_use] extern crate libimagentryutil;
extern crate libimagerror;
extern crate libimagentrylink;
extern crate libimagentryurl;
module_entry_path_mod!("bookmark");
+pub mod bookmark;
pub mod store;
diff --git a/lib/domain/libimagbookmark/src/store.rs b/lib/domain/libimagbookmark/src/store.rs
index 32401228..d11fe331 100644
--- a/lib/domain/libimagbookmark/src/store.rs
+++ b/lib/domain/libimagbookmark/src/store.rs
@@ -26,7 +26,10 @@ use libimagstore::storeid::StoreId;
use libimagstore::store::FileLockEntry;
use libimagstore::iter::Entries;
use libimagentryurl::link::Link;
+use libimagentryutil::isa::Is;
+use crate::bookmark::IsBookmark;
+use crate::bookmark::Bookmark;
pub trait BookmarkStore {
@@ -45,7 +48,10 @@ impl BookmarkStore for Store {
let uuid = uuid::Uuid::new_v4();
id_for_uuid(&uuid)
.and_then(|id| self.create(id))
- .and_then(|mut entry| entry.set_url(url).map(|_| (uuid, entry)))
+ .and_then(|mut entry| {
+ entry.set_isflag::<IsBookmark>()?;
+ entry.set_url(url).map(|_| (uuid, entry))
+ })
}
fn get_bookmark_by_uuid<'a>(&'a self, uuid: &Uuid) -> Result<Option<FileLockEntry<'a>>> {