[Pkg-owncloud-commits] [owncloud-client] 117/498: AccountSettings: move the progress handling in FolderStatusModel

Sandro Knauß hefee-guest at moszumanska.debian.org
Tue Aug 11 14:48:42 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 984434c7289ad2382092dc00ce293525286ff26e
Author: Olivier Goffart <ogoffart at woboq.com>
Date:   Tue Jun 2 19:45:23 2015 +0200

    AccountSettings: move the progress handling in FolderStatusModel
    
    This is required to compile with Qt4 because signals were protected.
    And the logic anyway belongs to the model
---
 src/gui/accountsettings.cpp   | 185 +---------------------------------------
 src/gui/accountsettings.h     |   6 --
 src/gui/folder.cpp            |   2 +
 src/gui/folder.h              |   1 +
 src/gui/folderman.cpp         |  10 ---
 src/gui/folderman.h           |   1 -
 src/gui/folderstatusmodel.cpp | 190 ++++++++++++++++++++++++++++++++++++++++--
 src/gui/folderstatusmodel.h   |  26 +++---
 8 files changed, 205 insertions(+), 216 deletions(-)

diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp
index a0b8267..9ea536c 100644
--- a/src/gui/accountsettings.cpp
+++ b/src/gui/accountsettings.cpp
@@ -129,9 +129,6 @@ AccountSettings::AccountSettings(AccountState *accountState, QWidget *parent) :
 
     connect(ui->deleteButton, SIGNAL(clicked()) , this, SLOT(slotDeleteAccount()));
 
-    connect( ProgressDispatcher::instance(), SIGNAL(progressInfo(QString, ProgressInfo)),
-             this, SLOT(slotSetProgress(QString, ProgressInfo)) );
-
 }
 
 void AccountSettings::slotCustomContextMenuRequested(const QPoint &pos)
@@ -357,7 +354,7 @@ void AccountSettings::slotEnableCurrentFolder()
         // keep state for the icon setting.
         if( currentlyPaused ) _wasDisabledBefore = true;
 
-        slotUpdateFolderState (f);
+        _model->slotUpdateFolderState (f);
     }
 }
 
@@ -372,190 +369,12 @@ void AccountSettings::slotSyncCurrentFolderNow()
     folderMan->slotScheduleSync(folderMan->folder(alias));
 }
 
-void AccountSettings::slotUpdateFolderState( Folder *folder )
-{
-    if( ! folder ) return;
-
-    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<int>() << FolderStatusDelegate::AddProgressSpace);
-}
-
 void AccountSettings::slotOpenOC()
 {
   if( _OCUrl.isValid() )
     QDesktopServices::openUrl( _OCUrl );
 }
 
