1
0
Fork 0
mirror of https://github.com/HenkKalkwater/harbour-sailfin.git synced 2024-11-14 05:25:17 +00:00
harbour-sailfin/qtquick/qml/main.qml
Chris Josten c72c10bad4
core: Split PlaybackManager up into smaller parts
The PlaybackManager was a giant class that handled UI bindings, fetching
stream URLS, playback logic.

It now has been split up into:

- ViewModel::PlaybackManager, which handles UI interfacing and allowing
  to swap out the Model::Playback implementation on the fly.
- Model::PlaybackManager, which is an interface for what a
  PlaybackManager must do, handling queues/playlists, and controlling a
  player.
- Model::LocalPlaybackManager, which is an Model::PlaybackManager
  implementation for playing back Jellyfin media within the application.
- Model::PlaybackReporter, which reports the current playback state to
  the Jellyfin server, for keeping track of played items.
- Model::Player, which handles playing back media from an URL and
  the usual play/pause et cetera.

In a future commit, this would allow for introducing a
Model::RemoteJellyfinPlaybackManager, to control other Jellyfin
instances.
2022-11-05 18:20:23 +01:00

132 lines
3.5 KiB
QML

import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Window 2.12
import QtMultimedia 5.12
import nl.netsoj.chris.Jellyfin 1.0 as J
import "components"
import ".."
import "."
ApplicationWindow {
id: appWindow
width: 600
height: 600
visible: true
property int _oldDepth: 0
property alias playbackManager: _playbackManager
J.PlaybackManager {
id: _playbackManager
apiClient: ApiClient
}
J.PlatformMediaControl {
playbackManager: appWindow.playbackManager
canQuit: true
onQuitRequested: appWindow.close()
desktopFile: "sailfin"
playerName: "Sailfin"
canRaise: true
onRaiseRequested: appWindow.raise()
}
background: Background {
id: background
anchors.fill: parent
}
StackView {
id: pageStack
anchors.fill: parent
onDepthChanged: {
if (depth >= _oldDepth) {
background.enter();
} else {
background.exit();
}
_oldDepth = depth
}
initialItem: Qt.resolvedUrl("pages/MainPage.qml")
Keys.onEscapePressed: pop()
}
NotificationList {
id: notifList
anchors {
right: parent.right
bottom: parent.bottom
}
width: Math.min(parent.width, 400)
height: parent.height
Connections {
target: ApiClient.eventbus
onDisplayMessage: {
console.log("Displaying message: ", header, ": ", message)
notifList.addNotification(header, message, timeout)
}
}
}
Connections {
target: ApiClient
onSetupRequired: { pageStack.replace(Qt.resolvedUrl("pages/setup/ServerSelectPage.qml")); }
}
Component.onCompleted: {
ApiClient.restoreSavedSession()
}
footer: Item {
id: footer
height: Math.max(details.height, playButtons.height)
Column {
id: details
anchors.verticalCenter: parent.verticalCenter
Text {
text: qsTr("Now playing")
color: "white"
}
Text {
text: "%1\n%2"
.arg(playbackManager.item.name ? playbackManager.item.name : "Nothing")
.arg(playbackManager.error === MediaPlayer.NoError ? playbackManager.streamUrl : playbackManager.errorString)
color: "white"
}
}
Row {
id: playButtons
anchors {
verticalCenter: parent.verticalCenter
right: parent.right
}
Button {
anchors.verticalCenter: parent.verticalCenter
text: "Previous"
onClicked: playbackManager.previous();
enabled: playbackManager.hasPrevious
}
Button {
readonly property bool _playing: playbackManager.playbackState === PlayerState.Playing
anchors.verticalCenter: parent.verticalCenter
text: _playing ? "Pause" : "Play"
onClicked: _playing ? playbackManager.pause() : playbackManager.play()
}
Button {
anchors.verticalCenter: parent.verticalCenter
text: "Next"
onClicked: playbackManager.next();
enabled: playbackManager.hasNext
}
}
}
Rectangle {
color: "darkblue"
anchors.fill: footer
}
}