File indexing completed on 2024-06-09 05:02:27
0001 /* 0002 SPDX-FileCopyrightText: 2014 Christian Dávid <christian-david@web.de> 0003 SPDX-FileCopyrightText: 2021 Dawid Wróbel <me@dawidwrobel.com> 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef IBANBICDATA_H 0008 #define IBANBICDATA_H 0009 0010 #ifndef KMM_MYMONEY_UNIT_TESTABLE 0011 # define KMM_MYMONEY_UNIT_TESTABLE 0012 #endif 0013 0014 #include "kmymoneyplugin.h" 0015 0016 #include <QObject> 0017 #include <QVariant> 0018 #include <QSqlDatabase> 0019 0020 namespace eIBANBIC { 0021 enum bicAllocationStatus : unsigned int; 0022 } 0023 0024 /** 0025 * @brief This class implements everything that needs lookup 0026 * 0027 * Kind of a static private class of payeeIdentifier::ibanBic. It loads the iban/bic data and queries the 0028 * databases. 0029 * 0030 * @internal This class is made if a cache will be needed in future. 0031 */ 0032 class ibanBicData : public KMyMoneyPlugin::Plugin, public KMyMoneyPlugin::DataPlugin 0033 { 0034 Q_OBJECT 0035 Q_INTERFACES(KMyMoneyPlugin::DataPlugin) 0036 KMM_MYMONEY_UNIT_TESTABLE 0037 0038 public: 0039 explicit ibanBicData(QObject *parent, const KPluginMetaData &metaData, const QVariantList &args); 0040 ~ibanBicData() override; 0041 0042 QVariant requestData(const QString &arg, uint type) override; 0043 0044 int bbanLength(const QString& countryCode); 0045 int bankIdentifierPosition(const QString& countryCode); 0046 int bankIdentifierLength(const QString& countryCode); 0047 0048 /** 0049 * @brief Create a BIC from a given IBAN 0050 * 0051 * The bic is always 11 characters long. 0052 * 0053 * @return QString::isNull() == true means an internal error occurred, QString::isEmpty() == true means there is no BIC 0054 */ 0055 QString iban2Bic(const QString& iban); 0056 0057 QString bankNameByBic(QString bic); 0058 0059 /** 0060 * @brief Create a BIC from a IBAN and get the institutes name 0061 * 0062 * first: bic, always 11 characters long. 0063 * second: institution name 0064 * 0065 * QString::isNull() == true means an internal error occurred, QString::isEmpty() == true means there is no data 0066 */ 0067 QPair<QString, QString> bankNameAndBic(const QString& iban); 0068 0069 QString extractBankIdentifier(const QString& iban); 0070 0071 eIBANBIC::bicAllocationStatus isBicAllocated(const QString& bic); 0072 0073 private: 0074 QVariant findPropertyByCountry(const QString& countryCode, const QString& property, const QVariant::Type type); 0075 0076 /** 0077 * @brief Create/get QSqlDatabase 0078 * 0079 * Returns a QSqlDatabase. It is invalid if something went wrong. 0080 * 0081 * @param database This string is used to locate the database in the data dir 0082 */ 0083 QSqlDatabase createDatabaseConnection(const QString& database); 0084 }; 0085 0086 #endif // IBANBICDATA_H