Permalink
Browse files

playdar.prefPane, initial commit.

Needs a little more work, but the playdar inside is functional. Intel
only. May require OS X 10.4.
  • Loading branch information...
0 parents commit 4e49a6459bdc572583c9e59552c05e550f17942a Max Howell committed Mar 2, 2009
Showing with 1,314 additions and 0 deletions.
  1. BIN English.lproj/InfoPlist.strings
  2. +622 −0 English.lproj/main.xib
  3. +32 −0 Info.plist
  4. +15 −0 install_name_tool.rb
  5. +44 −0 main.h
  6. +131 −0 main.m
  7. +8 −0 pc.h
  8. BIN playdar.icns
  9. +9 −0 playdar.ini.rb
  10. +439 −0 playdar.prefPane.xcodeproj/project.pbxproj
  11. +14 −0 scan.sh
Binary file not shown.
Oops, something went wrong.
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIconFile</key>
+ <string>playdar.icns</string>
+ <key>CFBundleIdentifier</key>
+ <string>org.playdar</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>BNDL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>0.1</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>0.1</string>
+ <key>NSMainNibFile</key>
+ <string>main</string>
+ <key>NSPrefPaneIconLabel</key>
+ <string>Playdar</string>
+ <key>NSPrincipalClass</key>
+ <string>OrgPlaydarPreferencePane</string>
+</dict>
+</plist>
@@ -0,0 +1,15 @@
+#!/usr/bin/ruby
+
+def opt( f )
+ lines = `otool -L #{f}`.split( "\n" )
+ lines.shift
+ lines.each do |line|
+ path = line.strip.split[0]
+ yield( path, "@executable_path/#{File.basename( path )}" ) if path.match( '^/opt' )
+ end
+end
+
+Dir['*'].each do |f|
+ `install_name_tool -id #{f} #{f}` if File.extname( f ) == '.dylib'
+ opt( f ) { |from, to| `install_name_tool -change #{from} #{to} #{f}` }
+end
@@ -0,0 +1,44 @@
+/*
+ Created on 28/02/2009
+ Copyright 2009 Max Howell <mxcl@users.sf.net>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#import <PreferencePanes/PreferencePanes.h>
+
+// long class name is because we get loaded into System Preferences process, so
+// we are required to be ultra verbose
+// http://developer.apple.com/documentation/UserExperience/Conceptual/PreferencePanes/Tasks/Conflicts.html#//apple_ref/doc/uid/20000706
+@interface OrgPlaydarPreferencePane : NSPreferencePane
+{
+ IBOutlet NSPopUpButton* popup;
+ IBOutlet NSButton* scan;
+ IBOutlet NSButton* start;
+}
+
+-(void)mainViewDidLoad;
+
+-(void)openPanelDidEnd:(NSOpenPanel*)panel
+ returnCode:(int)returnCode
+ contextInfo:(void*)contextInfo;
+
+-(void)exec:(NSString*)command
+ withArgs:(NSArray*)args;
+
+-(IBAction)select:(id)sender; //TODO doesn't need to be IBAction
+-(IBAction)onScan:(id)sender;
+-(IBAction)onStart:(id)sender;
+
+@end
@@ -0,0 +1,131 @@
+/*
+ Created on 28/02/2009
+ Copyright 2009 Max Howell <mxcl@users.sf.net>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+
+//TODO remember path that we scanned with defaults controller
+//TODO memory leaks
+//TODO watch exit code of playdard (if early exits), and watch process while pref pane is open
+//TODO log that stupid exception
+//TODO sparkle updates
+//TODO start at login checkbox
+
+
+#import "main.h"
+
+
+static inline NSString* iniPath()
+{
+ return [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Preferences/org.playdar.ini"];
+}
+
+static inline NSString* collectionDbPath()
+{
+ return [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/Playdar/collection.db"];
+}
+
+static inline NSString* fullname()
+{
+ // being cautious
+ NSString* fullname = NSFullUserName();
+ return (fullname && [fullname length] > 0) ? fullname : NSUserName();
+}
+
+
+@implementation OrgPlaydarPreferencePane
+
+-(void)mainViewDidLoad
+{
+ NSString* ini = iniPath();
+ if ([[NSFileManager defaultManager] fileExistsAtPath:ini] == false)
+ {
+ NSArray* args = [NSArray arrayWithObjects: fullname(), collectionDbPath(), ini, nil];
+ [self exec:@"playdar.ini.rb" withArgs:args];
+ }
+
+ NSString* home = NSHomeDirectory();
+ [popup addItemWithTitle: [home stringByAppendingPathComponent:@"Music"]];
+ [popup addItemWithTitle: home];
+ [[popup menu] addItem:[NSMenuItem separatorItem]];
+ [[[popup menu] addItemWithTitle:@"Select..." action:@selector(select:) keyEquivalent:@""] setTarget:self];
+}
+
+-(void)onScan:(id)sender
+{
+ NSArray* args = [NSArray arrayWithObjects:[popup titleOfSelectedItem], collectionDbPath(), nil];
+ [self exec:@"scan.sh" withArgs:args];
+}
+
+-(void)onStart:(id)sender
+{
+ NSArray* args = [NSArray arrayWithObjects:@"-c", iniPath(), nil];
+ [self exec:@"../MacOS/playdard" withArgs:args];
+}
+
+////// Directory selector
+-(void)select:(id)sender
+{
+ if ([popup indexOfSelectedItem] != [popup numberOfItems]-1) return;
+
+ NSOpenPanel* panel = [NSOpenPanel openPanel];
+ [panel setCanChooseFiles:NO];
+ [panel setCanChooseDirectories:YES];
+
+ [panel beginSheetForDirectory:nil
+ file:nil
+ modalForWindow:[[self mainView] window]
+ modalDelegate:self
+ didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:)
+ contextInfo:nil];
+}
+
+-(void)openPanelDidEnd:(NSOpenPanel*)panel
+ returnCode:(int)returnCode
+ contextInfo:(void*)contextInfo
+{
+ if (returnCode == NSOKButton) {
+ int const index = [[popup menu] numberOfItems]-2;
+ [popup insertItemWithTitle:[panel filename]
+ atIndex:index];
+ [popup selectItemAtIndex: index];
+ }
+ else
+ [popup selectItemAtIndex:0];
+}
+////// Directory selectors
+
+
+-(void)exec:(NSString*)command
+ withArgs:(NSArray*)args
+{
+ @try {
+ NSString* resources = [[self bundle] resourcePath];
+ NSString* path = [resources stringByAppendingPathComponent:command];
+
+ NSTask *task = [[NSTask alloc] init];
+ [task setCurrentDirectoryPath:resources];
+ [task setLaunchPath:path];
+ [task setArguments:args];
+ [task launch];
+ }
+ @catch (NSException* e)
+ {
+ //TODO log - couldn't figure out easy way to do this
+ }
+}
+
+@end
@@ -0,0 +1,8 @@
+//
+// Prefix header for all source files of the 'playdar-prefpane' target in the 'playdar-prefpane' project.
+//
+
+#ifdef __OBJC__
+ #import <Foundation/Foundation.h>
+ #import <AppKit/AppKit.h>
+#endif
Binary file not shown.
@@ -0,0 +1,9 @@
+#!/usr/bin/ruby
+# Created by Max Howell on 01/03/2009.
+
+contents = File.new( 'playdar.ini' ).read
+contents.sub!( 'name="YOURNAMEHERE"', "name=\"#{ARGV[0]}\"" )
+contents.sub!( 'db="collection.db"', "db=\"#{ARGV[1]}\"" )
+File.open( ARGV[2], 'w' ) { |f| f.write( contents ) }
+
+puts "Created #{ARGV[2]}"
Oops, something went wrong.

0 comments on commit 4e49a64

Please sign in to comment.