[kde-doc-english] [trojita] src/Gui: GUI: MessageView: show an indicator whenever the message parts are being loaded

Jan Kundrát jkt at flaska.net
Wed Aug 14 17:28:49 UTC 2013


Git commit 696b993b76598ac2a5053c44c5825a7256d54e86 by Jan Kundrát.
Committed on 14/08/2013 at 16:17.
Pushed by jkt into branch 'master'.

GUI: MessageView: show an indicator whenever the message parts are being loaded

It looks that QWebView does not have support for showing any placeholder
whenever it is loading data from network; instead, a simple empty widget is
shown. This is suboptimal because the user doesn't know that the mail is
currently loading unless they pay close attention to the global
application-level progress indicator in the status bar.

This patch propagates loadingStarted/loadingFinished signals of the enclosed
SimplePartWidget instances to the MessageView which simply shows/hides another
progress indicator.

Another idea was to implement this on the QNAM level, but it turned out that the
same MsgPartNetAccessManager is used also for attachment download which is not
what we are interested in.

REVIEW: 112092

M  +29   -4    src/Gui/MessageView.cpp
M  +4    -0    src/Gui/MessageView.h
M  +4    -0    src/Gui/SimplePartWidget.cpp

http://commits.kde.org/trojita/696b993b76598ac2a5053c44c5825a7256d54e86

diff --git a/src/Gui/MessageView.cpp b/src/Gui/MessageView.cpp
index 4cdcec3..fbe4d63 100644
--- a/src/Gui/MessageView.cpp
+++ b/src/Gui/MessageView.cpp
@@ -25,6 +25,7 @@
 #include <QKeyEvent>
 #include <QMenu>
 #include <QMessageBox>
+#include <QProgressBar>
 #include <QTimer>
 #include <QUrl>
 #include <QVBoxLayout>
@@ -35,17 +36,17 @@
 
 #include "MessageView.h"
 #include "AbstractPartWidget.h"
-#include "Composer/SubjectMangling.h"
+#include "ComposeWidget.h"
 #include "EmbeddedWebView.h"
 #include "EnvelopeView.h"
 #include "ExternalElementsWidget.h"
+#include "OverlayWidget.h"
 #include "PartWidgetFactory.h"
 #include "SimplePartWidget.h"
 #include "TagListWidget.h"
 #include "UserAgentWebPage.h"
 #include "Window.h"
-#include "ComposeWidget.h"
-
+#include "Composer/SubjectMangling.h"
 #include "Imap/Model/MailboxTree.h"
 #include "Imap/Model/MsgListModel.h"
 #include "Imap/Network/MsgPartNetAccessManager.h"
@@ -53,7 +54,7 @@
 namespace Gui
 {
 
-MessageView::MessageView(QWidget *parent): QWidget(parent)
+MessageView::MessageView(QWidget *parent): QWidget(parent), m_loadingItemCount(0)
 {
     QPalette pal = palette();
     pal.setColor(backgroundRole(), palette().color(QPalette::Active, QPalette::Base));
@@ -140,6 +141,13 @@ MessageView::MessageView(QWidget *parent): QWidget(parent)
     markAsReadTimer = new QTimer(this);
     markAsReadTimer->setSingleShot(true);
     connect(markAsReadTimer, SIGNAL(timeout()), this, SLOT(markAsRead()));
+
+    QProgressBar *progress = new QProgressBar();
+    progress->setRange(0, 0);
+    progress->setEnabled(false);
+    OverlayWidget *overlay = new OverlayWidget(progress, this);
+    m_progress = overlay;
+    m_progress->hide();
 }
 
 MessageView::~MessageView()
@@ -171,6 +179,8 @@ void MessageView::setEmpty()
         viewer->show();
         layout->addWidget(viewer);
         emit messageChanged();
+        m_loadingItemCount = 0;
+        m_progress->hide();
     }
 }
 
@@ -214,6 +224,9 @@ void MessageView::setMessage(const QModelIndex &index)
 
         netAccess->setModelMessage(message);
 
+        m_loadingItemCount = 0;
+        m_progress->hide();
+
         viewer = factory->create(rootPartIndex);
         viewer->setParent(this);
         layout->addWidget(viewer);
@@ -484,4 +497,16 @@ QModelIndex MessageView::currentMessage() const
     return message;
 }
 
+void MessageView::onWebViewLoadStarted()
+{
+    ++m_loadingItemCount;
+    m_progress->show();
+}
+
+void MessageView::onWebViewLoadFinished()
+{
+    if (--m_loadingItemCount == 0)
+        m_progress->hide();
+}
+
 }
diff --git a/src/Gui/MessageView.h b/src/Gui/MessageView.h
index b94f52d..0ff522a 100644
--- a/src/Gui/MessageView.h
+++ b/src/Gui/MessageView.h
@@ -86,6 +86,8 @@ private slots:
     void partContextMenuRequested(const QPoint &point);
     void partLinkHovered(const QString &link, const QString &title, const QString &textContent);
     void triggerSearchDialog();
+    void onWebViewLoadStarted();
+    void onWebViewLoadFinished();
 signals:
     void messageChanged();
     void linkHovered(const QString &url);
@@ -108,6 +110,8 @@ private:
     QTimer *markAsReadTimer;
     QWebView *emptyView;
     PartWidgetFactory *factory;
+    QWidget *m_progress;
+    int m_loadingItemCount;
 
     MessageView(const MessageView &); // don't implement
     MessageView &operator=(const MessageView &); // don't implement
diff --git a/src/Gui/SimplePartWidget.cpp b/src/Gui/SimplePartWidget.cpp
index a7bad17..1dfc1fd 100644
--- a/src/Gui/SimplePartWidget.cpp
+++ b/src/Gui/SimplePartWidget.cpp
@@ -46,6 +46,10 @@ SimplePartWidget::SimplePartWidget(QWidget *parent, Imap::Network::MsgPartNetAcc
     flowedFormat(Composer::Util::FORMAT_PLAIN)
 {
     Q_ASSERT(partIndex.isValid());
+
+    connect(this, SIGNAL(loadStarted()), m_messageView, SLOT(onWebViewLoadStarted()));
+    connect(this, SIGNAL(loadFinished(bool)), m_messageView, SLOT(onWebViewLoadFinished()));
+
     QUrl url;
     url.setScheme(QLatin1String("trojita-imap"));
     url.setHost(QLatin1String("msg"));


More information about the kde-doc-english mailing list