Commit 7ac2f876 authored by Slava Monich's avatar Slava Monich

[transfer-engine] Prevent premature exits

If TransferEnginePrivate::exitSafely() finds out that activity is still
ongoing it should cancel previously sheduled delayedExitSafely() call.
Otherwise delayedExitSafely() may be invoked between two syncs causing
nemo-transfer-engine to exit and get immediately restarted by D-Bus which
isn't something we really want. We want to exit when all the activity has
really calmed down.
parent 3236670a
......@@ -147,6 +147,11 @@ TransferEnginePrivate::TransferEnginePrivate(TransferEngine *parent):
m_fileWatcherTimer->setSingleShot(true);
connect(m_fileWatcherTimer, SIGNAL(timeout()), this, SLOT(enabledPluginsCheck()));
m_delayedExitTimer = new QTimer(this);
m_delayedExitTimer->setSingleShot(true);
m_delayedExitTimer->setInterval(5000);
connect(m_delayedExitTimer, SIGNAL(timeout()), this, SLOT(delayedExitSafely()));
m_fileWatcher = new QFileSystemWatcher(this);
m_fileWatcher->addPath(SHARE_PLUGINS_PATH);
connect(m_fileWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(pluginDirChanged()));
......@@ -177,19 +182,17 @@ void TransferEnginePrivate::pluginDirChanged()
void TransferEnginePrivate::exitSafely()
{
if (!m_activityMonitor->activeTransfers()) {
qDebug() << Q_FUNC_INFO;
QTimer::singleShot(2000, this, SLOT(delayedExitSafely()));
qDebug() << "Scheduling exit in" << m_delayedExitTimer->interval() << "ms";
m_delayedExitTimer->start();
} else {
m_delayedExitTimer->stop();
}
}
void TransferEnginePrivate::delayedExitSafely()
{
if (m_activityMonitor->activeTransfers()) {
qDebug() << "Keeping transfer engine alive, transfers still ongoing";
} else {
qDebug() << "Stopping transfer engine";
qApp->exit();
}
qDebug() << "Stopping transfer engine";
qApp->exit();
}
void TransferEnginePrivate::enabledPluginsCheck()
......
......@@ -83,8 +83,6 @@ private:
QTimer *m_timer;
};
class TransferEnginePrivate: QObject
{
Q_OBJECT
......@@ -133,6 +131,7 @@ public:
MediaTransferInterface *loadPlugin(const QString &pluginId) const;
QString mediaFileOrResourceName(MediaItem *mediaItem) const;
private:
QMap <MediaTransferInterface*, int> m_plugins;
QMap <int, TransferEngineData::TransferType> m_keyTypeCache;
bool m_notificationsEnabled;
......@@ -141,6 +140,7 @@ public:
Accounts::Manager *m_accountManager;
QFileSystemWatcher *m_fileWatcher;
QTimer *m_fileWatcherTimer;
QTimer *m_delayedExitTimer;
QSettings m_settings;
ClientActivityMonitor *m_activityMonitor;
TransferEngine *q_ptr;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment