]> granicus.if.org Git - handbrake/commitdiff
MacGui: added a HBDockTile class to manage the dock tile.
authorritsuka <damiog@gmail.com>
Wed, 20 Aug 2014 07:29:18 +0000 (07:29 +0000)
committerritsuka <damiog@gmail.com>
Wed, 20 Aug 2014 07:29:18 +0000 (07:29 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6324 b64f7644-9d1e-0410-96f1-a4d463321fa5

macosx/Controller.h
macosx/Controller.m
macosx/HBDockTile.h [new file with mode: 0644]
macosx/HBDockTile.m [new file with mode: 0644]
macosx/HandBrake.xcodeproj/project.pbxproj

index 9ae122d21d229a0ed6cab963a598cb1fd403945a..954817d5c4f0d3ac805f1f1be6ca2902aec3b02c 100644 (file)
@@ -30,7 +30,7 @@ extern NSString *keyTitleTag;
 @class HBOutputPanelController;
 @class HBPresetsViewController;
 @class HBPresetsManager;
-@class DockTextField;
+@class HBDockTile;
 
 @interface HBController : NSObject <GrowlApplicationBridgeDelegate, HBPictureControllerDelegate, NSToolbarDelegate, NSDrawerDelegate>
 {
@@ -192,9 +192,8 @@ extern NSString *keyTitleTag;
     double                          dockIconProgress;
     
     BOOL                            fWillScan;
-    NSDockTile                    * dockTile;
-    DockTextField                 * percentField;
-    DockTextField                 * timeField;
+
+    HBDockTile  *dockTile;
 }
 - (int) getPidnum;
 
@@ -322,6 +321,4 @@ extern NSString *keyTitleTag;
 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender;
 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
 
-- (void) updateDockIcon:(double)progress withETA:(NSString*)etaStr;
-
 @end
index f17eda416c35f86339b12a1a67ec8364228e586f..9e7f1b3469ace486c6d9b56565ca69fa9062415c 100644 (file)
@@ -12,7 +12,7 @@
 #import "HBPresetsManager.h"
 #import "HBPreset.h"
 #import "HBPreviewController.h"
-#import "DockTextField.h"
+#import "HBDockTile.h"
 #import "HBUtilities.h"
 
 #import "HBPresetsViewController.h"
@@ -26,7 +26,6 @@ NSString *keyTitleTag                          = @"keyTitleTag";
 
 NSString *dragDropFiles                        = @"dragDropFiles";
 
-NSString *dockTilePercentFormat                = @"%2.1f%%";
 // DockTile update freqency in total percent increment
 #define dockTileUpdateFrequency                  0.1f
 
@@ -53,67 +52,56 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
  *******************************/
 @implementation HBController
 
-- (id)init
+- (instancetype)init
 {
     self = [super init];
-    if( !self )
+    if (self)
     {
-        return nil;
-    }
+        // Register the defaults preferences
+        [HBPreferencesController registerUserDefaults];
 
-    [HBPreferencesController registerUserDefaults];
-    fHandle = NULL;
-    fQueueEncodeLibhb = NULL;
-
-    /* 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];
-    }                                                            
-    outputPanel = [[HBOutputPanelController alloc] init];
-    fPictureController = [[HBPictureController alloc] init];
-    fQueueController = [[HBQueueController alloc] init];
-
-    /* we init the HBPresetsManager class */
-    NSURL *presetsURL = [NSURL fileURLWithPath:[[HBUtilities appSupportPath] stringByAppendingPathComponent:@"UserPresets.plist"]];
-    presetManager = [[HBPresetsManager alloc] initWithURL:presetsURL];
-    _selectedPreset = presetManager.defaultPreset;
-
-    fPreferencesController = [[HBPreferencesController alloc] init];
-    /* 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]];
-    
-    /* Load the dockTile and instiante initial text fields */
-    dockTile = [[NSApplication sharedApplication] dockTile];
-    NSImageView *iv = [[NSImageView alloc] init];
-    [iv setImage:[[NSApplication sharedApplication] applicationIconImage]];
-    [dockTile setContentView:iv];
-    [iv release];
-    
-    /* We can move the specific values out from here by subclassing NSDockTile and package everything in here */
-    /* If colors are to be chosen once and for all, we can also remove the instantiation with numerical values */
-    percentField = [[DockTextField alloc] initWithFrame:NSMakeRect(0.0f, 32.0f, [dockTile size].width, 30.0f)];
-    [percentField changeGradientColors:[NSColor colorWithDeviceRed:0.4f green:0.6f blue:0.4f alpha:1.0f] endColor:[NSColor colorWithDeviceRed:0.2f green:0.4f blue:0.2f alpha:1.0f]];
-    [iv addSubview:percentField];
-    
-    timeField = [[DockTextField alloc] initWithFrame:NSMakeRect(0.0f, 0.0f, [dockTile size].width, 30.0f)];
-    [timeField changeGradientColors:[NSColor colorWithDeviceRed:0.6f green:0.4f blue:0.4f alpha:1.0f] endColor:[NSColor colorWithDeviceRed:0.4f green:0.2f blue:0.2f alpha:1.0f]];
-    [iv addSubview:timeField];
-    
-    [self updateDockIcon:-1.0 withETA:@""];
-    
-    /* Init libhb with check for updates libhb style set to "0" so its ignored and lets sparkle take care of it */
-    int loggingLevel = [[[NSUserDefaults standardUserDefaults] objectForKey:@"LoggingLevel"] intValue];
-    fHandle = hb_init(loggingLevel, 0);
-    /* Optional dvd nav UseDvdNav*/
-    hb_dvd_set_dvdnav([[[NSUserDefaults standardUserDefaults] objectForKey:@"UseDvdNav"] boolValue]);
-    /* Init a separate instance of libhb for user scanning and setting up jobs */
-    fQueueEncodeLibhb = hb_init(loggingLevel, 0);
+        /* 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];
+        fQueueController = [[HBQueueController alloc] init];
+
+        // we init the HBPresetsManager class
+        NSURL *presetsURL = [NSURL fileURLWithPath:[[HBUtilities appSupportPath] stringByAppendingPathComponent:@"UserPresets.plist"]];
+        presetManager = [[HBPresetsManager alloc] initWithURL:presetsURL];
+        _selectedPreset = presetManager.defaultPreset;
+
+        // Load the dockTile and instiante initial text fields
+        dockTile = [[HBDockTile alloc] initWithDockTile:[[NSApplication sharedApplication] dockTile]
+                                                  image:[[NSApplication sharedApplication] applicationIconImage]];
+
+        [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]];
+
+        // Init libhb with check for updates libhb style set to "0" so its ignored and lets sparkle take care of it
+        int loggingLevel = [[[NSUserDefaults standardUserDefaults] objectForKey:@"LoggingLevel"] intValue];
+        fHandle = hb_init(loggingLevel, 0);
+
+        // Optional dvd nav UseDvdNav
+        hb_dvd_set_dvdnav([[[NSUserDefaults standardUserDefaults] objectForKey:@"UseDvdNav"] boolValue]);
+
+        // Init a separate instance of libhb for user scanning and setting up jobs
+        fQueueEncodeLibhb = hb_init(loggingLevel, 0);
+    }
 
     return self;
 }
@@ -561,6 +549,7 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
     [[NSUserDefaults standardUserDefaults] removeObjectForKey:dragDropFiles];
 
     [presetManager savePresets];
+    [presetManager release];
 
     [self closeQueueFSEvent];
     [currentQueueEncodeNameString release];
@@ -569,11 +558,11 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
        [fQueueController release];
     [fPreviewController release];
     [fPictureController release];
+    [dockTile release];
 
     hb_close(&fHandle);
     hb_close(&fQueueEncodeLibhb);
     hb_global_close();
-
 }
 
 
@@ -750,31 +739,6 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
     [fChapterTitlesController setUIEnabled:b];
 }
 
-/***********************************************************************
- * updateDockIcon
- ***********************************************************************
- * Updates two DockTextFields on the dockTile,
- * one with total percentage, the other one with the ETA.
- * The ETA string is formated by the callers
- **********************************************************************/
-- (void) updateDockIcon: (double) progress withETA:(NSString*)etaStr
-{
-    if (progress < 0.0 || progress > 1.0)
-    {
-        [percentField setHidden:YES];
-        [timeField setHidden:YES];
-    }
-    else
-    {
-        [percentField setTextToDisplay:[NSString stringWithFormat:dockTilePercentFormat,progress * 100]];
-        [percentField setHidden:NO];
-        [timeField setTextToDisplay:etaStr];
-        [timeField setHidden:NO];
-    }
-    
-    [dockTile display];
-}
-
 - (void) updateUI: (NSTimer *) timer
 {
     /* Update UI for fHandle (user scanning instance of libhb ) */
@@ -1035,7 +999,7 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
                 else
                     etaStr = @"~";
                 
-                [self updateDockIcon:progress_total withETA:etaStr];
+                [dockTile updateDockIcon:progress_total withETA:etaStr];
 
                 dockIconProgress += dockTileUpdateFrequency;
             }
@@ -1056,7 +1020,7 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
             [fRipIndicator startAnimation: nil];
             
             /* Update dock icon */
-            [self updateDockIcon:1.0 withETA:@""];
+            [dockTile updateDockIcon:1.0 withETA:@""];
             
                        break;
         }
@@ -1084,7 +1048,7 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
             [[fWindow toolbar] validateVisibleItems];
             
             /* Restore dock icon */
-            [self updateDockIcon:-1.0 withETA:@""];
+            [dockTile updateDockIcon:-1.0 withETA:@""];
             dockIconProgress = 0;
             
             if( fRipIndicatorShown )
@@ -4254,8 +4218,8 @@ fWorkingCount = 0;
     hb_list_item(list, (int)[fSrcTitlePopUp indexOfSelectedItem]);
 
     // Generate a new file name
-    NSString *fileName = [HBUtilities automaticNameForSource:[browsedSourceDisplayName stringByDeletingPathExtension]
-                                                       title: title->index
+    NSString *fileName = [HBUtilities automaticNameForSource:@(title->name)
+                                                       title:title->index
                                                     chapters:NSMakeRange([fSrcChapterStartPopUp indexOfSelectedItem] + 1, [fSrcChapterEndPopUp indexOfSelectedItem] + 1)
                                                      quality:fVideoController.selectedQualityType ? fVideoController.selectedQuality : 0
                                                      bitrate:!fVideoController.selectedQualityType ? fVideoController.selectedBitrate : 0
@@ -4680,7 +4644,12 @@ the user is using "Custom" settings by determining the sender*/
  */
 - (IBAction) showPreferencesWindow: (id) sender
 {
-    NSWindow * window = [fPreferencesController window];
+    if (fPreferencesController == nil)
+    {
+        fPreferencesController = [[HBPreferencesController alloc] init];
+    }
+
+    NSWindow *window = [fPreferencesController window];
     if (![window isVisible])
         [window center];
 
diff --git a/macosx/HBDockTile.h b/macosx/HBDockTile.h
new file mode 100644 (file)
index 0000000..f7bfde7
--- /dev/null
@@ -0,0 +1,22 @@
+//
+//  HBDockTile.h
+//  HandBrake
+//
+//  Created by Damiano Galassi on 20/08/14.
+//
+//
+
+#import <Cocoa/Cocoa.h>
+
+@interface HBDockTile : NSObject
+
+- (instancetype)initWithDockTile:(NSDockTile *)dockTile image:(NSImage *)image;
+
+/**
+ *  Updates two DockTextFields on the dockTile,
+ *  one with total percentage, the other one with the ETA.
+ *  The ETA string is formated by the callers *
+ */
+- (void)updateDockIcon:(double)progress withETA:(NSString *)etaStr;
+
+@end
diff --git a/macosx/HBDockTile.m b/macosx/HBDockTile.m
new file mode 100644 (file)
index 0000000..bfbed37
--- /dev/null
@@ -0,0 +1,77 @@
+//
+//  HBDockTile.m
+//  HandBrake
+//
+//  Created by Damiano Galassi on 20/08/14.
+//
+//
+
+#import "HBDockTile.h"
+#import "DockTextField.h"
+
+NSString *dockTilePercentFormat = @"%2.1f%%";
+
+@interface HBDockTile ()
+
+@property (nonatomic, retain) NSDockTile *dockTile;
+@property (nonatomic, retain) NSImage *image;
+@property (nonatomic, retain) DockTextField * percentField;
+@property (nonatomic, retain) DockTextField * timeField;
+
+@end
+
+@implementation HBDockTile
+
+- (instancetype)initWithDockTile:(NSDockTile *)dockTile image:(NSImage *)image
+{
+    self = [super init];
+    if (self)
+    {
+        _dockTile = [dockTile retain];
+        _image = [image retain];
+
+        NSImageView *iv = [[NSImageView alloc] init];
+        [iv setImage:_image];
+        [dockTile setContentView:iv];
+
+        _percentField = [[DockTextField alloc] initWithFrame:NSMakeRect(0.0f, 32.0f, [dockTile size].width, 30.0f)];
+        [_percentField changeGradientColors:[NSColor colorWithDeviceRed:0.4f green:0.6f blue:0.4f alpha:1.0f] endColor:[NSColor colorWithDeviceRed:0.2f green:0.4f blue:0.2f alpha:1.0f]];
+        [iv addSubview:_percentField];
+
+        _timeField = [[DockTextField alloc] initWithFrame:NSMakeRect(0.0f, 0.0f, [dockTile size].width, 30.0f)];
+        [_timeField changeGradientColors:[NSColor colorWithDeviceRed:0.6f green:0.4f blue:0.4f alpha:1.0f] endColor:[NSColor colorWithDeviceRed:0.4f green:0.2f blue:0.2f alpha:1.0f]];
+        [iv addSubview:_timeField];
+        [iv release];
+    }
+    return self;
+}
+
+- (void)dealloc
+{
+    [_dockTile release];
+    [_image release];
+    [_percentField release];
+    [_timeField release];
+
+    [super dealloc];
+}
+
+- (void)updateDockIcon:(double)progress withETA:(NSString *)etaStr
+{
+    if (progress < 0.0 || progress > 1.0)
+    {
+        [_percentField setHidden:YES];
+        [_timeField setHidden:YES];
+    }
+    else
+    {
+        [_percentField setTextToDisplay:[NSString stringWithFormat:dockTilePercentFormat, progress * 100]];
+        [_percentField setHidden:NO];
+        [_timeField setTextToDisplay:etaStr];
+        [_timeField setHidden:NO];
+    }
+
+    [_dockTile display];
+}
+
+@end
index f7a6fc85175ec2d0458bb662ddd1bc5edc3f75a6..0e098b425d8042055fe11e7ed95943a86e972d19 100644 (file)
                A9F2EB6F196F12C800066546 /* Audio.xib in Resources */ = {isa = PBXBuildFile; fileRef = A9F2EB6D196F12C800066546 /* Audio.xib */; };
                A9F472891976B7F30009EC65 /* HBSubtitlesDefaultsController.m in Sources */ = {isa = PBXBuildFile; fileRef = A9F472871976B7F30009EC65 /* HBSubtitlesDefaultsController.m */; };
                A9F4728D1976BAA70009EC65 /* HBSubtitlesSettings.m in Sources */ = {isa = PBXBuildFile; fileRef = A9F4728C1976BAA70009EC65 /* HBSubtitlesSettings.m */; };
+               A9F7102619A475EC00F61301 /* HBDockTile.m in Sources */ = {isa = PBXBuildFile; fileRef = A9F7102519A475EC00F61301 /* HBDockTile.m */; };
                D2BCB10916F5152C0084604C /* activity.png in Resources */ = {isa = PBXBuildFile; fileRef = D2BCB0F616F515230084604C /* activity.png */; };
                D2BCB10A16F5152C0084604C /* activity@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = D2BCB0F716F515230084604C /* activity@2x.png */; };
                D2BCB10B16F5152C0084604C /* addqueue.png in Resources */ = {isa = PBXBuildFile; fileRef = D2BCB0F816F515240084604C /* addqueue.png */; };
                A9F472871976B7F30009EC65 /* HBSubtitlesDefaultsController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HBSubtitlesDefaultsController.m; sourceTree = "<group>"; };
                A9F4728B1976BAA70009EC65 /* HBSubtitlesSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HBSubtitlesSettings.h; sourceTree = "<group>"; };
                A9F4728C1976BAA70009EC65 /* HBSubtitlesSettings.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HBSubtitlesSettings.m; sourceTree = "<group>"; };
+               A9F7102419A475EC00F61301 /* HBDockTile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HBDockTile.h; sourceTree = "<group>"; };
+               A9F7102519A475EC00F61301 /* HBDockTile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HBDockTile.m; sourceTree = "<group>"; };
                D2BCB0F616F515230084604C /* activity.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = activity.png; sourceTree = "<group>"; };
                D2BCB0F716F515230084604C /* activity@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "activity@2x.png"; sourceTree = "<group>"; };
                D2BCB0F816F515240084604C /* addqueue.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = addqueue.png; sourceTree = "<group>"; };
                        children = (
                                46AB433315F98A2B009C0961 /* DockTextField.h */,
                                46AB433415F98A2B009C0961 /* DockTextField.m */,
+                               A9F7102419A475EC00F61301 /* HBDockTile.h */,
+                               A9F7102519A475EC00F61301 /* HBDockTile.m */,
                                273F209914ADBE670021BE6D /* HBImageAndTextCell.h */,
                                273F209A14ADBE670021BE6D /* HBImageAndTextCell.m */,
                                A9BB0F2519A0ECE40079F1C1 /* HBHUDButtonCell.h */,
                        isa = PBXSourcesBuildPhase;
                        buildActionMask = 2147483647;
                        files = (
+                               A9F7102619A475EC00F61301 /* HBDockTile.m in Sources */,
                                A98C29C41977B10600AF5DED /* HBLanguagesSelection.m in Sources */,
                                A9BB0F2719A0ECE40079F1C1 /* HBHUDButtonCell.m in Sources */,
                                A932E273198834130047D13E /* HBAudioSettings.m in Sources */,
                                GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
                                GCC_WARN_ABOUT_RETURN_TYPE = YES;
                                GCC_WARN_UNUSED_VARIABLE = YES;
+                               MACOSX_DEPLOYMENT_TARGET = 10.6;
                                OTHER_LDFLAGS = (
                                        "-filelist",
                                        "$(EXTERNAL_BUILD)/macosx/osl.filelist.txt",
                                GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
                                GCC_WARN_ABOUT_RETURN_TYPE = YES;
                                GCC_WARN_UNUSED_VARIABLE = YES;
+                               MACOSX_DEPLOYMENT_TARGET = 10.6;
                                OTHER_LDFLAGS = (
                                        "-filelist",
                                        "$(EXTERNAL_BUILD)/macosx/osl.filelist.txt",