OSDN Git Service

BuildSystem: darwin
[handbrake-jp/handbrake-jp-git.git] / macosx / Controller.mm
index 287b494..1239ef7 100644 (file)
@@ -73,7 +73,7 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
     fPresetsBuiltin = [[HBPresets alloc] init];
     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:@"CFBundleGetInfoString"]] stringByAppendingString: [NSString stringWithFormat: @" (%@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]];
+    NSString *versionStringFull = [[NSString stringWithFormat: @"Handbrake Version: %@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]] stringByAppendingString: [NSString stringWithFormat: @" (%@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]]];
     [self writeToActivityLog: "%s", [versionStringFull UTF8String]];    
     
     return self;
@@ -106,6 +106,8 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
 
     [fPresetsOutlineView setAutosaveName:@"Presets View"];
     [fPresetsOutlineView setAutosaveExpandedItems:YES];
+    
+    dockIconProgress = 0;
 
     /* Call UpdateUI every 1/2 sec */
     [[NSRunLoop currentRunLoop] addTimer:[NSTimer
@@ -208,9 +210,14 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
 
 - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication *) app
 {
-    if ([fPreviewController fullScreen] == YES)
+    /* if we are in preview full screen mode, we need to go to
+     * windowed mode and release the display before we terminate.
+     * We do it here (instead of applicationWillTerminate) so we 
+     * release the displays and can then see the alerts below.
+     */
+    if ([fPictureController previewFullScreenMode] == YES)
     {
-        [fPreviewController goWindowedScreen:nil];
+        [fPictureController previewGoWindowed:nil];
     }
     
     hb_state_t s;
@@ -250,13 +257,14 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
 
 - (void)applicationWillTerminate:(NSNotification *)aNotification
 {
-       [browsedSourceDisplayName release];
+    
+    [browsedSourceDisplayName release];
     [outputPanel release];
        [fQueueController release];
+    [fPreviewController release];
     [fPictureController release];
     [fPictureFilterController release];
     
-    [fPreviewController release];
        hb_close(&fHandle);
     hb_close(&fQueueEncodeLibhb);
 }
@@ -589,7 +597,7 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
                                             NSLocalizedString( @"Scanning title %d of %d...", @"" ),
                                             p.title_cur, p.title_count]];
             [fScanIndicator setHidden: NO];
-            [fScanIndicator setDoubleValue: 100.0 * ( p.title_cur - 1 ) / p.title_count];
+            [fScanIndicator setDoubleValue: 100.0 * ((double)( p.title_cur - 1 ) / p.title_count)];
             break;
                }
 #undef p
@@ -666,9 +674,6 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
             [fQueueController setQueueStatusString: [NSString stringWithFormat:
                                                      NSLocalizedString( @"Queue Scanning title %d of %d...", @"" ),
                                                      p.title_cur, p.title_count]];
-            
-            [fRipIndicator setHidden: NO];
-            [fRipIndicator setDoubleValue: 100.0 * ( p.title_cur - 1 ) / p.title_count];
             break;
                }
 #undef p
@@ -676,9 +681,6 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
 #define p s.param.scandone
         case HB_STATE_SCANDONE:
         {
-            [fRipIndicator setIndeterminate: NO];
-            [fRipIndicator setDoubleValue: 0.0];
-            
                        [self writeToActivityLog:"ScanDone state received from fQueueEncodeLibhb"];
             [self processNewQueueEncode];
             [[fWindow toolbar] validateVisibleItems];
@@ -690,7 +692,6 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
 #define p s.param.working
         case HB_STATE_WORKING:
         {
-            float progress_total;
             NSMutableString * string;
                        /* Update text field */
                        string = [NSMutableString stringWithFormat: NSLocalizedString( @"Encoding: pass %d of %d, %.2f %%", @"" ), p.job_cur, p.job_count, 100.0 * p.progress];
@@ -706,9 +707,9 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
             /* Set the status string in fQueueController as well */
             [fQueueController setQueueStatusString: string];
             /* Update slider */
-                       progress_total = ( p.progress + p.job_cur - 1 ) / p.job_count;
+            double progress_total = ( p.progress + p.job_cur - 1 ) / p.job_count;
             [fRipIndicator setIndeterminate: NO];
-            [fRipIndicator setDoubleValue: 100.0 * progress_total];
+            [fRipIndicator setDoubleValue:100.0 * progress_total];
             
             // If progress bar hasn't been revealed at the bottom of the window, do
             // that now. This code used to be in doRip. I moved it to here to handle
@@ -725,10 +726,14 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
                 fRipIndicatorShown = YES;
                 
             }
-            
+
             /* Update dock icon */
-            [self UpdateDockIcon: progress_total];
-            
+            if( dockIconProgress < 100.0 * progress_total )
+            {
+                [self UpdateDockIcon: progress_total];
+                dockIconProgress += 5;
+            }
+
             break;
         }
 #undef p
@@ -768,11 +773,13 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
             /* Set the status string in fQueueController as well */
             [fQueueController setQueueStatusString: NSLocalizedString( @"Encode Finished.", @"" )];
             [fRipIndicator setIndeterminate: NO];
+            [fRipIndicator stopAnimation: nil];
             [fRipIndicator setDoubleValue: 0.0];
             [[fWindow toolbar] validateVisibleItems];
             
             /* Restore dock icon */
             [self UpdateDockIcon: -1.0];
+            dockIconProgress = 0;
             
             if( fRipIndicatorShown )
             {
@@ -856,7 +863,7 @@ static NSString *        ChooseSourceIdentifier             = @"Choose Source It
 }
 
 /* We use this to write messages to stderr from the macgui which show up in the activity window and log*/
