Commit 67b241aa authored by David Fuhrmann's avatar David Fuhrmann

macosx: cancel resume dialog after 6 seconds

Also reduce intentation of code.
parent 20f32dd1
...@@ -101,6 +101,8 @@ ...@@ -101,6 +101,8 @@
IBOutlet id o_save_accessory_text; IBOutlet id o_save_accessory_text;
IBOutlet id o_playlist_header; IBOutlet id o_playlist_header;
int currentResumeTimeout;
} }
- (void)searchfieldChanged:(NSNotification *)o_notification; - (void)searchfieldChanged:(NSNotification *)o_notification;
......
...@@ -1486,56 +1486,87 @@ ...@@ -1486,56 +1486,87 @@
return YES; return YES;
} }
- (void)updateAlertWindow:(NSTimer *)timer
{
NSAlert *alert = [timer userInfo];
--currentResumeTimeout;
if (currentResumeTimeout <= 0) {
[[alert window] close];
[NSApp abortModal];
}
NSString *buttonLabel = _NS("Restart playback");
buttonLabel = [buttonLabel stringByAppendingFormat:@" (%d)", currentResumeTimeout];
[[[alert buttons] objectAtIndex:2] setTitle:buttonLabel];
}
- (void)continuePlaybackWhereYouLeftOff:(input_thread_t *)p_input_thread - (void)continuePlaybackWhereYouLeftOff:(input_thread_t *)p_input_thread
{ {
NSDictionary *recentlyPlayedFiles = [[NSUserDefaults standardUserDefaults] objectForKey:@"recentlyPlayedMedia"]; NSDictionary *recentlyPlayedFiles = [[NSUserDefaults standardUserDefaults] objectForKey:@"recentlyPlayedMedia"];
if (recentlyPlayedFiles) { if (!recentlyPlayedFiles)
input_item_t *p_item = input_GetItem(p_input_thread); return;
if (!p_item)
return;
/* allow the user to over-write the start/stop/run-time */ input_item_t *p_item = input_GetItem(p_input_thread);
if (var_GetFloat(p_input_thread, "run-time") > 0 || if (!p_item)
var_GetFloat(p_input_thread, "start-time") > 0 || return;
var_GetFloat(p_input_thread, "stop-time") > 0) {
return;
}
/* check for file existance before resuming */ /* allow the user to over-write the start/stop/run-time */
if (![self isValidResumeItem:p_item]) if (var_GetFloat(p_input_thread, "run-time") > 0 ||
return; var_GetFloat(p_input_thread, "start-time") > 0 ||
var_GetFloat(p_input_thread, "stop-time") > 0) {
return;
}
char *psz_url = decode_URI(input_item_GetURI(p_item)); /* check for file existance before resuming */
if (!psz_url) if (![self isValidResumeItem:p_item])
return; return;
NSString *url = toNSStr(psz_url);
free(psz_url);
NSNumber *lastPosition = [recentlyPlayedFiles objectForKey:url]; char *psz_url = decode_URI(input_item_GetURI(p_item));
if (lastPosition && lastPosition.intValue > 0) { if (!psz_url)
return;
NSString *url = toNSStr(psz_url);
free(psz_url);
int settingValue = config_GetInt(VLCIntf, "macosx-continue-playback"); NSNumber *lastPosition = [recentlyPlayedFiles objectForKey:url];
NSInteger returnValue = NSAlertErrorReturn; if (!lastPosition || lastPosition.intValue <= 0)
return;
if (settingValue == 0) { int settingValue = config_GetInt(VLCIntf, "macosx-continue-playback");
NSAlert *theAlert = [NSAlert alertWithMessageText:_NS("Continue playback?") defaultButton:_NS("Continue") alternateButton:_NS("Restart playback") otherButton:_NS("Always continue") informativeTextWithFormat:_NS("Playback of \"%@\" will continue at %@"), [NSString stringWithUTF8String:input_item_GetTitleFbName(p_item)], [[VLCStringUtility sharedInstance] stringForTime:lastPosition.intValue]]; if (settingValue == 2) // never resume
return;
[[VLCCoreInteraction sharedInstance] pause]; NSInteger returnValue = NSAlertErrorReturn;
returnValue = [theAlert runModal]; if (settingValue == 0) { // ask
[[VLCCoreInteraction sharedInstance] playOrPause]; NSAlert *theAlert = [NSAlert alertWithMessageText:_NS("Continue playback?") defaultButton:_NS("Continue") alternateButton:_NS("Restart playback") otherButton:_NS("Always continue") informativeTextWithFormat:_NS("Playback of \"%@\" will continue at %@"), [NSString stringWithUTF8String:input_item_GetTitleFbName(p_item)], [[VLCStringUtility sharedInstance] stringForTime:lastPosition.intValue]];
}
if (returnValue == NSAlertAlternateReturn || settingValue == 2) currentResumeTimeout = 6;
lastPosition = [NSNumber numberWithInt:0]; NSTimer *timer = [NSTimer timerWithTimeInterval:1
target:self
selector:@selector(updateAlertWindow:)
userInfo:theAlert
repeats:YES];
mtime_t lastPos = (mtime_t)lastPosition.intValue * 1000000; [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSModalPanelRunLoopMode];
msg_Dbg(VLCIntf, "continuing playback at %lld", lastPos);
var_SetTime(p_input_thread, "time", lastPos);
if (returnValue == NSAlertOtherReturn) [[VLCCoreInteraction sharedInstance] pause];
config_PutInt(VLCIntf, "macosx-continue-playback", 1); returnValue = [theAlert runModal];
} [timer invalidate];
[[VLCCoreInteraction sharedInstance] playOrPause];
// restart button was pressed or timeout happened
if (returnValue == NSAlertAlternateReturn ||
returnValue == NSRunAbortedResponse)
return;
} }
mtime_t lastPos = (mtime_t)lastPosition.intValue * 1000000;
msg_Dbg(VLCIntf, "continuing playback at %lld", lastPos);
var_SetTime(p_input_thread, "time", lastPos);
if (returnValue == NSAlertOtherReturn)
config_PutInt(VLCIntf, "macosx-continue-playback", 1);
} }
- (void)storePlaybackPositionForItem:(input_thread_t *)p_input_thread - (void)storePlaybackPositionForItem:(input_thread_t *)p_input_thread
......
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