Changeset View
Changeset View
Standalone View
Standalone View
kmymoney/converter/webpricequote.h
Show First 20 Lines • Show All 128 Lines • ▼ Show 20 Line(s) | |||||
129 | */ | 129 | */ | ||
130 | class WebPriceQuote: public QObject | 130 | class WebPriceQuote: public QObject | ||
131 | { | 131 | { | ||
132 | Q_OBJECT | 132 | Q_OBJECT | ||
133 | public: | 133 | public: | ||
134 | explicit WebPriceQuote(QObject* = 0); | 134 | explicit WebPriceQuote(QObject* = 0); | ||
135 | ~WebPriceQuote(); | 135 | ~WebPriceQuote(); | ||
136 | 136 | | |||
137 | /** | ||||
138 | * Hold errors reported from price quote fetching and parsing | ||||
139 | * | ||||
140 | * The implementation provides a type safe way to use | ||||
141 | * bit operations like '|=' for combining values and '&' | ||||
142 | * for checking value presence. | ||||
143 | */ | ||||
144 | class Errors { | ||||
145 | public: | ||||
146 | enum Type { | ||||
147 | None, | ||||
148 | Data, | ||||
149 | Date, | ||||
150 | DateFormat, | ||||
151 | Price, | ||||
152 | Script, | ||||
153 | Source, | ||||
154 | Symbol, | ||||
155 | Success, | ||||
156 | URL, | ||||
157 | }; | ||||
158 | | ||||
159 | inline Errors() { } | ||||
160 | inline Errors(Type type) { m_type.append(type); } | ||||
161 | inline Errors(const Errors &e) { m_type = e.m_type; } | ||||
162 | inline Errors &operator |=(Type t) { if (!m_type.contains(t)) m_type.append(t); return *this; } | ||||
163 | inline bool operator &(Type t) const { return m_type.contains(t); } | ||||
164 | | ||||
165 | protected: | ||||
166 | QList<Type> m_type; | ||||
167 | }; | ||||
168 | | ||||
137 | typedef enum _quoteSystemE { | 169 | typedef enum _quoteSystemE { | ||
138 | Native = 0, | 170 | Native = 0, | ||
139 | FinanceQuote | 171 | FinanceQuote | ||
140 | } quoteSystemE; | 172 | } quoteSystemE; | ||
141 | 173 | | |||
142 | /** | 174 | /** | ||
143 | * This launches a web-based quote update for the given @p _symbol. | 175 | * This launches a web-based quote update for the given @p _symbol. | ||
144 | * When the quote is received back from the web source, it will be | 176 | * When the quote is received back from the web source, it will be | ||
145 | * emitted on the 'quote' signal. | 177 | * emitted on the 'quote' signal. | ||
146 | * | 178 | * | ||
147 | * @param _symbol the trading symbol of the stock to fetch a price for | 179 | * @param _symbol the trading symbol of the stock to fetch a price for | ||
148 | * @param _id an arbitrary identifier, which will be emitted in the quote | 180 | * @param _id an arbitrary identifier, which will be emitted in the quote | ||
149 | * signal when a price is sent back. | 181 | * signal when a price is sent back. | ||
150 | * @param _source the source of the quote (must be a valid value returned | 182 | * @param _source the source of the quote (must be a valid value returned | ||
151 | * by quoteSources(). Send QString() to use the default | 183 | * by quoteSources(). Send QString() to use the default | ||
152 | * source. | 184 | * source. | ||
153 | * @return bool Whether the quote fetch process was launched successfully | 185 | * @return bool Whether the quote fetch process was launched successfully | ||
186 | * In case of failures it returns false and @ref errors() | ||||
187 | * could be used to get error details. | ||||
154 | */ | 188 | */ | ||
155 | | ||||
156 | bool launch(const QString& _symbol, const QString& _id, const QString& _source = QString()); | 189 | bool launch(const QString& _symbol, const QString& _id, const QString& _source = QString()); | ||
157 | 190 | | |||
158 | /** | 191 | /** | ||
192 | * If @ref launch(), @ref launchNative() or @ref launchFinanceQuote() returns false, | ||||
193 | * this method can be used to get details about the errors that occurred. | ||||
194 | * | ||||
195 | * @return bit map of errors, see class @ref Errors for details | ||||
196 | */ | ||||
197 | const Errors &errors() { return m_errors; } | ||||
198 | | ||||
199 | /** | ||||
159 | * This returns a list of the names of the quote sources | 200 | * This returns a list of the names of the quote sources | ||
160 | * currently defined. | 201 | * currently defined. | ||
161 | * | 202 | * | ||
162 | * @param _system whether to return Native or Finance::Quote source list | 203 | * @param _system whether to return Native or Finance::Quote source list | ||
163 | * @return QStringList of quote source names | 204 | * @return QStringList of quote source names | ||
164 | */ | 205 | */ | ||
165 | static const QStringList quoteSources(const _quoteSystemE _system = Native); | 206 | static const QStringList quoteSources(const _quoteSystemE _system = Native); | ||
166 | 207 | | |||
167 | signals: | 208 | signals: | ||
168 | void quote(const QString&, const QString&, const QDate&, const double&); | 209 | void quote(const QString&, const QString&, const QDate&, const double&); | ||
169 | void failed(const QString&, const QString&); | 210 | void failed(const QString&, const QString&); | ||
170 | void status(const QString&); | 211 | void status(const QString&); | ||
171 | void error(const QString&); | 212 | void error(const QString&); | ||
172 | 213 | | |||
173 | protected slots: | 214 | protected slots: | ||
174 | void slotParseQuote(const QString&); | 215 | bool slotParseQuote(const QString& _quotedata); | ||
175 | 216 | | |||
176 | protected: | 217 | protected: | ||
177 | static const QMap<QString, WebPriceQuoteSource> defaultQuoteSources(); | 218 | static const QMap<QString, WebPriceQuoteSource> defaultQuoteSources(); | ||
178 | 219 | | |||
179 | private: | 220 | private: | ||
180 | bool launchNative(const QString& _symbol, const QString& _id, const QString& _source = QString()); | 221 | Errors m_errors; | ||
181 | bool launchFinanceQuote(const QString& _symbol, const QString& _id, const QString& _source = QString()); | 222 | bool launchNative(const QString& _symbol, const QString& _id, const QString& _source); | ||
223 | bool launchFinanceQuote(const QString& _symbol, const QString& _id, const QString& _source); | ||||
182 | void enter_loop(); | 224 | void enter_loop(); | ||
183 | 225 | | |||
184 | static const QStringList quoteSourcesNative(); | 226 | static const QStringList quoteSourcesNative(); | ||
185 | static const QStringList quoteSourcesFinanceQuote(); | 227 | static const QStringList quoteSourcesFinanceQuote(); | ||
186 | 228 | | |||
187 | private: | 229 | private: | ||
188 | /// \internal d-pointer class. | 230 | /// \internal d-pointer class. | ||
189 | class Private; | 231 | class Private; | ||
▲ Show 20 Lines • Show All 50 Lines • Show Last 20 Lines |