Made the ping messages better
This commit is contained in:
@@ -46,8 +46,18 @@ class AppConfiguration:
|
|||||||
'current_server': self.current_server,
|
'current_server': self.current_server,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_default_configuration(cls):
|
||||||
|
config = AppConfiguration()
|
||||||
|
config.servers = []
|
||||||
|
config.current_server = -1
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
def get_config(filename: str) -> AppConfiguration:
|
def get_config(filename: str) -> AppConfiguration:
|
||||||
|
if not os.path.exists(filename):
|
||||||
|
return AppConfiguration.get_default_configuration()
|
||||||
|
|
||||||
with open(filename, 'r') as f:
|
with open(filename, 'r') as f:
|
||||||
try:
|
try:
|
||||||
response_json = json.load(f)
|
response_json = json.load(f)
|
||||||
@@ -64,5 +74,7 @@ def get_config(filename: str) -> AppConfiguration:
|
|||||||
|
|
||||||
|
|
||||||
def save_config(config: AppConfiguration, filename: str):
|
def save_config(config: AppConfiguration, filename: str):
|
||||||
|
# Make the necessary directories before writing the config.
|
||||||
|
os.makedirs(os.path.dirname(filename), exist_ok=True)
|
||||||
with open(filename, 'w+') as f:
|
with open(filename, 'w+') as f:
|
||||||
f.write(json.dumps(config.to_json(), indent=2, sort_keys=True))
|
f.write(json.dumps(config.to_json(), indent=2, sort_keys=True))
|
||||||
|
@@ -39,7 +39,7 @@ class LibremsonicApp(Gtk.Application):
|
|||||||
config_folder = (os.environ.get('XDG_CONFIG_HOME')
|
config_folder = (os.environ.get('XDG_CONFIG_HOME')
|
||||||
or os.environ.get('APPDATA') or os.path.join(
|
or os.environ.get('APPDATA') or os.path.join(
|
||||||
os.environ.get('HOME'), '.config'))
|
os.environ.get('HOME'), '.config'))
|
||||||
config_folder = os.path.join(config_folder, 'visplay')
|
config_folder = os.path.join(config_folder, 'libremsonic')
|
||||||
self.config_file = os.path.join(config_folder, 'config.yaml')
|
self.config_file = os.path.join(config_folder, 'config.yaml')
|
||||||
|
|
||||||
self.activate()
|
self.activate()
|
||||||
|
@@ -90,7 +90,24 @@ class EditServerDialog(Gtk.Dialog):
|
|||||||
self.data['Username'].get_text(),
|
self.data['Username'].get_text(),
|
||||||
self.data['Password'].get_text(),
|
self.data['Password'].get_text(),
|
||||||
)
|
)
|
||||||
|
try:
|
||||||
server.ping()
|
server.ping()
|
||||||
|
dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO,
|
||||||
|
Gtk.ButtonsType.OK,
|
||||||
|
'Connection to server successful.')
|
||||||
|
dialog.format_secondary_markup(
|
||||||
|
f"Connection to {self.data['Server address'].get_text()} successful."
|
||||||
|
)
|
||||||
|
except Exception as err:
|
||||||
|
dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.ERROR,
|
||||||
|
Gtk.ButtonsType.OK,
|
||||||
|
'Connection to server unsuccessful.')
|
||||||
|
dialog.format_secondary_markup(
|
||||||
|
f"Connection to {self.data['Server address'].get_text()} resulted in the following error:\n\n{err}"
|
||||||
|
)
|
||||||
|
|
||||||
|
dialog.run()
|
||||||
|
dialog.destroy()
|
||||||
|
|
||||||
def on_open_in_browser_clicked(self, event):
|
def on_open_in_browser_clicked(self, event):
|
||||||
subprocess.call(['xdg-open', self.data['Server address'].get_text()])
|
subprocess.call(['xdg-open', self.data['Server address'].get_text()])
|
||||||
@@ -129,8 +146,8 @@ class ConfigureServersDialog(Gtk.Dialog):
|
|||||||
(Gtk.Button('Add...'), lambda e: self.on_edit_clicked(e, True),
|
(Gtk.Button('Add...'), lambda e: self.on_edit_clicked(e, True),
|
||||||
'start', False),
|
'start', False),
|
||||||
(Gtk.Button('Remove'), self.on_remove_clicked, 'start', True),
|
(Gtk.Button('Remove'), self.on_remove_clicked, 'start', True),
|
||||||
(Gtk.Button('Connect'), self.on_connect_clicked, 'end', False),
|
|
||||||
(Gtk.Button('Close'), lambda _: self.close(), 'end', False),
|
(Gtk.Button('Close'), lambda _: self.close(), 'end', False),
|
||||||
|
(Gtk.Button('Connect'), self.on_connect_clicked, 'end', True),
|
||||||
]
|
]
|
||||||
for button_cfg in self.buttons:
|
for button_cfg in self.buttons:
|
||||||
btn, action, pack_end, requires_selection = button_cfg
|
btn, action, pack_end, requires_selection = button_cfg
|
||||||
@@ -202,6 +219,7 @@ class ConfigureServersDialog(Gtk.Dialog):
|
|||||||
else:
|
else:
|
||||||
self.server_configs[selected_index] = new_config
|
self.server_configs[selected_index] = new_config
|
||||||
|
|
||||||
|
self.refresh_server_list()
|
||||||
self.emit('server-list-changed', self.server_configs)
|
self.emit('server-list-changed', self.server_configs)
|
||||||
|
|
||||||
dialog.destroy()
|
dialog.destroy()
|
||||||
|
@@ -31,8 +31,13 @@ class MainWindow(Gtk.ApplicationWindow):
|
|||||||
self.add(stack)
|
self.add(stack)
|
||||||
|
|
||||||
def update(self, config: AppConfiguration):
|
def update(self, config: AppConfiguration):
|
||||||
|
# Update the Connected to label on the popup menu.
|
||||||
|
if config.current_server >= 0:
|
||||||
server_name = config.servers[config.current_server].name
|
server_name = config.servers[config.current_server].name
|
||||||
self.connected_to_label.set_markup(f'Connected to {server_name}')
|
self.connected_to_label.set_markup(f'Connected to {server_name}')
|
||||||
|
else:
|
||||||
|
self.connected_to_label.set_markup(
|
||||||
|
f'<span style="italic">Not Connected to a Server</span>')
|
||||||
|
|
||||||
def create_stack(self, **kwargs):
|
def create_stack(self, **kwargs):
|
||||||
stack = Gtk.Stack()
|
stack = Gtk.Stack()
|
||||||
|
Reference in New Issue
Block a user