-- (void) writeToActivityLog:(char *) format, ...
+- (void) writeToActivityLog:(const char *) format, ...
 {
     va_list args;
     va_start(args, format);
@@ -2063,33 +2070,32 @@ fWorkingCount = 0;
 }
 
 /* this is actually called from the queue controller to modify the queue array and return it back to the queue controller */
-- (void)moveObjectsInQueueArray:(NSMutableArray *)array fromIndexes:(NSIndexSet *)indexSet toIndex:(unsigned)insertIndex
+- (void)moveObjectsInQueueArray:(NSMutableArray *)array fromIndexes:(NSIndexSet *)indexSet toIndex:(NSUInteger)insertIndex
 {
-    unsigned index = [indexSet lastIndex];
-    unsigned aboveInsertIndexCount = 0;
+    NSUInteger index = [indexSet lastIndex];
+    NSUInteger aboveInsertIndexCount = 0;
     
-    while (index != NSNotFound)
-    {
-        unsigned removeIndex;
-        
-        if (index >= insertIndex)
-        {
-            removeIndex = index + aboveInsertIndexCount;
-            aboveInsertIndexCount++;
-        }
-        else
-        {
-            removeIndex = index;
-            insertIndex--;
-        }
-        
-        id object = [[QueueFileArray objectAtIndex:removeIndex] retain];
-        [QueueFileArray removeObjectAtIndex:removeIndex];
-        [QueueFileArray insertObject:object atIndex:insertIndex];
-        [object release];
+    
+    NSUInteger removeIndex;
         
-        index = [indexSet indexLessThanIndex:index];
+    if (index >= insertIndex)
+    {
+        removeIndex = index + aboveInsertIndexCount;
+        aboveInsertIndexCount++;
+    }
+    else
+    {
+        removeIndex = index;
+        insertIndex--;
     }
+
+    id object = [[QueueFileArray objectAtIndex:removeIndex] retain];
+    [QueueFileArray removeObjectAtIndex:removeIndex];
+    [QueueFileArray insertObject:object atIndex:insertIndex];
+    [object release];
+        
+    index = [indexSet indexLessThanIndex:index];
+
    /* We save all of the Queue data here 
     * and it also gets sent back to the queue controller*/
     [self saveQueueFileItem]; 
@@ -5328,7 +5334,7 @@ the user is using "Custom" settings by determining the sender*/
 }
 
 /* We use this to deterimine children of an item */
-- (id)outlineView:(NSOutlineView *)fPresetsOutlineView child:(int)index ofItem:(id)item
+- (id)outlineView:(NSOutlineView *)fPresetsOutlineView child:(NSInteger)index ofItem:(id)item
 {
     
     /* we need to return the count of the array in ChildrenArray for this folder */
@@ -5344,7 +5350,7 @@ the user is using "Custom" settings by determining the sender*/
             children = [item objectForKey:@"ChildrenArray"];
         }
     }   
-    if ((children == nil) || ([children count] <= index))
+    if ((children == nil) || ( [children count] <= (NSUInteger) index))
     {
         return nil;
     }
@@ -5547,7 +5553,7 @@ return YES;
     return YES;
 }
 
-- (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
+- (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index
 {
        
        // Don't allow dropping ONTO an item since they can't really contain any children.
@@ -5576,7 +5582,7 @@ return YES;
 
 
 
-- (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index
+- (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)index
 {
     /* first, lets see if we are dropping into a folder */
     if ([[fPresetsOutlineView itemAtRow:index] objectForKey:@"Folder"] && [[[fPresetsOutlineView itemAtRow:index] objectForKey:@"Folder"] intValue] == 1) // if its a folder
@@ -5604,33 +5610,30 @@ return YES;
     return YES;
 }
 
-- (void)moveObjectsInPresetsArray:(NSMutableArray *)array fromIndexes:(NSIndexSet *)indexSet toIndex:(unsigned)insertIndex
+- (void)moveObjectsInPresetsArray:(NSMutableArray *)array fromIndexes:(NSIndexSet *)indexSet toIndex:(NSUInteger)insertIndex
 {
-    unsigned index = [indexSet lastIndex];
-    unsigned aboveInsertIndexCount = 0;
+    NSUInteger index = [indexSet lastIndex];
+    NSUInteger aboveInsertIndexCount = 0;
     
-    while (index != NSNotFound)
+    NSUInteger removeIndex;
+
+    if (index >= insertIndex)
     {
-        unsigned removeIndex;
-        
-        if (index >= insertIndex)
-        {
-            removeIndex = index + aboveInsertIndexCount;
-            aboveInsertIndexCount++;
-        }
-        else
-        {
-            removeIndex = index;
-            insertIndex--;
-        }
-        
-        id object = [[array objectAtIndex:removeIndex] retain];
-        [array removeObjectAtIndex:removeIndex];
-        [array insertObject:object atIndex:insertIndex];
-        [object release];
-        
-        index = [indexSet indexLessThanIndex:index];
+        removeIndex = index + aboveInsertIndexCount;
+        aboveInsertIndexCount++;
     }
+    else
+    {
+        removeIndex = index;
+        insertIndex--;
+    }
+
+    id object = [[array objectAtIndex:removeIndex] retain];
+    [array removeObjectAtIndex:removeIndex];
+    [array insertObject:object atIndex:insertIndex];
+    [object release];
+
+    index = [indexSet indexLessThanIndex:index];
 }