File indexing completed on 2024-04-28 05:02:31

0001 /*
0002     SPDX-FileCopyrightText: 2004 Ace Jones acejones @users.sourceforge.net
0003     SPDX-FileCopyrightText: 2019 Thomas Baumgart tbaumgart @kde.org
0004     SPDX-FileCopyrightText: 2024 Ralf Habacker ralf.habacker @freenet.de
0005 
0006     This file is part of libalkimia.
0007 
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #ifndef ALKONLINEQUOTE_PRIVATE_H
0012 #define ALKONLINEQUOTE_PRIVATE_H
0013 
0014 #include "alkonlinequote.h"
0015 
0016 #ifdef ENABLE_FINANCEQUOTE
0017 #include "alkonlinequoteprocess.h"
0018 #endif
0019 #include "alkonlinequotesource.h"
0020 
0021 #if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
0022     #define KUrl QUrl
0023     #define prettyUrl() toDisplayString()
0024     #include <QUrl>
0025 #else
0026     #include <KUrl>
0027 #endif
0028 #ifdef BUILD_WITH_QTNETWORK
0029 class QNetworkReply;
0030 #else
0031 class KJob;
0032 #endif
0033 
0034 #include <QApplication>
0035 #include <QByteArray>
0036 #include <QFile>
0037 #include <QTextStream>
0038 #include <QTextCodec>
0039 #include <QTimer>
0040 
0041 class ALK_EXPORT AlkOnlineQuote::Private : public QObject
0042 {
0043     Q_OBJECT
0044 public:
0045     AlkOnlineQuote *m_p;
0046 #ifdef ENABLE_FINANCEQUOTE
0047     AlkOnlineQuoteProcess m_filter;
0048 #endif
0049     QString m_quoteData;
0050     QString m_symbol;
0051     QString m_id;
0052     QDate m_startDate;
0053     QDate m_endDate;
0054     QDate m_date;
0055     double m_price;
0056     AlkOnlineQuoteSource m_source;
0057     AlkOnlineQuote::Errors m_errors;
0058     KUrl m_url;
0059     QEventLoop *m_eventLoop;
0060     QString m_acceptLanguage;
0061     AlkOnlineQuotesProfile *m_profile;
0062     bool m_ownProfile;
0063     int m_timeout;
0064     bool m_useSingleQuoteSignal{false};
0065 
0066 #if QT_VERSION < QT_VERSION_CHECK(5,0,0)
0067     static int dbgArea();
0068 #endif
0069 
0070     explicit Private(AlkOnlineQuote *parent);
0071 
0072     ~Private();
0073 
0074     bool initLaunch(const QString &_symbol, const QString &_id, const QString &_source);
0075     bool launchWebKitCssSelector(const QString &_symbol, const QString &_id,
0076                                  const QString &_source);
0077     bool launchWebKitHtmlParser(const QString &_symbol, const QString &_id, const QString &_source);
0078     bool launchNative(const QString &_symbol, const QString &_id, const QString &_source);
0079     bool launchFinanceQuote(const QString& _symbol, const QString& _id, const QString& _source);
0080     bool parsePrice(const QString &pricestr);
0081     bool parseDate(const QString &datestr);
0082     bool parseQuoteStripHTML(const QString &quotedata);
0083     bool parseQuoteHTML(const QString &quotedata);
0084     bool parseQuoteCSV(const QString &quotedata);
0085     bool downloadUrl(const KUrl& url);
0086     bool processDownloadedFile(const KUrl& url, const QString& tmpFile);
0087     bool processDownloadedPage(const KUrl &url, const QByteArray &page);
0088 #ifdef ENABLE_FINANCEQUOTE
0089     bool processLocalScript(const KUrl& url);
0090 #endif
0091 
0092 public Q_SLOTS:
0093     void slotLoadStarted();
0094     void slotLoadFinishedHtmlParser(bool ok = false);
0095     void slotLoadFinishedCssSelector(bool ok);
0096     bool slotParseQuote(const QString &quotedata);
0097 
0098 private Q_SLOTS:
0099     void slotLoadTimeout();
0100 #ifndef BUILD_WITH_QTNETWORK
0101     void downloadUrlDone(KJob* job);
0102 #else
0103     void downloadUrlDone(QNetworkReply *reply);
0104 #endif
0105 };
0106 
0107 #endif // ALKONLINEQUOTE_PRIVATE_H