File indexing completed on 2024-04-28 05:08:14

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 #ifndef TELLICO_BORROWER_H
0026 #define TELLICO_BORROWER_H
0027 
0028 #include "datavectors.h"
0029 #include "entry.h"
0030 
0031 #include <QDate>
0032 #include <QString>
0033 #include <QExplicitlySharedDataPointer>
0034 
0035 namespace Tellico {
0036   namespace Data {
0037 
0038 class Loan : public QSharedData {
0039 
0040 public:
0041   Loan(Data::EntryPtr entry, QDate loanDate, QDate dueDate, const QString& note);
0042   Loan(const Loan& other);
0043 
0044   Data::BorrowerPtr borrower() const;
0045   void setBorrower(Data::BorrowerPtr b) { m_borrower = b; }
0046 
0047   const QString& uid() const { return m_uid; }
0048   void setUID(const QString& uid) { m_uid = uid; }
0049 
0050   Data::EntryPtr entry() const;
0051 
0052   const QDate& loanDate() const { return m_loanDate; }
0053 
0054   const QDate& dueDate() const { return m_dueDate; }
0055   void setDueDate(QDate date) { m_dueDate = date; }
0056 
0057   const QString& note() const { return m_note; }
0058   void setNote(const QString& text) { m_note = text; }
0059 
0060   bool inCalendar() const { return m_inCalendar; }
0061   void setInCalendar(bool inCalendar) { m_inCalendar = inCalendar; }
0062 
0063 private:
0064   Loan& operator=(const Loan&);
0065 
0066   QString m_uid;
0067   BorrowerPtr m_borrower;
0068   EntryPtr m_entry;
0069   QDate m_loanDate;
0070   QDate m_dueDate;
0071   QString m_note;
0072   bool m_inCalendar;
0073 };
0074 
0075 typedef QExplicitlySharedDataPointer<Loan> LoanPtr;
0076 typedef QList<LoanPtr> LoanList;
0077 
0078 /**
0079  * @author Robby Stephenson
0080  */
0081 class Borrower : public QSharedData {
0082 
0083 public:
0084   Borrower(const QString& name, const QString& uid);
0085   Borrower(const Borrower& other);
0086   Borrower& operator=(const Borrower& other);
0087 
0088   const QString& uid() const { return m_uid; }
0089   const QString& name() const { return m_name; }
0090   const LoanList& loans() const { return m_loans; }
0091   bool isEmpty() const { return m_loans.isEmpty(); }
0092   int count() const { return m_loans.count(); }
0093 
0094   Data::LoanPtr loan(Data::EntryPtr entry);
0095   void addLoan(Data::LoanPtr loan);
0096   bool removeLoan(Data::LoanPtr loan);
0097 
0098   bool hasEntry(Data::EntryPtr entry);
0099 
0100 private:
0101   QString m_name;
0102   QString m_uid; // uid used by KABC
0103   LoanList m_loans;
0104 };
0105 
0106   } // end namespace
0107 } // end namespace
0108 #endif