From 85ff245aef4c57482555413d8d0737978f5650af Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 9 Apr 2015 12:06:47 +0200 Subject: [PATCH] Account settings: add the progress back on the new ui --- src/gui/accountsettings.cpp | 189 ++++++++-------------------------- src/gui/accountsettings.h | 6 -- src/gui/folderstatusmodel.cpp | 10 ++ src/gui/folderstatusmodel.h | 12 ++- 4 files changed, 66 insertions(+), 151 deletions(-) diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index 5eab1b01b..7fb0ed3f2 100644 --- a/src/gui/accountsettings.cpp +++ b/src/gui/accountsettings.cpp @@ -232,70 +232,6 @@ void AccountSettings::setGeneralErrors( const QStringList& errors ) } } -void AccountSettings::folderToModelItem( QStandardItem *item, Folder *f, bool accountConnected ) -{ - if( ! item || !f ) return; - - item->setData( f->nativePath(), FolderStatusDelegate::FolderPathRole ); - item->setData( f->remotePath(), FolderStatusDelegate::FolderSecondPathRole ); - item->setData( f->alias(), FolderStatusDelegate::FolderAliasRole ); - item->setData( f->syncPaused(), FolderStatusDelegate::FolderSyncPaused ); - item->setData( accountConnected, FolderStatusDelegate::FolderAccountConnected ); - SyncResult res = f->syncResult(); - SyncResult::Status status = res.status(); - - QStringList errorList = res.errorStrings(); - - Theme *theme = Theme::instance(); - item->setData( theme->statusHeaderText( status ), Qt::ToolTipRole ); - if ( accountConnected ) { - if( f->syncPaused() ) { - item->setData( theme->folderDisabledIcon( ), FolderStatusDelegate::FolderStatusIconRole ); // size 48 before - _wasDisabledBefore = false; - } else { - 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 ); - } 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 ); - } - } - } - } else { - 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 )) { - errorList << theme->statusHeaderText(status); - } - } - - item->setData( errorList, FolderStatusDelegate::FolderErrorMsg); - - bool ongoing = false; - item->setData( QVariant(res.warnCount()), FolderStatusDelegate::WarningCount ); - if( status == SyncResult::SyncRunning ) { - ongoing = true; - } - item->setData( ongoing, FolderStatusDelegate::SyncRunning); - -} - void AccountSettings::slotRemoveCurrentFolder() { QModelIndex selected = ui->_folderList->selectionModel()->currentIndex(); @@ -452,27 +388,13 @@ void AccountSettings::slotSyncCurrentFolderNow() void AccountSettings::slotUpdateFolderState( Folder *folder ) { - QStandardItem *item = 0; - int row = 0; - if( ! folder ) return; -#if 0 - item = _model->item( row ); - while( item ) { - if( item->data( FolderStatusDelegate::FolderAliasRole ) == folder->alias() ) { - // its the item to update! - break; - } - item = _model->item( ++row ); - } - - if( item ) { - folderToModelItem( item, folder, _accountState->isConnectedOrMaintenance() ); - } else { - // the dialog is not visible. - } -#endif + auto folderList = FolderMan::instance()->map().values(); + auto folderIndex = folderList.indexOf(folder); + if (folderIndex < 0) { return; } + emit _model->dataChanged(_model->index(folderIndex), _model->index(folderIndex), + QVector() << FolderStatusDelegate::AddProgressSpace); } void AccountSettings::slotOpenOC() @@ -481,11 +403,6 @@ void AccountSettings::slotOpenOC() QDesktopServices::openUrl( _OCUrl ); } -QStandardItem* AccountSettings::itemForFolder(const QString& folder) -{ - return nullptr; -} - QString AccountSettings::shortenFilename( const QString& folder, const QString& file ) const { // strip off the server prefix from the file name @@ -508,26 +425,35 @@ QString AccountSettings::shortenFilename( const QString& folder, const QString& void AccountSettings::slotSetProgress(const QString& folder, const Progress::Info &progress ) { -#if 0 if (!isVisible()) { return; // for https://github.com/owncloud/client/issues/2648#issuecomment-71377909 } - QStandardItem *item = itemForFolder( folder ); - if( !item ) return; - // switch on extra space. - item->setData( QVariant(true), FolderStatusDelegate::AddProgressSpace ); + Folder *f = FolderMan::instance()->folder(folder); + if( !f ) { return; } + + auto folderList = FolderMan::instance()->map().values(); + auto folderIndex = folderList.indexOf(f); + if (folderIndex < 0) { return; } + + if (_model->_progresses.size() <= folderIndex) { + _model->_progresses.resize(folderIndex + 1); + } + FolderStatusModel::ProgressInfo *progressInfo = &_model->_progresses[folderIndex]; + + QVector roles; + roles << FolderStatusDelegate::AddProgressSpace << FolderStatusDelegate::SyncProgressItemString + << FolderStatusDelegate::WarningCount; if (!progress._currentDiscoveredFolder.isEmpty()) { - item->setData( tr("Discovering '%1'").arg(progress._currentDiscoveredFolder) , FolderStatusDelegate::SyncProgressItemString ); + progressInfo->_progressString = tr("Discovering '%1'").arg(progress._currentDiscoveredFolder); + emit _model->dataChanged(_model->index(folderIndex), _model->index(folderIndex), roles); return; } if(!progress._lastCompletedItem.isEmpty() && Progress::isWarningKind(progress._lastCompletedItem._status)) { - int warnCount = item->data(FolderStatusDelegate::WarningCount).toInt(); - warnCount++; - item->setData( QVariant(warnCount), FolderStatusDelegate::WarningCount ); + progressInfo->_warningCount++; } // find the single item to display: This is going to be the bigger item, or the last completed @@ -571,7 +497,7 @@ void AccountSettings::slotSetProgress(const QString& folder, const Progress::Inf //: Example text: "uploading foobar.png" fileProgressString = tr("%1 %2").arg(kindString, itemFileName); } - item->setData( fileProgressString,FolderStatusDelegate::SyncProgressItemString); + progressInfo->_progressString = fileProgressString; // overall progress quint64 completedSize = progress.completedSize(); @@ -593,81 +519,56 @@ void AccountSettings::slotSetProgress(const QString& folder, const Progress::Inf overallSyncString = tr("file %1 of %2") .arg(currentFile).arg(totalFileCount); } - item->setData( overallSyncString, FolderStatusDelegate::SyncProgressOverallString ); + progressInfo->_overallSyncString = overallSyncString; int overallPercent = 0; if( totalFileCount > 0 ) { // Add one 'byte' for each files so the percentage is moving when deleting or renaming files overallPercent = qRound(double(completedSize + progress._completedFileCount)/double(totalSize + totalFileCount) * 100.0); } - overallPercent = qBound(0, overallPercent, 100); - item->setData( overallPercent, FolderStatusDelegate::SyncProgressOverallPercent); -#endif + progressInfo->_overallPercent = qBound(0, overallPercent, 100); + emit _model->dataChanged(_model->index(folderIndex), _model->index(folderIndex), roles); } void AccountSettings::slotHideProgress() { -#if 0 - QTimer *send_timer = qobject_cast(this->sender()); - QHash::const_iterator i = _hideProgressTimers.constBegin(); - while (i != _hideProgressTimers.constEnd()) { - if( i.value() == send_timer ) { - QStandardItem *item = i.key(); + auto folderIndex = sender()->property("owncloud_folderIndex").toInt(); + if (folderIndex < 0) { return; } - /* Check if this item is still existing */ - bool ok = false; - for( int r = 0; !ok && r < _model->rowCount(); r++) { - if( item == _model->item(r,0) ) { - ok = true; - } - } - - if( ok ) { - item->setData( false, FolderStatusDelegate::AddProgressSpace ); - item->setData( QString(), FolderStatusDelegate::SyncProgressOverallString ); - item->setData( QString(), FolderStatusDelegate::SyncProgressItemString ); - item->setData( 0, FolderStatusDelegate::SyncProgressOverallPercent ); - } - _hideProgressTimers.remove(item); - break; - } - ++i; + if (_model->_progresses.size() <= folderIndex) { + return; } - send_timer->deleteLater(); -#endif + _model->_progresses[folderIndex] = FolderStatusModel::ProgressInfo(); + emit _model->dataChanged(_model->index(folderIndex), _model->index(folderIndex), + QVector() << FolderStatusDelegate::AddProgressSpace); } void AccountSettings::slotFolderSyncStateChange() { -#if 0 Folder* folder = qobject_cast(sender()); if (!folder) return; - - QStandardItem *item = itemForFolder( folder->alias() ); - if( !item ) return; + auto folderList = FolderMan::instance()->map().values(); + auto folderIndex = folderList.indexOf(folder); + if (folderIndex < 0) { return; } SyncResult::Status state = folder->syncResult().status(); if (state == SyncResult::SyncPrepare) { - item->setData( QVariant(0), FolderStatusDelegate::WarningCount ); + if (_model->_progresses.size() > folderIndex) { + _model->_progresses[folderIndex] = FolderStatusModel::ProgressInfo(); + } } else if (state == SyncResult::Success || state == SyncResult::Problem) { // start a timer to stop the progress display QTimer *timer; - if( _hideProgressTimers.contains(item) ) { - timer = _hideProgressTimers[item]; - // there is already one timer running. - } else { - timer = new QTimer(this); - connect(timer, SIGNAL(timeout()), this, SLOT(slotHideProgress())); - timer->setSingleShot(true); - _hideProgressTimers.insert(item, timer); - } + timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(slotHideProgress())); + connect(timer, SIGNAL(timeout()), timer, SLOT(deleteLater())); + timer->setSingleShot(true); + timer->setProperty("owncloud_folderIndex", folderIndex); timer->start(5000); } -#endif } - void AccountSettings::slotUpdateQuota(qint64 total, qint64 used) { if( total > 0 ) { diff --git a/src/gui/accountsettings.h b/src/gui/accountsettings.h index da0132bb7..111a5b5b0 100644 --- a/src/gui/accountsettings.h +++ b/src/gui/accountsettings.h @@ -19,14 +19,11 @@ #include #include #include -#include #include "folder.h" #include "progressdispatcher.h" -class QStandardItemModel; class QModelIndex; -class QStandardItem; class QNetworkReply; class QListWidgetItem; class QLabel; @@ -83,15 +80,12 @@ protected slots: private: QString shortenFilename( const QString& folder, const QString& file ) const; - void folderToModelItem(QStandardItem *, Folder * , bool accountConnected); - QStandardItem* itemForFolder(const QString& ); void showConnectionLabel( const QString& message, const QString& tooltip = QString() ); Ui::AccountSettings *ui; FolderStatusModel *_model; QUrl _OCUrl; - QHash _hideProgressTimers; QStringList _generalErrors; bool _wasDisabledBefore; AccountState *_accountState; diff --git a/src/gui/folderstatusmodel.cpp b/src/gui/folderstatusmodel.cpp index 04a0e6a93..e27c98c4b 100644 --- a/src/gui/folderstatusmodel.cpp +++ b/src/gui/folderstatusmodel.cpp @@ -131,6 +131,16 @@ QVariant FolderStatusModel::data(const QModelIndex &index, int role) const } else { return Theme::instance()->folderOfflineIcon(); } + case FolderStatusDelegate::AddProgressSpace: + return !_progresses.value(index.row()).isNull(); + case FolderStatusDelegate::SyncProgressItemString: + return _progresses.value(index.row())._progressString; + case FolderStatusDelegate::WarningCount: + return _progresses.value(index.row())._warningCount; + case FolderStatusDelegate::SyncProgressOverallPercent: + return _progresses.value(index.row())._overallPercent; + case FolderStatusDelegate::SyncProgressOverallString: + return _progresses.value(index.row())._overallSyncString; } return QVariant(); } diff --git a/src/gui/folderstatusmodel.h b/src/gui/folderstatusmodel.h index 2e1709b78..e8945b259 100644 --- a/src/gui/folderstatusmodel.h +++ b/src/gui/folderstatusmodel.h @@ -48,7 +48,6 @@ public: struct SubFolderInfo { -// QWeakPointer parent; QString _name; QString _path; QVector _pathIdx; @@ -68,6 +67,17 @@ public: bool isDirty() { return _dirty; } + struct ProgressInfo { + bool isNull() const + { return _progressString.isEmpty() && _warningCount == 0 && _overallSyncString.isEmpty(); } + QString _progressString; + QString _overallSyncString; + int _warningCount = 0; + int _overallPercent = 0; + }; + QVector _progresses; + + public slots: void slotApplySelectiveSync(); void resetFolders();