[vlc-commits] macosx: cancel resume dialog after 6 seconds
David Fuhrmann
git at videolan.org
Sat Nov 29 15:15:28 CET 2014
vlc/vlc-2.2 | branch: master | David Fuhrmann <dfuhrmann at videolan.org> | Sat Nov 29 15:01:39 2014 +0100| [d676a3c3a6d71b2f081dd4900735c225ede65457] | committer: Felix Paul Kühne
macosx: cancel resume dialog after 6 seconds
Also reduce intentation of code.
(cherry picked from commit 67b241aa87e243ac7906c11efeb47bfe2578a3c6)
Signed-off-by: Felix Paul Kühne <fkuehne at videolan.org>
> http://git.videolan.org/gitweb.cgi/vlc/vlc-2.2.git/?a=commit;h=d676a3c3a6d71b2f081dd4900735c225ede65457
---
modules/gui/macosx/playlist.h | 2 +
modules/gui/macosx/playlist.m | 103 +++++++++++++++++++++++++++--------------
2 files changed, 69 insertions(+), 36 deletions(-)
diff --git a/modules/gui/macosx/playlist.h b/modules/gui/macosx/playlist.h
index 07bb518..0326eb0 100644
--- a/modules/gui/macosx/playlist.h
+++ b/modules/gui/macosx/playlist.h
@@ -106,6 +106,8 @@
IBOutlet id o_save_accessory_text;
IBOutlet id o_playlist_header;
+
+ int currentResumeTimeout;
}
- (void)searchfieldChanged:(NSNotification *)o_notification;
diff --git a/modules/gui/macosx/playlist.m b/modules/gui/macosx/playlist.m
index 38643c4..d999cee 100644
--- a/modules/gui/macosx/playlist.m
+++ b/modules/gui/macosx/playlist.m
@@ -1506,56 +1506,87 @@
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
{
NSDictionary *recentlyPlayedFiles = [[NSUserDefaults standardUserDefaults] objectForKey:@"recentlyPlayedMedia"];
- if (recentlyPlayedFiles) {
- input_item_t *p_item = input_GetItem(p_input_thread);
- if (!p_item)
- return;
+ if (!recentlyPlayedFiles)
+ return;
- /* allow the user to over-write the start/stop/run-time */
- if (var_GetFloat(p_input_thread, "run-time") > 0 ||
- var_GetFloat(p_input_thread, "start-time") > 0 ||
- var_GetFloat(p_input_thread, "stop-time") > 0) {
- return;
- }
+ input_item_t *p_item = input_GetItem(p_input_thread);
+ if (!p_item)
+ return;
- /* check for file existance before resuming */
- if (![self isValidResumeItem:p_item])
- return;
+ /* allow the user to over-write the start/stop/run-time */
+ if (var_GetFloat(p_input_thread, "run-time") > 0 ||
+ 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));
- if (!psz_url)
- return;
- NSString *url = toNSStr(psz_url);
- free(psz_url);
+ /* check for file existance before resuming */
+ if (![self isValidResumeItem:p_item])
+ return;
- NSNumber *lastPosition = [recentlyPlayedFiles objectForKey:url];
- if (lastPosition && lastPosition.intValue > 0) {
+ char *psz_url = decode_URI(input_item_GetURI(p_item));
+ if (!psz_url)
+ return;
+ NSString *url = toNSStr(psz_url);
+ free(psz_url);
- int settingValue = config_GetInt(VLCIntf, "macosx-continue-playback");
- NSInteger returnValue = NSAlertErrorReturn;
+ NSNumber *lastPosition = [recentlyPlayedFiles objectForKey:url];
+ if (!lastPosition || lastPosition.intValue <= 0)
+ return;
- if (settingValue == 0) {
- 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]];
+ int settingValue = config_GetInt(VLCIntf, "macosx-continue-playback");
+ if (settingValue == 2) // never resume
+ return;
- [[VLCCoreInteraction sharedInstance] pause];
- returnValue = [theAlert runModal];
- [[VLCCoreInteraction sharedInstance] playOrPause];
- }
+ NSInteger returnValue = NSAlertErrorReturn;
+ if (settingValue == 0) { // ask
+ 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)
- lastPosition = [NSNumber numberWithInt:0];
+ currentResumeTimeout = 6;
+ NSTimer *timer = [NSTimer timerWithTimeInterval:1
+ target:self
+ selector:@selector(updateAlertWindow:)
+ userInfo:theAlert
+ repeats:YES];
- mtime_t lastPos = (mtime_t)lastPosition.intValue * 1000000;
- msg_Dbg(VLCIntf, "continuing playback at %lld", lastPos);
- var_SetTime(p_input_thread, "time", lastPos);
+ [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSModalPanelRunLoopMode];
- if (returnValue == NSAlertOtherReturn)
- config_PutInt(VLCIntf, "macosx-continue-playback", 1);
- }
+ [[VLCCoreInteraction sharedInstance] pause];
+ 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
More information about the vlc-commits
mailing list