PlaylistDialog.qml 2.52 KB
Newer Older
1
import QtQuick 2.0
2
import QtQuick.Controls 2.10
3
import org.kde.kirigami 2.2 as Kirigami
Camilo Higuita's avatar
Camilo Higuita committed
4
import org.kde.mauikit 1.0 as Maui
5
import QtQuick.Layouts 1.3
6 7

import "../../view_models"
8 9
import "../../utils/Player.js" as Player
import "../../db/Queries.js" as Q
10

Camilo higuita's avatar
Camilo higuita committed
11
Maui.Dialog
12 13 14 15
{
    title: "Add "+ tracks.length +" tracks to..."

    property var tracks : []
16 17
    maxHeight: 400 * Maui.Style.unit
    page.padding: Maui.Style.space.medium
18

19
    ColumnLayout
20 21 22 23 24 25
    {
        anchors.fill: parent

        BabeList
        {
            id: playlistsList
26

27 28
            Layout.fillHeight: true
            Layout.fillWidth: true
29

30
            headBar.visible: false
31 32
            holder.title: qsTr("There's not playlists")
            holder.body: qsTr("Create a new one and start adding tracks to it")
33 34

            model: playlistsView.playlistModel
35

36
            delegate: Maui.ListDelegate
37 38
            {
                id: delegate
39
                label: model.playlist
40 41 42 43

                Connections
                {
                    target: delegate
44 45
                    onClicked: playlistsList.currentIndex = index
                    onPressAndHold:
46 47
                    {
                        playlistsList.currentIndex = index
Camilo higuita's avatar
Camilo higuita committed
48
                        insert()
49 50 51
                    }
                }
            }
52 53
        }

54 55

        Maui.TextField
56 57
        {
            Layout.fillWidth: true
58 59 60 61
            id: newPlaylistField
            color: Kirigami.Theme.textColor
            placeholderText: qsTr("New playlist")
            onAccepted:
62
            {
63 64 65
                addPlaylist()
                playlistsView.playlistList.addTrack(playlistsList.listView.currentIndex, tracks)
                clear()
66 67
            }

68
            actions.data: ToolButton
69
            {
70
                icon.name: "checkbox"
71
                icon.color: Kirigami.Theme.textColor
72 73
                onClicked: addPlaylist()
            }
74 75 76
        }
    }

77 78
    onAccepted:
    {
79
        if(newPlaylistField.text.length)
80 81
            addPlaylist()

Camilo higuita's avatar
Camilo higuita committed
82 83 84 85 86
        insert()
    }

    function insert()
    {
87 88
        playlistsView.playlistList.addTrack(playlistsList.listView.currentIndex, tracks)
        close()
89
    }
90

91
    function addPlaylist()
92
    {
93 94 95
        if (newPlaylistField.text)
        {
            var title = newPlaylistField.text.trim()
96
            if( playlistsView.playlistList.insertAt(title, 0))
97
            {
98 99
                playlistsList.listView.currentIndex = 0
                playlistsList.listView.positionViewAtBeginning()
100 101
            }

102
            newPlaylistField.clear()
103
        }
104
    }
105

106
}