introduced theming in the status dialog, removed the syncState again

and moved it to the SyncResult object to simplify code, removed
icon code from folders (WIP), removed some unused code.
This commit is contained in:
Klaas Freitag 2012-02-20 16:45:27 +01:00
parent 34f28bb4ad
commit 4c655684a0
12 changed files with 176 additions and 146 deletions

View file

@ -65,7 +65,7 @@ Application::Application(int argc, char **argv) :
_folderWizard = new FolderWizard();
_owncloudSetupWizard = new OwncloudSetupWizard();
_statusDialog = new StatusDialog();
_statusDialog = new StatusDialog( _theme );
connect( _statusDialog, SIGNAL(removeFolderAlias( const QString&)),
SLOT(slotRemoveFolder(const QString&)));
@ -292,14 +292,14 @@ void Application::slotInfoFolder( const QString& alias )
QString folderMessage = tr( "Last sync was succesful" );
SyncResult::Result syncResult = folderResult.result();
if ( syncResult == SyncResult::Error ) {
SyncResult::Status syncStatus = folderResult.status();
if ( syncStatus == SyncResult::Error ) {
folderMessage = tr( "%1" ).arg( folderResult.errorString() );
} else if ( syncResult == SyncResult::SetupError ) {
} else if ( syncStatus == SyncResult::SetupError ) {
folderMessage = tr( "Setup error" );
} else if ( syncResult == SyncResult::Disabled ) {
} else if ( syncStatus == SyncResult::Disabled ) {
folderMessage = tr( "%1" ).arg( folderResult.errorString() );
} else if ( syncResult == SyncResult::Undefined ) {
} else if ( syncStatus == SyncResult::Undefined ) {
folderMessage = tr( "Undefined state" );
}
@ -352,12 +352,12 @@ void Application::slotConfigure()
void Application::slotSyncStateChange( const QString& alias )
{
Folder::SyncState state = _folderMan->syncState( alias );
SyncResult result = _folderMan->syncResult( alias );
_statusDialog->setFolderList( _folderMan->map() );
if( state == Folder::Waiting ) computeOverallSyncStatus();
computeOverallSyncStatus();
qDebug() << "Sync state changed for folder " << alias << ": " << state;
qDebug() << "Sync state changed for folder " << alias << ": " << result.errorString();
}
void Application::computeOverallSyncStatus()
@ -370,26 +370,26 @@ void Application::computeOverallSyncStatus()
foreach ( Folder *syncedFolder, map ) {
QString folderMessage;
SyncResult folderResult = syncedFolder->lastSyncResult();
SyncResult::Result syncResult = folderResult.result();
if ( syncResult == SyncResult::Success ) {
SyncResult folderResult = syncedFolder->syncResult();
SyncResult::Status syncStatus = folderResult.status();
if ( syncStatus == SyncResult::Success ) {
folderMessage = tr( "Folder %1: Ok." ).arg( syncedFolder->alias() );
} else if ( syncResult == SyncResult::Error ) {
} else if ( syncStatus == SyncResult::Error ) {
overallResult = SyncResult::Error;
folderMessage = tr( "Folder %1: %2" ).arg( syncedFolder->alias(), folderResult.errorString() );
} else if ( syncResult == SyncResult::SetupError ) {
if ( overallResult.result() != SyncResult::Error ) {
} else if ( syncStatus == SyncResult::SetupError ) {
if ( overallResult.status() != SyncResult::Error ) {
overallResult = SyncResult::SetupError;
}
folderMessage = tr( "Folder %1: setup error" ).arg( syncedFolder->alias() );
} else if ( syncResult == SyncResult::Disabled ) {
if ( overallResult.result() != SyncResult::SetupError
&& overallResult.result() != SyncResult::Error ) {
} else if ( syncStatus == SyncResult::Disabled ) {
if ( overallResult.status() != SyncResult::SetupError
&& overallResult.status() != SyncResult::Error ) {
overallResult = SyncResult::Disabled;
}
folderMessage = tr( "Folder %1: %2" ).arg( syncedFolder->alias(), folderResult.errorString() );
} else if ( syncResult == SyncResult::Undefined ) {
if ( overallResult.result() == SyncResult::Success ) {
} else if ( syncStatus == SyncResult::Undefined ) {
if ( overallResult.status() == SyncResult::Success ) {
overallResult = SyncResult::Undefined;
}
folderMessage = tr( "Folder %1: undefined state" ).arg( syncedFolder->alias() );
@ -401,16 +401,16 @@ void Application::computeOverallSyncStatus()
}
QString statusIcon = MIRALL_ICON;
qDebug() << "overall result is " << overallResult.result();
if( overallResult.result() == SyncResult::Error ) {
qDebug() << "overall result is " << overallResult.status();
if( overallResult.status() == SyncResult::Error ) {
statusIcon = "dialog-close";
} else if( overallResult.result() == SyncResult::Success ) {
} else if( overallResult.status() == SyncResult::Success ) {
statusIcon = MIRALL_ICON;
} else if( overallResult.result() == SyncResult::Disabled ) {
} else if( overallResult.status() == SyncResult::Disabled ) {
statusIcon = "dialog-cancel";
} else if( overallResult.result() == SyncResult::SetupError ) {
} else if( overallResult.status() == SyncResult::SetupError ) {
statusIcon = "dialog-cancel";
} else if( overallResult.result() == SyncResult::Undefined ) {
} else if( overallResult.status() == SyncResult::Undefined ) {
statusIcon = "view-refresh";
}

View file

@ -24,7 +24,7 @@
#include "mirall/folder.h"
#include "mirall/folderwatcher.h"
#define DEFAULT_POLL_INTERVAL_SEC 45
#define DEFAULT_POLL_INTERVAL_SEC 15
namespace Mirall {
@ -38,8 +38,7 @@ Folder::Folder(const QString &alias, const QString &path, QObject *parent)
_onlyOnlineEnabled(false),
_onlyThisLANEnabled(false),
_online(false),
_enabled(true),
_syncState( Unknown )
_enabled(true)
{
_openAction = new QAction(QIcon::fromTheme(FOLDER_ICON, QIcon( QString( ":/mirall/resources/%1").arg(FOLDER_ICON))), path, this);
_openAction->setIconVisibleInMenu(true);
@ -64,6 +63,8 @@ Folder::Folder(const QString &alias, const QString &path, QObject *parent)
_online = _networkMgr.isOnline();
QObject::connect(&_networkMgr, SIGNAL(onlineStateChanged(bool)), SLOT(slotOnlineChanged(bool)));
_syncResult = SyncResult( SyncResult::NotYetStarted );
}
QAction * Folder::openAction() const
@ -150,9 +151,9 @@ void Folder::incrementErrorCount()
}
}
SyncResult Folder::lastSyncResult() const
SyncResult Folder::syncResult() const
{
return _lastSyncResult;
return _syncResult;
}
void Folder::evaluateSync(const QStringList &pathList)
@ -198,16 +199,15 @@ void Folder::slotSyncStarted()
{
// disable events until syncing is done
_watcher->setEventsEnabled(false);
_syncState = Running;
_syncResult = SyncResult( SyncResult::SyncRunning );
emit syncStateChange();
_openAction->setIcon(QIcon::fromTheme(FOLDER_SYNC_ICON, QIcon( QString( ":/mirall/resources/%1").arg(FOLDER_SYNC_ICON))));
}
void Folder::slotSyncFinished(const SyncResult &result)
{
_lastSyncResult = result;
_openAction->setIcon(icon(22));
_syncState = Waiting;
_syncResult = result;
emit syncStateChange();
// reenable the poll timer if folder is sync enabled
@ -223,20 +223,6 @@ void Folder::slotSyncFinished(const SyncResult &result)
void Folder::setBackend( const QString& b )
{
_backend = b;
if( _openAction ) {
_openAction->setIcon( icon(22) );
}
}
QIcon Folder::icon( int size ) const
{
QString name;
if( _backend == "sitecopy") name = QString( "mirall-%1.png" ).arg(size);
if( _backend == "unison" ) name = QString( "folder-%1.png" ).arg(size);
if( _backend == "csync" ) name = QString("folder-remote-%1.png").arg(size);
return QIcon( QString( ":/mirall/resources/%1").arg(name) );
}
QString Folder::backend() const

View file

@ -39,8 +39,6 @@ public:
Folder(const QString &alias, const QString &path, QObject *parent = 0L);
virtual ~Folder();
enum SyncState{ Unknown, Running, Waiting };
typedef QHash<QString, Folder*> Map;
/**
@ -116,9 +114,7 @@ public:
/**
* return the last sync result with error message and status
*/
SyncResult lastSyncResult() const;
SyncState syncState() { return _syncState; }
SyncResult syncResult() const;
/**
* set the backend description string.
@ -133,6 +129,7 @@ public:
public slots:
void slotSyncFinished(const SyncResult &);
void slotChanged(const QStringList &pathList = QStringList() );
protected:
/**
@ -175,8 +172,7 @@ private:
QNetworkConfigurationManager _networkMgr;
bool _online;
bool _enabled;
SyncResult _lastSyncResult;
SyncState _syncState;
SyncResult _syncResult;
QString _backend;
protected slots:
@ -187,7 +183,6 @@ protected slots:
/* called when the watcher detect a list of changed
paths */
void slotChanged(const QStringList &pathList);
void slotOpenFolder();

View file

@ -29,9 +29,7 @@
namespace Mirall {
FolderMan::FolderMan(QObject *parent) :
QObject(parent),
_folderSyncCount(0)
QObject(parent)
{
// if QDir::mkpath would not be so stupid, I would not need to have this
// duplication of folderConfigPath() here
@ -61,26 +59,32 @@ int FolderMan::setupFolders()
{
// setup a handler to look for configuration changes
_configFolderWatcher = new FolderWatcher( _folderConfigPath );
_configFolderWatcher->setEventInterval(200);
connect(_configFolderWatcher, SIGNAL(folderChanged(const QStringList &)),
this, SLOT(slotReparseConfiguration()));
this, SLOT( slotReparseConfiguration()) );
return setupKnownFolders();
int cnt = setupKnownFolders();
// do an initial sync
foreach( Folder *f, _folderMap.values() ) {
f->slotChanged();
}
return cnt;
}
QString FolderMan::folderConfigPath() const
void FolderMan::slotReparseConfiguration()
{
return _folderConfigPath;
setupKnownFolders();
}
int FolderMan::setupKnownFolders()
{
qDebug() << "* Setup folders from " << folderConfigPath();
qDebug() << "* Setup folders from " << _folderConfigPath;
_folderMap.clear(); // FIXME: check if delete of folder structure happens
QDir dir(folderConfigPath());
QDir dir( _folderConfigPath );
dir.setFilter(QDir::Files);
QStringList list = dir.entryList();
@ -97,7 +101,7 @@ Folder* FolderMan::setupFolderFromConfigFile(const QString &file) {
Folder *folder = 0L;
qDebug() << " ` -> setting up:" << file;
QSettings settings(folderConfigPath() + "/" + file, QSettings::IniFormat);
QSettings settings( _folderConfigPath + "/" + file, QSettings::IniFormat);
qDebug() << " -> file path: " + settings.fileName();
settings.beginGroup( file ); // read the group with the same name as the file which is the folder alias
@ -208,18 +212,7 @@ SyncResult FolderMan::syncResult( const QString& alias )
SyncResult res;
if( _folderMap.contains( alias ) ) {
Folder *f = _folderMap[alias];
res = f->lastSyncResult();
}
return res;
}
Folder::SyncState FolderMan::syncState( const QString& alias )
{
Folder::SyncState res( Folder::Unknown );
if( _folderMap.contains( alias ) ) {
Folder *f = _folderMap[alias];
res = f->syncState();
res = f->syncResult();
}
return res;
}
@ -230,7 +223,7 @@ void FolderMan::slotFolderSyncStarted( )
void FolderMan::slotFolderSyncFinished( const SyncResult& )
{
_folderSyncCount--;
}
/**
@ -247,7 +240,7 @@ Folder* FolderMan::addFolderDefinition( const QString& backend, const QString& a
bool onlyThisLAN )
{
// Create a settings file named after the alias
QSettings settings(folderConfigPath() + "/" + alias, QSettings::IniFormat);
QSettings settings( _folderConfigPath + "/" + alias, QSettings::IniFormat);
settings.setValue(QString("%1/localPath").arg(alias), sourceFolder );
settings.setValue(QString("%1/targetPath").arg(alias), targetPath );
@ -274,7 +267,7 @@ void FolderMan::slotRemoveFolder( const QString& alias )
qDebug() << "!! Can not remove " << alias << ", not in folderMap.";
}
QFile file( folderConfigPath() + "/" + alias );
QFile file( _folderConfigPath + "/" + alias );
if( file.exists() ) {
qDebug() << "Remove folder config file " << file.fileName();
file.remove();

View file

@ -41,8 +41,6 @@ public:
Mirall::Folder::Map map();
QString folderConfigPath() const;
/**
* Add a folder definition to the config
* Params:
@ -59,11 +57,6 @@ public:
*/
SyncResult syncResult( const QString& );
/**
* returns the current sync state of the folder named by alias
*/
Folder::SyncState syncState( const QString& );
signals:
/**
* signal to indicate a folder named by alias has changed its sync state.
@ -78,6 +71,8 @@ public slots:
void slotFolderSyncStarted();
void slotFolderSyncFinished( const SyncResult& );
void slotReparseConfiguration();
private:
// finds all folder configuration files
// and create the folders
@ -94,10 +89,6 @@ private:
OwncloudSetup *_ownCloudSetup;
QSignalMapper *_folderChangeSignalMapper;
// counter tracking number of folders doing a sync
int _folderSyncCount;
};
}

View file

@ -32,14 +32,14 @@ static const uint32_t standard_event_mask =
/* minimum amount of seconds between two
events to consider it a new event */
#define DEFAULT_EVENT_INTERVAL_SEC 3
#define DEFAULT_EVENT_INTERVAL_MSEC 1000
namespace Mirall {
FolderWatcher::FolderWatcher(const QString &root, QObject *parent)
: QObject(parent),
_eventsEnabled(true),
_eventInterval(DEFAULT_EVENT_INTERVAL_SEC),
_eventInterval(DEFAULT_EVENT_INTERVAL_MSEC),
_root(root),
_processTimer(new QTimer(this)),
_lastMask(0),
@ -241,7 +241,7 @@ void FolderWatcher::setProcessTimer()
if (!_processTimer->isActive()) {
qDebug() << "* Pending events for" << root() << "will be processed after events stop for" << eventInterval() << "seconds (" << QTime::currentTime().addSecs(eventInterval()).toString("HH:mm:ss") << ")." << _pendingPathes.size() << "events until now )";
}
_processTimer->start(eventInterval() * 1000);
_processTimer->start(eventInterval());
}
}

View file

@ -15,9 +15,10 @@
#include <QtCore>
#include <QtGui>
#include "statusdialog.h"
#include "folder.h"
#include "version.h"
#include "mirall/statusdialog.h"
#include "mirall/folder.h"
#include "mirall/version.h"
#include "mirall/theme.h"
namespace Mirall {
FolderViewDelegate::FolderViewDelegate()
@ -109,11 +110,12 @@ void FolderViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
// ====================================================================================
StatusDialog::StatusDialog(QWidget *parent) :
QDialog(parent)
StatusDialog::StatusDialog( Theme *theme, QWidget *parent) :
QDialog(parent),
_theme( theme )
{
setupUi( this );
setWindowTitle( tr("Mirall %1").arg( VERSION_STRING ) );
setWindowTitle( _theme->appName() + QString (" %1" ).arg( VERSION_STRING ) );
_model = new QStandardItemModel();
FolderViewDelegate *delegate = new FolderViewDelegate();
@ -168,42 +170,25 @@ void StatusDialog::setFolderList( Folder::Map folders )
foreach( Folder *f, folders ) {
qDebug() << "Folder: " << f;
QStandardItem *item = new QStandardItem();
QIcon icon = f->icon( 48 );
item->setData( icon, FolderViewDelegate::FolderIconRole );
item->setData( f->path(), FolderViewDelegate::FolderPathRole );
QIcon icon = _theme->folderIcon( f->backend(), 48 );
item->setData( icon, FolderViewDelegate::FolderIconRole );
item->setData( f->path(), FolderViewDelegate::FolderPathRole );
item->setData( f->alias(), FolderViewDelegate::FolderNameRole );
item->setData( f->syncEnabled(), FolderViewDelegate::FolderSyncEnabled );
qDebug() << "Folder is SyncEnabled: " << f->syncEnabled();
QString resultStr = tr("Undefined");
QString statusIcon = "view-refresh";
SyncResult res = f->lastSyncResult();
SyncResult res = f->syncResult();
SyncResult::Status status = res.status();
qDebug() << "Status: " << status;
if( f->syncState() == Folder::Waiting ) {
qDebug() << "Status: " << res.result();
if( res.result() == SyncResult::Error ) {
resultStr = tr("Error");
statusIcon = "dialog-close";
} else if( res.result() == SyncResult::Success ) {
resultStr = tr("Success");
statusIcon = "dialog-ok";
} else if( res.result() == SyncResult::Disabled ) {
resultStr = tr("Disabled");
statusIcon = "dialog-cancel";
} else if( res.result() == SyncResult::SetupError ) {
resultStr = tr( "Setup Error" );
statusIcon = "dialog-cancel";
}
} else if( f->syncState() == Folder::Running ){
statusIcon = "view-refresh";
resultStr = tr("Synchronisation running.");
}
item->setData( QIcon::fromTheme( statusIcon, QIcon( QString( ":/mirall/resources/%1").arg(statusIcon))), FolderViewDelegate::FolderStatusIcon );
item->setData( resultStr, FolderViewDelegate::FolderStatus );
item->setData( res.errorString(), FolderViewDelegate::FolderErrorMsg );
item->setData( _theme->syncStateIcon( status, 64 ), FolderViewDelegate::FolderStatusIcon );
item->setData( _theme->statusHeaderText( status ), FolderViewDelegate::FolderStatus );
item->setData( res.errorString(), FolderViewDelegate::FolderErrorMsg );
_model->appendRow( item );
}
}
void StatusDialog::slotRemoveFolder()

View file

@ -25,6 +25,8 @@
namespace Mirall {
class Theme;
class FolderViewDelegate : public QStyledItemDelegate
{
public:
@ -48,7 +50,7 @@ class StatusDialog : public QDialog, public Ui::statusDialog
{
Q_OBJECT
public:
explicit StatusDialog(QWidget *parent = 0);
explicit StatusDialog( Theme *theme, QWidget *parent = 0);
void setFolderList( Folder::Map );
void setOCUrl( const QUrl& );
@ -70,7 +72,8 @@ public slots:
private:
QStandardItemModel *_model;
QUrl _OCUrl;
QUrl _OCUrl;
Theme *_theme;
};
};

View file

@ -18,18 +18,18 @@ namespace Mirall
{
SyncResult::SyncResult()
: _result( Undefined )
: _status( Undefined )
{
}
SyncResult::SyncResult(SyncResult::Result result)
: _result(result)
SyncResult::SyncResult(SyncResult::Status status )
: _status(status)
{
}
SyncResult::Result SyncResult::result() const
SyncResult::Status SyncResult::status() const
{
return _result;
return _status;
}
void SyncResult::setErrorString( const QString& err )

View file

@ -24,9 +24,11 @@ namespace Mirall
class SyncResult
{
public:
enum Result
enum Status
{
Undefined,
NotYetStarted,
SyncRunning,
Success,
Error,
Disabled,
@ -34,17 +36,17 @@ public:
};
SyncResult();
SyncResult(Result result);
SyncResult( Status status );
~SyncResult();
void setErrorString( const QString& );
void setErrorString( const QString& );
QString errorString() const;
void setSyncChanges( const QHash<QString, QStringList> &changes );
void setSyncChanges( const QHash<QString, QStringList> &changes );
QHash<QString, QStringList> syncChanges() const;
Result result() const;
Status status() const;
private:
Result _result;
Status _status;
QHash<QString, QStringList> _syncChanges;
/**

View file

@ -12,16 +12,76 @@
* for more details.
*/
#include <QString>
#include "theme.h"
#include <QtCore>
#include <QtGui>
namespace Mirall {
Theme::Theme()
:QObject()
{
}
QIcon Theme::folderIcon( const QString& backend, int size ) const
{
QString name;
if( backend == "owncloud") name = QString( "mirall-%1.png" ).arg(size);
if( backend == "unison" ) name = QString( "folder-%1.png" ).arg(size);
if( backend == "csync" ) name = QString( "folder-remote-%1.png" ).arg(size);
return QIcon( QString( ":/mirall/resources/%1").arg(name) );
}
QIcon Theme::syncStateIcon( SyncResult::Status status, int ) const
{
// FIXME: Mind the size!
QString statusIcon;
qDebug() << "Status: " << status;
if( status == SyncResult::NotYetStarted ) {
statusIcon = "dialog-close";
} else if( status == SyncResult::SyncRunning ) {
statusIcon = "view-refresh";
} else if( status == SyncResult::Success ) {
statusIcon = "dialog-ok";
} else if( status == SyncResult::Error ) {
statusIcon = "dialog-close";
} else if( status == SyncResult::Disabled ) {
statusIcon = "dialog-cancel";
} else if( status == SyncResult::SetupError ) {
statusIcon = "dialog-cancel";
} else {
statusIcon = "dialog-close";
}
return QIcon::fromTheme( statusIcon, QIcon( QString( ":/mirall/resources/%1").arg(statusIcon) ) );
}
QString Theme::statusHeaderText( SyncResult::Status status ) const
{
QString resultStr;
if( status == SyncResult::NotYetStarted ) {
resultStr = tr("Not yet started");
} else if( status == SyncResult::SyncRunning ) {
resultStr = tr("Sync running");
} else if( status == SyncResult::Success ) {
resultStr = tr("Success");
} else if( status == SyncResult::Error ) {
resultStr = tr("Error");
} else if( status == SyncResult::Disabled ) {
resultStr = tr("Disabled");
} else if( status == SyncResult::SetupError ) {
resultStr = tr( "Setup Error" );
} else {
resultStr = tr("Undefined");
}
return resultStr;
}
}

View file

@ -15,9 +15,17 @@
#ifndef _THEME_H
#define _THEME_H
#include "mirall/syncresult.h"
class QIcon;
class QString;
class QObject;
namespace Mirall {
class Theme
class SyncResult;
class Theme : public QObject
{
public:
Theme();
@ -26,6 +34,13 @@ public:
virtual QString configFileName() const = 0;
/**
* get a folder icon for a given backend in a given size.
*/
QIcon folderIcon( const QString&, int ) const;
QIcon syncStateIcon( SyncResult::Status, int ) const;
QString statusHeaderText( SyncResult::Status ) const;
private: