File indexing completed on 2024-05-12 05:06:40

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