# Path: resources/lib/controller/basecontroller.py
# class BaseController(object):
#     def render(self, name, args=None):
#         if args:
#             return router.render(name, args=args)
#         else:
#             return router.render(name)
# 
#     def route_exists(self, name):
#         return router.route_exists(name)
# 
#     def cleanup(self):
#         raise NotImplementedError("Cleanup needs to be implemented.")
# 
# def route(name):
#     def decorator(func):
#         xbmc.log("[script.luna.router]: Adding route with name %s to cache" % name)
#         assert name not in router._routes_cache, "Route with name %s already exists on the same class" % name
#         router._routes_cache[name] = func
#         return func
# 
#     return decorator


import xbmcgui
from resources.lib.controller.basecontroller import BaseController, route


class AudioController(BaseController):
    def __init__(self, core, audio_manager, config_helper):
        self.core = core
        self.audio_manager = audio_manager
        self.config_helper = config_helper

    @route(name="select")
    def select_audio_device(self):
        device_list = [dev.get_name() for dev in self.audio_manager.devices]
        device_list.append('sysdefault')
        audio_device = xbmcgui.Dialog().select('Choose Audio Device', device_list)

        if audio_device != -1:
            device_name = device_list[audio_device]
            device = self.audio_manager.get_device_by_name(device_name)
            if device:
                self.core.set_setting('audio_device', device.handler)
                self.core.set_setting('audio_device_name', device.name)


# Path: resources/lib/controller/basecontroller.py
# class BaseController(object):
#     def render(self, name, args=None):
#         if args:
#             return router.render(name, args=args)
#         else:
#             return router.render(name)
# 
#     def route_exists(self, name):
#         return router.route_exists(name)
# 
#     def cleanup(self):
#         raise NotImplementedError("Cleanup needs to be implemented.")
# 
# def route(name):
#     def decorator(func):
#         xbmc.log("[script.luna.router]: Adding route with name %s to cache" % name)
#         assert name not in router._routes_cache, "Route with name %s already exists on the same class" % name
#         router._routes_cache[name] = func
#         return func
# 
#     return decorator


# Path: resources/lib/controller/audiocontroller.py
import xbmcgui
from resources.lib.controller.basecontroller import BaseController, route



class AudioController(BaseController):
    def __init__(self, core, audio_manager, config_helper):
        self.core = core
        self.audio_manager = audio_manager
        self.config_helper = config_helper

    @route(name="select")
    def select_audio_device(self):
        device_list = [dev.get_name() for dev in self.audio_manager.devices]
        device_list.append('sysdefault')
        audio_device = xbmcgui.Dialog().select('Choose Audio Device', device_list)

        if audio_device != -1:
            device_name = device_list[audio_device]
            device = self.audio_manager.get_device_by_name(device_name)
            if device:
                self.core.set_setting('audio_device', device.handler)
                self.core.set_setting('audio_device_name', device.name)


        return