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:
Klaas Freitag 2012-03-29 10:13:19 +02:00
parent d938c531c8
commit 3fb471edad
4 changed files with 58 additions and 24 deletions

View file

@ -187,7 +187,7 @@ void Folder::evaluateSync(const QStringList &pathList)
// sync finished. // sync finished.
qDebug() << "* " << alias() << "Poll timer disabled"; qDebug() << "* " << alias() << "Poll timer disabled";
_pollTimer->stop(); _pollTimer->stop();
emit scheduleToSync( this ); emit scheduleToSync( alias() );
// startSync( pathList ); // startSync( pathList );
} }

View file

@ -160,7 +160,7 @@ signals:
void syncStateChange(); void syncStateChange();
void syncStarted(); void syncStarted();
void syncFinished(const SyncResult &result); void syncFinished(const SyncResult &result);
void scheduleToSync(Folder*); void scheduleToSync( const QString& );
protected: protected:
#ifdef USE_WATCHER #ifdef USE_WATCHER

View file

@ -26,8 +26,8 @@
namespace Mirall { namespace Mirall {
FolderMan::FolderMan(QObject *parent) : FolderMan::FolderMan(QObject *parent) :
QObject(parent) QObject(parent),
, _currentSyncFolder(0) _folderToDelete(false)
{ {
// if QDir::mkpath would not be so stupid, I would not need to have this // if QDir::mkpath would not be so stupid, I would not need to have this
// duplication of folderConfigPath() here // duplication of folderConfigPath() here
@ -174,7 +174,7 @@ Folder* FolderMan::setupFolderFromConfigFile(const QString &file) {
qDebug() << "Adding folder to Folder Map " << folder; qDebug() << "Adding folder to Folder Map " << folder;
/* Use a signal mapper to connect the signals to the alias */ /* 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(syncStateChange()), _folderChangeSignalMapper, SLOT(map()));
connect(folder, SIGNAL(syncStarted()), SLOT(slotFolderSyncStarted())); connect(folder, SIGNAL(syncStarted()), SLOT(slotFolderSyncStarted()));
connect(folder, SIGNAL(syncFinished(SyncResult)), SLOT(slotFolderSyncFinished(SyncResult))); connect(folder, SIGNAL(syncFinished(SyncResult)), SLOT(slotFolderSyncFinished(SyncResult)));
@ -239,14 +239,24 @@ SyncResult FolderMan::syncResult( const QString& alias )
* if a folder wants to be synced, it calls this slot and is added * 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. * 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 " << 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 );
qDebug() << "Schedule folder " << folder->alias() << " to sync!";
_scheduleQueue.enqueue( folder );
slotScheduleFolderSync(); slotScheduleFolderSync();
} }
}
/* /*
* slot to start folder syncs. * slot to start folder syncs.
@ -255,20 +265,24 @@ void FolderMan::slotScheduleSync( Folder *folder )
*/ */
void FolderMan::slotScheduleFolderSync() void FolderMan::slotScheduleFolderSync()
{ {
if( _currentSyncFolder ) { if( !_currentSyncFolder.isEmpty() ) {
qDebug() << "Currently folder " << _currentSyncFolder << " is running, wait for finish!"; qDebug() << "Currently folder " << _currentSyncFolder << " is running, wait for finish!";
return; return;
} }
if( ! _scheduleQueue.isEmpty() ) { if( ! _scheduleQueue.isEmpty() ) {
_currentSyncFolder = _scheduleQueue.dequeue(); const QString alias = _scheduleQueue.takeFirst();
_currentSyncFolder->startSync( QStringList() ); if( _folderMap.contains( alias ) ) {
Folder *f = _folderMap[alias];
_currentSyncFolder = alias;
f->startSync( QStringList() );
}
} }
} }
void FolderMan::slotFolderSyncStarted( ) 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& ) void FolderMan::slotFolderSyncFinished( const SyncResult& )
{ {
qDebug() << "<===================================== sync finsihed for " << _currentSyncFolder->alias(); qDebug() << "<===================================== sync finsihed for " << _currentSyncFolder;
_currentSyncFolder = 0;
// 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())); QTimer::singleShot(200, this, SLOT(slotScheduleFolderSync()));
} }
@ -315,10 +337,21 @@ void FolderMan::slotRemoveFolder( const QString& alias )
{ {
if( alias.isEmpty() ) return; 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 )) { if( _folderMap.contains( alias )) {
qDebug() << "Removing " << alias; qDebug() << "Removing " << alias;
Folder *f = _folderMap.take( alias ); Folder *f = _folderMap.take( alias );
delete f; f->deleteLater();
} else { } else {
qDebug() << "!! Can not remove " << alias << ", not in folderMap."; 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(); qDebug() << "Remove folder config file " << file.fileName();
file.remove(); file.remove();
} }
// FIXME: Refresh GUI elements
} }
} }

View file

@ -81,7 +81,7 @@ public slots:
private slots: private slots:
// slot to add a folder to the syncing queue // 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. // slot to take the next folder from queue and start syncing.
void slotScheduleFolderSync(); void slotScheduleFolderSync();
@ -91,6 +91,8 @@ private:
// and create the folders // and create the folders
int setupKnownFolders(); int setupKnownFolders();
void removeFolder( const QString& );
// creates a folder for a specific // creates a folder for a specific
// configuration // configuration
@ -102,8 +104,9 @@ private:
QString _folderConfigPath; QString _folderConfigPath;
OwncloudSetup *_ownCloudSetup; OwncloudSetup *_ownCloudSetup;
QSignalMapper *_folderChangeSignalMapper; QSignalMapper *_folderChangeSignalMapper;
Folder *_currentSyncFolder; QString _currentSyncFolder;
QQueue<Folder*> _scheduleQueue; QStringList _scheduleQueue;
bool _folderToDelete;
}; };
} }