PlaylistsView.qml 5.05 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
            Kirigami.Separator{ Layout.fillWidth: true; width: parent.width; height: 1}

65 66 67
            ColorTagsBar
            {
                Layout.fillWidth: true
68
                height: rowHeightAlt
69 70
                recSize: isMobile ? toolBarIconSize : 16

71 72 73 74
                Rectangle
                {
                    anchors.fill: parent
                    z: -999
75
                    color:midColor
76 77
                    opacity: 0.3

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


    Page
91 92
    {
        id: playlistViewDrawer
93
        anchors.fill: parent
94 95 96

        background: Rectangle
        {
97
            color: altColor
98 99 100 101 102
        }

        BabeTable
        {
            id: filterList
103
            anchors.fill: parent
104 105
            quickPlayVisible: true
            coverArtVisible: true
106 107
            trackRating: true
            trackDuration: false
Camilo Higuita's avatar
Camilo Higuita committed
108 109 110 111 112
            headerBarVisible: true
            headerBarExitIcon: "arrow-left"
            headerBarExit: !playlistViewRoot.wideMode
            headerBarTitle: playlistViewRoot.wideMode ? "" : playlistViewModel.model.get(playlistViewModel.currentIndex).playlist
            onExit: if(!playlistViewRoot.wideMode)
113 114
                                playlistViewRoot.currentIndex = 0

115
            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
116
            holder.emoji: "qrc:/assets/face-hug.png"
117

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

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

    }

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

        var tracks = bae.get(query)

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

    }

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

        setPlaylists()
    }

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

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

189
    Component.onCompleted: setPlaylists()
190
}