Ubuntu Pastebin

Paste from ogra at Mon, 9 Mar 2015 11:35:57 +0000

Download as text
  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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
import QtQuick 2.0
import Ubuntu.Components 1.1
import QtMultimedia 5.2
//import Ubuntu.Components.Pickers 1.0
import Ubuntu.Components.ListItems 1.0 as ListItem

MainView {
    objectName: "mainView"
    applicationName: "lautfm.ogra"

    useDeprecatedToolbar: false

    width: units.gu(100)
    height: units.gu(75)
    backgroundColor: UbuntuColors.coolGrey

    property string running_stream: ""
    property string list_source: "http://api.laut.fm/stations?limit=300"
    property string list_query: "$"
    property string current_source: ""
    property string current_query: ""
    property string playing_station: ""
    property int track_length: 0
    property int track_time_sec: 0
    property int track_offset: 0

    ListModel {
        id: currentSongModel
    }

    PageStack {
            id: pageStack
            Component.onCompleted: push(rootPage)
    Page {
        id: rootPage
        title: i18n.tr("laut.fm")

        Component.onCompleted: stationlist.refresh()

        JSONListModel {
            id: stationlist
            source: list_source
            query: list_query
        }

        JSONListModel {
            id: current
            source: current_source
            query: current_query
            onListModelUpdateChanged: {
                title.text = "Title: <b>" + model.get(0).title + "</b>";
                artist.text = "Artist: <b>" + model.get(0).artist.name + "</b>";
                if (model.get(0).length != track_length) {
                    track_length = model.get(0).length;
                    track_time_sec = 0;
                }
            }
        }

        function setCurrent() {
            if (running_stream.length != 0) {
                current_source = "http://api.laut.fm/station/" + playing_station + "/current_song";
                current_query = "$";
                current.refresh();
            }
        }

        function toggleButton() {
            if (player.playbackState == 0 && running_stream.length != 0) {
                setCurrent();
                player.play();
                playbtn.source = "pause.png";
                refreshTimer.start();
                playTimer.start();
            }
            else {
                player.stop();
                playbtn.source = "play.png";
                refreshTimer.stop();
                playTimer.stop();
            }
        }

        function doSearch() {
            rootPage.state = "default"
            if (searchfield.text == "") {
                list_source = "http://api.laut.fm/stations?limit=300"
                list_query = "$"
            }
            else {
                list_source = "http://api.laut.fm/search/stations?query=" + searchfield.text + "&limit=1000"
                list_query = "$...station"
            }
            stationlist.refresh()
            searchfield.text = ""
        }

        Audio {
            id: player
            source: running_stream
        }

        function pad(number, length) {
            var str = '' + number;
            while (str.length < length) {
            str = '0' + str;
            }
            return str;
        }

        function normalize(seconds) {
            var m = Math.floor((seconds % 3600) / 60);
            var s = seconds % 60;
            var str = m + ":" + pad(s, 2);
            return str;
        }

        head {
            sections {
                model: ["last", "favorites", "genres", "all"]
            }
        }

        state: "default"
        states: [
            PageHeadState {
                name: "default"
                head: rootPage.head
                actions: Action {
                    iconName: "search"
                    onTriggered: rootPage.state = "search"
                }
            },
            PageHeadState {
                id: headerState
                name: "search"
                head: rootPage.head
                actions: [
                    Action {
                        id: searchAction
                        //iconSource: "./lautfm-trans.png"
                        iconName: "search"
                        onTriggered: {
                            rootPage.state = "default"
                        }
                    }
                ]
                backAction: Action {
                    id: leaveSearchAction
                    text: "back"
                    iconName: "back"
                    onTriggered: rootPage.state = "default"
                }
                contents: TextField {
                    id: searchfield
                    placeholderText: "artist/song/station ..."
                    onAccepted: rootPage.doSearch(searchfield)
                }
            }
        ]

        Component {
            id: stationComponent
            ListItem.Standard {
                iconSource: images.station_80x80
                text: "<b>" + name + "</b><br>" + description
                onClicked: {
                    player.stop();
                    running_stream = stream_url;
                    stationname.text = "Station: <b>" + name + "</b>";
                    playing_station = name;
                    track_time_sec = 0;
                    rootPage.toggleButton();
                }
            }
        }

//        Component {
//            id: genreComponent
//            ListItem.Standard {
//                iconSource: images.station_80x80
//                text: "<b>" + name + "</b><br>" + description
//                onClicked: {
//                    player.stop();
//                    running_stream = stream_url;
//                    stationname.text = "Station: <b>" + name + "</b>";
//                    rootPage.toggleButton();
//                }
//            }
//        }

        Column {
            id: content
            anchors {
                //fill: parent
                top: parent.top
                left: parent.left
                right: parent.right
                bottom: control.top
            }
            UbuntuListView {
                id: myView
                //height: parent.height
                width: parent.width
                clip: true
                model: stationlist.model
                cacheBuffer: contentHeight

                //delegate: listSearch? searchComponent : stationComponent
                delegate: stationComponent
            }
        }

//        Column{
//            id: playerview
//            anchors {
//                bottom: control.top
//                top: content.bottom
//                left: parent.left
//                right: parent.right
//            }
//            height: units.gu(1)
//            width: parent.width
//            //visible: false
//        }

        Column{
            id: control
            anchors {
                bottom: parent.bottom
                left: parent.left
                right: parent.right
             }
            Rectangle {
                width: parent.width
                height: units.gu(10)
                color: "black"
                opacity: 0.9
                Label {
                   id: stationname
                   anchors.left: parent.left
                   anchors.top: parent.top
                   anchors.leftMargin: units.gu(12)
                   anchors.topMargin: units.gu(2)
                   text: "<b>Please select a station</b>"
                }
                Label {
                   id: artist
                   anchors.left: parent.left
                   anchors.top: parent.top
                   anchors.leftMargin: units.gu(12)
                   anchors.topMargin: units.gu(4)
                   text: "Artist:"
                }
                Label {
                   id: title
                   anchors.left: parent.left
                   anchors.top: parent.top
                   anchors.leftMargin: units.gu(12)
                   anchors.topMargin: units.gu(6)
                   text: "Title:"
                }
                Label {
                   id: time
                   anchors.right: parent.right
                   anchors.bottom: parent.bottom
                   anchors.rightMargin: units.gu(1)
                   font.pixelSize: units.gu(1)
                   text: rootPage.normalize(track_time_sec) + " - " + rootPage.normalize(track_length)
                }

                MouseArea {
                   width: units.gu(10)
                   height: units.gu(10)
                   anchors.leftMargin: units.gu(2)
                   id: button
                   Image {
                       width: units.gu(8)
                       height: units.gu(8)
                       anchors.verticalCenter: parent.verticalCenter
                       anchors.left: parent.left
                       anchors.leftMargin: units.gu(2)
                       id: playbtn
                       source: "play.png"
                   }
                   onClicked: {
                       rootPage.toggleButton();
                   }
                }
            }
            Timer {
                id: refreshTimer
                interval: 10000; running: false; repeat: true;
                onTriggered: rootPage.setCurrent();
            }
            Timer {
                id: playTimer
                running: false; repeat: true;
                onTriggered: {
                    track_time_sec++;
                    console.warn(track_time_sec + " length: " + track_length);
                }
            }
           // playMusic.source = "http://stream.laut.fm/telecaster";
        }
    }
    }
}
Download as text