]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/coredialogs.m
macosx: remove 2 interface update timers (2 threads), 1 additional interface update...
[vlc] / modules / gui / macosx / coredialogs.m
index 8ed476de35395288595251b9641f29cf0beffcce..7af5e69ab4c864c5bfeaff0d779e222c80f074ba 100644 (file)
 /* for the icon in our custom error panel */
 #import <ApplicationServices/ApplicationServices.h>
 
-
-/*****************************************************************************
- * Local prototypes.
- *****************************************************************************/
-
-bool b_progress_cancelled;
-static void updateProgressPanel (void *, const char *, float);
-static bool checkProgressPanel (void *);
-static void destroyProgressPanel (void *);
-
 /*****************************************************************************
  * VLCCoreDialogProvider implementation
  *****************************************************************************/
@@ -58,18 +48,6 @@ static VLCCoreDialogProvider *_o_sharedInstance = nil;
     else
     {
         _o_sharedInstance = [super init];
-        [[NSNotificationCenter defaultCenter] addObserver:self
-                                                 selector:@selector(performDialogEvent:)
-                                                     name: @"VLCNewCoreDialogEventNotification"
-                                                   object:self];
-        [[NSNotificationCenter defaultCenter] addObserver: self
-                                                 selector:@selector(performProgressBarEvent:)
-                                                     name:@"VLCCoreDialogProgressBarUpdateNotification" 
-                                                   object: self];
-        [[NSNotificationCenter defaultCenter] addObserver: self
-                                                 selector:@selector(performProgressBarEvent:)
-                                                     name:@"VLCCoreDialogProgressBarDestroyNotification" 
-                                                   object: self];
         o_error_panel = [[VLCErrorPanel alloc] init];
         b_progress_cancelled = NO;
     }
@@ -86,41 +64,42 @@ static VLCCoreDialogProvider *_o_sharedInstance = nil;
     [o_prog_cancel_btn setTitle: _NS("Cancel")];
     [o_prog_bar setUsesThreadedAnimation: YES];
 
-}    
+}
 
--(void)performDialogEvent: (NSNotification *)o_notification
+-(void)performEventWithObject: (NSValue *)o_value ofType: (const char*)type
 {
-    NSValue *o_value = [[o_notification userInfo] objectForKey:@"VLCDialogPointer"];
-    NSString *o_type = [[o_notification userInfo] objectForKey:@"VLCDialogType"];
+    NSString *o_type = [NSString stringWithUTF8String:type];
 
-    if( [o_type isEqualToString: @"dialog-fatal"] )
-        [self showFatalDialog: o_value];
+    if( [o_type isEqualToString: @"dialog-error"] )
+        [self performSelectorOnMainThread:@selector(showFatalDialog:) withObject:o_value waitUntilDone:YES];
+    else if( [o_type isEqualToString: @"dialog-critical"] )
+        [self performSelectorOnMainThread:@selector(showFatalWaitDialog:) withObject:o_value waitUntilDone:YES];
     else if( [o_type isEqualToString: @"dialog-question"] )
-        [self showQuestionDialog: o_value];
+        [self performSelectorOnMainThread:@selector(showQuestionDialog:) withObject:o_value waitUntilDone:YES];
     else if( [o_type isEqualToString: @"dialog-login"] )
-        [self showLoginDialog: o_value];
+        [self performSelectorOnMainThread:@selector(showLoginDialog:) withObject:o_value waitUntilDone:YES];
     else if( [o_type isEqualToString: @"dialog-progress-bar"] )
-        [self showProgressDialog: o_value];
+        [self performSelectorOnMainThread:@selector(showProgressDialog:) withObject:o_value waitUntilDone:YES];
     else
-        msg_Err( VLCIntf, "unhandled dialog type: '%s'", [o_type UTF8String] );
+        msg_Err( VLCIntf, "unhandled dialog type: '%s'", type );
 }
 
 -(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];
-    }
+
+    [o_error_panel addError: [NSString stringWithUTF8String: p_dialog->title] withMsg: [NSString stringWithUTF8String: p_dialog->message]];
+    [o_error_panel showPanel];
+}
+
+-(void)showFatalWaitDialog: (NSValue *)o_value
+{
+    dialog_fatal_t *p_dialog = [o_value pointerValue];
+    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];
 }
 
 -(void)showQuestionDialog: (NSValue *)o_value
