]> granicus.if.org Git - handbrake/commitdiff
MacGui: clean up the methods to update the destination file name and extension.
authorritsuka <damiog@gmail.com>
Sun, 1 Feb 2015 12:21:34 +0000 (12:21 +0000)
committerritsuka <damiog@gmail.com>
Sun, 1 Feb 2015 12:21:34 +0000 (12:21 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6854 b64f7644-9d1e-0410-96f1-a4d463321fa5

macosx/HBController.m
macosx/HBJob.m

index 1fdcbc25a384c5dca3f1846e825d5fe3c2a141fd..a484f1838c2c58256aa592b027f6080c177493b8 100644 (file)
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pictureSettingsDidChange) name:HBFiltersChangedNotification object:job.filters];
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(formatChanged:) name:HBContainerChangedNotification object:job];
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(customSettingUsed) name:HBVideoChangedNotification object:job.video];
-        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(autoSetM4vExtension:) name:HBMixdownChangedNotification object:job.audio];
-        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(autoSetM4vExtension:) name:HBChaptersChangedNotification object:job];
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateFileExtension:) name:HBMixdownChangedNotification object:job.audio];
+        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateFileExtension:) name:HBChaptersChangedNotification object:job];
     }
 
     // Retain the new job
 {
     NSString *extension = @(hb_container_get_default_extension(job.container));
 
-    BOOL anyCodecAC3 = [job.audio anyCodecMatches:HB_ACODEC_AC3] || [job.audio anyCodecMatches:HB_ACODEC_AC3_PASS];
-    // Chapter markers are enabled if the checkbox is ticked and we are doing p2p or we have > 1 chapter
-    BOOL chapterMarkers = (job.chaptersEnabled) &&
-    (job.range.type != HBRangeTypeChapters || job.range.chapterStart < job.range.chapterStop);
-
-    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"DefaultMpegExtension"] isEqualToString:@".m4v"] ||
-        ((YES == anyCodecAC3 || YES == chapterMarkers) &&
-         [[[NSUserDefaults standardUserDefaults] objectForKey:@"DefaultMpegExtension"] isEqualToString:@"Auto"]))
+    if (job.container & HB_MUX_MASK_MP4)
     {
-        extension = @"m4v";
+        BOOL anyCodecAC3 = [job.audio anyCodecMatches:HB_ACODEC_AC3] || [job.audio anyCodecMatches:HB_ACODEC_AC3_PASS];
+        // Chapter markers are enabled if the checkbox is ticked and we are doing p2p or we have > 1 chapter
+        BOOL chapterMarkers = (job.chaptersEnabled) &&
+        (job.range.type != HBRangeTypeChapters || job.range.chapterStart < job.range.chapterStop);
+
+        if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"DefaultMpegExtension"] isEqualToString:@".m4v"] ||
+            ((YES == anyCodecAC3 || YES == chapterMarkers) &&
+            [[[NSUserDefaults standardUserDefaults] objectForKey:@"DefaultMpegExtension"] isEqualToString:@"Auto"]))
+        {
+            extension = @"m4v";
+        }
     }
 
     return extension;
     // We're changing the chapter range - we may need to flip the m4v/mp4 extension
     if (self.job.container & HB_MUX_MASK_MP4)
     {
-        [self autoSetM4vExtension:notification];
+        [self updateFileExtension:notification];
     }
-
-    // If Auto Naming is on it might need to be update if it includes the chapters range
-    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultAutoNaming"])
+    else
     {
+        // If Auto Naming is on it might need to be update if it includes the chapters range
         [self updateFileName];
     }
 }
 
 - (void)formatChanged:(NSNotification *)notification
 {
-    if (self.job)
-    {
-        int videoContainer = self.job.container;
-
-        // set the file extension
-        const char *ext = hb_container_get_default_extension(videoContainer);
-        self.job.destURL = [[self.job.destURL URLByDeletingPathExtension] URLByAppendingPathExtension:@(ext)];
-
-        if (videoContainer & HB_MUX_MASK_MP4)
-        {
-            [self autoSetM4vExtension:notification];
-        }
-    }
+    [self updateFileExtension:notification];
+    [self customSettingUsed];
 }
 
 - (void)updateFileName
 {
-    // Generate a new file name
-    NSString *fileName = [self automaticNameForJob:self.job];
+    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultAutoNaming"])
+    {
+        // Generate a new file name
+        NSString *fileName = [self automaticNameForJob:self.job];
 
-    // Swap the old one with the new one
-    self.job.destURL = [[self.job.destURL URLByDeletingLastPathComponent] URLByAppendingPathComponent:
-                        [NSString stringWithFormat:@"%@.%@", fileName, self.job.destURL.pathExtension]];
+        // Swap the old one with the new one
+        self.job.destURL = [[self.job.destURL URLByDeletingLastPathComponent] URLByAppendingPathComponent:
+                            [NSString stringWithFormat:@"%@.%@", fileName, self.job.destURL.pathExtension]];
+    }
 }
 
