]> git.sesse.net Git - vlc/commitdiff
macosx: implement 'dialog-fatal' and 'dialog-question' correctly and completely
authorFelix Paul Kühne <fkuehne@videolan.org>
Tue, 7 Apr 2009 17:46:45 +0000 (19:46 +0200)
committerFelix Paul Kühne <fkuehne@videolan.org>
Tue, 7 Apr 2009 17:46:45 +0000 (19:46 +0200)
This introduces a lot of dead code, which will be cleaned up later on, but is left there for reference.

modules/gui/macosx/interaction.h
modules/gui/macosx/interaction.m
modules/gui/macosx/intf.m

index bde4badb3cfdfebbb78fffc44e06aed9517e967f..b933dc3e8f107d549a05e21cc67858a3245c63c3 100644 (file)
@@ -1,11 +1,11 @@
 /*****************************************************************************
  * interaction.h: Mac OS X interaction dialogs
  *****************************************************************************
- * Copyright (C) 2005-2006 the VideoLAN team
+ * Copyright (C) 2005-2009 the VideoLAN team
  * $Id$
  *
  * Authors: Derk-Jan Hartman <hartman at videolan dot org>
- *          Felix Kühne <fkuehne at videolan dot org>
+ *          Felix Paul Kühne <fkuehne at videolan dot org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
-#include <vlc_common.h>
-#include <vlc_interface.h>
-#include <Cocoa/Cocoa.h>
+#import <vlc_common.h>
+#import <vlc_dialog.h>
+#import <Cocoa/Cocoa.h>
+
+
+/*****************************************************************************
+ * VLCErrorPanel interface
+ *****************************************************************************/
+
+@interface VLCErrorPanel : NSObject
+{
+    IBOutlet id o_window;
+    IBOutlet id o_cleanup_button;
+    IBOutlet id o_error_table;
+    IBOutlet id o_messages_btn;
+    
+    NSMutableArray * o_errors;
+    NSMutableArray * o_icons;
+    
+    BOOL nib_interact_errpanel_loaded;
+}
+- (IBAction)cleanupTable:(id)sender;
+- (IBAction)showMessages:(id)sender;
+
+-(void)showPanel;
+-(void)addError: (NSString *)o_error withMsg:(NSString *)o_msg;
+
+@end
+
+
+/*****************************************************************************
+ * VLCCoreDialogSupport interface
+ *****************************************************************************/
+@interface VLCCoreDialogSupport : NSObject
+{
+    NSMutableArray *o_interaction_list;
+    VLCErrorPanel *o_error_panel;
+}
+
+-(void)newInteractionEvent: (NSNotification *)o_notification;
+#if 0
+-(void)addInteraction: (interaction_dialog_t *)p_dialog;
+-(void)removeInteraction: (VLCInteraction *)p_interaction;
+#endif
+
+-(void)showFatalDialog: (NSValue *)o_value;
+-(void)showQuestionDialog: (NSValue *)o_value;
+
+-(id)getErrorPanel;
+
+@end
 
 /*****************************************************************************
  * VLCInteraction interface
  *****************************************************************************/
 
+#if 0
 @interface VLCInteraction : NSObject
 {
     /* progress dialogue */
     IBOutlet id o_auth_title;
     IBOutlet id o_auth_win;
 
-    /* string input dialogue */
-    IBOutlet id o_input_cancel_btn;
-    IBOutlet id o_input_description;
-    IBOutlet id o_input_fld;
-    IBOutlet id o_input_ok_btn;
-    IBOutlet id o_input_title;
-    IBOutlet id o_input_win;
-
-    interaction_dialog_t * p_dialog;
+    vlc_object_t * p_dialog;
     intf_thread_t * p_intf;
     NSProgressIndicator * o_mainIntfPgbar;
     BOOL nib_interact_loaded;
 }
 
-- (IBAction)cancelAndClose:(id)sender;
 - (IBAction)okayAndClose:(id)sender;
 - (IBAction)cancelDialog:(id)sender;
 
--(id)initDialog: (interaction_dialog_t *)_p_dialog;
+-(id)initDialog: (vlc_object_t *)_p_dialog;
 -(void)runDialog;
 -(void)updateDialog;
 -(void)hideDialog;
 -(void)destroyDialog;
 
 @end
