Commit 44bfeed3 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

Provide UI feedback when waiting for opened message to be retrieved

When user double-clicks a message, the Viewer will not appear until
the ItemFetchJob retrieves the message. This can however take some
time when the Session is blocked and during that time user does not
have any feedback on what is happening.

This patch makes use of the busy dialog provided by KMCommands, so
that users can at least see that something is going on.

REVIEW: 121091
parent 06187139
......@@ -272,6 +272,11 @@ void KMCommand::slotPostTransfer( KMCommand::Result result )
deleteLater();
}
Akonadi::ItemFetchJob *KMCommand::createFetchJob( const Akonadi::Item::List &items )
{
return new Akonadi::ItemFetchJob( items, this );
}
void KMCommand::transferSelectedMsgs()
{
// make sure no other transfer is active
......@@ -303,7 +308,7 @@ void KMCommand::transferSelectedMsgs()
if ( !mFetchScope.isEmpty() ) {
complete = false;
++KMCommand::mCountJobs;
Akonadi::ItemFetchJob *fetch = new Akonadi::ItemFetchJob( mMsgList, this );
Akonadi::ItemFetchJob *fetch = createFetchJob( mMsgList );
mFetchScope.fetchAttribute< MessageCore::MDNStateAttribute >();
fetch->setFetchScope( mFetchScope );
connect( fetch, SIGNAL(itemsReceived(Akonadi::Item::List)), SLOT(slotMsgTransfered(Akonadi::Item::List)) );
......@@ -1614,3 +1619,33 @@ KMCommand::Result KMShareImageCommand::execute()
return OK;
}
KMFetchMessageCommand::KMFetchMessageCommand( QWidget *parent, const Akonadi::Item &item )
: KMCommand( parent, item )
{
// Workaround KMCommand::transferSelectedMsgs() expecting non-empty fetchscope
fetchScope().fetchFullPayload(true);
}
Akonadi::ItemFetchJob *KMFetchMessageCommand::createFetchJob( const Akonadi::Item::List &items )
{
Q_ASSERT( items.size() == 1 );
Akonadi::ItemFetchJob *fetch = MessageViewer::Viewer::createFetchJob( items.first() );
fetchScope() = fetch->fetchScope();
return fetch;
}
KMCommand::Result KMFetchMessageCommand::execute()
{
Akonadi::Item item = retrievedMessage();
if ( !item.isValid() || !item.hasPayload<KMime::Message::Ptr>() ) {
return Failed;
}
mItem = item;
return OK;
}
Akonadi::Item KMFetchMessageCommand::item() const
{
return mItem;
}
......@@ -80,6 +80,8 @@ signals:
void completed( KMCommand *command );
protected:
virtual Akonadi::ItemFetchJob* createFetchJob( const Akonadi::Item::List &items );
/** Allows to configure how much data should be retrieved of the messages. */
Akonadi::ItemFetchScope& fetchScope() { return mFetchScope; }
......@@ -585,5 +587,20 @@ private:
KUrl mUrl;
};
class KMAIL_EXPORT KMFetchMessageCommand : public KMCommand
{
Q_OBJECT
public:
explicit KMFetchMessageCommand( QWidget *parent, const Akonadi::Item &item );
Akonadi::Item item() const;
private:
Akonadi::ItemFetchJob *createFetchJob( const Akonadi::Item::List &items );
Result execute();
Akonadi::Item mItem;
};
#endif /*KMCommands_h*/
......@@ -2680,18 +2680,22 @@ void KMMainWidget::slotMessageActivated( const Akonadi::Item &msg )
}
// Try to fetch the mail, even in offline mode, it might be cached
ItemFetchJob *itemFetchJob = MessageViewer::Viewer::createFetchJob( msg );
connect( itemFetchJob, SIGNAL(itemsReceived(Akonadi::Item::List)),
SLOT(slotItemsFetchedForActivation(Akonadi::Item::List)) );
connect( itemFetchJob, SIGNAL(result(KJob*)),
SLOT(itemsFetchForActivationDone(KJob*)) );
KMFetchMessageCommand *cmd = new KMFetchMessageCommand(this, msg);
connect(cmd, SIGNAL(completed(KMCommand*)),
this, SLOT(slotItemsFetchedForActivation(KMCommand*)));
cmd->start();
}
void KMMainWidget::slotItemsFetchedForActivation( const Akonadi::Item::List &list )
void KMMainWidget::slotItemsFetchedForActivation( KMCommand *command )
{
Q_ASSERT( list.size() == 1 );
KMCommand::Result result = command->result();
if (result != KMCommand::OK) {
kDebug() << "Result:" << result;
return;
}
const Item msg = list.first();
KMFetchMessageCommand *fetchCmd = qobject_cast<KMFetchMessageCommand*>(command);
const Item msg = fetchCmd->item();
KMReaderMainWin *win = new KMReaderMainWin( mFolderDisplayFormatPreference, mFolderHtmlLoadExtPreference );
const bool useFixedFont = mMsgView ? mMsgView->isFixedFont() :
......@@ -2704,14 +2708,6 @@ void KMMainWidget::slotItemsFetchedForActivation( const Akonadi::Item::List &lis
win->show();
}
void KMMainWidget::itemsFetchForActivationDone( KJob * job )
{
if ( job->error() ) {
kDebug() << job->error() << job->errorString();
BroadcastStatus::instance()->setStatusMsg( job->errorString() );
}
}
void KMMainWidget::slotMessageStatusChangeRequest( const Akonadi::Item &item, const Akonadi::MessageStatus & set, const Akonadi::MessageStatus &clear )
{
if ( !item.isValid() )
......
......@@ -203,7 +203,7 @@ public slots:
*/
void slotMessageSelected( const Akonadi::Item & );
void slotItemsFetchedForActivation( const Akonadi::Item::List &list );
void slotItemsFetchedForActivation( KMCommand* command );
void slotMessageStatusChangeRequest( const Akonadi::Item &, const Akonadi::MessageStatus &, const Akonadi::MessageStatus & );
......@@ -525,7 +525,6 @@ private slots:
void itemsReceived(const Akonadi::Item::List &list );
void itemsFetchDone( KJob *job );
void itemsFetchForActivationDone( KJob *job );
void slotCollectionPropertiesContinued( KJob* job );
void slotCollectionPropertiesFinished( KJob *job );
......
Markdown is supported
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