@@ -205,69 +184,38 @@ static VLCCoreDialogProvider *_o_sharedInstance = nil;
     else
         [o_prog_description_txt setStringValue: @""];
     [o_prog_bar setDoubleValue: 0];
+    [o_prog_bar startAnimation: self];
 
-    p_dialog->pf_update = updateProgressPanel;
-    p_dialog->pf_check = checkProgressPanel;
-    p_dialog->pf_destroy = destroyProgressPanel;
-    p_dialog->p_sys = self;
-
-    [NSApp runModalForWindow: o_prog_win];
+    [o_prog_win makeKeyAndOrderFront: self];
 }
 
--(void)performProgressBarEvent: (NSNotification *)o_notification
+-(void)updateProgressPanelWithText: (NSString *)string andNumber: (double)d_number
 {
-    NSLog( @"%@ received", [o_notification name] );
-    if( [[o_notification name] isEqualToString: @"VLCCoreDialogProgressBarUpdateNotification"] )
-    {
-        NSNumber *o_number = [[o_notification userInfo] objectForKey:@"IntValue"];
-        NSString *o_text = [[o_notification userInfo] objectForKey:@"Text"];
-        [o_prog_description_txt setStringValue: o_text];
-        [o_prog_bar setDoubleValue: [o_number doubleValue]];
-    }
-    if( [[o_notification name] isEqualToString: @"VLCCoreDialogProgressBarDestroyNotification"] )
-    {
-        [NSApp stopModalWithCode: 0];
-        [o_prog_win close];
-    }
+    [o_prog_description_txt setStringValue: string];
+    [o_prog_bar setDoubleValue: d_number];
 }
 
-void updateProgressPanel (void *priv, const char *text, float value)
+-(void)destroyProgressPanel
 {
-    NSLog( @"we were updated with %s (%f)", text, value );
-    NSString *o_txt;
-    if( text != NULL )
-        o_txt = [NSString stringWithUTF8String: text];
-    [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCCoreDialogProgressBarUpdateNotification" object:[[VLCMain sharedInstance] getCoreDialogProvider] userInfo:[NSDictionary dictionaryWithObjectsAndKeys: o_txt, @"Text", [NSNumber numberWithInt: ((int)(value * 1000.))], @"IntValue", nil]];
+    [o_prog_bar stopAnimation: self];
+    [o_prog_win close];
 }
 
-void destroyProgressPanel (void *priv)
+-(IBAction)progDialogAction:(id)sender
 {
-    NSLog( @"we should destroy" );
-    [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCCoreDialogProgressBarDestroyNotification" object:[[VLCMain sharedInstance] getCoreDialogProvider] userInfo: nil];
+    b_progress_cancelled = YES;
 }
 
-bool checkProgressPanel (void *priv)
+-(BOOL)progressCancelled
 {
-    NSLog( @"we were checked" );
     return b_progress_cancelled;
 }
 
--(IBAction)progDialogAction:(id)sender
-{
-    NSLog( @"buttonAction!" );
-    b_progress_cancelled = YES;
-}
-
--(id)getErrorPanel
+-(id)errorPanel
 {
     return o_error_panel;
 }
 
--(void)dealloc
-{
-    [[NSNotificationCenter defaultCenter] removeObserver:self];
-    [super dealloc];
-}
 @end
 
 /*****************************************************************************
@@ -278,12 +226,15 @@ bool checkProgressPanel (void *priv)
 {
     [super init];
 
-    nib_loaded = [NSBundle loadNibNamed:@"InteractionErrorPanel" owner:self];
-
-    /* init strings */
-    [o_window setTitle: _NS("Errors and Warnings")];
-    [o_cleanup_button setTitle: _NS("Clean up")];
-    [o_messages_btn setTitle: _NS("Show Details")];
+    if( !b_nib_loaded )
+    {
+        b_nib_loaded = [NSBundle loadNibNamed:@"ErrorPanel" owner:self];
+    
+        /* init strings */
+        [o_window setTitle: _NS("Errors and Warnings")];
+        [o_cleanup_button setTitle: _NS("Clean up")];
+        [o_messages_btn setTitle: _NS("Show Details")];
+    }
 
     /* init data sources */
     o_errors = [[NSMutableArray alloc] init];
@@ -319,7 +270,7 @@ bool checkProgressPanel (void *priv)
     [o_errors addObject: ourError];
     [ourError release];
 
-    [o_icons addObject: [NSImage imageWithErrorIcon]];
+    [o_icons addObject: [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kAlertStopIcon)]];
 
     [o_error_table reloadData];
 }