| 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 | /*! |
|---|
| 45 | * @brief Override the layout |
|---|
| 46 | * |
|---|
| 47 | */ |
|---|
| 48 | - (void)_doLayout |
|---|
| 49 | { |
|---|
| 50 | //Shrink the list frame to make room for displaying the filename |
|---|
| 51 | [super _doLayout]; |
|---|
| 52 | NSRect master = [SapphireFrontRowCompat frameOfController:self]; |
|---|
| 53 | NSRect listFrame = [[_listControl layer] frame]; |
|---|
| 54 | listFrame.size.height -= 2.5f*listFrame.origin.y; |
|---|
| 55 | listFrame.size.width*=2.0f; |
|---|
| 56 | listFrame.origin.x = (master.size.width - listFrame.size.width) * 0.5f; |
|---|
| 57 | listFrame.origin.y *= 2.0f; |
|---|
| 58 | [[_listControl layer] setFrame:listFrame]; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | - (void)dealloc |
|---|
| 62 | { |
|---|
| 63 | [movies release]; |
|---|
| 64 | [fileName release]; |
|---|
| 65 | [super dealloc]; |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | /*! |
|---|
| 69 | * @brief The list of movies to choose from |
|---|
| 70 | * |
|---|
| 71 | * @return The list of movies to choose from |
|---|
| 72 | */ |
|---|
| 73 | - (NSArray *)movies |
|---|
| 74 | { |
|---|
| 75 | return movies; |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | /*! |
|---|
| 79 | * @brief Sets the movies to choose from |
|---|
| 80 | * |
|---|
| 81 | * @param movieList The list of movies to choose from |
|---|
| 82 | */ |
|---|
| 83 | - (void)setMovies:(NSArray *)movieList |
|---|
| 84 | { |
|---|
| 85 | movies = [movieList retain]; |
|---|
| 86 | [[self list] reload]; |
|---|
| 87 | [SapphireFrontRowCompat addDividerAtIndex:3 toList:[self list]]; |
|---|
| 88 | [SapphireFrontRowCompat renderScene:[self scene]]; |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | /*! |
|---|
| 92 | * @brief Sets the filename to display |
|---|
| 93 | * |
|---|
| 94 | * @param choosingForFileName The filename being choosen for |
|---|
| 95 | */ |
|---|
| 96 | - (void)setFileName:(NSString*)choosingForFileName |
|---|
| 97 | { |
|---|
| 98 | fileName=[choosingForFileName retain] ; |
|---|
| 99 | [SapphireFrontRowCompat setText:choosingForFileName withAtrributes:[[BRThemeInfo sharedTheme] paragraphTextAttributes] forControl:fileNameText]; |
|---|
| 100 | NSRect master = [SapphireFrontRowCompat frameOfController:self]; |
|---|
| 101 | [fileNameText setMaximumSize:NSMakeSize(master.size.width * 2.0f/3.0f, master.size.height * 0.4f)]; |
|---|
| 102 | NSSize txtSize = [fileNameText renderedSize]; |
|---|
| 103 | NSRect frame; |
|---|
| 104 | frame.origin.x = (master.size.width - txtSize.width) * 0.5f; |
|---|
| 105 | frame.origin.y = (master.size.height * 0.44f - txtSize.height) + master.size.height * 0.3f/0.8f + master.origin.y; |
|---|
| 106 | frame.size = txtSize; |
|---|
| 107 | [fileNameText setFrame:frame]; |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | /*! |
|---|
| 111 | * @brief The file name we searched for |
|---|
| 112 | * |
|---|
| 113 | * @return The file name we searched for |
|---|
| 114 | */ |
|---|
| 115 | - (NSString *)fileName |
|---|
| 116 | { |
|---|
| 117 | return fileName; |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | /*! |
|---|
| 121 | * @brief The item the user selected. Special values are in the header file |
|---|
| 122 | * |
|---|
| 123 | * @return The user's selection |
|---|
| 124 | */ |
|---|
| 125 | - (int)selection |
|---|
| 126 | { |
|---|
| 127 | return selection - 3; |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | - (long) itemCount |
|---|
| 131 | { |
|---|
| 132 | return [movies count] + 3; |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | - (id<BRMenuItemLayer>) itemForRow: (long) row |
|---|
| 136 | { |
|---|
| 137 | BRAdornedMenuItemLayer *result = [SapphireFrontRowCompat textMenuItemForScene:[self scene] folder:NO]; |
|---|
| 138 | |
|---|
| 139 | if(row == 0)/*Put in the special "this is not a movie"*/ |
|---|
| 140 | [SapphireFrontRowCompat setTitle:BRLocalizedString(@"<This is NOT a Movie>", @"Mark a file that is not a movie in the movie chooser") forMenu:result]; |
|---|
| 141 | else if(row==1)/*Put in the special "this is something else"*/ |
|---|
| 142 | [SapphireFrontRowCompat setTitle:BRLocalizedString(@"<This is something else>", @"Mark a file that something else in the movie chooser") forMenu:result]; |
|---|
| 143 | else if(row==2)/*Put in the special "this is a tv show"*/ |
|---|
| 144 | [SapphireFrontRowCompat setTitle:BRLocalizedString(@"<This is a TV Show>", @"Mark a file that is tv show in the movie chooser") forMenu:result]; |
|---|
| 145 | else |
|---|
| 146 | /*Put in the movie results*/ |
|---|
| 147 | [SapphireFrontRowCompat setTitle:[[movies objectAtIndex:row-3] objectForKey:@"name"] forMenu:result]; |
|---|
| 148 | |
|---|
| 149 | return result; |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | - (NSString *) titleForRow: (long) row |
|---|
| 153 | { |
|---|
| 154 | if(row > [movies count]) |
|---|
| 155 | return nil; |
|---|
| 156 | |
|---|
| 157 | if(row == 0)/*Put in the special "this is not a movie"*/ |
|---|
| 158 | return BRLocalizedString(@"<This is NOT a Movie>", @"Mark a file that is not a movie in the movie chooser"); |
|---|
| 159 | else if(row==1)/*Put in the special "this is something else"*/ |
|---|
| 160 | return BRLocalizedString(@"<This is something else>", @"Mark a file that is something else in the movie chooser"); |
|---|
| 161 | else if(row==2)/*Put in the special "this is a tv show"*/ |
|---|
| 162 | return BRLocalizedString(@"<This is a TV Show>", @"Mark a file that is a tv show in the movie chooser"); |
|---|
| 163 | else |
|---|
| 164 | /*Put in the movie*/ |
|---|
| 165 | return [[movies objectAtIndex:row-3] objectForKey:@"name"]; |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | |
|---|
| 169 | - (void) itemSelected: (long) row |
|---|
| 170 | { |
|---|
| 171 | /*User made selection, let's exit*/ |
|---|
| 172 | selection = row; |
|---|
| 173 | [[self stack] popController]; |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | @end |
|---|