diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ find_package(ECM 0.0.11 REQUIRED NO_MODULE) -set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) include(KDEInstallDirs) include(KDECMakeSettings) @@ -63,12 +63,15 @@ find_package(KF5 REQUIRED COMPONENTS Config CoreAddons - KDELibs4Support - #I18n - #WebKit + Completion + I18n Package Plasma NewStuff + KIO + IconThemes + TextWidgets + OPTIONAL_COMPONENTS ${OPT_KF5_COMPONENTS} ) set(QT_USE_LIBSPREFIX Qt5::) @@ -83,14 +86,6 @@ if(CMAKE_COMPILER_IS_GNUCC) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations") endif() - add_definitions( - -DKDELIBS4SUPPORT_EXPORT_WRAPPER_H - -DKDELIBS4SUPPORT_DEPRECATED_NOISE= - -DKDELIBS4SUPPORT_DEPRECATED_EXPORT_NOISE=Q_DECL_IMPORT - -DKDELIBS4SUPPORT_DEPRECATED= - -DKDELIBS4SUPPORT_DEPRECATED_EXPORT=Q_DECL_IMPORT - -DKDELIBS4SUPPORT_EXPORT=Q_DECL_IMPORT - ) endif() # figure out which multi-precision library to use diff --git a/Messages.sh b/Messages.sh new file mode 100644 --- /dev/null +++ b/Messages.sh @@ -0,0 +1,11 @@ +#!bin/sh +# invoke the extractrc script on all .ui, .rc, and .kcfg files in the sources +# the results are stored in a pseudo .cpp file to be picked up by xgettext. +$EXTRACTRC `find . -name \*.rc -o -name \*.ui -o -name \*.kcfg` >> rc.cpp + +# call xgettext on all source files. If your sources have other filename +# extensions besides .cpp, and .h, just add them in the find call. +$XGETTEXT `find . -name \*.cpp -o -name \*.h` -o $podir/alkimia.pot + +# Remove these two generated files again +rm rc.cpp diff --git a/plasma/applets/ForeignCurrencies/Messages.sh b/plasma/applets/ForeignCurrencies/Messages.sh new file mode 100644 --- /dev/null +++ b/plasma/applets/ForeignCurrencies/Messages.sh @@ -0,0 +1,11 @@ +#!bin/sh +# invoke the extractrc script on all .ui, .rc, and .kcfg files in the sources +# the results are stored in a pseudo .cpp file to be picked up by xgettext. +$EXTRACTRC `find . -name \*.rc -o -name \*.ui -o -name \*.kcfg` >> rc.cpp + +# call xgettext on all source files. If your sources have other filename +# extensions besides .cpp, and .h, just add them in the find call. +$XGETTEXT `find . -name \*.cpp -o -name \*.h -o -name \*.qml` -o $podir/alkimia-plasma-foreign-currencies.pot + +# Remove these two generated files again +rm rc.cpp diff --git a/plasma/applets/ForeignCurrencies/contents/ui/config/ConfigGeneral.qml b/plasma/applets/ForeignCurrencies/contents/ui/config/ConfigGeneral.qml --- a/plasma/applets/ForeignCurrencies/contents/ui/config/ConfigGeneral.qml +++ b/plasma/applets/ForeignCurrencies/contents/ui/config/ConfigGeneral.qml @@ -35,7 +35,7 @@ Dialog { id: addCurrencyDialog - title: i18n('Add Currency Pair') + title: i18n("Add Currency Pair") width: 300 @@ -52,7 +52,7 @@ TextField { id: symbolField - placeholderText: i18n('Paste currency pair symbol here') + placeholderText: i18n("Paste currency pair symbol here") width: parent.width } @@ -64,7 +64,7 @@ anchors.right: parent.right Label { - text: i18n('Currency Pairs') + text: i18n("Currency Pairs") font.bold: true Layout.alignment: Qt.AlignLeft } @@ -78,7 +78,7 @@ TableViewColumn { id: symbolIdCol role: 'symbolId' - title: i18n('Symbol') + title: i18n("Symbol") // width: parent.width * 0.6 delegate: Label { @@ -93,7 +93,7 @@ TableViewColumn { - title: i18n('Action') + title: i18n("Action") // width: parent.width * 0.2 delegate: Item { diff --git a/plasma/applets/ForeignCurrencies/metadata.desktop b/plasma/applets/ForeignCurrencies/metadata.desktop --- a/plasma/applets/ForeignCurrencies/metadata.desktop +++ b/plasma/applets/ForeignCurrencies/metadata.desktop @@ -1,27 +1,20 @@ [Desktop Entry] Encoding=UTF-8 Name=Foreign Currencies -Name[ca]=Monedes estrangeres -Name[ca@valencia]=Monedes estrangeres -Name[cs]=Cizí měny -Name[de]=Ausländische Währungen Name[es]=Monedas extranjeras Name[fr]=Devises étrangères +Name[gl]=Divisas estranxeiras Name[nl]=Vreemde valuta Name[pt]=Moedas Estrangeiras -Name[sk]=Zahraničné meny Name[sv]=Utländska valutor -Name[uk]=Іноземні валюти Name[x-test]=xxForeign Currenciesxx Comment=Plasmoid showing current foreign currencies prices. Fork of Foreign Currencies plasmoid by bravenec2nd. -Comment[ca]=Plasmoide que mostra els preus actuals de les monedes estrangeres. Bifurcació del plasmoide monedes estrangeres per en «bravenec2nd». -Comment[ca@valencia]=Plasmoide que mostra els preus actuals de les monedes estrangeres. Bifurcació del plasmoide monedes estrangeres per en «bravenec2nd». Comment[es]=Plasmoide para mostrar los precios actuales de monedas extranjeras. Bifurcación del plasmoide «Monedas extranjeras» de bravenec2nd. Comment[fr]=Composant graphique affichant les taux de change en vigueur de devises étrangères. Fork du composant graphique Foreign Currencies de bravenec2nd. +Comment[gl]=Plasmoide que mostra os prezos actuais de divisas estranxeiras. Nacido do plasmoide de divisas estranxeiras de bravenec2nd. Comment[nl]=Plasmoid die huidige koersen van vreemde valuta toont. Afsplitsing van plasmoid Vreemde valuta door bravenec2nd. -Comment[pt]=Plasmóide que mostra os preços actuais das moedas estrangeiras. Derivado do plasmóide de Moedas Estrangeiras de 'bravenec2nd'. +Comment[pt]=Plasmóide que mostra os preços das moedas estrangeiras actuais. Nova versão do plasmóide de Moedas Estrangeiras do 'bravenec2nd'. Comment[sv]=Plasmoid som visar aktuella utländska valutakurser. Avknoppning av plasmoiden Foreign Currencies av bravenec2nd. -Comment[uk]=Плазмоїд для показу курсів іноземних валют. Відгалуження плазмоїда курсів іноземних валют, автором якого є bravenec2nd. Comment[x-test]=xxPlasmoid showing current foreign currencies prices. Fork of Foreign Currencies plasmoid by bravenec2nd.xx Type=Service Icon=applications-internet diff --git a/plasma/applets/onlinequote/CMakeLists.txt b/plasma/applets/onlinequote/CMakeLists.txt --- a/plasma/applets/onlinequote/CMakeLists.txt +++ b/plasma/applets/onlinequote/CMakeLists.txt @@ -22,6 +22,7 @@ KF5::Package KF5::Plasma ) + add_definitions(-DTRANSLATION_DOMAIN=\"alkimia-plasma-onlinequote\") endif() install(TARGETS plasma_applet_onlinequote diff --git a/plasma/applets/onlinequote/Messages.sh b/plasma/applets/onlinequote/Messages.sh new file mode 100644 --- /dev/null +++ b/plasma/applets/onlinequote/Messages.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +# invoke the extractrc script on all .ui, .rc, and .kcfg files in the sources +# the results are stored in a pseudo .cpp file to be picked up by xgettext. +$EXTRACTRC `find . -name \*.rc -o -name \*.ui -o -name \*.kcfg` >> rc.cpp + +# call xgettext on all source files. If your sources have other filename +# extensions besides .cc, .cpp, and .h, just add them in the find call. +$XGETTEXT `find . -name \*.cc -o -name \*.cpp -o -name \*.h -name \*.qml` -o $podir/alkimia-plasma-onlinequote.pot + +# Remove this generated files +rm rc.cpp + diff --git a/plasma/applets/onlinequote/plasma-applet-onlinequote.desktop b/plasma/applets/onlinequote/plasma-applet-onlinequote.desktop --- a/plasma/applets/onlinequote/plasma-applet-onlinequote.desktop +++ b/plasma/applets/onlinequote/plasma-applet-onlinequote.desktop @@ -1,25 +1,19 @@ [Desktop Entry] Name=Online Quote -Name[ca]=Cotització en línia -Name[ca@valencia]=Cotització en línia -Name[de]=Online-Kursnotizen Name[es]=Cotización en línea Name[fr]=Cotation en ligne +Name[gl]=Cotización por internet Name[nl]=Online koersen Name[pt]=Cotação 'Online' Name[sv]=Direktkurs -Name[uk]=Інтернет-курс Name[x-test]=xxOnline Quotexx Comment=Plasma applet for an online quote -Comment[ca]=Miniaplicació del Plasma per a una cotització en línia -Comment[ca@valencia]=Miniaplicació del Plasma per a una cotització en línia -Comment[de]=Plasma-Miniprogramm für Online-Kursnotizen Comment[es]=Miniaplicación de Plasma para cotizaciones en línea Comment[fr]=Composant graphique plasma pour les cotations en ligne +Comment[gl]=Miniaplicativo de Plasma para cotizacións por internet Comment[nl]=Plasma-applet voor een online valutakoers -Comment[pt]=Elemento do Plasma para obter cotações 'online' +Comment[pt]=Elemento do Plasma para obter uma cotação 'online' Comment[sv]=Plasma-miniprogram för direktkurser -Comment[uk]=Аплет Плазми для інтернет-курсів Comment[x-test]=xxPlasma applet for an online quotexx Type=Service ServiceTypes=Plasma/Applet diff --git a/plasma/applets/onlinequote/plasma-onlinequote.cpp b/plasma/applets/onlinequote/plasma-onlinequote.cpp --- a/plasma/applets/onlinequote/plasma-onlinequote.cpp +++ b/plasma/applets/onlinequote/plasma-onlinequote.cpp @@ -37,7 +37,7 @@ { setHasConfigurationInterface(true); m_svg.setImagePath("widgets/background"); -#if QT_VERSION < 0x050000 +#if QT_VERSION < QT_VERSION_CHECK(5,0,0) // this will get us the standard applet background, for free! setBackgroundHints(DefaultBackground); resize(200, 200); @@ -54,7 +54,7 @@ PlasmaOnlineQuote::~PlasmaOnlineQuote() { -#if QT_VERSION < 0x050000 +#if QT_VERSION < QT_VERSION_CHECK(5,0,0) if (hasFailedToLaunch()) { // Do some cleanup here } else @@ -67,7 +67,7 @@ void PlasmaOnlineQuote::init() { -#if QT_VERSION < 0x050000 +#if QT_VERSION < QT_VERSION_CHECK(5,0,0) // A small demonstration of the setFailedToLaunch function if (m_icon.isNull()) { setFailedToLaunch(true, "No world to say hello"); @@ -175,7 +175,7 @@ qDebug() << "got quote" << date << price; m_date = date; m_price = price; -#if QT_VERSION < 0x050000 +#if QT_VERSION < QT_VERSION_CHECK(5,0,0) update(); #else #warning how to update ui ? diff --git a/qml/qmlalkimiaplugin.h b/qml/qmlalkimiaplugin.h --- a/qml/qmlalkimiaplugin.h +++ b/qml/qmlalkimiaplugin.h @@ -18,7 +18,7 @@ ***************************************************************************/ #include -#if QT_VERSION >= 0x050000 +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) #include #else #include diff --git a/qml/qmlalkimiaplugin.cpp b/qml/qmlalkimiaplugin.cpp --- a/qml/qmlalkimiaplugin.cpp +++ b/qml/qmlalkimiaplugin.cpp @@ -27,6 +27,6 @@ qmlRegisterType(uri, 1, 0, "AlkOnlineQuote"); } -#if QT_VERSION < 0x050000 +#if QT_VERSION < QT_VERSION_CHECK(5,0,0) Q_EXPORT_PLUGIN2(qmlalkimiaplugin, QmlAlkimiaPlugin); #endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -38,7 +38,6 @@ PRIVATE ${QT_USE_LIBSPREFIX}WebKitWidgets KF5::CoreAddons - KF5::KDELibs4Support KF5::NewStuff ) endif() @@ -71,9 +70,7 @@ alkonlinequoteswidget.h ) -set(alkimia_UI - alkonlinequoteswidget.ui -) +set(alkimia_UI alkonlinequoteswidget${ALKIMIA_LIB_SUFFIX}.ui) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/alkvalue.h.in @@ -105,10 +102,17 @@ set(ALKIMIA_LIBS PRIVATE ${QT_USE_LIBSPREFIX}WebKitWidgets - KF5::KDELibs4Support + KF5::Completion + KF5::I18n KF5::NewStuff + KF5::IconThemes + KF5::TextWidgets + KF5::KIOCore + KF5::KIOWidgets ) + add_definitions(-DTRANSLATION_DOMAIN=\"alkimia\") endif() + target_link_libraries(alkimia PRIVATE alkimia-internal diff --git a/src/alkonlinequote.cpp b/src/alkonlinequote.cpp --- a/src/alkonlinequote.cpp +++ b/src/alkonlinequote.cpp @@ -1,5 +1,6 @@ /*************************************************************************** * Copyright 2004 Ace Jones * + * Copyright 2019 Thomas Baumgart * * * * This file is part of libalkimia. * * * @@ -31,21 +32,33 @@ #include #include #include -//#include #include #include #include +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) + #include + #include + #include + #include + #include + #define kDebug(a) qDebug() + #define KIcon QIcon + #define KUrl QUrl + #define prettyUrl() toDisplayString() +#else + #include + #include + #include + #include + #include + #include +#endif + #include -#include #include -#include -#include -#include -#include #include #include -#include AlkOnlineQuote::Errors::Errors() { @@ -94,11 +107,13 @@ AlkOnlineQuotesProfile *m_profile; bool m_ownProfile; +#if QT_VERSION < QT_VERSION_CHECK(5,0,0) static int dbgArea() { static int s_area = KDebug::registerArea("Alkimia (AlkOnlineQuote)"); return s_area; } +#endif Private(AlkOnlineQuote *parent) : m_p(parent) @@ -123,12 +138,17 @@ void enter_loop(); bool parsePrice(const QString &pricestr); bool parseDate(const QString &datestr); + bool downloadUrl(const KUrl& url); + bool processDownloadedFile(const KUrl& url, const QString& tmpFile); public slots: void slotLoadStarted(); void slotLoadFinishedHtmlParser(bool ok); void slotLoadFinishedCssSelector(bool ok); bool slotParseQuote(const QString &_quotedata); + +private slots: + void downloadUrlDone(KJob* job); }; bool AlkOnlineQuote::Private::initLaunch(const QString &_symbol, const QString &_id, const QString &_source) @@ -245,6 +265,7 @@ m_eventLoop = new QEventLoop; m_eventLoop->exec(); delete m_eventLoop; + m_eventLoop = nullptr; disconnect(webPage, SIGNAL(loadStarted()), this, SLOT(slotLoadStarted())); disconnect(webPage, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinishedCssSelector(bool))); @@ -266,6 +287,7 @@ m_eventLoop = new QEventLoop; m_eventLoop->exec(); delete m_eventLoop; + m_eventLoop = nullptr; disconnect(webPage, SIGNAL(loadStarted()), this, SLOT(slotLoadStarted())); disconnect(webPage, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinishedHtmlParser(bool))); @@ -301,41 +323,102 @@ } } else { slotLoadStarted(); + result = downloadUrl(url); + } + return result; +} - QString tmpFile; - if (KIO::NetAccess::download(url, tmpFile, 0)) { - // kDebug(Private::dbgArea()) << "Downloaded " << tmpFile; - kDebug(Private::dbgArea()) << "Downloaded" << tmpFile << "from" << url; - QFile f(tmpFile); - if (f.open(QIODevice::ReadOnly)) { - // Find out the page encoding and convert it to unicode - QByteArray page = f.readAll(); - KEncodingProber prober(KEncodingProber::Universal); - prober.feed(page); - QTextCodec *codec = QTextCodec::codecForName(prober.encoding()); - if (!codec) { - codec = QTextCodec::codecForLocale(); - } - QString quote = codec->toUnicode(page); - f.close(); - emit m_p->status(i18n("URL found: %1...", url.prettyUrl())); - if (AlkOnlineQuotesProfileManager::instance().webPageEnabled()) - AlkOnlineQuotesProfileManager::instance().webPage()->setContent(quote.toLocal8Bit()); - result = slotParseQuote(quote); - } else { - emit m_p->error(i18n("Failed to open downloaded file")); - m_errors |= Errors::URL; - result = slotParseQuote(QString()); - } - KIO::NetAccess::removeTempFile(tmpFile); - } else { - emit m_p->error(KIO::NetAccess::lastErrorString()); - m_errors |= Errors::URL; - result = slotParseQuote(QString()); - } +bool AlkOnlineQuote::Private::processDownloadedFile(const KUrl& url, const QString& tmpFile) +{ + bool result = false; + + QFile f(tmpFile); + if (f.open(QIODevice::ReadOnly)) { + // Find out the page encoding and convert it to unicode + QByteArray page = f.readAll(); + KEncodingProber prober(KEncodingProber::Universal); + prober.feed(page); + QTextCodec *codec = QTextCodec::codecForName(prober.encoding()); + if (!codec) { + codec = QTextCodec::codecForLocale(); + } + QString quote = codec->toUnicode(page); + f.close(); + emit m_p->status(i18n("URL found: %1...", url.prettyUrl())); + if (AlkOnlineQuotesProfileManager::instance().webPageEnabled()) + AlkOnlineQuotesProfileManager::instance().webPage()->setContent(quote.toLocal8Bit()); + result = slotParseQuote(quote); + } else { + emit m_p->error(i18n("Failed to open downloaded file")); + m_errors |= Errors::URL; + result = slotParseQuote(QString()); + } + return result; +} + +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) +bool AlkOnlineQuote::Private::downloadUrl(const QUrl& url) +{ + QTemporaryFile tmpFile; + tmpFile.open(); + auto tmpFileName = QUrl::fromLocalFile(tmpFile.fileName()); + + m_eventLoop = new QEventLoop; + + KJob *job = KIO::file_copy(url, tmpFileName, -1, KIO::HideProgressInfo | KIO::Overwrite); + connect(job, SIGNAL(result(KJob*)), this, SLOT(downloadUrlDone(KJob*))); + + auto result = m_eventLoop->exec(QEventLoop::ExcludeUserInputEvents); + delete m_eventLoop; + m_eventLoop = nullptr; + + return result; +} + +void AlkOnlineQuote::Private::downloadUrlDone(KJob* job) +{ + QString tmpFileName = dynamic_cast(job)->destUrl().toLocalFile(); + QUrl url = dynamic_cast(job)->srcUrl(); + + bool result; + if (!job->error()) { + qDebug() << "Downloaded" << tmpFileName << "from" << url; + result = processDownloadedFile(url, tmpFileName); + } else { + emit m_p->error(job->errorString()); + m_errors |= Errors::URL; + result = slotParseQuote(QString()); + } + m_eventLoop->exit(result); +} + +#else + +// This is simply a placeholder. It is unused but needs to be present +// to make the linker happy (since the declaration of the slot cannot +// be made dependendant on QT_VERSION with the Qt4 moc compiler. +void AlkOnlineQuote::Private::downloadUrlDone(KJob* job) +{ +} + +bool AlkOnlineQuote::Private::downloadUrl(const KUrl& url) +{ + bool result = false; + + QString tmpFile; + if (KIO::NetAccess::download(url, tmpFile, 0)) { + // kDebug(Private::dbgArea()) << "Downloaded " << tmpFile; + kDebug(Private::dbgArea()) << "Downloaded" << tmpFile << "from" << url; + result = processDownloadedFile(url, tmpFile); + KIO::NetAccess::removeTempFile(tmpFile); + } else { + emit m_p->error(KIO::NetAccess::lastErrorString()); + m_errors |= Errors::URL; + result = slotParseQuote(QString()); } return result; } +#endif bool AlkOnlineQuote::Private::launchFinanceQuote(const QString &_symbol, const QString &_id, const QString &_sourcename) diff --git a/src/alkonlinequotesprofile.cpp b/src/alkonlinequotesprofile.cpp --- a/src/alkonlinequotesprofile.cpp +++ b/src/alkonlinequotesprofile.cpp @@ -1,5 +1,6 @@ /*************************************************************************** * Copyright 2018 Ralf Habacker * + * Copyright 2019 Thomas Baumgart * * * * This file is part of libalkimia. * * * @@ -31,8 +32,13 @@ #include #include -#include -#include + +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) + #include +#else + #include + #include +#endif #include class AlkOnlineQuotesProfile::Private : public QObject @@ -51,18 +57,27 @@ static QString m_financeQuoteScriptPath; static QStringList m_financeQuoteSources; + bool setupFinanceQuoteScriptPath() + { + if (m_financeQuoteScriptPath.isEmpty()) { +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) + m_financeQuoteScriptPath = QStandardPaths::locate(QStandardPaths::AppDataLocation, QStringLiteral("misc/financequote.pl")); +#else + m_financeQuoteScriptPath = KGlobal::dirs()->findResource("appdata", + QString("misc/financequote.pl")); +#endif + } + return !m_financeQuoteScriptPath.isEmpty(); + } + Private(AlkOnlineQuotesProfile *p) : m_p(p) , m_profileManager(0) , m_manager(0) , m_config(0) , m_type(Type::Undefined) { - - if (m_financeQuoteScriptPath.isEmpty()) { - m_financeQuoteScriptPath = KGlobal::dirs()->findResource("appdata", - QString("misc/financequote.pl")); - } + setupFinanceQuoteScriptPath(); } ~Private() @@ -139,16 +154,14 @@ if (m_financeQuoteSources.empty()) { // run the process one time only // since this is a static function it can be called without constructing an object // so we need to make sure that m_financeQuoteScriptPath is properly initialized - if (m_financeQuoteScriptPath.isEmpty()) { - m_financeQuoteScriptPath = KGlobal::dirs()->findResource("appdata", - QString("financequote.pl")); - } - AlkFinanceQuoteProcess getList; - getList.launch(m_financeQuoteScriptPath); - while (!getList.isFinished()) { - qApp->processEvents(); + if (setupFinanceQuoteScriptPath()) { + AlkFinanceQuoteProcess getList; + getList.launch(m_financeQuoteScriptPath); + while (!getList.isFinished()) { + qApp->processEvents(); + } + m_financeQuoteSources = getList.getSourceList(); } - m_financeQuoteSources = getList.getSourceList(); } return m_financeQuoteSources; } @@ -161,10 +174,14 @@ const QStringList quoteSourcesGHNS() { QStringList sources; - QString relPath = m_GHNSFilePath; - - foreach (const QString &file, - KStandardDirs().findAllResources("data", relPath + QString::fromLatin1("/*.txt"))) { + const QString filename = QString("%1/*.txt").arg(m_GHNSFilePath); + +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) + const auto resources = QStandardPaths::locateAll(QStandardPaths::DataLocation, filename); +#else + const QStringList resources = KStandardDirs().findAllResources("data", filename); +#endif + foreach (const QString &file, resources) { QFileInfo f(file); QString file2 = f.completeBaseName(); AlkOnlineQuoteSource source(file2, m_p); @@ -288,7 +305,11 @@ QString AlkOnlineQuotesProfile::hotNewStuffConfigFile() const { +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) + QString configFile = QStandardPaths::locate(QStandardPaths::AppConfigLocation, d->m_GHNSFile); +#else QString configFile = KStandardDirs::locate("config", d->m_GHNSFile); +#endif if (configFile.isEmpty()) { configFile = QString("%1/%2").arg(KNSRC_DIR, d->m_GHNSFile); } diff --git a/src/alkonlinequoteswidget.cpp b/src/alkonlinequoteswidget.cpp --- a/src/alkonlinequoteswidget.cpp +++ b/src/alkonlinequoteswidget.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright 2004 Thomas Baumgart tbaumgart@kde.org * + * Copyright 2004-2019 Thomas Baumgart tbaumgart@kde.org * * * * This file is part of libalkimia. * * * @@ -31,16 +31,28 @@ #include #include -#include -#include -#include -#include +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) + #include + #include + #include + #include + #define KIcon QIcon +#else + #include + #include + #include + #include + #include +#endif + #include #include -#include -#include -#include +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) + #include +#else + #include +#endif class AlkOnlineQuotesWidget::Private : public QWidget, public Ui::AlkOnlineQuotesWidget { @@ -123,31 +135,40 @@ KIcon("dialog-ok"), i18n("Accepts the entered data and stores it"), i18n("Use this to accept the modified data.")); - m_updateButton->setGuiItem(updateButtenItem); KGuiItem deleteButtenItem(i18n("&Delete"), KIcon("edit-delete"), i18n("Delete the selected source entry"), i18n("Use this to delete the selected online source entry")); - m_deleteButton->setGuiItem(deleteButtenItem); KGuiItem checkButtonItem(i18nc("Check the selected source entry", "&Check Source"), KIcon("document-edit-verify"), i18n("Check the selected source entry"), i18n("Use this to check the selected online source entry")); - m_checkButton->setGuiItem(checkButtonItem); KGuiItem showButtonItem(i18nc("Show the selected source entry in a web browser", "&Show page"), KIcon("applications-internet"), i18n("Show the selected source entry in a web browser"), i18n("Use this to show the selected online source entry")); - m_showButton->setGuiItem(showButtonItem); KGuiItem newButtenItem(i18nc("Create a new source entry for online quotes", "&New..."), KIcon("document-new"), i18n("Create a new source entry for online quotes"), i18n("Use this to create a new entry for online quotes")); + +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) + KGuiItem::assign(m_updateButton, updateButtenItem); + KGuiItem::assign(m_deleteButton, deleteButtenItem); + KGuiItem::assign(m_checkButton, checkButtonItem); + KGuiItem::assign(m_showButton, showButtonItem); + KGuiItem::assign(m_newButton, newButtenItem); +#else + m_updateButton->setGuiItem(updateButtenItem); + m_deleteButton->setGuiItem(deleteButtenItem); + m_checkButton->setGuiItem(checkButtonItem); + m_showButton->setGuiItem(showButtonItem); m_newButton->setGuiItem(newButtenItem); +#endif connect(m_newProfile, SIGNAL(clicked()), this, SLOT(slotNewProfile())); connect(m_deleteProfile, SIGNAL(clicked()), this, SLOT(slotDeleteProfile())); @@ -190,6 +211,8 @@ void AlkOnlineQuotesWidget::Private::loadProfiles() { AlkOnlineQuotesProfileList list = AlkOnlineQuotesProfileManager::instance().profiles(); + if (list.isEmpty()) + return; foreach (AlkOnlineQuotesProfile *profile, list) { QListWidgetItem *item = new QListWidgetItem(dynamic_cast(m_profileList)); item->setText(profile->name()); @@ -266,6 +289,8 @@ AlkOnlineQuotesProfileList list = AlkOnlineQuotesProfileManager::instance().profiles(); if (!m_showProfiles) { AlkOnlineQuotesProfileList list = AlkOnlineQuotesProfileManager::instance().profiles(); + if (list.isEmpty()) + return; m_profile = list.first(); loadQuotesList(); return; @@ -353,7 +378,7 @@ { QList items = m_quoteSourceList->findItems( m_currentItem.name(), Qt::MatchExactly); - if (items.size() == 0) { + if (items.isEmpty()) { return; } QListWidgetItem *item = items.at(0); @@ -381,7 +406,7 @@ { QList items = m_quoteSourceList->findItems( m_currentItem.name(), Qt::MatchExactly); - if (items.size() == 0) { + if (items.isEmpty()) { return; } QListWidgetItem *item = items.at(0); @@ -665,4 +690,16 @@ d->m_acceptLanguage = text; } +#if QT_VERSION < QT_VERSION_CHECK(5,0,0) +class InitCatalog { +public: + InitCatalog() + { + KComponentData a("alkimia", "alkimia"); + } +}; + +static InitCatalog init; +#endif + #include "alkonlinequoteswidget.moc" diff --git a/src/alkonlinequoteswidget5.ui b/src/alkonlinequoteswidget5.ui new file mode 100644 --- /dev/null +++ b/src/alkonlinequoteswidget5.ui @@ -0,0 +1,579 @@ + + + AlkOnlineQuotesWidget + + + + 0 + 0 + 523 + 879 + + + + + 0 + 0 + + + + Online Quotes + + + + + + <html><head/><body><p>Select, add or delete an application profile, where to load profiles from and save into eg. kmymoney or skrooge.</p></body></html> + + + Application Profiles + + + Qt::AlignCenter + + + + + + + + + + + + + false + + + New + + + + + + + false + + + Delete + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + Profile details + + + Qt::AlignCenter + + + + + + GHNS config file + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Config file + + + + + + + + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + + + + + + + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + + + + + + + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + + + + + + GHNS data path + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + true + + + <html><head/><body><p>online price quotes</p></body></html> + + + Online Quotes + + + Qt::AlignCenter + + + + + + + + + + + + + New + + + + + + + Delete + + + + + + + Create a duplicate of the currently selected source entry under a different name. + + + Use this to create a duplicate of an entry for an online source + + + Duplicate + + + + .. + + + + + + + Install + + + + + + + Upload + + + + + + + Qt::Vertical + + + + 14 + 13 + + + + + + + + + + + + + + + <html><head/><body><p><span style=" font-style:italic;">Enter regular expressions which can be used to parse the data returned from the URL entered above. The symbol, price, and date must be found in the quote data to be usable. You may also try the KMyMoney forum at </span><a href="https://forum.kde.org/viewforum.php?f=69"><span style=" text-decoration: underline; color:#2980b9;">https://forum.kde.org/viewforum.php?f=69</span></a> or the <span style=" font-style:italic;">user's mailinglist at </span><a href="mailto:kmymoney@kde.org"><span style=" font-style:italic; text-decoration: underline; color:#2980b9;">kmymoney@kde.org</span></a><span style=" font-style:italic;"> to find what settings work for other users in your country.</span></p></body></html> + + + Details + + + Qt::AlignCenter + + + + + + + + + + Regular Expression to extract the date from the downloaded data + + + + + + + Date Format + + + false + + + + + + + + + + + + + + Regular Expression to extract the symbol from the downloaded data + + + + + + + Date + + + false + + + + + + + <p>For easier processing of the data returned by the online source, KMyMoney usually strips unused parts before it is parsed with the regular expressions. If matching of the fields relies on those items, then use this option to turn stripping off.</p> + +<p>The following items are usually removed by stripping: + +<ul> +<li>HTML tags such as <b>&lt;tag&gt;</b></li> +<li>& encoded characters such as <b>&amp;nbsp;</b></li> +<li>duplicate whitespace</li> +</ul> +</p> + + + Skip HTML stripping + + + + + + + + + + + + + + + + + + + + + URL + + + false + + + + + + + Regular Expression to extract the price from the downloaded data + + + + + + + Options + + + + + + + + + + GHNS Source + + + + + + + + + + + + + + + + + + + + + Price + + + false + + + + + + + Symbol + + + false + + + + + + + Regular Expression to extract the date from the downloaded data + + + + + + + URL to be used to download the quote + + + Enter the URL from which stock quotes will be fetched. <b>%1</b> will be replaced with the symbol for the security being quoted. For currency conversions, <b>%2</b> will be replaced with the currency to be quoted and <b>%1</b> with the currency the quote is based on. + + + + + + + + + 0 + + + + + Accept + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Debugging + + + Qt::AlignCenter + + + + + + + + + + + + One Symbol + + + + + + + + + + + + + + Two Symbols + + + + + + + + + + + + + + + + + + + + + Check Source + + + + + + + Show Page + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + KTextEdit + QTextEdit +
ktextedit.h
+
+ + KLineEdit + QLineEdit +
klineedit.h
+
+
+ + +
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -21,3 +21,8 @@ qmlalkonlinequotetest.cpp ) target_link_libraries(qmlalkonlinequotetest ${TEST_LIB}) + +add_executable(alkonlinequoteswidgettest + alkonlinequoteswidgettest.cpp +) +target_link_libraries(alkonlinequoteswidgettest ${TEST_LIB}) diff --git a/tests/qmlalkonlinequotetest.cpp b/tests/alkonlinequoteswidgettest.cpp copy from tests/qmlalkonlinequotetest.cpp copy to tests/alkonlinequoteswidgettest.cpp --- a/tests/qmlalkonlinequotetest.cpp +++ b/tests/alkonlinequoteswidgettest.cpp @@ -1,5 +1,6 @@ /*************************************************************************** - * Copyright 2018 Ralf Habacker ralf.habacker@freenet.de * + * Copyright 2019 Ralf Habacker ralf.habacker@freenet.de * + * Copyright 2019 Thomas Baumgart * * * * This file is part of libalkimia. * * * @@ -17,44 +18,44 @@ * along with this program. If not, see * ***************************************************************************/ -#include "alkonlinequote.h" +#include "alkonlinequoteswidget.h" +#include "alkonlinequotesprofile.h" +#include "alkonlinequotesprofilemanager.h" -#if QT_VERSION >= 0x050000 -#include -#include + +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) + #include #else -#include -class QGuiApplication : public QApplication -{ -public: - QGuiApplication(int &argc, char **argv) : QApplication(argc, argv) {} -}; + #include + #include + class QGuiApplication : public QApplication + { + public: + QGuiApplication(int &argc, char **argv) : QApplication(argc, argv) {} + }; +#endif -#include -#include -#include +#include +#include -class QQmlApplicationEngine : public QDeclarativeEngine -{ +class Dialog : public QDialog { public: - void load(const QString &url) + Dialog() { - QString s = url; - s.replace(".qml", "-qt4.qml"); - QUrl a = QUrl::fromLocalFile(s); - view.setSource(a); - view.show(); + + QGridLayout *layout = new QGridLayout; + layout->addWidget(new AlkOnlineQuotesWidget); + setLayout(layout); } - QDeclarativeView view; }; -#endif int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); - QQmlApplicationEngine engine; - engine.load(CMAKE_CURRENT_SOURCE_DIR "/qmlalkonlinequotetest.qml"); + AlkOnlineQuotesProfile profile("no-config-file", AlkOnlineQuotesProfile::Type::None); + AlkOnlineQuotesProfileManager::instance().addProfile(&profile); - return app.exec(); + Dialog dialog; + dialog.exec(); } diff --git a/tests/qmlalkonlinequotetest.cpp b/tests/qmlalkonlinequotetest.cpp --- a/tests/qmlalkonlinequotetest.cpp +++ b/tests/qmlalkonlinequotetest.cpp @@ -19,7 +19,7 @@ #include "alkonlinequote.h" -#if QT_VERSION >= 0x050000 +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) #include #include #else diff --git a/tools/onlinequoteseditor/CMakeLists.txt b/tools/onlinequoteseditor/CMakeLists.txt --- a/tools/onlinequoteseditor/CMakeLists.txt +++ b/tools/onlinequoteseditor/CMakeLists.txt @@ -13,18 +13,30 @@ ) set(UI - mainwindow.ui + mainwindow.ui ) ki18n_wrap_ui(SOURCES ${UI} ) #kde4_add_app_icon(SOURCES "${KDE4_INSTALL_DIR}/share/icons/oxygen/*/actions/application-exit.png") ecm_add_executable(onlinequoteseditor ${SOURCES} ${HEADERS}) if(BUILD_QT4) - set(LIBS ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBS} ${QT_USE_LIBSPREFIX}Core ${QT_USE_LIBSPREFIX}Network ${QT_USE_LIBSPREFIX}WebKit) + set(LIBS + ${KDE4_KDECORE_LIBS} + ${KDE4_KDEUI_LIBS} + ${QT_USE_LIBSPREFIX}Core + ${QT_USE_LIBSPREFIX}Network + ${QT_USE_LIBSPREFIX}WebKit + ) else() - set(LIBS Qt5::Widgets Qt5::WebKitWidgets KF5::KDELibs4Support) + set(LIBS + Qt5::Widgets + Qt5::WebKitWidgets + KF5::CoreAddons + KF5::I18n + ) + add_definitions(-DTRANSLATION_DOMAIN=\"onlinequoteseditor\") endif() target_link_libraries(onlinequoteseditor diff --git a/tools/onlinequoteseditor/Messages.sh b/tools/onlinequoteseditor/Messages.sh new file mode 100644 --- /dev/null +++ b/tools/onlinequoteseditor/Messages.sh @@ -0,0 +1,11 @@ +#!bin/sh +# invoke the extractrc script on all .ui, .rc, and .kcfg files in the sources +# the results are stored in a pseudo .cpp file to be picked up by xgettext. +$EXTRACTRC `find . -name \*.rc -o -name \*.ui -o -name \*.kcfg` >> rc.cpp + +# call xgettext on all source files. If your sources have other filename +# extensions besides .cpp, and .h, just add them in the find call. +$XGETTEXT `find . -name \*.cpp -o -name \*.h -o -name \*.qml` -o $podir/onlinequoteeditor.pot + +# Remove these two generated files again +rm rc.cpp diff --git a/tools/onlinequoteseditor/main.cpp b/tools/onlinequoteseditor/main.cpp --- a/tools/onlinequoteseditor/main.cpp +++ b/tools/onlinequoteseditor/main.cpp @@ -1,5 +1,6 @@ /*************************************************************************** * Copyright 2018 Ralf Habacker * + * Copyright 2019 Thomas Baumgart * * * * This file is part of libalkimia. * * * @@ -19,35 +20,41 @@ #include "mainwindow.h" -#if QT_VERSION >= 0x050000 -#define KABOUTDATA_H -#include -#define KAboutData K4AboutData -#else #include +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) + #include + #include +#else + #include + #include #endif -#include -#include int main(int argc, char **argv) { - KAboutData about("onlinequoteseditor", 0, +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) + KAboutData about(QStringLiteral("onlinequoteseditor"), + i18n("onlinequoteseditor"), + QStringLiteral("1.0"), + i18n("Editor for online price quotes used by finance applications"), + KAboutLicense::GPL, + i18n("(C) 2018 Ralf Habacker")); + QApplication app(argc,argv); + +#else + + KAboutData about("onlinequoteseditor", + "onlinequoteeditor", ki18n("onlinequoteseditor"), "1.0", ki18n("Editor for online price quotes used by finance applications"), KAboutData::License_GPL, ki18n("(C) 2018 Ralf Habacker")); + KCmdLineArgs::init(argc, argv, &about); KApplication app(true); - KCmdLineOptions options; - KCmdLineArgs::addCmdLineOptions(options); // Add my own options. - - KComponentData a(&about); - - // Get application specific arguments - KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); +#endif MainWindow w; w.show(); diff --git a/tools/onlinequoteseditor/mainwindow.cpp b/tools/onlinequoteseditor/mainwindow.cpp --- a/tools/onlinequoteseditor/mainwindow.cpp +++ b/tools/onlinequoteseditor/mainwindow.cpp @@ -81,7 +81,9 @@ manager.addProfile(new AlkOnlineQuotesProfile("kmymoney4", AlkOnlineQuotesProfile::Type::KMyMoney4, "kmymoney-quotes.knsrc")); manager.addProfile(new AlkOnlineQuotesProfile("kmymoney5", AlkOnlineQuotesProfile::Type::KMyMoney5, "kmymoney-quotes.knsrc")); d->ui.setupUi(this); - +#if QT_VERSION >= QT_VERSION_CHECK(5,0,0) + d->ui.mainToolBar->deleteLater(); +#endif d->quotesWidget = new AlkOnlineQuotesWidget(true, true); QDockWidget *profilesWidget = new QDockWidget(tr("Profiles"), this);