Skip to content

Commit

Permalink
[transfer-engine] Prevent premature exits
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
monich committed Sep 30, 2014
1 parent 3236670 commit 7ac2f87
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
19 changes: 11 additions & 8 deletions src/transferengine.cpp
Expand Up @@ -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()));
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/transferengine_p.h
Expand Up @@ -83,8 +83,6 @@ public Q_SLOTS:
QTimer *m_timer;
};



class TransferEnginePrivate: QObject
{
Q_OBJECT
Expand Down Expand Up @@ -133,6 +131,7 @@ public Q_SLOTS:
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;
Expand All @@ -141,6 +140,7 @@ public Q_SLOTS:
Accounts::Manager *m_accountManager;
QFileSystemWatcher *m_fileWatcher;
QTimer *m_fileWatcherTimer;
QTimer *m_delayedExitTimer;
QSettings m_settings;
ClientActivityMonitor *m_activityMonitor;
TransferEngine *q_ptr;
Expand Down

0 comments on commit 7ac2f87

Please sign in to comment.