[trojita] src/Imap/Model: GUI: Gray out systray icon when not actually connected
Jan Kundrát
jkt at kde.org
Mon Oct 24 13:11:55 UTC 2016
Git commit 738e6cc1592b8cd0d64fd869e48aeba9f4a7242d by Jan Kundrát.
Committed on 17/10/2016 at 21:15.
Pushed by gerrit into branch 'master'.
GUI: Gray out systray icon when not actually connected
The connection state tracking is tricky, there's a window where the
IMAP Model's networkPolicy() reports the intended policy, but where the
actual network connection has not succeeded yet. This can happen for
example when the system as a whole believes that we /might/ still be
online, but where the network connection is already dead and Trojita
happens to be reconnecting or waiting for a timeout.
This change ensures that the systray icon only reports success where the
connection is alive and OK.
This patch might be a bit too intrusive because the NetworkWatcher's
status is also used in part loading to control whether it makes sense to
ask for certain parts. However, because we always invalidate indexes at
reconnect time anyway, this is a safe thing (as in "won't introduce
visual regressions) because if we ever reconnect, the part widgets will
loose their state anyway.
Change-Id: I2e90f237ceff5fe2e1635f41456eaf793041535e
M +6 -1 src/Imap/Model/NetworkWatcher.cpp
http://commits.kde.org/trojita/738e6cc1592b8cd0d64fd869e48aeba9f4a7242d
diff --git a/src/Imap/Model/NetworkWatcher.cpp b/src/Imap/Model/NetworkWatcher.cpp
index cd3a049..fca5922 100644
--- a/src/Imap/Model/NetworkWatcher.cpp
+++ b/src/Imap/Model/NetworkWatcher.cpp
@@ -45,7 +45,12 @@ NetworkWatcher::NetworkWatcher(ImapAccess *parent, Model *model):
NetworkPolicy NetworkWatcher::effectiveNetworkPolicy() const
{
- return m_model->networkPolicy();
+ // Do we have any connection which is really alive?
+ auto parser = std::find_if(m_model->m_parsers.cbegin(), m_model->m_parsers.cend(),
+ [](const Imap::Mailbox::ParserState & state) {
+ return state.connState != CONN_STATE_LOGOUT && state.connState >= CONN_STATE_AUTHENTICATED;
+ });
+ return parser == m_model->m_parsers.cend() ? NETWORK_OFFLINE : m_model->networkPolicy();
}
/** @short Start the reconnect attempt cycle */
More information about the kde-doc-english
mailing list