VLCOneDriveController.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*****************************************************************************
  2. * VLCOneDriveController.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2014-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 "VLCOneDriveController.h"
  13. #import "VLCOneDriveConstants.h"
  14. #import "VLCOneDriveObject.h"
  15. /* the Live SDK doesn't have an umbrella header so we need to import what we need */
  16. #import <LiveSDK/LiveConnectClient.h>
  17. /* include private API headers */
  18. #import <LiveSDK/LiveApiHelper.h>
  19. @interface VLCOneDriveController () <LiveAuthDelegate, LiveDownloadOperationDelegate, VLCOneDriveObjectDelegate>
  20. {
  21. LiveConnectClient *_liveClient;
  22. NSArray *_liveScopes;
  23. BOOL _activeSession;
  24. }
  25. @end
  26. @implementation VLCOneDriveController
  27. + (VLCOneDriveController *)sharedInstance
  28. {
  29. static VLCOneDriveController *sharedInstance = nil;
  30. static dispatch_once_t pred;
  31. dispatch_once(&pred, ^{
  32. sharedInstance = [[self alloc] init];
  33. });
  34. return sharedInstance;
  35. }
  36. - (instancetype)init
  37. {
  38. self = [super init];
  39. if (!self)
  40. return self;
  41. _liveScopes = @[@"wl.signin",@"wl.offline_access",@"wl.skydrive"];
  42. _liveClient = [[LiveConnectClient alloc] initWithClientId:kVLCOneDriveClientID
  43. scopes:_liveScopes
  44. delegate:self
  45. userState:@"init"];
  46. return self;
  47. }
  48. #pragma mark - authentication
  49. - (BOOL)activeSession
  50. {
  51. return _activeSession;
  52. }
  53. - (void)login
  54. {
  55. [_liveClient login:self.delegate
  56. scopes:_liveScopes
  57. delegate:self
  58. userState:@"login"];
  59. }
  60. - (void)logout
  61. {
  62. [_liveClient logoutWithDelegate:self userState:@"logout"];
  63. _activeSession = NO;
  64. _userAuthenticated = NO;
  65. }
  66. - (void)authCompleted:(LiveConnectSessionStatus)status session:(LiveConnectSession *)session userState:(id)userState
  67. {
  68. NSLog(@"authCompleted, status %i, state %@", status, userState);
  69. if (status == 1 && session != NULL && [userState isEqualToString:@"init"])
  70. _activeSession = YES;
  71. else
  72. _activeSession = NO;
  73. if (status == 1 && session != NULL && [userState isEqualToString:@"login"])
  74. _userAuthenticated = YES;
  75. else
  76. _userAuthenticated = NO;
  77. if (self.delegate) {
  78. if ([self.delegate respondsToSelector:@selector(sessionWasUpdated)])
  79. [self.delegate performSelector:@selector(sessionWasUpdated)];
  80. }
  81. }
  82. - (void)authFailed:(NSError *)error userState:(id)userState
  83. {
  84. APLog(@"OneDrive auth failed: %@, %@", error, userState);
  85. _activeSession = NO;
  86. if (self.delegate) {
  87. if ([self.delegate respondsToSelector:@selector(sessionWasUpdated)])
  88. [self.delegate performSelector:@selector(sessionWasUpdated)];
  89. }
  90. }
  91. - (void)liveOperationSucceeded:(LiveDownloadOperation *)operation
  92. {
  93. APLog(@"ODC: liveOperationSucceeded (%@)", operation.userState);
  94. }
  95. - (void)liveOperationFailed:(NSError *)error operation:(LiveDownloadOperation *)operation
  96. {
  97. APLog(@"ODC: liveOperationFailed %@ (%@)", error, operation.userState);
  98. }
  99. #pragma mark - listing
  100. - (void)loadTopLevelFolder
  101. {
  102. _rootFolder = [[VLCOneDriveObject alloc] init];
  103. _rootFolder.objectId = @"me/skydrive";
  104. _rootFolder.name = @"OneDrive";
  105. _rootFolder.type = @"folder";
  106. _rootFolder.liveClient = _liveClient;
  107. _rootFolder.delegate = self;
  108. _currentFolder = _rootFolder;
  109. [_rootFolder loadFolderContent];
  110. }
  111. - (void)loadCurrentFolder
  112. {
  113. if (_currentFolder == nil)
  114. [self loadTopLevelFolder];
  115. else {
  116. _currentFolder.delegate = self;
  117. [_currentFolder loadFolderContent];
  118. }
  119. }
  120. #pragma mark - file handling
  121. - (void)downloadFileWithPath:(NSString *)path
  122. {
  123. }
  124. - (void)liveDownloadOperationProgressed:(LiveOperationProgress *)progress
  125. data:(NSData *)receivedData
  126. operation:(LiveDownloadOperation *)operation
  127. {
  128. }
  129. - (void)streamFileWithPath:(NSString *)path
  130. {
  131. }
  132. #pragma mark - skydrive object delegation
  133. - (void)folderContentLoaded:(VLCOneDriveObject *)sender
  134. {
  135. if (self.delegate)
  136. [self.delegate performSelector:@selector(mediaListUpdated)];
  137. }
  138. - (void)folderContentLoadingFailed:(NSError *)error sender:(VLCOneDriveObject *)sender
  139. {
  140. APLog(@"folder content loading failed %@", error);
  141. }
  142. - (void)fileContentLoaded:(VLCOneDriveObject *)sender
  143. {
  144. }
  145. - (void)fileContentLoadingFailed:(NSError *)error sender:(VLCOneDriveObject *)sender
  146. {
  147. APLog(@"file content loading failed %@", error);
  148. }
  149. - (void)fullFolderTreeLoaded:(VLCOneDriveObject *)sender
  150. {
  151. if (self.delegate)
  152. [self.delegate performSelector:@selector(mediaListUpdated)];
  153. }
  154. @end