PlaylistsView.qml 7.4 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
import org.kde.maui 1.0 as Maui
6 7

import "../../view_models/BabeTable"
8
import "../../view_models/BabeMenu"
9
import "../../view_models"
Camilo Higuita's avatar
Camilo Higuita committed
10
import "../../db/Queries.js" as Q
11
import "../../utils/Help.js" as H
12 13


14 15
Kirigami.PageRow
{
16 17
    id: playlistViewRoot

18
    property string playlistQuery
19 20
    property alias playlistViewModel : playlistViewModel

21 22
    signal rowClicked(var track)
    signal quickPlayTrack(var track)
Camilo Higuita's avatar
Camilo Higuita committed
23
    signal playAll(var tracks)
24
    signal playSync(var playlist)
Camilo Higuita's avatar
Camilo Higuita committed
25
    signal appendAll(var tracks)
26

Camilo Higuita's avatar
Camilo Higuita committed
27
    clip: true
28
    separatorVisible: wideMode
29
    initialPage: [playlistList, playlistViewDrawer]
30
    defaultColumnWidth: Kirigami.Units.gridUnit * 15
31
    interactive: currentIndex === 1 && !wideMode
32

33

Camilo Higuita's avatar
Camilo Higuita committed
34
    Page
35 36
    {
        id: playlistList
37
        clip: true
38

39 40 41 42 43 44
        ColumnLayout
        {
            anchors.fill: parent
            spacing: 0
            Layout.margins: 0

Camilo Higuita's avatar
Camilo Higuita committed
45 46

            SwipeView
47
            {
Camilo Higuita's avatar
Camilo Higuita committed
48
                id: playlistSwipe
49 50 51 52

                Layout.fillHeight: true
                Layout.fillWidth: true

53 54 55
                interactive: false
                clip: true

Camilo Higuita's avatar
Camilo Higuita committed
56 57 58 59 60 61 62 63 64 65
                PlaylistsViewModel
                {
                    id: playlistViewModel
                    onPlaySync: syncAndPlay(index)
                }

                BabeList
                {
                    id: playlistViewModelFilter

Camilo Higuita's avatar
Camilo Higuita committed
66
                    headBarExitIcon: "go-previous"
Camilo Higuita's avatar
Camilo Higuita committed
67 68

                    model : ListModel {}
69
                    delegate: Maui.LabelDelegate
Camilo Higuita's avatar
Camilo Higuita committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83
                    {
                        id: delegate
                        label : tag
                        Connections
                        {
                            target: delegate

                            onClicked: {}
                        }
                    }

                    onExit: playlistSwipe.currentIndex = 0
                }

84 85 86 87 88
            }

            ColorTagsBar
            {
                Layout.fillWidth: true
89
                height: rowHeightAlt
90
                recSize: isMobile ? iconSize : 16
91

Camilo Higuita's avatar
Camilo Higuita committed
92 93 94 95 96 97
                onColorClicked:
                {
                    populate(Q.GET.colorTracks_.arg(color))
                    if(!playlistViewRoot.wideMode)
                        playlistViewRoot.currentIndex = 1
                }
98 99 100 101 102 103
            }
        }
    }


    Page
104 105
    {
        id: playlistViewDrawer
106
        anchors.fill: parent
107
        clip: true
108 109 110 111

        BabeTable
        {
            id: filterList
112
            anchors.fill: parent
113 114
            quickPlayVisible: true
            coverArtVisible: true
115 116
            trackRating: true
            trackDuration: false
Camilo Higuita's avatar
Camilo Higuita committed
117 118 119 120
            headBarVisible: true
            headBarExitIcon: "go-previous"
            headBarExit: !playlistViewRoot.wideMode
            headBarTitle: playlistViewRoot.wideMode ? "" : playlistViewModel.model.get(playlistViewModel.currentIndex).playlist
Camilo Higuita's avatar
Camilo Higuita committed
121
            onExit: if(!playlistViewRoot.wideMode)
122
                        playlistViewRoot.currentIndex = 0
123

124
            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
125
            holder.emoji: "qrc:/assets/face-hug.png"
126

127 128 129
            headerMenu.menuItem:  [
                BabeMenuItem
                {
130
                    enabled: !playlistViewModel.model.get(playlistViewModel.currentIndex).playlistIcon
131 132 133 134 135
                    text: "Sync tags"
                    onTriggered: {}
                },
                BabeMenuItem
                {
136
                    enabled: !playlistViewModel.model.get(playlistViewModel.currentIndex).playlistIcon
137
                    text: "Play-n-Sync"
138 139 140 141 142
                    onTriggered:
                    {
                        filterList.headerMenu.close()
                        syncAndPlay(playlistViewModel.currentIndex)
                    }
143 144 145 146 147 148 149 150 151 152
                },
                BabeMenuItem
                {
                    enabled: !playlistViewModel.model.get(playlistViewModel.currentIndex).playlistIcon
                    text: "Remove playlist"
                    onTriggered: removePlaylist()
                }
            ]


153 154 155 156 157 158 159 160 161 162 163 164
//            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)
//                    }
//                }
//            ]
165

166 167

            section.criteria: ViewSection.FullString
168
            section.delegate: Maui.LabelDelegate
169 170 171 172
            {
                label: filterList.section.property === qsTr("stars") ? H.setStars(section) : section
                isSection: true
                boldLabel: true
173
                labelTxt.font.family: "Material Design Icons"
174 175 176

            }

177 178 179 180 181 182 183 184
            Connections
            {
                target: filterList
                onRowClicked: playlistViewRoot.rowClicked(filterList.model.get(index))
                onQuickPlayTrack:
                {
                    playlistViewRoot.quickPlayTrack(filterList.model.get(index))
                }
Camilo Higuita's avatar
Camilo Higuita committed
185 186
                onPlayAll: playAll(bae.get(playlistQuery))
                onAppendAll: appendAll(bae.get(playlistQuery))
187
                onPulled: populate(playlistQuery)
188
            }
189 190 191 192 193 194 195 196 197 198 199

            Connections
            {
                target: filterList.contextMenu

                onTrackRemoved:
                {
                    bae.removePlaylistTrack(url, playlistViewModel.model.get(playlistViewModel.currentIndex).playlist)
                    populate(playlistQuery)
                }
            }
200 201 202 203
        }

    }

Camilo Higuita's avatar
Camilo Higuita committed
204 205 206 207 208 209
    function populateExtra(query, title)
    {
        playlistSwipe.currentIndex = 1

        var res = bae.get(query)
        playlistViewModelFilter.clearTable()
Camilo Higuita's avatar
Camilo Higuita committed
210
        playlistViewModelFilter.headBarTitle = title
211 212 213 214 215
        appendToExtraList(res)
    }

    function appendToExtraList(res)
    {
Camilo Higuita's avatar
Camilo Higuita committed
216 217 218 219 220
        if(res.length>0)
            for(var i in res)
                playlistViewModelFilter.model.append(res[i])
    }

221 222
    function populate(query)
    {
223 224 225 226

        if(!playlistViewRoot.wideMode)
            playlistViewRoot.currentIndex = 1

Camilo Higuita's avatar
Camilo Higuita committed
227
        playlistQuery = query
228
        filterList.clearTable()
229 230 231 232 233 234 235 236 237

        var tracks = bae.get(query)

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

    }

238
    function refresh()
239
    {
240 241
        for(var i=9; i < playlistViewModel.count; i++)
            playlistViewModel.model.remove(i)
242 243 244 245 246 247 248

        setPlaylists()
    }

    function setPlaylists()
    {
        var playlists = bae.get(Q.GET.playlists)
249 250 251 252
        if(playlists.length > 0)
            for(var i in playlists)
                playlistViewModel.model.append(playlists[i])
    }
253

254 255 256 257 258 259
    function syncAndPlay(index)
    {
        if(!playlistViewModel.model.get(index).playlistIcon)
            playlistViewRoot.playSync(playlistViewModel.model.get(index).playlist)
    }

260 261 262 263 264 265 266 267 268 269
    function removePlaylist()
    {

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

        filterList.clearTable()
        refresh()

    }

270
    Component.onCompleted: setPlaylists()
271
}