From 091de2ad4bf02fd7da1ae5f4202b750e1c6435f8 Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Sat, 26 Sep 2015 08:23:41 -0700 Subject: [PATCH 1/9] Removed unused generate_export_header --- kcmplugin/CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/kcmplugin/CMakeLists.txt b/kcmplugin/CMakeLists.txt index 18b7c09be..03232284a 100644 --- a/kcmplugin/CMakeLists.txt +++ b/kcmplugin/CMakeLists.txt @@ -22,8 +22,6 @@ set_target_properties(kdeconnectpluginkcm PROPERTIES ) target_include_directories(kdeconnectpluginkcm PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) -generate_export_header(kdeconnectpluginkcm EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}../core/kdeconnectcore_export.h BASE_NAME kdeconnectpluginkcm) -# Remove NAMELINK_SKIP if/when headers are being installed and the library -# becomes public. +# Remove NAMELINK_SKIP if/when headers are being installed and the library becomes public. install(TARGETS kdeconnectpluginkcm EXPORT kdeconnectLibraryTargets ${INSTALL_TARGETS_DEFAULT_ARGS} LIBRARY NAMELINK_SKIP) From 53e6381d3004c55691a1890c736c64e591a5e05a Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Sat, 26 Sep 2015 08:23:55 -0700 Subject: [PATCH 2/9] Fixed warning about using pointers in slots --- plugins/notifications/notificationsdbusinterface.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/notifications/notificationsdbusinterface.h b/plugins/notifications/notificationsdbusinterface.h index e8d5c2a7a..127d56273 100644 --- a/plugins/notifications/notificationsdbusinterface.h +++ b/plugins/notifications/notificationsdbusinterface.h @@ -44,10 +44,10 @@ public: void processPackage(const NetworkPackage& np); void clearNotifications(); + void dismissRequested(Notification* notification); public Q_SLOTS: Q_SCRIPTABLE QStringList activeNotifications(); - void dismissRequested(Notification* notification); Q_SIGNALS: Q_SCRIPTABLE void notificationPosted(const QString& publicId); From 4574aa3639c9a0b38075615c9b68e373843c59b1 Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Sat, 17 Oct 2015 13:32:57 -0700 Subject: [PATCH 3/9] Make the origin also contain the file name, not only the device name --- core/filetransferjob.cpp | 13 ++++++------- core/filetransferjob.h | 4 ++-- plugins/share/shareplugin.cpp | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/core/filetransferjob.cpp b/core/filetransferjob.cpp index 46c84e270..662909313 100644 --- a/core/filetransferjob.cpp +++ b/core/filetransferjob.cpp @@ -33,7 +33,7 @@ FileTransferJob::FileTransferJob(const QSharedPointer& origin, qint64 : KJob() , mOrigin(origin) , mReply(Q_NULLPTR) - , mDeviceName("KDE Connect") //TODO: Actually fetch the device name + , mFrom("KDE Connect") , mDestination(destination) , mSpeedBytes(0) , mWritten(0) @@ -47,6 +47,7 @@ FileTransferJob::FileTransferJob(const QSharedPointer& origin, qint64 if (size >= 0) { setTotalAmount(Bytes, size); } + setCapabilities(Killable); qCDebug(KDECONNECT_CORE) << "FileTransferJob Downloading payload to" << destination; } @@ -59,9 +60,8 @@ void FileTransferJob::start() void FileTransferJob::doStart() { - description(this, i18n("Receiving file over KDE-Connect"), - QPair(i18nc("File transfer origin", "From"), - mDeviceName) + description(this, i18n("Receiving file over KDE Connect"), + QPair(i18nc("File transfer origin", "From"), mFrom) ); if (mDestination.isLocalFile() && QFile::exists(mDestination.toLocalFile())) { @@ -77,9 +77,8 @@ void FileTransferJob::startTransfer() { setProcessedAmount(Bytes, 0); mTime = QTime::currentTime(); - description(this, i18n("Receiving file over KDE-Connect"), - QPair(i18nc("File transfer origin", "From"), - mDeviceName), + description(this, i18n("Receiving file over KDE Connect"), + QPair(i18nc("File transfer origin", "From"), mFrom), QPair(i18nc("File transfer destination", "To"), mDestination.toLocalFile())); QNetworkRequest req(mDestination); diff --git a/core/filetransferjob.h b/core/filetransferjob.h index 859a30321..2d26ba408 100644 --- a/core/filetransferjob.h +++ b/core/filetransferjob.h @@ -53,7 +53,7 @@ public: FileTransferJob(const QSharedPointer& origin, qint64 size, const QUrl &destination); virtual void start() Q_DECL_OVERRIDE; QUrl destination() const { return mDestination; } - void setDeviceName(const QString &deviceName) { mDeviceName = deviceName; } + void setOriginName(QString from) { mFrom = from; } private Q_SLOTS: void doStart(); @@ -67,7 +67,7 @@ private: QSharedPointer mOrigin; QNetworkReply* mReply; - QString mDeviceName; + QString mFrom; QUrl mDestination; QTime mTime; qulonglong mSpeedBytes; diff --git a/plugins/share/shareplugin.cpp b/plugins/share/shareplugin.cpp index b4331b32a..e462a8bb7 100644 --- a/plugins/share/shareplugin.cpp +++ b/plugins/share/shareplugin.cpp @@ -96,7 +96,7 @@ bool SharePlugin::receivePackage(const NetworkPackage& np) } FileTransferJob* job = np.createPayloadTransferJob(destination); - job->setDeviceName(device()->name()); + job->setOriginName(device()->name() + ": " + filename); connect(job, SIGNAL(result(KJob*)), this, SLOT(finished(KJob*))); KIO::getJobTracker()->registerJob(job); job->start(); From 6deec3429af0d41f50c2526f10c45eec5b4d26a5 Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Sat, 17 Oct 2015 15:32:13 -0700 Subject: [PATCH 4/9] Use id instead of a pointer in the dismissRequested signal and slot. Also changed connection to the Qt5 way. --- plugins/notifications/notification.cpp | 4 ++-- plugins/notifications/notification.h | 6 +++--- plugins/notifications/notificationsdbusinterface.cpp | 8 +++----- plugins/notifications/notificationsdbusinterface.h | 2 +- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/plugins/notifications/notification.cpp b/plugins/notifications/notification.cpp index b44b5f854..3e42f2aa8 100644 --- a/plugins/notifications/notification.cpp +++ b/plugins/notifications/notification.cpp @@ -25,7 +25,7 @@ Notification::Notification(const NetworkPackage& np, const QString& iconPath, QObject* parent) : QObject(parent) { - mId = np.get("id"); + mInternalId = np.get("id"); mAppName = np.get("appName"); mTicker = np.get("ticker"); mDismissable = np.get("isClearable"); @@ -40,7 +40,7 @@ Notification::~Notification() void Notification::dismiss() { if (mDismissable) { - Q_EMIT dismissRequested(this); + Q_EMIT dismissRequested(mInternalId); } } diff --git a/plugins/notifications/notification.h b/plugins/notifications/notification.h index 3c14d26d0..dcf09a77c 100644 --- a/plugins/notifications/notification.h +++ b/plugins/notifications/notification.h @@ -41,7 +41,7 @@ public: Notification(const NetworkPackage& np, const QString& iconPath, QObject* parent); virtual ~Notification(); - QString internalId() const { return mId; } + QString internalId() const { return mInternalId; } QString appName() const { return mAppName; } QString ticker() const { return mTicker; } QString iconPath() const { return mIconPath; } @@ -51,10 +51,10 @@ public Q_SLOTS: Q_SCRIPTABLE void dismiss(); Q_SIGNALS: - void dismissRequested(Notification* self); + void dismissRequested(const QString& mInternalId); private: - QString mId; + QString mInternalId; QString mAppName; QString mTicker; QString mIconPath; diff --git a/plugins/notifications/notificationsdbusinterface.cpp b/plugins/notifications/notificationsdbusinterface.cpp index e7b89f26c..3c504c646 100644 --- a/plugins/notifications/notificationsdbusinterface.cpp +++ b/plugins/notifications/notificationsdbusinterface.cpp @@ -98,8 +98,8 @@ void NotificationsDbusInterface::addNotification(Notification* noti) removeNotification(internalId); } - connect(noti, SIGNAL(dismissRequested(Notification*)), - this, SLOT(dismissRequested(Notification*))); + connect(noti, &Notification::dismissRequested, + this, &NotificationsDbusInterface::dismissRequested); const QString& publicId = newId(); mNotifications[publicId] = noti; @@ -133,10 +133,8 @@ void NotificationsDbusInterface::removeNotification(const QString& internalId) Q_EMIT notificationRemoved(publicId); } -void NotificationsDbusInterface::dismissRequested(Notification* notification) +void NotificationsDbusInterface::dismissRequested(const QString& internalId) { - const QString& internalId = notification->internalId(); - NetworkPackage np(PACKAGE_TYPE_NOTIFICATION); np.set("cancel", internalId); mPlugin->sendPackage(np); diff --git a/plugins/notifications/notificationsdbusinterface.h b/plugins/notifications/notificationsdbusinterface.h index 127d56273..21d5a6afe 100644 --- a/plugins/notifications/notificationsdbusinterface.h +++ b/plugins/notifications/notificationsdbusinterface.h @@ -44,7 +44,7 @@ public: void processPackage(const NetworkPackage& np); void clearNotifications(); - void dismissRequested(Notification* notification); + void dismissRequested(const QString& notification); public Q_SLOTS: Q_SCRIPTABLE QStringList activeNotifications(); From 30f00fb3fae1f3af7eb7aae4c31b0aa994288001 Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Sat, 17 Oct 2015 17:31:17 -0700 Subject: [PATCH 5/9] Fix a crash where unmount was called again after m_proc had been destroyed This happened because of scheduling m_proc->kill() from unmount 5 seconds after the destructor was called (which was who called unmount first). Simplified unmount logic a bit as well. Known bug: we might end with a fuse mountpoint still mounted after killing the sshfs process. BUG: 352861 --- plugins/sftp/mounter.cpp | 55 ++++++++++++++++------------------------ plugins/sftp/mounter.h | 5 ++-- 2 files changed, 24 insertions(+), 36 deletions(-) diff --git a/plugins/sftp/mounter.cpp b/plugins/sftp/mounter.cpp index b83e55f85..6eebc7b84 100644 --- a/plugins/sftp/mounter.cpp +++ b/plugins/sftp/mounter.cpp @@ -48,13 +48,13 @@ Mounter::Mounter(SftpPlugin* sftp) m_connectTimer.setSingleShot(true); QTimer::singleShot(0, this, SLOT(start())); - qCDebug(KDECONNECT_PLUGIN_SFTP) << "Created"; + qCDebug(KDECONNECT_PLUGIN_SFTP) << "Created mounter"; } Mounter::~Mounter() { + qCDebug(KDECONNECT_PLUGIN_SFTP) << "Destroy mounter"; unmount(); - qCDebug(KDECONNECT_PLUGIN_SFTP) << "Destroyed"; } bool Mounter::wait() @@ -95,12 +95,14 @@ void Mounter::onPakcageReceived(const NetworkPackage& np) * Q_EMIT mounted(); */ - m_proc.reset(new KProcess(this)); + unmount(); + + m_proc = new KProcess(this); m_proc->setOutputChannelMode(KProcess::MergedChannels); - connect(m_proc.data(), SIGNAL(started()), SLOT(onStarted())); - connect(m_proc.data(), SIGNAL(error(QProcess::ProcessError)), SLOT(onError(QProcess::ProcessError))); - connect(m_proc.data(), SIGNAL(finished(int,QProcess::ExitStatus)), SLOT(onFinished(int,QProcess::ExitStatus))); + connect(m_proc, SIGNAL(started()), SLOT(onStarted())); + connect(m_proc, SIGNAL(error(QProcess::ProcessError)), SLOT(onError(QProcess::ProcessError))); + connect(m_proc, SIGNAL(finished(int,QProcess::ExitStatus)), SLOT(onFinished(int,QProcess::ExitStatus))); QDir().mkpath(m_mountPoint); @@ -125,12 +127,6 @@ void Mounter::onPakcageReceived(const NetworkPackage& np) m_proc->setProgram(program, arguments); - //To debug - //m_proc->setStandardOutputFile("/tmp/kdeconnect-sftp.out"); - //m_proc->setStandardErrorFile("/tmp/kdeconnect-sftp.err"); - - cleanMountPoint(); - qCDebug(KDECONNECT_PLUGIN_SFTP) << "Starting process: " << m_proc->program().join(" "); m_proc->start(); } @@ -140,11 +136,13 @@ void Mounter::onStarted() qCDebug(KDECONNECT_PLUGIN_SFTP) << "Process started"; m_started = true; Q_EMIT mounted(); - - connect(m_proc.data(), &KProcess::readyReadStandardError, [this]() { + + //m_proc->setStandardOutputFile("/tmp/kdeconnect-sftp.out"); + //m_proc->setStandardErrorFile("/tmp/kdeconnect-sftp.err"); + connect(m_proc, &KProcess::readyReadStandardError, [this]() { qCDebug(KDECONNECT_PLUGIN_SFTP) << "stderr: " << m_proc->readAll(); }); - connect(m_proc.data(), &KProcess::readyReadStandardOutput, [this]() { + connect(m_proc, &KProcess::readyReadStandardOutput, [this]() { qCDebug(KDECONNECT_PLUGIN_SFTP) << "stdout:" << m_proc->readAll(); }); } @@ -172,9 +170,7 @@ void Mounter::onFinished(int exitCode, QProcess::ExitStatus exitStatus) Q_EMIT failed(i18n("Error when accessing to filesystem")); } - cleanMountPoint(); - m_proc.reset(); - m_started = false; + unmount(); } void Mounter::onMountTimeout() @@ -192,25 +188,18 @@ void Mounter::start() m_connectTimer.start(); } -void Mounter::cleanMountPoint() -{ - qCDebug(KDECONNECT_PLUGIN_SFTP()) << "cleanMountPoint"; - KProcess::execute(QStringList() << "fusermount" << "-u" << m_mountPoint, 10000); -} - void Mounter::unmount() { + qCDebug(KDECONNECT_PLUGIN_SFTP) << "Unmount" << m_proc; if (m_proc) { - cleanMountPoint(); - if (m_proc) - { - m_proc->terminate(); - QTimer::singleShot(5000, m_proc.data(), SLOT(kill())); - m_proc->waitForFinished(); - } + auto toDestroy = m_proc; + m_proc = nullptr; //So we don't reenter this code path when onFinished gets called + toDestroy->kill(); + delete toDestroy; + //Free mount point (won't always succeed if the path is in use) + KProcess::execute(QStringList() << "fusermount" << "-u" << m_mountPoint, 10000); } - - m_started = false; + m_started = false; } diff --git a/plugins/sftp/mounter.h b/plugins/sftp/mounter.h index 76ac860f8..bb2d3f58f 100644 --- a/plugins/sftp/mounter.h +++ b/plugins/sftp/mounter.h @@ -51,13 +51,12 @@ private Q_SLOTS: void onMountTimeout(); void start(); -private: - void cleanMountPoint(); +private: void unmount(); private: SftpPlugin* m_sftp; - QScopedPointer m_proc; + KProcess* m_proc; QTimer m_connectTimer; QString m_mountPoint; bool m_started; From e4c5ea646edcd1184e6f4ba46f1573c28e1eaead Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Sun, 18 Oct 2015 15:08:36 -0700 Subject: [PATCH 6/9] Added a link to the wiki from the KCM. --- kcm/kcm.ui | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/kcm/kcm.ui b/kcm/kcm.ui index 6f763c843..147cf575b 100644 --- a/kcm/kcm.ui +++ b/kcm/kcm.ui @@ -70,7 +70,9 @@ - + + + @@ -91,7 +93,9 @@ - + + + @@ -295,7 +299,38 @@ - If you have an Android phone, make sure to install the <a href="https://play.google.com/store/apps/details?id=org.kde.kdeconnect_tp"><span style=" text-decoration: underline; color:#0000ff;">KDE Connect Android app</span></a> (also available <a href="https://f-droid.org/repository/browse/?fdid=org.kde.kdeconnect_tp"><span style=" text-decoration: underline; color:#0000ff;">from F-Droid</span></a>). + <html><head/><body><p>If you own Android device, make sure to install the <a href="https://play.google.com/store/apps/details?id=org.kde.kdeconnect_tp"><span style=" text-decoration: underline; color:#0000ff;">KDE Connect Android app</span></a> (also available <a href="https://f-droid.org/repository/browse/?fdid=org.kde.kdeconnect_tp"><span style=" text-decoration: underline; color:#0000ff;">from F-Droid</span></a>) and it should appear in the list.</p></body></html> + + + Qt::RichText + + + Qt::AlignCenter + + + true + + + 40 + + + true + + + Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse + + + + + + + + 0 + 0 + + + + <html><head/><body><p>If you are having problems, visit the <a href="https://community.kde.org/KDEConnect"><span style=" text-decoration: underline; color:#0000ff;">KDE Connect Community wiki</span></a> for help.</p></body></html> Qt::RichText From 229e3aa0700f8b18dc91f6ce61e17b566e6b5666 Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Sun, 18 Oct 2015 19:42:40 -0700 Subject: [PATCH 7/9] Removed unused class --- core/backends/lan/lanlinkprovider.h | 1 - core/backends/lan/netaddress.h | 37 ----------------------------- 2 files changed, 38 deletions(-) delete mode 100644 core/backends/lan/netaddress.h diff --git a/core/backends/lan/lanlinkprovider.h b/core/backends/lan/lanlinkprovider.h index 81f2f75da..eb897285e 100644 --- a/core/backends/lan/lanlinkprovider.h +++ b/core/backends/lan/lanlinkprovider.h @@ -26,7 +26,6 @@ #include #include "../linkprovider.h" -#include "netaddress.h" class LanLinkProvider : public LinkProvider diff --git a/core/backends/lan/netaddress.h b/core/backends/lan/netaddress.h deleted file mode 100644 index f264ba1b4..000000000 --- a/core/backends/lan/netaddress.h +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2013 Albert Vaca - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License or (at your option) version 3 or any later version - * accepted by the membership of KDE e.V. (or its successor approved - * by the membership of KDE e.V.), which shall act as a proxy - * defined in Section 14 of version 3 of the license. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef NETADDRESS_H -#define NETADDRESS_H - -#include - -struct NetAddress { - NetAddress() { } - NetAddress(QHostAddress _ip, quint16 _port) : ip(_ip), port(_port) { } - QHostAddress ip; - quint16 port; -}; - -inline bool operator< (const NetAddress& a, const NetAddress& b){ - return (a.ip.toString()+a.port) < (b.ip.toString()+b.port); -} - -#endif // NETADDRESS_H From e2f068b2869b0a94be1bd87b714731e86dff90e5 Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Sun, 18 Oct 2015 21:48:39 -0700 Subject: [PATCH 8/9] Fixed a memory leak making the DownloadJob destroy itself on disconnect There are still some code paths where it doesn't get destroyed though, like when the device gets unreachable (and the download socket doesn't close for some reason). --- core/backends/lan/downloadjob.cpp | 34 ++++++++-- core/backends/lan/downloadjob.h | 6 +- core/core_debug.h | 4 +- tests/CMakeLists.txt | 1 + tests/downloadjobtest.cpp | 107 ++++++++++++++++++++++++++++++ 5 files changed, 141 insertions(+), 11 deletions(-) create mode 100644 tests/downloadjobtest.cpp diff --git a/core/backends/lan/downloadjob.cpp b/core/backends/lan/downloadjob.cpp index bba2e988b..abbedf102 100644 --- a/core/backends/lan/downloadjob.cpp +++ b/core/backends/lan/downloadjob.cpp @@ -20,30 +20,50 @@ #include "downloadjob.h" +#include + +#include +#include +#include +#include + +#include "lanlinkprovider.h" + DownloadJob::DownloadJob(QHostAddress address, QVariantMap transferInfo): KJob() { mAddress = address; mPort = transferInfo["port"].toInt(); - mSocket = QSharedPointer(new QTcpSocket); + mSocket = QSharedPointer(new QTcpSocket()); +} + +DownloadJob::~DownloadJob() +{ } void DownloadJob::start() { - //kDebug(kdeconnect_kded()) << "DownloadJob Start"; + //TODO: Timeout? + connect(mSocket.data(), &QAbstractSocket::disconnected, this, &DownloadJob::done); + connect(mSocket.data(), SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(done())); + //connect(mSocket.data(), &QAbstractSocket::connected, [=](){ qDebug() << "Connected"; }); + mSocket->connectToHost(mAddress, mPort, QIODevice::ReadOnly); - connect(mSocket.data(), SIGNAL(disconnected()), - this, SLOT(disconnected())); + + //mSocket->open(QIODevice::ReadOnly); + //TODO: Implement payload encryption somehow (create an intermediate iodevice to encrypt the payload here?) } -void DownloadJob::disconnected() +void DownloadJob::done() { - //kDebug(kdeconnect_kded()) << "DownloadJob End"; + if (mSocket->error()) { + qWarning(KDECONNECT_CORE) << mSocket->errorString(); + } emitResult(); + deleteLater(); } QSharedPointer DownloadJob::getPayload() { - //kDebug(kdeconnect_kded()) << "getPayload"; return mSocket.staticCast(); } diff --git a/core/backends/lan/downloadjob.h b/core/backends/lan/downloadjob.h index 544e33cd4..e3d3a7dc6 100644 --- a/core/backends/lan/downloadjob.h +++ b/core/backends/lan/downloadjob.h @@ -35,7 +35,8 @@ class DownloadJob Q_OBJECT public: DownloadJob(QHostAddress address, QVariantMap transferInfo); - virtual void start() override; + ~DownloadJob(); + void start() Q_DECL_OVERRIDE; QSharedPointer getPayload(); private: @@ -43,9 +44,8 @@ private: qint16 mPort; QSharedPointer mSocket; - private Q_SLOTS: - void disconnected(); + void done(); }; diff --git a/core/core_debug.h b/core/core_debug.h index 93a0f1d1f..d74745cb9 100644 --- a/core/core_debug.h +++ b/core/core_debug.h @@ -23,6 +23,8 @@ #include -Q_DECLARE_LOGGING_CATEGORY(KDECONNECT_CORE) +#include "kdeconnectcore_export.h" + +KDECONNECTCORE_EXPORT Q_DECLARE_LOGGING_CATEGORY(KDECONNECT_CORE) #endif //CORE_DEBUG_H diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 727f3951d..4be7945cb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -16,3 +16,4 @@ set(kdeconnect_libraries ecm_add_test(networkpackagetests.cpp LINK_LIBRARIES ${kdeconnect_libraries}) ecm_add_test(testsocketlinereader.cpp ../core/backends/lan/socketlinereader.cpp TEST_NAME testsocketlinereader LINK_LIBRARIES ${kdeconnect_libraries}) +ecm_add_test(downloadjobtest.cpp ../core/backends/lan/downloadjob.cpp TEST_NAME downloadjobtest LINK_LIBRARIES ${kdeconnect_libraries}) diff --git a/tests/downloadjobtest.cpp b/tests/downloadjobtest.cpp new file mode 100644 index 000000000..efaea3dc2 --- /dev/null +++ b/tests/downloadjobtest.cpp @@ -0,0 +1,107 @@ +/************************************************************************************* + * Copyright (C) 2014 by Albert Vaca Cintora * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this library; if not, write to the Free Software * + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * + *************************************************************************************/ + +#include "../core/backends/lan/downloadjob.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class DownloadJobTest : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void failToConnectShouldDestroyTheJob(); + void closingTheConnectionShouldDestroyTheJob(); +private: + + void initServer(); + void initDownloadJob(); + void awaitToBeDestroyedOrTimeOut(); + void stopServer(); + + QTimer mTimer; + QEventLoop mLoop; + DownloadJob* test; + QTcpServer *mServer; +}; + +void DownloadJobTest::initServer() +{ + mServer = new QTcpServer(this); + QVERIFY2(mServer->listen(QHostAddress::LocalHost, 8694), "Failed to create local tcp server"); +} + +void DownloadJobTest::stopServer() +{ + mServer->close(); +} + +void DownloadJobTest::initDownloadJob() +{ + QVariantMap transferInfo; + transferInfo["port"]= 8694; + test = new DownloadJob(QHostAddress::LocalHost, transferInfo); + test->start(); +} + +void DownloadJobTest::awaitToBeDestroyedOrTimeOut() +{ + //Either the job is destroyed + connect(test, &QObject::destroyed, &mLoop, &QEventLoop::quit); + + //Or we time out + mTimer.setInterval(2000); + mTimer.setSingleShot(true); + connect(&mTimer, &QTimer::timeout, [this]() { + mLoop.quit(); + QFAIL("Test timed out"); + }); + mTimer.start(); + + //We wait + mLoop.exec(); + + mTimer.stop(); +} + +void DownloadJobTest::failToConnectShouldDestroyTheJob() +{ + initDownloadJob(); + awaitToBeDestroyedOrTimeOut(); +} + +void DownloadJobTest::closingTheConnectionShouldDestroyTheJob() +{ + initServer(); + initDownloadJob(); + stopServer(); + awaitToBeDestroyedOrTimeOut(); +} + +QTEST_GUILESS_MAIN(DownloadJobTest) + +#include "downloadjobtest.moc" From d2b4a6f214ba7402c36b5e5508cf73c9465f4a4b Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Sun, 18 Oct 2015 21:49:29 -0700 Subject: [PATCH 9/9] Indentation --- core/backends/lan/socketlinereader.cpp | 4 ++-- kio/kiokdeconnect.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/backends/lan/socketlinereader.cpp b/core/backends/lan/socketlinereader.cpp index a6bd85eec..b973b99a9 100644 --- a/core/backends/lan/socketlinereader.cpp +++ b/core/backends/lan/socketlinereader.cpp @@ -33,8 +33,8 @@ void SocketLineReader::dataReceived() { while (mSocket->canReadLine()) { const QByteArray line = mSocket->readLine(); - if (line.length() > 1) { - mPackages.enqueue(line);//we don't want single \n + if (line.length() > 1) { //we don't want a single \n + mPackages.enqueue(line); } } diff --git a/kio/kiokdeconnect.h b/kio/kiokdeconnect.h index c30195877..2586f9ebb 100644 --- a/kio/kiokdeconnect.h +++ b/kio/kiokdeconnect.h @@ -32,7 +32,7 @@ Q_DECLARE_LOGGING_CATEGORY(KDECONNECT_KIO) class KioKdeconnect : public QObject, public KIO::SlaveBase { - Q_OBJECT + Q_OBJECT public: KioKdeconnect(const QByteArray &pool, const QByteArray &app);