PlaylistsView.qml 6.48 KB
Newer Older
1 2 3
import QtQuick 2.9
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.2
Camilo higuita's avatar
Camilo higuita committed
4
import org.kde.kirigami 2.6 as Kirigami
Camilo Higuita's avatar
Camilo Higuita committed
5
import org.kde.mauikit 1.0 as Maui
6 7 8

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

12
ColumnLayout
13
{
14 15 16
    id: control
    clip: true
    spacing: 0
17

18
    property string playlistQuery
19 20 21
    property alias playlistModel : playlistViewModel.model
    property alias playlistList : playlistViewModel.list
    property alias playlistViewList : playlistViewModel
22

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

29
    SwipeView
30
    {
31 32 33 34 35
        id: playlistSwipe

        Layout.fillHeight: true
        Layout.fillWidth: true
        interactive: false
36
        clip: true
Camilo higuita's avatar
Camilo higuita committed
37

38
        PlaylistsViewModel
39
        {
40 41 42
            id: playlistViewModel
            onPlaySync: syncAndPlay(index)
        }
43

44 45 46
        BabeList
        {
            id: playlistViewModelFilter
camilo higuita's avatar
camilo higuita committed
47
//            headBarExitIcon: "go-previous"
48 49 50 51 52
            headBar.leftContent: ToolButton
            {
                icon.name: "go-previous"
                onClicked: playlistSwipe.currentIndex = 0
            }
53

54 55
            model : ListModel {}
            delegate: Maui.LabelDelegate
Camilo higuita's avatar
Camilo higuita committed
56
            {
57 58 59
                id: delegate
                label : tag
                Connections
Camilo Higuita's avatar
Camilo Higuita committed
60
                {
61
                    target: delegate
camilo higuita's avatar
camilo higuita committed
62

63 64
                    onClicked: {}
                }
65
            }
Camilo higuita's avatar
Camilo higuita committed
66
        }
67 68
    }

69
    ColorTagsBar
70
    {
71 72 73
        Layout.fillWidth: true
        height: rowHeightAlt
        recSize: isMobile ? iconSize : 16
74
        onColorClicked: populate(Q.GET.colorTracks_.arg(color.toLowerCase()))
75
    }
Camilo higuita's avatar
fixes  
Camilo higuita committed
76

77 78 79 80 81 82 83 84 85
    Maui.Dialog
    {
        id: _filterDialog
        parent: parent
        maxHeight: maxWidth
        maxWidth: unit * 600
        defaultButtons: false

        BabeTable
Camilo higuita's avatar
Camilo higuita committed
86
        {
87 88 89 90 91 92 93 94
            id: filterList
            anchors.fill: parent
            clip: true
            quickPlayVisible: true
            coverArtVisible: true
            trackRating: true
            trackDuration: false
            headBar.visible: !holder.visible
95
            title: playlistViewModel.list.get(playlistViewModel.currentIndex).playlist
96 97 98 99 100 101 102
            holder.emoji: "qrc:/assets/Electricity.png"
            holder.isMask: false
            holder.title : playlistViewModel.model.get(playlistViewModel.currentIndex).playlist
            holder.body: "Your playlist is empty,<br>start adding new music to it"
            holder.emojiSize: iconSizes.huge

            contextMenuItems:
camilo higuita's avatar
camilo higuita committed
103
                MenuItem
104 105 106
                {
                    text: qsTr("Remove from playlist")
                }
107 108


109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
            //        headerMenu.menuItem:  [
            //            Maui.MenuItem
            //            {
            //                enabled: !playlistViewModel.model.get(playlistViewModel.currentIndex).playlistIcon
            //                text: "Sync tags"
            //                onTriggered: {}
            //            },
            //            Maui.MenuItem
            //            {
            //                enabled: !playlistViewModel.model.get(playlistViewModel.currentIndex).playlistIcon
            //                text: "Play-n-Sync"
            //                onTriggered:
            //                {
            //                    filterList.headerMenu.close()
            //                    syncAndPlay(playlistViewModel.currentIndex)
            //                }
            //            },
            //            Maui.MenuItem
            //            {
            //                enabled: !playlistViewModel.model.get(playlistViewModel.currentIndex).playlistIcon
            //                text: "Remove playlist"
            //                onTriggered: removePlaylist()
            //            }
            //        ]


            //            contextMenu.menuItem: [

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

            section.criteria: ViewSection.FullString
            section.delegate: Maui.LabelDelegate
150
            {
151 152 153 154 155
                label: filterList.section.property === qsTr("stars") ? H.setStars(section) : section
                isSection: true
                boldLabel: true
                labelTxt.font.family: "Material Design Icons"

156
            }
157

158 159 160 161 162
            Connections
            {
                target: filterList
                onRowClicked: control.rowClicked(filterList.model.get(index))
                onQuickPlayTrack: control.quickPlayTrack(filterList.model.get(filterList.currentIndex))
163

164 165 166 167 168 169
                onPlayAll: playAll()
                onAppendAll: appendAll()
                onPulled: populate(playlistQuery)
            }

            Connections
Camilo higuita's avatar
Camilo higuita committed
170
            {
171 172 173 174 175 176 177
                target: filterList.contextMenu

                onRemoveClicked:
                {
                    playlistList.removeTrack(playlistViewList.currentIndex, filterList.list.get(filterList.currentIndex).url)
                    populate(playlistQuery)
                }
178
            }
179 180 181
        }
    }

Camilo higuita's avatar
Camilo higuita committed
182

183 184 185
    function populateExtra(query, title)
    {
        //        playlistSwipe.currentIndex = 1
186

187 188 189 190 191
        //        var res = bae.get(query)
        //        playlistViewModelFilter.clearTable()
        //        playlistViewModelFilter.headBarTitle = title
        //        appendToExtraList(res)
    }
Camilo Higuita's avatar
Camilo Higuita committed
192

193 194 195 196 197 198
    function appendToExtraList(res)
    {
        if(res.length>0)
            for(var i in res)
                playlistViewModelFilter.model.append(res[i])
    }
199

200 201
    function populate(query)
    {
202 203
        playlistQuery = query
        filterList.list.query = playlistQuery
204
        _filterDialog.open()
205
    }
206

207 208 209
    function syncAndPlay(index)
    {
        if(!playlistList.get(index).playlistIcon)
210
            playSync(playlistList.get(index).playlist)
211
    }
212

213 214 215 216 217
    function removePlaylist()
    {
        playlistList.removePlaylist(playlistViewList.currentIndex)
        filterList.clearTable()
    }
218
}