mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-22 21:15:55 +03:00
Merge pull request #3891 from nextcloud/bugfix/update-sync-state-no-folders
Also update sync state summary based on connectivity
This commit is contained in:
commit
c2dd75df12
2 changed files with 62 additions and 27 deletions
|
@ -13,6 +13,7 @@
|
|||
*/
|
||||
|
||||
#include "syncstatussummary.h"
|
||||
#include "accountfwd.h"
|
||||
#include "folderman.h"
|
||||
#include "navigationpanehelper.h"
|
||||
#include "networkjobs.h"
|
||||
|
@ -51,41 +52,24 @@ SyncStatusSummary::SyncStatusSummary(QObject *parent)
|
|||
connect(folderMan, &FolderMan::folderSyncStateChange, this, &SyncStatusSummary::onFolderSyncStateChanged);
|
||||
}
|
||||
|
||||
bool SyncStatusSummary::reloadNeeded(AccountState *accountState) const
|
||||
{
|
||||
if (_accountState.data() == accountState) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void SyncStatusSummary::load()
|
||||
{
|
||||
const auto currentUser = UserModel::instance()->currentUser();
|
||||
if (!currentUser) {
|
||||
return;
|
||||
}
|
||||
auto accountState = currentUser->accountState();
|
||||
|
||||
if (_accountState.data() == accountState.data()) {
|
||||
return;
|
||||
}
|
||||
|
||||
_accountState = accountState;
|
||||
setAccountState(currentUser->accountState());
|
||||
clearFolderErrors();
|
||||
connectToFoldersProgress(FolderMan::instance()->map());
|
||||
auto syncStateFallbackNeeded = true;
|
||||
for (const auto &folder : FolderMan::instance()->map()) {
|
||||
if (_accountState.data() != folder->accountState()) {
|
||||
continue;
|
||||
}
|
||||
onFolderSyncStateChanged(folder);
|
||||
syncStateFallbackNeeded = false;
|
||||
}
|
||||
|
||||
if (syncStateFallbackNeeded) {
|
||||
setSyncing(false);
|
||||
setSyncStatusDetailString("");
|
||||
if (_accountState && !_accountState->isConnected()) {
|
||||
setSyncStatusString(tr("Offline"));
|
||||
setSyncIcon(Theme::instance()->folderOffline());
|
||||
} else {
|
||||
setSyncStatusString(tr("All synced!"));
|
||||
setSyncIcon(Theme::instance()->syncStatusOk());
|
||||
}
|
||||
}
|
||||
initSyncState();
|
||||
}
|
||||
|
||||
double SyncStatusSummary::syncProgress() const
|
||||
|
@ -315,4 +299,48 @@ void SyncStatusSummary::connectToFoldersProgress(const Folder::Map &folderMap)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SyncStatusSummary::onIsConnectedChanged()
|
||||
{
|
||||
setSyncStateToConnectedState();
|
||||
}
|
||||
|
||||
void SyncStatusSummary::setSyncStateToConnectedState()
|
||||
{
|
||||
setSyncing(false);
|
||||
setSyncStatusDetailString("");
|
||||
if (_accountState && !_accountState->isConnected()) {
|
||||
setSyncStatusString(tr("Offline"));
|
||||
setSyncIcon(Theme::instance()->folderOffline());
|
||||
} else {
|
||||
setSyncStatusString(tr("All synced!"));
|
||||
setSyncIcon(Theme::instance()->syncStatusOk());
|
||||
}
|
||||
}
|
||||
|
||||
void SyncStatusSummary::setAccountState(AccountStatePtr accountState)
|
||||
{
|
||||
if (!reloadNeeded(accountState.data())) {
|
||||
return;
|
||||
}
|
||||
if (_accountState) {
|
||||
disconnect(
|
||||
_accountState.data(), &AccountState::isConnectedChanged, this, &SyncStatusSummary::onIsConnectedChanged);
|
||||
}
|
||||
_accountState = accountState;
|
||||
connect(_accountState.data(), &AccountState::isConnectedChanged, this, &SyncStatusSummary::onIsConnectedChanged);
|
||||
}
|
||||
|
||||
void SyncStatusSummary::initSyncState()
|
||||
{
|
||||
auto syncStateFallbackNeeded = true;
|
||||
for (const auto &folder : FolderMan::instance()->map()) {
|
||||
onFolderSyncStateChanged(folder);
|
||||
syncStateFallbackNeeded = false;
|
||||
}
|
||||
|
||||
if (syncStateFallbackNeeded) {
|
||||
setSyncStateToConnectedState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "account.h"
|
||||
#include "accountfwd.h"
|
||||
#include "accountstate.h"
|
||||
#include "folderman.h"
|
||||
|
||||
|
@ -59,6 +61,7 @@ private:
|
|||
void onFolderListChanged(const OCC::Folder::Map &folderMap);
|
||||
void onFolderProgressInfo(const ProgressInfo &progress);
|
||||
void onFolderSyncStateChanged(const Folder *folder);
|
||||
void onIsConnectedChanged();
|
||||
|
||||
void setSyncStateForFolder(const Folder *folder);
|
||||
void markFolderAsError(const Folder *folder);
|
||||
|
@ -66,12 +69,16 @@ private:
|
|||
bool folderErrors() const;
|
||||
bool folderError(const Folder *folder) const;
|
||||
void clearFolderErrors();
|
||||
void setSyncStateToConnectedState();
|
||||
bool reloadNeeded(AccountState *accountState) const;
|
||||
void initSyncState();
|
||||
|
||||
void setSyncProgress(double value);
|
||||
void setSyncing(bool value);
|
||||
void setSyncStatusString(const QString &value);
|
||||
void setSyncStatusDetailString(const QString &value);
|
||||
void setSyncIcon(const QUrl &value);
|
||||
void setAccountState(AccountStatePtr accountState);
|
||||
|
||||
AccountStatePtr _accountState;
|
||||
std::set<QString> _foldersWithErrors;
|
||||
|
|
Loading…
Reference in a new issue