Merge pull request #2064 from owncloud/fix-1959

Show folder icon a offline when account is offline
This commit is contained in:
Daniel Molkentin 2014-08-15 15:11:06 +02:00
commit 3d6b622879
14 changed files with 78 additions and 76 deletions

View file

@ -111,9 +111,13 @@ AccountSettings::AccountSettings(QWidget *parent) :
this, SLOT(slotAccountChanged(Account*,Account*)));
slotAccountChanged(AccountManager::instance()->account(), 0);
connect(FolderMan::instance(), SIGNAL(folderListLoaded(Folder::Map)),
FolderMan *folderMan = FolderMan::instance();
connect(folderMan, SIGNAL(folderSyncStateChange(QString)),
this, SLOT(slotSyncStateChange(QString)));
connect(folderMan, SIGNAL(folderListLoaded(Folder::Map)),
this, SLOT(setFolderList(Folder::Map)));
setFolderList(FolderMan::instance()->map());
slotSyncStateChange();
}
void AccountSettings::slotAccountChanged(Account *newAccount, Account *oldAccount)
@ -122,6 +126,7 @@ void AccountSettings::slotAccountChanged(Account *newAccount, Account *oldAccoun
disconnect(oldAccount, SIGNAL(stateChanged(int)), this, SLOT(slotAccountStateChanged(int)));
disconnect(oldAccount->quotaInfo(), SIGNAL(quotaUpdated(qint64,qint64)),
this, SLOT(slotUpdateQuota(qint64,qint64)));
disconnect(oldAccount, SIGNAL(stateChanged(int)), this, SLOT(slotAccountStateChanged(int)));
}
_account = newAccount;
@ -260,35 +265,39 @@ void AccountSettings::folderToModelItem( QStandardItem *item, Folder *f )
Theme *theme = Theme::instance();
item->setData( theme->statusHeaderText( status ), Qt::ToolTipRole );
if( f->syncEnabled() ) {
if( status == SyncResult::SyncPrepare ) {
if( _wasDisabledBefore ) {
// if the folder was disabled before, set the sync icon
if (_account->state() == Account::Connected) {
if( f->syncEnabled() ) {
if( status == SyncResult::SyncPrepare ) {
if( _wasDisabledBefore ) {
// if the folder was disabled before, set the sync icon
item->setData( theme->syncStateIcon( SyncResult::SyncRunning), FolderStatusDelegate::FolderStatusIconRole );
} // we keep the previous icon for the SyncPrepare state.
} else if( status == SyncResult::Undefined ) {
// startup, the sync was never done.
qDebug() << "XXX FIRST time sync, setting icon to sync running!";
item->setData( theme->syncStateIcon( SyncResult::SyncRunning), FolderStatusDelegate::FolderStatusIconRole );
} // we keep the previous icon for the SyncPrepare state.
} else if( status == SyncResult::Undefined ) {
// startup, the sync was never done.
qDebug() << "XXX FIRST time sync, setting icon to sync running!";
item->setData( theme->syncStateIcon( SyncResult::SyncRunning), FolderStatusDelegate::FolderStatusIconRole );
} else {
// kepp the previous icon for the prepare phase.
if( status == SyncResult::Problem) {
item->setData( theme->syncStateIcon( SyncResult::Success), FolderStatusDelegate::FolderStatusIconRole );
} else {
item->setData( theme->syncStateIcon( status ), FolderStatusDelegate::FolderStatusIconRole );
// kepp the previous icon for the prepare phase.
if( status == SyncResult::Problem) {
item->setData( theme->syncStateIcon( SyncResult::Success), FolderStatusDelegate::FolderStatusIconRole );
} else {
item->setData( theme->syncStateIcon( status ), FolderStatusDelegate::FolderStatusIconRole );
}
}
} else {
item->setData( theme->folderDisabledIcon( ), FolderStatusDelegate::FolderStatusIconRole ); // size 48 before
_wasDisabledBefore = false;
}
} else {
item->setData( theme->folderDisabledIcon( ), FolderStatusDelegate::FolderStatusIconRole ); // size 48 before
_wasDisabledBefore = false;
item->setData( theme->folderOfflineIcon(), FolderStatusDelegate::FolderStatusIconRole);
}
item->setData( theme->statusHeaderText( status ), FolderStatusDelegate::FolderStatus );
if( errorList.isEmpty() ) {
if( (status == SyncResult::Error ||
status == SyncResult::SetupError ||
status == SyncResult::SyncAbortRequested ||
status == SyncResult::Unavailable)) {
status == SyncResult::SyncAbortRequested )) {
errorList << theme->statusHeaderText(status);
}
}
@ -730,6 +739,11 @@ void AccountSettings::slotAccountStateChanged(int state)
QUrl safeUrl(_account->url());
safeUrl.setPassword(QString()); // Remove the password from the URL to avoid showing it in the UI
slotButtonsSetEnabled();
FolderMan *folderMan = FolderMan::instance();
foreach (Folder *folder, folderMan->map().values()) {
slotUpdateFolderState(folder);
}
slotSyncStateChange();
if (state == Account::Connected) {
QString user;
if (AbstractCredentials *cred = _account->credentials()) {
@ -755,6 +769,21 @@ void AccountSettings::slotAccountStateChanged(int state)
}
}
void AccountSettings::slotSyncStateChange(const QString& alias)
{
Q_UNUSED(alias);
FolderMan *folderMan = FolderMan::instance();
SyncResult state = folderMan->accountStatus(folderMan->map().values());
QIcon icon;
if (_account && _account->state() == Account::Connected) {
icon = Theme::instance()->syncStateIcon(state.status());
} else {
icon = Theme::instance()->folderOfflineIcon();
}
emit accountIconChanged(icon);
}
AccountSettings::~AccountSettings()
{
delete ui;

View file

@ -54,6 +54,7 @@ signals:
void openProtocol();
void openFolderAlias( const QString& );
void infoFolderAlias( const QString& );
void accountIconChanged( const QIcon& );
public slots:
void slotFolderActivated( const QModelIndex& );
@ -62,6 +63,7 @@ public slots:
void slotDoubleClicked( const QModelIndex& );
void slotSetProgress(const QString& folder, const Progress::Info& progress);
void slotButtonsSetEnabled();
void slotSyncStateChange(const QString& alias = QString());
void slotUpdateQuota( qint64,qint64 );
void slotIgnoreFilesEditor();

View file

@ -179,7 +179,6 @@ void Application::slotLogout()
FolderMan *folderMan = FolderMan::instance();
folderMan->setSyncEnabled(false);
folderMan->terminateSyncProcess();
folderMan->unloadAllFolders();
a->setState(Account::SignedOut);
// show result
_gui->slotComputeOverallSyncStatus();

View file

@ -287,7 +287,6 @@ void Folder::slotNetworkUnavailable()
if (account && account->state() == Account::Connected) {
account->setState(Account::Disconnected);
}
_syncResult.setStatus(SyncResult::Unavailable);
emit syncStateChange();
}
@ -662,7 +661,8 @@ void Folder::slotSyncFinished()
_syncResult.setErrorStrings( _errors );
qDebug() << " * owncloud csync thread finished with error";
} else if (_csyncUnavail) {
_syncResult.setStatus(SyncResult::Unavailable);
_syncResult.setStatus(SyncResult::Error);
qDebug() << " ** csync not available.";
} else if( _syncResult.warnCount() > 0 ) {
// there have been warnings on the way.
_syncResult.setStatus(SyncResult::Problem);

View file

@ -695,9 +695,6 @@ SyncResult FolderMan::accountStatus(const QList<Folder*> &folders)
case SyncResult::SyncRunning:
overallResult.setStatus( SyncResult::SyncRunning );
break;
case SyncResult::Unavailable:
overallResult.setStatus( SyncResult::Unavailable );
break;
case SyncResult::Problem: // don't show the problem icon in tray.
case SyncResult::Success:
if( overallResult.status() == SyncResult::Undefined )
@ -724,7 +721,6 @@ SyncResult FolderMan::accountStatus(const QList<Folder*> &folders)
int abortSeen = 0;
int runSeen = 0;
int various = 0;
int unavail = 0;
foreach ( Folder *folder, folders ) {
SyncResult folderResult = folder->syncResult();
@ -739,9 +735,6 @@ SyncResult FolderMan::accountStatus(const QList<Folder*> &folders)
case SyncResult::SyncRunning:
runSeen++;
break;
case SyncResult::Unavailable:
unavail++;
break;
case SyncResult::Problem: // don't show the problem icon in tray.
case SyncResult::Success:
goodSeen++;
@ -795,9 +788,6 @@ QString FolderMan::statusToString( SyncResult syncStatus, bool enabled ) const
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;

View file

@ -212,12 +212,12 @@ void ownCloudGui::slotComputeOverallSyncStatus()
{
if (Account *a = AccountManager::instance()->account()) {
if (a->state() == Account::SignedOut) {
_tray->setIcon(Theme::instance()->syncStateIcon( SyncResult::Unavailable, true));
_tray->setIcon(Theme::instance()->folderOfflineIcon(true));
_tray->setToolTip(tr("Please sign in"));
return;
}
if (a->state() == Account::Disconnected) {
_tray->setIcon(Theme::instance()->syncStateIcon( SyncResult::Unavailable, true));
_tray->setIcon(Theme::instance()->folderOfflineIcon(true));
_tray->setToolTip(tr("Disconnected from server"));
return;
}

View file

@ -81,12 +81,6 @@ QIcon ownCloudTheme::trayFolderIcon( const QString& ) const
return QIcon::fromTheme("folder", fallback);
}
QIcon ownCloudTheme::folderDisabledIcon( ) const
{
// Fixme: Do we really want the dialog-canel from theme here?
return themeIcon( QLatin1String("state-pause") );
}
QIcon ownCloudTheme::applicationIcon( ) const
{
return themeIcon( QLatin1String("owncloud-icon") );

View file

@ -31,7 +31,6 @@ public:
QIcon folderIcon( const QString& ) const;
QIcon trayFolderIcon( const QString& ) const Q_DECL_OVERRIDE;
QIcon folderDisabledIcon() const Q_DECL_OVERRIDE;
QIcon applicationIcon() const Q_DECL_OVERRIDE;
QVariant customMedia(CustomMediaType type) Q_DECL_OVERRIDE;

View file

@ -14,7 +14,6 @@
#include "settingsdialog.h"
#include "ui_settingsdialog.h"
#include "mirall/folderman.h"
#include "mirall/theme.h"
#include "mirall/generalsettings.h"
#include "mirall/networksettings.h"
@ -74,11 +73,8 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) :
NetworkSettings *networkSettings = new NetworkSettings;
_ui->stack->addWidget(networkSettings);
FolderMan *folderMan = FolderMan::instance();
connect( folderMan, SIGNAL(folderSyncStateChange(QString)),
this, SLOT(slotSyncStateChange(QString)));
connect( _accountSettings, SIGNAL(folderChanged()), gui, SLOT(slotFoldersChanged()));
connect( _accountSettings, SIGNAL(accountIconChanged(QIcon)), SLOT(slotUpdateAccountIcon(QIcon)));
connect( _accountSettings, SIGNAL(openFolderAlias(const QString&)),
gui, SLOT(slotFolderOpenAction(QString)));
@ -130,22 +126,7 @@ void SettingsDialog::addAccount(const QString &title, QWidget *widget)
_accountItem->setSizeHint(QSize(0, 32));
_ui->labelWidget->addItem(_accountItem);
_ui->stack->addWidget(widget);
slotSyncStateChange();
}
void SettingsDialog::slotSyncStateChange(const QString& alias)
{
FolderMan *folderMan = FolderMan::instance();
SyncResult state = folderMan->accountStatus(folderMan->map().values());
_accountItem->setIcon(Theme::instance()->syncStateIcon(state.status()));
if (!alias.isEmpty()) {
Folder *folder = folderMan->folder(alias);
if( folder ) {
_accountSettings->slotUpdateFolderState(folder);
}
}
_accountSettings->slotSyncStateChange();
}
void SettingsDialog::setGeneralErrors(const QStringList &errors)
@ -168,6 +149,11 @@ void SettingsDialog::accept() {
QDialog::accept();
}
void SettingsDialog::slotUpdateAccountIcon(const QIcon &icon)
{
_accountItem->setIcon(icon);
}
void SettingsDialog::showActivityPage()
{
_ui->labelWidget->setCurrentRow(_protocolIdx);

View file

@ -45,13 +45,15 @@ public:
void setGeneralErrors( const QStringList& errors );
public slots:
void slotSyncStateChange(const QString& alias = QString());
void showActivityPage();
protected:
void reject() Q_DECL_OVERRIDE;
void accept() Q_DECL_OVERRIDE;
private slots:
void slotUpdateAccountIcon(const QIcon& icon);
private:
Ui::SettingsDialog *_ui;
AccountSettings *_accountSettings;

View file

@ -64,9 +64,6 @@ QString SyncResult::statusString() const
case Problem:
re = QLatin1String("Success, some files were ignored.");
break;
case Unavailable:
re = QLatin1String("Not availabe");
break;
case SyncAbortRequested:
re = QLatin1String("Sync Request aborted by user");
break;

View file

@ -39,8 +39,7 @@ public:
Problem,
Error,
SetupError,
Paused,
Unavailable
Paused
};
SyncResult();

View file

@ -68,9 +68,6 @@ QString Theme::statusHeaderText( SyncResult::Status status ) const
case SyncResult::SetupError:
resultStr = QCoreApplication::translate("theme", "Setup Error" );
break;
case SyncResult::Unavailable:
resultStr = QCoreApplication::translate("theme", "The server is currently unavailable" );
break;
case SyncResult::SyncPrepare:
resultStr = QCoreApplication::translate("theme", "Preparing to sync" );
break;
@ -268,9 +265,6 @@ QIcon Theme::syncStateIcon( SyncResult::Status status, bool sysTray ) const
switch( status ) {
case SyncResult::Undefined:
case SyncResult::NotYetStarted:
case SyncResult::Unavailable:
statusIcon = QLatin1String("state-offline");
break;
case SyncResult::SyncRunning:
statusIcon = QLatin1String("state-sync");
break;
@ -287,7 +281,7 @@ QIcon Theme::syncStateIcon( SyncResult::Status status, bool sysTray ) const
break;
case SyncResult::Error:
case SyncResult::SetupError:
statusIcon = QLatin1String("state-error"); // FIXME: Use state-problem once we have an icon.
// FIXME: Use state-problem once we have an icon.
default:
statusIcon = QLatin1String("state-error");
}
@ -295,6 +289,16 @@ QIcon Theme::syncStateIcon( SyncResult::Status status, bool sysTray ) const
return themeIcon( statusIcon, sysTray );
}
QIcon Theme::folderDisabledIcon( ) const
{
return themeIcon( QLatin1String("state-pause") );
}
QIcon Theme::folderOfflineIcon(bool systray) const
{
return themeIcon( QLatin1String("state-offline"), systray );
}
QColor Theme::wizardHeaderTitleColor() const
{
return qApp->palette().text().color();

View file

@ -90,7 +90,8 @@ public:
*/
virtual QIcon syncStateIcon( SyncResult::Status, bool sysTray = false ) const;
virtual QIcon folderDisabledIcon() const = 0;
virtual QIcon folderDisabledIcon() const;
virtual QIcon folderOfflineIcon(bool systray = false) const;
virtual QIcon applicationIcon() const = 0;
#endif