VLCOneDriveObject.m 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*****************************************************************************
  2. * VLCOneDriveObject.h
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2015 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. #import "VLCOneDriveObject.h"
  13. @implementation VLCOneDriveObject
  14. #pragma mark properties
  15. - (BOOL)isFolder
  16. {
  17. return [self.type isEqual:@"folder"] || [self.type isEqual:@"album"];
  18. }
  19. - (BOOL)isVideo
  20. {
  21. return [self.type isEqual:@"video"];
  22. }
  23. - (BOOL)isAudio
  24. {
  25. return [self.type isEqual:@"audio"];
  26. }
  27. - (NSString *)filesPath
  28. {
  29. return [self.objectId stringByAppendingString:@"/files"];
  30. }
  31. - (BOOL)hasFullFolderTree
  32. {
  33. BOOL hasFullTree = YES;
  34. if (self.folders != nil) {
  35. NSUInteger count = self.folders.count;
  36. for (NSUInteger x = 0; x < count; x++) {
  37. VLCOneDriveObject *folder = self.folders[x];
  38. if (!folder.hasFullFolderTree) {
  39. hasFullTree = NO;
  40. break;
  41. }
  42. }
  43. } else
  44. hasFullTree = NO;
  45. return hasFullTree;
  46. }
  47. #pragma mark - actions
  48. - (void)loadFolderContent
  49. {
  50. NSLog(@"loadFolderContent");
  51. if (!self.isFolder) {
  52. APLog(@"%@ is no folder, can't load content", self.objectId);
  53. return;
  54. }
  55. if (self.folders == nil) {
  56. [self.liveClient getWithPath:self.filesPath
  57. delegate:self
  58. userState:@"load-folder-content"];
  59. } else {
  60. NSUInteger count = self.folders.count;
  61. for (NSUInteger x = 0; x < count; x++) {
  62. VLCOneDriveObject *folder = self.folders[x];
  63. if (!folder.hasFullFolderTree) {
  64. [folder loadFolderContent];
  65. return;
  66. }
  67. }
  68. [self.delegate fullFolderTreeLoaded:self];
  69. }
  70. }
  71. - (void)loadFileContent
  72. {
  73. }
  74. #pragma mark - live operations
  75. - (void)liveOperationSucceeded:(LiveDownloadOperation *)operation
  76. {
  77. NSString *userState = operation.userState;
  78. NSLog(@"liveOperationSucceeded: %@", userState);
  79. if ([userState isEqualToString:@"load-file-content"]) {
  80. // LiveDownloadOperation *downloadOperation = (LiveDownloadOperation *)operation;
  81. //FIXME: handle the incoming data!
  82. [self.delegate fileContentLoaded:self];
  83. } else if ([userState isEqualToString:@"load-folder-content"]) {
  84. NSMutableArray *subFolders = [[NSMutableArray alloc] init];
  85. NSMutableArray *folderFiles = [[NSMutableArray alloc] init];
  86. NSMutableArray *items = [[NSMutableArray alloc] init];
  87. NSArray *rawFolderObjects = operation.result[@"data"];
  88. BOOL hasSubFolders = NO;
  89. NSUInteger count = rawFolderObjects.count;
  90. for (NSUInteger x = 0; x < count; x++) {
  91. NSDictionary *rawObject = rawFolderObjects[x];
  92. VLCOneDriveObject *oneDriveObject = [[VLCOneDriveObject alloc] init];
  93. oneDriveObject.parent = self;
  94. oneDriveObject.objectId = rawObject[@"id"];
  95. oneDriveObject.name = rawObject[@"name"];
  96. oneDriveObject.type = rawObject[@"type"];
  97. oneDriveObject.liveClient = self.liveClient;
  98. if (oneDriveObject.isFolder) {
  99. hasSubFolders = YES;
  100. [subFolders addObject:oneDriveObject];
  101. } else {
  102. oneDriveObject.size = rawObject[@"size"];
  103. oneDriveObject.thumbnailURL = rawObject[@"picture"];
  104. oneDriveObject.downloadPath = rawObject[@"source"];
  105. oneDriveObject.duration = rawObject[@"duration"];
  106. [folderFiles addObject:oneDriveObject];
  107. }
  108. [items addObject:oneDriveObject];
  109. }
  110. self.folders = subFolders;
  111. self.files = folderFiles;
  112. self.items = items;
  113. [self.delegate folderContentLoaded:self];
  114. }
  115. }
  116. - (void)liveOperationFailed:(NSError *)error operation:(LiveDownloadOperation *)operation
  117. {
  118. NSString *userState = operation.userState;
  119. NSLog(@"liveOperationFailed %@ (%@)", userState, error);
  120. if ([userState isEqualToString:@"load-folder-content"])
  121. [self.delegate folderContentLoadingFailed:error sender:self];
  122. else if ([userState isEqualToString:@"load-file-content"])
  123. [self.delegate fileContentLoadingFailed:error sender:self];
  124. else
  125. APLog(@"failing live operation with state %@ failed with error %@", userState, error);
  126. }
  127. #pragma mark - delegation
  128. - (void)folderContentLoaded:(VLCOneDriveObject *)sender
  129. {
  130. }
  131. - (void)folderContentLoadingFailed:(NSError *)error sender:(VLCOneDriveObject *)sender
  132. {
  133. if (self.delegate)
  134. [self.delegate folderContentLoadingFailed:error sender:self];
  135. }
  136. - (void)fullFolderTreeLoaded:(VLCOneDriveObject *)sender
  137. {
  138. [self loadFolderContent];
  139. }
  140. - (void)fileContentLoaded:(VLCOneDriveObject *)sender
  141. {
  142. }
  143. - (void)fileContentLoadingFailed:(NSError *)error sender:(VLCOneDriveObject *)sender
  144. {
  145. }
  146. @end