-QString AccountSettings::shortenFilename( const QString& folder, const QString& file ) const
-{
-    // strip off the server prefix from the file name
-    QString shortFile(file);
-    if( shortFile.isEmpty() ) {
-        return QString::null;
-    }
-
-    if(shortFile.startsWith(QLatin1String("ownclouds://")) ||
-            shortFile.startsWith(QLatin1String("owncloud://")) ) {
-        // rip off the whole ownCloud URL.
-        Folder *f = FolderMan::instance()->folder(folder);
-        if( f ) {
-            QString remotePathUrl = f->remoteUrl().toString();
-            shortFile.remove(Utility::toCSyncScheme(remotePathUrl));
-        }
-    }
-    return shortFile;
-}
-
-void AccountSettings::slotSetProgress(const QString& folder, const ProgressInfo &progress )
-{
-    if (!isVisible()) {
-        return; // for https://github.com/owncloud/client/issues/2648#issuecomment-71377909
-    }
-
-    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<int> roles;
-    roles << FolderStatusDelegate::AddProgressSpace << FolderStatusDelegate::SyncProgressItemString
-        << FolderStatusDelegate::WarningCount;
-
-    if (!progress._currentDiscoveredFolder.isEmpty()) {
-        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)) {
-        progressInfo->_warningCount++;
-    }
-
-    // find the single item to display:  This is going to be the bigger item, or the last completed
-    // item if no items are in progress.
-    SyncFileItem curItem = progress._lastCompletedItem;
-    qint64 curItemProgress = -1; // -1 means finished
-    quint64 biggerItemSize = -1;
-    foreach(const ProgressInfo::ProgressItem &citm, progress._currentItems) {
-        if (curItemProgress == -1 || (ProgressInfo::isSizeDependent(citm._item)
-                                      && biggerItemSize < citm._item._size)) {
-            curItemProgress = citm._progress.completed();
-            curItem = citm._item;
-            biggerItemSize = citm._item._size;
-        }
-    }
-    if (curItemProgress == -1) {
-        curItemProgress = curItem._size;
-    }
-
-    QString itemFileName = shortenFilename(folder, curItem._file);
-    QString kindString = Progress::asActionString(curItem);
-
-
-
-    QString fileProgressString;
-    if (ProgressInfo::isSizeDependent(curItem)) {
-        QString s1 = Utility::octetsToString( curItemProgress );
-        QString s2 = Utility::octetsToString( curItem._size );
-        quint64 estimatedBw = progress.fileProgress(curItem).estimatedBandwidth;
-        if (estimatedBw) {
-            //: Example text: "uploading foobar.png (1MB of 2MB) time left 2 minutes at a rate of 24Kb/s"
-            fileProgressString = tr("%1 %2 (%3 of %4) %5 left at a rate of %6/s")
-                .arg(kindString, itemFileName, s1, s2,
-                    Utility::timeToDescriptiveString(progress.fileProgress(curItem).estimatedEta, 3, " ", true),
-                    Utility::octetsToString(estimatedBw) );
-        } else {
-            //: Example text: "uploading foobar.png (2MB of 2MB)"
-            fileProgressString = tr("%1 %2 (%3 of %4)") .arg(kindString, itemFileName, s1, s2);
-        }
-    } else if (!kindString.isEmpty()) {
-        //: Example text: "uploading foobar.png"
-        fileProgressString = tr("%1 %2").arg(kindString, itemFileName);
-    }
-    progressInfo->_progressString = fileProgressString;
-
-    // overall progress
-    quint64 completedSize = progress.completedSize();
-    quint64 completedFile = progress.completedFiles();
-    quint64 currentFile = progress.currentFile();
-    if (currentFile == ULLONG_MAX)
-        currentFile = 0;
-    quint64 totalSize = qMax(completedSize, progress.totalSize());
-    quint64 totalFileCount = qMax(currentFile, progress.totalFiles());
-    QString overallSyncString;
-    if (totalSize > 0) {
-        QString s1 = Utility::octetsToString( completedSize );
-        QString s2 = Utility::octetsToString( totalSize );
-        overallSyncString = tr("%1 of %2, file %3 of %4\nTotal time left %5")
-            .arg(s1, s2)
-            .arg(currentFile).arg(totalFileCount)
-            .arg( Utility::timeToDescriptiveString(progress.totalProgress().estimatedEta, 3, " ", true) );
-    } else if (totalFileCount > 0) {
-        // Don't attemt to estimate the time left if there is no kb to transfer.
-        overallSyncString = tr("file %1 of %2") .arg(currentFile).arg(totalFileCount);
-    }
-
-    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 + completedFile)/double(totalSize + totalFileCount) * 100.0);
-    }
-    progressInfo->_overallPercent = qBound(0, overallPercent, 100);
-    emit _model->dataChanged(_model->index(folderIndex), _model->index(folderIndex), roles);
-}
-
-void AccountSettings::slotHideProgress()
-{
-    auto folderIndex = sender()->property("owncloud_folderIndex").toInt();
-    if (folderIndex < 0) { return; }
-
-    if (_model->_progresses.size() <= folderIndex) {
-        return;
-    }
-
-    _model->_progresses[folderIndex] = FolderStatusModel::ProgressInfo();
-    emit _model->dataChanged(_model->index(folderIndex), _model->index(folderIndex),
-                             QVector<int>() << FolderStatusDelegate::AddProgressSpace);
-}
-
-void AccountSettings::slotFolderSyncStateChange()
-{
-    Folder* folder = qobject_cast<Folder *>(sender());
-    if (!folder) 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)  {
-        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;
-        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);
-    }
-}
-
 void AccountSettings::slotUpdateQuota(qint64 total, qint64 used)
 {
     if( total > 0 ) {
@@ -590,7 +409,7 @@ void AccountSettings::slotAccountStateChanged(int state)
         safeUrl.setPassword(QString()); // Remove the password from the URL to avoid showing it in the UI
         FolderMan *folderMan = FolderMan::instance();
         foreach (Folder *folder, folderMan->map().values()) {
-            slotUpdateFolderState(folder);
+            _model->slotUpdateFolderState(folder);
         }
         if (state == AccountState::Connected || state == AccountState::ServiceUnavailable) {
             QString user;
diff --git a/src/gui/accountsettings.h b/src/gui/accountsettings.h
index fbbf23d..2f7b732 100644
--- a/src/gui/accountsettings.h
+++ b/src/gui/accountsettings.h
@@ -58,10 +58,7 @@ signals:
 public slots:
     void slotFolderActivated( const QModelIndex& );
     void slotOpenOC();
-    void slotUpdateFolderState( Folder* );
     void slotDoubleClicked( const QModelIndex& );
-    void slotSetProgress(const QString& folder, const ProgressInfo& progress);
-
     void slotUpdateQuota( qint64,qint64 );
     void slotAccountStateChanged(int state);
 
@@ -76,12 +73,10 @@ protected slots:
     void slotResetCurrentFolder();
     void slotFolderWizardAccepted();
     void slotFolderWizardRejected();
-    void slotHideProgress();
     void slotDeleteAccount();
     void refreshSelectiveSyncStatus();
 
 private:
-    QString shortenFilename( const QString& folder, const QString& file ) const;
     void showConnectionLabel( const QString& message, const QString& tooltip = QString() );
 
     Ui::AccountSettings *ui;
@@ -93,7 +88,6 @@ private:
     AccountState *_accountState;
     QLabel *_quotaLabel;
 private slots:
-    void slotFolderSyncStateChange();
     void slotCustomContextMenuRequested(const QPoint&);
 };
 
diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp
index 8a2b3c5..73cade4 100644
--- a/src/gui/folder.cpp
+++ b/src/gui/folder.cpp
@@ -976,6 +976,7 @@ void Folder::slotFolderDiscovered(bool, QString folderName)
 {
     ProgressInfo pi;
     pi._currentDiscoveredFolder = folderName;
+    emit progressInfo(pi);
     ProgressDispatcher::instance()->setProgressInfo(alias(), pi);
 }
 
@@ -988,6 +989,7 @@ void Folder::slotTransmissionProgress(const ProgressInfo &pi)
         // this is the beginning of a sync, set the warning level to 0
         _syncResult.setWarnCount(0);
     }
+    emit progressInfo(pi);
     ProgressDispatcher::instance()->setProgressInfo(alias(), pi);
 }
 