-
-@interface VLCErrorInteractionPanel : NSObject
-{
-    IBOutlet id o_window;
-    IBOutlet id o_cleanup_button;
-    IBOutlet id o_error_table;
-    IBOutlet id o_messages_btn;
-
-    NSMutableArray * o_errors;
-    NSMutableArray * o_icons;
-
-    BOOL nib_interact_errpanel_loaded;
-}
-- (IBAction)cleanupTable:(id)sender;
-- (IBAction)showMessages:(id)sender;
-
--(void)showPanel;
--(void)addError: (NSString *)o_error withMsg:(NSString *)o_msg;
--(void)addWarning: (NSString *)o_warning withMsg:(NSString *)o_msg;
-
-@end
-
-/*****************************************************************************
- * VLCInteractionList interface
- *****************************************************************************/
-@interface VLCInteractionList : NSObject
-{
-    NSMutableArray *o_interaction_list;
-    VLCErrorInteractionPanel *o_error_panel;
-}
-
--(void)newInteractionEvent: (NSNotification *)o_notification;
--(void)addInteraction: (interaction_dialog_t *)p_dialog;
--(void)removeInteraction: (VLCInteraction *)p_interaction;
-
--(id)getErrorPanel;
-
-@end
+#endif
index eab3fb8811f09573a75425ba8117baec7eb04655..ed4abf39c83e03bf946ebc338ea91640b646cb02 100644 (file)
@@ -1,11 +1,11 @@
 /*****************************************************************************
  * interaction.h: Mac OS X interaction dialogs
  *****************************************************************************
- * Copyright (C) 2005-2007 the VideoLAN team
+ * Copyright (C) 2005-2009 the VideoLAN team
  * $Id$
  *
  * Authors: Derk-Jan Hartman <hartman at videolan dot org>
- *          Felix Kühne <fkuehne at videolan dot org>
+ *          Felix Paul Kühne <fkuehne at videolan dot org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -30,9 +30,9 @@
 #import <ApplicationServices/ApplicationServices.h>
 
 /*****************************************************************************
- * VLCInteractionList implementation
+ * VLCCoreDialogSupport implementation
  *****************************************************************************/
-@implementation VLCInteractionList
+@implementation VLCCoreDialogSupport
 
 -(id)init
 {
     o_interaction_list = [[NSMutableArray alloc] initWithCapacity:1];
     [[NSNotificationCenter defaultCenter] addObserver:self
         selector:@selector(newInteractionEvent:)
-        name: @"VLCNewInteractionEventNotification"
+        name: @"VLCNewCoreDialogEventNotification"
         object:self];
 
-    o_error_panel = [[VLCErrorInteractionPanel alloc] init];
+    o_error_panel = [[VLCErrorPanel alloc] init];
 
     return self;
 }
 
 -(void)newInteractionEvent: (NSNotification *)o_notification
 {
-    VLCInteraction *o_interaction;
     NSValue *o_value = [[o_notification userInfo] objectForKey:@"VLCDialogPointer"];
-    interaction_dialog_t *p_dialog = [o_value pointerValue];
+    NSString *o_type = [[o_notification userInfo] objectForKey:@"VLCDialogType"];
 
+    if( [o_type isEqualToString: @"dialog-fatal"] )
+        [self showFatalDialog: o_value];
+    else if( [o_type isEqualToString: @"dialog-question"] )
+        [self showQuestionDialog: o_value];
+    else
+        msg_Err( VLCIntf, "unhandled dialog type: '%s'", [o_type UTF8String] );
+
+#if 0
     switch( p_dialog->i_action )
     {
     case INTERACT_NEW:
         p_dialog->i_status = DESTROYED_DIALOG;
         break;
     }
+#endif
 }
 
