From 134eae63dd7246ba0bb1e1ff73e7d031ce7bba6d Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Fri, 29 Sep 2023 01:24:01 +0800 Subject: [PATCH] Add static convenience method to FileProviderItemMetadata to convert from NSFileProviderItem Signed-off-by: Claudio Cambra --- src/gui/macOS/fileprovideritemmetadata.h | 2 + src/gui/macOS/fileprovideritemmetadata_mac.mm | 49 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/gui/macOS/fileprovideritemmetadata.h b/src/gui/macOS/fileprovideritemmetadata.h index 82b91bf5f..6ec4c0aca 100644 --- a/src/gui/macOS/fileprovideritemmetadata.h +++ b/src/gui/macOS/fileprovideritemmetadata.h @@ -56,6 +56,8 @@ class FileProviderItemMetadata Q_PROPERTY(bool sharedByCurrentUser READ sharedByCurrentUser CONSTANT) public: + static FileProviderItemMetadata fromNSFileProviderItem(const void *const nsFileProviderItem); + QString identifier() const; QString parentItemIdentifier() const; QString filename() const; diff --git a/src/gui/macOS/fileprovideritemmetadata_mac.mm b/src/gui/macOS/fileprovideritemmetadata_mac.mm index 5521baa46..9248873ff 100644 --- a/src/gui/macOS/fileprovideritemmetadata_mac.mm +++ b/src/gui/macOS/fileprovideritemmetadata_mac.mm @@ -41,3 +41,52 @@ QHash extendedAttributesToHash(NSDictionary bridgedNsFileProviderItem = (__bridge id)nsFileProviderItem; + if (bridgedNsFileProviderItem == nil) { + return {}; + } + + metadata._identifier = QString::fromNSString(bridgedNsFileProviderItem.itemIdentifier); + metadata._parentItemIdentifier = QString::fromNSString(bridgedNsFileProviderItem.parentItemIdentifier); + metadata._filename = QString::fromNSString(bridgedNsFileProviderItem.filename); + metadata._typeIdentifier = QString::fromNSString(bridgedNsFileProviderItem.contentType.identifier); + metadata._symlinkTargetPath = QString::fromNSString(bridgedNsFileProviderItem.symlinkTargetPath); + metadata._uploadingError = QString::fromNSString(bridgedNsFileProviderItem.uploadingError.localizedDescription); + metadata._downloadingError = QString::fromNSString(bridgedNsFileProviderItem.downloadingError.localizedDescription); + metadata._mostRecentEditorName = nsNameComponentsToLocalisedQString(bridgedNsFileProviderItem.mostRecentEditorNameComponents); + metadata._ownerName = nsNameComponentsToLocalisedQString(bridgedNsFileProviderItem.ownerNameComponents); + metadata._contentModificationDate = QDateTime::fromNSDate(bridgedNsFileProviderItem.contentModificationDate); + metadata._creationDate = QDateTime::fromNSDate(bridgedNsFileProviderItem.creationDate); + metadata._lastUsedDate = QDateTime::fromNSDate(bridgedNsFileProviderItem.lastUsedDate); + metadata._contentVersion = QByteArray::fromNSData(bridgedNsFileProviderItem.itemVersion.contentVersion); + metadata._metadataVersion = QByteArray::fromNSData(bridgedNsFileProviderItem.itemVersion.metadataVersion); + metadata._tagData = QByteArray::fromNSData(bridgedNsFileProviderItem.tagData); + metadata._extendedAttributes = extendedAttributesToHash(bridgedNsFileProviderItem.extendedAttributes); + metadata._capabilities = bridgedNsFileProviderItem.capabilities; + metadata._fileSystemFlags = bridgedNsFileProviderItem.fileSystemFlags; + metadata._childItemCount = bridgedNsFileProviderItem.childItemCount.unsignedIntegerValue; + metadata._typeOsCode = bridgedNsFileProviderItem.typeAndCreator.type; + metadata._creatorOsCode = bridgedNsFileProviderItem.typeAndCreator.creator; + metadata._documentSize = bridgedNsFileProviderItem.documentSize.unsignedLongLongValue; + metadata._mostRecentVersionDownloaded = bridgedNsFileProviderItem.mostRecentVersionDownloaded; + metadata._uploading = bridgedNsFileProviderItem.uploading; + metadata._uploaded = bridgedNsFileProviderItem.uploaded; + metadata._downloading = bridgedNsFileProviderItem.downloading; + metadata._downloaded = bridgedNsFileProviderItem.downloaded; + metadata._shared = bridgedNsFileProviderItem.shared; + metadata._sharedByCurrentUser = bridgedNsFileProviderItem.sharedByCurrentUser; + + return metadata; +} + +} + +}