Merge lp:~urbanape/ubuntuone-ios-files/auto-upload-pics into lp:ubuntuone-ios-files
- auto-upload-pics
- Merge into trunk
Proposed by
Zachery Bir
Status: | Merged |
---|---|
Merge reported by: | Zachery Bir |
Merged at revision: | not available |
Proposed branch: | lp:~urbanape/ubuntuone-ios-files/auto-upload-pics |
Merge into: | lp:ubuntuone-ios-files |
Diff against target: |
1698 lines (+1018/-63) 26 files modified
Files.xcodeproj/project.pbxproj (+33/-3) Files/Files-Info.plist (+9/-1) Files/FilesAppDelegate.m (+89/-29) Files/Generated/_U1Asset.h (+76/-0) Files/Generated/_U1Asset.m (+64/-0) Files/Generated/_U1Volume.h (+16/-1) Files/Generated/_U1Volume.m (+7/-0) Files/U1Asset.h (+5/-0) Files/U1Asset.m (+7/-0) Files/U1AssetUploadOperation.h (+25/-0) Files/U1AssetUploadOperation.m (+74/-0) Files/U1DataRepository.h (+5/-1) Files/U1DataRepository.m (+53/-0) Files/U1FilePreviewViewController.m (+1/-0) Files/U1Files.xcdatamodeld/.xccurrentversion (+1/-1) Files/U1FilesClient.h (+6/-1) Files/U1FilesClient.m (+124/-8) Files/U1FilesService.h (+5/-3) Files/U1FilesService.m (+77/-1) Files/U1FolderViewController.m (+1/-1) Files/U1LocalAssetsManager.h (+29/-0) Files/U1LocalAssetsManager.m (+209/-0) Files/U1Volume.h (+18/-1) Files/U1Volume.m (+53/-1) Files/U1VolumesViewController.h (+4/-3) Files/U1VolumesViewController.m (+27/-8) |
To merge this branch: | bzr merge lp:~urbanape/ubuntuone-ios-files/auto-upload-pics |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jason Foreman (community) | Approve | ||
Review via email: mp+77757@code.launchpad.net |
Commit message
Description of the change
This branch adds rough auto-upload of the user's photo library (only photos, no video).
It provides no feedback or controls to cancel the operation yet, and is very, very chatty.
To post a comment you must log in.
Revision history for this message
Zachery Bir (urbanape) wrote : | # |
- 36. By Zachery Bir
-
Renamed to match the new bundle version
- 37. By Zachery Bir
-
Renamed data model
- 38. By Zachery Bir
-
Updated bundle version
- 39. By Zachery Bir
-
No longer a private property
- 40. By Zachery Bir
-
Using a FilesClient, rather than the bare FilesService
- 41. By Zachery Bir
-
Move the static variable outside the implementation, and close an errant code block
- 42. By Zachery Bir
-
Uncomment the icon block
- 43. By Zachery Bir
-
Updates to make build more better good.
Revision history for this message
Jason Foreman (threeve) wrote : | # |
I've ended up un-singletonizing (just the bits about overriding retain/release) in a later changeset, but otherwise looks good.
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'Files.xcodeproj/project.pbxproj' | |||
2 | --- Files.xcodeproj/project.pbxproj 2011-09-27 14:36:00 +0000 | |||
3 | +++ Files.xcodeproj/project.pbxproj 2011-10-04 14:38:28 +0000 | |||
4 | @@ -7,6 +7,11 @@ | |||
5 | 7 | objects = { | 7 | objects = { |
6 | 8 | 8 | ||
7 | 9 | /* Begin PBXBuildFile section */ | 9 | /* Begin PBXBuildFile section */ |
8 | 10 | 91A5E2DC142A70DF00EAAC2B /* U1LocalAssetsManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 91A5E2DB142A70DF00EAAC2B /* U1LocalAssetsManager.m */; }; | ||
9 | 11 | 91A5E2DF142B727600EAAC2B /* U1AssetUploadOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 91A5E2DE142B727500EAAC2B /* U1AssetUploadOperation.m */; }; | ||
10 | 12 | 91B3F2D5141E87F900939B3C /* AssetsLibrary.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 91B3F2D4141E87F900939B3C /* AssetsLibrary.framework */; }; | ||
11 | 13 | 91B3F2DC141FDFAB00939B3C /* _U1Asset.m in Sources */ = {isa = PBXBuildFile; fileRef = 91B3F2DB141FDFAB00939B3C /* _U1Asset.m */; }; | ||
12 | 14 | 91B3F2DF141FDFBE00939B3C /* U1Asset.m in Sources */ = {isa = PBXBuildFile; fileRef = 91B3F2DE141FDFBE00939B3C /* U1Asset.m */; }; | ||
13 | 10 | 960D46131409E0E100B73177 /* PullRefreshTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 960D46001409E09F00B73177 /* PullRefreshTableViewController.m */; }; | 15 | 960D46131409E0E100B73177 /* PullRefreshTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 960D46001409E09F00B73177 /* PullRefreshTableViewController.m */; }; |
14 | 11 | 960D46141409E0F000B73177 /* arrow.png in Resources */ = {isa = PBXBuildFile; fileRef = 960D45FB1409E09F00B73177 /* arrow.png */; }; | 16 | 960D46141409E0F000B73177 /* arrow.png in Resources */ = {isa = PBXBuildFile; fileRef = 960D45FB1409E09F00B73177 /* arrow.png */; }; |
15 | 12 | 960D46161409E10200B73177 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 960D46151409E10200B73177 /* QuartzCore.framework */; }; | 17 | 960D46161409E10200B73177 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 960D46151409E10200B73177 /* QuartzCore.framework */; }; |
16 | @@ -116,6 +121,15 @@ | |||
17 | 116 | /* End PBXContainerItemProxy section */ | 121 | /* End PBXContainerItemProxy section */ |
18 | 117 | 122 | ||
19 | 118 | /* Begin PBXFileReference section */ | 123 | /* Begin PBXFileReference section */ |
20 | 124 | 91A5E2DB142A70DF00EAAC2B /* U1LocalAssetsManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = U1LocalAssetsManager.m; sourceTree = "<group>"; }; | ||
21 | 125 | 91A5E2DD142B727500EAAC2B /* U1AssetUploadOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = U1AssetUploadOperation.h; sourceTree = "<group>"; }; | ||
22 | 126 | 91A5E2DE142B727500EAAC2B /* U1AssetUploadOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = U1AssetUploadOperation.m; sourceTree = "<group>"; }; | ||
23 | 127 | 91B3F2D4141E87F900939B3C /* AssetsLibrary.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AssetsLibrary.framework; path = System/Library/Frameworks/AssetsLibrary.framework; sourceTree = SDKROOT; }; | ||
24 | 128 | 91B3F2D7141FC9BE00939B3C /* U1LocalAssetsManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = U1LocalAssetsManager.h; sourceTree = "<group>"; }; | ||
25 | 129 | 91B3F2DA141FDFAB00939B3C /* _U1Asset.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _U1Asset.h; sourceTree = "<group>"; }; | ||
26 | 130 | 91B3F2DB141FDFAB00939B3C /* _U1Asset.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = _U1Asset.m; sourceTree = "<group>"; }; | ||
27 | 131 | 91B3F2DD141FDFBE00939B3C /* U1Asset.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = U1Asset.h; sourceTree = "<group>"; }; | ||
28 | 132 | 91B3F2DE141FDFBE00939B3C /* U1Asset.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = U1Asset.m; sourceTree = "<group>"; }; | ||
29 | 119 | 960D45FA1409E09F00B73177 /* .gitignore */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitignore; sourceTree = "<group>"; }; | 133 | 960D45FA1409E09F00B73177 /* .gitignore */ = {isa = PBXFileReference; lastKnownFileType = text; path = .gitignore; sourceTree = "<group>"; }; |
30 | 120 | 960D45FB1409E09F00B73177 /* arrow.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = arrow.png; sourceTree = "<group>"; }; | 134 | 960D45FB1409E09F00B73177 /* arrow.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = arrow.png; sourceTree = "<group>"; }; |
31 | 121 | 960D45FD1409E09F00B73177 /* DemoTableViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DemoTableViewController.h; sourceTree = "<group>"; }; | 135 | 960D45FD1409E09F00B73177 /* DemoTableViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DemoTableViewController.h; sourceTree = "<group>"; }; |
32 | @@ -194,6 +208,7 @@ | |||
33 | 194 | 96A1699F1430C9C900E4C990 /* 265-download@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "265-download@2x.png"; path = "Assets/265-download@2x.png"; sourceTree = "<group>"; }; | 208 | 96A1699F1430C9C900E4C990 /* 265-download@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "265-download@2x.png"; path = "Assets/265-download@2x.png"; sourceTree = "<group>"; }; |
34 | 195 | 96A169A21430D53600E4C990 /* U1LocalFileInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = U1LocalFileInfo.h; sourceTree = "<group>"; }; | 209 | 96A169A21430D53600E4C990 /* U1LocalFileInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = U1LocalFileInfo.h; sourceTree = "<group>"; }; |
35 | 196 | 96A169A31430D53600E4C990 /* U1LocalFileInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = U1LocalFileInfo.m; sourceTree = "<group>"; }; | 210 | 96A169A31430D53600E4C990 /* U1LocalFileInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = U1LocalFileInfo.m; sourceTree = "<group>"; }; |
36 | 211 | 96A56430143265B4007A1A93 /* U1Files 1.0-3.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "U1Files 1.0-3.xcdatamodel"; sourceTree = "<group>"; }; | ||
37 | 197 | 96CC17C71417E5E400EFC1BA /* U1Files.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = U1Files.xcdatamodel; sourceTree = "<group>"; }; | 212 | 96CC17C71417E5E400EFC1BA /* U1Files.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = U1Files.xcdatamodel; sourceTree = "<group>"; }; |
38 | 198 | 96CC17CB1417EA0700EFC1BA /* _U1FileNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _U1FileNode.h; sourceTree = "<group>"; }; | 213 | 96CC17CB1417EA0700EFC1BA /* _U1FileNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _U1FileNode.h; sourceTree = "<group>"; }; |
39 | 199 | 96CC17CC1417EA0700EFC1BA /* _U1FileNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = _U1FileNode.m; sourceTree = "<group>"; }; | 214 | 96CC17CC1417EA0700EFC1BA /* _U1FileNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = _U1FileNode.m; sourceTree = "<group>"; }; |
40 | @@ -292,6 +307,7 @@ | |||
41 | 292 | isa = PBXFrameworksBuildPhase; | 307 | isa = PBXFrameworksBuildPhase; |
42 | 293 | buildActionMask = 2147483647; | 308 | buildActionMask = 2147483647; |
43 | 294 | files = ( | 309 | files = ( |
44 | 310 | 91B3F2D5141E87F900939B3C /* AssetsLibrary.framework in Frameworks */, | ||
45 | 295 | 96CC17D81417EA2B00EFC1BA /* CoreData.framework in Frameworks */, | 311 | 96CC17D81417EA2B00EFC1BA /* CoreData.framework in Frameworks */, |
46 | 296 | 96733B12140DFD6D0074D545 /* Security.framework in Frameworks */, | 312 | 96733B12140DFD6D0074D545 /* Security.framework in Frameworks */, |
47 | 297 | 960D46161409E10200B73177 /* QuartzCore.framework in Frameworks */, | 313 | 960D46161409E10200B73177 /* QuartzCore.framework in Frameworks */, |
48 | @@ -350,6 +366,8 @@ | |||
49 | 350 | 96CC17CA1417E9E500EFC1BA /* Generated */, | 366 | 96CC17CA1417E9E500EFC1BA /* Generated */, |
50 | 351 | 96CC17DF1418091100EFC1BA /* Parsers */, | 367 | 96CC17DF1418091100EFC1BA /* Parsers */, |
51 | 352 | 96CC17C61417E5E400EFC1BA /* U1Files.xcdatamodeld */, | 368 | 96CC17C61417E5E400EFC1BA /* U1Files.xcdatamodeld */, |
52 | 369 | 91B3F2DD141FDFBE00939B3C /* U1Asset.h */, | ||
53 | 370 | 91B3F2DE141FDFBE00939B3C /* U1Asset.m */, | ||
54 | 353 | 96CC17D91417EBF500EFC1BA /* U1Volume.h */, | 371 | 96CC17D91417EBF500EFC1BA /* U1Volume.h */, |
55 | 354 | 96CC17DA1417EBF500EFC1BA /* U1Volume.m */, | 372 | 96CC17DA1417EBF500EFC1BA /* U1Volume.m */, |
56 | 355 | 960D4629140D99DB00B73177 /* U1Node.h */, | 373 | 960D4629140D99DB00B73177 /* U1Node.h */, |
57 | @@ -407,6 +425,8 @@ | |||
58 | 407 | 96CC17CA1417E9E500EFC1BA /* Generated */ = { | 425 | 96CC17CA1417E9E500EFC1BA /* Generated */ = { |
59 | 408 | isa = PBXGroup; | 426 | isa = PBXGroup; |
60 | 409 | children = ( | 427 | children = ( |
61 | 428 | 91B3F2DA141FDFAB00939B3C /* _U1Asset.h */, | ||
62 | 429 | 91B3F2DB141FDFAB00939B3C /* _U1Asset.m */, | ||
63 | 410 | 96CC17CB1417EA0700EFC1BA /* _U1FileNode.h */, | 430 | 96CC17CB1417EA0700EFC1BA /* _U1FileNode.h */, |
64 | 411 | 96CC17CC1417EA0700EFC1BA /* _U1FileNode.m */, | 431 | 96CC17CC1417EA0700EFC1BA /* _U1FileNode.m */, |
65 | 412 | 96CC17CD1417EA0700EFC1BA /* _U1FolderNode.h */, | 432 | 96CC17CD1417EA0700EFC1BA /* _U1FolderNode.h */, |
66 | @@ -451,6 +471,7 @@ | |||
67 | 451 | 96E860B413F7251D0026783D /* Frameworks */ = { | 471 | 96E860B413F7251D0026783D /* Frameworks */ = { |
68 | 452 | isa = PBXGroup; | 472 | isa = PBXGroup; |
69 | 453 | children = ( | 473 | children = ( |
70 | 474 | 91B3F2D4141E87F900939B3C /* AssetsLibrary.framework */, | ||
71 | 454 | 96CC17D71417EA2B00EFC1BA /* CoreData.framework */, | 475 | 96CC17D71417EA2B00EFC1BA /* CoreData.framework */, |
72 | 455 | 96733B11140DFD6D0074D545 /* Security.framework */, | 476 | 96733B11140DFD6D0074D545 /* Security.framework */, |
73 | 456 | 960D46151409E10200B73177 /* QuartzCore.framework */, | 477 | 960D46151409E10200B73177 /* QuartzCore.framework */, |
74 | @@ -486,6 +507,8 @@ | |||
75 | 486 | 96E8614213F728380026783D /* U1FilesService.m */, | 507 | 96E8614213F728380026783D /* U1FilesService.m */, |
76 | 487 | 96CC17E314180C5F00EFC1BA /* U1FilesClient.h */, | 508 | 96CC17E314180C5F00EFC1BA /* U1FilesClient.h */, |
77 | 488 | 96CC17E414180C5F00EFC1BA /* U1FilesClient.m */, | 509 | 96CC17E414180C5F00EFC1BA /* U1FilesClient.m */, |
78 | 510 | 91B3F2D7141FC9BE00939B3C /* U1LocalAssetsManager.h */, | ||
79 | 511 | 91A5E2DB142A70DF00EAAC2B /* U1LocalAssetsManager.m */, | ||
80 | 489 | 969EF22613F8C10C00CEF6CB /* U1VolumesViewController.h */, | 512 | 969EF22613F8C10C00CEF6CB /* U1VolumesViewController.h */, |
81 | 490 | 969EF22713F8C10C00CEF6CB /* U1VolumesViewController.m */, | 513 | 969EF22713F8C10C00CEF6CB /* U1VolumesViewController.m */, |
82 | 491 | 969EF22813F8C10C00CEF6CB /* U1VolumesViewController.xib */, | 514 | 969EF22813F8C10C00CEF6CB /* U1VolumesViewController.xib */, |
83 | @@ -498,6 +521,8 @@ | |||
84 | 498 | 960D4624140D8AF200B73177 /* U1ByteSizeValueTransformer.m */, | 521 | 960D4624140D8AF200B73177 /* U1ByteSizeValueTransformer.m */, |
85 | 499 | 960D4626140D8B4400B73177 /* U1FriendlyDateValueTransformer.h */, | 522 | 960D4626140D8B4400B73177 /* U1FriendlyDateValueTransformer.h */, |
86 | 500 | 960D4627140D8B4400B73177 /* U1FriendlyDateValueTransformer.m */, | 523 | 960D4627140D8B4400B73177 /* U1FriendlyDateValueTransformer.m */, |
87 | 524 | 91A5E2DD142B727500EAAC2B /* U1AssetUploadOperation.h */, | ||
88 | 525 | 91A5E2DE142B727500EAAC2B /* U1AssetUploadOperation.m */, | ||
89 | 501 | 965D7EB71429690C00E4754F /* U1NavigationBar.h */, | 526 | 965D7EB71429690C00E4754F /* U1NavigationBar.h */, |
90 | 502 | 965D7EB81429690C00E4754F /* U1NavigationBar.m */, | 527 | 965D7EB81429690C00E4754F /* U1NavigationBar.m */, |
91 | 503 | 96A169A21430D53600E4C990 /* U1LocalFileInfo.h */, | 528 | 96A169A21430D53600E4C990 /* U1LocalFileInfo.h */, |
92 | @@ -818,6 +843,10 @@ | |||
93 | 818 | 96CC17DE1417EF7200EFC1BA /* U1DataRepository.m in Sources */, | 843 | 96CC17DE1417EF7200EFC1BA /* U1DataRepository.m in Sources */, |
94 | 819 | 96CC17E21418094800EFC1BA /* U1NodeJSONParser.m in Sources */, | 844 | 96CC17E21418094800EFC1BA /* U1NodeJSONParser.m in Sources */, |
95 | 820 | 96CC17E514180C6000EFC1BA /* U1FilesClient.m in Sources */, | 845 | 96CC17E514180C6000EFC1BA /* U1FilesClient.m in Sources */, |
96 | 846 | 91B3F2DC141FDFAB00939B3C /* _U1Asset.m in Sources */, | ||
97 | 847 | 91B3F2DF141FDFBE00939B3C /* U1Asset.m in Sources */, | ||
98 | 848 | 91A5E2DC142A70DF00EAAC2B /* U1LocalAssetsManager.m in Sources */, | ||
99 | 849 | 91A5E2DF142B727600EAAC2B /* U1AssetUploadOperation.m in Sources */, | ||
100 | 821 | 965D7EB91429690C00E4754F /* U1NavigationBar.m in Sources */, | 850 | 965D7EB91429690C00E4754F /* U1NavigationBar.m in Sources */, |
101 | 822 | 96A169A41430D53700E4C990 /* U1LocalFileInfo.m in Sources */, | 851 | 96A169A41430D53700E4C990 /* U1LocalFileInfo.m in Sources */, |
102 | 823 | ); | 852 | ); |
103 | @@ -939,14 +968,14 @@ | |||
104 | 939 | 96E860F013F7251D0026783D /* Release */ = { | 968 | 96E860F013F7251D0026783D /* Release */ = { |
105 | 940 | isa = XCBuildConfiguration; | 969 | isa = XCBuildConfiguration; |
106 | 941 | buildSettings = { | 970 | buildSettings = { |
108 | 942 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; | 971 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer: Zachery Bir (P7WDPDEFHU)"; |
109 | 943 | GCC_PRECOMPILE_PREFIX_HEADER = YES; | 972 | GCC_PRECOMPILE_PREFIX_HEADER = YES; |
110 | 944 | GCC_PREFIX_HEADER = "Files/Files-Prefix.pch"; | 973 | GCC_PREFIX_HEADER = "Files/Files-Prefix.pch"; |
111 | 945 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0; | 974 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0; |
112 | 946 | INFOPLIST_FILE = "Files/Files-Info.plist"; | 975 | INFOPLIST_FILE = "Files/Files-Info.plist"; |
113 | 947 | IPHONEOS_DEPLOYMENT_TARGET = 4.0; | 976 | IPHONEOS_DEPLOYMENT_TARGET = 4.0; |
114 | 948 | PRODUCT_NAME = "$(TARGET_NAME)"; | 977 | PRODUCT_NAME = "$(TARGET_NAME)"; |
116 | 949 | "PROVISIONING_PROFILE[sdk=iphoneos*]" = ""; | 978 | "PROVISIONING_PROFILE[sdk=iphoneos*]" = "84E0B7E6-02A2-46EF-9C76-AA80C48130A7"; |
117 | 950 | TARGETED_DEVICE_FAMILY = 1; | 979 | TARGETED_DEVICE_FAMILY = 1; |
118 | 951 | WRAPPER_EXTENSION = app; | 980 | WRAPPER_EXTENSION = app; |
119 | 952 | }; | 981 | }; |
120 | @@ -1022,9 +1051,10 @@ | |||
121 | 1022 | 96CC17C61417E5E400EFC1BA /* U1Files.xcdatamodeld */ = { | 1051 | 96CC17C61417E5E400EFC1BA /* U1Files.xcdatamodeld */ = { |
122 | 1023 | isa = XCVersionGroup; | 1052 | isa = XCVersionGroup; |
123 | 1024 | children = ( | 1053 | children = ( |
124 | 1054 | 96A56430143265B4007A1A93 /* U1Files 1.0-3.xcdatamodel */, | ||
125 | 1025 | 96CC17C71417E5E400EFC1BA /* U1Files.xcdatamodel */, | 1055 | 96CC17C71417E5E400EFC1BA /* U1Files.xcdatamodel */, |
126 | 1026 | ); | 1056 | ); |
128 | 1027 | currentVersion = 96CC17C71417E5E400EFC1BA /* U1Files.xcdatamodel */; | 1057 | currentVersion = 96A56430143265B4007A1A93 /* U1Files 1.0-3.xcdatamodel */; |
129 | 1028 | path = U1Files.xcdatamodeld; | 1058 | path = U1Files.xcdatamodeld; |
130 | 1029 | sourceTree = "<group>"; | 1059 | sourceTree = "<group>"; |
131 | 1030 | versionGroupType = wrapper.xcdatamodel; | 1060 | versionGroupType = wrapper.xcdatamodel; |
132 | 1031 | 1061 | ||
133 | === modified file 'Files/Files-Info.plist' | |||
134 | --- Files/Files-Info.plist 2011-09-27 14:42:09 +0000 | |||
135 | +++ Files/Files-Info.plist 2011-10-04 14:38:28 +0000 | |||
136 | @@ -6,6 +6,8 @@ | |||
137 | 6 | <string>en</string> | 6 | <string>en</string> |
138 | 7 | <key>CFBundleDisplayName</key> | 7 | <key>CFBundleDisplayName</key> |
139 | 8 | <string>${PRODUCT_NAME}</string> | 8 | <string>${PRODUCT_NAME}</string> |
140 | 9 | <key>CFBundleDocumentTypes</key> | ||
141 | 10 | <array/> | ||
142 | 9 | <key>CFBundleExecutable</key> | 11 | <key>CFBundleExecutable</key> |
143 | 10 | <string>${EXECUTABLE_NAME}</string> | 12 | <string>${EXECUTABLE_NAME}</string> |
144 | 11 | <key>CFBundleIconFile</key> | 13 | <key>CFBundleIconFile</key> |
145 | @@ -22,8 +24,10 @@ | |||
146 | 22 | <string>1.0</string> | 24 | <string>1.0</string> |
147 | 23 | <key>CFBundleSignature</key> | 25 | <key>CFBundleSignature</key> |
148 | 24 | <string>????</string> | 26 | <string>????</string> |
149 | 27 | <key>CFBundleURLTypes</key> | ||
150 | 28 | <array/> | ||
151 | 25 | <key>CFBundleVersion</key> | 29 | <key>CFBundleVersion</key> |
153 | 26 | <string>2</string> | 30 | <string>3</string> |
154 | 27 | <key>LSRequiresIPhoneOS</key> | 31 | <key>LSRequiresIPhoneOS</key> |
155 | 28 | <true/> | 32 | <true/> |
156 | 29 | <key>NSMainNibFile</key> | 33 | <key>NSMainNibFile</key> |
157 | @@ -43,5 +47,9 @@ | |||
158 | 43 | <string>UIInterfaceOrientationLandscapeLeft</string> | 47 | <string>UIInterfaceOrientationLandscapeLeft</string> |
159 | 44 | <string>UIInterfaceOrientationLandscapeRight</string> | 48 | <string>UIInterfaceOrientationLandscapeRight</string> |
160 | 45 | </array> | 49 | </array> |
161 | 50 | <key>UTExportedTypeDeclarations</key> | ||
162 | 51 | <array/> | ||
163 | 52 | <key>UTImportedTypeDeclarations</key> | ||
164 | 53 | <array/> | ||
165 | 46 | </dict> | 54 | </dict> |
166 | 47 | </plist> | 55 | </plist> |
167 | 48 | 56 | ||
168 | === modified file 'Files/FilesAppDelegate.m' | |||
169 | --- Files/FilesAppDelegate.m 2011-09-27 14:36:00 +0000 | |||
170 | +++ Files/FilesAppDelegate.m 2011-10-04 14:38:28 +0000 | |||
171 | @@ -13,6 +13,10 @@ | |||
172 | 13 | // You should have received a copy of the GNU Affero General Public License | 13 | // You should have received a copy of the GNU Affero General Public License |
173 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
174 | 15 | 15 | ||
175 | 16 | #import <AssetsLibrary/ALAssetsLibrary.h> | ||
176 | 17 | #import <AssetsLibrary/ALAssetsGroup.h> | ||
177 | 18 | #import <AssetsLibrary/ALAsset.h> | ||
178 | 19 | |||
179 | 16 | #import "FilesAppDelegate.h" | 20 | #import "FilesAppDelegate.h" |
180 | 17 | 21 | ||
181 | 18 | #import "U1AccountManager.h" | 22 | #import "U1AccountManager.h" |
182 | @@ -20,35 +24,41 @@ | |||
183 | 20 | #import "U1FileNode.h" | 24 | #import "U1FileNode.h" |
184 | 21 | #import "U1FilePreviewViewController.h" | 25 | #import "U1FilePreviewViewController.h" |
185 | 22 | #import "U1FilesClient.h" | 26 | #import "U1FilesClient.h" |
186 | 27 | #import "U1LocalAssetsManager.h" | ||
187 | 23 | #import "U1FilesService.h" | 28 | #import "U1FilesService.h" |
188 | 24 | #import "U1FolderNode.h" | 29 | #import "U1FolderNode.h" |
189 | 25 | #import "U1FolderViewController.h" | 30 | #import "U1FolderViewController.h" |
190 | 26 | #import "U1LoginController.h" | 31 | #import "U1LoginController.h" |
191 | 27 | #import "U1Node.h" | 32 | #import "U1Node.h" |
192 | 28 | #import "U1VolumesViewController.h" | 33 | #import "U1VolumesViewController.h" |
193 | 34 | #import "U1Volume.h" | ||
194 | 29 | 35 | ||
195 | 30 | 36 | ||
196 | 31 | @interface FilesAppDelegate () <U1FolderViewControllerDelegate, U1VolumesViewControllerDelegate, U1LoginControllerDelegate> | 37 | @interface FilesAppDelegate () <U1FolderViewControllerDelegate, U1VolumesViewControllerDelegate, U1LoginControllerDelegate> |
197 | 32 | @property (retain) U1FilesService *filesService; | 38 | @property (retain) U1FilesService *filesService; |
198 | 33 | @property (retain) U1FilesClient *filesClient; | 39 | @property (retain) U1FilesClient *filesClient; |
199 | 40 | @property (retain) U1LocalAssetsManager *localAssetsManager; | ||
200 | 34 | @property (retain) U1LoginController *loginController; | 41 | @property (retain) U1LoginController *loginController; |
201 | 35 | @property (retain) U1DataRepository *dataRepository; | 42 | @property (retain) U1DataRepository *dataRepository; |
202 | 36 | - (NSURL*)dataStoreURL; | ||
203 | 37 | - (void)showVolumes; | 43 | - (void)showVolumes; |
204 | 38 | - (void)showLoginController; | 44 | - (void)showLoginController; |
205 | 45 | - (void)ensureUploadFolder; | ||
206 | 46 | - (NSString*)remoteUploadFolderPath; | ||
207 | 47 | - (NSString*)localUploadQueuePath; | ||
208 | 39 | @end | 48 | @end |
209 | 40 | 49 | ||
210 | 41 | 50 | ||
211 | 42 | @implementation FilesAppDelegate | 51 | @implementation FilesAppDelegate |
212 | 43 | 52 | ||
213 | 44 | @synthesize window; | 53 | @synthesize window; |
215 | 45 | @synthesize filesService, filesClient, navController, loginController, dataRepository; | 54 | @synthesize filesService, filesClient, localAssetsManager, navController, loginController, dataRepository; |
216 | 46 | 55 | ||
217 | 47 | - (void)dealloc | 56 | - (void)dealloc |
218 | 48 | { | 57 | { |
219 | 49 | [window release]; | 58 | [window release]; |
220 | 50 | [filesService release]; | 59 | [filesService release]; |
221 | 51 | [filesClient release]; | 60 | [filesClient release]; |
222 | 61 | [localAssetsManager release]; | ||
223 | 52 | [navController release]; | 62 | [navController release]; |
224 | 53 | [loginController release]; | 63 | [loginController release]; |
225 | 54 | [dataRepository release]; | 64 | [dataRepository release]; |
226 | @@ -59,51 +69,104 @@ | |||
227 | 59 | { | 69 | { |
228 | 60 | [self.window makeKeyAndVisible]; | 70 | [self.window makeKeyAndVisible]; |
229 | 61 | 71 | ||
230 | 72 | return YES; | ||
231 | 73 | } | ||
232 | 74 | |||
233 | 75 | - (void)applicationDidBecomeActive:(UIApplication *)application; | ||
234 | 76 | { | ||
235 | 62 | if (![[U1AccountManager sharedAccountManager] hasCredentials]) | 77 | if (![[U1AccountManager sharedAccountManager] hasCredentials]) |
236 | 63 | { | 78 | { |
237 | 64 | [self showLoginController]; | 79 | [self showLoginController]; |
238 | 65 | } | 80 | } |
239 | 66 | else | 81 | else |
240 | 67 | { | 82 | { |
242 | 68 | [self showVolumes]; | 83 | self.filesService = [U1FilesService sharedFilesService]; |
243 | 84 | self.filesClient = [U1FilesClient sharedFilesClient]; | ||
244 | 85 | |||
245 | 86 | self.localAssetsManager = [U1LocalAssetsManager sharedFilesManager]; | ||
246 | 87 | NSLog(@"Showing Volumes: Reading localAssetsToUpload from filesystem."); | ||
247 | 88 | NSMutableArray *uploadQueue = [NSMutableArray arrayWithContentsOfFile:[self localUploadQueuePath]]; | ||
248 | 89 | if (uploadQueue != nil) { | ||
249 | 90 | NSLog(@"Retrieved the upload queue from the filesystem."); | ||
250 | 91 | NSLog(@"Length of the array on filesystem: %d", [uploadQueue count]); | ||
251 | 92 | self.localAssetsManager.localAssetsToUpload = uploadQueue; | ||
252 | 93 | NSLog(@"Read in the file, now we delete it."); | ||
253 | 94 | NSError *error = nil; | ||
254 | 95 | [[NSFileManager defaultManager] removeItemAtPath:[self localUploadQueuePath] error:&error]; | ||
255 | 96 | } | ||
256 | 97 | |||
257 | 98 | [self ensureUploadFolder]; | ||
258 | 69 | } | 99 | } |
261 | 70 | 100 | } | |
262 | 71 | return YES; | 101 | |
263 | 102 | - (void)ensureUploadFolder; | ||
264 | 103 | { | ||
265 | 104 | [self.filesClient volumesWithCompletionBlock:^(NSArray *volumeInfos, NSError *error) { | ||
266 | 105 | dispatch_async(dispatch_get_main_queue(), ^(void) { | ||
267 | 106 | // iterate over volumeInfos. If there isn't one there called "Pictures - <device name>", create it. | ||
268 | 107 | BOOL found = NO; | ||
269 | 108 | NSLog(@"Walking the volumes, to see if it has been created already."); | ||
270 | 109 | for (U1Volume *volume in volumeInfos) { | ||
271 | 110 | if ([volume.path isEqualToString:[self remoteUploadFolderPath]]) | ||
272 | 111 | { | ||
273 | 112 | NSLog(@"Found the volume. No need to try to create it."); | ||
274 | 113 | found = YES; | ||
275 | 114 | self.localAssetsManager.remoteUploadVolume = volume; | ||
276 | 115 | break; | ||
277 | 116 | } | ||
278 | 117 | } | ||
279 | 118 | if (!found) | ||
280 | 119 | { | ||
281 | 120 | NSLog(@"Didn't find the volume. Creating it."); | ||
282 | 121 | [self.filesClient createVolumeAtPath:[self remoteUploadFolderPath] | ||
283 | 122 | completionBlock:^(U1Volume *volume, NSError *error) { | ||
284 | 123 | self.localAssetsManager.remoteUploadVolume = volume; | ||
285 | 124 | [self.localAssetsManager uploadPendingAssets]; | ||
286 | 125 | [self.localAssetsManager checkForNewAssets]; | ||
287 | 126 | NSLog(@"Error: %@", error); | ||
288 | 127 | }]; | ||
289 | 128 | } else | ||
290 | 129 | { | ||
291 | 130 | [self.localAssetsManager uploadPendingAssets]; | ||
292 | 131 | [self.localAssetsManager checkForNewAssets]; | ||
293 | 132 | } | ||
294 | 133 | [self showVolumes]; | ||
295 | 134 | }); | ||
296 | 135 | }]; | ||
297 | 136 | } | ||
298 | 137 | |||
299 | 138 | - (NSString *)remoteUploadFolderPath; | ||
300 | 139 | { | ||
301 | 140 | return [NSString stringWithFormat:@"/~/Pictures - %@", [[UIDevice currentDevice] name]]; | ||
302 | 141 | } | ||
303 | 142 | |||
304 | 143 | - (NSString*)localUploadQueuePath; | ||
305 | 144 | { | ||
306 | 145 | NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | ||
307 | 146 | return [[paths objectAtIndex:0] stringByAppendingPathComponent:@"localAssetsToUpload.array"]; | ||
308 | 72 | } | 147 | } |
309 | 73 | 148 | ||
310 | 74 | - (void)applicationWillResignActive:(UIApplication *)application; | 149 | - (void)applicationWillResignActive:(UIApplication *)application; |
311 | 75 | { | 150 | { |
312 | 76 | [self.dataRepository save:NULL]; | 151 | [self.dataRepository save:NULL]; |
313 | 152 | NSLog(@"Application Resigning: Writing localAssetsToUpload (%d items) to the filesystem.", [self.localAssetsManager.localAssetsToUpload count]); | ||
314 | 153 | [self.localAssetsManager.localAssetsToUpload writeToFile:[self localUploadQueuePath] atomically:YES]; | ||
315 | 154 | // serialize self.filesManager's localAssetsToUpload to the filesystem | ||
316 | 77 | } | 155 | } |
317 | 78 | 156 | ||
318 | 79 | - (void)applicationWillTerminate:(UIApplication *)application; | 157 | - (void)applicationWillTerminate:(UIApplication *)application; |
319 | 80 | { | 158 | { |
320 | 81 | // TODO: check error | 159 | // TODO: check error |
321 | 82 | [self.dataRepository save:NULL]; | 160 | [self.dataRepository save:NULL]; |
329 | 83 | } | 161 | NSLog(@"Application Terminating: Writing localAssetsToUpload (%d items) to the filesystem.", [self.localAssetsManager.localAssetsToUpload count]); |
330 | 84 | 162 | [self.localAssetsManager.localAssetsToUpload writeToFile:[self localUploadQueuePath] atomically:YES]; | |
331 | 85 | - (NSURL*)dataStoreURL; | 163 | // serialize self.filesManager's localAssetsToUpload to the filesystem |
325 | 86 | { | ||
326 | 87 | NSURL *cachesDirectory = [[[NSFileManager defaultManager] URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask] lastObject]; | ||
327 | 88 | NSURL *storeURL = [NSURL URLWithString:@"U1Files.sqlite" relativeToURL:cachesDirectory]; | ||
328 | 89 | return storeURL; | ||
332 | 90 | } | 164 | } |
333 | 91 | 165 | ||
334 | 92 | - (void)showVolumes; | 166 | - (void)showVolumes; |
335 | 93 | { | 167 | { |
336 | 94 | filesService = [U1FilesService new]; | ||
337 | 95 | |||
338 | 96 | NSURL *storeURL = [self dataStoreURL]; | ||
339 | 97 | self.dataRepository = [[U1DataRepository alloc] initWithStoreURL:storeURL]; | ||
340 | 98 | [dataRepository release]; | ||
341 | 99 | |||
342 | 100 | filesClient = [[U1FilesClient alloc] init]; | ||
343 | 101 | [self.filesClient setFilesService:filesService]; | ||
344 | 102 | [self.filesClient setDataRepository:self.dataRepository]; | ||
345 | 103 | |||
346 | 104 | U1VolumesViewController *rootController = [U1VolumesViewController new]; | 168 | U1VolumesViewController *rootController = [U1VolumesViewController new]; |
347 | 105 | rootController.delegate = self; | 169 | rootController.delegate = self; |
348 | 106 | rootController.filesService = self.filesService; | ||
349 | 107 | 170 | ||
350 | 108 | [self.navController setViewControllers:[NSArray arrayWithObject:rootController] animated:NO]; | 171 | [self.navController setViewControllers:[NSArray arrayWithObject:rootController] animated:NO]; |
351 | 109 | } | 172 | } |
352 | @@ -119,7 +182,7 @@ | |||
353 | 119 | { | 182 | { |
354 | 120 | [self.navController dismissModalViewControllerAnimated:YES]; | 183 | [self.navController dismissModalViewControllerAnimated:YES]; |
355 | 121 | self.loginController = nil; | 184 | self.loginController = nil; |
357 | 122 | [self showVolumes]; | 185 | [self applicationDidBecomeActive:nil]; |
358 | 123 | } | 186 | } |
359 | 124 | 187 | ||
360 | 125 | 188 | ||
361 | @@ -130,14 +193,12 @@ | |||
362 | 130 | if ([node isFolder]) | 193 | if ([node isFolder]) |
363 | 131 | { | 194 | { |
364 | 132 | U1FolderViewController *nextFolderController = [[U1FolderViewController alloc] initWithNodeResourcePath:node.resourcePath]; | 195 | U1FolderViewController *nextFolderController = [[U1FolderViewController alloc] initWithNodeResourcePath:node.resourcePath]; |
365 | 133 | nextFolderController.filesClient = self.filesClient; | ||
366 | 134 | nextFolderController.delegate = self; | 196 | nextFolderController.delegate = self; |
367 | 135 | [self.navController pushViewController:nextFolderController animated:YES]; | 197 | [self.navController pushViewController:nextFolderController animated:YES]; |
368 | 136 | } | 198 | } |
369 | 137 | else if ([node isFile]) | 199 | else if ([node isFile]) |
370 | 138 | { | 200 | { |
371 | 139 | U1FilePreviewViewController *fileController = [[U1FilePreviewViewController alloc] initWithNode:(id)node]; | 201 | U1FilePreviewViewController *fileController = [[U1FilePreviewViewController alloc] initWithNode:(id)node]; |
372 | 140 | fileController.filesClient = self.filesClient; | ||
373 | 141 | [self.navController pushViewController:fileController animated:YES]; | 202 | [self.navController pushViewController:fileController animated:YES]; |
374 | 142 | } | 203 | } |
375 | 143 | } | 204 | } |
376 | @@ -145,11 +206,10 @@ | |||
377 | 145 | 206 | ||
378 | 146 | #pragma mark U1VolumesControllerDelegate Methods | 207 | #pragma mark U1VolumesControllerDelegate Methods |
379 | 147 | 208 | ||
381 | 148 | - (void)volumesController:(U1VolumesViewController *)volumesController didSelectVolume:(NSDictionary *)volume; | 209 | - (void)volumesController:(U1VolumesViewController *)volumesController didSelectVolume:(U1Volume *)volume; |
382 | 149 | { | 210 | { |
384 | 150 | NSString *nodePath = [volume objectForKey:@"node_path"]; | 211 | NSString *nodePath = volume.nodePath; |
385 | 151 | U1FolderViewController *folderController = [[U1FolderViewController alloc] initWithNodeResourcePath:nodePath]; | 212 | U1FolderViewController *folderController = [[U1FolderViewController alloc] initWithNodeResourcePath:nodePath]; |
386 | 152 | folderController.filesClient = self.filesClient; | ||
387 | 153 | folderController.delegate = self; | 213 | folderController.delegate = self; |
388 | 154 | [self.navController pushViewController:folderController animated:YES]; | 214 | [self.navController pushViewController:folderController animated:YES]; |
389 | 155 | } | 215 | } |
390 | 156 | 216 | ||
391 | === added file 'Files/Generated/_U1Asset.h' | |||
392 | --- Files/Generated/_U1Asset.h 1970-01-01 00:00:00 +0000 | |||
393 | +++ Files/Generated/_U1Asset.h 2011-10-04 14:38:28 +0000 | |||
394 | @@ -0,0 +1,76 @@ | |||
395 | 1 | // DO NOT EDIT. This file is machine-generated and constantly overwritten. | ||
396 | 2 | // Make changes to U1Asset.h instead. | ||
397 | 3 | |||
398 | 4 | #import <CoreData/CoreData.h> | ||
399 | 5 | |||
400 | 6 | |||
401 | 7 | |||
402 | 8 | |||
403 | 9 | |||
404 | 10 | |||
405 | 11 | |||
406 | 12 | @interface U1AssetID : NSManagedObjectID {} | ||
407 | 13 | @end | ||
408 | 14 | |||
409 | 15 | @interface _U1Asset : NSManagedObject {} | ||
410 | 16 | + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_; | ||
411 | 17 | + (NSString*)entityName; | ||
412 | 18 | + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_; | ||
413 | 19 | - (U1AssetID*)objectID; | ||
414 | 20 | |||
415 | 21 | |||
416 | 22 | |||
417 | 23 | |||
418 | 24 | @property (nonatomic, retain) NSString *filename; | ||
419 | 25 | |||
420 | 26 | |||
421 | 27 | //- (BOOL)validateFilename:(id*)value_ error:(NSError**)error_; | ||
422 | 28 | |||
423 | 29 | |||
424 | 30 | |||
425 | 31 | |||
426 | 32 | @property (nonatomic, retain) NSString *groupId; | ||
427 | 33 | |||
428 | 34 | |||
429 | 35 | //- (BOOL)validateGroupId:(id*)value_ error:(NSError**)error_; | ||
430 | 36 | |||
431 | 37 | |||
432 | 38 | |||
433 | 39 | |||
434 | 40 | @property (nonatomic, retain) NSString *url; | ||
435 | 41 | |||
436 | 42 | |||
437 | 43 | //- (BOOL)validateUrl:(id*)value_ error:(NSError**)error_; | ||
438 | 44 | |||
439 | 45 | |||
440 | 46 | |||
441 | 47 | |||
442 | 48 | |||
443 | 49 | @end | ||
444 | 50 | |||
445 | 51 | @interface _U1Asset (CoreDataGeneratedAccessors) | ||
446 | 52 | |||
447 | 53 | @end | ||
448 | 54 | |||
449 | 55 | @interface _U1Asset (CoreDataGeneratedPrimitiveAccessors) | ||
450 | 56 | |||
451 | 57 | |||
452 | 58 | - (NSString*)primitiveFilename; | ||
453 | 59 | - (void)setPrimitiveFilename:(NSString*)value; | ||
454 | 60 | |||
455 | 61 | |||
456 | 62 | |||
457 | 63 | |||
458 | 64 | - (NSString*)primitiveGroupId; | ||
459 | 65 | - (void)setPrimitiveGroupId:(NSString*)value; | ||
460 | 66 | |||
461 | 67 | |||
462 | 68 | |||
463 | 69 | |||
464 | 70 | - (NSString*)primitiveUrl; | ||
465 | 71 | - (void)setPrimitiveUrl:(NSString*)value; | ||
466 | 72 | |||
467 | 73 | |||
468 | 74 | |||
469 | 75 | |||
470 | 76 | @end | ||
471 | 0 | 77 | ||
472 | === added file 'Files/Generated/_U1Asset.m' | |||
473 | --- Files/Generated/_U1Asset.m 1970-01-01 00:00:00 +0000 | |||
474 | +++ Files/Generated/_U1Asset.m 2011-10-04 14:38:28 +0000 | |||
475 | @@ -0,0 +1,64 @@ | |||
476 | 1 | // DO NOT EDIT. This file is machine-generated and constantly overwritten. | ||
477 | 2 | // Make changes to U1Asset.m instead. | ||
478 | 3 | |||
479 | 4 | #import "_U1Asset.h" | ||
480 | 5 | |||
481 | 6 | @implementation U1AssetID | ||
482 | 7 | @end | ||
483 | 8 | |||
484 | 9 | @implementation _U1Asset | ||
485 | 10 | |||
486 | 11 | + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_ { | ||
487 | 12 | NSParameterAssert(moc_); | ||
488 | 13 | return [NSEntityDescription insertNewObjectForEntityForName:@"Asset" inManagedObjectContext:moc_]; | ||
489 | 14 | } | ||
490 | 15 | |||
491 | 16 | + (NSString*)entityName { | ||
492 | 17 | return @"Asset"; | ||
493 | 18 | } | ||
494 | 19 | |||
495 | 20 | + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_ { | ||
496 | 21 | NSParameterAssert(moc_); | ||
497 | 22 | return [NSEntityDescription entityForName:@"Asset" inManagedObjectContext:moc_]; | ||
498 | 23 | } | ||
499 | 24 | |||
500 | 25 | - (U1AssetID*)objectID { | ||
501 | 26 | return (U1AssetID*)[super objectID]; | ||
502 | 27 | } | ||
503 | 28 | |||
504 | 29 | + (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key { | ||
505 | 30 | NSSet *keyPaths = [super keyPathsForValuesAffectingValueForKey:key]; | ||
506 | 31 | |||
507 | 32 | |||
508 | 33 | return keyPaths; | ||
509 | 34 | } | ||
510 | 35 | |||
511 | 36 | |||
512 | 37 | |||
513 | 38 | |||
514 | 39 | @dynamic filename; | ||
515 | 40 | |||
516 | 41 | |||
517 | 42 | |||
518 | 43 | |||
519 | 44 | |||
520 | 45 | |||
521 | 46 | @dynamic groupId; | ||
522 | 47 | |||
523 | 48 | |||
524 | 49 | |||
525 | 50 | |||
526 | 51 | |||
527 | 52 | |||
528 | 53 | @dynamic url; | ||
529 | 54 | |||
530 | 55 | |||
531 | 56 | |||
532 | 57 | |||
533 | 58 | |||
534 | 59 | |||
535 | 60 | |||
536 | 61 | |||
537 | 62 | |||
538 | 63 | |||
539 | 64 | @end | ||
540 | 0 | 65 | ||
541 | === modified file 'Files/Generated/_U1Volume.h' | |||
542 | --- Files/Generated/_U1Volume.h 2011-09-08 16:59:34 +0000 | |||
543 | +++ Files/Generated/_U1Volume.h 2011-10-04 14:38:28 +0000 | |||
544 | @@ -2,6 +2,7 @@ | |||
545 | 2 | // Make changes to U1Volume.h instead. | 2 | // Make changes to U1Volume.h instead. |
546 | 3 | 3 | ||
547 | 4 | #import <CoreData/CoreData.h> | 4 | #import <CoreData/CoreData.h> |
548 | 5 | #import "U1Node.h" | ||
549 | 5 | 6 | ||
550 | 6 | 7 | ||
551 | 7 | 8 | ||
552 | @@ -9,7 +10,7 @@ | |||
553 | 9 | @interface U1VolumeID : NSManagedObjectID {} | 10 | @interface U1VolumeID : NSManagedObjectID {} |
554 | 10 | @end | 11 | @end |
555 | 11 | 12 | ||
557 | 12 | @interface _U1Volume : NSManagedObject {} | 13 | @interface _U1Volume : U1Node {} |
558 | 13 | + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_; | 14 | + (id)insertInManagedObjectContext:(NSManagedObjectContext*)moc_; |
559 | 14 | + (NSString*)entityName; | 15 | + (NSString*)entityName; |
560 | 15 | + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_; | 16 | + (NSEntityDescription*)entityInManagedObjectContext:(NSManagedObjectContext*)moc_; |
561 | @@ -18,6 +19,14 @@ | |||
562 | 18 | 19 | ||
563 | 19 | 20 | ||
564 | 20 | 21 | ||
565 | 22 | @property (nonatomic, retain) NSString *nodePath; | ||
566 | 23 | |||
567 | 24 | |||
568 | 25 | //- (BOOL)validateNodePath:(id*)value_ error:(NSError**)error_; | ||
569 | 26 | |||
570 | 27 | |||
571 | 28 | |||
572 | 29 | |||
573 | 21 | 30 | ||
574 | 22 | @end | 31 | @end |
575 | 23 | 32 | ||
576 | @@ -28,4 +37,10 @@ | |||
577 | 28 | @interface _U1Volume (CoreDataGeneratedPrimitiveAccessors) | 37 | @interface _U1Volume (CoreDataGeneratedPrimitiveAccessors) |
578 | 29 | 38 | ||
579 | 30 | 39 | ||
580 | 40 | - (NSString*)primitiveNodePath; | ||
581 | 41 | - (void)setPrimitiveNodePath:(NSString*)value; | ||
582 | 42 | |||
583 | 43 | |||
584 | 44 | |||
585 | 45 | |||
586 | 31 | @end | 46 | @end |
587 | 32 | 47 | ||
588 | === modified file 'Files/Generated/_U1Volume.m' | |||
589 | --- Files/Generated/_U1Volume.m 2011-09-08 16:59:34 +0000 | |||
590 | +++ Files/Generated/_U1Volume.m 2011-10-04 14:38:28 +0000 | |||
591 | @@ -36,6 +36,13 @@ | |||
592 | 36 | 36 | ||
593 | 37 | 37 | ||
594 | 38 | 38 | ||
595 | 39 | @dynamic nodePath; | ||
596 | 40 | |||
597 | 41 | |||
598 | 42 | |||
599 | 43 | |||
600 | 44 | |||
601 | 45 | |||
602 | 39 | 46 | ||
603 | 40 | 47 | ||
604 | 41 | 48 | ||
605 | 42 | 49 | ||
606 | === added file 'Files/U1Asset.h' | |||
607 | --- Files/U1Asset.h 1970-01-01 00:00:00 +0000 | |||
608 | +++ Files/U1Asset.h 2011-10-04 14:38:28 +0000 | |||
609 | @@ -0,0 +1,5 @@ | |||
610 | 1 | #import "_U1Asset.h" | ||
611 | 2 | |||
612 | 3 | @interface U1Asset : _U1Asset {} | ||
613 | 4 | // Custom logic goes here. | ||
614 | 5 | @end | ||
615 | 0 | 6 | ||
616 | === added file 'Files/U1Asset.m' | |||
617 | --- Files/U1Asset.m 1970-01-01 00:00:00 +0000 | |||
618 | +++ Files/U1Asset.m 2011-10-04 14:38:28 +0000 | |||
619 | @@ -0,0 +1,7 @@ | |||
620 | 1 | #import "U1Asset.h" | ||
621 | 2 | |||
622 | 3 | @implementation U1Asset | ||
623 | 4 | |||
624 | 5 | // Custom logic goes here. | ||
625 | 6 | |||
626 | 7 | @end | ||
627 | 0 | 8 | ||
628 | === added file 'Files/U1AssetUploadOperation.h' | |||
629 | --- Files/U1AssetUploadOperation.h 1970-01-01 00:00:00 +0000 | |||
630 | +++ Files/U1AssetUploadOperation.h 2011-10-04 14:38:28 +0000 | |||
631 | @@ -0,0 +1,25 @@ | |||
632 | 1 | // | ||
633 | 2 | // U1AssetUploadOperation.h | ||
634 | 3 | // Files | ||
635 | 4 | // | ||
636 | 5 | // Created by Zachery Bir on 9/22/11. | ||
637 | 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. | ||
638 | 7 | // | ||
639 | 8 | |||
640 | 9 | #import <Foundation/Foundation.h> | ||
641 | 10 | #import <AssetsLibrary/AssetsLibrary.h> | ||
642 | 11 | |||
643 | 12 | @class U1Asset; | ||
644 | 13 | @class U1FolderNode; | ||
645 | 14 | |||
646 | 15 | @interface U1AssetUploadOperation : NSOperation { | ||
647 | 16 | @private | ||
648 | 17 | |||
649 | 18 | } | ||
650 | 19 | @property (retain) ALAssetRepresentation *representation; | ||
651 | 20 | @property (retain) NSData *assetData; | ||
652 | 21 | @property (retain) U1Asset *asset; | ||
653 | 22 | @property (retain) U1FolderNode *folder; | ||
654 | 23 | @property (retain) NSString *filename; | ||
655 | 24 | @property (retain) NSError *error; | ||
656 | 25 | @end | ||
657 | 0 | 26 | ||
658 | === added file 'Files/U1AssetUploadOperation.m' | |||
659 | --- Files/U1AssetUploadOperation.m 1970-01-01 00:00:00 +0000 | |||
660 | +++ Files/U1AssetUploadOperation.m 2011-10-04 14:38:28 +0000 | |||
661 | @@ -0,0 +1,74 @@ | |||
662 | 1 | // | ||
663 | 2 | // U1AssetUploadOperation.m | ||
664 | 3 | // Files | ||
665 | 4 | // | ||
666 | 5 | // Created by Zachery Bir on 9/22/11. | ||
667 | 6 | // Copyright 2011 __MyCompanyName__. All rights reserved. | ||
668 | 7 | // | ||
669 | 8 | |||
670 | 9 | #import "U1AssetUploadOperation.h" | ||
671 | 10 | #import "U1Asset.h" | ||
672 | 11 | #import "U1FilesClient.h" | ||
673 | 12 | |||
674 | 13 | @interface U1AssetUploadOperation () | ||
675 | 14 | @property (getter=isExecuting) BOOL executing; | ||
676 | 15 | @property (getter=isFinished) BOOL finished; | ||
677 | 16 | - (void)finishExecuting; | ||
678 | 17 | @end | ||
679 | 18 | |||
680 | 19 | @implementation U1AssetUploadOperation | ||
681 | 20 | |||
682 | 21 | @synthesize executing, finished, asset, assetData, representation, folder, filename, error; | ||
683 | 22 | |||
684 | 23 | - (id)init | ||
685 | 24 | { | ||
686 | 25 | self = [super init]; | ||
687 | 26 | if (self) { | ||
688 | 27 | // Initialization code here. | ||
689 | 28 | } | ||
690 | 29 | |||
691 | 30 | return self; | ||
692 | 31 | } | ||
693 | 32 | |||
694 | 33 | - (BOOL)isConcurrent; | ||
695 | 34 | { | ||
696 | 35 | return YES; | ||
697 | 36 | } | ||
698 | 37 | |||
699 | 38 | - (void)finishExecuting; | ||
700 | 39 | { | ||
701 | 40 | [self willChangeValueForKey:@"isExecuting"]; | ||
702 | 41 | [self willChangeValueForKey:@"isFinished"]; | ||
703 | 42 | self.finished = YES; | ||
704 | 43 | self.executing = NO; | ||
705 | 44 | [self didChangeValueForKey:@"isFinished"]; | ||
706 | 45 | [self didChangeValueForKey:@"isExecuting"]; | ||
707 | 46 | // [UONetworkStatusCoordinator removeNetworkActivity]; | ||
708 | 47 | } | ||
709 | 48 | |||
710 | 49 | - (void)start; | ||
711 | 50 | { | ||
712 | 51 | // Trigger the filesClient to upload our asset, setting the completion block to marking ourself completed. | ||
713 | 52 | [self willChangeValueForKey:@"isExecuting"]; | ||
714 | 53 | self.executing = YES; | ||
715 | 54 | [self didChangeValueForKey:@"isExecuting"]; | ||
716 | 55 | dispatch_async(dispatch_get_main_queue(), ^(void) { | ||
717 | 56 | U1FilesClient *filesClient = [U1FilesClient sharedFilesClient]; | ||
718 | 57 | [filesClient uploadContentData:self.assetData | ||
719 | 58 | toFolder:self.folder withResourceName:self.filename progressBlock:^(long long bytesUploaded, long long totalBytes) { | ||
720 | 59 | dispatch_async(dispatch_get_main_queue(), ^(void){ | ||
721 | 60 | NSLog(@"Uploaded %lld of %lld for %@", bytesUploaded, totalBytes, self.filename); | ||
722 | 61 | }); | ||
723 | 62 | } completionBlock:^(U1FileNode *updatedNode, NSError *uploadError) { | ||
724 | 63 | self.error = uploadError; | ||
725 | 64 | [self finishExecuting]; | ||
726 | 65 | }]; | ||
727 | 66 | }); | ||
728 | 67 | } | ||
729 | 68 | |||
730 | 69 | - (void)dealloc | ||
731 | 70 | { | ||
732 | 71 | [super dealloc]; | ||
733 | 72 | } | ||
734 | 73 | |||
735 | 74 | @end | ||
736 | 0 | 75 | ||
737 | === modified file 'Files/U1DataRepository.h' | |||
738 | --- Files/U1DataRepository.h 2011-09-08 16:59:34 +0000 | |||
739 | +++ Files/U1DataRepository.h 2011-10-04 14:38:28 +0000 | |||
740 | @@ -20,12 +20,16 @@ | |||
741 | 20 | 20 | ||
742 | 21 | 21 | ||
743 | 22 | @interface U1DataRepository : NSObject | 22 | @interface U1DataRepository : NSObject |
745 | 23 | 23 | + (U1DataRepository*)sharedDataRepository; | |
746 | 24 | - (id)initWithStoreURL:(NSURL*)storeURL; | 24 | - (id)initWithStoreURL:(NSURL*)storeURL; |
747 | 25 | - (BOOL)save:(NSError**)error; | 25 | - (BOOL)save:(NSError**)error; |
748 | 26 | 26 | ||
749 | 27 | - (U1Node*)nodeWithResourcePath:(NSString*)resourcePath; | 27 | - (U1Node*)nodeWithResourcePath:(NSString*)resourcePath; |
750 | 28 | 28 | ||
751 | 29 | //- (void)fetchResultsForEntityClass:(Class)entityClass matchingPredicate:(NSPredicate*)predicate withSortDescriptors:(NSArray*)sortDescriptors completionBlock:(void(^)(NSArray *results, NSError *error))completionBlock; | ||
752 | 30 | |||
753 | 31 | - (NSArray*)resultsForEntityClass:(Class)entityClass matchingPredicate:(NSPredicate*)predicate withSortDescriptors:(NSArray*)sortDescriptors error:(NSError**)error; | ||
754 | 32 | |||
755 | 29 | - (void)dispatchBlockWithManagedObjectContext:(void(^)(NSManagedObjectContext *context))block; | 33 | - (void)dispatchBlockWithManagedObjectContext:(void(^)(NSManagedObjectContext *context))block; |
756 | 30 | 34 | ||
757 | 31 | - (void)dispatchAsyncBlockWithManagedObjectContext:(void(^)(NSManagedObjectContext *context))block; | 35 | - (void)dispatchAsyncBlockWithManagedObjectContext:(void(^)(NSManagedObjectContext *context))block; |
758 | 32 | 36 | ||
759 | === modified file 'Files/U1DataRepository.m' | |||
760 | --- Files/U1DataRepository.m 2011-09-08 16:59:34 +0000 | |||
761 | +++ Files/U1DataRepository.m 2011-10-04 14:38:28 +0000 | |||
762 | @@ -19,6 +19,7 @@ | |||
763 | 19 | 19 | ||
764 | 20 | #import "U1Node.h" | 20 | #import "U1Node.h" |
765 | 21 | 21 | ||
766 | 22 | static U1DataRepository *sharedDataRepository = nil; | ||
767 | 22 | 23 | ||
768 | 23 | @interface U1DataRepository () | 24 | @interface U1DataRepository () |
769 | 24 | 25 | ||
770 | @@ -35,6 +36,48 @@ | |||
771 | 35 | 36 | ||
772 | 36 | @synthesize model, mainContext, storeCoordinator; | 37 | @synthesize model, mainContext, storeCoordinator; |
773 | 37 | 38 | ||
774 | 39 | + (U1DataRepository*)sharedDataRepository; | ||
775 | 40 | { | ||
776 | 41 | if (sharedDataRepository == nil) | ||
777 | 42 | { | ||
778 | 43 | NSURL *cachesDirectory = [[[NSFileManager defaultManager] URLsForDirectory:NSCachesDirectory | ||
779 | 44 | inDomains:NSUserDomainMask] lastObject]; | ||
780 | 45 | NSURL *storeURL = [NSURL URLWithString:@"U1Files.sqlite" relativeToURL:cachesDirectory]; | ||
781 | 46 | sharedDataRepository = [[super allocWithZone:NULL] initWithStoreURL:storeURL]; | ||
782 | 47 | } | ||
783 | 48 | return sharedDataRepository; | ||
784 | 49 | } | ||
785 | 50 | |||
786 | 51 | + (id)allocWithZone:(NSZone *)zone; | ||
787 | 52 | { | ||
788 | 53 | return [[self sharedDataRepository] retain]; | ||
789 | 54 | } | ||
790 | 55 | |||
791 | 56 | - (id)copyWithZone:(NSZone *)zone; | ||
792 | 57 | { | ||
793 | 58 | return self; | ||
794 | 59 | } | ||
795 | 60 | |||
796 | 61 | - (id)retain; | ||
797 | 62 | { | ||
798 | 63 | return self; | ||
799 | 64 | } | ||
800 | 65 | |||
801 | 66 | - (NSUInteger)retainCount; | ||
802 | 67 | { | ||
803 | 68 | return NSUIntegerMax; | ||
804 | 69 | } | ||
805 | 70 | |||
806 | 71 | - (void)release; | ||
807 | 72 | { | ||
808 | 73 | |||
809 | 74 | } | ||
810 | 75 | |||
811 | 76 | - (id)autorelease; | ||
812 | 77 | { | ||
813 | 78 | return self; | ||
814 | 79 | } | ||
815 | 80 | |||
816 | 38 | - (id)initWithStoreURL:(NSURL*)storeURL; | 81 | - (id)initWithStoreURL:(NSURL*)storeURL; |
817 | 39 | { | 82 | { |
818 | 40 | if (!(self = [super init])) | 83 | if (!(self = [super init])) |
819 | @@ -93,6 +136,16 @@ | |||
820 | 93 | return node; | 136 | return node; |
821 | 94 | } | 137 | } |
822 | 95 | 138 | ||
823 | 139 | //- (void)fetchResultsForEntityClass:(Class)entityClass matchingPredicate:(NSPredicate*)predicate withSortDescriptors:(NSArray*)sortDescriptors completionBlock:(void(^)(NSArray *results, NSError *error))completionBlock; | ||
824 | 140 | //{ | ||
825 | 141 | // | ||
826 | 142 | //} | ||
827 | 143 | |||
828 | 144 | - (NSArray*)resultsForEntityClass:(Class)entityClass matchingPredicate:(NSPredicate*)predicate withSortDescriptors:(NSArray*)sortDescriptors error:(NSError**)error; | ||
829 | 145 | { | ||
830 | 146 | return [self fetchEntitiesForClass:entityClass inContext:self.mainContext withPredicate:predicate sortDescriptors:sortDescriptors error:error]; | ||
831 | 147 | } | ||
832 | 148 | |||
833 | 96 | - (NSArray*)fetchEntitiesForClass:(Class)class inContext:(NSManagedObjectContext*)context withPredicate:(NSPredicate*)predicate sortDescriptors:(NSArray*)sortDescriptors error:(NSError**)error; | 149 | - (NSArray*)fetchEntitiesForClass:(Class)class inContext:(NSManagedObjectContext*)context withPredicate:(NSPredicate*)predicate sortDescriptors:(NSArray*)sortDescriptors error:(NSError**)error; |
834 | 97 | { | 150 | { |
835 | 98 | NSParameterAssert(class != nil); | 151 | NSParameterAssert(class != nil); |
836 | 99 | 152 | ||
837 | === modified file 'Files/U1FilePreviewViewController.m' | |||
838 | --- Files/U1FilePreviewViewController.m 2011-09-27 14:36:00 +0000 | |||
839 | +++ Files/U1FilePreviewViewController.m 2011-10-04 14:38:28 +0000 | |||
840 | @@ -78,6 +78,7 @@ | |||
841 | 78 | self = [super initWithNibName:@"U1FilePreviewViewController" bundle:nil]; | 78 | self = [super initWithNibName:@"U1FilePreviewViewController" bundle:nil]; |
842 | 79 | if (self == nil) | 79 | if (self == nil) |
843 | 80 | return nil; | 80 | return nil; |
844 | 81 | filesClient = [U1FilesClient sharedFilesClient]; | ||
845 | 81 | self.node = theNode; | 82 | self.node = theNode; |
846 | 82 | self.title = [node.path lastPathComponent]; | 83 | self.title = [node.path lastPathComponent]; |
847 | 83 | 84 | ||
848 | 84 | 85 | ||
849 | === modified file 'Files/U1Files.xcdatamodeld/.xccurrentversion' | |||
850 | --- Files/U1Files.xcdatamodeld/.xccurrentversion 2011-09-08 16:59:34 +0000 | |||
851 | +++ Files/U1Files.xcdatamodeld/.xccurrentversion 2011-10-04 14:38:28 +0000 | |||
852 | @@ -3,6 +3,6 @@ | |||
853 | 3 | <plist version="1.0"> | 3 | <plist version="1.0"> |
854 | 4 | <dict> | 4 | <dict> |
855 | 5 | <key>_XCCurrentVersionName</key> | 5 | <key>_XCCurrentVersionName</key> |
857 | 6 | <string>U1Files.xcdatamodel</string> | 6 | <string>U1Files 1.0-3.xcdatamodel</string> |
858 | 7 | </dict> | 7 | </dict> |
859 | 8 | </plist> | 8 | </plist> |
860 | 9 | 9 | ||
861 | === added directory 'Files/U1Files.xcdatamodeld/U1Files 1.0-3.xcdatamodel' | |||
862 | === added file 'Files/U1Files.xcdatamodeld/U1Files 1.0-3.xcdatamodel/elements' | |||
863 | 10 | Binary files Files/U1Files.xcdatamodeld/U1Files 1.0-3.xcdatamodel/elements 1970-01-01 00:00:00 +0000 and Files/U1Files.xcdatamodeld/U1Files 1.0-3.xcdatamodel/elements 2011-10-04 14:38:28 +0000 differ | 10 | Binary files Files/U1Files.xcdatamodeld/U1Files 1.0-3.xcdatamodel/elements 1970-01-01 00:00:00 +0000 and Files/U1Files.xcdatamodeld/U1Files 1.0-3.xcdatamodel/elements 2011-10-04 14:38:28 +0000 differ |
864 | === added file 'Files/U1Files.xcdatamodeld/U1Files 1.0-3.xcdatamodel/layout' | |||
865 | 11 | Binary files Files/U1Files.xcdatamodeld/U1Files 1.0-3.xcdatamodel/layout 1970-01-01 00:00:00 +0000 and Files/U1Files.xcdatamodeld/U1Files 1.0-3.xcdatamodel/layout 2011-10-04 14:38:28 +0000 differ | 11 | Binary files Files/U1Files.xcdatamodeld/U1Files 1.0-3.xcdatamodel/layout 1970-01-01 00:00:00 +0000 and Files/U1Files.xcdatamodeld/U1Files 1.0-3.xcdatamodel/layout 2011-10-04 14:38:28 +0000 differ |
866 | === modified file 'Files/U1Files.xcdatamodeld/U1Files.xcdatamodel/elements' | |||
867 | 12 | Binary files Files/U1Files.xcdatamodeld/U1Files.xcdatamodel/elements 2011-09-08 16:59:34 +0000 and Files/U1Files.xcdatamodeld/U1Files.xcdatamodel/elements 2011-10-04 14:38:28 +0000 differ | 12 | Binary files Files/U1Files.xcdatamodeld/U1Files.xcdatamodel/elements 2011-09-08 16:59:34 +0000 and Files/U1Files.xcdatamodeld/U1Files.xcdatamodel/elements 2011-10-04 14:38:28 +0000 differ |
868 | === modified file 'Files/U1Files.xcdatamodeld/U1Files.xcdatamodel/layout' | |||
869 | 13 | Binary files Files/U1Files.xcdatamodeld/U1Files.xcdatamodel/layout 2011-09-08 16:59:34 +0000 and Files/U1Files.xcdatamodeld/U1Files.xcdatamodel/layout 2011-10-04 14:38:28 +0000 differ | 13 | Binary files Files/U1Files.xcdatamodeld/U1Files.xcdatamodel/layout 2011-09-08 16:59:34 +0000 and Files/U1Files.xcdatamodeld/U1Files.xcdatamodel/layout 2011-10-04 14:38:28 +0000 differ |
870 | === modified file 'Files/U1FilesClient.h' | |||
871 | --- Files/U1FilesClient.h 2011-09-27 14:36:00 +0000 | |||
872 | +++ Files/U1FilesClient.h 2011-10-04 14:38:28 +0000 | |||
873 | @@ -16,7 +16,7 @@ | |||
874 | 16 | #import <Foundation/Foundation.h> | 16 | #import <Foundation/Foundation.h> |
875 | 17 | 17 | ||
876 | 18 | @class NSFetchedResultsController; | 18 | @class NSFetchedResultsController; |
878 | 19 | @class U1Node, U1FileNode, U1FolderNode, U1NodeChildrenResultSet, U1LocalFileInfo; | 19 | @class U1Node, U1FileNode, U1FolderNode, U1NodeChildrenResultSet, U1Volume, U1LocalFileInfo; |
879 | 20 | @class U1DataRepository, U1FilesService; | 20 | @class U1DataRepository, U1FilesService; |
880 | 21 | 21 | ||
881 | 22 | 22 | ||
882 | @@ -25,11 +25,16 @@ | |||
883 | 25 | @property (retain) U1DataRepository *dataRepository; | 25 | @property (retain) U1DataRepository *dataRepository; |
884 | 26 | @property (retain) U1FilesService *filesService; | 26 | @property (retain) U1FilesService *filesService; |
885 | 27 | 27 | ||
886 | 28 | + (U1FilesClient *)sharedFilesClient; | ||
887 | 29 | |||
888 | 30 | - (id)volumesWithCompletionBlock:(void(^)(NSArray *volumes, NSError *error))completionBlock; | ||
889 | 28 | - (id)fetchNodeWithResourcePath:(NSString*)nodePath completionBlock:(void(^)(U1Node *node, NSFetchedResultsController *childrenResultsController, NSError *error))completionBlock; | 31 | - (id)fetchNodeWithResourcePath:(NSString*)nodePath completionBlock:(void(^)(U1Node *node, NSFetchedResultsController *childrenResultsController, NSError *error))completionBlock; |
890 | 29 | - (id)deleteNode:(U1Node*)node completionBlock:(void(^)(NSError *error))completionBlock; | 32 | - (id)deleteNode:(U1Node*)node completionBlock:(void(^)(NSError *error))completionBlock; |
891 | 30 | - (id)uploadContentData:(NSData*)contentData toFolder:(U1FolderNode*)folderNode withResourceName:(NSString*)resourceName progressBlock:(void(^)(long long bytesUploaded, long long totalBytes))progressBlock completionBlock:(void(^)(U1FileNode *updatedNode, NSError *error))completionBlock; | 33 | - (id)uploadContentData:(NSData*)contentData toFolder:(U1FolderNode*)folderNode withResourceName:(NSString*)resourceName progressBlock:(void(^)(long long bytesUploaded, long long totalBytes))progressBlock completionBlock:(void(^)(U1FileNode *updatedNode, NSError *error))completionBlock; |
892 | 31 | - (id)publishNode:(U1FileNode*)node completionBlock:(void(^)(U1FileNode *node, NSError *error))completionBlock; | 34 | - (id)publishNode:(U1FileNode*)node completionBlock:(void(^)(U1FileNode *node, NSError *error))completionBlock; |
893 | 32 | - (id)unpublishNode:(U1FileNode*)node completionBlock:(void(^)(U1FileNode *node, NSError *error))completionBlock; | 35 | - (id)unpublishNode:(U1FileNode*)node completionBlock:(void(^)(U1FileNode *node, NSError *error))completionBlock; |
894 | 36 | - (id)createFolderNamed:(NSString*)name inFolder:(U1FolderNode*)folderNode completionBlock:(void(^)(U1FolderNode *newFolderNode, NSError *error))completionBlock; | ||
895 | 37 | - (id)createVolumeAtPath:(NSString*)folderPath completionBlock:(void(^)(U1Volume *volume, NSError *error))completionBlock; | ||
896 | 33 | - (BOOL)isNodeSavedLocally:(U1FileNode*)node; | 38 | - (BOOL)isNodeSavedLocally:(U1FileNode*)node; |
897 | 34 | - (U1LocalFileInfo*)localInfoForNode:(U1FileNode*)node; | 39 | - (U1LocalFileInfo*)localInfoForNode:(U1FileNode*)node; |
898 | 35 | 40 | ||
899 | 36 | 41 | ||
900 | === modified file 'Files/U1FilesClient.m' | |||
901 | --- Files/U1FilesClient.m 2011-09-27 14:36:00 +0000 | |||
902 | +++ Files/U1FilesClient.m 2011-10-04 14:38:28 +0000 | |||
903 | @@ -23,22 +23,93 @@ | |||
904 | 23 | #import "U1FolderNode.h" | 23 | #import "U1FolderNode.h" |
905 | 24 | #import "U1LocalFileInfo.h" | 24 | #import "U1LocalFileInfo.h" |
906 | 25 | #import "U1Node.h" | 25 | #import "U1Node.h" |
907 | 26 | #import "U1Volume.h" | ||
908 | 26 | 27 | ||
909 | 27 | 28 | ||
910 | 28 | @interface U1FilesClient () | 29 | @interface U1FilesClient () |
911 | 29 | - (NSURL*)fileURLForNode:(U1FileNode*)node; | 30 | - (NSURL*)fileURLForNode:(U1FileNode*)node; |
912 | 30 | @end | 31 | @end |
913 | 31 | 32 | ||
914 | 33 | static U1FilesClient *sharedFilesClient = nil; | ||
915 | 32 | 34 | ||
916 | 33 | @implementation U1FilesClient | 35 | @implementation U1FilesClient |
917 | 34 | 36 | ||
918 | 35 | @synthesize dataRepository, filesService; | 37 | @synthesize dataRepository, filesService; |
919 | 36 | 38 | ||
925 | 37 | - (void)dealloc; | 39 | + (U1FilesClient*)sharedFilesClient; |
926 | 38 | { | 40 | { |
927 | 39 | [dataRepository release]; | 41 | if (sharedFilesClient == nil) |
928 | 40 | [filesService release]; | 42 | { |
929 | 41 | [super dealloc]; | 43 | sharedFilesClient = [[super allocWithZone:NULL] init]; |
930 | 44 | } | ||
931 | 45 | return sharedFilesClient; | ||
932 | 46 | } | ||
933 | 47 | |||
934 | 48 | + (id)allocWithZone:(NSZone *)zone; | ||
935 | 49 | { | ||
936 | 50 | return [[self sharedFilesClient] retain]; | ||
937 | 51 | } | ||
938 | 52 | |||
939 | 53 | - (id)copyWithZone:(NSZone *)zone; | ||
940 | 54 | { | ||
941 | 55 | return self; | ||
942 | 56 | } | ||
943 | 57 | |||
944 | 58 | - (id)retain; | ||
945 | 59 | { | ||
946 | 60 | return self; | ||
947 | 61 | } | ||
948 | 62 | |||
949 | 63 | - (NSUInteger)retainCount; | ||
950 | 64 | { | ||
951 | 65 | return NSUIntegerMax; | ||
952 | 66 | } | ||
953 | 67 | |||
954 | 68 | - (void)release; | ||
955 | 69 | { | ||
956 | 70 | |||
957 | 71 | } | ||
958 | 72 | |||
959 | 73 | - (id)autorelease; | ||
960 | 74 | { | ||
961 | 75 | return self; | ||
962 | 76 | } | ||
963 | 77 | |||
964 | 78 | - (id)init; | ||
965 | 79 | { | ||
966 | 80 | self = [super init]; | ||
967 | 81 | if (self == nil) | ||
968 | 82 | return nil; | ||
969 | 83 | dataRepository = [U1DataRepository sharedDataRepository]; | ||
970 | 84 | filesService = [U1FilesService sharedFilesService]; | ||
971 | 85 | return self; | ||
972 | 86 | } | ||
973 | 87 | |||
974 | 88 | - (id)volumesWithCompletionBlock:(void(^)(NSArray *volumes, NSError *error))completionBlock; | ||
975 | 89 | { | ||
976 | 90 | NSParameterAssert(completionBlock != NULL); | ||
977 | 91 | |||
978 | 92 | [self.filesService volumeInfoWithCompletionBlock:^(NSArray *volumeInfos, NSError *error) { | ||
979 | 93 | |||
980 | 94 | NSMutableArray *volumes = [NSMutableArray array]; | ||
981 | 95 | [self.dataRepository dispatchBlockWithManagedObjectContext:^(NSManagedObjectContext *context) { | ||
982 | 96 | for (NSDictionary *volumeInfo in volumeInfos) | ||
983 | 97 | { | ||
984 | 98 | NSString *path = [volumeInfo objectForKey:@"path"]; | ||
985 | 99 | NSPredicate *p = [NSPredicate predicateWithFormat:@"path = %@", path]; | ||
986 | 100 | U1Volume *volume = [[self.dataRepository resultsForEntityClass:[U1Volume class] matchingPredicate:p withSortDescriptors:nil error:NULL] lastObject]; | ||
987 | 101 | if (!volume) | ||
988 | 102 | { | ||
989 | 103 | volume = [U1Volume insertInManagedObjectContext:context]; | ||
990 | 104 | } | ||
991 | 105 | [volume updatePropertiesFromJSONDictionary:volumeInfo]; | ||
992 | 106 | [volumes addObject:volume]; | ||
993 | 107 | } | ||
994 | 108 | [context save:NULL]; | ||
995 | 109 | }]; | ||
996 | 110 | completionBlock(volumes, error); | ||
997 | 111 | }]; | ||
998 | 112 | return nil; | ||
999 | 42 | } | 113 | } |
1000 | 43 | 114 | ||
1001 | 44 | - (id)fetchNodeWithResourcePath:(NSString*)nodePath completionBlock:(void(^)(U1Node *node, NSFetchedResultsController *childrenResultsController, NSError *error))completionBlock; | 115 | - (id)fetchNodeWithResourcePath:(NSString*)nodePath completionBlock:(void(^)(U1Node *node, NSFetchedResultsController *childrenResultsController, NSError *error))completionBlock; |
1002 | @@ -144,9 +215,18 @@ | |||
1003 | 144 | } | 215 | } |
1004 | 145 | 216 | ||
1005 | 146 | return [self.filesService uploadContentData:contentData forNode:node progressBlock:progressBlock completionBlock:^(NSDictionary *updatedNodeInfo, NSError *error) { | 217 | return [self.filesService uploadContentData:contentData forNode:node progressBlock:progressBlock completionBlock:^(NSDictionary *updatedNodeInfo, NSError *error) { |
1009 | 147 | 218 | if (error != nil) | |
1010 | 148 | [node updatePropertiesFromJSONDictionary:updatedNodeInfo]; | 219 | { |
1011 | 149 | completionBlock(node, error); | 220 | [self.dataRepository dispatchBlockWithManagedObjectContext:^(NSManagedObjectContext *context) { |
1012 | 221 | [context deleteObject:node]; | ||
1013 | 222 | }]; | ||
1014 | 223 | completionBlock(nil, error); | ||
1015 | 224 | } | ||
1016 | 225 | else | ||
1017 | 226 | { | ||
1018 | 227 | [node updatePropertiesFromJSONDictionary:updatedNodeInfo]; | ||
1019 | 228 | completionBlock(node, error); | ||
1020 | 229 | } | ||
1021 | 150 | }]; | 230 | }]; |
1022 | 151 | } | 231 | } |
1023 | 152 | 232 | ||
1024 | @@ -160,6 +240,42 @@ | |||
1025 | 160 | return [self.filesService unpublishNode:node completionBlock:completionBlock]; | 240 | return [self.filesService unpublishNode:node completionBlock:completionBlock]; |
1026 | 161 | } | 241 | } |
1027 | 162 | 242 | ||
1028 | 243 | - (id)createFolderNamed:(NSString*)name inFolder:(U1FolderNode*)folderNode completionBlock:(void(^)(U1FolderNode *newFolderNode, NSError *error))completionBlock; | ||
1029 | 244 | { | ||
1030 | 245 | NSString *resourcePath = folderNode.resourcePath; | ||
1031 | 246 | resourcePath = [resourcePath stringByAppendingPathComponent:name]; | ||
1032 | 247 | |||
1033 | 248 | U1FolderNode *node = (id)[self.dataRepository nodeWithResourcePath:resourcePath]; | ||
1034 | 249 | if (!node) | ||
1035 | 250 | { | ||
1036 | 251 | [self.dataRepository dispatchBlockWithManagedObjectContext:^(NSManagedObjectContext *context) { | ||
1037 | 252 | U1FolderNode *newNode = [U1FolderNode insertInManagedObjectContext:context]; | ||
1038 | 253 | newNode.resourcePath = resourcePath; | ||
1039 | 254 | newNode.kind = @"directory"; | ||
1040 | 255 | newNode.contentPath = [folderNode.contentPath stringByAppendingPathComponent:name]; | ||
1041 | 256 | newNode.parent = folderNode; | ||
1042 | 257 | [context save:NULL]; | ||
1043 | 258 | }]; | ||
1044 | 259 | node = (id)[self.dataRepository nodeWithResourcePath:resourcePath]; | ||
1045 | 260 | } | ||
1046 | 261 | |||
1047 | 262 | return [self.filesService createFolderAtPath:resourcePath completionBlock:^(NSDictionary *nodeInfo, NSError *error) { | ||
1048 | 263 | [node updatePropertiesFromJSONDictionary:nodeInfo]; | ||
1049 | 264 | completionBlock(node, error); | ||
1050 | 265 | }]; | ||
1051 | 266 | } | ||
1052 | 267 | |||
1053 | 268 | - (id)createVolumeAtPath:(NSString*)folderPath completionBlock:(void(^)(U1Volume *volume, NSError *error))completionBlock; | ||
1054 | 269 | { | ||
1055 | 270 | return [self.filesService createVolumeAtPath:folderPath completionBlock:^(NSDictionary *volumeInfo, NSError *error) { | ||
1056 | 271 | [self.dataRepository dispatchBlockWithManagedObjectContext:^(NSManagedObjectContext *context) { | ||
1057 | 272 | U1Volume *volume = [U1Volume insertInManagedObjectContext:context]; | ||
1058 | 273 | [volume updatePropertiesFromJSONDictionary:volumeInfo]; | ||
1059 | 274 | completionBlock(volume, error); | ||
1060 | 275 | }]; | ||
1061 | 276 | }]; | ||
1062 | 277 | } | ||
1063 | 278 | |||
1064 | 163 | - (BOOL)isNodeSavedLocally:(U1FileNode*)node; | 279 | - (BOOL)isNodeSavedLocally:(U1FileNode*)node; |
1065 | 164 | { | 280 | { |
1066 | 165 | NSString *contentPath = node.contentPath; | 281 | NSString *contentPath = node.contentPath; |
1067 | 166 | 282 | ||
1068 | === modified file 'Files/U1FilesService.h' | |||
1069 | --- Files/U1FilesService.h 2011-09-08 16:59:34 +0000 | |||
1070 | +++ Files/U1FilesService.h 2011-10-04 14:38:28 +0000 | |||
1071 | @@ -15,12 +15,12 @@ | |||
1072 | 15 | 15 | ||
1073 | 16 | #import <Foundation/Foundation.h> | 16 | #import <Foundation/Foundation.h> |
1074 | 17 | 17 | ||
1076 | 18 | @class U1Node, U1FileNode; | 18 | @class U1Node, U1FileNode, U1FolderNode; |
1077 | 19 | 19 | ||
1078 | 20 | 20 | ||
1079 | 21 | @interface U1FilesService : NSObject | 21 | @interface U1FilesService : NSObject |
1082 | 22 | 22 | + (U1FilesService *)sharedFilesService; | |
1083 | 23 | - (id)volumeInfoWithCompletionBlock:(void(^)(NSArray *volumeInfo, NSError *error))completionBlock; | 23 | - (id)volumeInfoWithCompletionBlock:(void(^)(NSArray *volumeInfos, NSError *error))completionBlock; |
1084 | 24 | 24 | ||
1085 | 25 | - (id)infoForNodeAtResourcePath:(NSString*)resourcePath includeChildren:(BOOL)includeChildren completionBlock:(void(^)(NSDictionary *node, NSError *error))completionBlock; | 25 | - (id)infoForNodeAtResourcePath:(NSString*)resourcePath includeChildren:(BOOL)includeChildren completionBlock:(void(^)(NSDictionary *node, NSError *error))completionBlock; |
1086 | 26 | - (id)infoForNode:(U1Node*)node includeChildren:(BOOL)includeChildren completionBlock:(void(^)(NSDictionary *node, NSError *error))completionBlock; | 26 | - (id)infoForNode:(U1Node*)node includeChildren:(BOOL)includeChildren completionBlock:(void(^)(NSDictionary *node, NSError *error))completionBlock; |
1087 | @@ -30,5 +30,7 @@ | |||
1088 | 30 | - (id)deleteNodeAtResourcePath:(NSString*)resourcePath completionBlock:(void(^)(NSError *error))completionBlock; | 30 | - (id)deleteNodeAtResourcePath:(NSString*)resourcePath completionBlock:(void(^)(NSError *error))completionBlock; |
1089 | 31 | - (id)publishNode:(U1FileNode*)node completionBlock:(void(^)(U1FileNode *node, NSError *error))completionBlock; | 31 | - (id)publishNode:(U1FileNode*)node completionBlock:(void(^)(U1FileNode *node, NSError *error))completionBlock; |
1090 | 32 | - (id)unpublishNode:(U1FileNode*)node completionBlock:(void(^)(U1FileNode *node, NSError *error))completionBlock; | 32 | - (id)unpublishNode:(U1FileNode*)node completionBlock:(void(^)(U1FileNode *node, NSError *error))completionBlock; |
1091 | 33 | - (id)createFolderAtPath:(NSString*)folderPath completionBlock:(void(^)(NSDictionary *nodeInfo, NSError *error))completionBlock; | ||
1092 | 34 | - (id)createVolumeAtPath:(NSString*)folderPath completionBlock:(void(^)(NSDictionary *volumeInfo, NSError *error))completionBlock; | ||
1093 | 33 | 35 | ||
1094 | 34 | @end | 36 | @end |
1095 | 35 | 37 | ||
1096 | === modified file 'Files/U1FilesService.m' | |||
1097 | --- Files/U1FilesService.m 2011-09-27 14:36:00 +0000 | |||
1098 | +++ Files/U1FilesService.m 2011-10-04 14:38:28 +0000 | |||
1099 | @@ -23,11 +23,13 @@ | |||
1100 | 23 | #import "U1Node.h" | 23 | #import "U1Node.h" |
1101 | 24 | #import "U1FileNode.h" | 24 | #import "U1FileNode.h" |
1102 | 25 | 25 | ||
1103 | 26 | static U1FilesService *sharedFilesService = nil; | ||
1104 | 26 | 27 | ||
1105 | 27 | @interface U1FilesService () | 28 | @interface U1FilesService () |
1106 | 28 | 29 | ||
1107 | 29 | @property (retain) NSOperationQueue *networkQueue; | 30 | @property (retain) NSOperationQueue *networkQueue; |
1108 | 30 | 31 | ||
1109 | 32 | - (NSURL*)URLForVolumeWithPath:(NSString*)volumePath; | ||
1110 | 31 | - (NSURL*)URLForNode:(NSString*)nodePath includeChildren:(BOOL)includeChildren; | 33 | - (NSURL*)URLForNode:(NSString*)nodePath includeChildren:(BOOL)includeChildren; |
1111 | 32 | - (id)execute:(NSString*)method toURL:(NSURL*)url withParameters:(NSDictionary*)parameters requestBody:(NSString*)body parseResponseBody:(BOOL)parseResponseBody completionBlock:(void(^)(id results, NSError *error))completionBlock; | 34 | - (id)execute:(NSString*)method toURL:(NSURL*)url withParameters:(NSDictionary*)parameters requestBody:(NSString*)body parseResponseBody:(BOOL)parseResponseBody completionBlock:(void(^)(id results, NSError *error))completionBlock; |
1112 | 33 | - (id)execute:(NSString*)method toURL:(NSURL*)url withParameters:(NSDictionary*)parameters requestData:(NSData*)bodyData contentType:(NSString*)contentType parseResponseBody:(BOOL)parseResponseBody completionBlock:(void(^)(id results, NSError *error))completionBlock; | 35 | - (id)execute:(NSString*)method toURL:(NSURL*)url withParameters:(NSDictionary*)parameters requestData:(NSData*)bodyData contentType:(NSString*)contentType parseResponseBody:(BOOL)parseResponseBody completionBlock:(void(^)(id results, NSError *error))completionBlock; |
1113 | @@ -44,6 +46,45 @@ | |||
1114 | 44 | 46 | ||
1115 | 45 | @synthesize networkQueue; | 47 | @synthesize networkQueue; |
1116 | 46 | 48 | ||
1117 | 49 | + (U1FilesService*)sharedFilesService; | ||
1118 | 50 | { | ||
1119 | 51 | if (sharedFilesService == nil) | ||
1120 | 52 | { | ||
1121 | 53 | sharedFilesService = [[super allocWithZone:NULL] init]; | ||
1122 | 54 | } | ||
1123 | 55 | return sharedFilesService; | ||
1124 | 56 | } | ||
1125 | 57 | |||
1126 | 58 | + (id)allocWithZone:(NSZone *)zone; | ||
1127 | 59 | { | ||
1128 | 60 | return [[self sharedFilesService] retain]; | ||
1129 | 61 | } | ||
1130 | 62 | |||
1131 | 63 | - (id)copyWithZone:(NSZone *)zone; | ||
1132 | 64 | { | ||
1133 | 65 | return self; | ||
1134 | 66 | } | ||
1135 | 67 | |||
1136 | 68 | - (id)retain; | ||
1137 | 69 | { | ||
1138 | 70 | return self; | ||
1139 | 71 | } | ||
1140 | 72 | |||
1141 | 73 | - (NSUInteger)retainCount; | ||
1142 | 74 | { | ||
1143 | 75 | return NSUIntegerMax; | ||
1144 | 76 | } | ||
1145 | 77 | |||
1146 | 78 | - (void)release; | ||
1147 | 79 | { | ||
1148 | 80 | |||
1149 | 81 | } | ||
1150 | 82 | |||
1151 | 83 | - (id)autorelease; | ||
1152 | 84 | { | ||
1153 | 85 | return self; | ||
1154 | 86 | } | ||
1155 | 87 | |||
1156 | 47 | - (id)init; | 88 | - (id)init; |
1157 | 48 | { | 89 | { |
1158 | 49 | self = [super init]; | 90 | self = [super init]; |
1159 | @@ -59,7 +100,7 @@ | |||
1160 | 59 | [super dealloc]; | 100 | [super dealloc]; |
1161 | 60 | } | 101 | } |
1162 | 61 | 102 | ||
1164 | 62 | - (id)volumeInfoWithCompletionBlock:(void(^)(NSArray *volumeInfo, NSError *error))completionBlock; | 103 | - (id)volumeInfoWithCompletionBlock:(void(^)(NSArray *volumeInfos, NSError *error))completionBlock; |
1165 | 63 | { | 104 | { |
1166 | 64 | NSURL *volumesURL = [self URLForNode:@"/volumes" includeChildren:NO]; | 105 | NSURL *volumesURL = [self URLForNode:@"/volumes" includeChildren:NO]; |
1167 | 65 | return [self execute:@"GET" toURL:volumesURL withParameters:nil requestBody:nil parseResponseBody:YES completionBlock:^(id results, NSError *error) { | 106 | return [self execute:@"GET" toURL:volumesURL withParameters:nil requestBody:nil parseResponseBody:YES completionBlock:^(id results, NSError *error) { |
1168 | @@ -205,9 +246,44 @@ | |||
1169 | 205 | }]; | 246 | }]; |
1170 | 206 | } | 247 | } |
1171 | 207 | 248 | ||
1172 | 249 | - (id)createFolderAtPath:(NSString*)folderPath completionBlock:(void(^)(NSDictionary *nodeInfo, NSError *error))completionBlock; | ||
1173 | 250 | { | ||
1174 | 251 | NSParameterAssert(folderPath != nil); | ||
1175 | 252 | NSParameterAssert(completionBlock != NULL); | ||
1176 | 253 | |||
1177 | 254 | NSURL *nodeURL = [self URLForNode:folderPath includeChildren:NO]; | ||
1178 | 255 | return [self execute:@"PUT" toURL:nodeURL withParameters:nil requestBody:@"{\"kind\": \"directory\"}" parseResponseBody:YES completionBlock:^(id results, NSError *error) { | ||
1179 | 256 | completionBlock(results, error); | ||
1180 | 257 | }]; | ||
1181 | 258 | } | ||
1182 | 259 | |||
1183 | 260 | - (id)createVolumeAtPath:(NSString*)volumePath completionBlock:(void(^)(NSDictionary *volumeInfo, NSError *error))completionBlock; | ||
1184 | 261 | { | ||
1185 | 262 | NSParameterAssert(volumePath != nil); | ||
1186 | 263 | NSParameterAssert(completionBlock != NULL); | ||
1187 | 264 | |||
1188 | 265 | NSURL *volumeURL = [self URLForVolumeWithPath:volumePath]; | ||
1189 | 266 | return [self execute:@"PUT" toURL:volumeURL withParameters:nil requestBody:@"" parseResponseBody:YES completionBlock:^(id results, NSError *error) { | ||
1190 | 267 | completionBlock(results, error); | ||
1191 | 268 | }]; | ||
1192 | 269 | } | ||
1193 | 270 | |||
1194 | 208 | 271 | ||
1195 | 209 | #pragma mark Private Methods | 272 | #pragma mark Private Methods |
1196 | 210 | 273 | ||
1197 | 274 | - (NSURL*)URLForVolumeWithPath:(NSString*)volumePath; | ||
1198 | 275 | { | ||
1199 | 276 | NSParameterAssert(volumePath != nil); | ||
1200 | 277 | NSParameterAssert([volumePath hasPrefix:@"/"]); | ||
1201 | 278 | |||
1202 | 279 | NSMutableString *urlString = [NSMutableString stringWithString:U1FilesServiceAPIBase]; | ||
1203 | 280 | [urlString appendString:U1FilesServiceAPIPath]; | ||
1204 | 281 | [urlString appendString:U1FilesServiceAPIVersion1]; | ||
1205 | 282 | [urlString appendString:@"/volumes"]; | ||
1206 | 283 | [urlString appendString:volumePath]; | ||
1207 | 284 | return [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; | ||
1208 | 285 | } | ||
1209 | 286 | |||
1210 | 211 | - (NSURL*)URLForNode:(NSString*)nodePath includeChildren:(BOOL)includeChildren; | 287 | - (NSURL*)URLForNode:(NSString*)nodePath includeChildren:(BOOL)includeChildren; |
1211 | 212 | { | 288 | { |
1212 | 213 | NSMutableString *urlString = [NSMutableString stringWithString:U1FilesServiceAPIBase]; | 289 | NSMutableString *urlString = [NSMutableString stringWithString:U1FilesServiceAPIBase]; |
1213 | 214 | 290 | ||
1214 | === modified file 'Files/U1FolderViewController.m' | |||
1215 | --- Files/U1FolderViewController.m 2011-09-27 14:36:00 +0000 | |||
1216 | +++ Files/U1FolderViewController.m 2011-10-04 14:38:28 +0000 | |||
1217 | @@ -50,6 +50,7 @@ | |||
1218 | 50 | self.title = [theResourcePath lastPathComponent]; | 50 | self.title = [theResourcePath lastPathComponent]; |
1219 | 51 | self.resourcePath = [theResourcePath copy]; | 51 | self.resourcePath = [theResourcePath copy]; |
1220 | 52 | self.byteSizeTransformer = [[U1ByteSizeValueTransformer new] autorelease]; | 52 | self.byteSizeTransformer = [[U1ByteSizeValueTransformer new] autorelease]; |
1221 | 53 | filesClient = [U1FilesClient sharedFilesClient]; | ||
1222 | 53 | 54 | ||
1223 | 54 | UIBarButtonItem *uploadItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(uploadImage:)]; | 55 | UIBarButtonItem *uploadItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(uploadImage:)]; |
1224 | 55 | [self.navigationItem setRightBarButtonItem:uploadItem]; | 56 | [self.navigationItem setRightBarButtonItem:uploadItem]; |
1225 | @@ -74,7 +75,6 @@ | |||
1226 | 74 | - (void)dealloc; | 75 | - (void)dealloc; |
1227 | 75 | { | 76 | { |
1228 | 76 | [loadingCell release]; | 77 | [loadingCell release]; |
1229 | 77 | [filesClient release]; | ||
1230 | 78 | [resourcePath release]; | 78 | [resourcePath release]; |
1231 | 79 | [node release]; | 79 | [node release]; |
1232 | 80 | [byteSizeTransformer release]; | 80 | [byteSizeTransformer release]; |
1233 | 81 | 81 | ||
1234 | === added file 'Files/U1LocalAssetsManager.h' | |||
1235 | --- Files/U1LocalAssetsManager.h 1970-01-01 00:00:00 +0000 | |||
1236 | +++ Files/U1LocalAssetsManager.h 2011-10-04 14:38:28 +0000 | |||
1237 | @@ -0,0 +1,29 @@ | |||
1238 | 1 | // | ||
1239 | 2 | // Copyright 2011 Canonical Ltd. | ||
1240 | 3 | // | ||
1241 | 4 | // This program is free software: you can redistribute it and/or modify it | ||
1242 | 5 | // under the terms of the GNU Affero General Public License version 3, | ||
1243 | 6 | // as published by the Free Software Foundation. | ||
1244 | 7 | // | ||
1245 | 8 | // This program is distributed in the hope that it will be useful, but | ||
1246 | 9 | // WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1247 | 10 | // MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1248 | 11 | // PURPOSE. See the GNU Affero General Public License for more details. | ||
1249 | 12 | // | ||
1250 | 13 | // You should have received a copy of the GNU Affero General Public License | ||
1251 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1252 | 15 | |||
1253 | 16 | #import <Foundation/Foundation.h> | ||
1254 | 17 | |||
1255 | 18 | @class U1DataRepository; | ||
1256 | 19 | @class U1Volume; | ||
1257 | 20 | |||
1258 | 21 | |||
1259 | 22 | @interface U1LocalAssetsManager : NSObject | ||
1260 | 23 | @property (retain) U1DataRepository *dataRepository; | ||
1261 | 24 | @property (retain) NSMutableArray *localAssetsToUpload; | ||
1262 | 25 | @property (retain) U1Volume *remoteUploadVolume; | ||
1263 | 26 | + (U1LocalAssetsManager *)sharedFilesManager; | ||
1264 | 27 | - (void)checkForNewAssets; | ||
1265 | 28 | - (void)uploadPendingAssets; | ||
1266 | 29 | @end | ||
1267 | 0 | 30 | ||
1268 | === added file 'Files/U1LocalAssetsManager.m' | |||
1269 | --- Files/U1LocalAssetsManager.m 1970-01-01 00:00:00 +0000 | |||
1270 | +++ Files/U1LocalAssetsManager.m 2011-10-04 14:38:28 +0000 | |||
1271 | @@ -0,0 +1,209 @@ | |||
1272 | 1 | // | ||
1273 | 2 | // Copyright 2011 Canonical Ltd. | ||
1274 | 3 | // | ||
1275 | 4 | // This program is free software: you can redistribute it and/or modify it | ||
1276 | 5 | // under the terms of the GNU Affero General Public License version 3, | ||
1277 | 6 | // as published by the Free Software Foundation. | ||
1278 | 7 | // | ||
1279 | 8 | // This program is distributed in the hope that it will be useful, but | ||
1280 | 9 | // WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1281 | 10 | // MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1282 | 11 | // PURPOSE. See the GNU Affero General Public License for more details. | ||
1283 | 12 | // | ||
1284 | 13 | // You should have received a copy of the GNU Affero General Public License | ||
1285 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1286 | 15 | |||
1287 | 16 | #import <AssetsLibrary/AssetsLibrary.h> | ||
1288 | 17 | |||
1289 | 18 | #import "U1Asset.h" | ||
1290 | 19 | #import "U1DataRepository.h" | ||
1291 | 20 | #import "U1LocalAssetsManager.h" | ||
1292 | 21 | #import "U1AssetUploadOperation.h" | ||
1293 | 22 | #import "U1FilesClient.h" | ||
1294 | 23 | #import "U1Volume.h" | ||
1295 | 24 | |||
1296 | 25 | @interface U1LocalAssetsManager () | ||
1297 | 26 | @property (retain) ALAssetsLibrary *assetsLibrary; | ||
1298 | 27 | @property (retain) NSOperationQueue *uploadQueue; | ||
1299 | 28 | - (void)walkAssetsInLibrary; | ||
1300 | 29 | - (void)uploadRepresentation:(ALAssetRepresentation*)rep forAsset:(U1Asset*)asset; | ||
1301 | 30 | - (NSString *)generateFilenameForAsset:(ALAsset *)asset; | ||
1302 | 31 | @end | ||
1303 | 32 | |||
1304 | 33 | static U1LocalAssetsManager *sharedFilesManager = nil; | ||
1305 | 34 | |||
1306 | 35 | @implementation U1LocalAssetsManager | ||
1307 | 36 | |||
1308 | 37 | @synthesize dataRepository, uploadQueue, localAssetsToUpload, remoteUploadVolume; | ||
1309 | 38 | @synthesize assetsLibrary; | ||
1310 | 39 | |||
1311 | 40 | + (U1LocalAssetsManager *)sharedFilesManager; | ||
1312 | 41 | { | ||
1313 | 42 | if (sharedFilesManager == nil) | ||
1314 | 43 | { | ||
1315 | 44 | sharedFilesManager = [[super allocWithZone:NULL] init]; | ||
1316 | 45 | } | ||
1317 | 46 | return sharedFilesManager; | ||
1318 | 47 | } | ||
1319 | 48 | |||
1320 | 49 | + (id)allocWithZone:(NSZone *)zone; | ||
1321 | 50 | { | ||
1322 | 51 | return [[self sharedFilesManager] retain]; | ||
1323 | 52 | } | ||
1324 | 53 | |||
1325 | 54 | - (id)copyWithZone:(NSZone *)zone; | ||
1326 | 55 | { | ||
1327 | 56 | return self; | ||
1328 | 57 | } | ||
1329 | 58 | |||
1330 | 59 | - (id)retain; | ||
1331 | 60 | { | ||
1332 | 61 | return self; | ||
1333 | 62 | } | ||
1334 | 63 | |||
1335 | 64 | - (NSUInteger)retainCount; | ||
1336 | 65 | { | ||
1337 | 66 | return NSUIntegerMax; | ||
1338 | 67 | } | ||
1339 | 68 | |||
1340 | 69 | - (void)release; | ||
1341 | 70 | { | ||
1342 | 71 | |||
1343 | 72 | } | ||
1344 | 73 | |||
1345 | 74 | - (id)autorelease; | ||
1346 | 75 | { | ||
1347 | 76 | return self; | ||
1348 | 77 | } | ||
1349 | 78 | |||
1350 | 79 | - (id)init | ||
1351 | 80 | { | ||
1352 | 81 | if (!(self = [super init])) | ||
1353 | 82 | return nil; | ||
1354 | 83 | |||
1355 | 84 | assetsLibrary = [[ALAssetsLibrary alloc] init]; | ||
1356 | 85 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(libraryChanged:) name:ALAssetsLibraryChangedNotification object:assetsLibrary]; | ||
1357 | 86 | dataRepository = [U1DataRepository sharedDataRepository]; | ||
1358 | 87 | uploadQueue = [[NSOperationQueue alloc] init]; | ||
1359 | 88 | self.localAssetsToUpload = [NSMutableArray array]; | ||
1360 | 89 | return self; | ||
1361 | 90 | } | ||
1362 | 91 | |||
1363 | 92 | - (void)dealloc | ||
1364 | 93 | { | ||
1365 | 94 | [[NSNotificationCenter defaultCenter] removeObserver:self]; | ||
1366 | 95 | [assetsLibrary release]; | ||
1367 | 96 | [super dealloc]; | ||
1368 | 97 | } | ||
1369 | 98 | |||
1370 | 99 | - (void)checkForNewAssets; | ||
1371 | 100 | { | ||
1372 | 101 | NSLog(@"Checking for new assets."); | ||
1373 | 102 | [self walkAssetsInLibrary]; | ||
1374 | 103 | } | ||
1375 | 104 | |||
1376 | 105 | - (void)libraryChanged:(NSNotification*)notification; | ||
1377 | 106 | { | ||
1378 | 107 | NSLog(@"The library changed, so we'll walk the assets again."); | ||
1379 | 108 | [self walkAssetsInLibrary]; | ||
1380 | 109 | } | ||
1381 | 110 | |||
1382 | 111 | - (void)walkAssetsInLibrary; | ||
1383 | 112 | { | ||
1384 | 113 | [self.assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos | ||
1385 | 114 | usingBlock:^(ALAssetsGroup *group, BOOL *stop) { | ||
1386 | 115 | [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop) { | ||
1387 | 116 | |||
1388 | 117 | ALAsset *someAsset = asset; | ||
1389 | 118 | if (someAsset == nil) | ||
1390 | 119 | return; | ||
1391 | 120 | dispatch_async(dispatch_get_main_queue(), ^(void) { | ||
1392 | 121 | ALAssetRepresentation *defaultRep = [someAsset defaultRepresentation]; | ||
1393 | 122 | NSString *assetURL = [[defaultRep url] absoluteString]; | ||
1394 | 123 | NSString *groupId = [group valueForProperty:ALAssetsGroupPropertyPersistentID]; | ||
1395 | 124 | |||
1396 | 125 | NSPredicate *p = [NSPredicate predicateWithFormat:@"groupId = %@ and url = %@", | ||
1397 | 126 | groupId, assetURL]; | ||
1398 | 127 | NSError *error = nil; | ||
1399 | 128 | NSArray *results = [self.dataRepository resultsForEntityClass:[U1Asset class] matchingPredicate:p withSortDescriptors:nil error:&error]; | ||
1400 | 129 | U1Asset *trackedAsset = [results lastObject]; | ||
1401 | 130 | NSLog(@"Did we find an asset? (%@)", [trackedAsset description]); | ||
1402 | 131 | if (trackedAsset == nil) | ||
1403 | 132 | { | ||
1404 | 133 | if ([[someAsset valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) { | ||
1405 | 134 | [self.dataRepository dispatchBlockWithManagedObjectContext:^(NSManagedObjectContext *context) { | ||
1406 | 135 | |||
1407 | 136 | U1Asset *newAsset = [U1Asset insertInManagedObjectContext:context]; | ||
1408 | 137 | newAsset.groupId = groupId; | ||
1409 | 138 | newAsset.url = assetURL; | ||
1410 | 139 | newAsset.filename = [self generateFilenameForAsset:someAsset]; | ||
1411 | 140 | NSLog(@"Adding and uploading an asset for %@ (filename: %@)", newAsset.url, newAsset.filename); | ||
1412 | 141 | [self.localAssetsToUpload addObject:newAsset]; | ||
1413 | 142 | [self uploadRepresentation:defaultRep forAsset:newAsset]; | ||
1414 | 143 | [self.dataRepository save:NULL]; | ||
1415 | 144 | }]; | ||
1416 | 145 | } | ||
1417 | 146 | } | ||
1418 | 147 | }); | ||
1419 | 148 | }]; | ||
1420 | 149 | } | ||
1421 | 150 | failureBlock:^(NSError *error) { | ||
1422 | 151 | NSLog(@"Some error happened."); | ||
1423 | 152 | }]; | ||
1424 | 153 | } | ||
1425 | 154 | |||
1426 | 155 | - (NSString *)generateFilenameForAsset:(ALAsset *)asset; | ||
1427 | 156 | { | ||
1428 | 157 | // get the type of the asset | ||
1429 | 158 | NSString *ext = @"JPG"; | ||
1430 | 159 | |||
1431 | 160 | if ([asset valueForProperty:ALAssetPropertyType] == ALAssetTypeVideo) { | ||
1432 | 161 | ext = @"M4V"; | ||
1433 | 162 | } | ||
1434 | 163 | |||
1435 | 164 | NSError *error = nil; | ||
1436 | 165 | int idx = [[self.dataRepository resultsForEntityClass:[U1Asset class] | ||
1437 | 166 | matchingPredicate:nil | ||
1438 | 167 | withSortDescriptors:nil | ||
1439 | 168 | error:&error] count]; | ||
1440 | 169 | |||
1441 | 170 | return [NSString stringWithFormat:@"IMG_%d.%@", idx, ext]; | ||
1442 | 171 | } | ||
1443 | 172 | |||
1444 | 173 | - (void)uploadPendingAssets; | ||
1445 | 174 | { | ||
1446 | 175 | NSLog(@"Uploading %d assets", [self.localAssetsToUpload count]); | ||
1447 | 176 | [self.localAssetsToUpload enumerateObjectsUsingBlock:^(U1Asset *obj, NSUInteger idx, BOOL *stop) { | ||
1448 | 177 | [self.assetsLibrary assetForURL:[NSURL URLWithString:obj.url] | ||
1449 | 178 | resultBlock:^(ALAsset *asset) { | ||
1450 | 179 | [self uploadRepresentation:[asset defaultRepresentation] forAsset:obj]; | ||
1451 | 180 | } failureBlock:^(NSError *error) { | ||
1452 | 181 | NSLog(@"Error: %@", error); | ||
1453 | 182 | }]; | ||
1454 | 183 | }]; | ||
1455 | 184 | } | ||
1456 | 185 | |||
1457 | 186 | - (void)uploadRepresentation:(ALAssetRepresentation *)rep forAsset:(U1Asset *)asset | ||
1458 | 187 | { | ||
1459 | 188 | // iterate self.localAssetsToUpload, creating NSOperations for each, giving each a completionBlock to remove the asset from localAssetsToUpload if it completed properly | ||
1460 | 189 | Byte *buffer = (Byte*)malloc(rep.size); | ||
1461 | 190 | NSUInteger length = [rep getBytes:buffer fromOffset:0 length:rep.size error:nil]; | ||
1462 | 191 | NSData *assetData = [NSData dataWithBytesNoCopy:buffer length:length freeWhenDone:YES]; | ||
1463 | 192 | |||
1464 | 193 | U1AssetUploadOperation *operation = [[U1AssetUploadOperation alloc] init]; | ||
1465 | 194 | operation.asset = asset; | ||
1466 | 195 | operation.folder = [self.remoteUploadVolume rootFolder]; | ||
1467 | 196 | operation.filename = asset.filename; | ||
1468 | 197 | operation.assetData = assetData; | ||
1469 | 198 | [operation setCompletionBlock:^{ | ||
1470 | 199 | dispatch_async(dispatch_get_main_queue(), ^(void) { | ||
1471 | 200 | if (operation.error == nil) // or the error is somehow unrecoverable (e.g., over quota) | ||
1472 | 201 | { | ||
1473 | 202 | [self.localAssetsToUpload removeObject:asset]; | ||
1474 | 203 | } | ||
1475 | 204 | }); | ||
1476 | 205 | }]; | ||
1477 | 206 | [self.uploadQueue addOperation:operation]; | ||
1478 | 207 | } | ||
1479 | 208 | |||
1480 | 209 | @end | ||
1481 | 0 | 210 | ||
1482 | === modified file 'Files/U1Volume.h' | |||
1483 | --- Files/U1Volume.h 2011-09-08 16:59:34 +0000 | |||
1484 | +++ Files/U1Volume.h 2011-10-04 14:38:28 +0000 | |||
1485 | @@ -1,5 +1,22 @@ | |||
1486 | 1 | // | ||
1487 | 2 | // Copyright 2011 Canonical Ltd. | ||
1488 | 3 | // | ||
1489 | 4 | // This program is free software: you can redistribute it and/or modify it | ||
1490 | 5 | // under the terms of the GNU Affero General Public License version 3, | ||
1491 | 6 | // as published by the Free Software Foundation. | ||
1492 | 7 | // | ||
1493 | 8 | // This program is distributed in the hope that it will be useful, but | ||
1494 | 9 | // WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1495 | 10 | // MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1496 | 11 | // PURPOSE. See the GNU Affero General Public License for more details. | ||
1497 | 12 | // | ||
1498 | 13 | // You should have received a copy of the GNU Affero General Public License | ||
1499 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1500 | 15 | |||
1501 | 1 | #import "_U1Volume.h" | 16 | #import "_U1Volume.h" |
1502 | 17 | #import "U1FolderNode.h" | ||
1503 | 18 | |||
1504 | 2 | 19 | ||
1505 | 3 | @interface U1Volume : _U1Volume {} | 20 | @interface U1Volume : _U1Volume {} |
1507 | 4 | // Custom logic goes here. | 21 | - (U1FolderNode *)rootFolder; |
1508 | 5 | @end | 22 | @end |
1509 | 6 | 23 | ||
1510 | === modified file 'Files/U1Volume.m' | |||
1511 | --- Files/U1Volume.m 2011-09-08 16:59:34 +0000 | |||
1512 | +++ Files/U1Volume.m 2011-10-04 14:38:28 +0000 | |||
1513 | @@ -1,7 +1,59 @@ | |||
1514 | 1 | // | ||
1515 | 2 | // Copyright 2011 Canonical Ltd. | ||
1516 | 3 | // | ||
1517 | 4 | // This program is free software: you can redistribute it and/or modify it | ||
1518 | 5 | // under the terms of the GNU Affero General Public License version 3, | ||
1519 | 6 | // as published by the Free Software Foundation. | ||
1520 | 7 | // | ||
1521 | 8 | // This program is distributed in the hope that it will be useful, but | ||
1522 | 9 | // WITHOUT ANY WARRANTY; without even the implied warranties of | ||
1523 | 10 | // MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
1524 | 11 | // PURPOSE. See the GNU Affero General Public License for more details. | ||
1525 | 12 | // | ||
1526 | 13 | // You should have received a copy of the GNU Affero General Public License | ||
1527 | 14 | // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1528 | 15 | |||
1529 | 1 | #import "U1Volume.h" | 16 | #import "U1Volume.h" |
1530 | 17 | #import "U1FolderNode.h" | ||
1531 | 18 | #import "U1DataRepository.h" | ||
1532 | 19 | |||
1533 | 2 | 20 | ||
1534 | 3 | @implementation U1Volume | 21 | @implementation U1Volume |
1535 | 4 | 22 | ||
1537 | 5 | // Custom logic goes here. | 23 | - (void)updatePropertiesFromJSONDictionary:(NSDictionary *)jsonDictionary; |
1538 | 24 | { | ||
1539 | 25 | [super updatePropertiesFromJSONDictionary:jsonDictionary]; | ||
1540 | 26 | self.nodePath = [jsonDictionary objectForKey:@"node_path"]; | ||
1541 | 27 | } | ||
1542 | 28 | |||
1543 | 29 | - (U1FolderNode *)rootFolder; | ||
1544 | 30 | { | ||
1545 | 31 | // Look up a U1FolderNode with us as the volume path and some part of us as its name? | ||
1546 | 32 | // If it doesn't exist, create it, and return it. | ||
1547 | 33 | U1DataRepository *dataRepository = [U1DataRepository sharedDataRepository]; | ||
1548 | 34 | NSPredicate *p = [NSPredicate predicateWithFormat:@"resourcePath = %@", self.nodePath]; | ||
1549 | 35 | NSError *error = nil; | ||
1550 | 36 | NSArray *results = [dataRepository resultsForEntityClass:[U1FolderNode class] matchingPredicate:p withSortDescriptors:nil error:&error]; | ||
1551 | 37 | U1FolderNode *rootFolder = [results lastObject]; | ||
1552 | 38 | NSLog(@"Did we find a root folder? (%@)", [rootFolder description]); | ||
1553 | 39 | |||
1554 | 40 | if (rootFolder == nil) | ||
1555 | 41 | { | ||
1556 | 42 | // Upload | ||
1557 | 43 | [dataRepository dispatchBlockWithManagedObjectContext:^(NSManagedObjectContext *context) { | ||
1558 | 44 | |||
1559 | 45 | U1FolderNode *rootFolder = [U1FolderNode insertInManagedObjectContext:context]; | ||
1560 | 46 | rootFolder.resourcePath = self.nodePath; | ||
1561 | 47 | rootFolder.contentPath = self.contentPath; | ||
1562 | 48 | NSLog(@"Adding a rootFolder node for %@", self.nodePath); | ||
1563 | 49 | [dataRepository save:NULL]; | ||
1564 | 50 | }]; | ||
1565 | 51 | |||
1566 | 52 | results = [dataRepository resultsForEntityClass:[U1FolderNode class] matchingPredicate:p withSortDescriptors:nil error:&error]; | ||
1567 | 53 | rootFolder = [results lastObject]; | ||
1568 | 54 | } | ||
1569 | 55 | |||
1570 | 56 | return rootFolder; | ||
1571 | 57 | } | ||
1572 | 6 | 58 | ||
1573 | 7 | @end | 59 | @end |
1574 | 8 | 60 | ||
1575 | === modified file 'Files/U1VolumesViewController.h' | |||
1576 | --- Files/U1VolumesViewController.h 2011-08-31 14:56:30 +0000 | |||
1577 | +++ Files/U1VolumesViewController.h 2011-10-04 14:38:28 +0000 | |||
1578 | @@ -17,7 +17,8 @@ | |||
1579 | 17 | 17 | ||
1580 | 18 | #import "PullRefreshTableViewController.h" | 18 | #import "PullRefreshTableViewController.h" |
1581 | 19 | 19 | ||
1583 | 20 | @class U1FilesService; | 20 | @class U1FilesClient; |
1584 | 21 | @class U1Volume; | ||
1585 | 21 | 22 | ||
1586 | 22 | @protocol U1VolumesViewControllerDelegate; | 23 | @protocol U1VolumesViewControllerDelegate; |
1587 | 23 | 24 | ||
1588 | @@ -27,12 +28,12 @@ | |||
1589 | 27 | @property (nonatomic, retain, readonly) IBOutlet UITableViewCell *loadingCell; | 28 | @property (nonatomic, retain, readonly) IBOutlet UITableViewCell *loadingCell; |
1590 | 28 | 29 | ||
1591 | 29 | @property (assign) id<U1VolumesViewControllerDelegate> delegate; | 30 | @property (assign) id<U1VolumesViewControllerDelegate> delegate; |
1593 | 30 | @property (nonatomic, retain) U1FilesService *filesService; | 31 | @property (retain) U1FilesClient *filesClient; |
1594 | 31 | 32 | ||
1595 | 32 | @end | 33 | @end |
1596 | 33 | 34 | ||
1597 | 34 | 35 | ||
1598 | 35 | @protocol U1VolumesViewControllerDelegate <NSObject> | 36 | @protocol U1VolumesViewControllerDelegate <NSObject> |
1599 | 36 | @required | 37 | @required |
1601 | 37 | - (void)volumesController:(U1VolumesViewController*)volumesController didSelectVolume:(NSDictionary*)volume; | 38 | - (void)volumesController:(U1VolumesViewController*)volumesController didSelectVolume:(U1Volume*)volume; |
1602 | 38 | @end | 39 | @end |
1603 | 39 | 40 | ||
1604 | === modified file 'Files/U1VolumesViewController.m' | |||
1605 | --- Files/U1VolumesViewController.m 2011-09-27 14:36:00 +0000 | |||
1606 | +++ Files/U1VolumesViewController.m 2011-10-04 14:38:28 +0000 | |||
1607 | @@ -15,18 +15,20 @@ | |||
1608 | 15 | 15 | ||
1609 | 16 | #import "U1VolumesViewController.h" | 16 | #import "U1VolumesViewController.h" |
1610 | 17 | 17 | ||
1612 | 18 | #import "U1FilesService.h" | 18 | #import "U1FilesClient.h" |
1613 | 19 | #import "U1Volume.h" | ||
1614 | 19 | 20 | ||
1615 | 20 | 21 | ||
1616 | 21 | @interface U1VolumesViewController () | 22 | @interface U1VolumesViewController () |
1617 | 22 | @property (retain) NSArray *volumes; | 23 | @property (retain) NSArray *volumes; |
1618 | 24 | - (void)loadVolumes; | ||
1619 | 23 | @end | 25 | @end |
1620 | 24 | 26 | ||
1621 | 25 | 27 | ||
1622 | 26 | @implementation U1VolumesViewController | 28 | @implementation U1VolumesViewController |
1623 | 27 | 29 | ||
1624 | 28 | @synthesize loadingCell; | 30 | @synthesize loadingCell; |
1626 | 29 | @synthesize delegate, filesService; | 31 | @synthesize delegate, filesClient; |
1627 | 30 | @synthesize volumes; | 32 | @synthesize volumes; |
1628 | 31 | 33 | ||
1629 | 32 | - (id)init; | 34 | - (id)init; |
1630 | @@ -35,6 +37,7 @@ | |||
1631 | 35 | if (!self) | 37 | if (!self) |
1632 | 36 | return nil; | 38 | return nil; |
1633 | 37 | self.title = NSLocalizedString(@"Home", @""); | 39 | self.title = NSLocalizedString(@"Home", @""); |
1634 | 40 | filesClient = [U1FilesClient sharedFilesClient]; | ||
1635 | 38 | UIImage *logoImage = [UIImage imageNamed:@"logo_4_white"]; | 41 | UIImage *logoImage = [UIImage imageNamed:@"logo_4_white"]; |
1636 | 39 | UIImageView *logoView = [[UIImageView alloc] initWithImage:logoImage]; | 42 | UIImageView *logoView = [[UIImageView alloc] initWithImage:logoImage]; |
1637 | 40 | [self.navigationItem setTitleView:logoView]; | 43 | [self.navigationItem setTitleView:logoView]; |
1638 | @@ -45,7 +48,6 @@ | |||
1639 | 45 | - (void)dealloc; | 48 | - (void)dealloc; |
1640 | 46 | { | 49 | { |
1641 | 47 | [loadingCell release]; | 50 | [loadingCell release]; |
1642 | 48 | [filesService release]; | ||
1643 | 49 | [volumes release]; | 51 | [volumes release]; |
1644 | 50 | [super dealloc]; | 52 | [super dealloc]; |
1645 | 51 | } | 53 | } |
1646 | @@ -53,12 +55,18 @@ | |||
1647 | 53 | - (void)viewDidLoad; | 55 | - (void)viewDidLoad; |
1648 | 54 | { | 56 | { |
1649 | 55 | [super viewDidLoad]; | 57 | [super viewDidLoad]; |
1651 | 56 | [self.filesService volumeInfoWithCompletionBlock:^(NSArray *volumeInfo, NSError *error) { | 58 | [self.filesClient volumesWithCompletionBlock:^(NSArray *volumeInfos, NSError *error) { |
1652 | 57 | dispatch_async(dispatch_get_main_queue(), ^(void) { | 59 | dispatch_async(dispatch_get_main_queue(), ^(void) { |
1654 | 58 | self.volumes = volumeInfo; | 60 | self.volumes = volumeInfos; |
1655 | 59 | [self.tableView reloadData]; | 61 | [self.tableView reloadData]; |
1656 | 60 | }); | 62 | }); |
1657 | 61 | }]; | 63 | }]; |
1658 | 64 | [self loadVolumes]; | ||
1659 | 65 | } | ||
1660 | 66 | |||
1661 | 67 | - (void)refresh; | ||
1662 | 68 | { | ||
1663 | 69 | [self loadVolumes]; | ||
1664 | 62 | } | 70 | } |
1665 | 63 | 71 | ||
1666 | 64 | - (void)viewDidUnload; | 72 | - (void)viewDidUnload; |
1667 | @@ -93,8 +101,8 @@ | |||
1668 | 93 | [cell setSelectionStyle:UITableViewCellSelectionStyleGray]; | 101 | [cell setSelectionStyle:UITableViewCellSelectionStyleGray]; |
1669 | 94 | [cell.imageView setImage:[UIImage imageNamed:@"ic_folder"]]; | 102 | [cell.imageView setImage:[UIImage imageNamed:@"ic_folder"]]; |
1670 | 95 | } | 103 | } |
1673 | 96 | NSDictionary *volume = [self.volumes objectAtIndex:indexPath.row]; | 104 | U1Volume *volume = [self.volumes objectAtIndex:indexPath.row]; |
1674 | 97 | NSString *volumePath = [volume objectForKey:@"path"]; | 105 | NSString *volumePath = volume.path; |
1675 | 98 | if ([@"~/.ubuntuone/Purchased from Ubuntu One" isEqualToString:volumePath]) | 106 | if ([@"~/.ubuntuone/Purchased from Ubuntu One" isEqualToString:volumePath]) |
1676 | 99 | volumePath = @"Purchased Music"; | 107 | volumePath = @"Purchased Music"; |
1677 | 100 | if ([volumePath hasPrefix:@"~/"]) | 108 | if ([volumePath hasPrefix:@"~/"]) |
1678 | @@ -106,8 +114,19 @@ | |||
1679 | 106 | 114 | ||
1680 | 107 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; | 115 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; |
1681 | 108 | { | 116 | { |
1683 | 109 | NSDictionary *volume = [self.volumes objectAtIndex:indexPath.row]; | 117 | U1Volume *volume = [self.volumes objectAtIndex:indexPath.row]; |
1684 | 110 | [self.delegate volumesController:self didSelectVolume:volume]; | 118 | [self.delegate volumesController:self didSelectVolume:volume]; |
1685 | 111 | } | 119 | } |
1686 | 112 | 120 | ||
1687 | 121 | - (void)loadVolumes; | ||
1688 | 122 | { | ||
1689 | 123 | [self.filesClient volumesWithCompletionBlock:^(NSArray *volumeInfos, NSError *error) { | ||
1690 | 124 | dispatch_async(dispatch_get_main_queue(), ^(void) { | ||
1691 | 125 | self.volumes = volumeInfos; | ||
1692 | 126 | [self stopLoading]; | ||
1693 | 127 | [self.tableView reloadData]; | ||
1694 | 128 | }); | ||
1695 | 129 | }]; | ||
1696 | 130 | } | ||
1697 | 131 | |||
1698 | 113 | @end | 132 | @end |
Also, this branch Singletonizes a bunch of the classes we use.