From: James Bunton Date: Sun, 2 Jan 2011 06:38:16 +0000 (+1100) Subject: More stuff works! X-Git-Tag: notipod-1.0~9 X-Git-Url: https://code.delx.au/notipod/commitdiff_plain/7040ac2828c56d1a87cb2a974e08dabb1459ed5a More stuff works! --- diff --git a/English.lproj/InfoPlist.strings b/English.lproj/InfoPlist.strings index 534be77..2a0067a 100644 Binary files a/English.lproj/InfoPlist.strings and b/English.lproj/InfoPlist.strings differ diff --git a/English.lproj/NotiPod.xib b/English.lproj/NotiPod.xib index 4ef5559..b8f55cd 100644 --- a/English.lproj/NotiPod.xib +++ b/English.lproj/NotiPod.xib @@ -343,50 +343,89 @@ - + 268 YES - - + + 2304 YES - - + + 256 - {312, 304} - + {327, 338} + YES - - - 256 - {312, 17} - - - - - - 256 + + + -2147483392 {{313, 0}, {16, 17}} - YES - - 6.400000e+01 - 1.000000e+01 - 3.402823e+38 + + selected + 4.000000e+01 + 1.600000e+01 + 1.000000e+03 75628032 0 - Playlist - + + LucidaGrande 1.100000e+01 3100 + + 3 + MC4zMzMzMzI5ODU2AA + + + 6 + System + headerTextColor + + + + + 67239424 + 131072 + + + + 1211912703 + 130 + + NSImage + NSSwitch + + + NSSwitch + + + + 200 + 25 + + 1 + YES + YES + + + + playlist + 2.710000e+02 + 1.000000e+01 + 3.402823e+38 + + 75628032 + 0 + + 6 System @@ -396,19 +435,14 @@ MQA - - 6 - System - headerTextColor - - + - + 337772096 2048 - Text Cell + - + 6 System @@ -417,10 +451,9 @@ - 3 + 1 YES - YES - + 3.000000e+00 @@ -436,7 +469,7 @@ 1.700000e+01 - -700448768 + -759169024 4 15 0 @@ -444,57 +477,40 @@ 1 - {{1, 17}, {312, 304}} - - - + {{1, 1}, {327, 338}} + + + 4 - - - 256 - {{313, 17}, {15, 304}} - - + + + -2147483392 + {{313, 1}, {15, 323}} + + _doScroller: - 4.742590e-01 + 9.556213e-01 - - - 256 - {{1, 321}, {312, 15}} - + + + -2147483392 + {{1, 324}, {327, 15}} + 1 - + _doScroller: - 5.714286e-01 - - - - 2304 - - YES - - - {{1, 0}, {312, 17}} - - - - - 4 + 9.159664e-01 - - {{32, 163}, {329, 337}} + {{32, 160}, {329, 340}} - - 50 - - - - - + + 562 + + + QSAAAEEgAABBmAAAQZgAAA @@ -556,8 +572,8 @@ {{0, 0}, {1024, 746}} {3.40282e+38, 3.40282e+38} - - PlaylistTableModel + + PlaylistModel @@ -661,27 +677,19 @@ - playlistView - - + outlineView + + - 461 + 478 playlistModel - - - 463 - - - - tableView - - + - 464 + 479 @@ -847,8 +855,8 @@ - + @@ -998,59 +1006,68 @@ - 452 - + 467 + YES - - - - + + + - 453 - - + 468 + + - 454 - - + 469 + + - 455 - + 470 + YES - + + - + - 456 - - + 472 + + + YES + + + - 462 - + 477 + - 465 - + 484 + + + + + 485 + YES - + - + - 466 - - + 486 + + @@ -1121,12 +1138,13 @@ 436.IBPluginDependency 437.IBPluginDependency 438.IBPluginDependency - 452.IBPluginDependency - 453.IBPluginDependency - 454.IBPluginDependency - 455.IBPluginDependency - 456.IBPluginDependency - 462.IBPluginDependency + 467.IBPluginDependency + 468.IBPluginDependency + 469.IBPluginDependency + 470.IBPluginDependency + 472.IBPluginDependency + 477.IBPluginDependency + 484.IBPluginDependency 56.IBPluginDependency 56.ImportedFromIB2 57.IBPluginDependency @@ -1207,6 +1225,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1231,7 +1250,7 @@ - 466 + 487 @@ -1296,10 +1315,10 @@ - PlaylistTableModel + PlaylistModel NSObject - tableView + outlineView id diff --git a/Info.plist b/Info.plist index 8387725..c313290 100644 --- a/Info.plist +++ b/Info.plist @@ -9,7 +9,7 @@ CFBundleIconFile CFBundleIdentifier - com.yourcompany.notipod + au.net.delx.notipod CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/NotiPod.py b/NotiPod.py index bb810ba..68bb1a1 100644 --- a/NotiPod.py +++ b/NotiPod.py @@ -10,25 +10,58 @@ from PyObjCTools import AppHelper import libsyncitunes -class PlaylistTableModel(NSObject): - tableView = objc.IBOutlet() +class PlaylistModel(NSObject): + outlineView = objc.IBOutlet() def awakeFromNib(self): - self.playlists = [] - self.tableView.setDataSource_(self) - + self.root = [] + self.playlists = {} + self.outlineView.setDataSource_(self) + def setPlaylists(self, playlists): + self.root = [] self.playlists = playlists - self.tableView.reloadData() - - def tableView_objectValueForTableColumn_row_(self, tableView, col, row): - assert 0 <= row < len(self.playlists) - return self.playlists[row] - - def numberOfRowsInTableView_(self, tableView): - print "get number of rows", len(self.playlists) - return len(self.playlists) - + for playlist in self.playlists: + if playlist.parent is None: + self.root.append(playlist) + self.outlineView.reloadData() + + def outlineView_child_ofItem_(self, _, childIndex, playlist): + if playlist == None: + return self.root[childIndex] + else: + return playlist.children[childIndex] + + def outlineView_isItemExpandable_(self, _, playlist): + if playlist == None: + return True + else: + return len(playlist.children) > 0 + + def outlineView_numberOfChildrenOfItem_(self, _, playlist): + if playlist == None: + return len(self.root) + else: + return len(playlist.children) + + def outlineView_objectValueForTableColumn_byItem_(self, _, col, playlist): + col = col.identifier() if col else "playlist" + + if col == "selected": + selected = NSApp.delegate().playlists() + return playlist.pid in selected + if col == None or col == "playlist": + return playlist.name + + def outlineView_setObjectValue_forTableColumn_byItem_(self, _, v, col, playlist): + col = col.identifier() if col else "playlist" + + if col != "selected": + return + if v: + NSApp.delegate().addPlaylist_(playlist.pid) + else: + NSApp.delegate().delPlaylist_(playlist.pid) class NotiPodController(NSObject): @@ -40,10 +73,9 @@ class NotiPodController(NSObject): def awakeFromNib(self): self.performSelectorInBackground_withObject_(self.loadLibrary, None) - print "awakeFromNib" def finishLoading(self): - self.playlistModel.setPlaylists(self.library.list_playlists()) + self.playlistModel.setPlaylists(self.library.get_playlists()) self.folderPopup.addItemsWithTitles_(NSApp.delegate().folders()) def loadLibrary(self): @@ -89,21 +121,14 @@ class NotiPodController(NSObject): class NotiPodAppDelegate(NSObject): # Delegate methods - def applicationWillFinishLaunching_(self, _): - print "loading prefs" - prefs = NSUserDefaults.standardUserDefaults() - self._playlists = prefs.stringArrayForKey_("playlists") - self._folders = prefs.stringArrayForKey_("folders") - print "folders", self._folders - print "playlists", self._playlists + pass def applicationDidFinishLaunching_(self, _): pass def applicationWillTerminate_(self, _): - prefs = NSUserDefaults.standardUserDefaults() - prefs.synchronize() + self.prefs().synchronize() def applicationShouldTerminateAfterLastWindowClosed_(self, _): return True @@ -111,23 +136,36 @@ class NotiPodAppDelegate(NSObject): # Public accessors + def prefs(self): + return NSUserDefaults.standardUserDefaults() + + def _getArray(self, key): + res = self.prefs().stringArrayForKey_(key) + return list(res) if res else [] + + def _saveArray(self, key, array): + self.prefs().setObject_forKey_(array, key) + def playlists(self): - return self._playlists + return self._getArray("playlists") def folders(self): - return self._folders or [] + return self._getArray("folders") def addFolder_(self, folder): - self._folders.insert(0, folder) + folders = self.folders() + folders.append(folder) + self._saveArray("folders", folders) + + def delPlaylist_(self, playlist): + playlists = self.playlists() + playlists.remove(playlist) + self._saveArray("playlists", playlists) - def hasPlaylist_(self, playlist): - return playlist in self._playlists - - def removePlaylist_(self, playlist): - self._playlists.remove(playlist) - def addPlaylist_(self, playlist): - self._playlists.append(playlist) + playlists = self.playlists() + playlists.append(playlist) + self._saveArray("playlists", playlists) diff --git a/libsyncitunes.py b/libsyncitunes.py index 096abc2..7e955ad 100644 --- a/libsyncitunes.py +++ b/libsyncitunes.py @@ -22,11 +22,16 @@ def read_plist(filename): raise TypeError(errStr) return plist -class Playlist(object): - def __init__(self, name, tracks, parent=None): +class Playlist(NSObject): + def init(self): + return self + + def set(self, name, pid, tracks, parent): self.name = name + self.pid = pid self.children = [] - self.tracks = tracks + self.tracks = [] + self.parent = parent if parent is not None: parent.children.append(self) @@ -39,25 +44,35 @@ class ITunesLibrary(NSObject): plist = read_plist(os.path.expanduser(filename)) self.folder = self.loc2name(plist["Music Folder"]) pl_tracks = plist["Tracks"] - self.playlists = [] + self.playlists = {} for pl_playlist in plist["Playlists"]: - self.playlists.append(self.make_playlist(pl_playlist, pl_tracks)) + playlist = self.make_playlist(pl_playlist, pl_tracks) + self.playlists[playlist.pid] = playlist return self def loc2name(self, location): return urllib.splithost(urllib.splittype(urllib.unquote(location))[1])[1] def make_playlist(self, pl_playlist, pl_tracks): +### print pl_playlist name = pl_playlist["Name"] + pid = pl_playlist["Playlist Persistent ID"] + parent = None + try: + parent_pid = pl_playlist["Parent Persistent ID"] + parent = self.playlists.get(parent_pid) + except KeyError: + pass tracks = [] for item in pl_playlist.get("Playlist Items", []): trackID = item["Track ID"] filename = str(pl_tracks[str(trackID)]["Location"]) filename = self.loc2name(filename) - filename = filename[len(self.folder):] filename = eval(repr(filename).lstrip("u")).decode("utf-8") tracks.append(filename) - return Playlist(name, tracks) + playlist = Playlist.alloc().init() + playlist.set(name, pid, tracks, parent) + return playlist def has_playlist(self, playlist): for p in self.playlists: @@ -69,8 +84,8 @@ class ITunesLibrary(NSObject): playlist = [p for p in self.playlists if p.name == name][0] return playlist.tracks - def list_playlists(self): - return [p.name for p in self.playlists] + def get_playlists(self): + return self.playlists.values() def outlineView_numberOfChildrenOfItem_(self, view, item): if item == None: