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));
89 // p_intf->b_should_run_on_first_thread = true;
92 msg_Dbg(p_intf,"Opening Mac OS X dialog provider");
96 /*****************************************************************************
97 * Run: waiting for the death
98 *****************************************************************************/
99 static void Run( intf_thread_t *p_intf )
101 /* subscribe to various interactive dialogues */
102 var_Create(p_intf,"dialog-error",VLC_VAR_ADDRESS);
103 var_AddCallback(p_intf,"dialog-error",DisplayError,p_intf);
104 var_Create(p_intf,"dialog-critical",VLC_VAR_ADDRESS);
105 var_AddCallback(p_intf,"dialog-critical",DisplayCritical,p_intf);
106 var_Create(p_intf,"dialog-login",VLC_VAR_ADDRESS);
107 var_AddCallback(p_intf,"dialog-login",DisplayLogin,p_intf);
108 var_Create(p_intf,"dialog-question",VLC_VAR_ADDRESS);
109 var_AddCallback(p_intf,"dialog-question",DisplayQuestion,p_intf);
110 // var_Create(p_intf,"dialog-progress-bar",VLC_VAR_ADDRESS);
111 // var_AddCallback(p_intf,"dialog-progress-bar",DisplayProgressPanelAction,p_intf);
112 dialog_Register(p_intf);
114 msg_Dbg(p_intf,"Mac OS X dialog provider initialised");
117 while(vlc_object_alive(p_intf))
122 /* unsubscribe from the interactive dialogues */
123 dialog_Unregister(p_intf );
124 var_DelCallback(p_intf,"dialog-error",DisplayError,p_intf);
125 var_DelCallback(p_intf,"dialog-critical",DisplayCritical,p_intf);
126 var_DelCallback(p_intf,"dialog-login",DisplayLogin,p_intf);
127 var_DelCallback(p_intf,"dialog-question",DisplayQuestion,p_intf);
128 // var_DelCallback(p_intf,"dialog-progress-bar",DisplayProgressPanelAction,p_intf);
130 /*****************************************************************************
131 * CloseIntf: destroy interface
132 *****************************************************************************/
133 void CloseIntf(vlc_object_t *p_this)
135 intf_thread_t *p_intf = (intf_thread_t*) p_this;
137 msg_Dbg(p_intf,"Mac OS X dialog provider closed");
142 /*****************************************************************************
143 * Callbacks triggered by the "dialog-*" variables
144 *****************************************************************************/
145 static int DisplayError(vlc_object_t *p_this, const char *type, vlc_value_t previous, vlc_value_t value, void *data)
147 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
148 dialog_fatal_t *p_dialog = (dialog_fatal_t *)value.p_address;
149 NSRunInformationalAlertPanel([NSString stringWithUTF8String:p_dialog->title],
150 [NSString stringWithUTF8String:p_dialog->message],
155 static int DisplayCritical(vlc_object_t *p_this, const char *type, vlc_value_t previous, vlc_value_t value, void *data)
157 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
158 dialog_fatal_t *p_dialog = (dialog_fatal_t *)value.p_address;
159 NSRunCriticalAlertPanel([NSString stringWithUTF8String:p_dialog->title],
160 [NSString stringWithUTF8String:p_dialog->message],
165 static int DisplayQuestion(vlc_object_t *p_this, const char *type, vlc_value_t previous, vlc_value_t value, void *data)
167 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
168 dialog_question_t *p_dialog = (dialog_question_t *)value.p_address;
170 NSString *o_yes, *o_no, *o_cancel;
171 NSInteger i_returnValue = 0;
173 if (p_dialog->yes != NULL)
174 o_yes = [NSString stringWithUTF8String:p_dialog->yes];
175 if (p_dialog->no != NULL)
176 o_no = [NSString stringWithUTF8String:p_dialog->no];
177 if (p_dialog->cancel != NULL)
178 o_cancel = [NSString stringWithUTF8String:p_dialog->cancel];
180 o_alert = [NSAlert alertWithMessageText:[NSString stringWithUTF8String:p_dialog->title]
184 informativeTextWithFormat:[NSString stringWithUTF8String:p_dialog->message]];
185 [o_alert setAlertStyle:NSInformationalAlertStyle];
186 i_returnValue = [o_alert runModal];
188 if (i_returnValue == NSAlertDefaultReturn)
189 p_dialog->answer = 1;
190 if (i_returnValue == NSAlertAlternateReturn)
191 p_dialog->answer = 2;
192 if (i_returnValue == NSAlertOtherReturn)
193 p_dialog->answer = 3;
197 static int DisplayLogin(vlc_object_t *p_this, const char *type, vlc_value_t previous, vlc_value_t value, void *data)
199 NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
200 dialog_login_t *p_dialog = (dialog_login_t *)value.p_address;
201 NSInteger i_returnValue = 0;
202 VLCLoginPanel *thePanel = [[VLCLoginPanel alloc] init];
203 [thePanel createContentView];
204 [thePanel setDialogTitle:[NSString stringWithUTF8String:p_dialog->title]];
205 [thePanel setDialogMessage:[NSString stringWithUTF8String:p_dialog->message]];
207 i_returnValue = [NSApp runModalForWindow: thePanel];
211 *p_dialog->username = strdup( [[thePanel userName] UTF8String] );
212 *p_dialog->password = strdup( [[thePanel password] UTF8String] );
216 *p_dialog->username = *p_dialog->password = NULL;