~vthompson/music-app/fixes-1308042-album-text-alignment

« back to all changes in this revision

Viewing changes to music-app.qml

  • Committer: Sergio Schvezov
  • Date: 2013-10-14 12:21:39 UTC
  • mfrom: (186 trunk)
  • mto: This revision was merged to the branch mainline in revision 189.
  • Revision ID: sergio.schvezov@canonical.com-20131014122139-ystbw5jp57g0ufo9
Merging trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
93
93
        onTriggered: player.stop()
94
94
    }
95
95
    Action {
 
96
        id: backAction
 
97
        text: i18n.tr("Back")
 
98
        keywords: i18n.tr("Go back to last page")
 
99
        onTriggered: musicToolbar.goBack();
 
100
    }
 
101
    Action {
96
102
        id: settingsAction
97
103
        text: i18n.tr("Settings")
98
104
        keywords: i18n.tr("Music Settings")
108
114
        onTriggered: Qt.quit()
109
115
    }
110
116
 
111
 
    actions: [nextAction, playsAction, prevAction, stopAction, settingsAction, quitAction]
 
117
    actions: [nextAction, playsAction, prevAction, stopAction, backAction, settingsAction, quitAction]
112
118
 
113
119
    // signal to open new URIs
114
120
    // TODO currently this only allows playing file:// URIs of known files
146
152
        }
147
153
    }
148
154
 
 
155
    // Design stuff
149
156
    Style { id: styleMusic }
150
 
 
151
157
    width: units.gu(50)
152
158
    height: units.gu(75)
 
159
 
 
160
    // RUn on startup
153
161
    Component.onCompleted: {
154
162
        customdebug("Version "+appVersion) // print the curren version
155
163
        customdebug("Arguments on startup: Debug: "+args.values.debug)
175
183
            // initialize settings
176
184
            console.debug("reset settings")
177
185
            Settings.setSetting("initialized", "true") // setting to make sure the DB is there
178
 
            //Settings.setSetting("scrobble", "0") // default state of shuffle
 
186
            Settings.setSetting("snaptrack", "1") // default state of snaptrack
 
187
            Settings.setSetting("shuffle", "0") // default state of shuffle
 
188
            Settings.setSetting("repeat", "0") // default state of repeat
179
189
            //Settings.setSetting("scrobble", "0") // default state of scrobble
180
190
        }
181
191
        Library.reset()
197
207
 
198
208
    // VARIABLES
199
209
    property string musicName: i18n.tr("Music")
200
 
    property string appVersion: '0.7'
 
210
    property string appVersion: '1.0'
201
211
    property bool isPlaying: false
202
212
    property bool random: false
203
213
    property bool scrobble: false
287
297
                console.log("trackQueue.count: " + trackQueue.model.count)
288
298
                currentIndex += direction
289
299
                player.source = Qt.resolvedUrl(trackQueue.model.get(currentIndex).file)
290
 
            } else if(direction === 1) {
 
300
            } else if(direction === 1 && Settings.getSetting("repeat") === "1") {
291
301
                console.log("currentIndex: " + currentIndex)
292
302
                console.log("trackQueue.count: " + trackQueue.model.count)
293
303
                currentIndex = 0
294
304
                player.source = Qt.resolvedUrl(trackQueue.model.get(currentIndex).file)
295
 
            } else if(direction === -1) {
 
305
            } else if(direction === -1 && Settings.getSetting("repeat") === "1") {
296
306
                console.log("currentIndex: " + currentIndex)
297
307
                console.log("trackQueue.count: " + trackQueue.model.count)
298
308
                currentIndex = trackQueue.model.count - 1
299
309
                player.source = Qt.resolvedUrl(trackQueue.model.get(currentIndex).file)
300
310
            }
 
311
            else
 
312
            {
 
313
                player.stop()
 
314
                return;
 
315
            }
 
316
 
301
317
            console.log("MediaPlayer statusChanged, currentIndex: " + currentIndex)
302
318
        }
303
319
        player.stop()  // Add stop so that if same song is selected it restarts
360
376
 
361
377
        console.debug(player.source, Qt.resolvedUrl(file))
362
378
 
363
 
        if (player.source == Qt.resolvedUrl(file))  // same file different pages what should happen then?
 
379
        // Clear the play queue and load the new tracks - if not trackQueue
 
380
        // Don't reload queue if model, query and parameters are the same
 
