diff --git a/CMakeLists.txt b/CMakeLists.txt index 323359263..40278e9cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ if (SAILFISHOS) add_definitions(-DQT_NO_URL_CAST_FROM_STRING) else() set(KF5_MIN_VERSION "5.42.0") - set(QT_MIN_VERSION "5.7.0") + set(QT_MIN_VERSION "5.10.0") set(KF5_REQUIRED_COMPONENTS I18n ConfigWidgets DBusAddons IconThemes Notifications KIO KCMUtils Service) set(KF5_OPTIONAL_COMPONENTS DocTools) if(UNIX) diff --git a/plugins/share/shareplugin.cpp b/plugins/share/shareplugin.cpp index 72a306cc2..6bd767b28 100644 --- a/plugins/share/shareplugin.cpp +++ b/plugins/share/shareplugin.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -81,6 +82,19 @@ static QString cleanFilename(const QString &filename) return idx>=0 ? filename.mid(idx + 1) : filename; } +void SharePlugin::setDateModified(const QUrl& destination, const qint64 timestamp) +{ + QFile receivedFile(destination.toLocalFile()); + if (!receivedFile.exists()) { + if (!receivedFile.open(QIODevice::ReadWrite | QIODevice::Text)) { + QString error_msg = receivedFile.errorString(); + return; + } + } + receivedFile.open(QIODevice::ReadWrite | QIODevice::Text); + receivedFile.setFileTime(QDateTime::fromMSecsSinceEpoch(timestamp), QFileDevice::FileTime(QFileDevice::FileModificationTime)); +} + bool SharePlugin::receivePacket(const NetworkPacket& np) { /* @@ -108,11 +122,12 @@ bool SharePlugin::receivePacket(const NetworkPacket& np) // qCDebug(KDECONNECT_PLUGIN_SHARE) << "receiving file" << filename << "in" << dir << "into" << destination; const QString filename = cleanFilename(np.get(QStringLiteral("filename"), QString::number(QDateTime::currentMSecsSinceEpoch()))); QUrl destination = getFileDestination(filename); - + if (np.hasPayload()) { + qint64 dateModified = np.get(QStringLiteral("lastModified"), QDateTime::currentMSecsSinceEpoch()); FileTransferJob* job = np.createPayloadTransferJob(destination); job->setOriginName(device()->name() + ": " + filename); - connect(job, &KJob::result, this, &SharePlugin::finished); + connect(job, &KJob::result, this, [this, dateModified] (KJob* job) -> void { finished(job, dateModified); }); KIO::getJobTracker()->registerJob(job); job->start(); } else { @@ -155,11 +170,12 @@ bool SharePlugin::receivePacket(const NetworkPacket& np) return true; } -void SharePlugin::finished(KJob* job) +void SharePlugin::finished(KJob* job, const qint64 dateModified) { FileTransferJob* ftjob = qobject_cast(job); if (ftjob && !job->error()) { Q_EMIT shareReceived(ftjob->destination().toString()); + setDateModified(ftjob->destination(), dateModified); qCDebug(KDECONNECT_PLUGIN_SHARE) << "File transfer finished." << ftjob->destination(); } else { qCDebug(KDECONNECT_PLUGIN_SHARE) << "File transfer failed." << (ftjob ? ftjob->destination() : QUrl()); diff --git a/plugins/share/shareplugin.h b/plugins/share/shareplugin.h index 16a51cbb7..caac5ff98 100644 --- a/plugins/share/shareplugin.h +++ b/plugins/share/shareplugin.h @@ -48,16 +48,17 @@ public: QString dbusPath() const override; private Q_SLOTS: - void finished(KJob*); void openDestinationFolder(); Q_SIGNALS: Q_SCRIPTABLE void shareReceived(const QString& url); private: + void finished(KJob* job, const qint64 dateModified); void shareUrl(const QUrl& url); void openFile(const QUrl& url); QUrl destinationDir() const; QUrl getFileDestination(const QString filename) const; + void setDateModified(const QUrl& destination, const qint64 timestamp); }; #endif