OSDN Git Service

macGui: Growl Support initial implementation
[handbrake-jp/handbrake-jp-git.git] / macosx / Controller.mm
index 9e614fa..7caaf7f 100644 (file)
@@ -9,6 +9,10 @@
 
 #define _(a) NSLocalizedString(a,NULL)
 
+
+
+
+
 static int FormatSettings[3][4] =
   { { HB_MUX_MP4 | HB_VCODEC_FFMPEG | HB_ACODEC_FAAC,
       HB_MUX_MP4 | HB_VCODEC_X264   | HB_ACODEC_FAAC,
@@ -37,18 +41,25 @@ static int FormatSettings[3][4] =
 
 - (void) applicationDidFinishLaunching: (NSNotification *) notification
 {
+
+
     int    build;
     char * version;
 
+
     /* Init libhb */
     fHandle = hb_init( HB_DEBUG_NONE, [[NSUserDefaults
         standardUserDefaults] boolForKey:@"CheckForUpdates"] );
-    
+       /* Set the Growl Delegate */
+       HBController *hbGrowlDelegate = [[HBController alloc] init];
+       [GrowlApplicationBridge setGrowlDelegate: hbGrowlDelegate];    
     /* Init others controllers */
     [fScanController    SetHandle: fHandle];
     [fPictureController SetHandle: fHandle];
     [fQueueController   SetHandle: fHandle];
        
+    fChapterTitlesDelegate = [[ChapterTitles alloc] init];
+    [fChapterTable setDataSource:fChapterTitlesDelegate];
 
      /* Call UpdateUI every 2/10 sec */
     [[NSRunLoop currentRunLoop] addTimer: [NSTimer
@@ -95,7 +106,9 @@ static int FormatSettings[3][4] =
 
     [self TranslateStrings];
 
-       /* Init User Presets .plist */
+
+//[self registrationDictionaryForGrowl];
+/* Init User Presets .plist */
        /* We declare the default NSFileManager into fileManager */
        NSFileManager * fileManager = [NSFileManager defaultManager];
        //presetPrefs = [[NSUserDefaults standardUserDefaults] retain];
@@ -223,7 +236,18 @@ static int FormatSettings[3][4] =
 
 }
 
+// register a test notification and make
+// it enabled by default
+#define SERVICE_NAME @"Encode Done"
+- (NSDictionary *)registrationDictionaryForGrowl 
+{ 
+NSDictionary *registrationDictionary = [NSDictionary dictionaryWithObjectsAndKeys: 
+[NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_ALL, 
+[NSArray arrayWithObjects:SERVICE_NAME,nil], GROWL_NOTIFICATIONS_DEFAULT, 
+nil]; 
 
+return registrationDictionary; 
+} 
 - (void) TranslateStrings
 {
     [fSrcDVD1Field      setStringValue: _( @"DVD:" )];
@@ -520,45 +544,65 @@ static int FormatSettings[3][4] =
 
         case HB_STATE_WORKDONE:
         {
-            [self EnableUI: YES];
+            //[self EnableUI: YES];
             [fStatusField setStringValue: _( @"Done." )];
             [fRipIndicator setIndeterminate: NO];
             [fRipIndicator setDoubleValue: 0.0];
             [fRipButton setTitle: _( @"Start" )];
-
+                       
             /* Restore dock icon */
             [self UpdateDockIcon: -1.0];
-
+                       
             [fPauseButton setEnabled: NO];
             [fPauseButton setTitle: _( @"Pause" )];
             [fRipButton setEnabled: YES];
             [fRipButton setTitle: _( @"Start" )];
-
+                       
             /* FIXME */
             hb_job_t * job;
             while( ( job = hb_job( fHandle, 0 ) ) )
             {
                 hb_rem( fHandle, job );
             }
+            
+                       if (fEncodeState != 2) // if the encode has not been cancelled
+                       {
+                               /* Lets alert the user that the encode has finished */
+                               /*Growl Notification*/
+                               [self showGrowlDoneNotification: NULL];
+                               /*On Screen Notification*/
+                               int status;
+                               NSBeep();
+                               status = NSRunAlertPanel(@"Put down that cocktail...",@"your HandBrake encode is done!", @"OK", nil, nil);
+                               //[NSApp requestUserAttention:NSInformationalRequest];
+                               [NSApp requestUserAttention:NSCriticalRequest];
+                               if ( status == NSAlertDefaultReturn ) 
+                               {
+                                       [self EnableUI: YES];
+                               }
+                       }
+                       else
+                       {
+                       [self EnableUI: YES];
+                       }
             break;
         }
     }
 
-    /* FIXME: we should only do that when necessary */
-    if( [fQueueCheck state] == NSOnState )
-    {
+    /* Lets show the queue status
+       here in the main window*/
+
         int count = hb_count( fHandle );
         if( count )
         {
-            [fQueueCheck setTitle: [NSString stringWithFormat:
-                @"Enable queue (%d task%s in queue)",
+            [fQueueStatus setStringValue: [NSString stringWithFormat:
+                @"%d task%s in the queue",
                 count, ( count > 1 ) ? "s" : ""]];
         }
         else
         {
-            [fQueueCheck setTitle: @"Enable queue (no task in queue)"];
+            [fQueueStatus setStringValue: @""];
         }
-    }
 
     [[NSRunLoop currentRunLoop] addTimer: [NSTimer
         scheduledTimerWithTimeInterval: 0.2 target: self
@@ -566,6 +610,20 @@ static int FormatSettings[3][4] =
         forMode: NSModalPanelRunLoopMode];
 }
 
+-(IBAction)showGrowlDoneNotification:(id)sender
+{
+
+  
+  [GrowlApplicationBridge 
+          notifyWithTitle:@"Put down that cocktail..." 
+              description:@"Thank You for using HandBrake" 
+         notificationName:SERVICE_NAME
+                 iconData:nil 
+                 priority:0 
+                 isSticky:1 
+             clickContext:nil];
+}
+
 - (void) EnableUI: (bool) b
 {
     NSControl * controls[] =
@@ -580,7 +638,7 @@ static int FormatSettings[3][4] =
         fAudLang1Field, fAudLang1PopUp, fAudLang2Field, fAudLang2PopUp,
         fAudTrack1MixLabel, fAudTrack1MixPopUp, fAudTrack2MixLabel, fAudTrack2MixPopUp,
         fAudRateField, fAudRatePopUp, fAudBitrateField,
-        fAudBitratePopUp, fPictureButton, fQueueCheck
+        fAudBitratePopUp, fPictureButton,fQueueStatus
                fPicSrcWidth,fPicSrcHeight,fPicSettingWidth,fPicSettingHeight,
                fPicSettingARkeep,fPicSettingDeinterlace,fPicSettingARkeepDsply,
                fPicSettingDeinterlaceDsply,fPicLabelSettings,fPicLabelSrc,fPicLabelOutp,
@@ -738,13 +796,12 @@ static int FormatSettings[3][4] =
     hb_title_t * title = (hb_title_t *) hb_list_item( list,
             [fSrcTitlePopUp indexOfSelectedItem] );
     hb_job_t * job = title->job;
+    //int i;
 
     /* Chapter selection */
     job->chapter_start = [fSrcChapterStartPopUp indexOfSelectedItem] + 1;
     job->chapter_end   = [fSrcChapterEndPopUp   indexOfSelectedItem] + 1;
        
-
-
     /* Format and codecs */
     int format = [fDstFormatPopUp indexOfSelectedItem];
     int codecs = [fDstCodecsPopUp indexOfSelectedItem];
@@ -755,7 +812,7 @@ static int FormatSettings[3][4] =
        mpeg4 and the checkbox being checked */
        if ([fDstFormatPopUp indexOfSelectedItem] == 0 && [fCreateChapterMarkers state] == NSOnState)
        {
-       job->chapter_markers = 1;
+        job->chapter_markers = 1;
        }
        else
        {
@@ -876,13 +933,7 @@ static int FormatSettings[3][4] =
 
 }
 
-- (IBAction) EnableQueue: (id) sender
-{
-    bool e = ( [fQueueCheck state] == NSOnState );
-    [fQueueAddButton  setHidden: !e];
-    [fQueueShowButton setHidden: !e];
-    [fRipButton       setTitle: e ? @"Start" : @"Start"];
-}
+
 
 - (IBAction) AddToQueue: (id) sender
 {
@@ -941,25 +992,21 @@ static int FormatSettings[3][4] =
 
 - (IBAction) Rip: (id) sender
 {
-   
-    
     /* Rip or Cancel ? */
     if( [[fRipButton title] isEqualToString: _( @"Cancel" )] )
     {
         [self Cancel: sender];
         return;
     }
-
-    if( [fQueueCheck state] == NSOffState )
-    {
-
-                       [self AddToQueue: sender];
-
-               
-
-    }
-
-    /* We check for duplicate name here */
+       /* if there is no job in the queue, then add it to the queue and rip 
+       otherwise, there are already jobs in queue, so just rip the queue */
+       int count = hb_count( fHandle );
+       if( count < 1 )
+        {
+               [self AddToQueue: sender];
+               }
+    
+           /* We check for duplicate name here */
        if( [[NSFileManager defaultManager] fileExistsAtPath:
             [fDstFile2Field stringValue]] )
     {
@@ -1017,6 +1064,8 @@ static int FormatSettings[3][4] =
 {
     /* Let libhb do the job */
     hb_start( fHandle );
+       /*set the fEncodeState State */
+       fEncodeState = 1;
 
     /* Disable interface */
    [self EnableUI: NO];
@@ -1040,6 +1089,8 @@ static int FormatSettings[3][4] =
         hb_stop( fHandle );
         [fPauseButton setEnabled: NO];
         [fRipButton   setEnabled: NO];
+               /*set the fEncodeState State */
+            fEncodeState = 2;
     }
 }
 
@@ -1136,7 +1187,6 @@ static int FormatSettings[3][4] =
        //[self EncoderPopUpChanged: NULL];
        /* END Get and set the initial pic size for display */ 
 
-
     /* Update subtitle popups */
     hb_subtitle_t * subtitle;
     [fSubPopUp removeAllItems];
@@ -1151,6 +1201,10 @@ static int FormatSettings[3][4] =
             subtitle->lang] action: NULL keyEquivalent: @""];
     }
     [fSubPopUp selectItemAtIndex: 0];
+    
+    /* Update chapter table */
+    [fChapterTitlesDelegate resetWithTitle:title];
+    [fChapterTable reloadData];
 
     /* Update audio popups */
     [self AddAllAudioTracksToPopUp: fAudLang1PopUp];
@@ -1846,10 +1900,11 @@ the user is using "Custom" settings by determining the sender*/
 {
     /* First, we delete any existing built in presets */
     [self DeleteFactoryPresets: sender];
-    /* Then, we re-create new built in presets programmatically CreatePS3Preset*/
+    /* Then, we re-create new built in presets programmatically CreatePSPPreset*/
        [UserPresets addObject:[self CreateIpodPreset]];
        [UserPresets addObject:[self CreateAppleTVPreset]];
        [UserPresets addObject:[self CreatePSThreePreset]];
+       [UserPresets addObject:[self CreatePSPPreset]];
     [self AddPreset];
 }
 - (IBAction)DeleteFactoryPresets:(id)sender
@@ -2224,6 +2279,72 @@ the user is using "Custom" settings by determining the sender*/
     return preset;
 
 }
+- (NSDictionary *)CreatePSPPreset
+{
+    NSMutableDictionary *preset = [[NSMutableDictionary alloc] init];
+       /* Get the New Preset Name from the field in the AddPresetPanel */
+    [preset setObject:@"HB-PSP" forKey:@"PresetName"];
+       /*Set whether or not this is a user preset where 0 is factory, 1 is user*/
+       [preset setObject:[NSNumber numberWithInt:0] forKey:@"Type"];
+       /*Set whether or not this is default, at creation set to 0*/
+       [preset setObject:[NSNumber numberWithInt:0] forKey:@"Default"];
+       /*Get the whether or not to apply pic settings in the AddPresetPanel*/
+       [preset setObject:[NSNumber numberWithInt:1] forKey:@"UsesPictureSettings"];
+       /* File Format */
+    [preset setObject:@"MP4 file" forKey:@"FileFormat"];
+       /* Chapter Markers*/
+        [preset setObject:[NSNumber numberWithInt:1] forKey:@"ChapterMarkers"];
+       /* Codecs */
+       [preset setObject:@"MPEG-4 Video / AAC Audio" forKey:@"FileCodecs"];
+       /* Video encoder */
+       [preset setObject:@"FFmpeg" forKey:@"VideoEncoder"];
+       /* x264 Option String (We can use this to tweak the appleTV output)*/
+       [preset setObject:@"" forKey:@"x264Option"];
+       /* Video quality */
+       [preset setObject:[NSNumber numberWithInt:1] forKey:@"VideoQualityType"];
+       [preset setObject:[fVidTargetSizeField stringValue] forKey:@"VideoTargetSize"];
+       [preset setObject:@"1024" forKey:@"VideoAvgBitrate"];
+       [preset setObject:[NSNumber numberWithFloat:[fVidQualitySlider floatValue]] forKey:@"VideoQualitySlider"];
+       
+       /* Video framerate */
+       [preset setObject:@"Same as source" forKey:@"VideoFramerate"];
+       /* GrayScale */
+       [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoGrayScale"];
+       /* 2 Pass Encoding */
+       [preset setObject:[NSNumber numberWithInt:0] forKey:@"VideoTwoPass"];
+       
+       /*Picture Settings*/
+       /* For PS3 we only want to retain UsesMaxPictureSettings
+       which depend on the source dvd picture settings, so we don't
+       record the current dvd's picture info since it will vary from
+       source to source*/
+       /* Use Max Picture settings for whatever the dvd is.*/
+       [preset setObject:[NSNumber numberWithInt:0] forKey:@"UsesMaxPictureSettings"];
+       [preset setObject:@"368" forKey:@"PictureWidth"];
+       [preset setObject:@"208" forKey:@"PictureHeight"];
+       [preset setObject:[NSNumber numberWithInt:1] forKey:@"PictureKeepRatio"];
+       [preset setObject:[NSNumber numberWithInt:0] forKey:@"PictureDeinterlace"];
+       [preset setObject:[NSNumber numberWithInt:0] forKey:@"PicturePAR"];
+       /* Set crop settings here */
+       /* The Auto Crop Matrix in the Picture Window autodetects differences in crop settings */
+       //[preset setObject:[NSNumber numberWithInt:job->crop[0]] forKey:@"PictureTopCrop"];
+    //[preset setObject:[NSNumber numberWithInt:job->crop[1]] forKey:@"PictureBottomCrop"];
+       //[preset setObject:[NSNumber numberWithInt:job->crop[2]] forKey:@"PictureLeftCrop"];
+       //[preset setObject:[NSNumber numberWithInt:job->crop[3]] forKey:@"PictureRightCrop"];
+       
+       /*Audio*/
+       /* Audio Sample Rate*/
+       [preset setObject:@"48" forKey:@"AudioSampleRate"];
+       /* Audio Bitrate Rate*/
+       [preset setObject:@"128" forKey:@"AudioBitRate"];
+       /* Subtitles*/
+       [preset setObject:@"None" forKey:@"Subtitles"];
+       
+
+    [preset autorelease];
+    return preset;
+
+}
 
 
 - (IBAction)DeletePreset:(id)sender
@@ -2238,6 +2359,7 @@ the user is using "Custom" settings by determining the sender*/
         return;
     /* Alert user before deleting preset */
        /* Comment out for now, tie to user pref eventually */
+
     //NSBeep();
     status = NSRunAlertPanel(@"Warning!", @"Are you sure that you want to delete the selected preset?", @"OK", @"Cancel", nil);