]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/bookmarks.m
macosx: Ask to send a mail to our bugreport ML if a crash log is detected.
[vlc] / modules / gui / macosx / bookmarks.m
index 43920dbfa2f1a89dfd10bb0bc645cdeee3bcda4d..5c562b058101a0b8ef7939c8ab7fb2a56afd9a00 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * bookmarks.m: MacOS X Bookmarks window
  *****************************************************************************
- * Copyright (C) 2005, 2006 the VideoLAN team
+ * Copyright (C) 2005 - 2007 the VideoLAN team
  * $Id$
  *
  * Authors: Felix Kühne <fkuehne@users.sf.net>
 
 
 /*****************************************************************************
- * Note: 
- * the code used to bind with VLC's modules is heavily based upon 
- * ../wxwidgets/bookmarks.cpp, written by Gildas Bazin. 
- * (he is a member of the VideoLAN team) 
+ * Note:
+ * the code used to bind with VLC's modules is heavily based upon
+ * ../wxwidgets/bookmarks.cpp, written by Gildas Bazin.
+ * (he is a member of the VideoLAN team)
  *****************************************************************************/
 
 
@@ -35,7 +35,6 @@
  *****************************************************************************/
 
 #import "bookmarks.h"
-#import "intf.h"
 #import "wizard.h"
 #import <vlc_interface.h>
 
@@ -78,16 +77,14 @@ static VLCBookmarks *_o_sharedInstance = nil;
 - (void)dealloc
 {
     if( p_old_input )
-    {
         vlc_object_release( p_old_input );
-    }
     [super dealloc];
 }
 
 - (void)initStrings
 {
     /* localise the items */
-    
     /* main window */
     [o_bookmarks_window setTitle: _NS("Bookmarks")];
     [o_btn_add setTitle: _NS("Add")];
@@ -101,7 +98,7 @@ static VLCBookmarks *_o_sharedInstance = nil;
         setStringValue: _NS("Position")];
     [[[o_tbl_dataTable tableColumnWithIdentifier:@"time_offset"] headerCell]
         setStringValue: _NS("Time")];
-        
     /* edit window */
     [o_edit_btn_ok setTitle: _NS("OK")];
     [o_edit_btn_cancel setTitle: _NS("Cancel")];
@@ -120,44 +117,40 @@ 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);
+    var_Get( VLCIntf, "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 );
-    
     vlc_object_release( p_input );
-    
     [o_tbl_dataTable reloadData];
 }
 
 - (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;
 
     input_Control( p_input, INPUT_CLEAR_BOOKMARKS );
 
     vlc_object_release( p_input );
-    
     [o_tbl_dataTable reloadData];
 }
 
@@ -166,24 +159,22 @@ 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 )
     {
         return;
-    } 
+    }
     else 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 );
@@ -196,7 +187,7 @@ static VLCBookmarks *_o_sharedInstance = nil;
         [o_edit_fld_bytes setStringValue: [[NSNumber numberWithInt:
             pp_bookmarks[row]->i_byte_offset] stringValue]];
     }
-    
     p_old_input = p_input;
     vlc_object_release( p_input );
 
@@ -217,13 +208,10 @@ 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 )
     {
         NSBeginCriticalAlertSheet(_NS("No input"), _NS("OK"),
@@ -242,37 +230,34 @@ static VLCBookmarks *_o_sharedInstance = nil;
         vlc_object_release( p_input );
         return;
     }
-    
     if( input_Control( p_input, INPUT_GET_BOOKMARKS, &pp_bookmarks,
         &i_bookmarks ) != VLC_SUCCESS )
     {
         vlc_object_release( p_input );
         return;
-    } 
+    }
 
     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]->psz_name = strdup([[o_edit_fld_name stringValue] UTF8String]);
     pp_bookmarks[i]->i_byte_offset = [[o_edit_fld_bytes stringValue] intValue];
     pp_bookmarks[i]->i_time_offset = ([[o_edit_fld_time stringValue] intValue]  * 1000000);
