PlaylistsView.qml 5.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
            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
                        playlistViewRoot.currentIndex = 0
114

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 145 146 147 148 149 150 151 152
                },
                BabeMenuItem
                {
                    enabled: !playlistViewModel.model.get(playlistViewModel.currentIndex).playlistIcon
                    text: "Remove playlist"
                    onTriggered: removePlaylist()
                }
            ]

            contextMenu.menuItem: [

                BabeMenuItem
                {
                    text: qsTr("Remove from playlist")
                    onTriggered:
                    {
                        bae.removePlaylistTrack(filterList.model.get(filterList.currentIndex).url, playlistViewModel.model.get(playlistViewModel.currentIndex).playlist)
                        populate(playlistQuery)
                    }
153 154 155
                }
            ]

156 157 158 159 160 161 162 163
            Connections
            {
                target: filterList
                onRowClicked: playlistViewRoot.rowClicked(filterList.model.get(index))
                onQuickPlayTrack:
                {
                    playlistViewRoot.quickPlayTrack(filterList.model.get(index))
                }
Camilo Higuita's avatar
Camilo Higuita committed
164 165
                onPlayAll: playAll(bae.get(playlistQuery))
                onAppendAll: appendAll(bae.get(playlistQuery))
166
                onPulled: populate(playlistQuery)
167 168 169 170 171 172 173
            }
        }

    }

    function populate(query)
    {
Camilo Higuita's avatar
Camilo Higuita committed
174
        playlistQuery = query
175
        filterList.clearTable()
176 177 178 179 180 181 182 183 184

        var tracks = bae.get(query)

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

    }

185
    function refresh()
186
    {
187 188
        for(var i=9; i < playlistViewModel.count; i++)
            playlistViewModel.model.remove(i)
189 190 191 192 193 194 195

        setPlaylists()
    }

    function setPlaylists()
    {
        var playlists = bae.get(Q.GET.playlists)
196 197 198 199
        if(playlists.length > 0)
            for(var i in playlists)
                playlistViewModel.model.append(playlists[i])
    }
200

201 202 203 204 205 206
    function syncAndPlay(index)
    {
        if(!playlistViewModel.model.get(index).playlistIcon)
            playlistViewRoot.playSync(playlistViewModel.model.get(index).playlist)
    }

207 208 209 210 211 212 213 214 215 216
    function removePlaylist()
    {

        bae.removePlaylist(playlistViewModel.model.get(playlistViewModel.currentIndex).playlist)

        filterList.clearTable()
        refresh()

    }

217
    Component.onCompleted: setPlaylists()
218
}