Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added manual library management option ui
- Loading branch information
Alex Ehlke
committed
May 31, 2010
1 parent
bda718a
commit d44d9fb
Showing
8 changed files
with
566 additions
and
38 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,77 @@ | |||
|
|||
|
|||
#from configobj import ConfigObj | |||
#import ConfigParser | |||
#import json | |||
import pickle | |||
|
|||
import sys | |||
from os import path, environ, makedirs | |||
|
|||
APP_NAME = "Download To iTunes" | |||
CONFIG_FILENAME = 'config.cfg' | |||
|
|||
DEFAULTS = {'iTunesManagesMyLibrary': 1} | |||
|
|||
def data_path(): | |||
#if sys.platform == 'darwin': | |||
from AppKit import NSSearchPathForDirectoriesInDomains | |||
# http://developer.apple.com/DOCUMENTATION/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Functions/Reference/reference.html#//apple_ref/c/func/NSSearchPathForDirectoriesInDomains | |||
# NSApplicationSupportDirectory = 14 | |||
# NSUserDomainMask = 1 | |||
# True for expanding the tilde into a fully qualified path | |||
ret = path.join(NSSearchPathForDirectoriesInDomains(14, 1, True)[0], APP_NAME) | |||
if not path.exists(ret): | |||
makedirs(ret) | |||
return ret | |||
|
|||
def config_file_path(): | |||
data_dir = data_path() | |||
return path.join(data_dir, CONFIG_FILENAME) | |||
|
|||
|
|||
def get_config(): | |||
#return ConfigObj(config_file_path()) | |||
#config2 = ConfigParser.RawConfigParser() | |||
#config2.read(config_file_path()) | |||
#return config2 | |||
try: | |||
f = open(config_file_path()) | |||
s = f.read() | |||
f.close() | |||
except IOError: | |||
return {} | |||
if s: | |||
#return json.loads(s) | |||
return pickle.loads(s) | |||
else: | |||
return {} | |||
|
|||
|
|||
def save_config(config_obj): | |||
#config_obj.write(config_file_path()) | |||
f = file(config_file_path(), 'w') | |||
#s = json.dumps(config_obj) | |||
s = pickle.dumps(config_obj) | |||
f.write(s) | |||
f.close() | |||
|
|||
def set_config_option(key, value): | |||
'''Sets and saves option.''' | |||
config_obj = get_config() | |||
#config_obj[key] = value | |||
config_obj[key] = value | |||
save_config(config_obj) | |||
|
|||
def get_config_option(key): | |||
config_obj = get_config() | |||
return config_obj.get(key, DEFAULTS.get(key, None)) | |||
|
|||
|
|||
|
|||
|
|||
#elif sys.platform == 'win32': | |||
# appdata = path.join(environ['APPDATA'], APPNAME) | |||
#else: | |||
# appdata = path.expanduser(path.join("~", "." + APPNAME)) | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,88 @@ | |||
# | |||
# controller.py | |||
# itunesloader | |||
# | |||
# Created by Alex Ehlke on 5/30/10. | |||
# Copyright (c) 2010 __MyCompanyName__. All rights reserved. | |||
# | |||
|
|||
from objc import YES, NO, IBAction, IBOutlet, ivar, accessor | |||
from Foundation import * | |||
from AppKit import * | |||
|
|||
import config | |||
|
|||
|
|||
|
|||
class controller(NSWindowController): | |||
iTunesManagesMyLibrary = ivar('iTunesManagesMyLibrary') | |||
#iTunesManagesMyLibrary = ivar() | |||
iTunesManagesMyLibraryMenuItem = IBOutlet() | |||
iTunesLibraryLocationMenuItem = IBOutlet() | |||
iTunesLibraryLocationMenuItemEnabled = ivar('iTunesLibraryLocationMenuItemEnabled') | |||
|
|||
def awakeFromNib(self): | |||
#NSLog('awakeFromNib') | |||
self.iTunesManagesMyLibrary = config.get_config_option('iTunesManagesMyLibrary') | |||
self.iTunesManagesMyLibraryMenuItem.setState_(self.iTunesManagesMyLibrary) | |||
self.refreshMenuEnable() | |||
|
|||
#@accessor | |||
#def iTunesManagesMyLibraryValue(self): | |||
# return self.iTunesManagesMyLibrary | |||
|
|||
@accessor | |||
def setITunesManagesMyLibrary_(self, value): | |||
#NSLog('setITunesManagesMyLibrary_') | |||
self.iTunesManagesMyLibrary = value | |||
#NSLog(str(self.iTunesManagesMyLibrary)) | |||
config.set_config_option('iTunesManagesMyLibrary', value) | |||
self.refreshMenuEnable() | |||
|
|||
@IBAction | |||
def setLibraryLocation_(self, sender): | |||
#NSLog('setLibraryLocation_') | |||
panel = NSOpenPanel.openPanel() | |||
panel.setCanChooseDirectories_(YES) | |||
panel.setAllowsMultipleSelection_(NO) | |||
panel.setCanChooseFiles_(NO) | |||
old_path = config.get_config_option('iTunesLibraryLocation') | |||
ret = panel.runModalForDirectory_file_types_(old_path, None, None) | |||
#NSLog(str(ret)) | |||
if ret: | |||
path = panel.filenames()[0] | |||
config.set_config_option('iTunesLibraryLocation', path) | |||
else: | |||
# Canceled | |||
pass | |||
|
|||
def refreshMenuEnable(self): | |||
#NSLog('refreshMenuEnable') | |||
if self.iTunesManagesMyLibrary: | |||
#NSLog('NO') | |||
#self.iTunesLibraryLocationMenuItem.setEnabled_(NO) | |||
self.iTunesLibraryLocationMenuItemEnabled = NO | |||
else: | |||
#NSLog('YES') | |||
#self.iTunesLibraryLocationMenuItem.setEnabled_(YES) | |||
self.iTunesLibraryLocationMenuItemEnabled = YES | |||
|
|||
@IBAction | |||
def toggleITunesManagesMyLibrary_(self, sender): | |||
#NSLog('toggleITunesManagesMyLibrary_') | |||
#self.refreshMenuEnable() | |||
pass | |||
#NSLog('tog action') | |||
#self.iTunesLibraryLocationMenuItem.setEnabled_(self.iTunesManagesMyLibrary == 0) | |||
#pass | |||
|
|||
#NSLog(sender.state()) | |||
#NSLog(dir(self).__repr__())#self.iTunesManagesMyLibrary).__repr__()) | |||
#self.toggleITunesManagesMyLibrary_.setState_(0) | |||
#NSLog(dir(self.toggleITunesManagesMyLibrary).__repr__()) | |||
#toggleITunesManagesMyLibrary_.setEnabled(false) | |||
|
|||
#self.iTunesManagesMyLibrary.setState_(0) | |||
#self.iTunesManagesMyLibrary.setEnabled(false) | |||
|
|||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.