Changeset View
Changeset View
Standalone View
Standalone View
src/alkonlinequotesprofile.cpp
1 | /*************************************************************************** | 1 | /*************************************************************************** | ||
---|---|---|---|---|---|
2 | * Copyright 2018 Ralf Habacker <ralf.habacker@freenet.de> * | 2 | * Copyright 2018 Ralf Habacker <ralf.habacker@freenet.de> * | ||
3 | * Copyright 2019 Thomas Baumgart <tbaumgart@kde.org> * | ||||
3 | * * | 4 | * * | ||
4 | * This file is part of libalkimia. * | 5 | * This file is part of libalkimia. * | ||
5 | * * | 6 | * * | ||
6 | * libalkimia is free software; you can redistribute it and/or * | 7 | * libalkimia is free software; you can redistribute it and/or * | ||
7 | * modify it under the terms of the GNU Lesser General Public License * | 8 | * modify it under the terms of the GNU Lesser General Public License * | ||
8 | * as published by the Free Software Foundation; either version 2.1 of * | 9 | * as published by the Free Software Foundation; either version 2.1 of * | ||
9 | * the License or (at your option) version 3 or any later version. * | 10 | * the License or (at your option) version 3 or any later version. * | ||
10 | * * | 11 | * * | ||
Show All 15 Lines | |||||
26 | #include <QApplication> | 27 | #include <QApplication> | ||
27 | #include <QDir> | 28 | #include <QDir> | ||
28 | #include <QString> | 29 | #include <QString> | ||
29 | #include <QtDebug> | 30 | #include <QtDebug> | ||
30 | #include <QFileInfo> | 31 | #include <QFileInfo> | ||
31 | 32 | | |||
32 | #include <KConfig> | 33 | #include <KConfig> | ||
33 | #include <KConfigGroup> | 34 | #include <KConfigGroup> | ||
35 | | ||||
36 | #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) | ||||
37 | #include <QStandardPaths> | ||||
38 | #else | ||||
34 | #include <KGlobal> | 39 | #include <KGlobal> | ||
35 | #include <KStandardDirs> | 40 | #include <KStandardDirs> | ||
41 | #endif | ||||
36 | #include <knewstuff3/downloadmanager.h> | 42 | #include <knewstuff3/downloadmanager.h> | ||
37 | 43 | | |||
38 | class AlkOnlineQuotesProfile::Private : public QObject | 44 | class AlkOnlineQuotesProfile::Private : public QObject | ||
39 | { | 45 | { | ||
40 | Q_OBJECT | 46 | Q_OBJECT | ||
41 | public: | 47 | public: | ||
42 | AlkOnlineQuotesProfile *m_p; | 48 | AlkOnlineQuotesProfile *m_p; | ||
43 | QString m_name; | 49 | QString m_name; | ||
44 | QString m_GHNSFile; | 50 | QString m_GHNSFile; | ||
45 | QString m_GHNSFilePath; | 51 | QString m_GHNSFilePath; | ||
46 | QString m_kconfigFile; | 52 | QString m_kconfigFile; | ||
47 | AlkOnlineQuotesProfileManager *m_profileManager; | 53 | AlkOnlineQuotesProfileManager *m_profileManager; | ||
48 | KNS3::DownloadManager *m_manager; | 54 | KNS3::DownloadManager *m_manager; | ||
49 | KConfig *m_config; | 55 | KConfig *m_config; | ||
50 | Type m_type; | 56 | Type m_type; | ||
51 | static QString m_financeQuoteScriptPath; | 57 | static QString m_financeQuoteScriptPath; | ||
52 | static QStringList m_financeQuoteSources; | 58 | static QStringList m_financeQuoteSources; | ||
53 | 59 | | |||
60 | bool setupFinanceQuoteScriptPath() | ||||
61 | { | ||||
62 | if (m_financeQuoteScriptPath.isEmpty()) { | ||||
63 | #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) | ||||
64 | m_financeQuoteScriptPath = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("misc/financequote.pl")); | ||||
65 | #else | ||||
66 | m_financeQuoteScriptPath = KGlobal::dirs()->findResource("appdata", | ||||
67 | QString("misc/financequote.pl")); | ||||
68 | #endif | ||||
69 | } | ||||
70 | return !m_financeQuoteScriptPath.isEmpty(); | ||||
71 | } | ||||
72 | | ||||
54 | Private(AlkOnlineQuotesProfile *p) | 73 | Private(AlkOnlineQuotesProfile *p) | ||
55 | : m_p(p) | 74 | : m_p(p) | ||
56 | , m_profileManager(0) | 75 | , m_profileManager(0) | ||
57 | , m_manager(0) | 76 | , m_manager(0) | ||
58 | , m_config(0) | 77 | , m_config(0) | ||
59 | , m_type(Type::Undefined) | 78 | , m_type(Type::Undefined) | ||
60 | { | 79 | { | ||
61 | 80 | setupFinanceQuoteScriptPath(); | |||
62 | if (m_financeQuoteScriptPath.isEmpty()) { | | |||
63 | m_financeQuoteScriptPath = KGlobal::dirs()->findResource("appdata", | | |||
64 | QString("misc/financequote.pl")); | | |||
65 | } | | |||
66 | } | 81 | } | ||
67 | 82 | | |||
68 | ~Private() | 83 | ~Private() | ||
69 | { | 84 | { | ||
70 | delete m_manager; | 85 | delete m_manager; | ||
71 | delete m_config; | 86 | delete m_config; | ||
72 | } | 87 | } | ||
73 | 88 | | |||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | 117 | { | |||
134 | return groups; | 149 | return groups; | ||
135 | } | 150 | } | ||
136 | 151 | | |||
137 | const QStringList quoteSourcesFinanceQuote() | 152 | const QStringList quoteSourcesFinanceQuote() | ||
138 | { | 153 | { | ||
139 | if (m_financeQuoteSources.empty()) { // run the process one time only | 154 | if (m_financeQuoteSources.empty()) { // run the process one time only | ||
140 | // since this is a static function it can be called without constructing an object | 155 | // since this is a static function it can be called without constructing an object | ||
141 | // so we need to make sure that m_financeQuoteScriptPath is properly initialized | 156 | // so we need to make sure that m_financeQuoteScriptPath is properly initialized | ||
142 | if (m_financeQuoteScriptPath.isEmpty()) { | 157 | if (setupFinanceQuoteScriptPath()) { | ||
143 | m_financeQuoteScriptPath = KGlobal::dirs()->findResource("appdata", | | |||
144 | QString("financequote.pl")); | | |||
145 | } | | |||
146 | AlkFinanceQuoteProcess getList; | 158 | AlkFinanceQuoteProcess getList; | ||
147 | getList.launch(m_financeQuoteScriptPath); | 159 | getList.launch(m_financeQuoteScriptPath); | ||
148 | while (!getList.isFinished()) { | 160 | while (!getList.isFinished()) { | ||
149 | qApp->processEvents(); | 161 | qApp->processEvents(); | ||
150 | } | 162 | } | ||
151 | m_financeQuoteSources = getList.getSourceList(); | 163 | m_financeQuoteSources = getList.getSourceList(); | ||
152 | } | 164 | } | ||
165 | } | ||||
153 | return m_financeQuoteSources; | 166 | return m_financeQuoteSources; | ||
154 | } | 167 | } | ||
155 | 168 | | |||
156 | const QStringList quoteSourcesSkrooge() | 169 | const QStringList quoteSourcesSkrooge() | ||
157 | { | 170 | { | ||
158 | return quoteSourcesGHNS(); | 171 | return quoteSourcesGHNS(); | ||
159 | } | 172 | } | ||
160 | 173 | | |||
161 | const QStringList quoteSourcesGHNS() | 174 | const QStringList quoteSourcesGHNS() | ||
162 | { | 175 | { | ||
163 | QStringList sources; | 176 | QStringList sources; | ||
164 | QString relPath = m_GHNSFilePath; | 177 | const QString filename = QString("%1/*.txt").arg(m_GHNSFilePath); | ||
165 | 178 | | |||
166 | foreach (const QString &file, | 179 | #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) | ||
167 | KStandardDirs().findAllResources("data", relPath + QString::fromLatin1("/*.txt"))) { | 180 | const auto resources = QStandardPaths::locateAll(QStandardPaths::DataLocation, filename); | ||
181 | #else | ||||
182 | const QStringList resources = KStandardDirs().findAllResources("data", filename); | ||||
183 | #endif | ||||
184 | foreach (const QString &file, resources) { | ||||
168 | QFileInfo f(file); | 185 | QFileInfo f(file); | ||
169 | QString file2 = f.completeBaseName(); | 186 | QString file2 = f.completeBaseName(); | ||
170 | AlkOnlineQuoteSource source(file2, m_p); | 187 | AlkOnlineQuoteSource source(file2, m_p); | ||
171 | if (source.isEmpty()) { | 188 | if (source.isEmpty()) { | ||
172 | qDebug() << "skipping" << file2; | 189 | qDebug() << "skipping" << file2; | ||
173 | continue; | 190 | continue; | ||
174 | } | 191 | } | ||
175 | if (!sources.contains(file2)) { | 192 | if (!sources.contains(file2)) { | ||
▲ Show 20 Lines • Show All 107 Lines • ▼ Show 20 Line(s) | |||||
283 | 300 | | |||
284 | QString AlkOnlineQuotesProfile::name() const | 301 | QString AlkOnlineQuotesProfile::name() const | ||
285 | { | 302 | { | ||
286 | return d->m_name; | 303 | return d->m_name; | ||
287 | } | 304 | } | ||
288 | 305 | | |||
289 | QString AlkOnlineQuotesProfile::hotNewStuffConfigFile() const | 306 | QString AlkOnlineQuotesProfile::hotNewStuffConfigFile() const | ||
290 | { | 307 | { | ||
308 | #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) | ||||
309 | QString configFile = QStandardPaths::locate(QStandardPaths::AppConfigLocation, d->m_GHNSFile); | ||||
310 | #else | ||||
291 | QString configFile = KStandardDirs::locate("config", d->m_GHNSFile); | 311 | QString configFile = KStandardDirs::locate("config", d->m_GHNSFile); | ||
312 | #endif | ||||
292 | if (configFile.isEmpty()) { | 313 | if (configFile.isEmpty()) { | ||
293 | configFile = QString("%1/%2").arg(KNSRC_DIR, d->m_GHNSFile); | 314 | configFile = QString("%1/%2").arg(KNSRC_DIR, d->m_GHNSFile); | ||
294 | } | 315 | } | ||
295 | 316 | | |||
296 | return configFile; | 317 | return configFile; | ||
297 | } | 318 | } | ||
298 | 319 | | |||
299 | QString AlkOnlineQuotesProfile::hotNewStuffReadFilePath(const QString &fileName) const | 320 | QString AlkOnlineQuotesProfile::hotNewStuffReadFilePath(const QString &fileName) const | ||
▲ Show 20 Lines • Show All 91 Lines • Show Last 20 Lines |