~music-app-dev/music-app/remix

« back to all changes in this revision

Viewing changes to MusicSearch.qml

* Remove lastfm, search and settings.

Approved by Ubuntu Phone Apps Jenkins Bot, Victor Thompson.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2013, 2014
3
 
 *      Andrew Hayzen <ahayzen@gmail.com>
4
 
 *      Daniel Holm <d.holmen@gmail.com>
5
 
 *      Victor Thompson <victor.thompson@gmail.com>
6
 
 *
7
 
 * This program is free software; you can redistribute it and/or modify
8
 
 * it under the terms of the GNU General Public License as published by
9
 
 * the Free Software Foundation; version 3.
10
 
 *
11
 
 * This program is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 * GNU General Public License for more details.
15
 
 *
16
 
 * You should have received a copy of the GNU General Public License
17
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 
 */
19
 
 
20
 
import QtMultimedia 5.0
21
 
import QtQuick 2.3
22
 
import Ubuntu.Components 1.1
23
 
import Ubuntu.Components.ListItems 1.0 as ListItem
24
 
import Ubuntu.Components.Popups 1.0
25
 
import Ubuntu.MediaScanner 0.1
26
 
import Ubuntu.Thumbnailer 0.1
27
 
import QtQuick.LocalStorage 2.0
28
 
import "playlists.js" as Playlists
29
 
import "common"
30
 
import "common/ListItemActions"
31
 
 
32
 
