]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/MainMenu.m
macosx: adapt setter for freetype settings
[vlc] / modules / gui / macosx / MainMenu.m
index 91bc9596d5f044ca663096348d294fcd3f7e22e8..9e68545aa5ec01b8c2fa527e873bcfa851d1cfba 100644 (file)
@@ -64,7 +64,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
     } else {
         _o_sharedInstance = [super init];
 
-        o_ptc_translation_dict = [NSDictionary dictionaryWithObjectsAndKeys:
+        o_ptc_translation_dict = [[NSDictionary alloc] initWithObjectsAndKeys:
                       _NS("Track Number"),  TRACKNUM_COLUMN,
                       _NS("Title"),         TITLE_COLUMN,
                       _NS("Author"),        ARTIST_COLUMN,
@@ -77,8 +77,9 @@ static VLCMainMenu *_o_sharedInstance = nil;
                       _NS("URI"),           URI_COLUMN,
                       nil];
         // this array also assigns tags (index) to type of menu item
-        o_ptc_menuorder = [NSArray arrayWithObjects:TRACKNUM_COLUMN, TITLE_COLUMN, ARTIST_COLUMN, DURATION_COLUMN,
-                       GENRE_COLUMN, ALBUM_COLUMN, DESCRIPTION_COLUMN, DATE_COLUMN, LANGUAGE_COLUMN, URI_COLUMN, nil];
+        o_ptc_menuorder = [[NSArray alloc] initWithObjects: TRACKNUM_COLUMN, TITLE_COLUMN,
+                           ARTIST_COLUMN, DURATION_COLUMN, GENRE_COLUMN, ALBUM_COLUMN,
+                           DESCRIPTION_COLUMN, DATE_COLUMN, LANGUAGE_COLUMN, URI_COLUMN, nil];
     }
 
     return _o_sharedInstance;
@@ -110,6 +111,9 @@ static VLCMainMenu *_o_sharedInstance = nil;
 
     [self releaseRepresentedObjects:[NSApp mainMenu]];
 
+    [o_ptc_translation_dict release];
+    [o_ptc_menuorder release];
+
     [super dealloc];
 }
 
@@ -259,6 +263,41 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [self setupExtensionsMenu];
 
     [self refreshAudioDeviceList];
+
+    /* setup subtitles menu */
+    [self setupMenu: o_mu_subtitle_size withIntList:"freetype-rel-fontsize" andSelector:@selector(switchSubtitleOption:)];
+    [self setupMenu: o_mu_subtitle_textcolor withIntList:"freetype-color" andSelector:@selector(switchSubtitleOption:)];
+    [o_mi_subtitle_bgopacity_sld setIntValue: config_GetInt(VLC_OBJECT(p_intf), "freetype-background-opacity")];
+    [self setupMenu: o_mu_subtitle_bgcolor withIntList:"freetype-background-color" andSelector:@selector(switchSubtitleOption:)];
+    [self setupMenu: o_mu_subtitle_outlinethickness withIntList:"freetype-outline-thickness" andSelector:@selector(switchSubtitleOption:)];
+}
+
+- (void)setupMenu: (NSMenu*)menu withIntList: (char *)psz_name andSelector:(SEL)selector
+{
+    module_config_t *p_item;
+
+    [menu removeAllItems];
+    p_item = config_FindConfig(VLC_OBJECT(p_intf), psz_name);
+
+    /* serious problem, if no item found */
+    assert(p_item);
+
+    for (int i = 0; i < p_item->list_count; i++) {
+        NSMenuItem *mi;
+        if (p_item->list_text != NULL)
+            mi = [[NSMenuItem alloc] initWithTitle: _NS(p_item->list_text[i]) action:NULL keyEquivalent: @""];
+        else if (p_item->list.i[i])
+            mi = [[NSMenuItem alloc] initWithTitle: [NSString stringWithFormat: @"%d", p_item->list.i[i]] action:NULL keyEquivalent: @""];
+        else
+            msg_Err(p_intf, "item %d of pref %s failed to be created", i, psz_name);
+        [mi setTarget:self];
+        [mi setAction:selector];
+        [mi setTag:p_item->list.i[i]];
+        [mi setRepresentedObject:@(psz_name)];
+        [menu addItem: [mi autorelease]];
+        if (p_item->value.i == p_item->list.i[i])
+            [mi setState:NSOnState];
+    }
 }
 
 - (void)initStrings
@@ -340,8 +379,8 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [o_mi_mute setTitle: _NS("Mute")];
     [o_mi_audiotrack setTitle: _NS("Audio Track")];
     [o_mu_audiotrack setTitle: _NS("Audio Track")];
-    [o_mi_channels setTitle: _NS("Audio Channels")];
-    [o_mu_channels setTitle: _NS("Audio Channels")];
+    [o_mi_channels setTitle: _NS("Stereo audio mode")];
+    [o_mu_channels setTitle: _NS("Stereo audio mode")];
     [o_mi_device setTitle: _NS("Audio Device")];
     [o_mu_device setTitle: _NS("Audio Device")];
     [o_mi_visual setTitle: _NS("Visualizations")];
@@ -357,8 +396,8 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [o_mi_snapshot setTitle: _NS("Snapshot")];
     [o_mi_videotrack setTitle: _NS("Video Track")];
     [o_mu_videotrack setTitle: _NS("Video Track")];
-    [o_mi_aspect_ratio setTitle: _NS("Aspect-ratio")];
-    [o_mu_aspect_ratio setTitle: _NS("Aspect-ratio")];
+    [o_mi_aspect_ratio setTitle: _NS("Aspect ratio")];
+    [o_mu_aspect_ratio setTitle: _NS("Aspect ratio")];
     [o_mi_crop setTitle: _NS("Crop")];
     [o_mu_crop setTitle: _NS("Crop")];
     [o_mi_screen setTitle: _NS("Fullscreen Video Device")];
@@ -371,9 +410,16 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [o_mu_ffmpeg_pp setTitle: _NS("Post processing")];
 
     [o_mu_subtitles setTitle:_NS("Subtitles")];
+    [o_mi_openSubtitleFile setTitle: _NS("Add Subtitle File...")];
     [o_mi_subtitle_track setTitle: _NS("Subtitles Track")];
     [o_mu_subtitle_tracks setTitle: _NS("Subtitles Track")];
-    [o_mi_openSubtitleFile setTitle: _NS("Open File...")];
+    [o_mi_subtitle_size setTitle: _NS("Text Size")];
+    [o_mi_subtitle_textcolor setTitle: _NS("Text Color")];
+    [o_mi_subtitle_outlinethickness setTitle: _NS("Outline Thickness")];
+    [o_mi_subtitle_bgopacity setView: o_mi_subtitle_bgopacity_view];
+    [o_mi_subtitle_bgopacity_lbl setStringValue: _NS("Background Opacity")];
+    [o_mi_subtitle_bgopacity_lbl_gray setStringValue: _NS("Background Opacity")];
+    [o_mi_subtitle_bgcolor setTitle: _NS("Background Color")];
     [o_mi_teletext setTitle: _NS("Teletext")];
     [o_mi_teletext_transparent setTitle: _NS("Transparent")];
     [o_mi_teletext_index setTitle: _NS("Index")];
@@ -464,7 +510,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
     NSArray *menuitems_array = [the_menu itemArray];
     NSUInteger menuItemCount = [menuitems_array count];
     for (NSUInteger i=0; i < menuItemCount; i++) {
-        NSMenuItem *one_item = [menuitems_array objectAtIndex: i];
+        NSMenuItem *one_item = [menuitems_array objectAtIndex:i];
         if ([one_item hasSubmenu])
             [self releaseRepresentedObjects: [one_item submenu]];
 
@@ -558,11 +604,11 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [o_mitem setTarget: self];
     NSRect s_rect;
     for (NSUInteger i = 0; i < count; i++) {
-        s_rect = [[o_screens objectAtIndex: i] frame];
+        s_rect = [[o_screens objectAtIndex:i] frame];
         [o_submenu addItemWithTitle: [NSString stringWithFormat: @"%@ %li (%ix%i)", _NS("Screen"), i+1,
                                       (int)s_rect.size.width, (int)s_rect.size.height] action:@selector(toggleFullscreenDevice:) keyEquivalent:@""];
         o_mitem = [o_submenu itemAtIndex:i+1];
-        [o_mitem setTag: (int)[[o_screens objectAtIndex: i] displayID]];
+        [o_mitem setTag: (int)[[o_screens objectAtIndex:i] displayID]];
         [o_mitem setEnabled: YES];
         [o_mitem setTarget: self];
     }
@@ -590,6 +636,14 @@ static VLCMainMenu *_o_sharedInstance = nil;
 - (void)setSubtitleMenuEnabled:(BOOL)b_enabled
 {
     [o_mi_openSubtitleFile setEnabled: b_enabled];
+    if (b_enabled) {
+        [o_mi_subtitle_bgopacity_lbl_gray setHidden: YES];
+        [o_mi_subtitle_bgopacity_lbl setHidden: NO];
+    } else {
+        [o_mi_subtitle_bgopacity_lbl_gray setHidden: NO];
+        [o_mi_subtitle_bgopacity_lbl setHidden: YES];
+    }
+    [o_mi_subtitle_bgopacity_sld setEnabled: b_enabled];
     [o_mi_teletext setEnabled: b_enabled];
 }
 
@@ -664,10 +718,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
 
 - (IBAction)toggleSidebar:(id)sender
 {
-    BOOL b_value = !config_GetInt(VLCIntf, "macosx-show-sidebar");
-    config_PutInt(VLCIntf, "macosx-show-sidebar", b_value);
     [[[VLCMain sharedInstance] mainWindow] toggleLeftSubSplitView];
-    [o_mi_toggleSidebar setState: b_value];
 }
 
 - (void)updateSidebarMenuItem
@@ -682,7 +733,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [[o_mu_playlistTableColumns            itemWithTag: i_tag] setState: i_new_state];
     [[o_mu_playlistTableColumnsContextMenu itemWithTag: i_tag] setState: i_new_state];
 
-    NSString *o_column = [o_ptc_menuorder objectAtIndex: i_tag];
+    NSString *o_column = [o_ptc_menuorder objectAtIndex:i_tag];
     [[[VLCMain sharedInstance] playlist] setColumn: o_column state: i_new_state translationDict: o_ptc_translation_dict];
 }
 
@@ -758,6 +809,8 @@ static VLCMainMenu *_o_sharedInstance = nil;
 
     [[o_mu_device itemWithTag:[[NSString stringWithFormat:@"%s", currentDevice] intValue]] setState:NSOnState];
 
+    free(currentDevice);
+
     for (NSUInteger x = 0; x < n; x++) {
         free(ids[x]);
         free(names[x]);
@@ -878,8 +931,8 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [openPanel setCanChooseFiles: YES];
     [openPanel setCanChooseDirectories: NO];
     [openPanel setAllowsMultipleSelection: YES];
-    [openPanel setAllowedFileTypes: [NSArray arrayWithObjects: @"cdg",@"@idx",@"srt",@"sub",@"utf",@"ass",@"ssa",@"aqt",@"jss",@"psb",@"rt",@"smi",@"txt",@"smil", nil]];
-    [openPanel setDirectoryURL:[NSURL fileURLWithPath:[[NSString stringWithUTF8String:path] stringByExpandingTildeInPath]]];
+    [openPanel setAllowedFileTypes: @[@"cdg",@"@idx",@"srt",@"sub",@"utf",@"ass",@"ssa",@"aqt",@"jss",@"psb",@"rt",@"smi",@"txt",@"smil"]];
+    [openPanel setDirectoryURL:[NSURL fileURLWithPath:[@(path) stringByExpandingTildeInPath]]];
     i_returnValue = [openPanel runModal];
     free(path);
 
@@ -891,15 +944,34 @@ static VLCMainMenu *_o_sharedInstance = nil;
         c = [[openPanel URLs] count];
 
         for (int i = 0; i < c ; i++) {
-            msg_Dbg(VLCIntf, "loading subs from %s", [[[[openPanel URLs] objectAtIndex: i] path] UTF8String]);
-            if (input_AddSubtitle(p_input, [[[[openPanel URLs] objectAtIndex: i] path] UTF8String], TRUE))
+            msg_Dbg(VLCIntf, "loading subs from %s", [[[[openPanel URLs] objectAtIndex:i] path] UTF8String]);
+            if (input_AddSubtitle(p_input, [[[[openPanel URLs] objectAtIndex:i] path] UTF8String], TRUE))
                 msg_Warn(VLCIntf, "unable to load subtitles from '%s'",
-                         [[[[openPanel URLs] objectAtIndex: i] path] UTF8String]);
+                         [[[[openPanel URLs] objectAtIndex:i] path] UTF8String]);
         }
     }
     vlc_object_release(p_input);
 }
 
