/core/externals/update-engine/externals/gdata-objectivec-client/Source/Clients/YouTube/GDataEntryYouTubeVideo.m

http://macfuse.googlecode.com/ · Objective C · 301 lines · 198 code · 72 blank · 31 comment · 13 complexity · 6f2156d6d44ea8e9f3c5241a09ba98f4 MD5 · raw file

  1. /* Copyright (c) 2008 Google Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. //
  16. // GDataEntryYouTubeVideo.m
  17. //
  18. #if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_YOUTUBE_SERVICE
  19. #import "GDataEntryYouTubeVideo.h"
  20. #import "GDataYouTubeConstants.h"
  21. #import "GDataYouTubeElements.h"
  22. @implementation GDataEntryYouTubeVideo
  23. + (GDataEntryYouTubeVideo *)videoEntry {
  24. GDataEntryYouTubeVideo *entry = [self object];
  25. [entry setNamespaces:[GDataYouTubeConstants youTubeNamespaces]];
  26. return entry;
  27. }
  28. #pragma mark -
  29. + (NSString *)standardEntryKind {
  30. return kGDataCategoryYouTubeVideo;
  31. }
  32. + (void)load {
  33. [self registerEntryClass];
  34. }
  35. - (void)addExtensionDeclarations {
  36. [super addExtensionDeclarations];
  37. Class entryClass = [self class];
  38. [self addExtensionDeclarationForParentClass:entryClass
  39. childClasses:
  40. [GDataComment class],
  41. [GDataYouTubeRating class],
  42. // YouTube element extensions
  43. [GDataYouTubeStatistics class],
  44. [GDataYouTubeNonEmbeddable class],
  45. [GDataYouTubeLocation class],
  46. [GDataYouTubeRecordedDate class],
  47. [GDataYouTubeAccessControl class],
  48. // YouTubeMediaGroup encapsulates YouTubeMediaContent
  49. [GDataYouTubeMediaGroup class],
  50. nil];
  51. // Geo
  52. [GDataGeo addGeoExtensionDeclarationsToObject:self
  53. forParentClass:entryClass];
  54. // the publication state element is an extension to the Atom publishing
  55. // control element
  56. Class atomPubControlClass = [GDataAtomPubControl class];
  57. [self addExtensionDeclarationForParentClass:atomPubControlClass
  58. childClasses:
  59. [GDataYouTubePublicationState class],
  60. [GDataYouTubeIncomplete class],
  61. nil];
  62. // the token element is an extension to the edit-media GDataLink
  63. [self addExtensionDeclarationForParentClass:[GDataLink class]
  64. childClass:[GDataYouTubeToken class]];
  65. }
  66. #if !GDATA_SIMPLE_DESCRIPTIONS
  67. - (NSMutableArray *)itemsForDescription {
  68. // report notEmbeddable since it's the unusual case
  69. NSString *nonEmbeddableValue = [self isEmbeddable] ? nil : @"YES";
  70. GDataYouTubeRating *rating = [self rating];
  71. NSString *ratingStr = nil;
  72. if (rating) {
  73. ratingStr = [NSString stringWithFormat:@"+%@/-%@",
  74. [rating numberOfLikes], [rating numberOfDislikes]];
  75. }
  76. struct GDataDescriptionRecord descRecs[] = {
  77. { @"state", @"publicationState", kGDataDescValueLabeled },
  78. { @"rating", ratingStr, kGDataDescValueIsKeyPath },
  79. { @"comment", @"comment", kGDataDescValueLabeled },
  80. { @"stats", @"statistics", kGDataDescValueLabeled },
  81. { @"mediaGroup", @"mediaGroup", kGDataDescValueLabeled },
  82. { @"geoLocation", @"geoLocation", kGDataDescValueLabeled },
  83. { @"notEmbeddable", nonEmbeddableValue, kGDataDescValueIsKeyPath },
  84. { @"pubState", @"publicationState", kGDataDescValueLabeled },
  85. { @"recorded", @"recordedDate", kGDataDescValueLabeled },
  86. { @"incomplete", @"isIncomplete", kGDataDescBooleanPresent },
  87. { @"accessControls", @"accessControls", kGDataDescArrayDescs },
  88. { nil, nil, (GDataDescRecTypes)0 }
  89. };
  90. NSMutableArray *items = [super itemsForDescription];
  91. [self addDescriptionRecords:descRecs toItems:items];
  92. return items;
  93. }
  94. #endif
  95. + (NSString *)defaultServiceVersion {
  96. return kGDataYouTubeDefaultServiceVersion;
  97. }
  98. #pragma mark -
  99. - (GDataYouTubeStatistics *)statistics {
  100. return [self objectForExtensionClass:[GDataYouTubeStatistics class]];
  101. }
  102. - (void)setStatistics:(GDataYouTubeStatistics *)obj {
  103. [self setObject:obj forExtensionClass:[GDataYouTubeStatistics class]];
  104. }
  105. - (GDataComment *)comment {
  106. return [self objectForExtensionClass:[GDataComment class]];
  107. }
  108. - (void)setComment:(GDataComment *)obj {
  109. [self setObject:obj forExtensionClass:[GDataComment class]];
  110. }
  111. - (NSString *)location {
  112. GDataYouTubeLocation *obj;
  113. obj = [self objectForExtensionClass:[GDataYouTubeLocation class]];
  114. return [obj stringValue];
  115. }
  116. - (void)setLocation:(NSString *)str {
  117. GDataYouTubeLocation *obj = [GDataYouTubeLocation valueWithString:str];
  118. [self setObject:obj forExtensionClass:[GDataYouTubeLocation class]];
  119. }
  120. - (GDataDateTime *)recordedDate {
  121. GDataYouTubeRecordedDate *obj;
  122. obj = [self objectForExtensionClass:[GDataYouTubeRecordedDate class]];
  123. return [obj dateTimeValue];
  124. }
  125. - (void)setRecordedDate:(GDataDateTime *)dateTime {
  126. GDataYouTubeRecordedDate *obj;
  127. // recordedDate is date only, no time
  128. [dateTime setHasTime:NO];
  129. obj = [GDataYouTubeRecordedDate valueWithDateTime:dateTime];
  130. [self setObject:obj forExtensionClass:[GDataYouTubeRecordedDate class]];
  131. }
  132. - (NSArray *)accessControls {
  133. return [self objectsForExtensionClass:[GDataYouTubeAccessControl class]];
  134. }
  135. - (void)setAccessControls:(NSArray *)array {
  136. [self setObjects:array forExtensionClass:[GDataYouTubeAccessControl class]];
  137. }
  138. - (void)addAccessControl:(GDataYouTubeAccessControl *)obj {
  139. [self addObject:obj forExtensionClass:[GDataYouTubeAccessControl class]];
  140. }
  141. - (BOOL)isEmbeddable {
  142. // note that the element is actually "non-embeddable", so we reverse the
  143. // sense
  144. GDataYouTubeNonEmbeddable *obj = [self objectForExtensionClass:[GDataYouTubeNonEmbeddable class]];
  145. return (obj == nil);
  146. }
  147. - (void)setIsEmbeddable:(BOOL)flag {
  148. if (!flag) {
  149. GDataYouTubeNonEmbeddable *nonEmbed = [GDataYouTubeNonEmbeddable implicitValue];
  150. [self setObject:nonEmbed forExtensionClass:[GDataYouTubeNonEmbeddable class]];
  151. } else {
  152. [self setObject:nil forExtensionClass:[GDataYouTubeNonEmbeddable class]];
  153. }
  154. }
  155. - (GDataYouTubeRating *)rating {
  156. return [self objectForExtensionClass:[GDataYouTubeRating class]];
  157. }
  158. - (void)setRating:(GDataYouTubeRating *)obj {
  159. [self setObject:obj forExtensionClass:[GDataYouTubeRating class]];
  160. }
  161. - (GDataYouTubeMediaGroup *)mediaGroup {
  162. return [self objectForExtensionClass:[GDataYouTubeMediaGroup class]];
  163. }
  164. - (void)setMediaGroup:(GDataYouTubeMediaGroup *)obj {
  165. [self setObject:obj forExtensionClass:[GDataYouTubeMediaGroup class]];
  166. }
  167. - (GDataYouTubePublicationState *)publicationState {
  168. // publication state is an extension to the entry's atomPubControl
  169. GDataAtomPubControl *atomPubControl = [self atomPubControl];
  170. return [atomPubControl objectForExtensionClass:[GDataYouTubePublicationState class]];
  171. }
  172. - (void)setGDataYouTubePublicationState:(GDataYouTubePublicationState *)obj {
  173. GDataAtomPubControl *atomPubControl = [self atomPubControl];
  174. if (obj != nil && atomPubControl == nil) {
  175. // to add the publication state, we need to make an atomPubControl element
  176. atomPubControl = [GDataAtomPubControl atomPubControl];
  177. }
  178. [atomPubControl setObject:obj forExtensionClass:[GDataYouTubePublicationState class]];
  179. }
  180. - (BOOL)isIncomplete {
  181. // incomplete is an extension to the entry's atomPubControl
  182. GDataAtomPubControl *atomPubControl = [self atomPubControl];
  183. GDataYouTubeIncomplete *obj;
  184. obj = [atomPubControl objectForExtensionClass:[GDataYouTubeIncomplete class]];
  185. return (obj != nil);
  186. }
  187. - (void)setIsIncomplete:(BOOL)flag {
  188. GDataAtomPubControl *atomPubControl = [self atomPubControl];
  189. GDataYouTubeIncomplete *obj = nil;
  190. if (flag) {
  191. obj = [GDataYouTubeIncomplete implicitValue];
  192. if (atomPubControl == nil) {
  193. // to add the incomplete, we need to make an atomPubControl element
  194. atomPubControl = [GDataAtomPubControl atomPubControl];
  195. }
  196. }
  197. [atomPubControl setObject:obj
  198. forExtensionClass:[GDataYouTubeIncomplete class]];
  199. }
  200. #pragma mark -
  201. - (GDataGeo *)geoLocation {
  202. return [GDataGeo geoLocationForObject:self];
  203. }
  204. - (void)setGeoLocation:(GDataGeo *)geo {
  205. [GDataGeo setGeoLocation:geo forObject:self];
  206. }
  207. #pragma mark -
  208. - (GDataLink *)videoResponsesLink {
  209. return [self linkWithRelAttributeValue:kGDataLinkYouTubeResponses];
  210. }
  211. - (GDataLink *)ratingsLink {
  212. return [self linkWithRelAttributeValue:kGDataLinkYouTubeRatings];
  213. }
  214. - (GDataLink *)complaintsLink {
  215. return [self linkWithRelAttributeValue:kGDataLinkYouTubeComplaints];
  216. }
  217. - (GDataLink *)captionTracksLink {
  218. return [self linkWithRelAttributeValue:kGDataLinkYouTubeCaptionTracks];
  219. }
  220. @end
  221. @implementation GDataLink (GDataYouTubeVideoEntryAdditions)
  222. - (GDataYouTubeToken *)youTubeToken {
  223. return [self objectForExtensionClass:[GDataYouTubeToken class]];
  224. }
  225. - (void)setYouTubeToken:(GDataYouTubeToken *)obj {
  226. [self setObject:obj forExtensionClass:[GDataYouTubeToken class]];
  227. }
  228. @end
  229. #endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_YOUTUBE_SERVICE