| 1 | /* |
|---|
| 2 | * SapphireMovieChooser.m |
|---|
| 3 | * Sapphire |
|---|
| 4 | * |
|---|
| 5 | * Created by Patrick Merrill on Jul. 27, 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 "SapphireMovieChooser.h" |
|---|
| 22 | #import <SapphireCompatClasses/SapphireFrontRowCompat.h> |
|---|
| 23 | #import "SapphireTheme.h" |
|---|
| 24 | |
|---|
| 25 | @interface SapphireMovieChooser (private) |
|---|
| 26 | - (void)doMyLayout; |
|---|
| 27 | @end |
|---|
| 28 | |
|---|
| 29 | @implementation SapphireMovieChooser |
|---|
| 30 | |
|---|
| 31 | - (id) initWithScene: (BRRenderScene *) scene |
|---|
| 32 | { |
|---|
| 33 | self = [super initWithScene:scene]; |
|---|
| 34 | if(!self) |
|---|
| 35 | return nil; |
|---|
| 36 | selection = -1; |
|---|
| 37 | |
|---|
| 38 | /* Set a control to display the fileName */ |
|---|
| 39 | fileNameText = [SapphireFrontRowCompat newTextControlWithScene:scene]; |
|---|
| 40 | [SapphireFrontRowCompat setText:@"File:" withAtrributes:[[BRThemeInfo sharedTheme] paragraphTextAttributes] forControl:fileNameText]; |
|---|
| 41 | |
|---|
| 42 | [self doMyLayout]; |
|---|
| 43 | [self addControl: fileNameText]; |
|---|
| 44 | [[self list] setDatasource:self]; |
|---|
| 45 | |
|---|
| 46 | [SapphireLayoutManager setCustomLayoutOnControl:self]; |
|---|
| 47 | |
|---|
| 48 | return self; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | - (void)dealloc |
|---|
| 52 | { |
|---|
| 53 | [movies release]; |
|---|
| 54 | [fileName release]; |
|---|
| 55 | [super dealloc]; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | - (void)doMyLayout |
|---|
| 59 | { |
|---|
| 60 | NSRect master = [SapphireFrontRowCompat frameOfController:self]; |
|---|
| 61 | NSSize txtSize = [SapphireFrontRowCompat textControl:fileNameText renderedSizeWithMaxSize:NSMakeSize(master.size.width * 2.0f/3.0f, master.size.height * 0.4f)]; |
|---|
| 62 | NSRect frame; |
|---|
| 63 | frame.origin.x = (master.size.width - txtSize.width) * 0.5f; |
|---|
| 64 | frame.origin.y = (master.size.height * 0.44f - txtSize.height) + master.size.height * 0.3f/0.8f + master.origin.y; |
|---|
| 65 | frame.size = txtSize; |
|---|
| 66 | [fileNameText setFrame:frame]; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | - (NSArray *)movies |
|---|
| 70 | { |
|---|
| 71 | return movies; |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | - (void)setMovies:(NSArray *)movieList |
|---|
| 75 | { |
|---|
| 76 | movies = [movieList retain]; |
|---|
| 77 | [[self list] reload]; |
|---|
| 78 | [SapphireFrontRowCompat addDividerAtIndex:1 toList:[self list]]; |
|---|
| 79 | [SapphireFrontRowCompat renderScene:[self scene]]; |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | - (void)setFileName:(NSString*)choosingForFileName |
|---|
| 83 | { |
|---|
| 84 | fileName=[choosingForFileName retain] ; |
|---|
| 85 | [SapphireFrontRowCompat setText:choosingForFileName withAtrributes:[[BRThemeInfo sharedTheme] paragraphTextAttributes] forControl:fileNameText]; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | - (NSString *)fileName |
|---|
| 89 | { |
|---|
| 90 | return fileName; |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | - (void)wasPushed |
|---|
| 94 | { |
|---|
| 95 | [(BRListControl *)[self list] setSelection:1]; |
|---|
| 96 | [self doMyLayout]; |
|---|
| 97 | [super wasPushed]; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | - (int)selection |
|---|
| 101 | { |
|---|
| 102 | return selection - 1; |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | - (long) itemCount |
|---|
| 106 | { |
|---|
| 107 | return [movies count] + 1; |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | - (id<BRMenuItemLayer>) itemForRow: (long) row |
|---|
| 111 | { |
|---|
| 112 | BRAdornedMenuItemLayer *result = [SapphireFrontRowCompat textMenuItemForScene:[self scene] folder:NO]; |
|---|
| 113 | SapphireTheme *theme = [SapphireTheme sharedTheme]; |
|---|
| 114 | |
|---|
| 115 | if(row == 0)/*Put in the special "this is not a movie"*/ |
|---|
| 116 | [SapphireFrontRowCompat setTitle:BRLocalizedString(@"<This is Not a Movie>", @"Mark a file that is not a movie in the movie chooser") forMenu:result]; |
|---|
| 117 | else |
|---|
| 118 | { |
|---|
| 119 | /*Put in the movie results*/ |
|---|
| 120 | [SapphireFrontRowCompat setTitle:[NSString stringWithFormat:@" %@",[[movies objectAtIndex:row-1] objectForKey:@"name"]] forMenu:result]; |
|---|
| 121 | [SapphireFrontRowCompat setRightIcon:[theme gem:IMDB_GEM_KEY] forMenu:result]; |
|---|
| 122 | } |
|---|
| 123 | return result; |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | - (NSString *) titleForRow: (long) row |
|---|
| 127 | { |
|---|
| 128 | if(row > [movies count]) |
|---|
| 129 | return nil; |
|---|
| 130 | |
|---|
| 131 | if(row == 0)/*Put in the special "this is not a movie"*/ |
|---|
| 132 | return BRLocalizedString(@"<This is NOT a Movie>", @"Mark a file that is not a movie in the movie chooser"); |
|---|
| 133 | else |
|---|
| 134 | /*Put in the movie*/ |
|---|
| 135 | return [[movies objectAtIndex:row-1] objectForKey:@"name"]; |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | - (void) itemSelected: (long) row |
|---|
| 140 | { |
|---|
| 141 | /*User made selection, let's exit*/ |
|---|
| 142 | selection = row; |
|---|
| 143 | [[self stack] popController]; |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | @end |
|---|