Add static convenience method to FileProviderItemMetadata to convert from NSFileProviderItem

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2023-09-29 01:24:01 +08:00
parent e3a0dabb07
commit 134eae63dd
No known key found for this signature in database
GPG key ID: C839200C384636B0
2 changed files with 51 additions and 0 deletions

View file

@ -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;

View file

@ -41,3 +41,52 @@ QHash<QString, QByteArray> extendedAttributesToHash(NSDictionary<NSString *, NSD
}
}
namespace OCC {
namespace Mac {
FileProviderItemMetadata FileProviderItemMetadata::fromNSFileProviderItem(const void *const nsFileProviderItem)
{
FileProviderItemMetadata metadata;
const id<NSFileProviderItem> bridgedNsFileProviderItem = (__bridge id<NSFileProviderItem>)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;
}
}
}