summaryrefslogtreecommitdiffstats
path: root/src/commands/filtercommand.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-01 19:17:32 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-01 19:17:32 +0000
commite38d2351b83fa65c66ccde443777647ef5cb6cff (patch)
tree1897fc20e9f73a81c520a5b9f76f8ed042124883 /src/commands/filtercommand.cpp
downloadtellico-e38d2351b83fa65c66ccde443777647ef5cb6cff.tar.gz
tellico-e38d2351b83fa65c66ccde443777647ef5cb6cff.zip
Added KDE3 version of Tellico
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/tellico@1097620 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/commands/filtercommand.cpp')
-rw-r--r--src/commands/filtercommand.cpp106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/commands/filtercommand.cpp b/src/commands/filtercommand.cpp
new file mode 100644
index 0000000..ba205e5
--- /dev/null
+++ b/src/commands/filtercommand.cpp
@@ -0,0 +1,106 @@
+/***************************************************************************
+ copyright : (C) 2005-2006 by Robby Stephenson
+ email : robby@periapsis.org
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of version 2 of the GNU General Public License as *
+ * published by the Free Software Foundation; *
+ * *
+ ***************************************************************************/
+
+#include "filtercommand.h"
+#include "../document.h"
+#include "../collection.h"
+#include "../controller.h"
+#include "../tellico_debug.h"
+
+#include <klocale.h>
+
+using Tellico::Command::FilterCommand;
+
+FilterCommand::FilterCommand(Mode mode_, FilterPtr activeFilter_, FilterPtr oldFilter_/*=0*/)
+ : KCommand()
+ , m_mode(mode_)
+ , m_activeFilter(activeFilter_)
+ , m_oldFilter(oldFilter_)
+{
+ if(!m_activeFilter) {
+ myDebug() << "FilterCommand() - null active filter pointer" << endl;
+ }
+#ifndef NDEBUG
+// just some sanity checking
+ if(m_mode == FilterAdd && m_oldFilter != 0) {
+ myDebug() << "FilterCommand() - adding field, but pointers are wrong" << endl;
+ } else if(m_mode == FilterModify && m_oldFilter == 0) {
+ myDebug() << "FilterCommand() - modifying field, but pointers are wrong" << endl;
+ } else if(m_mode == FilterRemove && m_oldFilter != 0) {
+ myDebug() << "FilterCommand() - removing field, but pointers are wrong" << endl;
+ }
+#endif
+}
+
+void FilterCommand::execute() {
+ if(!m_activeFilter) {
+ return;
+ }
+
+ switch(m_mode) {
+ case FilterAdd:
+ Data::Document::self()->collection()->addFilter(m_activeFilter);
+ Controller::self()->addedFilter(m_activeFilter);
+ break;
+
+ case FilterModify:
+ Data::Document::self()->collection()->removeFilter(m_oldFilter);
+ Controller::self()->removedFilter(m_oldFilter);
+ Data::Document::self()->collection()->addFilter(m_activeFilter);
+ Controller::self()->addedFilter(m_activeFilter);
+ break;
+
+ case FilterRemove:
+ Data::Document::self()->collection()->removeFilter(m_activeFilter);
+ Controller::self()->removedFilter(m_activeFilter);
+ break;
+ }
+}
+
+void FilterCommand::unexecute() {
+ if(!m_activeFilter) {
+ return;
+ }
+
+ switch(m_mode) {
+ case FilterAdd:
+ Data::Document::self()->collection()->removeFilter(m_activeFilter);
+ Controller::self()->removedFilter(m_activeFilter);
+ break;
+
+ case FilterModify:
+ Data::Document::self()->collection()->removeFilter(m_activeFilter);
+ Controller::self()->removedFilter(m_activeFilter);
+ Data::Document::self()->collection()->addFilter(m_oldFilter);
+ Controller::self()->addedFilter(m_oldFilter);
+ break;
+
+ case FilterRemove:
+ Data::Document::self()->collection()->addFilter(m_activeFilter);
+ Controller::self()->addedFilter(m_activeFilter);
+ break;
+ }
+}
+
+QString FilterCommand::name() const {
+ switch(m_mode) {
+ case FilterAdd:
+ return i18n("Add Filter");
+ case FilterModify:
+ return i18n("Modify Filter");
+ case FilterRemove:
+ return i18n("Delete Filter");
+ }
+ // hush warnings
+ return QString::null;
+}