SSH: Use Qt5-style connects

The heavy lifting was done by clazy.

Change-Id: I04261849c92c54990f9f142fe541d984c5fb21d3
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
This commit is contained in:
Orgad Shaneh
2016-06-07 22:04:26 +03:00
committed by Orgad Shaneh
parent 4cb94be1b5
commit 35036110ce
10 changed files with 50 additions and 47 deletions

View File

@@ -284,19 +284,20 @@ void SftpFileSystemModel::handleSshConnectionFailure()
void SftpFileSystemModel::handleSftpChannelInitialized() void SftpFileSystemModel::handleSftpChannelInitialized()
{ {
connect(d->sftpChannel.data(), connect(d->sftpChannel.data(),
SIGNAL(fileInfoAvailable(QSsh::SftpJobId,QList<QSsh::SftpFileInfo>)), &SftpChannel::fileInfoAvailable,
SLOT(handleFileInfo(QSsh::SftpJobId,QList<QSsh::SftpFileInfo>))); this, &SftpFileSystemModel::handleFileInfo);
connect(d->sftpChannel.data(), SIGNAL(finished(QSsh::SftpJobId,QString)), connect(d->sftpChannel.data(), &SftpChannel::finished,
SLOT(handleSftpJobFinished(QSsh::SftpJobId,QString))); this, &SftpFileSystemModel::handleSftpJobFinished);
statRootDirectory(); statRootDirectory();
} }
void SftpFileSystemModel::handleSshConnectionEstablished() void SftpFileSystemModel::handleSshConnectionEstablished()
{ {
d->sftpChannel = d->sshConnection->createSftpChannel(); d->sftpChannel = d->sshConnection->createSftpChannel();
connect(d->sftpChannel.data(), SIGNAL(initialized()), SLOT(handleSftpChannelInitialized())); connect(d->sftpChannel.data(), &SftpChannel::initialized,
connect(d->sftpChannel.data(), SIGNAL(channelError(QString)), this, &SftpFileSystemModel::handleSftpChannelInitialized);
SLOT(handleSftpChannelError(QString))); connect(d->sftpChannel.data(), &SftpChannel::channelError,
this, &SftpFileSystemModel::handleSftpChannelError);
d->sftpChannel->initialize(); d->sftpChannel->initialize();
} }

View File

@@ -76,7 +76,7 @@ signals:
// Success <=> error.isEmpty(). // Success <=> error.isEmpty().
void sftpOperationFinished(QSsh::SftpJobId, const QString &error); void sftpOperationFinished(QSsh::SftpJobId, const QString &error);
private slots: private:
void handleSshConnectionEstablished(); void handleSshConnectionEstablished();
void handleSshConnectionFailure(); void handleSshConnectionFailure();
void handleSftpChannelInitialized(); void handleSftpChannelInitialized();
@@ -84,7 +84,6 @@ private slots:
void handleFileInfo(QSsh::SftpJobId jobId, const QList<QSsh::SftpFileInfo> &fileInfoList); void handleFileInfo(QSsh::SftpJobId jobId, const QList<QSsh::SftpFileInfo> &fileInfoList);
void handleSftpJobFinished(QSsh::SftpJobId jobId, const QString &errorMessage); void handleSftpJobFinished(QSsh::SftpJobId jobId, const QString &errorMessage);
private:
int columnCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const;
Qt::ItemFlags flags(const QModelIndex &index) const; Qt::ItemFlags flags(const QModelIndex &index) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;

View File

