<commit_before>//
//  VideoDetailsViewController.swift
//  WWDC
//
//  Created by <NAME> on 18/04/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import Cocoa

class VideoDetailsViewController: NSViewController {
    
    var auxWindowControllers: [NSWindowController] = []
    
    var session: Session? {
        didSet {
            updateUI()
        }
    }
    
    @IBOutlet weak var titleLabel: NSTextField!
    @IBOutlet weak var subtitleLabel: NSTextField!
    @IBOutlet weak var descriptionLabel: NSTextField!
    @IBOutlet weak var watchVideoButton: NSButton!
    @IBOutlet weak var watchHDVideoButton: NSButton!
    @IBOutlet weak var viewSlidesButton: NSButton!
    @IBOutlet weak var markAsUnwatchedButton: NSButton!
    @IBOutlet var downloadController: DownloadProgressViewController!
    
    private func updateUI()
    {
        if let session = self.session {
            titleLabel.stringValue = session.title
            subtitleLabel.stringValue = "\(session.track) | Session \(session.id)"
            descriptionLabel.stringValue = session.description
            descriptionLabel.hidden = false
            watchVideoButton.hidden = false
            watchHDVideoButton.hidden = false
            
            if session.slides != nil {
                viewSlidesButton.hidden = false
            } else {
                viewSlidesButton.hidden = true
            }
            if session.progress > 0 && session.progress < 1 {
                markAsUnwatchedButton.hidden = false
            } else {
                markAsUnwatchedButton.hidden = true
            }
            if session.hd_url != nil {
                watchHDVideoButton.enabled = true
                if VideoStore.SharedStore().hasVideo(session.hd_url!) {
                    watchHDVideoButton.toolTip = "Watch the downloaded video in HD"
                    watchVideoButton.enabled = false
                } else {
                    watchHDVideoButton.toolTip = "Stream the video in HD"
                    watchVideoButton.enabled = true
                }
            } else {
                watchHDVideoButton.enabled = false
            }
            
            downloadController.session = session
            downloadController.downloadFinishedCallback = { [unowned self] in
                self.updateUI()
            }
        } else {
            titleLabel.stringValue = "No session selected"
            subtitleLabel.stringValue = "Select a session to see It here"
            descriptionLabel.hidden = true
            watchVideoButton.hidden = true
            viewSlidesButton.hidden = true
            markAsUnwatchedButton.hidden = true
            watchHDVideoButton.hidden = true
        }
    }
    
    @IBAction func watchVideo(sender: NSButton) {
        doWatchVideo(sender, url: session!.url)
    }
    @IBAction func watchHDVideo(sender: NSButton) {
        if session!.hd_url != nil {
            if VideoStore.SharedStore().hasVideo(session!.hd_url!) {
                doWatchVideo(sender, url: VideoStore.SharedStore().localVideoAbsoluteURLString(session!.hd_url!))
            } else {
                doWatchVideo(sender, url: session!.hd_url!)
            }
        }
    }
    
    private func doWatchVideo(sender: AnyObject?, url: String)
    {
        let playerWindowController = VideoWindowController(session: session!, videoURL: url)
        playerWindowController.showWindow(sender)
        followWindowLifecycle(playerWindowController.window)
        auxWindowControllers.append(playerWindowController)
    }
    
    @IBAction func viewSlides(sender: NSButton) {
        if session!.slides != nil {
            let slidesWindowController = PDFWindowController(session: session!)
            slidesWindowController.showWindow(sender)
            followWindowLifecycle(slidesWindowController.window)
            auxWindowControllers.append(slidesWindowController)
        }
    }
    
    private func followWindowLifecycle(window: NSWindow!) {
        NSNotificationCenter.defaultCenter().addObserverForName(NSWindowWillCloseNotification, object: window, queue: nil) { note in
            if let window = note.object as? NSWindow {
                if let controller = window.windowController() as? NSWindowController {
                    self.auxWindowControllers.removeObject(controller)
                }
            }
        }
    }
    
    @IBAction func markAsUnwatched(sender: NSButton) {
        session?.progress = 0
        sender.hidden = true
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        updateUI()
    }
    
    
    
}
<commit_msg>Fixed a bug where marking a video as unwatched would not make it start playing from the beginning<commit_after>//
//  VideoDetailsViewController.swift
//  WWDC
//
//  Created by <NAME> on 18/04/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import Cocoa

