From 204da1b0bdc007a7f364874df016b9eef00e374b Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 22 Apr 2019 14:05:55 +0200 Subject: [PATCH] Remove libimagnotification Signed-off-by: Matthias Beyer --- Cargo.toml | 1 - imagrc.toml | 5 - lib/etc/libimagnotification/Cargo.toml | 28 --- lib/etc/libimagnotification/src/lib.rs | 45 ---- .../libimagnotification/src/notificator.rs | 117 ---------- .../src/result_notification.rs | 202 ------------------ scripts/release.sh | 1 - 7 files changed, 399 deletions(-) delete mode 100644 lib/etc/libimagnotification/Cargo.toml delete mode 100644 lib/etc/libimagnotification/src/lib.rs delete mode 100644 lib/etc/libimagnotification/src/notificator.rs delete mode 100644 lib/etc/libimagnotification/src/result_notification.rs diff --git a/Cargo.toml b/Cargo.toml index 20f7d34f..25835359 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,7 +53,6 @@ members = [ "lib/entry/libimagentryutil", "lib/entry/libimagentryview", "lib/etc/libimaginteraction", - "lib/etc/libimagnotification", "lib/etc/libimagtimeui", "lib/etc/libimagutil", ] diff --git a/imagrc.toml b/imagrc.toml index f1d3be91..d881a3cf 100644 --- a/imagrc.toml +++ b/imagrc.toml @@ -102,11 +102,6 @@ error = "[imag][{{red level}}]: {{red message}}" # not be wanted behaviour. # -[imag.logging.modules.libimagnotification] -destinations = [] -level = "debug" -enabled = true - [imag.logging.modules.libimagutil] destinations = [] level = "debug" diff --git a/lib/etc/libimagnotification/Cargo.toml b/lib/etc/libimagnotification/Cargo.toml deleted file mode 100644 index 3299c092..00000000 --- a/lib/etc/libimagnotification/Cargo.toml +++ /dev/null @@ -1,28 +0,0 @@ -[package] -name = "libimagnotification" -version = "0.10.0" -authors = ["Matthias Beyer "] - -description = "Library for the imag core distribution" - -keywords = ["imag", "PIM", "personal", "information", "management"] -readme = "../../../README.md" -license = "LGPL-2.1" - -documentation = "https://imag-pim.org/doc/" -repository = "https://github.com/matthiasbeyer/imag" -homepage = "http://imag-pim.org" - -[badges] -travis-ci = { repository = "matthiasbeyer/imag" } -is-it-maintained-issue-resolution = { repository = "matthiasbeyer/imag" } -is-it-maintained-open-issues = { repository = "matthiasbeyer/imag" } -maintenance = { status = "actively-developed" } - -[dependencies] -notify-rust = "3.4.2" -failure = "0.1" -failure_derive = "0.1" - -libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" } - diff --git a/lib/etc/libimagnotification/src/lib.rs b/lib/etc/libimagnotification/src/lib.rs deleted file mode 100644 index 7396df0f..00000000 --- a/lib/etc/libimagnotification/src/lib.rs +++ /dev/null @@ -1,45 +0,0 @@ -// -// 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 -// - -#![forbid(unsafe_code)] - -#![deny( - dead_code, - non_camel_case_types, - non_snake_case, - path_statements, - trivial_numeric_casts, - unstable_features, - unused_allocation, - unused_import_braces, - unused_imports, - unused_must_use, - unused_mut, - unused_qualifications, - while_true, -)] - -extern crate notify_rust; -extern crate failure; - -extern crate libimagerror; - -pub mod notificator; -pub mod result_notification; - diff --git a/lib/etc/libimagnotification/src/notificator.rs b/lib/etc/libimagnotification/src/notificator.rs deleted file mode 100644 index f275ae30..00000000 --- a/lib/etc/libimagnotification/src/notificator.rs +++ /dev/null @@ -1,117 +0,0 @@ -// -// 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; - -/// A Notificator provides a function that can be called to notify about a certain object. -/// -/// # TODO -/// -/// The user of the library does _not_ get access to the notification handle. -/// This is not optimal, but enough for today. -/// -pub trait Notificator { - fn notify(&self, item: &T) -> Result<()>; -} - -pub mod default { - use std::fmt::Debug; - use std::fmt::Display; - - use failure::Fallible as Result; - - use notify_rust::Notification as RustNotification; - use notify_rust::NotificationUrgency; - - use super::Notificator; - - #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug)] - pub enum Urgency { - Low, - Normal, - High - } - - impl Default for Urgency { - fn default() -> Urgency { - Urgency::Normal - } - } - - impl Into for Urgency { - - fn into(self) -> NotificationUrgency { - match self { - Urgency::Low => NotificationUrgency::Low, - Urgency::Normal => NotificationUrgency::Normal, - Urgency::High => NotificationUrgency::Critical, - } - } - - } - - #[derive(Debug, Default, Clone)] - pub struct Notification { - pub timeout: i32, - pub message: String, - pub summary: String, - pub urgency: Urgency, - } - - impl Notificator for Notification { - - /// A default implementation for all Types that implement Display - fn notify(&self, item: &T) -> Result<()> { - let mut n = RustNotification::new(); - n.appname("imag"); - n.summary(&self.summary); - n.urgency(self.urgency.clone().into()); - n.body(&format!("{}: {}", &self.message, item)); - let _ = n.finalize().show(); // Ignoring error here - Ok(()) - } - - } - - #[derive(Debug, Default, Clone)] - pub struct DebugNotification(Notification); - - impl From for DebugNotification { - fn from(n: Notification) -> DebugNotification { - DebugNotification(n) - } - } - - impl Notificator for DebugNotification { - - /// A default implementation for all Types that implement Display - fn notify(&self, item: &T) -> Result<()> { - let mut n = RustNotification::new(); - n.appname("imag"); - n.summary(&self.0.summary); - n.urgency(self.0.urgency.clone().into()); - n.body(&format!("{}: {:?}", &self.0.message, item)); - let _ = n.finalize().show(); // Ignoring error here - Ok(()) - } - - } - -} - diff --git a/lib/etc/libimagnotification/src/result_notification.rs b/lib/etc/libimagnotification/src/result_notification.rs deleted file mode 100644 index d5e9e29c..00000000 --- a/lib/etc/libimagnotification/src/result_notification.rs +++ /dev/null @@ -1,202 +0,0 @@ -// -// 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 std::error::Error; - -use notificator::Notificator; -use self::err::*; -use self::ok::*; - -pub mod err { - use std::ops::Deref; - use std::ops::DerefMut; - use std::error::Error; - - use notify_rust::Notification as RustNotification; - use notify_rust::NotificationUrgency; - - use notificator::default::Urgency; - use notificator::default::Notification; - use notificator::Notificator; - use failure::Fallible as Result; - use failure::err_msg; - - #[derive(Debug, Default, Clone)] - pub struct ErrorNotification(Notification, usize); - - impl ErrorNotification { - pub fn new(trace: usize, timeout: i32) -> ErrorNotification { - let notif = Notification { - timeout, - message: String::new(), // Not used in this special case - summary: "[Error]".to_owned(), - urgency: Urgency::High, - }; - - ErrorNotification(notif, trace) - } - } - - impl Notificator for ErrorNotification { - - /// A default implementation for all Types that implement Display - fn notify(&self, item: &T) -> Result<()>{ - fn trace_notify(urgency: NotificationUrgency, e: &Error, u: usize) -> Result<()> { - let mut n = RustNotification::new(); - n.appname("imag"); - n.summary("[Error]"); - n.urgency(urgency); - n.body(e.description()); - let _ = n.finalize() - .show() - .map_err(|_| err_msg("Notification error"))?; - - if u > 0 { - e.cause().map(|cause| trace_notify(urgency, cause, u - 1)); - } - - Ok(()) - } - - trace_notify(self.0.urgency.clone().into(), item, self.1) - } - - } - - impl Deref for ErrorNotification { - type Target = Notification; - - fn deref(&self) -> &Notification { - &self.0 - } - - } - - impl DerefMut for ErrorNotification { - - fn deref_mut(&mut self) -> &mut Notification { - &mut self.0 - } - - } - -} - -pub mod ok { - use std::ops::Deref; - use std::ops::DerefMut; - - use notify_rust::Notification as RustNotification; - - use notificator::default::Notification; - use notificator::Notificator; - use failure::Fallible as Result; - use failure::err_msg; - - #[derive(Debug, Default, Clone)] - pub struct OkNotification(Notification); - - impl From for OkNotification { - - fn from(n: Notification) -> OkNotification { - OkNotification(n) - } - - } - - impl Notificator for OkNotification { - - /// A default implementation for all Types that implement Display - fn notify(&self, _: &T) -> Result<()> { - let mut n = RustNotification::new(); - n.appname("imag"); - n.summary("[Ok]"); - n.urgency(self.0.urgency.clone().into()); - n.body(&"< >".to_owned()); - n.finalize() - .show() - .map(|_| ()) - .map_err(|_| err_msg("Notification error")) - } - - } - - impl Deref for OkNotification { - type Target = Notification; - - fn deref(&self) -> &Notification { - &self.0 - } - - } - - impl DerefMut for OkNotification { - - fn deref_mut(&mut self) -> &mut Notification { - &mut self.0 - } - - } - -} - -/// An extension trait for Result types -/// -/// Can be used to notify on error or on "Ok(_)" values. -/// -/// # Warning -/// -/// As the notification could go wrong, but inside a mapping function, the error cannot be given to -/// someone, we ignore errors in the Notificator::notify() call. -pub trait ResultNotification { - - /// Notify with a custom Notificator, only notify on Ok(T) - fn notify_with(self, n: &Notificator) -> Self; - - /// Notify with the OkNotification::default(), only notify on Ok(T) - fn notify(self) -> Self; - - /// Notify with a custom Notificator, only notify on Err(E) - fn notify_on_err_with(self, n: &Notificator) -> Self; - - /// Notify with the ErrorNotification::default(), only notify on Err(E) - fn notify_on_err(self) -> Self; - -} - -impl ResultNotification for Result { - - fn notify_with(self, n: &Notificator) -> Self { - self.map(|item| { let _ = n.notify(&item); item }) - } - - fn notify(self) -> Self { - self.notify_with(&OkNotification::default()) - } - - fn notify_on_err_with(self, n: &Notificator) -> Self { - self.map_err(|e| { let _ = n.notify(&e); e }) - } - - fn notify_on_err(self) -> Self { - self.notify_on_err_with(&ErrorNotification::default()) - } - -} - diff --git a/scripts/release.sh b/scripts/release.sh index 5c41d0e8..ec4da882 100644 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -13,7 +13,6 @@ CRATES=( ./lib/etc/libimagtimeui ./lib/core/libimagerror ./lib/core/libimagstore - ./lib/etc/libimagnotification ./lib/etc/libimaginteraction ./lib/core/libimagrt ./lib/entry/libimagentrylink