/
ArtistSelect.qml
203 lines (172 loc) · 6.34 KB
/
ArtistSelect.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import QtQuick 2.0
import Sailfish.Silica 1.0
import QtSparql 1.0
import harbour.sirensong 1.0
import "functions.js" as UIFunctions
Column {
id: root
property Item _currActiveGroup
property Item _currActiveAlbum
//Top Level Menu
Repeater {
model: queryModel
Item {
id: artistItem
width: parent.width
height: Theme.itemSizeSmall + ((groupResultsList != null) && (active == true) ? groupResultsList.height : 0)
property bool active
property Item groupResultsList
property alias pressed: mouseArea.pressed
property alias containsMouse: mouseArea.containsMouse
property bool highlighted: pressed && containsMouse || artistItem.active
property int baseHeight: Theme.itemSizeSmall
property string selectedArtist
MouseArea {
id: mouseArea
anchors.fill: parent
onClicked: activate(artistItem)
Rectangle {
width: parent.width
height: parent.height
color: Theme.highlightBackgroundColor
opacity: highlighted ? 0.1 : 0.3
}
Item{
height: Theme.itemSizeSmall
x:30
Label { text: artistName; anchors.verticalCenter: parent.verticalCenter }
}
}
function activate(artistItem)
{
if(!artistItem.active)
{
if(root._currActiveGroup != null)
{
deactivate(root._currActiveGroup);
}
groupResultsList = albumListComponent.createObject(artistItem);
groupResultsList.open(artistName);
artistItem.active = true;
artistItem.selectedArtist = artistName;
root._currActiveGroup = artistItem;
}
else
{
deactivate(artistItem)
}
}
function deactivate(artistItem)
{
artistItem.active = false;
artistItem.groupResultsList.close();
artistItem.selectedArtist = "";
}
}
}
//Empty List
ListModel {
id: emptyModel
}
SparqlListModel {
id: queryModel
property string filterProperty: 'title'
// create a new SparqlConnection for the queryModel
connection: SparqlConnection {
id: sparqlConnection
driver: "QTRACKER_DIRECT"
}
// This is the query for the model
query: "SELECT ?artistName ?albumArtist " +
"WHERE { ?album a nmm:MusicAlbum . " +
"?album nmm:albumArtist ?albumArtist . " +
"?albumArtist nmm:artistName ?artistName " +
"} GROUP BY ?artistName ORDER BY ASC(?artistName) "
}
Component {
id: albumListComponent
TieredMenu {
width: root.width
subListComponent: songListComponent
activeParentItem: root._currActiveAlbum
menuListQueryModel: SparqlListModel {
id: albumListQueryModel
connection: SparqlConnection {
driver: "QTRACKER_DIRECT"
}
function filter(filterText)
{
albumListQueryModel.query = "SELECT ?menuText " + "WHERE { ?album a nmm:MusicAlbum . " +
"?album nmm:albumArtist ?albumArtist . " +
"?album nmm:albumTitle ?menuText. " +
"?albumArtist nmm:artistName ?artistName " +
"FILTER (?artistName = '"+ filterText +"') "+
"} "
albumListQueryModel.reload()
}
}
}
}
Component {
id: songListComponent
ColumnView {
id: songListView
itemHeight: Theme.itemSizeSmall
model: songListQueryModel
x: -parent.x
y: Theme.itemSizeSmall
width: root.width
property bool active: false
Behavior on implicitHeight
{
NumberAnimation { duration: 200 }
}
delegate: SongItem {
width: parent.width
id: songList
}
function open(albumTitle)
{
active = true;
songListQueryModel.filter(albumTitle)
songListView.model = songListQueryModel
}
function close()
{
songListView.model = emptyModel
active = false;
}
//Empty List
ListModel {
id: emptyModel
}
SparqlListModel {
id: songListQueryModel
query: ""
connection: SparqlConnection {
id: sparqlConnection
driver: "QTRACKER_DIRECT"
}
function filter(filterText)
{
songListQueryModel.query = "SELECT ?title ?artist ?url ?length ?filename " +
"WHERE { ?song a nmm:MusicPiece . " +
"?song nie:url ?url . " +
"OPTIONAL { ?song nie:title ?title } " +
"?song nfo:duration ?length . " +
"?song nfo:fileName ?filename . " +
"?song nmm:trackNumber ?tracknumber . "+
"?song nmm:musicAlbum ?album . " +
"?album nmm:albumArtist ?albumArtist . " +
"?album nmm:albumTitle ?albumTitle . " +
"?song nmm:performer ?aName . "+
"?aName nmm:artistName ?artist "+
"FILTER (?albumTitle = '"+ filterText +"' &&
?artist = '"+ _currActiveGroup.selectedArtist +"') "+
"} " +
"GROUP BY ?song ORDER BY ASC(?tracknumber)"
}
}
}
}
}