From 628ff92dec68132646f10d6a5f6b4643589b4ce0 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 7 Mar 2023 20:18:23 +0100 Subject: [PATCH] Add a Progress extension with convenience methods for copying progress data from one progress object to another Signed-off-by: Claudio Cambra --- .../Extensions/Progress+Extensions.swift | 46 +++++++++++++++++++ .../project.pbxproj | 12 +++++ 2 files changed, 58 insertions(+) create mode 100644 shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/Extensions/Progress+Extensions.swift diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/Extensions/Progress+Extensions.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/Extensions/Progress+Extensions.swift new file mode 100644 index 000000000..97123fd90 --- /dev/null +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/Extensions/Progress+Extensions.swift @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2023 by Claudio Cambra + * + * 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 Foundation + +extension Progress { + func copyCurrentStateToProgress(_ otherProgress: Progress) { + otherProgress.cancellationHandler = self.cancellationHandler + otherProgress.pausingHandler = self.pausingHandler + otherProgress.totalUnitCount = self.totalUnitCount + otherProgress.completedUnitCount = self.completedUnitCount + otherProgress.estimatedTimeRemaining = self.estimatedTimeRemaining + otherProgress.localizedDescription = self.localizedAdditionalDescription + otherProgress.localizedAdditionalDescription = self.localizedAdditionalDescription + otherProgress.isCancellable = self.isCancellable + otherProgress.isPausable = self.isPausable + otherProgress.fileCompletedCount = self.fileCompletedCount + otherProgress.fileURL = self.fileURL + otherProgress.fileTotalCount = self.fileTotalCount + otherProgress.fileCompletedCount = self.fileCompletedCount + otherProgress.fileOperationKind = self.fileOperationKind + otherProgress.kind = self.kind + otherProgress.throughput = self.throughput + + for (key, object) in self.userInfo { + otherProgress.setUserInfoObject(object, forKey: key) + } + } + + func copyOfCurrentState() -> Progress { + let newProgress = Progress() + copyCurrentStateToProgress(newProgress) + return newProgress + } +} diff --git a/shell_integration/MacOSX/NextcloudIntegration/NextcloudIntegration.xcodeproj/project.pbxproj b/shell_integration/MacOSX/NextcloudIntegration/NextcloudIntegration.xcodeproj/project.pbxproj index 133cfb4da..8ebaa4924 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/NextcloudIntegration.xcodeproj/project.pbxproj +++ b/shell_integration/MacOSX/NextcloudIntegration/NextcloudIntegration.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 5307A6EB2965DB8D001E0C6A /* RealmSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 5307A6EA2965DB8D001E0C6A /* RealmSwift */; }; 5307A6F029674953001E0C6A /* NextcloudFilesDatabaseTables.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5307A6EF29674953001E0C6A /* NextcloudFilesDatabaseTables.swift */; }; 5307A6F229675346001E0C6A /* NextcloudFilesDatabaseManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5307A6F129675346001E0C6A /* NextcloudFilesDatabaseManager.swift */; }; + 5352E85B29B7BFE6002CE85C /* Progress+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5352E85A29B7BFE6002CE85C /* Progress+Extensions.swift */; }; 536EFBF7295CF58100F4CB13 /* FileProviderSocketLineProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 536EFBF6295CF58100F4CB13 /* FileProviderSocketLineProcessor.swift */; }; 536EFC36295E3C1100F4CB13 /* NextcloudAccount.swift in Sources */ = {isa = PBXBuildFile; fileRef = 536EFC35295E3C1100F4CB13 /* NextcloudAccount.swift */; }; 538E396A27F4765000FA63D5 /* UniformTypeIdentifiers.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 538E396927F4765000FA63D5 /* UniformTypeIdentifiers.framework */; }; @@ -131,6 +132,7 @@ /* Begin PBXFileReference section */ 5307A6EF29674953001E0C6A /* NextcloudFilesDatabaseTables.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NextcloudFilesDatabaseTables.swift; sourceTree = ""; }; 5307A6F129675346001E0C6A /* NextcloudFilesDatabaseManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NextcloudFilesDatabaseManager.swift; sourceTree = ""; }; + 5352E85A29B7BFE6002CE85C /* Progress+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Progress+Extensions.swift"; sourceTree = ""; }; 536EFBF6295CF58100F4CB13 /* FileProviderSocketLineProcessor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileProviderSocketLineProcessor.swift; sourceTree = ""; }; 536EFC35295E3C1100F4CB13 /* NextcloudAccount.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NextcloudAccount.swift; sourceTree = ""; }; 538E396727F4765000FA63D5 /* FileProviderExt.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = FileProviderExt.appex; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -203,6 +205,14 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 5352E85929B7BFB4002CE85C /* Extensions */ = { + isa = PBXGroup; + children = ( + 5352E85A29B7BFE6002CE85C /* Progress+Extensions.swift */, + ); + path = Extensions; + sourceTree = ""; + }; 538E396827F4765000FA63D5 /* Frameworks */ = { isa = PBXGroup; children = ( @@ -214,6 +224,7 @@ 538E396B27F4765000FA63D5 /* FileProviderExt */ = { isa = PBXGroup; children = ( + 5352E85929B7BFB4002CE85C /* Extensions */, 538E397027F4765000FA63D5 /* FileProviderEnumerator.swift */, 538E396C27F4765000FA63D5 /* FileProviderExtension.swift */, 538E396E27F4765000FA63D5 /* FileProviderItem.swift */, @@ -528,6 +539,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 5352E85B29B7BFE6002CE85C /* Progress+Extensions.swift in Sources */, 5307A6F029674953001E0C6A /* NextcloudFilesDatabaseTables.swift in Sources */, 536EFC36295E3C1100F4CB13 /* NextcloudAccount.swift in Sources */, 538E396D27F4765000FA63D5 /* FileProviderExtension.swift in Sources */, -- 2.30.2