From 8120ff64673b8bbbb8c2c2b4fde4dbea52b68f63 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Wed, 23 Mar 2016 09:35:56 +0100 Subject: [PATCH] Work on web browsing. --- CMakeLists.txt | 4 +--- src/definitions/definitions.h.in | 5 ----- src/gui/statusbar.cpp | 18 +++++++++++++----- src/gui/statusbar.h | 1 - src/miscellaneous/settings.cpp | 17 +---------------- src/miscellaneous/settings.h | 17 ----------------- src/network-web/webbrowser.cpp | 9 ++++----- src/network-web/webpage.cpp | 7 +------ src/network-web/webpage.h | 3 --- src/network-web/webview.cpp | 25 +++++++++++++------------ 10 files changed, 33 insertions(+), 73 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e02fb7505..734b2c161 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -330,8 +330,7 @@ file( GLOB APP_FORMS "src/services/standard/gui/*.ui" "src/services/tt-rss/gui/*.ui" "src/services/owncloud/gui/*.ui" - "src/network-web/*.ui" - "src/network-web/adblock/*.ui") + "src/network-web/*.ui") # APP translations. file( GLOB APP_TRANSLATIONS @@ -383,7 +382,6 @@ include_directories ( ${CMAKE_SOURCE_DIR}/src/gui/dialogs ${CMAKE_SOURCE_DIR}/src/gui/notifications ${CMAKE_SOURCE_DIR}/src/network-web - ${CMAKE_SOURCE_DIR}/src/network-web/adblock ${CMAKE_SOURCE_DIR}/src/dynamic-shortcuts ${CMAKE_BINARY_DIR}/src ) diff --git a/src/definitions/definitions.h.in b/src/definitions/definitions.h.in index cf5e91a01..648dd8792 100755 --- a/src/definitions/definitions.h.in +++ b/src/definitions/definitions.h.in @@ -104,11 +104,6 @@ #define PLACEHOLDER_UNREAD_COUNTS "%unread" #define PLACEHOLDER_ALL_COUNTS "%all" -#define ADBLOCK_CUSTOM_LIST_FILENAME "custom_rules.txt" -#define ADBLOCK_BASE_DIRECTORY_NAME "data/adblock" -#define ADBLOCK_FILTERS_HELP "https://adblockplus.org/en/filters" -#define ADBLOCK_EASYLIST_URL "https://easylist-downloads.adblockplus.org/easylist.txt" - #define BACKUP_NAME_SETTINGS "config" #define BACKUP_SUFFIX_SETTINGS ".ini.backup" #define BACKUP_NAME_DATABASE "database" diff --git a/src/gui/statusbar.cpp b/src/gui/statusbar.cpp index 54133e47c..f90cb6ad8 100755 --- a/src/gui/statusbar.cpp +++ b/src/gui/statusbar.cpp @@ -156,7 +156,7 @@ void StatusBar::loadChangeableActions(const QStringList &action_names) { action_to_add->setProperty("type", SPACER_ACTION_NAME); action_to_add->setProperty("name", tr("Toolbar spacer")); } - else { + else if (matching_action != NULL) { // Add originally toolbar action. PlainToolButton *tool_button = new PlainToolButton(this); tool_button->reactOnActionChange(matching_action); @@ -167,13 +167,21 @@ void StatusBar::loadChangeableActions(const QStringList &action_names) { connect(tool_button, SIGNAL(clicked(bool)), matching_action, SLOT(trigger())); connect(matching_action, SIGNAL(changed()), tool_button, SLOT(reactOnActionChange())); } + else { + action_to_add = NULL; + widget_to_add = NULL; + } - action_to_add->setProperty("should_remove_widget", true); + if (action_to_add != NULL) { + action_to_add->setProperty("should_remove_widget", true); + } } - action_to_add->setProperty("widget", QVariant::fromValue((void*) widget_to_add)); - addPermanentWidget(widget_to_add); - addAction(action_to_add); + if (action_to_add != NULL && widget_to_add != NULL) { + action_to_add->setProperty("widget", QVariant::fromValue((void*) widget_to_add)); + addPermanentWidget(widget_to_add); + addAction(action_to_add); + } } } diff --git a/src/gui/statusbar.h b/src/gui/statusbar.h index 39b3c36b8..a61ee3d89 100755 --- a/src/gui/statusbar.h +++ b/src/gui/statusbar.h @@ -25,7 +25,6 @@ class QProgressBar; class PlainToolButton; class QLabel; -class AdBlockIcon; class StatusBar : public QStatusBar, public BaseBar { Q_OBJECT diff --git a/src/miscellaneous/settings.cpp b/src/miscellaneous/settings.cpp index ed03109b0..9022f3a78 100755 --- a/src/miscellaneous/settings.cpp +++ b/src/miscellaneous/settings.cpp @@ -85,7 +85,7 @@ DKEY GUI::FeedsToolbarActions = "feeds_toolbar"; DVALUE(char*) GUI::FeedsToolbarActionsDef = "m_actionUpdateAllItems,m_actionStopRunningItemsUpdate,m_actionMarkAllItemsRead"; DKEY GUI::StatusbarActions = "status_bar"; -DVALUE(char*) GUI::StatusbarActionsDef = "m_lblProgressFeedsAction,m_barProgressFeedsAction,m_actionUpdateAllItems,m_actionUpdateSelectedItems,m_actionStopRunningItemsUpdate,m_adBlockIconAction,m_actionFullscreen,m_actionQuit"; +DVALUE(char*) GUI::StatusbarActionsDef = "m_lblProgressFeedsAction,m_barProgressFeedsAction,m_actionUpdateAllItems,m_actionUpdateSelectedItems,m_actionStopRunningItemsUpdate,m_actionFullscreen,m_actionQuit"; DKEY GUI::MainWindowInitialSize = "window_size"; DKEY GUI::MainWindowInitialPosition = "window_position"; @@ -241,21 +241,6 @@ DVALUE(char*) Database::ActiveDriverDef = APP_DB_SQLITE_DRIVER; // Keyboard. DKEY Keyboard::ID = "keyboard"; -// Adblock. -DKEY AdBlock::ID = "adblock"; - -DKEY AdBlock::Enabled = "enabled"; -DVALUE(bool) AdBlock::EnabledDef = false; - -DKEY AdBlock::UseLimitedEasyList = "use_limited_easylist"; -DVALUE(bool) AdBlock::UseLimitedEasyListDef = true; - -DKEY AdBlock::DisabledRules = "disabled_rules"; -DVALUE(QStringList) AdBlock::DisabledRulesDef = QStringList(); - -DKEY AdBlock::LastUpdated = "last_updated"; -DVALUE(QDateTime) AdBlock::LastUpdatedDef = QDateTime(); - // Web browser. DKEY Browser::ID = "browser"; diff --git a/src/miscellaneous/settings.h b/src/miscellaneous/settings.h index f9683ea00..022a32bf6 100755 --- a/src/miscellaneous/settings.h +++ b/src/miscellaneous/settings.h @@ -269,23 +269,6 @@ namespace Keyboard { KEY ID; } -// Adblock. -namespace AdBlock { - KEY ID; - - KEY Enabled; - VALUE(bool) EnabledDef; - - KEY UseLimitedEasyList; - VALUE(bool) UseLimitedEasyListDef; - - KEY DisabledRules; - VALUE(QStringList) DisabledRulesDef; - - KEY LastUpdated; - VALUE(QDateTime) LastUpdatedDef; -} - // Web browser. namespace Browser { KEY ID; diff --git a/src/network-web/webbrowser.cpp b/src/network-web/webbrowser.cpp index 89f1695da..3eab9fc4e 100755 --- a/src/network-web/webbrowser.cpp +++ b/src/network-web/webbrowser.cpp @@ -163,19 +163,18 @@ void WebBrowser::initializeLayout() { void WebBrowser::onLoadingStarted() { m_loadingProgress->setValue(0); m_loadingWidget->show(); + m_btnDiscoverFeeds->setEnabled(false); } void WebBrowser::onLoadingProgress(int progress) { m_loadingProgress->setValue(progress); - // 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) { if (success) { - // Let's check if there are any feeds defined on the web and eventually - // display "Add feeds" button. - m_btnDiscoverFeeds->setFeedAddresses(NetworkFactory::extractFeedLinksFromHtmlPage(m_webView->url(), m_webView->page()->toHtml())); + m_webView->page()->toHtml([this](const QString &html) { + this->m_btnDiscoverFeeds->setFeedAddresses(NetworkFactory::extractFeedLinksFromHtmlPage(m_webView->url(), html)); + }); } else { m_btnDiscoverFeeds->clearFeedAddresses(); diff --git a/src/network-web/webpage.cpp b/src/network-web/webpage.cpp index 81bdb5ded..c462543ec 100755 --- a/src/network-web/webpage.cpp +++ b/src/network-web/webpage.cpp @@ -31,6 +31,7 @@ WebPage::~WebPage() { } bool WebPage::isLoading() const { + // TODO: nepouzivany? return m_loadProgress < 100; } @@ -41,9 +42,3 @@ void WebPage::progress(int prog) { void WebPage::finished() { progress(100); } - -QString WebPage::toHtml() const { - return QString(); - // TODO: TODO - //return mainFrame()->toHtml(); -} diff --git a/src/network-web/webpage.h b/src/network-web/webpage.h index 1da11261a..2e76039d4 100755 --- a/src/network-web/webpage.h +++ b/src/network-web/webpage.h @@ -22,8 +22,6 @@ #include -class AdBlockRule; - class WebPage : public QWebEnginePage { Q_OBJECT @@ -32,7 +30,6 @@ class WebPage : public QWebEnginePage { explicit WebPage(QObject *parent = 0); virtual ~WebPage(); - QString toHtml() const; bool isLoading() const; private slots: diff --git a/src/network-web/webview.cpp b/src/network-web/webview.cpp index b80afde85..baacca247 100755 --- a/src/network-web/webview.cpp +++ b/src/network-web/webview.cpp @@ -125,20 +125,21 @@ void WebView::saveCurrentPageToFile() { }*/ if (!selected_file.isEmpty()) { - QFile selected_file_handle(selected_file); + page()->toHtml([this, selected_file](const QString &html) { + QFile selected_file_handle(selected_file); - if (selected_file_handle.open(QIODevice::WriteOnly | QIODevice::Unbuffered)) { - const QString html_text = page()->toHtml(); - QTextStream str(&selected_file_handle); + if (selected_file_handle.open(QIODevice::WriteOnly | QIODevice::Unbuffered)) { + QTextStream str(&selected_file_handle); - str.setCodec("UTF-16"); - str << html_text; - selected_file_handle.close(); - } - else { - MessageBox::show(this, QMessageBox::Critical, tr("Cannot save web page"), - tr("Web page cannot be saved because destination file is not writtable.")); - } + str.setCodec("UTF-16"); + str << html; + selected_file_handle.close(); + } + else { + MessageBox::show(this, QMessageBox::Critical, tr("Cannot save web page"), + tr("Web page cannot be saved because destination file is not writtable.")); + } + }); } }