Files
sublime-music/libremsonic/ui/app.py
2019-06-05 22:54:27 -06:00

68 lines
2.0 KiB
Python

import os
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gio, Gtk
from libremsonic.config import get_config, save_config
from .main import MainWindow
from .configure_servers import ConfigureServersDialog
class LibremsonicApp(Gtk.Application):
def __init__(self, *args, **kwargs):
super().__init__(
*args,
application_id="com.sumnerevans.libremsonic",
**kwargs,
)
self.window = None
# TODO load this from the config file
self.config = None
def do_startup(self):
Gtk.Application.do_startup(self)
action = Gio.SimpleAction.new('configure_servers', None)
action.connect('activate', self.on_configure_servers)
self.add_action(action)
def do_activate(self):
# We only allow a single window and raise any existing ones
if not self.window:
# Windows are associated with the application
# when the last one is closed the application shuts down
self.window = MainWindow(application=self, title="LibremSonic")
self.window.show_all()
self.window.present()
self.load_settings()
if self.config.current_server is None:
self.show_configure_servers_dialog()
print('current config', self.config)
def on_configure_servers(self, action, param):
self.show_configure_servers_dialog()
def on_server_list_changed(self, action, params):
server_config, *_ = params
self.save_settings()
def show_configure_servers_dialog(self):
dialog = ConfigureServersDialog(self.window, self.config.servers)
dialog.connect('server-list-changed', self.on_server_list_changed)
dialog.run()
dialog.destroy()
def load_settings(self):
self.config = get_config(os.path.expanduser('~/tmp/test.json'))
def save_settings(self):
save_config(self.config, os.path.expanduser('~/tmp/test.json'))