| 1 | // |
|---|
| 2 | // SapphireMarkMenu.m |
|---|
| 3 | // Sapphire |
|---|
| 4 | // |
|---|
| 5 | // Created by Graham Booker on 6/25/07. |
|---|
| 6 | // Copyright 2007 __www.nanopi.net__. All rights reserved. |
|---|
| 7 | // |
|---|
| 8 | |
|---|
| 9 | #import "SapphireMarkMenu.h" |
|---|
| 10 | #import "SapphireMetaData.h" |
|---|
| 11 | |
|---|
| 12 | @implementation SapphireMarkMenu |
|---|
| 13 | |
|---|
| 14 | - (id) initWithScene: (BRRenderScene *) scene metaData: (SapphireMetaData *)meta |
|---|
| 15 | { |
|---|
| 16 | self = [super initWithScene:scene]; |
|---|
| 17 | if(!self) |
|---|
| 18 | return nil; |
|---|
| 19 | |
|---|
| 20 | isDir = [meta isKindOfClass:[SapphireDirectoryMetaData class]]; |
|---|
| 21 | metaData = [meta retain]; |
|---|
| 22 | if(isDir) |
|---|
| 23 | names = [[NSArray alloc] initWithObjects: |
|---|
| 24 | @"Mark All as Watched", |
|---|
| 25 | @"Mark All as Unwatched", |
|---|
| 26 | @"Mark All as Favorite", |
|---|
| 27 | @"Mark All as Not Favorite", |
|---|
| 28 | @"Mark All to Refetch TV Data", |
|---|
| 29 | nil]; |
|---|
| 30 | else if([meta isKindOfClass:[SapphireFileMetaData class]]) |
|---|
| 31 | { |
|---|
| 32 | SapphireFileMetaData *fileMeta = (SapphireFileMetaData *)metaData; |
|---|
| 33 | NSString *watched = nil; |
|---|
| 34 | NSString *favorite = nil; |
|---|
| 35 | NSString *reimport = nil; |
|---|
| 36 | |
|---|
| 37 | if([fileMeta watched]) |
|---|
| 38 | watched = @"Mark as Unwatched"; |
|---|
| 39 | else |
|---|
| 40 | watched = @"Mark as Watched"; |
|---|
| 41 | |
|---|
| 42 | if([fileMeta favorite]) |
|---|
| 43 | favorite = @"Mark as Not Favorite"; |
|---|
| 44 | else |
|---|
| 45 | favorite = @"Mark as Favorite"; |
|---|
| 46 | if([fileMeta importedFromSource:META_TVRAGE_IMPORT_KEY]) |
|---|
| 47 | reimport = @"Mark to Refetch TV Data"; |
|---|
| 48 | names = [[NSArray alloc] initWithObjects:watched, favorite, reimport, nil]; |
|---|
| 49 | } |
|---|
| 50 | else |
|---|
| 51 | { |
|---|
| 52 | [self autorelease]; |
|---|
| 53 | return nil; |
|---|
| 54 | } |
|---|
| 55 | [[self list] setDatasource:self]; |
|---|
| 56 | |
|---|
| 57 | return self; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | - (void) dealloc |
|---|
| 61 | { |
|---|
| 62 | [metaData release]; |
|---|
| 63 | [names release]; |
|---|
| 64 | [predicate release]; |
|---|
| 65 | [super dealloc]; |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | - (void)setPredicate:(SapphirePredicate *)newPredicate |
|---|
| 69 | { |
|---|
| 70 | predicate = [newPredicate retain]; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | - (void) willBePushed |
|---|
| 74 | { |
|---|
| 75 | // We're about to be placed on screen, but we're not yet there |
|---|
| 76 | |
|---|
| 77 | // always call super |
|---|
| 78 | [super willBePushed]; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | - (void) wasPushed |
|---|
| 82 | { |
|---|
| 83 | // We've just been put on screen, the user can see this controller's content now |
|---|
| 84 | |
|---|
| 85 | // always call super |
|---|
| 86 | [super wasPushed]; |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | - (void) willBePopped |
|---|
| 90 | { |
|---|
| 91 | // The user pressed Menu, but we've not been removed from the screen yet |
|---|
| 92 | |
|---|
| 93 | // always call super |
|---|
| 94 | [super willBePopped]; |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | - (void) wasPopped |
|---|
| 98 | { |
|---|
| 99 | // The user pressed Menu, removing us from the screen |
|---|
| 100 | |
|---|
| 101 | // always call super |
|---|
| 102 | [super wasPopped]; |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | - (void) willBeBuried |
|---|
| 106 | { |
|---|
| 107 | // The user just chose an option, and we will be taken off the screen |
|---|
| 108 | |
|---|
| 109 | // always call super |
|---|
| 110 | [super willBeBuried]; |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | - (void) wasBuriedByPushingController: (BRLayerController *) controller |
|---|
| 114 | { |
|---|
| 115 | // The user chose an option and this controller os no longer on screen |
|---|
| 116 | |
|---|
| 117 | // always call super |
|---|
| 118 | [super wasBuriedByPushingController: controller]; |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | - (void) willBeExhumed |
|---|
| 122 | { |
|---|
| 123 | // the user pressed Menu, but we've not been revealed yet |
|---|
| 124 | |
|---|
| 125 | // always call super |
|---|
| 126 | [super willBeExhumed]; |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | - (void) wasExhumedByPoppingController: (BRLayerController *) controller |
|---|
| 130 | { |
|---|
| 131 | // handle being revealed when the user presses Menu |
|---|
| 132 | |
|---|
| 133 | // always call super |
|---|
| 134 | [super wasExhumedByPoppingController: controller]; |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | - (long) itemCount |
|---|
| 138 | { |
|---|
| 139 | // return the number of items in your menu list here |
|---|
| 140 | return ( [ names count]); |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | - (id<BRMenuItemLayer>) itemForRow: (long) row |
|---|
| 144 | { |
|---|
| 145 | /* |
|---|
| 146 | // build a BRTextMenuItemLayer or a BRAdornedMenuItemLayer, etc. here |
|---|
| 147 | // return that object, it will be used to display the list item. |
|---|
| 148 | return ( nil ); |
|---|
| 149 | */ |
|---|
| 150 | if( row >= [names count] ) return ( nil ) ; |
|---|
| 151 | |
|---|
| 152 | BRAdornedMenuItemLayer * result = nil ; |
|---|
| 153 | NSString *name = [names objectAtIndex:row]; |
|---|
| 154 | result = [BRAdornedMenuItemLayer adornedMenuItemWithScene: [self scene]] ; |
|---|
| 155 | |
|---|
| 156 | // add text |
|---|
| 157 | [[result textItem] setTitle: name] ; |
|---|
| 158 | |
|---|
| 159 | return ( result ) ; |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | - (NSString *) titleForRow: (long) row |
|---|
| 163 | { |
|---|
| 164 | |
|---|
| 165 | if ( row >= [ names count] ) return ( nil ); |
|---|
| 166 | |
|---|
| 167 | NSString *result = [ names objectAtIndex: row] ; |
|---|
| 168 | return ( result ) ; |
|---|
| 169 | } |
|---|
| 170 | |
|---|
| 171 | - (long) rowForTitle: (NSString *) title |
|---|
| 172 | { |
|---|
| 173 | long result = -1; |
|---|
| 174 | long i, count = [self itemCount]; |
|---|
| 175 | for ( i = 0; i < count; i++ ) |
|---|
| 176 | { |
|---|
| 177 | if ( [title isEqualToString: [self titleForRow: i]] ) |
|---|
| 178 | { |
|---|
| 179 | result = i; |
|---|
| 180 | break; |
|---|
| 181 | } |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | return ( result ); |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | - (void) itemSelected: (long) row |
|---|
| 188 | { |
|---|
| 189 | // This is called when the user presses play/pause on a list item |
|---|
| 190 | if(row >= [names count]) |
|---|
| 191 | return; |
|---|
| 192 | |
|---|
| 193 | if(isDir) |
|---|
| 194 | { |
|---|
| 195 | SapphireDirectoryMetaData *dirMeta = (SapphireDirectoryMetaData *)metaData; |
|---|
| 196 | switch(row) |
|---|
| 197 | { |
|---|
| 198 | case 0: |
|---|
| 199 | [dirMeta setWatched:YES predicate:predicate]; |
|---|
| 200 | break; |
|---|
| 201 | case 1: |
|---|
| 202 | [dirMeta setWatched:NO predicate:predicate]; |
|---|
| 203 | break; |
|---|
| 204 | case 2: |
|---|
| 205 | [dirMeta setFavorite:YES predicate:predicate]; |
|---|
| 206 | break; |
|---|
| 207 | case 3: |
|---|
| 208 | [dirMeta setFavorite:NO predicate:predicate]; |
|---|
| 209 | break; |
|---|
| 210 | case 4: |
|---|
| 211 | [dirMeta setToImportFromTVForPredicate:predicate]; |
|---|
| 212 | break; |
|---|
| 213 | } |
|---|
| 214 | } |
|---|
| 215 | else |
|---|
| 216 | { |
|---|
| 217 | SapphireFileMetaData *fileMeta = (SapphireFileMetaData *)metaData; |
|---|
| 218 | switch(row) |
|---|
| 219 | { |
|---|
| 220 | case 0: |
|---|
| 221 | [fileMeta setWatched:![fileMeta watched]]; |
|---|
| 222 | break; |
|---|
| 223 | case 1: |
|---|
| 224 | [fileMeta setFavorite:![fileMeta favorite]]; |
|---|
| 225 | break; |
|---|
| 226 | case 2: |
|---|
| 227 | [fileMeta setToImportFromSource:META_TVRAGE_IMPORT_KEY]; |
|---|
| 228 | break; |
|---|
| 229 | } |
|---|
| 230 | } |
|---|
| 231 | [metaData writeMetaData]; |
|---|
| 232 | [[self stack] popController]; |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | - (id<BRMediaPreviewController>) previewControllerForItem: (long) item |
|---|
| 236 | { |
|---|
| 237 | // If subclassing BRMediaMenuController, this function is called when the selection cursor |
|---|
| 238 | // passes over an item. |
|---|
| 239 | return ( nil ); |
|---|
| 240 | } |
|---|
| 241 | |
|---|
| 242 | @end |
|---|