Skip to content

Commit

Permalink
Add initial working implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
yamadapc committed Jul 12, 2015
1 parent 930f926 commit 1d9ab1f
Show file tree
Hide file tree
Showing 3 changed files with 263 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,63 @@
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "667EACB21B51F68800E09272"
BuildableName = "iBooks Export.app"
BlueprintName = "iBooks Export"
ReferencedContainer = "container:iBooks Export.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "667EACC41B51F68800E09272"
BuildableName = "iBooks ExportTests.xctest"
BlueprintName = "iBooks ExportTests"
ReferencedContainer = "container:iBooks Export.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "667EACC41B51F68800E09272"
BuildableName = "iBooks ExportTests.xctest"
BlueprintName = "iBooks ExportTests"
ReferencedContainer = "container:iBooks Export.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "667EACB21B51F68800E09272"
BuildableName = "iBooks Export.app"
BlueprintName = "iBooks Export"
ReferencedContainer = "container:iBooks Export.xcodeproj">
</BuildableReference>
</MacroExpansion>
</TestAction>
<LaunchAction
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
Expand All @@ -23,6 +72,16 @@
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "667EACB21B51F68800E09272"
BuildableName = "iBooks Export.app"
BlueprintName = "iBooks Export"
ReferencedContainer = "container:iBooks Export.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
Expand All @@ -32,6 +91,16 @@
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "667EACB21B51F68800E09272"
BuildableName = "iBooks Export.app"
BlueprintName = "iBooks Export"
ReferencedContainer = "container:iBooks Export.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
Expand Down
108 changes: 101 additions & 7 deletions iBooks Export/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="6198" systemVersion="14A297b" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="7706" systemVersion="14D136" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6198"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7706"/>
</dependencies>
<scenes>
<!--Application-->
Expand Down Expand Up @@ -641,12 +641,12 @@
<outlet property="delegate" destination="Voe-Tx-rLC" id="PrD-fu-P6m"/>
</connections>
</application>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModuleProvider="target"/>
<customObject id="Voe-Tx-rLC" customClass="AppDelegate" customModule="iBooks_Export" customModuleProvider="target"/>
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="75" y="0.0"/>
</scene>
<!--Window Controller - Window-->
<!--Window Controller-->
<scene sceneID="R2V-B0-nI4">
<objects>
<windowController id="B8D-0N-5wS" sceneMemberID="viewController">
Expand All @@ -667,15 +667,109 @@
<!--View Controller-->
<scene sceneID="hIz-AP-VOD">
<objects>
<viewController id="XfG-lQ-9wD" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="XfG-lQ-9wD" customClass="ViewController" customModule="iBooks_Export" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" id="m2S-Jp-Qdl">
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<rect key="frame" x="0.0" y="0.0" width="486" height="270"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<scrollView autohidesScrollers="YES" horizontalLineScroll="19" horizontalPageScroll="10" verticalLineScroll="19" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="xeP-jo-oUq">
<rect key="frame" x="0.0" y="34" width="486" height="236"/>
<clipView key="contentView" id="4VE-FI-JKk">
<rect key="frame" x="1" y="17" width="238" height="117"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" columnSelection="YES" multipleSelection="NO" autosaveColumns="NO" headerView="Drj-2P-DcV" id="M2g-Jr-8Ok">
<rect key="frame" x="0.0" y="0.0" width="484" height="0.0"/>
<autoresizingMask key="autoresizingMask"/>
<size key="intercellSpacing" width="3" height="2"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
<color key="gridColor" name="gridColor" catalog="System" colorSpace="catalog"/>
<tableColumns>
<tableColumn identifier="path" width="116" minWidth="40" maxWidth="1000" id="c7S-qQ-JH2">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="File Path">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
</tableHeaderCell>
<textFieldCell key="dataCell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" alignment="left" title="Text Cell" id="gQE-e3-e4c">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
</tableColumn>
<tableColumn identifier="itemName" width="111.41015625" minWidth="40" maxWidth="1000" id="dfd-LA-mp8">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="Book Name">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
</tableHeaderCell>
<textFieldCell key="dataCell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" alignment="left" title="Text Cell" id="dWD-Ut-WZZ">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
</tableColumn>
<tableColumn identifier="displayName" width="247.5" minWidth="10" maxWidth="3.4028234663852886e+38" id="pIo-41-x03">
<tableHeaderCell key="headerCell" lineBreakMode="truncatingTail" borderStyle="border" alignment="left" title="Original Filename">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
</tableHeaderCell>
<textFieldCell key="dataCell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" alignment="left" title="Text Cell" id="TRO-qC-2QX">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
</tableColumn>
</tableColumns>
</tableView>
</subviews>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
</clipView>
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="YES" id="ihM-xV-aUc">
<rect key="frame" x="1" y="119" width="223" height="15"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" hidden="YES" verticalHuggingPriority="750" horizontal="NO" id="ZSO-Su-8VL">
<rect key="frame" x="224" y="17" width="15" height="102"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<tableHeaderView key="headerView" id="Drj-2P-DcV">
<rect key="frame" x="0.0" y="0.0" width="238" height="17"/>
<autoresizingMask key="autoresizingMask"/>
</tableHeaderView>
</scrollView>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Bj8-I3-ZDG">
<rect key="frame" x="202" y="0.0" width="82" height="32"/>
<buttonCell key="cell" type="push" title="Extract" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="X38-sW-YnJ">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="onClickExtractButton:" target="XfG-lQ-9wD" id="YMp-8f-Yas"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstItem="xeP-jo-oUq" firstAttribute="top" secondItem="m2S-Jp-Qdl" secondAttribute="top" id="4uD-55-u1R"/>
<constraint firstAttribute="bottom" secondItem="Bj8-I3-ZDG" secondAttribute="bottom" constant="7" id="6CB-na-T8P"/>
<constraint firstAttribute="trailing" secondItem="xeP-jo-oUq" secondAttribute="trailing" id="KFz-HR-lRR"/>
<constraint firstAttribute="centerX" secondItem="Bj8-I3-ZDG" secondAttribute="centerX" id="Os5-Od-0vX"/>
<constraint firstItem="xeP-jo-oUq" firstAttribute="leading" secondItem="m2S-Jp-Qdl" secondAttribute="leading" id="W9E-7h-STX"/>
<constraint firstItem="Bj8-I3-ZDG" firstAttribute="top" secondItem="xeP-jo-oUq" secondAttribute="bottom" constant="6" id="nJg-Qv-0BY"/>
</constraints>
</view>
<connections>
<outlet property="extractButton" destination="Bj8-I3-ZDG" id="Whc-uO-coB"/>
<outlet property="tableView" destination="M2g-Jr-8Ok" id="fS7-vb-aB5"/>
</connections>
</viewController>
<customObject id="rPt-NT-nkU" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="75" y="655"/>
<point key="canvasLocation" x="78" y="655"/>
</scene>
</scenes>
</document>
96 changes: 93 additions & 3 deletions iBooks Export/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,43 @@

