1 /*****************************************************************************
2 * sfilter.m: MacOS X Subpicture filters dialogue
3 *****************************************************************************
4 * Copyright (C) 2005-2006 the VideoLAN team
7 * Authors: Felix Kühne <fkuehne@users.sf.net>
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 *****************************************************************************/
37 - check for memory leaks
38 - save the preferences, if requested
41 @implementation VLCsFilters
43 static VLCsFilters *_o_sharedInstance = nil;
45 + (VLCsFilters *)sharedInstance
47 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
52 if (_o_sharedInstance) {
55 _o_sharedInstance = [super init];
58 return _o_sharedInstance;
70 [o_sfilter_win setTitle: _NS("Subpicture Filters")];
71 [[o_sfilter_tabView tabViewItemAtIndex: 0] setLabel: _NS("Logo")];
72 [[o_sfilter_tabView tabViewItemAtIndex: 1] setLabel: _NS("Time")];
73 [[o_sfilter_tabView tabViewItemAtIndex: 2] setLabel: _NS("Marquee")];
74 [o_sfilter_saveSettings_ckb setTitle: _NS("Save settings")];
75 [o_logo_image_btn setTitle: _NS("Browse...")];
76 [o_logo_enabled_ckb setTitle: _NS("Enabled")];
77 [o_logo_image_lbl setStringValue: [_NS("Image") \
78 stringByAppendingString: @":"]];
79 [o_logo_pos_lbl setStringValue: [_NS("Position") \
80 stringByAppendingString: @":"]];
81 [o_logo_opaque_lbl setStringValue: [_NS("Opaqueness") \
82 stringByAppendingString: @":"]];
83 [o_time_enabled_ckb setTitle: _NS("Enabled")];
84 [o_time_stamp_lbl setStringValue: [_NS("Timestamp") \
85 stringByAppendingString: @":"]];
86 [o_time_size_lbl setStringValue: [_NS("Size") \
87 stringByAppendingString: @":"]];
88 [o_time_color_lbl setStringValue: [_NS("Color") \
89 stringByAppendingString: @":"]];
90 [o_time_opaque_lbl setStringValue: [_NS("Opaqueness") \
91 stringByAppendingString: @":"]];
92 [o_time_pos_lbl setStringValue: [_NS("Position") \
93 stringByAppendingString: @":"]];
94 [o_time_size_inPx_lbl setStringValue: _NS("(in pixels)")];
95 [o_marq_enabled_ckb setTitle: _NS("Enabled")];
96 [o_marq_color_lbl setStringValue: [_NS("Color") \
97 stringByAppendingString: @":"]];
98 [o_marq_marq_lbl setStringValue: [_NS("Marquee") \
99 stringByAppendingString: @":"]];
100 [o_marq_opaque_lbl setStringValue: [_NS("Opaqueness") \
101 stringByAppendingString: @":"]];
102 [o_marq_tmOut_lbl setStringValue: [_NS("Timeout") \
103 stringByAppendingString: @":"]];
104 [o_marq_tmOut_ms_lbl setStringValue: _NS("ms")];
105 [o_marq_pos_lbl setStringValue: [_NS("Position") \
106 stringByAppendingString: @":"]];
107 [o_marq_size_lbl setStringValue: [_NS("Size") \
108 stringByAppendingString: @":"]];
109 [o_time_color_lbl setStringValue: _NS("(in pixels)")];
114 /* colors as implemented at the beginning of marq.c and time.c
115 * feel free to add more colors, but remember to add them to these files
116 * as well to keep a certain level of consistency across the interfaces */
134 o_default = [NSArray arrayWithObjects: _NS("Default"), @"-1", nil];
135 o_black = [NSArray arrayWithObjects: _NS("Black"), @"0x000000", nil];
136 o_gray = [NSArray arrayWithObjects: _NS("Gray"), @"0x808080", nil];
137 o_silver = [NSArray arrayWithObjects: _NS("Silver"), @"0xC0C0C0", nil];
138 o_white = [NSArray arrayWithObjects: _NS("White"), @"0xFFFFFF", nil];
139 o_maroon = [NSArray arrayWithObjects: _NS("Maroon"), @"0x800000", nil];
140 o_red = [NSArray arrayWithObjects: _NS("Red"), @"0xFF0000", nil];
141 o_fuchsia = [NSArray arrayWithObjects: _NS("Fuchsia"), @"0xFF00FF", nil];
142 o_yellow = [NSArray arrayWithObjects: _NS("Yellow"), @"0xFFFF00", nil];
143 o_olive = [NSArray arrayWithObjects: _NS("Olive"), @"0x808000", nil];
144 o_green = [NSArray arrayWithObjects: _NS("Green"), @"0x008000", nil];
145 o_teal = [NSArray arrayWithObjects: _NS("Teal"), @"0x008080", nil];
146 o_lime = [NSArray arrayWithObjects: _NS("Lime"), @"0x00FF00", nil];
147 o_purple = [NSArray arrayWithObjects: _NS("Purple"), @"0x800080", nil];
148 o_navy = [NSArray arrayWithObjects: _NS("Navy"), @"0x000080", nil];
149 o_blue = [NSArray arrayWithObjects: _NS("Blue"), @"0x0000FF", nil];
150 o_aqua = [NSArray arrayWithObjects: _NS("Aqua"), @"0x00FFFF", nil];
151 o_colors = [[NSArray alloc] initWithObjects: o_default, o_black, o_gray, \
152 o_silver, o_white, o_maroon, o_red, o_fuchsia, o_yellow, o_olive, \
153 o_green, o_teal, o_lime, o_purple, o_navy, o_blue, o_aqua, nil];
156 [o_marq_color_pop removeAllItems];
157 [o_time_color_pop removeAllItems];
159 /* we are adding tags to the items, so we can easily identify them even if
160 * the menu was sorted */
161 while (x != [o_colors count])
163 [o_marq_color_pop addItemWithTitle: [[o_colors objectAtIndex:x] \
165 [[o_marq_color_pop lastItem] setTag: x];
167 [o_time_color_pop addItemWithTitle: [[o_colors objectAtIndex:x] \
169 [[o_time_color_pop lastItem] setTag: x];
174 [o_marq_color_pop selectItemAtIndex:0];
175 [o_time_color_pop selectItemAtIndex:0];
177 /* define the relative positions and copy them to the menues
178 * we can destroy the array afterwards, because we are saving the ints
179 * as tags to the menu-items */
189 NSArray * o_positions;
190 o_cnt_cnt = [NSArray arrayWithObjects: _NS("Center-Center"), @"0", nil];
191 o_lft_cnt = [NSArray arrayWithObjects: _NS("Left-Center"), @"1", nil];
192 o_rht_cnt = [NSArray arrayWithObjects: _NS("Right-Center"), @"2", nil];
193 o_cnt_top = [NSArray arrayWithObjects: _NS("Center-Top"), @"4", nil];
194 o_lft_top = [NSArray arrayWithObjects: _NS("Left-Top"), @"5", nil];
195 o_rht_top = [NSArray arrayWithObjects: _NS("Right-Top"), @"6", nil];
196 o_cnt_btm = [NSArray arrayWithObjects: _NS("Center-Bottom"), @"8", nil];
197 o_lft_btm = [NSArray arrayWithObjects: _NS("Left-Bottom"), @"9", nil];
198 o_rht_btm = [NSArray arrayWithObjects: _NS("Right-Bottom"), @"10", nil];
199 o_positions = [[NSArray alloc] initWithObjects: o_cnt_cnt, o_lft_cnt, \
200 o_rht_cnt, o_cnt_top, o_lft_top, o_rht_top, o_cnt_btm, o_lft_btm, \
204 [o_time_pos_rel_pop removeAllItems];
205 [o_marq_pos_rel_pop removeAllItems];
206 [o_logo_pos_rel_pop removeAllItems];
208 /* we are adding a tag here, so we can easily select an item later on */
209 while ( x != [o_positions count] )
211 [o_time_pos_rel_pop addItemWithTitle: [[o_positions objectAtIndex:x] \
213 [[o_time_pos_rel_pop lastItem] setTag: [[[o_positions objectAtIndex:x] \
214 objectAtIndex:1] intValue]];
215 [o_marq_pos_rel_pop addItemWithTitle: [[o_positions objectAtIndex:x] \
217 [[o_marq_pos_rel_pop lastItem] setTag: [[[o_positions objectAtIndex:x] \
218 objectAtIndex:1] intValue]];
219 [o_logo_pos_rel_pop addItemWithTitle: [[o_positions objectAtIndex:x] \
221 [[o_logo_pos_rel_pop lastItem] setTag: [[[o_positions objectAtIndex:x] \
222 objectAtIndex:1] intValue]];
226 [o_positions release];
229 o_sizes = [[NSArray alloc] initWithObjects: @"6", @"8", @"10", @"11", @"12",\
230 @"14", @"13", @"16", @"18", @"24", @"36", @"48", @"64", @"72", @"96", \
231 @"144", @"288", nil];
232 [o_marq_size_pop removeAllItems];
233 [o_marq_size_pop addItemsWithTitles: o_sizes];
234 [o_time_size_pop removeAllItems];
235 [o_time_size_pop addItemsWithTitles: o_sizes];
241 /* called from intf.m */
242 [o_sfilter_win displayIfNeeded];
243 [o_sfilter_win makeKeyAndOrderFront:nil];
245 /* show a warning until the panel is removed for 0.8.5
246 * This isn't to be localised */
247 NSBeginCriticalAlertSheet( @"Implementation incomplete", @"OK", \
248 @"", @"", o_sfilter_win, nil, nil, nil, nil, @"The panel " \
249 "you just opened is not implemented completely and contains " \
250 "various limitations and certain bugs. Be warned.\n\nIt isn't going " \
251 "to be included within the final build of VLC 0.8.5." );
253 intf_thread_t * p_intf = VLCIntf;
255 /* retrieve the marquee settings */
257 int tempInt = config_GetInt( p_intf, "marq-color" );
258 while( strtol([[[o_colors objectAtIndex:x] objectAtIndex:1] UTF8String], \
259 NULL, 0) != tempInt )
263 if( x >= [o_marq_color_pop numberOfItems] )
269 [o_marq_color_pop selectItemAtIndex: x];
270 [o_marq_marq_fld setStringValue: [NSString stringWithUTF8String: \
271 config_GetPsz( p_intf, "marq-marquee" )]];
272 [o_marq_opaque_sld setIntValue: config_GetInt( p_intf, "marq-opacity")];
274 tempInt = config_GetInt( p_intf, "marq-position" );
275 while( tempInt != [[o_marq_pos_rel_pop itemAtIndex:x] tag] )
279 if( x >= [o_marq_pos_rel_pop numberOfItems] )
285 [o_marq_pos_rel_pop selectItemAtIndex:x];
287 tempInt = config_GetInt( p_intf, "marq-size" );
288 while( [[[o_marq_size_pop itemAtIndex: x] title] intValue] != tempInt )
291 if( x >= [o_marq_size_pop numberOfItems] )
296 [o_marq_size_pop selectItemAtIndex: x];
297 [o_marq_tmOut_fld setStringValue: [[NSNumber numberWithInt: \
298 config_GetInt( p_intf, "marq-timeout" )] stringValue]];
300 /* retrieve the time settings */
302 tempInt = config_GetInt( p_intf, "time-color" );
303 while( strtol([[[o_colors objectAtIndex:x] objectAtIndex:1] UTF8String], \
304 NULL, 0) != tempInt )
308 if( x >= [o_time_color_pop numberOfItems] )
314 [o_time_color_pop selectItemAtIndex: x];
315 [o_time_stamp_fld setStringValue: [NSString stringWithUTF8String: \
316 config_GetPsz( p_intf, "time-format" )]];
317 [o_time_opaque_sld setIntValue: config_GetInt( p_intf, "time-opacity")];
319 tempInt = config_GetInt( p_intf, "time-size" );
320 while( [[[o_time_size_pop itemAtIndex: x] title] intValue] != tempInt )
323 if( x >= [o_time_size_pop numberOfItems] )
328 [o_time_size_pop selectItemAtIndex: x];
330 tempInt = config_GetInt( p_intf, "time-position" );
331 while( tempInt != [[o_time_pos_rel_pop itemAtIndex:x] tag] )
335 if( x >= [o_time_pos_rel_pop numberOfItems] )
342 /* retrieve the logo settings */
343 [o_logo_opaque_sld setIntValue: config_GetInt( p_intf, "logo-transparency")];
344 /* in case that no path has been saved yet */
345 NSString * tempString = [[NSString alloc] initWithUTF8String: \
346 config_GetPsz( p_intf, "logo-file" )];
347 if( [tempString length] == 0 )
349 [o_logo_image_fld setStringValue: @""];
353 [o_logo_image_fld setStringValue: tempString ];
355 [tempString release];
357 tempInt = config_GetInt( p_intf, "logo-position" );
358 while( tempInt != [[o_logo_pos_rel_pop itemAtIndex:x] tag] )
362 if( x >= [o_logo_pos_rel_pop numberOfItems] )
369 /* enable the wanted filters */
370 char * psz_subfilters;
371 psz_subfilters = config_GetPsz( p_intf, "sub-filter" );
374 [o_marq_enabled_ckb setState: (int)strstr( psz_subfilters, "marq")];
375 [o_logo_enabled_ckb setState: (int)strstr( psz_subfilters, "logo")];
376 [o_time_enabled_ckb setState: (int)strstr( psz_subfilters, "time")];
383 - (IBAction)logo_selectFile:(id)sender
385 NSOpenPanel * openPanel = [NSOpenPanel openPanel];
386 SEL sel = @selector(logo_getFile:returnCode:contextInfo:);
387 [openPanel beginSheetForDirectory:nil file:nil types: [NSArray \
388 arrayWithObjects: @"png", @"PNG", @"'PNGf'", nil] modalForWindow: \
389 o_sfilter_win modalDelegate:self didEndSelector:sel contextInfo:nil];
392 - (void)logo_getFile: (NSOpenPanel *)sheet returnCode: \
393 (int)returnCode contextInfo: (void *)contextInfo
395 if (returnCode == NSOKButton)
397 [o_logo_image_fld setStringValue: [sheet filename]];
401 - (IBAction)propertyChanged:(id)sender
403 intf_thread_t * p_intf = VLCIntf;
404 input_thread_t * p_input = (input_thread_t *)vlc_object_find( p_intf, \
405 VLC_OBJECT_INPUT, FIND_ANYWHERE );
409 /* general properties */
410 if( sender == o_sfilter_saveSettings_ckb)
412 o_save_settings = [o_sfilter_saveSettings_ckb state];
416 else if( sender == o_marq_marq_fld )
418 if( [[o_marq_marq_fld stringValue] length] == 0 )
424 val.psz_string = (char *)[[o_marq_marq_fld stringValue] UTF8String];
428 var_Set( p_input->p_libvlc, "marq-marquee", val );
430 config_PutPsz( p_intf, "marq-marquee", val.psz_string );
433 else if( sender == o_marq_pos_rel_pop )
435 val.i_int = [[o_marq_pos_rel_pop selectedItem] tag];
438 var_Set( p_input->p_libvlc, "marq-position", val );
440 config_PutInt( p_intf, "marq-position", val.i_int );
443 else if( sender == o_marq_color_pop )
445 val.i_int = strtol( [[[o_colors objectAtIndex: [o_marq_color_pop \
446 indexOfSelectedItem]] objectAtIndex: 1] UTF8String], NULL, 0 );
449 var_Set( p_input->p_libvlc, "marq-color", val );
451 config_PutInt( p_intf, "marq-color", val.i_int );
454 else if( sender == o_marq_opaque_sld )
456 val.i_int = [o_marq_opaque_sld intValue];
459 var_Set( p_input->p_libvlc, "marq-opacity", val );
461 config_PutInt( p_intf, "marq-opacity", val.i_int );
464 else if( sender == o_marq_size_pop )
466 val.i_int = [[o_marq_size_pop titleOfSelectedItem] intValue];
469 var_Set( p_input->p_libvlc, "marq-size", val );
471 config_PutInt( p_intf, "marq-size", val.i_int );
474 else if( sender == o_marq_tmOut_fld && [[sender stringValue] length] > 0 )
476 val.i_int = [o_marq_tmOut_fld intValue];
479 var_Set( p_input->p_libvlc, "marq-timeout", val );
481 config_PutInt( p_intf, "marq-timeout", val.i_int );
486 else if( sender == o_time_stamp_fld )
488 if( [[o_time_stamp_fld stringValue] length] == 0 )
494 val.psz_string = (char *)[[o_time_stamp_fld stringValue] UTF8String];
498 var_Set( p_input->p_libvlc, "time-format", val );
500 config_PutPsz( p_intf, "time-format", val.psz_string );
503 else if( sender == o_time_pos_rel_pop )
505 val.i_int = [[o_time_pos_rel_pop selectedItem] tag];
508 var_Set( p_input->p_libvlc, "time-position", val );
510 config_PutInt( p_intf, "time-position", val.i_int );
513 else if( sender == o_time_color_pop )
515 val.i_int = strtol( [[[o_colors objectAtIndex: [o_time_color_pop \
516 indexOfSelectedItem]] objectAtIndex: 1] UTF8String], NULL, 0 );
519 var_Set( p_input->p_libvlc, "time-color", val );
521 config_PutInt( p_intf, "time-color", val.i_int );
524 else if( sender == o_time_opaque_sld )
526 val.i_int = [o_time_opaque_sld intValue];
529 var_Set( p_input->p_libvlc, "time-opacity", val );
531 config_PutInt( p_intf, "time-opacity", val.i_int );
534 else if( sender == o_time_size_pop )
536 val.i_int = [[o_time_size_pop titleOfSelectedItem] intValue];
539 var_Set( p_input->p_libvlc, "time-size", val );
541 config_PutInt( p_intf, "time-size", val.i_int );
545 else if( sender == o_logo_opaque_sld )
547 val.i_int = [o_logo_opaque_sld intValue];
550 var_Set( p_input->p_libvlc, "logo-transparency", val );
552 config_PutInt( p_intf, "logo-transparency", val.i_int );
555 else if( sender == o_logo_pos_rel_pop )
557 val.i_int = [[o_logo_pos_rel_pop selectedItem] tag];
560 var_Set( p_input->p_libvlc, "logo-position", val );
562 config_PutInt( p_intf, "logo-position", val.i_int );
568 o_config_changed = YES;
569 vlc_object_release( p_input );
573 - (IBAction)enableFilter:(id)sender
575 if( sender == o_marq_enabled_ckb )
577 if( [o_marq_enabled_ckb state] == NSOnState )
579 [self changeFiltersString:"marq" onOrOff:VLC_TRUE];
583 [self changeFiltersString:"marq" onOrOff:VLC_FALSE];
587 if( sender == o_logo_enabled_ckb )
589 if( [o_logo_enabled_ckb state] == NSOnState )
591 [self changeFiltersString:"logo" onOrOff:VLC_TRUE];
595 [self changeFiltersString:"logo" onOrOff:VLC_FALSE];
599 if( sender == o_time_enabled_ckb )
601 if( [o_time_enabled_ckb state] == NSOnState )
603 [self changeFiltersString:"time" onOrOff:VLC_TRUE];
607 [self changeFiltersString:"time" onOrOff:VLC_FALSE];
615 [o_marq_color_pop setEnabled: [o_marq_enabled_ckb state]];
616 [o_marq_marq_fld setEnabled: [o_marq_enabled_ckb state]];
617 [o_marq_opaque_sld setEnabled: [o_marq_enabled_ckb state]];
618 [o_marq_size_pop setEnabled: [o_marq_enabled_ckb state]];
619 [o_marq_tmOut_fld setEnabled: [o_marq_enabled_ckb state]];
620 [o_marq_pos_rel_pop setEnabled: [o_marq_enabled_ckb state]];
625 [o_time_color_pop setEnabled: [o_time_enabled_ckb state]];
626 [o_time_stamp_fld setEnabled: [o_time_enabled_ckb state]];
627 [o_time_opaque_sld setEnabled: [o_time_enabled_ckb state]];
628 [o_time_size_pop setEnabled: [o_time_enabled_ckb state]];
629 [o_time_pos_rel_pop setEnabled: [o_time_enabled_ckb state]];
634 [o_logo_image_btn setEnabled: [o_logo_enabled_ckb state]];
635 [o_logo_image_fld setEnabled: [o_logo_enabled_ckb state]];
636 [o_logo_opaque_sld setEnabled: [o_logo_enabled_ckb state]];
637 [o_logo_pos_rel_pop setEnabled: [o_logo_enabled_ckb state]];
640 - (void)changeFiltersString:(char *)psz_name onOrOff:(vlc_bool_t )b_add
642 /* copied from ../wxwidgets/extrapanel.cpp
643 * renamed to conform with Cocoa's rules
644 * and slightly modified to suit our needs */
646 intf_thread_t * p_intf = VLCIntf;
648 char *psz_parser, *psz_string;
649 psz_string = config_GetPsz( p_intf, "sub-filter" );
651 if( !psz_string ) psz_string = strdup("");
653 psz_parser = strstr( psz_string, psz_name );
659 psz_parser = psz_string;
660 asprintf( &psz_string, (*psz_string) ? "%s:%s" : "%s%s",
661 psz_string, psz_name );
673 memmove( psz_parser, psz_parser + strlen(psz_name) +
674 (*(psz_parser + strlen(psz_name)) == ':' ? 1 : 0 ),
675 strlen(psz_parser + strlen(psz_name)) + 1 );
677 /* Remove trailing : : */
678 if( *(psz_string+strlen(psz_string ) -1 ) == ':' )
680 *(psz_string+strlen(psz_string ) -1 ) = '\0';
690 config_PutPsz( p_intf, "sub-filter", psz_string );
692 /* Try to set on the fly */
693 /* FIXME: enable this once we support on-the-fly addition of this kind of
695 vout_thread_t *p_vout;
696 p_vout = (vout_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_VOUT,
700 var_SetString( p_vout, "sub-filter", psz_string );
701 vlc_object_release( p_vout );
706 vlc_object_release( p_intf );
708 o_config_changed = YES;