Skip to content

Commit

Permalink
do various things, see desc
Browse files Browse the repository at this point in the history
fix adding album art with drag and drop when library doesn't organize, refactor table menu for greater flexibility (fixing no-selection 'get info' crash), add lazy accessor to NSArrayController subclass; try to deallocate iTunesParser correctly after library import
  • Loading branch information
jcm93 committed Aug 27, 2017
1 parent ab9cb27 commit 142c978
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 92 deletions.
Binary file not shown.
27 changes: 15 additions & 12 deletions jmc/Backend/Database:Filesystem Management/DatabaseManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,7 @@ class DatabaseManager: NSObject {
let destination = getAlbumDirectory(for: albumArt.album ?? albumArt.album_multiple!).appendingPathComponent(filename)
do {
let oldLocation = URL(string: albumArt.artwork_location!)!
if globalRootLibrary?.organization_type == NSNumber(value: 1) {
try fileManager.moveItem(at: oldLocation, to: destination)
} else if globalRootLibrary?.organization_type == NSNumber(value: 2) {
try fileManager.copyItem(at: oldLocation, to: destination)
}
try fileManager.copyItem(at: oldLocation, to: destination)
albumArt.artwork_location = destination.absoluteString
} catch {
print(error)
Expand Down Expand Up @@ -1463,19 +1459,26 @@ class DatabaseManager: NSObject {
}
}
}
if numTracksChecked >= count {
if visualUpdateHandler != nil {
DispatchQueue.main.async {
visualUpdateHandler!.completionHandler()
}
}
}
if visualUpdateHandler != nil {
DispatchQueue.main.async {
visualUpdateHandler!.completionHandler()
}
}
print(missingTracks.count)
return missingTracks
} catch {
if visualUpdateHandler != nil {
DispatchQueue.main.async {
visualUpdateHandler!.completionHandler()
}
}
print(error)
}
if visualUpdateHandler != nil {
DispatchQueue.main.async {
visualUpdateHandler!.completionHandler()
}
}
return nil
}

