1 /*****************************************************************************
2 * dialogProvider.m: Minimal Dialog Provider for Mac OS X
3 *****************************************************************************
4 * Copyright (C) 2009-2010 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 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #import <stdlib.h> /* malloc(), free() */
34 #import <vlc_common.h>
35 #import <vlc_plugin.h>
36 #import <vlc_dialog.h>
37 #import <vlc_interface.h>
39 #import <Cocoa/Cocoa.h>
40 #import "VLCLoginPanel.h"
42 /*****************************************************************************
44 *****************************************************************************/
45 static int OpenIntf(vlc_object_t *);
46 static void CloseIntf(vlc_object_t *);
47 static void Run(intf_thread_t * );
49 static int DisplayError(vlc_object_t *,const char *,vlc_value_t,vlc_value_t,void * );
50 static int DisplayCritical(vlc_object_t *,const char *,vlc_value_t,vlc_value_t,void * );
51 static int DisplayQuestion(vlc_object_t *,const char *,vlc_value_t,vlc_value_t,void * );
52 static int DisplayLogin(vlc_object_t *,const char *,vlc_value_t,vlc_value_t,void * );
60 /*****************************************************************************
62 *****************************************************************************/
65 /* Minimal interface. see intf.m */
66 set_shortname("Mac OS X Dialogs")
67 add_shortcut("macosx_dialog_provider")
69 set_description("Minimal Mac OS X Dialog Provider")
70 set_capability("interface", 50)
71 set_callbacks(OpenIntf, CloseIntf)
72 set_category(CAT_INTERFACE)
73 set_subcategory(SUBCAT_INTERFACE_MAIN)
76 /*****************************************************************************
77 * OpenIntf: initialize interface
78 *****************************************************************************/
79 int OpenIntf(vlc_object_t *p_this)
81 intf_thread_t *p_intf = (intf_thread_t*) p_this;
83 p_intf->p_sys = malloc(sizeof(intf_sys_t));
87 memset(p_intf->p_sys,0,sizeof(*p_intf->p_sys));
91 msg_Dbg(p_intf,"Opening Mac OS X dialog provider");
95 /*****************************************************************************
96 * Run: waiting for the death
97 *****************************************************************************/
98 static void Run( intf_thread_t *p_intf )
100 /* subscribe to various interactive dialogues */
101 var_Create(p_intf,"dialog-error",VLC_VAR_ADDRESS);
102 var_AddCallback(p_intf,"dialog-error",DisplayError,p_intf);
103 var_Create(p_intf,"dialog-critical",VLC_VAR_ADDRESS);
104 var_AddCallback(p_intf,"dialog-critical",DisplayCritical,p_intf);
105 var_Create(p_intf,"dialog-login",VLC_VAR_ADDRESS);
106 var_AddCallback(p_intf,"dialog-login",DisplayLogin,p_intf);
107 var_Create(p_intf,"dialog-question",VLC_VAR_ADDRESS);
108 var_AddCallback(p_intf,"dialog-question",DisplayQuestion,p_intf);
109 // var_Create(p_intf,"dialog-progress-bar",VLC_VAR_ADDRESS);
110 // var_AddCallback(p_intf,"dialog-progress-bar",DisplayProgressPanelAction,p_intf);
111 dialog_Register(p_intf);
113 msg_Dbg(p_intf,"Mac OS X dialog provider initialised");
116 while(vlc_object_alive(p_intf))
121 /* unsubscribe from the interactive dialogues */
122 dialog_Unregister(p_intf );
123 var_DelCallback(p_intf,"dialog-error",DisplayError,p_intf);
124 var_DelCallback(p_intf,"dialog-critical",DisplayCritical,p_intf);
125 var_DelCallback(p_intf,"dialog-login",DisplayLogin,p_intf);
126 var_DelCallback(p_intf,"dialog-question",DisplayQuestion,p_intf);
127 // var_DelCallback(p_intf,"dialog-progress-bar",DisplayProgressPanelAction,p_intf);
129 /*****************************************************************************
130 * CloseIntf: destroy interface
131 *****************************************************************************/
132 void CloseIntf(vlc_object_t *p_this)
134 intf_thread_t *p_intf = (intf_thread_t*) p_this;
136 msg_Dbg(p_intf,"Mac OS X dialog provider closed");
141 /*****************************************************************************
142 * Callbacks triggered by the "dialog-*" variables
143 *****************************************************************************/
144 static int DisplayError(vlc_object_t *p_this, const char *type, vlc_value_t previous, vlc_value_t value, void *data)
146 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
147 dialog_fatal_t *p_dialog = (dialog_fatal_t *)value.p_address;
148 NSRunInformationalAlertPanel([NSString stringWithUTF8String:p_dialog->title],
149 [NSString stringWithUTF8String:p_dialog->message],
154 static int DisplayCritical(vlc_object_t *p_this, const char *type, vlc_value_t previous, vlc_value_t value, void *data)
156 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
157 dialog_fatal_t *p_dialog = (dialog_fatal_t *)value.p_address;
158 NSRunCriticalAlertPanel([NSString stringWithUTF8String:p_dialog->title],
159 [NSString stringWithUTF8String:p_dialog->message],
164 static int DisplayQuestion(vlc_object_t *p_this, const char *type, vlc_value_t previous, vlc_value_t value, void *data)
166 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
167 dialog_question_t *p_dialog = (dialog_question_t *)value.p_address;
169 NSString *o_yes, *o_no, *o_cancel;
170 NSInteger i_returnValue = 0;
172 if (p_dialog->yes != NULL)
173 o_yes = [NSString stringWithUTF8String:p_dialog->yes];
174 if (p_dialog->no != NULL)
175 o_no = [NSString stringWithUTF8String:p_dialog->no];
176 if (p_dialog->cancel != NULL)
177 o_cancel = [NSString stringWithUTF8String:p_dialog->cancel];
179 o_alert = [NSAlert alertWithMessageText:[NSString stringWithUTF8String:p_dialog->title]
183 informativeTextWithFormat:[NSString stringWithUTF8String:p_dialog->message]];
184 [o_alert setAlertStyle:NSInformationalAlertStyle];
185 i_returnValue = [o_alert runModal];
187 if (i_returnValue == NSAlertDefaultReturn)
188 p_dialog->answer = 1;
189 if (i_returnValue == NSAlertAlternateReturn)
190 p_dialog->answer = 2;
191 if (i_returnValue == NSAlertOtherReturn)
192 p_dialog->answer = 3;
196 static int DisplayLogin(vlc_object_t *p_this, const char *type, vlc_value_t previous, vlc_value_t value, void *data)
198 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
199 dialog_login_t *p_dialog = (dialog_login_t *)value.p_address;
200 NSInteger i_returnValue = 0;
201 VLCLoginPanel *thePanel = [[VLCLoginPanel alloc] init];
202 [thePanel createContentView];
203 [thePanel setDialogTitle:[NSString stringWithUTF8String:p_dialog->title]];
204 [thePanel setDialogMessage:[NSString stringWithUTF8String:p_dialog->message]];
206 i_returnValue = [NSApp runModalForWindow: thePanel];
210 *p_dialog->username = strdup( [[thePanel userName] UTF8String] );
211 *p_dialog->password = strdup( [[thePanel password] UTF8String] );
215 *p_dialog->username = *p_dialog->password = NULL;