PlaylistsViewModel.qml 3.15 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.2 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
22

Camilo Higuita's avatar
Camilo Higuita committed
23
24
    headBarExit: false
    headBarTitle: "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
    signal playSync(int index)
    headBar.plegable: false
37

Camilo Higuita's avatar
Camilo Higuita committed
38
    headBar.leftContent: Maui.ToolButton
39
    {
Camilo Higuita's avatar
Camilo Higuita committed
40
41
42
43
44
        id : createPlaylistBtn
        anim : true
        iconName : "list-add"
        onClicked : newPlaylistDialog.open()
    }
Camilo Higuita's avatar
Camilo Higuita committed
45

Camilo Higuita's avatar
Camilo Higuita committed
46
    headBar.rightContent: Maui.ToolButton
Camilo Higuita's avatar
Camilo Higuita committed
47
48
    {
        iconName: "list-remove"
49
        onClicked: removePlaylist()
50
51
    }

52
53
54
55
56
57
58
    BaseModel
    {
        id: _playlistsModel
        list: _playlistsList
    }

    Playlists
59
    {
60
        id: _playlistsList
61
62
    }

63
    model: _playlistsModel
64

65
    delegate : Maui.ListDelegate
66
67
    {
        id: delegate
68
        width: control.width
69
        label: model.playlist
70
71
72
73
74
75
76
77

        Connections
        {
            target : delegate

            onClicked :
            {
                currentIndex = index
78
79
                var playlist = _playlistsList.get(index).playlist
                filterList.group = false
80
81
82

                switch(playlist)
                {
83
84
                case "Most Played":

85
                    populate(Q.GET.mostPlayedTracks);
86
                    filterList.list.sortBy = Tracks.COUNT
87
88
                    break;

89
                case "Rating":
90
91
92
                    filterList.list.sortBy = Tracks.RATE
                    filterList.group = true

93
                    populate(Q.GET.favoriteTracks);
94
95
96
                    break;

                case "Recent":
97
                    populate(Q.GET.recentTracks);
98
99
                    filterList.list.sortBy = Tracks.ADDDATE
                    filterList.group = true
100
101
                    break;

102
                case "Favs":
103
                    populate(Q.GET.babedTracks);
104
105
106
                    break;

                case "Online":
107
                    populate(Q.GET.favoriteTracks);
108
109
110
                    break;

                case "Tags":
Camilo Higuita's avatar
Camilo Higuita committed
111
                    populateExtra(Q.GET.tags, "Tags")
112
113
114
                    break;

                case "Relationships":
115
                    populate(Q.GET.favoriteTracks);
116
117
118
                    break;

                case "Popular":
119
                    populate(Q.GET.favoriteTracks);
120
121
                    break;

Camilo Higuita's avatar
Camilo Higuita committed
122
123
                case "Genres":
                    populateExtra(Q.GET.genres, "Genres")
124
125
126
                    break;

                default:
127
                    populate(Q.GET.playlistTracks_.arg(playlist));
128
                    break;
129

Camilo Higuita's avatar
Camilo Higuita committed
130
                }
131
132
133
            }
        }
    }
134
135
136
137

    function addPlaylist(text)
    {
        var title = text.trim()
138
139
        if(list.insertAt(title,  0))
            control.listView.positionViewAtEnd()
140
    }
141
}