+-(void)showFatalDialog: (NSValue *)o_value
+{
+    dialog_fatal_t *p_dialog = [o_value pointerValue];
+    /* do we need to block ? */
+    if( p_dialog->modal == YES )
+    {
+        NSAlert *o_alert;
+        o_alert = [NSAlert alertWithMessageText: [NSString stringWithUTF8String: p_dialog->title] defaultButton: _NS("OK") alternateButton: nil otherButton: nil informativeTextWithFormat: [NSString stringWithUTF8String: p_dialog->message]];
+        [o_alert setAlertStyle: NSCriticalAlertStyle];
+        [o_alert runModal];
+    }
+    else
+    {
+        [o_error_panel addError: [NSString stringWithUTF8String: p_dialog->title] withMsg: [NSString stringWithUTF8String: p_dialog->message]];
+        [o_error_panel showPanel];
+    }
+}
+
+-(void)showQuestionDialog: (NSValue *)o_value
+{
+    dialog_question_t *p_dialog = [o_value pointerValue];
+    NSAlert *o_alert;
+    NSString *o_yes, *o_no, *o_cancel;
+    NSInteger i_returnValue = 0;
+    
+    if( p_dialog->yes != NULL )
+        o_yes = [NSString stringWithUTF8String: p_dialog->yes];
+    if( p_dialog->no != NULL )
+        o_no = [NSString stringWithUTF8String: p_dialog->no];
+    if( p_dialog->cancel != NULL )
+        o_cancel = [NSString stringWithUTF8String: p_dialog->cancel];
+
+    o_alert = [NSAlert alertWithMessageText: [NSString stringWithUTF8String: p_dialog->title] defaultButton: o_yes alternateButton:o_no otherButton: o_cancel informativeTextWithFormat: [NSString stringWithUTF8String: p_dialog->message]];
+    [o_alert setAlertStyle: NSInformationalAlertStyle];
+    i_returnValue = [o_alert runModal];
+
+    if( i_returnValue == NSAlertDefaultReturn )
+        p_dialog->answer = 1;
+    if( i_returnValue == NSAlertAlternateReturn )
+        p_dialog->answer = 2;
+    if( i_returnValue == NSAlertOtherReturn )
+        p_dialog->answer = 3;
+}
+
+#if 0
 -(void)addInteraction: (interaction_dialog_t *)p_dialog
 {
     VLCInteraction *o_interaction = [[VLCInteraction alloc] initDialog: p_dialog];
 {
     [o_interaction_list removeObject:o_interaction];
 }
+#endif
 
 -(id)getErrorPanel
 {
 /*****************************************************************************
  * VLCInteraction implementation
  *****************************************************************************/
+#if 0
 @implementation VLCInteraction
 
--(id)initDialog: (interaction_dialog_t *)_p_dialog
+-(id)initDialog: (vlc_object_t *)_p_dialog
 {
     p_intf = VLCIntf;
     [super init];
         [o_auth_pw_txt setStringValue: _NS("Password:")];
         [o_auth_cancel_btn setTitle: _NS("Cancel")];
         [o_auth_ok_btn setTitle: _NS("OK")];
-        [o_input_ok_btn setTitle: _NS("OK")];
-        [o_input_cancel_btn setTitle: _NS("Cancel")];
         o_mainIntfPgbar = [[VLCMain sharedInstance] getMainIntfPgbar];
     }
 
         o_window = [NSApp mainWindow];
     }
 
-#if 0
     msg_Dbg( p_intf, "Title: %s", [o_title UTF8String] );
     msg_Dbg( p_intf, "Description: %s", [o_description UTF8String] );
-    msg_Dbg( p_intf, "Delivered flag: %i", p_dialog->i_flags );
-#endif
 
-    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:),
-            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]
-        addError: o_title withMsg: o_description];
-    }
-    else if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
+#if 0
+    dialog_question_t
     {
         msg_Dbg( p_intf, "yes-no-cancel-dialog requested" );
         NSBeginInformationalAlertSheet( o_title, o_defaultButton,
             @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil,
             o_description );
     }
-    else if( p_dialog->i_flags & DIALOG_LOGIN_PW_OK_CANCEL )
+
+    dialog_login_t
     {
         msg_Dbg( p_intf, "dialog for login and pw requested" );
         [o_auth_title setStringValue: o_title];
             modalDelegate: self didEndSelector: nil contextInfo: nil];
         [o_auth_win makeKeyWindow];
     }
-    else if( p_dialog->i_flags & DIALOG_USER_PROGRESS )
+
+    dialog_progress_bar_t
     {
         msg_Dbg( p_intf, "user progress dialog requested" );
         [o_prog_title setStringValue: o_title];
             modalDelegate: self didEndSelector: nil contextInfo: nil];
         [o_prog_win makeKeyWindow];
     }
-    else if( p_dialog->i_flags & DIALOG_PSZ_INPUT_OK_CANCEL )
-    {
-        msg_Dbg( p_intf, "text input from user requested" );
-        [o_input_title setStringValue: o_title];
-        [o_input_description setStringValue: o_description];
-        [o_input_fld setStringValue: @""];
-        [NSApp beginSheet: o_input_win modalForWindow: o_window
-            modalDelegate: self didEndSelector: nil contextInfo: nil];
-        [o_input_win makeKeyWindow];
-    }
-    else if( p_dialog->i_flags & DIALOG_INTF_PROGRESS )
+
+    DIALOG_INTF_PROGRESS
     {
         msg_Dbg( p_intf, "progress-bar in main intf requested" );
         [[VLCMain sharedInstance] setScrollField: o_description stopAfter: -1];
         [[[VLCMain sharedInstance] getControllerWindow] makeKeyWindow];
         [o_mainIntfPgbar setIndeterminate: NO];
     }
