File indexing completed on 2024-05-12 16:42:37

0001 /*
0002     SPDX-FileCopyrightText: 2000-2001 Michael Edwardes <mte@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2002-2017 Thomas Baumgart <tbaumgart@kde.org>
0004     SPDX-FileCopyrightText: 2003 Kevin Tambascio <ktambascio@users.sourceforge.net>
0005     SPDX-FileCopyrightText: 2004-2006 Ace Jones <acejones@users.sourceforge.net>
0006     SPDX-FileCopyrightText: 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #include "mymoneyinstitution.h"
0011 #include "mymoneyinstitution_p.h"
0012 
0013 // ----------------------------------------------------------------------------
0014 // QT Includes
0015 
0016 #include <QPixmap>
0017 #include <QPixmapCache>
0018 #include <QIcon>
0019 
0020 // ----------------------------------------------------------------------------
0021 // KDE Includes
0022 
0023 // ----------------------------------------------------------------------------
0024 // Project Includes
0025 
0026 #include "icons.h"
0027 #include <mymoneyexception.h>
0028 
0029 using namespace Icons;
0030 
0031 MyMoneyInstitution::MyMoneyInstitution() :
0032     MyMoneyObject(*new MyMoneyInstitutionPrivate),
0033     MyMoneyKeyValueContainer()
0034 {
0035 }
0036 
0037 MyMoneyInstitution::MyMoneyInstitution(const QString &id) :
0038     MyMoneyObject(*new MyMoneyInstitutionPrivate, id),
0039     MyMoneyKeyValueContainer()
0040 {
0041 }
0042 
0043 MyMoneyInstitution::MyMoneyInstitution(const QString& name,
0044                                        const QString& town,
0045                                        const QString& street,
0046                                        const QString& postcode,
0047                                        const QString& telephone,
0048                                        const QString& manager,
0049                                        const QString& sortcode) :
0050     MyMoneyObject(*new MyMoneyInstitutionPrivate),
0051     MyMoneyKeyValueContainer()
0052 {
0053     Q_D(MyMoneyInstitution);
0054     clearId();
0055     d->m_name = name;
0056     d->m_town = town;
0057     d->m_street = street;
0058     d->m_postcode = postcode;
0059     d->m_telephone = telephone;
0060     d->m_manager = manager;
0061     d->m_sortcode = sortcode;
0062 }
0063 
0064 MyMoneyInstitution::MyMoneyInstitution(const MyMoneyInstitution& other) :
0065     MyMoneyObject(*new MyMoneyInstitutionPrivate(*other.d_func()), other.id()),
0066     MyMoneyKeyValueContainer(other)
0067 {
0068 }
0069 
0070 MyMoneyInstitution::MyMoneyInstitution(const QString& id, const MyMoneyInstitution& other) :
0071     MyMoneyObject(*new MyMoneyInstitutionPrivate(*other.d_func()), id),
0072     MyMoneyKeyValueContainer(other)
0073 {
0074 }
0075 
0076 MyMoneyInstitution::~MyMoneyInstitution()
0077 {
0078 }
0079 
0080 QString MyMoneyInstitution::manager() const
0081 {
0082     Q_D(const MyMoneyInstitution);
0083     return d->m_manager;
0084 }
0085 
0086 void MyMoneyInstitution::setManager(const QString& manager)
0087 {
0088     Q_D(MyMoneyInstitution);
0089     d->m_manager = manager;
0090 }
0091 
0092 QString MyMoneyInstitution::name() const
0093 {
0094     Q_D(const MyMoneyInstitution);
0095     return d->m_name;
0096 }
0097 
0098 void MyMoneyInstitution::setName(const QString& name)
0099 {
0100     Q_D(MyMoneyInstitution);
0101     d->m_name = name;
0102 }
0103 
0104 QString MyMoneyInstitution::postcode() const
0105 {
0106     Q_D(const MyMoneyInstitution);
0107     return d->m_postcode;
0108 }
0109 
0110 void MyMoneyInstitution::setPostcode(const QString& code)
0111 {
0112     Q_D(MyMoneyInstitution);
0113     d->m_postcode = code;
0114 }
0115 
0116 QString MyMoneyInstitution::street() const
0117 {
0118     Q_D(const MyMoneyInstitution);
0119     return d->m_street;
0120 }
0121 
0122 void MyMoneyInstitution::setStreet(const QString& street)
0123 {
0124     Q_D(MyMoneyInstitution);
0125     d->m_street = street;
0126 }
0127 
0128 QString MyMoneyInstitution::telephone() const
0129 {
0130     Q_D(const MyMoneyInstitution);
0131     return d->m_telephone;
0132 }
0133 
0134 void MyMoneyInstitution::setTelephone(const QString& tel)
0135 {
0136     Q_D(MyMoneyInstitution);
0137     d->m_telephone = tel;
0138 }
0139 
0140 QString MyMoneyInstitution::town() const
0141 {
0142     Q_D(const MyMoneyInstitution);
0143     return d->m_town;
0144 }
0145 
0146 void MyMoneyInstitution::setTown(const QString& town)
0147 {
0148     Q_D(MyMoneyInstitution);
0149     d->m_town = town;
0150 }
0151 
0152 QString MyMoneyInstitution::city() const
0153 {
0154     return town();
0155 }
0156 
0157 void MyMoneyInstitution::setCity(const QString& town)
0158 {
0159     setTown(town);
0160 }
0161 
0162 QString MyMoneyInstitution::sortcode() const
0163 {
0164     Q_D(const MyMoneyInstitution);
0165     return d->m_sortcode;
0166 }
0167 
0168 void MyMoneyInstitution::setSortcode(const QString& code)
0169 {
0170     Q_D(MyMoneyInstitution);
0171     d->m_sortcode = code;
0172 }
0173 
0174 void MyMoneyInstitution::addAccountId(const QString& account)
0175 {
0176     Q_D(MyMoneyInstitution);
0177     // only add this account if it is not yet presently in the list
0178     if (d->m_accountList.contains(account) == 0)
0179         d->m_accountList.append(account);
0180 }
0181 
0182 QString MyMoneyInstitution::removeAccountId(const QString& account)
0183 {
0184     Q_D(MyMoneyInstitution);
0185     QString rc;
0186 
0187     auto pos = d->m_accountList.indexOf(account);
0188     if (pos != -1) {
0189         d->m_accountList.removeAt(pos);
0190         rc = account;
0191     }
0192     return rc;
0193 }
0194 
0195 QStringList MyMoneyInstitution::accountList() const
0196 {
0197     Q_D(const MyMoneyInstitution);
0198     return d->m_accountList;
0199 }
0200 
0201 /**
0202   * This method returns the number of accounts known to
0203   * this institution
0204   * @return number of accounts
0205   */
0206 unsigned int MyMoneyInstitution::accountCount() const
0207 {
0208     Q_D(const MyMoneyInstitution);
0209     return d->m_accountList.count();
0210 }
0211 
0212 bool MyMoneyInstitution::operator < (const MyMoneyInstitution& right) const
0213 {
0214     Q_D(const MyMoneyInstitution);
0215     auto d2 = static_cast<const MyMoneyInstitutionPrivate *>(right.d_func());
0216     return d->m_name < d2->m_name;
0217 }
0218 
0219 bool MyMoneyInstitution::operator == (const MyMoneyInstitution& right) const
0220 {
0221     Q_D(const MyMoneyInstitution);
0222     auto d2 = static_cast<const MyMoneyInstitutionPrivate *>(right.d_func());
0223     if (MyMoneyObject::operator==(right) //
0224             && ((d->m_name.length() == 0 && d2->m_name.length() == 0) || (d->m_name == d2->m_name)) &&
0225             ((d->m_town.length() == 0 && d2->m_town.length() == 0) || (d->m_town == d2->m_town)) &&
0226             ((d->m_street.length() == 0 && d2->m_street.length() == 0) || (d->m_street == d2->m_street)) &&
0227             ((d->m_postcode.length() == 0 && d2->m_postcode.length() == 0) || (d->m_postcode == d2->m_postcode)) &&
0228             ((d->m_telephone.length() == 0 && d2->m_telephone.length() == 0) || (d->m_telephone == d2->m_telephone)) &&
0229             ((d->m_sortcode.length() == 0 && d2->m_sortcode.length() == 0) || (d->m_sortcode == d2->m_sortcode)) &&
0230             ((d->m_manager.length() == 0 && d2->m_manager.length() == 0) || (d->m_manager == d2->m_manager)) &&
0231             (d->m_accountList == d2->m_accountList)) {
0232         return true;
0233     } else
0234         return false;
0235 }
0236 
0237 bool MyMoneyInstitution::hasReferenceTo(const QString& /* id */) const
0238 {
0239     return false;
0240 }
0241 
0242 QPixmap MyMoneyInstitution::pixmap(const int size)
0243 {
0244     QPixmap pxIcon;
0245     auto kyIcon = QString::fromLatin1("view_institution%1").arg(QString::number(size));
0246     if (!QPixmapCache::find(kyIcon, pxIcon)) {
0247         pxIcon = Icons::get(Icon::Institution).pixmap(size);
0248         QPixmapCache::insert(kyIcon, pxIcon);
0249     }
0250     return pxIcon;
0251 }