Started trying to figure out how to listen to the system bus for network changes
This commit is contained in:
@@ -432,8 +432,8 @@ class SublimeMusicApp(Gtk.Application):
|
||||
dialog = SettingsDialog(self.window, self.state.config)
|
||||
result = dialog.run()
|
||||
if result == Gtk.ResponseType.OK:
|
||||
self.state.config.show_headers = dialog.data[
|
||||
'show_headers'].get_active()
|
||||
self.state.config.port_number = int(
|
||||
dialog.data['port_number'].get_text())
|
||||
self.state.config.always_stream = dialog.data[
|
||||
'always_stream'].get_active()
|
||||
self.state.config.download_on_stream = dialog.data[
|
||||
|
@@ -6,6 +6,7 @@ import shutil
|
||||
import json
|
||||
import hashlib
|
||||
|
||||
from functools import lru_cache
|
||||
from collections import defaultdict
|
||||
from time import sleep
|
||||
|
||||
@@ -75,6 +76,12 @@ class SongCacheStatus(Enum):
|
||||
DOWNLOADING = 3
|
||||
|
||||
|
||||
# This may end up being called a lot, so cache the similarity ratios.
|
||||
@lru_cache(maxsize=8192)
|
||||
def similarity_ratio(query, string):
|
||||
return fuzz.partial_ratio(query.lower(), string.lower())
|
||||
|
||||
|
||||
class SearchResult:
|
||||
_artist: Set[Union[Artist, ArtistID3]] = set()
|
||||
_album: Set[Union[Child, AlbumID3]] = set()
|
||||
@@ -100,14 +107,7 @@ class SearchResult:
|
||||
|
||||
def _to_result(self, it, transform):
|
||||
all_results = sorted(
|
||||
(
|
||||
(
|
||||
fuzz.partial_ratio(
|
||||
self.query.lower(),
|
||||
transform(x).lower(),
|
||||
),
|
||||
x,
|
||||
) for x in it),
|
||||
((similarity_ratio(self.query, transform(x)), x) for x in it),
|
||||
key=lambda rx: rx[0],
|
||||
reverse=True,
|
||||
)
|
||||
|
@@ -57,7 +57,6 @@ class AppConfiguration:
|
||||
current_server: int = -1
|
||||
_cache_location: str = ''
|
||||
max_cache_size_mb: int = -1 # -1 means unlimited
|
||||
show_headers: bool = True # show the headers on song lists
|
||||
always_stream: bool = False # always stream instead of downloading songs
|
||||
download_on_stream: bool = True # also download when streaming a song
|
||||
song_play_notification: bool = True
|
||||
|
@@ -78,6 +78,14 @@ class DBusManager:
|
||||
dbus_name_lost,
|
||||
)
|
||||
|
||||
def system_bus_ready(_, task):
|
||||
connection = Gio.bus_get_finish(task)
|
||||
print(connection.signal_subscribe(
|
||||
None, 'org.freedesktop.DBus.Properties', None, None, None,
|
||||
Gio.DBusSignalFlags.NONE, lambda *a: print(a), None))
|
||||
|
||||
Gio.bus_get(Gio.BusType.SYSTEM, None, system_bus_ready)
|
||||
|
||||
def shutdown(self):
|
||||
Gio.bus_unown_name(self.bus_number)
|
||||
|
||||
|
@@ -148,7 +148,7 @@ class AlbumWithSongs(Gtk.Box):
|
||||
self.album_songs = Gtk.TreeView(
|
||||
model=self.album_song_store,
|
||||
name='album-songs-list',
|
||||
headers_visible=False, # TODO use the config value for this
|
||||
headers_visible=False,
|
||||
margin_top=15,
|
||||
margin_left=10,
|
||||
margin_right=10,
|
||||
|
@@ -16,7 +16,6 @@ class SettingsDialog(EditFormDialog):
|
||||
),
|
||||
]
|
||||
boolean_fields = [
|
||||
('Show headers on song lists', 'show_headers'),
|
||||
('Always stream songs', 'always_stream'),
|
||||
('When streaming, also download song', 'download_on_stream'),
|
||||
(
|
||||
|
Reference in New Issue
Block a user