Commit 2039e055 authored by Felix Paul Kühne's avatar Felix Paul Kühne

macosx: fix and clean-up the bookmarks code (close #6947)

The code is far from being great, but it matches the Qt intf now.
(cherry picked from commit cd612818db02b7831bec1d72e0a864f968daed6a)

Conflicts:
	modules/gui/macosx/bookmarks.m
parent d8ee86a4
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
input_thread_t *p_old_input; input_thread_t *p_old_input;
} }
+ (VLCBookmarks *)sharedInstance;
- (IBAction)add:(id)sender; - (IBAction)add:(id)sender;
- (IBAction)clear:(id)sender; - (IBAction)clear:(id)sender;
...@@ -60,9 +61,6 @@ ...@@ -60,9 +61,6 @@
- (IBAction)edit_cancel:(id)sender; - (IBAction)edit_cancel:(id)sender;
- (IBAction)edit_ok:(id)sender; - (IBAction)edit_ok:(id)sender;
+ (VLCBookmarks *)sharedInstance;
- (void)initStrings;
- (void)showBookmarks; - (void)showBookmarks;
- (id)dataTable; - (id)dataTable;
@end @end
...@@ -117,12 +117,12 @@ static VLCBookmarks *_o_sharedInstance = nil; ...@@ -117,12 +117,12 @@ static VLCBookmarks *_o_sharedInstance = nil;
/* add item to list */ /* add item to list */
input_thread_t * p_input = pl_CurrentInput( VLCIntf ); input_thread_t * p_input = pl_CurrentInput( VLCIntf );
if( !p_input ) return; if( !p_input )
return;
seekpoint_t bookmark; seekpoint_t bookmark;
if( !input_Control( p_input, INPUT_GET_BOOKMARK, &bookmark ) ) if( !input_Control( p_input, INPUT_GET_BOOKMARK, &bookmark ) ) {
{
bookmark.psz_name = _("Untitled"); bookmark.psz_name = _("Untitled");
input_Control( p_input, INPUT_ADD_BOOKMARK, &bookmark ); input_Control( p_input, INPUT_ADD_BOOKMARK, &bookmark );
} }
...@@ -161,43 +161,36 @@ static VLCBookmarks *_o_sharedInstance = nil; ...@@ -161,43 +161,36 @@ static VLCBookmarks *_o_sharedInstance = nil;
if( !p_input ) if( !p_input )
return; return;
if (row < 0) if( row < 0 ) {
{
vlc_object_release( p_input ); vlc_object_release( p_input );
return; return;
} }
if( input_Control( p_input, INPUT_GET_BOOKMARKS, &pp_bookmarks, if( input_Control( p_input, INPUT_GET_BOOKMARKS, &pp_bookmarks, &i_bookmarks ) != VLC_SUCCESS ) {
&i_bookmarks ) != VLC_SUCCESS )
{
vlc_object_release( p_input ); vlc_object_release( p_input );
return; return;
} }
[o_edit_fld_name setStringValue: [NSString stringWithUTF8String: [o_edit_fld_name setStringValue: [NSString stringWithFormat:@"%s", pp_bookmarks[row]->psz_name]];
pp_bookmarks[row]->psz_name]]; int total = pp_bookmarks[row]->i_time_offset/ 1000000;
[o_edit_fld_time setStringValue: [[NSNumber numberWithInt: int hour = total / (60*60);
(pp_bookmarks[row]->i_time_offset / 1000000)] stringValue]]; int min = (total - hour*60*60) / 60;
[o_edit_fld_bytes setStringValue: [[NSNumber numberWithInt: int sec = total - hour*60*60 - min*60;
pp_bookmarks[row]->i_byte_offset] stringValue]]; [o_edit_fld_time setStringValue: [NSString stringWithFormat:@"%02d:%02d:%02d", hour, min, sec]];
[o_edit_fld_bytes setStringValue: [NSString stringWithFormat:@"%lli", pp_bookmarks[row]->i_byte_offset]];
/* Just keep the pointer value to check if it /* Just keep the pointer value to check if it
* changes. Note, we don't need to keep a reference to the object. * changes. Note, we don't need to keep a reference to the object.
* so release it now. */ * so release it now. */
p_old_input = p_input; p_old_input = p_input;
vlc_object_release( p_input ); vlc_object_release( p_input );
[NSApp beginSheet: o_edit_window [NSApp beginSheet: o_edit_window modalForWindow: o_bookmarks_window modalDelegate: o_edit_window didEndSelector: nil contextInfo: nil];
modalForWindow: o_bookmarks_window
modalDelegate: o_edit_window
didEndSelector: nil
contextInfo: nil];
// Clear the bookmark list // Clear the bookmark list
for( int i = 0; i < i_bookmarks; i++) for( int i = 0; i < i_bookmarks; i++)
vlc_seekpoint_Delete( pp_bookmarks[i] ); vlc_seekpoint_Delete( pp_bookmarks[i] );
free( pp_bookmarks ); free( pp_bookmarks );
} }
- (IBAction)edit_cancel:(id)sender - (IBAction)edit_cancel:(id)sender
...@@ -213,29 +206,17 @@ static VLCBookmarks *_o_sharedInstance = nil; ...@@ -213,29 +206,17 @@ static VLCBookmarks *_o_sharedInstance = nil;
seekpoint_t **pp_bookmarks; seekpoint_t **pp_bookmarks;
int i_bookmarks, i; int i_bookmarks, i;
input_thread_t * p_input = pl_CurrentInput( VLCIntf ); input_thread_t * p_input = pl_CurrentInput( VLCIntf );
if( !p_input ) if( !p_input ) {
{ NSBeginCriticalAlertSheet(_NS("No input"), _NS("OK"), @"", @"", o_bookmarks_window, nil, nil, nil, nil, _NS("No input found. A stream must be playing or paused for bookmarks to work."));
NSBeginCriticalAlertSheet(_NS("No input"), _NS("OK"),
@"", @"", o_bookmarks_window, nil, nil, nil, nil, _NS("No "
"input found. A stream must be playing or paused for "
"bookmarks to work."));
return;
} }
if( p_old_input != p_input ) if( p_old_input != p_input ) {
{ NSBeginCriticalAlertSheet(_NS("Input has changed"), _NS("OK"), @"", @"", o_bookmarks_window, nil, nil, nil, nil, _NS("Input has changed, unable to save bookmark. Suspending playback with \"Pause\" while editing bookmarks to ensure to keep the same input."));
NSBeginCriticalAlertSheet(_NS("Input has changed"), _NS("OK"),
@"", @"", o_bookmarks_window, nil, nil, nil, nil, _NS("Input "
"has changed, unable to save bookmark. Suspending playback with "
"\"Pause\" while editing bookmarks to ensure to keep the same "
"input."));
vlc_object_release( p_input ); vlc_object_release( p_input );
return; return;
} }
if( input_Control( p_input, INPUT_GET_BOOKMARKS, &pp_bookmarks, if( input_Control( p_input, INPUT_GET_BOOKMARKS, &pp_bookmarks, &i_bookmarks ) != VLC_SUCCESS ) {
&i_bookmarks ) != VLC_SUCCESS )
{
vlc_object_release( p_input ); vlc_object_release( p_input );
return; return;
} }
...@@ -246,19 +227,28 @@ static VLCBookmarks *_o_sharedInstance = nil; ...@@ -246,19 +227,28 @@ static VLCBookmarks *_o_sharedInstance = nil;
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_byte_offset = [[o_edit_fld_bytes stringValue] intValue];
pp_bookmarks[i]->i_time_offset = ([[o_edit_fld_time stringValue] intValue] * 1000000);
NSArray * components = [[o_edit_fld_time stringValue] componentsSeparatedByString:@":"];
if( input_Control( p_input, INPUT_CHANGE_BOOKMARK, pp_bookmarks[i], i ) NSUInteger componentCount = [components count];
!= VLC_SUCCESS ) if( componentCount == 1 )
{ pp_bookmarks[i]->i_time_offset = 1000000 * ( [[components objectAtIndex:0] intValue] );
else if( componentCount == 2 )
pp_bookmarks[i]->i_time_offset = 1000000 * ( [[components objectAtIndex:0] intValue] * 60 + [[components objectAtIndex:1] intValue] );
else if( componentCount == 3 )
pp_bookmarks[i]->i_time_offset = 1000000 * ( [[components objectAtIndex:0] intValue] * 3600 + [[components objectAtIndex:1] intValue] * 60 + [[components objectAtIndex:2] intValue] );
else {
msg_Err( VLCIntf, "Invalid string format for time" );
goto clear;
}
if( input_Control( p_input, INPUT_CHANGE_BOOKMARK, pp_bookmarks[i], i ) != VLC_SUCCESS ) {
msg_Warn( VLCIntf, "Unable to change the bookmark"); msg_Warn( VLCIntf, "Unable to change the bookmark");
goto clear; goto clear;
} }
[o_tbl_dataTable reloadData]; [o_tbl_dataTable reloadData];
vlc_object_release( p_input ); vlc_object_release( p_input );
[NSApp endSheet: o_edit_window]; [NSApp endSheet: o_edit_window];
[o_edit_window close]; [o_edit_window close];
...@@ -271,20 +261,13 @@ clear: ...@@ -271,20 +261,13 @@ clear:
- (IBAction)extract:(id)sender - (IBAction)extract:(id)sender
{ {
/* extract */ if( [o_tbl_dataTable numberOfSelectedRows] < 2 ) {
if( [o_tbl_dataTable numberOfSelectedRows] < 2 ) NSBeginAlertSheet(_NS("Invalid selection"), _NS("OK"), @"", @"", o_bookmarks_window, nil, nil, nil, nil, _NS("Two bookmarks have to be selected."));
{
NSBeginAlertSheet(_NS("Invalid selection"), _NS("OK"),
@"", @"", o_bookmarks_window, nil, nil, nil, nil,
_NS("Two bookmarks have to be selected."));
return; return;
} }
input_thread_t * p_input = pl_CurrentInput( VLCIntf ); input_thread_t * p_input = pl_CurrentInput( VLCIntf );
if( !p_input ) if( !p_input ) {
{ NSBeginCriticalAlertSheet(_NS("No input found"), _NS("OK"), @"", @"", o_bookmarks_window, nil, nil, nil, nil, _NS("The stream must be playing or paused for bookmarks to work."));
NSBeginCriticalAlertSheet(_NS("No input found"), _NS("OK"),
@"", @"", o_bookmarks_window, nil, nil, nil, nil,
_NS("The stream must be playing or paused for bookmarks to work."));
return; return;
} }
...@@ -293,44 +276,28 @@ clear: ...@@ -293,44 +276,28 @@ clear:
int i_first = -1; int i_first = -1;
int i_second = -1; int i_second = -1;
int c = 0; int c = 0;
for (NSUInteger x = 0; c != 2; x++) for (NSUInteger x = 0; c != 2; x++) {
{ if([o_tbl_dataTable isRowSelected:x]) {
if([o_tbl_dataTable isRowSelected:x]) if (i_first == -1) {
{
if (i_first == -1)
{
i_first = x; i_first = x;
c = 1; c = 1;
} } else if (i_second == -1) {
else if (i_second == -1)
{
i_second = x; i_second = x;
c = 2; c = 2;
} }
} }
} }
msg_Dbg( VLCIntf, "got the bookmark-indexes"); if( input_Control( p_input, INPUT_GET_BOOKMARKS, &pp_bookmarks, &i_bookmarks ) != VLC_SUCCESS ) {
if( input_Control( p_input, INPUT_GET_BOOKMARKS, &pp_bookmarks,
&i_bookmarks ) != VLC_SUCCESS )
{
vlc_object_release( p_input ); vlc_object_release( p_input );
msg_Err( VLCIntf, "already defined bookmarks couldn't be retrieved"); msg_Err( VLCIntf, "already defined bookmarks couldn't be retrieved");
return; return;
} }
msg_Dbg( VLCIntf, "calling wizard");
char *psz_uri = input_item_GetURI( input_GetItem( p_input ) ); char *psz_uri = input_item_GetURI( input_GetItem( p_input ) );
[[[VLCMain sharedInstance] wizard] initWithExtractValuesFrom: [[[VLCMain sharedInstance] wizard] initWithExtractValuesFrom: [NSString stringWithFormat:@"%lli", pp_bookmarks[i_first]->i_time_offset/1000000] to: [NSString stringWithFormat:@"%lli", pp_bookmarks[i_second]->i_time_offset/1000000] ofItem: [NSString stringWithFormat:@"%s", psz_uri]];
[[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: psz_uri]];
free( psz_uri ); free( psz_uri );
vlc_object_release( p_input ); vlc_object_release( p_input );
msg_Dbg( VLCIntf, "released input");
// Clear the bookmark list // Clear the bookmark list
for( int i = 0; i < i_bookmarks; i++) for( int i = 0; i < i_bookmarks; i++)
...@@ -341,8 +308,9 @@ clear: ...@@ -341,8 +308,9 @@ clear:
- (IBAction)goToBookmark:(id)sender - (IBAction)goToBookmark:(id)sender
{ {
input_thread_t * p_input = pl_CurrentInput( VLCIntf ); input_thread_t * p_input = pl_CurrentInput( VLCIntf );
if( !p_input ) return; if( !p_input )
return;
input_Control( p_input, INPUT_SET_BOOKMARK, [o_tbl_dataTable selectedRow] ); input_Control( p_input, INPUT_SET_BOOKMARK, [o_tbl_dataTable selectedRow] );
...@@ -351,10 +319,10 @@ clear: ...@@ -351,10 +319,10 @@ clear:
- (IBAction)remove:(id)sender - (IBAction)remove:(id)sender
{ {
/* remove selected item */
input_thread_t * p_input = pl_CurrentInput( VLCIntf ); input_thread_t * p_input = pl_CurrentInput( VLCIntf );
if( !p_input ) return; if( !p_input )
return;
int i_focused = [o_tbl_dataTable selectedRow]; int i_focused = [o_tbl_dataTable selectedRow];
...@@ -385,15 +353,13 @@ clear: ...@@ -385,15 +353,13 @@ clear:
input_thread_t * p_input = pl_CurrentInput( VLCIntf ); input_thread_t * p_input = pl_CurrentInput( VLCIntf );
seekpoint_t **pp_bookmarks; seekpoint_t **pp_bookmarks;
int i_bookmarks; int i_bookmarks;
if( !p_input ) return 0; if( !p_input )
else if( input_Control( p_input, INPUT_GET_BOOKMARKS, &pp_bookmarks, return 0;
&i_bookmarks ) != VLC_SUCCESS ) else if( input_Control( p_input, INPUT_GET_BOOKMARKS, &pp_bookmarks, &i_bookmarks ) != VLC_SUCCESS ) {
{
vlc_object_release( p_input ); vlc_object_release( p_input );
return 0; return 0;
} } else {
else {
vlc_object_release( p_input ); vlc_object_release( p_input );
// Clear the bookmark list // Clear the bookmark list
for( int i = 0; i < i_bookmarks; i++) for( int i = 0; i < i_bookmarks; i++)
...@@ -403,48 +369,29 @@ clear: ...@@ -403,48 +369,29 @@ clear:
} }
} }
- (id)tableView:(NSTableView *)theDataTable objectValueForTableColumn: - (id)tableView:(NSTableView *)theDataTable objectValueForTableColumn: (NSTableColumn *)theTableColumn row: (NSInteger)row
(NSTableColumn *)theTableColumn row: (NSInteger)row
{ {
/* return the corresponding data as NSString */ /* return the corresponding data as NSString */
input_thread_t * p_input = pl_CurrentInput( VLCIntf ); input_thread_t * p_input = pl_CurrentInput( VLCIntf );
seekpoint_t **pp_bookmarks; seekpoint_t **pp_bookmarks;
int i_bookmarks; int i_bookmarks;
char *toBeReturned;
int i_toBeReturned = 0;
id ret; id ret;
if( !p_input ) return @""; if( !p_input ) return @"";
else if( input_Control( p_input, INPUT_GET_BOOKMARKS, &pp_bookmarks, else if( input_Control( p_input, INPUT_GET_BOOKMARKS, &pp_bookmarks, &i_bookmarks ) != VLC_SUCCESS )
&i_bookmarks ) != VLC_SUCCESS )
{
ret = @""; ret = @"";
} else {
else
{
NSString * identifier = [theTableColumn identifier]; NSString * identifier = [theTableColumn identifier];
if ([identifier isEqualToString: @"description"]) if ([identifier isEqualToString: @"description"]) {
{ ret = [NSString stringWithFormat:@"%s", pp_bookmarks[row]->psz_name];
toBeReturned = pp_bookmarks[row]->psz_name; } else if ([identifier isEqualToString: @"size_offset"]) {
ret = [NSString stringWithUTF8String: toBeReturned]; ret = [NSString stringWithFormat:@"%lli", pp_bookmarks[row]->i_byte_offset];
} } else if ([identifier isEqualToString: @"time_offset"]) {
else if ([identifier isEqualToString: @"size_offset"]) int total = pp_bookmarks[row]->i_time_offset/ 1000000;
{ int hour = total / (60*60);
i_toBeReturned = pp_bookmarks[row]->i_byte_offset; int min = (total - hour*60*60) / 60;
ret = [[NSNumber numberWithInt: i_toBeReturned] stringValue]; int sec = total - hour*60*60 - min*60;
} ret = [NSString stringWithFormat:@"%02d:%02d:%02d", hour, min, sec];
else if ([identifier isEqualToString: @"time_offset"])
{
i_toBeReturned = pp_bookmarks[row]->i_time_offset;
ret = [[NSNumber numberWithInt: (i_toBeReturned / 1000000)]
stringValue];
}
else
{
/* may not happen, just in case */
msg_Err( VLCIntf, "unknown table column identifier (%s) while "
"updating the bookmark table", [identifier UTF8String] );
ret = @"unknown identifier";
} }
// Clear the bookmark list // Clear the bookmark list
...@@ -463,22 +410,17 @@ clear: ...@@ -463,22 +410,17 @@ clear:
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification - (void)tableViewSelectionDidChange:(NSNotification *)aNotification
{ {
/* check whether a row is selected and en-/disable the edit/remove buttons */ /* check whether a row is selected and en-/disable the edit/remove buttons */
if ([o_tbl_dataTable selectedRow] == -1) if ([o_tbl_dataTable selectedRow] == -1) {
{
/* no row is selected */ /* no row is selected */
[o_btn_edit setEnabled: NO]; [o_btn_edit setEnabled: NO];
[o_btn_rm setEnabled: NO]; [o_btn_rm setEnabled: NO];
[o_btn_extract setEnabled: NO]; [o_btn_extract setEnabled: NO];
} } else {
else
{
/* a row is selected */ /* a row is selected */
[o_btn_edit setEnabled: YES]; [o_btn_edit setEnabled: YES];
[o_btn_rm setEnabled: YES]; [o_btn_rm setEnabled: YES];
if ([o_tbl_dataTable numberOfSelectedRows] == 2) if ([o_tbl_dataTable numberOfSelectedRows] == 2)
{
[o_btn_extract setEnabled: YES]; [o_btn_extract setEnabled: YES];
}
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment