10#include "alkonlinequotesprofile.h"
14#include "alkonlinequotesource.h"
15#include "alkonlinequotesprofilemanager.h"
17#include "alkonlinequotesprofile_p.h"
19#include <KSharedConfig>
21#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
22#include <QRegularExpression>
23#include <QStandardPaths>
27#include <KStandardDirs>
31AlkOnlineQuotesProfile::AlkOnlineQuotesProfile(
const QString &name, Type type,
33 : d(new Private(this))
36 d->m_GHNSFile = ghnsConfigFile;
38 if (type == Type::KMyMoney5)
39 d->m_kconfigFile =
QString(
"%1/kmymoney/kmymoneyrc").arg(d->configPath());
40 else if (type == Type::KMyMoney4)
41 d->m_kconfigFile =
QString(
"%1/kmymoneyrc").arg(d->configPath());
42 else if (type == Type::Alkimia5 || type == Type::Alkimia4)
43 d->m_kconfigFile =
QString(
"%1/alkimiarc").arg(d->configPath());
44 else if (type == Type::Test)
45 d->m_kconfigFile =
QString(
"%1/alkimiatestrc").arg(d->configPath());
47 d->m_kconfigFile.
clear();
49 if (!d->m_kconfigFile.isEmpty()) {
50 d->m_config = KSharedConfig::openConfig(d->m_kconfigFile, KConfig::SimpleConfig);
51 alkDebug() << d->m_config;
54 if (!d->m_GHNSFile.isEmpty()) {
55 QString ghnsFile = hotNewStuffConfigFile();
56 KConfig ghnsConfig(ghnsFile);
57 KConfigGroup group = ghnsConfig.group(
"KNewStuff3");
58 d->m_GHNSFilePath = group.readEntry(
"TargetDir");
59 d->m_engine->init(ghnsFile);
60 d->m_engine->checkForUpdates();
64AlkOnlineQuotesProfile::~AlkOnlineQuotesProfile()
69QString AlkOnlineQuotesProfile::name()
const
74QString AlkOnlineQuotesProfile::hotNewStuffConfigFile()
const
76#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
82 QString configFile = KStandardDirs::locate(
"config", d->m_GHNSFile);
84 configFile = KStandardDirs::locate(
"data",
"knsrcfiles/" + d->m_GHNSFile);
88 configFile =
QString(
"%1/%2").
arg(KNSRC_DIR, d->m_GHNSFile);
94QString AlkOnlineQuotesProfile::hotNewStuffReadFilePath(
const QString &fileName)
const
96 for (
const QString &path : hotNewStuffReadPath()) {
99 return f.absoluteFilePath();
104QString AlkOnlineQuotesProfile::hotNewStuffWriteFilePath(
const QString &fileName)
const
106 return QString(
"%1%2").
arg(hotNewStuffWriteDir(), fileName);
109QStringList AlkOnlineQuotesProfile::hotNewStuffReadPath()
const
112 <<
QString(
"%1/%2/").
arg(d->dataReadPath(), d->m_GHNSFilePath)
113 << hotNewStuffWriteDir();
116QString AlkOnlineQuotesProfile::hotNewStuffWriteDir()
const
118 return QString(
"%1/%2/").
arg(d->dataWritePath(), d->m_GHNSFilePath);
121QString AlkOnlineQuotesProfile::hotNewStuffRelPath()
const
123 return d->m_GHNSFilePath;
126QString AlkOnlineQuotesProfile::kConfigFile()
const
128 return d->m_kconfigFile;
131KSharedConfigPtr AlkOnlineQuotesProfile::kConfig()
const
136#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
137void AlkOnlineQuotesProfile::setKConfig(KSharedConfigPtr kconfig)
139 d->m_config = kconfig;
143void AlkOnlineQuotesProfile::reload()
149AlkOnlineQuotesProfile::Type AlkOnlineQuotesProfile::type()
154bool AlkOnlineQuotesProfile::typeIsSupported()
const
156#ifndef ENABLE_FINANCEQUOTE
157 if (d->m_type == Type::Script) {
164bool AlkOnlineQuotesProfile::typeIsOperational()
const
166 if (d->m_type == Type::Script) {
167#ifdef ENABLE_FINANCEQUOTE
168 if (d->quoteSourcesFinanceQuote().isEmpty()) {
178bool AlkOnlineQuotesProfile::hasGHNSSupport()
180 return !d->m_GHNSFile.isEmpty();
186 case AlkOnlineQuotesProfile::Type::Test:
187 return d->quoteSourcesTesting();
189 return d->defaultQuoteSources();
193const QStringList AlkOnlineQuotesProfile::quoteSources()
197 case AlkOnlineQuotesProfile::Type::Alkimia4:
198 case AlkOnlineQuotesProfile::Type::Alkimia5:
199 case AlkOnlineQuotesProfile::Type::KMyMoney4:
200 case AlkOnlineQuotesProfile::Type::KMyMoney5:
201 result << d->quoteSourcesNative();
203#ifdef ENABLE_FINANCEQUOTE
204 case AlkOnlineQuotesProfile::Type::Script:
205 result << d->quoteSourcesFinanceQuote();
208 case AlkOnlineQuotesProfile::Type::None:
209 result << d->defaultQuoteSources().keys();
211 case AlkOnlineQuotesProfile::Type::Test:
212 result << d->quoteSourcesNative();
217 if (hasGHNSSupport())
218 result << d->quoteSourcesGHNS();
224 return d->quoteSourcesTesting();
227void AlkOnlineQuotesProfile::setManager(AlkOnlineQuotesProfileManager *manager)
229 d->m_profileManager = manager;
232AlkOnlineQuotesProfileManager *AlkOnlineQuotesProfile::manager()
234 return d->m_profileManager;
237QString AlkOnlineQuotesProfile::scriptPath()
239 return d->m_financeQuoteScriptPath;
244 return d->GHNSId(name);
247QString AlkOnlineQuotesProfile::GHNSFilePath(
const QString &name)
const
249 return d->GHNSFilePath(name);
254 return d->GHNSName(
id);
Wrapper for debug output.
Type type(const QSqlDatabase &db)
QString name(StandardAction id)
QString locate(StandardLocation type, const QString &fileName, LocateOptions options)
QString arg(Args &&... args) const const
bool isEmpty() const const