PlaylistsViewModel.qml 3.32 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.6 as Kirigami
Camilo Higuita's avatar
Camilo Higuita committed
5
import org.kde.mauikit 1.0 as Maui
6 7
import PlaylistsList 1.0
import BaseModel 1.0
8

9 10
import TracksList 1.0

11 12 13 14
import "../../utils"

import "../../view_models"
import "../../db/Queries.js" as Q
Camilo Higuita's avatar
Camilo Higuita committed
15
import "../../utils/Help.js" as H
16 17

BabeList
18
{
19 20 21
    id: control

    property alias list: _playlistsList
camilo higuita's avatar
camilo higuita committed
22 23
    signal playSync(int index)

24
    title: "Playlists"
Camilo higuita's avatar
Camilo higuita committed
25

26
    Maui.NewDialog
27
    {
28
        id: newPlaylistDialog
Camilo higuita's avatar
Camilo higuita committed
29
        title: qsTr("New Playlist...")
30
        onFinished: addPlaylist(text)
Camilo higuita's avatar
Camilo higuita committed
31 32
        acceptText: qsTr("Create")
        rejectButton.visible: false
33 34 35
    }


36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
    headBar.rightContent: Kirigami.ActionToolBar
    {
        Layout.fillWidth: true
        actions:
            [
            Kirigami.Action
            {
                text: qsTr("Remove")
                icon.name: "list-remove"
                onTriggered: removePlaylist()
            },
            Kirigami.Action
            {
                id : createPlaylistBtn
                text: qsTr("Add")
                icon.name : "list-add"
                onTriggered : newPlaylistDialog.open()
            }
        ]
    }


58 59 60 61 62 63 64
    BaseModel
    {
        id: _playlistsModel
        list: _playlistsList
    }

    Playlists
65
    {
66
        id: _playlistsList
67 68
    }

69
    model: _playlistsModel
70

71
    delegate : Maui.ListDelegate
72 73
    {
        id: delegate
74
        width: control.width
75
        label: model.playlist
76 77 78 79 80 81 82 83

        Connections
        {
            target : delegate

            onClicked :
            {
                currentIndex = index
84 85
                var playlist = _playlistsList.get(index).playlist
                filterList.group = false
86 87 88

                switch(playlist)
                {
89 90
                case "Most Played":

91
                    populate(Q.GET.mostPlayedTracks);
92
                    filterList.list.sortBy = Tracks.COUNT
93 94
                    break;

95
                case "Rating":
96 97 98
                    filterList.list.sortBy = Tracks.RATE
                    filterList.group = true

99
                    populate(Q.GET.favoriteTracks);
100 101 102
                    break;

                case "Recent":
103
                    populate(Q.GET.recentTracks);
104 105
                    filterList.list.sortBy = Tracks.ADDDATE
                    filterList.group = true
106 107
                    break;

108
                case "Favs":
109
                    populate(Q.GET.babedTracks);
110 111 112
                    break;

                case "Online":
113
                    populate(Q.GET.favoriteTracks);
114 115 116
                    break;

                case "Tags":
Camilo Higuita's avatar
Camilo Higuita committed
117
                    populateExtra(Q.GET.tags, "Tags")
118 119 120
                    break;

                case "Relationships":
121
                    populate(Q.GET.favoriteTracks);
122 123 124
                    break;

                case "Popular":
125
                    populate(Q.GET.favoriteTracks);
126 127
                    break;

Camilo Higuita's avatar
Camilo Higuita committed
128 129
                case "Genres":
                    populateExtra(Q.GET.genres, "Genres")
130 131 132
                    break;

                default:
133
                    populate(Q.GET.playlistTracks_.arg(playlist));
134
                    break;
135

Camilo Higuita's avatar
Camilo Higuita committed
136
                }
137 138 139
            }
        }
    }
140 141 142 143

    function addPlaylist(text)
    {
        var title = text.trim()
144 145
        if(list.insertAt(title,  0))
            control.listView.positionViewAtEnd()
146
    }
147
}