Commit 41d63a4d authored by Camilo Higuita's avatar Camilo Higuita

playlists work and palylist-sync feature, pulled event on babelist

parent 89bb91ca
......@@ -15,10 +15,10 @@ var GET = {
mostPlayedTracks : "select t.*, al.artwork from tracks t inner join albums al on t.album = al.album and t.artist = al.artist WHERE al.played > 0 ORDER BY played desc LIMIT 100",
favoriteTracks : "select t.*, al.artwork from tracks t inner join albums al on t.album = al.album and t.artist = al.artist where stars > 0 order by stars desc limit 100",
recentTracks: "select t.* , al.artwork from tracks t inner join albums al on t.album = al.album and t.artist = al.artist order by strftime(\"%s\", addDate) desc LIMIT 100",
recentTracks: "select t.* , al.artwork from tracks t inner join albums al on t.album = al.album and t.artist = al.artist order by strftime(\"%s\", t.addDate) desc LIMIT 100",
babedTracks: "select t.* , al.artwork from tracks t inner join albums al on t.album = al.album and t.artist = al.artist where t.babe = 1",
playlistTracks_ : "select t.* , al.artwork from tracks t inner join albums al on t.album = al.album and t.artist = al.artist inner join tracks_playlists pl on pl.url = t.url where pl.playlist = \"%1\" order by strftime(\"%s\", pl.addDate) desc",
playlists: "select * from playlists order by strftime(\"%s\", addDate) desc",
colorTracks_: "select t.*, al.artwork from tracks t inner join albums al on al.album = t.album and al.artist = t.artist where t.art = \"%1\""
......
......@@ -483,7 +483,7 @@ bool CollectionDB::addPlaylist(const QString &title)
if(!title.isEmpty())
{
QVariantMap playlist {{KEYMAP[KEY::PLAYLIST],title},
{KEYMAP[KEY::ADD_DATE],QDate::currentDate()}};
{KEYMAP[KEY::ADD_DATE],QDateTime::currentDateTime()}};
if(insert(TABLEMAP[TABLE::PLAYLISTS],playlist))
return true;
......@@ -496,7 +496,7 @@ bool CollectionDB::trackPlaylist(const QString &url, const QString &playlist)
{
QVariantMap map {{KEYMAP[KEY::PLAYLIST],playlist},
{KEYMAP[KEY::URL],url},
{KEYMAP[KEY::ADD_DATE],QDate::currentDate()}};
{KEYMAP[KEY::ADD_DATE],QDateTime::currentDateTime()}};
if(insert(TABLEMAP[TABLE::TRACKS_PLAYLISTS],map))
return true;
......@@ -507,7 +507,7 @@ bool CollectionDB::trackPlaylist(const QString &url, const QString &playlist)
bool CollectionDB::addFolder(const QString &url)
{
QVariantMap map {{KEYMAP[KEY::URL],url},
{KEYMAP[KEY::ADD_DATE],QDate::currentDate()}};
{KEYMAP[KEY::ADD_DATE],QDateTime::currentDateTime()}};
if(insert(TABLEMAP[TABLE::FOLDERS],map))
return true;
......
......@@ -84,19 +84,25 @@ Kirigami.ApplicationWindow
property alias mainPlaylist : mainPlaylist
/*USEFUL PROPS*/
property string syncPlaylist : ""
property bool sync : false
pageStack.defaultColumnWidth: columnWidth
pageStack.initialPage: [mainPlaylist, views]
pageStack.interactive: isMobile
pageStack.separatorVisible: pageStack.wideMode
// overlay.modal: Rectangle
// {
// color: "transparent"
// }
// overlay.modeless: Rectangle
// {
// color: "transparent"
// }
overlay.modal: Rectangle
{
color: isMobile ? "#8f28282a" : "transparent"
}
overlay.modeless: Rectangle
{
color: "transparent"
}
onWidthChanged: if(root.isMobile)
{
......@@ -464,6 +470,14 @@ Kirigami.ApplicationWindow
onQuickPlayTrack: Player.quickPlay(track)
onPlayAll: Player.playAll(tracks)
onAppendAll: Player.appendAll(tracks)
onPlaySync:
{
var tracks = bae.get(Q.GET.playlistTracks_.arg(playlist))
Player.playAll(tracks)
root.sync = true
root.syncPlaylist = playlist
console.log("ALLOW PLAYLIOST SYNC FOR: " ,root.syncPlaylist = playlist)
}
}
}
......
......@@ -1718,6 +1718,7 @@ var Babe = {
/*headers*/
"dialog-close" : Icon.close,
"window-close" : Icon.close,
"player-time" : Icon.playBoxOutline,
......@@ -1729,5 +1730,8 @@ var Babe = {
"gohome" : Icon.home,
"sd" : Icon.sd,
"disks": Icon.disk
"disks": Icon.disk,
"playlist-generator": Icon.refresh,
"amarok_playlist_refresh" : Icon.refresh,
"checkbox" : Icon.check
}
......@@ -133,8 +133,16 @@ function appendTracksAt(tracks, at)
function appendTrack(track)
{
if(track)
{
root.mainPlaylist.list.model.append(track)
if(root.sync === true)
{
console.log("SYNC TRACK")
addToPlaylist([track.url], root.syncPlaylist)
}
}
// if(track)
// {
// var empty = root.mainPlaylist.list.count
......@@ -206,6 +214,9 @@ function playAll(tracks)
{
if(tracks)
{
root.sync = false
root.syncPlaylist = ""
root.mainPlaylist.list.clearTable()
root.pageStack.currentIndex = 0
......@@ -238,3 +249,15 @@ function babeTrack()
}
}
function addToPlaylist(urls, playlist)
{
if(urls.length > 0)
{
for(var i in urls)
bae.trackPlaylist(urls[i], playlist)
if(!isMobile)
bae.notify(playlist, urls.length + " tracks added to the playlist:\n"+urls.join("\n"))
}
}
......@@ -12,10 +12,10 @@ ToolButton
property color iconColor: foregroundColor
readonly property string defaultColor : foregroundColor
// icon.name: isMobile ? "" : babeButton.iconName
// icon.width: isMobile ? 0 : babeButton.iconSize
//// icon.height: isMobile ? 0 : babeButton.iconSize
// icon.color: isMobile ? "transparent" : (iconColor || defaultColor)
// icon.name: isMobile ? "" : babeButton.iconName
// icon.width: isMobile ? 0 : babeButton.iconSize
// // icon.height: isMobile ? 0 : babeButton.iconSize
// icon.color: isMobile ? "transparent" : (iconColor || defaultColor)
Kirigami.Icon
{
......@@ -25,8 +25,6 @@ ToolButton
height: iconSize
visible: !isMobile
source: isMobile ? "" : iconName
isMask: true
smooth: true
color: iconColor || defaultColor
}
......
......@@ -4,7 +4,9 @@ import QtQuick.Controls.Material 2.1
Dialog
{
width: parent.width / 2
width: columnWidth * 0.9
height: isMobile ? parent.height*0.8 : parent.height*0.5
x: (parent.width - width) / 2
y: (parent.height - height) / 2
parent: ApplicationWindow.overlay
......
......@@ -7,6 +7,7 @@ ListView
id: babeList
property alias holder : holder
signal pulled()
clip: true
highlight: Rectangle
......@@ -58,4 +59,11 @@ ListView
ScrollBar.vertical:BabeScrollBar { }
onContentYChanged:
{
if(contentY < -120)
pulled()
}
}
......@@ -95,7 +95,7 @@ BabeList
{
id: menuBtn
iconName: /*"application-menu"*/ "overflow-menu"
onClicked: headerMenu.open()
onClicked: headerMenu.popup()
}
}
}
......
......@@ -8,7 +8,6 @@ import ".."
BabeMenu
{
signal saveListClicked();
BabeMenuItem
{
......
import QtQuick 2.0
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import org.kde.kirigami 2.2 as Kirigami
import QtQuick.Layouts 1.3
import "../../view_models/BabeDialog"
import "../../view_models"
import "../../utils/Player.js" as Player
import "../../db/Queries.js" as Q
BabeDialog
{
title: "Add "+ tracks.length +" tracks to..."
standardButtons: Dialog.Save | Dialog.Cancel
width: isMobile ? parent.width*0.7 : parent.width*0.4
height: parent.height*0.5
property var tracks : []
Column
ColumnLayout
{
spacing: 20
anchors.fill: parent
BabeList
{
id: playlistsList
width: parent.width
height: parent.height
Layout.fillHeight: true
Layout.fillWidth: true
holder.message: "<h2>There's not playlists</h2><br><p>Create a new one and start adding tracks to it<p/>"
ListModel { id: listModel }
......@@ -38,30 +39,72 @@ BabeDialog
Connections
{
target: delegate
onClicked:
onClicked: playlistsList.currentIndex = index
onPressAndHold:
{
playlistsList.currentIndex = index
Player.addToPlaylist(tracks, playlistsList.model.get(playlistsList.currentIndex).playlist)
close()
}
}
}
}
RowLayout
{
Layout.fillWidth: true
Layout.margins: contentMargins
Component.onCompleted:
TextField
{
var playlists = bae.get("select * from playlists order by addDate desc")
if(playlists.length > 0)
for(var i in playlists)
playlistsList.model.append(playlists[i])
Layout.fillWidth: true
id: newPlaylistField
color: foregroundColor
placeholderText: qsTr("New playlist")
onAccepted:
{
addPlaylist()
clear()
close()
}
}
BabeButton
{
iconName: "checkbox"
iconColor: textColor
onClicked: addPlaylist()
}
}
}
onAccepted: addToPlaylist(tracks)
onOpened:
{
newPlaylistField.clear()
playlistsList.clearTable()
var playlists = bae.get(Q.GET.playlists)
if(playlists.length > 0)
for(var i in playlists)
playlistsList.model.append(playlists[i])
}
onAccepted: Player.addToPlaylist(tracks, playlistsList.model.get(playlistsList.currentIndex).playlist)
function addToPlaylist(tracks)
function addPlaylist()
{
if(tracks.length > 0)
for(var i in tracks)
bae.trackPlaylist(tracks[i], playlistsList.model.get(playlistsList.currentIndex).playlist)
if (newPlaylistField.text)
{
var title = newPlaylistField.text.trim()
if(bae.addPlaylist(title))
{
playlistsList.model.append({playlist: title})
playlistsView.playlistViewModel.model.append({playlist: title})
playlistsList.positionViewAtEnd()
}
Player.addToPlaylist(tracks, title)
}
}
}
......@@ -54,16 +54,8 @@ BabePopup
{
Layout.alignment: Qt.AlignRight
onClicked: {accepted(dirList.currentUrl); close()}
contentItem: Text
{
color: foregroundColor
text: "Accept"
}
background: Rectangle
{
color: babeColor
radius: 2
}
text: "Accept"
}
}
......
......@@ -17,6 +17,9 @@ Item
{
id: mainPlaylistRoot
readonly property real opacityLevel : 0.7
property var currentTrack
property int currentTrackIndex : 0
property int prevTrackIndex : 0
......@@ -144,14 +147,14 @@ Item
Layout.column: 1
Layout.fillWidth: true
Layout.preferredHeight: visible ? 48 : 0
// anchors.top: cover.bottom
// anchors.top: cover.bottom
visible: list.count > 0
Rectangle
{
anchors.fill: parent
color: midLightColor
opacity: 0.8
opacity: opacityLevel
z: -999
}
......@@ -192,8 +195,8 @@ Item
{
anchors.fill: parent
anchors.centerIn: parent
// spacing: 0
// Layout.margins: 0
// spacing: 0
// Layout.margins: 0
Item
{
......@@ -296,7 +299,7 @@ Item
{
anchors.fill: parent
color: midLightColor
opacity: 0.8
opacity: opacityLevel
z: -999
}
......
......@@ -40,4 +40,11 @@ BabeMenu
onTriggered: saveToClicked()
}
BabeMenuItem
{
enabled: syncPlaylist.length > 0
text: syncPlaylist.length > 0 && sync ? qsTr("Pause syncing") : qsTr("Continue syncing")
onTriggered: sync = !sync
}
}
......@@ -139,21 +139,7 @@ Item
id: loginBtn
background: Rectangle
{
color: babeColor
radius: 3
}
contentItem: Text
{
text: "Login"
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter
color: highlightTextColor
font.bold: true
font.pointSize: 11
}
text: "Login"
}
......
import QtQuick 2.0
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import "../../view_models/BabeDialog"
BabeDialog
......@@ -7,17 +8,16 @@ BabeDialog
id: newPlaylistDialogRoot
title: "New Playlist"
standardButtons: Dialog.Save | Dialog.Cancel
width: isMobile ? parent.width*0.7 : parent.width*0.4
Column
height: parent.height * 0.3
ColumnLayout
{
spacing: 20
anchors.fill: parent
anchors.centerIn: parent
width: parent.width
TextField
{
Layout.fillWidth: true
Layout.margins: contentMargins
id: newPlaylistField
width: parent.width
color: foregroundColor
......@@ -36,5 +36,6 @@ BabeDialog
var title = newPlaylistField.text.trim()
if(bae.addPlaylist(title))
model.append({playlist: title})
positionViewAtEnd()
}
}
......@@ -13,7 +13,7 @@ ItemDelegate
clip: true
property string textColor: ListView.isCurrentItem ? highlightTextColor : foregroundColor
signal playSync(int index)
Rectangle
{
......@@ -22,17 +22,15 @@ ItemDelegate
opacity: 0.3
}
MouseArea
{
anchors.fill: parent
acceptedButtons: Qt.RightButton
// onClicked:
// {
// if(!root.isMobile && mouse.button === Qt.RightButton)
// rightClicked()
// }
// onClicked:
// {
// if(!root.isMobile && mouse.button === Qt.RightButton)
// rightClicked()
// }
}
RowLayout
......@@ -54,7 +52,6 @@ ItemDelegate
}
}
Item
{
Layout.fillHeight: true
......@@ -76,6 +73,22 @@ ItemDelegate
}
}
Item
{
visible: !playlistIcon
Layout.fillHeight: true
width: parent.height
BabeButton
{
id: syncBtn
anchors.centerIn: parent
iconName: "amarok_playlist_refresh" //"playlist-generator"
iconColor: textColor
onClicked: playSync(index)
}
}
}
......
......@@ -18,16 +18,19 @@ Kirigami.PageRow
id: playlistViewRoot
property string playlistQuery
property alias playlistViewModel : playlistViewModel
signal rowClicked(var track)
signal quickPlayTrack(var track)
signal playAll(var tracks)
signal playSync(var playlist)
signal appendAll(var tracks)
clip: true
separatorVisible: wideMode
initialPage:[playlistList, playlistViewDrawer]
defaultColumnWidth: Kirigami.Units.gridUnit * 15
interactive: false
interactive: false
Page
{
......@@ -45,6 +48,12 @@ Kirigami.PageRow
Layout.fillHeight: true
Layout.fillWidth: true
onPlaySync:
{
if(!playlistViewModel.model.get(index).playlistIcon)
playlistViewRoot.playSync(playlistViewModel.model.get(index).playlist)
}
}
ColorTagsBar
......@@ -75,16 +84,6 @@ Kirigami.PageRow
{
id: playlistViewDrawer
anchors.fill: parent
// y: root.header.height
// height: parent.height - root.header.height - root.footer.height
// width: root.isMobile ? parent.width : parent.width* 0.7
// edge: Qt.RightEdge
// interactive: true
// focus: true
// modal: isMobile
// modal: !root.wideScreen
// onModalChanged: drawerOpen = !modal
background: Rectangle
{
......@@ -106,9 +105,11 @@ Kirigami.PageRow
onHeaderClosed: if(!playlistViewRoot.wideMode)
playlistViewRoot.currentIndex = 0
holder.message: "<h2>"+playlistViewModel.model.get(playlistViewModel.currentIndex).playlist+"</h2><p>Your playlist is empty, start adding new music to it</p>"
holder.message: "<h2>"+playlistViewModel.model.get(playlistViewModel.currentIndex).playlist+"</h2><p>Your playlist is empty,<br>start adding new music to it</p>"
holder.emoji: "qrc:/assets/face-hug.png"
Connections
{
target: filterList
......@@ -119,13 +120,12 @@ Kirigami.PageRow
}
onPlayAll: playAll(bae.get(playlistQuery))
onAppendAll: appendAll(bae.get(playlistQuery))
onPulled: populate(playlistQuery)
}
}
}
function populate(query)
{
playlistQuery = query
......@@ -139,11 +139,22 @@ Kirigami.PageRow
}
Component.onCompleted:
function refresh()
{
var playlists = bae.get("select * from playlists order by addDate desc")
var i = 9
for(i; i < playlistViewModel.count; i++)
playlistViewModel.remove(i)
setPlaylists()
}
function setPlaylists()
{
var playlists = bae.get(Q.GET.playlists)
if(playlists.length > 0)
for(var i in playlists)
playlistViewModel.model.append(playlists[i])
}
Component.onCompleted: setPlaylists()
}
......@@ -16,6 +16,7 @@ BabeList
}
headerPositioning: ListView.OverlayHeader
signal playSync(int index)
Rectangle
{
......@@ -118,6 +119,9 @@ BabeList
playlistViewRoot.currentIndex = 1
}
onPlaySync: playlistListRoot.playSync(index)
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment