Commit f0d85b14 authored by David Faure's avatar David Faure
Browse files

Rework "offline page" logic.

Pre-akonadi logic was to check for imap resource and check its offline status,
when clicking on a mail.
New logic is rather: always try to fetch mail (it could be cached, after all),
and only on error, check if resource (of any type) is offline, and then show error page.

The main bonus of this patch is that it removes the "early return" in case
of offline mode, which led to a much slower folder-switching in the messagelist.

Concept by Volker, patch review by Dan.
parent 8353a3a0
......@@ -227,7 +227,6 @@ K_GLOBAL_STATIC( KMMainWidget::PtrList, theMainWidgetList )
mFolderViewSplitter( 0 ),
mArchiveFolderAction( 0 ),
mShowBusySplashTimer( 0 ),
mShowingOfflineScreen( false ),
mMsgActions( 0 ),
mCurrentFolder( 0 ),
mVacationIndicatorActive( false ),
......@@ -495,27 +494,7 @@ void KMMainWidget::folderSelected( const Akonadi::Collection & col )
if (mMsgView)
mMsgView->clear(true);
const bool newFolder = mCurrentFolder && ( mCurrentFolder->collection() != col );
// Re-enable the msg list and quicksearch if we're showing a splash
// screen. This is true either if there's no active folder, or if we
// have a timer that is no longer active (i.e. it has already fired)
// To make the if () a bit more complicated, we suppress the hiding
// when the new folder is also an IMAP folder, because that's an
// async operation and we don't want flicker if it results in just
// a new splash.
bool isImapResourceOnline = false;
bool folderIsAnImap = KMKernel::self()->isImapFolder( col, isImapResourceOnline );
const bool isNewImapFolder = col.isValid() && folderIsAnImap && newFolder;
if ( ( !mCurrentFolder )
|| ( !isNewImapFolder && mShowBusySplashTimer )
|| ( newFolder && mShowingOfflineScreen && !( isNewImapFolder && !isImapResourceOnline ) ) ) {
if ( mMsgView ) {
mMsgView->viewer()->enableMessageDisplay();
mMsgView->clear( true );
}
if ( mMessagePane )
mMessagePane->show();
mShowingOfflineScreen = false;
}
// Delete any pending timer, if needed it will be recreated below
delete mShowBusySplashTimer;
mShowBusySplashTimer = 0;
......@@ -527,20 +506,6 @@ void KMMainWidget::folderSelected( const Akonadi::Collection & col )
mCurrentFolder = FolderCollection::forCollection( col );
if ( col.isValid() && folderIsAnImap ) {
if ( !isImapResourceOnline )
{
//mMessageListView->setCurrentFolder( 0 ); <-- useless in the new view: just do nothing
// FIXME: Use an "offline tab" ?
if (kmkernel->isOffline())
showOfflinePage();
else
showResourceOfflinePage();
updateFolderMenu();
return;
}
}
readFolderConfig();
if (mMsgView)
{
......@@ -2527,7 +2492,6 @@ void KMMainWidget::slotShowBusySplash()
void KMMainWidget::showOfflinePage()
{
if ( !mReaderWindowActive ) return;
mShowingOfflineScreen = true;
mMsgView->displayOfflinePage();
}
......@@ -2535,7 +2499,6 @@ void KMMainWidget::showOfflinePage()
void KMMainWidget::showResourceOfflinePage()
{
if ( !mReaderWindowActive ) return;
mShowingOfflineScreen = true;
mMsgView->displayResourceOfflinePage();
}
......@@ -2746,11 +2709,15 @@ void KMMainWidget::slotMessageActivated( const Akonadi::Item &msg )
return;
}
kDebug();
// Try to fetch the mail, even in offline mode, it might be cached
#if 0
bool isImapResourceOnline = false;
bool folderIsAnImap = KMKernel::self()->isImapFolder( mCurrentFolder->collection(), isImapResourceOnline );
if (folderIsAnImap && !isImapResourceOnline) {
return;
}
#endif
ItemFetchJob *itemFetchJob = MessageViewer::Viewer::createFetchJob( msg );
connect( itemFetchJob, SIGNAL(itemsReceived(Akonadi::Item::List)),
SLOT(slotItemsFetchedForActivation(Akonadi::Item::List)) );
......@@ -4510,6 +4477,7 @@ void KMMainWidget::slotMessageSelected(const Akonadi::Item &item)
mShowBusySplashTimer->start( GlobalSettings::self()->folderLoadingTimeout() ); //TODO: check if we need a different timeout setting for this
Akonadi::ItemFetchJob *itemFetchJob = MessageViewer::Viewer::createFetchJob( item );
itemFetchJob->setProperty( "_item", QVariant::fromValue(item) );
connect( itemFetchJob, SIGNAL(itemsReceived(Akonadi::Item::List)),
SLOT(itemsReceived(Akonadi::Item::List)) );
connect( itemFetchJob, SIGNAL(result(KJob*)), SLOT(itemsFetchDone(KJob*)) );
......@@ -4558,7 +4526,26 @@ void KMMainWidget::itemsFetchDone( KJob *job )
delete mShowBusySplashTimer;
mShowBusySplashTimer = 0;
if ( job->error() ) {
kDebug() << job->errorString();
// Unfortunately job->error() is Job::Unknown in many cases.
// (see JobPrivate::handleResponse in akonadi/job.cpp)
// So we show the "offline" page after checking the resource status.
kDebug() << job->error() << job->errorString();
Akonadi::Item item = job->property("_item").value<Akonadi::Item>();
const Akonadi::AgentInstance agentInstance = Akonadi::AgentManager::self()->instance( item.parentCollection().resource() );
if ( !agentInstance.isOnline() ) {
// The resource is offline
if ( mMsgView ) {
mMsgView->viewer()->enableMessageDisplay();
mMsgView->clear( true );
}
mMessagePane->show();
if (kmkernel->isOffline())
showOfflinePage();
else
showResourceOfflinePage();
}
}
}
......
......@@ -596,7 +596,7 @@ private:
KActionCollection *mActionCollection;
QAction *mToolbarActionSeparator;
QVBoxLayout *mTopLayout;
bool mDestructed, mShowingOfflineScreen;
bool mDestructed;
QList<QAction*> mFilterMenuActions;
QList<QAction*> mFilterTBarActions;
QList<KMMetaFilterActionCommand*> mFilterCommands;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment