From acf5e63f7ce27abd8042d1fed322c653e29dffef Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Sun, 5 Jan 2014 18:43:07 +0100 Subject: [PATCH] Massive code upkeep. --- src/gui/feedmessageviewer.cpp | 10 +++++----- src/gui/messagesview.cpp | 19 ++++++++++++------- src/gui/messagesview.h | 10 +++++----- src/gui/tabwidget.cpp | 12 +++++------- src/gui/tabwidget.h | 1 - src/gui/webbrowser.cpp | 7 ++----- src/gui/webbrowser.h | 7 +++---- src/gui/webview.h | 1 + 8 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/gui/feedmessageviewer.cpp b/src/gui/feedmessageviewer.cpp index 2dcf296ca..ed9335bb7 100644 --- a/src/gui/feedmessageviewer.cpp +++ b/src/gui/feedmessageviewer.cpp @@ -132,13 +132,13 @@ void FeedMessageViewer::onFeedUpdatesFinished() { void FeedMessageViewer::createConnections() { // General connections. - connect(m_messagesView, SIGNAL(currentMessageRemoved()), + connect(m_messagesView, SIGNAL(currentMessagesRemoved()), m_messagesBrowser, SLOT(clear())); - connect(m_messagesView, SIGNAL(currentMessageChanged(Message)), - m_messagesBrowser, SLOT(navigateToMessage(Message))); - connect(m_messagesView, SIGNAL(openMessageNewTabRequested(Message)), + connect(m_messagesView, SIGNAL(currentMessagesChanged(QList)), + m_messagesBrowser, SLOT(navigateToMessages(QList))); + connect(m_messagesView, SIGNAL(openMessagesInNewspaperView(QList)), FormMain::getInstance()->m_ui->m_tabWidget, - SLOT(addBrowserWithMessage(Message))); + SLOT(addBrowserWithMessages(QList))); connect(m_messagesView, SIGNAL(openLinkMessageNewTabRequested(QString)), FormMain::getInstance()->m_ui->m_tabWidget, SLOT(addLinkedBrowser(QString))); diff --git a/src/gui/messagesview.cpp b/src/gui/messagesview.cpp index 1759941aa..281ff7cce 100644 --- a/src/gui/messagesview.cpp +++ b/src/gui/messagesview.cpp @@ -84,7 +84,7 @@ void MessagesView::reloadSelections(int mark_current_index_read) { // be selected and no message can be displayed. // TOTO: Check if this is OKAY. If not, then emit this signal // from FeedsView itself. - emit currentMessageRemoved(); + emit currentMessagesRemoved(); } } @@ -205,10 +205,11 @@ void MessagesView::currentChanged(const QModelIndex ¤t, m_sourceModel->setMessageRead(mapped_current_index.row(), 1); } - emit currentMessageChanged(m_sourceModel->messageAt(mapped_current_index.row())); + emit currentMessagesChanged(QList() << + m_sourceModel->messageAt(mapped_current_index.row())); } else { - emit currentMessageRemoved(); + emit currentMessagesRemoved(); } QTreeView::currentChanged(current, previous); @@ -222,7 +223,7 @@ void MessagesView::loadFeeds(const QList &feed_ids) { // Messages are loaded, make sure that previously // active message is not shown in browser. - emit currentMessageRemoved(); + emit currentMessagesRemoved(); } void MessagesView::openSelectedSourceArticlesExternally() { @@ -256,15 +257,19 @@ void MessagesView::openSelectedSourceMessagesInternally() { tr("Message '%s' does not contain URL.").arg(message.m_title)); } else { - emit openLinkMessageNewTabRequested(message.m_url); + emit openLinkNewTab(message.m_url); } } } void MessagesView::openSelectedMessagesInternally() { + QList messages; + foreach (const QModelIndex &index, selectionModel()->selectedRows()) { - emit openMessageNewTabRequested(m_sourceModel->messageAt(m_proxyModel->mapToSource(index).row())); + messages << m_sourceModel->messageAt(m_proxyModel->mapToSource(index).row()); } + + emit openMessagesInNewspaperView(messages); } void MessagesView::markSelectedMessagesRead() { @@ -324,7 +329,7 @@ void MessagesView::deleteSelectedMessages() { reselectIndexes(QModelIndexList() << last_item); } else { - emit currentMessageRemoved(); + emit currentMessagesRemoved(); } } diff --git a/src/gui/messagesview.h b/src/gui/messagesview.h index 8f1854dfc..6d49b48d1 100755 --- a/src/gui/messagesview.h +++ b/src/gui/messagesview.h @@ -64,12 +64,12 @@ class MessagesView : public QTreeView { const QModelIndex &previous); signals: - void openLinkMessageNewTabRequested(const QString &link); - void openMessageNewTabRequested(const Message &message); - void openMessagesInNewspaperViewRequested(const QList &messages); + void openLinkNewTab(const QString &link); + void openMessagesInNewspaperView(const QList &messages); - void currentMessageChanged(const Message &message); - void currentMessageRemoved(); + // Notify others about message selections. + void currentMessagesChanged(const QList &messages); + void currentMessagesRemoved(); // Emitted if counts of unread/total messages has changed // because of user interaction with list of messages. diff --git a/src/gui/tabwidget.cpp b/src/gui/tabwidget.cpp index 14a808d32..1baecc837 100644 --- a/src/gui/tabwidget.cpp +++ b/src/gui/tabwidget.cpp @@ -175,15 +175,13 @@ int TabWidget::insertTab(int index, QWidget *widget, const QString &label, return tab_index; } -int TabWidget::addBrowserWithMessage(const Message &message) { - int new_index = addBrowser(false, false); - static_cast(widget(new_index))->navigateToMessage(message); - return new_index; -} - int TabWidget::addBrowserWithMessages(const QList &messages) { int new_index = addBrowser(false, true); - static_cast(widget(new_index))->navigateToMessages(messages); + WebBrowser *browser = static_cast(widget(new_index)); + + browser->setNavigationBarVisible(false); + browser->navigateToMessages(messages); + return new_index; } diff --git a/src/gui/tabwidget.h b/src/gui/tabwidget.h index b533362a0..5a48043e5 100644 --- a/src/gui/tabwidget.h +++ b/src/gui/tabwidget.h @@ -78,7 +78,6 @@ class TabWidget : public QTabWidget { void closeAllTabsExceptCurrent(); // Open single or multiple (newspaper mode) messages in new tab. - int addBrowserWithMessage(const Message &message); int addBrowserWithMessages(const QList &messages); // Adds new WebBrowser tab to global TabWidget. diff --git a/src/gui/webbrowser.cpp b/src/gui/webbrowser.cpp index 3b09bb6ec..c40258469 100644 --- a/src/gui/webbrowser.cpp +++ b/src/gui/webbrowser.cpp @@ -35,7 +35,8 @@ WebBrowser::WebBrowser(QWidget *parent) m_actionBack(m_webView->pageAction(QWebPage::Back)), m_actionForward(m_webView->pageAction(QWebPage::Forward)), m_actionReload(m_webView->pageAction(QWebPage::Reload)), - m_actionStop(m_webView->pageAction(QWebPage::Stop)) { + m_actionStop(m_webView->pageAction(QWebPage::Stop)), + m_activeNewspaperMode(false) { m_index = -1; @@ -165,10 +166,6 @@ void WebBrowser::clear() { m_webView->load(QUrl()); } -void WebBrowser::navigateToMessage(const Message &message) { - navigateToMessages(QList() << message); -} - void WebBrowser::navigateToMessages(const QList &messages) { SkinFactory *factory = SkinFactory::getInstance(); QString messages_layout; diff --git a/src/gui/webbrowser.h b/src/gui/webbrowser.h index 29ce7c59b..230e8d94a 100644 --- a/src/gui/webbrowser.h +++ b/src/gui/webbrowser.h @@ -60,10 +60,7 @@ class WebBrowser : public TabContent { void navigateToUrl(const QString &url); void navigateToUrl(const QUrl &url); - // Navigates to single message. - void navigateToMessage(const Message &message); - - // Navigates to messages via "newspaper" view. + // Navigates to messages, used also as "newspaper" view. void navigateToMessages(const QList &messages); // Clears contents. @@ -112,6 +109,8 @@ class WebBrowser : public TabContent { QAction *m_actionReload; QAction *m_actionStop; + bool m_activeNewspaperMode; + static QPointer m_networkManager; static QList m_runningWebBrowsers; }; diff --git a/src/gui/webview.h b/src/gui/webview.h index 8844a20aa..a769b7400 100644 --- a/src/gui/webview.h +++ b/src/gui/webview.h @@ -16,6 +16,7 @@ class WebView : public QWebView { explicit WebView(QWidget *parent = 0); virtual ~WebView(); + // Page accessor. WebPage *page() const; void setupIcons();