This commit is contained in:
Benjamin Schaaf
2022-01-11 17:16:53 +11:00
parent c7b0bc0bc8
commit 1f31e62340
5 changed files with 38 additions and 77 deletions

View File

@@ -458,7 +458,7 @@ class AdapterManager:
f"expected size ({expected_size})." f"expected size ({expected_size})."
) )
block_size = 1024 # 1 KiB block_size = 512 * 1024 # 512 KiB
total_consumed = 0 total_consumed = 0
with open(download_tmp_filename, "wb+") as f: with open(download_tmp_filename, "wb+") as f:
@@ -473,21 +473,18 @@ class AdapterManager:
) )
raise Exception("Download Cancelled") raise Exception("Download Cancelled")
if i % 100 == 0: if DOWNLOAD_BLOCK_DELAY is not None:
# Only delay (if configured) and update the progress UI sleep(DOWNLOAD_BLOCK_DELAY)
# every 100 KiB.
if DOWNLOAD_BLOCK_DELAY is not None:
sleep(DOWNLOAD_BLOCK_DELAY)
if expected_size_exists: if expected_size_exists:
AdapterManager._instance.song_download_progress( AdapterManager._instance.song_download_progress(
id, id,
DownloadProgress( DownloadProgress(
DownloadProgress.Type.PROGRESS, DownloadProgress.Type.PROGRESS,
total_bytes=total_size, total_bytes=total_size,
current_bytes=total_consumed, current_bytes=total_consumed,
), ),
) )
# Everything succeeded. # Everything succeeded.
if expected_size_exists: if expected_size_exists:

View File

@@ -6,7 +6,7 @@ import sys
from datetime import timedelta from datetime import timedelta
from functools import partial from functools import partial
from pathlib import Path from pathlib import Path
from typing import Any, Callable, Dict, Iterable, List, Optional, Set, Tuple from typing import Any, Callable, Dict, Iterable, List, Optional, Set, Tuple, Union
from urllib.parse import urlparse from urllib.parse import urlparse
import bleach import bleach
@@ -173,6 +173,10 @@ class SublimeMusicApp(Gtk.Application):
register_action(albums, self.albums_select_album, 'select-album') register_action(albums, self.albums_select_album, 'select-album')
self.window.insert_action_group('albums', albums) self.window.insert_action_group('albums', albums)
playlists = Gio.SimpleActionGroup()
register_action(playlists, self.playlists_set_details_expanded, 'set-details-expanded')
self.window.insert_action_group('playlists', playlists)
settings = Gio.SimpleActionGroup() settings = Gio.SimpleActionGroup()
register_dataclass_actions(settings, self.app_config, after=self._save_and_refresh) register_dataclass_actions(settings, self.app_config, after=self._save_and_refresh)
self.window.insert_action_group('settings', settings) self.window.insert_action_group('settings', settings)
@@ -826,7 +830,7 @@ class SublimeMusicApp(Gtk.Application):
self.app_config.state.current_tab = tab_id self.app_config.state.current_tab = tab_id
self.update_window() self.update_window()
def play_song_action(self, song_index: int, song_queue: List[str], metadata: Dict[str, bool]): def play_song_action(self, song_index: int, song_queue: List[str], metadata: Dict[str, Any]):
if not song_queue: if not song_queue:
song_queue = self.app_config.state.play_queue song_queue = self.app_config.state.play_queue
@@ -992,6 +996,10 @@ class SublimeMusicApp(Gtk.Application):
self.app_config.state.selected_album_id = album_id self.app_config.state.selected_album_id = album_id
self.update_window() self.update_window()
def playlists_set_details_expanded(self, expanded: bool):
self.app_config.state.playlist_details_expanded = expanded
self.update_window()
def players_set_option(self, player: str, option: str, value: Any): def players_set_option(self, player: str, option: str, value: Any):
self.app_config.player_config[player][option] = value self.app_config.player_config[player][option] = value

View File

@@ -485,12 +485,12 @@ class ArtistDetailPanel(Gtk.Box):
def on_play_all_clicked(self, _): def on_play_all_clicked(self, _):
songs = self.get_artist_song_ids() songs = self.get_artist_song_ids()
run_action(self, 'app.play-song', 0, songs, {"force_shuffle_state": False}) run_action(self, 'app.play-song', 0, songs, {"force_shuffle_state": GLib.Variant('b', False)})
def on_shuffle_all_button(self, _): def on_shuffle_all_button(self, _):
songs = self.get_artist_song_ids() songs = self.get_artist_song_ids()
song_idx = randint(0, len(songs) - 1) song_idx = randint(0, len(songs) - 1)
run_action(self, 'app.play-song', song_idx, songs, {"force_shuffle_state": True}) run_action(self, 'app.play-song', song_idx, songs, {"force_shuffle_state": GLib.Variant('b', True)})
# Helper Methods # Helper Methods
# ========================================================================= # =========================================================================

View File

@@ -1,5 +1,5 @@
from random import randint from random import randint
from typing import Any, cast, List from typing import Any, cast, List, Dict
from gi.repository import Gdk, GLib, GObject, Gtk, Pango, Handy from gi.repository import Gdk, GLib, GObject, Gtk, Pango, Handy
@@ -243,13 +243,13 @@ class AlbumWithSongs(Gtk.Box):
) )
def play_btn_clicked(self, btn: Any): def play_btn_clicked(self, btn: Any):
self.play_song(0, {"force_shuffle_state": False}) self.play_song(0, {"force_shuffle_state": GLib.Variant('b', False)})
def shuffle_btn_clicked(self, btn: Any): def shuffle_btn_clicked(self, btn: Any):
self.play_song(randint(0, len(self.album_song_store) - 1), self.play_song(randint(0, len(self.album_song_store) - 1),
{"force_shuffle_state": True}) {"force_shuffle_state": GLib.Variant('b', True)})
def play_song(self, index: int, metadata: Any): def play_song(self, index: int, metadata: Dict[str, GLib.Variant]):
run_action(self, 'app.play-song', index, [m[-1] for m in self.album_song_store], metadata) run_action(self, 'app.play-song', index, [m[-1] for m in self.album_song_store], metadata)
# Helper Methods # Helper Methods

