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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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
106 p_dialog = _p_dialog;
115 msg_Err( p_intf, "serious issue (p_dialog == nil)" );
117 NSString *o_title = [NSString stringWithUTF8String:p_dialog->psz_title ? p_dialog->psz_title : "title"];
118 NSString *o_description = [NSString stringWithUTF8String:p_dialog->psz_description ? p_dialog->psz_description : ""];
120 vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
123 NSEnumerator * o_enum = [[NSApp orderedWindows] objectEnumerator];
125 while( ( o_window = [o_enum nextObject] ) )
127 if( [[o_window className] isEqualToString: @"VLCWindow"] )
129 vlc_object_release( (vlc_object_t *)p_vout );
133 vlc_object_release( (vlc_object_t *)p_vout );
137 o_window = [NSApp mainWindow];
140 msg_Dbg( p_intf, "Title: %s", [o_title UTF8String] );
141 msg_Dbg( p_intf, "Description: %s", [o_description UTF8String] );
142 if( p_dialog->i_id == DIALOG_ERRORS )
144 for( i = 0; i < p_dialog->i_widgets; i++ )
146 msg_Err( p_intf, "Error: %s", p_dialog->pp_widgets[i]->psz_text );
151 for( i = 0; i < p_dialog->i_widgets; i++ )
153 msg_Dbg( p_intf, "widget: %s", p_dialog->pp_widgets[i]->psz_text );
154 o_description = [o_description stringByAppendingString:
155 [NSString stringWithUTF8String: p_dialog->pp_widgets[i]->psz_text]];
157 if( p_dialog->i_flags & DIALOG_OK_CANCEL )
159 NSBeginInformationalAlertSheet( o_title, @"OK" , @"Cancel", nil, o_window, self,
160 @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil, o_description );
162 else if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
164 NSBeginInformationalAlertSheet( o_title, @"Yes", @"Cancel", @"No", o_window, self,
165 @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil, o_description );
168 msg_Dbg( p_intf, "requested dialog type not implemented yet" );
172 - (void)sheetDidEnd:(NSWindow *)o_sheet returnCode:(int)i_return
173 contextInfo:(void *)o_context
175 vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
176 if( i_return == NSAlertDefaultReturn )
178 p_dialog->i_return = DIALOG_OK_YES;
180 else if( i_return == NSAlertAlternateReturn && ( p_dialog->i_flags & DIALOG_OK_CANCEL ) )
182 p_dialog->i_return = DIALOG_CANCELLED;
184 else if( i_return == NSAlertAlternateReturn )
186 p_dialog->i_return = DIALOG_NO;
188 else if( i_return == NSAlertOtherReturn )
190 p_dialog->i_return = DIALOG_CANCELLED;
192 p_dialog->i_status = ANSWERED_DIALOG;
193 vlc_mutex_unlock( &p_dialog->p_interaction->object_lock );
198 msg_Dbg( p_intf, "update event" );
203 msg_Dbg( p_intf, "hide event" );
208 msg_Dbg( p_intf, "destroy event" );