Commit 5c4d7d51 authored by Felix Paul Kühne's avatar Felix Paul Kühne

macosx/coredialogs: re-write using new API

parent 173a3df6
......@@ -33,22 +33,22 @@
@interface VLCCoreDialogProvider : NSObject
{
/* authentication dialog */
IBOutlet id authenticationCancelButton;
IBOutlet id authenticationDescriptionLabel;
IBOutlet id authenticationLoginTextField;
IBOutlet id authenticationLoginLabel;
IBOutlet id authenticationOkButton;
IBOutlet id authenticationPasswordTextField;
IBOutlet id authenticationPasswordLabel;
IBOutlet id authenticationTitleLabel;
IBOutlet id authenticationWindow;
IBOutlet NSButton *authenticationCancelButton;
IBOutlet NSTextField *authenticationDescriptionLabel;
IBOutlet NSTextField *authenticationLoginTextField;
IBOutlet NSTextField *authenticationLoginLabel;
IBOutlet NSButton *authenticationOkButton;
IBOutlet NSTextField *authenticationPasswordTextField;
IBOutlet NSTextField *authenticationPasswordLabel;
IBOutlet NSTextField *authenticationTitleLabel;
IBOutlet NSWindow *authenticationWindow;
/* progress dialog */
IBOutlet NSProgressIndicator * progressIndicator;
IBOutlet id progressCancelButton;
IBOutlet id progressDescriptionLabel;
IBOutlet id progressTitleLabel;
IBOutlet id progressWindow;
IBOutlet NSProgressIndicator *progressIndicator;
IBOutlet NSButton *progressCancelButton;
IBOutlet NSTextField *progressDescriptionLabel;
IBOutlet NSTextField *progressTitleLabel;
IBOutlet NSWindow *progressWindow;
}
@property (atomic,readwrite) BOOL progressCancelled;
......
......@@ -29,16 +29,145 @@
/* for the icon in our custom error panel */
#import <ApplicationServices/ApplicationServices.h>
static void displayErrorCallback(const char *psz_title, const char *psz_text, void * p_data)
@interface VLCCoreDialogProvider ()
- (void)displayLoginDialogWithID:(vlc_dialog_id *)p_id
title:(const char *)psz_title
description:(const char *)psz_text
defaultUserName:(const char *)psz_default_username
askToStore:(bool )b_ask_store;
- (void)displayProgressDialogWithID:(vlc_dialog_id *)p_id
title:(const char *)psz_title
description:(const char *)psz_text
isIndeterminate:(bool)b_indeterminate
position:(float)f_position
cancelTitle:(const char *)psz_cancel;
- (void)updateDisplayedProgressDialogWithID:(vlc_dialog_id *)p_id
value:(float)f_value
description:(const char *)psz_text;
@end
static void displayErrorCallback(const char *psz_title,
const char *psz_text,
void *p_data)
{
@autoreleasepool {
VLCCoreDialogProvider *dialogProvider = (__bridge VLCCoreDialogProvider *)p_data;
NSAlert *alert = [NSAlert alertWithMessageText: toNSStr(psz_title) defaultButton: _NS("OK") alternateButton: nil otherButton: nil informativeTextWithFormat: @"%@", toNSStr(psz_text)];
[alert setAlertStyle: NSCriticalAlertStyle];
NSAlert *alert = [NSAlert alertWithMessageText:toNSStr(psz_title)
defaultButton:_NS("OK")
alternateButton:nil
otherButton:nil
informativeTextWithFormat:@"%@", toNSStr(psz_text)];
[alert setAlertStyle:NSCriticalAlertStyle];
[alert runModal];
}
}
static void displayLoginCallback(vlc_dialog_id *p_id,
const char *psz_title,
const char *psz_text,
const char *psz_default_username,
bool b_ask_store,
void *p_data)
{
@autoreleasepool {
VLCCoreDialogProvider *dialogProvider = (__bridge VLCCoreDialogProvider *)p_data;
[dialogProvider displayLoginDialogWithID:p_id
title:psz_title
description:psz_text
defaultUserName:psz_default_username
askToStore:b_ask_store];
}
}
static void displayQuestionCallback(vlc_dialog_id *p_id,
const char *psz_title,
const char *psz_text,
vlc_dialog_question_type i_type,
const char *psz_cancel,
const char *psz_action1,
const char *psz_action2,
void *p_data)
{
@autoreleasepool {
NSAlert *alert = [NSAlert alertWithMessageText:toNSStr(psz_title)
defaultButton:toNSStr(psz_action1)
alternateButton:toNSStr(psz_action2)
otherButton:toNSStr(psz_cancel)
informativeTextWithFormat:@"%@", toNSStr(psz_text)];
switch (i_type) {
case VLC_DIALOG_QUESTION_WARNING:
[alert setAlertStyle:NSWarningAlertStyle];
break;
case VLC_DIALOG_QUESTION_CRITICAL:
[alert setAlertStyle:NSCriticalAlertStyle];
break;
default:
[alert setAlertStyle:NSInformationalAlertStyle];
break;
}
NSInteger returnValue = [alert runModal];
switch (returnValue) {
case NSAlertAlternateReturn:
vlc_dialog_id_post_action(p_id, 2);
break;
case NSAlertOtherReturn:
vlc_dialog_id_post_action(p_id, 3);
break;
default:
vlc_dialog_id_post_action(p_id, 1);
break;
}
}
}
static void displayProgressCallback(vlc_dialog_id *p_id,
const char *psz_title,
const char *psz_text,
bool b_indeterminate,
float f_position,
const char *psz_cancel,
void *p_data)
{
@autoreleasepool {
VLCCoreDialogProvider *dialogProvider = (__bridge VLCCoreDialogProvider *)p_data;
[dialogProvider displayProgressDialogWithID:p_id
title:psz_title
description:psz_text
isIndeterminate:b_indeterminate
position:f_position
cancelTitle:psz_cancel];
}
}
static void cancelCallback(vlc_dialog_id *p_id,
void *p_data)
{
@autoreleasepool {
[NSApp stopModalWithCode: 0];
}
}
static void updateProgressCallback(vlc_dialog_id *p_id,
float f_value,
const char *psz_text,
void *p_data)
{
@autoreleasepool {
VLCCoreDialogProvider *dialogProvider = (__bridge VLCCoreDialogProvider *)p_data;
[dialogProvider updateDisplayedProgressDialogWithID:p_id
value:f_value
description:psz_text];
}
}
@implementation VLCCoreDialogProvider
- (instancetype)init
......@@ -52,22 +181,13 @@ static void displayErrorCallback(const char *psz_title, const char *psz_text, vo
intf_thread_t *p_intf = getIntf();
/* subscribe to various interactive dialogues */
/* const vlc_dialog_cbs cbs = {
const vlc_dialog_cbs cbs = {
displayErrorCallback,
displayLoginCallback,
displayQuestionCallback,
displayProgressCallback,
cancelCallback,
updateProgressCallback
};*/
const vlc_dialog_cbs cbs = {
displayErrorCallback,
NULL,
NULL,
NULL,
NULL,
NULL
};
vlc_dialog_provider_set_callbacks(p_intf, &cbs, (__bridge void *)self);
......@@ -96,12 +216,89 @@ static void displayErrorCallback(const char *psz_title, const char *psz_text, vo
[progressIndicator setUsesThreadedAnimation: YES];
}
- (void)displayLoginDialogWithID:(vlc_dialog_id *)p_id
title:(const char *)psz_title
description:(const char *)psz_text
defaultUserName:(const char *)psz_default_username
askToStore:(bool )b_ask_store
{
// FIXME: add support for b_ask_store
[authenticationTitleLabel setStringValue:toNSStr(psz_title)];
authenticationWindow.title = authenticationTitleLabel.stringValue;
[authenticationDescriptionLabel setStringValue:toNSStr(psz_text)];
[authenticationLoginTextField setStringValue:toNSStr(psz_default_username)];
[authenticationPasswordTextField setStringValue:@""];
[authenticationWindow center];
NSInteger returnValue = [NSApp runModalForWindow:authenticationWindow];
[authenticationWindow close];
NSString *username = authenticationLoginTextField.stringValue;
NSString *password = authenticationPasswordTextField.stringValue;
vlc_dialog_id_post_login(p_id,
username ? [username UTF8String] : NULL,
password ? [password UTF8String] : NULL,
false);
}
- (IBAction)authenticationDialogAction:(id)sender
{
if ([[sender title] isEqualToString: _NS("OK")])
[NSApp stopModalWithCode: 1];
else
[NSApp stopModalWithCode: 0];
}
- (void)displayProgressDialogWithID:(vlc_dialog_id *)p_id
title:(const char *)psz_title
description:(const char *)psz_text
isIndeterminate:(bool)b_indeterminate
position:(float)f_position
cancelTitle:(const char *)psz_cancel
{
progressTitleLabel.stringValue = toNSStr(psz_title);
progressWindow.title = progressTitleLabel.stringValue;
progressDescriptionLabel.stringValue = toNSStr(psz_text);
progressIndicator.indeterminate = b_indeterminate;
progressIndicator.doubleValue = f_position;
if (psz_cancel) {
progressCancelButton.title = toNSStr(psz_cancel);
} else {
progressCancelButton.title = _NS("Cancel");
}
[progressIndicator startAnimation:self];
[progressWindow center];
[NSApp runModalForWindow:progressWindow];
[progressWindow close];
if (p_id != NULL) {
vlc_dialog_id_dismiss(p_id);
}
p_id = NULL;
}
- (void)updateDisplayedProgressDialogWithID:(vlc_dialog_id *)p_id
value:(float)f_value
description:(const char *)psz_text
{
if (!progressIndicator.indeterminate) {
progressIndicator.doubleValue = f_value;
progressDescriptionLabel.stringValue = toNSStr(psz_text);
}
}
- (IBAction)progressDialogAction:(id)sender
{
[NSApp stopModalWithCode: 0];
}
@end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment