diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-03-01 19:17:32 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-03-01 19:17:32 +0000 |
commit | e38d2351b83fa65c66ccde443777647ef5cb6cff (patch) | |
tree | 1897fc20e9f73a81c520a5b9f76f8ed042124883 /src/commands/collectioncommand.cpp | |
download | tellico-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/collectioncommand.cpp')
-rw-r--r-- | src/commands/collectioncommand.cpp | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/src/commands/collectioncommand.cpp b/src/commands/collectioncommand.cpp new file mode 100644 index 0000000..8955ea0 --- /dev/null +++ b/src/commands/collectioncommand.cpp @@ -0,0 +1,126 @@ +/*************************************************************************** + 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 "collectioncommand.h" +#include "../collection.h" +#include "../document.h" +#include "../controller.h" +#include "../tellico_debug.h" + +#include <klocale.h> + +using Tellico::Command::CollectionCommand; + +CollectionCommand::CollectionCommand(Mode mode_, Data::CollPtr origColl_, Data::CollPtr newColl_) + : KCommand() + , m_mode(mode_) + , m_origColl(origColl_) + , m_newColl(newColl_) + , m_cleanup(DoNothing) +{ +#ifndef NDEBUG +// just some sanity checking + if(m_origColl == 0 || m_newColl == 0) { + myDebug() << "CollectionCommand() - null collection pointer" << endl; + } +#endif +} + +CollectionCommand::~CollectionCommand() { + switch(m_cleanup) { + case ClearOriginal: + m_origColl->clear(); + break; + case ClearNew: + m_newColl->clear(); + break; + default: + break; + } +} + +void CollectionCommand::execute() { + if(!m_origColl || !m_newColl) { + return; + } + + switch(m_mode) { + case Append: + copyFields(); + Data::Document::self()->appendCollection(m_newColl); + Controller::self()->slotCollectionModified(m_origColl); + break; + + case Merge: + copyFields(); + m_mergePair = Data::Document::self()->mergeCollection(m_newColl); + Controller::self()->slotCollectionModified(m_origColl); + break; + + case Replace: + // replaceCollection() makes the URL = "Unknown" + m_origURL = Data::Document::self()->URL(); + Data::Document::self()->replaceCollection(m_newColl); + Controller::self()->slotCollectionDeleted(m_origColl); + Controller::self()->slotCollectionAdded(m_newColl); + m_cleanup = ClearOriginal; + break; + } +} + +void CollectionCommand::unexecute() { + if(!m_origColl || !m_newColl) { + return; + } + + switch(m_mode) { + case Append: + Data::Document::self()->unAppendCollection(m_newColl, m_origFields); + Controller::self()->slotCollectionModified(m_origColl); + break; + + case Merge: + Data::Document::self()->unMergeCollection(m_newColl, m_origFields, m_mergePair); + Controller::self()->slotCollectionModified(m_origColl); + break; + + case Replace: + Data::Document::self()->replaceCollection(m_origColl); + Data::Document::self()->setURL(m_origURL); + Controller::self()->slotCollectionDeleted(m_newColl); + Controller::self()->slotCollectionAdded(m_origColl); + m_cleanup = ClearNew; + break; + } +} + +QString CollectionCommand::name() const { + switch(m_mode) { + case Append: + return i18n("Append Collection"); + case Merge: + return i18n("Merge Collection"); + case Replace: + return i18n("Replace Collection"); + } + // hush warnings + return QString::null; +} + +void CollectionCommand::copyFields() { + m_origFields.clear(); + Data::FieldVec fieldsToCopy = m_origColl->fields(); + for(Data::FieldVec::Iterator field = fieldsToCopy.begin(); field != fieldsToCopy.end(); ++field) { + m_origFields.append(new Data::Field(*field)); + } +} |