Commit 72535ecf authored by Jean Vincent's avatar Jean Vincent Committed by Albert Vaca Cintora

Make member variable names, & placement and * placement more coherent

Summary:
Change all member variables to the form m_fooBar because it is the preferred form in Qt (it was half and half between this and mFooBar, and a minority didn't have anything).
Place all references and pointers on the side of the type since it is the majority.

Basically:
 - mFoo -> m_foo
 - foo -> m_foo (if it is a member variable)
 - Type &ref -> Type& ref
 - Type *ptr -> Type* ptr

Reviewers: #kde_connect, nicolasfella, albertvaka

Reviewed By: #kde_connect, nicolasfella, albertvaka

Subscribers: albertvaka, #kde_connect

Tags: #kde_connect

Differential Revision: https://phabricator.kde.org/D7312
parent 5d4821fb
......@@ -23,7 +23,7 @@
#include <KAboutData>
#include <KLocalizedString>
int main(int argc, char *argv[])
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
KAboutData aboutData(QStringLiteral("kdeconnect.app"), i18n("KDE Connect App"), QStringLiteral("1.0"), i18n("KDE Connect App"), KAboutLicense::GPL, i18n("(c) 2015, Aleix Pol Gonzalez"));
......
......@@ -11,7 +11,6 @@ Name[el]=Εφαρμογή KDE Connect
Name[en_GB]=KDE Connect Application
Name[es]=Aplicación KDE Connect
Name[et]=KDE Connecti rakendus
Name[eu]=KDE Connect aplikazioa
Name[fi]=KDE Connect -sovellus
Name[fr]=Application KDE Connect
Name[gl]=Aplicativo de KDE Connect
......@@ -48,7 +47,6 @@ GenericName[el]=Συγχρονισμός συσκευών
GenericName[en_GB]=Device Synchronisation
GenericName[es]=Sincronización de dispositivos
GenericName[et]=Seadmete sünkroonimine
GenericName[eu]=Galuak sinkronizatzea
GenericName[fi]=Laitteiden synkronointi
GenericName[fr]=Synchronisation de périphériques
GenericName[gl]=Sincronización de dispositivos
......@@ -86,7 +84,6 @@ Comment[el]=Όλες οι συσκευές σας σε μία
Comment[en_GB]=Make all your devices one
Comment[es]=Convertir todos sus dispositivos en uno
Comment[et]=Kõigi seadmete ühendamine
Comment[eu]=Bat egin zure gailu guztiak
Comment[fi]=Yhdistä kaikki laitteesi toisiinsa
Comment[fr]=Unifiez vos périphériques
Comment[gl]=Unifique os seus dispositivos.
......
......@@ -152,7 +152,7 @@ int main(int argc, char** argv)
QTextStream(stderr) << i18n("waiting for device...") << endl;
blockOnReply(iface.acquireDiscoveryMode(id));
QObject::connect(&iface, &DaemonDbusInterface::deviceAdded, [&](const QString &deviceAddedId) {
QObject::connect(&iface, &DaemonDbusInterface::deviceAdded, [&](const QString& deviceAddedId) {
if (device == deviceAddedId) {
wait.quit();
}
......
......@@ -20,7 +20,7 @@
#include "bluetoothdownloadjob.h"
BluetoothDownloadJob::BluetoothDownloadJob(const QBluetoothAddress &remoteAddress, const QVariantMap &transferInfo, QObject *parent)
BluetoothDownloadJob::BluetoothDownloadJob(const QBluetoothAddress& remoteAddress, const QVariantMap& transferInfo, QObject* parent)
: QObject(parent)
, mRemoteAddress(remoteAddress)
, mTransferUuid(QBluetoothUuid(transferInfo.value("uuid").toString()))
......
......@@ -34,7 +34,7 @@ class BluetoothDownloadJob
{
Q_OBJECT
public:
explicit BluetoothDownloadJob(const QBluetoothAddress &remoteAddress, const QVariantMap &transferInfo, QObject* parent = 0);
explicit BluetoothDownloadJob(const QBluetoothAddress& remoteAddress, const QVariantMap& transferInfo, QObject* parent = 0);
QSharedPointer<QIODevice> payload() const;
void start();
......
......@@ -24,7 +24,7 @@
#include "core_debug.h"
#include <QCoreApplication>
BluetoothUploadJob::BluetoothUploadJob(const QSharedPointer<QIODevice> &data, const QBluetoothAddress &remoteAddress, QObject *parent)
BluetoothUploadJob::BluetoothUploadJob(const QSharedPointer<QIODevice>& data, const QBluetoothAddress& remoteAddress, QObject* parent)
: QObject(parent)
, mData(data)
, mRemoteAddress(remoteAddress)
......
......@@ -34,7 +34,7 @@ class BluetoothUploadJob
{
Q_OBJECT
public:
explicit BluetoothUploadJob(const QSharedPointer<QIODevice> &data, const QBluetoothAddress &remoteAddress, QObject* parent = 0);
explicit BluetoothUploadJob(const QSharedPointer<QIODevice>& data, const QBluetoothAddress& remoteAddress, QObject* parent = 0);
QVariantMap transferInfo() const;
void start();
......
......@@ -23,33 +23,33 @@
DeviceLineReader::DeviceLineReader(QIODevice* device, QObject* parent)
: QObject(parent)
, mDevice(device)
, m_device(device)
{
connect(mDevice, SIGNAL(readyRead()),
connect(m_device, SIGNAL(readyRead()),
this, SLOT(dataReceived()));
connect(mDevice, SIGNAL(disconnected()),
connect(m_device, SIGNAL(disconnected()),
this, SIGNAL(disconnected()));
}
void DeviceLineReader::dataReceived()
{
while(mDevice->canReadLine()) {
const QByteArray line = mDevice->readLine();
while(m_device->canReadLine()) {
const QByteArray line = m_device->readLine();
if (line.length() > 1) {
mPackages.enqueue(line);//we don't want single \n
m_packages.enqueue(line);//we don't want single \n
}
}
//If we still have things to read from the device, call dataReceived again
//We do this manually because we do not trust readyRead to be emitted again
//So we call this method again just in case.
if (mDevice->bytesAvailable() > 0) {
if (m_device->bytesAvailable() > 0) {
QMetaObject::invokeMethod(this, "dataReceived", Qt::QueuedConnection);
return;
}
//If we have any packages, tell it to the world.
if (!mPackages.isEmpty()) {
if (!m_packages.isEmpty()) {
Q_EMIT readyRead();
}
}
......@@ -39,9 +39,9 @@ class DeviceLineReader
public:
DeviceLineReader(QIODevice* device, QObject* parent = 0);
QByteArray readLine() { return mPackages.dequeue(); }
qint64 write(const QByteArray& data) { return mDevice->write(data); }
qint64 bytesAvailable() const { return mPackages.size(); }
QByteArray readLine() { return m_packages.dequeue(); }
qint64 write(const QByteArray& data) { return m_device->write(data); }
qint64 bytesAvailable() const { return m_packages.size(); }
Q_SIGNALS:
void readyRead();
......@@ -51,9 +51,9 @@ private Q_SLOTS:
void dataReceived();
private:
QByteArray lastChunk;
QIODevice* mDevice;
QQueue<QByteArray> mPackages;
QByteArray m_lastChunk;
QIODevice* m_device;
QQueue<QByteArray> m_packages;
};
......
......@@ -24,10 +24,10 @@
DeviceLink::DeviceLink(const QString& deviceId, LinkProvider* parent)
: QObject(parent)
, mPrivateKey(KdeConnectConfig::instance()->privateKey())
, mDeviceId(deviceId)
, mLinkProvider(parent)
, mPairStatus(NotPaired)
, m_privateKey(KdeConnectConfig::instance()->privateKey())
, m_deviceId(deviceId)
, m_linkProvider(parent)
, m_pairStatus(NotPaired)
{
Q_ASSERT(!deviceId.isEmpty());
......@@ -36,8 +36,8 @@ DeviceLink::DeviceLink(const QString& deviceId, LinkProvider* parent)
void DeviceLink::setPairStatus(DeviceLink::PairStatus status)
{
if (mPairStatus != status) {
mPairStatus = status;
if (m_pairStatus != status) {
m_pairStatus = status;
Q_EMIT pairStatusChanged(status);
}
}
......
......@@ -44,8 +44,8 @@ public:
virtual QString name() = 0;
const QString& deviceId() const { return mDeviceId; }
LinkProvider* provider() { return mLinkProvider; }
const QString& deviceId() const { return m_deviceId; }
LinkProvider* provider() { return m_linkProvider; }
virtual bool sendPackage(NetworkPackage& np) = 0;
......@@ -53,7 +53,7 @@ public:
virtual void userRequestsPair() = 0;
virtual void userRequestsUnpair() = 0;
PairStatus pairStatus() const { return mPairStatus; }
PairStatus pairStatus() const { return m_pairStatus; }
virtual void setPairStatus(PairStatus status);
//The daemon will periodically destroy unpaired links if this returns false
......@@ -63,16 +63,16 @@ Q_SIGNALS:
void pairingRequest(PairingHandler* handler);
void pairingRequestExpired(PairingHandler* handler);
void pairStatusChanged(DeviceLink::PairStatus status);
void pairingError(const QString &error);
void pairingError(const QString& error);
void receivedPackage(const NetworkPackage& np);
protected:
QCA::PrivateKey mPrivateKey;
QCA::PrivateKey m_privateKey;
private:
const QString mDeviceId;
LinkProvider* mLinkProvider;
PairStatus mPairStatus;
const QString m_deviceId;
LinkProvider* m_linkProvider;
PairStatus m_pairStatus;
};
......
......@@ -31,16 +31,16 @@
#include "lanlinkprovider.h"
#include "core/core_debug.h"
DownloadJob::DownloadJob(const QHostAddress &address, const QVariantMap &transferInfo)
DownloadJob::DownloadJob(const QHostAddress& address, const QVariantMap& transferInfo)
: KJob()
, mAddress(address)
, mPort(transferInfo[QStringLiteral("port")].toInt())
, mSocket(new QSslSocket)
, mBuffer(new QBuffer)
, m_address(address)
, m_port(transferInfo[QStringLiteral("port")].toInt())
, m_socket(new QSslSocket)
, m_buffer(new QBuffer)
{
LanLinkProvider::configureSslSocket(mSocket.data(), transferInfo.value(QStringLiteral("deviceId")).toString(), true);
LanLinkProvider::configureSslSocket(m_socket.data(), transferInfo.value(QStringLiteral("deviceId")).toString(), true);
connect(mSocket.data(), SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketFailed(QAbstractSocket::SocketError)));
connect(m_socket.data(), SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketFailed(QAbstractSocket::SocketError)));
// connect(mSocket.data(), &QAbstractSocket::stateChanged, [](QAbstractSocket::SocketState state){ qDebug() << "statechange" << state; });
}
......@@ -53,27 +53,27 @@ void DownloadJob::start()
{
//TODO: Timeout?
// Cannot use read only, might be due to ssl handshake, getting QIODevice::ReadOnly error and no connection
mSocket->connectToHostEncrypted(mAddress.toString(), mPort, QIODevice::ReadWrite);
m_socket->connectToHostEncrypted(m_address.toString(), m_port, QIODevice::ReadWrite);
bool b = mBuffer->open(QBuffer::ReadWrite);
bool b = m_buffer->open(QBuffer::ReadWrite);
Q_ASSERT(b);
}
void DownloadJob::socketFailed(QAbstractSocket::SocketError error)
{
if (error != QAbstractSocket::RemoteHostClosedError) { //remote host closes when finishes
qWarning(KDECONNECT_CORE) << "error..." << mSocket->errorString();
qWarning(KDECONNECT_CORE) << "error..." << m_socket->errorString();
setError(error + 1);
setErrorText(mSocket->errorString());
setErrorText(m_socket->errorString());
} else {
auto ba = mSocket->readAll();
mBuffer->write(ba);
mBuffer->seek(0);
auto ba = m_socket->readAll();
m_buffer->write(ba);
m_buffer->seek(0);
}
emitResult();
}
QSharedPointer<QIODevice> DownloadJob::getPayload()
{
return mBuffer.staticCast<QIODevice>();
return m_buffer.staticCast<QIODevice>();
}
......@@ -38,16 +38,16 @@ class KDECONNECTCORE_EXPORT DownloadJob
{
Q_OBJECT
public:
DownloadJob(const QHostAddress &address, const QVariantMap &transferInfo);
DownloadJob(const QHostAddress& address, const QVariantMap& transferInfo);
~DownloadJob() override;
void start() override;
QSharedPointer<QIODevice> getPayload();
private:
QHostAddress mAddress;
qint16 mPort;
QSharedPointer<QSslSocket> mSocket;
QSharedPointer<QBuffer> mBuffer;
QHostAddress m_address;
qint16 m_port;
QSharedPointer<QSslSocket> m_socket;
QSharedPointer<QBuffer> m_buffer;
private Q_SLOTS:
void socketFailed(QAbstractSocket::SocketError error);
......
......@@ -31,30 +31,30 @@
LanDeviceLink::LanDeviceLink(const QString& deviceId, LinkProvider* parent, QSslSocket* socket, ConnectionStarted connectionSource)
: DeviceLink(deviceId, parent)
, mSocketLineReader(nullptr)
, m_socketLineReader(nullptr)
{
reset(socket, connectionSource);
}
void LanDeviceLink::reset(QSslSocket* socket, ConnectionStarted connectionSource)
{
if (mSocketLineReader) {
disconnect(mSocketLineReader->mSocket, &QAbstractSocket::disconnected, this, &QObject::deleteLater);
delete mSocketLineReader;
if (m_socketLineReader) {
disconnect(m_socketLineReader->m_socket, &QAbstractSocket::disconnected, this, &QObject::deleteLater);
delete m_socketLineReader;
}
mSocketLineReader = new SocketLineReader(socket, this);
m_socketLineReader = new SocketLineReader(socket, this);
connect(socket, &QAbstractSocket::disconnected, this, &QObject::deleteLater);
connect(mSocketLineReader, &SocketLineReader::readyRead, this, &LanDeviceLink::dataReceived);
connect(m_socketLineReader, &SocketLineReader::readyRead, this, &LanDeviceLink::dataReceived);
//We take ownership of the socket.
//When the link provider destroys us,
//the socket (and the reader) will be
//destroyed as well
socket->setParent(mSocketLineReader);
socket->setParent(m_socketLineReader);
mConnectionSource = connectionSource;
m_connectionSource = connectionSource;
QString certString = KdeConnectConfig::instance()->getDeviceProperty(deviceId(), QStringLiteral("certificate"));
DeviceLink::setPairStatus(certString.isEmpty()? PairStatus::NotPaired : PairStatus::Paired);
......@@ -62,10 +62,10 @@ void LanDeviceLink::reset(QSslSocket* socket, ConnectionStarted connectionSource
QHostAddress LanDeviceLink::hostAddress() const
{
if (!mSocketLineReader) {
if (!m_socketLineReader) {
return QHostAddress::Null;
}
QHostAddress addr = mSocketLineReader->mSocket->peerAddress();
QHostAddress addr = m_socketLineReader->m_socket->peerAddress();
if (addr.protocol() == QAbstractSocket::IPv6Protocol) {
bool success;
QHostAddress convertedAddr = QHostAddress(addr.toIPv4Address(&success));
......@@ -88,7 +88,7 @@ bool LanDeviceLink::sendPackage(NetworkPackage& np)
np.setPayloadTransferInfo(sendPayload(np)->transferInfo());
}
int written = mSocketLineReader->write(np.serialize());
int written = m_socketLineReader->write(np.serialize());
//Actually we can't detect if a package is received or not. We keep TCP
//"ESTABLISHED" connections that look legit (return true when we use them),
......@@ -105,9 +105,9 @@ UploadJob* LanDeviceLink::sendPayload(const NetworkPackage& np)
void LanDeviceLink::dataReceived()
{
if (mSocketLineReader->bytesAvailable() == 0) return;
if (m_socketLineReader->bytesAvailable() == 0) return;
const QByteArray serializedPackage = mSocketLineReader->readLine();
const QByteArray serializedPackage = m_socketLineReader->readLine();
NetworkPackage package(QString::null);
NetworkPackage::unserialize(serializedPackage, &package);
......@@ -125,14 +125,14 @@ void LanDeviceLink::dataReceived()
//FIXME: The next two lines shouldn't be needed! Why are they here?
transferInfo.insert(QStringLiteral("useSsl"), true);
transferInfo.insert(QStringLiteral("deviceId"), deviceId());
DownloadJob* job = new DownloadJob(mSocketLineReader->peerAddress(), transferInfo);
DownloadJob* job = new DownloadJob(m_socketLineReader->peerAddress(), transferInfo);
job->start();
package.setPayload(job->getPayload(), package.payloadSize());
}
Q_EMIT receivedPackage(package);
if (mSocketLineReader->bytesAvailable() > 0) {
if (m_socketLineReader->bytesAvailable() > 0) {
QMetaObject::invokeMethod(this, "dataReceived", Qt::QueuedConnection);
}
......@@ -140,7 +140,7 @@ void LanDeviceLink::dataReceived()
void LanDeviceLink::userRequestsPair()
{
if (mSocketLineReader->peerCertificate().isNull()) {
if (m_socketLineReader->peerCertificate().isNull()) {
Q_EMIT pairingError(i18n("This device cannot be paired because it is running an old version of KDE Connect."));
} else {
qobject_cast<LanLinkProvider*>(provider())->userRequestsPair(deviceId());
......@@ -154,7 +154,7 @@ void LanDeviceLink::userRequestsUnpair()
void LanDeviceLink::setPairStatus(PairStatus status)
{
if (status == Paired && mSocketLineReader->peerCertificate().isNull()) {
if (status == Paired && m_socketLineReader->peerCertificate().isNull()) {
Q_EMIT pairingError(i18n("This device cannot be paired because it is running an old version of KDE Connect."));
return;
}
......@@ -162,8 +162,8 @@ void LanDeviceLink::setPairStatus(PairStatus status)
DeviceLink::setPairStatus(status);
if (status == Paired) {
Q_ASSERT(KdeConnectConfig::instance()->trustedDevices().contains(deviceId()));
Q_ASSERT(!mSocketLineReader->peerCertificate().isNull());
KdeConnectConfig::instance()->setDeviceProperty(deviceId(), QStringLiteral("certificate"), mSocketLineReader->peerCertificate().toPem());
Q_ASSERT(!m_socketLineReader->peerCertificate().isNull());
KdeConnectConfig::instance()->setDeviceProperty(deviceId(), QStringLiteral("certificate"), m_socketLineReader->peerCertificate().toPem());
}
}
......
......@@ -60,9 +60,9 @@ private Q_SLOTS:
void dataReceived();
private:
SocketLineReader* mSocketLineReader;
ConnectionStarted mConnectionSource;
QHostAddress mHostAddress;
SocketLineReader* m_socketLineReader;
ConnectionStarted m_connectionSource;
QHostAddress m_hostAddress;
};
#endif
This diff is collapsed.
......@@ -47,8 +47,8 @@ public:
QString name() override { return QStringLiteral("LanLinkProvider"); }
int priority() override { return PRIORITY_HIGH; }
void userRequestsPair(const QString &deviceId);
void userRequestsUnpair(const QString &deviceId);
void userRequestsPair(const QString& deviceId);
void userRequestsUnpair(const QString& deviceId);
void incomingPairPackage(DeviceLink* device, const NetworkPackage& np);
static void configureSslSocket(QSslSocket* socket, const QString& deviceId, bool isDeviceTrusted);
......@@ -77,24 +77,24 @@ private Q_SLOTS:
private:
LanPairingHandler* createPairingHandler(DeviceLink* link);
void onNetworkConfigurationChanged(const QNetworkConfiguration &config);
void onNetworkConfigurationChanged(const QNetworkConfiguration& config);
void addLink(const QString& deviceId, QSslSocket* socket, NetworkPackage* receivedPackage, LanDeviceLink::ConnectionStarted connectionOrigin);
Server* mServer;
QUdpSocket mUdpSocket;
quint16 mTcpPort;
Server* m_server;
QUdpSocket m_udpSocket;
quint16 m_tcpPort;
QMap<QString, LanDeviceLink*> mLinks;
QMap<QString, LanPairingHandler*> mPairingHandlers;
QMap<QString, LanDeviceLink*> m_links;
QMap<QString, LanPairingHandler*> m_pairingHandlers;
struct PendingConnect {
NetworkPackage* np;
QHostAddress sender;
};
QMap<QSslSocket*, PendingConnect> receivedIdentityPackages;
QMap<QSslSocket*, PendingConnect> m_receivedIdentityPackages;
QNetworkConfiguration m_lastConfig;
const bool mTestMode;
QTimer combineBroadcastsTimer;
const bool m_testMode;
QTimer m_combineBroadcastsTimer;
};
#endif
......@@ -34,7 +34,7 @@ Server::Server(QObject * parent)
}
void Server::incomingConnection(qintptr socketDescriptor) {
QSslSocket *serverSocket = new QSslSocket(parent());
QSslSocket* serverSocket = new QSslSocket(parent());
if (serverSocket->setSocketDescriptor(socketDescriptor)) {
pendingConnections.append(serverSocket);
Q_EMIT newConnection();
......
......@@ -23,31 +23,31 @@
SocketLineReader::SocketLineReader(QSslSocket* socket, QObject* parent)
: QObject(parent)
, mSocket(socket)
, m_socket(socket)
{
connect(mSocket, &QIODevice::readyRead,
connect(m_socket, &QIODevice::readyRead,
this, &SocketLineReader::dataReceived);
}
void SocketLineReader::dataReceived()
{
while (mSocket->canReadLine()) {
const QByteArray line = mSocket->readLine();
while (m_socket->canReadLine()) {
const QByteArray line = m_socket->readLine();
if (line.length() > 1) { //we don't want a single \n
mPackages.enqueue(line);
m_packages.enqueue(line);
}
}
//If we still have things to read from the socket, call dataReceived again
//We do this manually because we do not trust readyRead to be emitted again
//So we call this method again just in case.
if (mSocket->bytesAvailable() > 0) {
if (m_socket->bytesAvailable() > 0) {
QMetaObject::invokeMethod(this, "dataReceived", Qt::QueuedConnection);
return;
}
//If we have any packages, tell it to the world.
if (!mPackages.isEmpty()) {
if (!m_packages.isEmpty()) {
Q_EMIT readyRead();
}
}
......@@ -40,13 +40,13 @@ class KDECONNECTCORE_EXPORT SocketLineReader
public:
explicit SocketLineReader(QSslSocket* socket, QObject* parent = nullptr);
QByteArray readLine() { return mPackages.dequeue(); }
qint64 write(const QByteArray& data) { return mSocket->write(data); }
QHostAddress peerAddress() const { return mSocket->peerAddress(); }
QSslCertificate peerCertificate() const { return mSocket->peerCertificate(); }
qint64 bytesAvailable() const { return mPackages.size(); }
QByteArray readLine() { return m_packages.dequeue(); }
qint64 write(const QByteArray& data) { return m_socket->write(data); }
QHostAddress peerAddress() const { return m_socket->peerAddress(); }
QSslCertificate peerCertificate() const { return m_socket->peerCertificate(); }
qint64 bytesAvailable() const { return m_packages.size(); }
QSslSocket* mSocket;
QSslSocket* m_socket;
Q_SIGNALS:
void readyRead();
......@@ -55,8 +55,8 @@ private Q_SLOTS:
void dataReceived();
private:
QByteArray lastChunk;
QQueue<QByteArray> mPackages;
QByteArray m_lastChunk;
QQueue<QByteArray> m_packages;
};
......
......@@ -28,92 +28,92 @@
UploadJob::UploadJob(const QSharedPointer<QIODevice>& source, const QString& deviceId)
: KJob()
, mInput(source)
, mServer(new Server(this))
, mSocket(nullptr)
, mPort(0)
, mDeviceId(deviceId) // We will use this info if link is on ssl, to send encrypted payload
, m_input(source)
, m_server(new Server(this))
, m_socket(nullptr)
, m_port(0)
, m_deviceId(deviceId) // We will use this info if link is on ssl, to send encrypted payload
{
connect(mInput.data(), &QIODevice::readyRead, this, &UploadJob::startUploading);
connect(mInput.data(), &QIODevice::aboutToClose, this, &UploadJob::aboutToClose);
connect(m_input.data(), &QIODevice::readyRead, this, &UploadJob::startUploading);
connect(m_input.data(), &QIODevice::aboutToClose, this, &UploadJob::aboutToClose);
}
void UploadJob::start()
{
mPort = MIN_PORT;
while (!mServer->listen(QHostAddress::Any, mPort)) {
mPort++;
if (mPort > MAX_PORT) { //No ports available?
m_port = MIN_PORT;
while (!m_server->listen(QHostAddress::Any, m_port)) {
m_port++;
if (m_port > MAX_PORT) { //No ports available?
qCWarning(KDECONNECT_CORE) << "Error opening a port in range" << MIN_PORT << "-" << MAX_PORT;
mPort = 0;
m_port = 0;
setError(1);
setErrorText(i18n("Couldn't find an available port"));
emitResult();
return;
}
}
connect(mServer, &QTcpServer::newConnection, this, &UploadJob::newConnection);
connect(m_server, &QTcpServer::newConnection, this, &UploadJob::newConnection);
}
void UploadJob::newConnection()
{
if (!mInput->open(QIODevice::ReadOnly)) {
if (!m_input->open(QIODevice::ReadOnly)) {
qCWarning(KDECONNECT_CORE) << "error when opening the input to upload";
return; //TODO: Handle error, clean up...
}
Server* server = qobject_cast<Server*>(sender());
// FIXME : It is called again when payload sending is finished. Unsolved mystery :(
disconnect(mServer, &QTcpServer::newConnection, this, &UploadJob::newConnection);
mSocket = server->nextPendingConnection();
mSocket->setParent(this);
connect(mSocket, &QSslSocket::disconnected, this, &UploadJob::cleanup);
connect(mSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketFailed(QAbstractSocket::SocketError)));
connect(mSocket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrors(QList<QSslError>)));
connect(mSocket, &QSslSocket::encrypted, this, &UploadJob::startUploading);
disconnect(m_server, &QTcpServer::newConnection, this, &UploadJob::newConnection);
m_socket = server->nextPendingConnection();
m_socket->setParent(this);
connect(m_socket, &QSslSocket::disconnected, this, &UploadJob::cleanup);
connect(m_socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketFailed(QAbstractSocket::SocketError)));
connect(m_socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(sslErrors(QList<QSslError>)));
connect(m_socket, &QSslSocket::encrypted, this, &UploadJob::startUploading);
// connect(mSocket, &QAbstractSocket::stateChanged, [](QAbstractSocket::SocketState state){ qDebug() << "statechange" << state; });
LanLinkProvider::configureSslSocket(mSocket, mDeviceId, true);
LanLinkProvider::configureSslSocket(m_socket, m_deviceId, true);
mSocket->startServerEncryption();
m_socket->startServerEncryption();
}
void UploadJob::startUploading()