File indexing completed on 2024-05-12 05:09:24
0001 /*************************************************************************** 0002 Copyright (C) 2005-2009 Robby Stephenson <robby@periapsis.org> 0003 ***************************************************************************/ 0004 0005 /*************************************************************************** 0006 * * 0007 * This program is free software; you can redistribute it and/or * 0008 * modify it under the terms of the GNU General Public License as * 0009 * published by the Free Software Foundation; either version 2 of * 0010 * the License or (at your option) version 3 or any later version * 0011 * accepted by the membership of KDE e.V. (or its successor approved * 0012 * by the membership of KDE e.V.), which shall act as a proxy * 0013 * defined in Section 14 of version 3 of the license. * 0014 * * 0015 * This program is distributed in the hope that it will be useful, * 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0018 * GNU General Public License for more details. * 0019 * * 0020 * You should have received a copy of the GNU General Public License * 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 0022 * * 0023 ***************************************************************************/ 0024 0025 #include "removeloans.h" 0026 #include "../document.h" 0027 #include "../entry.h" 0028 #include "../controller.h" 0029 #include "../tellico_debug.h" 0030 0031 #include <KLocalizedString> 0032 0033 using Tellico::Command::RemoveLoans; 0034 0035 RemoveLoans::RemoveLoans(Tellico::Data::LoanList loans_, QUndoCommand* parent_) 0036 : QUndoCommand(parent_) 0037 , m_loans(loans_) 0038 { 0039 if(!m_loans.isEmpty()) { 0040 setText(m_loans.count() > 1 ? i18n("Check-in Entries") 0041 : i18nc("Check-in (Entry Title)", "Check-in %1", m_loans[0]->entry()->title())); 0042 } 0043 } 0044 0045 void RemoveLoans::redo() { 0046 if(m_loans.isEmpty()) { 0047 return; 0048 } 0049 0050 // not all of the loans might be in the calendar 0051 Data::LoanList calLoans; 0052 Data::EntryList modifiedEntries; 0053 // remove the loans from the borrowers 0054 foreach(Data::LoanPtr loan, m_loans) { 0055 if(loan->inCalendar()) { 0056 calLoans.append(loan); 0057 } 0058 loan->borrower()->removeLoan(loan); 0059 Data::Document::self()->checkInEntry(loan->entry()); 0060 modifiedEntries.append(loan->entry()); 0061 Controller::self()->modifiedBorrower(loan->borrower()); 0062 } 0063 if(!calLoans.isEmpty()) { 0064 myWarning() << "Add to calendar not implemented"; 0065 } 0066 } 0067 0068 void RemoveLoans::undo() { 0069 if(m_loans.isEmpty()) { 0070 return; 0071 } 0072 0073 // not all of the loans might be in the calendar 0074 Data::LoanList calLoans; 0075 Data::EntryList modifiedEntries; 0076 foreach(Data::LoanPtr loan, m_loans) { 0077 if(loan->inCalendar()) { 0078 calLoans.append(loan); 0079 } 0080 // if the removeed loan was the only one by the borrower 0081 // then instead of modifying the borrower, it has to be added back to the model 0082 const bool emptyBorrower = loan->borrower()->isEmpty(); 0083 loan->borrower()->addLoan(loan); 0084 Data::Document::self()->checkOutEntry(loan->entry()); 0085 modifiedEntries.append(loan->entry()); 0086 if(emptyBorrower) { 0087 Controller::self()->addedBorrower(loan->borrower()); 0088 } else { 0089 Controller::self()->modifiedBorrower(loan->borrower()); 0090 } 0091 } 0092 if(!modifiedEntries.isEmpty()) { 0093 Controller::self()->modifiedEntries(modifiedEntries); 0094 } 0095 if(!calLoans.isEmpty()) { 0096 myWarning() << "Add to calendar not implemented"; 0097 } 0098 }