]> granicus.if.org Git - handbrake/commitdiff
MacGui: simplify the toolbar/menu validation methods, plus some cosmetics.
authorritsuka <damiog@gmail.com>
Wed, 14 Jan 2015 07:21:57 +0000 (07:21 +0000)
committerritsuka <damiog@gmail.com>
Wed, 14 Jan 2015 07:21:57 +0000 (07:21 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6748 b64f7644-9d1e-0410-96f1-a4d463321fa5

macosx/Controller.m
macosx/HBPreviewController.m
macosx/HBPreviewGenerator.h
macosx/HBPreviewGenerator.m

index ebbf968fc772a3ce22d3f2ff1d214be7836434a7..bc57b3518051dbff5d82f6a7cf742fc5ba69be0e 100644 (file)
@@ -62,9 +62,6 @@
 
 @end
 
-/*******************************
- * HBController implementation *
- *******************************/
 @implementation HBController
 
 - (instancetype)init
         // Register the defaults preferences
         [HBPreferencesController registerUserDefaults];
 
-        /* Check for and create the App Support Preview directory if necessary */
-        NSString *previewDirectory = [[HBUtilities appSupportPath] stringByAppendingPathComponent:@"Previews"];
-        if (![[NSFileManager defaultManager] fileExistsAtPath:previewDirectory])
-        {
-            [[NSFileManager defaultManager] createDirectoryAtPath:previewDirectory
-                                      withIntermediateDirectories:YES
-                                                       attributes:nil
-                                                            error:NULL];
-        }
-
         // Inits the controllers
         outputPanel = [[HBOutputPanelController alloc] init];
         fPictureController = [[HBPictureController alloc] init];
         fPreviewController = [[HBPreviewController  alloc] initWithDelegate:self];
         fQueueController = [[HBQueueController alloc] init];
 
-        // we init the HBPresetsManager class
+        // we init the HBPresetsManager
         NSURL *presetsURL = [NSURL fileURLWithPath:[[HBUtilities appSupportPath] stringByAppendingPathComponent:@"UserPresets.plist"]];
         presetManager = [[HBPresetsManager alloc] initWithURL:presetsURL];
         _selectedPreset = [presetManager.defaultPreset retain];
         dockTile = [[HBDockTile alloc] initWithDockTile:[[NSApplication sharedApplication] dockTile]
                                                   image:appIcon];
 
-        [dockTile updateDockIcon:-1.0 withETA:@""];
-
         // Lets report the HandBrake version number here to the activity log and text log file
-        NSString *versionStringFull = [[NSString stringWithFormat:@"Handbrake Version: %@",
-                                        [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]]
-                                       stringByAppendingString:[NSString stringWithFormat: @" (%@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]];
-        [HBUtilities writeToActivityLog: "%s", [versionStringFull UTF8String]];
+        NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
+        NSString *versionStringFull = [NSString stringWithFormat:@"Handbrake Version: %@  (%@)", infoDict[@"CFBundleShortVersionString"], infoDict[@"CFBundleVersion"]];
+        [HBUtilities writeToActivityLog: "%s", versionStringFull.UTF8String];
 
-        // Optional dvd nav UseDvdNav
+        // Optionally use dvd nav
         [HBCore setDVDNav:[[[NSUserDefaults standardUserDefaults] objectForKey:@"UseDvdNav"] boolValue]];
 
-        int loggingLevel = [[[NSUserDefaults standardUserDefaults] objectForKey:@"LoggingLevel"] intValue];
         // Init libhb
+        int loggingLevel = [[[NSUserDefaults standardUserDefaults] objectForKey:@"LoggingLevel"] intValue];
         _core = [[HBCore alloc] initWithLoggingLevel:loggingLevel];
         _core.name = @"ScanCore";
 
 - (BOOL) validateToolbarItem: (NSToolbarItem *) toolbarItem
 {
     SEL action = toolbarItem.action;
-        
-    if (self.core)
+
+    if (self.core.state == HBStateScanning)
     {
-        if (self.core.state == HBStateScanning)
+        if (action == @selector(browseSources:))
         {
-            
-            if (action == @selector(browseSources:))
-            {
-                [toolbarItem setImage: [NSImage imageNamed: @"stopencode"]];
-                [toolbarItem setLabel: @"Cancel Scan"];
-                [toolbarItem setPaletteLabel: @"Cancel Scanning"];
-                [toolbarItem setToolTip: @"Cancel Scanning Source"];
-                return YES;
-            }
-            
-            if (action == @selector(Rip:) || action == @selector(addToQueue:))
-                return NO;
+            [toolbarItem setImage: [NSImage imageNamed: @"stopencode"]];
+            [toolbarItem setLabel: @"Cancel Scan"];
+            [toolbarItem setPaletteLabel: @"Cancel Scanning"];
+            [toolbarItem setToolTip: @"Cancel Scanning Source"];
+            return YES;
         }
-        else
+
+        if (action == @selector(Rip:) || action == @selector(addToQueue:))
+            return NO;
+    }
+    else
+    {
+        if (action == @selector(browseSources:))
         {
-            if (action == @selector(browseSources:))
-            {
-                [toolbarItem setImage: [NSImage imageNamed: @"source"]];
-                [toolbarItem setLabel: @"Source"];
-                [toolbarItem setPaletteLabel: @"Source"];
-                [toolbarItem setToolTip: @"Choose Video Source"];
-                return YES;
-            }
+            [toolbarItem setImage: [NSImage imageNamed: @"source"]];
+            [toolbarItem setLabel: @"Source"];
+            [toolbarItem setPaletteLabel: @"Source"];
+            [toolbarItem setToolTip: @"Choose Video Source"];
+            return YES;
         }
+    }
 
-        HBState queueState = self.queueCore.state;
+    HBState queueState = self.queueCore.state;
 
-        if (queueState == HBStateWorking || queueState == HBStateSearching || queueState == HBStateMuxing)
+    if (queueState == HBStateScanning || queueState == HBStateWorking || queueState == HBStateSearching || queueState == HBStateMuxing)
+    {
+        if (action == @selector(Rip:))
         {
-            if (action == @selector(Rip:))
-            {
-                [toolbarItem setImage: [NSImage imageNamed: @"stopencode"]];
-                [toolbarItem setLabel: @"Stop"];
-                [toolbarItem setPaletteLabel: @"Stop"];
-                [toolbarItem setToolTip: @"Stop Encoding"];
-                return YES;
-            }
-            if (action == @selector(Pause:))
-            {
-                [toolbarItem setImage: [NSImage imageNamed: @"pauseencode"]];
-                [toolbarItem setLabel: @"Pause"];
-                [toolbarItem setPaletteLabel: @"Pause Encoding"];
-                [toolbarItem setToolTip: @"Pause Encoding"];
-                return YES;
-            }
-            if (self.job)
-            {
-                if (action == @selector(addToQueue:))
-                    return YES;
-                if (action == @selector(showPicturePanel:))
-                    return YES;
-                if (action == @selector(showPreviewWindow:))
-                    return YES;
-            }
+            [toolbarItem setImage: [NSImage imageNamed: @"stopencode"]];
+            [toolbarItem setLabel: @"Stop"];
+            [toolbarItem setPaletteLabel: @"Stop"];
+            [toolbarItem setToolTip: @"Stop Encoding"];
+            return YES;
         }
-        else if (queueState == HBStatePaused)
+        if (action == @selector(Pause:))
         {
-            if (action == @selector(Pause:))
-            {
-                [toolbarItem setImage: [NSImage imageNamed: @"encode"]];
-                [toolbarItem setLabel: @"Resume"];
-                [toolbarItem setPaletteLabel: @"Resume Encoding"];
-                [toolbarItem setToolTip: @"Resume Encoding"];
-                return YES;
-            }
-            if (action == @selector(Rip:))
-                return YES;
-            if (action == @selector(addToQueue:))
-                return YES;
-            if (action == @selector(showPicturePanel:))
-                return YES;
-            if (action == @selector(showPreviewWindow:))
-                return YES;
+            [toolbarItem setImage: [NSImage imageNamed: @"pauseencode"]];
+            [toolbarItem setLabel: @"Pause"];
+            [toolbarItem setPaletteLabel: @"Pause Encoding"];
+            [toolbarItem setToolTip: @"Pause Encoding"];
+            return YES;
         }
-        else if (queueState == HBStateScanning)
+    }
+    else if (queueState == HBStatePaused)
+    {
+        if (action == @selector(Pause:))
         {
-            return NO;
+            [toolbarItem setImage: [NSImage imageNamed: @"encode"]];
+            [toolbarItem setLabel: @"Resume"];
+            [toolbarItem setPaletteLabel: @"Resume Encoding"];
+            [toolbarItem setToolTip: @"Resume Encoding"];
+            return YES;
         }
-        else if (queueState == HBStateWorkDone || queueState == HBStateScanDone || self.job)
+        if (action == @selector(Rip:))
+            return YES;
+    }
+    else
+    {
+        if (action == @selector(Rip:))
         {
-            if (action == @selector(Rip:))
-            {
-                [toolbarItem setImage: [NSImage imageNamed: @"encode"]];
-                if (QueueFileArray.count > 0)
-                    [toolbarItem setLabel: @"Start Queue"];
-                else
-                    [toolbarItem setLabel: @"Start"];
-                [toolbarItem setPaletteLabel: @"Start Encoding"];
-                [toolbarItem setToolTip: @"Start Encoding"];
-                return YES;
-            }
-            if (action == @selector(addToQueue:))
-                return YES;
-            if (action == @selector(showPicturePanel:))
-                return YES;
-            if (action == @selector(showPreviewWindow:))
-                return YES;
+            [toolbarItem setImage: [NSImage imageNamed: @"encode"]];
+            if (fPendingCount > 0)
+                [toolbarItem setLabel: @"Start Queue"];
+            else
+                [toolbarItem setLabel: @"Start"];
+            [toolbarItem setPaletteLabel: @"Start Encoding"];
+            [toolbarItem setToolTip: @"Start Encoding"];
         }
+    }
 
+    if (self.job)
+    {
+        if (action == @selector(showPicturePanel:))
+            return YES;
+        if (action == @selector(showPreviewWindow:))
+            return YES;
+        if (action == @selector(addToQueue:))
+            return YES;
+    }
+    else
+    {
+        if (action == @selector(showPicturePanel:))
+            return NO;
+        if (action == @selector(showPreviewWindow:))
+            return NO;
+        if (action == @selector(addToQueue:))
+            return NO;
     }
-    /* If there are any pending queue items, make sure the start/stop button is active */
-    if (action == @selector(Rip:) && fPendingCount > 0)
+
+    // If there are any pending queue items, make sure the start/stop button is active.
+    if (action == @selector(Rip:) && (fPendingCount > 0 || self.job))
         return YES;
     if (action == @selector(showQueueWindow:))
         return YES;
         return YES;
     if (action == @selector(showDebugOutputPanel:))
         return YES;
-    
+
     return NO;
 }
 
 - (BOOL) validateMenuItem: (NSMenuItem *) menuItem
 {
     SEL action = [menuItem action];
+    HBState queueState = self.queueCore.state;
 
-    if (self.queueCore)
-    {
-        HBState queueState = self.queueCore.state;
+    if (action == @selector(addToQueue:) || action == @selector(addAllTitlesToQueue:) || action == @selector(showPicturePanel:) || action == @selector(showAddPresetPanel:))
+        return self.job && [fWindow attachedSheet] == nil;
 
-        if (action == @selector(addToQueue:) || action == @selector(addAllTitlesToQueue:) || action == @selector(showPicturePanel:) || action == @selector(showAddPresetPanel:))
-            return self.job && [fWindow attachedSheet] == nil;
-        
-        if (action == @selector(selectDefaultPreset:))
-            return [fWindow attachedSheet] == nil;
-        if (action == @selector(Pause:))
+    if (action == @selector(selectDefaultPreset:))
+        return [fWindow attachedSheet] == nil;
+
+    if (action == @selector(Pause:))
+    {
+        if (queueState == HBStateWorking)
         {
-            if (queueState == HBStateWorking)
-            {
-                if(![[menuItem title] isEqualToString:@"Pause Encoding"])
-                    [menuItem setTitle:@"Pause Encoding"];
-                return YES;
-            }
-            else if (queueState == HBStatePaused)
-            {
-                if(![[menuItem title] isEqualToString:@"Resume Encoding"])
-                    [menuItem setTitle:@"Resume Encoding"];
-                return YES;
-            }
-            else
-                return NO;
+            if(![[menuItem title] isEqualToString:@"Pause Encoding"])
+                [menuItem setTitle:@"Pause Encoding"];
+            return YES;
         }
-        if (action == @selector(Rip:))
+        else if (queueState == HBStatePaused)
         {
-            if (queueState == HBStateWorking || queueState == HBStateMuxing || queueState == HBStatePaused)
-            {
-                if(![[menuItem title] isEqualToString:@"Stop Encoding"])
-                    [menuItem setTitle:@"Stop Encoding"];
-                return YES;
-            }
-            else if (self.job)
-            {
-                if(![[menuItem title] isEqualToString:@"Start Encoding"])
-                    [menuItem setTitle:@"Start Encoding"];
-                return [fWindow attachedSheet] == nil;
-            }
-            else
-                return NO;
+            if(![[menuItem title] isEqualToString:@"Resume Encoding"])
+                [menuItem setTitle:@"Resume Encoding"];
+            return YES;
         }
-        if (action == @selector(browseSources:))
+        else
+            return NO;
+    }
+    if (action == @selector(Rip:))
+    {
+        if (queueState == HBStateWorking || queueState == HBStateMuxing || queueState == HBStatePaused)
         {
-            if (self.core.state == HBStateScanning)
-                return NO;
-            else
-                return [fWindow attachedSheet] == nil;
+            if(![[menuItem title] isEqualToString:@"Stop Encoding"])
+                [menuItem setTitle:@"Stop Encoding"];
+            return YES;
         }
-        if (action == @selector(selectPresetFromMenu:))
+        else if (self.job)
         {
-            if ([menuItem.representedObject isEqualTo:self.selectedPreset])
-            {
-                [menuItem setState:NSOnState];
-            }
-            else
-            {
-                [menuItem setState:NSOffState];
-            }
+            if(![[menuItem title] isEqualToString:@"Start Encoding"])
+                [menuItem setTitle:@"Start Encoding"];
+            return [fWindow attachedSheet] == nil;
+        }
+        else
+            return NO;
+    }
+    if (action == @selector(browseSources:))
+    {
+        if (self.core.state == HBStateScanning)
+            return NO;
+        else
+            return [fWindow attachedSheet] == nil;
+    }
+    if (action == @selector(selectPresetFromMenu:))
+    {
+        if ([menuItem.representedObject isEqualTo:self.selectedPreset])
+        {
+            menuItem.state = NSOnState;
+        }
+        else
+        {
+            menuItem.state = NSOffState;
         }
     }
 
  *  Register a test notification and make
  *  it enabled by default
  */
-- (NSDictionary *)registrationDictionaryForGrowl 
-{ 
+- (NSDictionary *)registrationDictionaryForGrowl
+{
     return @{GROWL_NOTIFICATIONS_ALL: @[SERVICE_NAME],
              GROWL_NOTIFICATIONS_DEFAULT: @[SERVICE_NAME]};
 }
index c64ee8e1cf080ab992eb02290ac9c8b96bc9c0b8..e921574c19d0402113eaf750853c05ad9e55afeb 100644 (file)
@@ -904,8 +904,8 @@ typedef enum ViewMode : NSUInteger {
         return;
 
     self.generator.delegate = self;
-    if ([self.generator createMovieAsyncWithImageIndex:self.pictureIndex
-                                       andDuration:[[fPreviewMovieLengthPopUp titleOfSelectedItem] intValue]])
+    if ([self.generator createMovieAsyncWithImageAtIndex:self.pictureIndex
+                                       duration:[[fPreviewMovieLengthPopUp titleOfSelectedItem] intValue]])
     {
         [self switchViewToMode:ViewModeEncoding];
     }
index c8219bc541c05f597f42b7011ae3aa318c24c6c8..577fe2d6ec4c6068ee3f0b5db88d2fb511a3ef20 100644 (file)
@@ -30,7 +30,7 @@
 - (void) purgeImageCache;
 
 /* Video generator */
-- (BOOL) createMovieAsyncWithImageIndex: (NSUInteger) index andDuration: (NSUInteger) duration;
+- (BOOL) createMovieAsyncWithImageAtIndex: (NSUInteger) index duration: (NSUInteger) seconds;
 - (void) cancel;
 
 @end
index c5cd36b401adb5c9f07326ef6703d104fc049869..51c0fd12528ca10441ae3c3e94c313f2de9deec2 100644 (file)
@@ -179,7 +179,7 @@ typedef enum EncodeState : NSUInteger {
     if (![[NSFileManager defaultManager] fileExistsAtPath:previewDirectory])
     {
         if (![[NSFileManager defaultManager] createDirectoryAtPath:previewDirectory
-                                  withIntermediateDirectories:NO
+                                  withIntermediateDirectories:YES
                                                    attributes:nil
                                                         error:nil])
             return nil;
@@ -196,7 +196,7 @@ typedef enum EncodeState : NSUInteger {
  * @param index picture index in title.
  * @param duration the duration in seconds of the preview movie.
  */
-- (BOOL) createMovieAsyncWithImageIndex: (NSUInteger) index andDuration: (NSUInteger) duration;
+- (BOOL) createMovieAsyncWithImageAtIndex: (NSUInteger) index duration: (NSUInteger) seconds;
 {
     // return if an encoding if already started.
     if (self.core || index >= self.imagesCount)
@@ -234,7 +234,7 @@ typedef enum EncodeState : NSUInteger {
 
     job->start_at_preview = (int)index + 1;
     job->seek_points = (int)self.imagesCount;
-    job->pts_to_stop = duration * 90000LL;
+    job->pts_to_stop = seconds * 90000LL;
     // Note: unlike a full encode, we only send 1 pass regardless if the final encode calls for 2 passes.
     // this should suffice for a fairly accurate short preview and cuts our preview generation time in half.
     job->twopass = 0;