Anna Schumaker
a73063a04c
Bind the width and height properties to the settings so they are restored on startup and bind the fullscreen property to mpris. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
83 lines
2.6 KiB
Python
83 lines
2.6 KiB
Python
# Copyright 2022 (c) Anna Schumaker.
|
|
"""Set up our Application."""
|
|
from . import gsetup
|
|
from . import db
|
|
from . import mpris2
|
|
from . import options
|
|
from . import window
|
|
from gi.repository import GObject
|
|
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."""
|
|
|
|
db = GObject.Property(type=db.Connection)
|
|
mpris = GObject.Property(type=mpris2.Connection)
|
|
win = GObject.Property(type=window.Window)
|
|
|
|
def __init__(self):
|
|
"""Initialize an Application."""
|
|
super().__init__(application_id=gsetup.APPLICATION_ID,
|
|
resource_base_path=gsetup.RESOURCE_PATH)
|
|
self.add_main_option_entries([options.Version])
|
|
|
|
def build_window(self) -> window.Window:
|
|
"""Build a new window instance."""
|
|
win = window.Window(VERSION_STRING)
|
|
for (setting, property) in [("window.width", "default-width"),
|
|
("window.height", "default-height")]:
|
|
self.db.settings.bind_setting(setting, win, property)
|
|
|
|
return win
|
|
|
|
def connect_mpris2(self) -> None:
|
|
"""Connect the mpris2 properties and functions."""
|
|
self.mpris.app.link_property("Fullscreen", self.win, "fullscreened")
|
|
self.mpris.app.connect("Raise", self.win.present)
|
|
self.mpris.app.connect("Quit", self.win.close)
|
|
|
|
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)
|
|
self.db = db.Connection()
|
|
self.mpris = mpris2.Connection()
|
|
|
|
gsetup.add_style()
|
|
self.db.load()
|
|
|
|
self.win = self.build_window()
|
|
self.add_window(self.win)
|
|
self.connect_mpris2()
|
|
|
|
def do_activate(self) -> None:
|
|
"""Handle the Adw.Application::activate signal."""
|
|
Adw.Application.do_activate(self)
|
|
self.win.present()
|
|
|
|
def do_shutdown(self) -> None:
|
|
"""Handle the Adw.Application::shutdown signal."""
|
|
Adw.Application.do_shutdown(self)
|
|
if self.win is not None:
|
|
self.win.close()
|
|
self.win = None
|
|
if self.mpris is not None:
|
|
self.mpris.disconnect()
|
|
self.mpris = None
|
|
if self.db is not None:
|
|
self.db.close()
|
|
self.db = None
|