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

View file

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

View file

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