Alkimia API

alkonlinequotesource.h
1/*
2 * SPDX-FileCopyrightText: 2018 Ralf Habacker ralf.habacker@freenet.de
3 * SPDX-FileCopyrightText: 2023 Thomas Baumgart <tbaumgart@kde.org>
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 *
6 * This file is part of libalkimia.
7 */
8
9#ifndef ALKONLINEQUOTESOURCE_H
10#define ALKONLINEQUOTESOURCE_H
11
12#include <alkimia/alkonlinequotesprofile.h>
13
14#include <QMetaType>
15#include <QString>
16
17class AlkOnlineQuotesProfile;
18
19/**
20 * @author Thomas Baumgart & Ace Jones
21 *
22 * This is a helper class to store information about an online source
23 * for stock prices or currency exchange rates.
24 */
25class ALK_EXPORT AlkOnlineQuoteSource
26{
27public:
28 enum IdSelector {
29 Symbol,
30 IdentificationNumber,
31 Name,
32 };
33
34 /**
35 * Supported formats of downloaded data
36 */
38 StrippedHTML,
39 HTML,
40 CSV,
41 CSS,
42 JSON,
43 };
44
45 /**
46 * Type of decimal separator
47 */
49 Legacy,
50 Period,
51 Comma
52 };
53
54 enum DownloadType {
55 Default,
56 Javascript,
57 };
58
60 explicit AlkOnlineQuoteSource(const QString &name, AlkOnlineQuotesProfile *profile);
61 explicit AlkOnlineQuoteSource(const QString& name,
62 const QString& url,
63 const QString& idRegex,
64 const IdSelector idBy,
65 const QString& priceRegex,
66 const QString& dateRegex,
67 const QString& dateFormat,
68 DataFormat dataFormat = HTML,
69 DecimalSeparator priceDecimalSeparator = Legacy,
70 DownloadType downloadType = Default);
72
75
76 static AlkOnlineQuoteSource defaultCurrencyQuoteSource(const QString& name);
77 static AlkOnlineQuoteSource testQuoteSource(const QString &name, bool twoSymbols = false, DownloadType downloadType = Default, DataFormat format = HTML);
78
79 friend void swap(AlkOnlineQuoteSource& first, AlkOnlineQuoteSource& second);
80
81 /**
82 * Return referenced quote source
83 *
84 * If this source is not a reference, an empty source is returned.
85 *
86 * @return referenced quote source or empty source otherwise
87 */
88 AlkOnlineQuoteSource asReference() const;
89
90 /**
91 * Return state if this source is a reference
92 *
93 * @return true the current source is a reference
94 * @return false the current source is not a reference
95 */
96 bool isReference() const;
97 bool isEmpty();
98 bool isValid();
99
100 bool read();
101 bool write();
102 void rename(const QString &name);
103 void remove();
104
105 /**
106 * Return name of the referenced quote source
107 *
108 * @return referenced source name
109 */
110 QString referenceName() const;
111 QString name() const;
112 QString url() const;
113 DecimalSeparator priceDecimalSeparator() const;
114 QString priceRegex() const;
115 QString idRegex() const;
116 /**
117 * Return the format of the downloaded data
118 *
119 * @return Format identifier
120 */
121 DataFormat dataFormat() const;
122 QString dateRegex() const;
123 QString dateFormat() const;
124 DownloadType downloadType() const;
125 QString financeQuoteName() const;
126 IdSelector idSelector() const;
127
128 bool isGHNS() const;
129 bool isReadOnly() const;
130 bool isFinanceQuote() const;
131 static bool isFinanceQuote(const QString &name);
132
133 /**
134 * Make this source a reference
135 *
136 * Calling this method makes this source a reference to a remote online quote source.
137 *
138 *@param name name of the referenced source
139 */
140 void setReferenceName(const QString &name);
141 void setName(const QString &name);
142 void setUrl(const QString &url);
143 void setPriceDecimalSeparator(DecimalSeparator separator);
144 void setPriceRegex(const QString &priceRegex);
145 void setIdRegex(const QString &idRegex);
146
147 /**
148 * Set the format of the downloaded data
149 *
150 * @param dataFormat Format identifier
151 */
152 void setDataFormat(DataFormat dataFormat);
153 void setDateRegex(const QString &dateRegex);
154 void setDateFormat(const QString &dateFormat);
155 void setDownloadType(DownloadType downloadType);
156 void setGHNS(bool state);
157 void setIdSelector(IdSelector idSelector);
158
159 /**
160 * Return the default identifier known to work
161 * @return default identifier
162 */
163 const QString &defaultId() const;
164
165 /**
166 * Set the default identifier, which is known to work
167 * @param defaultID default identifier
168 */
169 void setDefaultId(const QString &defaultId);
170
171 /**
172 * Return state if this source requires two identifier
173 * @return false required one identifier
174 * @return true required two identifier
175 */
176 bool requiresTwoIdentifier() const;
177
178 /**
179 * Return state if this source supports a date range
180 * @return true source supports a date range
181 * @return false source does not support a date range
182 * @since 8.1.90
183 */
184 bool supportsDateRange() const;
185
186 QString ghnsWriteFileName() const;
187 void setProfile(AlkOnlineQuotesProfile *profile);
188 AlkOnlineQuotesProfile *profile();
189 AlkOnlineQuotesProfile *profile() const;
190
191protected:
192 class Private;
193 Private *d;
194};
195
196Q_DECLARE_METATYPE(AlkOnlineQuoteSource::DataFormat)
198Q_DECLARE_METATYPE(AlkOnlineQuoteSource::DownloadType)
199Q_DECLARE_METATYPE(AlkOnlineQuoteSource::IdSelector)
200
201inline void swap(AlkOnlineQuoteSource& first, AlkOnlineQuoteSource& second) // krazy:exclude=inline
202{
203 using std::swap;
204 swap(first.d, second.d);
205}
206
207/**
208 * Returns the specified data format as text
209 * @param format data format for which the text is to be returned
210 * @return data format as text
211 */
213
214#endif // ALKONLINEQUOTESOURCE_H
DataFormat
Supported formats of downloaded data.
DecimalSeparator
Type of decimal separator.
bool remove(const QString &column, const QVariant &value)
char * toString(const EngineQuery &query)
KIOCORE_EXPORT SimpleJob * rename(const QUrl &src, const QUrl &dest, JobFlags flags=DefaultFlags)
QVariant read(const QByteArray &data, int versionOverride=0)
bool isValid(QStringView ifopt)
QString name(StandardAction id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.