Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

PlaylistsView.qml 6.43 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
47 48 49 50 51
            headBar.leftContent: ToolButton
            {
                icon.name: "go-previous"
                onClicked: playlistSwipe.currentIndex = 0
            }
52

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

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

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

        BabeTable
Camilo higuita's avatar
Camilo higuita committed
84
        {
85 86 87 88 89 90 91 92
            id: filterList
            anchors.fill: parent
            clip: true
            quickPlayVisible: true
            coverArtVisible: true
            trackRating: true
            trackDuration: false
            headBar.visible: !holder.visible
93
            title: playlistViewModel.list.get(playlistViewModel.currentIndex).playlist
94 95 96 97 98 99 100
            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
101
                MenuItem
102 103 104
                {
                    text: qsTr("Remove from playlist")
                }
105 106


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
            //        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
148
            {
149 150 151 152 153
                label: filterList.section.property === qsTr("stars") ? H.setStars(section) : section
                isSection: true
                boldLabel: true
                labelTxt.font.family: "Material Design Icons"

154
            }
155

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

162 163 164 165 166 167
                onPlayAll: playAll()
                onAppendAll: appendAll()
                onPulled: populate(playlistQuery)
            }

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

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

Camilo higuita's avatar
Camilo higuita committed
180

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

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

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

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

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

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