AlbumsView.qml 6.38 KB
Newer Older
Camilo Higuita's avatar
Camilo Higuita committed
1 2 3 4
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3

5 6 7
import "../view_models/BabeGrid"
import "../view_models/BabeTable"

8
import "../db/Queries.js" as Q
Camilo Higuita's avatar
Camilo Higuita committed
9
import "../utils/Help.js" as H
10
import org.kde.kirigami 2.6 as Kirigami
Camilo Higuita's avatar
Camilo Higuita committed
11
import org.kde.mauikit 1.0 as Maui
camilo higuita's avatar
camilo higuita committed
12 13
import TracksList 1.0
import AlbumsList 1.0
14

Camilo higuita's avatar
Camilo higuita committed
15
BabeGrid
Camilo Higuita's avatar
Camilo Higuita committed
16
{
Camilo higuita's avatar
Camilo higuita committed
17
    id: albumsViewGrid
18

19 20 21
    property string currentAlbum: ""
    property string currentArtist: ""

Camilo higuita's avatar
Camilo higuita committed
22 23
    property var tracks: []

24
    property alias table : albumsViewTable
25
//    property alias tagBar : tagBar
Camilo Higuita's avatar
Camilo Higuita committed
26

Camilo Higuita's avatar
Camilo Higuita committed
27
    signal rowClicked(var track)
28 29
    signal playTrack(var track)
    signal queueTrack(var track)
Camilo Higuita's avatar
Camilo Higuita committed
30

31 32
    signal appendAll(string album, string artist)
    signal playAll(string album, string artist)
Camilo higuita's avatar
Camilo higuita committed
33
    //    signal albumCoverClicked(string album, string artist)
34
    signal albumCoverPressedAndHold(string album, string artist)
35

Camilo higuita's avatar
Camilo higuita committed
36 37 38
    visible: true
    //        topPadding: space.large
    onAlbumCoverPressed: albumCoverPressedAndHold(album, artist)
39 40 41 42 43 44
    headBar.visible: false
//    headBar.rightContent: Kirigami.ActionToolBar
//    {
//        Layout.fillWidth: true
//        actions:   [
//            Kirigami.Action
Camilo higuita's avatar
Camilo higuita committed
45
//        {
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
//            id: sortBtn
//            icon.name: "view-sort"
//                text: qsTr("Sort")


//                    Kirigami.Action
//                {
//                    text: qsTr("Artist")
//                    checkable: true
//                    checked: list.sortBy === Albums.ARTIST
//                    onTriggered: list.sortBy = Albums.ARTIST
//                }

//                Kirigami.Action
//                {
//                    text: qsTr("Album")
//                    checkable: true
//                    checked: list.sortBy === Albums.ALBUM
//                    onTriggered: list.sortBy = Albums.ALBUM
//                }

//                Kirigami.Action
//                {
//                    text: qsTr("Release date")
//                    checkable: true
//                    checked: list.sortBy === Albums.RELEASEDATE
//                    onTriggered: list.sortBy = Albums.RELEASEDATE
//                }

//                Kirigami.Action
//                {
//                    text: qsTr("Add date")
//                    checkable: true
//                    checked: list.sortBy === Albums.ADDDATE
//                    onTriggered: list.sortBy = Albums.ADDDATE
//                }
//            }
//    ]
//    }
85

Camilo higuita's avatar
Camilo higuita committed
86 87
//    headBar.rightContent: [

88
//        ToolButton
Camilo higuita's avatar
Camilo higuita committed
89 90 91 92
//        {
//            id: appendBtn
//            visible: headBar.visible && albumsViewGrid.count > 0
//            anim : true
93
//            icon.name : "media-playlist-append"//"media-repeat-track-amarok"
Camilo higuita's avatar
Camilo higuita committed
94 95 96
//            onClicked: appendAll()
//        }
//    ]
97

Camilo higuita's avatar
Camilo higuita committed
98
    Maui.Dialog
99
    {
Camilo higuita's avatar
Camilo higuita committed
100
        id: albumDialog
101
        parent: parent
Camilo higuita's avatar
Camilo higuita committed
102 103 104
        maxHeight: maxWidth
        maxWidth: unit * 600
        defaultButtons: false
camilo higuita's avatar
camilo higuita committed
105 106
        page.padding: 0

camilo higuita's avatar
camilo higuita committed
107
        //        verticalAlignment: Qt.AlignBottom
108

Camilo higuita's avatar
Camilo higuita committed
109
        ColumnLayout
110
        {
Camilo higuita's avatar
Camilo higuita committed
111 112 113
            id: albumFilter
            anchors.fill: parent
            spacing: 0
114

Camilo higuita's avatar
Camilo higuita committed
115
            BabeTable
116
            {
Camilo higuita's avatar
Camilo higuita committed
117 118 119 120
                id: albumsViewTable
                Layout.fillHeight: true
                Layout.fillWidth: true
                trackNumberVisible: true
121
                trackRating: true
122
                headBar.visible: true
Camilo higuita's avatar
Camilo higuita committed
123 124 125
                coverArtVisible: true
                quickPlayVisible: true
                focus: true
camilo higuita's avatar
camilo higuita committed
126
                list.sortBy: Tracks.TRACK
Camilo higuita's avatar
Camilo higuita committed
127
                headBar.plegable: false
camilo higuita's avatar
camilo higuita committed
128

Camilo higuita's avatar
Camilo higuita committed
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
                holder.emoji: "qrc:/assets/ElectricPlug.png"
                holder.isMask: false
                holder.title : "Oops!"
                holder.body: "This list is empty"
                holder.emojiSize: iconSizes.huge

                onRowClicked:
                {
                    albumsViewGrid.rowClicked(model.get(index))
                }

                onQuickPlayTrack:
                {
                    albumsViewGrid.playTrack(model.get(index))
                }

                onQueueTrack:
                {
                    albumsViewGrid.queueTrack(model.get(index))
                }

                onPlayAll:
                {
                    albumDialog.close()
                    albumsViewGrid.playAll(currentAlbum, currentArtist)
                }

                onAppendAll:
                {
                    albumDialog.close()
                    albumsViewGrid.appendAll(currentAlbum, currentArtist)
                }
161 162
            }

163 164 165 166 167 168 169 170
//            Maui.TagsBar
//            {
//                id: tagBar
//                visible:false
//                Layout.fillWidth: true
//                allowEditMode: false
//                onTagClicked: H.searchFor("tag:"+tag)
//            }
171
        }
Camilo Higuita's avatar
Camilo Higuita committed
172 173
    }

174
    function populateTable(album, artist)
175
    {
Camilo Higuita's avatar
Camilo Higuita committed
176
        console.log("PAPULATE ALBUMS VIEW")
Camilo higuita's avatar
Camilo higuita committed
177
        albumDialog.open()
178

179 180 181 182 183 184 185 186 187 188
        var query = ""
        var tagq = ""

        currentAlbum = album === undefined ? "" : album
        currentArtist= artist

        if(album && artist)
        {
            query = Q.GET.albumTracks_.arg(album)
            query = query.arg(artist)
189
            albumsView.table.title = album
190 191 192 193 194
            tagq = Q.GET.albumTags_.arg(album)

        }else if(artist && album === undefined)
        {
            query = Q.GET.artistTracks_.arg(artist)
195
            artistsView.table.title = artist
196 197
            tagq = Q.GET.artistTags_.arg(artist)
        }
198

camilo higuita's avatar
camilo higuita committed
199
        albumsViewTable.list.query = query
200

camilo higuita's avatar
camilo higuita committed
201 202 203 204 205 206 207 208
        /*dunoooo*/
//        if(tracks.length > 0)
//        {
//            tagq = tagq.arg(artist)
//            var tags = bae.get(tagq)
//            console.log(tagq, "TAGS", tags)
//            tagBar.populate(tags)
//        }
Camilo Higuita's avatar
Camilo Higuita committed
209 210
    }

Camilo Higuita's avatar
Camilo Higuita committed
211 212 213
    function filter(tracks)
    {
        var matches = []
214

Camilo Higuita's avatar
Camilo Higuita committed
215 216 217
        for(var i = 0; i<tracks.length; i++)
            matches.push(find(tracks[i].album))

218 219
        for(var j = 0 ; j < albumsViewGrid.gridModel.count; j++)
            albumsViewGrid.gridModel.remove(j,1)
Camilo Higuita's avatar
Camilo Higuita committed
220 221


222 223 224 225 226
        //        for(var match in matches)
        //        {
        //            albumsViewGrid.gridModel.get(match).hide = true
        //            console.log(match)
        //        }
Camilo Higuita's avatar
Camilo Higuita committed
227 228 229 230 231 232 233 234 235 236
    }

    function find(query)
    {
        var indexes = []
        for(var i = 0 ; i < albumsViewGrid.gridModel.count; i++)
            if(albumsViewGrid.gridModel.get(i).album.includes(query))
                indexes.push(i)

    }
Camilo Higuita's avatar
Camilo Higuita committed
237
}
238