Playlist editing
This commit is contained in:
@@ -5,93 +5,35 @@ from gi.repository import Gtk, GObject
|
|||||||
|
|
||||||
from libremsonic.server import Server
|
from libremsonic.server import Server
|
||||||
from libremsonic.config import ServerConfiguration
|
from libremsonic.config import ServerConfiguration
|
||||||
|
from libremsonic.ui import util
|
||||||
|
|
||||||
|
|
||||||
class EditServerDialog(Gtk.Dialog):
|
class EditServerDialog(util.EditFormDialog):
|
||||||
"""
|
entity_name: str = 'Server'
|
||||||
The Add New/Edit Server Dialog. The dialogs are the same, but when editing,
|
initial_size = (450, 250)
|
||||||
an ``existing_config`` will be specified.
|
|
||||||
"""
|
|
||||||
def __init__(self, parent, existing_config=None):
|
|
||||||
editing = existing_config is not None
|
|
||||||
Gtk.Dialog.__init__(
|
|
||||||
self,
|
|
||||||
f'Edit {existing_config.name}' if editing else 'Add New Server',
|
|
||||||
parent, 0, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
|
|
||||||
Gtk.STOCK_EDIT if editing else Gtk.STOCK_ADD,
|
|
||||||
Gtk.ResponseType.OK))
|
|
||||||
|
|
||||||
if not existing_config:
|
|
||||||
existing_config = ServerConfiguration()
|
|
||||||
|
|
||||||
# Create the two columns for the labels and corresponding entry fields.
|
|
||||||
self.set_default_size(450, 250)
|
|
||||||
content_area = self.get_content_area()
|
|
||||||
flowbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
|
|
||||||
label_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
|
||||||
entry_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
|
||||||
flowbox.pack_start(label_box, False, True, 10)
|
|
||||||
flowbox.pack_start(entry_box, True, True, 10)
|
|
||||||
|
|
||||||
# Store a map of field label to GTK component.
|
|
||||||
self.data = {}
|
|
||||||
|
|
||||||
# Create all of the text entry fields for the server configuration.
|
|
||||||
text_fields = [
|
text_fields = [
|
||||||
('Name', existing_config.name, False),
|
('Name', 'name', False),
|
||||||
('Server address', existing_config.server_address, False),
|
('Server address', 'server_address', False),
|
||||||
('Local network address', existing_config.local_network_address,
|
('Local network address', 'local_network_address', False),
|
||||||
False),
|
('Local network SSID', 'local_network_ssid', False),
|
||||||
('Local network SSID', existing_config.local_network_ssid, False),
|
('Username', 'username', False),
|
||||||
('Username', existing_config.username, False),
|
('Password', 'password', True),
|
||||||
('Password', existing_config.password, True),
|
|
||||||
]
|
]
|
||||||
for label, value, is_password in text_fields:
|
|
||||||
# Put the label in the left box.
|
|
||||||
entry_label = Gtk.Label(label + ':')
|
|
||||||
entry_label.set_halign(Gtk.Align.START)
|
|
||||||
label_box.pack_start(entry_label, True, True, 0)
|
|
||||||
|
|
||||||
# Put the text entry in the right box.
|
|
||||||
entry = Gtk.Entry(text=value)
|
|
||||||
if is_password:
|
|
||||||
entry.set_visibility(False)
|
|
||||||
entry_box.pack_start(entry, True, True, 0)
|
|
||||||
self.data[label] = entry
|
|
||||||
|
|
||||||
# Create all of the check box fields for the server configuration.
|
|
||||||
boolean_fields = [
|
boolean_fields = [
|
||||||
('Browse by tags', existing_config.browse_by_tags),
|
('Browse by tags', 'browse_by_tags'),
|
||||||
('Sync enabled', existing_config.sync_enabled),
|
('Sync enabled', 'sync_enabled'),
|
||||||
]
|
]
|
||||||
for label, value in boolean_fields:
|
|
||||||
# Put the label in the left box.
|
|
||||||
entry_label = Gtk.Label(label + ':')
|
|
||||||
entry_label.set_halign(Gtk.Align.START)
|
|
||||||
label_box.pack_start(entry_label, True, True, 0)
|
|
||||||
|
|
||||||
# Put the checkbox in the right box. Note we have to pad here since
|
|
||||||
# the checkboxes are smaller than the text fields.
|
|
||||||
checkbox = Gtk.CheckButton(active=value)
|
|
||||||
entry_box.pack_start(checkbox, True, True, 5)
|
|
||||||
self.data[label] = checkbox
|
|
||||||
|
|
||||||
content_area.pack_start(flowbox, True, True, 10)
|
|
||||||
|
|
||||||
# Create a box for buttons.
|
|
||||||
button_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
|
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
test_server = Gtk.Button('Test Connection to Server')
|
test_server = Gtk.Button('Test Connection to Server')
|
||||||
test_server.connect('clicked', self.on_test_server_clicked)
|
test_server.connect('clicked', self.on_test_server_clicked)
|
||||||
button_box.pack_start(test_server, False, True, 5)
|
|
||||||
|
|
||||||
open_in_browser = Gtk.Button('Open in Browser')
|
open_in_browser = Gtk.Button('Open in Browser')
|
||||||
open_in_browser.connect('clicked', self.on_open_in_browser_clicked)
|
open_in_browser.connect('clicked', self.on_open_in_browser_clicked)
|
||||||
button_box.pack_start(open_in_browser, False, True, 5)
|
|
||||||
|
|
||||||
content_area.pack_start(button_box, True, True, 10)
|
self.extra_buttons = [test_server, open_in_browser]
|
||||||
|
|
||||||
self.show_all()
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
def on_test_server_clicked(self, event):
|
def on_test_server_clicked(self, event):
|
||||||
# Instantiate the server.
|
# Instantiate the server.
|
||||||
|
@@ -11,6 +11,13 @@ from libremsonic.cache_manager import CacheManager, SongCacheStatus
|
|||||||
from libremsonic.ui import util
|
from libremsonic.ui import util
|
||||||
|
|
||||||
|
|
||||||
|
class EditPlaylistDialog(util.EditFormDialog):
|
||||||
|
entity_name: str = 'Playlist'
|
||||||
|
initial_size = (350, 120)
|
||||||
|
text_fields = [('Name', 'name', False), ('Comment', 'comment', False)]
|
||||||
|
boolean_fields = [('Public', 'public')]
|
||||||
|
|
||||||
|
|
||||||
class PlaylistsPanel(Gtk.Paned):
|
class PlaylistsPanel(Gtk.Paned):
|
||||||
"""Defines the playlists panel."""
|
"""Defines the playlists panel."""
|
||||||
__gsignals__ = {
|
__gsignals__ = {
|
||||||
@@ -126,14 +133,20 @@ class PlaylistsPanel(Gtk.Paned):
|
|||||||
# Action buttons, name, comment, number of songs, etc.
|
# Action buttons, name, comment, number of songs, etc.
|
||||||
playlist_details_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
playlist_details_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
||||||
|
|
||||||
# Action buttons
|
# Action buttons (note we are packing end here, so we have to put them
|
||||||
|
# in right-to-left).
|
||||||
# TODO hide this if there is no selected playlist
|
# TODO hide this if there is no selected playlist
|
||||||
action_button_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
|
action_button_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
|
||||||
|
|
||||||
view_refresh_button = util.button_with_icon('view-refresh')
|
view_refresh_button = util.button_with_icon('view-refresh-symbolic')
|
||||||
view_refresh_button.connect('clicked', self.on_view_refresh_click)
|
view_refresh_button.connect('clicked', self.on_view_refresh_click)
|
||||||
action_button_box.pack_end(view_refresh_button, False, False, 5)
|
action_button_box.pack_end(view_refresh_button, False, False, 5)
|
||||||
|
|
||||||
|
playlist_edit_button = util.button_with_icon('document-edit-symbolic')
|
||||||
|
playlist_edit_button.connect('clicked',
|
||||||
|
self.on_playlist_edit_button_click)
|
||||||
|
action_button_box.pack_end(playlist_edit_button, False, False, 5)
|
||||||
|
|
||||||
playlist_details_box.pack_start(action_button_box, False, False, 5)
|
playlist_details_box.pack_start(action_button_box, False, False, 5)
|
||||||
|
|
||||||
playlist_details_box.pack_start(Gtk.Box(), True, False, 0)
|
playlist_details_box.pack_start(Gtk.Box(), True, False, 0)
|
||||||
@@ -237,6 +250,24 @@ class PlaylistsPanel(Gtk.Paned):
|
|||||||
def on_list_refresh_click(self, button):
|
def on_list_refresh_click(self, button):
|
||||||
self.update_playlist_list(force=True)
|
self.update_playlist_list(force=True)
|
||||||
|
|
||||||
|
def on_playlist_edit_button_click(self, button):
|
||||||
|
selected = self.playlist_list.get_selected_row()
|
||||||
|
playlist_id = self.playlist_map[selected.get_index()].id
|
||||||
|
dialog = EditPlaylistDialog(
|
||||||
|
self.get_toplevel(),
|
||||||
|
CacheManager.get_playlist(playlist_id,
|
||||||
|
before_download=lambda: None).result())
|
||||||
|
result = dialog.run()
|
||||||
|
if result == Gtk.ResponseType.OK:
|
||||||
|
CacheManager.update_playlist(
|
||||||
|
playlist_id,
|
||||||
|
name=dialog.data['Name'].get_text(),
|
||||||
|
comment=dialog.data['Comment'].get_text(),
|
||||||
|
public=dialog.data['Public'].get_active(),
|
||||||
|
)
|
||||||
|
self.update_playlist_view(playlist_id, force=True)
|
||||||
|
dialog.destroy()
|
||||||
|
|
||||||
def on_view_refresh_click(self, button):
|
def on_view_refresh_click(self, button):
|
||||||
playlist_id = self.playlist_map[
|
playlist_id = self.playlist_map[
|
||||||
self.playlist_list.get_selected_row().get_index()]
|
self.playlist_list.get_selected_row().get_index()]
|
||||||
@@ -385,12 +416,18 @@ class PlaylistsPanel(Gtk.Paned):
|
|||||||
|
|
||||||
def format_stats(self, playlist):
|
def format_stats(self, playlist):
|
||||||
created_date = playlist.created.strftime('%B %d, %Y')
|
created_date = playlist.created.strftime('%B %d, %Y')
|
||||||
return ' • '.join([
|
lines = [
|
||||||
|
' • '.join([
|
||||||
f'Created by {playlist.owner} on {created_date}',
|
f'Created by {playlist.owner} on {created_date}',
|
||||||
|
f"{'Not v' if not playlist.public else 'V'}isible with others",
|
||||||
|
]),
|
||||||
|
' • '.join([
|
||||||
'{} {}'.format(playlist.songCount,
|
'{} {}'.format(playlist.songCount,
|
||||||
util.pluralize("song", playlist.songCount)),
|
util.pluralize("song", playlist.songCount)),
|
||||||
self.format_playlist_duration(playlist.duration)
|
self.format_playlist_duration(playlist.duration)
|
||||||
])
|
]),
|
||||||
|
]
|
||||||
|
return '\n'.join(lines)
|
||||||
|
|
||||||
def format_playlist_duration(self, duration_secs) -> str:
|
def format_playlist_duration(self, duration_secs) -> str:
|
||||||
duration_mins = (duration_secs // 60) % 60
|
duration_mins = (duration_secs // 60) % 60
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
import functools
|
import functools
|
||||||
|
from typing import List, Tuple
|
||||||
|
|
||||||
from concurrent.futures import Future
|
from concurrent.futures import Future
|
||||||
|
|
||||||
@@ -37,6 +38,93 @@ def esc(string):
|
|||||||
return string.replace('&', '&')
|
return string.replace('&', '&')
|
||||||
|
|
||||||
|
|
||||||
|
class EditFormDialog(Gtk.Dialog):
|
||||||
|
entity_name: str
|
||||||
|
initial_size: Tuple[int, int]
|
||||||
|
text_fields: List[Tuple[str, str, bool]] = []
|
||||||
|
boolean_fields: List[Tuple[str, str]] = []
|
||||||
|
extra_buttons: List[Gtk.Button] = []
|
||||||
|
|
||||||
|
def get_object_name(self, obj):
|
||||||
|
"""
|
||||||
|
Gets the friendly object name. Can be overridden.
|
||||||
|
"""
|
||||||
|
return obj.name if obj else ''
|
||||||
|
|
||||||
|
def get_default_object(self):
|
||||||
|
return None
|
||||||
|
|
||||||
|
def __init__(self, parent, existing_object=None):
|
||||||
|
editing = existing_object is not None
|
||||||
|
Gtk.Dialog.__init__(
|
||||||
|
self,
|
||||||
|
f'Edit {self.get_object_name(existing_object)}'
|
||||||
|
if editing else f'Create New {self.entity_name}',
|
||||||
|
parent,
|
||||||
|
0,
|
||||||
|
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
|
||||||
|
Gtk.STOCK_EDIT if editing else Gtk.STOCK_ADD,
|
||||||
|
Gtk.ResponseType.OK),
|
||||||
|
)
|
||||||
|
|
||||||
|
if not existing_object:
|
||||||
|
existing_object = self.get_default_object()
|
||||||
|
|
||||||
|
self.set_default_size(*self.initial_size)
|
||||||
|
|
||||||
|
if len(self.text_fields) + len(self.boolean_fields) > 0:
|
||||||
|
# Create two columns for the labels and corresponding entry fields.
|
||||||
|
content_area = self.get_content_area()
|
||||||
|
flowbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
|
||||||
|
label_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
||||||
|
entry_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
||||||
|
flowbox.pack_start(label_box, False, True, 10)
|
||||||
|
flowbox.pack_start(entry_box, True, True, 10)
|
||||||
|
|
||||||
|
# Store a map of field label to GTK component.
|
||||||
|
self.data = {}
|
||||||
|
|
||||||
|
# Create all of the text entry fields.
|
||||||
|
for label, value_field_name, is_password in self.text_fields:
|
||||||
|
# Put the label in the left box.
|
||||||
|
entry_label = Gtk.Label(label + ':')
|
||||||
|
entry_label.set_halign(Gtk.Align.START)
|
||||||
|
label_box.pack_start(entry_label, True, True, 0)
|
||||||
|
|
||||||
|
# Put the text entry in the right box.
|
||||||
|
entry = Gtk.Entry(
|
||||||
|
text=getattr(existing_object, value_field_name, ''))
|
||||||
|
if is_password:
|
||||||
|
entry.set_visibility(False)
|
||||||
|
entry_box.pack_start(entry, True, True, 0)
|
||||||
|
self.data[label] = entry
|
||||||
|
|
||||||
|
# Create all of the check box fields.
|
||||||
|
for label, value_field_name in self.boolean_fields:
|
||||||
|
# Put the label in the left box.
|
||||||
|
entry_label = Gtk.Label(label + ':')
|
||||||
|
entry_label.set_halign(Gtk.Align.START)
|
||||||
|
label_box.pack_start(entry_label, True, True, 0)
|
||||||
|
|
||||||
|
# Put the checkbox in the right box. Note we have to pad here
|
||||||
|
# since the checkboxes are smaller than the text fields.
|
||||||
|
checkbox = Gtk.CheckButton(
|
||||||
|
active=getattr(existing_object, value_field_name, False))
|
||||||
|
entry_box.pack_start(checkbox, True, True, 5)
|
||||||
|
self.data[label] = checkbox
|
||||||
|
|
||||||
|
content_area.pack_start(flowbox, True, True, 10)
|
||||||
|
|
||||||
|
# Create a box for buttons.
|
||||||
|
if len(self.extra_buttons) > 0:
|
||||||
|
button_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
|
||||||
|
for button in self.extra_buttons:
|
||||||
|
button_box.pack_start(button, False, True, 5)
|
||||||
|
content_area.pack_start(button_box, True, True, 10)
|
||||||
|
|
||||||
|
self.show_all()
|
||||||
|
|
||||||
|
|
||||||
def async_callback(future_fn, before_download=None, on_failure=None):
|
def async_callback(future_fn, before_download=None, on_failure=None):
|
||||||
"""
|
"""
|
||||||
Defines the ``async_callback`` decorator.
|
Defines the ``async_callback`` decorator.
|
||||||
|
Reference in New Issue
Block a user