View File

@@ -131,19 +131,6 @@ class EditPlaylistWindow(Handy.Window):
class PlaylistsPanel(Handy.Leaflet): class PlaylistsPanel(Handy.Leaflet):
"""Defines the playlists panel.""" """Defines the playlists panel."""
__gsignals__ = {
"song-clicked": (
GObject.SignalFlags.RUN_FIRST,
GObject.TYPE_NONE,
(int, object, object),
),
"refresh-window": (
GObject.SignalFlags.RUN_FIRST,
GObject.TYPE_NONE,
(object, bool),
),
}
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
Gtk.Paned.__init__(self, transition_type=Handy.LeafletTransitionType.SLIDE, can_swipe_forward=False, interpolate_size=False) Gtk.Paned.__init__(self, transition_type=Handy.LeafletTransitionType.SLIDE, can_swipe_forward=False, interpolate_size=False)
@@ -154,14 +141,6 @@ class PlaylistsPanel(Handy.Leaflet):
details_sizer = Sizer(hexpand=True, natural_width=800) details_sizer = Sizer(hexpand=True, natural_width=800)
self.playlist_detail_panel = PlaylistDetailPanel() self.playlist_detail_panel = PlaylistDetailPanel()
self.playlist_detail_panel.connect(
"song-clicked",
lambda _, *args: self.emit("song-clicked", *args),
)
self.playlist_detail_panel.connect(
"refresh-window",
lambda _, *args: self.emit("refresh-window", *args),
)
details_sizer.add(self.playlist_detail_panel) details_sizer.add(self.playlist_detail_panel)
self.add(details_sizer) self.add(details_sizer)
@@ -382,16 +361,6 @@ class PlaylistList(Gtk.Box):
class PlaylistDetailPanel(Gtk.Overlay): class PlaylistDetailPanel(Gtk.Overlay):
__gsignals__ = { __gsignals__ = {
"back-clicked": (GObject.SignalFlags.RUN_FIRST, GObject.TYPE_NONE, ()), "back-clicked": (GObject.SignalFlags.RUN_FIRST, GObject.TYPE_NONE, ()),
"song-clicked": (
GObject.SignalFlags.RUN_FIRST,
GObject.TYPE_NONE,
(int, object, object),
),
"refresh-window": (
GObject.SignalFlags.RUN_FIRST,
GObject.TYPE_NONE,
(object, bool),
),
} }
show_mobile = GObject.Property(type=bool, default=False) show_mobile = GObject.Property(type=bool, default=False)
@@ -769,39 +738,26 @@ class PlaylistDetailPanel(Gtk.Overlay):
on_song_download_complete=download_state_change, on_song_download_complete=download_state_change,
) )
def play_song(self, index: int, metadata: Dict[str, Any]):
metadata["active_playlist_id"] = GLib.Variant('s', self.playlist_id)
run_action(self, 'app.play-song', index, [m[-1] for m in self.playlist_song_store], metadata)
def on_play_all_clicked(self, _): def on_play_all_clicked(self, _):
self.emit( self.play_song(0, {"force_shuffle_state": GLib.Variant('b', False)})
"song-clicked",
0,
[m[-1] for m in self.playlist_song_store],
{"force_shuffle_state": False, "active_playlist_id": self.playlist_id},
)
def on_shuffle_all_button(self, _): def on_shuffle_all_button(self, _):
self.emit( self.play_song(
"song-clicked",
randint(0, len(self.playlist_song_store) - 1), randint(0, len(self.playlist_song_store) - 1),
[m[-1] for m in self.playlist_song_store], {"force_shuffle_state": GLib.Variant('b', True)})
{"force_shuffle_state": True, "active_playlist_id": self.playlist_id},
)
def on_expand_collapse_click(self, _): def on_expand_collapse_click(self, _):
self.emit( run_action(self, 'playlists.set-details-expanded', not self.playlist_details_expanded)
"refresh-window",
{"playlist_details_expanded": not self.playlist_details_expanded},
False,
)
def on_song_activated(self, _, idx: Gtk.TreePath, col: Any): def on_song_activated(self, _, idx: Gtk.TreePath, col: Any):
if not self.playlist_song_store[idx[0]][0]: if not self.playlist_song_store[idx[0]][0]:
return return
# The song ID is in the last column of the model. # The song ID is in the last column of the model.
self.emit( self.play_song(idx.get_indices()[0], {})
"song-clicked",
idx.get_indices()[0],
[m[-1] for m in self.playlist_song_store],
{"active_playlist_id": self.playlist_id},
)
def on_song_button_press(self, tree: Gtk.TreeView, event: Gdk.EventButton) -> bool: def on_song_button_press(self, tree: Gtk.TreeView, event: Gdk.EventButton) -> bool:
if event.button == 3: # Right click if event.button == 3: # Right click
@@ -873,7 +829,7 @@ class PlaylistDetailPanel(Gtk.Overlay):
on_remove_songs_click, on_remove_songs_click,
) )
], ],
on_playlist_state_change=lambda: self.emit("refresh-window", {}, True), on_playlist_state_change=lambda: run_action(self, 'app.refresh'),
) )
# If the click was on a selected row, don't deselect anything. # If the click was on a selected row, don't deselect anything.