]> git.sesse.net Git - vlc/blob - modules/gui/macosx/interaction.m
Fix message advice (use description.widgets instead of only description)
[vlc] / modules / gui / macosx / interaction.m
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 $
6  *
7  * Authors: Derk-Jan Hartman <hartman at videolan dot org>
8  *
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.
13  * 
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.
18  *
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  *****************************************************************************/
23
24 #include "intf.h"
25 #import <interaction.h>
26
27 /*****************************************************************************
28  * VLCInteractionList implementation
29  *****************************************************************************/
30 @implementation VLCInteractionList
31
32 -(id)init
33 {
34     [super init];
35     o_interaction_list = [[NSMutableArray alloc] initWithCapacity:1];
36     [[NSNotificationCenter defaultCenter] addObserver:self
37         selector:@selector(newInteractionEvent:)
38         name: @"VLCNewInteractionEventNotification"
39         object:self];
40
41     return self;
42 }
43
44 -(void)newInteractionEvent: (NSNotification *)o_notification
45 {
46     VLCInteraction *o_interaction;
47     NSValue *o_value = [[o_notification userInfo] objectForKey:@"VLCDialogPointer"];
48     interaction_dialog_t *p_dialog = [o_value pointerValue];
49
50     switch( p_dialog->i_action )
51     {
52     case INTERACT_NEW:
53         [self addInteraction: p_dialog];
54         break;
55     case INTERACT_UPDATE:
56         o_interaction = (VLCInteraction *)p_dialog->p_private;
57         [o_interaction updateDialog];
58         break;
59     case INTERACT_HIDE:
60         o_interaction = (VLCInteraction *)p_dialog->p_private;
61         [o_interaction hideDialog];
62         break;
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;
68         break;
69     }
70 }
71
72 -(void)addInteraction: (interaction_dialog_t *)p_dialog
73 {
74
75     VLCInteraction *o_interaction = [[VLCInteraction alloc] initDialog: p_dialog];
76     
77     p_dialog->p_private = (void *)o_interaction;
78     [o_interaction_list addObject:[o_interaction autorelease]];
79     [o_interaction runDialog];
80 }
81
82 -(void)removeInteraction: (VLCInteraction *)o_interaction
83 {
84     [o_interaction_list removeObject:o_interaction];
85 }
86
87 -(void)dealloc
88 {
89     [[NSNotificationCenter defaultCenter] removeObserver:self];
90     [o_interaction_list removeAllObjects];
91     [o_interaction_list release];
92     [super dealloc];
93 }
94
95 @end
96
97 /*****************************************************************************
98  * VLCInteraction implementation
99  *****************************************************************************/
100 @implementation VLCInteraction
101
102 -(id)initDialog: (interaction_dialog_t *)_p_dialog
103 {
104     [super init];
105     p_dialog = _p_dialog;
106     return self;
107 }
108
109 -(void)runDialog
110 {
111     int i = 0;
112     id o_window = NULL;
113     if( !p_dialog )
114         NSLog( @"serious issue" );
115
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 : ""];
118     
119     vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
120     if( p_vout != NULL )
121     {
122         NSEnumerator * o_enum = [[NSApp orderedWindows] objectEnumerator];
123
124         while( ( o_window = [o_enum nextObject] ) )
125         {
126             if( [[o_window className] isEqualToString: @"VLCWindow"] )
127             {
128                 vlc_object_release( (vlc_object_t *)p_vout );
129                 break;
130             }
131         }
132         vlc_object_release( (vlc_object_t *)p_vout );
133     }
134     else
135     {
136         o_window = [NSApp mainWindow];
137     }
138     
139     NSLog( @"Title: %@", o_title );
140     NSLog( @"Description: %@", o_description );
141     if( p_dialog->i_id == DIALOG_ERRORS )
142     {
143         for( i = 0; i < p_dialog->i_widgets; i++ )
144         {
145             NSLog( @"Error: %@", [NSString stringWithUTF8String: p_dialog->pp_widgets[i]->psz_text] );
146         }
147     }
148     else
149     {
150         for( i = 0; i < p_dialog->i_widgets; i++ )
151         {
152             NSLog( @"widget: %@", [NSString stringWithUTF8String: p_dialog->pp_widgets[i]->psz_text] );
153             o_description = [o_description stringByAppendingString:
154                                 [NSString stringWithUTF8String: p_dialog->pp_widgets[i]->psz_text]];
155         }
156         if( p_dialog->i_flags & DIALOG_OK_CANCEL )
157         {
158             NSBeginInformationalAlertSheet( o_title, @"OK" , @"Cancel", nil, o_window, self,
159                 @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil, o_description );
160         }
161         else if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
162         {
163             NSBeginInformationalAlertSheet( o_title, @"Yes" , @"No", @"Cancel", o_window, self,
164                 @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil, o_description );
165         }
166         else
167             NSLog( @"not implemented yet" );
168     }
169 }
170
171 - (void)sheetDidEnd:(NSWindow *)o_sheet returnCode:(int)i_return
172     contextInfo:(void *)o_context
173 {
174     vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
175     if( i_return == NSAlertDefaultReturn )
176     {
177         p_dialog->i_return = DIALOG_OK_YES;
178     }
179     else if( i_return == NSAlertAlternateReturn && ( p_dialog->i_flags & DIALOG_OK_CANCEL ) )
180     {
181         p_dialog->i_return = DIALOG_CANCELLED;
182     }
183     else if( i_return == NSAlertAlternateReturn )
184     {
185         p_dialog->i_return = DIALOG_NO;
186     }
187     else if( i_return == NSAlertOtherReturn )
188     {
189         p_dialog->i_return = DIALOG_CANCELLED;
190     }
191     p_dialog->i_status = ANSWERED_DIALOG;
192     vlc_mutex_unlock( &p_dialog->p_interaction->object_lock );
193 }
194
195 -(void)updateDialog
196 {
197     NSLog( @"update event" );
198 }
199
200 -(void)hideDialog
201 {
202     NSLog( @"hide event" );
203 }
204
205 -(void)destroyDialog
206 {
207     NSLog( @"destroy event" );
208 }
209
210 -(void)dealloc
211 {
212     [super dealloc];
213 }
214
215 @end