diff options
author | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2022-12-17 02:59:54 +0200 |
---|---|---|
committer | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2023-01-17 20:24:12 +0200 |
commit | f48abc46321502df2425aebc0999be2f5f3bf1f2 (patch) | |
tree | 377d7aefcb868b5e54e5ed4c0707fb8e38d693f6 /src | |
parent | d50d4e8b9febb670e5a48fdf5b60dff8456d8692 (diff) |
Android: handle move operation with content uris
Allow moving content uris if the destination is provided
a full content uri with a parent that's different from the
source content uri (i.e. different folders).
Note: since the underlaying Android APIs don't always know about
the parent of a uri, we do some step to deduce that, but that's
not always guaranteed to work.
Task-number: QTBUG-98974
Change-Id: If21954e5963f4eb0b96c7ccd983943ea2cab5b24
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
(cherry picked from commit c203ec2720b694fd877512da531a227e0f3310cb)
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/platforms/android/androidcontentfileengine.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/plugins/platforms/android/androidcontentfileengine.cpp b/src/plugins/platforms/android/androidcontentfileengine.cpp index ffda304308..1e6cd9baba 100644 --- a/src/plugins/platforms/android/androidcontentfileengine.cpp +++ b/src/plugins/platforms/android/androidcontentfileengine.cpp @@ -500,6 +500,7 @@ const QLatin1String COLUMN_SIZE("_size"); constexpr int FLAG_DIR_SUPPORTS_CREATE = 0x00000008; constexpr int FLAG_SUPPORTS_DELETE = 0x00000004; +constexpr int FLAG_SUPPORTS_MOVE = 0x00000100; constexpr int FLAG_SUPPORTS_RENAME = 0x00000040; constexpr int FLAG_SUPPORTS_WRITE = 0x00000002; constexpr int FLAG_VIRTUAL_DOCUMENT = 0x00000200; @@ -592,6 +593,24 @@ bool deleteDocument(const QJNIObjectPrivate &documentUri) documentUri.object()); } +QJNIObjectPrivate moveDocument(const QJNIObjectPrivate &sourceDocumentUri, + const QJNIObjectPrivate &sourceParentDocumentUri, + const QJNIObjectPrivate &targetParentDocumentUri) +{ + const int flags = Cursor::queryColumn(sourceDocumentUri, Document::COLUMN_FLAGS).toInt(); + if (!(flags & Document::FLAG_SUPPORTS_MOVE)) + return {}; + + JniExceptionCleaner cleaner; + return QJNIObjectPrivate::callStaticObjectMethod("android/provider/DocumentsContract", + "moveDocument", + "(Landroid/content/ContentResolver;Landroid/net/Uri;Landroid/net/Uri;Landroid/net/Uri;)Landroid/net/Uri;", + contentResolverInstance().object(), + sourceDocumentUri.object(), + sourceParentDocumentUri.object(), + targetParentDocumentUri.object()); +} + QJNIObjectPrivate renameDocument(const QJNIObjectPrivate &documentUri, const QString &displayName) { const int flags = Cursor::queryColumn(documentUri, Document::COLUMN_FLAGS).toInt(); @@ -848,6 +867,12 @@ bool DocumentFile::rename(const QString &newName) displayName.remove(0, 3); uri = renameDocument(m_uri, displayName); + } else { + // Move + QJNIObjectPrivate srcParentUri = fromTreeUri(parseUri(parent))->uri(); + const QString destParent = newName.left(lastSeparatorIndex(newName)); + QJNIObjectPrivate targetParentUri = fromTreeUri(parseUri(destParent))->uri(); + uri = moveDocument(m_uri, srcParentUri, targetParentUri); } } else { uri = renameDocument(m_uri, newName); |