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

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: 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 "mymoneypayee.h"
0011 #include "mymoneypayee_p.h"
0012 
0013 // ----------------------------------------------------------------------------
0014 // QT Includes
0015 
0016 #include <QString>
0017 #include <QStringList>
0018 
0019 // ----------------------------------------------------------------------------
0020 // Project Includes
0021 
0022 #include "mymoneyexception.h"
0023 #include "mymoneyenums.h"
0024 
0025 /// @todo remove and replace that one occurrence with MyMoneyPayee()
0026 MyMoneyPayee MyMoneyPayee::null;
0027 
0028 MyMoneyPayee::MyMoneyPayee() :
0029     MyMoneyObject(*new MyMoneyPayeePrivate)
0030 {
0031 }
0032 
0033 MyMoneyPayee::MyMoneyPayee(const QString &id):
0034     MyMoneyObject(*new MyMoneyPayeePrivate, id)
0035 {
0036 }
0037 
0038 MyMoneyPayee::MyMoneyPayee(const MyMoneyPayee& other) :
0039     MyMoneyObject(*new MyMoneyPayeePrivate(*other.d_func()), other.id()),
0040     MyMoneyPayeeIdentifierContainer(other)
0041 {
0042 }
0043 
0044 MyMoneyPayee::MyMoneyPayee(const QString& id, const MyMoneyPayee& other) :
0045     MyMoneyObject(*new MyMoneyPayeePrivate(*other.d_func()), id),
0046     MyMoneyPayeeIdentifierContainer(other)
0047 {
0048 }
0049 
0050 MyMoneyPayee::~MyMoneyPayee()
0051 {
0052 }
0053 
0054 bool MyMoneyPayee::operator == (const MyMoneyPayee& right) const
0055 {
0056     Q_D(const MyMoneyPayee);
0057     auto d2 = static_cast<const MyMoneyPayeePrivate *>(right.d_func());
0058     return (MyMoneyObject::operator==(right) //
0059             && ((d->m_name.length() == 0 && d2->m_name.length() == 0) || (d->m_name == d2->m_name)) &&
0060             ((d->m_address.length() == 0 && d2->m_address.length() == 0) || (d->m_address == d2->m_address)) &&
0061             ((d->m_city.length() == 0 && d2->m_city.length() == 0) || (d->m_city == d2->m_city)) &&
0062             ((d->m_state.length() == 0 && d2->m_state.length() == 0) || (d->m_state == d2->m_state)) &&
0063             ((d->m_postcode.length() == 0 && d2->m_postcode.length() == 0) || (d->m_postcode == d2->m_postcode)) &&
0064             ((d->m_telephone.length() == 0 && d2->m_telephone.length() == 0) || (d->m_telephone == d2->m_telephone)) &&
0065             ((d->m_email.length() == 0 && d2->m_email.length() == 0) || (d->m_email == d2->m_email)) &&
0066             (d->m_matchingEnabled == d2->m_matchingEnabled) &&
0067             (d->m_usingMatchKey == d2->m_usingMatchKey) &&
0068             (d->m_matchKeyIgnoreCase == d2->m_matchKeyIgnoreCase) &&
0069             ((d->m_matchKey.length() == 0 && d2->m_matchKey.length() == 0) || d->m_matchKey == d2->m_matchKey) &&
0070             ((d->m_reference.length() == 0 && d2->m_reference.length() == 0) || (d->m_reference == d2->m_reference)) &&
0071             ((d->m_defaultAccountId.length() == 0 && d2->m_defaultAccountId.length() == 0) || d->m_defaultAccountId == d2->m_defaultAccountId));
0072 }
0073 
0074 bool MyMoneyPayee::operator < (const MyMoneyPayee& right) const
0075 {
0076     Q_D(const MyMoneyPayee);
0077     auto d2 = static_cast<const MyMoneyPayeePrivate *>(right.d_func());
0078     return d->m_name < d2->m_name;
0079 }
0080 
0081 bool MyMoneyPayee::hasReferenceTo(const QString& id) const
0082 {
0083     Q_D(const MyMoneyPayee);
0084     return id == d->m_defaultAccountId;
0085 }
0086 
0087 QString MyMoneyPayee::name() const
0088 {
0089     Q_D(const MyMoneyPayee);
0090     return d->m_name;
0091 }
0092 
0093 void MyMoneyPayee::setName(const QString& val)
0094 {
0095     Q_D(MyMoneyPayee);
0096     d->m_name = val;
0097 }
0098 
0099 QString MyMoneyPayee::address() const
0100 {
0101     Q_D(const MyMoneyPayee);
0102     return d->m_address;
0103 }
0104 
0105 void MyMoneyPayee::setAddress(const QString& val)
0106 {
0107     Q_D(MyMoneyPayee);
0108     d->m_address = val;
0109 }
0110 
0111 QString MyMoneyPayee::city() const
0112 {
0113     Q_D(const MyMoneyPayee);
0114     return d->m_city;
0115 }
0116 
0117 void MyMoneyPayee::setCity(const QString& val)
0118 {
0119     Q_D(MyMoneyPayee);
0120     d->m_city = val;
0121 }
0122 
0123 QString MyMoneyPayee::state() const
0124 {
0125     Q_D(const MyMoneyPayee);
0126     return d->m_state;
0127 }
0128 
0129 void MyMoneyPayee::setState(const QString& val)
0130 {
0131     Q_D(MyMoneyPayee);
0132     d->m_state = val;
0133 }
0134 
0135 QString MyMoneyPayee::postcode() const
0136 {
0137     Q_D(const MyMoneyPayee);
0138     return d->m_postcode;
0139 }
0140 
0141 void MyMoneyPayee::setPostcode(const QString& val)
0142 {
0143     Q_D(MyMoneyPayee);
0144     d->m_postcode = val;
0145 }
0146 
0147 QString MyMoneyPayee::telephone() const
0148 {
0149     Q_D(const MyMoneyPayee);
0150     return d->m_telephone;
0151 }
0152 
0153 void MyMoneyPayee::setTelephone(const QString& val)
0154 {
0155     Q_D(MyMoneyPayee);
0156     d->m_telephone = val;
0157 }
0158 
0159 QString MyMoneyPayee::email() const
0160 {
0161     Q_D(const MyMoneyPayee);
0162     return d->m_email;
0163 }
0164 
0165 void MyMoneyPayee::setEmail(const QString& val)
0166 {
0167     Q_D(MyMoneyPayee);
0168     d->m_email = val;
0169 }
0170 
0171 QString MyMoneyPayee::notes() const
0172 {
0173     Q_D(const MyMoneyPayee);
0174     return d->m_notes;
0175 }
0176 
0177 void MyMoneyPayee::setNotes(const QString& val)
0178 {
0179     Q_D(MyMoneyPayee);
0180     d->m_notes = val;
0181 }
0182 
0183 QString MyMoneyPayee::reference() const
0184 {
0185     Q_D(const MyMoneyPayee);
0186     return d->m_reference;
0187 }
0188 
0189 void MyMoneyPayee::setReference(const QString& ref)
0190 {
0191     Q_D(MyMoneyPayee);
0192     d->m_reference = ref;
0193 }
0194 
0195 bool MyMoneyPayee::isMatchingEnabled() const
0196 {
0197     Q_D(const MyMoneyPayee);
0198     return d->m_matchingEnabled;
0199 }
0200 
0201 bool MyMoneyPayee::isUsingMatchKey() const
0202 {
0203     Q_D(const MyMoneyPayee);
0204     return d->m_usingMatchKey;
0205 }
0206 
0207 bool MyMoneyPayee::isMatchKeyIgnoreCase() const
0208 {
0209     Q_D(const MyMoneyPayee);
0210     return d->m_matchKeyIgnoreCase;
0211 }
0212 
0213 QString MyMoneyPayee::matchKey() const
0214 {
0215     Q_D(const MyMoneyPayee);
0216     return d->m_matchKey;
0217 }
0218 
0219 eMyMoney::Payee::MatchType MyMoneyPayee::matchData(bool& ignorecase, QStringList& keys) const
0220 {
0221     auto type = eMyMoney::Payee::MatchType::Disabled;
0222     keys.clear();
0223 
0224     Q_D(const MyMoneyPayee);
0225     ignorecase = d->m_matchKeyIgnoreCase;
0226 
0227     if (d->m_matchingEnabled) {
0228         type = d->m_usingMatchKey ? eMyMoney::Payee::MatchType::Key : eMyMoney::Payee::MatchType::Name;
0229         if (type == eMyMoney::Payee::MatchType::Key) {
0230             if (d->m_matchKey.contains(QLatin1Char('\n')))
0231                 keys = d->m_matchKey.split(QLatin1Char('\n'));
0232             else
0233                 keys = d->m_matchKey.split(QLatin1Char(';'));  // for compatibility with 4.8.0
0234         } else if (d->m_matchKey.compare(QLatin1String("^$")) == 0) {
0235             type = eMyMoney::Payee::MatchType::NameExact;
0236         }
0237     }
0238 
0239     return type;
0240 }
0241 
0242 eMyMoney::Payee::MatchType MyMoneyPayee::matchData(bool& ignorecase, QString& keyString) const
0243 {
0244     QStringList keys;
0245     auto type = matchData(ignorecase, keys);
0246     keyString = keys.join(QLatin1Char('\n'));
0247     return type;
0248 }
0249 
0250 void MyMoneyPayee::setMatchData(eMyMoney::Payee::MatchType type, bool ignorecase, const QStringList& keys)
0251 {
0252     Q_D(MyMoneyPayee);
0253     d->m_matchingEnabled = (type != eMyMoney::Payee::MatchType::Disabled);
0254     d->m_matchKeyIgnoreCase = ignorecase;
0255     d->m_matchKey.clear();
0256 
0257     if (d->m_matchingEnabled) {
0258         d->m_usingMatchKey = (type == eMyMoney::Payee::MatchType::Key);
0259         if (d->m_usingMatchKey) {
0260             QRegExp validKeyRegExp("[^ ]");
0261             QStringList filteredKeys = keys.filter(validKeyRegExp);
0262             d->m_matchKey = filteredKeys.join(QLatin1Char('\n'));
0263         } else if ((type == eMyMoney::Payee::MatchType::Name) && (keys.count() == 1) && (keys.at(0) == QLatin1String("^$"))) {
0264             type = eMyMoney::Payee::MatchType::NameExact;
0265             d->m_matchKey = QLatin1String("^$");
0266         } else if (type == eMyMoney::Payee::MatchType::NameExact) {
0267             d->m_matchKey = QLatin1String("^$");
0268         }
0269     }
0270 }
0271 
0272 void MyMoneyPayee::setMatchData(eMyMoney::Payee::MatchType type, bool ignorecase, const QString& keys)
0273 {
0274     if (keys.contains(QLatin1Char('\n')))
0275         setMatchData(type, ignorecase, keys.split(QLatin1Char('\n')));
0276     else
0277         setMatchData(type, ignorecase, keys.split(QLatin1Char(';'))); // for compatibility with 4.8.0
0278 }
0279 
0280 QString MyMoneyPayee::defaultAccountId() const
0281 {
0282     Q_D(const MyMoneyPayee);
0283     return d->m_defaultAccountId;
0284 }
0285 
0286 void MyMoneyPayee::setDefaultAccountId(const QString& id)
0287 {
0288     Q_D(MyMoneyPayee);
0289     d->m_defaultAccountId = id;
0290 }
0291 
0292 // vim:cin:si:ai:et:ts=2:sw=2: