OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / macosx / HBSubtitles.m
index d0e959c..aca6c02 100644 (file)
     
 }
 
+/* used to return the current subtitleArray to controller.m */
 - (NSMutableArray*) getSubtitleArray
 {
     return subtitleArray;
 
 - (void)containerChanged:(int) newContainer
 {
-container = newContainer;
+    container = newContainer;
+}
+
+- (void)setNewSubtitles:(NSMutableArray*) newSubtitleArray
+{
+    /* Note: we need to look for external subtitles so it can be added to the source array track.
+     * Remember the source container subs are already loaded with resetTitle which is already called
+     * so any external sub sources need to be added to our source subs here
+     */
+    
+    int i = 0;
+    NSEnumerator *enumerator = [newSubtitleArray objectEnumerator];
+    id tempObject;
+    while ( tempObject = [enumerator nextObject] )  
+    {
+        /* We have an srt track */
+        if ([[tempObject objectForKey:@"subtitleSourceTrackType"] isEqualToString:@"SRT"])
+        {
+            NSString *filePath = [tempObject objectForKey:@"subtitleSourceSrtFilePath"];
+            /* Start replicate the add new srt code above */
+            /* Create a new entry for the subtitle source array so it shows up in our subtitle source list */
+            NSString *displayname = [filePath lastPathComponent];// grok an appropriate display name from the srt subtitle */
+            /* create a dictionary of source subtitle information to store in our array */
+            NSMutableDictionary *newSubtitleSourceTrack = [[NSMutableDictionary alloc] init];
+            /* Subtitle Source track popup index */
+            [newSubtitleSourceTrack setObject:[NSNumber numberWithInt:[subtitleSourceArray count]+1] forKey:@"sourceTrackNum"];
+            /* Subtitle Source track type */
+            [newSubtitleSourceTrack setObject:displayname forKey:@"sourceTrackName"];
+            /* Subtitle Source track type (Source, Srt, etc.) */
+            [newSubtitleSourceTrack setObject:@"SRT" forKey:@"sourceTrackType"];
+            [newSubtitleSourceTrack setObject:@"SRT" forKey:@"subtitleSourceTrackType"];
+            /* Subtitle Source track type */
+            [newSubtitleSourceTrack setObject:filePath forKey:@"sourceSrtFilePath"];
+            /* Subtitle Source track popup isPictureSub */ 
+            [newSubtitleSourceTrack setObject:[NSNumber numberWithInt:0] forKey:@"sourceTrackisPictureSub"];
+            
+            [subtitleSourceArray addObject:newSubtitleSourceTrack];
+            [newSubtitleSourceTrack autorelease];
+            /* END replicate the add new srt code above */
+        }
+        i++;
+    }
+    
+    
+    /*Set the subtitleArray to the newSubtitleArray */
+    [subtitleArray setArray:newSubtitleArray];
 }
    
 #pragma mark -
@@ -711,18 +757,34 @@ container = newContainer;
     if ([[aTableColumn identifier] isEqualToString:@"track"])
     {
         
-        /* since mp4 only supports burned in vobsubs (bitmap) we need to make sure burned in is specified */
+        /* Since currently no quicktime based playback devices support soft vobsubs (bitmap) in mp4, we make sure
+         * "burned in" is specified  by default to avoid massive confusion and anarchy. However we also want to guard against
+         * multiple burned in subtitle tracks as libhb would ignore all but the first one anyway. Plus it would probably be
+         * stupid.
+         */
         if (container == HB_MUX_MP4 && [anObject intValue] != 0)
         {
-            /* so, if isPictureSub = TRUE and we are mp4, we now have to A) set burned-in to 1 and b) remove any other
-             * tracks specified that are burned in */
             if ([[[subtitleArray objectAtIndex:rowIndex] objectForKey:@"subtitleSourceTrackisPictureSub"] intValue] == 1)
             {
-                [[subtitleArray objectAtIndex:rowIndex] setObject:[NSNumber numberWithInt:1] forKey:@"subtitleTrackBurned"];
+                /* lets see if there are currently any burned in subs specified */
+                NSEnumerator *enumerator = [subtitleArray objectEnumerator];
+                id tempObject;
+                BOOL subtrackBurnedInFound = NO;
+                while ( tempObject = [enumerator nextObject] )  
+                {
+                    if ([[tempObject objectForKey:@"subtitleTrackBurned"] intValue] == 1)
+                    {
+                        subtrackBurnedInFound = YES;
+                    }
+                }
+                /* if we have no current vobsub set to burn it in ... burn it in by default */
+                if(!subtrackBurnedInFound)
+                {
+                    [[subtitleArray objectAtIndex:rowIndex] setObject:[NSNumber numberWithInt:1] forKey:@"subtitleTrackBurned"];
+                }
             }
         }
         
-        
         /* We use the track popup index number (presumes index 0 is "None" which is ignored and only used to remove tracks if need be)
          * to determine whether to 1 modify an existing track, 2. add a new empty "None" track or 3. remove an existing track.
          */
@@ -792,11 +854,10 @@ container = newContainer;
         else if ([[aTableColumn identifier] isEqualToString:@"burned"])
         {
             [aCell setState:[[[subtitleArray objectAtIndex:rowIndex] objectForKey:@"subtitleTrackBurned"] intValue]];
-            /* Disable the "Burned-In" checkbox if a) the track is "None", b) the subtitle track is text (we do not support burning in
-             * text subs, or c) we are mp4 and the track is a vobsub (picture sub) */
+            /* Disable the "Burned-In" checkbox if a) the track is "None" or b) the subtitle track is text (we do not support burning in
+             * text subs) */
             if ([[[subtitleArray objectAtIndex:rowIndex] objectForKey:@"subtitleSourceTrackNum"] intValue] == 0 ||
-                [[[subtitleArray objectAtIndex:rowIndex] objectForKey:@"subtitleSourceTrackisPictureSub"] intValue] == 0 ||
-                (container == HB_MUX_MP4 && [[[subtitleArray objectAtIndex:rowIndex] objectForKey:@"subtitleSourceTrackisPictureSub"] intValue] == 1))
+                [[[subtitleArray objectAtIndex:rowIndex] objectForKey:@"subtitleSourceTrackisPictureSub"] intValue] == 0)
             {
                 [aCell setEnabled:NO];
             }
@@ -869,50 +930,7 @@ container = newContainer;
         }
         
     }