-- (void)autoSetM4vExtension:(NSNotification *)notification
+- (void)updateFileExtension:(NSNotification *)notification
 {
-    if (!(self.job.container & HB_MUX_MASK_MP4))
-    {
-        return;
-    }
-
     NSString *extension = [self automaticExtForJob:self.job];
     if (![extension isEqualTo:self.job.destURL.pathExtension])
     {
     [fPresetsView deselect];
     // Change UI to show "Custom" settings are being used
     self.job.presetName = NSLocalizedString(@"Custom", @"");
-
-    // If Auto Naming is on it might need to be update if it includes the quality token
-    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultAutoNaming"])
-    {
-        [self updateFileName];
-    }
+    [self updateFileName];
 }
 
 #pragma mark - Queue progress
         // Apply the preset to the current job
         [self.job applyPreset:preset];
 
-        // If Auto Naming is on. We create an output filename of dvd name - title number
-        if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DefaultAutoNaming"])
-        {
-            [self updateFileName];
-        }
+        // If Auto Naming is on, update the destination
+        [self updateFileName];
 
         [fPreviewController reloadPreviews];
     }
index d991d970939df73f2003841fdbe9801c95afe571..f81d387a2597032a680de13469cc34096c29c3df 100644 (file)
 NSString *HBContainerChangedNotification = @"HBContainerChangedNotification";
 NSString *HBChaptersChangedNotification  = @"HBChaptersChangedNotification";
 
+@interface HBJob ()
+
+@property (nonatomic, readwrite, getter=areNotificationsEnabled) BOOL notificationsEnabled;
+
+@end
+
 @implementation HBJob
 
 - (instancetype)initWithTitle:(HBTitle *)title andPreset:(HBPreset *)preset
@@ -47,6 +53,8 @@ NSString *HBChaptersChangedNotification  = @"HBChaptersChangedNotification";
         _uuid = [[[NSUUID UUID] UUIDString] retain];
 
         [self applyPreset:preset];
+
+        _notificationsEnabled = YES;
     }
 
     return self;
@@ -54,6 +62,8 @@ NSString *HBChaptersChangedNotification  = @"HBChaptersChangedNotification";
 
 - (void)applyPreset:(HBPreset *)preset
 {
+    self.notificationsEnabled = NO;
+
     if (preset.isDefault)
     {
         self.presetName = [NSString stringWithFormat:@"%@ (Default)", preset.name];
@@ -76,6 +86,8 @@ NSString *HBChaptersChangedNotification  = @"HBChaptersChangedNotification";
 
     [@[self.audio, self.subtitles, self.filters, self.picture, self.video] makeObjectsPerformSelector:@selector(applyPreset:)
                                                                                                            withObject:content];
+
+    self.notificationsEnabled = YES;
 }
 
 - (void)applyCurrentSettingsToPreset:(NSMutableDictionary *)dict
@@ -98,8 +110,11 @@ NSString *HBChaptersChangedNotification  = @"HBChaptersChangedNotification";
     [self.subtitles containerChanged:container];
     [self.video containerChanged];
 
-    // post a notification for any interested observers to indicate that our video container has changed
-    [[NSNotificationCenter defaultCenter] postNotificationName:HBContainerChangedNotification object:self];
+    if (self.notificationsEnabled)
+    {
+        // post a notification for any interested observers to indicate that our video container has changed
+        [[NSNotificationCenter defaultCenter] postNotificationName:HBContainerChangedNotification object:self];
+    }
 }
 
 - (void)setTitle:(HBTitle *)title
@@ -112,7 +127,10 @@ NSString *HBChaptersChangedNotification  = @"HBChaptersChangedNotification";
 - (void)setChaptersEnabled:(BOOL)chaptersEnabled
 {
     _chaptersEnabled = chaptersEnabled;
-    [[NSNotificationCenter defaultCenter] postNotificationName:HBChaptersChangedNotification object:self];
+    if (self.notificationsEnabled)
+    {
+        [[NSNotificationCenter defaultCenter] postNotificationName:HBChaptersChangedNotification object:self];
+    }
 }
 
 + (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key
@@ -186,6 +204,8 @@ NSString *HBChaptersChangedNotification  = @"HBChaptersChangedNotification";
 
         copy->_chaptersEnabled = _chaptersEnabled;
         copy->_chapterTitles = [[NSMutableArray alloc] initWithArray:_chapterTitles copyItems:YES];
+
+        copy->_notificationsEnabled = _notificationsEnabled;
     }
 
     return copy;