Improved settings, plumbed it through to concurrent download limit

This commit is contained in:
Sumner Evans
2019-08-08 22:49:32 -06:00
parent ba3b306ea1
commit 75960ff8ba
6 changed files with 20 additions and 9 deletions

View File

@@ -195,7 +195,10 @@ class LibremsonicApp(Gtk.Application):
'download_on_stream'].get_active()
self.state.config.prefetch_amount = dialog.data[
'prefetch_amount'].get_value_as_int()
self.state.config.concurrent_download_limit = dialog.data[
'concurrent_download_limit'].get_value_as_int()
self.state.save()
self.reset_cache_manager()
dialog.destroy()
def on_play_pause(self, *args):
@@ -269,11 +272,13 @@ class LibremsonicApp(Gtk.Application):
self.state.config.current_server = current_server
self.state.save()
# Reset the CacheManager.
self.reset_cache_manager()
def reset_cache_manager(self):
CacheManager.reset(
self.state.config,
self.state.config.servers[current_server]
if current_server >= 0 else None,
self.state.config.servers[self.state.config.current_server]
if self.state.config.current_server >= 0 else None,
)
# Update the window according to the new server configuration.

View File

@@ -85,6 +85,9 @@ class CacheManager(metaclass=Singleton):
return json.JSONEncoder.default(self, obj)
class __CacheManagerInternal:
# TODO don't blow all of this away when the new cache manager is
# created on reset.
# Thread lock for preventing threads from overriding the state while
# it's being saved.
cache_lock = threading.Lock()
@@ -99,9 +102,6 @@ class CacheManager(metaclass=Singleton):
download_set_lock = threading.Lock()
current_downloads: Set[Path] = set()
# TODO make this configurable.
download_limiter_semaphore = threading.Semaphore(5)
def __init__(
self,
app_config: AppConfiguration,
@@ -116,6 +116,8 @@ class CacheManager(metaclass=Singleton):
username=server_config.username,
password=server_config.password,
)
self.download_limiter_semaphore = threading.Semaphore(
self.app_config.concurrent_download_limit)
self.load_cache_info()

View File

@@ -43,8 +43,10 @@ class AppConfiguration:
always_stream: bool = False # always stream instead of downloading songs
download_on_stream: bool = True # also download when streaming a song
prefetch_amount: int = 3
concurrent_download_limit: int = 5
def to_json(self):
# TODO can we simplify?
return {
'servers': [s.__dict__ for s in self.servers],
'current_server': self.current_server,
@@ -54,6 +56,7 @@ class AppConfiguration:
'always_stream': self.always_stream,
'download_on_stream': self.download_on_stream,
'prefetch_amount': self.prefetch_amount,
'concurrent_download_limit': self.concurrent_download_limit,
}
@property

View File

@@ -481,7 +481,7 @@ class AlbumWithSongs(Gtk.Box):
self.album_songs = Gtk.TreeView(
model=self.album_songs_model,
name='album-songs-list',
headers_visible=False,
headers_visible=False, # TODO use the config value for this
margin_top=15,
margin_left=10,
margin_right=10,

View File

@@ -94,14 +94,14 @@ class EditFormDialog(Gtk.Dialog):
i += 1
# Add the spin button entries to the content area.
for label, value_field_name, default_value in self.numeric_fields:
for label, value_field_name, range_config, default_value in self.numeric_fields:
entry_label = Gtk.Label(label=label + ':')
entry_label.set_halign(Gtk.Align.START)
content_grid.attach(entry_label, 0, i, 1, 1)
# Put the checkbox in the right box. Note we have to pad here
# since the checkboxes are smaller than the text fields.
spin_button = Gtk.SpinButton.new_with_range(0, 10, 1)
spin_button = Gtk.SpinButton.new_with_range(*range_config)
spin_button.set_value(
getattr(existing_object, value_field_name, default_value))
self.data[value_field_name] = spin_button

View File

@@ -234,6 +234,7 @@ class PlaylistsPanel(Gtk.Paned):
self.playlist_songs = Gtk.TreeView(
model=self.playlist_song_model,
headers_visible=False, # TODO use the config value for this
reorderable=True,
margin_top=15,
enable_search=True,