Refactor sync result

Sync result computation is now owned by FolderMan
This commit is contained in:
Daniel Molkentin 2013-07-22 12:10:13 +02:00
parent d5ad3a8a70
commit 40c2d891c1
3 changed files with 97 additions and 67 deletions

View file

@ -651,80 +651,25 @@ void Application::computeOverallSyncStatus()
{
// display the info of the least successful sync (eg. not just display the result of the latest sync
SyncResult overallResult(SyncResult::Undefined );
QMap<QString, QString> overallStatusStrings;
QString trayMessage;
Folder::Map map = _folderMan->map();
foreach ( Folder *syncedFolder, map.values() ) {
QString folderMessage;
SyncResult folderResult = syncedFolder->syncResult();
SyncResult::Status syncStatus = folderResult.status();
switch( syncStatus ) {
case SyncResult::Undefined:
if ( overallResult.status() != SyncResult::Error ) {
overallResult.setStatus(SyncResult::Error);
}
folderMessage = tr( "Undefined State." );
break;
case SyncResult::NotYetStarted:
folderMessage = tr( "Waits to start syncing." );
overallResult.setStatus( SyncResult::NotYetStarted );
break;
case SyncResult::SyncPrepare:
folderMessage = tr( "Preparing for sync." );
overallResult.setStatus( SyncResult::SyncPrepare );
break;
case SyncResult::SyncRunning:
folderMessage = tr( "Sync is running." );
overallResult.setStatus( SyncResult::SyncRunning );
break;
case SyncResult::Unavailable:
folderMessage = tr( "Server is currently not available." );
overallResult.setStatus( SyncResult::Unavailable );
break;
case SyncResult::Success:
if( overallResult.status() == SyncResult::Undefined ) {
overallResult.setStatus( SyncResult::Success );
}
folderMessage = tr( "Last Sync was successful." );
break;
case SyncResult::Error:
overallResult.setStatus( SyncResult::Error );
folderMessage = tr( "Syncing Error." );
break;
case SyncResult::SetupError:
if ( overallResult.status() != SyncResult::Error ) {
overallResult.setStatus( SyncResult::SetupError );
}
folderMessage = tr( "Setup Error." );
break;
default:
folderMessage = tr( "Undefined Error State." );
overallResult.setStatus( SyncResult::Error );
}
if( !syncedFolder->syncEnabled() ) {
// sync is disabled.
folderMessage += tr( " (Sync is paused)" );
}
qDebug() << "Folder in overallStatus Message: " << syncedFolder << " with name " << syncedFolder->alias();
QString msg = tr("Folder %1: %2").arg(syncedFolder->alias(), folderMessage);
overallStatusStrings[syncedFolder->alias()] = msg;
}
SyncResult overallResult = FolderMan::accountStatus(map.values());
// create the tray blob message, check if we have an defined state
if( overallResult.status() != SyncResult::Undefined ) {
QStringList allStatusStrings = overallStatusStrings.values();
QStringList allStatusStrings;
foreach(Folder* folder, map.values()) {
qDebug() << "Folder in overallStatus Message: " << folder << " with name " << folder->alias();
QString folderMessage = _folderMan->statusToString(folder->syncResult().status());
allStatusStrings += tr("Folder %1: %2").arg(folder->alias(), folderMessage);
}
if( ! allStatusStrings.isEmpty() )
trayMessage = allStatusStrings.join(QLatin1String("\n"));
else
trayMessage = tr("No sync folders configured.");
QIcon statusIcon = _theme->syncStateIcon( overallResult.status(), true); // size 48 before
QIcon statusIcon = _theme->syncStateIcon( overallResult.status(), true);
_tray->setIcon( statusIcon );
_tray->setToolTip(trayMessage);
}

View file

@ -526,4 +526,84 @@ bool FolderMan::startFromScratch( const QString& localFolder )
return false;
}
SyncResult FolderMan::accountStatus(const QList<Folder*> &folders)
{
SyncResult overallResult(SyncResult::Undefined);
foreach ( Folder *folder, folders ) {
SyncResult folderResult = folder->syncResult();
SyncResult::Status syncStatus = folderResult.status();
switch( syncStatus ) {
case SyncResult::Undefined:
if ( overallResult.status() != SyncResult::Error )
overallResult.setStatus(SyncResult::Error);
break;
case SyncResult::NotYetStarted:
overallResult.setStatus( SyncResult::NotYetStarted );
break;
case SyncResult::SyncPrepare:
overallResult.setStatus( SyncResult::SyncPrepare );
break;
case SyncResult::SyncRunning:
overallResult.setStatus( SyncResult::SyncRunning );
break;
case SyncResult::Unavailable:
overallResult.setStatus( SyncResult::Unavailable );
break;
case SyncResult::Success:
if( overallResult.status() == SyncResult::Undefined )
overallResult.setStatus( SyncResult::Success );
break;
case SyncResult::Error:
overallResult.setStatus( SyncResult::Error );
break;
case SyncResult::SetupError:
if ( overallResult.status() != SyncResult::Error )
overallResult.setStatus( SyncResult::SetupError );
break;
// no default case on purpose, check compiler warnings
}
}
return overallResult;
}
QString FolderMan::statusToString( SyncResult syncStatus ) const
{
QString folderMessage;
switch( syncStatus.status() ) {
case SyncResult::Undefined:
folderMessage = tr( "Undefined State." );
break;
case SyncResult::NotYetStarted:
folderMessage = tr( "Waits to start syncing." );
break;
case SyncResult::SyncPrepare:
folderMessage = tr( "Preparing for sync." );
break;
case SyncResult::SyncRunning:
folderMessage = tr( "Sync is running." );
break;
case SyncResult::Unavailable:
folderMessage = tr( "Server is currently not available." );
break;
case SyncResult::Success:
folderMessage = tr( "Last Sync was successful." );
break;
case SyncResult::Error:
break;
case SyncResult::SetupError:
folderMessage = tr( "Setup Error." );
break;
// no default case on purpose, check compiler warnings
}
// FIXME!
// if( !folder->syncEnabled() ) {
// // sync is disabled.
// folderMessage = tr( "%1 (Sync is paused)" ).arg(folderMessage);
// }
return folderMessage;
}
} // namespace Mirall

View file

@ -18,6 +18,7 @@
#include <QObject>
#include <QQueue>
#include <QList>
#include "mirall/folder.h"
#include "mirall/folderwatcher.h"
@ -25,10 +26,10 @@
class QSignalMapper;
namespace Mirall {
class SyncResult;
namespace Mirall {
class FolderMan : public QObject
{
Q_OBJECT
@ -93,6 +94,10 @@ public:
*/
bool startFromScratch( const QString& );
QString statusToString( SyncResult ) const;
static SyncResult accountStatus( const QList<Folder*> &folders );
signals:
/**
* signal to indicate a folder named by alias has changed its sync state.
@ -150,5 +155,5 @@ private:
bool _syncEnabled;
};
}
} // namespace Mirall
#endif // FOLDERMAN_H