Some very initial and hugely experimental porting to QtWebEngine modules.

This commit is contained in:
Martin Rotter 2016-03-22 13:45:51 +01:00
parent a989dfa9db
commit ee8dd96ddc
18 changed files with 157 additions and 491 deletions

View File

@ -2,7 +2,7 @@
# #
# This file is part of RSS Guard. # This file is part of RSS Guard.
# #
# Copyright (C) 2011-2015 by Martin Rotter <rotter.martinos@gmail.com> # Copyright (C) 2011-2016 by Martin Rotter <rotter.martinos@gmail.com>
# #
# RSS Guard is free software: you can redistribute it and/or modify # RSS Guard is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -25,22 +25,15 @@
# #
# Usage: # Usage:
# a) DEBUG build for testing. # a) DEBUG build for testing.
# cmake -DCMAKE_BUILD_TYPE=debug -DCMAKE_INSTALL_PREFIX=/usr -DUSE_QT_5=ON # cmake -DCMAKE_BUILD_TYPE=debug -DCMAKE_INSTALL_PREFIX=/usr
# #
# b) RELEASE build for production use. # b) RELEASE build for production use.
# cmake -DCMAKE_BUILD_TYPE=release -DCMAKE_INSTALL_PREFIX=/usr -DUSE_QT_5=ON # cmake -DCMAKE_BUILD_TYPE=release -DCMAKE_INSTALL_PREFIX=/usr
# #
# Arguments: # Arguments:
# -DCMAKE_INSTALL_PREFIX=/usr # -DCMAKE_INSTALL_PREFIX=/usr
# Installation path, replace with something like "C:\rssguard" on Windows. # Installation path, replace with something like "C:\rssguard" on Windows.
# #
# -DUSE_QT_5=OFF
# Specifies which major Qt version to use. Qt 4 and Qt 5 are supported.
# If "OFF" is passed as an argument, then Qt 4 is used. Default is "OFF".
#
# -DENABLE_OS2_RC=OFF
# If "ON" then icon is compiled into executable file on OS/2. Defaults to "OFF".
#
# Refreshing translation sources: # Refreshing translation sources:
# make lupdate # make lupdate
# #
@ -52,7 +45,7 @@
# #
# Other information: # Other information:
# - supports Windows, Linux, OS/2 (eComStation), # - supports Windows, Linux, OS/2 (eComStation),
# - Qt 4.7.3 and higher is required, # - Qt 5.6 and higher is required,
# - resource compiler (windres.exe) is needed on MinGW, # - resource compiler (windres.exe) is needed on MinGW,
# - resource compiler (rc.exe) is recommended on OS/2. # - resource compiler (rc.exe) is recommended on OS/2.
# #
@ -77,7 +70,7 @@ set(APP_URL_ISSUES_NEW_GITHUB "https://github.com/martinrotter/rssguard/issues/n
set(APP_URL_ISSUES_NEW_BITBUCKET "http://bitbucket.org/skunkos/rssguard/issues/new") set(APP_URL_ISSUES_NEW_BITBUCKET "http://bitbucket.org/skunkos/rssguard/issues/new")
set(APP_URL_WIKI "https://bitbucket.org/skunkos/rssguard/wiki/Home") set(APP_URL_WIKI "https://bitbucket.org/skunkos/rssguard/wiki/Home")
set(APP_EMAIL "rotter.martinos@gmail.com") set(APP_EMAIL "rotter.martinos@gmail.com")
set(MINIMUM_QT_VERSION 4.7.3) set(MINIMUM_QT_VERSION 5.6)
set(EXE_NAME ${APP_LOW_NAME}) set(EXE_NAME ${APP_LOW_NAME})
if(APPLE) if(APPLE)
@ -85,13 +78,8 @@ if(APPLE)
endif(APPLE) endif(APPLE)
# Options declaration. # Options declaration.
option(USE_QT_5 "Use Qt 5 for building" OFF)
option(ENABLE_ADDITIONAL_ICONS "Install additional icons" ON) option(ENABLE_ADDITIONAL_ICONS "Install additional icons" ON)
if(OS2)
option(ENABLE_OS2_RC "Compile application icon on OS/2" OFF)
endif(OS2)
if(WIN32) if(WIN32)
option(USE_NSIS "Use NSIS generator to produce installer" OFF) option(USE_NSIS "Use NSIS generator to produce installer" OFF)
endif(WIN32) endif(WIN32)
@ -101,27 +89,16 @@ if(POLICY CMP0012)
cmake_policy(SET CMP0012 NEW) cmake_policy(SET CMP0012 NEW)
endif() endif()
if(USE_QT_5) if(POLICY CMP0054)
cmake_minimum_required(VERSION 2.8.10) cmake_policy(SET CMP0054 NEW)
else(USE_QT_5) endif()
cmake_minimum_required(VERSION 2.6.0)
endif(USE_QT_5)
if(${APPLE}) cmake_minimum_required(VERSION 2.8.10)
if(NOT USE_QT_5)
message(FATAL_ERROR "[${APP_LOW_NAME}] Only Qt 5.x.x is supported on Mac OS X.")
endif(NOT USE_QT_5)
endif(${APPLE})
message(STATUS "") message(STATUS "")
message(STATUS "[${APP_LOW_NAME}] ==== Options summary ====") message(STATUS "[${APP_LOW_NAME}] ==== Options summary ====")
message(STATUS "[${APP_LOW_NAME}] Use Qt 5 for building -> ${USE_QT_5}")
message(STATUS "[${APP_LOW_NAME}] Install additional icons -> ${ENABLE_ADDITIONAL_ICONS}") message(STATUS "[${APP_LOW_NAME}] Install additional icons -> ${ENABLE_ADDITIONAL_ICONS}")
if(OS2)
message(STATUS "[${APP_LOW_NAME}] Compile application icon on OS/2 -> ${ENABLE_OS2_RC}")
endif(OS2)
if(WIN32) if(WIN32)
message(STATUS "[${APP_LOW_NAME}] Use NSIS generator to produce installer -> ${USE_NSIS}") message(STATUS "[${APP_LOW_NAME}] Use NSIS generator to produce installer -> ${USE_NSIS}")
endif(WIN32) endif(WIN32)
@ -148,15 +125,10 @@ if(POLICY CMP0020)
cmake_policy(SET CMP0020 NEW) cmake_policy(SET CMP0020 NEW)
endif(POLICY CMP0020) endif(POLICY CMP0020)
# Select which Qt version to use. message(STATUS "[${APP_LOW_NAME}] Using Qt 5 library for building.")
if(USE_QT_5)
message(STATUS "[${APP_LOW_NAME}] Using Qt 5 library for building.") # Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
else(USE_QT_5)
message(STATUS "[${APP_LOW_NAME}] Using Qt 4 library for building.")
endif(USE_QT_5)
# Obtain revision number if available. # Obtain revision number if available.
message(STATUS "[${APP_LOW_NAME}] Obtaining revision number.") message(STATUS "[${APP_LOW_NAME}] Obtaining revision number.")
@ -230,61 +202,37 @@ add_definitions(-DUNICODE -D_UNICODE)
# Check for C++ 11 features availability. # Check for C++ 11 features availability.
# See http://stackoverflow.com/questions/10984442/how-to-detect-c11-support-of-a-compiler-with-cmake # See http://stackoverflow.com/questions/10984442/how-to-detect-c11-support-of-a-compiler-with-cmake
if(USE_QT_5) if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") execute_process(
execute_process( COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION
COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION )
) if(${GCC_VERSION} VERSION_GREATER 4.7 OR ${GCC_VERSION} VERSION_EQUAL 4.7)
add_definitions(-std=c++11)
if(${GCC_VERSION} VERSION_GREATER 4.7 OR ${GCC_VERSION} VERSION_EQUAL 4.7) elseif(GCC_VERSION VERSION_GREATER 4.3 OR GCC_VERSION VERSION_EQUAL 4.3)
add_definitions(-std=c++11) add_definitions(-std=gnu++0x)
elseif(GCC_VERSION VERSION_GREATER 4.3 OR GCC_VERSION VERSION_EQUAL 4.3) else(${GCC_VERSION} VERSION_GREATER 4.7 OR ${GCC_VERSION} VERSION_EQUAL 4.7)
add_definitions(-std=gnu++0x)
else(${GCC_VERSION} VERSION_GREATER 4.7 OR ${GCC_VERSION} VERSION_EQUAL 4.7)
message(FATAL_ERROR "[${APP_LOW_NAME}] Your C++ compiler does not support C++ 11.")
endif(${GCC_VERSION} VERSION_GREATER 4.7 OR ${GCC_VERSION} VERSION_EQUAL 4.7)
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
add_definitions(-std=c++11 -stdlib=libc++)
elseif(${MSVC_VERSION} VERSION_LESS 1600)
message(FATAL_ERROR "[${APP_LOW_NAME}] Your C++ compiler does not support C++ 11.") message(FATAL_ERROR "[${APP_LOW_NAME}] Your C++ compiler does not support C++ 11.")
endif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") endif(${GCC_VERSION} VERSION_GREATER 4.7 OR ${GCC_VERSION} VERSION_EQUAL 4.7)
endif(USE_QT_5)
elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
add_definitions(-std=c++11 -stdlib=libc++)
elseif(${MSVC_VERSION} VERSION_LESS 1600)
message(FATAL_ERROR "[${APP_LOW_NAME}] Your C++ compiler does not support C++ 11.")
endif(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
# Setup libraries. # Setup libraries.
if(UNIX) if(UNIX)
# On Unices, enable D-Bus support. # On Unices, enable D-Bus support.
if(USE_QT_5) find_package(Qt5 REQUIRED DBus Sql WebEngineWidgets Widgets Xml XmlPatterns Network LinguistTools PrintSupport)
find_package(Qt5 REQUIRED DBus Sql WebKit WebKitWidgets Widgets Xml XmlPatterns Network LinguistTools PrintSupport)
else(USE_QT_5)
set(QT_MIN_VERSION ${MINIMUM_QT_VERSION})
find_package(Qt4 REQUIRED QtDBus QtCore QtGui QtSql QtNetwork QtWebkit QtXml QtXmlPatterns)
include(${QT_USE_FILE})
endif(USE_QT_5)
else(UNIX) else(UNIX)
if(USE_QT_5) find_package(Qt5 REQUIRED Sql WebEngineWidgets Widgets Xml XmlPatterns Network LinguistTools PrintSupport)
find_package(Qt5 REQUIRED Sql WebKit WebKitWidgets Widgets Xml XmlPatterns Network LinguistTools PrintSupport)
else(USE_QT_5)
set(QT_MIN_VERSION ${MINIMUM_QT_VERSION})
find_package(Qt4 REQUIRED QtCore QtGui QtSql QtNetwork QtWebkit QtXml QtXmlPatterns)
include(${QT_USE_FILE})
endif(USE_QT_5)
endif(UNIX) endif(UNIX)
# Configure QStringBuilder behavior. # Configure QStringBuilder behavior.
if(USE_QT_5) message(STATUS "[${APP_LOW_NAME}] Enabling fast QString concatenation.")
message(STATUS "[${APP_LOW_NAME}] Enabling fast QString concatenation.")
add_definitions(-DQT_USE_FAST_CONCATENATION) add_definitions(-DQT_USE_FAST_CONCATENATION)
add_definitions(-DQT_USE_FAST_OPERATOR_PLUS) add_definitions(-DQT_USE_FAST_OPERATOR_PLUS)
elseif(NOT ${QTVERSION} VERSION_LESS 4.8.0)
message(STATUS "[${APP_LOW_NAME}] Enabling fast QString concatenation.")
add_definitions(-DQT_USE_FAST_CONCATENATION)
add_definitions(-DQT_USE_FAST_OPERATOR_PLUS)
else(NOT ${QTVERSION} VERSION_LESS 4.8.0)
message(STATUS "[${APP_LOW_NAME}] Disabling fast QString concatenation.")
endif(USE_QT_5)
# Configure executable "properties" for Windows or OS2. # Configure executable "properties" for Windows or OS2.
if(WIN32) if(WIN32)
@ -293,12 +241,6 @@ if(WIN32)
${PROJECT_SOURCE_DIR}/resources/executable_properties/rssguard_win.rc.in ${PROJECT_SOURCE_DIR}/resources/executable_properties/rssguard_win.rc.in
${CMAKE_BINARY_DIR}/resources/executable_properties/rssguard_win.rc ${CMAKE_BINARY_DIR}/resources/executable_properties/rssguard_win.rc
) )
elseif(OS2 AND ENABLE_OS2_RC)
message(STATUS "[${APP_LOW_NAME}] Generating executable file properties for OS2.")
configure_file (
${PROJECT_SOURCE_DIR}/resources/executable_properties/rssguard_os2.rc.in
${CMAKE_BINARY_DIR}/resources/executable_properties/rssguard_os2.rc
)
endif(WIN32) endif(WIN32)
# Set special linker flag for Windows XP & MSVC++ 2013 support. # Set special linker flag for Windows XP & MSVC++ 2013 support.
@ -318,21 +260,6 @@ if(WIN32 AND MINGW)
set(APP_SOURCES set(APP_SOURCES
${APP_SOURCES} ${APP_SOURCES}
${CMAKE_BINARY_DIR}/resources/executable_properties/rssguard_win.rc) ${CMAKE_BINARY_DIR}/resources/executable_properties/rssguard_win.rc)
elseif(OS2)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Zstack 0x2000 -Zlinker \"DISABLE 1121\" -s -Zlinker /PM:PM -Zno-fork -Zhigh-mem -Zmap")
if(${ENABLE_OS2_RC})
enable_language(RC)
set(CMAKE_RC_COMPILER_INIT rc)
message(STATUS "[${APP_LOW_NAME}] Icon file binary will be builded for OS2.")
message(STATUS "[${APP_LOW_NAME}] Used tool is: ${CMAKE_RC_COMPILER}")
set(CMAKE_RC_COMPILE_OBJECT
"<CMAKE_RC_COMPILER> -n -r <SOURCE> <OBJECT>")
set(APP_SOURCES
${APP_SOURCES}
${CMAKE_BINARY_DIR}/resources/executable_properties/rssguard_os2.rc)
endif(${ENABLE_OS2_RC})
elseif(WIN32 AND MSVC) elseif(WIN32 AND MSVC)
# MSVC takes care of this automatically - no need to use windres.exe # MSVC takes care of this automatically - no need to use windres.exe
# for MSVC compilers. # for MSVC compilers.
@ -419,15 +346,6 @@ file( GLOB APP_TEXT
"resources/text/C*") "resources/text/C*")
if(WIN32) if(WIN32)
file( GLOB APP_DLLS_QT4_MSVC2013
"resources/binaries/windows/qt4-msvc2013/*.dll")
file( GLOB APP_DLLS_QT4_MSVC2013_IMAGEFORMATS
"resources/binaries/windows/qt4-msvc2013/imageformats/*.dll")
file( GLOB APP_DLLS_QT4_MSVC2013_SQLDRIVERS
"resources/binaries/windows/qt4-msvc2013/sqldrivers/*.dll")
file( GLOB APP_DLLS_QT5_MSVC2013 file( GLOB APP_DLLS_QT5_MSVC2013
"resources/binaries/windows/qt5-msvc2013/*.dll") "resources/binaries/windows/qt5-msvc2013/*.dll")
@ -450,23 +368,15 @@ if(APPLE)
endif(APPLE) endif(APPLE)
# Wrap files, create moc files. # Wrap files, create moc files.
if(USE_QT_5) qt5_wrap_ui(APP_UI ${APP_FORMS})
qt5_wrap_ui(APP_UI ${APP_FORMS})
# Load translations.
# Load translations. if(${Qt5LinguistTools_FOUND})
if(${Qt5LinguistTools_FOUND}) message(STATUS "[${APP_LOW_NAME}] Qt Linguist Tools found. Translations will get compiled.")
message(STATUS "[${APP_LOW_NAME}] Qt Linguist Tools found. Translations will get compiled.") qt5_add_translation(APP_QM ${APP_TRANSLATIONS})
qt5_add_translation(APP_QM ${APP_TRANSLATIONS}) else(${Qt5LinguistTools_FOUND})
else(${Qt5LinguistTools_FOUND}) message(STATUS "[${APP_LOW_NAME}] Qt Linguist Tools NOT found. No compilation for translations.")
message(STATUS "[${APP_LOW_NAME}] Qt Linguist Tools NOT found. No compilation for translations.") endif(${Qt5LinguistTools_FOUND})
endif(${Qt5LinguistTools_FOUND})
else(USE_QT_5)
qt4_wrap_cpp(APP_MOC ${APP_HEADERS})
qt4_wrap_ui(APP_UI ${APP_FORMS})
# Load translations.
qt4_add_translation(APP_QM ${APP_TRANSLATIONS})
endif(USE_QT_5)
# Include additional directory paths. # Include additional directory paths.
include_directories ( include_directories (
@ -481,99 +391,55 @@ include_directories (
) )
# Compile "rssguard" # Compile "rssguard"
if(USE_QT_5) add_executable(${EXE_NAME} WIN32 MACOSX_BUNDLE
add_executable(${EXE_NAME} WIN32 MACOSX_BUNDLE ${APP_SOURCES}
${APP_SOURCES} ${APP_FORMS}
${APP_FORMS} ${APP_RCC}
${APP_RCC} ${APP_QM}
${APP_QM} )
)
if(WIN32) if(WIN32)
target_link_libraries(${EXE_NAME} Qt5::WinMain) target_link_libraries(${EXE_NAME} Qt5::WinMain)
endif(WIN32) endif(WIN32)
if(UNIX) if(UNIX)
# Use modules from Qt.
qt5_use_modules(${EXE_NAME}
DBus
Core
Widgets
Sql
Network
Xml
WebKit
WebKitWidgets
PrintSupport
)
else(UNIX)
# Use modules from Qt. # Use modules from Qt.
qt5_use_modules(${EXE_NAME} qt5_use_modules(${EXE_NAME}
Core DBus
Widgets Core
Sql Widgets
Network Sql
Xml Network
WebKit Xml
WebKitWidgets WebEngineWidgets
PrintSupport PrintSupport
)
endif(UNIX)
# Setup compilation for Qt 4.
else(USE_QT_5)
add_executable(${EXE_NAME} WIN32 MACOSX_BUNDLE
${APP_SOURCES}
${APP_FORMS}
${APP_MOC}
${APP_RCC}
${APP_QM}
) )
else(UNIX)
if(UNIX) # Use modules from Qt.
# Link modules from Qt. qt5_use_modules(${EXE_NAME}
target_link_libraries(${EXE_NAME} Core
${QT_QTDBUS_LIBRARY} Widgets
${QT_QTCORE_LIBRARY} Sql
${QT_QTGUI_LIBRARY} Network
${QT_QTNETWORK_LIBRARY} Xml
${QT_QTSQL_LIBRARY} WebEngineWidgets
${QT_QTXML_LIBRARY} PrintSupport
${QT_QTMAIN_LIBRARY} )
${QT_QTWEBKIT_LIBRARY} endif(UNIX)
)
else(UNIX)
# Link modules from Qt.
target_link_libraries(${EXE_NAME}
${QT_QTCORE_LIBRARY}
${QT_QTGUI_LIBRARY}
${QT_QTNETWORK_LIBRARY}
${QT_QTSQL_LIBRARY}
${QT_QTXML_LIBRARY}
${QT_QTMAIN_LIBRARY}
${QT_QTWEBKIT_LIBRARY}
)
endif(UNIX)
endif(USE_QT_5)
# Installation stage. # Installation stage.
if(WIN32 OR OS2) if(WIN32)
message(STATUS "[${APP_LOW_NAME}] You will probably install on Windows or OS/2.") message(STATUS "[${APP_LOW_NAME}] You will probably install on Windows or OS/2.")
install(TARGETS ${EXE_NAME} RUNTIME DESTINATION ./) install(TARGETS ${EXE_NAME} RUNTIME DESTINATION ./)
# Copy DLLs and other binary files for main installation. # Copy DLLs and other binary files for main installation.
if(WIN32 AND USE_QT_5) if(WIN32)
install(FILES ${APP_DLLS_QT5_MSVC2013} DESTINATION ./) install(FILES ${APP_DLLS_QT5_MSVC2013} DESTINATION ./)
install(FILES ${APP_DLLS_QT5_MSVC2013_IMAGEFORMATS} DESTINATION ./imageformats) install(FILES ${APP_DLLS_QT5_MSVC2013_IMAGEFORMATS} DESTINATION ./imageformats)
install(FILES ${APP_DLLS_QT5_MSVC2013_SQLDRIVERS} DESTINATION ./sqldrivers) install(FILES ${APP_DLLS_QT5_MSVC2013_SQLDRIVERS} DESTINATION ./sqldrivers)
install(FILES ${APP_DLLS_QT5_MSVC2013_PLATFORMS} DESTINATION ./platforms) install(FILES ${APP_DLLS_QT5_MSVC2013_PLATFORMS} DESTINATION ./platforms)
install(FILES ${APP_DLLS_QT5_MSVC2013_PRINTSUPPORT} DESTINATION ./printsupport) install(FILES ${APP_DLLS_QT5_MSVC2013_PRINTSUPPORT} DESTINATION ./printsupport)
endif(WIN32 AND USE_QT_5) endif(WIN32)
if(WIN32 AND NOT USE_QT_5)
install(FILES ${APP_DLLS_QT4_MSVC2013} DESTINATION ./)
install(FILES ${APP_DLLS_QT4_MSVC2013_IMAGEFORMATS} DESTINATION ./imageformats)
install(FILES ${APP_DLLS_QT4_MSVC2013_SQLDRIVERS} DESTINATION ./sqldrivers)
endif(WIN32 AND NOT USE_QT_5)
install(DIRECTORY resources/graphics/icons/mini-kfaenza DESTINATION ./icons) install(DIRECTORY resources/graphics/icons/mini-kfaenza DESTINATION ./icons)
@ -661,7 +527,7 @@ elseif(UNIX)
install(FILES resources/graphics/${APP_LOW_NAME}_plain_128.png DESTINATION share/rssguard/icons RENAME ${APP_LOW_NAME}_plain.png) install(FILES resources/graphics/${APP_LOW_NAME}_plain_128.png DESTINATION share/rssguard/icons RENAME ${APP_LOW_NAME}_plain.png)
install(FILES ${APP_QM} DESTINATION share/${APP_LOW_NAME}/l10n) install(FILES ${APP_QM} DESTINATION share/${APP_LOW_NAME}/l10n)
install(FILES ${APP_TEXT} DESTINATION share/${APP_LOW_NAME}/information) install(FILES ${APP_TEXT} DESTINATION share/${APP_LOW_NAME}/information)
endif(WIN32 OR OS2) endif(WIN32)
# Custom target for packaging. # Custom target for packaging.
if(WIN32) if(WIN32)
@ -702,16 +568,8 @@ configure_file(
add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source) add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source)
# make lupdate implementation. # make lupdate implementation.
if(USE_QT_5) add_custom_target(lupdate
add_custom_target(lupdate ${Qt5Core_QMAKE_EXECUTABLE} -project -o ${CMAKE_BINARY_DIR}/${APP_LOW_NAME}.pro
${Qt5Core_QMAKE_EXECUTABLE} -project -o ${CMAKE_BINARY_DIR}/${APP_LOW_NAME}.pro COMMAND ${Qt5_LUPDATE_EXECUTABLE} -no-obsolete -ts ${APP_TRANSLATIONS_WO_QT} -pro ${CMAKE_BINARY_DIR}/${APP_LOW_NAME}.pro
COMMAND ${Qt5_LUPDATE_EXECUTABLE} -no-obsolete -ts ${APP_TRANSLATIONS_WO_QT} -pro ${CMAKE_BINARY_DIR}/${APP_LOW_NAME}.pro WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} )
)
else(USE_QT_5)
add_custom_target(lupdate
${QT_QMAKE_EXECUTABLE} -project -o ${CMAKE_BINARY_DIR}/${APP_LOW_NAME}.pro
COMMAND ${QT_LUPDATE_EXECUTABLE} -no-obsolete -ts ${APP_TRANSLATIONS_WO_QT} -pro ${CMAKE_BINARY_DIR}/${APP_LOW_NAME}.pro
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endif(USE_QT_5)

View File

@ -1 +0,0 @@
ICON 1 DISCARDABLE "@PROJECT_SOURCE_DIR@/resources/graphics/rssguard_os2.ico"

Binary file not shown.

View File

@ -53,6 +53,7 @@
#include <QThread> #include <QThread>
#include <QProgressBar> #include <QProgressBar>
#include <QStatusBar> #include <QStatusBar>
#include <QWebEngineSettings>
#include <QPointer> #include <QPointer>
@ -118,9 +119,9 @@ void FeedMessageViewer::loadSize() {
void FeedMessageViewer::loadMessageViewerFonts() { void FeedMessageViewer::loadMessageViewerFonts() {
const Settings *settings = qApp->settings(); const Settings *settings = qApp->settings();
QWebSettings *view_settings = m_messagesBrowser->view()->settings(); QWebEngineSettings *view_settings = m_messagesBrowser->view()->settings();
view_settings->setFontFamily(QWebSettings::StandardFont, settings->value(GROUP(Messages), view_settings->setFontFamily(QWebEngineSettings::StandardFont, settings->value(GROUP(Messages),
SETTING(Messages::PreviewerFontStandard)).toString()); SETTING(Messages::PreviewerFontStandard)).toString());
} }

View File

@ -23,7 +23,7 @@
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
#include <QPointer> #include <QPointer>
#include <QWebSettings> #include <QWebEngineSettings>
#include <QLocale> #include <QLocale>
@ -304,7 +304,7 @@ DKEY CategoriesExpandStates::ID = "categories_expand_sta
Settings::Settings(const QString &file_name, Format format, const SettingsProperties::SettingsType &status, QObject *parent) Settings::Settings(const QString &file_name, Format format, const SettingsProperties::SettingsType &status, QObject *parent)
: QSettings(file_name, format, parent), m_initializationStatus(status) { : QSettings(file_name, format, parent), m_initializationStatus(status) {
// Perform last-minute initializations. // Perform last-minute initializations.
Messages::PreviewerFontStandardDef = QWebSettings::globalSettings()->fontFamily(QWebSettings::StandardFont); Messages::PreviewerFontStandardDef = QWebEngineSettings::globalSettings()->fontFamily(QWebEngineSettings::StandardFont);
} }
Settings::~Settings() { Settings::~Settings() {
@ -357,11 +357,6 @@ Settings *Settings::setupSettings(QObject *parent) {
// Portable settings are available, use them. // Portable settings are available, use them.
new_settings = new Settings(properties.m_absoluteSettingsFileName, QSettings::IniFormat, properties.m_type, parent); new_settings = new Settings(properties.m_absoluteSettingsFileName, QSettings::IniFormat, properties.m_type, parent);
// Construct icon cache in the same path.
const QString web_path = properties.m_baseDirectory + QDir::separator() + QString(APP_DB_WEB_PATH);
QDir(web_path).mkpath(web_path);
QWebSettings::setIconDatabasePath(web_path);
// Check if portable settings are available. // Check if portable settings are available.
if (properties.m_type == SettingsProperties::Portable) { if (properties.m_type == SettingsProperties::Portable) {
qDebug("Initializing settings in '%s' (portable way).", qPrintable(QDir::toNativeSeparators(properties.m_absoluteSettingsFileName))); qDebug("Initializing settings in '%s' (portable way).", qPrintable(QDir::toNativeSeparators(properties.m_absoluteSettingsFileName)));

View File

@ -30,7 +30,7 @@
#include <QMenu> #include <QMenu>
#include <QMouseEvent> #include <QMouseEvent>
#include <QWebFrame> #include <QWebEnginePage>
AdBlockIcon::AdBlockIcon(QWidget *window, QWidget *parent) AdBlockIcon::AdBlockIcon(QWidget *window, QWidget *parent)
@ -71,7 +71,7 @@ void AdBlockIcon::createMenu(QMenu *menu) {
AdBlockCustomList *custom_list = manager->customList(); AdBlockCustomList *custom_list = manager->customList();
WebPage *page = qApp->mainForm()->tabWidget()->currentWidget()->webBrowser()->view()->page(); WebPage *page = qApp->mainForm()->tabWidget()->currentWidget()->webBrowser()->view()->page();
const QUrl page_url = page->mainFrame()->url(); const QUrl page_url = page->url();
menu->addAction(tr("Show Adblock &settings"), manager, SLOT(showDialog())); menu->addAction(tr("Show Adblock &settings"), manager, SLOT(showDialog()));
menu->addSeparator(); menu->addSeparator();

View File

@ -34,7 +34,7 @@
#include <QTextStream> #include <QTextStream>
#include <QDir> #include <QDir>
#include <QTimer> #include <QTimer>
#include <QWebFrame> #include <QWebEnginePage>
AdBlockManager *AdBlockManager::s_adBlockManager = NULL; AdBlockManager *AdBlockManager::s_adBlockManager = NULL;
@ -90,7 +90,7 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request) {
WebPage *web_page = static_cast<WebPage*>(v.value<void*>()); WebPage *web_page = static_cast<WebPage*>(v.value<void*>());
if (WebPage::isPointerSafeToUse(web_page)) { if (WebPage::isPointerSafeToUse(web_page)) {
if (!canBeBlocked(web_page->mainFrame()->url())) { if (!canBeBlocked(web_page->url())) {
return NULL; return NULL;
} }

View File

@ -56,8 +56,7 @@
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
#include <QNetworkRequest> #include <QNetworkRequest>
#include <QWebFrame> #include <QWebEnginePage>
#include <QWebPage>
AdBlockRule::AdBlockRule(const QString &filter, AdBlockSubscription* subscription) AdBlockRule::AdBlockRule(const QString &filter, AdBlockSubscription* subscription)
@ -289,21 +288,7 @@ bool AdBlockRule::matchObject(const QNetworkRequest &request) const {
} }
bool AdBlockRule::matchSubdocument(const QNetworkRequest &request) const { bool AdBlockRule::matchSubdocument(const QNetworkRequest &request) const {
QWebFrame *originatingFrame = static_cast<QWebFrame*>(request.originatingObject()); return false;
if (originatingFrame == NULL) {
return false;
}
QWebPage *page = originatingFrame->page();
if (page == NULL) {
return false;
}
bool match = !(originatingFrame == page->mainFrame());
return hasException(SubdocumentOption) ? !match : match;
} }
bool AdBlockRule::matchXmlHttpRequest(const QNetworkRequest &request) const { bool AdBlockRule::matchXmlHttpRequest(const QNetworkRequest &request) const {

View File

@ -57,7 +57,7 @@
#include <QTimer> #include <QTimer>
#include <QNetworkReply> #include <QNetworkReply>
#include <QDir> #include <QDir>
#include <QWebPage> #include <QWebEnginePage>
AdBlockSubscription::AdBlockSubscription(const QString &title, QObject *parent) AdBlockSubscription::AdBlockSubscription(const QString &title, QObject *parent)

View File

@ -38,7 +38,7 @@
#include <QProcess> #include <QProcess>
#include <QSettings> #include <QSettings>
#include <QDebug> #include <QDebug>
#include <QWebSettings> #include <QWebEngineSettings>
DownloadItem::DownloadItem(bool is_direct_download, QNetworkReply *reply, QWidget *parent) : QWidget(parent), DownloadItem::DownloadItem(bool is_direct_download, QNetworkReply *reply, QWidget *parent) : QWidget(parent),
@ -603,14 +603,12 @@ void DownloadManager::updateRow(DownloadItem *item) {
int old_height = m_ui->m_viewDownloads->rowHeight(row); int old_height = m_ui->m_viewDownloads->rowHeight(row);
m_ui->m_viewDownloads->setRowHeight(row, qMax(old_height, item->minimumSizeHint().height())); m_ui->m_viewDownloads->setRowHeight(row, qMax(old_height, item->minimumSizeHint().height()));
QWebSettings *globalSettings = QWebSettings::globalSettings();
// Remove the item if: // Remove the item if:
// a) It is not downloading and private browsing is enabled. // a) It is not downloading and private browsing is enabled.
// OR // OR
// b) Item is already downloaded and it should be remove from downloader list. // b) Item is already downloaded and it should be remove from downloader list.
bool remove = (!item->downloading() && globalSettings->testAttribute(QWebSettings::PrivateBrowsingEnabled)) || bool remove = item->downloadedSuccessfully() && removePolicy() == DownloadManager::OnSuccessfullDownload;
(item->downloadedSuccessfully() && removePolicy() == DownloadManager::OnSuccessfullDownload);
if (remove) { if (remove) {
m_model->removeRow(row); m_model->removeRow(row);

View File

@ -18,7 +18,6 @@
#include "network-web/webbrowser.h" #include "network-web/webbrowser.h"
#include "definitions/definitions.h" #include "definitions/definitions.h"
#include "network-web/webbrowsernetworkaccessmanager.h"
#include "network-web/webpage.h" #include "network-web/webpage.h"
#include "network-web/webview.h" #include "network-web/webview.h"
#include "network-web/networkfactory.h" #include "network-web/networkfactory.h"
@ -33,7 +32,7 @@
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QToolBar> #include <QToolBar>
#include <QAction> #include <QAction>
#include <QWebFrame> #include <QWebEnginePage>
#include <QWidgetAction> #include <QWidgetAction>
#include <QSlider> #include <QSlider>
#include <QLabel> #include <QLabel>
@ -50,10 +49,10 @@ WebBrowser::WebBrowser(QWidget *parent)
m_toolBar(new QToolBar(tr("Navigation panel"), this)), m_toolBar(new QToolBar(tr("Navigation panel"), this)),
m_webView(new WebView(this)), m_webView(new WebView(this)),
m_txtLocation(new LocationLineEdit(this)), m_txtLocation(new LocationLineEdit(this)),
m_actionBack(m_webView->pageAction(QWebPage::Back)), m_actionBack(m_webView->pageAction(QWebEnginePage::Back)),
m_actionForward(m_webView->pageAction(QWebPage::Forward)), m_actionForward(m_webView->pageAction(QWebEnginePage::Forward)),
m_actionReload(m_webView->pageAction(QWebPage::Reload)), m_actionReload(m_webView->pageAction(QWebEnginePage::Reload)),
m_actionStop(m_webView->pageAction(QWebPage::Stop)) { m_actionStop(m_webView->pageAction(QWebEnginePage::Stop)) {
// Add this new instance to the global list of web browsers. // Add this new instance to the global list of web browsers.
// NOTE: This is used primarily for dynamic icon theme switching. // NOTE: This is used primarily for dynamic icon theme switching.
m_runningWebBrowsers.append(this); m_runningWebBrowsers.append(this);
@ -168,7 +167,8 @@ void WebBrowser::onLoadingStarted() {
void WebBrowser::onLoadingProgress(int progress) { void WebBrowser::onLoadingProgress(int progress) {
m_loadingProgress->setValue(progress); m_loadingProgress->setValue(progress);
m_lblProgress->setText(QString(QSL(" %1 kB / %2 kB")).arg(m_webView->page()->bytesReceived() / 1000).arg(m_webView->page()->totalBytes() / 1000)); // TODO: TODO
//m_lblProgress->setText(QString(QSL(" %1 kB / %2 kB")).arg(m_webView->page()-> / 1000).arg(m_webView->page()->totalBytes() / 1000));
} }
void WebBrowser::onLoadingFinished(bool success) { void WebBrowser::onLoadingFinished(bool success) {
@ -209,7 +209,8 @@ void WebBrowser::createConnections() {
} }
void WebBrowser::onIconChanged() { void WebBrowser::onIconChanged() {
emit iconChanged(m_index, m_webView->icon()); // TODO: todo
//emit iconChanged(m_index, m_webView->icon());
} }
void WebBrowser::onTitleChanged(const QString &new_title) { void WebBrowser::onTitleChanged(const QString &new_title) {
@ -319,3 +320,11 @@ void WebBrowser::setupIcons() {
m_actionStop->setIcon(qApp->icons()->fromTheme(QSL("go-stop"))); m_actionStop->setIcon(qApp->icons()->fromTheme(QSL("go-stop")));
m_webView->setupIcons(); m_webView->setupIcons();
} }
QIcon WebBrowser::icon() const {
return QIcon();
// TODO: TODO.
//return m_webView->iconUrl();
}

View File

@ -37,7 +37,6 @@ class QHBoxLayout;
class QProgressBar; class QProgressBar;
class QMenu; class QMenu;
class QLabel; class QLabel;
class WebBrowserNetworkAccessManager;
class TabWidget; class TabWidget;
class WebBrowser : public TabContent { class WebBrowser : public TabContent {
@ -52,9 +51,7 @@ class WebBrowser : public TabContent {
void setupIcons(); void setupIcons();
// Returns icon associated with currently loaded website. // Returns icon associated with currently loaded website.
inline QIcon icon() const { QIcon icon() const;
return m_webView->icon();
}
inline WebView *view() const { inline WebView *view() const {
return m_webView; return m_webView;

View File

@ -3,7 +3,7 @@
#include "miscellaneous/application.h" #include "miscellaneous/application.h"
#include <QRegExp> #include <QRegExp>
#include <QWebSettings> #include <QWebEngineSettings>
#include <QProcess> #include <QProcess>
#include <QUrl> #include <QUrl>
#include <QDesktopServices> #include <QDesktopServices>
@ -14,7 +14,7 @@ QPointer<WebFactory> WebFactory::s_instance;
WebFactory::WebFactory(QObject *parent) WebFactory::WebFactory(QObject *parent)
: QObject(parent), m_escapes(QMap<QString, QString>()), : QObject(parent), m_escapes(QMap<QString, QString>()),
m_deEscapes(QMap<QString, QString>()), m_deEscapes(QMap<QString, QString>()),
m_globalSettings(QWebSettings::globalSettings()) { m_globalSettings(QWebEngineSettings::globalSettings()) {
} }
WebFactory::~WebFactory() { WebFactory::~WebFactory() {
@ -34,7 +34,7 @@ bool WebFactory::sendMessageViaEmail(const Message &message) {
const QString arguments = qApp->settings()->value(GROUP(Browser), SETTING(Browser::CustomExternalEmailArguments)).toString(); const QString arguments = qApp->settings()->value(GROUP(Browser), SETTING(Browser::CustomExternalEmailArguments)).toString();
return QProcess::startDetached(QString("\"") + browser + QSL("\" ") + arguments.arg(message.m_title, return QProcess::startDetached(QString("\"") + browser + QSL("\" ") + arguments.arg(message.m_title,
stripTags(message.m_contents))); stripTags(message.m_contents)));
} }
else { else {
// Send it via mailto protocol. // Send it via mailto protocol.
@ -71,7 +71,7 @@ void WebFactory::switchJavascript(bool enable, bool save_settings) {
qApp->settings()->setValue(GROUP(Browser), Browser::JavascriptEnabled, enable); qApp->settings()->setValue(GROUP(Browser), Browser::JavascriptEnabled, enable);
} }
m_globalSettings->setAttribute(QWebSettings::JavascriptEnabled, enable); m_globalSettings->setAttribute(QWebEngineSettings::JavascriptEnabled, enable);
emit javascriptSwitched(enable); emit javascriptSwitched(enable);
} }
@ -80,7 +80,7 @@ void WebFactory::switchPlugins(bool enable, bool save_settings) {
qApp->settings()->setValue(GROUP(Browser), Browser::PluginsEnabled, enable); qApp->settings()->setValue(GROUP(Browser), Browser::PluginsEnabled, enable);
} }
m_globalSettings->setAttribute(QWebSettings::PluginsEnabled, enable); m_globalSettings->setAttribute(QWebEngineSettings::PluginsEnabled, enable);
emit pluginsSwitched(enable); emit pluginsSwitched(enable);
} }
@ -89,7 +89,7 @@ void WebFactory::switchImages(bool enable, bool save_settings) {
qApp->settings()->setValue(GROUP(Browser), Browser::ImagesEnabled, enable); qApp->settings()->setValue(GROUP(Browser), Browser::ImagesEnabled, enable);
} }
m_globalSettings->setAttribute(QWebSettings::AutoLoadImages, enable); m_globalSettings->setAttribute(QWebEngineSettings::AutoLoadImages, enable);
emit imagesLoadingSwitched(enable); emit imagesLoadingSwitched(enable);
} }
@ -102,15 +102,15 @@ WebFactory *WebFactory::instance() {
} }
bool WebFactory::javascriptEnabled() const { bool WebFactory::javascriptEnabled() const {
return m_globalSettings->testAttribute(QWebSettings::JavascriptEnabled); return m_globalSettings->testAttribute(QWebEngineSettings::JavascriptEnabled);
} }
bool WebFactory::pluginsEnabled() const { bool WebFactory::pluginsEnabled() const {
return m_globalSettings->testAttribute(QWebSettings::PluginsEnabled); return m_globalSettings->testAttribute(QWebEngineSettings::PluginsEnabled);
} }
bool WebFactory::autoloadImages() const { bool WebFactory::autoloadImages() const {
return m_globalSettings->testAttribute(QWebSettings::AutoLoadImages); return m_globalSettings->testAttribute(QWebEngineSettings::AutoLoadImages);
} }
QString WebFactory::stripTags(QString text) { QString WebFactory::stripTags(QString text) {

View File

@ -9,7 +9,7 @@
#include <QMap> #include <QMap>
class QWebSettings; class QWebEngineSettings;
class WebFactory : public QObject { class WebFactory : public QObject {
Q_OBJECT Q_OBJECT
@ -67,7 +67,7 @@ class WebFactory : public QObject {
QMap<QString, QString> m_escapes; QMap<QString, QString> m_escapes;
QMap<QString, QString> m_deEscapes; QMap<QString, QString> m_deEscapes;
QWebSettings *m_globalSettings; QWebEngineSettings *m_globalSettings;
// Singleton. // Singleton.
static QPointer<WebFactory> s_instance; static QPointer<WebFactory> s_instance;

View File

@ -17,29 +17,21 @@
#include "network-web/webpage.h" #include "network-web/webpage.h"
#include "network-web/webbrowsernetworkaccessmanager.h"
#include "network-web/webbrowser.h" #include "network-web/webbrowser.h"
#include "miscellaneous/application.h" #include "miscellaneous/application.h"
#include "network-web/adblock/adblockmanager.h" #include "network-web/adblock/adblockmanager.h"
#include <QNetworkReply> #include <QNetworkReply>
#include <QWebElement>
#include <QWebFrame>
QList<WebPage*> WebPage::s_livingPages; QList<WebPage*> WebPage::s_livingPages;
WebPage::WebPage(QObject *parent) WebPage::WebPage(QObject *parent)
: QWebPage(parent), m_loadProgress(-1) { : QWebEnginePage(parent), m_loadProgress(-1) {
// Setup global network access manager.
// NOTE: This makes network settings easy for all web browsers.
setNetworkAccessManager(new WebBrowserNetworkAccessManager(this, this));
setForwardUnsupportedContent(true);
connect(this, SIGNAL(unsupportedContent(QNetworkReply*)), this, SLOT(handleUnsupportedContent(QNetworkReply*)));
connect(this, SIGNAL(loadProgress(int)), this, SLOT(progress(int))); connect(this, SIGNAL(loadProgress(int)), this, SLOT(progress(int)));
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(finished())); connect(this, SIGNAL(loadFinished(bool)), this, SLOT(finished()));
connect(this, SIGNAL(urlChanged(QUrl)), this, SLOT(urlChanged(QUrl)));
s_livingPages.append(this); s_livingPages.append(this);
} }
@ -58,65 +50,6 @@ void WebPage::progress(int prog) {
void WebPage::finished() { void WebPage::finished() {
progress(100); progress(100);
cleanBlockedObjects();
}
void WebPage::cleanBlockedObjects() {
AdBlockManager *manager = AdBlockManager::instance();
if (!manager->isEnabled()) {
return;
}
const QWebElement doc_element = mainFrame()->documentElement();
foreach (const AdBlockedEntry &entry, m_adBlockedEntries) {
const QString url_string = entry.url.toString();
if (url_string.endsWith(QL1S(".js")) || url_string.endsWith(QL1S(".css"))) {
continue;
}
QString url_end;
int pos = url_string.lastIndexOf(QL1C('/'));
if (pos > 8) {
url_end = url_string.mid(pos + 1);
}
if (url_string.endsWith(QL1C('/'))) {
url_end = url_string.left(url_string.size() - 1);
}
QString selector(QSL("img[src$=\"%1\"], iframe[src$=\"%1\"],embed[src$=\"%1\"]"));
QWebElementCollection elements = doc_element.findAll(selector.arg(url_end));
foreach (QWebElement element, elements) {
QString src = element.attribute(QSL("src"));
src.remove(QL1S("../"));
if (url_string.contains(src)) {
element.setStyleProperty(QSL("display"), QSL("none"));
}
}
}
// Apply domain-specific element hiding rules
QString element_hiding = manager->elementHidingRulesForDomain(mainFrame()->url());
if (element_hiding.isEmpty()) {
return;
}
element_hiding.append(QL1S("\n</style>"));
QWebElement body_element = doc_element.findFirst(QSL("body"));
body_element.appendInside(QSL("<style type=\"text/css\">\n/* AdBlock for RSS Guard */\n") + element_hiding);
// When hiding some elements, scroll position of page will change
// If user loaded anchor link in background tab (and didn't show it yet), fix the scroll position
if (view() && !view()->isVisible() && !mainFrame()->url().fragment().isEmpty()) {
mainFrame()->scrollToAnchor(mainFrame()->url().fragment());
}
} }
void WebPage::urlChanged(const QUrl &url) { void WebPage::urlChanged(const QUrl &url) {
@ -150,10 +83,6 @@ bool WebPage::isPointerSafeToUse(WebPage *page) {
return page == 0 ? false : s_livingPages.contains(page); return page == 0 ? false : s_livingPages.contains(page);
} }
QString WebPage::toPlainText() const {
return mainFrame()->toPlainText();
}
void WebPage::populateNetworkRequest(QNetworkRequest &request) { void WebPage::populateNetworkRequest(QNetworkRequest &request) {
WebPage *page_pointer = this; WebPage *page_pointer = this;
@ -161,48 +90,8 @@ void WebPage::populateNetworkRequest(QNetworkRequest &request) {
request.setAttribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100), variant); request.setAttribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100), variant);
} }
void WebPage::handleUnsupportedContent(QNetworkReply *reply) {
if (reply != NULL) {
const QUrl reply_url = reply->url();
if (reply_url.scheme() == QL1S("abp")) {
return;
}
switch (reply->error()) {
case QNetworkReply::NoError:
if (reply->header(QNetworkRequest::ContentTypeHeader).isValid()) {
qApp->downloadManager()->handleUnsupportedContent(reply, true);
return;
}
default:
return;
}
}
}
QString WebPage::toHtml() const { QString WebPage::toHtml() const {
return mainFrame()->toHtml(); return QString();
} // TODO: TODO
//return mainFrame()->toHtml();
bool WebPage::acceptNavigationRequest(QWebFrame *frame,
const QNetworkRequest &request,
QWebPage::NavigationType type) {
const QString scheme = request.url().scheme();
if (scheme == QL1S("mailto") || scheme == QL1S("ftp")) {
qWarning("Received request with scheme '%s', blocking it.", qPrintable(scheme));
return false;
}
if (type == QWebPage::NavigationTypeLinkClicked &&
frame == mainFrame()) {
// Make sure that appropriate signal is emitted even if
// no delegation is enabled.
emit linkClicked(request.url());
}
qDebug("Accepting request '%s'.", qPrintable(request.url().toString()));
return QWebPage::acceptNavigationRequest(frame, request, type);
} }

View File

@ -18,13 +18,13 @@
#ifndef WEBPAGE_H #ifndef WEBPAGE_H
#define WEBPAGE_H #define WEBPAGE_H
#include <QWebPage> #include <QWebEnginePage>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
class AdBlockRule; class AdBlockRule;
class WebPage : public QWebPage { class WebPage : public QWebEnginePage {
Q_OBJECT Q_OBJECT
public: public:
@ -42,7 +42,6 @@ class WebPage : public QWebPage {
virtual ~WebPage(); virtual ~WebPage();
QString toHtml() const; QString toHtml() const;
QString toPlainText() const;
bool isLoading() const; bool isLoading() const;
QVector<AdBlockedEntry> adBlockedEntries() const; QVector<AdBlockedEntry> adBlockedEntries() const;
@ -54,14 +53,8 @@ class WebPage : public QWebPage {
private slots: private slots:
void progress(int prog); void progress(int prog);
void finished(); void finished();
void cleanBlockedObjects();
void urlChanged(const QUrl &url); void urlChanged(const QUrl &url);
void handleUnsupportedContent(QNetworkReply *reply);
protected:
bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type);
private: private:
QVector<AdBlockedEntry> m_adBlockedEntries; QVector<AdBlockedEntry> m_adBlockedEntries;
int m_loadProgress; int m_loadProgress;

View File

@ -32,7 +32,7 @@
#include <QMenu> #include <QMenu>
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
#include <QWebFrame> #include <QWebEnginePage>
#include <QContextMenuEvent> #include <QContextMenuEvent>
#include <QDateTime> #include <QDateTime>
#include <QClipboard> #include <QClipboard>
@ -46,7 +46,7 @@
WebView::WebView(QWidget *parent) WebView::WebView(QWidget *parent)
: QWebView(parent), m_page(new WebPage(this)) { : QWebEngineView(parent), m_page(new WebPage(this)) {
setPage(m_page); setPage(m_page);
setContextMenuPolicy(Qt::CustomContextMenu); setContextMenuPolicy(Qt::CustomContextMenu);
initializeActions(); initializeActions();
@ -133,7 +133,7 @@ void WebView::saveCurrentPageToFile() {
QFile selected_file_handle(selected_file); QFile selected_file_handle(selected_file);
if (selected_file_handle.open(QIODevice::WriteOnly | QIODevice::Unbuffered)) { if (selected_file_handle.open(QIODevice::WriteOnly | QIODevice::Unbuffered)) {
const QString html_text = page()->mainFrame()->toHtml(); const QString html_text = page()->toHtml();
QTextStream str(&selected_file_handle); QTextStream str(&selected_file_handle);
str.setCodec("UTF-16"); str.setCodec("UTF-16");
@ -183,13 +183,13 @@ void WebView::setupIcons() {
void WebView::initializeActions() { void WebView::initializeActions() {
// Create needed actions. // Create needed actions.
m_actionReload = pageAction(QWebPage::Reload); m_actionReload = pageAction(QWebEnginePage::Reload);
m_actionReload->setParent(this); m_actionReload->setParent(this);
m_actionPrint = new QAction(tr("Print"), this); m_actionPrint = new QAction(tr("Print"), this);
m_actionPrint->setToolTip(tr("Print current web page.")); m_actionPrint->setToolTip(tr("Print current web page."));
m_actionCopySelectedItem = pageAction(QWebPage::Copy); m_actionCopySelectedItem = pageAction(QWebEnginePage::Copy);
m_actionCopySelectedItem->setParent(this); m_actionCopySelectedItem->setParent(this);
#if defined(Q_OS_OS2) #if defined(Q_OS_OS2)
@ -197,33 +197,34 @@ void WebView::initializeActions() {
addAction(m_actionCopySelectedItem); addAction(m_actionCopySelectedItem);
#endif #endif
m_actionSaveHyperlinkAs = pageAction(QWebPage::DownloadLinkToDisk); m_actionSaveHyperlinkAs = pageAction(QWebEnginePage::DownloadLinkToDisk);
m_actionSaveHyperlinkAs->setParent(this); m_actionSaveHyperlinkAs->setParent(this);
m_actionCopyLink = pageAction(QWebPage::CopyLinkToClipboard); m_actionCopyLink = pageAction(QWebEnginePage::CopyLinkToClipboard);
m_actionCopyLink->setParent(this); m_actionCopyLink->setParent(this);
m_actionCopyImage = pageAction(QWebPage::CopyImageToClipboard); m_actionCopyImage = pageAction(QWebEnginePage::CopyImageToClipboard);
m_actionCopyImage->setParent(this); m_actionCopyImage->setParent(this);
m_actionSaveImageAs = pageAction(QWebPage::DownloadImageToDisk); m_actionSaveImageAs = pageAction(QWebEnginePage::DownloadImageToDisk);
m_actionSaveImageAs->setParent(this); m_actionSaveImageAs->setParent(this);
m_actionSavePageAs = new QAction(qApp->icons()->fromTheme(QSL("document-download")), tr("Save page as..."), this); m_actionSavePageAs = new QAction(qApp->icons()->fromTheme(QSL("document-download")), tr("Save page as..."), this);
#if QT_VERSION >= 0x040800 #if QT_VERSION >= 0x040800
m_actionCopyImageUrl = pageAction(QWebPage::CopyImageUrlToClipboard); m_actionCopyImageUrl = pageAction(QWebEnginePage::CopyImageUrlToClipboard);
m_actionCopyImageUrl->setParent(this); m_actionCopyImageUrl->setParent(this);
#endif #endif
m_actionOpenLinkNewTab = pageAction(QWebPage::OpenLinkInNewWindow); m_actionOpenLinkNewTab = pageAction(QWebEnginePage::OpenLinkInNewTab);
m_actionOpenLinkNewTab->setParent(this); m_actionOpenLinkNewTab->setParent(this);
m_actionOpenLinkThisTab = pageAction(QWebPage::OpenLink); m_actionOpenLinkThisTab = pageAction(QWebEnginePage::OpenLinkInThisWindow);
m_actionOpenLinkThisTab->setParent(this); m_actionOpenLinkThisTab->setParent(this);
m_actionOpenLinkExternally = new QAction(tr("Open link in external browser"), this); m_actionOpenLinkExternally = new QAction(tr("Open link in external browser"), this);
m_actionOpenImageNewTab = pageAction(QWebPage::OpenImageInNewWindow); // TODO: bude fungovat?
m_actionOpenImageNewTab = pageAction(QWebEnginePage::OpenLinkInNewTab);
m_actionOpenImageNewTab->setParent(this); m_actionOpenImageNewTab->setParent(this);
m_actionLookupText = new QAction("", this); m_actionLookupText = new QAction("", this);
@ -275,68 +276,8 @@ void WebView::displayErrorPage() {
*/ */
} }
void WebView::popupContextMenu(const QPoint &pos) { void WebView::popupContextMenu(const QPoint &pos) {
QMenu context_menu(tr("Web browser"), this); page()->createStandardContextMenu()->exec(mapToGlobal(pos));
QMenu image_submenu(tr("Image"), &context_menu);
QMenu link_submenu(tr("Hyperlink"), this);
QWebHitTestResult hit_result = page()->mainFrame()->hitTestContent(pos);
image_submenu.setIcon(qApp->icons()->fromTheme(QSL("image-generic")));
link_submenu.setIcon(qApp->icons()->fromTheme(QSL("text-html")));
// Assemble the menu from actions.
QString current_url = url().toString();
if (!current_url.isEmpty() && current_url != INTERNAL_URL_EMPTY && current_url != INTERNAL_URL_BLANK) {
context_menu.addAction(m_actionPrint);
if (current_url != INTERNAL_URL_NEWSPAPER) {
context_menu.addAction(m_actionReload);
}
}
context_menu.addAction(m_actionCopySelectedItem);
context_menu.addAction(m_actionSavePageAs);
const QUrl hit_url = hit_result.linkUrl();
const QUrl hit_image_url = hit_result.imageUrl();
if (hit_url.isValid()) {
m_contextLinkUrl = hit_url;
context_menu.addMenu(&link_submenu);
link_submenu.addAction(m_actionOpenLinkThisTab);
link_submenu.addAction(m_actionOpenLinkNewTab);
link_submenu.addAction(m_actionOpenLinkExternally);
link_submenu.addAction(m_actionCopyLink);
link_submenu.addAction(m_actionSaveHyperlinkAs);
}
if (!hit_result.pixmap().isNull()) {
// Add 'Image' menu, because if user clicked image it needs to be visible.
context_menu.addMenu(&image_submenu);
if (hit_image_url.isValid()) {
m_contextImageUrl = hit_image_url;
image_submenu.addAction(m_actionOpenImageNewTab);
#if QT_VERSION >= 0x040800
image_submenu.addAction(m_actionCopyImageUrl);
#endif
}
image_submenu.addAction(m_actionCopyImage);
image_submenu.addAction(m_actionSaveImageAs);
}
if (!selectedText().isEmpty()) {
m_actionLookupText->setText(tr("Search \"%1\" via Google...").arg(TextFactory::shorten(selectedText())));
context_menu.addAction(m_actionLookupText);
}
// Display the menu.
setActionTexts();
context_menu.exec(mapToGlobal(pos));
} }
void WebView::printCurrentPage() { void WebView::printCurrentPage() {
@ -350,7 +291,8 @@ void WebView::downloadLink(const QNetworkRequest &request) {
} }
void WebView::mousePressEvent(QMouseEvent *event) { void WebView::mousePressEvent(QMouseEvent *event) {
if (event->button() & Qt::LeftButton && event->modifiers() & Qt::ControlModifier) { // TODO: TODO
/*if (event->button() & Qt::LeftButton && event->modifiers() & Qt::ControlModifier) {
QWebHitTestResult hit_result = page()->mainFrame()->hitTestContent(event->pos()); QWebHitTestResult hit_result = page()->mainFrame()->hitTestContent(event->pos());
// Check if user clicked with middle mouse button on some // Check if user clicked with middle mouse button on some
@ -367,12 +309,12 @@ void WebView::mousePressEvent(QMouseEvent *event) {
return; return;
} }
} }
else if (event->button() & Qt::MiddleButton) { else */if (event->button() & Qt::MiddleButton) {
m_gestureOrigin = event->pos(); m_gestureOrigin = event->pos();
return; return;
} }
QWebView::mousePressEvent(event); QWebEngineView::mousePressEvent(event);
} }
void WebView::mouseReleaseEvent(QMouseEvent *event) { void WebView::mouseReleaseEvent(QMouseEvent *event) {
@ -402,7 +344,7 @@ void WebView::mouseReleaseEvent(QMouseEvent *event) {
} }
} }
QWebView::mouseReleaseEvent(event); QWebEngineView::mouseReleaseEvent(event);
} }
void WebView::wheelEvent(QWheelEvent *event) { void WebView::wheelEvent(QWheelEvent *event) {
@ -419,7 +361,7 @@ void WebView::wheelEvent(QWheelEvent *event) {
} }
} }
QWebView::wheelEvent(event); QWebEngineView::wheelEvent(event);
} }
bool WebView::increaseWebPageZoom() { bool WebView::increaseWebPageZoom() {

View File

@ -18,14 +18,14 @@
#ifndef BASEWEBVIEW_H #ifndef BASEWEBVIEW_H
#define BASEWEBVIEW_H #define BASEWEBVIEW_H
#include <QWebView> #include <QWebEngineView>
class QAction; class QAction;
class QPaintEvent; class QPaintEvent;
class WebPage; class WebPage;
class WebView : public QWebView { class WebView : public QWebEngineView {
Q_OBJECT Q_OBJECT
public: public: