1 /*****************************************************************************
2 * sfilter.m: MacOS X Subpicture filters dialogue
3 *****************************************************************************
4 * Copyright (C) 2005-2008 the VideoLAN team
7 * Authors: Felix Paul Kühne <fkuehne -at -videolan -dot- org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
25 /*****************************************************************************
27 * the code used to bind with VLC's core is partially based upon the
28 * RC-interface, written by Antoine Cellerier and Mark F. Moriarty
29 * (members of the VideoLAN team)
30 *****************************************************************************/
36 - check for memory leaks
37 - save the preferences, if requested
40 @implementation VLCsFilters
42 static VLCsFilters *_o_sharedInstance = nil;
44 + (VLCsFilters *)sharedInstance
46 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
51 if (_o_sharedInstance) {
54 _o_sharedInstance = [super init];
57 return _o_sharedInstance;
69 [o_sfilter_win setTitle: _NS("Subpicture Filters")];
70 [[o_sfilter_tabView tabViewItemAtIndex: 0] setLabel: _NS("Logo")];
71 [[o_sfilter_tabView tabViewItemAtIndex: 1] setLabel: _NS("Time")];
72 [[o_sfilter_tabView tabViewItemAtIndex: 2] setLabel: _NS("Marquee")];
73 [o_sfilter_saveSettings_ckb setTitle: _NS("Save settings")];
74 [o_logo_image_btn setTitle: _NS("Browse...")];
75 [o_logo_enabled_ckb setTitle: _NS("Enabled")];
76 [o_logo_image_lbl setStringValue: _NS("Image:")];
77 [o_logo_pos_lbl setStringValue: _NS("Position:")];
78 [o_logo_opaque_lbl setStringValue: _NS("Opaqueness")];
79 [o_time_enabled_ckb setTitle: _NS("Enabled")];
80 [o_time_stamp_lbl setStringValue: _NS("Timestamp:")];
81 [o_time_size_lbl setStringValue: _NS("Size:")];
82 [o_time_color_lbl setStringValue: _NS("Color:")];
83 [o_time_opaque_lbl setStringValue: _NS("Opaqueness:")];
84 [o_time_pos_lbl setStringValue: _NS("Position:")];
85 [o_time_size_inPx_lbl setStringValue: _NS("(in pixels)")];
86 [o_marq_enabled_ckb setTitle: _NS("Enabled")];
87 [o_marq_color_lbl setStringValue: _NS("Color:")];
88 [o_marq_marq_lbl setStringValue: _NS("Marquee:")];
89 [o_marq_opaque_lbl setStringValue: _NS("Opaqueness")];
90 [o_marq_tmOut_lbl setStringValue: _NS("Timeout:")];
91 [o_marq_tmOut_ms_lbl setStringValue: _NS("ms")];
92 [o_marq_pos_lbl setStringValue: _NS("Position:")];
93 [o_marq_size_lbl setStringValue: _NS("Size:")];
94 [o_time_color_lbl setStringValue: _NS("(in pixels)")];
99 /* colors as implemented at the beginning of marq.c and time.c
100 * feel free to add more colors, but remember to add them to these files
101 * as well to keep a certain level of consistency across the interfaces */
119 o_default = [NSArray arrayWithObjects: _NS("Default"), @"-1", nil];
120 o_black = [NSArray arrayWithObjects: _NS("Black"), @"0x000000", nil];
121 o_gray = [NSArray arrayWithObjects: _NS("Gray"), @"0x808080", nil];
122 o_silver = [NSArray arrayWithObjects: _NS("Silver"), @"0xC0C0C0", nil];
123 o_white = [NSArray arrayWithObjects: _NS("White"), @"0xFFFFFF", nil];
124 o_maroon = [NSArray arrayWithObjects: _NS("Maroon"), @"0x800000", nil];
125 o_red = [NSArray arrayWithObjects: _NS("Red"), @"0xFF0000", nil];
126 o_fuchsia = [NSArray arrayWithObjects: _NS("Fuchsia"), @"0xFF00FF", nil];
127 o_yellow = [NSArray arrayWithObjects: _NS("Yellow"), @"0xFFFF00", nil];
128 o_olive = [NSArray arrayWithObjects: _NS("Olive"), @"0x808000", nil];
129 o_green = [NSArray arrayWithObjects: _NS("Green"), @"0x008000", nil];
130 o_teal = [NSArray arrayWithObjects: _NS("Teal"), @"0x008080", nil];
131 o_lime = [NSArray arrayWithObjects: _NS("Lime"), @"0x00FF00", nil];
132 o_purple = [NSArray arrayWithObjects: _NS("Purple"), @"0x800080", nil];
133 o_navy = [NSArray arrayWithObjects: _NS("Navy"), @"0x000080", nil];
134 o_blue = [NSArray arrayWithObjects: _NS("Blue"), @"0x0000FF", nil];
135 o_aqua = [NSArray arrayWithObjects: _NS("Aqua"), @"0x00FFFF", nil];
136 o_colors = [[NSArray alloc] initWithObjects: o_default, o_black, o_gray,
137 o_silver, o_white, o_maroon, o_red, o_fuchsia, o_yellow, o_olive,
138 o_green, o_teal, o_lime, o_purple, o_navy, o_blue, o_aqua, nil];
141 [o_marq_color_pop removeAllItems];
142 [o_time_color_pop removeAllItems];
144 /* we are adding tags to the items, so we can easily identify them even if
145 * the menu was sorted */
146 while (x != [o_colors count])
148 [o_marq_color_pop addItemWithTitle: [[o_colors objectAtIndex:x]
150 [[o_marq_color_pop lastItem] setTag: x];
152 [o_time_color_pop addItemWithTitle: [[o_colors objectAtIndex:x]
154 [[o_time_color_pop lastItem] setTag: x];
159 [o_marq_color_pop selectItemAtIndex:0];
160 [o_time_color_pop selectItemAtIndex:0];
163 o_sizes = [[NSArray alloc] initWithObjects: @"6", @"8", @"10", @"11", @"12",\
164 @"13", @"14", @"16", @"18", @"24", @"36", @"48", @"64", @"72", @"96",
165 @"144", @"288", nil];
166 [o_marq_size_pop removeAllItems];
167 [o_marq_size_pop addItemsWithTitles: o_sizes];
168 [o_time_size_pop removeAllItems];
169 [o_time_size_pop addItemsWithTitles: o_sizes];
177 /* called from intf.m */
178 [o_sfilter_win displayIfNeeded];
179 [o_sfilter_win makeKeyAndOrderFront:nil];
181 intf_thread_t * p_intf = VLCIntf;
183 /* retrieve the marquee settings */
185 int tempInt = config_GetInt( p_intf, "marq-color" );
186 while( strtol([[[o_colors objectAtIndex:x] objectAtIndex:1] UTF8String],
187 NULL, 0) != tempInt )
191 if( x >= [o_marq_color_pop numberOfItems] )
197 [o_marq_color_pop selectItemAtIndex: x];
198 if( psz_temp = config_GetPsz( p_intf, "time-format" ) )
199 [o_marq_marq_fld setStringValue: [NSString stringWithUTF8String: psz_temp]];
201 [o_marq_marq_fld setStringValue: _NS("Not Available")];
203 [o_marq_opaque_sld setIntValue: config_GetInt( p_intf, "marq-opacity")];
204 [o_marq_pos_radio selectCellWithTag: config_GetInt( p_intf, "marq-position" )];
205 /* FIXME: the following line doesn't work with "-1", which is the default
207 [o_marq_size_pop selectItemWithTitle:
208 [[NSNumber numberWithInt: config_GetInt( p_intf, "marq-size" )]
210 [o_marq_size_pop selectItemAtIndex: x];
211 [o_marq_tmOut_fld setStringValue: [[NSNumber numberWithInt:
212 config_GetInt( p_intf, "marq-timeout" )] stringValue]];
214 /* retrieve the time settings */
216 tempInt = config_GetInt( p_intf, "time-color" );
217 while( strtol([[[o_colors objectAtIndex:x] objectAtIndex:1] UTF8String], NULL, 0) != tempInt )
221 if( x >= [o_time_color_pop numberOfItems] )
227 [o_time_color_pop selectItemAtIndex: x];
228 if( psz_temp = config_GetPsz( p_intf, "time-format" ) )
229 [o_time_stamp_fld setStringValue: [NSString stringWithUTF8String: psz_temp]];
231 [o_time_stamp_fld setStringValue: _NS("Not Available")];
233 [o_time_opaque_sld setIntValue: config_GetInt( p_intf, "time-opacity")];
234 /* FIXME: the following line doesn't work with "-1", which is the default
236 [o_time_size_pop selectItemWithTitle:
237 [[NSNumber numberWithInt: config_GetInt( p_intf, "time-size" )]
239 [o_time_pos_radio selectCellWithTag: config_GetInt( p_intf, "time-position" )];
241 /* retrieve the logo settings */
242 [o_logo_opaque_sld setIntValue: config_GetInt( p_intf, "logo-transparency")];
243 /* in case that no path has been saved yet */
244 if( psz_temp = config_GetPsz( p_intf, "logo-file" ) )
245 [o_logo_image_fld setStringValue: [NSString stringWithUTF8String: psz_temp]];
247 [o_logo_image_fld setStringValue: @""];
248 [o_logo_pos_radio selectCellWithTag: config_GetInt( p_intf, "logo-position" )];
250 /* enable the requested filters */
251 char * psz_subfilters;
252 psz_subfilters = config_GetPsz( p_intf, "sub-filter" );
255 if( strstr( psz_subfilters, "marq") )
256 [o_marq_enabled_ckb setState: YES];
258 [o_marq_enabled_ckb setState: NO];
260 if( strstr( psz_subfilters, "logo") )
261 [o_logo_enabled_ckb setState: YES];
263 [o_logo_enabled_ckb setState: NO];
265 if( strstr( psz_subfilters, "time") )
266 [o_time_enabled_ckb setState: YES];
268 [o_time_enabled_ckb setState: NO];
275 - (IBAction)logo_selectFile:(id)sender
277 NSOpenPanel * openPanel = [NSOpenPanel openPanel];
278 SEL sel = @selector(logo_getFile:returnCode:contextInfo:);
279 [openPanel beginSheetForDirectory:nil file:nil types: [NSArray
280 arrayWithObjects: @"png", @"PNG", @"'PNGf'", nil] modalForWindow:
281 o_sfilter_win modalDelegate:self didEndSelector:sel contextInfo:nil];
284 - (void)logo_getFile: (NSOpenPanel *)sheet returnCode:
285 (int)returnCode contextInfo: (void *)contextInfo
287 if (returnCode == NSOKButton)
289 [o_logo_image_fld setStringValue: [sheet filename]];
290 /* Make sure we notice that */
291 [self propertyChanged: o_logo_image_fld];
295 - (IBAction)propertyChanged:(id)sender
297 intf_thread_t * p_intf = VLCIntf;
298 input_thread_t * p_input = (input_thread_t *)vlc_object_find( p_intf,
299 VLC_OBJECT_INPUT, FIND_ANYWHERE );
303 /* general properties */
304 if( sender == o_sfilter_saveSettings_ckb)
306 o_save_settings = [o_sfilter_saveSettings_ckb state];
310 else if( sender == o_marq_marq_fld )
312 if( [[o_marq_marq_fld stringValue] length] == 0 )
314 val.psz_string = (char *)"";
318 val.psz_string = (char *)[[o_marq_marq_fld stringValue] UTF8String];
322 var_Set( p_input->p_libvlc, "marq-marquee", val );
324 config_PutPsz( p_intf, "marq-marquee", val.psz_string );
327 else if( sender == o_marq_pos_radio )
329 val.i_int = [[o_marq_pos_radio selectedCell] tag];
332 var_Set( p_input->p_libvlc, "marq-position", val );
334 config_PutInt( p_intf, "marq-position", val.i_int );
337 else if( sender == o_marq_color_pop )
339 val.i_int = strtol( [[[o_colors objectAtIndex: [o_marq_color_pop
340 indexOfSelectedItem]] objectAtIndex: 1] UTF8String], NULL, 0 );
343 var_Set( p_input->p_libvlc, "marq-color", val );
345 config_PutInt( p_intf, "marq-color", val.i_int );
348 else if( sender == o_marq_opaque_sld )
350 val.i_int = [o_marq_opaque_sld intValue];
353 var_Set( p_input->p_libvlc, "marq-opacity", val );
355 config_PutInt( p_intf, "marq-opacity", val.i_int );
358 else if( sender == o_marq_size_pop )
360 val.i_int = [[o_marq_size_pop titleOfSelectedItem] intValue];
363 var_Set( p_input->p_libvlc, "marq-size", val );
365 config_PutInt( p_intf, "marq-size", val.i_int );
368 else if( sender == o_marq_tmOut_fld && [[sender stringValue] length] > 0 )
370 val.i_int = [o_marq_tmOut_fld intValue];
373 var_Set( p_input->p_libvlc, "marq-timeout", val );
375 config_PutInt( p_intf, "marq-timeout", val.i_int );
380 else if( sender == o_time_stamp_fld )
382 if( [[o_time_stamp_fld stringValue] length] == 0 )
384 val.psz_string = (char *)"";
388 val.psz_string = (char *)[[o_time_stamp_fld stringValue] UTF8String];
392 var_Set( p_input->p_libvlc, "time-format", val );
394 config_PutPsz( p_intf, "time-format", val.psz_string );
397 else if( sender == o_time_pos_radio )
399 val.i_int = [[o_time_pos_radio selectedCell] tag];
402 var_Set( p_input->p_libvlc, "time-position", val );
404 config_PutInt( p_intf, "time-position", val.i_int );
407 else if( sender == o_time_color_pop )
409 val.i_int = strtol( [[[o_colors objectAtIndex: [o_time_color_pop
410 indexOfSelectedItem]] objectAtIndex: 1] UTF8String], NULL, 0 );
413 var_Set( p_input->p_libvlc, "time-color", val );
415 config_PutInt( p_intf, "time-color", val.i_int );
418 else if( sender == o_time_opaque_sld )
420 val.i_int = [o_time_opaque_sld intValue];
423 var_Set( p_input->p_libvlc, "time-opacity", val );
425 config_PutInt( p_intf, "time-opacity", val.i_int );
428 else if( sender == o_time_size_pop )
430 val.i_int = [[o_time_size_pop titleOfSelectedItem] intValue];
433 var_Set( p_input->p_libvlc, "time-size", val );
435 config_PutInt( p_intf, "time-size", val.i_int );
439 else if( sender == o_logo_opaque_sld )
441 val.i_int = [o_logo_opaque_sld intValue];
444 var_Set( p_input->p_libvlc, "logo-transparency", val );
446 config_PutInt( p_intf, "logo-transparency", val.i_int );
449 else if( sender == o_logo_pos_radio )
451 val.i_int = [[o_logo_pos_radio selectedCell] tag];
454 var_Set( p_input->p_libvlc, "logo-position", val );
456 config_PutInt( p_intf, "logo-position", val.i_int );
458 else if ( sender == o_logo_image_fld )
460 val.psz_string = (char *)[[o_logo_image_fld stringValue] UTF8String];
463 var_Set( p_input->p_libvlc, "logo-file", val );
465 config_PutPsz( p_intf, "logo-file", val.psz_string );
470 msg_Err( p_intf, "couldn't find any action for sender" );
476 o_config_changed = YES;
477 vlc_object_release( p_input );
481 - (IBAction)enableFilter:(id)sender
483 if( sender == o_marq_enabled_ckb )
485 [self changeFiltersString:"marq" onOrOff: [o_marq_enabled_ckb state]];
489 if( sender == o_logo_enabled_ckb )
491 [self changeFiltersString:"logo" onOrOff: [o_logo_enabled_ckb state]];
495 if( sender == o_time_enabled_ckb )
497 [self changeFiltersString:"time" onOrOff: [o_time_enabled_ckb state]];
505 [o_marq_color_pop setEnabled: [o_marq_enabled_ckb state]];
506 [o_marq_marq_fld setEnabled: [o_marq_enabled_ckb state]];
507 [o_marq_opaque_sld setEnabled: [o_marq_enabled_ckb state]];
508 [o_marq_size_pop setEnabled: [o_marq_enabled_ckb state]];
509 [o_marq_tmOut_fld setEnabled: [o_marq_enabled_ckb state]];
510 [o_marq_pos_radio setEnabled: [o_marq_enabled_ckb state]];
515 [o_time_color_pop setEnabled: [o_time_enabled_ckb state]];
516 [o_time_stamp_fld setEnabled: [o_time_enabled_ckb state]];
517 [o_time_opaque_sld setEnabled: [o_time_enabled_ckb state]];
518 [o_time_size_pop setEnabled: [o_time_enabled_ckb state]];
519 [o_time_pos_radio setEnabled: [o_time_enabled_ckb state]];
524 [o_logo_image_btn setEnabled: [o_logo_enabled_ckb state]];
525 [o_logo_image_fld setEnabled: [o_logo_enabled_ckb state]];
526 [o_logo_opaque_sld setEnabled: [o_logo_enabled_ckb state]];
527 [o_logo_pos_radio setEnabled: [o_logo_enabled_ckb state]];
530 - (void)changeFiltersString:(char *)psz_name onOrOff:(bool )b_add
532 /* copied from ../wxwidgets/extrapanel.cpp
533 * renamed to conform with Cocoa's rules
534 * and slightly modified to suit our needs */
536 intf_thread_t * p_intf = VLCIntf;
538 char *psz_parser, *psz_string;
539 psz_string = config_GetPsz( p_intf, "sub-filter" );
541 if( !psz_string ) psz_string = strdup("");
543 psz_parser = strstr( psz_string, psz_name );
549 psz_parser = psz_string;
550 asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
551 psz_string, psz_name );
563 memmove( psz_parser, psz_parser + strlen(psz_name) +
564 (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
565 strlen(psz_parser + strlen(psz_name)) + 1 );
567 /* Remove trailing : : */
568 if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
570 *(psz_string+strlen(psz_string ) -1 ) = '\0';
580 config_PutPsz( p_intf, "sub-filter", psz_string );
582 /* Try to set on the fly */
583 /* FIXME: enable this once we support on-the-fly addition of this kind of
585 vout_thread_t *p_vout;
586 p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
590 var_SetString( p_vout, "sub-filter", psz_string );
591 vlc_object_release( p_vout );
596 o_config_changed = YES;