macosx: finally completed the progress-panel's implementation
authorFelix Paul Kühne <fkuehne@videolan.org>
Thu, 21 May 2009 15:03:47 +0000 (17:03 +0200)
committerFelix Paul Kühne <fkuehne@videolan.org>
Thu, 21 May 2009 15:04:52 +0000 (17:04 +0200)
modules/gui/macosx/coredialogs.h
modules/gui/macosx/coredialogs.m
modules/gui/macosx/intf.h
modules/gui/macosx/intf.m

index 5beb045..8fecec1 100644 (file)
     IBOutlet id o_auth_win;
 
     /* progress dialogue */
-    IBOutlet id o_prog_bar;
+    IBOutlet NSProgressIndicator * o_prog_bar;
     IBOutlet id o_prog_cancel_btn;
     IBOutlet id o_prog_description_txt;
     IBOutlet id o_prog_title_txt;
     IBOutlet id o_prog_win;
+    BOOL b_progress_cancelled;
 }
 + (VLCCoreDialogProvider *)sharedInstance;
 
 -(void)performDialogEvent: (NSNotification *)o_notification;
--(void)performProgressBarEvent: (NSNotification *)o_notification;
 
 -(void)showFatalDialog: (NSValue *)o_value;
 -(void)showQuestionDialog: (NSValue *)o_value;
+
 -(void)showLoginDialog: (NSValue *)o_value;
 -(IBAction)loginDialogAction:(id)sender;
+
 -(void)showProgressDialog: (NSValue *)o_value;
 -(IBAction)progDialogAction:(id)sender;
+-(BOOL)progressCancelled;
+-(void)updateProgressPanelWithText: (NSString *)string andNumber: (double)d_number;
+-(void)destroyProgressPanel;
 
 -(id)errorPanel;
 
index 925c994..62ed718 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
  *****************************************************************************/
@@ -62,14 +52,6 @@ static VLCCoreDialogProvider *_o_sharedInstance = nil;
                                                  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;
     }
@@ -205,59 +187,33 @@ 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] coreDialogProvider] 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] coreDialogProvider] 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)errorPanel
 {
     return o_error_panel;
index 6f85f51..d983f82 100644 (file)
@@ -83,8 +83,6 @@ struct intf_sys_t
     msg_subscription_t * p_sub;
 };
 
-static void MsgCallback( msg_cb_data_t *, msg_item_t *, unsigned );
-
 /*****************************************************************************
  * VLCMain interface
  *****************************************************************************/
index 4757dde..ef0baaa 100644 (file)
@@ -69,6 +69,12 @@ static void * ManageThread( void *user_data );
 static unichar VLCKeyToCocoa( unsigned int i_key );
 static unsigned int VLCModifiersToCocoa( unsigned int i_key );
 
+static void updateProgressPanel (void *, const char *, float);
+static bool checkProgressPanel (void *);
+static void destroyProgressPanel (void *);
+
+static void MsgCallback( msg_cb_data_t *, msg_item_t *, unsigned );
+
 #pragma mark -
 #pragma mark VLC Interface Object Callbacks
 
@@ -176,7 +182,6 @@ static void MsgCallback( msg_cb_data_t *data, msg_item_t *item, unsigned int i )
     vlc_restorecancel( canc );
 }
 
-
 /*****************************************************************************
  * playlistChanged: Callback triggered by the intf-change playlist
  * variable, to let the intf update the playlist.
@@ -231,15 +236,53 @@ 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;
 
-    const dialog_fatal_t *p_dialog = (const dialog_fatal_t *)value.p_address;
+    if( [[NSString stringWithUTF8String: type] isEqualToString: @"dialog-progress-bar"] )
+    {
+        /* the progress panel needs to update itself and therefore wants special treatment within this context */
+        dialog_progress_bar_t *p_dialog = (dialog_progress_bar_t *)value.p_address;
 
-    NSValue *o_value = [NSValue valueWithPointer:p_dialog];
+        p_dialog->pf_update = updateProgressPanel;
+        p_dialog->pf_check = checkProgressPanel;
+        p_dialog->pf_destroy = destroyProgressPanel;
+        p_dialog->p_sys = VLCIntf->p_libvlc;
+    }
+
+    NSValue *o_value = [NSValue valueWithPointer:value.p_address];
     [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCNewCoreDialogEventNotification" object:[interface coreDialogProvider] userInfo:[NSDictionary dictionaryWithObjectsAndKeys: o_value, @"VLCDialogPointer", [NSString stringWithUTF8String: type], @"VLCDialogType", nil]];
 
     [o_pool release];
     return VLC_SUCCESS;
 }
 
+void updateProgressPanel (void *priv, const char *text, float value)
+{
+    NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
+
+    NSString *o_txt;
+    if( text != NULL )
+        o_txt = [NSString stringWithUTF8String: text];
+    else
+        o_txt = @"";
+
+    [[[VLCMain sharedInstance] coreDialogProvider] updateProgressPanelWithText: o_txt andNumber: (double)(value * 1000.)];
+
+    [o_pool release];
+}
+
+void destroyProgressPanel (void *priv)
+{
+    NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
+    [[[VLCMain sharedInstance] coreDialogProvider] destroyProgressPanel];
+    [o_pool release];
+}
+
+bool checkProgressPanel (void *priv)
+{
+    NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
+    return [[[VLCMain sharedInstance] coreDialogProvider] progressCancelled];
+    [o_pool release];
+}
+
 #pragma mark -
 #pragma mark Private