| 1 | // |
|---|
| 2 | // SapphireShowChooser.m |
|---|
| 3 | // Sapphire |
|---|
| 4 | // |
|---|
| 5 | // Created by Graham Booker on 7/1/07. |
|---|
| 6 | // Copyright 2007 www.nanopi.net. All rights reserved. |
|---|
| 7 | // |
|---|
| 8 | |
|---|
| 9 | #import "SapphireShowChooser.h" |
|---|
| 10 | #import "SapphireFrontRowCompat.h" |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | @implementation SapphireShowChooser |
|---|
| 14 | |
|---|
| 15 | /*! |
|---|
| 16 | * @brief Creates a new show 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 | |
|---|
| 27 | selection = -1; |
|---|
| 28 | |
|---|
| 29 | /* Set a control to display the fileName */ |
|---|
| 30 | fileName = [SapphireFrontRowCompat newTextControlWithScene:scene]; |
|---|
| 31 | [SapphireFrontRowCompat setText:@"File:" withAtrributes:[[BRThemeInfo sharedTheme] paragraphTextAttributes] forControl:fileName]; |
|---|
| 32 | NSRect frame = [SapphireFrontRowCompat frameOfController:self]; |
|---|
| 33 | // frame.size.height = frame.size.height / 16.0f; |
|---|
| 34 | // frame.size.width = frame.size.width * 2.0f / 3.0f; |
|---|
| 35 | frame.origin.y = frame.size.height / 4.0f; |
|---|
| 36 | frame.origin.x = frame.size.width * (2.0f / 9.0f); |
|---|
| 37 | [fileName setFrame: frame]; |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | [self addControl: fileName]; |
|---|
| 41 | [[self list] setDatasource:self]; |
|---|
| 42 | |
|---|
| 43 | return self; |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | - (void)dealloc |
|---|
| 47 | { |
|---|
| 48 | [shows release]; |
|---|
| 49 | [searchStr release]; |
|---|
| 50 | [super dealloc]; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | /*! |
|---|
| 54 | * @brief Sets the shows to choose from |
|---|
| 55 | * |
|---|
| 56 | * @param showList The list of shows to choose from |
|---|
| 57 | */ |
|---|
| 58 | - (void)setShows:(NSArray *)showList |
|---|
| 59 | { |
|---|
| 60 | shows = [showList retain]; |
|---|
| 61 | [[self list] reload]; |
|---|
| 62 | [SapphireFrontRowCompat addDividerAtIndex:1 toList:[self list]]; |
|---|
| 63 | [SapphireFrontRowCompat renderScene:[self scene]]; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | /*! |
|---|
| 67 | * @brief The list of shows to choose from |
|---|
| 68 | * |
|---|
| 69 | * @return The list of shows to choose from |
|---|
| 70 | */ |
|---|
| 71 | - (NSArray *)shows |
|---|
| 72 | { |
|---|
| 73 | return shows; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | /*! |
|---|
| 77 | * @brief Sets the string we searched for |
|---|
| 78 | * |
|---|
| 79 | * @param search The string we searched for |
|---|
| 80 | */ |
|---|
| 81 | - (void)setSearchStr:(NSString *)search |
|---|
| 82 | { |
|---|
| 83 | searchStr = [search retain]; |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | /*! |
|---|
| 87 | * @brief Sets the filename to display |
|---|
| 88 | * |
|---|
| 89 | * @param choosingForFileName The filename being choosen for |
|---|
| 90 | */ |
|---|
| 91 | - (void)setFileName:(NSString*)choosingForFileName |
|---|
| 92 | { |
|---|
| 93 | [SapphireFrontRowCompat setText:choosingForFileName withAtrributes:[[BRThemeInfo sharedTheme] paragraphTextAttributes] forControl:fileName]; |
|---|
| 94 | NSRect master = [SapphireFrontRowCompat frameOfController:self]; |
|---|
| 95 | [fileName setMaximumSize:NSMakeSize(master.size.width * 2.0f/3.0f, master.size.height * 0.4f)]; |
|---|
| 96 | NSSize txtSize = [fileName renderedSize]; |
|---|
| 97 | NSRect frame; |
|---|
| 98 | frame.origin.x = (master.size.width - txtSize.width) * 0.5f; |
|---|
| 99 | frame.origin.y = (master.size.height * 0.44f - txtSize.height) + master.size.height * 0.3f/0.8f + master.origin.y; |
|---|
| 100 | frame.size = txtSize; |
|---|
| 101 | [fileName setFrame:frame]; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | /*! |
|---|
| 105 | * @brief The string we searched for |
|---|
| 106 | * |
|---|
| 107 | * @return The string we searched for |
|---|
| 108 | */ |
|---|
| 109 | - (NSString *)searchStr |
|---|
| 110 | { |
|---|
| 111 | return searchStr; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | - (void)wasPushed |
|---|
| 115 | { |
|---|
| 116 | [super wasPushed]; |
|---|
| 117 | [(BRListControl *)[self list] setSelection:1]; |
|---|
| 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 - 1; |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | - (long) itemCount |
|---|
| 131 | { |
|---|
| 132 | return [shows count] + 1; |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | - (id<BRMenuItemLayer>) itemForRow: (long) row |
|---|
| 136 | { |
|---|
| 137 | BRAdornedMenuItemLayer *result = [SapphireFrontRowCompat textMenuItemForScene:[self scene] folder:NO]; |
|---|
| 138 | |
|---|
| 139 | if(row == 0) |
|---|
| 140 | /*Put in the special "this is not a show"*/ |
|---|
| 141 | [SapphireFrontRowCompat setTitle:BRLocalizedString(@"<This is not a TV Show>", @"Mark an episode as not a TV show in the show chooser") forMenu:result]; |
|---|
| 142 | else |
|---|
| 143 | /*Put in the show*/ |
|---|
| 144 | [SapphireFrontRowCompat setTitle:[[shows objectAtIndex:row-1] objectForKey:@"name"] forMenu:result]; |
|---|
| 145 | |
|---|
| 146 | return result; |
|---|
| 147 | } |
|---|
| 148 | |
|---|
| 149 | - (NSString *) titleForRow: (long) row |
|---|
| 150 | { |
|---|
| 151 | if(row > [shows count]) |
|---|
| 152 | return nil; |
|---|
| 153 | |
|---|
| 154 | if(row == 0) |
|---|
| 155 | /*Put in the special "this is not a show"*/ |
|---|
| 156 | return BRLocalizedString(@"<This is not a TV Show>", @"Mark an episode as not a TV show in the show chooser"); |
|---|
| 157 | else |
|---|
| 158 | /*Put in the show*/ |
|---|
| 159 | return [[shows objectAtIndex:row-1] objectForKey:@"name"]; |
|---|
| 160 | } |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | - (void) itemSelected: (long) row |
|---|
| 164 | { |
|---|
| 165 | /*User made selection, let's exit*/ |
|---|
| 166 | selection = row; |
|---|
| 167 | [[self stack] popController]; |
|---|
| 168 | } |
|---|
| 169 | @end |
|---|