Commit f5adc483 authored by Volker Krause's avatar Volker Krause
Browse files

Import passes from temporary files without an extra copy

parent fd6719ec
......@@ -57,7 +57,7 @@ void handleViewIntent(PkPassManager *passMgr)
const auto scheme = uri.callObjectMethod("getScheme", "()Ljava/lang/String;");
if (scheme.toString() == QLatin1String("content")) {
const auto tmpFile = activity.callObjectMethod("receiveContent", "(Landroid/net/Uri;)Ljava/lang/String;", uri.object<jobject>());
passMgr->importPass(QUrl::fromLocalFile(tmpFile.toString()));
passMgr->importPassFromTempFile(tmpFile.toString());
} else if (scheme.toString() == QLatin1String("file")) {
const auto uriStr = uri.callObjectMethod("toString", "()Ljava/lang/String;");
passMgr->importPass(QUrl(uriStr.toString()));
......
......@@ -16,6 +16,7 @@
*/
#include "pkpassmanager.h"
#include "logging.h"
#include <KPkPass/File>
......@@ -65,6 +66,17 @@ KPkPass::File* PkPassManager::pass(const QString& passId)
void PkPassManager::importPass(const QUrl& url)
{
doImportPass(url, Copy);
}
void PkPassManager::importPassFromTempFile(const QString& tmpFile)
{
doImportPass(QUrl::fromLocalFile(tmpFile), Move);
}
void PkPassManager::doImportPass(const QUrl& url, PkPassManager::ImportMode mode)
{
qCDebug(Log) << url << mode;
if (!url.isLocalFile())
return; // TODO
......@@ -85,7 +97,16 @@ void PkPassManager::importPass(const QUrl& url)
// serialNumber() can contain percent-encoding or slashes,
// ie stuff we don't want to have in file names
const auto passId = QString::fromUtf8(file->serialNumber().toUtf8().toBase64(QByteArray::Base64UrlEncoding));
QFile::copy(url.toLocalFile(), dir.absoluteFilePath(passId + QLatin1String(".pkpass")));
switch (mode) {
case Move:
QFile::rename(url.toLocalFile(), dir.absoluteFilePath(passId + QLatin1String(".pkpass")));
break;
case Copy:
QFile::copy(url.toLocalFile(), dir.absoluteFilePath(passId + QLatin1String(".pkpass")));
break;
}
emit passAdded(dir.dirName() + QLatin1Char('/') + passId);
}
......
......@@ -37,12 +37,16 @@ public:
KPkPass::File* pass(const QString &passId);
Q_INVOKABLE void importPass(const QUrl &url);
void importPassFromTempFile(const QString &tmpFile);
Q_INVOKABLE void removePass(const QString &passId);
signals:
void passAdded(const QString &passId);
private:
enum ImportMode { Copy, Move };
void doImportPass(const QUrl &url, ImportMode mode);
QHash<QString, KPkPass::File*> m_passes;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment