SearchSuggestions.qml 3.27 KB
Newer Older
1
import QtQuick 2.0
2
import QtQuick.Controls 2.10
Camilo Higuita's avatar
Camilo Higuita committed
3
import org.kde.mauikit 1.0 as Maui
4 5

import "../../view_models"
Camilo Higuita's avatar
Camilo Higuita committed
6
import "../../db/Queries.js" as Q
7

Camilo higuita's avatar
Camilo higuita committed
8
Maui.Popup
9 10
{
    id: searchSuggestionsRoot
11
    property alias model : suggestionsList.model
12
    maxHeight: Maui.Style.unit * 700
Camilo higuita's avatar
Camilo higuita committed
13 14 15
    heightHint: 0.5

    verticalAlignment: Qt.AlignBottom
Camilo Higuita's avatar
Camilo Higuita committed
16

17 18 19 20
    BabeList
    {
        id: suggestionsList
        anchors.fill: parent
21
        headBar.visible: false
22 23
        model: ListModel {id: suggestionsModel}

24
        section.property : "type"
25
        section.delegate: Maui.LabelDelegate
26 27 28
        {
            label: section
            isSection: true
29
            width: parent.width
30 31
        }

32
        delegate: Maui.LabelDelegate
33 34 35 36 37 38 39 40 41 42 43
        {
            id: delegate
            label: suggestion

            Connections
            {
                target: delegate

                onClicked:
                {
                    suggestionsList.currentIndex = index
Camilo Higuita's avatar
Camilo Higuita committed
44 45
                    runSearch(suggestionsList.model.get(index).suggestion)
                    close()
46 47 48 49 50
                }
            }
        }
    }

Camilo higuita's avatar
Camilo higuita committed
51
//    onOpened: updateSuggestions()
Camilo Higuita's avatar
Camilo Higuita committed
52

Camilo higuita's avatar
Camilo higuita committed
53 54 55
//    function updateSuggestions()
//    {
//        if(!visible) open()
56

Camilo higuita's avatar
Camilo higuita committed
57
////        suggestionsList.clearTable()
58

Camilo higuita's avatar
Camilo higuita committed
59 60
//        var qq = bae.loadSetting("QUERIES", "BABE", {})
//        savedQueries = qq.split(",")
61

Camilo higuita's avatar
Camilo higuita committed
62 63 64
//        if(searchInput.text.length>3 && searchInput.text.indexOf(":") < 0)
//        {
//            //            var similar = bae.get('select distinct * from tracks where title LIKE "%'+searchInput.text+'%" or artist LIKE "%'+searchInput.text+'%" or album LIKE "%'+searchInput.text+'%" limit 5')
Camilo Higuita's avatar
Camilo Higuita committed
65

Camilo higuita's avatar
Camilo higuita committed
66 67 68
//            var similarArtist = bae.get('select distinct * from tracks where artist LIKE "%'+searchInput.text+'%" limit 5')
//            var similarAlbum= bae.get('select distinct * from tracks where album LIKE "%'+searchInput.text+'%" limit 5')
//            var similarTracks = bae.get('select distinct * from tracks where title LIKE "%'+searchInput.text+'%" limit 5')
Camilo Higuita's avatar
Camilo Higuita committed
69

Camilo higuita's avatar
Camilo higuita committed
70
//            var checkList = []
Camilo Higuita's avatar
Camilo Higuita committed
71 72


Camilo higuita's avatar
Camilo higuita committed
73 74 75 76 77 78
//            for(var i in similarArtist)
//                if(checkList.indexOf("artist: "+similarArtist[i].artist) < 0)
//                {
//                    checkList.push("artist: "+similarArtist[i].artist)
//                    suggestionsList.model.append({suggestion: "artist: "+similarArtist[i].artist, type: "Artists"})
//                }
Camilo Higuita's avatar
Camilo Higuita committed
79

Camilo higuita's avatar
Camilo higuita committed
80 81 82 83 84 85
//            for(i in similarAlbum)
//                if(checkList.indexOf("album: "+similarAlbum[i].album) < 0)
//                {
//                    checkList.push("album: "+similarAlbum[i].album)
//                    suggestionsList.model.append({suggestion: "album: "+similarAlbum[i].album, type: "Albums"})
//                }
Camilo Higuita's avatar
Camilo Higuita committed
86

Camilo higuita's avatar
Camilo higuita committed
87 88 89 90 91 92 93
//            for(i in similarTracks)
//                if(checkList.indexOf("title: "+similarTracks[i].title) < 0)
//                {
//                    checkList.push("title: "+similarTracks[i].title)
//                    suggestionsList.model.append({suggestion: "title: "+similarTracks[i].title, type: "Tracks"})
//                }
//        }
Camilo Higuita's avatar
Camilo Higuita committed
94

Camilo higuita's avatar
Camilo higuita committed
95 96 97 98
//        if(savedQueries.length>0)
//            for(i=0; i < 3; i++)
//                if(i < savedQueries.length )
//                    suggestionsList.model.append({suggestion: savedQueries[i], type: "Recent"})
Camilo Higuita's avatar
Camilo Higuita committed
99

Camilo higuita's avatar
Camilo higuita committed
100
//    }
101
}