PlaylistsView.qml 4.93 KB
Newer Older
1 2 3
import QtQuick 2.9
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.2
4
import org.kde.kirigami 2.2 as Kirigami
5 6

import "../../view_models/BabeTable"
7
import "../../view_models/BabeMenu"
8
import "../../view_models"
Camilo Higuita's avatar
Camilo Higuita committed
9
import "../../db/Queries.js" as Q
10 11


12 13 14 15 16 17 18
//    transform: Translate
//    {
//        x: (playlistViewDrawer.position * playlistViewRoot.width * 0.33)*-1
//    }

Kirigami.PageRow
{
19
    id: playlistViewRoot
Camilo Higuita's avatar
Camilo Higuita committed
20
    property string playlistQuery
21

22 23
    property alias playlistViewModel : playlistViewModel

24 25
    signal rowClicked(var track)
    signal quickPlayTrack(var track)
Camilo Higuita's avatar
Camilo Higuita committed
26
    signal playAll(var tracks)
27
    signal playSync(var playlist)
Camilo Higuita's avatar
Camilo Higuita committed
28
    signal appendAll(var tracks)
29

Camilo Higuita's avatar
Camilo Higuita committed
30
    clip: true
31 32 33
    separatorVisible: wideMode
    initialPage:[playlistList, playlistViewDrawer]
    defaultColumnWidth: Kirigami.Units.gridUnit * 15
34
    interactive: false
35

Camilo Higuita's avatar
Camilo Higuita committed
36
    Page
37 38
    {
        id: playlistList
39 40 41 42 43 44 45 46

        Rectangle
        {
            anchors.fill: parent
            color: altColor
            z: -999
        }

47 48 49 50 51 52 53 54 55 56 57 58 59
        ColumnLayout
        {
            anchors.fill: parent
            spacing: 0
            Layout.margins: 0

            PlaylistsViewModel
            {
                id: playlistViewModel

                Layout.fillHeight: true
                Layout.fillWidth: true

60
                onPlaySync: syncAndPlay(index)
61 62 63 64 65
            }

            ColorTagsBar
            {
                Layout.fillWidth: true
66 67
                height: rowHeightAlt
                recSize: toolBarIconSize
68 69 70 71
                Rectangle
                {
                    anchors.fill: parent
                    z: -999
72
                    color:midColor
73 74
                    opacity: 0.3

75
                }
Camilo Higuita's avatar
Camilo Higuita committed
76 77 78 79 80 81
                onColorClicked:
                {
                    populate(Q.GET.colorTracks_.arg(color))
                    if(!playlistViewRoot.wideMode)
                        playlistViewRoot.currentIndex = 1
                }
82 83 84 85 86 87 88
            }

        }
    }


    Page
89 90
    {
        id: playlistViewDrawer
91
        anchors.fill: parent
92 93 94

        background: Rectangle
        {
95
            color: altColor
96 97 98 99 100 101 102 103 104
        }

        BabeTable
        {
            id: filterList
            width: parent.width
            height: parent.height
            quickPlayVisible: true
            coverArtVisible: true
105 106
            trackRating: true
            trackDuration: false
107
            headerBar: true
108
            headerClose: !playlistViewRoot.wideMode
Camilo Higuita's avatar
Camilo Higuita committed
109
            headerTitle: playlistViewRoot.wideMode ? "" : playlistViewModel.model.get(playlistViewModel.currentIndex).playlist
110 111 112
            onHeaderClosed: if(!playlistViewRoot.wideMode)
                                playlistViewRoot.currentIndex = 0

113
            holder.message:  "<h2>"+playlistViewModel.model.get(playlistViewModel.currentIndex).playlist+"</h2><p>Your playlist is empty,<br>start adding new music to it</p>"
Camilo Higuita's avatar
Camilo Higuita committed
114
            holder.emoji: "qrc:/assets/face-hug.png"
115

116 117 118
            headerMenu.menuItem:  [
                BabeMenuItem
                {
119
                    enabled: !playlistViewModel.model.get(playlistViewModel.currentIndex).playlistIcon
120 121 122 123 124
                    text: "Sync tags"
                    onTriggered: {}
                },
                BabeMenuItem
                {
125
                    enabled: !playlistViewModel.model.get(playlistViewModel.currentIndex).playlistIcon
126
                    text: "Play-n-Sync"
127 128 129 130 131
                    onTriggered:
                    {
                        filterList.headerMenu.close()
                        syncAndPlay(playlistViewModel.currentIndex)
                    }
132 133 134
                }
            ]

135 136 137 138 139 140 141 142
            Connections
            {
                target: filterList
                onRowClicked: playlistViewRoot.rowClicked(filterList.model.get(index))
                onQuickPlayTrack:
                {
                    playlistViewRoot.quickPlayTrack(filterList.model.get(index))
                }
Camilo Higuita's avatar
Camilo Higuita committed
143 144
                onPlayAll: playAll(bae.get(playlistQuery))
                onAppendAll: appendAll(bae.get(playlistQuery))
145
                onPulled: populate(playlistQuery)
146 147 148 149 150 151 152
            }
        }

    }

    function populate(query)
    {
Camilo Higuita's avatar
Camilo Higuita committed
153
        playlistQuery = query
154 155 156 157 158 159 160 161 162 163
        filterList.clearTable()

        var tracks = bae.get(query)

        if(tracks.length>0)
            for(var i in tracks)
                filterList.model.append(tracks[i])

    }

164
    function refresh()
165
    {
166 167 168 169 170 171 172 173 174 175
        var i = 9
        for(i; i < playlistViewModel.count; i++)
            playlistViewModel.remove(i)

        setPlaylists()
    }

    function setPlaylists()
    {
        var playlists = bae.get(Q.GET.playlists)
176 177 178 179
        if(playlists.length > 0)
            for(var i in playlists)
                playlistViewModel.model.append(playlists[i])
    }
180

181 182 183 184 185 186
    function syncAndPlay(index)
    {
        if(!playlistViewModel.model.get(index).playlistIcon)
            playlistViewRoot.playSync(playlistViewModel.model.get(index).playlist)
    }

187
    Component.onCompleted: setPlaylists()
188
}