_lastSyncFolder = 0;
_currentSyncFolder = 0;
_scheduleQueue.clear();
+ emit scheduleQueueChanged();
Q_ASSERT(_folderMap.count() == 0);
return cnt;
Folder *f = setupFolderFromOldConfigFile( alias, accountState );
if( f ) {
slotScheduleSync(f);
- emit( folderSyncStateChange( f ) );
+ emit folderSyncStateChange(f);
}
}
qDebug() << "Schedule folder " << alias << " to sync!";
if( ! _scheduleQueue.contains(f) ) {
- if(f->canSync()) {
- f->prepareToSync();
- } else {
+ if( !f->canSync() ) {
qDebug() << "Folder is not ready to sync, not scheduled!";
if( _socketApi ) {
_socketApi->slotUpdateFolderView(f);
}
return;
}
+ f->prepareToSync();
+ emit folderSyncStateChange(f);
_scheduleQueue.enqueue(f);
+ emit scheduleQueueChanged();
} else {
qDebug() << " II> Sync for folder " << alias << " already scheduled, do not enqueue!";
}
it.remove();
}
}
+ emit scheduleQueueChanged();
}
}
// Try to start the top scheduled sync.
Folder *f = _scheduleQueue.dequeue();
+ emit scheduleQueueChanged();
Q_ASSERT(f);
// Start syncing this folder!
terminateSyncProcess();
}
- _scheduleQueue.removeAll(f);
+ if (_scheduleQueue.removeAll(f) > 0) {
+ emit scheduleQueueChanged();
+ }
f->wipe();
f->setSyncPaused(true);
}
}
+QQueue<Folder*> FolderMan::scheduleQueue() const
+{
+ return _scheduleQueue;
+}
+
+Folder *FolderMan::currentSyncFolder() const
+{
+ return _currentSyncFolder;
+}
+
void FolderMan::restartApplication()
{
if( Utility::isLinux() ) {
bool ignoreHiddenFiles() const;
void setIgnoreHiddenFiles(bool ignore);
+ /**
+ * Access to the current queue of scheduled folders.
+ */
+ QQueue<Folder*> scheduleQueue() const;
+
+ /**
+ * Access to the currently syncing folder.
+ */
+ Folder* currentSyncFolder() const;
+
signals:
/**
* signal to indicate a folder has changed its sync state.
*/
void folderSyncStateChange(Folder*);
+ /**
+ * Indicates when the schedule queue changes.
+ */
+ void scheduleQueueChanged();
+
void folderListLoaded(const Folder::Map &);
public slots:
_folders.clear();
_accountState = accountState;
+ connect(FolderMan::instance(), SIGNAL(folderSyncStateChange(Folder*)),
+ SLOT(slotFolderSyncStateChange(Folder*)), Qt::UniqueConnection);
+ connect(FolderMan::instance(), SIGNAL(scheduleQueueChanged()),
+ SLOT(slotFolderScheduleQueueChanged()), Qt::UniqueConnection);
+
auto folders = FolderMan::instance()->map();
foreach (auto f, folders) {
if (f->accountState() != accountState)
_folders << info;
connect(f, SIGNAL(progressInfo(ProgressInfo)), this, SLOT(slotSetProgress(ProgressInfo)), Qt::UniqueConnection);
- connect(f, SIGNAL(syncStateChange()), this, SLOT(slotFolderSyncStateChange()), Qt::UniqueConnection);
connect(f, SIGNAL(newBigFolderDiscovered(QString)), this, SLOT(slotNewBigFolder()), Qt::UniqueConnection);
}
emit dataChanged(index(folderIndex), index(folderIndex), roles);
}
-void FolderStatusModel::slotFolderSyncStateChange()
+void FolderStatusModel::slotFolderSyncStateChange(Folder *f)
{
- Folder *f = qobject_cast<Folder*>(sender());
if( !f ) { return; }
int folderIndex = -1;
if (folderIndex < 0) { return; }
SyncResult::Status state = f->syncResult().status();
- if (state == SyncResult::SyncPrepare
- || state == SyncResult::Problem
- || state == SyncResult::Success) {
- // Reset the progress info before and after a sync.
+ if (state == SyncResult::NotYetStarted) {
+ FolderMan* folderMan = FolderMan::instance();
+ int pos = folderMan->scheduleQueue().indexOf(f);
+ if (folderMan->currentSyncFolder()
+ && folderMan->currentSyncFolder() != f) {
+ pos += 1;
+ }
+ QString message;
+ if (pos <= 0) {
+ message = tr("Waiting...");
+ } else {
+ message = tr("Waiting for %n other folder(s)...", "", pos);
+ }
+ _folders[folderIndex]._progress = SubFolderInfo::Progress();
+ _folders[folderIndex]._progress._progressString = message;
+ } else if (state == SyncResult::SyncPrepare) {
+ _folders[folderIndex]._progress = SubFolderInfo::Progress();
+ _folders[folderIndex]._progress._progressString = tr("Preparing to sync...");
+ } else if (state == SyncResult::Problem || state == SyncResult::Success) {
+ // Reset the progress info after a sync.
_folders[folderIndex]._progress = SubFolderInfo::Progress();
} else if (state == SyncResult::Error) {
_folders[folderIndex]._progress._progressString = f->syncResult().errorString();
}
}
+void FolderStatusModel::slotFolderScheduleQueueChanged()
+{
+ // Update messages on waiting folders.
+ // It's ok to only update folders currently in the queue, because folders
+ // are only removed from the queue if they are deleted.
+ foreach (Folder* f, FolderMan::instance()->scheduleQueue()) {
+ slotFolderSyncStateChange(f);
+ }
+}
+
void FolderStatusModel::resetFolders()
{
setAccountState(_accountState);