diff --git a/src/gui/folder.h b/src/gui/folder.h
index ac623a3..ba7d699 100644
--- a/src/gui/folder.h
+++ b/src/gui/folder.h
@@ -178,6 +178,7 @@ signals:
     void syncStarted();
     void syncFinished(const SyncResult &result);
     void scheduleToSync(Folder*);
+    void progressInfo(const ProgressInfo& progress);
 
 public slots:
 
diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp
index ec99dac..c39f1f5 100644
--- a/src/gui/folderman.cpp
+++ b/src/gui/folderman.cpp
@@ -398,7 +398,6 @@ Folder* FolderMan::setupFolderFromOldConfigFile(const QString &file, AccountStat
     }
 
     connect(folder, SIGNAL(scheduleToSync(Folder*)), SLOT(slotScheduleSync(Folder*)));
-    connect(folder, SIGNAL(syncStateChange()), this, SLOT(slotFolderSyncStateChanged()));
     connect(folder, SIGNAL(syncStarted()), SLOT(slotFolderSyncStarted()));
     connect(folder, SIGNAL(syncFinished(SyncResult)), SLOT(slotFolderSyncFinished(SyncResult)));
 
@@ -700,14 +699,6 @@ void FolderMan::slotFolderSyncFinished( const SyncResult& )
     startScheduledSyncSoon();
 }
 
