From: dynaflash Date: Fri, 8 May 2009 04:24:46 +0000 (+0000) Subject: MacGui: Preset Import / Export initial implementation and auto updating of built... X-Git-Url: http://git.osdn.jp/view?a=commitdiff_plain;h=d0e64b1ce0adb0f331422299de3cb25590927e4b;p=handbrake-jp%2Fhandbrake-jp-git.git MacGui: Preset Import / Export initial implementation and auto updating of built in presets. - Preset Import / Export: -- Export is only available to custom user presets. -- Export is only the selected preset at this time. -- Exported presets will be tagged with their build number. -- Import of mutiple presets. --- Compatible with LinGui presets. --- NOT compatible with WinGui presets at this time. - Built-In preset auto-updating: -- Adds the key/value pair to the UserPresets.plist file for key "PresetBuildNumber". -- If the HandBrake.app build number as defined in the Info.plist key "CFBundleVersion" is > the built in presets "PresetBuildNumber" then the - (IBAction)addFactoryPresets:(id)sender is called to automagically update the built in presets. -- An alert window is shown along with a system beep ( can be turned off in Preferences -> Advanced for svn mavens and devs) to tell the user that the built in presets are going to be updated. -- NOTE: First launch of this build will initiate a built in preset update even though the built in presets are the same, since the build number will be added to the built in presets. git-svn-id: svn://localhost/HandBrake/trunk@2405 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- diff --git a/macosx/Controller.h b/macosx/Controller.h index 6a8e587b..87e7cd6a 100644 --- a/macosx/Controller.h +++ b/macosx/Controller.h @@ -364,10 +364,19 @@ BOOL fIsDragging; - (void)outlineView:(NSOutlineView *)fPresetsOutlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item; /* We use this to provide tooltips for the items in the presets outline view */ - (NSString *)outlineView:(NSOutlineView *)fPresetsOutlineView toolTipForCell:(NSCell *)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tc item:(id)item mouseLocation:(NSPoint)mouseLocation; - +- (void) checkBuiltInsForUpdates; /* We use this to actually select the preset and act accordingly */ - (IBAction)selectPreset:(id)sender; +/* Export / Import Presets */ +- (IBAction) browseExportPresetFile: (id) sender; +- (void) browseExportPresetFileDone: (NSSavePanel *) sheet + returnCode: (int) returnCode contextInfo: (void *) contextInfo; + +- (IBAction) browseImportPresetFile: (id) sender; +- (void) browseImportPresetDone: (NSSavePanel *) sheet + returnCode: (int) returnCode contextInfo: (void *) contextInfo; + /* Manage User presets */ - (void) loadPresets; - (IBAction) customSettingUsed: (id) sender; diff --git a/macosx/Controller.mm b/macosx/Controller.mm index 1164f0f2..40e42c73 100644 --- a/macosx/Controller.mm +++ b/macosx/Controller.mm @@ -6296,6 +6296,46 @@ return YES; [self addFactoryPresets:nil]; } [fPresetsOutlineView reloadData]; + + [self checkBuiltInsForUpdates]; +} + +- (void) checkBuiltInsForUpdates { + + BOOL updateBuiltInPresets = NO; + int i = 0; + NSEnumerator *enumerator = [UserPresets objectEnumerator]; + id tempObject; + while (tempObject = [enumerator nextObject]) + { + /* iterate through the built in presets to see if any have an old build number */ + NSMutableDictionary *thisPresetDict = tempObject; + /*Key Type == 0 is built in, and key PresetBuildNumber is the build number it was created with */ + if ([[thisPresetDict objectForKey:@"Type"] intValue] == 0) + { + if (![thisPresetDict objectForKey:@"PresetBuildNumber"] || [[thisPresetDict objectForKey:@"PresetBuildNumber"] intValue] < [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] intValue]) + { + updateBuiltInPresets = YES; + } + } + i++; + } + /* if we have built in presets to update, then do so AlertBuiltInPresetUpdate*/ + if ( updateBuiltInPresets == YES) + { + if( [[NSUserDefaults standardUserDefaults] boolForKey:@"AlertBuiltInPresetUpdate"] == YES) + { + /* Show an alert window that built in presets will be updated */ + /*On Screen Notification*/ + int status; + NSBeep(); + status = NSRunAlertPanel(@"HandBrake has determined your built in presets are out of date...",@"HandBrake will now update your built-in presets.", @"OK", nil, nil); + [NSApp requestUserAttention:NSCriticalRequest]; + } + /* when alert is dismissed, go ahead and update the built in presets */ + [self addFactoryPresets:nil]; + } + } @@ -6383,6 +6423,9 @@ return YES; - (NSDictionary *)createPreset { NSMutableDictionary *preset = [[NSMutableDictionary alloc] init]; + /* Preset build number */ + [preset setObject:[NSString stringWithFormat: @"%d", [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] intValue]] forKey:@"PresetBuildNumber"]; + [preset setObject:[fPresetNewName stringValue] forKey:@"PresetName"]; /* Get the New Preset Name from the field in the AddPresetPanel */ [preset setObject:[fPresetNewName stringValue] forKey:@"PresetName"]; /* Set whether or not this is to be a folder fPresetNewFolderCheck*/ @@ -6605,6 +6648,119 @@ return YES; } } + +#pragma mark - +#pragma mark Import Export Preset(s) + +- (IBAction) browseExportPresetFile: (id) sender +{ + /* Open a panel to let the user choose where and how to save the export file */ + NSSavePanel * panel = [NSSavePanel savePanel]; + /* We get the current file name and path from the destination field here */ + NSString *defaultExportDirectory = [NSString stringWithFormat: @"%@/Desktop/", NSHomeDirectory()]; + + [panel beginSheetForDirectory: defaultExportDirectory file: @"HB_Export.plist" + modalForWindow: fWindow modalDelegate: self + didEndSelector: @selector( browseExportPresetFileDone:returnCode:contextInfo: ) + contextInfo: NULL]; +} + +- (void) browseExportPresetFileDone: (NSSavePanel *) sheet + returnCode: (int) returnCode contextInfo: (void *) contextInfo +{ + if( returnCode == NSOKButton ) + { + NSString *presetExportDirectory = [[sheet filename] stringByDeletingLastPathComponent]; + NSString *exportPresetsFile = [sheet filename]; + [[NSUserDefaults standardUserDefaults] setObject:presetExportDirectory forKey:@"LastPresetExportDirectory"]; + /* We check for the presets.plist */ + if ([[NSFileManager defaultManager] fileExistsAtPath:exportPresetsFile] == 0) + { + [[NSFileManager defaultManager] createFileAtPath:exportPresetsFile contents:nil attributes:nil]; + } + NSMutableArray * presetsToExport = [[NSMutableArray alloc] initWithContentsOfFile:exportPresetsFile]; + if (nil == presetsToExport) + { + presetsToExport = [[NSMutableArray alloc] init]; + + /* now get and add selected presets to export */ + + } + if ([fPresetsOutlineView selectedRow] >= 0 && [[[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]] objectForKey:@"Folder"] intValue] != 1) + { + [presetsToExport addObject:[fPresetsOutlineView itemAtRow:[fPresetsOutlineView selectedRow]]]; + [presetsToExport writeToFile:exportPresetsFile atomically:YES]; + + } + + } +} + + +- (IBAction) browseImportPresetFile: (id) sender +{ + + NSOpenPanel * panel; + + panel = [NSOpenPanel openPanel]; + [panel setAllowsMultipleSelection: NO]; + [panel setCanChooseFiles: YES]; + [panel setCanChooseDirectories: NO ]; + NSString * sourceDirectory; + if ([[NSUserDefaults standardUserDefaults] stringForKey:@"LastPresetImportDirectory"]) + { + sourceDirectory = [[NSUserDefaults standardUserDefaults] stringForKey:@"LastPresetImportDirectory"]; + } + else + { + sourceDirectory = @"~/Desktop"; + sourceDirectory = [sourceDirectory stringByExpandingTildeInPath]; + } + /* we open up the browse sources sheet here and call for browseSourcesDone after the sheet is closed + * to evaluate whether we want to specify a title, we pass the sender in the contextInfo variable + */ + /* set this for allowed file types, not sure if we should allow xml or not */ + NSArray *fileTypes = [NSArray arrayWithObjects:@"plist", @"xml", nil]; + [panel beginSheetForDirectory: sourceDirectory file: nil types: fileTypes + modalForWindow: fWindow modalDelegate: self + didEndSelector: @selector( browseImportPresetDone:returnCode:contextInfo: ) + contextInfo: sender]; +} + +- (void) browseImportPresetDone: (NSSavePanel *) sheet + returnCode: (int) returnCode contextInfo: (void *) contextInfo +{ + if( returnCode == NSOKButton ) + { + NSString *importPresetsDirectory = [[sheet filename] stringByDeletingLastPathComponent]; + NSString *importPresetsFile = [sheet filename]; + [[NSUserDefaults standardUserDefaults] setObject:importPresetsDirectory forKey:@"LastPresetImportDirectory"]; + /* NOTE: here we need to do some sanity checking to verify we do not hose up our presets file */ + NSMutableArray * presetsToImport = [[NSMutableArray alloc] initWithContentsOfFile:importPresetsFile]; + /* iterate though the new array of presets to import and add them to our presets array */ + int i = 0; + NSEnumerator *enumerator = [presetsToImport objectEnumerator]; + id tempObject; + while (tempObject = [enumerator nextObject]) + { + /* make any changes to the incoming preset we see fit */ + /* make sure the incoming preset is not tagged as default */ + [tempObject setObject:[NSNumber numberWithInt:0] forKey:@"Default"]; + /* prepend "(imported) to the name of the incoming preset for clarification since it can be changed */ + NSString * prependedName = [@"(import) " stringByAppendingString:[tempObject objectForKey:@"PresetName"]] ; + [tempObject setObject:prependedName forKey:@"PresetName"]; + + /* actually add the new preset to our presets array */ + [UserPresets addObject:tempObject]; + i++; + } + [presetsToImport autorelease]; + [self sortPresets]; + [self addPreset]; + + } +} + #pragma mark - #pragma mark Manage Default Preset @@ -6863,16 +7019,33 @@ return YES; } - /* We use this method to recreate new, updated factory - presets */ + /* We use this method to recreate new, updated factory presets */ - (IBAction)addFactoryPresets:(id)sender { - - /* First, we delete any existing built in presets */ + + /* First, we delete any existing built in presets */ [self deleteFactoryPresets: sender]; /* Then we generate new built in presets programmatically with fPresetsBuiltin - * which is all setup in HBPresets.h and HBPresets.m*/ + * which is all setup in HBPresets.h and HBPresets.m*/ [fPresetsBuiltin generateBuiltinPresets:UserPresets]; + /* update build number for built in presets */ + /* iterate though the new array of presets to import and add them to our presets array */ + int i = 0; + NSEnumerator *enumerator = [UserPresets objectEnumerator]; + id tempObject; + while (tempObject = [enumerator nextObject]) + { + /* Record the apps current build number in the PresetBuildNumber key */ + if ([[tempObject objectForKey:@"Type"] intValue] == 0) // Type 0 is a built in preset + { + /* Preset build number */ + [[UserPresets objectAtIndex:i] setObject:[NSString stringWithFormat: @"%d", [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] intValue]] forKey:@"PresetBuildNumber"]; + } + i++; + } + /* report the built in preset updating to the activity log */ + [self writeToActivityLog: "built in presets updated to build number: %d", [[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] intValue]]; + [self sortPresets]; [self addPreset]; diff --git a/macosx/English.lproj/MainMenu.xib b/macosx/English.lproj/MainMenu.xib index da8f6db9..be20ff85 100644 --- a/macosx/English.lproj/MainMenu.xib +++ b/macosx/English.lproj/MainMenu.xib @@ -8,6 +8,7 @@ 353.00 YES + @@ -3487,6 +3488,22 @@ + + + Export ... + + 2147483647 + + + + + + Import ... + + 2147483647 + + + Select Default Preset @@ -6160,6 +6177,22 @@ 5187 + + + browseExportPresetFile: + + + + 5191 + + + + browseImportPresetFile: + + + + 5193 + @@ -7441,6 +7474,8 @@ + + @@ -9332,6 +9367,16 @@ + + 5188 + + + + + 5192 + + + @@ -10078,6 +10123,8 @@ 5184.IBPluginDependency 5184.ImportedFromIB2 5185.IBPluginDependency + 5188.IBPluginDependency + 5192.IBPluginDependency 56.IBPluginDependency 56.ImportedFromIB2 57.IBPluginDependency @@ -10369,7 +10416,7 @@ com.apple.InterfaceBuilder.CocoaPlugin - {{195, 732}, {236, 93}} + {{195, 692}, {236, 133}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -10863,6 +10910,8 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -10897,7 +10946,7 @@ - 5187 + 5193 @@ -10923,7 +10972,9 @@ audioTrackMixdownChanged: audioTrackPopUpChanged: autoSetM4vExtension: + browseExportPresetFile: browseFile: + browseImportPresetFile: browseSources: calculateBitrate: calculatePictureSizing: @@ -11014,6 +11065,8 @@ id id id + id + id diff --git a/macosx/English.lproj/Preferences.xib b/macosx/English.lproj/Preferences.xib index 0ef8e594..bb9f7001 100644 --- a/macosx/English.lproj/Preferences.xib +++ b/macosx/English.lproj/Preferences.xib @@ -8,7 +8,6 @@ 353.00 YES - @@ -59,12 +58,12 @@ YES - UseDvdNav + AlertBuiltInPresetUpdate YES - + 256 YES @@ -450,7 +449,6 @@ {492, 231} - NSView NSControl @@ -806,7 +804,7 @@ 256 - {{84, 201}, {367, 18}} + {{84, 253}, {367, 18}} YES @@ -827,7 +825,7 @@ 256 - {{40, 202}, {41, 17}} + {{40, 254}, {41, 17}} YES @@ -843,7 +841,7 @@ 256 - {{83, 179}, {301, 17}} + {{83, 231}, {301, 17}} YES @@ -859,7 +857,7 @@ 256 - {{37, 140}, {239, 17}} + {{37, 192}, {239, 17}} YES @@ -875,7 +873,7 @@ 256 - {{71, 39}, {184, 17}} + {{71, 91}, {184, 17}} YES @@ -891,7 +889,7 @@ 256 - {{40, 63}, {32, 17}} + {{40, 115}, {32, 17}} YES @@ -907,7 +905,7 @@ 256 - {{75, 61}, {367, 18}} + {{75, 113}, {367, 18}} YES @@ -928,7 +926,7 @@ 256 - {{41, 105}, {367, 18}} + {{41, 157}, {367, 18}} YES @@ -946,10 +944,31 @@ 25 + + + 256 + {{41, 56}, {269, 18}} + + YES + + 67239424 + 0 + Alert when updating built-in presets + + + 1211912703 + 2 + + + + 200 + 25 + + 268 - {{276, 135}, {66, 22}} + {{276, 187}, {66, 22}} YES @@ -1038,7 +1057,7 @@ 268 - {{386, 174}, {66, 22}} + {{386, 226}, {66, 22}} YES @@ -1113,7 +1132,7 @@ 268 - {{255, 34}, {66, 22}} + {{255, 86}, {66, 22}} YES @@ -1177,7 +1196,7 @@ - {480, 239} + {479, 291} NSView @@ -1476,6 +1495,22 @@ 400 + + + value: values.AlertBuiltInPresetUpdate + + + + + + value: values.AlertBuiltInPresetUpdate + value + values.AlertBuiltInPresetUpdate + 2 + + + 403 + @@ -1687,6 +1722,7 @@ + Advanced @@ -2139,6 +2175,20 @@ + + 401 + + + YES + + + + + + 402 + + + @@ -2279,6 +2329,9 @@ 398.IBPluginDependency 398.ImportedFromIB2 399.IBPluginDependency + 401.IBPluginDependency + 401.ImportedFromIB2 + 402.IBPluginDependency 5.IBEditorWindowLastContentRect 5.IBWindowTemplateEditedContentRect 5.ImportedFromIB2 @@ -2307,7 +2360,7 @@ {{73, 774}, {500, 82}} com.apple.InterfaceBuilder.CocoaPlugin - {{404, 534}, {480, 239}} + {{404, 482}, {479, 291}} com.apple.InterfaceBuilder.CocoaPlugin {{0, 650}, {500, 184}} @@ -2427,6 +2480,9 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + com.apple.InterfaceBuilder.CocoaPlugin {{69, 656}, {500, 200}} {{69, 656}, {500, 200}} @@ -2460,7 +2516,7 @@ - 400 + 403 diff --git a/macosx/HBPreferencesController.m b/macosx/HBPreferencesController.m index 7f947e12..0deddbf2 100644 --- a/macosx/HBPreferencesController.m +++ b/macosx/HBPreferencesController.m @@ -59,7 +59,8 @@ @"NO", @"EncodeLogLocation", @"10", @"PreviewsNumber", @"", @"Drawer Size", - @"0.25", @"x264CqSliderFractional", + @"0.25", @"x264CqSliderFractional", + @"YES", @"AlertBuiltInPresetUpdate", nil]]; }