diff --git a/src/commands/CMakeLists.txt b/src/commands/CMakeLists.txt index cd6f7a519..575e351e7 100644 --- a/src/commands/CMakeLists.txt +++ b/src/commands/CMakeLists.txt @@ -40,6 +40,7 @@ set (commands_SRCS Command.cpp Command.h CmdModify.cpp CmdModify.h CmdPrepend.cpp CmdPrepend.h CmdProjects.cpp CmdProjects.h + CmdPurge.cpp CmdPurge.h CmdReports.cpp CmdReports.h CmdShow.cpp CmdShow.h CmdStart.cpp CmdStart.h diff --git a/src/commands/CmdPurge.cpp b/src/commands/CmdPurge.cpp new file mode 100644 index 000000000..5ca665efe --- /dev/null +++ b/src/commands/CmdPurge.cpp @@ -0,0 +1,80 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2006 - 2016, Paul Beckingham, Federico Hernandez. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +extern Context context; + +//////////////////////////////////////////////////////////////////////////////// +CmdPurge::CmdPurge () +{ + _keyword = "purge"; + _usage = "task purge"; + _description = STRING_CMD_PURGE_USAGE; + _read_only = false; + _displays_id = false; + _needs_confirm = true; + _needs_gc = false; + _uses_context = true; + _accepts_filter = true; + _accepts_modifications = false; + _accepts_miscellaneous = false; + _category = Command::Category::operation; +} + +//////////////////////////////////////////////////////////////////////////////// +int CmdPurge::execute (std::string&) +{ + int rc = 0; + int count = 0; + + // Apply filter. + Filter filter; + std::vector filtered; + filter.subset (filtered); + if (filtered.size () == 0) + { + context.footnote (STRING_FEEDBACK_NO_TASKS_SP); + return 1; + } + + for (auto& task : filtered) + { + if (task.getStatus () == Task::deleted) + { + context.tdb2.purge (task); + count++; + } + } + + return rc; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdPurge.h b/src/commands/CmdPurge.h new file mode 100644 index 000000000..8e9c76446 --- /dev/null +++ b/src/commands/CmdPurge.h @@ -0,0 +1,41 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Copyright 2006 - 2016, Paul Beckingham, Federico Hernandez. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included +// in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. +// +// http://www.opensource.org/licenses/mit-license.php +// +//////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDED_CMDPURGE +#define INCLUDED_CMDPURGE + +#include +#include + +class CmdPurge : public Command +{ +public: + CmdPurge (); + int execute (std::string&); +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index 29025d994..4783afc68 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -70,6 +70,7 @@ #include #include #include +#include #include #include #include @@ -145,6 +146,7 @@ void Command::factory (std::map & all) c = new CmdModify (); all[c->keyword ()] = c; c = new CmdPrepend (); all[c->keyword ()] = c; c = new CmdProjects (); all[c->keyword ()] = c; + c = new CmdPurge (); all[c->keyword ()] = c; c = new CmdReports (); all[c->keyword ()] = c; c = new CmdShow (); all[c->keyword ()] = c; c = new CmdShowRaw (); all[c->keyword ()] = c; diff --git a/src/l10n/eng-USA.h b/src/l10n/eng-USA.h index b97777e13..cbc038b76 100644 --- a/src/l10n/eng-USA.h +++ b/src/l10n/eng-USA.h @@ -396,6 +396,8 @@ #define STRING_CMD_DUPLICATE_1 "Duplicated {1} task." #define STRING_CMD_DUPLICATE_N "Duplicated {1} tasks." +#define STRING_CMD_PURGE_USAGE "Removes the specified task from the data files. Causes permanent loss of data." + #define STRING_CMD_START_USAGE "Marks specified task as started" #define STRING_CMD_START_NO "Task not started." #define STRING_CMD_START_ALREADY "Task {1} '{2}' already started."