-void FolderMan::slotFolderSyncStateChanged()
-{
-    auto f = qobject_cast<Folder *>(sender());
-    Q_ASSERT(f);
-    emit folderSyncStateChange(f);
-}
-
-
 Folder* FolderMan::addFolder(AccountState* accountState, const FolderDefinition& folderDefinition)
 {
     if (!ensureJournalGone(folderDefinition.localPath)) {
@@ -732,7 +723,6 @@ Folder* FolderMan::addFolderInternal(AccountState* accountState, const FolderDef
 
     /* Use a signal mapper to connect the signals to the alias */
     connect(folder, SIGNAL(scheduleToSync(Folder*)), SLOT(slotScheduleSync(Folder*)));
-    connect(folder, SIGNAL(syncStateChange()), this, SLOT(slotFolderSyncStateChanged()));
     connect(folder, SIGNAL(syncStarted()), SLOT(slotFolderSyncStarted()));
     connect(folder, SIGNAL(syncFinished(SyncResult)), SLOT(slotFolderSyncFinished(SyncResult)));
 
diff --git a/src/gui/folderman.h b/src/gui/folderman.h
index 9fc0119..f7a3d2c 100644
--- a/src/gui/folderman.h
+++ b/src/gui/folderman.h
@@ -134,7 +134,6 @@ private slots:
     void slotEtagPollTimerTimeout();
 
     void slotRemoveFoldersForAccount(AccountState* accountState);
-    void slotFolderSyncStateChanged();
 
 private:
     /** Adds a folder for an account, does not add it to the account settings.
diff --git a/src/gui/folderstatusmodel.cpp b/src/gui/folderstatusmodel.cpp
index 351090f..ec1b74c 100644
--- a/src/gui/folderstatusmodel.cpp
+++ b/src/gui/folderstatusmodel.cpp
@@ -57,6 +57,9 @@ void FolderStatusModel::setAccount(const AccountPtr& account)
         info._path = "/";
         info._folder = f;
         _folders << info;
+
+        connect(f, SIGNAL(progressInfo(ProgressInfo)), this, SLOT(slotSetProgress(ProgressInfo)), Qt::UniqueConnection);
+        connect(f, SIGNAL(syncStateChange()), this, SLOT(slotFolderSyncStateChange()), Qt::UniqueConnection);
     }
 
     endResetModel();
@@ -145,15 +148,15 @@ QVariant FolderStatusModel::data(const QModelIndex &index, int role) const
             return Theme::instance()->folderOfflineIcon();
         }
     case FolderStatusDelegate::AddProgressSpace:
-        return !_progresses.value(index.row()).isNull();
+        return !_folders.value(index.row())._progress.isNull();
     case FolderStatusDelegate::SyncProgressItemString:
-        return _progresses.value(index.row())._progressString;
+        return _folders.value(index.row())._progress._progressString;
     case FolderStatusDelegate::WarningCount:
-        return _progresses.value(index.row())._warningCount;
+        return _folders.value(index.row())._progress._warningCount;
     case FolderStatusDelegate::SyncProgressOverallPercent:
-        return _progresses.value(index.row())._overallPercent;
+        return _folders.value(index.row())._progress._overallPercent;
     case FolderStatusDelegate::SyncProgressOverallString:
-        return _progresses.value(index.row())._overallSyncString;
+        return _folders.value(index.row())._progress._overallSyncString;
     }
     return QVariant();
 }
@@ -460,6 +463,17 @@ QStringList FolderStatusModel::createBlackList(FolderStatusModel::SubFolderInfo
     return result;
 }
 
+void FolderStatusModel::slotUpdateFolderState(Folder *folder)
+{
+    if( ! folder ) return;
+    for (int i = 0; i < _folders.count(); ++i) {
+        if (_folders.at(i)._folder == folder) {
+            emit dataChanged(index(i), index(i),
+                             QVector<int>() << FolderStatusDelegate::AddProgressSpace);
+        }
+    }
+}
+
 void FolderStatusModel::slotApplySelectiveSync()
 {
     if (!_dirty)
@@ -493,6 +507,172 @@ void FolderStatusModel::slotApplySelectiveSync()
     resetFolders();
 }
 
+static QString shortenFilename( Folder *f, const QString& file )
+{
+    // strip off the server prefix from the file name
+    QString shortFile(file);
+    if( shortFile.isEmpty() ) {
+        return QString::null;
+    }
+
+    if(shortFile.startsWith(QLatin1String("ownclouds://")) ||
+            shortFile.startsWith(QLatin1String("owncloud://")) ) {
+        // rip off the whole ownCloud URL.
+        if( f ) {
+            QString remotePathUrl = f->remoteUrl().toString();
+            shortFile.remove(Utility::toCSyncScheme(remotePathUrl));
+        }
+    }
+    return shortFile;
+}
+
+void FolderStatusModel::slotSetProgress(const ProgressInfo &progress)
+{
+    auto par = qobject_cast<QWidget*>(QObject::parent());
+    if (!par->isVisible()) {
+        return; // for https://github.com/owncloud/client/issues/2648#issuecomment-71377909
+    }
+
+    Folder *f = qobject_cast<Folder*>(sender());
+    if( !f ) { return; }
+
+    int folderIndex = -1;
+    for (int i = 0; i < _folders.count(); ++i) {
+        if (_folders.at(i)._folder == f) {
+            folderIndex = i;
+            break;
+        }
+    }
+    if (folderIndex < 0) { return; }
+
+    auto *pi = &_folders[folderIndex]._progress;
+
+    QVector<int> roles;
+    roles << FolderStatusDelegate::AddProgressSpace << FolderStatusDelegate::SyncProgressItemString
+        << FolderStatusDelegate::WarningCount;
+
+    if (!progress._currentDiscoveredFolder.isEmpty()) {
+        pi->_progressString = tr("Discovering '%1'").arg(progress._currentDiscoveredFolder);
+        emit dataChanged(index(folderIndex), index(folderIndex), roles);
+        return;
+    }
+
+    if(!progress._lastCompletedItem.isEmpty()
+            && Progress::isWarningKind(progress._lastCompletedItem._status)) {
+        pi->_warningCount++;
+    }
+
+    // find the single item to display:  This is going to be the bigger item, or the last completed
+    // item if no items are in progress.
+    SyncFileItem curItem = progress._lastCompletedItem;
+    qint64 curItemProgress = -1; // -1 means finished
+    quint64 biggerItemSize = -1;
+    foreach(const ProgressInfo::ProgressItem &citm, progress._currentItems) {
+        if (curItemProgress == -1 || (ProgressInfo::isSizeDependent(citm._item)
+                                      && biggerItemSize < citm._item._size)) {
+            curItemProgress = citm._progress.completed();
+            curItem = citm._item;
+            biggerItemSize = citm._item._size;
+        }
+    }
+    if (curItemProgress == -1) {
+        curItemProgress = curItem._size;
+    }
+
+    QString itemFileName = shortenFilename(f, curItem._file);
+    QString kindString = Progress::asActionString(curItem);
+
+    QString fileProgressString;
+    if (ProgressInfo::isSizeDependent(curItem)) {
+        QString s1 = Utility::octetsToString( curItemProgress );
+        QString s2 = Utility::octetsToString( curItem._size );
+        quint64 estimatedBw = progress.fileProgress(curItem).estimatedBandwidth;
+        if (estimatedBw) {
+            //: Example text: "uploading foobar.png (1MB of 2MB) time left 2 minutes at a rate of 24Kb/s"
+            fileProgressString = tr("%1 %2 (%3 of %4) %5 left at a rate of %6/s")
+                .arg(kindString, itemFileName, s1, s2,
+                    Utility::timeToDescriptiveString(progress.fileProgress(curItem).estimatedEta, 3, " ", true),
+                    Utility::octetsToString(estimatedBw) );
+        } else {
+            //: Example text: "uploading foobar.png (2MB of 2MB)"
+            fileProgressString = tr("%1 %2 (%3 of %4)") .arg(kindString, itemFileName, s1, s2);
+        }
+    } else if (!kindString.isEmpty()) {
+        //: Example text: "uploading foobar.png"
+        fileProgressString = tr("%1 %2").arg(kindString, itemFileName);
+    }
+    pi->_progressString = fileProgressString;
+
+    // overall progress
+    quint64 completedSize = progress.completedSize();
+    quint64 completedFile = progress.completedFiles();
+    quint64 currentFile = progress.currentFile();
+    if (currentFile == ULLONG_MAX)
+        currentFile = 0;
+    quint64 totalSize = qMax(completedSize, progress.totalSize());
+    quint64 totalFileCount = qMax(currentFile, progress.totalFiles());
+    QString overallSyncString;
+    if (totalSize > 0) {
+        QString s1 = Utility::octetsToString( completedSize );
+        QString s2 = Utility::octetsToString( totalSize );
+        overallSyncString = tr("%1 of %2, file %3 of %4\nTotal time left %5")
+            .arg(s1, s2)
+            .arg(currentFile).arg(totalFileCount)
+            .arg( Utility::timeToDescriptiveString(progress.totalProgress().estimatedEta, 3, " ", true) );
+    } else if (totalFileCount > 0) {
+        // Don't attemt to estimate the time left if there is no kb to transfer.
+        overallSyncString = tr("file %1 of %2") .arg(currentFile).arg(totalFileCount);
+    }
+
+    pi->_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 + completedFile)/double(totalSize + totalFileCount) * 100.0);
+    }
+    pi->_overallPercent = qBound(0, overallPercent, 100);
+    emit dataChanged(index(folderIndex), index(folderIndex), roles);
+}
+
+void FolderStatusModel::slotHideProgress()
+{
+    auto folderIndex = sender()->property("owncloud_folderIndex").toInt();
+    if (folderIndex < 0 || _folders.size() <= folderIndex) { return; }
+
+    _folders[folderIndex]._progress = SubFolderInfo::Progress();
+    emit dataChanged(index(folderIndex), index(folderIndex),
+                             QVector<int>() << FolderStatusDelegate::AddProgressSpace);
+}
+
+void FolderStatusModel::slotFolderSyncStateChange()
+{
+    Folder *f = qobject_cast<Folder*>(sender());
+    if( !f ) { return; }
+    int folderIndex = -1;
+    for (int i = 0; i < _folders.count(); ++i) {
+        if (_folders.at(i)._folder == f) {
+            folderIndex = i;
+            break;
+        }
+    }
+    if (folderIndex < 0) { return; }
+
+    SyncResult::Status state = f->syncResult().status();
+    if (state == SyncResult::SyncPrepare)  {
+        _folders[folderIndex]._progress = SubFolderInfo::Progress();
+    } else if (state == SyncResult::Success || state == SyncResult::Problem) {
+        // start a timer to stop the progress display
+        QTimer *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);
+    }
+}
+
 
 void FolderStatusModel::resetFolders()
 {
diff --git a/src/gui/folderstatusmodel.h b/src/gui/folderstatusmodel.h
index 9658e47..650a4aa 100644
--- a/src/gui/folderstatusmodel.h
+++ b/src/gui/folderstatusmodel.h
@@ -26,6 +26,7 @@
 namespace OCC {
 
 class Folder;
+class ProgressInfo;
 
 class FolderStatusModel : public QAbstractItemModel
 {
@@ -57,6 +58,16 @@ public:
         QVector<SubFolderInfo> _subs;
         Qt::CheckState _checked = Qt::Checked;
         Folder *_folder;
+
+        struct Progress {
+            bool isNull() const
+            { return _progressString.isEmpty() && _warningCount == 0 && _overallSyncString.isEmpty(); }
+            QString _progressString;
+            QString _overallSyncString;
+            int _warningCount = 0;
+            int _overallPercent = 0;
+        };
+        Progress _progress;
     };
 
     QVector<SubFolderInfo> _folders;
@@ -68,23 +79,16 @@ public:
     // If the selective sync check boxes were changed
     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<ProgressInfo> _progresses;
-
-
 public slots:
+    void slotUpdateFolderState(Folder *);
     void slotApplySelectiveSync();
     void resetFolders();
+    void slotSetProgress(const ProgressInfo &progress);
 
 private slots:
     void slotUpdateDirectories(const QStringList &);
+    void slotHideProgress();
+    void slotFolderSyncStateChange();
 
 private:
     QStringList createBlackList(OCC::FolderStatusModel::SubFolderInfo* root,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list