PlaylistsView.qml 6.44 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
9
import "../../view_models/BabeTable"
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
16


ColumnLayout
17
{
18
19
20
    id: control
    clip: true
    spacing: 0
21

22
    property string playlistQuery
23
24
25
    property alias playlistModel : playlistViewModel.model
    property alias playlistList : playlistViewModel.list
    property alias playlistViewList : playlistViewModel
26

27
28
    signal rowClicked(var track)
    signal quickPlayTrack(var track)
Camilo higuita's avatar
Camilo higuita committed
29
    signal playAll()
30
    signal playSync(var playlist)
Camilo higuita's avatar
Camilo higuita committed
31
    signal appendAll()
32

33
    SwipeView
34
    {
35
36
37
38
39
40
        id: playlistSwipe

        Layout.fillHeight: true
        Layout.fillWidth: true

        interactive: false
41
        clip: true
Camilo higuita's avatar
Camilo higuita committed
42

43
        PlaylistsViewModel
44
        {
45
46
47
            id: playlistViewModel
            onPlaySync: syncAndPlay(index)
        }
48

49
50
51
        BabeList
        {
            id: playlistViewModelFilter
Camilo Higuita's avatar
Camilo Higuita committed
52

53
            headBarExitIcon: "go-previous"
54

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

64
65
                    onClicked: {}
                }
66
67
            }

68
            onExit: playlistSwipe.currentIndex = 0
Camilo higuita's avatar
Camilo higuita committed
69
        }
70

71
72
    }

73
    ColorTagsBar
74
    {
75
76
77
78
        Layout.fillWidth: true
        height: rowHeightAlt
        recSize: isMobile ? iconSize : 16

79
        onColorClicked: populate(Q.GET.colorTracks_.arg(color.toLowerCase()))
Camilo higuita's avatar
fixes    
Camilo higuita committed
80

81
    }
Camilo higuita's avatar
fixes    
Camilo higuita committed
82

83
84
85
86
87
88
89
90
91
92
    Maui.Dialog
    {
        id: _filterDialog
        parent: parent
        maxHeight: maxWidth
        maxWidth: unit * 600
        defaultButtons: false
        page.margins: 0

        BabeTable
Camilo higuita's avatar
Camilo higuita committed
93
        {
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
            id: filterList
            anchors.fill: parent
            clip: true
            quickPlayVisible: true
            coverArtVisible: true
            trackRating: true
            trackDuration: false
            headBar.visible: !holder.visible
            headBarExit: false
            headBarTitle: playlistViewModel.list.get(playlistViewModel.currentIndex).playlist


            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:
                Maui.MenuItem
                {
                    text: qsTr("Remove from playlist")
                }
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
150
151
152
153
154
155
156
157
158
159
160
            //        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
161
            {
162
163
164
165
166
                label: filterList.section.property === qsTr("stars") ? H.setStars(section) : section
                isSection: true
                boldLabel: true
                labelTxt.font.family: "Material Design Icons"

167
            }
168

169
170
171
172
173
            Connections
            {
                target: filterList
                onRowClicked: control.rowClicked(filterList.model.get(index))
                onQuickPlayTrack: control.quickPlayTrack(filterList.model.get(filterList.currentIndex))
174

175
176
177
178
179
180
                onPlayAll: playAll()
                onAppendAll: appendAll()
                onPulled: populate(playlistQuery)
            }

            Connections
Camilo higuita's avatar
Camilo higuita committed
181
            {
182
183
184
185
186
187
188
                target: filterList.contextMenu

                onRemoveClicked:
                {
                    playlistList.removeTrack(playlistViewList.currentIndex, filterList.list.get(filterList.currentIndex).url)
                    populate(playlistQuery)
                }
189
            }
190
191
192
        }
    }

Camilo higuita's avatar
Camilo higuita committed
193

194
195
196
    function populateExtra(query, title)
    {
        //        playlistSwipe.currentIndex = 1
197

198
199
200
201
202
        //        var res = bae.get(query)
        //        playlistViewModelFilter.clearTable()
        //        playlistViewModelFilter.headBarTitle = title
        //        appendToExtraList(res)
    }
Camilo Higuita's avatar
Camilo Higuita committed
203

204
205
206
207
208
209
    function appendToExtraList(res)
    {
        if(res.length>0)
            for(var i in res)
                playlistViewModelFilter.model.append(res[i])
    }
210

211
212
    function populate(query)
    {
213
214
        playlistQuery = query
        filterList.list.query = playlistQuery
215
        _filterDialog.open()
216
    }
217

218
219
220
    function syncAndPlay(index)
    {
        if(!playlistList.get(index).playlistIcon)
221
            playSync(playlistList.get(index).playlist)
222
    }
223

224
225
226
227
228
    function removePlaylist()
    {
        playlistList.removePlaylist(playlistViewList.currentIndex)
        filterList.clearTable()
    }
229
}