CmdPurge: Add initial implementation

This commit is contained in:
Tomas Babej 2016-03-19 21:18:41 +01:00 committed by Paul Beckingham
parent 96d6fb145f
commit 1caa9daec0
5 changed files with 126 additions and 0 deletions

View file

@ -40,6 +40,7 @@ set (commands_SRCS Command.cpp Command.h
CmdModify.cpp CmdModify.h CmdModify.cpp CmdModify.h
CmdPrepend.cpp CmdPrepend.h CmdPrepend.cpp CmdPrepend.h
CmdProjects.cpp CmdProjects.h CmdProjects.cpp CmdProjects.h
CmdPurge.cpp CmdPurge.h
CmdReports.cpp CmdReports.h CmdReports.cpp CmdReports.h
CmdShow.cpp CmdShow.h CmdShow.cpp CmdShow.h
CmdStart.cpp CmdStart.h CmdStart.cpp CmdStart.h

80
src/commands/CmdPurge.cpp Normal file
View file

@ -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 <cmake.h>
#include <CmdPurge.h>
#include <Context.h>
#include <Filter.h>
#include <i18n.h>
extern Context context;
////////////////////////////////////////////////////////////////////////////////
CmdPurge::CmdPurge ()
{
_keyword = "purge";
_usage = "task <filter> 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 <Task> 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;
}
////////////////////////////////////////////////////////////////////////////////

41
src/commands/CmdPurge.h Normal file
View file

@ -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 <string>
#include <Command.h>
class CmdPurge : public Command
{
public:
CmdPurge ();
int execute (std::string&);
};
#endif
////////////////////////////////////////////////////////////////////////////////

View file

@ -70,6 +70,7 @@
#include <CmdModify.h> #include <CmdModify.h>
#include <CmdPrepend.h> #include <CmdPrepend.h>
#include <CmdProjects.h> #include <CmdProjects.h>
#include <CmdPurge.h>
#include <CmdReports.h> #include <CmdReports.h>
#include <CmdShow.h> #include <CmdShow.h>
#include <CmdStart.h> #include <CmdStart.h>
@ -145,6 +146,7 @@ void Command::factory (std::map <std::string, Command*>& all)
c = new CmdModify (); all[c->keyword ()] = c; c = new CmdModify (); all[c->keyword ()] = c;
c = new CmdPrepend (); all[c->keyword ()] = c; c = new CmdPrepend (); all[c->keyword ()] = c;
c = new CmdProjects (); 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 CmdReports (); all[c->keyword ()] = c;
c = new CmdShow (); all[c->keyword ()] = c; c = new CmdShow (); all[c->keyword ()] = c;
c = new CmdShowRaw (); all[c->keyword ()] = c; c = new CmdShowRaw (); all[c->keyword ()] = c;

View file

@ -396,6 +396,8 @@
#define STRING_CMD_DUPLICATE_1 "Duplicated {1} task." #define STRING_CMD_DUPLICATE_1 "Duplicated {1} task."
#define STRING_CMD_DUPLICATE_N "Duplicated {1} tasks." #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_USAGE "Marks specified task as started"
#define STRING_CMD_START_NO "Task not started." #define STRING_CMD_START_NO "Task not started."
#define STRING_CMD_START_ALREADY "Task {1} '{2}' already started." #define STRING_CMD_START_ALREADY "Task {1} '{2}' already started."