Make FolderMan a member of the application

The goal here is that it is going to be destroyed with the application
It need to be destoyed so the folder are destroyed, which is required
for properly finishing the sync while exiting.

It must not be destroyed after the application because the QSQLite plugin
may be already destroyed in that case.

Since the constructor of FolderMan is called earlier, we can't call the
config file too early

 fixes 1793
This commit is contained in:
Olivier Goffart 2014-05-26 14:34:08 +02:00
parent 50ce0f9681
commit 8a671c40d1
3 changed files with 18 additions and 16 deletions

View file

@ -28,6 +28,7 @@
#include "mirall/connectionvalidator.h" #include "mirall/connectionvalidator.h"
#include "mirall/progressdispatcher.h" #include "mirall/progressdispatcher.h"
#include "mirall/clientproxy.h" #include "mirall/clientproxy.h"
#include "mirall/folderman.h"
class QMessageBox; class QMessageBox;
class QSystemTrayIcon; class QSystemTrayIcon;
@ -107,6 +108,8 @@ private:
QTimer _checkConnectionTimer; QTimer _checkConnectionTimer;
FolderMan folderManager;
friend class ownCloudGui; // for _startupNetworkError friend class ownCloudGui; // for _startupNetworkError
}; };

View file

@ -41,13 +41,6 @@ FolderMan::FolderMan(QObject *parent) :
QObject(parent), QObject(parent),
_syncEnabled( true ) _syncEnabled( true )
{ {
// if QDir::mkpath would not be so stupid, I would not need to have this
// duplication of folderConfigPath() here
MirallConfigFile cfg;
QDir storageDir(cfg.configPath());
storageDir.mkpath(QLatin1String("folders"));
_folderConfigPath = cfg.configPath() + QLatin1String("folders");
_folderChangeSignalMapper = new QSignalMapper(this); _folderChangeSignalMapper = new QSignalMapper(this);
connect(_folderChangeSignalMapper, SIGNAL(mapped(const QString &)), connect(_folderChangeSignalMapper, SIGNAL(mapped(const QString &)),
this, SIGNAL(folderSyncStateChange(const QString &))); this, SIGNAL(folderSyncStateChange(const QString &)));
@ -55,15 +48,14 @@ FolderMan::FolderMan(QObject *parent) :
_folderWatcherSignalMapper = new QSignalMapper(this); _folderWatcherSignalMapper = new QSignalMapper(this);
connect(_folderWatcherSignalMapper, SIGNAL(mapped(const QString&)), connect(_folderWatcherSignalMapper, SIGNAL(mapped(const QString&)),
this, SLOT(slotScheduleSync(const QString&))); this, SLOT(slotScheduleSync(const QString&)));
ne_sock_init();
Q_ASSERT(!_instance);
_instance = this;
} }
FolderMan *FolderMan::instance() FolderMan *FolderMan::instance()
{ {
if(!_instance) {
_instance = new FolderMan;
ne_sock_init();
}
return _instance; return _instance;
} }
@ -71,6 +63,7 @@ FolderMan::~FolderMan()
{ {
qDeleteAll(_folderMap); qDeleteAll(_folderMap);
ne_sock_exit(); ne_sock_exit();
_instance = 0;
} }
Mirall::Folder::Map FolderMan::map() Mirall::Folder::Map FolderMan::map()
@ -144,6 +137,11 @@ int FolderMan::setupFolders()
unloadAllFolders(); unloadAllFolders();
MirallConfigFile cfg;
QDir storageDir(cfg.configPath());
storageDir.mkpath(QLatin1String("folders"));
_folderConfigPath = cfg.configPath() + QLatin1String("folders");
QDir dir( _folderConfigPath ); QDir dir( _folderConfigPath );
//We need to include hidden files just in case the alias starts with '.' //We need to include hidden files just in case the alias starts with '.'
dir.setFilter(QDir::Files | QDir::Hidden); dir.setFilter(QDir::Files | QDir::Hidden);

View file

@ -30,12 +30,13 @@ class SyncResult;
namespace Mirall { namespace Mirall {
class Application;
class OWNCLOUDSYNC_EXPORT FolderMan : public QObject class OWNCLOUDSYNC_EXPORT FolderMan : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
static FolderMan* instance(); static FolderMan* instance();
~FolderMan();
int setupFolders(); int setupFolders();
@ -144,10 +145,10 @@ private:
QQueue<QString> _scheduleQueue; QQueue<QString> _scheduleQueue;
QMap<QString, FolderWatcher*> _folderWatchers; QMap<QString, FolderWatcher*> _folderWatchers;
explicit FolderMan(QObject *parent = 0);
static FolderMan *_instance; static FolderMan *_instance;
explicit FolderMan(QObject *parent = 0);
~FolderMan();
friend class Mirall::Application;
}; };
} // namespace Mirall } // namespace Mirall