]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/interaction.m
* download the updated versions through VLC and not through your default browser
[vlc] / modules / gui / macosx / interaction.m
index 48ad4ea7c4314f0fe2bf8d676d79a26426c57593..f5128077ee254a96245b5858b9e1391be382c100 100644 (file)
@@ -1,10 +1,11 @@
 /*****************************************************************************
  * interaction.h: Mac OS X interaction dialogs
  *****************************************************************************
- * Copyright (C) 2001-2005 the VideoLAN team
- * $Id: vout.h 13803 2005-12-18 18:54:28Z bigben $
+ * Copyright (C) 2005-2006 the VideoLAN team
+ * $Id$
  *
  * Authors: Derk-Jan Hartman <hartman at videolan dot org>
+ *          Felix 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
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 #include "intf.h"
-#import <interaction.h>
+#import "interaction.h"
 
 /*****************************************************************************
  * VLCInteractionList implementation
 
 -(id)initDialog: (interaction_dialog_t *)_p_dialog
 {
+    p_intf = VLCIntf;
     [super init];
     p_dialog = _p_dialog;
     return self;
     int i = 0;
     id o_window = NULL;
     if( !p_dialog )
-        NSLog( @"serious issue" );
+        msg_Err( p_intf, "serious issue (p_dialog == nil)" );
+
+    if( !nib_interact_loaded )
+    {
+        nib_interact_loaded = [NSBundle loadNibNamed:@"Interaction" owner:self];
+        [o_prog_cancel_btn setTitle: _NS("Cancel")];
+        [o_prog_bar setUsesThreadedAnimation: YES];
+    }
 
     NSString *o_title = [NSString stringWithUTF8String:p_dialog->psz_title ? p_dialog->psz_title : "title"];
-    NSString *o_description = [NSString stringWithUTF8String:p_dialog->psz_description ? p_dialog->psz_description : "desc"];
+    NSString *o_description = [NSString stringWithUTF8String:p_dialog->psz_description ? p_dialog->psz_description : ""];
     
     vout_thread_t *p_vout = vlc_object_find( VLCIntf, VLC_OBJECT_VOUT, FIND_ANYWHERE );
     if( p_vout != NULL )
         o_window = [NSApp mainWindow];
     }
     
-    NSLog( @"Title: %@", o_title );
-    NSLog( @"Description: %@", o_description );
+    msg_Dbg( p_intf, "Title: %s", [o_title UTF8String] );
+    msg_Dbg( p_intf, "Description: %s", [o_description UTF8String] );
     if( p_dialog->i_id == DIALOG_ERRORS )
     {
         for( i = 0; i < p_dialog->i_widgets; i++ )
         {
-            NSLog( @"Error: %@", [NSString stringWithUTF8String: p_dialog->pp_widgets[i]->psz_text] );
+            msg_Err( p_intf, "Error: %s", p_dialog->pp_widgets[i]->psz_text );
         }
     }
     else
     {
         for( i = 0; i < p_dialog->i_widgets; i++ )
         {
-            NSLog( @"widget: %@", [NSString stringWithUTF8String: p_dialog->pp_widgets[i]->psz_text] );
+            msg_Dbg( p_intf, "widget: %s", p_dialog->pp_widgets[i]->psz_text );
+            o_description = [o_description stringByAppendingString: \
+                [NSString stringWithUTF8String: \
+                    p_dialog->pp_widgets[i]->psz_text]];
         }
         if( p_dialog->i_flags & DIALOG_OK_CANCEL )
         {
-            NSBeginInformationalAlertSheet( o_title, @"OK" , @"Cancel", nil, o_window, self,
-                @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil, o_description );
+            msg_Dbg( p_intf, "requested flag: DIALOG_OK_CANCEL" );
+            NSBeginInformationalAlertSheet( o_title, @"OK" , @"Cancel", nil, \
+                o_window, self,@selector(sheetDidEnd: returnCode: contextInfo:),\
+                NULL, nil, o_description );
         }
         else if( p_dialog->i_flags & DIALOG_YES_NO_CANCEL )
         {
-            NSBeginInformationalAlertSheet( o_title, @"Yes" , @"No", @"Cancel", o_window, self,
-                @selector(sheetDidEnd: returnCode: contextInfo:), NULL, nil, o_description );
+            msg_Dbg( p_intf, "requested flag: DIALOG_YES_NO_CANCEL" );
+            NSBeginInformationalAlertSheet( o_title, @"Yes", @"No", @"Cancel", \
+                o_window, self,@selector(sheetDidEnd: returnCode: contextInfo:),\
+                NULL, nil, o_description );
+        }
+        else if( p_dialog->i_type & WIDGET_PROGRESS )
+        {
+            msg_Dbg( p_intf, "requested type: WIDGET_PROGRESS" );
+            [o_prog_title setStringValue: o_title];
+            [o_prog_description setStringValue: o_description];
+            [o_prog_bar setDoubleValue: 0];
+            [NSApp beginSheet: o_prog_win modalForWindow: o_window \
+                modalDelegate: self didEndSelector: nil contextInfo: nil];
+            [o_prog_win makeKeyWindow];
         }
         else
-            NSLog( @"not implemented yet" );
+            msg_Warn( p_intf, "requested dialog type not implemented yet" );
     }
 }
 
 
 -(void)updateDialog
 {
-    NSLog( @"update event" );
+    int i = 0;
+    for( i = 0 ; i< p_dialog->i_widgets; i++ )
+    {
+        if( p_dialog->i_type & WIDGET_PROGRESS )
+        {
+            [o_prog_bar setDoubleValue: \
+                (double)(p_dialog->pp_widgets[i]->val.f_float)];
+
+            if( [o_prog_bar doubleValue] == 100.0 )
+            {
+                /* we are done, let's hide */
+                [self hideDialog];
+                return;
+            }
+        }
+    }
 }
 
 -(void)hideDialog
 {
-    NSLog( @"hide event" );
+    msg_Dbg( p_intf, "hide event" );
+    if( p_dialog->i_type & WIDGET_PROGRESS )
+    {
+        [NSApp endSheet: o_prog_win];
+        [o_prog_win close];
+    }
 }
 
 -(void)destroyDialog
 {
-    NSLog( @"destroy event" );
+    msg_Dbg( p_intf, "destroy event" );
 }
 
--(void)dealloc
+- (IBAction)cancelAndClose:(id)sender
 {
-    [super dealloc];
+    /* tell the core that the dialog was cancelled */
+    vlc_mutex_lock( &p_dialog->p_interaction->object_lock );
+    p_dialog->i_return = DIALOG_CANCELLED;
+    p_dialog->i_status = ANSWERED_DIALOG;
+    vlc_mutex_unlock( &p_dialog->p_interaction->object_lock );
+    msg_Dbg( p_intf, "dialog cancelled" );
 }
 
-@end
\ No newline at end of file
+@end