</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="372"/>
- <integer value="528"/>
<integer value="29"/>
+ <integer value="528"/>
+ <integer value="372"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
</object>
<int key="connectionID">646</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">delegate</string>
+ <reference key="source" ref="972006081"/>
+ <reference key="destination" ref="719278169"/>
+ </object>
+ <int key="connectionID">647</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">646</int>
+ <int key="maxID">647</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
parent.children.append(self)
class ITunesLibrary(NSObject):
- def load_(self, filename):
+ def load_(self, filename=None):
if filename is None:
- filename = "~/Music/iTunes/iTunes Music Library.xml"
- filename = os.path.expanduser(filename)
+ filename = getattr(self, "filename", None)
+ if filename is None:
+ filename = os.path.expanduser("~/Music/iTunes/iTunes Music Library.xml")
+ self.filename = filename
+ self.mtime = os.stat(filename).st_mtime
yield "Reading library..."
plist = read_plist(os.path.expanduser(filename))
if plist is None:
self.playlists.append(playlist)
pl_lookup[playlist.pid] = playlist
+ def needs_reload(self):
+ return os.stat(self.filename).st_mtime > self.mtime
+
def loc2name(self, location):
return urllib.splithost(urllib.splittype(urllib.unquote(location))[1])[1]
for target in self.targets:
folders.append(target["folder"])
self.folderModel.loadFolders_(folders)
-
+
self.library = libnotipod.ITunesLibrary.alloc().init()
- def finish():
- self.playlistModel.setPlaylists(self.library.get_playlists())
- def fail():
- sys.exit(0)
- self.runGenerator(lambda: self.library.load_(None), finish, fail)
+ self.loadLibrary()
def applicationWillTerminate_(self, _):
self.prefs().synchronize()
def applicationShouldTerminateAfterLastWindowClosed_(self, _):
return True
+ def windowDidBecomeKey_(self, _):
+ if self.library.needs_reload():
+ print "needs reload!"
+ self.loadLibrary()
+ else:
+ print "no reloading this time"
+
# Utility methods
+ def loadLibrary(self):
+ if self.runningGenerator:
+ return
+
+ def finish():
+ self.playlistModel.setPlaylists(self.library.get_playlists())
+ def fail():
+ NSRunAlertPanel("Error!", "Unable to load iTunes library! Exiting...", "Ok", None, None)
+ sys.exit(0)
+ self.runGenerator(lambda: self.library.load_(None), finish, fail)
+
def runGenerator(self, func, finish, fail):
assert not self.runningGenerator
self.runningGenerator = True
def _migratePrefs(self):
p = self.prefs()
-
+
playlists = p.stringArrayForKey_("playlists")
if playlists is not None:
p.removeObjectForKey_("playlists")
def _loadPrefs(self):
p = self.prefs()
- self.current_target = None
- self.setCurrentTarget_(p.stringForKey_("current_target"))
+ self.currentTarget = None
+ self.setCurrentTarget_(p.stringForKey_("currentTarget"))
self.targets = self.prefs().arrayForKey_("targets")
if self.targets is None:
def _savePrefs(self):
p = self.prefs()
- p.setObject_forKey_(self.current_target, "current_target")
+ p.setObject_forKey_(self.currentTarget, "currentTarget")
p.setObject_forKey_(self.targets, "targets")
p.synchronize()
def getCurrentTarget(self):
for target in self.targets:
- if target["uuid"] == self.current_target:
+ if target["uuid"] == self.currentTarget:
return target
return None
-
- def setCurrentTarget_(self, target_uuid):
- old_uuid = self.current_target
- self.current_target = target_uuid
- if old_uuid is None and target_uuid is not None:
+
+ def setCurrentTarget_(self, targetUuid):
+ oldUuid = self.currentTarget
+ self.currentTarget = targetUuid
+ if oldUuid is None and targetUuid is not None:
self.playlistModel.outlineView.setEnabled_(True)
- if old_uuid != target_uuid:
+ if oldUuid != targetUuid:
self.playlistModel.outlineView.reloadItem_reloadChildren_(None, True)
def playlists(self):