1 /*****************************************************************************
2 * interaction.h: Mac OS X interaction dialogs
3 *****************************************************************************
4 * Copyright (C) 2001-2005 the VideoLAN team
5 * $Id: vout.h 13803 2005-12-18 18:54:28Z bigben $
7 * Authors: Derk-Jan Hartman <hartman 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
25 #import <interaction.h>
27 /*****************************************************************************
28 * VLCInteractionList implementation
29 *****************************************************************************/
30 @implementation VLCInteractionList
35 o_interaction_list = [[NSMutableArray alloc] initWithCapacity:1];
36 [[NSNotificationCenter defaultCenter] addObserver:self
37 selector:@selector(newInteractionEvent:)
38 name: @"VLCNewInteractionEventNotification"
44 -(void)newInteractionEvent: (NSNotification *)o_notification
46 VLCInteraction *o_interaction;
47 NSValue *o_value = [[o_notification userInfo] objectForKey:@"VLCDialogPointer"];
48 interaction_dialog_t *p_dialog = [o_value pointerValue];
50 switch( p_dialog->i_action )
53 [self addInteraction: p_dialog];
56 o_interaction = (VLCInteraction *)p_dialog->p_private;
57 [o_interaction updateDialog];
60 o_interaction = (VLCInteraction *)p_dialog->p_private;
61 [o_interaction hideDialog];
63 case INTERACT_DESTROY:
64 o_interaction = (VLCInteraction *)p_dialog->p_private;
65 [o_interaction destroyDialog];
66 [self removeInteraction:o_interaction];
67 p_dialog->i_status = DESTROYED_DIALOG;
72 -(void)addInteraction: (interaction_dialog_t *)p_dialog
75 VLCInteraction *o_interaction = [[VLCInteraction alloc] initDialog: p_dialog];
77 p_dialog->p_private = (void *)o_interaction;
78 [o_interaction_list addObject:[o_interaction autorelease]];
79 [o_interaction runDialog];
82 -(void)removeInteraction: (VLCInteraction *)o_interaction
84 [o_interaction_list removeObject:o_interaction];
89 [[NSNotificationCenter defaultCenter] removeObserver:self];
90 [o_interaction_list removeAllObjects];
91 [o_interaction_list release];
97 /*****************************************************************************
98 * VLCInteraction implementation
99 *****************************************************************************/
100 @implementation VLCInteraction
102 -(id)initDialog: (interaction_dialog_t *)_p_dialog
105 p_dialog = _p_dialog;
114 NSLog( @"serious issue" );
116 NSString *o_title = [NSString stringWithUTF8String:p_dialog->psz_title ? p_dialog->psz_title : "title"];
117 NSString *o_description = [NSString stringWithUTF8String:p_dialog->psz_description ? p_dialog->psz_description : "desc"];
119 vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
122 NSEnumerator * o_enum = [[NSApp orderedWindows] objectEnumerator];
124 while( ( o_window = [o_enum nextObject] ) )
126 if( [[o_window className] isEqualToString: @"VLCWindow"] )
128 vlc_object_release( (vlc_object_t *)p_vout );
132 vlc_object_release( (vlc_object_t *)p_vout );
136 o_window = [NSApp mainWindow];
139 NSLog( @"Title: %@", o_title );
140 NSLog( @"Description: %@", o_description );
141 if( p_dialog->i_id == DIALOG_ERRORS )
143 for( i = 0; i < p_dialog->i_widgets; i++ )
145 NSLog( @"Error: %@", [NSString stringWithUTF8String: p_dialog->pp_widgets[i]->psz_text] );
150 for( i = 0; i < p_dialog->i_widgets; i++ )
152 NSLog( @"widget: %@", [NSString stringWithUTF8String: p_dialog->pp_widgets[i]->psz_text] );
154 if( p_dialog->i_flags & DIALOG_OK_CANCEL )
156 NSBeginInformationalAlertSheet( o_title, @"OK" , @"Cancel", nil, o_window, self,
157 @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil, o_description );
159 else if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
161 NSBeginInformationalAlertSheet( o_title, @"Yes" , @"No", @"Cancel", o_window, self,
162 @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil, o_description );
165 NSLog( @"not implemented yet" );
169 - (void)sheetDidEnd:(NSWindow *)o_sheet returnCode:(int)i_return
170 contextInfo:(void *)o_context
172 vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
173 if( i_return == NSAlertDefaultReturn )
175 p_dialog->i_return = DIALOG_OK_YES;
177 else if( i_return == NSAlertAlternateReturn && ( p_dialog->i_flags & DIALOG_OK_CANCEL ) )
179 p_dialog->i_return = DIALOG_CANCELLED;
181 else if( i_return == NSAlertAlternateReturn )
183 p_dialog->i_return = DIALOG_NO;
185 else if( i_return == NSAlertOtherReturn )
187 p_dialog->i_return = DIALOG_CANCELLED;
189 p_dialog->i_status = ANSWERED_DIALOG;
190 vlc_mutex_unlock( &p_dialog->p_interaction->object_lock );
195 NSLog( @"update event" );
200 NSLog( @"hide event" );
205 NSLog( @"destroy event" );