import Cocoa

class ViewController: NSViewController {
struct Book {
var itemName: String?
var displayName: String
var path: String
}

class ViewController: NSViewController, NSTableViewDataSource {
@IBOutlet weak var tableView: NSTableView!

@IBAction func onClickExtractButton(sender: AnyObject) {
println("Clicked")
let filemanager = NSFileManager()
var error: NSError?
filemanager.createDirectoryAtPath(NSHomeDirectory() + "/Documents/iBooks-exported", withIntermediateDirectories: false, attributes: nil, error: &error)

if error != nil {
println(error)
}

for book in self.books {
if let targetPath = self.targetPath(book) {
filemanager.copyItemAtPath(book.path, toPath: NSHomeDirectory() + "/Documents/iBooks-exported/" + targetPath, error: &error)
if error != nil {
println(error)
}
}

}
}

var books: [Book] = []


override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
self.getUserBooks()
self.tableView.setDataSource(self)
}

override var representedObject: AnyObject? {
Expand All @@ -22,6 +53,65 @@ class ViewController: NSViewController {
}
}

func numberOfRowsInTableView(tableView: NSTableView) -> Int {
if tableView != self.tableView {
return 0
}

return self.books.count
}

func tableView(tableView: NSTableView, objectValueForTableColumn tableColumn: NSTableColumn?, row: Int) -> AnyObject? {
if tableView != self.tableView {
return nil
}

let book = self.books[row]
let identifier = tableColumn?.identifier

switch(identifier!) {
case "itemName":
return book.itemName
case "displayName":
return book.displayName
case "path":
return book.path.lastPathComponent
default:
return nil
}
}

private func targetPath(book: Book) -> String? {
if book.displayName != "" {
if let itemName = book.itemName {
return itemName + ".epub"
}
return nil
}
return book.displayName
}

private func getUserBooks() {
let info = self.getUserBooksPlist()
if let infoBooks: AnyObject = info?.objectForKey("Books") {
for info in infoBooks as! [AnyObject] {
let path = info.objectForKey("path") as! String

if path.pathExtension != "epub" {
continue
}

let displayName = info.objectForKey("BKDisplayName") as! String
let itemName = info.objectForKey("itemName") as? String
self.books.append(Book(itemName: itemName, displayName: displayName, path: path))
}
}
}

private func getUserBooksPlist() -> NSDictionary? {
let home = NSHomeDirectory()
let path = home + "/Library/Containers/com.apple.BKAgentService/Data/Documents/iBooks/Books/Books.plist"
return NSDictionary(contentsOfFile: path)
}
}

0 comments on commit 1d9ab1f

Please sign in to comment.