Alkimia API

alkonlinequote.cpp
1/*
2 SPDX-FileCopyrightText: 2004 Ace Jones acejones @users.sourceforge.net
3 SPDX-FileCopyrightText: 2019 Thomas Baumgart tbaumgart @kde.org
4
5 This file is part of libalkimia.
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9
10#include "alkonlinequote.h"
11
12#include "alkonlinequote_p.h"
13
14AlkOnlineQuote::Errors::Errors()
15{
16}
17
18AlkOnlineQuote::Errors::Errors(Type type)
19{
20 if (type != None)
21 m_type.append(type);
22 else
23 m_type.clear();
24}
25
26AlkOnlineQuote::Errors& AlkOnlineQuote::Errors::operator|=(Type t)
27{
28 if (!m_type.contains(t)) {
29 m_type.append(t);
30 }
31 return *this;
32}
33
34bool AlkOnlineQuote::Errors::operator &(Type t) const
35{
36 return m_type.contains(t);
37}
38
39bool AlkOnlineQuote::Errors::operator ==(Type t) const
40{
41 return m_type.size() == 1 && m_type.contains(t);
42}
43
44bool AlkOnlineQuote::Errors::operator !=(Type t) const
45{
46 return m_type.size() != 1 || !m_type.contains(t);
47}
48
49bool AlkOnlineQuote::Errors::isEmpty() const
50{
51 return m_type.size() == 0;
52}
53
54AlkOnlineQuote::AlkOnlineQuote(AlkOnlineQuotesProfile *profile, QObject *_parent)
55 : QObject(_parent)
56 , d(new Private(this))
57{
58 if (profile)
59 d->m_profile = profile;
60 else {
61 d->m_profile = new AlkOnlineQuotesProfile;
62 d->m_ownProfile = true;
63 }
64}
65
66AlkOnlineQuote::~AlkOnlineQuote()
67{
68 delete d;
69}
70
71AlkOnlineQuotesProfile *AlkOnlineQuote::profile()
72{
73 return d->m_profile;
74}
75
76void AlkOnlineQuote::setProfile(AlkOnlineQuotesProfile *profile)
77{
78 if (profile && d->m_ownProfile) {
79 // switching from own profile to external
80 delete d->m_profile;
81 d->m_ownProfile = false;
82 d->m_profile = profile;
83
84 } else if (!profile && !d->m_ownProfile) {
85 // switching from external to own profile
86 d->m_profile = new AlkOnlineQuotesProfile;
87 d->m_ownProfile = true;
88
89 } else if (profile) {
90 // exchange external profile
91 d->m_profile = profile;
92 }
93}
94
96{
97 d->m_acceptLanguage = language;
98}
99
101{
102 return d->m_timeout;
103}
104
105void AlkOnlineQuote::setTimeout(int newTimeout)
106{
107 d->m_timeout = newTimeout;
108}
109
110void AlkOnlineQuote::setDateRange(const QDate &from, const QDate &to)
111{
112 d->m_startDate = from;
113 d->m_endDate = to;
114}
115
117{
118 return d->m_alwaysReturnLastPrice;
119}
120
122{
123 d->m_alwaysReturnLastPrice = state;
124}
125
127{
128 d->m_useSingleQuoteSignal = state;
129}
130
132{
133 return d->m_useSingleQuoteSignal;
134}
135
137{
138 return d->m_reverseLaunchEnabled;
139}
140
142{
143 d->m_reverseLaunchEnabled = state;
144}
145
147{
148 return d->m_source;
149}
150
151bool AlkOnlineQuote::launch(const QString &_symbol, const QString &_id, const QString &_source)
152{
153 return d->launch(_symbol, _id, _source);
154}
155
157{
158 return d->m_errors;
159}
160
161AlkOnlineQuote::Private &AlkOnlineQuote::d_ptr()
162{
163 return *d;
164}
Hold errors reported from price quote fetching and parsing.
const AlkOnlineQuoteSource & source() const
Provides the currently used online source.
void setAcceptLanguage(const QString &language)
Set accepted language the online quote should be returned for.
bool enableReverseLaunch()
Returns the status whether a search with swapped symbols should be performed after a query for a symb...
void setEnableReverseLaunch(bool state)
Set the status whether a search with swapped symbole should be performed after a query for a symbol r...
void setDateRange(const QDate &from, const QDate &to)
Defines a date range within which the data is to be retrieved.
void setTimeout(int newTimeout)
Set timeout for fetching online quotes If the timeout is != -1, a request to retrieve online quotes w...
int timeout() const
Return actual used timeout for fetching online quotes If the returned value is -1,...
bool launch(const QString &_symbol, const QString &_id, const QString &_source=QString())
This launches a web-based quote update for the given _symbol.
bool useSingleQuoteSignal()
Returns the status of whether the quote signal is always used.
void setReturnLastPriceState(LastPriceState state)
Sets the status of the price to be returned for special date range.
LastPriceState returnLastPriceState()
Returns the status of the price to be returned for special date ranges.
void setUseSingleQuoteSignal(bool state)
Always use signal quote.
const AlkOnlineQuote::Errors & errors()
If launch() returns false, this method can be used to get details about the errors that occurred.
LastPriceState
Supported values for returning prices in special cases.
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.