]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/bookmarks.m
macosx: prevent ugly artifacts when playing a video
[vlc] / modules / gui / macosx / bookmarks.m
index 4a2c15c994f76878e2a3ea93fa8332d2de0647cf..aaee87f1e78d514c81826f9d6c8899bc881a224d 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright (C) 2005 - 2007 the VideoLAN team
  * $Id$
  *
- * Authors: Felix Kühne <fkuehne@users.sf.net>
+ * Authors: 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
 #import "bookmarks.h"
 #import "wizard.h"
 #import <vlc_interface.h>
-
-/*****************************************************************************
- * VLCExtended implementation
- *
- * implements the GUI functions for the window, the data source and the
- * delegate for o_tbl_dataTable
- *****************************************************************************/
+#import "CompatibilityFixes.h"
 
 @implementation VLCBookmarks
 
@@ -71,13 +65,14 @@ static VLCBookmarks *_o_sharedInstance = nil;
 
 - (void)awakeFromNib
 {
+    if (OSX_LION)
+        [o_bookmarks_window setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
+
     [self initStrings];
 }
 
 - (void)dealloc
 {
-    if( p_old_input )
-        vlc_object_release( p_old_input );
     [super dealloc];
 }
 
@@ -117,24 +112,17 @@ static VLCBookmarks *_o_sharedInstance = nil;
 - (IBAction)add:(id)sender
 {
     /* add item to list */
-    intf_thread_t * p_intf = VLCIntf;
-    input_thread_t * p_input = (input_thread_t *)vlc_object_find( p_intf,
-        VLC_OBJECT_INPUT, FIND_ANYWHERE );
-    if( !p_input )
-        return;
+    input_thread_t * p_input = pl_CurrentInput( VLCIntf );
+
+    if( !p_input ) return;
  
     seekpoint_t bookmark;
-    vlc_value_t pos;
-    bookmark.psz_name = NULL;
-    bookmark.i_byte_offset = 0;
-    bookmark.i_time_offset = 0;
-    var_Get(p_intf, "position", &pos);
-    bookmark.psz_name = _("Untitled");
-    input_Control( p_input, INPUT_GET_BYTE_POSITION, &bookmark.i_byte_offset );
-    var_Get( p_input, "time", &pos );
-    bookmark.i_time_offset = pos.i_time;
-    input_Control( p_input, INPUT_ADD_BOOKMARK, &bookmark );
+
+    if( !input_Control( p_input, INPUT_GET_BOOKMARK, &bookmark ) )
+       {
+               bookmark.psz_name = _("Untitled");
+               input_Control( p_input, INPUT_ADD_BOOKMARK, &bookmark );
+       }
  
     vlc_object_release( p_input );
  
@@ -144,9 +132,7 @@ static VLCBookmarks *_o_sharedInstance = nil;
 - (IBAction)clear:(id)sender
 {
     /* clear table */
-    intf_thread_t * p_intf = VLCIntf;
-    input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
-        VLC_OBJECT_INPUT, FIND_ANYWHERE );
+    input_thread_t * p_input = pl_CurrentInput( VLCIntf );
  
     if( !p_input )
         return;
@@ -163,37 +149,32 @@ static VLCBookmarks *_o_sharedInstance = nil;
     /* put values to the sheet's fields and show sheet */
     /* we take the values from the core and not the table, because we cannot
      * really trust it */
-    intf_thread_t * p_intf = VLCIntf;
-    input_thread_t * p_input = (input_thread_t *)vlc_object_find( p_intf,
-        VLC_OBJECT_INPUT, FIND_ANYWHERE );
+    input_thread_t * p_input = pl_CurrentInput( VLCIntf );
     seekpoint_t **pp_bookmarks;
     int i_bookmarks;
     int row;
     row = [o_tbl_dataTable selectedRow];
  
-    if( !p_input )
-    {
+    if( !p_input && row < 0 )
         return;
-    }
-    else if( input_Control( p_input, INPUT_GET_BOOKMARKS, &pp_bookmarks,
+
+    if( input_Control( p_input, INPUT_GET_BOOKMARKS, &pp_bookmarks,
         &i_bookmarks ) != VLC_SUCCESS )
     {
         vlc_object_release( p_input );
         return;
     }
-    else if(row < 0)
-    {
-        vlc_object_release( p_input );
-        return;
-    } else {
-        [o_edit_fld_name setStringValue: [NSString stringWithUTF8String:
+
+    [o_edit_fld_name setStringValue: [NSString stringWithUTF8String:
             pp_bookmarks[row]->psz_name]];
-        [o_edit_fld_time setStringValue: [[NSNumber numberWithInt:
+    [o_edit_fld_time setStringValue: [[NSNumber numberWithInt:
             (pp_bookmarks[row]->i_time_offset / 1000000)] stringValue]];
-        [o_edit_fld_bytes setStringValue: [[NSNumber numberWithInt:
+    [o_edit_fld_bytes setStringValue: [[NSNumber numberWithInt:
             pp_bookmarks[row]->i_byte_offset] stringValue]];
-    }
  
+    /* Just keep the pointer value to check if it
+     * changes. Note, we don't need to keep a reference to the object.
+     * so release it now. */
     p_old_input = p_input;
     vlc_object_release( p_input );
 
@@ -202,6 +183,12 @@ static VLCBookmarks *_o_sharedInstance = nil;
         modalDelegate: o_edit_window
         didEndSelector: nil
         contextInfo: nil];
+
+    // Clear the bookmark list
+    for( int i = 0; i < i_bookmarks; i++)
+        vlc_seekpoint_Delete( pp_bookmarks[i] );
+    free( pp_bookmarks );
+
 }
 
 - (IBAction)edit_cancel:(id)sender
@@ -214,12 +201,9 @@ static VLCBookmarks *_o_sharedInstance = nil;
 - (IBAction)edit_ok:(id)sender
 {
     /* save field contents and close sheet */
-    intf_thread_t * p_intf = VLCIntf;
-    seekpoint_t **pp_bookmarks;
+     seekpoint_t **pp_bookmarks;
     int i_bookmarks, i;
-    input_thread_t *p_input = (input_thread_t *)vlc_object_find( p_intf,
-        VLC_OBJECT_INPUT, FIND_ANYWHERE );
+    input_thread_t * p_input = pl_CurrentInput( VLCIntf );
  
     if( !p_input )
     {
@@ -249,8 +233,7 @@ static VLCBookmarks *_o_sharedInstance = nil;
 
     i = [o_tbl_dataTable selectedRow];
  
-    if( pp_bookmarks[i]->psz_name )
-        free( pp_bookmarks[i]->psz_name );
+    free( pp_bookmarks[i]->psz_name );
 
     pp_bookmarks[i]->psz_name = strdup([[o_edit_fld_name stringValue] UTF8String]);
     pp_bookmarks[i]->i_byte_offset = [[o_edit_fld_bytes stringValue] intValue];
@@ -259,9 +242,8 @@ static VLCBookmarks *_o_sharedInstance = nil;
     if( input_Control( p_input, INPUT_CHANGE_BOOKMARK, pp_bookmarks[i], i )
         != VLC_SUCCESS )
     {
-        msg_Warn( p_intf, "Unable to change the bookmark");
-        vlc_object_release( p_input );
-        return;
+        msg_Warn( VLCIntf, "Unable to change the bookmark");
+        goto clear;
     }
  
     [o_tbl_dataTable reloadData];
@@ -270,14 +252,17 @@ static VLCBookmarks *_o_sharedInstance = nil;
  
     [NSApp endSheet: o_edit_window];
     [o_edit_window close];
+
+clear:
+    // Clear the bookmark list
+    for( int i = 0; i < i_bookmarks; i++)
+        vlc_seekpoint_Delete( pp_bookmarks[i] );
+    free( pp_bookmarks );
 }
 
 - (IBAction)extract:(id)sender
 {
     /* extract */
-    intf_thread_t * p_intf = VLCIntf;
     if( [o_tbl_dataTable numberOfSelectedRows] < 2 )
     {
         NSBeginAlertSheet(_NS("Invalid selection"), _NS("OK"),
@@ -285,9 +270,7 @@ static VLCBookmarks *_o_sharedInstance = nil;
             _NS("Two bookmarks have to be selected."));
         return;
     }
-    input_thread_t *p_input =
-        (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
-                                           FIND_ANYWHERE );
+    input_thread_t * p_input = pl_CurrentInput( VLCIntf );
     if( !p_input )
     {
         NSBeginCriticalAlertSheet(_NS("No input found"), _NS("OK"),
@@ -320,19 +303,19 @@ static VLCBookmarks *_o_sharedInstance = nil;
         x = (x + 1);
     }
  
-    msg_Dbg(p_intf, "got the bookmark-indexes");
+    msg_Dbg( VLCIntf, "got the bookmark-indexes");
  
     if( input_Control( p_input, INPUT_GET_BOOKMARKS, &pp_bookmarks,
         &i_bookmarks ) != VLC_SUCCESS )
     {
         vlc_object_release( p_input );
-        msg_Err(p_intf, "already defined bookmarks couldn't be retrieved");
+        msg_Err( VLCIntf, "already defined bookmarks couldn't be retrieved");
         return;
     }
-    msg_Dbg(p_intf, "calling wizard");
+    msg_Dbg( VLCIntf, "calling wizard");
 
     char *psz_uri = input_item_GetURI( input_GetItem( p_input ) );
-    [[[VLCMain sharedInstance] getWizard] initWithExtractValuesFrom:
+    [[[VLCMain sharedInstance] wizard] initWithExtractValuesFrom:
             [[NSNumber numberWithInt:
             (pp_bookmarks[i_first]->i_time_offset/1000000)] stringValue]
             to: [[NSNumber numberWithInt:
@@ -340,15 +323,17 @@ static VLCBookmarks *_o_sharedInstance = nil;
             ofItem: [NSString stringWithUTF8String: psz_uri]];
     free( psz_uri );
     vlc_object_release( p_input );
-    msg_Dbg(p_intf, "released input");
+    msg_Dbg( VLCIntf, "released input");
+
+    // Clear the bookmark list
+    for( int i = 0; i < i_bookmarks; i++)
+        vlc_seekpoint_Delete( pp_bookmarks[i] );
+    free( pp_bookmarks );
 }
 
 - (IBAction)goToBookmark:(id)sender
 {
-    intf_thread_t * p_intf = VLCIntf;
-    input_thread_t *p_input =
-    (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
-        FIND_ANYWHERE );
+    input_thread_t * p_input = pl_CurrentInput( VLCIntf );
  
     if( !p_input ) return;
 
@@ -360,10 +345,7 @@ static VLCBookmarks *_o_sharedInstance = nil;
 - (IBAction)remove:(id)sender
 {
     /* remove selected item */
-    intf_thread_t * p_intf = VLCIntf;
-    input_thread_t *p_input =
-    (input_thread_t *)vlc_object_find( p_intf, VLC_OBJECT_INPUT,
-        FIND_ANYWHERE );
+    input_thread_t * p_input = pl_CurrentInput( VLCIntf );
  
     if( !p_input ) return;
 
@@ -381,7 +363,7 @@ static VLCBookmarks *_o_sharedInstance = nil;
  * callback stuff
  *****************************************************************************/
 
--(id)getDataTable
+-(id)dataTable
 {
     return o_tbl_dataTable;
 }
@@ -390,12 +372,10 @@ static VLCBookmarks *_o_sharedInstance = nil;
  * data source methods
  *****************************************************************************/
 
-- (int)numberOfRowsInTableView:(NSTableView *)theDataTable
+- (NSInteger)numberOfRowsInTableView:(NSTableView *)theDataTable
 {
     /* return the number of bookmarks */
-    intf_thread_t * p_intf = VLCIntf;
-    input_thread_t * p_input = (input_thread_t *)vlc_object_find( p_intf,
-        VLC_OBJECT_INPUT, FIND_ANYWHERE );
+    input_thread_t * p_input = pl_CurrentInput( VLCIntf );
     seekpoint_t **pp_bookmarks;
     int i_bookmarks;
  
@@ -408,61 +388,65 @@ static VLCBookmarks *_o_sharedInstance = nil;
     }
     else {
         vlc_object_release( p_input );
+        // Clear the bookmark list
+        for( int i = 0; i < i_bookmarks; i++)
+            vlc_seekpoint_Delete( pp_bookmarks[i] );
+        free( pp_bookmarks );
         return i_bookmarks;
     }
 }
 
 - (id)tableView:(NSTableView *)theDataTable objectValueForTableColumn:
-    (NSTableColumn *)theTableColumn row: (int)row
+    (NSTableColumn *)theTableColumn row: (NSInteger)row
 {
     /* return the corresponding data as NSString */
-    intf_thread_t * p_intf = VLCIntf;
-    input_thread_t * p_input = (input_thread_t *)vlc_object_find( p_intf,
-        VLC_OBJECT_INPUT, FIND_ANYWHERE );
+    input_thread_t * p_input = pl_CurrentInput( VLCIntf );
     seekpoint_t **pp_bookmarks;
     int i_bookmarks;
     char *toBeReturned;
     int i_toBeReturned = 0;
+    id ret;
+
     if( !p_input ) return @"";
     else if( input_Control( p_input, INPUT_GET_BOOKMARKS, &pp_bookmarks,
                        &i_bookmarks ) != VLC_SUCCESS )
     {
-        vlc_object_release( p_input );
-        return @"";
+        ret = @"";
     }
     else
     {
         if ([[theTableColumn identifier] isEqualToString: @"description"])
         {
             toBeReturned = pp_bookmarks[row]->psz_name;
-            vlc_object_release( p_input );
-            return [NSString stringWithUTF8String: toBeReturned];
+            ret = [NSString stringWithUTF8String: toBeReturned];
         }
         else if ([[theTableColumn identifier] isEqualToString: @"size_offset"])
         {
             i_toBeReturned = pp_bookmarks[row]->i_byte_offset;
-            vlc_object_release( p_input );
-            return [[NSNumber numberWithInt: i_toBeReturned] stringValue];
+            ret = [[NSNumber numberWithInt: i_toBeReturned] stringValue];
         }
         else if ([[theTableColumn identifier] isEqualToString: @"time_offset"])
         {
             i_toBeReturned = pp_bookmarks[row]->i_time_offset;
-            vlc_object_release( p_input );
-            return [[NSNumber numberWithInt: (i_toBeReturned / 1000000)]
+            ret = [[NSNumber numberWithInt: (i_toBeReturned / 1000000)]
                 stringValue];
         }
         else
         {
             /* may not happen, just in case */
-            vlc_object_release( p_input );
-            msg_Err(p_intf, "unknown table column identifier (%s) while "
+            msg_Err( VLCIntf, "unknown table column identifier (%s) while "
                 "updating the bookmark table", [[theTableColumn identifier]
                 UTF8String] );
-            return @"unknown identifier";
+            ret = @"unknown identifier";
         }
-    }
 
+        // Clear the bookmark list
+        for( int i = 0; i < i_bookmarks; i++)
+            vlc_seekpoint_Delete( pp_bookmarks[i] );
+        free( pp_bookmarks );
+    }
+    vlc_object_release( p_input );
+    return ret;
 }
 
 /*****************************************************************************