зеркало из https://github.com/nextcloud/desktop.git
Changed the folder queue to use QString instead of folder ptrs.
Delete folder after finished if its syncing at deletion time.
This commit is contained in:
Родитель
d938c531c8
Коммит
3fb471edad
|
@ -187,7 +187,7 @@ void Folder::evaluateSync(const QStringList &pathList)
|
|||
// sync finished.
|
||||
qDebug() << "* " << alias() << "Poll timer disabled";
|
||||
_pollTimer->stop();
|
||||
emit scheduleToSync( this );
|
||||
emit scheduleToSync( alias() );
|
||||
// startSync( pathList );
|
||||
}
|
||||
|
||||
|
|
|
@ -160,7 +160,7 @@ signals:
|
|||
void syncStateChange();
|
||||
void syncStarted();
|
||||
void syncFinished(const SyncResult &result);
|
||||
void scheduleToSync(Folder*);
|
||||
void scheduleToSync( const QString& );
|
||||
|
||||
protected:
|
||||
#ifdef USE_WATCHER
|
||||
|
|
|
@ -26,8 +26,8 @@
|
|||
namespace Mirall {
|
||||
|
||||
FolderMan::FolderMan(QObject *parent) :
|
||||
QObject(parent)
|
||||
, _currentSyncFolder(0)
|
||||
QObject(parent),
|
||||
_folderToDelete(false)
|
||||
{
|
||||
// if QDir::mkpath would not be so stupid, I would not need to have this
|
||||
// duplication of folderConfigPath() here
|
||||
|
@ -174,7 +174,7 @@ Folder* FolderMan::setupFolderFromConfigFile(const QString &file) {
|
|||
|
||||
qDebug() << "Adding folder to Folder Map " << folder;
|
||||
/* Use a signal mapper to connect the signals to the alias */
|
||||
connect(folder, SIGNAL(scheduleToSync(Folder*)), SLOT(slotScheduleSync(Folder*)));
|
||||
connect(folder, SIGNAL(scheduleToSync(const QString&)), SLOT(slotScheduleSync(const QString&)));
|
||||
connect(folder, SIGNAL(syncStateChange()), _folderChangeSignalMapper, SLOT(map()));
|
||||
connect(folder, SIGNAL(syncStarted()), SLOT(slotFolderSyncStarted()));
|
||||
connect(folder, SIGNAL(syncFinished(SyncResult)), SLOT(slotFolderSyncFinished(SyncResult)));
|
||||
|
@ -239,13 +239,23 @@ SyncResult FolderMan::syncResult( const QString& alias )
|
|||
* if a folder wants to be synced, it calls this slot and is added
|
||||
* to the queue. The slot to actually start a sync is called afterwards.
|
||||
*/
|
||||
void FolderMan::slotScheduleSync( Folder *folder )
|
||||
void FolderMan::slotScheduleSync( const QString& alias )
|
||||
{
|
||||
if( ! folder ) return;
|
||||
if( alias.isEmpty() ) return;
|
||||
|
||||
qDebug() << "Schedule folder " << folder->alias() << " to sync!";
|
||||
_scheduleQueue.enqueue( folder );
|
||||
slotScheduleFolderSync();
|
||||
qDebug() << "Schedule folder " << alias << " to sync!";
|
||||
if( _currentSyncFolder == alias ) {
|
||||
// the current folder is currently syncing.
|
||||
qDebug() << "OOOOOOOOOOOOOOOOOOOOOOO Folder is currently syncing";
|
||||
}
|
||||
|
||||
if( _scheduleQueue.contains( alias ) ) {
|
||||
qDebug() << " II> Sync for folder " << alias << " already scheduled, do not enqueue!";
|
||||
} else {
|
||||
_scheduleQueue.append( alias );
|
||||
|
||||
slotScheduleFolderSync();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -255,20 +265,24 @@ void FolderMan::slotScheduleSync( Folder *folder )
|
|||
*/
|
||||
void FolderMan::slotScheduleFolderSync()
|
||||
{
|
||||
if( _currentSyncFolder ) {
|
||||
if( !_currentSyncFolder.isEmpty() ) {
|
||||
qDebug() << "Currently folder " << _currentSyncFolder << " is running, wait for finish!";
|
||||
return;
|
||||
}
|
||||
|
||||
if( ! _scheduleQueue.isEmpty() ) {
|
||||
_currentSyncFolder = _scheduleQueue.dequeue();
|
||||
_currentSyncFolder->startSync( QStringList() );
|
||||
const QString alias = _scheduleQueue.takeFirst();
|
||||
if( _folderMap.contains( alias ) ) {
|
||||
Folder *f = _folderMap[alias];
|
||||
_currentSyncFolder = alias;
|
||||
f->startSync( QStringList() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FolderMan::slotFolderSyncStarted( )
|
||||
{
|
||||
qDebug() << ">===================================== sync started for " << _currentSyncFolder->alias();
|
||||
qDebug() << ">===================================== sync started for " << _currentSyncFolder;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -277,8 +291,16 @@ void FolderMan::slotFolderSyncStarted( )
|
|||
*/
|
||||
void FolderMan::slotFolderSyncFinished( const SyncResult& )
|
||||
{
|
||||
qDebug() << "<===================================== sync finsihed for " << _currentSyncFolder->alias();
|
||||
_currentSyncFolder = 0;
|
||||
qDebug() << "<===================================== sync finsihed for " << _currentSyncFolder;
|
||||
|
||||
// check if the folder is scheduled to be deleted. The flag is set in slotRemoveFolder
|
||||
// after the user clicked to delete it.
|
||||
if( _folderToDelete ) {
|
||||
qDebug() << " !! This folder is going to be deleted now!";
|
||||
removeFolder( _currentSyncFolder );
|
||||
_folderToDelete = false;
|
||||
}
|
||||
_currentSyncFolder = QString();
|
||||
QTimer::singleShot(200, this, SLOT(slotScheduleFolderSync()));
|
||||
}
|
||||
|
||||
|
@ -315,10 +337,21 @@ void FolderMan::slotRemoveFolder( const QString& alias )
|
|||
{
|
||||
if( alias.isEmpty() ) return;
|
||||
|
||||
if( _currentSyncFolder == alias ) {
|
||||
// attention: sync is currently running!
|
||||
_folderToDelete = true; // flag for the sync finished slot
|
||||
} else {
|
||||
removeFolder(alias);
|
||||
}
|
||||
}
|
||||
|
||||
// remove a folder from the map. Should be sure n
|
||||
void FolderMan::removeFolder( const QString& alias )
|
||||
{
|
||||
if( _folderMap.contains( alias )) {
|
||||
qDebug() << "Removing " << alias;
|
||||
Folder *f = _folderMap.take( alias );
|
||||
delete f;
|
||||
f->deleteLater();
|
||||
} else {
|
||||
qDebug() << "!! Can not remove " << alias << ", not in folderMap.";
|
||||
}
|
||||
|
@ -328,8 +361,6 @@ void FolderMan::slotRemoveFolder( const QString& alias )
|
|||
qDebug() << "Remove folder config file " << file.fileName();
|
||||
file.remove();
|
||||
}
|
||||
// FIXME: Refresh GUI elements
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ public slots:
|
|||
|
||||
private slots:
|
||||
// slot to add a folder to the syncing queue
|
||||
void slotScheduleSync( Folder* );
|
||||
void slotScheduleSync( const QString & );
|
||||
|
||||
// slot to take the next folder from queue and start syncing.
|
||||
void slotScheduleFolderSync();
|
||||
|
@ -91,19 +91,22 @@ private:
|
|||
// and create the folders
|
||||
int setupKnownFolders();
|
||||
|
||||
void removeFolder( const QString& );
|
||||
|
||||
|
||||
// creates a folder for a specific
|
||||
// configuration
|
||||
Folder* setupFolderFromConfigFile(const QString & );
|
||||
|
||||
FolderWatcher *_configFolderWatcher;
|
||||
Folder::Map _folderMap;
|
||||
Folder::Map _folderMap;
|
||||
QHash<QString, bool> _folderEnabledMap;
|
||||
QString _folderConfigPath;
|
||||
QString _folderConfigPath;
|
||||
OwncloudSetup *_ownCloudSetup;
|
||||
QSignalMapper *_folderChangeSignalMapper;
|
||||
Folder *_currentSyncFolder;
|
||||
QQueue<Folder*> _scheduleQueue;
|
||||
QString _currentSyncFolder;
|
||||
QStringList _scheduleQueue;
|
||||
bool _folderToDelete;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче