bool Folder::canSync() const { return !syncPaused() && accountState()->isConnected(); }
QVariant FolderStatusModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); if (role == Qt::EditRole) return QVariant(); switch(classify(index)) { case AddButton: { if (role == FolderStatusDelegate::AddButton) { return QVariant(true); } else if (role == Qt::ToolTipRole) { if (!_accountState->isConnected()) { return tr("You need to be connected to add a folder"); } if (_folders.count() == 1) { auto remotePath = _folders.at(0)._folder->remotePath(); if (remotePath.isEmpty() || remotePath == QLatin1String("/")) { // Syncing the entire owncloud: disable the add folder button (#3438) return tr("Adding folder is disabled because you are already syncing all your files. " "If you want to sync multiple folders, please remove the currently " "configured root folder."); } } return tr("Click this button to add a folder to synchronize."); } return QVariant(); } case SubFolder: { const auto &x = static_cast<SubFolderInfo *>(index.internalPointer())->_subs[index.row()]; switch (role) { case Qt::ToolTipRole: case Qt::DisplayRole: return tr("%1 (%2)").arg(x._name, Utility::octetsToString(x._size)); case Qt::CheckStateRole: return x._checked; case Qt::DecorationRole: return QFileIconProvider().icon(QFileIconProvider::Folder); case Qt::ForegroundRole: if (x._isUndecided) { return QColor(Qt::red); } break; } } return QVariant(); case FetchLabel: { const auto x = static_cast<SubFolderInfo *>(index.internalPointer()); switch(role) { case Qt::DisplayRole: if (x->_hasError) { return tr("Error while loading the list of folders from the server."); } else { return tr("Fetching folder list from server..."); } break; default: return QVariant(); } } case RootFolder: break; } const SubFolderInfo & folderInfo = _folders.at(index.row()); auto f = folderInfo._folder; if (!f) return QVariant(); const SubFolderInfo::Progress & progress = folderInfo._progress; const bool accountConnected = _accountState->isConnected(); switch (role) { case FolderStatusDelegate::FolderPathRole : return f->shortGuiPath(); case FolderStatusDelegate::FolderSecondPathRole : return f->remotePath(); case FolderStatusDelegate::HeaderRole : return f->aliasGui(); case FolderStatusDelegate::FolderAliasRole : return f->alias(); case FolderStatusDelegate::FolderSyncPaused : return f->syncPaused(); case FolderStatusDelegate::FolderAccountConnected : return accountConnected; case Qt::ToolTipRole: if ( accountConnected ) return Theme::instance()->statusHeaderText(f->syncResult().status()); else return tr("Signed out"); case FolderStatusDelegate::FolderStatusIconRole: if ( accountConnected ) { auto theme = Theme::instance(); auto status = f->syncResult().status(); if( f->syncPaused() ) { return theme->folderDisabledIcon( ); } else { if( status == SyncResult::SyncPrepare ) { return theme->syncStateIcon(SyncResult::SyncRunning); } else if( status == SyncResult::Undefined ) { return theme->syncStateIcon( SyncResult::SyncRunning); } else { // keep the previous icon for the prepare phase. if( status == SyncResult::Problem) { return theme->syncStateIcon( SyncResult::Success); } else { return theme->syncStateIcon( status ); } } } } else { return Theme::instance()->folderOfflineIcon(); } case FolderStatusDelegate::SyncProgressItemString: return progress._progressString; case FolderStatusDelegate::WarningCount: return progress._warningCount; case FolderStatusDelegate::SyncProgressOverallPercent: return progress._overallPercent; case FolderStatusDelegate::SyncProgressOverallString: return progress._overallSyncString; } return QVariant(); }
QVariant FolderStatusModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); if (role == Qt::EditRole) return QVariant(); switch (classify(index)) { case AddButton: { if (role == FolderStatusDelegate::AddButton) { return QVariant(true); } else if (role == Qt::ToolTipRole) { if (!_accountState->isConnected()) { return tr("You need to be connected to add a folder"); } return tr("Click this button to add a folder to synchronize."); } return QVariant(); } case SubFolder: { const auto &x = static_cast<SubFolderInfo *>(index.internalPointer())->_subs[index.row()]; switch (role) { case Qt::DisplayRole: //: Example text: "File.txt (23KB)" return x._size < 0 ? x._name : tr("%1 (%2)").arg(x._name, Utility::octetsToString(x._size)); case Qt::ToolTipRole: return QString(QLatin1String("<qt>") + Utility::escape(x._size < 0 ? x._name : tr("%1 (%2)").arg(x._name, Utility::octetsToString(x._size))) + QLatin1String("</qt>")); case Qt::CheckStateRole: return x._checked; case Qt::DecorationRole: return QFileIconProvider().icon(x._isExternal ? QFileIconProvider::Network : QFileIconProvider::Folder); case Qt::ForegroundRole: if (x._isUndecided) { return QColor(Qt::red); } break; case FolderStatusDelegate::FolderPathRole: { auto f = x._folder; if (!f) return QVariant(); return QVariant(f->path() + x._path); } } } return QVariant(); case FetchLabel: { const auto x = static_cast<SubFolderInfo *>(index.internalPointer()); switch (role) { case Qt::DisplayRole: if (x->_hasError) { return QVariant(tr("Error while loading the list of folders from the server.") + QString("\n") + x->_lastErrorString); } else { return tr("Fetching folder list from server..."); } break; default: return QVariant(); } } case RootFolder: break; } const SubFolderInfo &folderInfo = _folders.at(index.row()); auto f = folderInfo._folder; if (!f) return QVariant(); const SubFolderInfo::Progress &progress = folderInfo._progress; const bool accountConnected = _accountState->isConnected(); switch (role) { case FolderStatusDelegate::FolderPathRole: return f->shortGuiLocalPath(); case FolderStatusDelegate::FolderSecondPathRole: return f->remotePath(); case FolderStatusDelegate::FolderConflictMsg: return (f->syncResult().hasUnresolvedConflicts()) ? QStringList(tr("There are unresolved conflicts. Click for details.")) : QStringList(); case FolderStatusDelegate::FolderErrorMsg: return f->syncResult().errorStrings(); case FolderStatusDelegate::FolderInfoMsg: return f->useVirtualFiles() ? QStringList(tr("New files are being created as virtual files.")) : QStringList(); case FolderStatusDelegate::SyncRunning: return f->syncResult().status() == SyncResult::SyncRunning; case FolderStatusDelegate::HeaderRole: return f->shortGuiRemotePathOrAppName(); case FolderStatusDelegate::FolderAliasRole: return f->alias(); case FolderStatusDelegate::FolderSyncPaused: return f->syncPaused(); case FolderStatusDelegate::FolderAccountConnected: return accountConnected; case Qt::ToolTipRole: { QString toolTip; if (!progress.isNull()) { return progress._progressString; } if (accountConnected) toolTip = Theme::instance()->statusHeaderText(f->syncResult().status()); else toolTip = tr("Signed out"); toolTip += "\n"; toolTip += folderInfo._folder->path(); return toolTip; } case FolderStatusDelegate::FolderStatusIconRole: if (accountConnected) { auto theme = Theme::instance(); auto status = f->syncResult().status(); if (f->syncPaused()) { return theme->folderDisabledIcon(); } else { if (status == SyncResult::SyncPrepare) { return theme->syncStateIcon(SyncResult::SyncRunning); } else if (status == SyncResult::Undefined) { return theme->syncStateIcon(SyncResult::SyncRunning); } else { // The "Problem" *result* just means some files weren't // synced, so we show "Success" in these cases. But we // do use the "Problem" *icon* for unresolved conflicts. if (status == SyncResult::Success || status == SyncResult::Problem) { if (f->syncResult().hasUnresolvedConflicts()) { return theme->syncStateIcon(SyncResult::Problem); } else { return theme->syncStateIcon(SyncResult::Success); } } else { return theme->syncStateIcon(status); } } } } else { return Theme::instance()->folderOfflineIcon(); } case FolderStatusDelegate::SyncProgressItemString: return progress._progressString; case FolderStatusDelegate::WarningCount: return progress._warningCount; case FolderStatusDelegate::SyncProgressOverallPercent: return progress._overallPercent; case FolderStatusDelegate::SyncProgressOverallString: return progress._overallSyncString; } return QVariant(); }