# Bryan Schumaker (8/7/2010)

__all__ = [ "audio", "sources",
	"event", "map", "path", "plugin"]

__major__ = 1
__minor__ = 3
__bug__   = 3
__dev__   = False

__vers__  = "Libsaria %s.%s" % (__major__, __minor__)
if __bug__ > 0:
	__vers__ = "%s.%s" % (__vers__, __bug__)
if __dev__ == True:
	__vers__ += "-dev"

import event
import path
from trees import Tree, PersPrefTree
from path.cache import Cache

# The cache is also saved across sessions
prefs = None
cache = Cache()

plugin   = None
audio    = None
lastfm   = None
controls = None

init_pref = None


# Initialize helpful variables
def init():
	global prefs
	global init_pref
	global audio
	global lastfm
	global controls

	prefs = trees.get_pref_tree("preferences")
	init_pref = prefs.init_pref
	import audio
	import controls
	from path import lastfm
	event.invite("POSTLIBLOAD", parse_user_input)

	controls.init()
	event.start("POSTINIT")


def startup():
	global plugin
	import plugin

	event.start("PRESTART")
	audio.init()
	controls.init2()
	plugin.load_all()
	prefs.enable_save()
	event.start("POSTSTART")


def shutdown():
	event.start("PREQUIT")
	import plugin
	plugin.quit()
	event.start("POSTQUIT")


def parse_user_input():
	import sys
	for item in sys.argv[1:]:
		path.files.universal_open(item)


init()