381
        // Same file different pages is treated as a new session
 
382
        if (libraryModel !== trackQueue &&
 
383
                (currentModel !== libraryModel ||
 
384
                    currentQuery !== libraryModel.query ||
 
385
                        currentParam !== libraryModel.param ||
 
386
                            queueChanged === true))
 
387
        {
 
388
                trackQueue.model.clear()
 
389
                addQueueFromModel(libraryModel)
 
390
        }
 
391
        else if (player.source == Qt.resolvedUrl(file))
364
392
        {
365
393
            if (play === false)
366
394
            {
380
408
                // Show the Now Playing page and make sure the track is visible
381
409
                nowPlaying.visible = true;
382
410
                nowPlaying.ensureVisibleIndex = index;
 
411
 
 
412
                musicToolbar.showToolbar();
383
413
            }
384
414
 
385
415
            return
386
416
        }
387
417
 
388
 
        // Clear the play queue and load the new tracks - if not trackQueue
389
 
        if (libraryModel !== trackQueue)
390
 
        {
391
 
            // Don't reload queue if model, query and parameters are the same
392
 
            if (currentModel !== libraryModel ||
393
 
                    currentQuery !== libraryModel.query ||
394
 
                        currentParam !== libraryModel.param ||
395
 
                            queueChanged === true)
396
 
            {
397
 
                trackQueue.model.clear()
398
 
                addQueueFromModel(libraryModel)
399
 
            }
400
 
        }
401
 
 
402
418
        // Current index must be updated before player.source
403
419
        currentModel = libraryModel
404
420
        currentQuery = libraryModel.query
428
444
            // Show the Now Playing page and make sure the track is visible
429
445
            nowPlaying.visible = true;
430
446
            nowPlaying.ensureVisibleIndex = index;
 
447
 
 
448
            musicToolbar.showToolbar();
431
449
        }
432
450
 
433
451
        return file
459
477
        undo.set(0, {"artist": artist, "title": title, "album": album, "path": file})
460
478
    }
461
479
 
462
 
    // random color for non-found cover art
463
 
    function get_random_color() {
464
 
        var letters = '0123456789ABCDEF'.split('');
465
 
        var color = '#';
466
 
        for (var i = 0; i < 6; i++ ) {
467
 
            color += letters[Math.round(Math.random() * 15)];
468
 
        }
469
 
        return color;
470
 
    }
471
 
 
472
480
    // WHERE THE MAGIC HAPPENS
473
481
    MediaPlayer {
474
482
        id: player
631
639
                    {
632
640
                        file = file.slice(7, file.length)
633
641
                    }
634
 
                    console.log("Artist:"+ griloModel.get(i).artist + ", Album:"+griloModel.get(i).album + ", Title:"+griloModel.get(i).title + ", File:"+file + ", Cover:"+griloModel.get(i).thumbnail + ", Number:"+griloModel.get(i).trackNumber + ", Genre:"+griloModel.get(i).genre);
 
642
                    //console.log("Artist:"+ griloModel.get(i).artist + ", Album:"+griloModel.get(i).album + ", Title:"+griloModel.get(i).title + ", File:"+file + ", Cover:"+griloModel.get(i).thumbnail + ", Number:"+griloModel.get(i).trackNumber + ", Genre:"+griloModel.get(i).genre);
635
643
                    Library.setMetadata(file, griloModel.get(i).title, griloModel.get(i).artist, griloModel.get(i).album, griloModel.get(i).thumbnail, griloModel.get(i).year, griloModel.get(i).trackNumber, griloModel.get(i).duration, griloModel.get(i).genre)
636
644
                }
637
645
            }
838
846
                             // add the new playlist to the tab
839
847
                             var index = Playlists.getID(); // get the latest ID
840
848
                             playlistModel.append({"id": index, "name": playlistName.text, "count": "0"})
 
849
                             PopupUtils.close(dialogueNewPlaylist)
841
850
                         }
842
851
                         else {
843
852
                             console.debug("Debug: Something went wrong: "+newList)
844
853
                             newplaylistoutput.visible = true
845
854
                             newplaylistoutput.text = i18n.tr("Error: "+newList)
846
855
                         }
847
 
 
848
 
                         PopupUtils.close(dialogueNewPlaylist)
849
856
                     }
850
857
                     else {
851
858
                         newplaylistoutput.visible = true