| 1 | /* |
|---|
| 2 | * SapphireMarkMenu.m |
|---|
| 3 | * Sapphire |
|---|
| 4 | * |
|---|
| 5 | * Created by Graham Booker on Jun. 25, 2007. |
|---|
| 6 | * Copyright 2007 Sapphire Development Team and/or www.nanopi.net |
|---|
| 7 | * All rights reserved. |
|---|
| 8 | * |
|---|
| 9 | * This program is free software; you can redistribute it and/or modify it under the terms of the GNU |
|---|
| 10 | * General Public License as published by the Free Software Foundation; either version 3 of the License, |
|---|
| 11 | * or (at your option) any later version. |
|---|
| 12 | * |
|---|
| 13 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even |
|---|
| 14 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|---|
| 15 | * Public License for more details. |
|---|
| 16 | * |
|---|
| 17 | * You should have received a copy of the GNU General Public License along with this program; if not, |
|---|
| 18 | * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | #import "SapphireMarkMenu.h" |
|---|
| 22 | #import "SapphireDirectoryMetaData.h" |
|---|
| 23 | #import "SapphireCollectionDirectory.h" |
|---|
| 24 | #import "SapphireFileMetaData.h" |
|---|
| 25 | #import "SapphireJoinedFile.h" |
|---|
| 26 | #import "SapphireMetaDataSupport.h" |
|---|
| 27 | #import "SapphireMediaPreview.h" |
|---|
| 28 | #import <SapphireCompatClasses/SapphireFrontRowCompat.h> |
|---|
| 29 | #import <QTKit/QTKit.h> |
|---|
| 30 | #import "SapphireTextEntryController.h" |
|---|
| 31 | #import "SapphireErrorDisplayController.h" |
|---|
| 32 | |
|---|
| 33 | @implementation SapphireMarkMenu |
|---|
| 34 | |
|---|
| 35 | typedef enum { |
|---|
| 36 | COMMAND_TOGGLE_WATCHED, |
|---|
| 37 | COMMAND_TOGGLE_FAVORITE, |
|---|
| 38 | COMMAND_MARK_TO_REFETCH_TV, |
|---|
| 39 | COMMAND_MARK_TO_REFETCH_MOVIE, |
|---|
| 40 | COMMAND_MARK_TO_DELETE_METADATA, |
|---|
| 41 | COMMAND_MARK_TO_RESET_IMPORT, |
|---|
| 42 | COMMAND_RENAME, |
|---|
| 43 | COMMAND_CUT_PATH, |
|---|
| 44 | //File Only Commands |
|---|
| 45 | COMMAND_MARK_TO_JOIN, |
|---|
| 46 | COMMAND_MARK_AND_JOIN, |
|---|
| 47 | COMMAND_CLEAR_JOIN_MARK, |
|---|
| 48 | COMMAND_JOIN, |
|---|
| 49 | //Directory Only Commands |
|---|
| 50 | COMMAND_MARK_WATCHED, |
|---|
| 51 | COMMAND_MARK_UNWATCHED, |
|---|
| 52 | COMMAND_MARK_FAVORITE, |
|---|
| 53 | COMMAND_MARK_NOT_FAVORITE, |
|---|
| 54 | COMMAND_TOGGLE_SKIP, |
|---|
| 55 | COMMAND_TOGGLE_COLLECTION, |
|---|
| 56 | COMMAND_PASTE_PATH, |
|---|
| 57 | } MarkCommand; |
|---|
| 58 | |
|---|
| 59 | static NSMutableArray *joinList; |
|---|
| 60 | static NSString *movingPath = nil; |
|---|
| 61 | |
|---|
| 62 | + (void)initialize |
|---|
| 63 | { |
|---|
| 64 | joinList = [[NSMutableArray alloc] init]; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | - (id) initWithScene: (BRRenderScene *) scene metaData: (SapphireMetaData *)meta |
|---|
| 68 | { |
|---|
| 69 | self = [super initWithScene:scene]; |
|---|
| 70 | if(!self) |
|---|
| 71 | return nil; |
|---|
| 72 | |
|---|
| 73 | /*Check to see if it is directory or file*/ |
|---|
| 74 | isDir = [meta conformsToProtocol:@protocol(SapphireDirectory)]; |
|---|
| 75 | metaData = [meta retain]; |
|---|
| 76 | commands = nil; |
|---|
| 77 | /*Create the menu*/ |
|---|
| 78 | if(isDir) |
|---|
| 79 | { |
|---|
| 80 | names = [[NSMutableArray alloc] initWithObjects: |
|---|
| 81 | BRLocalizedString(@"Rename this Directory", @"Rename a directory"), |
|---|
| 82 | BRLocalizedString(@"Mark All as Watched", @"Mark whole directory as watched"), |
|---|
| 83 | BRLocalizedString(@" Unwatched", @"Mark whole directory as unwatched"), |
|---|
| 84 | BRLocalizedString(@" Favorite", @"Mark whole directory as favorite"), |
|---|
| 85 | BRLocalizedString(@" Not Favorite", @"Mark whole directory as not favorite"), |
|---|
| 86 | BRLocalizedString(@" Refetch TV Data", @"Mark whole directory to re-fetch its tv data"), |
|---|
| 87 | BRLocalizedString(@" Refetch Movie Data", @"Mark whole directory to re-fetch its movie data"), |
|---|
| 88 | BRLocalizedString(@" Clear Metadata", @"Mark whole directory to delete the metadata"), |
|---|
| 89 | BRLocalizedString(@" Reset Import Decisions", @"Mark whole directory to reset import decisions"), |
|---|
| 90 | nil]; |
|---|
| 91 | markDescriptions = [[NSMutableArray alloc] initWithObjects: |
|---|
| 92 | BRLocalizedString(@"Edit the name for this directory", @""), |
|---|
| 93 | BRLocalizedString(@"Sapphire will save this directory as watched.", @"Mark directory watched description"), |
|---|
| 94 | BRLocalizedString(@"Sapphire will save this directory as unwatched.", @"Mark directory as unwatched description"), |
|---|
| 95 | BRLocalizedString(@"Sapphire will add this directory as favorite.", @"Mark directory as favorite description"), |
|---|
| 96 | BRLocalizedString(@"Sapphire will remove this directory from favorites.", @"Mark directory as not favorite"), |
|---|
| 97 | BRLocalizedString(@"Tells Sapphire to refetch TV Show metadata for this directory the next time an import is run.", @"Mark directory to refetch tv data description"), |
|---|
| 98 | BRLocalizedString(@"Tells Sapphire to refetch Movie metadata for this directory the next time an import is run.", @"Mark whole directory to re-fetch its movie data"), |
|---|
| 99 | BRLocalizedString(@"Tells Sapphire to remove all metadata for this directory.", @"Mark directory to delete metadata description"), |
|---|
| 100 | BRLocalizedString(@"Tells Sapphire to forget import decisions made on files in this directory.", @"Mark directory to reset import decisions description"), |
|---|
| 101 | nil]; |
|---|
| 102 | commands = [[NSMutableArray alloc] initWithObjects: |
|---|
| 103 | [NSNumber numberWithInt:COMMAND_RENAME], |
|---|
| 104 | [NSNumber numberWithInt:COMMAND_MARK_WATCHED], |
|---|
| 105 | [NSNumber numberWithInt:COMMAND_MARK_UNWATCHED], |
|---|
| 106 | [NSNumber numberWithInt:COMMAND_MARK_FAVORITE], |
|---|
| 107 | [NSNumber numberWithInt:COMMAND_MARK_NOT_FAVORITE], |
|---|
| 108 | [NSNumber numberWithInt:COMMAND_MARK_TO_REFETCH_TV], |
|---|
| 109 | [NSNumber numberWithInt:COMMAND_MARK_TO_REFETCH_MOVIE], |
|---|
| 110 | [NSNumber numberWithInt:COMMAND_MARK_TO_DELETE_METADATA], |
|---|
| 111 | [NSNumber numberWithInt:COMMAND_MARK_TO_RESET_IMPORT], |
|---|
| 112 | nil]; |
|---|
| 113 | id <SapphireDirectory> dirMeta = (id <SapphireDirectory>)meta; |
|---|
| 114 | if([dirMeta isKindOfClass:[SapphireDirectoryMetaData class]]) |
|---|
| 115 | { |
|---|
| 116 | SapphireCollectionDirectory *collection = [(SapphireDirectoryMetaData *)dirMeta collectionDirectory]; |
|---|
| 117 | if([collection isMountValue]) |
|---|
| 118 | { |
|---|
| 119 | [names replaceObjectAtIndex:0 withObject:BRLocalizedString(@"Rename this Collection", @"Rename a collection")]; |
|---|
| 120 | [markDescriptions replaceObjectAtIndex:0 withObject:BRLocalizedString(@"Edit the display name for this collection", @"")]; |
|---|
| 121 | } |
|---|
| 122 | if([collection skipValue]) |
|---|
| 123 | { |
|---|
| 124 | [names addObject:BRLocalizedString(@"Mark Directory For Importing", @"Marks this directory to be no longer be skipped during import")]; |
|---|
| 125 | [markDescriptions addObject:BRLocalizedString(@"Tells Sapphire it's okay to import from this directory.", @"Mark Directory For Importing description")]; |
|---|
| 126 | } |
|---|
| 127 | else |
|---|
| 128 | { |
|---|
| 129 | [names addObject:BRLocalizedString(@"Mark this Directory to Skip Import", @"Marks this directory to be skipped during import")]; |
|---|
| 130 | [markDescriptions addObject:BRLocalizedString(@"Tells Sapphire to skip this directory when importing.", @"Mark this Directory to Skip Import description")]; |
|---|
| 131 | } |
|---|
| 132 | [commands addObject:[NSNumber numberWithInt:COMMAND_TOGGLE_SKIP]]; |
|---|
| 133 | if(![collection isMountValue]) |
|---|
| 134 | { |
|---|
| 135 | if(collection != nil) |
|---|
| 136 | { |
|---|
| 137 | [names addObject:BRLocalizedString(@" to Not be a Collection", @"Marks the directory to no longer be a collection")]; |
|---|
| 138 | [markDescriptions addObject:BRLocalizedString(@"Tells Sapphire to remove this directory from the Collections list.", @"Marks the directory to no longer be a collection description")]; |
|---|
| 139 | } |
|---|
| 140 | else |
|---|
| 141 | { |
|---|
| 142 | [names addObject:BRLocalizedString(@" as a Collection", @"Marks the directory to be a collection")]; |
|---|
| 143 | [markDescriptions addObject:BRLocalizedString(@"Tells Sapphire to add this directory to the Collections list.", @"Marks the directory to be a collection description")]; |
|---|
| 144 | } |
|---|
| 145 | [commands addObject:[NSNumber numberWithInt:COMMAND_TOGGLE_COLLECTION]]; |
|---|
| 146 | } |
|---|
| 147 | if(![collection isMountValue]) |
|---|
| 148 | { |
|---|
| 149 | [names addObject:BRLocalizedString(@"Move Directory", @"Marks this directory to be moved")]; |
|---|
| 150 | [markDescriptions addObject:BRLocalizedString(@"Marks this directory as the object to move. Select destination later.", @"")]; |
|---|
| 151 | [commands addObject:[NSNumber numberWithInt:COMMAND_CUT_PATH]]; |
|---|
| 152 | } |
|---|
| 153 | if(movingPath != nil && ![[dirMeta path] hasPrefix:movingPath]) |
|---|
| 154 | { |
|---|
| 155 | [names addObject:BRLocalizedString(@"Move to Here", @"Move File to within this directory")]; |
|---|
| 156 | [markDescriptions addObject:[NSString stringWithFormat:BRLocalizedString(@"Move %@ to here", @"parameter is last component of path"), [movingPath lastPathComponent]]]; |
|---|
| 157 | [commands addObject:[NSNumber numberWithInt:COMMAND_PASTE_PATH]]; |
|---|
| 158 | } |
|---|
| 159 | } |
|---|
| 160 | } |
|---|
| 161 | else if([meta isKindOfClass:[SapphireFileMetaData class]]) |
|---|
| 162 | { |
|---|
| 163 | SapphireFileMetaData *fileMeta = (SapphireFileMetaData *)metaData; |
|---|
| 164 | NSString *watched = nil; |
|---|
| 165 | NSString *watchedDesc = nil; |
|---|
| 166 | NSString *favorite = nil; |
|---|
| 167 | NSString *favoriteDesc = nil; |
|---|
| 168 | |
|---|
| 169 | if([fileMeta watchedValue]) |
|---|
| 170 | { |
|---|
| 171 | watched = BRLocalizedString(@"Mark as Unwatched", @"Mark file as unwatched"); |
|---|
| 172 | watchedDesc = BRLocalizedString(@"Sapphire will save this file as unwatched.", @"Mark directory watched description"); |
|---|
| 173 | } |
|---|
| 174 | else |
|---|
| 175 | { |
|---|
| 176 | watched = BRLocalizedString(@"Mark as Watched", @"Mark file as watched"); |
|---|
| 177 | watchedDesc = BRLocalizedString(@"Sapphire will save this file as watched.", @"Mark directory watched description"); |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | if([fileMeta favoriteValue]) |
|---|
| 181 | { |
|---|
| 182 | favorite = BRLocalizedString(@" Not Favorite", @"Mark file as a favorite"); |
|---|
| 183 | favoriteDesc = BRLocalizedString(@"Sapphire will remove this file from favorites.", @"Mark directory as not favorite"); |
|---|
| 184 | } |
|---|
| 185 | else |
|---|
| 186 | { |
|---|
| 187 | favorite = BRLocalizedString(@" Favorite", @"Mark file as not a favorite"); |
|---|
| 188 | favoriteDesc = BRLocalizedString(@"Sapphire will add this file as a favorite.", @"Mark directory as favorite description"); |
|---|
| 189 | |
|---|
| 190 | } |
|---|
| 191 | names = [[NSMutableArray alloc] initWithObjects: |
|---|
| 192 | BRLocalizedString(@"Rename this file", @"Rename a file"), |
|---|
| 193 | watched, |
|---|
| 194 | favorite, |
|---|
| 195 | nil]; |
|---|
| 196 | markDescriptions = [[NSMutableArray alloc] initWithObjects: |
|---|
| 197 | BRLocalizedString(@"Move a file to another name", @"Rename file description"), |
|---|
| 198 | watchedDesc, |
|---|
| 199 | favoriteDesc, |
|---|
| 200 | nil]; |
|---|
| 201 | commands = [[NSMutableArray alloc] initWithObjects: |
|---|
| 202 | [NSNumber numberWithInt:COMMAND_RENAME], |
|---|
| 203 | [NSNumber numberWithInt:COMMAND_TOGGLE_WATCHED], |
|---|
| 204 | [NSNumber numberWithInt:COMMAND_TOGGLE_FAVORITE], |
|---|
| 205 | nil]; |
|---|
| 206 | if([fileMeta joinedToFile] != nil) |
|---|
| 207 | { |
|---|
| 208 | [names removeObjectAtIndex:0]; |
|---|
| 209 | [markDescriptions removeObjectAtIndex:0]; |
|---|
| 210 | [commands removeObjectAtIndex:0]; |
|---|
| 211 | } |
|---|
| 212 | int importType = [fileMeta importTypeValue]; |
|---|
| 213 | if(importType | IMPORT_TYPE_TVSHOW_MASK) |
|---|
| 214 | { |
|---|
| 215 | [names addObject:BRLocalizedString(@" Refetch TV Data", @"Mark file to re-fetch its tv data")]; |
|---|
| 216 | [markDescriptions addObject:BRLocalizedString(@"Tells Sapphire to refetch TV Show metadata for this file the next time an import is run.", @"Mark file to refetch tv data description")]; |
|---|
| 217 | |
|---|
| 218 | [commands addObject:[NSNumber numberWithInt:COMMAND_MARK_TO_REFETCH_TV]]; |
|---|
| 219 | } |
|---|
| 220 | if(importType | IMPORT_TYPE_MOVIE_MASK) |
|---|
| 221 | { |
|---|
| 222 | [names addObject:BRLocalizedString(@" Refetch Movie Data", @"Mark file to re-fetch its movie data")]; |
|---|
| 223 | [markDescriptions addObject:BRLocalizedString(@"Tells Sapphire to refetch Movie metadata for this file the next time an import is run.", @"Mark file to refetch movie description")]; |
|---|
| 224 | |
|---|
| 225 | [commands addObject:[NSNumber numberWithInt:COMMAND_MARK_TO_REFETCH_MOVIE]]; |
|---|
| 226 | } |
|---|
| 227 | if([fileMeta fileClass] != FILE_CLASS_UNKNOWN) |
|---|
| 228 | { |
|---|
| 229 | [names addObject:BRLocalizedString(@" Clear Metadata", @"Mark a file to delete the metadata")]; |
|---|
| 230 | [markDescriptions addObject:BRLocalizedString(@"Tells Sapphire to remove all metadata for this file.", @"Mark file to delete metadata description")]; |
|---|
| 231 | |
|---|
| 232 | [commands addObject:[NSNumber numberWithInt:COMMAND_MARK_TO_DELETE_METADATA]]; |
|---|
| 233 | |
|---|
| 234 | [names addObject:BRLocalizedString(@" Reset Import Decisions", @"Mark a file to reset import decisions")]; |
|---|
| 235 | [markDescriptions addObject:BRLocalizedString(@"Tells Sapphire to forget import decisions made on this file.", @"Mark a file to reset import decisions description")]; |
|---|
| 236 | |
|---|
| 237 | [commands addObject:[NSNumber numberWithInt:COMMAND_MARK_TO_RESET_IMPORT]]; |
|---|
| 238 | } |
|---|
| 239 | if(![joinList containsObject:fileMeta]) |
|---|
| 240 | { |
|---|
| 241 | [names addObject:BRLocalizedString(@"Join To Other Files", @"Join To Other Files")]; |
|---|
| 242 | [markDescriptions addObject:BRLocalizedString(@"Tells Sapphire you wish to add this file to a list of files to be joined. The files will be joined in the order they were added to the list.", @"Mark file to be joined description")]; |
|---|
| 243 | [commands addObject:[NSNumber numberWithInt:COMMAND_MARK_TO_JOIN]]; |
|---|
| 244 | [names addObject:BRLocalizedString(@" This File and Complete", @" This File and Complete")]; |
|---|
| 245 | [markDescriptions addObject:BRLocalizedString(@"Tells Sapphire to use this file to complete the joined list.", @"Mark file and join description")]; |
|---|
| 246 | [commands addObject:[NSNumber numberWithInt:COMMAND_MARK_AND_JOIN]]; |
|---|
| 247 | } |
|---|
| 248 | if([joinList count]) |
|---|
| 249 | { |
|---|
| 250 | [names addObject:BRLocalizedString(@" Selected Files", @" Selected Files")]; |
|---|
| 251 | [markDescriptions addObject:BRLocalizedString(@"Tells Sapphire to complete the file join.", @"Join Marked Files description")]; |
|---|
| 252 | |
|---|
| 253 | [commands addObject:[NSNumber numberWithInt:COMMAND_JOIN]]; |
|---|
| 254 | [names addObject:BRLocalizedString(@" Clear", @" Clear")]; |
|---|
| 255 | [markDescriptions addObject:BRLocalizedString(@"Tells Sapphire to clear the file join list.", @"clear file join list description")]; |
|---|
| 256 | |
|---|
| 257 | [commands addObject:[NSNumber numberWithInt:COMMAND_CLEAR_JOIN_MARK]]; |
|---|
| 258 | } |
|---|
| 259 | [names addObject:BRLocalizedString(@"Move File", @"Marks this file to be moved")]; |
|---|
| 260 | [markDescriptions addObject:BRLocalizedString(@"Marks this file as the object to move. Select destination later.", @"")]; |
|---|
| 261 | [commands addObject:[NSNumber numberWithInt:COMMAND_CUT_PATH]]; |
|---|
| 262 | } |
|---|
| 263 | else |
|---|
| 264 | { |
|---|
| 265 | /*Neither, so just return nil*/ |
|---|
| 266 | [self autorelease]; |
|---|
| 267 | return nil; |
|---|
| 268 | } |
|---|
| 269 | [[self list] setDatasource:self]; |
|---|
| 270 | |
|---|
| 271 | return self; |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | - (void) dealloc |
|---|
| 275 | { |
|---|
| 276 | [commands release]; |
|---|
| 277 | [names release]; |
|---|
| 278 | [markDescriptions release]; |
|---|
| 279 | [metaData release]; |
|---|
| 280 | [names release]; |
|---|
| 281 | [super dealloc]; |
|---|
| 282 | } |
|---|
| 283 | |
|---|
| 284 | - (void)doJoin |
|---|
| 285 | { |
|---|
| 286 | if(![joinList count]) |
|---|
| 287 | return; |
|---|
| 288 | |
|---|
| 289 | QTMovie *resultingMovie = [[QTMovie alloc] init]; |
|---|
| 290 | [resultingMovie setAttribute:[NSNumber numberWithBool:YES] forKey:QTMovieEditableAttribute]; |
|---|
| 291 | |
|---|
| 292 | NSString *savePath = [[joinList objectAtIndex:0] path]; |
|---|
| 293 | BOOL hasmovExt = [[savePath pathExtension] isEqualToString:@"mov"]; |
|---|
| 294 | NSString *base = [savePath stringByDeletingPathExtension]; |
|---|
| 295 | if([[base lowercaseString] hasSuffix:@" part 1"]) |
|---|
| 296 | base = [base substringToIndex:[base length] - 7]; |
|---|
| 297 | if(hasmovExt) |
|---|
| 298 | savePath = [[base stringByAppendingString:@" Joined"] stringByAppendingPathExtension:@"mov"]; |
|---|
| 299 | else |
|---|
| 300 | savePath = [base stringByAppendingPathExtension:@"mov"]; |
|---|
| 301 | |
|---|
| 302 | NSManagedObjectContext *moc = [[joinList objectAtIndex:0] managedObjectContext]; |
|---|
| 303 | [SapphireFileMetaData createFileWithPath:savePath inContext:moc]; |
|---|
| 304 | SapphireJoinedFile *joined = [SapphireJoinedFile joinedFileForPath:savePath inContext:moc]; |
|---|
| 305 | int i, count=[joinList count]; |
|---|
| 306 | for(i=0;i<count;i++) |
|---|
| 307 | { |
|---|
| 308 | SapphireFileMetaData *meta = [joinList objectAtIndex:i]; |
|---|
| 309 | NSError *error = nil; |
|---|
| 310 | NSDictionary *openAttr = [NSDictionary dictionaryWithObjectsAndKeys: |
|---|
| 311 | [meta path], QTMovieFileNameAttribute, |
|---|
| 312 | [NSNumber numberWithBool:NO], QTMovieOpenAsyncOKAttribute, |
|---|
| 313 | nil]; |
|---|
| 314 | QTMovie *current = [[QTMovie alloc] initWithAttributes:openAttr error:&error]; |
|---|
| 315 | if(error == nil) |
|---|
| 316 | { |
|---|
| 317 | QTTimeRange range; |
|---|
| 318 | range.time = [current selectionStart]; |
|---|
| 319 | range.duration = [current duration]; |
|---|
| 320 | [current setSelection:range]; |
|---|
| 321 | [resultingMovie appendSelectionFromMovie:current]; |
|---|
| 322 | [meta setJoinedToFile:joined]; |
|---|
| 323 | } |
|---|
| 324 | [current release]; |
|---|
| 325 | } |
|---|
| 326 | |
|---|
| 327 | [resultingMovie writeToFile:savePath withAttributes:[NSDictionary dictionary]]; |
|---|
| 328 | [resultingMovie release]; |
|---|
| 329 | [joinList removeAllObjects]; |
|---|
| 330 | [SapphireMetaDataSupport save:moc]; |
|---|
| 331 | } |
|---|
| 332 | |
|---|
| 333 | - (long) itemCount |
|---|
| 334 | { |
|---|
| 335 | // return the number of items in your menu list here |
|---|
| 336 | return ( [ names count]); |
|---|
| 337 | } |
|---|
| 338 | |
|---|
| 339 | - (id<BRMenuItemLayer>) itemForRow: (long) row |
|---|
| 340 | { |
|---|
| 341 | /* |
|---|
| 342 | // build a BRTextMenuItemLayer or a BRAdornedMenuItemLayer, etc. here |
|---|
| 343 | // return that object, it will be used to display the list item. |
|---|
| 344 | return ( nil ); |
|---|
| 345 | */ |
|---|
| 346 | if( row >= [names count] ) return ( nil ) ; |
|---|
| 347 | |
|---|
| 348 | BRAdornedMenuItemLayer * result = nil ; |
|---|
| 349 | NSString *name = [names objectAtIndex:row]; |
|---|
| 350 | result = [SapphireFrontRowCompat textMenuItemForScene:[self scene] folder:NO]; |
|---|
| 351 | |
|---|
| 352 | // add text |
|---|
| 353 | [SapphireFrontRowCompat setTitle:name forMenu:result]; |
|---|
| 354 | |
|---|
| 355 | return ( result ) ; |
|---|
| 356 | } |
|---|
| 357 | |
|---|
| 358 | - (NSString *) titleForRow: (long) row |
|---|
| 359 | { |
|---|
| 360 | |
|---|
| 361 | if ( row >= [ names count] ) return ( nil ); |
|---|
| 362 | |
|---|
| 363 | NSString *result = [ names objectAtIndex: row] ; |
|---|
| 364 | return ( result ) ; |
|---|
| 365 | } |
|---|
| 366 | |
|---|
| 367 | - (long) rowForTitle: (NSString *) title |
|---|
| 368 | { |
|---|
| 369 | long result = -1; |
|---|
| 370 | long i, count = [self itemCount]; |
|---|
| 371 | for ( i = 0; i < count; i++ ) |
|---|
| 372 | { |
|---|
| 373 | if ( [title isEqualToString: [self titleForRow: i]] ) |
|---|
| 374 | { |
|---|
| 375 | result = i; |
|---|
| 376 | break; |
|---|
| 377 | } |
|---|
| 378 | } |
|---|
| 379 | |
|---|
| 380 | return ( result ); |
|---|
| 381 | } |
|---|
| 382 | |
|---|
| 383 | - (void) itemSelected: (long) row |
|---|
| 384 | { |
|---|
| 385 | // This is called when the user presses play/pause on a list item |
|---|
| 386 | if(row >= [names count]) |
|---|
| 387 | return; |
|---|
| 388 | |
|---|
| 389 | NSManagedObjectContext *moc = [metaData managedObjectContext]; |
|---|
| 390 | BRLayerController *replaceController = nil; |
|---|
| 391 | /*Do action on dir or file*/ |
|---|
| 392 | if(isDir) |
|---|
| 393 | { |
|---|
| 394 | id <SapphireDirectory> dirMeta = (id <SapphireDirectory>)metaData; |
|---|
| 395 | SapphireCollectionDirectory *collection = nil; |
|---|
| 396 | if([dirMeta isKindOfClass:[SapphireDirectoryMetaData class]]) |
|---|
| 397 | collection = [(SapphireDirectoryMetaData *)dirMeta collectionDirectory]; |
|---|
| 398 | NSString *path = [dirMeta path]; |
|---|
| 399 | switch([[commands objectAtIndex:row] intValue]) |
|---|
| 400 | { |
|---|
| 401 | case COMMAND_MARK_WATCHED: |
|---|
| 402 | setSubtreeToWatched(dirMeta, YES); |
|---|
| 403 | break; |
|---|
| 404 | case COMMAND_MARK_UNWATCHED: |
|---|
| 405 | setSubtreeToWatched(dirMeta, NO); |
|---|
| 406 | break; |
|---|
| 407 | case COMMAND_MARK_FAVORITE: |
|---|
| 408 | setSubtreeToFavorite(dirMeta, YES); |
|---|
| 409 | break; |
|---|
| 410 | case COMMAND_MARK_NOT_FAVORITE: |
|---|
| 411 | setSubtreeToFavorite(dirMeta, NO); |
|---|
| 412 | break; |
|---|
| 413 | case COMMAND_MARK_TO_REFETCH_TV: |
|---|
| 414 | setSubtreeToReimportFromMask(dirMeta, IMPORT_TYPE_TVSHOW_MASK); |
|---|
| 415 | break; |
|---|
| 416 | case COMMAND_MARK_TO_REFETCH_MOVIE: |
|---|
| 417 | setSubtreeToReimportFromMask(dirMeta, IMPORT_TYPE_MOVIE_MASK); |
|---|
| 418 | break; |
|---|
| 419 | case COMMAND_MARK_TO_DELETE_METADATA: |
|---|
| 420 | setSubtreeToClearMetaData(dirMeta); |
|---|
| 421 | break; |
|---|
| 422 | case COMMAND_MARK_TO_RESET_IMPORT: |
|---|
| 423 | setSubtreeToResetImportDecisions(dirMeta); |
|---|
| 424 | break; |
|---|
| 425 | case COMMAND_TOGGLE_SKIP: |
|---|
| 426 | if(collection == nil) |
|---|
| 427 | collection = [SapphireCollectionDirectory collectionAtPath:path inContext:moc]; |
|---|
| 428 | [collection setSkipValue:![collection skipValue]]; |
|---|
| 429 | break; |
|---|
| 430 | case COMMAND_TOGGLE_COLLECTION: |
|---|
| 431 | if(collection == nil) |
|---|
| 432 | [SapphireCollectionDirectory collectionAtPath:path inContext:moc]; |
|---|
| 433 | else |
|---|
| 434 | [moc deleteObject:collection]; |
|---|
| 435 | break; |
|---|
| 436 | case COMMAND_RENAME: |
|---|
| 437 | if([dirMeta isKindOfClass:[SapphireDirectoryMetaData class]]) |
|---|
| 438 | { |
|---|
| 439 | NSString *title = [NSString stringWithFormat:BRLocalizedString(@"Rename %@", @"Rename a collection, argument is path"), [dirMeta path]]; |
|---|
| 440 | NSInvocation *invoke; |
|---|
| 441 | NSString *oldName; |
|---|
| 442 | if(collection == nil) |
|---|
| 443 | { |
|---|
| 444 | oldName = [[dirMeta path] lastPathComponent]; |
|---|
| 445 | invoke = [NSInvocation invocationWithMethodSignature:[(SapphireDirectoryMetaData *)dirMeta methodSignatureForSelector:@selector(rename:)]]; |
|---|
| 446 | [invoke setTarget:dirMeta]; |
|---|
| 447 | } |
|---|
| 448 | else |
|---|
| 449 | { |
|---|
| 450 | oldName = [collection name]; |
|---|
| 451 | if([oldName length] == 0) |
|---|
| 452 | oldName = title; |
|---|
| 453 | |
|---|
| 454 | invoke = [NSInvocation invocationWithMethodSignature:[collection methodSignatureForSelector:@selector(rename:)]]; |
|---|
| 455 | [invoke setTarget:collection]; |
|---|
| 456 | } |
|---|
| 457 | [invoke setSelector:@selector(rename:)]; |
|---|
| 458 | SapphireTextEntryController *rename = [[SapphireTextEntryController alloc] initWithScene:[self scene] title:title defaultText:oldName completionInvocation:invoke]; |
|---|
| 459 | replaceController = [rename autorelease]; |
|---|
| 460 | } |
|---|
| 461 | break; |
|---|
| 462 | case COMMAND_CUT_PATH: |
|---|
| 463 | [movingPath release]; |
|---|
| 464 | movingPath = [[dirMeta path] retain]; |
|---|
| 465 | break; |
|---|
| 466 | case COMMAND_PASTE_PATH: |
|---|
| 467 | { |
|---|
| 468 | SapphireMetaData *meta = [SapphireMetaData metaDataWithPath:movingPath inContext:moc]; |
|---|
| 469 | NSString *errorString = nil; |
|---|
| 470 | if([meta isKindOfClass:[SapphireDirectoryMetaData class]]) |
|---|
| 471 | { |
|---|
| 472 | SapphireDirectoryMetaData *dir = (SapphireDirectoryMetaData *)meta; |
|---|
| 473 | errorString = [dir moveToDir:(SapphireDirectoryMetaData *)dirMeta]; |
|---|
| 474 | } |
|---|
| 475 | else if([meta isKindOfClass:[SapphireFileMetaData class]]) |
|---|
| 476 | { |
|---|
| 477 | SapphireFileMetaData *file = (SapphireFileMetaData *)meta; |
|---|
| 478 | errorString = [file moveToDir:(SapphireDirectoryMetaData *)dirMeta]; |
|---|
| 479 | } |
|---|
| 480 | else |
|---|
| 481 | errorString = [NSString stringWithFormat:BRLocalizedString(@"%@ Seems to be missing", @"Could not find file; parameter is moving file"), [movingPath lastPathComponent]]; |
|---|
| 482 | if(errorString != nil) |
|---|
| 483 | { |
|---|
| 484 | SapphireErrorDisplayController *error = [[SapphireErrorDisplayController alloc] initWithScene:[self scene] error:BRLocalizedString(@"Moving Error", @"") longError:errorString]; |
|---|
| 485 | replaceController = [error autorelease]; |
|---|
| 486 | } |
|---|
| 487 | else |
|---|
| 488 | { |
|---|
| 489 | [movingPath release]; |
|---|
| 490 | movingPath = nil; |
|---|
| 491 | } |
|---|
| 492 | } |
|---|
| 493 | break; |
|---|
| 494 | } |
|---|
| 495 | } |
|---|
| 496 | else |
|---|
| 497 | { |
|---|
| 498 | SapphireFileMetaData *fileMeta = (SapphireFileMetaData *)metaData; |
|---|
| 499 | switch([[commands objectAtIndex:row] intValue]) |
|---|
| 500 | { |
|---|
| 501 | case COMMAND_TOGGLE_WATCHED: |
|---|
| 502 | [fileMeta setWatchedValue:![fileMeta watchedValue]]; |
|---|
| 503 | [fileMeta setResumeTime:0]; |
|---|
| 504 | break; |
|---|
| 505 | case COMMAND_TOGGLE_FAVORITE: |
|---|
| 506 | [fileMeta setFavoriteValue:![fileMeta favoriteValue]]; |
|---|
| 507 | break; |
|---|
| 508 | case COMMAND_MARK_TO_REFETCH_TV: |
|---|
| 509 | [fileMeta setToReimportFromMask:IMPORT_TYPE_TVSHOW_MASK]; |
|---|
| 510 | break; |
|---|
| 511 | case COMMAND_MARK_TO_REFETCH_MOVIE: |
|---|
| 512 | [fileMeta setToReimportFromMask:IMPORT_TYPE_MOVIE_MASK]; |
|---|
| 513 | break; |
|---|
| 514 | case COMMAND_MARK_TO_DELETE_METADATA: |
|---|
| 515 | [fileMeta clearMetaData]; |
|---|
| 516 | break; |
|---|
| 517 | case COMMAND_MARK_TO_RESET_IMPORT: |
|---|
| 518 | [fileMeta setToResetImportDecisions]; |
|---|
| 519 | break; |
|---|
| 520 | case COMMAND_MARK_TO_JOIN: |
|---|
| 521 | [joinList addObject:fileMeta]; |
|---|
| 522 | break; |
|---|
| 523 | case COMMAND_CLEAR_JOIN_MARK: |
|---|
| 524 | [joinList removeAllObjects]; |
|---|
| 525 | break; |
|---|
| 526 | case COMMAND_MARK_AND_JOIN: |
|---|
| 527 | [joinList addObject:fileMeta]; |
|---|
| 528 | case COMMAND_JOIN: |
|---|
| 529 | [self doJoin]; |
|---|
| 530 | break; |
|---|
| 531 | case COMMAND_RENAME: |
|---|
| 532 | { |
|---|
| 533 | NSString *title = [NSString stringWithFormat:BRLocalizedString(@"Rename %@", @"Rename a file, argument is path"), [fileMeta path]]; |
|---|
| 534 | NSString *oldName = [[fileMeta path] lastPathComponent]; |
|---|
| 535 | |
|---|
| 536 | NSInvocation *invoke = [NSInvocation invocationWithMethodSignature:[fileMeta methodSignatureForSelector:@selector(rename:)]]; |
|---|
| 537 | [invoke setSelector:@selector(rename:)]; |
|---|
| 538 | [invoke setTarget:fileMeta]; |
|---|
| 539 | SapphireTextEntryController *rename = [[SapphireTextEntryController alloc] initWithScene:[self scene] title:title defaultText:oldName completionInvocation:invoke]; |
|---|
| 540 | replaceController = [rename autorelease]; |
|---|
| 541 | } |
|---|
| 542 | break; |
|---|
| 543 | case COMMAND_CUT_PATH: |
|---|
| 544 | [movingPath release]; |
|---|
| 545 | movingPath = [[fileMeta path] retain]; |
|---|
| 546 | break; |
|---|
| 547 | } |
|---|
| 548 | } |
|---|
| 549 | /*Save and exit*/ |
|---|
| 550 | [SapphireMetaDataSupport save:moc]; |
|---|
| 551 | if(replaceController != nil) |
|---|
| 552 | [[self stack] swapController:replaceController]; |
|---|
| 553 | else |
|---|
| 554 | [[self stack] popController]; |
|---|
| 555 | } |
|---|
| 556 | |
|---|
| 557 | - (id<BRMediaPreviewController>) previewControlForItem:(long)item |
|---|
| 558 | { |
|---|
| 559 | return [self previewControllerForItem:item]; |
|---|
| 560 | } |
|---|
| 561 | |
|---|
| 562 | - (id<BRMediaPreviewController>) previewControllerForItem: (long) item |
|---|
| 563 | { |
|---|
| 564 | // If subclassing BRMediaMenuController, this function is called when the selection cursor |
|---|
| 565 | // passes over an item. |
|---|
| 566 | if(item >= [names count]) |
|---|
| 567 | return nil; |
|---|
| 568 | else |
|---|
| 569 | { |
|---|
| 570 | /* Get setting name & kill cushion */ |
|---|
| 571 | NSString *markName =[NSString stringWithFormat:@"%@ for \"%@\"",[names objectAtIndex:item],(NSString *)[self listTitle]]; |
|---|
| 572 | NSString *markDescription=[markDescriptions objectAtIndex:item]; |
|---|
| 573 | /* Construct a gerneric metadata asset for display */ |
|---|
| 574 | NSMutableDictionary *markMeta=[[NSMutableDictionary alloc] init]; |
|---|
| 575 | [markMeta setObject:markName forKey:META_TITLE_KEY]; |
|---|
| 576 | [markMeta setObject:[NSNumber numberWithInt:FILE_CLASS_UTILITY] forKey:FILE_CLASS_KEY]; |
|---|
| 577 | [markMeta setObject:markDescription forKey:META_DESCRIPTION_KEY]; |
|---|
| 578 | SapphireMediaPreview *preview = [[SapphireMediaPreview alloc] initWithScene:[self scene]]; |
|---|
| 579 | [preview setUtilityData:markMeta]; |
|---|
| 580 | [markMeta release]; |
|---|
| 581 | [preview setShowsMetadataImmediately:YES]; |
|---|
| 582 | /*And go*/ |
|---|
| 583 | return [preview autorelease]; |
|---|
| 584 | } |
|---|
| 585 | return ( nil ); |
|---|
| 586 | } |
|---|
| 587 | |
|---|
| 588 | @end |
|---|