From 75ab0c1408ae400a40e80277c7fbdd82e0a8c474 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 8 Dec 2019 13:28:26 +0100 Subject: Add "is"-flag setting when creating bookmark Signed-off-by: Matthias Beyer --- lib/domain/libimagbookmark/Cargo.toml | 1 + lib/domain/libimagbookmark/src/bookmark.rs | 37 ++++++++++++++++++++++++++++++ lib/domain/libimagbookmark/src/lib.rs | 2 ++ lib/domain/libimagbookmark/src/store.rs | 8 ++++++- 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 lib/domain/libimagbookmark/src/bookmark.rs 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 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; +} + +impl Bookmark for Entry { + fn is_bookmark(&self) -> Result { + self.is::() + } +} + 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::()?; + entry.set_url(url).map(|_| (uuid, entry)) + }) } fn get_bookmark_by_uuid<'a>(&'a self, uuid: &Uuid) -> Result>> { -- cgit v1.2.3