+++ /dev/null
-/*
- * Copyright (C) 2022 by Claudio Cambra <claudio.cambra@nextcloud.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- */
-
-import FileProvider
-import NextcloudKit
-import NextcloudFileProviderKit
-import UniformTypeIdentifiers
-
-class FileProviderItem: NSObject, NSFileProviderItem {
- enum FileProviderItemTransferError: Error {
- case downloadError
- case uploadError
- }
-
- let metadata: ItemMetadata
- let parentItemIdentifier: NSFileProviderItemIdentifier
- let ncKit: NextcloudKit
-
- var itemIdentifier: NSFileProviderItemIdentifier {
- NSFileProviderItemIdentifier(metadata.ocId)
- }
-
- var capabilities: NSFileProviderItemCapabilities {
- guard !metadata.directory else {
- if #available(macOS 13.0, *) {
- // .allowsEvicting deprecated on macOS 13.0+, use contentPolicy instead
- return [
- .allowsAddingSubItems,
- .allowsContentEnumerating,
- .allowsReading,
- .allowsDeleting,
- .allowsRenaming
- ]
- } else {
- return [
- .allowsAddingSubItems,
- .allowsContentEnumerating,
- .allowsReading,
- .allowsDeleting,
- .allowsRenaming,
- .allowsEvicting
- ]
- }
- }
- guard !metadata.lock else {
- return [.allowsReading]
- }
- return [
- .allowsWriting,
- .allowsReading,
- .allowsDeleting,
- .allowsRenaming,
- .allowsReparenting,
- .allowsEvicting
- ]
- }
-
- var itemVersion: NSFileProviderItemVersion {
- NSFileProviderItemVersion(
- contentVersion: metadata.etag.data(using: .utf8)!,
- metadataVersion: metadata.etag.data(using: .utf8)!)
- }
-
- var filename: String {
- metadata.fileNameView
- }
-
- var contentType: UTType {
- if itemIdentifier == .rootContainer || metadata.directory {
- return .folder
- }
-
- let internalType = ncKit.nkCommonInstance.getInternalType(
- fileName: metadata.fileNameView,
- mimeType: "",
- directory: metadata.directory)
- return UTType(filenameExtension: internalType.ext) ?? .content
- }
-
- var documentSize: NSNumber? {
- NSNumber(value: metadata.size)
- }
-
- var creationDate: Date? {
- metadata.creationDate as Date
- }
-
- var lastUsedDate: Date? {
- metadata.date as Date
- }
-
- var contentModificationDate: Date? {
- metadata.date as Date
- }
-
- var isDownloaded: Bool {
- metadata.directory
- || FilesDatabaseManager.shared.localFileMetadataFromOcId(metadata.ocId) != nil
- }
-
- var isDownloading: Bool {
- metadata.status == ItemMetadata.Status.downloading.rawValue
- }
-
- var downloadingError: Error? {
- if metadata.status == ItemMetadata.Status.downloadError.rawValue {
- return FileProviderItemTransferError.downloadError
- }
- return nil
- }
-
- var isUploaded: Bool {
- FilesDatabaseManager.shared.localFileMetadataFromOcId(metadata.ocId) != nil
- }
-
- var isUploading: Bool {
- metadata.status == ItemMetadata.Status.uploading.rawValue
- }
-
- var uploadingError: Error? {
- if metadata.status == ItemMetadata.Status.uploadError.rawValue {
- FileProviderItemTransferError.uploadError
- } else {
- nil
- }
- }
-
- var childItemCount: NSNumber? {
- if metadata.directory {
- NSNumber(
- integerLiteral: FilesDatabaseManager.shared.childItemsForDirectory(
- metadata
- ).count)
- } else {
- nil
- }
- }
-
- @available(macOSApplicationExtension 13.0, *)
- var contentPolicy: NSFileProviderContentPolicy {
- .downloadLazily
- }
-
- required init(
- metadata: ItemMetadata,
- parentItemIdentifier: NSFileProviderItemIdentifier,
- ncKit: NextcloudKit
- ) {
- self.metadata = metadata
- self.parentItemIdentifier = parentItemIdentifier
- self.ncKit = ncKit
- super.init()
- }
-}
537630982B8612F00026BFAB /* FPUIExtensionService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 537630962B860D920026BFAB /* FPUIExtensionService.swift */; };
538E396A27F4765000FA63D5 /* UniformTypeIdentifiers.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 538E396927F4765000FA63D5 /* UniformTypeIdentifiers.framework */; };
538E396D27F4765000FA63D5 /* FileProviderExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 538E396C27F4765000FA63D5 /* FileProviderExtension.swift */; };
- 538E396F27F4765000FA63D5 /* FileProviderItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 538E396E27F4765000FA63D5 /* FileProviderItem.swift */; };
538E397627F4765000FA63D5 /* FileProviderExt.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 538E396727F4765000FA63D5 /* FileProviderExt.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
53903D1E2956164F00D0B308 /* NCDesktopClientSocketKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 53903D0E2956164F00D0B308 /* NCDesktopClientSocketKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
53903D212956164F00D0B308 /* NCDesktopClientSocketKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 53903D0C2956164F00D0B308 /* NCDesktopClientSocketKit.framework */; };
538E396727F4765000FA63D5 /* FileProviderExt.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = FileProviderExt.appex; sourceTree = BUILT_PRODUCTS_DIR; };
538E396927F4765000FA63D5 /* UniformTypeIdentifiers.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UniformTypeIdentifiers.framework; path = System/Library/Frameworks/UniformTypeIdentifiers.framework; sourceTree = SDKROOT; };
538E396C27F4765000FA63D5 /* FileProviderExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileProviderExtension.swift; sourceTree = "<group>"; };
- 538E396E27F4765000FA63D5 /* FileProviderItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileProviderItem.swift; sourceTree = "<group>"; };
538E397227F4765000FA63D5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
538E397327F4765000FA63D5 /* FileProviderExt.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = FileProviderExt.entitlements; sourceTree = "<group>"; };
53903D0C2956164F00D0B308 /* NCDesktopClientSocketKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = NCDesktopClientSocketKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
538E396C27F4765000FA63D5 /* FileProviderExtension.swift */,
53ED472F29C9CE0B00795DB1 /* FileProviderExtension+ClientInterface.swift */,
5352B36B29DC44B50011CE03 /* FileProviderExtension+Thumbnailing.swift */,
- 538E396E27F4765000FA63D5 /* FileProviderItem.swift */,
5318AD9629BF493600CBB71C /* FileProviderMaterialisedEnumerationObserver.swift */,
536EFBF6295CF58100F4CB13 /* FileProviderSocketLineProcessor.swift */,
538E397327F4765000FA63D5 /* FileProviderExt.entitlements */,
537630972B860D920026BFAB /* FPUIExtensionService.swift in Sources */,
535AE30E29C0A2CC0042A9BA /* Logger+Extensions.swift in Sources */,
537630952B860D560026BFAB /* FPUIExtensionServiceSource.swift in Sources */,
- 538E396F27F4765000FA63D5 /* FileProviderItem.swift in Sources */,
5350E4E92B0C534A00F276CB /* ClientCommunicationService.swift in Sources */,
5318AD9729BF493600CBB71C /* FileProviderMaterialisedEnumerationObserver.swift in Sources */,
5352B36C29DC44B50011CE03 /* FileProviderExtension+Thumbnailing.swift in Sources */,