+- (IBAction)switchSubtitleOption:(id)sender
+{
+    int intValue = [sender tag];
+    NSString *representedObject = [sender representedObject];
+
+    config_PutInt(p_intf, [representedObject UTF8String], intValue);
+
+    NSMenu *menu = [sender menu];
+    NSUInteger count = [menu numberOfItems];
+    for (NSUInteger x = 0; x < count; x++)
+        [[menu itemAtIndex:x] setState:NSOffState];
+    [[menu itemWithTag:intValue] setState:NSOnState];
+}
+
+- (IBAction)switchSubtitleBackgroundOpacity:(id)sender
+{
+    config_PutInt(p_intf, "freetype-background-opacity", [sender intValue]);
+}
+
 - (IBAction)telxTransparent:(id)sender
 {
     vlc_object_t *p_vbi;
@@ -1046,7 +1118,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
 - (IBAction)showLicense:(id)sender
 {
     [self initAbout];
-    [o_about showGPL: sender];
+    [o_about showGPL];
 }
 
 - (IBAction)viewHelp:(id)sender
@@ -1228,7 +1300,7 @@ static VLCMainMenu *_o_sharedInstance = nil;
     [o_parent setEnabled:NO];
 
     /* Aspect Ratio */
-    if ([[o_parent title] isEqualToString: _NS("Aspect-ratio")] == YES) {
+    if ([[o_parent title] isEqualToString: _NS("Aspect ratio")] == YES) {
         NSMenuItem *o_lmi_tmp2;
         o_lmi_tmp2 = [o_menu addItemWithTitle: _NS("Lock Aspect Ratio") action: @selector(lockVideosAspectRatio:) keyEquivalent: @""];
         [o_lmi_tmp2 setTarget: [[VLCMain sharedInstance] controls]];
@@ -1434,6 +1506,19 @@ static VLCMainMenu *_o_sharedInstance = nil;
         }
 
         [self setupMenus]; /* Make sure video menu is up to date */
+
+    } else if ([o_title isEqualToString: _NS("Add Subtitle File...")]) {
+        bEnabled = [o_mi isEnabled];
+        [self setupMenus]; /* Make sure subtitles menu is up to date */
+    } else {
+        NSMenuItem *o_mi_parent = [o_mi parentItem];
+        if (o_mi_parent == o_mi_subtitle_size || o_mi == o_mi_subtitle_size ||
+            o_mi_parent == o_mi_subtitle_textcolor || o_mi == o_mi_subtitle_textcolor ||
+            o_mi_parent == o_mi_subtitle_bgcolor || o_mi == o_mi_subtitle_bgcolor ||
+            o_mi_parent == o_mi_subtitle_bgopacity || o_mi == o_mi_subtitle_bgopacity ||
+            o_mi_parent == o_mi_subtitle_outlinethickness || o_mi == o_mi_subtitle_outlinethickness ||
+            o_mi_parent == o_mi_teletext || o_mi == o_mi_teletext)
+            bEnabled = o_mi_openSubtitleFile.isEnabled;
     }
 
     /* Special case for telx menu */