-    
-    
-    if (container == HB_MUX_MP4)
-    {
-        /* now remove any other tracks that are set as burned and are picturesubs */
-        int i = 0;
-        int removedTracks = 0;
-        NSEnumerator *enumerator = [subtitleArray objectEnumerator];
-        id tempObject;
-        NSMutableArray *tempArrayToDelete = [NSMutableArray array];
-        BOOL removeTrack = NO; 
-        while ( tempObject = [enumerator nextObject] )  
-        {
-            
-            if ([[tempObject objectForKey:@"subtitleSourceTrackisPictureSub"] intValue] == 1)
-            {
-                /* if this is the first vobsub mark it. if not, remove it */
-                if (removeTrack == NO)
-                {
-                    /* make sure that this is set to be burned in */
-                    [tempObject setObject:[NSNumber numberWithInt:1] forKey:@"subtitleTrackBurned"];
-                    removeTrack = YES;
-                }
-                else
-                {
-                    [tempArrayToDelete addObject:tempObject];
-                    removedTracks ++;
-                }
-            }
-            
-            i++;
-        }
-        /* check to see if there are tracks to remove from the array */
-        if ([tempArrayToDelete count] > 0)
-        {
-            /* Popup a warning that hb only support one pic sub being burned in with mp4 */
-            int status;
-            status = NSRunAlertPanel(@"More than one vobsub is not supported in an mp4...",@"Your first vobsub track will now be used.", @"OK", nil, nil);
-            [NSApp requestUserAttention:NSCriticalRequest];
-            
-            [subtitleArray removeObjectsInArray:tempArrayToDelete];
-            [aTableView reloadData];
-        }
-    }
+     
 }