-    else
-        msg_Err( p_intf, "requested dialog type unknown (%i)", p_dialog->i_flags );
-}
-
-- (void)sheetDidEnd:(NSWindow *)o_sheet returnCode:(int)i_return
-    contextInfo:(void *)o_context
-{
-    vlc_mutex_lock( p_dialog->p_lock );
-    if( i_return == NSAlertDefaultReturn )
-    {
-        p_dialog->i_return = DIALOG_OK_YES;
-    }
-    else if( i_return == NSAlertAlternateReturn )
-    {
-        p_dialog->i_return = DIALOG_NO;
-    }
-    else if( i_return == NSAlertOtherReturn )
-    {
-        p_dialog->i_return = DIALOG_CANCELLED;
-    }
-    p_dialog->i_status = ANSWERED_DIALOG;
-    vlc_mutex_unlock( p_dialog->p_lock );
+#endif
 }
 
 -(void)updateDialog
 
         return;
     }
-    if( p_dialog->i_flags & DIALOG_INTF_PROGRESS )
-    {
-        [[VLCMain sharedInstance] setScrollField:
-            [NSString stringWithUTF8String: p_dialog->psz_description]
-            stopAfter: -1];
-        [o_mainIntfPgbar setDoubleValue: (double)p_dialog->val.f_float];
-
-        if( [o_mainIntfPgbar doubleValue] == 100.0 )
-        {
-            /* we are done, let's hide */
-            [self hideDialog];
-        }
-        return;
-    }
 }
 
 -(void)hideDialog
             [o_prog_win close];
         }
     }
-    if( p_dialog->i_flags & DIALOG_LOGIN_PW_OK_CANCEL )
-    {
-        if([o_auth_win isVisible])
-        {
-            [NSApp endSheet: o_auth_win];
-            [o_auth_win close];
-        }
-    }
-    if( p_dialog->i_flags & DIALOG_PSZ_INPUT_OK_CANCEL )
-    {
-        if([o_input_win isVisible])
-        {
-            [NSApp endSheet: o_input_win];
-            [o_input_win close];
-        }
-    }
-    if( p_dialog->i_flags & DIALOG_INTF_PROGRESS )
-    {
-        [o_mainIntfPgbar setIndeterminate: YES];
-        [o_mainIntfPgbar setHidden: YES];
-        [[VLCMain sharedInstance] resetScrollField];
-    }
 }
 
 -(void)destroyDialog
         [o_mainIntfPgbar release];
 }
 