class VideoDetailsViewController: NSViewController {
    
    var auxWindowControllers: [NSWindowController] = []
    
    var session: Session? {
        didSet {
            updateUI()
        }
    }
    
    @IBOutlet weak var titleLabel: NSTextField!
    @IBOutlet weak var subtitleLabel: NSTextField!
    @IBOutlet weak var descriptionLabel: NSTextField!
    @IBOutlet weak var watchVideoButton: NSButton!
    @IBOutlet weak var watchHDVideoButton: NSButton!
    @IBOutlet weak var viewSlidesButton: NSButton!
    @IBOutlet weak var markAsUnwatchedButton: NSButton!
    @IBOutlet var downloadController: DownloadProgressViewController!
    
    private func updateUI()
    {
        if let session = self.session {
            titleLabel.stringValue = session.title
            subtitleLabel.stringValue = "\(session.track) | Session \(session.id)"
            descriptionLabel.stringValue = session.description
            descriptionLabel.hidden = false
            watchVideoButton.hidden = false
            watchHDVideoButton.hidden = false
            
            if session.slides != nil {
                viewSlidesButton.hidden = false
            } else {
                viewSlidesButton.hidden = true
            }
            if session.progress > 0 && session.progress < 1 {
                markAsUnwatchedButton.hidden = false
            } else {
                markAsUnwatchedButton.hidden = true
            }
            if session.hd_url != nil {
                watchHDVideoButton.enabled = true
                if VideoStore.SharedStore().hasVideo(session.hd_url!) {
                    watchHDVideoButton.toolTip = "Watch the downloaded video in HD"
                    watchVideoButton.enabled = false
                } else {
                    watchHDVideoButton.toolTip = "Stream the video in HD"
                    watchVideoButton.enabled = true
                }
            } else {
                watchHDVideoButton.enabled = false
            }
            
            downloadController.session = session
            downloadController.downloadFinishedCallback = { [unowned self] in
                self.updateUI()
            }
        } else {
            titleLabel.stringValue = "No session selected"
            subtitleLabel.stringValue = "Select a session to see It here"
            descriptionLabel.hidden = true
            watchVideoButton.hidden = true
            viewSlidesButton.hidden = true
            markAsUnwatchedButton.hidden = true
            watchHDVideoButton.hidden = true
        }
    }
    
    @IBAction func watchVideo(sender: NSButton) {
        doWatchVideo(sender, url: session!.url)
    }
    @IBAction func watchHDVideo(sender: NSButton) {
        if session!.hd_url != nil {
            if VideoStore.SharedStore().hasVideo(session!.hd_url!) {
                doWatchVideo(sender, url: VideoStore.SharedStore().localVideoAbsoluteURLString(session!.hd_url!))
            } else {
                doWatchVideo(sender, url: session!.hd_url!)
            }
        }
    }
    
    private func doWatchVideo(sender: AnyObject?, url: String)
    {
        let playerWindowController = VideoWindowController(session: session!, videoURL: url)
        playerWindowController.showWindow(sender)
        followWindowLifecycle(playerWindowController.window)
        auxWindowControllers.append(playerWindowController)
    }
    
    @IBAction func viewSlides(sender: NSButton) {
        if session!.slides != nil {
            let slidesWindowController = PDFWindowController(session: session!)
            slidesWindowController.showWindow(sender)
            followWindowLifecycle(slidesWindowController.window)
            auxWindowControllers.append(slidesWindowController)
        }
    }
    
    private func followWindowLifecycle(window: NSWindow!) {
        NSNotificationCenter.defaultCenter().addObserverForName(NSWindowWillCloseNotification, object: window, queue: nil) { note in
            if let window = note.object as? NSWindow {
                if let controller = window.windowController() as? NSWindowController {
                    self.auxWindowControllers.removeObject(controller)
                }
            }
        }
    }
    
    @IBAction func markAsUnwatched(sender: NSButton) {
        session?.progress = 0
        session?.currentPosition = 0
        sender.hidden = true
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        updateUI()
    }
    
    
    
}

{'fraction_non_alphanumeric': 0.0756177749496235, 'fraction_numerical': 0.0028635062042634426, 'mean_word_length': 1.974763406940063, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1196578', 'n_tokens_mistral': 2439, 'n_tokens_neox': 2356, 'n_words': 525}