From 8d1b10fb3eb480e4b556f5d1a0a94886b17da994 Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Wed, 27 Aug 2014 02:01:44 +0200 Subject: [PATCH] actions: add missing flag restriction for physical deletion --- doc/config | 2 ++ doc/ncmpcpp.1 | 3 +++ src/actions.cpp | 12 +++++++++++- src/browser.cpp | 2 ++ src/settings.cpp | 6 ++++++ src/settings.h | 1 + 6 files changed, 25 insertions(+), 1 deletion(-) diff --git a/doc/config b/doc/config index ab12006d..af3d9dae 100644 --- a/doc/config +++ b/doc/config @@ -347,6 +347,8 @@ # #generate_win32_compatible_filenames = "yes" # +#allow_for_physical_item_deletion = "no" +# ## ## Note: If you set this variable, ncmpcpp will try to ## get info from last.fm in language you set and if it diff --git a/doc/ncmpcpp.1 b/doc/ncmpcpp.1 index 838cdb83..d470da13 100644 --- a/doc/ncmpcpp.1 +++ b/doc/ncmpcpp.1 @@ -240,6 +240,9 @@ If enabled, lyrics will be saved in song's directory, otherwise in ~/.lyrics. No .B generate_win32_compatible_filenames = yes/no If set to yes, filenames generated by ncmpcpp (with tag editor, for lyrics, artists etc.) will not contain the following characters: /\?*:|"<> - otherwise only slash (/) will not be used. .TP +.B allow_for_physical_item_deletion = yes/no +If set to yes, it will be possible to physically delete files and directories from the disk in the browser. +.TP .B lastfm_preferred_language = ISO 639 alpha-2 language code If set, ncmpcpp will try to get info from last.fm in language you set and if it fails, it will fall back to english. Otherwise it will use english the first time. .TP diff --git a/src/actions.cpp b/src/actions.cpp index 9c58534c..e8690e93 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -643,9 +643,19 @@ void DeletePlaylistItems::run() bool DeleteBrowserItems::canBeRun() const { + auto check_if_deletion_allowed = []() { + if (Config.allow_for_physical_item_deletion) + return true; + else + { + Statusbar::msg("Flag 'allow_for_physical_item_deletion' needs to be enabled in configuration file"); + return false; + } + }; return myScreen == myBrowser && !myBrowser->main().empty() - && isMPDMusicDirSet(); + && isMPDMusicDirSet() + && check_if_deletion_allowed(); } void DeleteBrowserItems::run() diff --git a/src/browser.cpp b/src/browser.cpp index 778720c8..05e29d37 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -543,6 +543,8 @@ void Browser::ChangeBrowseMode() bool Browser::deleteItem(const MPD::Item &item, std::string &errmsg) { + if (!Config.allow_for_physical_item_deletion) + FatalError("Browser::deleteItem invoked with allow_for_physical_item_deletion = false"); if (isParentDirectory((item))) FatalError("Parent directory passed to Browser::deleteItem"); diff --git a/src/settings.cpp b/src/settings.cpp index d0dbeb0d..bf620839 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -217,6 +217,7 @@ void Configuration::SetDefaults() store_lyrics_in_song_dir = false; generate_win32_compatible_filenames = true; ask_for_locked_screen_width_part = true; + allow_for_physical_item_deletion = false; progressbar_boldness = true; set_window_title = true; mpd_port = 6600; @@ -824,6 +825,11 @@ void Configuration::Read() if (!v.empty()) ask_for_locked_screen_width_part = v == "yes"; } + else if (name == "allow_for_physical_item_deletion") + { + if (!v.empty()) + allow_for_physical_item_deletion = v == "yes"; + } else if (name == "progressbar_boldness") { if (!v.empty()) diff --git a/src/settings.h b/src/settings.h index e5bece98..ceaf6ed5 100644 --- a/src/settings.h +++ b/src/settings.h @@ -183,6 +183,7 @@ struct Configuration bool store_lyrics_in_song_dir; bool generate_win32_compatible_filenames; bool ask_for_locked_screen_width_part; + bool allow_for_physical_item_deletion; bool progressbar_boldness; int mpd_port;