1 /***************************************************************************
2 Copyright (C) 2005-2011 Robby Stephenson <robby@periapsis.org>
3 ***************************************************************************/
4
5 /***************************************************************************
6 * *
7 * This program is free software; you can redistribute it and/or *
8 * modify it under the terms of the GNU General Public License as *
9 * published by the Free Software Foundation; either version 2 of *
10 * the License or (at your option) version 3 or any later version *
11 * accepted by the membership of KDE e.V. (or its successor approved *
12 * by the membership of KDE e.V.), which shall act as a proxy *
13 * defined in Section 14 of version 3 of the license. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
22 * *
23 ***************************************************************************/
24
25 #include "removeentries.h"
26 #include "removeloans.h"
27 #include "../collection.h"
28 #include "../controller.h"
29 #include "../tellico_debug.h"
30
31 #include <KLocalizedString>
32
33 using Tellico::Command::RemoveEntries;
34
RemoveEntries(Tellico::Data::CollPtr coll_,const Tellico::Data::EntryList & entries_)35 RemoveEntries::RemoveEntries(Tellico::Data::CollPtr coll_, const Tellico::Data::EntryList& entries_)
36 : QUndoCommand()
37 , m_coll(coll_)
38 , m_entries(entries_)
39 {
40 if(!m_entries.isEmpty()) {
41 setText(m_entries.count() > 1 ? i18n("Delete Entries")
42 : i18nc("Delete (Entry Title)", "Delete %1", m_entries[0]->title()));
43 }
44
45 // also need to allow for removing entries that might be loaned out
46 // nothing for it but to do full-blown iterative search
47 Data::LoanList loans;
48 foreach(Data::BorrowerPtr borrower, m_coll->borrowers()) {
49 foreach(Data::EntryPtr entry, m_entries) {
50 if(borrower->hasEntry(entry)) {
51 loans += borrower->loan(entry);
52 }
53 }
54 }
55 if(!loans.isEmpty()) {
56 new RemoveLoans(loans, this);
57 }
58 }
59
redo()60 void RemoveEntries::redo() {
61 if(!m_coll || m_entries.isEmpty()) {
62 return;
63 }
64
65 m_coll->removeEntries(m_entries);
66 Controller::self()->removedEntries(m_entries);
67
68 QUndoCommand::redo();
69 }
70
undo()71 void RemoveEntries::undo() {
72 if(!m_coll || m_entries.isEmpty()) {
73 return;
74 }
75
76 m_coll->addEntries(m_entries);
77 Controller::self()->addedEntries(m_entries);
78
79 QUndoCommand::undo();
80 }
81