diff --git a/kded/backends/lan/landevicelink.cpp b/kded/backends/lan/landevicelink.cpp index 3704696dc..b34074696 100644 --- a/kded/backends/lan/landevicelink.cpp +++ b/kded/backends/lan/landevicelink.cpp @@ -81,13 +81,16 @@ bool LanDeviceLink::sendPackage(NetworkPackage& np) void LanDeviceLink::dataReceived() { - //qDebug() << "LanDeviceLink dataReceived"; - QByteArray data = mSocket->readAll(); + + //qDebug() << "LanDeviceLink dataReceived" << data; + QList packages = data.split('\n'); Q_FOREACH(const QByteArray& package, packages) { - if (package.length() < 3) continue; + if (package.length() < 3) { + continue; + } NetworkPackage unserialized(QString::null); NetworkPackage::unserialize(package, &unserialized); @@ -109,15 +112,22 @@ void LanDeviceLink::dataReceived() } else { if (unserialized.hasPayloadTransferInfo()) { - //Lets ignore unencrypted payloads + qWarning() << "Ignoring unencrypted payload"; + continue; } - Q_EMIT receivedPackage(unserialized); } } + + //qDebug() << "MOAR BYTES" << mSocket->bytesAvailable() << packages.length(); + + if (mSocket->bytesAvailable() > 0) { + QMetaObject::invokeMethod(this, "dataReceived", Qt::QueuedConnection); + } + } void LanDeviceLink::readyRead() diff --git a/kded/backends/loopback/loopbacklinkprovider.cpp b/kded/backends/loopback/loopbacklinkprovider.cpp index 82d367b78..961a1bb18 100644 --- a/kded/backends/loopback/loopbacklinkprovider.cpp +++ b/kded/backends/loopback/loopbacklinkprovider.cpp @@ -45,6 +45,7 @@ void LoopbackLinkProvider::onNetworkChange(QNetworkSession::State state) if (loopbackDeviceLink) { delete loopbackDeviceLink; } + loopbackDeviceLink = newLoopbackDeviceLink; } diff --git a/kded/filetransferjob.cpp b/kded/filetransferjob.cpp index d8b3ad3cc..ce597ee04 100644 --- a/kded/filetransferjob.cpp +++ b/kded/filetransferjob.cpp @@ -27,17 +27,27 @@ FileTransferJob::FileTransferJob(const QSharedPointer& origin, int size, const KUrl& destination): KJob() { + Q_ASSERT(destination.isLocalFile()); + QFile(destination.path()).open(QIODevice::WriteOnly | QIODevice::Truncate); //HACK: KIO is so dumb it can't create the file if it doesn't exist mDestination = KIO::open(destination, QIODevice::WriteOnly); + connect(mDestination, SIGNAL(open(KIO::Job*)), this, SLOT(open(KIO::Job*))); + connect(mDestination, SIGNAL(result(KJob*)), this, SLOT(openFinished(KJob*))); mOrigin = origin; mSize = size; mWritten = 0; - qDebug() << "Downloading payload to" << destination; + qDebug() << "FileTransferJob Downloading payload to" << destination; +} + +void FileTransferJob::openFinished(KJob* job) +{ + qDebug() << job->errorString(); } void FileTransferJob::start() { + //qDebug() << "FileTransferJob start"; + //Open destination file - connect(mDestination, SIGNAL(open(KIO::Job*)), this, SLOT(open(KIO::Job*))); mDestination->start(); } @@ -45,7 +55,7 @@ void FileTransferJob::open(KIO::Job* job) { Q_UNUSED(job); - qDebug() << "open"; + //qDebug() << "FileTransferJob open"; if (!mOrigin) { qDebug() << "FileTransferJob: Origin is null"; @@ -64,21 +74,17 @@ void FileTransferJob::open(KIO::Job* job) void FileTransferJob::readyRead() { - qDebug() << "readyRead"; - - //Copy a chunk of data - int bytes = qMin(qint64(4096), mOrigin->bytesAvailable()); QByteArray data = mOrigin->read(bytes); mDestination->write(data); mWritten += bytes; + //qDebug() << "readyRead" << mSize << mWritten << bytes; + if (mSize > -1) { setPercent((mWritten*100)/mSize); } - qDebug() << mSize << mWritten << bytes; - if (mSize > -1 && mWritten >= mSize) { //At the end or expected size reached qDebug() << "No more data to read"; disconnect(mOrigin.data(), SIGNAL(readyRead()),this, SLOT(readyRead())); @@ -90,8 +96,6 @@ void FileTransferJob::readyRead() void FileTransferJob::sourceFinished() { - qDebug() << "sourceFinished"; - //Make sure we do not enter this function again disconnect(mOrigin.data(), SIGNAL(aboutToClose()),this, SLOT(sourceFinished())); @@ -104,7 +108,8 @@ void FileTransferJob::sourceFinished() } else { qDebug() << "Finished transfer" << mDestination->url(); } + mDestination->close(); + mDestination->deleteLater(); emitResult(); } - diff --git a/kded/filetransferjob.h b/kded/filetransferjob.h index eed813c00..e1a9b813d 100644 --- a/kded/filetransferjob.h +++ b/kded/filetransferjob.h @@ -44,6 +44,7 @@ public Q_SLOTS: void readyRead(); void open(KIO::Job*); void sourceFinished(); + void openFinished(KJob*); private: QSharedPointer mOrigin; diff --git a/kded/plugins/notifications/notificationsdbusinterface.cpp b/kded/plugins/notifications/notificationsdbusinterface.cpp index 2ed568fe9..1248c52d9 100644 --- a/kded/plugins/notifications/notificationsdbusinterface.cpp +++ b/kded/plugins/notifications/notificationsdbusinterface.cpp @@ -23,7 +23,6 @@ #include "../../filetransferjob.h" #include -#include #include #include @@ -34,8 +33,9 @@ NotificationsDbusInterface::NotificationsDbusInterface(Device* device, QObject * : QDBusAbstractAdaptor(parent) , mDevice(device) , mLastId(0) + , imagesDir(QDir::temp().absoluteFilePath("kdeconnect")) { - + imagesDir.mkpath(imagesDir.absolutePath()); } NotificationsDbusInterface::~NotificationsDbusInterface() @@ -56,8 +56,8 @@ void NotificationsDbusInterface::processPackage(const NetworkPackage& np) QString destination; if (np.hasPayload()) { - //TODO: Store the image with extension? - destination = QDir::temp().absoluteFilePath("kdeconnect/"+KMD5(np.get("appName").toLatin1()).hexDigest()); + QString filename = KMD5(np.get("appName").toLatin1()).hexDigest(); //TODO: Store with extension? + destination = imagesDir.absoluteFilePath(filename); FileTransferJob* job = np.createPayloadTransferJob(destination); job->start(); } diff --git a/kded/plugins/notifications/notificationsdbusinterface.h b/kded/plugins/notifications/notificationsdbusinterface.h index 38e42fbb0..9865ae7cc 100644 --- a/kded/plugins/notifications/notificationsdbusinterface.h +++ b/kded/plugins/notifications/notificationsdbusinterface.h @@ -25,6 +25,7 @@ #include #include #include +#include #include "../../device.h" #include "notification.h" @@ -59,6 +60,7 @@ private /*attributes*/: QHash mNotifications; QHash mInternalIdToPublicId; int mLastId; + QDir imagesDir; };