-- (IBAction)cancelAndClose:(id)sender
-{
-    /* tell the core that the dialog was cancelled in a yes/no-style dialogue */
-    vlc_mutex_lock( p_dialog->p_lock );
-    p_dialog->i_return = DIALOG_CANCELLED;
-    p_dialog->i_status = ANSWERED_DIALOG;
-    vlc_mutex_unlock( p_dialog->p_lock );
-    msg_Dbg( p_intf, "dialog cancelled" );
-}
-
 - (IBAction)cancelDialog:(id)sender
 {
     /* tell core that the user wishes to cancel the dialogue
 }
 
 @end
-
+#endif
 /*****************************************************************************
- * VLCErrorInteractionPanel implementation
+ * VLCErrorPanel implementation
  *****************************************************************************/
-@implementation VLCErrorInteractionPanel
+@implementation VLCErrorPanel
 -(id)init
 {
     [super init];
     [o_error_table reloadData];
 }
 
--(void)addWarning: (NSString *)o_warning withMsg:(NSString *)o_msg
-{
-    /* format our string as desired */
-    NSMutableAttributedString * ourWarning;
-    ourWarning = [[NSMutableAttributedString alloc] initWithString:
-        [NSString stringWithFormat:@"%@\n%@", o_warning, o_msg]
-        attributes:
-        [NSDictionary dictionaryWithObject: [NSFont systemFontOfSize:11] forKey: NSFontAttributeName]];
-    [ourWarning
-        addAttribute: NSFontAttributeName
-        value: [NSFont boldSystemFontOfSize:11]
-        range: NSMakeRange( 0, [o_warning length])];
-    [o_errors addObject: ourWarning];
-    [ourWarning release];
-
-    [o_icons addObject: [NSImage imageWithWarningIcon]];
-    [o_error_table reloadData];
-}
-
 -(IBAction)cleanupTable:(id)sender
 {
     [o_errors removeAllObjects];
index 833dee43329f7d82696fd2360eb789231972f075..e34600ee7f9f94763e10080868d14136769a4fe5 100644 (file)
@@ -228,18 +228,13 @@ static int DialogCallback( vlc_object_t *p_this, const char *type, vlc_value_t p
 {
     NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
     VLCMain *interface = (VLCMain *)data;
-    
-    NSLog( @"dialog callback triggered; type of dialogue is '%s'", type );
-    if(!strcmp (type, "dialog-fatal"))
-    {
-        const dialog_fatal_t *p_dialog = (const dialog_fatal_t *)value.p_address;
-        NSLog( @"fatal dialogue with title '%s' and message '%s'", p_dialog->title, p_dialog->message );
-#if 0
-        NSValue *o_value = [NSValue valueWithPointer:p_dialog];
 
-        [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCNewInteractionEventNotification" object:[interface getInteractionList] userInfo:[NSDictionary dictionaryWithObject:o_value forKey:@"VLCDialogPointer"]];
-#endif
-    }
+    const dialog_fatal_t *p_dialog = (const dialog_fatal_t *)value.p_address;
+
+    NSLog( @"dialog callback triggered; type of dialogue is '%s'", type );
+    
+    NSValue *o_value = [NSValue valueWithPointer:p_dialog];
+    [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCNewCoreDialogEventNotification" object:[interface getInteractionList] userInfo:[NSDictionary dictionaryWithObjectsAndKeys: o_value, @"VLCDialogPointer", [NSString stringWithUTF8String: type], @"VLCDialogType", nil]];
 
     [o_pool release];
     return VLC_SUCCESS;
@@ -290,7 +285,7 @@ static VLCMain *_o_sharedMainInstance = nil;
     o_extended = nil;
     o_bookmarks = [[VLCBookmarks alloc] init];
     o_embedded_list = [[VLCEmbeddedList alloc] init];
-    o_interaction_list = [[VLCInteractionList alloc] init];
+    o_interaction_list = [[VLCCoreDialogSupport alloc] init];
     o_info = [[VLCInfo alloc] init];
 #ifdef UPDATE_CHECK
     o_update = [[VLCUpdate alloc] init];
@@ -471,6 +466,12 @@ static VLCMain *_o_sharedMainInstance = nil;
     /* subscribe to various interactive dialogues */
     var_Create( p_intf, "dialog-fatal", VLC_VAR_ADDRESS );
     var_AddCallback( p_intf, "dialog-fatal", DialogCallback, self );
+    var_Create( p_intf, "dialog-login", VLC_VAR_ADDRESS );
+    var_AddCallback( p_intf, "dialog-login", DialogCallback, self );
+    var_Create( p_intf, "dialog-question", VLC_VAR_ADDRESS );
+    var_AddCallback( p_intf, "dialog-question", DialogCallback, self );
+    var_Create( p_intf, "dialog-progress-bar", VLC_VAR_ADDRESS );
+    var_AddCallback( p_intf, "dialog-progress-bar", DialogCallback, self );
     dialog_Register( p_intf );
 
     /* update the playmode stuff */
@@ -747,6 +748,9 @@ static VLCMain *_o_sharedMainInstance = nil;
     /* unsubscribe from the interactive dialogues */
     dialog_Unregister( p_intf );
     var_DelCallback( p_intf, "dialog-fatal", DialogCallback, self );
+    var_DelCallback( p_intf, "dialog-login", DialogCallback, self );
+    var_DelCallback( p_intf, "dialog-question", DialogCallback, self );
+    var_DelCallback( p_intf, "dialog-progress-bar", DialogCallback, self );
 
     /* remove global observer watching for vout device changes correctly */
     [[NSNotificationCenter defaultCenter] removeObserver: self];
@@ -2117,8 +2121,8 @@ end:
 
 - (IBAction)showBookmarks:(id)sender
 {
-    dialog_Fatal( p_intf, _("Video Settings not saved"),
-                 _("An error occured while saving your settings via SimplePrefs.") );
+    dialog_Question( p_intf, _("Video Settings not saved"),
+                 _("An error occured while saving your settings via SimplePrefs."), "Yes", "No", "Cancel" );
 
     /* we need the wizard-nib for the bookmarks's extract functionality */
     if( !nib_wizard_loaded )
@@ -2156,7 +2160,7 @@ end:
     [o_update showUpdateWindow];
 #else
     msg_Err( VLCIntf, "Update checker wasn't enabled in this build" );
-    dialog_Fatal( VLCIntf, _("Update check failed"), _("Checking for updates was not enabled in this build.") );
+    dialog_FatalWait( VLCIntf, _("Update check failed"), _("Checking for updates was not enabled in this build.") );
 #endif
 }