Added support for Qt 4, fully compiles and runs.

This commit is contained in:
Martin Rotter 2013-08-30 17:40:17 +02:00
parent 705811a401
commit 253ae7b84f
40 changed files with 466 additions and 285 deletions

View File

@ -5,7 +5,7 @@ project(rssguard)
set(APP_NAME "RSS Guard") set(APP_NAME "RSS Guard")
set(APP_UP_NAME "RSSGuard") set(APP_UP_NAME "RSSGuard")
set(APP_LOW_NAME "rssguard") set(APP_LOW_NAME "rssguard")
set(APP_VERSION "2.0.0-prealpha-1") set(APP_VERSION "2.0.0-prealpha-2")
set(APP_AUTHOR "Martin Rotter") set(APP_AUTHOR "Martin Rotter")
set(APP_URL "http://rssguard.sf.net") set(APP_URL "http://rssguard.sf.net")
@ -22,12 +22,19 @@ endif(APPLE)
# Find includes in corresponding build directories # Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# 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.")
# Select which Qt version to use.
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)
else(${USE_QT_5})
message(STATUS "[${APP_LOW_NAME}] Using Qt 4 library for building.")
endif(${USE_QT_5})
if(EXISTS "${PROJECT_SOURCE_DIR}/.git") if(EXISTS "${PROJECT_SOURCE_DIR}/.git")
find_package(Git) find_package(Git)
if(GIT_FOUND) if(GIT_FOUND)
@ -99,36 +106,43 @@ endif(CMAKE_BUILD_TYPE STREQUAL "release" OR CMAKE_BUILD_TYPE STREQUAL "Release"
# Force Qt to use string builders. # Force Qt to use string builders.
add_definitions(-DQT_USE_QSTRINGBUILDER) add_definitions(-DQT_USE_QSTRINGBUILDER)
# Check for C++ 11 features availability.
# See http://stackoverflow.com/questions/10984442/how-to-detect-c11-support-of-a-compiler-with-cmake
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION
)
if(NOT (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.")
else(NOT (GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7))
add_definitions(-std=c++11)
endif(NOT (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.")
endif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
# Unicode settings. # Unicode settings.
add_definitions(-DUNICODE -D_UNICODE) add_definitions(-DUNICODE -D_UNICODE)
# Find all needed Qt modules. if(${USE_QT_5})
find_package(Qt5Sql) # Check for C++ 11 features availability.
find_package(Qt5WebKit) # See http://stackoverflow.com/questions/10984442/how-to-detect-c11-support-of-a-compiler-with-cmake
find_package(Qt5WebKitWidgets) if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
find_package(Qt5Widgets) execute_process(
find_package(Qt5Xml) COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION
find_package(Qt5Network) )
find_package(Qt5LinguistTools)
if(NOT (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.")
else(NOT (GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7))
add_definitions(-std=c++11)
endif(NOT (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.")
endif("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
endif(${USE_QT_5})
# Setup libraries.
if(${USE_QT_5})
find_package(Qt5Sql)
find_package(Qt5WebKit)
find_package(Qt5WebKitWidgets)
find_package(Qt5Widgets)
find_package(Qt5Xml)
find_package(Qt5Network)
find_package(Qt5LinguistTools)
else(${USE_QT_5})
find_package(Qt4 REQUIRED QtCore QtGui QtSql QtNetwork QtWebkit QtXml)
include(${QT_USE_FILE})
endif(${USE_QT_5})
# Compile application icon if compiling with MinGW on WIN32. # Compile application icon if compiling with MinGW on WIN32.
if(MINGW AND WIN32) if(MINGW AND WIN32)
@ -263,16 +277,26 @@ set(APP_MISC
) )
# Wrap files, create moc files. # Wrap files, create moc files.
qt5_wrap_cpp(APP_MOC ${APP_HEADERS}) if(${USE_QT_5})
qt5_wrap_ui(APP_UI ${APP_FORMS}) #qt5_wrap_cpp(APP_MOC ${APP_HEADERS})
qt5_add_resources(APP_RCC ${APP_RESOURCES}) qt5_wrap_ui(APP_UI ${APP_FORMS})
qt5_add_resources(APP_RCC ${APP_RESOURCES})
if(Qt5LinguistTools_FOUND) # Load translations.
message(STATUS "[${APP_LOW_NAME}] Qt Linguist Tools found. Translations will get refreshed.") if(Qt5LinguistTools_FOUND)
qt5_add_translation(APP_QM ${APP_TRANSLATIONS}) message(STATUS "[${APP_LOW_NAME}] Qt Linguist Tools found. Translations will get refreshed.")
else(Qt5LinguistTools_FOUND) qt5_add_translation(APP_QM ${APP_TRANSLATIONS})
message(STATUS "[${APP_LOW_NAME}] Qt Linguist Tools NOT found. No refreshing for translations.") else(Qt5LinguistTools_FOUND)
endif(Qt5LinguistTools_FOUND) message(STATUS "[${APP_LOW_NAME}] Qt Linguist Tools NOT found. No refreshing for translations.")
endif(Qt5LinguistTools_FOUND)
else(${USE_QT_5})
qt4_wrap_cpp(APP_MOC ${APP_HEADERS})
qt4_wrap_ui(APP_UI ${APP_FORMS})
qt4_add_resources(APP_RCC ${APP_RESOURCES})
# 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 (
@ -282,33 +306,55 @@ include_directories (
${CMAKE_CURRENT_BINARY_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}/src
) )
if(WIN32) # Setup compilation.
if(${USE_QT_5})
if(WIN32)
add_executable(${EXE_NAME} WIN32
${APP_SOURCES}
${APP_FORMS}
${APP_RCC}
${APP_QM}
)
target_link_libraries(${EXE_NAME} Qt5::WinMain)
else(WIN32)
add_executable(${EXE_NAME}
${APP_SOURCES}
${APP_FORMS}
${APP_RCC}
${APP_QM}
)
endif(WIN32)
# Use modules from Qt.
qt5_use_modules(${EXE_NAME}
Core
Widgets
Sql
Network
Xml
WebKit
WebKitWidgets
)
else(${USE_QT_5})
add_executable(${EXE_NAME} WIN32 add_executable(${EXE_NAME} WIN32
${APP_SOURCES} ${APP_SOURCES}
${APP_FORMS} ${APP_FORMS}
${APP_MOC}
${APP_RCC} ${APP_RCC}
${APP_QM} ${APP_QM}
) )
target_link_libraries(${EXE_NAME} Qt5::WinMain)
else(WIN32)
add_executable(${EXE_NAME}
${APP_SOURCES}
${APP_FORMS}
${APP_RCC}
${APP_QM}
)
endif(WIN32)
# Use modules from Qt. # Link modules from Qt.
qt5_use_modules(${EXE_NAME} target_link_libraries( ${EXE_NAME}
Core ${QT_QTCORE_LIBRARY}
Widgets ${QT_QTGUI_LIBRARY}
Sql ${QT_QTNETWORK_LIBRARY}
Network ${QT_QTSQL_LIBRARY}
Xml ${QT_QTXML_LIBRARY}
WebKit ${QT_QTMAIN_LIBRARY}
WebKitWidgets ${QT_QTWEBKIT_LIBRARY}
) )
endif(${USE_QT_5})
# Installation stage. # Installation stage.
if(WIN32) if(WIN32)
@ -366,8 +412,16 @@ include(CPack)
add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source) add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source)
# make lupdate and make lrelease implementation. # make lupdate and make lrelease implementation.
add_custom_target(lupdate if(${USE_QT_5})
${Qt5Core_QMAKE_EXECUTABLE} -project -o ${CMAKE_CURRENT_BINARY_DIR}/${APP_LOW_NAME}.pro add_custom_target(lupdate
COMMAND ${Qt5_LUPDATE_EXECUTABLE} -ts ${APP_TRANSLATIONS_WO_QT} -pro ${CMAKE_CURRENT_BINARY_DIR}/${APP_LOW_NAME}.pro ${Qt5Core_QMAKE_EXECUTABLE} -project -o ${CMAKE_CURRENT_BINARY_DIR}/${APP_LOW_NAME}.pro
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMAND ${Qt5_LUPDATE_EXECUTABLE} -ts ${APP_TRANSLATIONS_WO_QT} -pro ${CMAKE_CURRENT_BINARY_DIR}/${APP_LOW_NAME}.pro
) WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
else(${USE_QT_5})
add_custom_target(lupdate
${QT_QMAKE_EXECUTABLE} -project -o ${CMAKE_CURRENT_BINARY_DIR}/${APP_LOW_NAME}.pro
COMMAND ${QT_LUPDATE_EXECUTABLE} -ts ${APP_TRANSLATIONS_WO_QT} -pro ${CMAKE_CURRENT_BINARY_DIR}/${APP_LOW_NAME}.pro
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
endif(${USE_QT_5})

View File

@ -1,4 +1,5 @@
#include <QNetworkProxy> #include <QNetworkProxy>
#include <QNetworkRequest>
#include "core/settings.h" #include "core/settings.h"
#include "core/defs.h" #include "core/defs.h"
@ -28,17 +29,18 @@ void BaseNetworkAccessManager::loadSettings() {
setProxy(QNetworkProxy::NoProxy); setProxy(QNetworkProxy::NoProxy);
return; return;
} }
Settings *settings = Settings::getInstance();
// Custom proxy is selected, set it up. // Custom proxy is selected, set it up.
new_proxy.setType(selected_proxy_type); new_proxy.setType(selected_proxy_type);
new_proxy.setHostName(Settings::getInstance()->value(APP_CFG_PROXY, new_proxy.setHostName(settings->value(APP_CFG_PROXY,
"host").toString()); "host").toString());
new_proxy.setPort(Settings::getInstance()->value(APP_CFG_PROXY, new_proxy.setPort(settings->value(APP_CFG_PROXY,
"port", 80).toInt()); "port", 80).toInt());
new_proxy.setUser(Settings::getInstance()->value(APP_CFG_PROXY, new_proxy.setUser(settings->value(APP_CFG_PROXY,
"username").toString()); "username").toString());
new_proxy.setPassword(Settings::getInstance()->value(APP_CFG_PROXY, new_proxy.setPassword(settings->value(APP_CFG_PROXY,
"password").toString()); "password").toString());
setProxy(new_proxy); setProxy(new_proxy);
} }
@ -52,6 +54,7 @@ QNetworkReply *BaseNetworkAccessManager::createRequest(QNetworkAccessManager::Op
new_request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); new_request.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
// Setup custom user-agent. // Setup custom user-agent.
new_request.setHeader(QNetworkRequest::UserAgentHeader, static_cast<QString>(APP_USERAGENT)); new_request.setRawHeader("User-Agent", QString(APP_USERAGENT).toLocal8Bit());
return QNetworkAccessManager::createRequest(op, new_request, outgoingData); return QNetworkAccessManager::createRequest(op, new_request, outgoingData);
} }

View File

@ -7,7 +7,7 @@
BaseWebPage::BaseWebPage(QObject *parent) BaseWebPage::BaseWebPage(QObject *parent)
: QWebPage(parent), m_openInNewTab(false) { : QWebPage(parent) {
// Setup global network access manager. // Setup global network access manager.
// NOTE: This makes network settings easy for all web browsers. // NOTE: This makes network settings easy for all web browsers.
setNetworkAccessManager(WebBrowser::globalNetworkManager()); setNetworkAccessManager(WebBrowser::globalNetworkManager());

View File

@ -14,11 +14,6 @@ class BaseWebPage : public QWebPage {
protected: protected:
QWebPage *createWindow(WebWindowType type); QWebPage *createWindow(WebWindowType type);
private:
friend class BaseWebView;
bool m_openInNewTab;
}; };
#endif // BASEWEBPAGE_H #endif // BASEWEBPAGE_H

View File

@ -6,11 +6,12 @@
class DateTime { class DateTime {
private: private:
DateTime(); explicit DateTime();
public: public:
// Returns QDatetime instance from input QString. // Returns QDatetime instance from input QString.
// If parsing fails, then invalid QDateTime is returned. // If parsing fails, then invalid QDateTime is returned.
// NOTE: Format of input date-time string is brute-force-determined.
static QDateTime fromString(const QString &date_time); static QDateTime fromString(const QString &date_time);
}; };

View File

@ -7,6 +7,7 @@
#include <cstdio> #include <cstdio>
#ifndef QT_NO_DEBUG_OUTPUT #ifndef QT_NO_DEBUG_OUTPUT
#if QT_VERSION >= 0x050000
#define DEBUG_OUTPUT_WORKER(type_string, file, line, message) \ #define DEBUG_OUTPUT_WORKER(type_string, file, line, message) \
fprintf(stderr, "[%s] %s (%s:%d): %s\n", \ fprintf(stderr, "[%s] %s (%s:%d): %s\n", \
APP_LOW_NAME, \ APP_LOW_NAME, \
@ -14,12 +15,17 @@
file, \ file, \
line, \ line, \
qPrintable(message)); qPrintable(message));
#else
#define DEBUG_OUTPUT_WORKER(type_string, message) \
fprintf(stderr, "[%s] %s: %s\n", \
APP_LOW_NAME, \
type_string, \
qPrintable(message));
#endif
#endif #endif
Debugging::Debugging() { #if QT_VERSION >= 0x050000
}
void Debugging::debugHandler(QtMsgType type, void Debugging::debugHandler(QtMsgType type,
const QMessageLogContext &placement, const QMessageLogContext &placement,
const QString &message) { const QString &message) {
@ -47,3 +53,31 @@ void Debugging::debugHandler(QtMsgType type,
Q_UNUSED(message); Q_UNUSED(message);
#endif #endif
} }
#else
void Debugging::debugHandler(QtMsgType type, const char *message) {
#ifndef QT_NO_DEBUG_OUTPUT
switch (type) {
case QtDebugMsg:
DEBUG_OUTPUT_WORKER("INFO", message);
break;
case QtWarningMsg:
DEBUG_OUTPUT_WORKER("WARNING", message);
break;
case QtCriticalMsg:
DEBUG_OUTPUT_WORKER("CRITICAL", message);
break;
case QtFatalMsg:
DEBUG_OUTPUT_WORKER("FATAL", message);
qApp->exit(EXIT_FAILURE);
default:
break;
}
#else
Q_UNUSED(type);
Q_UNUSED(message);
#endif
}
#endif
Debugging::Debugging() {
}

View File

@ -6,15 +6,20 @@
class Debugging { class Debugging {
private: private:
Debugging(); explicit Debugging();
public: public:
// Specifies format of output console messages. // Specifies format of output console messages.
// Macros: // Macros:
// QT_NO_DEBUG_OUTPUT - disables debug outputs completely!!! // QT_NO_DEBUG_OUTPUT - disables debug outputs completely!!!
#if QT_VERSION >= 0x050000
static void debugHandler(QtMsgType type, static void debugHandler(QtMsgType type,
const QMessageLogContext &placement, const QMessageLogContext &placement,
const QString &message); const QString &message);
#else
static void debugHandler(QtMsgType type,
const char *message);
#endif
}; };
#endif // DEBUGGING_H #endif // DEBUGGING_H

View File

@ -2,7 +2,11 @@
#define DEFS_H #define DEFS_H
#include <QtGlobal> #include <QtGlobal>
#if QT_VERSION >= 0x050000
#include <QtWebKitVersion> #include <QtWebKitVersion>
#else
#include <qwebkitversion.h>
#endif
#define CMAKE_VERSION "@CMAKE_VERSION@" #define CMAKE_VERSION "@CMAKE_VERSION@"
#define CMAKE_SYSTEM "@CMAKE_SYSTEM@" #define CMAKE_SYSTEM "@CMAKE_SYSTEM@"

View File

@ -9,18 +9,22 @@ DynamicShortcuts::DynamicShortcuts() {
} }
void DynamicShortcuts::save(const QList<QAction *> actions) { void DynamicShortcuts::save(const QList<QAction *> actions) {
Settings *settings = Settings::getInstance();
foreach (QAction *action, actions) { foreach (QAction *action, actions) {
Settings::getInstance()->setValue(APP_CFG_CUTS, settings->setValue(APP_CFG_CUTS,
action->objectName(), action->objectName(),
action->shortcut().toString(QKeySequence::NativeText)); action->shortcut().toString(QKeySequence::NativeText));
} }
} }
void DynamicShortcuts::load(const QList<QAction *> actions) { void DynamicShortcuts::load(const QList<QAction *> actions) {
Settings *settings = Settings::getInstance();
foreach (QAction *action, actions) { foreach (QAction *action, actions) {
QString shortcut_for_action = Settings::getInstance()->value(APP_CFG_CUTS, QString shortcut_for_action = settings->value(APP_CFG_CUTS,
action->objectName(), action->objectName(),
action->shortcut().toString(QKeySequence::NativeText)).toString(); action->shortcut().toString(QKeySequence::NativeText)).toString();
action->setShortcut(QKeySequence::fromString(shortcut_for_action, action->setShortcut(QKeySequence::fromString(shortcut_for_action,
QKeySequence::NativeText)); QKeySequence::NativeText));
} }

View File

@ -3,11 +3,12 @@
#include <QList> #include <QList>
class QAction; class QAction;
class DynamicShortcuts { class DynamicShortcuts {
private: private:
DynamicShortcuts(); explicit DynamicShortcuts();
public: public:
// Checks the application settings and then initializes shortcut of // Checks the application settings and then initializes shortcut of

View File

@ -11,19 +11,19 @@
if (app_translator.load(QString("rssguard_%1.qm").arg(locale_name), \ if (app_translator.load(QString("rssguard_%1.qm").arg(locale_name), \
APP_LANG_PATH)) { \ APP_LANG_PATH)) { \
QApplication::installTranslator(&app_translator); \ QApplication::installTranslator(&app_translator); \
qDebug("Application localization %s loaded successfully. Setting up locale.", \ qDebug("Application localization %s loaded successfully.", \
qPrintable(locale_name)); \ qPrintable(locale_name)); \
} \ } \
else { \ else { \
qDebug("Application localization %s was not loaded.", qPrintable(locale_name)); \ qWarning("Application localization %s was not loaded.", qPrintable(locale_name)); \
} \ } \
if (qt_translator.load(QString("qt_%1.qm").arg(locale_name), \ if (qt_translator.load(QString("qt_%1.qm").arg(locale_name), \
APP_LANG_PATH)) { \ APP_LANG_PATH)) { \
qDebug("Qt localization %s loaded successfully. Setting up locale.", \ qDebug("Qt localization %s loaded successfully.", \
qPrintable(locale_name)); \ qPrintable(locale_name)); \
} \ } \
else { \ else { \
qDebug("Qt localization %s was not loaded.", qPrintable(locale_name)); \ qWarning("Qt localization %s was not loaded.", qPrintable(locale_name)); \
} \ } \
QLocale::setDefault(QLocale(locale_name)); QLocale::setDefault(QLocale(locale_name));
@ -40,10 +40,9 @@ struct Language {
class Localization { class Localization {
private: private:
Localization(); explicit Localization();
public: public:
// Returns list of installed application localizations. // Returns list of installed application localizations.
// This list is used ie. in settings dialog. // This list is used ie. in settings dialog.
static QList<Language> getInstalledLanguages(); static QList<Language> getInstalledLanguages();

View File

@ -39,9 +39,8 @@ Settings::~Settings() {
QSettings::Status Settings::checkSettings() { QSettings::Status Settings::checkSettings() {
qDebug("Syncing settings."); qDebug("Syncing settings.");
s_instance->sync(); sync();
return status();
return s_instance->status();
} }
Settings *Settings::getInstance() { Settings *Settings::getInstance() {

View File

@ -2,6 +2,7 @@
#define SETTINGS_H #define SETTINGS_H
#include <QSettings> #include <QSettings>
#include <QPointer>
class Settings : public QSettings { class Settings : public QSettings {

View File

@ -37,7 +37,7 @@ SystemFactory::AutoStartStatus SystemFactory::getAutoStartStatus() {
// No correct path was found. // No correct path was found.
if (desktop_file_location.isEmpty()) { if (desktop_file_location.isEmpty()) {
qDebug("Searching for auto-start function status failed. HOME variable not found."); qWarning("Searching for auto-start function status failed. HOME variable not found.");
return SystemFactory::Unavailable; return SystemFactory::Unavailable;
} }

View File

@ -4,7 +4,7 @@
class SystemFactory { class SystemFactory {
private: private:
SystemFactory(); explicit SystemFactory();
public: public:
// Specifies possible states of auto-start functionality. // Specifies possible states of auto-start functionality.

View File

@ -6,4 +6,5 @@ WebBrowserNetworkAccessManager::WebBrowserNetworkAccessManager(QObject *parent)
} }
WebBrowserNetworkAccessManager::~WebBrowserNetworkAccessManager() { WebBrowserNetworkAccessManager::~WebBrowserNetworkAccessManager() {
qDebug("Destroying WebBrowserNetworkAccessManager instance.");
} }

View File

@ -12,7 +12,6 @@ class WebBrowserNetworkAccessManager : public BaseNetworkAccessManager {
// Constructors and destructors. // Constructors and destructors.
explicit WebBrowserNetworkAccessManager(QObject *parent = 0); explicit WebBrowserNetworkAccessManager(QObject *parent = 0);
virtual ~WebBrowserNetworkAccessManager(); virtual ~WebBrowserNetworkAccessManager();
}; };
#endif // WEBBROWSERNETWORKACCESSMANAGER_H #endif // WEBBROWSERNETWORKACCESSMANAGER_H

View File

@ -30,11 +30,22 @@ void BaseWebView::onLoadFinished(bool ok) {
} }
} }
void BaseWebView::openLinkInNewTab() {
emit linkMiddleClicked(m_contextLinkUrl);
}
void BaseWebView::openImageInNewTab() {
emit linkMiddleClicked(m_contextImageUrl);
}
void BaseWebView::createConnections() { void BaseWebView::createConnections() {
connect(this, &BaseWebView::loadFinished, connect(this, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool)));
this, &BaseWebView::onLoadFinished); connect(this, SIGNAL(customContextMenuRequested(QPoint)),
connect(this, &BaseWebView::customContextMenuRequested, this, SLOT(popupContextMenu(QPoint)));
this, &BaseWebView::popupContextMenu);
connect(m_actionOpenLinkNewTab,SIGNAL(triggered()), this, SLOT(openLinkInNewTab()));
connect(m_actionOpenImageNewTab, SIGNAL(triggered()),
this, SLOT(openImageInNewTab()));
} }
void BaseWebView::setupIcons() { void BaseWebView::setupIcons() {
@ -42,6 +53,9 @@ void BaseWebView::setupIcons() {
m_actionCopyLink->setIcon(IconThemeFactory::getInstance()->fromTheme("edit-copy")); m_actionCopyLink->setIcon(IconThemeFactory::getInstance()->fromTheme("edit-copy"));
m_actionCopyImage->setIcon(IconThemeFactory::getInstance()->fromTheme("insert-image")); m_actionCopyImage->setIcon(IconThemeFactory::getInstance()->fromTheme("insert-image"));
m_actionCopyImageUrl->setIcon(IconThemeFactory::getInstance()->fromTheme("edit-copy")); m_actionCopyImageUrl->setIcon(IconThemeFactory::getInstance()->fromTheme("edit-copy"));
m_actionOpenLinkThisTab->setIcon(IconThemeFactory::getInstance()->fromTheme("text-html"));
m_actionOpenLinkNewTab->setIcon(IconThemeFactory::getInstance()->fromTheme("text-html"));
m_actionOpenImageNewTab->setIcon(IconThemeFactory::getInstance()->fromTheme("insert-image"));
} }
void BaseWebView::initializeActions() { void BaseWebView::initializeActions() {
@ -66,12 +80,20 @@ void BaseWebView::initializeActions() {
m_actionCopyImageUrl->setText(tr("Copy image url")); m_actionCopyImageUrl->setText(tr("Copy image url"));
m_actionCopyImageUrl->setToolTip(tr("Copy image url to clipboard")); m_actionCopyImageUrl->setToolTip(tr("Copy image url to clipboard"));
// TODO: Finish implementation of "open link in new tab"
// viz WebPage::createWindow in browser example.
m_actionOpenLinkNewTab = pageAction(QWebPage::OpenLinkInNewWindow); m_actionOpenLinkNewTab = pageAction(QWebPage::OpenLinkInNewWindow);
m_actionOpenLinkNewTab->setParent(this); m_actionOpenLinkNewTab->setParent(this);
m_actionOpenLinkNewTab->setText(tr("Open link in new tab")); m_actionOpenLinkNewTab->setText(tr("Open link in new tab"));
m_actionOpenLinkNewTab->setToolTip(tr("Open this hyperlink in new tab")); m_actionOpenLinkNewTab->setToolTip(tr("Open this hyperlink in new tab"));
m_actionOpenLinkThisTab = pageAction(QWebPage::OpenLink);
m_actionOpenLinkThisTab->setParent(this);
m_actionOpenLinkThisTab->setText(tr("Follow link"));
m_actionOpenLinkThisTab->setToolTip(tr("Open the hyperlink in this tab"));
m_actionOpenImageNewTab = pageAction(QWebPage::OpenImageInNewWindow);
m_actionOpenImageNewTab->setParent(this);
m_actionOpenImageNewTab->setText(tr("Open image in new tab"));
m_actionOpenImageNewTab->setToolTip(tr("Open this image in this tab"));
} }
void BaseWebView::displayErrorPage() { void BaseWebView::displayErrorPage() {
@ -82,34 +104,46 @@ void BaseWebView::displayErrorPage() {
void BaseWebView::popupContextMenu(const QPoint &pos) { void BaseWebView::popupContextMenu(const QPoint &pos) {
QMenu context_menu(tr("Web browser"), this); QMenu context_menu(tr("Web browser"), this);
QMenu image_submenu(tr("Image"), &context_menu); QMenu image_submenu(tr("Image"), &context_menu);
QMenu link_submenu(tr("Hyperlink"), this);
QWebHitTestResult hit_result = page()->mainFrame()->hitTestContent(pos); QWebHitTestResult hit_result = page()->mainFrame()->hitTestContent(pos);
image_submenu.setIcon(IconThemeFactory::getInstance()->fromTheme("image-x-generic")); image_submenu.setIcon(IconThemeFactory::getInstance()->fromTheme("image-x-generic"));
link_submenu.setIcon(IconThemeFactory::getInstance()->fromTheme("text-html"));
// Assemble the menu from actions. // Assemble the menu from actions.
context_menu.addAction(m_actionReload); context_menu.addAction(m_actionReload);
if (hit_result.linkUrl().isValid()) { QUrl hit_url = hit_result.linkUrl();
context_menu.addAction(m_actionCopyLink); 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_actionCopyLink);
} }
if (!hit_result.pixmap().isNull()) { if (!hit_result.pixmap().isNull()) {
// Add 'Image' menu, because if user clicked image it needs to be visible. // Add 'Image' menu, because if user clicked image it needs to be visible.
context_menu.addMenu(&image_submenu); context_menu.addMenu(&image_submenu);
if (hit_image_url.isValid()) {
m_contextImageUrl = hit_image_url;
image_submenu.addAction(m_actionOpenImageNewTab);
image_submenu.addAction(m_actionCopyImageUrl);
}
image_submenu.addAction(m_actionCopyImage); image_submenu.addAction(m_actionCopyImage);
} }
if (hit_result.imageUrl().isValid()) {
image_submenu.addAction(m_actionCopyImageUrl);
}
// Display the menu. // Display the menu.
context_menu.exec(mapToGlobal(pos)); context_menu.exec(mapToGlobal(pos));
} }
void BaseWebView::mousePressEvent(QMouseEvent *event) { void BaseWebView::mousePressEvent(QMouseEvent *event) {
if (event->button() & Qt::MiddleButton) { if ((event->button() & Qt::MiddleButton) ||
(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
@ -119,7 +153,6 @@ void BaseWebView::mousePressEvent(QMouseEvent *event) {
if (link_url.isValid()) { if (link_url.isValid()) {
emit linkMiddleClicked(link_url); emit linkMiddleClicked(link_url);
// No more handling of event is now needed. Return. // No more handling of event is now needed. Return.
return; return;
} }

View File

@ -2,9 +2,9 @@
#define BASEWEBVIEW_H #define BASEWEBVIEW_H
#include <QWebView> #include <QWebView>
#include <QAction>
class QAction;
class QPaintEvent; class QPaintEvent;
class BaseWebPage; class BaseWebPage;
@ -30,6 +30,9 @@ class BaseWebView : public QWebView {
// Executes if loading of any page is done. // Executes if loading of any page is done.
void onLoadFinished(bool ok); void onLoadFinished(bool ok);
void openLinkInNewTab();
void openImageInNewTab();
// Provides custom context menu. // Provides custom context menu.
void popupContextMenu(const QPoint &pos); void popupContextMenu(const QPoint &pos);
@ -56,9 +59,13 @@ class BaseWebView : public QWebView {
QAction *m_actionCopyLink; QAction *m_actionCopyLink;
QAction *m_actionCopyImage; QAction *m_actionCopyImage;
QAction *m_actionCopyImageUrl; QAction *m_actionCopyImageUrl;
QAction *m_actionOpenLinkThisTab;
QAction *m_actionOpenLinkNewTab; QAction *m_actionOpenLinkNewTab;
QAction *m_actionOpenImageNewTab;
QPoint m_gestureOrigin; QPoint m_gestureOrigin;
QUrl m_contextLinkUrl;
QUrl m_contextImageUrl;
}; };
#endif // BASEWEBVIEW_H #endif // BASEWEBVIEW_H

View File

@ -15,13 +15,13 @@ FormAbout::FormAbout(QWidget *parent) : QDialog(parent), m_ui(new Ui::FormAbout)
m_ui->m_lblIcon->setPixmap(QPixmap(APP_ICON_PATH)); m_ui->m_lblIcon->setPixmap(QPixmap(APP_ICON_PATH));
// Load information from embedded text files. // Load information from embedded text files.
QTextStream str; QTextStream text_stream;
QFile file; QFile file;
str.setDevice(&file); text_stream.setDevice(&file);
file.setFileName(APP_INFO_PATH + "/COPYING_GNU_GPL_HTML"); file.setFileName(APP_INFO_PATH + "/COPYING_GNU_GPL_HTML");
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
m_ui->m_txtLicenseGnu->setText(str.readAll()); m_ui->m_txtLicenseGnu->setText(text_stream.readAll());
} }
else { else {
m_ui->m_txtLicenseGnu->setText(tr("License not found.")); m_ui->m_txtLicenseGnu->setText(tr("License not found."));
@ -30,7 +30,7 @@ FormAbout::FormAbout(QWidget *parent) : QDialog(parent), m_ui(new Ui::FormAbout)
file.setFileName(APP_INFO_PATH + "/COPYING_BSD"); file.setFileName(APP_INFO_PATH + "/COPYING_BSD");
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
m_ui->m_txtLicenseBsd->setText(str.readAll()); m_ui->m_txtLicenseBsd->setText(text_stream.readAll());
} }
else { else {
m_ui->m_txtLicenseBsd->setText(tr("License not found.")); m_ui->m_txtLicenseBsd->setText(tr("License not found."));
@ -39,7 +39,7 @@ FormAbout::FormAbout(QWidget *parent) : QDialog(parent), m_ui(new Ui::FormAbout)
file.setFileName(APP_INFO_PATH + "/AUTHORS"); file.setFileName(APP_INFO_PATH + "/AUTHORS");
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
m_ui->m_txtThanks->setText(str.readAll()); m_ui->m_txtThanks->setText(text_stream.readAll());
} }
else { else {
m_ui->m_txtThanks->setText(tr("Authors information not found.")); m_ui->m_txtThanks->setText(tr("Authors information not found."));
@ -48,7 +48,7 @@ FormAbout::FormAbout(QWidget *parent) : QDialog(parent), m_ui(new Ui::FormAbout)
file.setFileName(APP_INFO_PATH + "/CHANGELOG"); file.setFileName(APP_INFO_PATH + "/CHANGELOG");
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
m_ui->m_txtChangelog->setText(str.readAll()); m_ui->m_txtChangelog->setText(text_stream.readAll());
} }
else { else {
m_ui->m_txtChangelog->setText(tr("Changelog not found.")); m_ui->m_txtChangelog->setText(tr("Changelog not found."));

View File

@ -1,5 +1,4 @@
#include <QCloseEvent> #include <QCloseEvent>
#include <QMessageBox>
#include "gui/formmain.h" #include "gui/formmain.h"
#include "gui/formabout.h" #include "gui/formabout.h"
@ -21,9 +20,8 @@ FormMain::FormMain(QWidget *parent) : QMainWindow(parent), m_ui(new Ui::FormMain
// Initialize singleton. // Initialize singleton.
s_instance = this; s_instance = this;
// Prepare main window. // Prepare main window and tabs.
prepareMenus(); prepareMenus();
m_ui->m_tabWidget->initializeTabs(); m_ui->m_tabWidget->initializeTabs();
// Establish connections. // Establish connections.
@ -61,9 +59,6 @@ QList<QAction*> FormMain::getActions() {
return actions; return actions;
} }
void FormMain::prepareTabs() {
}
void FormMain::prepareMenus() { void FormMain::prepareMenus() {
// Setup menu for tray icon. // Setup menu for tray icon.
if (SystemTrayIcon::isSystemTrayAvailable()) { if (SystemTrayIcon::isSystemTrayAvailable()) {
@ -96,7 +91,6 @@ void FormMain::switchFullscreenMode(bool turn_fullscreen_on) {
if (turn_fullscreen_on) { if (turn_fullscreen_on) {
showFullScreen(); showFullScreen();
} else { } else {
showNormal(); showNormal();
} }
} }
@ -158,19 +152,19 @@ void FormMain::setupIcons() {
void FormMain::createConnections() { void FormMain::createConnections() {
// Menu "File" connections. // Menu "File" connections.
connect(m_ui->m_actionQuit, &QAction::triggered, this, &FormMain::quit); connect(m_ui->m_actionQuit, SIGNAL(triggered()), this, SLOT(quit()));
// Menu "View" connections. // Menu "View" connections.
connect(m_ui->m_actionFullscreen, &QAction::triggered, this, &FormMain::switchFullscreenMode); connect(m_ui->m_actionFullscreen, SIGNAL(triggered(bool)), this, SLOT(switchFullscreenMode(bool)));
// Menu "Tools" connections. // Menu "Tools" connections.
connect(m_ui->m_actionSettings, &QAction::triggered, this, &FormMain::showSettings); connect(m_ui->m_actionSettings, SIGNAL(triggered()), this, SLOT(showSettings()));
// Menu "Help" connections. // Menu "Help" connections.
connect(m_ui->m_actionAboutGuard, &QAction::triggered, this, &FormMain::showAbout); connect(m_ui->m_actionAboutGuard, SIGNAL(triggered()), this, SLOT(showAbout()));
// General connections. // General connections.
connect(qApp, &QCoreApplication::aboutToQuit, this, &FormMain::cleanupResources); connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(cleanupResources()));
} }
void FormMain::closeEvent(QCloseEvent *event) { void FormMain::closeEvent(QCloseEvent *event) {

View File

@ -18,6 +18,7 @@ class FormMain : public QMainWindow {
// Returns menu for the tray icon. // Returns menu for the tray icon.
QMenu *getTrayMenu(); QMenu *getTrayMenu();
// Returns global tab widget.
TabWidget *getTabWidget(); TabWidget *getTabWidget();
// Returns list of all globally available actions. // Returns list of all globally available actions.
@ -31,9 +32,6 @@ class FormMain : public QMainWindow {
// Creates all needed menus and sets them up. // Creates all needed menus and sets them up.
void prepareMenus(); void prepareMenus();
// Initializes "Feeds" tab and related stuff.
void prepareTabs();
// Creates needed connections for this window. // Creates needed connections for this window.
void createConnections(); void createConnections();

View File

@ -26,11 +26,21 @@ FormSettings::FormSettings(QWidget *parent) : QDialog(parent), m_ui(new Ui::Form
// Setup behavior. // Setup behavior.
m_ui->m_treeLanguages->setColumnCount(5); m_ui->m_treeLanguages->setColumnCount(5);
m_ui->m_treeLanguages->setHeaderHidden(false); m_ui->m_treeLanguages->setHeaderHidden(false);
#if QT_VERSION >= 0x050000
m_ui->m_treeLanguages->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); m_ui->m_treeLanguages->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
m_ui->m_treeLanguages->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents); m_ui->m_treeLanguages->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
m_ui->m_treeLanguages->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents); m_ui->m_treeLanguages->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
m_ui->m_treeLanguages->header()->setSectionResizeMode(3, QHeaderView::ResizeToContents); m_ui->m_treeLanguages->header()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
m_ui->m_treeLanguages->header()->setSectionResizeMode(4, QHeaderView::ResizeToContents); m_ui->m_treeLanguages->header()->setSectionResizeMode(4, QHeaderView::ResizeToContents);
#else
m_ui->m_treeLanguages->header()->setResizeMode(0, QHeaderView::ResizeToContents);
m_ui->m_treeLanguages->header()->setResizeMode(1, QHeaderView::ResizeToContents);
m_ui->m_treeLanguages->header()->setResizeMode(2, QHeaderView::ResizeToContents);
m_ui->m_treeLanguages->header()->setResizeMode(3, QHeaderView::ResizeToContents);
m_ui->m_treeLanguages->header()->setResizeMode(4, QHeaderView::ResizeToContents);
#endif
m_ui->m_treeLanguages->setHeaderLabels(QStringList() m_ui->m_treeLanguages->setHeaderLabels(QStringList()
<< tr("Language") << tr("Language")
<< tr("Code") << tr("Code")
@ -39,13 +49,13 @@ FormSettings::FormSettings(QWidget *parent) : QDialog(parent), m_ui(new Ui::Form
<< tr("Email")); << tr("Email"));
// Establish needed connections. // Establish needed connections.
connect(this, &FormSettings::accepted, this, &FormSettings::saveSettings); connect(this, SIGNAL(accepted()), this, SLOT(saveSettings()));
connect(m_ui->m_cmbProxyType, static_cast<void (QComboBox::*)(int index)>(&QComboBox::currentIndexChanged), connect(m_ui->m_cmbProxyType, SIGNAL(currentIndexChanged(int)),
this, &FormSettings::onProxyTypeChanged); this, SLOT(onProxyTypeChanged(int)));
connect(m_ui->m_checkShowPassword, &QCheckBox::stateChanged, connect(m_ui->m_checkShowPassword, SIGNAL(stateChanged(int)),
this, &FormSettings::displayProxyPassword); this, SLOT(displayProxyPassword(int)));
connect(m_ui->m_btnBrowserProgressColor, &QPushButton::clicked, connect(m_ui->m_btnBrowserProgressColor, SIGNAL(clicked()),
this, &FormSettings::changeBrowserProgressColor); this, SLOT(changeBrowserProgressColor()));
// Load all settings. // Load all settings.
loadGeneral(); loadGeneral();
@ -107,35 +117,39 @@ void FormSettings::onProxyTypeChanged(int index) {
} }
void FormSettings::loadBrowser() { void FormSettings::loadBrowser() {
Settings *settings = Settings::getInstance();
// Load settings of web browser GUI. // Load settings of web browser GUI.
m_initialSettings.m_webBrowserProgress = Settings::getInstance()->value(APP_CFG_BROWSER, m_initialSettings.m_webBrowserProgress = settings->value(APP_CFG_BROWSER,
"browser_progress_color", "browser_progress_color",
QColor(0, 255, 0, 100)).value<QColor>(); QColor(0, 255, 0, 100)).value<QColor>();
m_ui->m_checkBrowserProgressColor->setChecked(Settings::getInstance()->value(APP_CFG_BROWSER, m_ui->m_checkBrowserProgressColor->setChecked(settings->value(APP_CFG_BROWSER,
"browser_colored_progress_enabled", "browser_colored_progress_enabled",
true).toBool()); true).toBool());
m_ui->m_checkMouseGestures->setChecked(Settings::getInstance()->value(APP_CFG_BROWSER, m_ui->m_checkMouseGestures->setChecked(settings->value(APP_CFG_BROWSER,
"gestures_enabled", "gestures_enabled",
true).toBool()); true).toBool());
m_ui->m_checkQueueTabs->setChecked(Settings::getInstance()->value(APP_CFG_BROWSER, m_ui->m_checkQueueTabs->setChecked(settings->value(APP_CFG_BROWSER,
"queue_tabs", "queue_tabs",
true).toBool()); true).toBool());
} }
void FormSettings::saveBrowser() { void FormSettings::saveBrowser() {
Settings *settings = Settings::getInstance();
// Save settings of GUI of web browser. // Save settings of GUI of web browser.
Settings::getInstance()->setValue(APP_CFG_BROWSER, settings->setValue(APP_CFG_BROWSER,
"browser_progress_color", "browser_progress_color",
m_initialSettings.m_webBrowserProgress); m_initialSettings.m_webBrowserProgress);
Settings::getInstance()->setValue(APP_CFG_BROWSER, settings->setValue(APP_CFG_BROWSER,
"browser_colored_progress_enabled", "browser_colored_progress_enabled",
m_ui->m_checkBrowserProgressColor->isChecked()); m_ui->m_checkBrowserProgressColor->isChecked());
Settings::getInstance()->setValue(APP_CFG_BROWSER, settings->setValue(APP_CFG_BROWSER,
"gestures_enabled", "gestures_enabled",
m_ui->m_checkMouseGestures->isChecked()); m_ui->m_checkMouseGestures->isChecked());
Settings::getInstance()->setValue(APP_CFG_BROWSER, settings->setValue(APP_CFG_BROWSER,
"queue_tabs", "queue_tabs",
m_ui->m_checkQueueTabs->isChecked()); m_ui->m_checkQueueTabs->isChecked());
} }
void FormSettings::loadProxy() { void FormSettings::loadProxy() {
@ -147,28 +161,32 @@ void FormSettings::loadProxy() {
QNetworkProxy::ProxyType selected_proxy_type = static_cast<QNetworkProxy::ProxyType>(Settings::getInstance()->value(APP_CFG_PROXY, QNetworkProxy::ProxyType selected_proxy_type = static_cast<QNetworkProxy::ProxyType>(Settings::getInstance()->value(APP_CFG_PROXY,
"proxy_type", "proxy_type",
QNetworkProxy::NoProxy).toInt()); QNetworkProxy::NoProxy).toInt());
Settings *settings = Settings::getInstance();
m_ui->m_cmbProxyType->setCurrentIndex(m_ui->m_cmbProxyType->findData(selected_proxy_type)); m_ui->m_cmbProxyType->setCurrentIndex(m_ui->m_cmbProxyType->findData(selected_proxy_type));
m_ui->m_txtProxyHost->setText(Settings::getInstance()->value(APP_CFG_PROXY, m_ui->m_txtProxyHost->setText(settings->value(APP_CFG_PROXY,
"host").toString()); "host").toString());
m_ui->m_txtProxyUsername->setText(Settings::getInstance()->value(APP_CFG_PROXY, m_ui->m_txtProxyUsername->setText(settings->value(APP_CFG_PROXY,
"username").toString()); "username").toString());
m_ui->m_txtProxyPassword->setText(Settings::getInstance()->value(APP_CFG_PROXY, m_ui->m_txtProxyPassword->setText(settings->value(APP_CFG_PROXY,
"password").toString()); "password").toString());
m_ui->m_spinProxyPort->setValue(Settings::getInstance()->value(APP_CFG_PROXY, m_ui->m_spinProxyPort->setValue(settings->value(APP_CFG_PROXY,
"port", 80).toInt()); "port", 80).toInt());
} }
void FormSettings::saveProxy() { void FormSettings::saveProxy() {
Settings::getInstance()->setValue(APP_CFG_PROXY, "proxy_type", Settings *settings = Settings::getInstance();
m_ui->m_cmbProxyType->itemData(m_ui->m_cmbProxyType->currentIndex()));
Settings::getInstance()->setValue(APP_CFG_PROXY, "host", settings->setValue(APP_CFG_PROXY, "proxy_type",
m_ui->m_txtProxyHost->text()); m_ui->m_cmbProxyType->itemData(m_ui->m_cmbProxyType->currentIndex()));
Settings::getInstance()->setValue(APP_CFG_PROXY, "username", settings->setValue(APP_CFG_PROXY, "host",
m_ui->m_txtProxyUsername->text()); m_ui->m_txtProxyHost->text());
Settings::getInstance()->setValue(APP_CFG_PROXY, "password", settings->setValue(APP_CFG_PROXY, "username",
m_ui->m_txtProxyPassword->text()); m_ui->m_txtProxyUsername->text());
Settings::getInstance()->setValue(APP_CFG_PROXY, "port", settings->setValue(APP_CFG_PROXY, "password",
m_ui->m_spinProxyPort->value()); m_ui->m_txtProxyPassword->text());
settings->setValue(APP_CFG_PROXY, "port",
m_ui->m_spinProxyPort->value());
// Reload settings for all network access managers. // Reload settings for all network access managers.
WebBrowser::globalNetworkManager()->loadSettings(); WebBrowser::globalNetworkManager()->loadSettings();
@ -198,18 +216,19 @@ void FormSettings::loadLanguage() {
} }
void FormSettings::saveLanguage() { void FormSettings::saveLanguage() {
if (m_ui->m_treeLanguages->currentItem() == nullptr) { if (m_ui->m_treeLanguages->currentItem() == NULL) {
qDebug("No localizations loaded in settings dialog, so no saving for them."); qDebug("No localizations loaded in settings dialog, so no saving for them.");
return; return;
} }
QString actual_lang = Settings::getInstance()->value(APP_CFG_GEN, Settings *settings = Settings::getInstance();
"language", QString actual_lang = settings->value(APP_CFG_GEN,
"en").toString(); "language",
"en").toString();
QString new_lang = m_ui->m_treeLanguages->currentItem()->text(1); QString new_lang = m_ui->m_treeLanguages->currentItem()->text(1);
if (new_lang != actual_lang) { if (new_lang != actual_lang) {
Settings::getInstance()->setValue(APP_CFG_GEN, "language", new_lang); settings->setValue(APP_CFG_GEN, "language", new_lang);
QMessageBox msg_question(this); QMessageBox msg_question(this);
msg_question.setText(tr("Language of RSS Guard was changed. Note that changes will take effect on next Qonverter start.")); msg_question.setText(tr("Language of RSS Guard was changed. Note that changes will take effect on next Qonverter start."));
@ -276,17 +295,19 @@ void FormSettings::saveGeneral() {
} }
void FormSettings::loadInterface() { void FormSettings::loadInterface() {
Settings *settings = Settings::getInstance();
// Load settings of tray icon. // Load settings of tray icon.
if (SystemTrayIcon::isSystemTrayAvailable()) { if (SystemTrayIcon::isSystemTrayAvailable()) {
m_ui->m_radioTrayOff->setChecked(!Settings::getInstance()->value(APP_CFG_GUI, m_ui->m_radioTrayOff->setChecked(!settings->value(APP_CFG_GUI,
"use_tray_icon", "use_tray_icon",
true).toBool()); true).toBool());
m_ui->m_cmbTrayClose->setCurrentIndex(Settings::getInstance()->value(APP_CFG_GUI, m_ui->m_cmbTrayClose->setCurrentIndex(settings->value(APP_CFG_GUI,
"close_win_action", "close_win_action",
0).toInt()); 0).toInt());
m_ui->m_checkHidden->setChecked(Settings::getInstance()->value(APP_CFG_GUI, m_ui->m_checkHidden->setChecked(settings->value(APP_CFG_GUI,
"start_hidden", "start_hidden",
false).toBool()); false).toBool());
} }
// Tray icon is not supported on this machine. // Tray icon is not supported on this machine.
else { else {
@ -316,35 +337,44 @@ void FormSettings::loadInterface() {
// Mark active theme. // Mark active theme.
if (current_theme == APP_THEME_SYSTEM) { if (current_theme == APP_THEME_SYSTEM) {
// Because system icon theme lies at the index 1. // Because system icon theme lies at the index 0.
m_ui->m_cmbIconTheme->setCurrentIndex(0); m_ui->m_cmbIconTheme->setCurrentIndex(0);
} }
else { else {
#if QT_VERSION >= 0x050000
m_ui->m_cmbIconTheme->setCurrentText(current_theme); m_ui->m_cmbIconTheme->setCurrentText(current_theme);
#else
int theme_index = m_ui->m_cmbIconTheme->findText(current_theme);
if (theme_index >= 0) {
m_ui->m_cmbIconTheme->setCurrentIndex(theme_index);
}
#endif
} }
// Load tab settings. // Load tab settings.
m_ui->m_checkCloseTabsMiddleClick->setChecked(Settings::getInstance()->value(APP_CFG_GUI, m_ui->m_checkCloseTabsMiddleClick->setChecked(settings->value(APP_CFG_GUI,
"tab_close_mid_button", "tab_close_mid_button",
true).toBool()); true).toBool());
m_ui->m_checkCloseTabsDoubleClick->setChecked(Settings::getInstance()->value(APP_CFG_GUI, m_ui->m_checkCloseTabsDoubleClick->setChecked(settings->value(APP_CFG_GUI,
"tab_close_double_button", "tab_close_double_button",
true).toBool()); true).toBool());
m_ui->m_checkNewTabDoubleClick->setChecked(Settings::getInstance()->value(APP_CFG_GUI, m_ui->m_checkNewTabDoubleClick->setChecked(settings->value(APP_CFG_GUI,
"tab_new_double_button", "tab_new_double_button",
true).toBool()); true).toBool());
} }
void FormSettings::saveInterface() { void FormSettings::saveInterface() {
Settings *settings = Settings::getInstance();
// Save tray icon. // Save tray icon.
if (SystemTrayIcon::isSystemTrayAvailable()) { if (SystemTrayIcon::isSystemTrayAvailable()) {
Settings::getInstance()->setValue(APP_CFG_GUI, "use_tray_icon", settings->setValue(APP_CFG_GUI, "use_tray_icon",
m_ui->m_radioTrayOn->isChecked()); m_ui->m_radioTrayOn->isChecked());
Settings::getInstance()->setValue(APP_CFG_GUI, "close_win_action", settings->setValue(APP_CFG_GUI, "close_win_action",
m_ui->m_cmbTrayClose->currentIndex()); m_ui->m_cmbTrayClose->currentIndex());
Settings::getInstance()->setValue(APP_CFG_GUI, "start_hidden", settings->setValue(APP_CFG_GUI, "start_hidden",
m_ui->m_checkHidden->isChecked()); m_ui->m_checkHidden->isChecked());
if (Settings::getInstance()->value(APP_CFG_GUI, "use_tray_icon", true).toBool()) { if (settings->value(APP_CFG_GUI, "use_tray_icon", true).toBool()) {
SystemTrayIcon::getInstance()->show(); SystemTrayIcon::getInstance()->show();
} }
else { else {
@ -358,10 +388,10 @@ void FormSettings::saveInterface() {
IconThemeFactory::getInstance()->setCurrentIconTheme(selected_icon_theme); IconThemeFactory::getInstance()->setCurrentIconTheme(selected_icon_theme);
// Save tab settings. // Save tab settings.
Settings::getInstance()->setValue(APP_CFG_GUI, "tab_close_mid_button", settings->setValue(APP_CFG_GUI, "tab_close_mid_button",
m_ui->m_checkCloseTabsMiddleClick->isChecked()); m_ui->m_checkCloseTabsMiddleClick->isChecked());
Settings::getInstance()->setValue(APP_CFG_GUI, "tab_close_double_button", settings->setValue(APP_CFG_GUI, "tab_close_double_button",
m_ui->m_checkCloseTabsDoubleClick->isChecked()); m_ui->m_checkCloseTabsDoubleClick->isChecked());
Settings::getInstance()->setValue(APP_CFG_GUI, "tab_new_double_button", settings->setValue(APP_CFG_GUI, "tab_new_double_button",
m_ui->m_checkNewTabDoubleClick->isChecked()); m_ui->m_checkNewTabDoubleClick->isChecked());
} }

View File

@ -21,9 +21,12 @@ FormWelcome::FormWelcome(QWidget *parent) : QDialog(parent), m_ui(new Ui::FormWe
move(screen.center() - rect().center()); move(screen.center() - rect().center());
// Make sure that clicked hyperlinks are opened in defult web browser. // Make sure that clicked hyperlinks are opened in defult web browser.
connect(m_ui->m_lblInfo, &QLabel::linkActivated, [=] (const QString &link) { connect(m_ui->m_lblInfo, SIGNAL(linkActivated(QString)),
QDesktopServices::openUrl(QUrl(link)); this, SLOT(openLink(QString)));
}); }
void FormWelcome::openLink(const QString &link) {
QDesktopServices::openUrl(QUrl(link));
} }
FormWelcome::~FormWelcome() { FormWelcome::~FormWelcome() {

View File

@ -18,6 +18,9 @@ class FormWelcome : public QDialog {
explicit FormWelcome(QWidget *parent = 0); explicit FormWelcome(QWidget *parent = 0);
virtual ~FormWelcome(); virtual ~FormWelcome();
private slots:
void openLink(const QString &link);
private: private:
Ui::FormWelcome *m_ui; Ui::FormWelcome *m_ui;
}; };

View File

@ -21,6 +21,7 @@ ThemeFactoryEvent::ThemeFactoryEvent() : QEvent(ThemeFactoryEvent::type()) {
} }
ThemeFactoryEvent::~ThemeFactoryEvent() { ThemeFactoryEvent::~ThemeFactoryEvent() {
qDebug("Destroying IconThemeFactoryEvent.");
} }
QEvent::Type ThemeFactoryEvent::type() { QEvent::Type ThemeFactoryEvent::type() {

View File

@ -4,6 +4,7 @@
#include <QString> #include <QString>
#include <QEvent> #include <QEvent>
#include <QIcon> #include <QIcon>
#include <QPointer>
class IconThemeFactory : public QObject { class IconThemeFactory : public QObject {
@ -13,6 +14,9 @@ class IconThemeFactory : public QObject {
// Singleton getter. // Singleton getter.
static IconThemeFactory *getInstance(); static IconThemeFactory *getInstance();
// Destructor.
virtual ~IconThemeFactory();
// Wrapper for QIcon::fromTheme. // Wrapper for QIcon::fromTheme.
// TODO: If icon is not found in user-defined icon theme, // TODO: If icon is not found in user-defined icon theme,
// then it is searched in system-default theme (ThemeFactory::getSystemIconTheme()). // then it is searched in system-default theme (ThemeFactory::getSystemIconTheme()).
@ -40,9 +44,8 @@ class IconThemeFactory : public QObject {
void setCurrentIconTheme(const QString &theme_name); void setCurrentIconTheme(const QString &theme_name);
private: private:
// Constructors and destructors // Constructor.
explicit IconThemeFactory(QObject *parent = 0); explicit IconThemeFactory(QObject *parent = 0);
virtual ~IconThemeFactory();
// Holds name of the current icon theme. // Holds name of the current icon theme.
QString m_currentIconTheme; QString m_currentIconTheme;

View File

@ -50,20 +50,21 @@ void LocationLineEdit::mousePressEvent(QMouseEvent *event) {
void LocationLineEdit::paintEvent(QPaintEvent *event) { void LocationLineEdit::paintEvent(QPaintEvent *event) {
// Draw "progress bar" if needed. // Draw "progress bar" if needed.
if (m_progress > 0 && Settings::getInstance()->value(APP_CFG_BROWSER, Settings *settings = Settings::getInstance();
"browser_colored_progress_enabled",
true).toBool()) { if (m_progress > 0 && settings->value(APP_CFG_BROWSER,
"browser_colored_progress_enabled",
true).toBool()) {
QPalette current_palette = palette(); QPalette current_palette = palette();
QColor loadingColor = Settings::getInstance()->value(APP_CFG_BROWSER, QColor loadingColor = settings->value(APP_CFG_BROWSER,
"browser_progress_color", "browser_progress_color",
QColor(0, 255, 0, 100)).value<QColor>(); QColor(0, 255, 0, 100)).value<QColor>();
QLinearGradient gradient(0, 0, width(), 0); QLinearGradient gradient(0, 0, width(), 0);
qreal percentage_border = m_progress / 100.0; qreal percentage_border = m_progress / 100.0;
gradient.setColorAt(0, loadingColor); gradient.setColorAt(0, loadingColor);
gradient.setColorAt(percentage_border - 0.01, loadingColor); gradient.setColorAt(percentage_border - 0.01, loadingColor);
gradient.setColorAt(percentage_border - 0.008, loadingColor.lighter(130)); gradient.setColorAt(percentage_border - 0.008, loadingColor.lighter(130));
//gradient.setColorAt(percentage_border - 0.002, loadingColor);
gradient.setColorAt(percentage_border, QApplication::palette().color(QPalette::Base)); gradient.setColorAt(percentage_border, QApplication::palette().color(QPalette::Base));
current_palette.setBrush(QPalette::Base, gradient); current_palette.setBrush(QPalette::Base, gradient);

View File

@ -7,7 +7,10 @@
class WebBrowser; class WebBrowser;
class LocationLineEdit : public BaseLineEdit { class LocationLineEdit : public BaseLineEdit {
Q_OBJECT
public: public:
// Constructors and destructors.
explicit LocationLineEdit(QWidget *parent = 0); explicit LocationLineEdit(QWidget *parent = 0);
virtual ~LocationLineEdit(); virtual ~LocationLineEdit();

View File

@ -40,7 +40,7 @@ ShortcutButton::~ShortcutButton() {
} }
void ShortcutButton::keyPressEvent(QKeyEvent *event) { void ShortcutButton::keyPressEvent(QKeyEvent *event) {
int pressed_key = event->key(); int pressed_key = event->key();
if (pressed_key == -1) { if (pressed_key == -1) {
m_catcher->doneRecording(); m_catcher->doneRecording();
@ -49,11 +49,11 @@ void ShortcutButton::keyPressEvent(QKeyEvent *event) {
Qt::KeyboardModifiers new_modifiers = event->modifiers() & Qt::KeyboardModifiers new_modifiers = event->modifiers() &
(Qt::SHIFT | Qt::CTRL | Qt::ALT | Qt::META); (Qt::SHIFT | Qt::CTRL | Qt::ALT | Qt::META);
if (m_catcher->m_isRecording == false && (pressed_key == Qt::Key_Return || pressed_key == Qt::Key_Space)) { if (!m_catcher->m_isRecording && (pressed_key == Qt::Key_Return || pressed_key == Qt::Key_Space)) {
return; return;
} }
if (m_catcher->m_isRecording == false) { if (!m_catcher->m_isRecording) {
return QPushButton::keyPressEvent(event); return QPushButton::keyPressEvent(event);
} }

View File

@ -36,7 +36,9 @@ class ShortcutCatcher;
class ShortcutButton : public QPushButton { class ShortcutButton : public QPushButton {
Q_OBJECT Q_OBJECT
public: public:
// Constructors and destructors.
explicit ShortcutButton(ShortcutCatcher *catcher, QWidget *parent = 0); explicit ShortcutButton(ShortcutCatcher *catcher, QWidget *parent = 0);
virtual ~ShortcutButton(); virtual ~ShortcutButton();

View File

@ -55,8 +55,8 @@ ShortcutCatcher::ShortcutCatcher(QWidget *parent)
m_layout->addWidget(m_clearButton); m_layout->addWidget(m_clearButton);
// Establish needed connections. // Establish needed connections.
connect(m_clearButton, &QToolButton::clicked, this, &ShortcutCatcher::clearShortcut); connect(m_clearButton, SIGNAL(clicked()), this, SLOT(clearShortcut()));
connect(m_sequenceButton, &ShortcutButton::clicked, this, &ShortcutCatcher::startRecording); connect(m_sequenceButton, SIGNAL(clicked()), this, SLOT(startRecording()));
// Prepare initial state of the control. // Prepare initial state of the control.
updateDisplayShortcut(); updateDisplayShortcut();

View File

@ -30,7 +30,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define KEYSEQUENCECATCHER_H #define KEYSEQUENCECATCHER_H
#include <QWidget> #include <QWidget>
#include <QPushButton>
class QHBoxLayout; class QHBoxLayout;
@ -42,6 +41,7 @@ class ShortcutCatcher : public QWidget {
friend class ShortcutButton; friend class ShortcutButton;
public: public:
// Constructors and destructors.
explicit ShortcutCatcher(QWidget *parent = 0); explicit ShortcutCatcher(QWidget *parent = 0);
virtual ~ShortcutCatcher(); virtual ~ShortcutCatcher();
@ -49,7 +49,7 @@ class ShortcutCatcher : public QWidget {
void updateDisplayShortcut(); void updateDisplayShortcut();
QKeySequence shortcut() const; QKeySequence shortcut() const;
void setShortcut(const QKeySequence& key); void setShortcut(const QKeySequence &key);
protected slots: protected slots:
void startRecording(); void startRecording();
@ -59,7 +59,7 @@ class ShortcutCatcher : public QWidget {
void clearShortcut(); void clearShortcut();
signals: signals:
void shortcutChanged(QKeySequence seguence); void shortcutChanged(const QKeySequence &seguence);
private: private:
QToolButton *m_clearButton; QToolButton *m_clearButton;

View File

@ -19,7 +19,7 @@ TrayIconMenu::~TrayIconMenu() {
} }
bool TrayIconMenu::event(QEvent *event) { bool TrayIconMenu::event(QEvent *event) {
if (QtSingleApplication::activeModalWidget() != nullptr && if (QtSingleApplication::activeModalWidget() != NULL &&
event->type() == QEvent::Show) { event->type() == QEvent::Show) {
QTimer::singleShot(0, this, SLOT(hide())); QTimer::singleShot(0, this, SLOT(hide()));
SystemTrayIcon::getInstance()->showMessage(APP_LONG_NAME, SystemTrayIcon::getInstance()->showMessage(APP_LONG_NAME,
@ -43,7 +43,8 @@ SystemTrayIcon::SystemTrayIcon(const QString &normal_icon,
setContextMenu(parent->getTrayMenu()); setContextMenu(parent->getTrayMenu());
// Create necessary connections. // Create necessary connections.
connect(this, &SystemTrayIcon::activated, this, &SystemTrayIcon::onActivated); connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this, SLOT(onActivated(QSystemTrayIcon::ActivationReason)));
} }
SystemTrayIcon::~SystemTrayIcon() { SystemTrayIcon::~SystemTrayIcon() {
@ -51,7 +52,7 @@ SystemTrayIcon::~SystemTrayIcon() {
hide(); hide();
} }
void SystemTrayIcon::onActivated(const ActivationReason &reason) { void SystemTrayIcon::onActivated(const QSystemTrayIcon::ActivationReason &reason) {
switch (reason) { switch (reason) {
case SystemTrayIcon::Trigger: case SystemTrayIcon::Trigger:
case SystemTrayIcon::DoubleClick: case SystemTrayIcon::DoubleClick:

View File

@ -12,6 +12,7 @@ class QEvent;
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
class TrayIconMenu : public QMenu { class TrayIconMenu : public QMenu {
public: public:
// Constructors and destructors.
explicit TrayIconMenu(const QString &title, QWidget *parent); explicit TrayIconMenu(const QString &title, QWidget *parent);
virtual ~TrayIconMenu(); virtual ~TrayIconMenu();
@ -24,6 +25,7 @@ class SystemTrayIcon : public QSystemTrayIcon {
Q_OBJECT Q_OBJECT
public: public:
// Constructors and destructors.
explicit SystemTrayIcon(const QString &normal_icon, explicit SystemTrayIcon(const QString &normal_icon,
const QString &plain_icon, const QString &plain_icon,
FormMain *parent = 0); FormMain *parent = 0);
@ -51,7 +53,7 @@ class SystemTrayIcon : public QSystemTrayIcon {
private slots: private slots:
void showPrivate(); void showPrivate();
void onActivated(const ActivationReason &reason); void onActivated(const QSystemTrayIcon::ActivationReason &reason);
private: private:
QString m_normalIcon; QString m_normalIcon;

View File

@ -19,9 +19,9 @@ TabWidget::~TabWidget() {
} }
void TabWidget::createConnections() { void TabWidget::createConnections() {
connect(tabBar(), &QTabBar::tabCloseRequested, this, &TabWidget::closeTab); connect(tabBar(), SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
connect(tabBar(), &TabBar::emptySpaceDoubleClicked, connect(tabBar(), SIGNAL(emptySpaceDoubleClicked()),
this, &TabWidget::addEmptyBrowser); this, SLOT(addEmptyBrowser()));
} }
TabBar *TabWidget::tabBar() { TabBar *TabWidget::tabBar() {
@ -53,7 +53,7 @@ void TabWidget::setupIcons() {
// Other indexes probably contain WebBrowsers. // Other indexes probably contain WebBrowsers.
else { else {
WebBrowser *active_browser = widget(index)->webBrowser(); WebBrowser *active_browser = widget(index)->webBrowser();
if (active_browser != nullptr && active_browser->icon().isNull()) { if (active_browser != NULL && active_browser->icon().isNull()) {
// We found WebBrowser instance of this tab page, which // We found WebBrowser instance of this tab page, which
// has no suitable icon, load a new one from the icon theme. // has no suitable icon, load a new one from the icon theme.
setTabIcon(index, IconThemeFactory::getInstance()->fromTheme("text-html")); setTabIcon(index, IconThemeFactory::getInstance()->fromTheme("text-html"));
@ -103,14 +103,10 @@ int TabWidget::insertTab(int index, QWidget *widget, const QString &label,
} }
int TabWidget::addEmptyBrowser() { int TabWidget::addEmptyBrowser() {
// TODO: Add reading of move_after_current and make_active
// flags from settings.
return addBrowser(false, true); return addBrowser(false, true);
} }
int TabWidget::addLinkedBrowser(const QUrl &initial_url) { int TabWidget::addLinkedBrowser(const QUrl &initial_url) {
// TODO: Add reading of move_after_current and make_active
// flags from settings.
return addBrowser(Settings::getInstance()->value(APP_CFG_BROWSER, return addBrowser(Settings::getInstance()->value(APP_CFG_BROWSER,
"queue_tabs", "queue_tabs",
true).toBool(), true).toBool(),

View File

@ -2,6 +2,7 @@
#define TABWIDGET_H #define TABWIDGET_H
#include <QTabWidget> #include <QTabWidget>
#include <QUrl>
#include "gui/tabbar.h" #include "gui/tabbar.h"
#include "gui/tabcontent.h" #include "gui/tabcontent.h"
@ -50,12 +51,12 @@ class TabWidget : public QTabWidget {
// Adds new WebBrowser with link. This is used when user // Adds new WebBrowser with link. This is used when user
// selects to "Open link in new tab.". // selects to "Open link in new tab.".
int addLinkedBrowser(const QUrl &initial_url); int addLinkedBrowser(const QUrl &initial_url = QUrl());
// General method for adding WebBrowsers. // General method for adding WebBrowsers.
int addBrowser(bool move_after_current, int addBrowser(bool move_after_current,
bool make_active, bool make_active,
const QUrl &initial_url = QUrl()); const QUrl &initial_url = QUrl());
}; };
#endif // TABWIDGET_H #endif // TABWIDGET_H

View File

@ -11,6 +11,7 @@
#include "core/basewebpage.h" #include "core/basewebpage.h"
#include "gui/basewebview.h" #include "gui/basewebview.h"
#include "gui/webbrowser.h" #include "gui/webbrowser.h"
#include "gui/formmain.h"
#include "gui/locationlineedit.h" #include "gui/locationlineedit.h"
#include "gui/iconthemefactory.h" #include "gui/iconthemefactory.h"
#include "gui/tabwidget.h" #include "gui/tabwidget.h"
@ -19,7 +20,7 @@
QPointer<WebBrowserNetworkAccessManager> WebBrowser::m_networkManager; QPointer<WebBrowserNetworkAccessManager> WebBrowser::m_networkManager;
QList<WebBrowser*> WebBrowser::m_runningWebBrowsers; QList<WebBrowser*> WebBrowser::m_runningWebBrowsers;
WebBrowser::WebBrowser(TabWidget *parent) WebBrowser::WebBrowser(QWidget *parent)
: TabContent(parent), m_layout(new QVBoxLayout(this)), : TabContent(parent), m_layout(new QVBoxLayout(this)),
m_toolBar(new QToolBar(tr("Navigation panel"), this)), m_toolBar(new QToolBar(tr("Navigation panel"), this)),
m_webView(new BaseWebView(this)), m_webView(new BaseWebView(this)),
@ -71,28 +72,20 @@ WebBrowser::WebBrowser(TabWidget *parent)
void WebBrowser::createConnections() { void WebBrowser::createConnections() {
// When user confirms new url, then redirect to it. // When user confirms new url, then redirect to it.
connect(m_txtLocation, connect(m_txtLocation,SIGNAL(submitted(QString)),
&LocationLineEdit::submitted, this, SLOT(navigateToUrl(QString)));
this,
static_cast<void (WebBrowser::*)(const QString &url)>(&WebBrowser::navigateToUrl));
// If new page loads, then update current url. // If new page loads, then update current url.
connect(m_webView, &BaseWebView::urlChanged, connect(m_webView, SIGNAL(urlChanged(QUrl)), this, SLOT(updateUrl(QUrl)));
this, &WebBrowser::updateUrl);
// Connect this WebBrowser to global TabWidget. // Connect this WebBrowser to global TabWidget.
// TODO: Think over moving this connections from here to TabWidget *tab_widget = FormMain::getInstance()->getTabWidget();
// e.g. TabWidget::addBrowser. connect(m_webView, SIGNAL(newTabRequested()), tab_widget, SLOT(addEmptyBrowser()));
TabWidget *parent_widget = static_cast<TabWidget*>(parent()); connect(m_webView, SIGNAL(linkMiddleClicked(QUrl)),
connect(m_webView, &BaseWebView::newTabRequested, tab_widget, SLOT(addLinkedBrowser(QUrl)));
parent_widget, &TabWidget::addEmptyBrowser);
connect(m_webView, &BaseWebView::linkMiddleClicked,
parent_widget, &TabWidget::addLinkedBrowser);
// Change location textbox status according to webpage status. // Change location textbox status according to webpage status.
connect(m_webView, &BaseWebView::loadProgress, connect(m_webView, SIGNAL(loadProgress(int)), m_txtLocation, SLOT(setProgress(int)));
m_txtLocation, &LocationLineEdit::setProgress); connect(m_webView, SIGNAL(loadFinished(bool)), m_txtLocation, SLOT(clearProgress()));
connect(m_webView, &BaseWebView::loadFinished,
m_txtLocation, &LocationLineEdit::clearProgress);
} }
void WebBrowser::updateUrl(const QUrl &url) { void WebBrowser::updateUrl(const QUrl &url) {
@ -106,7 +99,11 @@ void WebBrowser::navigateToUrl(const QUrl &url) {
} }
void WebBrowser::navigateToUrl(const QString &textual_url) { void WebBrowser::navigateToUrl(const QString &textual_url) {
navigateToUrl(QUrl::fromUserInput(textual_url)); // Prepare input url.
QString better_url = textual_url;
better_url = better_url.replace('\\', '/');
navigateToUrl(QUrl::fromUserInput(better_url));
} }
WebBrowser::~WebBrowser() { WebBrowser::~WebBrowser() {
@ -124,7 +121,7 @@ WebBrowser *WebBrowser::webBrowser() {
} }
QMenu *WebBrowser::globalMenu() { QMenu *WebBrowser::globalMenu() {
return nullptr; return NULL;
} }
QIcon WebBrowser::icon() { QIcon WebBrowser::icon() {

View File

@ -2,6 +2,8 @@
#define WEBBROWSER_H #define WEBBROWSER_H
#include <QWidget> #include <QWidget>
#include <QPointer>
#include <QUrl>
#include "gui/tabcontent.h" #include "gui/tabcontent.h"
@ -19,7 +21,7 @@ class WebBrowser : public TabContent {
public: public:
// Constructors and destructors. // Constructors and destructors.
explicit WebBrowser(TabWidget *parent = 0); explicit WebBrowser(QWidget *parent = 0);
~WebBrowser(); ~WebBrowser();
// Reloads icons for all buttons. // Reloads icons for all buttons.

View File

@ -43,7 +43,11 @@ int main(int argc, char *argv[]) {
#endif #endif
// Setup debug output system. // Setup debug output system.
#if QT_VERSION >= 0x050000
qInstallMessageHandler(Debugging::debugHandler); qInstallMessageHandler(Debugging::debugHandler);
#else
qInstallMsgHandler(Debugging::debugHandler);
#endif
// Instantiate base application object. // Instantiate base application object.
QtSingleApplication application(argc, argv); QtSingleApplication application(argc, argv);
@ -109,8 +113,8 @@ int main(int argc, char *argv[]) {
} }
// Setup single-instance behavior. // Setup single-instance behavior.
QObject::connect(&application, &QtSingleApplication::messageReceived, QObject::connect(&application, SIGNAL(messageReceived(const QString&)),
&window, &FormMain::processExecutionMessage); &window, SLOT(processExecutionMessage(QString)));
// Enter global event loop. // Enter global event loop.
return QtSingleApplication::exec(); return QtSingleApplication::exec();