-- (IBAction)DeletePreset:(id)sender
-{
- int status;
- NSEnumerator *enumerator;
- NSNumber *index;
- NSMutableArray *tempArray;
- id tempObject;
-
- if ( [tableView numberOfSelectedRows] == 0 )
- return;
- /* Alert user before deleting preset */
- /* Comment out for now, tie to user pref eventually */
-
- //NSBeep();
- status = NSRunAlertPanel(@"Warning!", @"Are you sure that you want to delete the selected preset?", @"OK", @"Cancel", nil);
-
- if ( status == NSAlertDefaultReturn ) {
- enumerator = [tableView selectedRowEnumerator];
- tempArray = [NSMutableArray array];
-
- while ( (index = [enumerator nextObject]) ) {
- tempObject = [UserPresets objectAtIndex:[index intValue]];
- [tempArray addObject:tempObject];
- }
-
- [UserPresets removeObjectsInArray:tempArray];
- [tableView reloadData];
- [self savePreset];
- }
-}
-- (IBAction)tableViewSelected:(id)sender
-{
- /* Since we cannot disable the presets tableView in terms of clickability
- we will use the enabled state of the add presets button to determine whether
- or not clicking on a preset will do anything */
- if ([fPresetsAdd isEnabled])
- {
-
- /* we get the chosen preset from the UserPresets array */
- chosenPreset = [UserPresets objectAtIndex:[sender selectedRow]];
- curUserPresetChosenNum = [sender selectedRow];
- /* we set the preset display field in main window here */
- [fPresetSelectedDisplay setStringValue: [NSString stringWithFormat: @"%@",[chosenPreset valueForKey:@"PresetName"]]];
- /* File Format */
- [fDstFormatPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"FileFormat"]]];
- [self FormatPopUpChanged: NULL];
-
- /* Chapter Markers*/
- [fCreateChapterMarkers setState:[[chosenPreset objectForKey:@"ChapterMarkers"] intValue]];
- /* Allow Mpeg4 64 bit formatting +4GB file sizes */
- [fDstMpgLargeFileCheck setState:[[chosenPreset objectForKey:@"Mp4LargeFile"] intValue]];
- /* Codecs */
- [fDstCodecsPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"FileCodecs"]]];
- [self CodecsPopUpChanged: NULL];
- /* Video encoder */
- [fVidEncoderPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoEncoder"]]];
-
- /* We can show the preset options here in the gui if we want to
- so we check to see it the user has specified it in the prefs */
- [fDisplayX264Options setStringValue: [NSString stringWithFormat:[chosenPreset valueForKey:@"x264Option"]]];
-
- [self X264AdvancedOptionsSet:NULL];
-
- /* Lets run through the following functions to get variables set there */
- [self EncoderPopUpChanged: NULL];
-
- [self CalculateBitrate: NULL];
-
- /* Video quality */
- [fVidQualityMatrix selectCellAtRow:[[chosenPreset objectForKey:@"VideoQualityType"] intValue] column:0];
-
- [fVidTargetSizeField setStringValue: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoTargetSize"]]];
- [fVidBitrateField setStringValue: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoAvgBitrate"]]];
-
- [fVidQualitySlider setFloatValue: [[chosenPreset valueForKey:@"VideoQualitySlider"] floatValue]];
- [self VideoMatrixChanged: NULL];
-
- /* Video framerate */
- [fVidRatePopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"VideoFramerate"]]];
-
- /* GrayScale */
- [fVidGrayscaleCheck setState:[[chosenPreset objectForKey:@"VideoGrayScale"] intValue]];
-
- /* 2 Pass Encoding */
- [fVidTwoPassCheck setState:[[chosenPreset objectForKey:@"VideoTwoPass"] intValue]];
- [self TwoPassCheckboxChanged: NULL];
- /* Turbo 1st pass for 2 Pass Encoding */
- [fVidTurboPassCheck setState:[[chosenPreset objectForKey:@"VideoTurboTwoPass"] intValue]];
-
- /*Audio*/
-
- /* Audio Sample Rate*/
- [fAudRatePopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"AudioSampleRate"]]];
- /* Audio Bitrate Rate*/
- [fAudBitratePopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"AudioBitRate"]]];
- /*Subtitles*/
- [fSubPopUp selectItemWithTitle: [NSString stringWithFormat:[chosenPreset valueForKey:@"Subtitles"]]];
-
- /* Picture Settings */
- /* Look to see if we apply these here in objectForKey:@"UsesPictureSettings"] */
- if ([[chosenPreset objectForKey:@"UsesPictureSettings"] intValue] > 0)
- {
- hb_job_t * job = fTitle->job;
- /* Check to see if we should use the max picture setting for the current title*/
- if ([[chosenPreset objectForKey:@"UsesPictureSettings"] intValue] == 2 || [[chosenPreset objectForKey:@"UsesMaxPictureSettings"] intValue] == 1)
- {
- /* Use Max Picture settings for whatever the dvd is.*/
- [self RevertPictureSizeToMax: NULL];
- job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"] intValue];
- if (job->keep_ratio == 1)
- {
- hb_fix_aspect( job, HB_KEEP_WIDTH );
- }
- job->pixel_ratio = [[chosenPreset objectForKey:@"PicturePAR"] intValue];
- }
- else
- {
- job->width = [[chosenPreset objectForKey:@"PictureWidth"] intValue];
- job->height = [[chosenPreset objectForKey:@"PictureHeight"] intValue];
- job->keep_ratio = [[chosenPreset objectForKey:@"PictureKeepRatio"] intValue];
- if (job->keep_ratio == 1)
- {
- hb_fix_aspect( job, HB_KEEP_WIDTH );
- }
- job->pixel_ratio = [[chosenPreset objectForKey:@"PicturePAR"] intValue];
- /* AutoCrop is in preset, then use the autocrop settings for each dvd */
- if ([[chosenPreset objectForKey:@"PictureAutoCrop"] intValue] == 1)
- {
- [fPicSettingAutoCrop setStringValue: [NSString stringWithFormat:
- @"%d", 1]];
- job->crop[0] = [[chosenPreset objectForKey:@"PictureTopCrop"] intValue];
- job->crop[1] = [[chosenPreset objectForKey:@"PictureBottomCrop"] intValue];
- job->crop[2] = [[chosenPreset objectForKey:@"PictureLeftCrop"] intValue];
- job->crop[3] = [[chosenPreset objectForKey:@"PictureRightCrop"] intValue];
- }
- else /* if custom crop has been saved in preset, use the saved custom cropping regardless of the source */
- {
- [fPicSettingAutoCrop setStringValue: [NSString stringWithFormat:
- @"%d", 0]];
- job->crop[0] = [[chosenPreset objectForKey:@"PictureTopCrop"] intValue];
- job->crop[1] = [[chosenPreset objectForKey:@"PictureBottomCrop"] intValue];
- job->crop[2] = [[chosenPreset objectForKey:@"PictureLeftCrop"] intValue];
- job->crop[3] = [[chosenPreset objectForKey:@"PictureRightCrop"] intValue];
- }
- }
- [self CalculatePictureSizing: NULL];
- }
-
-
-
-
-}
-}
-
-
-
-- (int)numberOfRowsInTableView:(NSTableView *)aTableView
-{
- return [UserPresets count];
-}
-
-/* we use this to determine display characteristics for
-each table cell based on content currently only used to
-show the built in presets in a blue font. */
-- (void)tableView:(NSTableView *)aTableView
- willDisplayCell:(id)aCell
- forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
-{
- NSDictionary *userPresetDict = [UserPresets objectAtIndex:rowIndex];
- NSColor *fontColor;
- NSColor *shadowColor;
- /* First, we check to see if its a selected row, if so, we use white since its highlighted in blue */
- if ([[aTableView selectedRowIndexes] containsIndex:rowIndex] && ([tableView editedRow] != rowIndex))
- {
-
- fontColor = [NSColor whiteColor];
- shadowColor = [NSColor colorWithDeviceRed:(127.0/255.0) green:(140.0/255.0) blue:(160.0/255.0) alpha:1.0];
- }
- else
- {
- /* We set the properties of unselected rows */
- /* if built-in preset (defined by "type" == 0) we use a blue font */
- if ([[userPresetDict objectForKey:@"Type"] intValue] == 0)
- {
- fontColor = [NSColor blueColor];
- }
- else // User created preset, use a black font
- {
- fontColor = [NSColor blackColor];
- }
- shadowColor = nil;
- }
- [aCell setTextColor:fontColor];
- /* this shadow stuff (like mail app) for some reason looks crappy, commented out
- temporarily in case we want to resurrect it */
- /*
- NSShadow *shadow = [[NSShadow alloc] init];
- NSSize shadowOffset = { width: 1.0, height: -1.5};
- [shadow setShadowOffset:shadowOffset];
- [shadow setShadowColor:shadowColor];
- [shadow set];
- */
-
-}
-/* Method to display tooltip with the description for each preset, if available */
-- (NSString *)tableView:(NSTableView *)aTableView toolTipForCell:(NSCell *)aCell
- rect:(NSRectPointer)aRect tableColumn:(NSTableColumn *)aTableColumn
- row:(int)rowIndex mouseLocation:(NSPoint)aPos
-{
- /* initialize the tooltip contents variable */
- NSString *loc_tip;
- /* if there is a description for the preset, we show it in the tooltip */
- if ([[UserPresets objectAtIndex:rowIndex] valueForKey:@"PresetDescription"])
- {
- loc_tip = [NSString stringWithFormat: @"%@",[[UserPresets objectAtIndex:rowIndex] valueForKey:@"PresetDescription"]];
- return (loc_tip);
- }
- else
- {
- loc_tip = @"No description available";
- }
- return (loc_tip);
-
-}
-
-- (id)tableView:(NSTableView *)aTableView
- objectValueForTableColumn:(NSTableColumn *)aTableColumn
- row:(int)rowIndex
-{
-id theRecord, theValue;
-
- theRecord = [UserPresets objectAtIndex:rowIndex];
- theValue = [theRecord objectForKey:[aTableColumn identifier]];
- return theValue;
-}
-
-// NSTableDataSource method that we implement to edit values directly in the table...
-- (void)tableView:(NSTableView *)aTableView
- setObjectValue:(id)anObject
- forTableColumn:(NSTableColumn *)aTableColumn
- row:(int)rowIndex
-{
- id theRecord;
-
- theRecord = [UserPresets objectAtIndex:rowIndex];
- [theRecord setObject:anObject forKey:@"PresetName"];
- /* We Sort the Presets By Factory or Custom */
- NSSortDescriptor * presetTypeDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"Type"
- ascending:YES] autorelease];
- /* We Sort the Presets Alphabetically by name */
- NSSortDescriptor * presetNameDescriptor=[[[NSSortDescriptor alloc] initWithKey:@"PresetName"
- ascending:YES selector:@selector(caseInsensitiveCompare:)] autorelease];
- NSArray *sortDescriptors=[NSArray arrayWithObjects:presetTypeDescriptor,presetNameDescriptor,nil];
- NSArray *sortedArray=[UserPresets sortedArrayUsingDescriptors:sortDescriptors];
- [UserPresets setArray:sortedArray];
- /* We Reload the New Table data for presets */
- [tableView reloadData];
- /* We save all of the preset data here */
- [self savePreset];
-}
-
-
-- (void)savePreset
-{
- [UserPresets writeToFile:UserPresetsFile atomically:YES];
-
-}
-
-
-
-- (void) controlTextDidBeginEditing: (NSNotification *) notification
-{
- [self CalculateBitrate: NULL];
-}
-
-- (void) controlTextDidEndEditing: (NSNotification *) notification
-{
- [self CalculateBitrate: NULL];
-}
-
-- (void) controlTextDidChange: (NSNotification *) notification
-{
- [self CalculateBitrate: NULL];
-}
-
-- (IBAction) OpenHomepage: (id) sender
-{
- [[NSWorkspace sharedWorkspace] openURL: [NSURL
- URLWithString:@"http://handbrake.m0k.org/"]];
-}