| 1 | /* |
|---|
| 2 | * SapphireSettings.m |
|---|
| 3 | * Sapphire |
|---|
| 4 | * |
|---|
| 5 | * Created by pnmerrill on Jun. 23, 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 | |
|---|
| 22 | #import <BackRow/BackRow.h> |
|---|
| 23 | #import "SapphireApplianceController.h" |
|---|
| 24 | #import "SapphireSettings.h" |
|---|
| 25 | #import "SapphireTheme.h" |
|---|
| 26 | #import "SapphireMediaPreview.h" |
|---|
| 27 | #import "SapphireAllFileDataImporter.h" |
|---|
| 28 | #import "SapphireTVShowImporter.h" |
|---|
| 29 | #import "SapphireMovieImporter.h" |
|---|
| 30 | #import "SapphirePosterChooser.h" |
|---|
| 31 | #import "SapphireCollectionSettings.h" |
|---|
| 32 | #import "SapphireFileMetaData.h" |
|---|
| 33 | #import "SapphireCollectionDirectory.h" |
|---|
| 34 | #import "SapphireDirectoryMetaData.h" |
|---|
| 35 | #import "SapphireMetaDataSupport.h" |
|---|
| 36 | #import <SapphireCompatClasses/SapphireFrontRowCompat.h> |
|---|
| 37 | #import "NSString-Extensions.h" |
|---|
| 38 | #import "NSFileManager-Extensions.h" |
|---|
| 39 | |
|---|
| 40 | static SapphireSettings *sharedInstance = nil; |
|---|
| 41 | |
|---|
| 42 | @interface SapphireSettings(private) |
|---|
| 43 | - (void)processFiles:(NSArray *)files; |
|---|
| 44 | - (void)filesProcessed:(NSDictionary *)files; |
|---|
| 45 | @end |
|---|
| 46 | |
|---|
| 47 | @implementation SapphireSettings |
|---|
| 48 | |
|---|
| 49 | NSString *HIDE_FAVORITE_KEY = @"HideFavorites"; |
|---|
| 50 | NSString *HIDE_TOP_SHOWS_KEY = @"HideTopShows"; |
|---|
| 51 | NSString *HIDE_UNWATCHED_KEY = @"HideUnwatched"; |
|---|
| 52 | NSString *HIDE_SPOILERS_KEY = @"HideSpoilers"; |
|---|
| 53 | NSString *HIDE_AUDIO_KEY = @"HideAudio"; |
|---|
| 54 | NSString *HIDE_VIDEO_KEY = @"HideVideo"; |
|---|
| 55 | NSString *HIDE_POSTER_CHOOSER_KEY = @"PosterChooserOptOut"; |
|---|
| 56 | NSString *HIDE_UI_QUIT_KEY = @"HideUIQuit"; |
|---|
| 57 | NSString *ENABLE_FAST_SWITCHING_KEY = @"EnableFastSwitching"; |
|---|
| 58 | NSString *USE_AC3_PASSTHROUGH = @"EnableAC3Passthrough"; |
|---|
| 59 | NSString *ENABLE_DIR_LOOKUP = @"EnableDirLookup"; |
|---|
| 60 | NSString *ENABLE_AUTO_SELECTION = @"EnableAutoSelection"; |
|---|
| 61 | NSString *DISABLE_ANON_KEY = @"DisableAnonymousReporting"; |
|---|
| 62 | NSString *LAST_PREDICATE = @"LastPredicate"; |
|---|
| 63 | |
|---|
| 64 | NSString *SETTING_NAME = @"Name"; |
|---|
| 65 | NSString *SETTING_DESCRIPTION = @"Description"; |
|---|
| 66 | NSString *SETTING_KEY = @"Key"; |
|---|
| 67 | NSString *SETTING_GEM = @"Gem"; |
|---|
| 68 | NSString *SETTING_COMMAND = @"Command"; |
|---|
| 69 | |
|---|
| 70 | typedef enum { |
|---|
| 71 | COMMAND_NONE, |
|---|
| 72 | COMMAND_IMPORT_FILE_DATA, |
|---|
| 73 | COMMAND_IMPORT_TV_DATA, |
|---|
| 74 | COMMAND_IMPORT_MOVIE_DATA, |
|---|
| 75 | COMMAND_IMPORT_HIDE_POSTER_CHOOSER, |
|---|
| 76 | COMMAND_IMPORT_USE_DIR_NAME, |
|---|
| 77 | COMMAND_IMPORT_HIDE_ALL_CHOOSERS, |
|---|
| 78 | |
|---|
| 79 | COMMAND_COLLECTIONS_HIDE, |
|---|
| 80 | COMMAND_COLLECTIONS_DONT_IMPORT, |
|---|
| 81 | COMMAND_COLLECTIONS_DELETE, |
|---|
| 82 | |
|---|
| 83 | COMMAND_FILTERS_SKIP_FAVORITE, |
|---|
| 84 | COMMAND_FILTERS_SKIP_UNWATCHED, |
|---|
| 85 | |
|---|
| 86 | COMMAND_METADATA_HIDE_SPOILERS, |
|---|
| 87 | COMMAND_METADATA_HIDE_AUDIO, |
|---|
| 88 | COMMAND_METADATA_HIDE_VIDEO, |
|---|
| 89 | |
|---|
| 90 | COMMAND_AUDIO_ENABLE_AC3, |
|---|
| 91 | |
|---|
| 92 | COMMAND_GENERAL_HIDE_UI_QUIT, |
|---|
| 93 | COMMAND_GENERAL_FAST_DIRECTORY_SWITCHING, |
|---|
| 94 | COMMAND_GENERAL_DONT_ANON_REPORT, |
|---|
| 95 | } SettingsCommand; |
|---|
| 96 | |
|---|
| 97 | + (SapphireSettings *)sharedSettings |
|---|
| 98 | { |
|---|
| 99 | return sharedInstance; |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | + (void)relinquishSettings |
|---|
| 103 | { |
|---|
| 104 | [sharedInstance release]; |
|---|
| 105 | sharedInstance = nil; |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | - (id) initWithScene: (BRRenderScene *) scene settingsPath:(NSString *)dictionaryPath context:(NSManagedObjectContext *)context; |
|---|
| 109 | { |
|---|
| 110 | if(sharedInstance != nil) |
|---|
| 111 | return sharedInstance; |
|---|
| 112 | |
|---|
| 113 | self = [super initWithScene:scene]; |
|---|
| 114 | |
|---|
| 115 | lastCommand = COMMAND_NONE; |
|---|
| 116 | /*Setup display*/ |
|---|
| 117 | moc = [context retain]; |
|---|
| 118 | |
|---|
| 119 | SapphireTheme *theme = [SapphireTheme sharedTheme]; |
|---|
| 120 | settings = [[NSArray alloc] initWithObjects: |
|---|
| 121 | [NSDictionary dictionaryWithObjectsAndKeys: |
|---|
| 122 | BRLocalizedString(@" Populate File Data", @"Populate File Data menu item"), SETTING_NAME, |
|---|
| 123 | BRLocalizedString(@"Tells Sapphire to examine all files, and remember the file size, length and other information that can be gathered from the file itself.", @"Populate File Data description"), SETTING_DESCRIPTION, |
|---|
| 124 | [theme gem:IMPORT_GEM_KEY], SETTING_GEM, |
|---|
| 125 | [NSNumber numberWithInt:COMMAND_IMPORT_FILE_DATA], SETTING_COMMAND, |
|---|
| 126 | nil], |
|---|
| 127 | [NSDictionary dictionaryWithObjectsAndKeys: |
|---|
| 128 | BRLocalizedString(@" Fetch TV Show Data", @"Fetch TV Show Data menu item"), SETTING_NAME, |
|---|
| 129 | BRLocalizedString(@"Tells Sapphire that for every TV episode, gather more information about this episode from the internet.", @"Fetch TV Show Data description"), SETTING_DESCRIPTION, |
|---|
| 130 | [theme gem:TVR_GEM_KEY], SETTING_GEM, |
|---|
| 131 | [NSNumber numberWithInt:COMMAND_IMPORT_TV_DATA], SETTING_COMMAND, |
|---|
| 132 | nil], |
|---|
| 133 | [NSDictionary dictionaryWithObjectsAndKeys: |
|---|
| 134 | BRLocalizedString(@" Fetch Movie Data", @"Fetch Movie Data menu item"), SETTING_NAME, |
|---|
| 135 | BRLocalizedString(@"Tells Sapphire that for every Movie, gather more information from the internet.", @"Fetch Movie Data description"), SETTING_DESCRIPTION, |
|---|
| 136 | [theme gem:IMDB_GEM_KEY], SETTING_GEM, |
|---|
| 137 | [NSNumber numberWithInt:COMMAND_IMPORT_MOVIE_DATA], SETTING_COMMAND, |
|---|
| 138 | nil], |
|---|
| 139 | /* [NSDictionary dictionaryWithObjectsAndKeys: |
|---|
| 140 | BRLocalizedString(@" Choose Movie Posters", @"Start Poster Chooser menu item"), SETTING_NAME, |
|---|
| 141 | BRLocalizedString(@"Choose Movie Posters", @"Start Poster Chooser description"), SETTING_DESCRIPTION, |
|---|
| 142 | [theme gem:GREEN_GEM_KEY], SETTING_GEM, |
|---|
| 143 | [NSNumber numberWithInt:COMMAND_IMPORT_MOVIE_POSTERS], SETTING_COMMAND, |
|---|
| 144 | nil],*/ |
|---|
| 145 | [NSDictionary dictionaryWithObjectsAndKeys: |
|---|
| 146 | BRLocalizedString(@" Hide Collections", @"Hide Collections menu item"), SETTING_NAME, |
|---|
| 147 | BRLocalizedString(@"Allows the user to specify which collections should be hidden from Sapphire's main menu.", @"Hide Collections description"), SETTING_DESCRIPTION, |
|---|
| 148 | [theme gem:FILE_GEM_KEY], SETTING_GEM, |
|---|
| 149 | [NSNumber numberWithInt:COMMAND_COLLECTIONS_HIDE], SETTING_COMMAND, |
|---|
| 150 | nil], |
|---|
| 151 | [NSDictionary dictionaryWithObjectsAndKeys: |
|---|
| 152 | BRLocalizedString(@" Don't Import Collections", @"Don't Import Collections menu item"), SETTING_NAME, |
|---|
| 153 | BRLocalizedString(@"Allows the user to specify which collections should be skipped when importing meta data.", @"Don't Import Collections description"), SETTING_DESCRIPTION, |
|---|
| 154 | [theme gem:FILE_GEM_KEY], SETTING_GEM, |
|---|
| 155 | [NSNumber numberWithInt:COMMAND_COLLECTIONS_DONT_IMPORT], SETTING_COMMAND, |
|---|
| 156 | nil], |
|---|
| 157 | [NSDictionary dictionaryWithObjectsAndKeys: |
|---|
| 158 | BRLocalizedString(@" Delete Collections", @"Delete Collections menu item"), SETTING_NAME, |
|---|
| 159 | BRLocalizedString(@"Allows the user to specify which collections should be delete along with its data. Use this for collections which will never be used again.", @"Delete Collections description"), SETTING_DESCRIPTION, |
|---|
| 160 | [theme gem:FILE_GEM_KEY], SETTING_GEM, |
|---|
| 161 | [NSNumber numberWithInt:COMMAND_COLLECTIONS_DELETE], SETTING_COMMAND, |
|---|
| 162 | nil], |
|---|
| 163 | [NSDictionary dictionaryWithObjectsAndKeys: |
|---|
| 164 | BRLocalizedString(@" Skip \"Favorite Shows\" filter", @"Skip Favorite shows menu item"), SETTING_NAME, |
|---|
| 165 | BRLocalizedString(@"Tells Sapphire that when changing filter settings, skip over the favorite shows filter.", @"Skip Favorite shows description"), SETTING_DESCRIPTION, |
|---|
| 166 | HIDE_FAVORITE_KEY, SETTING_KEY, |
|---|
| 167 | [theme gem:YELLOW_GEM_KEY], SETTING_GEM, |
|---|
| 168 | [NSNumber numberWithInt:COMMAND_FILTERS_SKIP_FAVORITE], SETTING_COMMAND, |
|---|
| 169 | nil], |
|---|
| 170 | /* [NSDictionary dictionaryWithObjectsAndKeys: |
|---|
| 171 | BRLocalizedString(@" Skip \"Top Shows\" filter", @"Skip Top shows menu item"), SETTING_NAME, |
|---|
| 172 | BRLocalizedString(@"Skip \"Top Shows\" filter", @"Skip Top shows description"), SETTING_DESCRIPTION, |
|---|
| 173 | HIDE_TOP_SHOWS_KEY, SETTING_KEY, |
|---|
| 174 | [theme gem:GREEN_GEM_KEY], SETTING_GEM, |
|---|
| 175 | [NSNumber numberWithInt:COMMAND_FILTERS_SKIP_TOP_SHOWS], SETTING_COMMAND, |
|---|
| 176 | nil],*/ |
|---|
| 177 | [NSDictionary dictionaryWithObjectsAndKeys: |
|---|
| 178 | BRLocalizedString(@" Skip \"Unwatched Shows\" filter", @"Skip Unwatched shows menu item"), SETTING_NAME, |
|---|
| 179 | BRLocalizedString(@"Tells Sapphire that when changing filter settings, skip over the unwatched shows filter.", @"Skip Unwatched shows description"), SETTING_DESCRIPTION, |
|---|
| 180 | HIDE_UNWATCHED_KEY, SETTING_KEY, |
|---|
| 181 | [theme gem:BLUE_GEM_KEY], SETTING_GEM, |
|---|
| 182 | [NSNumber numberWithInt:COMMAND_FILTERS_SKIP_UNWATCHED], SETTING_COMMAND, |
|---|
| 183 | nil], |
|---|
| 184 | [NSDictionary dictionaryWithObjectsAndKeys: |
|---|
| 185 | BRLocalizedString(@" Hide Show Spoilers", @"Hide show summarys menu item"), SETTING_NAME, |
|---|
| 186 | BRLocalizedString(@"Tells Sapphire to disable the display of the show's synopsis.", @"Hide show summarys description"), SETTING_DESCRIPTION, |
|---|
| 187 | HIDE_SPOILERS_KEY, SETTING_KEY, |
|---|
| 188 | [theme gem:NOTE_GEM_KEY], SETTING_GEM, |
|---|
| 189 | [NSNumber numberWithInt:COMMAND_METADATA_HIDE_SPOILERS], SETTING_COMMAND, |
|---|
| 190 | nil], |
|---|
| 191 | [NSDictionary dictionaryWithObjectsAndKeys: |
|---|
| 192 | BRLocalizedString(@" Hide Audio Info", @"Hide perian audio info menu item"), SETTING_NAME, |
|---|
| 193 | BRLocalizedString(@"Tells Sapphire to disable the display of audio codec and sample rate information.", @"Hide perian audio info description"), SETTING_DESCRIPTION, |
|---|
| 194 | HIDE_AUDIO_KEY, SETTING_KEY, |
|---|
| 195 | [theme gem:AUDIO_GEM_KEY], SETTING_GEM, |
|---|
| 196 | [NSNumber numberWithInt:COMMAND_METADATA_HIDE_AUDIO], SETTING_COMMAND, |
|---|
| 197 | nil], |
|---|
| 198 | [NSDictionary dictionaryWithObjectsAndKeys: |
|---|
| 199 | BRLocalizedString(@" Hide Video Info", @"Hide perian video info menu item"), SETTING_NAME, |
|---|
| 200 | BRLocalizedString(@"Tells Sapphire to disable the display of video codec, resolution, and color depth information.", @"Hide perian video info description"), SETTING_DESCRIPTION, |
|---|
| 201 | HIDE_VIDEO_KEY, SETTING_KEY, |
|---|
| 202 | [theme gem:VIDEO_GEM_KEY], SETTING_GEM, |
|---|
| 203 | [NSNumber numberWithInt:COMMAND_METADATA_HIDE_VIDEO], SETTING_COMMAND, |
|---|
| 204 | nil], |
|---|
| 205 | [NSDictionary dictionaryWithObjectsAndKeys: |
|---|
| 206 | BRLocalizedString(@" Hide Poster Chooser", @"Hide poster chooser menu item"), SETTING_NAME, |
|---|
| 207 | BRLocalizedString(@"Tells Sapphire to automatically choose posters for movies instead of asking the user to choose one.", @"Hide poster chooser description"), SETTING_DESCRIPTION, |
|---|
| 208 | HIDE_POSTER_CHOOSER_KEY, SETTING_KEY, |
|---|
| 209 | [theme gem:IMPORT_GEM_KEY], SETTING_GEM, |
|---|
| 210 | [NSNumber numberWithInt:COMMAND_IMPORT_HIDE_POSTER_CHOOSER], SETTING_COMMAND, |
|---|
| 211 | nil], |
|---|
| 212 | [NSDictionary dictionaryWithObjectsAndKeys: |
|---|
| 213 | BRLocalizedString(@" Hide UI Quit", @"Hide the ui quitter menu item"), SETTING_NAME, |
|---|
| 214 | BRLocalizedString(@"Tells Sapphire to hide the main menu element forcing frontrow to quit.", @"Hide the ui quitter description"), SETTING_DESCRIPTION, |
|---|
| 215 | HIDE_UI_QUIT_KEY, SETTING_KEY, |
|---|
| 216 | [theme gem:FRONTROW_GEM_KEY], SETTING_GEM, |
|---|
| 217 | [NSNumber numberWithInt:COMMAND_GENERAL_HIDE_UI_QUIT], SETTING_COMMAND, |
|---|
| 218 | nil], |
|---|
| 219 | [NSDictionary dictionaryWithObjectsAndKeys: |
|---|
| 220 | BRLocalizedString(@" Fast Directory Switching", @"Don't rescan directories upon entry and used cached data"), SETTING_NAME, |
|---|
| 221 | BRLocalizedString(@"Tells Sapphire that when using a filter, use the cached data to setup directories rather than scanning the directories themselves for new files.", @"Fast Directory Switching description"), SETTING_DESCRIPTION, |
|---|
| 222 | ENABLE_FAST_SWITCHING_KEY, SETTING_KEY, |
|---|
| 223 | [theme gem:FAST_GEM_KEY], SETTING_GEM, |
|---|
| 224 | [NSNumber numberWithInt:COMMAND_GENERAL_FAST_DIRECTORY_SWITCHING], SETTING_COMMAND, |
|---|
| 225 | nil], |
|---|
| 226 | [NSDictionary dictionaryWithObjectsAndKeys: |
|---|
| 227 | BRLocalizedString(@" Enable AC3 Passthrough", @"Enable AC3 Passthrough menu item"), SETTING_NAME, |
|---|
| 228 | BRLocalizedString(@"Tells Sapphire that you have an AC3 decoder and to enable passthrough of the full audio information to the decoder. This is how you get 5.1 output.", @"Enable AC3 Passthrough description"), SETTING_DESCRIPTION, |
|---|
| 229 | USE_AC3_PASSTHROUGH, SETTING_KEY, |
|---|
| 230 | [theme gem:AC3_GEM_KEY], SETTING_GEM, |
|---|
| 231 | [NSNumber numberWithInt:COMMAND_AUDIO_ENABLE_AC3], SETTING_COMMAND, |
|---|
| 232 | nil], |
|---|
| 233 | [NSDictionary dictionaryWithObjectsAndKeys: |
|---|
| 234 | BRLocalizedString(@" Use Directory Lookup", @"Use directory names instead of filename for movie lookup"), SETTING_NAME, |
|---|
| 235 | BRLocalizedString(@"Tells Sapphire that you want to use directory names instead of file names for identifying movies.", @"Enable Directory lookup description"), SETTING_DESCRIPTION, |
|---|
| 236 | ENABLE_DIR_LOOKUP, SETTING_KEY, |
|---|
| 237 | [theme gem:IMDB_GEM_KEY], SETTING_GEM, |
|---|
| 238 | [NSNumber numberWithInt:COMMAND_IMPORT_USE_DIR_NAME], SETTING_COMMAND, |
|---|
| 239 | nil], |
|---|
| 240 | [NSDictionary dictionaryWithObjectsAndKeys: |
|---|
| 241 | BRLocalizedString(@" Auto-Select Movies/Shows", @"Hide movie/show chooser menu item"), SETTING_NAME, |
|---|
| 242 | BRLocalizedString(@"Tells Sapphire to automatically choose movie and tv show selection.", @"Enable movie/show chooser description"), SETTING_DESCRIPTION, |
|---|
| 243 | ENABLE_AUTO_SELECTION, SETTING_KEY, |
|---|
| 244 | [theme gem:IMPORT_GEM_KEY], SETTING_GEM, |
|---|
| 245 | [NSNumber numberWithInt:COMMAND_IMPORT_HIDE_ALL_CHOOSERS], SETTING_COMMAND, |
|---|
| 246 | nil], |
|---|
| 247 | [NSDictionary dictionaryWithObjectsAndKeys: |
|---|
| 248 | BRLocalizedString(@" Disable Anonymous Reporting", @"Disable the anonymous reporting for aid in future features"), SETTING_NAME, |
|---|
| 249 | BRLocalizedString(@"Tells Sapphire to not report any anonymous information on how you use Sapphire. Anonymous reporting enables us to improve the plugin for future use.", @"Disable the anonymous reporting description"), SETTING_DESCRIPTION, |
|---|
| 250 | DISABLE_ANON_KEY, SETTING_KEY, |
|---|
| 251 | [theme gem:REPORT_GEM_KEY], SETTING_GEM, |
|---|
| 252 | [NSNumber numberWithInt:COMMAND_GENERAL_DONT_ANON_REPORT], SETTING_COMMAND, |
|---|
| 253 | nil], |
|---|
| 254 | nil]; |
|---|
| 255 | |
|---|
| 256 | path = [dictionaryPath retain]; |
|---|
| 257 | options = [[NSDictionary dictionaryWithContentsOfFile:dictionaryPath] mutableCopy]; |
|---|
| 258 | /*Set deaults*/ |
|---|
| 259 | defaults = [[NSDictionary alloc] initWithObjectsAndKeys: |
|---|
| 260 | [NSNumber numberWithBool:NO], HIDE_FAVORITE_KEY, |
|---|
| 261 | [NSNumber numberWithBool:YES], HIDE_TOP_SHOWS_KEY, |
|---|
| 262 | [NSNumber numberWithBool:NO], HIDE_UNWATCHED_KEY, |
|---|
| 263 | [NSNumber numberWithBool:NO], HIDE_SPOILERS_KEY, |
|---|
| 264 | [NSNumber numberWithBool:NO], HIDE_AUDIO_KEY, |
|---|
| 265 | [NSNumber numberWithBool:NO], HIDE_VIDEO_KEY, |
|---|
| 266 | [NSNumber numberWithBool:NO], HIDE_POSTER_CHOOSER_KEY, |
|---|
| 267 | [NSNumber numberWithBool:YES], HIDE_UI_QUIT_KEY, |
|---|
| 268 | [NSNumber numberWithBool:YES], ENABLE_FAST_SWITCHING_KEY, |
|---|
| 269 | [NSNumber numberWithBool:NO], USE_AC3_PASSTHROUGH, |
|---|
| 270 | [NSNumber numberWithBool:NO], ENABLE_DIR_LOOKUP, |
|---|
| 271 | [NSNumber numberWithBool:NO], ENABLE_AUTO_SELECTION, |
|---|
| 272 | [NSNumber numberWithBool:NO], DISABLE_ANON_KEY, |
|---|
| 273 | [NSNumber numberWithInt:NSNotFound], LAST_PREDICATE, |
|---|
| 274 | nil]; |
|---|
| 275 | if(options == nil) |
|---|
| 276 | options = [[NSMutableDictionary alloc] init]; |
|---|
| 277 | |
|---|
| 278 | /*display*/ |
|---|
| 279 | BRListControl *list = [self list]; |
|---|
| 280 | [list setDatasource:self]; |
|---|
| 281 | [SapphireFrontRowCompat addDividerAtIndex:6 toList:list]; |
|---|
| 282 | /*Save our instance*/ |
|---|
| 283 | sharedInstance = [self retain]; |
|---|
| 284 | |
|---|
| 285 | return self; |
|---|
| 286 | } |
|---|
| 287 | |
|---|
| 288 | /*! |
|---|
| 289 | * @brief Writes settings to disk |
|---|
| 290 | */ |
|---|
| 291 | - (void)writeSettings |
|---|
| 292 | { |
|---|
| 293 | [options writeToFile:path atomically:YES]; |
|---|
| 294 | } |
|---|
| 295 | |
|---|
| 296 | - (void)dealloc |
|---|
| 297 | { |
|---|
| 298 | [settings release]; |
|---|
| 299 | [options release]; |
|---|
| 300 | [path release]; |
|---|
| 301 | [defaults release]; |
|---|
| 302 | [moc release]; |
|---|
| 303 | [super dealloc]; |
|---|
| 304 | } |
|---|
| 305 | |
|---|
| 306 | /*! |
|---|
| 307 | * @brief Get a setting |
|---|
| 308 | * |
|---|
| 309 | * @param key The setting to retrieve |
|---|
| 310 | * @return The setting in an NSNumber |
|---|
| 311 | */ |
|---|
| 312 | - (NSNumber *)numberForKey:(NSString *)key |
|---|
| 313 | { |
|---|
| 314 | /*Check the user's setting*/ |
|---|
| 315 | NSNumber *num = [options objectForKey:key]; |
|---|
| 316 | if(!num) |
|---|
| 317 | /*User hasn't set yet, use default then*/ |
|---|
| 318 | num = [defaults objectForKey:key]; |
|---|
| 319 | return num; |
|---|
| 320 | } |
|---|
| 321 | |
|---|
| 322 | /*! |
|---|
| 323 | * @brief Get a setting |
|---|
| 324 | * |
|---|
| 325 | * @param key The setting to retrieve |
|---|
| 326 | * @return YES if set, NO otherwise |
|---|
| 327 | */ |
|---|
| 328 | - (BOOL)boolForKey:(NSString *)key |
|---|
| 329 | { |
|---|
| 330 | /*Check the user's setting*/ |
|---|
| 331 | NSNumber *num = [options objectForKey:key]; |
|---|
| 332 | if(!num) |
|---|
| 333 | /*User hasn't set yet, use default then*/ |
|---|
| 334 | num = [defaults objectForKey:key]; |
|---|
| 335 | return [num boolValue]; |
|---|
| 336 | } |
|---|
| 337 | |
|---|
| 338 | - (BOOL)displayUnwatched |
|---|
| 339 | { |
|---|
| 340 | return ![self boolForKey:HIDE_UNWATCHED_KEY]; |
|---|
| 341 | } |
|---|
| 342 | |
|---|
| 343 | - (BOOL)displayFavorites |
|---|
| 344 | { |
|---|
| 345 | return ![self boolForKey:HIDE_FAVORITE_KEY]; |
|---|
| 346 | } |
|---|
| 347 | |
|---|
| 348 | - (BOOL)displayTopShows |
|---|
| 349 | { |
|---|
| 350 | return ![self boolForKey:HIDE_TOP_SHOWS_KEY]; |
|---|
| 351 | } |
|---|
| 352 | |
|---|
| 353 | - (BOOL)displaySpoilers |
|---|
| 354 | { |
|---|
| 355 | return ![self boolForKey:HIDE_SPOILERS_KEY]; |
|---|
| 356 | } |
|---|
| 357 | |
|---|
| 358 | - (BOOL)displayAudio |
|---|
| 359 | { |
|---|
| 360 | return ![self boolForKey:HIDE_AUDIO_KEY]; |
|---|
| 361 | } |
|---|
| 362 | |
|---|
| 363 | - (BOOL)displayVideo |
|---|
| 364 | { |
|---|
| 365 | return ![self boolForKey:HIDE_VIDEO_KEY]; |
|---|
| 366 | } |
|---|
| 367 | |
|---|
| 368 | - (BOOL)displayPosterChooser |
|---|
| 369 | { |
|---|
| 370 | return ![self boolForKey:HIDE_POSTER_CHOOSER_KEY]; |
|---|
| 371 | } |
|---|
| 372 | |
|---|
| 373 | - (BOOL)disableUIQuit |
|---|
| 374 | { |
|---|
| 375 | return [self boolForKey:HIDE_UI_QUIT_KEY]; |
|---|
| 376 | } |
|---|
| 377 | |
|---|
| 378 | - (BOOL)disableAnonymousReporting; |
|---|
| 379 | { |
|---|
| 380 | return [self boolForKey:DISABLE_ANON_KEY]; |
|---|
| 381 | } |
|---|
| 382 | |
|---|
| 383 | - (BOOL)useAC3Passthrough |
|---|
| 384 | { |
|---|
| 385 | return [self boolForKey:USE_AC3_PASSTHROUGH]; |
|---|
| 386 | } |
|---|
| 387 | |
|---|
| 388 | - (BOOL)fastSwitching |
|---|
| 389 | { |
|---|
| 390 | return [self boolForKey:ENABLE_FAST_SWITCHING_KEY]; |
|---|
| 391 | |
|---|
| 392 | } |
|---|
| 393 | |
|---|
| 394 | - (BOOL)dirLookup |
|---|
| 395 | { |
|---|
| 396 | return [self boolForKey:ENABLE_DIR_LOOKUP]; |
|---|
| 397 | } |
|---|
| 398 | |
|---|
| 399 | - (BOOL)autoSelection |
|---|
| 400 | { |
|---|
| 401 | return [self boolForKey:ENABLE_AUTO_SELECTION]; |
|---|
| 402 | } |
|---|
| 403 | |
|---|
| 404 | - (int)indexOfLastPredicate |
|---|
| 405 | { |
|---|
| 406 | return [[self numberForKey:LAST_PREDICATE] intValue]; |
|---|
| 407 | } |
|---|
| 408 | |
|---|
| 409 | - (void)setIndexOfLastPredicate:(int)index |
|---|
| 410 | { |
|---|
| 411 | [options setObject:[NSNumber numberWithInt:index] forKey:LAST_PREDICATE]; |
|---|
| 412 | /*Save our settings*/ |
|---|
| 413 | [self writeSettings]; |
|---|
| 414 | } |
|---|
| 415 | |
|---|
| 416 | - (void)wasExhumed |
|---|
| 417 | { |
|---|
| 418 | // handle being revealed when the user presses Menu |
|---|
| 419 | |
|---|
| 420 | if(lastCommand == COMMAND_COLLECTIONS_DELETE) |
|---|
| 421 | { |
|---|
| 422 | NSArray *collections = [SapphireCollectionDirectory allCollectionsInContext:moc]; |
|---|
| 423 | NSEnumerator *colEnum = [collections objectEnumerator]; |
|---|
| 424 | SapphireCollectionDirectory *collection; |
|---|
| 425 | BOOL change = NO; |
|---|
| 426 | while((collection = [colEnum nextObject]) != nil) |
|---|
| 427 | { |
|---|
| 428 | if([collection deleteValue]) |
|---|
| 429 | { |
|---|
| 430 | change = YES; |
|---|
| 431 | SapphireDirectoryMetaData *dir = [collection directory]; |
|---|
| 432 | [moc deleteObject:dir]; |
|---|
| 433 | } |
|---|
| 434 | } |
|---|
| 435 | if(change) |
|---|
| 436 | [SapphireMetaDataSupport save:moc]; |
|---|
| 437 | } |
|---|
| 438 | |
|---|
| 439 | // always call super |
|---|
| 440 | [super wasExhumed]; |
|---|
| 441 | } |
|---|
| 442 | |
|---|
| 443 | - (long) itemCount |
|---|
| 444 | { |
|---|
| 445 | // return the number of items in your menu list here |
|---|
| 446 | return [settings count]; |
|---|
| 447 | } |
|---|
| 448 | |
|---|
| 449 | - (id<BRMenuItemLayer>) itemForRow: (long) row |
|---|
| 450 | { |
|---|
| 451 | /* |
|---|
| 452 | // build a BRTextMenuItemLayer or a BRAdornedMenuItemLayer, etc. here |
|---|
| 453 | // return that object, it will be used to display the list item. |
|---|
| 454 | return ( nil ); |
|---|
| 455 | */ |
|---|
| 456 | if( row >= [settings count] ) return ( nil ) ; |
|---|
| 457 | |
|---|
| 458 | BRAdornedMenuItemLayer * result = nil; |
|---|
| 459 | NSDictionary *setting = [settings objectAtIndex:row]; |
|---|
| 460 | NSString *name = [setting objectForKey:SETTING_NAME]; |
|---|
| 461 | result = [SapphireFrontRowCompat textMenuItemForScene:[self scene] folder:NO]; |
|---|
| 462 | |
|---|
| 463 | NSString *key = [setting objectForKey:SETTING_KEY]; |
|---|
| 464 | if(key != nil && [self boolForKey:key]) |
|---|
| 465 | { |
|---|
| 466 | [SapphireFrontRowCompat setLeftIcon:[SapphireFrontRowCompat selectedSettingImageForScene:[self scene]] forMenu:result]; |
|---|
| 467 | } |
|---|
| 468 | [SapphireFrontRowCompat setRightIcon:[setting objectForKey:SETTING_GEM] forMenu:result]; |
|---|
| 469 | |
|---|
| 470 | // add text |
|---|
| 471 | [SapphireFrontRowCompat setTitle:name forMenu:result]; |
|---|
| 472 | |
|---|
| 473 | return result; |
|---|
| 474 | } |
|---|
| 475 | |
|---|
| 476 | - (NSString *) titleForRow: (long) row |
|---|
| 477 | { |
|---|
| 478 | |
|---|
| 479 | if (row >= [settings count]) |
|---|
| 480 | return nil; |
|---|
| 481 | |
|---|
| 482 | NSString *result = [[settings objectAtIndex:row] objectForKey:SETTING_NAME]; |
|---|
| 483 | return result; |
|---|
| 484 | /* |
|---|
| 485 | // return the title for the list item at the given index here |
|---|
| 486 | return ( @"Sapphire" ); |
|---|
| 487 | */ |
|---|
| 488 | } |
|---|
| 489 | |
|---|
| 490 | - (long) rowForTitle: (NSString *) title |
|---|
| 491 | { |
|---|
| 492 | long result = -1; |
|---|
| 493 | long i, count = [self itemCount]; |
|---|
| 494 | for ( i = 0; i < count; i++ ) |
|---|
| 495 | { |
|---|
| 496 | if ( [title isEqualToString: [self titleForRow: i]] ) |
|---|
| 497 | { |
|---|
| 498 | result = i; |
|---|
| 499 | break; |
|---|
| 500 | } |
|---|
| 501 | } |
|---|
| 502 | |
|---|
| 503 | return ( result ); |
|---|
| 504 | } |
|---|
| 505 | |
|---|
| 506 | - (void) itemSelected: (long) row |
|---|
| 507 | { |
|---|
| 508 | // This is called when the user changed a setting |
|---|
| 509 | NSDictionary *setting = [settings objectAtIndex:row]; |
|---|
| 510 | |
|---|
| 511 | lastCommand = [[setting objectForKey:SETTING_COMMAND] intValue]; |
|---|
| 512 | switch (lastCommand) { |
|---|
| 513 | case COMMAND_IMPORT_FILE_DATA: |
|---|
| 514 | { |
|---|
| 515 | SapphireAllFileDataImporter *importer = [[SapphireAllFileDataImporter alloc] init]; |
|---|
| 516 | SapphireImporterDataMenu *menu = [[SapphireImporterDataMenu alloc] initWithScene:[self scene] context:moc importer:importer]; |
|---|
| 517 | [[self stack] pushController:menu]; |
|---|
| 518 | [menu release]; |
|---|
| 519 | [importer release]; |
|---|
| 520 | break; |
|---|
| 521 | } |
|---|
| 522 | case COMMAND_IMPORT_TV_DATA: |
|---|
| 523 | { |
|---|
| 524 | SapphireTVShowImporter *importer = [[SapphireTVShowImporter alloc] initWithContext:moc]; |
|---|
| 525 | SapphireImporterDataMenu *menu = [[SapphireImporterDataMenu alloc] initWithScene:[self scene] context:moc importer:importer]; |
|---|
| 526 | [[self stack] pushController:menu]; |
|---|
| 527 | [menu release]; |
|---|
| 528 | [importer release]; |
|---|
| 529 | break; |
|---|
| 530 | } |
|---|
| 531 | case COMMAND_IMPORT_MOVIE_DATA: |
|---|
| 532 | { |
|---|
| 533 | SapphireMovieImporter *importer = [[SapphireMovieImporter alloc] initWithContext:moc]; |
|---|
| 534 | SapphireImporterDataMenu *menu = [[SapphireImporterDataMenu alloc] initWithScene:[self scene] context:moc importer:importer]; |
|---|
| 535 | [[self stack] pushController:menu]; |
|---|
| 536 | [menu release]; |
|---|
| 537 | [importer release]; |
|---|
| 538 | break; |
|---|
| 539 | } |
|---|
| 540 | /* case COMMAND_IMPORT_MOVIE_POSTERS: |
|---|
| 541 | { |
|---|
| 542 | SapphirePosterBrowse *chooser = [[SapphirePosterChooser alloc] initWithScene:[self scene] metaDataPath:[[path stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"movieData.plist"]]; |
|---|
| 543 | [[self stack] pushController:chooser]; |
|---|
| 544 | [chooser release]; |
|---|
| 545 | break; |
|---|
| 546 | }*/ |
|---|
| 547 | case COMMAND_COLLECTIONS_HIDE: |
|---|
| 548 | { |
|---|
| 549 | SapphireCollectionSettings *colSettings = [[SapphireCollectionSettings alloc] initWithScene:[self scene] context:moc]; |
|---|
| 550 | [colSettings setGettingSelector:@selector(hiddenValue)]; |
|---|
| 551 | [colSettings setSettingSelector:@selector(setHiddenValue:)]; |
|---|
| 552 | [colSettings setListTitle:BRLocalizedString(@"Hide Collections", @"Hide Collections Menu Title")] ; |
|---|
| 553 | [[self stack] pushController:colSettings]; |
|---|
| 554 | [colSettings release]; |
|---|
| 555 | break; |
|---|
| 556 | } |
|---|
| 557 | case COMMAND_COLLECTIONS_DONT_IMPORT: |
|---|
| 558 | { |
|---|
| 559 | SapphireCollectionSettings *colSettings = [[SapphireCollectionSettings alloc] initWithScene:[self scene] context:moc]; |
|---|
| 560 | [colSettings setGettingSelector:@selector(skipValue)]; |
|---|
| 561 | [colSettings setSettingSelector:@selector(setSkipValue:)]; |
|---|
| 562 | [colSettings setListTitle:BRLocalizedString(@"Skip Collections", @"Skip Collections Menu Title")] ; |
|---|
| 563 | [[self stack] pushController:colSettings]; |
|---|
| 564 | [colSettings release]; |
|---|
| 565 | break; |
|---|
| 566 | } |
|---|
| 567 | case COMMAND_COLLECTIONS_DELETE: |
|---|
| 568 | { |
|---|
| 569 | SapphireCollectionSettings *colSettings = [[SapphireCollectionSettings alloc] initWithScene:[self scene] context:moc]; |
|---|
| 570 | [colSettings setGettingSelector:@selector(deleteValue)]; |
|---|
| 571 | [colSettings setSettingSelector:@selector(setDeleteValue:)]; |
|---|
| 572 | [colSettings setListTitle:BRLocalizedString(@"Delete Collections", @"Delete Collections Menu Title")]; |
|---|
| 573 | [[self stack] pushController:colSettings]; |
|---|
| 574 | [colSettings release]; |
|---|
| 575 | break; |
|---|
| 576 | } |
|---|
| 577 | default: |
|---|
| 578 | { |
|---|
| 579 | NSString *key = [setting objectForKey:SETTING_KEY]; |
|---|
| 580 | if(key == nil) |
|---|
| 581 | break; |
|---|
| 582 | BOOL setting = [self boolForKey:key]; |
|---|
| 583 | [options setObject:[NSNumber numberWithBool:!setting] forKey:key]; |
|---|
| 584 | } |
|---|
| 585 | } |
|---|
| 586 | |
|---|
| 587 | /*Save our settings*/ |
|---|
| 588 | [self writeSettings]; |
|---|
| 589 | |
|---|
| 590 | /*Redraw*/ |
|---|
| 591 | [[self list] reload] ; |
|---|
| 592 | [SapphireFrontRowCompat renderScene:[self scene]]; |
|---|
| 593 | |
|---|
| 594 | } |
|---|
| 595 | |
|---|
| 596 | - (id<BRMediaPreviewController>) previewControlForItem: (long) row |
|---|
| 597 | { |
|---|
| 598 | return [self previewControllerForItem:row]; |
|---|
| 599 | } |
|---|
| 600 | |
|---|
| 601 | - (id<BRMediaPreviewController>) previewControllerForItem: (long) item |
|---|
| 602 | { |
|---|
| 603 | if(item >= [settings count]) |
|---|
| 604 | return nil; |
|---|
| 605 | |
|---|
| 606 | NSDictionary *setting = [settings objectAtIndex:item]; |
|---|
| 607 | |
|---|
| 608 | /* Get setting name & kill the gem cushion */ |
|---|
| 609 | NSString *settingName = [[setting objectForKey:SETTING_NAME] substringFromIndex:2]; |
|---|
| 610 | NSString *settingDescription=[setting objectForKey:SETTING_DESCRIPTION]; |
|---|
| 611 | /* Construct a gerneric metadata asset for display */ |
|---|
| 612 | NSMutableDictionary *settingMeta=[[NSMutableDictionary alloc] init]; |
|---|
| 613 | [settingMeta setObject:settingName forKey:META_TITLE_KEY]; |
|---|
| 614 | [settingMeta setObject:[NSNumber numberWithInt:FILE_CLASS_UTILITY] forKey:FILE_CLASS_KEY]; |
|---|
| 615 | [settingMeta setObject:settingDescription forKey:META_DESCRIPTION_KEY]; |
|---|
| 616 | SapphireMediaPreview *preview = [[SapphireMediaPreview alloc] initWithScene:[self scene]]; |
|---|
| 617 | [preview setUtilityData:settingMeta]; |
|---|
| 618 | [settingMeta release]; |
|---|
| 619 | [preview setShowsMetadataImmediately:YES]; |
|---|
| 620 | /*And go*/ |
|---|
| 621 | return [preview autorelease]; |
|---|
| 622 | } |
|---|
| 623 | |
|---|
| 624 | @end |
|---|
| 625 | |
|---|