@@ -281,7 +281,7 @@ SshTcpIpForwardServer::Ptr SshChannelManager::createForwardServer(const QString
void SshChannelManager::insertChannel(AbstractSshChannel *priv, void SshChannelManager::insertChannel(AbstractSshChannel *priv,
const QSharedPointer<QObject> &pub) const QSharedPointer<QObject> &pub)
{ {
connect(priv, SIGNAL(timeout()), this, SIGNAL(timeout())); connect(priv, &AbstractSshChannel::timeout, this, &SshChannelManager::timeout);
m_channels.insert(priv->localChannelId(), priv); m_channels.insert(priv->localChannelId(), priv);
m_sessions.insert(priv, pub); m_sessions.insert(priv, pub);
} }

View File

@@ -100,14 +100,14 @@ SshConnection::SshConnection(const SshConnectionParameters &serverInfo, QObject
qRegisterMetaType<QList <QSsh::SftpFileInfo> >("QList<QSsh::SftpFileInfo>"); qRegisterMetaType<QList <QSsh::SftpFileInfo> >("QList<QSsh::SftpFileInfo>");
d = new Internal::SshConnectionPrivate(this, serverInfo); d = new Internal::SshConnectionPrivate(this, serverInfo);
connect(d, SIGNAL(connected()), this, SIGNAL(connected()), connect(d, &Internal::SshConnectionPrivate::connected, this, &SshConnection::connected,
Qt::QueuedConnection); Qt::QueuedConnection);
connect(d, SIGNAL(dataAvailable(QString)), this, connect(d, &Internal::SshConnectionPrivate::dataAvailable, this,
SIGNAL(dataAvailable(QString)), Qt::QueuedConnection); &SshConnection::dataAvailable, Qt::QueuedConnection);
connect(d, SIGNAL(disconnected()), this, SIGNAL(disconnected()), connect(d, &Internal::SshConnectionPrivate::disconnected, this, &SshConnection::disconnected,
Qt::QueuedConnection); Qt::QueuedConnection);
connect(d, SIGNAL(error(QSsh::SshError)), this, connect(d, &Internal::SshConnectionPrivate::error, this,
SIGNAL(error(QSsh::SshError)), Qt::QueuedConnection); &SshConnection::error, Qt::QueuedConnection);
} }
void SshConnection::connectToHost() void SshConnection::connectToHost()
@@ -135,7 +135,7 @@ SshConnection::State SshConnection::state() const
SshError SshConnection::errorState() const SshError SshConnection::errorState() const
{ {
return d->error(); return d->errorState();
} }
QString SshConnection::errorString() const QString SshConnection::errorString() const
@@ -227,7 +227,8 @@ SshConnectionPrivate::SshConnectionPrivate(SshConnection *conn,
m_timeoutTimer.setInterval(m_connParams.timeout * 1000); m_timeoutTimer.setInterval(m_connParams.timeout * 1000);
m_keepAliveTimer.setSingleShot(true); m_keepAliveTimer.setSingleShot(true);
m_keepAliveTimer.setInterval(10000); m_keepAliveTimer.setInterval(10000);
connect(m_channelManager, SIGNAL(timeout()), this, SLOT(handleTimeout())); connect(m_channelManager, &SshChannelManager::timeout,
this, &SshConnectionPrivate::handleTimeout);
} }
SshConnectionPrivate::~SshConnectionPrivate() SshConnectionPrivate::~SshConnectionPrivate()
@@ -589,7 +590,7 @@ void SshConnectionPrivate::handleUserAuthSuccessPacket()
m_timeoutTimer.stop(); m_timeoutTimer.stop();
emit connected(); emit connected();
m_lastInvalidMsgSeqNr = InvalidSeqNr; m_lastInvalidMsgSeqNr = InvalidSeqNr;
connect(&m_keepAliveTimer, SIGNAL(timeout()), SLOT(sendKeepAlivePacket())); connect(&m_keepAliveTimer, &QTimer::timeout, this, &SshConnectionPrivate::sendKeepAlivePacket);
m_keepAliveTimer.start(); m_keepAliveTimer.start();
} }
@@ -767,13 +768,16 @@ void SshConnectionPrivate::connectToHost()
return; return;
} }
connect(m_socket, SIGNAL(connected()), this, SLOT(handleSocketConnected())); connect(m_socket, &QAbstractSocket::connected,
connect(m_socket, SIGNAL(readyRead()), this, SLOT(handleIncomingData())); this, &SshConnectionPrivate::handleSocketConnected);
connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, connect(m_socket, &QIODevice::readyRead,
SLOT(handleSocketError())); this, &SshConnectionPrivate::handleIncomingData);
connect(m_socket, SIGNAL(disconnected()), this, connect(m_socket,
SLOT(handleSocketDisconnected())); static_cast<void (QAbstractSocket::*)(QAbstractSocket::SocketError)>(&QAbstractSocket::error),
connect(&m_timeoutTimer, SIGNAL(timeout()), this, SLOT(handleTimeout())); this, &SshConnectionPrivate::handleSocketError);
connect(m_socket, &QAbstractSocket::disconnected,
this, &SshConnectionPrivate::handleSocketDisconnected);
connect(&m_timeoutTimer, &QTimer::timeout, this, &SshConnectionPrivate::handleTimeout);
m_state = SocketConnecting; m_state = SocketConnecting;
m_keyExchangeState = NoKeyExchange; m_keyExchangeState = NoKeyExchange;
m_timeoutTimer.start(); m_timeoutTimer.start();

View File

