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