Commit 4a63b6a2 authored by Volker Krause's avatar Volker Krause

Add Android support for adding documents

parent 82f9cf20
......@@ -474,24 +474,46 @@ void ApplicationController::addDocument(const QString &batchId)
QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation)),
i18n("All Files (*.*)"));
if (url.isValid()) {
const auto docId = QUuid::createUuid().toString();
auto res = m_resMgr->reservation(batchId);
DocumentUtil::addDocumentId(res, docId);
addDocument(batchId, url);
}
#else
const auto ACTION_OPEN_DOCUMENT = QAndroidJniObject::getStaticObjectField<jstring>("android/content/Intent", "ACTION_OPEN_DOCUMENT");
QAndroidJniObject intent("android/content/Intent", "(Ljava/lang/String;)V", ACTION_OPEN_DOCUMENT.object());
const auto CATEGORY_OPENABLE = QAndroidJniObject::getStaticObjectField<jstring>("android/content/Intent", "CATEGORY_OPENABLE");
intent.callObjectMethod("addCategory", "(Ljava/lang/String;)Landroid/content/Intent;", CATEGORY_OPENABLE.object());
intent.callObjectMethod("setType", "(Ljava/lang/String;)Landroid/content/Intent;", QAndroidJniObject::fromString(QStringLiteral("*/*")).object());
QtAndroid::startActivity(intent, 0, new ActivityResultReceiver([this, batchId](int, int, const QAndroidJniObject &intent) {
if (!intent.isValid()) {
return;
}
const auto uri = intent.callObjectMethod("getData", "()Landroid/net/Uri;");
if (!uri.isValid()) {
return;
}
const auto uriStr = uri.callObjectMethod("toString", "()Ljava/lang/String;");
addDocument(batchId, QUrl(uriStr.toString()));
}));
#endif
}
DigitalDocument docInfo;
docInfo.setName(url.fileName());
void ApplicationController::addDocument(const QString &batchId, const QUrl &url)
{
const auto docId = QUuid::createUuid().toString();
auto res = m_resMgr->reservation(batchId);
DocumentUtil::addDocumentId(res, docId);
QMimeDatabase db;
docInfo.setEncodingFormat(db.mimeTypeForFile(url.isLocalFile() ? url.toLocalFile() : url.toString()).name());
DigitalDocument docInfo;
docInfo.setName(url.fileName());
m_docMgr->addDocument(docId, docInfo, url.isLocalFile() ? url.toLocalFile() : url.toString());
QMimeDatabase db;
docInfo.setEncodingFormat(db.mimeTypeForFile(url.isLocalFile() ? url.toLocalFile() : url.toString()).name());
const auto resIds = m_resMgr->reservationsForBatch(batchId);
for (const auto &resId : resIds) {
m_resMgr->updateReservation(resId, res);
}
m_docMgr->addDocument(docId, docInfo, url.isLocalFile() ? url.toLocalFile() : url.toString());
const auto resIds = m_resMgr->reservationsForBatch(batchId);
for (const auto &resId : resIds) {
m_resMgr->updateReservation(resId, res);
}
#endif
}
void ApplicationController::removeDocument(const QString &batchId, const QString &docId)
......
......@@ -80,6 +80,7 @@ Q_SIGNALS:
private:
void importLocalFile(const QUrl &url);
void importBundle(KItinerary::File *file);
void addDocument(const QString &batchId, const QUrl &url);
static ApplicationController *s_instance;
......
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