Expand Down
1 change: 1 addition & 0 deletions jmc/Delegate:Main Window Controller/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {

func doneImportingiTunesLibrary() {
mainWindowController?.sourceListViewController?.reloadData()
self.iTunesParser = nil
}

@IBAction func addToLibrary(_ sender: AnyObject) {
Expand Down
64 changes: 32 additions & 32 deletions jmc/LibraryConsolidatorTableViewController.xib

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ class DragAndDropArrayController: NSArrayController, NSTableViewDataSource, NSTa
return true
}

func object(at index: Int) -> TrackView? {
guard let array = self.arrangedObjects as? NSArray else { return nil }
guard index > -1, array.count > index else { return nil }
return array[index] as? TrackView
}

func tableView(_ tableView: NSTableView, draggingSession session: NSDraggingSession, willBeginAt screenPoint: NSPoint, forRowIndexes rowIndexes: IndexSet) {
print("dragypoo called")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ class LibraryTableViewController: NSViewController, NSMenuDelegate {
var needsPlaylistRefresh = false
var currentTrackRow = 0

let getInfoMenuItem = NSMenuItem(title: "Get Info", action: #selector(getInfoFromTableView), keyEquivalent: "")
let addToQueueMenuItem = NSMenuItem(title: "Add to Queue", action: #selector(addToQueueFromTableView), keyEquivalent: "")
let playMenuItem = NSMenuItem(title: "Play", action: #selector(playFromTableView), keyEquivalent: "")
let separatorMenuItem = NSMenuItem.separator()
let toggleEnabledMenuItem = NSMenuItem(title: "Toggle Enabled/Disabled", action: #selector(toggleEnabled), keyEquivalent: "")
let showInFinderMenuItem = NSMenuItem(title: "Show in Finder", action: #selector(showInFinderAction), keyEquivalent: "")

var normalMenuItemsArray: [NSMenuItem]!

var isVisibleDict = NSMutableDictionary()
func populateIsVisibleDict() {
if self.trackViewArrayController != nil {
Expand Down Expand Up @@ -420,9 +429,19 @@ class LibraryTableViewController: NSViewController, NSMenuDelegate {
}

func menuWillOpen(_ menu: NSMenu) {
for menuItem in menu.items {
if menuItem.representedObject != nil {
menuItem.state = (menuItem.representedObject as! NSTableColumn).isHidden ? NSOffState : NSOnState
switch menu {
case self.columnVisibilityMenu:
for menuItem in menu.items {
if menuItem.representedObject != nil {
menuItem.state = (menuItem.representedObject as! NSTableColumn).isHidden ? NSOffState : NSOnState
}
}
default:
guard let _ = self.trackViewArrayController.object(at: tableView.clickedRow) else { menu.removeAllItems(); return }
if menu.items.count == 0 {
for item in self.normalMenuItemsArray {
menu.addItem(item)
}
}
}
}
Expand Down Expand Up @@ -484,9 +503,11 @@ class LibraryTableViewController: NSViewController, NSMenuDelegate {

override func viewDidLoad() {
print("view did load")
self.normalMenuItemsArray = [self.getInfoMenuItem, self.addToQueueMenuItem, self.playMenuItem, self.separatorMenuItem, self.toggleEnabledMenuItem, self.showInFinderMenuItem]
trackViewArrayController.addObserver(self, forKeyPath: "arrangedObjects", options: .new, context: &my_context)
trackViewArrayController.tableViewController = self as! LibraryTableViewControllerCellBased
tableView.target = self
tableView.menu?.delegate = self
tableView.doubleAction = #selector(tableViewDoubleClick)
columnVisibilityMenu.delegate = self
//self.initializeColumnVisibilityMenu(self.tableView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,40 +638,6 @@
<menu id="H0B-Bf-KKf">
<point key="canvasLocation" x="-70.5" y="-189.5"/>
</menu>
<menu id="GHk-a7-b5o">
<items>
<menuItem title="Add to Queue" id="qFT-yZ-lP8">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="addToQueueFromTableView:" target="-2" id="4Jo-Gm-T5w"/>
</connections>
</menuItem>
<menuItem title="Play" id="JSl-Hw-NLi">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="playFromTableView:" target="-2" id="mUW-FZ-QgI"/>
</connections>
</menuItem>
<menuItem title="Get Info..." id="APy-P4-Xiq">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="getInfoFromTableView:" target="-2" id="YUD-u9-OCb"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="u24-lV-AMW"/>
<menuItem title="Toggle Enabled/Disabled" id="n06-D6-ewQ">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="toggleEnabled:" target="-2" id="Tuj-vF-HWM"/>
</connections>
</menuItem>
<menuItem title="Show in Finder" id="rHt-8y-MTS">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="showInFinderAction:" target="-2" id="Sub-TL-erD"/>
</connections>
</menuItem>
</items>
</menu>
<menu id="GHk-a7-b5o"/>
</objects>
</document>
12 changes: 6 additions & 6 deletions jmc/MediaKeyListener.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ class MediaKeyListener: NSObject {

let callback: @convention(c) (OpaquePointer, CGEventType, CGEvent, Optional<UnsafeMutableRawPointer>) -> Optional<Unmanaged<CGEvent>> = {
(proxy: OpaquePointer, type: CGEventType, event: CGEvent, refcon: Optional<UnsafeMutableRawPointer>) -> Optional<Unmanaged<CGEvent>> in
guard type == CGEventType(rawValue: UInt32(NX_SYSDEFINED)) else { return Unmanaged.passRetained(event) }
guard let keyEvent = NSEvent(cgEvent: event) else { return Unmanaged.passRetained(event) }
guard keyEvent.subtype == NSEventSubtype.init(rawValue: 8) else { return Unmanaged.passRetained(event) }
guard type == CGEventType(rawValue: UInt32(NX_SYSDEFINED)) else { return Unmanaged.passUnretained(event) }
guard let keyEvent = NSEvent(cgEvent: event) else { return Unmanaged.passUnretained(event) }
guard keyEvent.subtype == NSEventSubtype.init(rawValue: 8) else { return Unmanaged.passUnretained(event) }
let this = Unmanaged<MediaKeyListener>.fromOpaque(refcon!).takeUnretainedValue()
guard this.shouldInterceptMediaKeys else { return Unmanaged.passRetained(event) }
guard this.shouldInterceptMediaKeys else { return Unmanaged.passUnretained(event) }
let keyCode = Int32((keyEvent.data1 & 0xFFFF0000) >> 16)
let keyFlags = keyEvent.data1 & 0xFFFF
let keyState = (keyFlags & 0xFF00) >> 8
Expand Down Expand Up @@ -121,7 +121,7 @@ class MediaKeyListener: NSObject {
this.backKeyPressed = false
}
default:
return Unmanaged.passRetained(event)
return Unmanaged.passUnretained(event)
}
print(keyCode)
return nil
Expand Down Expand Up @@ -150,7 +150,7 @@ class MediaKeyListener: NSObject {
super.init()
let options = CGEventTapOptions.defaultTap
let eventsOfInterest: UInt64 = UInt64(1 << NX_SYSDEFINED)
let machPort = CGEvent.tapCreate(tap: .cgSessionEventTap, place: .headInsertEventTap, options: options, eventsOfInterest: eventsOfInterest, callback: self.callback, userInfo: Unmanaged.passRetained(self).toOpaque())
let machPort = CGEvent.tapCreate(tap: .cgSessionEventTap, place: .headInsertEventTap, options: options, eventsOfInterest: eventsOfInterest, callback: self.callback, userInfo: Unmanaged.passUnretained(self).toOpaque())
let eventPortSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, machPort!, 0)
CFRunLoopAddSource(CFRunLoopGetCurrent(), eventPortSource, CFRunLoopMode.commonModes)
print("created event tap")
Expand Down
1 change: 0 additions & 1 deletion jmc/Other Windows/ImageCollectionViewItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import Cocoa

class ImageCollectionViewItem: NSCollectionViewItem {


@IBOutlet weak var shadowView: NSView!
var imageURL: URL?

Expand Down
1 change: 1 addition & 0 deletions jmc/Other Windows/ImportWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ImportWindowController: NSWindowController, NSTableViewDelegate {
DispatchQueue.global(qos: .default).async {
appDelegate.iTunesParser?.makeLibrary(parentLibrary: globalRootLibrary, visualUpdateHandler: appDelegate.backgroundAddFilesHandler)
}
self.iTunesParser = nil
self.window?.close()
}

Expand Down
7 changes: 4 additions & 3 deletions jmc/Other Windows/ImportWindowController.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="12118" systemVersion="16D32" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="12121" systemVersion="16D32" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="12118"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="12121"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -19,7 +19,8 @@
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="Import from iTunes" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" animationBehavior="default" id="F0z-JX-Cv5">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<rect key="contentRect" x="196" y="240" width="480" height="301"/>
<windowPositionMask key="initialPositionMask" topStrut="YES"/>
<rect key="contentRect" x="196" y="524" width="480" height="301"/>
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/>
<view key="contentView" id="se5-gp-TjO">
<rect key="frame" x="0.0" y="0.0" width="480" height="301"/>
Expand Down

0 comments on commit 142c978

Please sign in to comment.