<commit_before>//
//  Document.swift
//  ApkInstaller
//
//  Created by MingWang on 8/25/14.
//  Copyright (c) 2014 MingWang. All rights reserved.
//

import Cocoa
import IOKit

class Document: NSDocument {
    weak var currentWindow: NSWindow!
    var appInfo = [String:String]()
    
    @IBOutlet weak var appIcon: NSImageView!
    @IBOutlet weak var appLabel: NSTextField!
    @IBOutlet weak var deviceCombo: NSComboBox!
    @IBOutlet weak var uninstallOldApk: NSButton!
    @IBOutlet weak var cancelButton: NSButton!
    @IBOutlet weak var installButton: NSButton!
    @IBOutlet weak var versionCode: NSTextField!
    @IBOutlet weak var versionName: NSTextField!
    @IBOutlet weak var appSize: NSTextField!
    @IBOutlet weak var progress: NSProgressIndicator!
    @IBOutlet weak var errorMessage: NSTextField!
    
    @IBAction func install(sender: NSButton) {
        installButton.enabled = false
        progress.hidden = false
        progress.startAnimation(self)
        errorMessage.hidden = false
        errorMessage.stringValue = "Installing..."
        installApk()
    }
    
    @IBAction func cancel(sender: NSButton) {
        if currentWindow != nil {
            currentWindow.close()
        }
    }
    
    override init() {
        super.init()
        
        appInfo["iconFile"] = "/tmp/icon.png"
    }

    override func windowControllerDidLoadNib(aController: NSWindowController) {
        super.windowControllerDidLoadNib(aController)
        
        currentWindow = aController.window
        appLabel.stringValue = appInfo["label"]
        appIcon.image = NSImage(contentsOfFile: appInfo["iconFile"])
        let vcode = appInfo["versionCode"]
        let vname = appInfo["versionName"]
        let size = appInfo["size"]
        versionCode.stringValue = "Version Code: \(vcode!)"
        versionName.stringValue = "Version Name: \(vname!)"
        appSize.stringValue = "Size: \(size!)"
        deviceCombo.addItemsWithObjectValues(listDevices())
        deviceCombo.enabled = deviceCombo.objectValues.count > 0
        installButton.enabled = deviceCombo.enabled
        deviceCombo.resetCursorRects()
        if deviceCombo.objectValues.count == 0 {
            deviceCombo.stringValue = "No Device"
        } else {
            deviceCombo.selectItemAtIndex(0)
        }
                                    
    }

    override var windowNibName: String {
        // Returns the nib file name of the document
        // If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this property and override -makeWindowControllers instead.<commit_msg>hide checkbox<commit_after>//
//  Document.swift
//  ApkInstaller
//
//  Created by MingWang on 8/25/14.
//  Copyright (c) 2014 MingWang. All rights reserved.
//

import Cocoa
import IOKit

class Document: NSDocument {
    weak var currentWindow: NSWindow!
    var appInfo = [String:String]()
    
    @IBOutlet weak var appIcon: NSImageView!
    @IBOutlet weak var appLabel: NSTextField!
    @IBOutlet weak var deviceCombo: NSComboBox!
    @IBOutlet weak var uninstallOldApk: NSButton!
    @IBOutlet weak var cancelButton: NSButton!
    @IBOutlet weak var installButton: NSButton!
    @IBOutlet weak var versionCode: NSTextField!
    @IBOutlet weak var versionName: NSTextField!
    @IBOutlet weak var appSize: NSTextField!
    @IBOutlet weak var progress: NSProgressIndicator!
    @IBOutlet weak var errorMessage: NSTextField!
    
    @IBAction func install(sender: NSButton) {
        installButton.enabled = false
        progress.hidden = false
        progress.startAnimation(self)
        errorMessage.hidden = false
        errorMessage.stringValue = "Installing..."
        installApk()
    }
    
    @IBAction func cancel(sender: NSButton) {
        if currentWindow != nil {
            currentWindow.close()
        }
    }
    
    override init() {
        super.init()
        
        appInfo["iconFile"] = "/tmp/icon.png"
    }

    override func windowControllerDidLoadNib(aController: NSWindowController) {
        super.windowControllerDidLoadNib(aController)
        
        currentWindow = aController.window
        appLabel.stringValue = appInfo["label"]
        appIcon.image = NSImage(contentsOfFile: appInfo["iconFile"])
        uninstallOldApk.hidden = true
        let vcode = appInfo["versionCode"]
        let vname = appInfo["versionName"]
        let size = appInfo["size"]
        versionCode.stringValue = "Version Code: \(vcode!)"
        versionName.stringValue = "Version Name: \(vname!)"
        appSize.stringValue = "Size: \(size!)"
        deviceCombo.addItemsWithObjectValues(listDevices())
        deviceCombo.enabled = deviceCombo.objectValues.count > 0
        installButton.enabled = deviceCombo.enabled
        deviceCombo.resetCursorRects()
        if deviceCombo.objectValues.count == 0 {
            deviceCombo.stringValue = "No Device"
        } else {
            deviceCombo.selectItemAtIndex(0)
        }
                                    
    }

    override var windowNibName: String {
        // Returns the nib file name of the document
        // If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this property and override -makeWindowControllers instead.
{'fraction_non_alphanumeric': 0.08578888474449832, 'fraction_numerical': 0.004475941812756434, 'mean_word_length': 2.5993288590604027, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7218852', 'n_tokens_mistral': 1517, 'n_tokens_neox': 1495, 'n_words': 392}