diff --git a/CMakeLists.txt b/CMakeLists.txt index 51c812e..6197b25 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,159 +1,175 @@ # The CMake version we require (must be first) cmake_minimum_required(VERSION 3.0.2) if(POLICY CMP0071) cmake_policy(SET CMP0071 NEW) endif() project(alkimia VERSION 8.0.2) option(BUILD_QT4 "Build for Qt4" OFF) option(BUILD_DOXYGEN_DOCS "Build api docs" ON) option(BUILD_APPLETS "Build plasma applets" ON) 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) include(ECMAddAppIcon) include(ECMInstallIcons) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) include(FeatureSummary) # check for PkgConfig, Qt and MPIR/GMP find_package(PkgConfig) if(BUILD_QT4) find_package(Qt4 REQUIRED COMPONENTS QtCore QtGui QtDBus QtTest QtWebKit QtDeclarative) set(QT_USE_LIBSPREFIX Qt4::Qt) set(ALKIMIA_LIB_SUFFIX "") set(ALKIMIA_INCLUDE_SUFFIX "Qt4") set(ALKIMIA_PATH_SUFFIX) set(PC_TARGET_QTPREFIX Qt) set(PC_TARGET_SUFFIX) + set(QT_BROWSER_LIB ${QT_USE_LIBSPREFIX}WebKit) + add_definitions(-DBUILD_WITH_WEBKIT) set(_kde4_uninstall_rule_created 1) find_package(KDE4 REQUIRED) include(KDE4Defaults) set(KDE_LIBRARIES ${KDE4_KDECORE_LIBS} ${KDE4_KIO_LIBS}) include_directories(${KDE4_INCLUDES}) macro(ki18n_wrap_ui) kde4_add_ui_files(${ARGN}) endmacro(ki18n_wrap_ui) macro(kconfig_add_kcfg_files) kde4_add_kcfg_files(${ARGN}) endmacro(kconfig_add_kcfg_files) macro(ecm_add_executable) kde4_add_executable(${ARGN}) endmacro(ecm_add_executable) macro(ecm_mark_nongui_executable) foreach(_target ${ARGN}) set_target_properties(${_target} PROPERTIES WIN32_EXECUTABLE FALSE MACOSX_BUNDLE FALSE ) endforeach() endmacro(ecm_mark_nongui_executable) macro(ecm_install_icons) kde4_install_icons(${ICON_INSTALL_DIR}) endmacro() add_definitions(-DQStringLiteral=QLatin1String) if(NOT SHARE_INSTALL_DIR) set(SHARE_INSTALL_DIR ${DATA_INSTALL_DIR}) endif() else() + option(BUILD_WITH_WEBKIT "Build with Qt Web Kit library" ON) + if(BUILD_WITH_WEBKIT) + add_definitions(-DBUILD_WITH_WEBKIT) + set(QT5_OPTIONAL_COMPONENTS WebKitWidgets) + else() + set(QT5_OPTIONAL_COMPONENTS Widgets) + endif() find_package(Qt5 REQUIRED COMPONENTS Core Test - WebKitWidgets + ${QT5_OPTIONAL_COMPONENTS} Qml ) if(BUILD_APPLETS) set(PLASMA_COMPONENT Package Plasma) endif() # search packages used by KDE find_package(KF5 REQUIRED COMPONENTS Config CoreAddons KDELibs4Support #I18n #WebKit ${PLASMA_COMPONENT} NewStuff ) set(QT_USE_LIBSPREFIX Qt5::) set(ALKIMIA_LIB_SUFFIX "5") set(ALKIMIA_INCLUDE_SUFFIX "Qt5") set(ALKIMIA_PATH_SUFFIX 5) set(PC_TARGET_QTPREFIX Qt5) set(PC_TARGET_SUFFIX 5) + + if(BUILD_WITH_WEBKIT) + set(QT_BROWSER_LIB ${QT_USE_LIBSPREFIX}WebKitWidgets) + else() + set(QT_BROWSER_LIB ${QT_USE_LIBSPREFIX}Widgets) + endif() + macro(ecm_add_executable) add_executable(${ARGN}) endmacro(ecm_add_executable) 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() set(TARGET_SUFFIX ${PC_TARGET_SUFFIX}) add_definitions(-DTARGET_SUFFIX=\"${TARGET_SUFFIX}\") # figure out which multi-precision library to use # MPIR is preferred over GMP find_package(MPIR) if(MPIR_FOUND) set(MP_INCLUDE_DIR ${MPIR_INCLUDE_DIR}) set(MP_LIBRARIES ${MPIR_LIBRARIES}) set(MP_HEADER mpirxx.h) set(MP_CMAKE_MODULE "MPIR") set(PC_LIB mpir) else() find_package(GMP REQUIRED) set(MP_INCLUDE_DIR ${GMP_INCLUDE_DIR}) set(MP_LIBRARIES ${GMP_LIBRARIES}) set(MP_HEADER gmpxx.h) set(MP_CMAKE_MODULE "GMP") set(PC_LIB gmp) endif() # check for Doxygen (for API documentation) if(BUILD_DOXYGEN_DOCS) find_package(Doxygen) endif() feature_summary(WHAT ALL) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS) include_directories( ${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR}/src ) add_subdirectory(src) add_subdirectory(autotests) add_subdirectory(qml) if(BUILD_APPLETS) if(BUILD_QT4) add_subdirectory(plasma/applets/onlinequote) else() add_subdirectory(plasma/applets/ForeignCurrencies) endif() endif() add_subdirectory(tests) add_subdirectory(tools) diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index d4eec46..6f9f822 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -1,39 +1,36 @@ include(ECMAddTests) set(TEST_LIB alkimia alkimia-internal ${QT_USE_LIBSPREFIX}Test ${QT_USE_LIBSPREFIX}Core ${QT_USE_LIBSPREFIX}DBus - ${QT_USE_LIBSPREFIX}WebKit ${MP_LIBRARIES} ) if(BUILD_QT4) list(APPEND TEST_LIB ${KDE_LIBRARIES}) -else() - list(APPEND TEST_LIB ${QT_USE_LIBSPREFIX}WebKitWidgets) endif() ecm_add_tests( alkonlinequotesourcetest.cpp alkvaluetest.cpp alkquoteitemtest.cpp alkcompanytest.cpp alkexceptiontest.cpp LINK_LIBRARIES alkimia ${TEST_LIB} ) ecm_add_test( alkonlinequotetest.cpp ../src/alkquotereceiver.cpp LINK_LIBRARIES ${TEST_LIB} TEST_NAME alkonlinequotestest ) ecm_add_test( alkdateformattest.cpp LINK_LIBRARIES ${TEST_LIB} TEST_NAME alkdateformattest ) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d849ef7..3315d43 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,241 +1,241 @@ include(GenerateExportHeader) include(ECMGenerateHeaders) include(ECMGeneratePriFile) include(CMakePackageConfigHelpers) include(ECMSetupVersion) include_directories( ${CMAKE_CURRENT_BINARY_DIR} ) ########### target alkimia-internal ########### set(alkimia_INTERNAL_SRCS alkdateformat.cpp alkexception.cpp alkonlinequoteprocess.cpp alkquoteitem.cpp alkquotereceiver.cpp ) set(alkimia_INTERNAL_HEADERS alkdateformat.h alkexception.h alkonlinequoteprocess.h alkquoteitem.h alkquotereceiver.h ) set(alkimia_INTERNAL_UI ) ki18n_wrap_ui(alkimia_INTERNAL_SRCS ${alkimia_INTERNAL_UI} ) add_library(alkimia-internal STATIC ${alkimia_INTERNAL_SRCS} ${alkimia_INTERNAL_HEADERS}) if(NOT BUILD_QT4) set (ALKIMIA_INTERNAL_LIBS PRIVATE - ${QT_USE_LIBSPREFIX}WebKitWidgets KF5::CoreAddons KF5::KDELibs4Support KF5::NewStuff ) endif() target_link_libraries(alkimia-internal PUBLIC ${QT_USE_LIBSPREFIX}Core ${ALKIMIA_INTERNAL_LIBS}) kde_target_enable_exceptions(alkimia-internal PUBLIC) ########### target alkimia ########### set(ALKIMIA_LIB_VERSION ${alkimia_VERSION}) set(ALKIMIA_LIB_SOVERSION "${alkimia_VERSION_MAJOR}") set(alkimia_LIB_SRCS alkcompany.cpp alkfinancequoteprocess.cpp alkonlinequote.cpp alkonlinequotesource.cpp alkonlinequotesprofile.cpp alkonlinequotesprofilemanager.cpp alkonlinequoteswidget.cpp alkvalue.cpp alkwebpage.cpp ) set(alkimia_LIB_HEADERS alkcompany.h alkfinancequoteprocess.h alkonlinequote.h alkonlinequotesource.h alkonlinequotesprofile.h alkonlinequotesprofilemanager.h alkonlinequoteswidget.h alkwebpage.h ) set(alkimia_UI alkonlinequoteswidget.ui ) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/alkvalue.h.in ${CMAKE_CURRENT_BINARY_DIR}/alkimia/alkvalue.h IMMEDIATE ) foreach(header ${alkimia_LIB_HEADERS}) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/${header} ${CMAKE_CURRENT_BINARY_DIR}/alkimia/${header} COPYONLY ) endforeach() add_definitions(-DKNSRC_DIR="${CMAKE_CURRENT_SOURCE_DIR}") ki18n_wrap_ui(alkimia_LIB_SRCS ${alkimia_UI} ) add_library(alkimia SHARED ${alkimia_LIB_SRCS} ${alkimia_INTERNAL_SRCS} ${alkimia_LIB_HEADERS}) kde_target_enable_exceptions(alkimia PUBLIC) if(BUILD_QT4) set(ALKIMIA_LIBS PRIVATE ${KDE_LIBRARIES} ${KDE4_KDEUI_LIBS} - ${KDE4_KNEWSTUFF3_LIBS}) + ${KDE4_KNEWSTUFF3_LIBS} + ) else() set(ALKIMIA_LIBS PRIVATE - ${QT_USE_LIBSPREFIX}WebKitWidgets KF5::KDELibs4Support KF5::NewStuff ) add_definitions(-DTRANSLATION_DOMAIN=\"alkimia\") endif() + target_link_libraries(alkimia PRIVATE alkimia-internal ${QT_USE_LIBSPREFIX}Core ${ALKIMIA_LIBS} ${QT_USE_LIBSPREFIX}DBus PUBLIC - ${QT_USE_LIBSPREFIX}WebKit ${MP_LIBRARIES} + ${QT_BROWSER_LIB} ) if(NOT BUILD_QT4 AND MSVC) message(WARNING "Applying fix for broken Qt WebKit package (see https://phabricator.kde.org/T10146 for details)") target_link_libraries(alkimia PRIVATE ${QT_USE_LIBSPREFIX}Test ) endif() install( DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/alkimia DESTINATION ${INCLUDE_INSTALL_DIR}/alkimia/${ALKIMIA_INCLUDE_SUFFIX} COMPONENT Devel ) generate_export_header(alkimia BASE_NAME alk EXPORT_FILE_NAME alkimia/alk_export.h) if(WIN32) set_target_properties(alkimia PROPERTIES SUFFIX "-${ALKIMIA_LIB_SOVERSION}${CMAKE_SHARED_LIBRARY_SUFFIX}") else() set_target_properties(alkimia PROPERTIES VERSION ${ALKIMIA_LIB_VERSION} SOVERSION ${ALKIMIA_LIB_SOVERSION}) endif() set_target_properties(alkimia PROPERTIES OUTPUT_NAME alkimia${ALKIMIA_LIB_SUFFIX}) set(INCLUDE_INSTALL_DIR include/alkimia/${ALKIMIA_INCLUDE_SUFFIX}) install(TARGETS alkimia EXPORT alkimiaTargets ${INSTALL_TARGETS_DEFAULT_ARGS} ) if(BUILD_QT4) if(WIN32) set(KNSRC_INSTALL_DIR ${SHARE_INSTALL_DIR}/config) else() set(KNSRC_INSTALL_DIR ${SHARE_INSTALL_DIR}/kde4/config) endif() set(APPDATA_INSTALL_DIR ${SHARE_INSTALL_DIR}/kde4/apps) set(FQ_LOCAL_INSTALL_PATH ${CMAKE_BINARY_DIR}/share/apps/alkimia${ALKIMIA_PATH_SUFFIX}/misc) else() set(KNSRC_INSTALL_DIR ${CONFIG_INSTALL_DIR}) set(APPDATA_INSTALL_DIR ${SHARE_INSTALL_DIR}) set(FQ_LOCAL_INSTALL_PATH ${CMAKE_BINARY_DIR}/share/alkimia${ALKIMIA_PATH_SUFFIX}/misc) endif() install(FILES alkimia-quotes.knsrc kmymoney-quotes.knsrc skrooge-quotes.knsrc DESTINATION ${KNSRC_INSTALL_DIR} ) # install perl script in expected location of build dir # KDE4: set KDEHOME to build dir # KF5: ??? make_directory(${FQ_LOCAL_INSTALL_PATH}) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/financequote.pl ${FQ_LOCAL_INSTALL_PATH}/financequote.pl IMMEDIATE COPYONLY) install(PROGRAMS financequote.pl DESTINATION ${APPDATA_INSTALL_DIR}/alkimia${ALKIMIA_PATH_SUFFIX}/misc ) if (NOT WIN32) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libalkimia.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libalkimia${ALKIMIA_PATH_SUFFIX}.pc IMMEDIATE @ONLY) endif(NOT WIN32) ########### create package configuration file ########### # create a Config.cmake and a ConfigVersion.cmake file and install them set(CMAKECONFIG_INSTALL_DIR "${CMAKECONFIG_INSTALL_PREFIX}/LibAlkimia${ALKIMIA_PATH_SUFFIX}-${alkimia_VERSION_MAJOR}.${alkimia_VERSION_MINOR}") ecm_setup_version(${alkimia_VERSION} VARIABLE_PREFIX ALKIMIA PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/LibAlkimia${ALKIMIA_PATH_SUFFIX}ConfigVersion.cmake" COMPATIBILITY SameMajorVersion ) configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/LibAlkimiaConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/LibAlkimia${ALKIMIA_PATH_SUFFIX}Config.cmake" INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR} PATH_VARS INCLUDE_INSTALL_DIR ) ########### install files ############### export(TARGETS alkimia FILE "${CMAKE_CURRENT_BINARY_DIR}/LibAlkimia${ALKIMIA_PATH_SUFFIX}Targets.cmake" NAMESPACE Alkimia:: ) install(EXPORT alkimiaTargets FILE LibAlkimia${ALKIMIA_PATH_SUFFIX}Targets.cmake NAMESPACE Alkimia:: DESTINATION ${CMAKECONFIG_INSTALL_DIR} ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/LibAlkimia${ALKIMIA_PATH_SUFFIX}Config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/LibAlkimia${ALKIMIA_PATH_SUFFIX}ConfigVersion.cmake" "../cmake/modules/Find${MP_CMAKE_MODULE}.cmake" DESTINATION "${CMAKECONFIG_INSTALL_DIR}" COMPONENT Devel) if (NOT WIN32) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libalkimia${ALKIMIA_PATH_SUFFIX}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) endif(NOT WIN32) ########### documentation ################### if(DOXYGEN_FOUND) set(APIDOC_DIR ${CMAKE_CURRENT_BINARY_DIR}/apidocs) make_directory(${APIDOC_DIR}) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libalkimia.doxygen.in ${CMAKE_CURRENT_BINARY_DIR}/libalkimia.doxygen IMMEDIATE) add_custom_target(libalkimia_apidoc ${DOXYGEN} ${CMAKE_CURRENT_BINARY_DIR}/libalkimia.doxygen) endif(DOXYGEN_FOUND) diff --git a/src/alkonlinequoteswidget.cpp b/src/alkonlinequoteswidget.cpp index 5cfd755..c34acc0 100644 --- a/src/alkonlinequoteswidget.cpp +++ b/src/alkonlinequoteswidget.cpp @@ -1,685 +1,684 @@ /*************************************************************************** * Copyright 2004-2019 Thomas Baumgart tbaumgart@kde.org * * * * This file is part of libalkimia. * * * * libalkimia is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * * as published by the Free Software Foundation; either version 2.1 of * * the License or (at your option) version 3 or any later version. * * * * libalkimia is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see * ***************************************************************************/ #include "alkonlinequoteswidget.h" #include "alkonlinequote.h" #include "alkonlinequotesprofile.h" #include "alkonlinequotesprofilemanager.h" #include "alkonlinequotesource.h" #include "alkwebpage.h" #include #include #include #include -#include #include #include #include #include #include #include #include #if QT_VERSION < QT_VERSION_CHECK(5,0,0) #include static KLocale _locale("alkimia"); #define i18nc(context, text) ki18nc(context, text).toString(&_locale) #define i18n(text) ki18n(text).toString(&_locale) #define tr2i18n(text, context) ki18nc(context, text).toString(&_locale) #endif #include class AlkOnlineQuotesWidget::Private : public QWidget, public Ui::AlkOnlineQuotesWidget { Q_OBJECT public: QString m_acceptLanguage; QList m_resetList; AlkOnlineQuoteSource m_currentItem; bool m_quoteInEditing; AlkOnlineQuotesProfile *m_profile; bool m_showProfiles; bool m_showUpload; QPixmap m_emptyIcon; QPixmap m_inWorkIcon; QPixmap m_okIcon; QPixmap m_failIcon; QPixmap m_unknownIcon; QDialog *m_webPageDialog; Private(bool showProfiles, bool showUpload, QWidget *parent); ~Private(); public slots: void slotNewProfile(); void slotDeleteProfile(); void slotSelectProfile(); void slotLoadProfile(); void slotDeleteEntry(); void slotDuplicateEntry(); void slotUpdateEntry(); void slotLoadWidgets(); void slotEntryChanged(); void slotNewEntry(); void slotCheckEntry(); void slotLogStatus(const QString &s); void slotLogError(const QString &s); void slotLogFailed(const QString &id, const QString &symbol); void slotLogQuote(const QString &id, const QString &symbol, const QDate &date, double price); void slotEntryRenamed(QListWidgetItem *item); void slotStartRename(QListWidgetItem *item); void slotInstallEntries(); void slotUploadEntry(); void slotShowButton(); public: void loadProfiles(); void loadQuotesList(const bool updateResetList = false); void clearIcons(); void initIcons(); void setupIcons(const AlkOnlineQuote::Errors &errors); QString singleSymbol() const; QStringList doubleSymbol() const; QString expandedUrl() const; }; AlkOnlineQuotesWidget::Private::Private(bool showProfiles, bool showUpload, QWidget *parent) : QWidget(parent) , m_quoteInEditing(false) , m_profile(nullptr) , m_showProfiles(showProfiles) , m_showUpload(showUpload) , m_inWorkIcon(BarIcon("view-refresh")) , m_okIcon(BarIcon("dialog-ok-apply")) , m_failIcon(BarIcon("dialog-cancel")) , m_webPageDialog(nullptr) { setupUi(parent); profilesGroupBox->setVisible(showProfiles); profileDetailsBox->setVisible(showProfiles); m_showButton->setVisible(!showProfiles && AlkOnlineQuotesProfileManager::instance().webPageEnabled()); m_ghnsSource->setEnabled(showProfiles); m_uploadButton->setVisible(showUpload); m_urlCheckLabel->setMinimumWidth(m_okIcon.width()); loadProfiles(); // TODO move to ui file KGuiItem updateButtenItem(i18nc("Accepts the entered data and stores it", "&Accept"), 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")); m_newButton->setGuiItem(newButtenItem); connect(m_newProfile, SIGNAL(clicked()), this, SLOT(slotNewProfile())); connect(m_deleteProfile, SIGNAL(clicked()), this, SLOT(slotDeleteProfile())); connect(m_profileList, SIGNAL(itemSelectionChanged()), this, SLOT(slotLoadProfile())); connect(m_updateButton, SIGNAL(clicked()), this, SLOT(slotUpdateEntry())); connect(m_newButton, SIGNAL(clicked()), this, SLOT(slotNewEntry())); connect(m_checkButton, SIGNAL(clicked()), this, SLOT(slotCheckEntry())); connect(m_deleteButton, SIGNAL(clicked()), this, SLOT(slotDeleteEntry())); connect(m_duplicateButton, SIGNAL(clicked()), this, SLOT(slotDuplicateEntry())); connect(m_installButton, SIGNAL(clicked()), this, SLOT(slotInstallEntries())); connect(m_uploadButton, SIGNAL(clicked()), this, SLOT(slotUploadEntry())); connect(m_quoteSourceList, SIGNAL(itemSelectionChanged()), this, SLOT(slotLoadWidgets())); connect(m_quoteSourceList, SIGNAL(itemChanged(QListWidgetItem *)), this, SLOT(slotEntryRenamed(QListWidgetItem *))); connect(m_quoteSourceList, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(slotStartRename(QListWidgetItem *))); connect(m_editURL, SIGNAL(textChanged(QString)), this, SLOT(slotEntryChanged())); connect(m_editSymbol, SIGNAL(textChanged(QString)), this, SLOT(slotEntryChanged())); connect(m_editDate, SIGNAL(textChanged(QString)), this, SLOT(slotEntryChanged())); connect(m_editDateFormat, SIGNAL(textChanged(QString)), this, SLOT(slotEntryChanged())); connect(m_editPrice, SIGNAL(textChanged(QString)), this, SLOT(slotEntryChanged())); connect(m_skipStripping, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); connect(m_ghnsSource, SIGNAL(toggled(bool)), this, SLOT(slotEntryChanged())); connect(m_showButton, SIGNAL(clicked()), this, SLOT(slotShowButton())); m_checkSymbol->setText("ORCL"); m_checkSymbol2->setText("BTC GBP"); m_updateButton->setEnabled(false); slotLoadProfile(); } AlkOnlineQuotesWidget::Private::~Private() { m_webPageDialog->deleteLater(); } 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()); item->setFlags(item->flags() | Qt::ItemIsEditable); } m_profileList->setCurrentRow(0); m_profile = AlkOnlineQuotesProfileManager::instance().profiles().first(); loadQuotesList(); } void AlkOnlineQuotesWidget::Private::loadQuotesList(const bool updateResetList) { m_quoteInEditing = false; QStringList groups = m_profile->quoteSources(); if (updateResetList) { m_resetList.clear(); } m_quoteSourceList->blockSignals(true); m_quoteSourceList->clear(); QStringList::Iterator it; for (it = groups.begin(); it != groups.end(); ++it) { AlkOnlineQuoteSource source(*it, m_profile); if (!source.isValid()) { continue; } QListWidgetItem *item = new QListWidgetItem(*it); item->setFlags(Qt::ItemIsEditable | Qt::ItemIsSelectable | Qt::ItemIsEnabled); m_quoteSourceList->addItem(item); if (updateResetList) { m_resetList += source; } } m_quoteSourceList->sortItems(); QListWidgetItem *item = nullptr; if (!m_currentItem.name().isEmpty()) { QList items = m_quoteSourceList->findItems(m_currentItem.name(), Qt::MatchExactly); if (items.size() > 0) item = items.at(0); if (item) m_quoteSourceList->setCurrentItem(item); } if (!item) { item = m_quoteSourceList->item(0); if (item) m_quoteSourceList->setCurrentItem(item); } m_quoteSourceList->blockSignals(false); slotLoadWidgets(); slotEntryChanged(); } void AlkOnlineQuotesWidget::Private::slotNewProfile() { QListWidgetItem *item = new QListWidgetItem(dynamic_cast(m_profileList)); item->setText(QLatin1String("new profile")); item->setFlags(item->flags() | Qt::ItemIsEditable); } void AlkOnlineQuotesWidget::Private::slotDeleteProfile() { delete m_profileList->currentItem(); } void AlkOnlineQuotesWidget::Private::slotSelectProfile() { slotLoadProfile(); } void AlkOnlineQuotesWidget::Private::slotLoadProfile() { AlkOnlineQuotesProfileList list = AlkOnlineQuotesProfileManager::instance().profiles(); if (!m_showProfiles) { AlkOnlineQuotesProfileList list = AlkOnlineQuotesProfileManager::instance().profiles(); if (list.isEmpty()) return; m_profile = list.first(); m_installButton->setVisible(m_profile->hasGHNSSupport()); loadQuotesList(); return; } foreach (AlkOnlineQuotesProfile *profile, list) { if (m_profileList->currentItem()->text() == profile->name()) { m_profile = profile; loadQuotesList(); m_installButton->setVisible(profile->hasGHNSSupport()); } } bool visible = m_profile->type() != AlkOnlineQuotesProfile::Type::None; m_configFilePath->setText(m_profile->kConfigFile()); m_configFilePath->setVisible(visible); m_configLabel->setEnabled(visible); visible = m_profile->hasGHNSSupport(); m_GHNSConfigFilePath->setText(m_profile->hotNewStuffConfigFile()); m_GHNSConfigFilePath->setVisible(visible); m_GHNSConfigLabel->setEnabled(visible); m_GHNSDataPath->setText(m_profile->hotNewStuffReadPath().join(" ")); m_GHNSDataPath->setVisible(visible); m_GHNSDataLabel->setEnabled(visible); } void AlkOnlineQuotesWidget::Private::slotLoadWidgets() { m_quoteInEditing = false; QListWidgetItem *item = m_quoteSourceList->currentItem(); bool isFinanceQuoteSource = (item && AlkOnlineQuoteSource::isFinanceQuote(item->text())) || m_profile->type() == AlkOnlineQuotesProfile::Type::Script; bool enabled = item && !isFinanceQuoteSource; m_editURL->setEnabled(enabled); m_editSymbol->setEnabled(enabled); m_editPrice->setEnabled(enabled); m_editDate->setEnabled(enabled); m_editDateFormat->setEnabled(enabled); m_ghnsSource->setEnabled(!isFinanceQuoteSource); m_skipStripping->setEnabled(enabled); m_editURL->clear(); m_editSymbol->clear(); m_editPrice->clear(); m_editDate->clear(); m_editDateFormat->clear(); if (item) { m_currentItem = AlkOnlineQuoteSource(item->text(), m_profile); m_editURL->setText(m_currentItem.url()); m_editSymbol->setText(m_currentItem.sym()); m_editPrice->setText(m_currentItem.price()); m_editDate->setText(m_currentItem.date()); m_editDateFormat->setText(m_currentItem.dateformat()); m_skipStripping->setChecked(m_currentItem.skipStripping()); m_ghnsSource->setChecked(m_currentItem.isGHNS()); } m_updateButton->setEnabled(false); } void AlkOnlineQuotesWidget::Private::slotEntryChanged() { clearIcons(); bool modified = m_editURL->text() != m_currentItem.url() || m_editSymbol->text() != m_currentItem.sym() || m_editDate->text() != m_currentItem.date() || m_editDateFormat->text() != m_currentItem.dateformat() || m_editPrice->text() != m_currentItem.price() || m_skipStripping->isChecked() != m_currentItem.skipStripping() || m_ghnsSource->isChecked() != m_currentItem.isGHNS(); bool isFinanceQuote = m_currentItem.isFinanceQuote() || m_profile->type() == AlkOnlineQuotesProfile::Type::Script; bool hasWriteSupport = (m_profile->type() != AlkOnlineQuotesProfile::Type::None && !isFinanceQuote) || m_profile->hasGHNSSupport(); bool noNewEntry = m_quoteSourceList->findItems(i18n("New Quote Source"), Qt::MatchExactly).count() == 0 || isFinanceQuote; m_newButton->setEnabled(hasWriteSupport && noNewEntry); m_duplicateButton->setEnabled(hasWriteSupport); m_deleteButton->setEnabled(!m_currentItem.isReadOnly() && !m_currentItem.isGHNS()); m_uploadButton->setEnabled(m_profile->hasGHNSSupport() && m_currentItem.isGHNS()); m_updateButton->setEnabled(modified); m_checkButton->setEnabled(isFinanceQuote || !modified); m_checkSymbol->setEnabled(!m_currentItem.url().contains("%2")); m_checkSymbol2->setEnabled(m_currentItem.url().contains("%2")); } void AlkOnlineQuotesWidget::Private::slotDeleteEntry() { QList items = m_quoteSourceList->findItems( m_currentItem.name(), Qt::MatchExactly); if (items.isEmpty()) { return; } QListWidgetItem *item = items.at(0); if (!item) { return; } int ret = KMessageBox::warningContinueCancel(this, i18n("Are you sure to delete this online quote ?"), i18n("Delete online quote"), KStandardGuiItem::cont(), KStandardGuiItem::cancel(), QString("DeletingOnlineQuote")); if (ret == KMessageBox::Cancel) { return; } // keep this order to avoid deleting the wrong current item m_currentItem.remove(); delete item; slotEntryChanged(); } void AlkOnlineQuotesWidget::Private::slotDuplicateEntry() { QList items = m_quoteSourceList->findItems( m_currentItem.name(), Qt::MatchExactly); if (items.isEmpty()) { return; } QListWidgetItem *item = items.at(0); if (!item) { return; } AlkOnlineQuoteSource copy(m_currentItem); copy.setName(copy.name() + i18n(".copy")); copy.setGHNS(false); copy.write(); m_currentItem = copy; loadQuotesList(); } void AlkOnlineQuotesWidget::Private::slotUpdateEntry() { m_currentItem.setUrl(m_editURL->text()); m_currentItem.setSym(m_editSymbol->text()); m_currentItem.setDate(m_editDate->text()); m_currentItem.setDateformat(m_editDateFormat->text()); m_currentItem.setPrice(m_editPrice->text()); m_currentItem.setSkipStripping(m_skipStripping->isChecked()); m_currentItem.setGHNS(m_ghnsSource->isChecked()); m_currentItem.write(); m_checkButton->setEnabled(true); slotEntryChanged(); } void AlkOnlineQuotesWidget::Private::slotNewEntry() { AlkOnlineQuoteSource newSource(i18n("New Quote Source"), m_profile); newSource.write(); m_currentItem = newSource; loadQuotesList(); } void AlkOnlineQuotesWidget::Private::clearIcons() { m_urlCheckLabel->setPixmap(m_emptyIcon); m_dateCheckLabel->setPixmap(m_emptyIcon); m_priceCheckLabel->setPixmap(m_emptyIcon); m_symbolCheckLabel->setPixmap(m_emptyIcon); m_dateFormatCheckLabel->setPixmap(m_emptyIcon); } void AlkOnlineQuotesWidget::Private::initIcons() { m_urlCheckLabel->setPixmap(m_inWorkIcon); m_dateCheckLabel->setPixmap(m_inWorkIcon); m_priceCheckLabel->setPixmap(m_inWorkIcon); m_symbolCheckLabel->setPixmap(m_inWorkIcon); m_dateFormatCheckLabel->setPixmap(m_inWorkIcon); } void AlkOnlineQuotesWidget::Private::setupIcons(const AlkOnlineQuote::Errors &errors) { clearIcons(); if (errors & AlkOnlineQuote::Errors::URL) { m_urlCheckLabel->setPixmap(m_failIcon); } else { m_urlCheckLabel->setPixmap(m_okIcon); m_symbolCheckLabel->setPixmap(errors & AlkOnlineQuote::Errors::Symbol ? m_failIcon : m_okIcon); m_priceCheckLabel->setPixmap(errors & AlkOnlineQuote::Errors::Price ? m_failIcon : m_okIcon); if (errors & AlkOnlineQuote::Errors::Date) { m_dateCheckLabel->setPixmap(m_failIcon); } else { m_dateCheckLabel->setPixmap(m_okIcon); m_dateFormatCheckLabel->setPixmap( errors & AlkOnlineQuote::Errors::DateFormat ? m_failIcon : m_okIcon); } } } void AlkOnlineQuotesWidget::Private::slotCheckEntry() { AlkOnlineQuote quote(m_profile); m_logWindow->setVisible(true); m_logWindow->clear(); clearIcons(); quote.setAcceptLanguage(m_acceptLanguage); connect("e, SIGNAL(status(QString)), this, SLOT(slotLogStatus(QString))); connect("e, SIGNAL(error(QString)), this, SLOT(slotLogError(QString))); connect("e, SIGNAL(failed(QString,QString)), this, SLOT(slotLogFailed(QString,QString))); connect("e, SIGNAL(quote(QString,QString,QDate,double)), this, SLOT(slotLogQuote(QString,QString,QDate,double))); initIcons(); if (m_currentItem.url().contains("%2")) { quote.launch(m_checkSymbol2->text(), m_checkSymbol2->text(), m_currentItem.name()); } else { quote.launch(m_checkSymbol->text(), m_checkSymbol->text(), m_currentItem.name()); } setupIcons(quote.errors()); } void AlkOnlineQuotesWidget::Private::slotLogStatus(const QString &s) { m_logWindow->append(s); } void AlkOnlineQuotesWidget::Private::slotLogError(const QString &s) { slotLogStatus(QString("") + s + QString("")); } void AlkOnlineQuotesWidget::Private::slotLogFailed(const QString &id, const QString &symbol) { slotLogStatus(QString("%1 %2").arg(id, symbol)); } void AlkOnlineQuotesWidget::Private::slotLogQuote(const QString &id, const QString &symbol, const QDate &date, double price) { slotLogStatus(QString("%1 %2 %3 %4").arg(id, symbol, date.toString()).arg( price)); } void AlkOnlineQuotesWidget::Private::slotStartRename(QListWidgetItem *item) { m_quoteInEditing = true; m_quoteSourceList->editItem(item); } void AlkOnlineQuotesWidget::Private::slotEntryRenamed(QListWidgetItem *item) { //if there is no current item selected, exit if (m_quoteInEditing == false || !m_quoteSourceList->currentItem() || item != m_quoteSourceList->currentItem()) { return; } m_quoteInEditing = false; QString text = item->text(); int nameCount = 0; for (int i = 0; i < m_quoteSourceList->count(); ++i) { if (m_quoteSourceList->item(i)->text() == text) { ++nameCount; } } // Make sure we get a non-empty and unique name if (text.length() > 0 && nameCount == 1) { m_currentItem.rename(text); } else { item->setText(m_currentItem.name()); } m_quoteSourceList->sortItems(); m_newButton->setEnabled(m_quoteSourceList->findItems(i18n( "New Quote Source"), Qt::MatchExactly).count() == 0); } void AlkOnlineQuotesWidget::Private::slotInstallEntries() { QString configFile = m_profile->hotNewStuffConfigFile(); QPointer dialog = new KNS3::DownloadDialog(configFile, this); dialog->exec(); delete dialog; loadQuotesList(); } void AlkOnlineQuotesWidget::Private::slotUploadEntry() { QString configFile = m_profile->hotNewStuffConfigFile(); QUrl url = QUrl::fromLocalFile(m_currentItem.ghnsWriteFileName()); qDebug() << "uploading file" << url; QPointer dialog = new KNS3::UploadDialog(configFile, this); dialog->setUploadName(m_currentItem.name()); dialog->setUploadFile(url); dialog->exec(); delete dialog; } void AlkOnlineQuotesWidget::Private::slotShowButton() { if (!m_webPageDialog) { m_webPageDialog = new QDialog; m_webPageDialog->setWindowTitle(i18n("Online Quote HTML Result Window")); QVBoxLayout *layout = new QVBoxLayout; AlkWebPage *webPage = AlkOnlineQuotesProfileManager::instance().webPage(); webPage->setWebInspectorEnabled(true); - layout->addWidget(webPage); + layout->addWidget(webPage->widget()); m_webPageDialog->setLayout(layout); } m_webPageDialog->show(); } QString AlkOnlineQuotesWidget::Private::expandedUrl() const { if (m_currentItem.url().contains("%2")) { return m_currentItem.url().arg(m_checkSymbol2->text()); } else { return m_currentItem.url().arg(m_checkSymbol->text()); } } AlkOnlineQuotesWidget::AlkOnlineQuotesWidget(bool showProfiles, bool showUpload, QWidget *parent) : QWidget(parent) , d(new Private(showProfiles, showUpload, this)) { } AlkOnlineQuotesWidget::~AlkOnlineQuotesWidget() { delete d; } QWidget *AlkOnlineQuotesWidget::profilesWidget() { QFrame *frame = new QFrame; frame->setLayout(d->profilesGroupBox->layout()); return frame; } QWidget *AlkOnlineQuotesWidget::profileDetailsWidget() { QFrame *frame = new QFrame; frame->setLayout(d->profileDetailsBox->layout()); return frame; } QWidget *AlkOnlineQuotesWidget::onlineQuotesWidget() { QFrame *frame = new QFrame; frame->setLayout(d->onlineQuotesGroupBox->layout()); return frame; } QWidget *AlkOnlineQuotesWidget::quoteDetailsWidget() { QFrame *frame = new QFrame; frame->setLayout(d->detailsGroupBox->layout()); return frame; } QWidget *AlkOnlineQuotesWidget::debugWidget() { QFrame *frame = new QFrame; frame->setLayout(d->debugGroupBox->layout()); return frame; } void AlkOnlineQuotesWidget::readConfig() { } void AlkOnlineQuotesWidget::writeConfig() { } void AlkOnlineQuotesWidget::resetConfig() { QStringList::ConstIterator it; QStringList groups = d->m_profile->quoteSources(); // delete all currently defined entries for (it = groups.constBegin(); it != groups.constEnd(); ++it) { AlkOnlineQuoteSource(*it, d->m_profile).remove(); } // and write back the one's from the reset list QList::iterator itr; for (itr = d->m_resetList.begin(); itr != d->m_resetList.end(); ++itr) { (*itr).write(); } d->loadQuotesList(); } QString AlkOnlineQuotesWidget::acceptLanguage() const { return d->m_acceptLanguage; } void AlkOnlineQuotesWidget::setAcceptLanguage(const QString &text) { d->m_acceptLanguage = text; } #include "alkonlinequoteswidget.moc" diff --git a/src/alkwebpage.cpp b/src/alkwebpage.cpp index 1939f68..cf409fb 100644 --- a/src/alkwebpage.cpp +++ b/src/alkwebpage.cpp @@ -1,102 +1,171 @@ /*************************************************************************** * Copyright 2018 Ralf Habacker * * * * This file is part of libalkimia. * * * * libalkimia is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public License * * as published by the Free Software Foundation; either version 2.1 of * * the License or (at your option) version 3 or any later version. * * * * libalkimia is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see * ***************************************************************************/ #include "alkwebpage.h" +#if defined(BUILD_WITH_WEBKIT) #include #include #include #include #include class AlkWebPage::Private { public: QWebInspector *inspector; Private() : inspector(nullptr) { } ~Private() { delete inspector; } void setWebInspectorEnabled(bool enable, QWebPage* page) { page->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, enable); delete inspector; inspector = nullptr; if (enable) { inspector = new QWebInspector(); inspector->setPage(page); } } bool webInspectorEnabled(QWebPage *page) { return page->settings()->testAttribute(QWebSettings::DeveloperExtrasEnabled); } }; AlkWebPage::AlkWebPage(QWidget *parent) : QWebView(parent) , d(new Private) { page()->settings()->setAttribute(QWebSettings::JavaEnabled, false); page()->settings()->setAttribute(QWebSettings::AutoLoadImages, false); page()->settings()->setAttribute(QWebSettings::PluginsEnabled, false); } AlkWebPage::~AlkWebPage() { delete d; } +QWidget *AlkWebPage::widget() +{ + return this; +} + void AlkWebPage::load(const QUrl &url, const QString &acceptLanguage) { QNetworkRequest request; request.setUrl(url); if (!acceptLanguage.isEmpty()) request.setRawHeader("Accept-Language", acceptLanguage.toLocal8Bit()); QWebView::load(request); } QString AlkWebPage::toHtml() { QWebFrame *frame = page()->mainFrame(); return frame->toHtml(); } QString AlkWebPage::getFirstElement(const QString &symbol) { QWebFrame *frame = page()->mainFrame(); QWebElement element = frame->findFirstElement(symbol); return element.toPlainText(); } void AlkWebPage::setWebInspectorEnabled(bool enable) { d->setWebInspectorEnabled(enable, page()); } bool AlkWebPage::webInspectorEnabled() { return d->webInspectorEnabled(page()); } + +#else + +class AlkWebPage::Private +{ +public: +}; + +AlkWebPage::AlkWebPage(QWidget *parent) + : QWidget(parent) + , d(new Private) +{ +} + +AlkWebPage::~AlkWebPage() +{ + delete d; +} + +QWidget *AlkWebPage::widget() +{ + return this; +} + +void AlkWebPage::load(const QUrl &url, const QString &acceptLanguage) +{ + Q_UNUSED(url) + Q_UNUSED(acceptLanguage) +} + +void AlkWebPage::setUrl(const QUrl &url) +{ + Q_UNUSED(url) +} + +void AlkWebPage::setContent(const QString &s) +{ + Q_UNUSED(s) +} + +QString AlkWebPage::toHtml() +{ + return QString(); +} + +QString AlkWebPage::getFirstElement(const QString &symbol) +{ + Q_UNUSED(symbol) + + return QString(); +} + +void AlkWebPage::setWebInspectorEnabled(bool enable) +{ + Q_UNUSED(enable) +} + +bool AlkWebPage::webInspectorEnabled() +{ + return false; +} + +#endif diff --git a/src/alkwebpage.h b/src/alkwebpage.h index b3a008e..dc9686f 100644 --- a/src/alkwebpage.h +++ b/src/alkwebpage.h @@ -1,54 +1,93 @@ /*************************************************************************** * Copyright 2018 Ralf Habacker * * * * This file is part of libalkimia. * * * * libalkimia is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public License * * as published by the Free Software Foundation; either version 2.1 of * * the License or (at your option) version 3 or any later version. * * * * libalkimia is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see * ***************************************************************************/ #ifndef ALKWEBPAGE_H #define ALKWEBPAGE_H #include #include -#include class QUrl; +#if defined(BUILD_WITH_WEBKIT) + +#include + /** * The AlkWebPage class provides an interface * to a browser component with javascript support * It is used for fetching and showing web pages. * * @author Ralf Habacker */ class ALK_EXPORT AlkWebPage : public QWebView { public: AlkWebPage(QWidget *parent = nullptr); virtual ~AlkWebPage(); + QWidget *widget(); + void load(const QUrl &url, const QString &acceptLanguage); + QString toHtml(); + QString getFirstElement(const QString &symbol); + void setWebInspectorEnabled(bool enable); + bool webInspectorEnabled(); + +private: + class Private; + Private *d; +}; + +#else + +#include + +/** + * The AlkWebPage class provides an interface + * to a browser component with javascript support + * It is used for fetching and showing web pages. + * + * @author Ralf Habacker + */ +class ALK_EXPORT AlkWebPage : public QWidget +{ +public: + AlkWebPage(QWidget *parent = nullptr); + virtual ~AlkWebPage(); + + QWidget *widget(); void load(const QUrl &url, const QString &acceptLanguage); + void setUrl(const QUrl &url); + void setContent(const QString &s); QString toHtml(); QString getFirstElement(const QString &symbol); void setWebInspectorEnabled(bool enable); bool webInspectorEnabled(); +Q_SIGNALS: + void loadStarted(); + void loadFinished(bool); private: class Private; Private *d; }; +#endif #endif // ALKWEBPAGE_H diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e5767cf..60db681 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,29 +1,27 @@ add_definitions(-DCMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}") set(TEST_LIB alkimia alkimia-internal ${QT_USE_LIBSPREFIX}Core - ${QT_USE_LIBSPREFIX}WebKit ) if(BUILD_QT4) list(APPEND TEST_LIB ${QT_USE_LIBSPREFIX}Declarative ${KDE_LIBRARIES} ) else() list(APPEND TEST_LIB ${QT_USE_LIBSPREFIX}Qml - ${QT_USE_LIBSPREFIX}WebKitWidgets KF5::KDELibs4Support ) endif() add_executable(qmlalkonlinequotetest qmlalkonlinequotetest.cpp ) target_link_libraries(qmlalkonlinequotetest ${TEST_LIB}) add_executable(alkonlinequoteswidgettest alkonlinequoteswidgettest.cpp ) target_link_libraries(alkonlinequoteswidgettest ${TEST_LIB}) diff --git a/tools/onlinequoteseditor/CMakeLists.txt b/tools/onlinequoteseditor/CMakeLists.txt index 2d040b5..26e8c67 100644 --- a/tools/onlinequoteseditor/CMakeLists.txt +++ b/tools/onlinequoteseditor/CMakeLists.txt @@ -1,53 +1,53 @@ add_subdirectory(icons) include_directories( ${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR}/src ) set(SOURCES applicationsettings.cpp main.cpp mainwindow.cpp ) set(HEADERS applicationsettings.h mainwindow.h ) set(UI mainwindow.ui ) ki18n_wrap_ui(SOURCES ${UI} ) ecm_add_app_icon(SOURCES ICONS icons/16-apps-onlinequoteseditor5.png icons/22-apps-onlinequoteseditor5.png icons/32-apps-onlinequoteseditor5.png icons/48-apps-onlinequoteseditor5.png icons/64-apps-onlinequoteseditor5.png icons/128-apps-onlinequoteseditor5.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) else() - set(LIBS Qt5::Widgets Qt5::WebKitWidgets KF5::KDELibs4Support) + set(LIBS Qt5::Widgets KF5::KDELibs4Support) add_definitions(-DTRANSLATION_DOMAIN=\"onlinequoteseditor\") endif() target_link_libraries(onlinequoteseditor alkimia alkimia-internal ${LIBS} ) set_target_properties(onlinequoteseditor PROPERTIES OUTPUT_NAME onlinequoteseditor${TARGET_SUFFIX}) install(TARGETS onlinequoteseditor ${KDE_INSTALL_TARGETS_DEFAULT_ARGS}) configure_file(org.kde.onlinequoteseditor.desktop.cmake ${CMAKE_CURRENT_BINARY_DIR}/org.kde.onlinequoteseditor${TARGET_SUFFIX}.desktop) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.kde.onlinequoteseditor${TARGET_SUFFIX}.desktop DESTINATION ${XDG_APPS_INSTALL_DIR}) diff --git a/tools/onlinequoteseditor/mainwindow.cpp b/tools/onlinequoteseditor/mainwindow.cpp index 608d479..4de9ae8 100644 --- a/tools/onlinequoteseditor/mainwindow.cpp +++ b/tools/onlinequoteseditor/mainwindow.cpp @@ -1,168 +1,170 @@ /*************************************************************************** * Copyright 2018 Ralf Habacker * * * * This file is part of libalkimia. * * * * libalkimia is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * * as published by the Free Software Foundation; either version 2.1 of * * the License or (at your option) version 3 or any later version. * * * * libalkimia is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see * ***************************************************************************/ #include "mainwindow.h" #include "ui_mainwindow.h" #include "alkonlinequotesprofile.h" #include "alkonlinequotesprofilemanager.h" #include "alkonlinequoteswidget.h" #include "alkwebpage.h" #include #include #include #include -#include class MainWindow::Private { public: Private() : urlLine(nullptr) , quotesWidget(nullptr) { } ~Private() { delete quotesWidget; } QLineEdit *urlLine; AlkOnlineQuotesWidget *quotesWidget; Ui::MainWindow ui; }; void MainWindow::slotUrlChanged(const QUrl &url) { d->urlLine->setText(url.toString()); } void MainWindow::slotEditingFinished() { AlkOnlineQuotesProfileManager::instance().webPage()->load(QUrl(d->urlLine->text()), d->quotesWidget->acceptLanguage()); } void MainWindow::slotLanguageChanged(const QString &text) { d->quotesWidget->setAcceptLanguage(text); if (!d->urlLine->text().isEmpty()) slotEditingFinished(); } MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ApplicationSettings(this, false) , d(new Private) { AlkOnlineQuotesProfileManager &manager = AlkOnlineQuotesProfileManager::instance(); - manager.setWebPageEnabled(true); manager.addProfile(new AlkOnlineQuotesProfile("no-config-file", AlkOnlineQuotesProfile::Type::None)); #if QT_VERSION < QT_VERSION_CHECK(5,0,0) manager.addProfile(new AlkOnlineQuotesProfile("alkimia4", AlkOnlineQuotesProfile::Type::Alkimia4, "alkimia-quotes.knsrc")); manager.addProfile(new AlkOnlineQuotesProfile("skrooge4", AlkOnlineQuotesProfile::Type::Skrooge4, "skrooge-quotes.knsrc")); manager.addProfile(new AlkOnlineQuotesProfile("kmymoney4", AlkOnlineQuotesProfile::Type::KMyMoney4, "kmymoney-quotes.knsrc")); #else manager.addProfile(new AlkOnlineQuotesProfile("alkimia5", AlkOnlineQuotesProfile::Type::Alkimia5, "alkimia-quotes.knsrc")); manager.addProfile(new AlkOnlineQuotesProfile("skrooge5", AlkOnlineQuotesProfile::Type::Skrooge5, "skrooge-quotes.knsrc")); manager.addProfile(new AlkOnlineQuotesProfile("kmymoney5", AlkOnlineQuotesProfile::Type::KMyMoney5, "kmymoney-quotes.knsrc")); #endif manager.addProfile(new AlkOnlineQuotesProfile("Finance::Quote", AlkOnlineQuotesProfile::Type::Script)); d->ui.setupUi(this); d->quotesWidget = new AlkOnlineQuotesWidget(true, true); QDockWidget *profilesWidget = new QDockWidget(i18n("Profiles"), this); profilesWidget->setObjectName("profilesDockWidget"); profilesWidget->setWidget(d->quotesWidget->profilesWidget()); addDockWidget(Qt::LeftDockWidgetArea, profilesWidget); QDockWidget *profileDetailsWidget = new QDockWidget(i18n("Profile details"), this); profileDetailsWidget->setObjectName("profileDetailsDockWidget"); profileDetailsWidget->setWidget(d->quotesWidget->profileDetailsWidget()); addDockWidget(Qt::RightDockWidgetArea, profileDetailsWidget); QDockWidget *onlineQuotesWidget = new QDockWidget(i18n("Online quotes"), this); onlineQuotesWidget->setObjectName("onlineQuotesDockWidget"); onlineQuotesWidget->setWidget(d->quotesWidget->onlineQuotesWidget()); addDockWidget(Qt::LeftDockWidgetArea, onlineQuotesWidget); QDockWidget *debugWidget = new QDockWidget(i18n("Debug"), this); debugWidget->setObjectName("debugDockWidget"); debugWidget->setWidget(d->quotesWidget->debugWidget()); addDockWidget(Qt::LeftDockWidgetArea, debugWidget); QDockWidget *quoteDetailsWidget = new QDockWidget(i18n("Quote details"), this); quoteDetailsWidget->setObjectName("quoteDetailsDockWidget"); quoteDetailsWidget->setWidget(d->quotesWidget->quoteDetailsWidget()); addDockWidget(Qt::RightDockWidgetArea, quoteDetailsWidget); +#if defined(BUILD_WITH_WEBKIT) + manager.setWebPageEnabled(true); QDockWidget *browserWidget = new QDockWidget(i18n("Browser"), this); browserWidget->setObjectName("browserDockWidget"); AlkWebPage *webPage = manager.webPage(); connect(webPage, SIGNAL(urlChanged(QUrl)), this, SLOT(slotUrlChanged(QUrl))); + + // setup url line + QHBoxLayout *hLayout = new QHBoxLayout; d->urlLine = new QLineEdit; connect(d->urlLine, SIGNAL(editingFinished()), this, SLOT(slotEditingFinished())); + hLayout->addWidget(d->urlLine); // setup language box QComboBox *box = new QComboBox; QList allLocales = QLocale::matchingLocales( QLocale::AnyLanguage, QLocale::AnyScript, QLocale::AnyCountry); QStringList languages; foreach(const QLocale &locale, allLocales) { languages.append(locale.uiLanguages()); } languages.sort(); box->addItems(languages); d->quotesWidget->setAcceptLanguage(box->currentText()); connect(box, SIGNAL(currentIndexChanged(QString)), this, SLOT(slotLanguageChanged(QString))); - - // setup layouts - QHBoxLayout *hLayout = new QHBoxLayout; - hLayout->addWidget(d->urlLine); hLayout->addWidget(box); + // setup browser window QVBoxLayout *layout = new QVBoxLayout; layout->addLayout(hLayout); - layout->addWidget(webPage); + layout->addWidget(webPage->widget()); QWidget *group = new QWidget; group->setLayout(layout); browserWidget->setWidget(group); addDockWidget(Qt::RightDockWidgetArea, browserWidget); + webPage->setWebInspectorEnabled(true); +#endif setCentralWidget(nullptr); - webPage->setWebInspectorEnabled(true); readPositionSettings(); } MainWindow::~MainWindow() { delete d; } void MainWindow::closeEvent(QCloseEvent *event) { writePositionSettings(); QMainWindow::closeEvent(event); }