set last modified time for files received in Android-> PC transfers

This commit is contained in:
Piyush Aggarwal 2019-05-11 19:52:00 +00:00
parent bba2d33579
commit 98bd91bf1c
3 changed files with 22 additions and 5 deletions

View file

@ -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)

View file

@ -28,6 +28,7 @@
#include <QDBusConnection>
#include <QDebug>
#include <QTemporaryFile>
#include <QDateTime>
#include <KLocalizedString>
#include <KJobTrackerInterface>
@ -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)
{
/*
@ -110,9 +124,10 @@ bool SharePlugin::receivePacket(const NetworkPacket& np)
QUrl destination = getFileDestination(filename);
if (np.hasPayload()) {
qint64 dateModified = np.get<qint64>(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<FileTransferJob*>(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());

View file

@ -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