Alkimia API

alkfinancequoteprocess.cpp
1/*
2 SPDX-FileCopyrightText: 2004 Ace Jones <acejones@users.sourceforge.net>
3 SPDX-FileCopyrightText: 2004 Thomas Baumgart <thb@net-bembel.de>
4
5 This file is part of libalkimia.
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9
10#include "alkfinancequoteprocess.h"
11
12#include <QMap>
13#include <QString>
14#include <QtDebug>
15
16class AlkFinanceQuoteProcess::Private
17{
18public:
19 typedef QMap<QString, QString> fqNameMap;
20 bool m_isDone;
21 QString m_string;
22 fqNameMap m_fqNames;
23
24 Private() : m_isDone(false)
25 {
26 }
27};
28
29AlkFinanceQuoteProcess::AlkFinanceQuoteProcess()
30 : d(new Private)
31{
32 d->m_fqNames["aex"] = "AEX";
33 d->m_fqNames["aex_futures"] = "AEX Futures";
34 d->m_fqNames["aex_options"] = "AEX Options";
35 d->m_fqNames["amfiindia"] = "AMFI India";
36 d->m_fqNames["asegr"] = "ASE";
37 d->m_fqNames["asia"] = "Asia (Yahoo, ...)";
38 d->m_fqNames["asx"] = "ASX";
39 d->m_fqNames["australia"] = "Australia (ASX, Yahoo, ...)";
40 d->m_fqNames["bmonesbittburns"] = "BMO NesbittBurns";
41 d->m_fqNames["brasil"] = "Brasil (Yahoo, ...)";
42 d->m_fqNames["canada"] = "Canada (Yahoo, ...)";
43 d->m_fqNames["canadamutual"] = "Canada Mutual (Fund Library, ...)";
44 d->m_fqNames["deka"] = "Deka Investments";
45 d->m_fqNames["dutch"] = "Dutch (AEX, ...)";
46 d->m_fqNames["dwsfunds"] = "DWS";
47 d->m_fqNames["europe"] = "Europe (Yahoo, ...)";
48 d->m_fqNames["fidelity"] = "Fidelity (Fidelity, ...)";
49 d->m_fqNames["fidelity_direct"] = "Fidelity Direct";
50 d->m_fqNames["financecanada"] = "Finance Canada";
51 d->m_fqNames["ftportfolios"] = "First Trust (First Trust, ...)";
52 d->m_fqNames["ftportfolios_direct"] = "First Trust Portfolios";
53 d->m_fqNames["fundlibrary"] = "Fund Library";
54 d->m_fqNames["greece"] = "Greece (ASE, ...)";
55 d->m_fqNames["indiamutual"] = "India Mutual (AMFI, ...)";
56 d->m_fqNames["maninv"] = "Man Investments";
57 d->m_fqNames["fool"] = "Motley Fool";
58 d->m_fqNames["nasdaq"] = "Nasdaq (Yahoo, ...)";
59 d->m_fqNames["nz"] = "New Zealand (Yahoo, ...)";
60 d->m_fqNames["nyse"] = "NYSE (Yahoo, ...)";
61 d->m_fqNames["nzx"] = "NZX";
62 d->m_fqNames["platinum"] = "Platinum Asset Management";
63 d->m_fqNames["seb_funds"] = "SEB";
64 d->m_fqNames["sharenet"] = "Sharenet";
65 d->m_fqNames["za"] = "South Africa (Sharenet, ...)";
66 d->m_fqNames["troweprice_direct"] = "T. Rowe Price";
67 d->m_fqNames["troweprice"] = "T. Rowe Price";
68 d->m_fqNames["tdefunds"] = "TD Efunds";
69 d->m_fqNames["tdwaterhouse"] = "TD Waterhouse Canada";
70 d->m_fqNames["tiaacref"] = "TIAA-CREF";
71 d->m_fqNames["trustnet"] = "Trustnet";
72 d->m_fqNames["uk_unit_trusts"] = "U.K. Unit Trusts";
73 d->m_fqNames["unionfunds"] = "Union Investments";
74 d->m_fqNames["tsp"] = "US Govt. Thrift Savings Plan";
75 d->m_fqNames["usfedbonds"] = "US Treasury Bonds";
76 d->m_fqNames["usa"] = "USA (Yahoo, Fool ...)";
77 d->m_fqNames["vanguard"] = "Vanguard";
78 d->m_fqNames["vwd"] = "VWD";
79 d->m_fqNames["yahoo"] = "Yahoo";
80 d->m_fqNames["yahoo_asia"] = "Yahoo Asia";
81 d->m_fqNames["yahoo_australia"] = "Yahoo Australia";
82 d->m_fqNames["yahoo_brasil"] = "Yahoo Brasil";
83 d->m_fqNames["yahoo_europe"] = "Yahoo Europe";
84 d->m_fqNames["yahoo_nz"] = "Yahoo New Zealand";
85 d->m_fqNames["zifunds"] = "Zuerich Investments";
86 connect(this, SIGNAL(readyReadStandardOutput()), this, SLOT(slotReceivedDataFromFilter()));
87 connect(this, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(slotProcessExited()));
88 connect(this, SIGNAL(error(QProcess::ProcessError)), this, SLOT(slotProcessExited()));
89}
90
91void AlkFinanceQuoteProcess::slotReceivedDataFromFilter()
92{
94
95// kDebug(2) << "WebPriceQuoteProcess::slotReceivedDataFromFilter(): " << QString(data);
96 d->m_string += QString(data);
97}
98
99void AlkFinanceQuoteProcess::slotProcessExited()
100{
101// kDebug(2) << "WebPriceQuoteProcess::slotProcessExited()";
102 d->m_isDone = true;
103}
104
106{
107 clearProgram();
108
109 qDebug() << "running perl" << scriptPath << "-t";
110
111 *this << "perl" << scriptPath << "-t";
113 start();
114 if (!waitForStarted()) {
115 qWarning("Unable to start FQ script");
116 }
117}
118
119void AlkFinanceQuoteProcess::launch(const QString &scriptPath)
120{
121 clearProgram();
122
123 qDebug() << "running" << "perl" << scriptPath << "-l";
124
125 *this << "perl" << scriptPath << "-l";
127 start();
128 if (!waitForStarted()) {
129 qWarning("Unable to start FQ script");
130 }
131}
132
133bool AlkFinanceQuoteProcess::isFinished() const
134{
135 return d->m_isDone;
136}
137
138const QStringList AlkFinanceQuoteProcess::getSourceList() const
139{
140 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
141 QStringList raw = d->m_string.split('\r', QString::SkipEmptyParts);
142 #else
143 QStringList raw = d->m_string.split('\r', Qt::SkipEmptyParts);
144 #endif
145 QStringList sources;
147 for (it = raw.begin(); it != raw.end(); ++it) {
148 if (d->m_fqNames[*it].isEmpty()) {
149 sources.append(*it);
150 } else {
151 sources.append(d->m_fqNames[*it]);
152 }
153 }
154 sources.sort();
155 return sources;
156}
157
158const QString AlkFinanceQuoteProcess::crypticName(const QString &niceName) const
159{
160 QString ret(niceName);
161 Private::fqNameMap::const_iterator it;
162 for (it = d->m_fqNames.begin(); it != d->m_fqNames.end(); ++it) {
163 if (niceName == it.value()) {
164 ret = it.key();
165 break;
166 }
167 }
168 return ret;
169}
170
171const QString AlkFinanceQuoteProcess::niceName(const QString &crypticName) const
172{
173 QString ret(d->m_fqNames[crypticName]);
174 if (ret.isEmpty()) {
175 ret = crypticName;
176 }
177 return ret;
178}
void testLaunch(const QString &scriptPath)
Check that all modules for Finance::Quote are installed.
void start()
void clearProgram()
void setOutputChannelMode(OutputChannelMode mode)
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
void append(QList< T > &&value)
iterator begin()
iterator end()
iterator begin()
iterator end()
bool isEmpty() const const
QByteArray readAllStandardOutput()
bool waitForStarted(int msecs)
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
void sort(Qt::CaseSensitivity cs)
SkipEmptyParts
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
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.