Some minor tweaks + fixed #320.

This commit is contained in:
Martin Rotter 2021-01-05 20:07:01 +01:00
parent c61561a742
commit 4a0b1a90b7
10 changed files with 59 additions and 33 deletions

View File

@ -239,10 +239,10 @@ nl_before_cpp_comment = 2 # unsigned number
nl_before_class = 0 # unsigned number
# The number of newlines after '}' or ';' of a class definition
nl_after_class = 0 # unsigned number
nl_after_class = 2 # unsigned number
# The number of newlines after '}' or ';' of a struct/enum/union definition.
nl_after_struct = 0 # unsigned number
nl_after_struct = 2 # unsigned number
# The number of newlines after '}' of a multi-line function body
nl_after_func_body = 2 # unsigned number

View File

@ -29,8 +29,8 @@ void DiscoverFeedsButton::clearFeedAddresses() {
void DiscoverFeedsButton::setFeedAddresses(const QStringList& addresses) {
setEnabled(!addresses.isEmpty());
setToolTip(addresses.isEmpty() ?
tr("This website does not contain any feeds.") :
tr("Click me to add feeds from this website.\nThis website contains %n feed(s).", 0, addresses.size()));
tr("This website does not contain any feeds") :
tr("Add one of %n feed(s)", 0, addresses.size()));
if (menu() == nullptr) {
// Initialize the menu.

View File

@ -32,7 +32,7 @@ class RSSGUARD_DLLSPEC FeedMessageViewer : public TabContent {
virtual ~FeedMessageViewer();
#if defined(USE_WEBENGINE)
WebBrowser* webBrowser() const;
virtual WebBrowser* webBrowser() const;
#endif
FeedsView* feedsView() const;

View File

@ -31,7 +31,7 @@ class NewspaperPreviewer : public TabContent {
explicit NewspaperPreviewer(int msg_height, RootItem* root, QList<Message> messages, QWidget* parent = nullptr);
#if defined(USE_WEBENGINE)
WebBrowser* webBrowser() const;
virtual WebBrowser* webBrowser() const;
#endif
public slots:

View File

@ -23,7 +23,6 @@ class TabContent : public QWidget {
virtual void setIndex(int index);
#if defined(USE_WEBENGINE)
// Obtains instance contained in this TabContent or nullptr.
// This can be used for obtaining the menu from the instance and so on.
virtual WebBrowser* webBrowser() const = 0;

View File

@ -9,6 +9,7 @@
#include "gui/webviewer.h"
#include "miscellaneous/application.h"
#include "miscellaneous/databasequeries.h"
#include "miscellaneous/iconfactory.h"
#include "network-web/networkfactory.h"
#include "network-web/webfactory.h"
#include "services/abstract/serviceroot.h"
@ -31,7 +32,10 @@ WebBrowser::WebBrowser(QWidget* parent) : TabContent(parent),
m_actionBack(m_webView->pageAction(QWebEnginePage::Back)),
m_actionForward(m_webView->pageAction(QWebEnginePage::Forward)),
m_actionReload(m_webView->pageAction(QWebEnginePage::Reload)),
m_actionStop(m_webView->pageAction(QWebEnginePage::Stop)) {
m_actionStop(m_webView->pageAction(QWebEnginePage::Stop)),
m_actionOpenInSystemBrowser(new QAction(qApp->icons()->fromTheme(QSL("document-open")),
tr("Open this website in system web browser"),
this)) {
// Initialize the components and layout.
initializeLayout();
setFocusProxy(m_txtLocation);
@ -58,6 +62,8 @@ void WebBrowser::createConnections() {
m_searchWidget->setFocus();
});
connect(m_actionOpenInSystemBrowser, &QAction::triggered, this, &WebBrowser::openCurrentSiteInSystemBrowser);
connect(m_txtLocation, &LocationLineEdit::submitted,
this, static_cast<void (WebBrowser::*)(const QString&)>(&WebBrowser::loadUrl));
connect(m_webView, &WebViewer::urlChanged, this, &WebBrowser::updateUrl);
@ -172,6 +178,22 @@ bool WebBrowser::eventFilter(QObject* watched, QEvent* event) {
return false;
}
void WebBrowser::openCurrentSiteInSystemBrowser() {
auto url = m_webView->url();
if (!url.isValid() || url.host().contains(APP_LOW_NAME)) {
return;
}
if (!qApp->web()->openUrlInExternalBrowser(url.toString())) {
qApp->showGuiMessage(tr("Failed to open URL in web browser"),
tr("URL '%1' could not be opened in system's web browser.").arg(url.toString()),
QSystemTrayIcon::MessageIcon::Critical,
qApp->mainFormWidget(),
true);
}
}
void WebBrowser::onTitleChanged(const QString& new_title) {
if (new_title.isEmpty()) {
//: Webbrowser tab title when no title is available.
@ -189,19 +211,16 @@ void WebBrowser::onIconChanged(const QIcon& icon) {
void WebBrowser::initializeLayout() {
m_toolBar->setFloatable(false);
m_toolBar->setMovable(false);
m_toolBar->setAllowedAreas(Qt::TopToolBarArea);
m_toolBar->setAllowedAreas(Qt::ToolBarArea::TopToolBarArea);
// Modify action texts.
m_actionBack->setText(tr("Back"));
m_actionBack->setToolTip(tr("Go back."));
m_actionForward->setText(tr("Forward"));
m_actionForward->setToolTip(tr("Go forward."));
m_actionReload->setText(tr("Reload"));
m_actionReload->setToolTip(tr("Reload current web page."));
m_actionStop->setText(tr("Stop"));
m_actionStop->setToolTip(tr("Stop web page loading."));
QWidgetAction* act_discover = new QWidgetAction(this);
m_actionOpenInSystemBrowser->setEnabled(false);
act_discover->setDefaultWidget(m_btnDiscoverFeeds);
// Add needed actions into toolbar.
@ -209,6 +228,7 @@ void WebBrowser::initializeLayout() {
m_toolBar->addAction(m_actionForward);
m_toolBar->addAction(m_actionReload);
m_toolBar->addAction(m_actionStop);
m_toolBar->addAction(m_actionOpenInSystemBrowser);
m_toolBar->addAction(act_discover);
m_toolBar->addWidget(m_txtLocation);
m_loadingProgress = new QProgressBar(this);
@ -232,6 +252,7 @@ void WebBrowser::initializeLayout() {
void WebBrowser::onLoadingStarted() {
m_btnDiscoverFeeds->clearFeedAddresses();
m_loadingProgress->show();
m_actionOpenInSystemBrowser->setEnabled(false);
}
void WebBrowser::onLoadingProgress(int progress) {
@ -240,6 +261,12 @@ void WebBrowser::onLoadingProgress(int progress) {
void WebBrowser::onLoadingFinished(bool success) {
if (success) {
auto url = m_webView->url();
if (url.isValid() && !url.host().contains(APP_LOW_NAME)) {
m_actionOpenInSystemBrowser->setEnabled(true);
}
// Let's check if there are any feeds defined on the web and eventually
// display "Add feeds" button.
m_webView->page()->toHtml([this](const QString& result) {
@ -252,7 +279,6 @@ void WebBrowser::onLoadingFinished(bool success) {
m_loadingProgress->hide();
m_loadingProgress->setValue(0);
}
Message* WebBrowser::findMessage(int id) {

View File

@ -31,7 +31,8 @@ class WebBrowser : public TabContent {
explicit WebBrowser(QWidget* parent = nullptr);
virtual ~WebBrowser();
WebBrowser* webBrowser() const;
virtual WebBrowser* webBrowser() const;
WebViewer* viewer() const;
double verticalScrollBarPosition() const;
@ -54,8 +55,8 @@ class WebBrowser : public TabContent {
virtual bool eventFilter(QObject* watched, QEvent* event);
private slots:
void openCurrentSiteInSystemBrowser();
void updateUrl(const QUrl& url);
void onLoadingStarted();
void onLoadingProgress(int progress);
void onLoadingFinished(bool success);
@ -85,6 +86,7 @@ class WebBrowser : public TabContent {
QAction* m_actionForward;
QAction* m_actionReload;
QAction* m_actionStop;
QAction* m_actionOpenInSystemBrowser;
QList<Message> m_messages;
QPointer<RootItem> m_root;
};

View File

@ -14,23 +14,17 @@
#include <QNetworkReply>
class AutoSaver;
class DownloadModel;
class QFileIconProvider;
class QMimeData;
class DownloadItem : public QWidget {
Q_OBJECT
// Friends of this class.
friend class DownloadManager;
friend class DownloadModel;
public:
// Constructors.
explicit DownloadItem(QNetworkReply* reply = 0, QWidget* parent = nullptr);
virtual ~DownloadItem();
@ -81,7 +75,6 @@ class DownloadItem : public QWidget {
};
#if defined(USE_WEBENGINE)
class WebBrowser;
#endif
@ -106,9 +99,7 @@ class DownloadManager : public TabContent {
virtual ~DownloadManager();
#if defined(USE_WEBENGINE)
WebBrowser* webBrowser() const {
return nullptr;
}
virtual WebBrowser* webBrowser() const;
#endif
SilentNetworkAccessManager* networkManager() const;
@ -160,6 +151,13 @@ class DownloadManager : public TabContent {
QString m_downloadDirectory;
};
#if defined(USE_WEBENGINE)
inline WebBrowser* DownloadManager::webBrowser() const {
return nullptr;
}
#endif
class DownloadModel : public QAbstractListModel {
Q_OBJECT
@ -168,11 +166,11 @@ class DownloadModel : public QAbstractListModel {
public:
explicit DownloadModel(DownloadManager* download_manager, QObject* parent = nullptr);
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
int rowCount(const QModelIndex& parent = QModelIndex()) const;
bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex());
Qt::ItemFlags flags(const QModelIndex& index) const;
QMimeData* mimeData(const QModelIndexList& indexes) const;
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
virtual bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex());
virtual Qt::ItemFlags flags(const QModelIndex& index) const;
virtual QMimeData* mimeData(const QModelIndexList& indexes) const;
private:
DownloadManager* m_downloadManager;

View File

@ -47,10 +47,10 @@ class GoogleSuggest : public QObject {
public:
explicit GoogleSuggest(LocationLineEdit* editor, QObject* parent = nullptr);
bool eventFilter(QObject* object, QEvent* event);
void showCompletion(const QStringList& choices);
virtual bool eventFilter(QObject* object, QEvent* event);
public slots:
void showCompletion(const QStringList& choices);
void doneCompletion();
void preventSuggest();
void autoSuggest();

View File

@ -73,6 +73,7 @@ class OAuthHttpHandler : public QObject {
QPair<quint8, quint8> m_version;
QMap<QByteArray, QByteArray> m_headers;
};
QMap<QTcpSocket*, QHttpRequest> m_connectedClients;
QTcpServer m_httpServer;
QHostAddress m_listenAddress;