| 1 | // |
|---|
| 2 | // SapphireMovieChooser.m |
|---|
| 3 | // Sapphire |
|---|
| 4 | // |
|---|
| 5 | // Created by Patrick Merrill on 7/27/07. |
|---|
| 6 | // Copyright 2007 __www.nanopi.net__. All rights reserved. |
|---|
| 7 | // |
|---|
| 8 | |
|---|
| 9 | #import "SapphireMovieChooser.h" |
|---|
| 10 | #import "SapphireFrontRowCompat.h" |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | @implementation SapphireMovieChooser |
|---|
| 14 | |
|---|
| 15 | /*! |
|---|
| 16 | * @brief Creates a new movie chooser |
|---|
| 17 | * |
|---|
| 18 | * @param scene The scene |
|---|
| 19 | * @return The chooser |
|---|
| 20 | */ |
|---|
| 21 | - (id) initWithScene: (BRRenderScene *) scene |
|---|
| 22 | { |
|---|
| 23 | self = [super initWithScene:scene]; |
|---|
| 24 | if(!self) |
|---|
| 25 | return nil; |
|---|
| 26 | selection = -1; |
|---|
| 27 | |
|---|
| 28 | /* Set a control to display the fileName */ |
|---|
| 29 | fileNameText = [SapphireFrontRowCompat newTextControlWithScene:scene]; |
|---|
| 30 | [SapphireFrontRowCompat setText:@"File:" withAtrributes:[[BRThemeInfo sharedTheme] paragraphTextAttributes] forControl:fileNameText]; |
|---|
| 31 | NSRect frame = [SapphireFrontRowCompat frameOfController:self]; |
|---|
| 32 | // frame.size.height = frame.size.height / 16.0f; |
|---|
| 33 | // frame.size.width = frame.size.width * 2.0f / 3.0f; |
|---|
| 34 | frame.origin.y = frame.size.height / 1.25f; |
|---|
| 35 | frame.origin.x = (frame.size.width / 4.0f) ; |
|---|
| 36 | [fileNameText setFrame: frame]; |
|---|
| 37 | |
|---|
| 38 | [self addControl: fileNameText]; |
|---|
| 39 | [[self list] setDatasource:self]; |
|---|
| 40 | |
|---|
| 41 | return self; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | - (void)dealloc |
|---|
| 45 | { |
|---|
| 46 | [movies release]; |
|---|
| 47 | [fileName release]; |
|---|
| 48 | [super dealloc]; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | /*! |
|---|
| 52 | * @brief The list of movies to choose from |
|---|
| 53 | * |
|---|
| 54 | * @return The list of movies to choose from |
|---|
| 55 | */ |
|---|
| 56 | - (NSArray *)movies |
|---|
| 57 | { |
|---|
| 58 | return movies; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | /*! |
|---|
| 62 | * @brief Sets the movies to choose from |
|---|
| 63 | * |
|---|
| 64 | * @param movieList The list of movies to choose from |
|---|
| 65 | */ |
|---|
| 66 | - (void)setMovies:(NSArray *)movieList |
|---|
| 67 | { |
|---|
| 68 | movies = [movieList retain]; |
|---|
| 69 | [[self list] reload]; |
|---|
| 70 | [SapphireFrontRowCompat addDividerAtIndex:1 toList:[self list]]; |
|---|
| 71 | [SapphireFrontRowCompat renderScene:[self scene]]; |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | /*! |
|---|
| 75 | * @brief Sets the filename to display |
|---|
| 76 | * |
|---|
| 77 | * @param choosingForFileName The filename being choosen for |
|---|
| 78 | */ |
|---|
| 79 | - (void)setFileName:(NSString*)choosingForFileName |
|---|
| 80 | { |
|---|
| 81 | fileName=[choosingForFileName retain] ; |
|---|
| 82 | [SapphireFrontRowCompat setText:choosingForFileName withAtrributes:[[BRThemeInfo sharedTheme] paragraphTextAttributes] forControl:fileNameText]; |
|---|
| 83 | NSRect master = [SapphireFrontRowCompat frameOfController:self]; |
|---|
| 84 | [fileNameText setMaximumSize:NSMakeSize(master.size.width * 2.0f/3.0f, master.size.height * 0.4f)]; |
|---|
| 85 | NSSize txtSize = [fileNameText renderedSize]; |
|---|
| 86 | NSRect frame; |
|---|
| 87 | frame.origin.x = (master.size.width - txtSize.width) * 0.5f; |
|---|
| 88 | frame.origin.y = (master.size.height * 0.44f - txtSize.height) + master.size.height * 0.3f/0.8f + master.origin.y; |
|---|
| 89 | frame.size = txtSize; |
|---|
| 90 | [fileNameText setFrame:frame]; |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | /*! |
|---|
| 94 | * @brief The file name we searched for |
|---|
| 95 | * |
|---|
| 96 | * @return The file name we searched for |
|---|
| 97 | */ |
|---|
| 98 | - (NSString *)fileName |
|---|
| 99 | { |
|---|
| 100 | return fileName; |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | - (void)wasPushed |
|---|
| 104 | { |
|---|
| 105 | [super wasPushed]; |
|---|
| 106 | [(BRListControl *)[self list] setSelection:1]; |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | /*! |
|---|
| 110 | * @brief The item the user selected. Special values are in the header file |
|---|
| 111 | * |
|---|
| 112 | * @return The user's selection |
|---|
| 113 | */ |
|---|
| 114 | - (int)selection |
|---|
| 115 | { |
|---|
| 116 | return selection - 1; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | - (long) itemCount |
|---|
| 120 | { |
|---|
| 121 | return [movies count] + 1; |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | - (id<BRMenuItemLayer>) itemForRow: (long) row |
|---|
| 125 | { |
|---|
| 126 | BRAdornedMenuItemLayer *result = [SapphireFrontRowCompat textMenuItemForScene:[self scene] folder:NO]; |
|---|
| 127 | |
|---|
| 128 | if(row == 0)/*Put in the special "this is not a movie"*/ |
|---|
| 129 | [SapphireFrontRowCompat setTitle:BRLocalizedString(@"<This is NOT a Movie>", @"Mark a file that is not a movie in the movie chooser") forMenu:result]; |
|---|
| 130 | else |
|---|
| 131 | /*Put in the movie results*/ |
|---|
| 132 | [SapphireFrontRowCompat setTitle:[[movies objectAtIndex:row-1] objectForKey:@"name"] forMenu:result]; |
|---|
| 133 | |
|---|
| 134 | return result; |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | - (NSString *) titleForRow: (long) row |
|---|
| 138 | { |
|---|
| 139 | if(row > [movies count]) |
|---|
| 140 | return nil; |
|---|
| 141 | |
|---|
| 142 | if(row == 0)/*Put in the special "this is not a movie"*/ |
|---|
| 143 | return BRLocalizedString(@"<This is NOT a Movie>", @"Mark a file that is not a movie in the movie chooser"); |
|---|
| 144 | else |
|---|
| 145 | /*Put in the movie*/ |
|---|
| 146 | return [[movies objectAtIndex:row-1] objectForKey:@"name"]; |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | - (void) itemSelected: (long) row |
|---|
| 151 | { |
|---|
| 152 | /*User made selection, let's exit*/ |
|---|
| 153 | selection = row; |
|---|
| 154 | [[self stack] popController]; |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | @end |
|---|