[SCM] kdeconnect packaging branch, master, updated. debian/0.9g-1-1183-g9d69498
Maximiliano Curia
maxy at moszumanska.debian.org
Fri Oct 14 14:27:02 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/kde-extras/kdeconnect.git;a=commitdiff;h=4bd5d2e
The following commit has been merged in the master branch:
commit 4bd5d2e4273f2a6066dadfe70520a9c50ffedad6
Author: Albert Vaca <albertvaka at gmail.com>
Date: Tue Sep 24 14:13:02 2013 +0200
Payloads are now QSharedPointer<QIODevice> instead of QIODevice*
---
kded/backends/lan/downloadjob.cpp | 7 +++--
kded/backends/lan/downloadjob.h | 8 +++--
kded/backends/lan/uploadjob.cpp | 6 ++--
kded/backends/lan/uploadjob.h | 5 +--
kded/backends/loopback/loopbackdevicelink.cpp | 6 ++--
kded/filetransferjob.cpp | 45 ++++++++-------------------
kded/filetransferjob.h | 10 +++---
kded/networkpackage.cpp | 5 ++-
kded/networkpackage.h | 8 ++---
9 files changed, 40 insertions(+), 60 deletions(-)
diff --git a/kded/backends/lan/downloadjob.cpp b/kded/backends/lan/downloadjob.cpp
index d868015..58a0ac2 100644
--- a/kded/backends/lan/downloadjob.cpp
+++ b/kded/backends/lan/downloadjob.cpp
@@ -22,9 +22,10 @@
DownloadJob::DownloadJob(QHostAddress address, QVariantMap transferInfo): KJob()
{
+ mAddress = address;
mPort = transferInfo["port"].toInt();
mSocket = new QTcpSocket();
- mAddress = address;
+ mOutput = QSharedPointer<QIODevice>(mSocket);
}
void DownloadJob::start()
@@ -40,8 +41,8 @@ void DownloadJob::disconnected()
emitResult();
}
-QIODevice* DownloadJob::getPayload()
+QSharedPointer<QIODevice> DownloadJob::getPayload()
{
qDebug() << "getPayload";
- return mSocket;
+ return mOutput;
}
diff --git a/kded/backends/lan/downloadjob.h b/kded/backends/lan/downloadjob.h
index 4cf2879..ff428c1 100644
--- a/kded/backends/lan/downloadjob.h
+++ b/kded/backends/lan/downloadjob.h
@@ -27,6 +27,7 @@
#include <QVariantMap>
#include <QHostAddress>
#include <QTcpSocket>
+#include <QSharedPointer>
class DownloadJob
: public KJob
@@ -35,13 +36,14 @@ class DownloadJob
public:
DownloadJob(QHostAddress address, QVariantMap transferInfo);
virtual void start();
- QIODevice* getPayload();
+ QSharedPointer<QIODevice> getPayload();
private:
- QIODevice* mOutput;
- QTcpSocket* mSocket;
QHostAddress mAddress;
qint16 mPort;
+ QTcpSocket* mSocket;
+ QSharedPointer<QIODevice> mOutput;
+
private Q_SLOTS:
void disconnected();
diff --git a/kded/backends/lan/uploadjob.cpp b/kded/backends/lan/uploadjob.cpp
index af8009c..a5c739e 100644
--- a/kded/backends/lan/uploadjob.cpp
+++ b/kded/backends/lan/uploadjob.cpp
@@ -23,7 +23,7 @@
#include "uploadjob.h"
-UploadJob::UploadJob(QIODevice* source): KJob()
+UploadJob::UploadJob(const QSharedPointer<QIODevice>& source): KJob()
{
mInput = source;
mServer = new QTcpServer(this);
@@ -51,8 +51,8 @@ void UploadJob::newConnection()
mSocket = mServer->nextPendingConnection();
- connect(mInput, SIGNAL(readyRead()), this, SLOT(readyRead()));
- connect(mInput, SIGNAL(aboutToClose()), this, SLOT(aboutToClose()));
+ connect(mInput.data(), SIGNAL(readyRead()), this, SLOT(readyRead()));
+ connect(mInput.data(), SIGNAL(aboutToClose()), this, SLOT(aboutToClose()));
if (!mInput->open(QIODevice::ReadOnly)) {
return; //TODO: Handle error, clean up...
diff --git a/kded/backends/lan/uploadjob.h b/kded/backends/lan/uploadjob.h
index a0a6474..4b3dd4d 100644
--- a/kded/backends/lan/uploadjob.h
+++ b/kded/backends/lan/uploadjob.h
@@ -27,18 +27,19 @@
#include <QVariantMap>
#include <QTcpServer>
#include <QTcpSocket>
+#include <QSharedPointer>
class UploadJob
: public KJob
{
Q_OBJECT
public:
- UploadJob(QIODevice* source);
+ UploadJob(const QSharedPointer<QIODevice>& source);
virtual void start();
QVariantMap getTransferInfo();
private:
- QIODevice* mInput;
+ QSharedPointer<QIODevice> mInput;
QTcpServer* mServer;
QTcpSocket* mSocket;
qint16 mPort;
diff --git a/kded/backends/loopback/loopbackdevicelink.cpp b/kded/backends/loopback/loopbackdevicelink.cpp
index c16a02e..718c5b8 100644
--- a/kded/backends/loopback/loopbackdevicelink.cpp
+++ b/kded/backends/loopback/loopbackdevicelink.cpp
@@ -46,8 +46,7 @@ bool LoopbackDeviceLink::sendPackageEncrypted(QCA::PublicKey& key, NetworkPackag
//LoopbackDeviceLink does not need deviceTransferInfo
if (input.hasPayload()) {
- QIODevice* device = input.payload();
- output.setPayload(device, input.payloadSize());
+ output.setPayload(input.payload(), input.payloadSize());
}
Q_EMIT receivedPackage(output);
@@ -62,8 +61,7 @@ bool LoopbackDeviceLink::sendPackage(NetworkPackage& input)
//LoopbackDeviceLink does not need deviceTransferInfo
if (input.hasPayload()) {
- QIODevice* device = input.payload();
- output.setPayload(device, input.payloadSize());
+ output.setPayload(input.payload(), input.payloadSize());
}
Q_EMIT receivedPackage(output);
diff --git a/kded/filetransferjob.cpp b/kded/filetransferjob.cpp
index 876b817..d8b3ad3 100644
--- a/kded/filetransferjob.cpp
+++ b/kded/filetransferjob.cpp
@@ -25,26 +25,20 @@
#include <QDebug>
#include <qalgorithms.h>
-FileTransferJob::FileTransferJob(QIODevice* origin, int size, const KUrl& destination): KJob()
+FileTransferJob::FileTransferJob(const QSharedPointer<QIODevice>& origin, int size, const KUrl& destination): KJob()
{
- mDestination = destination;
+ mDestination = KIO::open(destination, QIODevice::WriteOnly);
mOrigin = origin;
mSize = size;
mWritten = 0;
+ qDebug() << "Downloading payload to" << destination;
}
void FileTransferJob::start()
{
//Open destination file
-
- QTemporaryFile tmp;
- tmp.setAutoRemove(false);
- tmp.open();
-
- mTempDestination = KIO::open(tmp.fileName(), QIODevice::WriteOnly);
- connect(mTempDestination, SIGNAL(open(KIO::Job*)), this, SLOT(open(KIO::Job*)));
- mTempDestination->start();
-
+ connect(mDestination, SIGNAL(open(KIO::Job*)), this, SLOT(open(KIO::Job*)));
+ mDestination->start();
}
void FileTransferJob::open(KIO::Job* job)
@@ -62,8 +56,8 @@ void FileTransferJob::open(KIO::Job* job)
mOrigin->open(QIODevice::ReadOnly);
Q_ASSERT(mOrigin->isOpen());
- connect(mOrigin, SIGNAL(readyRead()),this, SLOT(readyRead()));
- connect(mOrigin, SIGNAL(disconnected()),this, SLOT(sourceFinished()));
+ connect(mOrigin.data(), SIGNAL(readyRead()),this, SLOT(readyRead()));
+ connect(mOrigin.data(), SIGNAL(disconnected()),this, SLOT(sourceFinished()));
if (mOrigin->bytesAvailable() > 0) readyRead();
}
@@ -76,7 +70,7 @@ void FileTransferJob::readyRead()
int bytes = qMin(qint64(4096), mOrigin->bytesAvailable());
QByteArray data = mOrigin->read(bytes);
- mTempDestination->write(data);
+ mDestination->write(data);
mWritten += bytes;
if (mSize > -1) {
@@ -87,7 +81,7 @@ void FileTransferJob::readyRead()
if (mSize > -1 && mWritten >= mSize) { //At the end or expected size reached
qDebug() << "No more data to read";
- disconnect(mOrigin, SIGNAL(readyRead()),this, SLOT(readyRead()));
+ disconnect(mOrigin.data(), SIGNAL(readyRead()),this, SLOT(readyRead()));
mOrigin->close();
} else if (mOrigin->bytesAvailable() > 0) {
QMetaObject::invokeMethod(this, "readyRead", Qt::QueuedConnection);
@@ -99,7 +93,7 @@ void FileTransferJob::sourceFinished()
qDebug() << "sourceFinished";
//Make sure we do not enter this function again
- disconnect(mOrigin, SIGNAL(aboutToClose()),this, SLOT(sourceFinished()));
+ disconnect(mOrigin.data(), SIGNAL(aboutToClose()),this, SLOT(sourceFinished()));
//TODO: MD5 check the file
if (mSize > -1 && mWritten != mSize) {
@@ -107,23 +101,10 @@ void FileTransferJob::sourceFinished()
setError(1);
setErrorText(i18n("Received incomplete file"));
emitResult();
- }
-
- qDebug() << "Finished" << mTempDestination->url() << mDestination;
- KIO::FileCopyJob* job = KIO::file_move(mTempDestination->url(), mDestination);
- connect(job, SIGNAL(result(KJob*)), this, SLOT(moveResult(KJob*)));
- job->start();
-
- //delete mOrigin; //TODO: Use shared pointers
-}
-
-void FileTransferJob::moveResult(KJob* job)
-{
- //TODO: Error handling, cleanup
- qDebug() << "Move finished";
- if (job->error()) {
- qDebug() << job->errorText();
+ } else {
+ qDebug() << "Finished transfer" << mDestination->url();
}
emitResult();
}
+
diff --git a/kded/filetransferjob.h b/kded/filetransferjob.h
index d38d0fe..8923291 100644
--- a/kded/filetransferjob.h
+++ b/kded/filetransferjob.h
@@ -35,21 +35,19 @@ class FileTransferJob : public KJob
Q_OBJECT
public:
- FileTransferJob(QIODevice* origin, int size, const KUrl& destination);
+ FileTransferJob(const QSharedPointer<QIODevice>& origin, int size, const KUrl& destination);
virtual void start();
- KUrl destination() { return mDestination; }
+ KUrl destination() { return mDestination->url(); }
public Q_SLOTS:
void readyRead();
- void moveResult(KJob*);
void open(KIO::Job*);
void sourceFinished();
private:
- KIO::FileJob* mTempDestination;
- KUrl mDestination;
+ QSharedPointer<QIODevice> mOrigin;
+ KIO::FileJob* mDestination;
int mSize;
- QIODevice* mOrigin;
int mWritten;
};
diff --git a/kded/networkpackage.cpp b/kded/networkpackage.cpp
index 86b691e..7949e93 100644
--- a/kded/networkpackage.cpp
+++ b/kded/networkpackage.cpp
@@ -29,7 +29,6 @@
#include <QSslKey>
#include <QDateTime>
#include <QtCrypto>
-
#include <qjson/serializer.h>
#include <qjson/qobjecthelper.h>
@@ -43,7 +42,7 @@ NetworkPackage::NetworkPackage(const QString& type)
mId = QString::number(QDateTime::currentMSecsSinceEpoch());
mType = type;
mBody = QVariantMap();
- mPayload = 0;
+ mPayload = QSharedPointer<QIODevice>();
mPayloadSize = 0;
}
@@ -53,7 +52,7 @@ void NetworkPackage::createIdentityPackage(NetworkPackage* np)
QString id = config->group("myself").readEntry<QString>("id","");
np->mId = QString::number(QDateTime::currentMSecsSinceEpoch());
np->mType = PACKAGE_TYPE_IDENTITY;
- np->mPayload = 0;
+ np->mPayload = QSharedPointer<QIODevice>();
np->mPayloadSize = 0;
np->set("deviceId", id);
np->set("deviceName", QHostInfo::localHostName());
diff --git a/kded/networkpackage.h b/kded/networkpackage.h
index 37433ec..5d6ce67 100644
--- a/kded/networkpackage.h
+++ b/kded/networkpackage.h
@@ -32,6 +32,7 @@
#include <QStringList>
#include <QIODevice>
#include <QtCrypto>
+#include <QSharedPointer>
#include <qjson/parser.h>
@@ -73,9 +74,8 @@ public:
template<typename T> void set(const QString& key, const T& value) { mBody[key] = QVariant(value); }
bool has(const QString& key) const { return mBody.contains(key); }
- //TODO: Change to a shared pointer
- QIODevice* payload() const { return mPayload; }
- void setPayload(QIODevice* device, int payloadSize) { mPayload = device; mPayloadSize = payloadSize; Q_ASSERT(mPayloadSize >= -1); }
+ QSharedPointer<QIODevice> payload() const { return mPayload; }
+ void setPayload(const QSharedPointer<QIODevice>& device, int payloadSize) { mPayload = device; mPayloadSize = payloadSize; Q_ASSERT(mPayloadSize >= -1); }
bool hasPayload() const { return (mPayloadSize != 0); }
int payloadSize() const { return mPayloadSize; } //-1 means it is an endless stream
FileTransferJob* createPayloadTransferJob(const KUrl& destination) const;
@@ -96,7 +96,7 @@ private:
QString mType;
QVariantMap mBody;
- QIODevice* mPayload;
+ QSharedPointer<QIODevice> mPayload;
int mPayloadSize;
QVariantMap mPayloadTransferInfo;
--
kdeconnect packaging
More information about the pkg-kde-commits
mailing list