@@ -90,7 +90,7 @@ public:
quint16 remotePort); quint16 remotePort);
SshStateInternal state() const { return m_state; } SshStateInternal state() const { return m_state; }
SshError error() const { return m_error; } SshError errorState() const { return m_error; }
QString errorString() const { return m_errorString; } QString errorString() const { return m_errorString; }
signals: signals:
@@ -100,12 +100,12 @@ signals:
void error(QSsh::SshError); void error(QSsh::SshError);
private: private:
Q_SLOT void handleSocketConnected(); void handleSocketConnected();
Q_SLOT void handleIncomingData(); void handleIncomingData();
Q_SLOT void handleSocketError(); void handleSocketError();
Q_SLOT void handleSocketDisconnected(); void handleSocketDisconnected();
Q_SLOT void handleTimeout(); void handleTimeout();
Q_SLOT void sendKeepAlivePacket(); void sendKeepAlivePacket();
void handleServerId(); void handleServerId();
void handlePackets(); void handlePackets();

View File

@@ -194,7 +194,6 @@ private:
connection->moveToThread(qobject_cast<QThread *>(threadObj)); connection->moveToThread(qobject_cast<QThread *>(threadObj));
} }
private slots:
void cleanup() void cleanup()
{ {
QMutexLocker locker(&m_listMutex); QMutexLocker locker(&m_listMutex);

View File

@@ -44,12 +44,10 @@ public:
QString privateKeyFilePath() const; QString privateKeyFilePath() const;
QString publicKeyFilePath() const; QString publicKeyFilePath() const;
private slots: private:
void keyTypeChanged(); void keyTypeChanged();
void generateKeys(); void generateKeys();
void handleBrowseButtonClicked(); void handleBrowseButtonClicked();
private:
void setPrivateKeyFile(const QString &filePath); void setPrivateKeyFile(const QString &filePath);
void saveKeys(); void saveKeys();
bool userForbidsOverwriting(); bool userForbidsOverwriting();

View File

@@ -127,10 +127,14 @@ void SshRemoteProcessRunner::handleConnected()
setState(Connected); setState(Connected);
d->m_process = d->m_connection->createRemoteProcess(d->m_command); d->m_process = d->m_connection->createRemoteProcess(d->m_command);
connect(d->m_process.data(), SIGNAL(started()), SLOT(handleProcessStarted())); connect(d->m_process.data(), &SshRemoteProcess::started,
connect(d->m_process.data(), SIGNAL(closed(int)), SLOT(handleProcessFinished(int))); this, &SshRemoteProcessRunner::handleProcessStarted);
connect(d->m_process.data(), SIGNAL(readyReadStandardOutput()), SLOT(handleStdout())); connect(d->m_process.data(), &SshRemoteProcess::closed,
connect(d->m_process.data(), SIGNAL(readyReadStandardError()), SLOT(handleStderr())); this, &SshRemoteProcessRunner::handleProcessFinished);
connect(d->m_process.data(), &SshRemoteProcess::readyReadStandardOutput,
this, &SshRemoteProcessRunner::handleStdout);
connect(d->m_process.data(), &SshRemoteProcess::readyReadStandardError,
this, &SshRemoteProcessRunner::handleStderr);
if (d->m_runInTerminal) if (d->m_runInTerminal)
d->m_process->requestTerminal(d->m_terminal); d->m_process->requestTerminal(d->m_terminal);
d->m_process->start(); d->m_process->start();

View File

@@ -65,7 +65,7 @@ signals:
void readyReadStandardError(); void readyReadStandardError();
void processClosed(int exitStatus); // values are of type SshRemoteProcess::ExitStatus void processClosed(int exitStatus); // values are of type SshRemoteProcess::ExitStatus
private slots: private:
void handleConnected(); void handleConnected();
void handleConnectionError(QSsh::SshError error); void handleConnectionError(QSsh::SshError error);
void handleDisconnected(); void handleDisconnected();
@@ -73,8 +73,6 @@ private slots:
void handleProcessFinished(int exitStatus); void handleProcessFinished(int exitStatus);
void handleStdout(); void handleStdout();
void handleStderr(); void handleStderr();
private:
void runInternal(const QByteArray &command, const QSsh::SshConnectionParameters &sshParams); void runInternal(const QByteArray &command, const QSsh::SshConnectionParameters &sshParams);
void setState(int newState); void setState(int newState);

View File

@@ -64,9 +64,6 @@ signals:
void error(const QString &reason); void error(const QString &reason);
void closed(); void closed();
private slots:
void handleEof();
protected: protected:
void handleOpenFailureInternal(const QString &reason) override; void handleOpenFailureInternal(const QString &reason) override;
void handleChannelDataInternal(const QByteArray &data) override; void handleChannelDataInternal(const QByteArray &data) override;
@@ -76,6 +73,9 @@ protected:
void closeHook() override; void closeHook() override;
QByteArray m_data; QByteArray m_data;
private:
void handleEof();
}; };
} // namespace Internal } // namespace Internal