set last modified time for files received in Android-> PC transfers
This commit is contained in:
parent
bba2d33579
commit
98bd91bf1c
3 changed files with 22 additions and 5 deletions
|
@ -23,7 +23,7 @@ if (SAILFISHOS)
|
||||||
add_definitions(-DQT_NO_URL_CAST_FROM_STRING)
|
add_definitions(-DQT_NO_URL_CAST_FROM_STRING)
|
||||||
else()
|
else()
|
||||||
set(KF5_MIN_VERSION "5.42.0")
|
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_REQUIRED_COMPONENTS I18n ConfigWidgets DBusAddons IconThemes Notifications KIO KCMUtils Service)
|
||||||
set(KF5_OPTIONAL_COMPONENTS DocTools)
|
set(KF5_OPTIONAL_COMPONENTS DocTools)
|
||||||
if(UNIX)
|
if(UNIX)
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <QDBusConnection>
|
#include <QDBusConnection>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QTemporaryFile>
|
#include <QTemporaryFile>
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
#include <KJobTrackerInterface>
|
#include <KJobTrackerInterface>
|
||||||
|
@ -81,6 +82,19 @@ static QString cleanFilename(const QString &filename)
|
||||||
return idx>=0 ? filename.mid(idx + 1) : 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)
|
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;
|
// qCDebug(KDECONNECT_PLUGIN_SHARE) << "receiving file" << filename << "in" << dir << "into" << destination;
|
||||||
const QString filename = cleanFilename(np.get<QString>(QStringLiteral("filename"), QString::number(QDateTime::currentMSecsSinceEpoch())));
|
const QString filename = cleanFilename(np.get<QString>(QStringLiteral("filename"), QString::number(QDateTime::currentMSecsSinceEpoch())));
|
||||||
QUrl destination = getFileDestination(filename);
|
QUrl destination = getFileDestination(filename);
|
||||||
|
|
||||||
if (np.hasPayload()) {
|
if (np.hasPayload()) {
|
||||||
|
qint64 dateModified = np.get<qint64>(QStringLiteral("lastModified"), QDateTime::currentMSecsSinceEpoch());
|
||||||
FileTransferJob* job = np.createPayloadTransferJob(destination);
|
FileTransferJob* job = np.createPayloadTransferJob(destination);
|
||||||
job->setOriginName(device()->name() + ": " + filename);
|
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);
|
KIO::getJobTracker()->registerJob(job);
|
||||||
job->start();
|
job->start();
|
||||||
} else {
|
} else {
|
||||||
|
@ -155,11 +170,12 @@ bool SharePlugin::receivePacket(const NetworkPacket& np)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SharePlugin::finished(KJob* job)
|
void SharePlugin::finished(KJob* job, const qint64 dateModified)
|
||||||
{
|
{
|
||||||
FileTransferJob* ftjob = qobject_cast<FileTransferJob*>(job);
|
FileTransferJob* ftjob = qobject_cast<FileTransferJob*>(job);
|
||||||
if (ftjob && !job->error()) {
|
if (ftjob && !job->error()) {
|
||||||
Q_EMIT shareReceived(ftjob->destination().toString());
|
Q_EMIT shareReceived(ftjob->destination().toString());
|
||||||
|
setDateModified(ftjob->destination(), dateModified);
|
||||||
qCDebug(KDECONNECT_PLUGIN_SHARE) << "File transfer finished." << ftjob->destination();
|
qCDebug(KDECONNECT_PLUGIN_SHARE) << "File transfer finished." << ftjob->destination();
|
||||||
} else {
|
} else {
|
||||||
qCDebug(KDECONNECT_PLUGIN_SHARE) << "File transfer failed." << (ftjob ? ftjob->destination() : QUrl());
|
qCDebug(KDECONNECT_PLUGIN_SHARE) << "File transfer failed." << (ftjob ? ftjob->destination() : QUrl());
|
||||||
|
|
|
@ -48,16 +48,17 @@ public:
|
||||||
QString dbusPath() const override;
|
QString dbusPath() const override;
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void finished(KJob*);
|
|
||||||
void openDestinationFolder();
|
void openDestinationFolder();
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
Q_SCRIPTABLE void shareReceived(const QString& url);
|
Q_SCRIPTABLE void shareReceived(const QString& url);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void finished(KJob* job, const qint64 dateModified);
|
||||||
void shareUrl(const QUrl& url);
|
void shareUrl(const QUrl& url);
|
||||||
void openFile(const QUrl& url);
|
void openFile(const QUrl& url);
|
||||||
QUrl destinationDir() const;
|
QUrl destinationDir() const;
|
||||||
QUrl getFileDestination(const QString filename) const;
|
QUrl getFileDestination(const QString filename) const;
|
||||||
|
void setDateModified(const QUrl& destination, const qint64 timestamp);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue