# Path: tomate/pomodoro/plugin.py
# class PluginEngine:
#     @inject(bus="tomate.bus", config="tomate.config", graph=Graph)
#     def __init__(self, bus: Bus, config: Config, graph: Graph):
#         self._bus = bus
#         self._graph = graph
# 
#         logger.debug("action=init paths=%s", config.plugin_paths())
#         self._plugin_manager = ConfigurablePluginManager(decorated_manager=VersionedPluginManager())
#         self._plugin_manager.setPluginPlaces(config.plugin_paths())
#         self._plugin_manager.setPluginInfoExtension("plugin")
#         self._plugin_manager.setConfigParser(config.parser, config.save)
# 
#     def collect(self) -> None:
#         logger.debug("action=collect")
#         self._plugin_manager.locatePlugins()
#         self._plugin_manager.loadPlugins(callback_after=self._configure_plugin)
# 
#     def _configure_plugin(self, plugin: PluginInfo) -> None:
#         if plugin.error is None:
#             plugin.plugin_object.configure(self._bus, self._graph)
# 
#     def deactivate(self, name: str) -> None:
#         self._plugin_manager.deactivatePluginByName(name)
# 
#     def activate(self, name: str) -> None:
#         self._plugin_manager.activatePluginByName(name)
# 
#     def all(self) -> List[PluginInfo]:
#         logger.debug("action=all")
#         return sorted(self._plugin_manager.getAllPlugins(), key=lambda info: info.name)
# 
#     def lookup(self, name: str, category="Default") -> Optional[PluginInfo]:
#         logger.debug("action=lookup name=%s category=%s", name, category)
#         return self._plugin_manager.getPluginByName(name, category)
# 
#     def has_plugins(self) -> bool:
#         has = len(self.all()) > 0
#         logger.debug("action=has_plugin has=%s", has)
#         return has
# 
#     def remove(self, plugin: object, category="Default") -> None:
#         self._plugin_manager.removePluginFromCategory(plugin, category)


import enum
import dbus.service
from dbus.mainloop.glib import DBusGMainLoop
from wiring import SingletonScope, inject
from wiring.scanning import register
from .plugin import PluginEngine


@register.factory("tomate.app", scope=SingletonScope)
class Application(dbus.service.Object):
    BUS_NAME = "com.github.Tomate"
    BUS_PATH = "/com/github/Tomate"
    BUS_INTERFACE = "com.github.Tomate"
    SPEC = "tomate.app"

    @inject(bus="dbus.session", window="tomate.ui.view", plugins="tomate.plugin")
    def __init__(self, bus, window, plugins: PluginEngine):
        dbus.service.Object.__init__(self, bus, self.BUS_PATH)
        self.state = State.STOPPED
        self._window = window
        plugins.collect()

    @dbus.service.method(BUS_INTERFACE, out_signature="b")
    def IsRunning(self):
        return self.state == State.STARTED

    @dbus.service.method(BUS_INTERFACE, out_signature="b")
    def Run(self):
        if self.IsRunning():
            self._window.show()
        else:
            self.state = State.STARTED
            self._window.run()

        return True


# Path: tomate/pomodoro/plugin.py
# class PluginEngine:
#     @inject(bus="tomate.bus", config="tomate.config", graph=Graph)
#     def __init__(self, bus: Bus, config: Config, graph: Graph):
#         self._bus = bus
#         self._graph = graph
# 
#         logger.debug("action=init paths=%s", config.plugin_paths())
#         self._plugin_manager = ConfigurablePluginManager(decorated_manager=VersionedPluginManager())
#         self._plugin_manager.setPluginPlaces(config.plugin_paths())
#         self._plugin_manager.setPluginInfoExtension("plugin")
#         self._plugin_manager.setConfigParser(config.parser, config.save)
# 
#     def collect(self) -> None:
#         logger.debug("action=collect")
#         self._plugin_manager.locatePlugins()
#         self._plugin_manager.loadPlugins(callback_after=self._configure_plugin)
# 
#     def _configure_plugin(self, plugin: PluginInfo) -> None:
#         if plugin.error is None:
#             plugin.plugin_object.configure(self._bus, self._graph)
# 
#     def deactivate(self, name: str) -> None:
#         self._plugin_manager.deactivatePluginByName(name)
# 
#     def activate(self, name: str) -> None:
#         self._plugin_manager.activatePluginByName(name)
# 
#     def all(self) -> List[PluginInfo]:
#         logger.debug("action=all")
#         return sorted(self._plugin_manager.getAllPlugins(), key=lambda info: info.name)
# 
#     def lookup(self, name: str, category="Default") -> Optional[PluginInfo]:
#         logger.debug("action=lookup name=%s category=%s", name, category)
#         return self._plugin_manager.getPluginByName(name, category)
# 
#     def has_plugins(self) -> bool:
#         has = len(self.all()) > 0
#         logger.debug("action=has_plugin has=%s", has)
#         return has
# 
#     def remove(self, plugin: object, category="Default") -> None:
#         self._plugin_manager.removePluginFromCategory(plugin, category)


# Path: tomate/pomodoro/app.py
import enum
import dbus.service
from dbus.mainloop.glib import DBusGMainLoop
from wiring import SingletonScope, inject
from wiring.scanning import register
from .plugin import PluginEngine



@register.factory("tomate.app", scope=SingletonScope)
class Application(dbus.service.Object):
    BUS_NAME = "com.github.Tomate"
    BUS_PATH = "/com/github/Tomate"
    BUS_INTERFACE = "com.github.Tomate"
    SPEC = "tomate.app"

    @inject(bus="dbus.session", window="tomate.ui.view", plugins="tomate.plugin")
    def __init__(self, bus, window, plugins: PluginEngine):
        dbus.service.Object.__init__(self, bus, self.BUS_PATH)
        self.state = State.STOPPED
        self._window = window
        plugins.collect()

    @dbus.service.method(BUS_INTERFACE, out_signature="b")
    def IsRunning(self):
        return self.state == State.STARTED

    @dbus.service.method(BUS_INTERFACE, out_signature="b")
    def Run(self):
        if self.IsRunning():
            self._window.show()
        else:
            self.state = State.STARTED
            self._window.run()

        return True


    @classmethod