Item {
33
 
    id: sheetItem
34
 
 
35
 
    property alias sheet: sheetComponent
36
 
    property bool sheetVisible: false
37
 
 
38
 
    Component {
39
 
        id: sheetComponent
40
 
 
41
 
        // Sheet to search for music tracks
42
 
         DefaultSheet {
43
 
             id: searchTrack
44
 
             title: i18n.tr("Search")
45
 
             contentsHeight: units.gu(80)
46
 
 
47
 
             onDoneClicked: PopupUtils.close(searchTrack)
48
 
 
49
 
             Component.onCompleted: {
50
 
                 searchField.forceActiveFocus()
51
 
             }
52
 
 
53
 
             onVisibleChanged: {
54
 
                 if (visible) {
55
 
                     musicToolbar.setSheet(searchTrack)
56
 
                     sheetVisible = true
57
 
                 }
58
 
                 else {
59
 
                     musicToolbar.removeSheet(searchTrack)
60
 
                     sheetVisible = false
61
 
                 }
62
 
             }
63
 
 
64
 
             TextField {
65
 
                 id: searchField
66
 
                 anchors {
67
 
                     left: parent.left;
68
 
                     leftMargin: units.gu(2);
69
 
                     top: parent.top;
70
 
                     right: parent.right;
71
 
                     rightMargin: units.gu(2);
72
 
                 }
73
 
 
74
 
                 width: parent.width/1.5
75
 
                 placeholderText: i18n.tr("Search")
76
 
                 hasClearButton: true
77
 
                 highlighted: true
78
 
                 focus: true
79
 
                 inputMethodHints: Qt.ImhNoPredictiveText
80
 
                 //canPaste: true // why work, you do not, hrm?
81
 
 
82
 
                 // search icon
83
 
                 primaryItem: Image {
84
 
                     height: parent.height*0.5
85
 
                     width: parent.height*0.5
86
 
                     anchors.verticalCenter: parent.verticalCenter
87
 
                     anchors.verticalCenterOffset: -units.gu(0.2)
88
 
                     source: Qt.resolvedUrl("images/search.svg")
89
 
                 }
90
 
 
91
 
                 onTextChanged: {
92
 
                     searchTimer.start() // start the countdown, baby!
93
 
                 }
94
 
 
95
 
                 // Provide a small pause before search
96
 
                 Timer {
97
 
                     id: searchTimer
98
 
                     interval: 500
99
 
                     repeat: false
100
 
                     onTriggered: {
101
 
                         songsSearchModel.query = searchField.text;
102
 
                         searchActivity.running = true // start the activity indicator
103
 
 
104
 
                         indicatorTimer.start()
105
 
                     }
106
 
                 }
107
 
                 // and onother one for the indicator
108
 
                 Timer {
109
 
                     id: indicatorTimer
110
 
                     interval: 500
111
 
                     repeat: false
112
 
                     onTriggered: {
113
 
                         searchActivity.running = false
114
 
                     }
115
 
                 }
116
 
 
117
 
                 // Indicator to show search activity
118
 
                 ActivityIndicator {
119
 
                     id: searchActivity
120
 
                     anchors {
121
 
                         verticalCenter: searchField.verticalCenter;
122
 
                         right: searchField.right;
123
 
                         rightMargin: units.gu(1)
124
 
                     }
125
 
                     running: false
126
 
                 }
127
 
             }
128
 
 
129
 
             Rectangle {
130
 
                 width: parent.width
131
 
                 height: parent.height
132
 
                 color: "transparent"
133
 
                 visible: searchField.text
134
 
                 clip: true
135
 
                 anchors {
136
 
                     top: searchField.bottom
137
 
                     bottom: parent.bottom
138
 
                     left: parent.left
139
 
                     right: parent.right
140
 
                 }
141
 
 
142
 
                 // show each playlist and make them chosable
143
 
                 ListView {
144
 
                     id: searchTrackView
145
 
                     objectName: "searchtrackview"
146
 
                     width: parent.width
147
 
                     height: parent.width
148
 
                     model: SongsSearchModel {
149
 
                        id: songsSearchModel
150
 
                        store: musicStore
151
 
                     }
152
 
 
153
 
                     onMovementStarted: {
154
 
                         searchTrackView.forceActiveFocus()
155
 
                     }
156
 
 
157
 
                     // Requirements for ListItemWithActions
158
 
                     property var selectedItems: []
159
 
 
160
 
                     signal clearSelection(bool closeSelection)
161
 
                     signal selectAll()
162
 
 
163
 
                     onClearSelection: {
164
 
                         selectedItems = []
165
 
 
166
 
                         if (closeSelection || closeSelection === undefined) {
167
 
                             state = "normal"
168
 
                         }
169
 
                     }
170
 
                     onSelectAll: {
171
 
                         for (var i=0; i < model.count; i++) {
172
 
                             if (selectedItems.indexOf(i) === -1) {
173
 
                                 selectedItems.push(i)
174
 
                             }
175
 
                         }
176
 
                     }
177
 
                     onVisibleChanged: {
178
 
                         if (!visible) {
179
 
                             clearSelection(true)
180
 
                         }
181
 
                     }
182
 
                     delegate: ListItemWithActions {
183
 
                            id: search
184
 
                            color: "transparent"
185
 
                            objectName: "playlist"
186
 
                            width: parent.width
187
 
                            height: styleMusic.common.itemHeight
188
 
 
189
 
                            rightSideActions: [
190
 
                                AddToQueue {
191
 
 
192
 
                                },
193
 
                                AddToPlaylist {
194
 
 
195
 
                                }
196
 
                            ]
197
 
 
198
 
                            onItemClicked: {
199
 
                                console.debug("Debug: "+title+" added to queue")
200
 
                                // now play this track, but keep current queue
201
 
                                trackQueue.append(model)
202
 
                                trackQueueClick(trackQueue.model.count - 1);
203
 
                                onDoneClicked: PopupUtils.close(searchTrack)
204
 
                            }
205
 
 
206
 
                            MusicRow {
207
 
                                covers: [{art: model.art}]
208
 
                                column: Column {
209
 
                                    spacing: units.gu(1)
210
 
                                    Label {
211
 
                                        id: trackArtist
212
 
                                        color: styleMusic.common.subtitle
213
 
                                        fontSize: "x-small"
214
 
                                        text: model.author
215
 
                                    }
216
 
                                    Label {
217
 
                                        id: trackTitle
218
 
                                        color: styleMusic.common.music
219
 
                                        fontSize: "small"
220
 
                                        objectName: "tracktitle"
221
 
                                        text: model.title
222
 
                                    }
223
 
                                    Label {
224
 
                                        id: trackAlbum
225
 
                                        color: styleMusic.common.subtitle
226
 
                                        fontSize: "xx-small"
227
 
                                        text: model.album
228
 
                                    }
229
 
                                }
230
 
                            }
231
 
                     }
232
 
                 }
233
 
             }
234
 
         }
235
 
    }
236
 
}