File: ResumeDialogController.m

package info (click to toggle)
vlc 2.2.7-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 191,124 kB
  • sloc: ansic: 356,116; cpp: 94,295; objc: 34,063; sh: 6,765; makefile: 4,272; xml: 1,538; asm: 1,251; python: 240; perl: 77; sed: 16
file content (126 lines) | stat: -rw-r--r-- 4,002 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*****************************************************************************
 * ResumeDialogController.m: MacOS X interface module
 *****************************************************************************
 * Copyright (C) 2015 VLC authors and VideoLAN
 *
 * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
 *          David Fuhrmann <david dot fuhrmann at googlemail dot com>
 *
 * 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
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/


#import "ResumeDialogController.h"

#import "intf.h"
#import "StringUtility.h"

@implementation ResumeDialogController

- (id)init
{
    self = [super initWithWindowNibName:@"ResumeDialog"];
    if (self) {

    }

    return self;
}

- (void)windowDidLoad
{
    [o_title_lbl setStringValue:_NS("Continue playback?")];
    [o_resume_btn setTitle:_NS("Continue")];

    [o_always_resume_btn setTitle:_NS("Always continue")];
}

- (void)showWindowWithItem:(input_item_t *)p_item withLastPosition:(NSInteger)pos completionBlock:(CompletionBlock)block
{
    NSWindow *w = [self window];

    if ([w isVisible]) {
        msg_Err(VLCIntf, "Resume dialog in use already");
        return;
    }

    currentResumeTimeout = 10;
    completionBlock = [block copy];


    NSString *o_restartButtonLabel = _NS("Restart playback");
    o_restartButtonLabel = [o_restartButtonLabel stringByAppendingFormat:@" (%d)", currentResumeTimeout];
    [o_restart_btn setTitle:o_restartButtonLabel];

    char *psz_title_name = input_item_GetTitleFbName(p_item);
    NSString *o_title = toNSStr(psz_title_name);
    free(psz_title_name);
    NSString *labelString = [NSString stringWithFormat:_NS("Playback of \"%@\" will continue at %@"), o_title, [[VLCStringUtility sharedInstance] stringForTime:pos]];
    [o_text_lbl setStringValue:labelString];

    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1
                                             target:self
                                           selector:@selector(updateAlertWindow:)
                                           userInfo:nil
                                            repeats:YES];

    [w setLevel:[[[VLCMain sharedInstance] voutController] currentStatusWindowLevel]];
    [w center];

    [w makeKeyAndOrderFront:nil];
}

- (void)updateAlertWindow:(NSTimer *)timer
{
    --currentResumeTimeout;
    if (currentResumeTimeout <= 0) {
        [self buttonClicked:o_restart_btn];
        [timer invalidate];
        timer = nil;
    }

    NSString *buttonLabel = _NS("Restart playback");
    buttonLabel = [buttonLabel stringByAppendingFormat:@" (%d)", currentResumeTimeout];

    [o_restart_btn setTitle:buttonLabel];
}

- (IBAction)buttonClicked:(id)sender
{
    enum ResumeResult resumeResult;

    if (sender == o_restart_btn)
        resumeResult = RESUME_RESTART;
    else if (sender == o_resume_btn)
        resumeResult = RESUME_NOW;
    else
        resumeResult = RESUME_ALWAYS;

    [[self window] close];

    if (completionBlock) {
        completionBlock(resumeResult);
        [completionBlock release];
        completionBlock = nil;
    }
}

- (void)updateCocoaWindowLevel:(NSInteger)i_level
{
    if (self.window && [self.window isVisible] && [self.window level] != i_level)
        [self.window setLevel: i_level];
}

@end