SshConnection: Reduce the scope of some variables

The file watching objects are temporary in nature and don't need to be
class members.

Change-Id: I845e4f8599a338517f6fc26ffd9d0061466ba33e
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
Christian Kandeler
2018-12-17 14:08:13 +01:00
parent b958b9b669
commit 068aff8a33

View File

@@ -149,9 +149,7 @@ struct SshConnection::SshConnectionPrivate
SshConnectionInfo connInfo; SshConnectionInfo connInfo;
SshProcess masterProcess; SshProcess masterProcess;
QString errorString; QString errorString;
QTimer socketWatcherTimer;
std::unique_ptr<TemporaryDirectory> masterSocketDir; std::unique_ptr<TemporaryDirectory> masterSocketDir;
FileSystemWatcher *socketWatcher = nullptr;
State state = Unconnected; State state = Unconnected;
const bool sharingEnabled = SshSettings::connectionSharingEnabled(); const bool sharingEnabled = SshSettings::connectionSharingEnabled();
}; };
@@ -163,30 +161,31 @@ SshConnection::SshConnection(const SshConnectionParameters &serverInfo, QObject
qRegisterMetaType<QSsh::SftpFileInfo>("QSsh::SftpFileInfo"); qRegisterMetaType<QSsh::SftpFileInfo>("QSsh::SftpFileInfo");
qRegisterMetaType<QList <QSsh::SftpFileInfo> >("QList<QSsh::SftpFileInfo>"); qRegisterMetaType<QList <QSsh::SftpFileInfo> >("QList<QSsh::SftpFileInfo>");
d->connParams = serverInfo; d->connParams = serverInfo;
d->socketWatcher = new FileSystemWatcher(this);
connect(&d->masterProcess, &QProcess::started, [this] { connect(&d->masterProcess, &QProcess::started, [this] {
QFileInfo socketInfo(d->socketFilePath()); QFileInfo socketInfo(d->socketFilePath());
if (socketInfo.exists()) { if (socketInfo.exists()) {
emitConnected(); emitConnected();
return; return;
} }
const auto socketFileChecker = [this] { auto * const socketWatcher = new FileSystemWatcher(this);
auto * const socketWatcherTimer = new QTimer(this);
const auto socketFileChecker = [this, socketWatcher, socketWatcherTimer] {
if (!QFileInfo::exists(d->socketFilePath())) if (!QFileInfo::exists(d->socketFilePath()))
return; return;
d->socketWatcher->disconnect(); socketWatcher->disconnect();
d->socketWatcher->deleteLater(); socketWatcher->deleteLater();
d->socketWatcher = nullptr; socketWatcherTimer->disconnect();
d->socketWatcherTimer.disconnect(); socketWatcherTimer->stop();
d->socketWatcherTimer.stop(); socketWatcherTimer->deleteLater();
emitConnected(); emitConnected();
}; };
connect(d->socketWatcher, &FileSystemWatcher::directoryChanged, socketFileChecker); connect(socketWatcher, &FileSystemWatcher::directoryChanged, socketFileChecker);
d->socketWatcher->addDirectory(socketInfo.path(), FileSystemWatcher::WatchAllChanges); socketWatcher->addDirectory(socketInfo.path(), FileSystemWatcher::WatchAllChanges);
if (HostOsInfo::isMacHost()) { if (HostOsInfo::isMacHost()) {
// QTBUG-72455 // QTBUG-72455
d->socketWatcherTimer.setInterval(1000); socketWatcherTimer->setInterval(1000);
connect(&d->socketWatcherTimer, &QTimer::timeout, socketFileChecker); connect(socketWatcherTimer, &QTimer::timeout, socketFileChecker);
d->socketWatcherTimer.start(); socketWatcherTimer->start();
} }
}); });
connect(&d->masterProcess, &QProcess::errorOccurred, [this] (QProcess::ProcessError error) { connect(&d->masterProcess, &QProcess::errorOccurred, [this] (QProcess::ProcessError error) {