WIP
This commit is contained in:
@@ -458,7 +458,7 @@ class AdapterManager:
|
||||
f"expected size ({expected_size})."
|
||||
)
|
||||
|
||||
block_size = 1024 # 1 KiB
|
||||
block_size = 512 * 1024 # 512 KiB
|
||||
total_consumed = 0
|
||||
|
||||
with open(download_tmp_filename, "wb+") as f:
|
||||
@@ -473,21 +473,18 @@ class AdapterManager:
|
||||
)
|
||||
raise Exception("Download Cancelled")
|
||||
|
||||
if i % 100 == 0:
|
||||
# Only delay (if configured) and update the progress UI
|
||||
# every 100 KiB.
|
||||
if DOWNLOAD_BLOCK_DELAY is not None:
|
||||
sleep(DOWNLOAD_BLOCK_DELAY)
|
||||
if DOWNLOAD_BLOCK_DELAY is not None:
|
||||
sleep(DOWNLOAD_BLOCK_DELAY)
|
||||
|
||||
if expected_size_exists:
|
||||
AdapterManager._instance.song_download_progress(
|
||||
id,
|
||||
DownloadProgress(
|
||||
DownloadProgress.Type.PROGRESS,
|
||||
total_bytes=total_size,
|
||||
current_bytes=total_consumed,
|
||||
),
|
||||
)
|
||||
if expected_size_exists:
|
||||
AdapterManager._instance.song_download_progress(
|
||||
id,
|
||||
DownloadProgress(
|
||||
DownloadProgress.Type.PROGRESS,
|
||||
total_bytes=total_size,
|
||||
current_bytes=total_consumed,
|
||||
),
|
||||
)
|
||||
|
||||
# Everything succeeded.
|
||||
if expected_size_exists:
|
||||
|
@@ -6,7 +6,7 @@ import sys
|
||||
from datetime import timedelta
|
||||
from functools import partial
|
||||
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
|
||||
|
||||
import bleach
|
||||
@@ -173,6 +173,10 @@ class SublimeMusicApp(Gtk.Application):
|
||||
register_action(albums, self.albums_select_album, 'select-album')
|
||||
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()
|
||||
register_dataclass_actions(settings, self.app_config, after=self._save_and_refresh)
|
||||
self.window.insert_action_group('settings', settings)
|
||||
@@ -826,7 +830,7 @@ class SublimeMusicApp(Gtk.Application):
|
||||
self.app_config.state.current_tab = tab_id
|
||||
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:
|
||||
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.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):
|
||||
self.app_config.player_config[player][option] = value
|
||||
|
||||
|
@@ -485,12 +485,12 @@ class ArtistDetailPanel(Gtk.Box):
|
||||
|
||||
def on_play_all_clicked(self, _):
|
||||
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, _):
|
||||
songs = self.get_artist_song_ids()
|
||||
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
|
||||
# =========================================================================
|
||||
|
@@ -1,5 +1,5 @@
|
||||
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
|
||||
|
||||
@@ -243,13 +243,13 @@ class AlbumWithSongs(Gtk.Box):
|
||||
)
|
||||
|
||||
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):
|
||||
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)
|
||||
|
||||
# Helper Methods
|
||||
|
@@ -131,19 +131,6 @@ class EditPlaylistWindow(Handy.Window):
|
||||
class PlaylistsPanel(Handy.Leaflet):
|
||||
"""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):
|
||||
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)
|
||||
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)
|
||||
self.add(details_sizer)
|
||||
|
||||
@@ -382,16 +361,6 @@ class PlaylistList(Gtk.Box):
|
||||
class PlaylistDetailPanel(Gtk.Overlay):
|
||||
__gsignals__ = {
|
||||
"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)
|
||||
@@ -769,39 +738,26 @@ class PlaylistDetailPanel(Gtk.Overlay):
|
||||
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, _):
|
||||
self.emit(
|
||||
"song-clicked",
|
||||
0,
|
||||
[m[-1] for m in self.playlist_song_store],
|
||||
{"force_shuffle_state": False, "active_playlist_id": self.playlist_id},
|
||||
)
|
||||
self.play_song(0, {"force_shuffle_state": GLib.Variant('b', False)})
|
||||
|
||||
def on_shuffle_all_button(self, _):
|
||||
self.emit(
|
||||
"song-clicked",
|
||||
self.play_song(
|
||||
randint(0, len(self.playlist_song_store) - 1),
|
||||
[m[-1] for m in self.playlist_song_store],
|
||||
{"force_shuffle_state": True, "active_playlist_id": self.playlist_id},
|
||||
)
|
||||
{"force_shuffle_state": GLib.Variant('b', True)})
|
||||
|
||||
def on_expand_collapse_click(self, _):
|
||||
self.emit(
|
||||
"refresh-window",
|
||||
{"playlist_details_expanded": not self.playlist_details_expanded},
|
||||
False,
|
||||
)
|
||||
run_action(self, 'playlists.set-details-expanded', not self.playlist_details_expanded)
|
||||
|
||||
def on_song_activated(self, _, idx: Gtk.TreePath, col: Any):
|
||||
if not self.playlist_song_store[idx[0]][0]:
|
||||
return
|
||||
# The song ID is in the last column of the model.
|
||||
self.emit(
|
||||
"song-clicked",
|
||||
idx.get_indices()[0],
|
||||
[m[-1] for m in self.playlist_song_store],
|
||||
{"active_playlist_id": self.playlist_id},
|
||||
)
|
||||
self.play_song(idx.get_indices()[0], {})
|
||||
|
||||
def on_song_button_press(self, tree: Gtk.TreeView, event: Gdk.EventButton) -> bool:
|
||||
if event.button == 3: # Right click
|
||||
@@ -873,7 +829,7 @@ class PlaylistDetailPanel(Gtk.Overlay):
|
||||
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.
|
||||
|
Reference in New Issue
Block a user