File indexing completed on 2024-07-21 04:35:16

0001 /*
0002  * SPDX-FileCopyrightText: 2018 Ralf Habacker ralf.habacker@freenet.de
0003  * SPDX-FileCopyrightText: 2023 Thomas Baumgart <tbaumgart@kde.org>
0004  * SPDX-License-Identifier: LGPL-2.1-or-later
0005  *
0006  * This file is part of libalkimia.
0007  */
0008 
0009 #ifndef ALKONLINEQUOTESOURCE_H
0010 #define ALKONLINEQUOTESOURCE_H
0011 
0012 #include <alkimia/alkonlinequotesprofile.h>
0013 
0014 #include <QString>
0015 
0016 class AlkOnlineQuotesProfile;
0017 
0018 /**
0019   * @author Thomas Baumgart & Ace Jones
0020   *
0021   * This is a helper class to store information about an online source
0022   * for stock prices or currency exchange rates.
0023   */
0024 class ALK_EXPORT AlkOnlineQuoteSource
0025 {
0026 public:
0027     enum IdSelector {
0028         Symbol,
0029         IdentificationNumber,
0030         Name,
0031     };
0032 
0033     /**
0034      * Supported formats of downloaded data
0035      */
0036     enum DataFormat {
0037         StrippedHTML,
0038         HTML,
0039         CSV
0040     };
0041 
0042     AlkOnlineQuoteSource();
0043     explicit AlkOnlineQuoteSource(const QString &name, AlkOnlineQuotesProfile *profile);
0044     explicit AlkOnlineQuoteSource(const QString& name,
0045                                   const QString& url,
0046                                   const QString& idRegex,
0047                                   const IdSelector idBy,
0048                                   const QString& priceRegex,
0049                                   const QString& dateRegex,
0050                                   const QString& dateFormat,
0051                                   DataFormat dataFormat = HTML);
0052     ~AlkOnlineQuoteSource();
0053 
0054     AlkOnlineQuoteSource(const AlkOnlineQuoteSource &other);
0055     AlkOnlineQuoteSource &operator=(AlkOnlineQuoteSource other);
0056 
0057     static AlkOnlineQuoteSource defaultCurrencyQuoteSource(const QString& name);
0058 
0059     friend void swap(AlkOnlineQuoteSource& first, AlkOnlineQuoteSource& second);
0060 
0061     bool isEmpty();
0062     bool isValid();
0063 
0064     bool read();
0065     bool write();
0066     void rename(const QString &name);
0067     void remove();
0068 
0069     QString name() const;
0070     QString url() const;
0071     QString priceRegex() const;
0072     QString idRegex() const;
0073     /**
0074      * Return the format of the downloaded data
0075      *
0076      * @return Format identifier
0077      */
0078     DataFormat dataFormat() const;
0079     QString dateRegex() const;
0080     QString dateFormat() const;
0081     QString financeQuoteName() const;
0082     IdSelector idSelector() const;
0083 
0084     bool isGHNS() const;
0085     bool isReadOnly() const;
0086     bool isFinanceQuote() const;
0087     static bool isFinanceQuote(const QString &name);
0088 
0089     void setName(const QString &name);
0090     void setUrl(const QString &url);
0091     void setPriceRegex(const QString &priceRegex);
0092     void setIdRegex(const QString &idRegex);
0093 
0094     /**
0095      * Set the format of the downloaded data
0096      *
0097      * @param dataFormat Format identifier
0098      */
0099     void setDataFormat(DataFormat dataFormat);
0100     void setDateRegex(const QString &dateRegex);
0101     void setDateFormat(const QString &dateFormat);
0102     void setGHNS(bool state);
0103     void setIdSelector(IdSelector idSelector);
0104 
0105     /**
0106      * Return the default identifier known to work
0107      * @return default identifier
0108      */
0109     const QString &defaultId() const;
0110 
0111     /**
0112      * Set the default identifier, which is known to work
0113      * @param defaultID default identifier
0114      */
0115     void setDefaultId(const QString &defaultId);
0116 
0117     /**
0118      * Return state if this source requires two identifier
0119      * @return false required one identifier
0120      * @return true required two identifier
0121      */
0122     bool requiresTwoIdentifier() const;
0123     QString ghnsWriteFileName() const;
0124     void setProfile(AlkOnlineQuotesProfile *profile);
0125     AlkOnlineQuotesProfile *profile();
0126     AlkOnlineQuotesProfile *profile() const;
0127 
0128 protected:
0129     class Private;
0130     Private *d;
0131 };
0132 
0133 inline void swap(AlkOnlineQuoteSource& first, AlkOnlineQuoteSource& second) // krazy:exclude=inline
0134 {
0135   using std::swap;
0136   swap(first.d, second.d);
0137 }
0138 
0139 #endif // ALKONLINEQUOTESOURCE_H