X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fgui%2Fmacosx%2Finteraction.m;h=c62e36c4fcb93f38ac78b9ac9b0faac0074d3854;hb=8a5d95d032dd1d3773858ece1d5efe2f970d6bab;hp=c420800ff67477f666311eb20369f22008c0548e;hpb=d57320b4266d9835d85f5d69b7270fbcb087e23a;p=vlc diff --git a/modules/gui/macosx/interaction.m b/modules/gui/macosx/interaction.m index c420800ff6..c62e36c4fc 100644 --- a/modules/gui/macosx/interaction.m +++ b/modules/gui/macosx/interaction.m @@ -1,7 +1,7 @@ /***************************************************************************** * interaction.h: Mac OS X interaction dialogs ***************************************************************************** - * Copyright (C) 2005-2006 the VideoLAN team + * Copyright (C) 2005-2007 the VideoLAN team * $Id$ * * Authors: Derk-Jan Hartman @@ -11,7 +11,7 @@ * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -24,9 +24,10 @@ #import "intf.h" #import "interaction.h" +#import "misc.h" /* for the icons in our custom error panel */ -#import +#import /***************************************************************************** * VLCInteractionList implementation @@ -78,7 +79,7 @@ -(void)addInteraction: (interaction_dialog_t *)p_dialog { VLCInteraction *o_interaction = [[VLCInteraction alloc] initDialog: p_dialog]; - + p_dialog->p_private = (void *)o_interaction; [o_interaction_list addObject:[o_interaction autorelease]]; [o_interaction runDialog]; @@ -138,9 +139,9 @@ NSString *o_title = [NSString stringWithUTF8String:p_dialog->psz_title ? p_dialog->psz_title : _("Error")]; NSString *o_description = [NSString stringWithUTF8String:p_dialog->psz_description ? p_dialog->psz_description : ""]; - NSString *o_defaultButton = p_dialog->psz_defaultButton ? [NSString stringWithUTF8String:p_dialog->psz_defaultButton] : nil; - NSString *o_alternateButton = p_dialog->psz_alternateButton ? [NSString stringWithUTF8String:p_dialog->psz_alternateButton] : nil; - NSString *o_otherButton = p_dialog->psz_otherButton ? [NSString stringWithUTF8String:p_dialog->psz_otherButton] : nil; + NSString *o_defaultButton = p_dialog->psz_default_button ? [NSString stringWithUTF8String:p_dialog->psz_default_button] : nil; + NSString *o_alternateButton = p_dialog->psz_alternate_button ? [NSString stringWithUTF8String:p_dialog->psz_alternate_button] : nil; + NSString *o_otherButton = p_dialog->psz_other_button ? [NSString stringWithUTF8String:p_dialog->psz_other_button] : nil; vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT, FIND_ANYWHERE ); if( p_vout != NULL ) @@ -149,7 +150,7 @@ while( ( o_window = [o_enum nextObject] ) ) { - if( [[o_window className] isEqualToString: @"VLCWindow"] ) + if( [[o_window className] isEqualToString: @"VLCVoutWindow"] ) { vlc_object_release( (vlc_object_t *)p_vout ); break; @@ -171,28 +172,28 @@ if( p_dialog->i_flags & DIALOG_BLOCKING_ERROR ) { msg_Dbg( p_intf, "error panel requested" ); - NSBeginInformationalAlertSheet( o_title, _NS("OK"), nil, nil, - o_window, self, @selector(sheetDidEnd: returnCode: contextInfo:), + NSBeginInformationalAlertSheet( o_title, _NS("OK"), nil, nil, + o_window, self, @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil, o_description ); } else if( p_dialog->i_flags & DIALOG_NONBLOCKING_ERROR ) { msg_Dbg( p_intf, "addition to non-blocking error panel received" ); - [[[[VLCMain sharedInstance] getInteractionList] getErrorPanel] + [[[[VLCMain sharedInstance] getInteractionList] getErrorPanel] addError: o_title withMsg: o_description]; } else if( p_dialog->i_flags & DIALOG_WARNING ) { msg_Dbg( p_intf, "addition to non-blocking warning panel received" ); - [[[[VLCMain sharedInstance] getInteractionList] getErrorPanel] + [[[[VLCMain sharedInstance] getInteractionList] getErrorPanel] addWarning: o_title withMsg: o_description]; } else if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL ) { msg_Dbg( p_intf, "yes-no-cancel-dialog requested" ); - NSBeginInformationalAlertSheet( o_title, o_defaultButton, + NSBeginInformationalAlertSheet( o_title, o_defaultButton, o_alternateButton, o_otherButton, o_window, self, - @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil, + @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil, o_description ); } else if( p_dialog->i_flags & DIALOG_LOGIN_PW_OK_CANCEL ) @@ -247,7 +248,7 @@ - (void)sheetDidEnd:(NSWindow *)o_sheet returnCode:(int)i_return contextInfo:(void *)o_context { - vlc_mutex_lock( &p_dialog->p_interaction->object_lock ); + vlc_object_lock( p_dialog->p_interaction ); if( i_return == NSAlertDefaultReturn ) { p_dialog->i_return = DIALOG_OK_YES; @@ -261,14 +262,14 @@ p_dialog->i_return = DIALOG_CANCELLED; } p_dialog->i_status = ANSWERED_DIALOG; - vlc_mutex_unlock( &p_dialog->p_interaction->object_lock ); + vlc_object_unlock( p_dialog->p_interaction ); } -(void)updateDialog { if( p_dialog->i_flags & DIALOG_USER_PROGRESS ) { - [o_prog_description setStringValue: \ + [o_prog_description setStringValue: [NSString stringWithUTF8String: p_dialog->psz_description]]; [o_prog_bar setDoubleValue: (double)p_dialog->val.f_float]; @@ -304,21 +305,30 @@ -(void)hideDialog { - msg_Dbg( p_intf, "hide event" ); + msg_Dbg( p_intf, "hide event %p", self ); if( p_dialog->i_flags & DIALOG_USER_PROGRESS ) { - [NSApp endSheet: o_prog_win]; - [o_prog_win close]; + if([o_prog_win isVisible]) + { + [NSApp endSheet: o_prog_win]; + [o_prog_win close]; + } } if( p_dialog->i_flags & DIALOG_LOGIN_PW_OK_CANCEL ) { - [NSApp endSheet: o_auth_win]; - [o_auth_win close]; + if([o_auth_win isVisible]) + { + [NSApp endSheet: o_auth_win]; + [o_auth_win close]; + } } if( p_dialog->i_flags & DIALOG_PSZ_INPUT_OK_CANCEL ) { - [NSApp endSheet: o_input_win]; - [o_input_win close]; + if([o_input_win isVisible]) + { + [NSApp endSheet: o_input_win]; + [o_input_win close]; + } } if( p_dialog->i_flags & DIALOG_INTF_PROGRESS ) { @@ -338,10 +348,10 @@ - (IBAction)cancelAndClose:(id)sender { /* tell the core that the dialog was cancelled in a yes/no-style dialogue */ - vlc_mutex_lock( &p_dialog->p_interaction->object_lock ); + vlc_object_lock( p_dialog->p_interaction ); p_dialog->i_return = DIALOG_CANCELLED; p_dialog->i_status = ANSWERED_DIALOG; - vlc_mutex_unlock( &p_dialog->p_interaction->object_lock ); + vlc_object_unlock( p_dialog->p_interaction ); msg_Dbg( p_intf, "dialog cancelled" ); } @@ -349,16 +359,16 @@ { /* tell core that the user wishes to cancel the dialogue * Use this function if cancelling is optionally like in the progress-dialogue */ - vlc_mutex_lock( &p_dialog->p_interaction->object_lock ); - p_dialog->b_cancelled = VLC_TRUE; - vlc_mutex_unlock( &p_dialog->p_interaction->object_lock ); + vlc_object_lock( p_dialog->p_interaction ); + p_dialog->b_cancelled = true; + vlc_object_unlock( p_dialog->p_interaction ); msg_Dbg( p_intf, "cancelling dialog, will close it later on" ); } - (IBAction)okayAndClose:(id)sender { msg_Dbg( p_intf, "running okayAndClose" ); - vlc_mutex_lock( &p_dialog->p_interaction->object_lock ); + vlc_object_lock( p_dialog->p_interaction ); if( p_dialog->i_flags == DIALOG_LOGIN_PW_OK_CANCEL ) { p_dialog->psz_returned[0] = strdup( [[o_auth_login_fld stringValue] UTF8String] ); @@ -368,7 +378,7 @@ p_dialog->psz_returned[0] = strdup( [[o_input_fld stringValue] UTF8String] ); p_dialog->i_return = DIALOG_OK_YES; p_dialog->i_status = ANSWERED_DIALOG; - vlc_mutex_unlock( &p_dialog->p_interaction->object_lock ); + vlc_object_unlock( p_dialog->p_interaction ); msg_Dbg( p_intf, "dialog acknowledged" ); } @@ -394,49 +404,11 @@ o_errors = [[NSMutableArray alloc] init]; o_icons = [[NSMutableArray alloc] init]; - /* ugly Carbon stuff following... - * regrettably, you can't get the icons through clean Cocoa */ - - /* retrieve our error icon */ - IconRef ourIconRef; - int returnValue; - returnValue = GetIconRef(kOnSystemDisk, 'macs', 'stop', &ourIconRef); - errorIcon = [[NSImage alloc] initWithSize:NSMakeSize(32,32)]; - [errorIcon lockFocus]; - CGRect rect = CGRectMake(0,0,32,32); - PlotIconRefInContext((CGContextRef)[[NSGraphicsContext currentContext] - graphicsPort], - &rect, - kAlignNone, - kTransformNone, - NULL /*inLabelColor*/, - kPlotIconRefNormalFlags, - (IconRef)ourIconRef); - [errorIcon unlockFocus]; - returnValue = ReleaseIconRef(ourIconRef); - - /* retrieve our caution icon */ - returnValue = GetIconRef(kOnSystemDisk, 'macs', 'caut', &ourIconRef); - warnIcon = [[NSImage alloc] initWithSize:NSMakeSize(32,32)]; - [warnIcon lockFocus]; - PlotIconRefInContext((CGContextRef)[[NSGraphicsContext currentContext] - graphicsPort], - &rect, - kAlignNone, - kTransformNone, - NULL /*inLabelColor*/, - kPlotIconRefNormalFlags, - (IconRef)ourIconRef); - [warnIcon unlockFocus]; - returnValue = ReleaseIconRef(ourIconRef); - return self; } -(void)dealloc { - [errorIcon release]; - [warnIcon release]; [o_errors release]; [o_icons release]; [super dealloc]; @@ -453,19 +425,18 @@ NSMutableAttributedString * ourError; ourError = [[NSMutableAttributedString alloc] initWithString: [NSString stringWithFormat:@"%@\n%@", o_error, o_msg] - attributes: + attributes: [NSDictionary dictionaryWithObject: [NSFont systemFontOfSize:11] forKey: NSFontAttributeName]]; - [ourError + [ourError addAttribute: NSFontAttributeName - value: [NSFont boldSystemFontOfSize:11] + value: [NSFont boldSystemFontOfSize:11] range: NSMakeRange( 0, [o_error length])]; [o_errors addObject: ourError]; [ourError release]; - [o_icons addObject: errorIcon]; + [o_icons addObject: [NSImage imageWithErrorIcon]]; [o_error_table reloadData]; - [self showPanel]; } -(void)addWarning: (NSString *)o_warning withMsg:(NSString *)o_msg @@ -474,20 +445,18 @@ NSMutableAttributedString * ourWarning; ourWarning = [[NSMutableAttributedString alloc] initWithString: [NSString stringWithFormat:@"%@\n%@", o_warning, o_msg] - attributes: + attributes: [NSDictionary dictionaryWithObject: [NSFont systemFontOfSize:11] forKey: NSFontAttributeName]]; - [ourWarning + [ourWarning addAttribute: NSFontAttributeName - value: [NSFont boldSystemFontOfSize:11] + value: [NSFont boldSystemFontOfSize:11] range: NSMakeRange( 0, [o_warning length])]; [o_errors addObject: ourWarning]; [ourWarning release]; - [o_icons addObject: warnIcon]; - + [o_icons addObject: [NSImage imageWithWarningIcon]]; + [o_error_table reloadData]; - - [self showPanel]; } -(IBAction)cleanupTable:(id)sender