PlaylistsView.qml 4.78 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 39 40 41 42 43 44 45 46 47 48 49 50 51
    {
        id: playlistList
        ColumnLayout
        {
            anchors.fill: parent
            spacing: 0
            Layout.margins: 0

            PlaylistsViewModel
            {
                id: playlistViewModel

                Layout.fillHeight: true
                Layout.fillWidth: true

52
                onPlaySync: syncAndPlay(index)
53

54 55 56 57 58
            }

            ColorTagsBar
            {
                Layout.fillWidth: true
59 60
                height: rowHeightAlt
                recSize: toolBarIconSize
61 62 63 64
                Rectangle
                {
                    anchors.fill: parent
                    z: -999
65
                    color:midColor
66
                }
Camilo Higuita's avatar
Camilo Higuita committed
67 68 69 70 71 72
                onColorClicked:
                {
                    populate(Q.GET.colorTracks_.arg(color))
                    if(!playlistViewRoot.wideMode)
                        playlistViewRoot.currentIndex = 1
                }
73 74 75 76 77 78 79
            }

        }
    }


    Page
80 81
    {
        id: playlistViewDrawer
82
        anchors.fill: parent
83 84 85

        background: Rectangle
        {
86
            color: altColor
87 88 89 90 91 92 93 94 95
        }

        BabeTable
        {
            id: filterList
            width: parent.width
            height: parent.height
            quickPlayVisible: true
            coverArtVisible: true
96 97
            trackRating: true
            trackDuration: false
98
            headerBar: true
99
            headerClose: !playlistViewRoot.wideMode
Camilo Higuita's avatar
Camilo Higuita committed
100
            headerTitle: playlistViewRoot.wideMode ? "" : playlistViewModel.model.get(playlistViewModel.currentIndex).playlist
101 102 103
            onHeaderClosed: if(!playlistViewRoot.wideMode)
                                playlistViewRoot.currentIndex = 0

104
            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
105
            holder.emoji: "qrc:/assets/face-hug.png"
106

107 108 109
            headerMenu.menuItem:  [
                BabeMenuItem
                {
110
                    enabled: !playlistViewModel.model.get(playlistViewModel.currentIndex).playlistIcon
111 112 113 114 115
                    text: "Sync tags"
                    onTriggered: {}
                },
                BabeMenuItem
                {
116
                    enabled: !playlistViewModel.model.get(playlistViewModel.currentIndex).playlistIcon
117
                    text: "Play-n-Sync"
118 119 120 121 122
                    onTriggered:
                    {
                        filterList.headerMenu.close()
                        syncAndPlay(playlistViewModel.currentIndex)
                    }
123 124 125
                }
            ]

126 127 128 129 130 131 132 133
            Connections
            {
                target: filterList
                onRowClicked: playlistViewRoot.rowClicked(filterList.model.get(index))
                onQuickPlayTrack:
                {
                    playlistViewRoot.quickPlayTrack(filterList.model.get(index))
                }
Camilo Higuita's avatar
Camilo Higuita committed
134 135
                onPlayAll: playAll(bae.get(playlistQuery))
                onAppendAll: appendAll(bae.get(playlistQuery))
136
                onPulled: populate(playlistQuery)
137 138 139 140 141 142 143
            }
        }

    }

    function populate(query)
    {
Camilo Higuita's avatar
Camilo Higuita committed
144
        playlistQuery = query
145 146 147 148 149 150 151 152 153 154
        filterList.clearTable()

        var tracks = bae.get(query)

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

    }

155
    function refresh()
156
    {
157 158 159 160 161 162 163 164 165 166
        var i = 9
        for(i; i < playlistViewModel.count; i++)
            playlistViewModel.remove(i)

        setPlaylists()
    }

    function setPlaylists()
    {
        var playlists = bae.get(Q.GET.playlists)
167 168 169 170
        if(playlists.length > 0)
            for(var i in playlists)
                playlistViewModel.model.append(playlists[i])
    }
171

172 173 174 175 176 177
    function syncAndPlay(index)
    {
        if(!playlistViewModel.model.get(index).playlistIcon)
            playlistViewRoot.playSync(playlistViewModel.model.get(index).playlist)
    }

178
    Component.onCompleted: setPlaylists()
179
}