-    
     if( input_Control( p_input, INPUT_CHANGE_BOOKMARK, pp_bookmarks[i], i )
         != VLC_SUCCESS )
     {
-        msg_Warn( p_intf, "Unable to change the bookmark");
+        msg_Warn( VLCIntf, "Unable to change the bookmark");
         vlc_object_release( p_input );
         return;
     }
-    
     [o_tbl_dataTable reloadData];
     vlc_object_release( p_input );
-     
-    
     [NSApp endSheet: o_edit_window];
     [o_edit_window close];
 }
@@ -280,27 +265,22 @@ static VLCBookmarks *_o_sharedInstance = nil;
 - (IBAction)extract:(id)sender
 {
     /* extract */
-    
-    intf_thread_t * p_intf = VLCIntf;
-    
     if( [o_tbl_dataTable numberOfSelectedRows] < 2 )
     {
         NSBeginAlertSheet(_NS("Invalid selection"), _NS("OK"),
-            @"", @"", o_bookmarks_window, nil, nil, nil, nil, 
+            @"", @"", o_bookmarks_window, nil, nil, nil, 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"),
-            @"", @"", o_bookmarks_window, nil, nil, nil, nil, 
+            @"", @"", o_bookmarks_window, nil, nil, nil, nil,
             _NS("The stream must be playing or paused for bookmarks to work."));
         return;
     }
-    
     seekpoint_t **pp_bookmarks;
     int i_bookmarks ;
     int i_first = -1;
@@ -315,7 +295,7 @@ static VLCBookmarks *_o_sharedInstance = nil;
             {
                 i_first = x;
                 c = 1;
-            } 
+            }
             else if (i_second == -1)
             {
                 i_second = x;
@@ -324,40 +304,35 @@ 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:
             [[NSNumber numberWithInt:
             (pp_bookmarks[i_first]->i_time_offset/1000000)] stringValue]
             to: [[NSNumber numberWithInt:
             (pp_bookmarks[i_second]->i_time_offset/1000000)] stringValue]
-            ofItem: [NSString stringWithUTF8String:
-            input_GetItem(p_input)->psz_uri]];
+            ofItem: [NSString stringWithUTF8String: psz_uri]];
+    free( psz_uri );
     vlc_object_release( p_input );
-    msg_Dbg(p_intf, "released input");
+    msg_Dbg( VLCIntf, "released input");
 }
 
 - (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 );
-    
-    if( !p_input ) 
-    {
-        return;
-    }
+    input_thread_t * p_input = pl_CurrentInput( VLCIntf );
+    if( !p_input ) return;
 
     input_Control( p_input, INPUT_SET_BOOKMARK, [o_tbl_dataTable selectedRow] );
 
@@ -367,21 +342,17 @@ 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;
 
     int i_focused = [o_tbl_dataTable selectedRow];
+
     if( i_focused >= 0 )
-    {
         input_Control( p_input, INPUT_DEL_BOOKMARK, i_focused );
-    }
 
     vlc_object_release( p_input );
-    
     [o_tbl_dataTable reloadData];
 }
 
@@ -401,16 +372,11 @@ static VLCBookmarks *_o_sharedInstance = nil;
 - (int)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;
-    
-    if( !p_input )
-    {
-        return 0;
-    }
+    if( !p_input ) return 0;
     else if( input_Control( p_input, INPUT_GET_BOOKMARKS, &pp_bookmarks,
                        &i_bookmarks ) != VLC_SUCCESS )
     {
@@ -427,57 +393,48 @@ static VLCBookmarks *_o_sharedInstance = nil;
     (NSTableColumn *)theTableColumn row: (int)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;
-    
-    if( !p_input )
-    {
-        return @"";
-    } 
+    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, but just in case */
-            vlc_object_release( p_input );
-            msg_Err(p_intf, "unknown table column identifier (%s) while "
+            /* may not happen, just in case */
+            msg_Err( VLCIntf, "unknown table column identifier (%s) while "
                 "updating the bookmark table", [[theTableColumn identifier]
-
                 UTF8String] );
-            return @"unknown identifier";
+            ret = @"unknown identifier";
         }
     }
-
+    vlc_object_release( p_input );
+    return ret;
 }
 
 /*****************************************************************************