Commit 5cdce52f authored by Volker Krause's avatar Volker Krause

Remove custom content URL handling

We now rely on QFile doing that.
parent fb35cf43
......@@ -298,14 +298,6 @@ void ApplicationController::importFromIntent(const QAndroidJniObject &intent)
return;
}
const auto scheme = uri.callObjectMethod("getScheme", "()Ljava/lang/String;");
qCDebug(Log) << uri.callObjectMethod("toString", "()Ljava/lang/String;").toString();
if (scheme.toString() == QLatin1String("content")) {
const auto tmpFile = QtAndroid::androidActivity().callObjectMethod("receiveContent", "(Landroid/net/Uri;)Ljava/lang/String;", uri.object<jobject>());
const auto tmpUrl = QUrl::fromLocalFile(tmpFile.toString());
importLocalFile(tmpUrl, true);
return;
}
const auto uriStr = uri.callObjectMethod("toString", "()Ljava/lang/String;");
importFromUrl(QUrl(uriStr.toString()));
}
......@@ -347,8 +339,8 @@ void ApplicationController::importFromClipboard()
void ApplicationController::importFromUrl(const QUrl &url)
{
qCDebug(Log) << url;
if (url.isLocalFile()) {
importLocalFile(url, false);
if (url.isLocalFile() || url.scheme() == QLatin1String("content")) {
importLocalFile(url);
return;
}
......@@ -374,15 +366,16 @@ void ApplicationController::importFromUrl(const QUrl &url)
qCDebug(Log) << "Unhandled URL type:" << url;
}
void ApplicationController::importLocalFile(const QUrl &url, bool isTempFile)
void ApplicationController::importLocalFile(const QUrl &url)
{
qCDebug(Log) << url;
if (url.isEmpty() || !url.isLocalFile())
if (url.isEmpty()) {
return;
}
QFile f(url.toLocalFile());
QFile f(url.isLocalFile() ? url.toLocalFile() : url.toString());
if (!f.open(QFile::ReadOnly)) {
qCWarning(Log) << "Failed to open" << url << f.errorString();
qCWarning(Log) << "Failed to open" << f.fileName() << f.errorString();
return;
}
......@@ -393,10 +386,7 @@ void ApplicationController::importLocalFile(const QUrl &url, bool isTempFile)
qCWarning(Log) << "Unknown content type:" << url;
break;
case ContentTypeProber::PkPass:
if (isTempFile)
m_pkPassMgr->importPassFromTempFile(url);
else
m_pkPassMgr->importPass(url);
m_pkPassMgr->importPass(url);
break;
case ContentTypeProber::JsonLd:
m_resMgr->importReservation(f.readAll());
......
......@@ -66,7 +66,7 @@ Q_SIGNALS:
void clipboardContentChanged();
private:
void importLocalFile(const QUrl &url, bool isTempFile);
void importLocalFile(const QUrl &url);
void importPdf(const QByteArray &data);
void importIataBcbp(const QByteArray &data);
......
......@@ -43,7 +43,6 @@ public:
/** Import pass from a local @p url, returns the pass id if successful. */
QString importPass(const QUrl &url);
void importPassFromTempFile(const QUrl &tmpFile);
void importPassFromData(const QByteArray &data);
Q_INVOKABLE void removePass(const QString &passId);
......@@ -60,6 +59,7 @@ Q_SIGNALS:
private:
enum ImportMode { Copy, Move, Data };
void importPassFromTempFile(const QUrl &tmpFile);
QString doImportPass(const QUrl &url, const QByteArray &data, ImportMode mode);
QHash<QString, KPkPass::Pass*> m_passes;
......
......@@ -37,34 +37,6 @@ public class Activity extends QtActivity
{
private static final String TAG = "org.kde.itinerary";
public String receiveContent(Uri uri)
{
ContentResolver resolver = getContentResolver();
File tempFile = new File(getCacheDir(), "content"); // TODO use random name
try {
InputStream is = resolver.openInputStream(uri);
tempFile.createNewFile();
FileOutputStream os = new FileOutputStream(tempFile);
while (true) {
byte[] buffer = new byte[4096];
int size = is.read(buffer, 0, 4096);
if (size < 0) {
break;
}
os.write(buffer, 0, size);
}
os.close();
} catch (Exception e) {
Log.e(TAG, e.toString());
return "";
}
return tempFile.toString();
}
public void launchViewIntentFromUri(String uri)
{
Uri mapIntentUri = Uri.parse(uri);
......
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