mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-02-02 18:36:49 +01:00
Some refactorings...
This commit is contained in:
parent
0782a948d6
commit
a009241611
@ -178,7 +178,7 @@ QVariant FeedsModelStandardFeed::data(int column, int role) const {
|
||||
}
|
||||
else if (column == FDS_MODEL_COUNTS_INDEX) {
|
||||
// TODO: Changeable text.
|
||||
return QString("%1").arg(QString::number(countOfUnreadMessages()));
|
||||
return QString("(%1)").arg(QString::number(countOfUnreadMessages()));
|
||||
//QString::number(countOfAllMessages()));
|
||||
}
|
||||
else {
|
||||
|
@ -1,8 +1,11 @@
|
||||
#include "core/webbrowsernetworkaccessmanager.h"
|
||||
|
||||
#include <QNetworkReply>
|
||||
#include <QApplication>
|
||||
|
||||
|
||||
QPointer<WebBrowserNetworkAccessManager> WebBrowserNetworkAccessManager::s_instance;
|
||||
|
||||
WebBrowserNetworkAccessManager::WebBrowserNetworkAccessManager(QObject *parent)
|
||||
: BaseNetworkAccessManager(parent) {
|
||||
connect(this, SIGNAL(sslErrors(QNetworkReply*,QList<QSslError>)),
|
||||
@ -29,7 +32,15 @@ void WebBrowserNetworkAccessManager::onAuthenticationRequired(QNetworkReply *rep
|
||||
QAuthenticator *authenticator) {
|
||||
Q_UNUSED(authenticator);
|
||||
|
||||
// Authentication is required but this feed does not contain it.
|
||||
// TODO: Support authentication for web pages.
|
||||
qDebug("URL '%s' requested authentication but username/password is not available.",
|
||||
qPrintable(reply->url().toString()));
|
||||
}
|
||||
|
||||
WebBrowserNetworkAccessManager *WebBrowserNetworkAccessManager::instance() {
|
||||
if (s_instance.isNull()) {
|
||||
s_instance = new WebBrowserNetworkAccessManager(qApp);
|
||||
}
|
||||
|
||||
return s_instance;
|
||||
}
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
#include "core/basenetworkaccessmanager.h"
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
|
||||
// This is network access manager for web browsers.
|
||||
class WebBrowserNetworkAccessManager : public BaseNetworkAccessManager {
|
||||
@ -13,9 +15,18 @@ class WebBrowserNetworkAccessManager : public BaseNetworkAccessManager {
|
||||
explicit WebBrowserNetworkAccessManager(QObject *parent = 0);
|
||||
virtual ~WebBrowserNetworkAccessManager();
|
||||
|
||||
// Returns pointer to global network access manager
|
||||
// used by ALL web browsers.
|
||||
// NOTE: All web browsers use shared network access manager,
|
||||
// which makes setting of custom network settings easy.
|
||||
static WebBrowserNetworkAccessManager *instance();
|
||||
|
||||
protected slots:
|
||||
void onSslErrors(QNetworkReply *reply, const QList<QSslError> &error);
|
||||
void onAuthenticationRequired(QNetworkReply * reply, QAuthenticator *authenticator);
|
||||
|
||||
private:
|
||||
static QPointer<WebBrowserNetworkAccessManager> s_instance;
|
||||
};
|
||||
|
||||
#endif // WEBBROWSERNETWORKACCESSMANAGER_H
|
||||
|
@ -11,7 +11,7 @@ WebPage::WebPage(QObject *parent)
|
||||
: QWebPage(parent) {
|
||||
// Setup global network access manager.
|
||||
// NOTE: This makes network settings easy for all web browsers.
|
||||
setNetworkAccessManager(WebBrowser::globalNetworkManager());
|
||||
setNetworkAccessManager(WebBrowserNetworkAccessManager::instance());
|
||||
}
|
||||
|
||||
WebPage::~WebPage() {
|
||||
|
@ -389,7 +389,7 @@ void FormSettings::saveProxy() {
|
||||
m_ui->m_spinProxyPort->value());
|
||||
|
||||
// Reload settings for all network access managers.
|
||||
WebBrowser::globalNetworkManager()->loadSettings();
|
||||
WebBrowserNetworkAccessManager::instance()->loadSettings();
|
||||
}
|
||||
|
||||
void FormSettings::loadLanguage() {
|
||||
|
@ -46,7 +46,7 @@ void FormUpdate::checkForUpdates() {
|
||||
m_ui->m_lblAvailableRelease->setText(tr("unknown"));
|
||||
m_ui->m_txtChanges->clear();
|
||||
m_ui->m_lblStatus->setStatus(WidgetWithStatus::Error,
|
||||
tr("Connection error occurred."),
|
||||
tr("Error: '%1'.").arg(NetworkFactory::networkErrorText(update.second)),
|
||||
tr("List with updates was "
|
||||
"not\ndownloaded successfully."));
|
||||
}
|
||||
|
@ -12,8 +12,6 @@
|
||||
#include <QVBoxLayout>
|
||||
#include <QToolBar>
|
||||
#include <QAction>
|
||||
#include <QPointer>
|
||||
#include <QApplication>
|
||||
#include <QWebFrame>
|
||||
#include <QWidgetAction>
|
||||
#include <QSlider>
|
||||
@ -21,7 +19,6 @@
|
||||
#include <QToolButton>
|
||||
|
||||
|
||||
QPointer<WebBrowserNetworkAccessManager> WebBrowser::m_networkManager;
|
||||
QList<WebBrowser*> WebBrowser::m_runningWebBrowsers;
|
||||
|
||||
WebBrowser::WebBrowser(QWidget *parent)
|
||||
@ -42,33 +39,8 @@ WebBrowser::WebBrowser(QWidget *parent)
|
||||
// NOTE: This is used primarily for dynamic icon theme switching.
|
||||
m_runningWebBrowsers.append(this);
|
||||
|
||||
// Set properties of some components.
|
||||
m_toolBar->setFloatable(false);
|
||||
m_toolBar->setMovable(false);
|
||||
m_toolBar->setAllowedAreas(Qt::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."));
|
||||
|
||||
// Add needed actions into toolbar.
|
||||
m_toolBar->addAction(m_actionBack);
|
||||
m_toolBar->addAction(m_actionForward);
|
||||
m_toolBar->addAction(m_actionReload);
|
||||
m_toolBar->addAction(m_actionStop);
|
||||
m_toolBar->addWidget(m_txtLocation);
|
||||
|
||||
// Setup layout.
|
||||
m_layout->addWidget(m_toolBar);
|
||||
m_layout->addWidget(m_webView);
|
||||
m_layout->setMargin(0);
|
||||
m_layout->setSpacing(0);
|
||||
// Initialize the components and layout.
|
||||
initializeLayout();
|
||||
|
||||
setTabOrder(m_txtLocation, m_toolBar);
|
||||
setTabOrder(m_toolBar, m_webView);
|
||||
@ -112,6 +84,35 @@ void WebBrowser::initializeZoomWidget() {
|
||||
m_actionZoom->setDefaultWidget(m_zoomButtons);
|
||||
}
|
||||
|
||||
void WebBrowser::initializeLayout() {
|
||||
m_toolBar->setFloatable(false);
|
||||
m_toolBar->setMovable(false);
|
||||
m_toolBar->setAllowedAreas(Qt::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."));
|
||||
|
||||
// Add needed actions into toolbar.
|
||||
m_toolBar->addAction(m_actionBack);
|
||||
m_toolBar->addAction(m_actionForward);
|
||||
m_toolBar->addAction(m_actionReload);
|
||||
m_toolBar->addAction(m_actionStop);
|
||||
m_toolBar->addWidget(m_txtLocation);
|
||||
|
||||
// Setup layout.
|
||||
m_layout->addWidget(m_toolBar);
|
||||
m_layout->addWidget(m_webView);
|
||||
m_layout->setMargin(0);
|
||||
m_layout->setSpacing(0);
|
||||
}
|
||||
|
||||
void WebBrowser::createConnections() {
|
||||
// When user confirms new url, then redirect to it.
|
||||
connect(m_txtLocation,SIGNAL(submitted(QString)),
|
||||
@ -163,22 +164,22 @@ void WebBrowser::navigateToUrl(const QUrl &url) {
|
||||
void WebBrowser::navigateToMessages(const QList<Message> &messages) {
|
||||
SkinFactory *factory = SkinFactory::instance();
|
||||
QString messages_layout;
|
||||
QString default_message_layout = factory->currentMarkup();
|
||||
QString single_message_layout = factory->currentMarkup();
|
||||
|
||||
foreach (const Message &message, messages) {
|
||||
messages_layout.append(default_message_layout.arg(message.m_title,
|
||||
tr("Written by ") + (message.m_author.isEmpty() ?
|
||||
tr("uknown author") :
|
||||
message.m_author),
|
||||
message.m_url,
|
||||
message.m_contents,
|
||||
message.m_created.toString(Qt::DefaultLocaleShortDate)));
|
||||
messages_layout.append(single_message_layout.arg(message.m_title,
|
||||
tr("Written by ") + (message.m_author.isEmpty() ?
|
||||
tr("uknown author") :
|
||||
message.m_author),
|
||||
message.m_url,
|
||||
message.m_contents,
|
||||
message.m_created.toString(Qt::DefaultLocaleShortDate)));
|
||||
}
|
||||
|
||||
QString layout_wrapper = factory->currentMarkupLayout().arg(messages.size() == 1 ?
|
||||
messages.at(0).m_title :
|
||||
tr("Newspaper view"),
|
||||
messages_layout);
|
||||
messages.at(0).m_title :
|
||||
tr("Newspaper view"),
|
||||
messages_layout);
|
||||
|
||||
m_webView->setHtml(layout_wrapper, QUrl(INTERNAL_URL_NEWSPAPER));
|
||||
emit iconChanged(m_index,
|
||||
@ -233,17 +234,3 @@ void WebBrowser::setupIcons() {
|
||||
m_actionStop->setIcon(IconThemeFactory::instance()->fromTheme("go-stop"));
|
||||
m_webView->setupIcons();
|
||||
}
|
||||
|
||||
QList<WebBrowser *> WebBrowser::runningWebBrowsers() {
|
||||
return m_runningWebBrowsers;
|
||||
}
|
||||
|
||||
|
||||
|
||||
WebBrowserNetworkAccessManager *WebBrowser::globalNetworkManager() {
|
||||
if (m_networkManager.isNull()) {
|
||||
m_networkManager = new WebBrowserNetworkAccessManager(qApp);
|
||||
}
|
||||
|
||||
return m_networkManager;
|
||||
}
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
#include <QWidget>
|
||||
#include <QWidgetAction>
|
||||
#include <QPointer>
|
||||
#include <QUrl>
|
||||
#include <QToolBar>
|
||||
|
||||
@ -56,14 +55,10 @@ class WebBrowser : public TabContent {
|
||||
return browser_menu;
|
||||
}
|
||||
|
||||
// Returns pointer to global network access manager
|
||||
// for web browsers.
|
||||
// NOTE: All web browsers use shared network access manager,
|
||||
// which makes setting of custom network settings easy.
|
||||
static WebBrowserNetworkAccessManager *globalNetworkManager();
|
||||
|
||||
// Returns list of all running web browsers.
|
||||
static QList<WebBrowser*> runningWebBrowsers();
|
||||
static inline QList<WebBrowser*> runningWebBrowsers() {
|
||||
return m_runningWebBrowsers;
|
||||
}
|
||||
|
||||
public slots:
|
||||
// Switches visibility of navigation bar.
|
||||
@ -95,6 +90,9 @@ class WebBrowser : public TabContent {
|
||||
// Initializes all buttons and widgets, which are needed for "Zoom" menu item.
|
||||
void initializeZoomWidget();
|
||||
|
||||
// Initializes layout.
|
||||
void initializeLayout();
|
||||
|
||||
protected slots:
|
||||
// Updates zoom-related gui.
|
||||
void updateZoomGui();
|
||||
@ -102,13 +100,17 @@ class WebBrowser : public TabContent {
|
||||
// Updates url (for example on location text box).
|
||||
void updateUrl(const QUrl &url);
|
||||
|
||||
// Title/icon is changed.
|
||||
void onTitleChanged(const QString &new_title);
|
||||
void onIconChanged();
|
||||
|
||||
signals:
|
||||
// User requests opening of new tab or clicks the link
|
||||
// with middle mouse button
|
||||
void newTabRequested();
|
||||
void linkMiddleClicked(const QUrl &link_url);
|
||||
|
||||
// Title/icon is changed.
|
||||
void iconChanged(int index, const QIcon &icon);
|
||||
void titleChanged(int index, const QString &title);
|
||||
|
||||
@ -128,7 +130,6 @@ class WebBrowser : public TabContent {
|
||||
|
||||
bool m_activeNewspaperMode;
|
||||
|
||||
static QPointer<WebBrowserNetworkAccessManager> m_networkManager;
|
||||
static QList<WebBrowser*> m_runningWebBrowsers;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user