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