2022-05-26 14:42:09 -04:00
|
|
|
# Copyright 2022 (c) Anna Schumaker.
|
|
|
|
"""Set up our Application."""
|
|
|
|
from . import gsetup
|
2022-05-26 17:17:03 -04:00
|
|
|
from . import db
|
2022-10-20 16:50:17 -04:00
|
|
|
from . import mpris2
|
2022-05-26 14:42:09 -04:00
|
|
|
from . import options
|
2022-05-26 17:17:03 -04:00
|
|
|
from gi.repository import GObject
|
2022-05-26 14:42:09 -04:00
|
|
|
from gi.repository import GLib
|
|
|
|
from gi.repository import Adw
|
|
|
|
|
|
|
|
MAJOR_VERSION = 3
|
|
|
|
MINOR_VERSION = 0
|
|
|
|
VERSION_STRING = f"Emmental {MAJOR_VERSION}.{MINOR_VERSION}{gsetup.DEBUG_STR}"
|
|
|
|
|
|
|
|
|
|
|
|
class Application(Adw.Application):
|
|
|
|
"""Our custom Adw.Application."""
|
|
|
|
|
2022-05-26 17:17:03 -04:00
|
|
|
db = GObject.Property(type=db.Connection)
|
2022-10-20 16:50:17 -04:00
|
|
|
mpris = GObject.Property(type=mpris2.Connection)
|
2022-05-26 17:17:03 -04:00
|
|
|
|
2022-05-26 14:42:09 -04:00
|
|
|
def __init__(self):
|
|
|
|
"""Initialize an Application."""
|
2022-07-15 14:53:04 -04:00
|
|
|
super().__init__(application_id=gsetup.APPLICATION_ID,
|
|
|
|
resource_base_path=gsetup.RESOURCE_PATH)
|
2022-05-26 14:42:09 -04:00
|
|
|
self.add_main_option_entries([options.Version])
|
|
|
|
|
|
|
|
def do_handle_local_options(self, opts: GLib.VariantDict) -> int:
|
|
|
|
"""Handle any command line options."""
|
|
|
|
if opts.contains("version"):
|
|
|
|
print(VERSION_STRING)
|
|
|
|
gsetup.print_versions()
|
|
|
|
return 0
|
|
|
|
return -1
|
|
|
|
|
|
|
|
def do_startup(self) -> None:
|
|
|
|
"""Handle the Adw.Application::startup signal."""
|
|
|
|
Adw.Application.do_startup(self)
|
2022-05-26 17:17:03 -04:00
|
|
|
self.db = db.Connection()
|
2022-10-20 16:50:17 -04:00
|
|
|
self.mpris = mpris2.Connection()
|
2022-05-26 17:17:03 -04:00
|
|
|
|
2022-08-02 13:15:24 -04:00
|
|
|
gsetup.add_style()
|
2022-05-26 17:18:21 -04:00
|
|
|
self.db.load()
|
2022-05-26 14:42:09 -04:00
|
|
|
|
|
|
|
def do_activate(self) -> None:
|
|
|
|
"""Handle the Adw.Application::activate signal."""
|
|
|
|
Adw.Application.do_activate(self)
|
2022-05-26 17:17:03 -04:00
|
|
|
|
|
|
|
def do_shutdown(self) -> None:
|
|
|
|
"""Handle the Adw.Application::shutdown signal."""
|
|
|
|
Adw.Application.do_shutdown(self)
|
2022-10-20 16:50:17 -04:00
|
|
|
if self.mpris is not None:
|
|
|
|
self.mpris.disconnect()
|
|
|
|
self.mpris = None
|
2022-05-26 17:17:03 -04:00
|
|
|
if self.db is not None:
|
|
|
|
self.db.close()
|
|
|
|
self.db = None
|