~lool/music-app/singleton

« back to all changes in this revision

Viewing changes to music-app.qml

  • Committer: Tarmac
  • Author(s): Victor Thompson, Daniel Holm
  • Date: 2013-09-22 19:36:51 UTC
  • mfrom: (100.3.9 use-mediascanner2-orig)
  • Revision ID: tarmac-20130922193651-37438m02493277nx
* use Grilo for accessing metadata
* fixes related to making this transition. Fixes: https://bugs.launchpad.net/bugs/1200368, https://bugs.launchpad.net/bugs/1200513.

Approved by Ubuntu Phone Apps Jenkins Bot, Daniel Holm.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import Ubuntu.Components.Popups 0.1
23
23
import Ubuntu.Components.ListItems 0.1 as ListItem
24
24
import Ubuntu.Unity.Action 1.0 as UnityActions
25
 
import org.nemomobile.folderlistmodel 1.0
 
25
import org.nemomobile.grilo 0.1
26
26
import QtMultimedia 5.0
27
27
import QtQuick.LocalStorage 2.0
28
28
import QtQuick.XmlListModel 2.0
143
143
            Settings.setSetting("initialized", "true") // setting to make sure the DB is there
144
144
            //Settings.setSetting("scrobble", "0") // default state of shuffle
145
145
            //Settings.setSetting("scrobble", "0") // default state of scrobble
146
 
            Settings.setSetting("currentfolder", folderModel.homePath() + "/Music")
147
146
        }
148
147
        Library.reset()
149
148
        Library.initialize()
150
 
        Settings.setSetting("currentfolder", folderModel.path)
151
 
        folderScannerModel.path = folderModel.path
152
 
        folderScannerModel.nameFilters = ["*.mp3","*.ogg","*.flac","*.wav","*.oga"]
153
 
        timer.start()
154
149
 
155
150
        // initialize playlists
156
151
        Playlists.initializePlaylists()
168
163
 
169
164
    // VARIABLES
170
165
    property string musicName: i18n.tr("Music")
171
 
    property string musicDir: ""
172
166
    property string appVersion: '0.6'
173
167
    property bool isPlaying: false
174
168
    property bool random: false
182
176
    property string chosenTitle: ""
183
177
    property string chosenArtist: ""
184
178
    property string chosenAlbum: ""
 
179
    property string chosenCover: ""
185
180
    property int chosenIndex: 0
186
181
 
187
182
    property string currentArtist: ""
195
190
    property string currentCover: ""
196
191
    property string currentCoverSmall: currentCover === "" ?
197
192
                                           "images/cover_default_icon.png" :
198
 
                                           "image://cover-art/" + currentCover
 
193
                                            currentCover
199
194
    property string currentCoverFull: currentCover !== "" ?
200
 
                                          "image://cover-art-full/" + currentCover :
 
195
                                          currentCover :
201
196
                                          "images/cover_default.png"
202
197
    property bool queueChanged: false
203
198
 
405
400
            file = file.slice(7, file.length)
406
401
        }
407
402
 
408
 
        currentCover = Library.hasCover(file) ? file : ""
 
403
        currentCover = trackQueue.model.get(currentIndex).cover !== "" ? trackQueue.model.get(currentIndex).cover : "images/cover_default_icon.png"
409
404
    }
410
405
 
411
406
    // undo removal function to use when swipe to remove
547
542
        }
548
543
    }
549
544
 
 
545
    GriloModel {
 
546
        id: griloModel
 
547
 
 
548
        source: GriloBrowse {
 
549
            id: browser
 
550
            source: "grl-mediascanner"
 
551
            registry: registry
 
552
            metadataKeys: [GriloBrowse.Title]
 
553
            typeFilter: [GriloBrowse.Audio]
 
554
            Component.onCompleted: {
 
555
                console.log(browser.supportedKeys);
 
556
                console.log(browser.slowKeys);
 
557
                refresh();
 
558
                console.log("Refreshing");
 
559
            }
 
560
 
 
561
            onAvailableChanged: {
 
562
                console.log("Available ? " + available);
 
563
                if (available === true) {
 
564
                    console.log("griloModel.count " + griloModel.count)
 
565
                }
 
566
            }
 
567
            onBaseMediaChanged: refresh();
 
568
        }
 
569
 
 
570
        onCountChanged: {
 
571
            if (count > 0) {
 
572
                timer.start()
 
573
                for (var i = timer.counted; i < griloModel.count; i++)
 
574
                {
 
575
                    var file = griloModel.get(i).url.toString()
 
576
                    if (file.indexOf("file://") == 0)
 
577
                    {
 
578
                        file = file.slice(7, file.length)
 
579
                    }
 
580
                    console.log("Artist:"+ griloModel.get(i).artist + ", Album:"+griloModel.get(i).album + ", Title:"+griloModel.get(i).title + ", File:"+file + ", Cover:"+griloModel.get(i).thumbnail);
 
581
                    Library.setMetadata(file, griloModel.get(i).title, griloModel.get(i).artist, griloModel.get(i).album, griloModel.get(i).thumbnail, griloModel.get(i).year, "1", griloModel.get(i).duration)
 
582
                }
 
583
            }
 
584
 
 
585
        }
 
586
    }
 
587
 
 
588
    GriloRegistry {
 
589
        id: registry
 
590
 
 
591
        Component.onCompleted: {
 
592
            console.log("Registry is ready");
 
593
            loadAll();
 
594
        }
 
595
    }
 
596
 
550
597
    LibraryListModel {
551
598
        id: libraryModel
552
599
    }
569
616
        id: recentAlbumTracksModel
570
617
    }
571
618
 
572
 
    FolderListModel {
573
 
        id: folderModel
574
 
        showDirectories: true
575
 
        filterDirectories: false
576
 
        nameFilters: ["*.mp3","*.ogg","*.flac","*.wav","*.oga"] // file types supported.
577
 
        path: homePath() + "/Music"
578
 
        onPathChanged: {
579
 
            console.log("Path changed: " + folderModel.path)
580
 
        }
581
 
    }
582
 
 
583
 
    FolderListModel {
584
 
        id: folderScannerModel
585
 
        property int count: 0
586
 
        readsMediaMetadata: true
587
 
        isRecursive: true
588
 
        showDirectories: true
589
 
        filterDirectories: false
590
 
        nameFilters: ["*.mp3","*.ogg","*.flac","*.wav","*.oga"] // file types supported.
591
 
        onPathChanged: {
592
 
            console.log("Scanner Path changed: " + folderModel.path)
593
 
        }
594
 
    }
595
 
 
596
619
    // list of tracks on startup. This is just during development
597
620
    LibraryListModel {
598
621
        id: trackQueue
620
643
 
621
644
    // list of single tracks
622
645
    ListModel {
623
 
        id: singleTracks
 
646
        id: singleTracksgriloMo
624
647
    }
625
648
 
626
649
    // create the listmodel to use for playlists
638
661
        id: undo
639
662
    }
640
663
 
641
 
 
642
 
    Column {
643
 
        Repeater {
644
 
            id: filelist
645
 
            width: parent.width
646
 
            height: parent.height - units.gu(8)
647
 
            anchors.top: parent.top
648
 
            model: folderScannerModel
649
 
 
650
 
            Component {
651
 
                id: fileScannerDelegate
652
 
                Rectangle {
653
 
                    Component.onCompleted: {
654
 
                        if (!model.isDir) {
655
 
                            console.log("Debug: Scanner fileDelegate onComplete")
656
 
                            if ("" === trackCover) {
657
 
                                Library.setMetadata(filePath, trackTitle, trackArtist, trackAlbum, "", trackYear, trackNumber, trackLength)
658
 
                            } else {
659
 
                                Library.setMetadata(filePath, trackTitle, trackArtist, trackAlbum, "image://cover-art/" + filePath, trackYear, trackNumber, trackLength)
660
 
                            }
661
 
                        }
662
 
                    }
663
 
                }
664
 
            }
665
 
        }
666
 
    }
667
 
 
668
664
    Timer {
669
665
        id: timer
670
666
        interval: 200; repeat: true
674
670
 
675
671
        onTriggered: {
676
672
            console.log("Counted: " + counted)
677
 
            console.log("filelist.count: " + filelist.count)
678
 
            if (counted === filelist.count) {
 
673
            console.log("griloModel.count: " + griloModel.count)
 
674
            if (counted === griloModel.count) {
679
675
                console.log("MOVING ON")
680
676
                Library.writeDb()
681
677
                libraryModel.populate()
690
686
                    libraryEmpty.visible = true;
691
687
                }
692
688
            }
693
 
            counted = filelist.count
 
689
            counted = griloModel.count
694
690
        }
695
691
    }
696
692
 
717
713
                    onClicked: {
718
714
                        console.debug("Debug: Add track to queue: " + chosenTitle)
719
715
                        PopupUtils.close(trackPopover)
720
 
                        trackQueue.model.append({"title": chosenTitle, "artist": chosenArtist, "file": chosenTrack, "album": chosenAlbum})
 
716
                        trackQueue.model.append({"title": chosenTitle, "artist": chosenArtist, "file": chosenTrack, "album": chosenAlbum, "cover": chosenCover})
721
717
                    }
722
718
                }
723
719
                ListItem.Standard {
1093
1089
    MusicaddtoPlaylist {
1094
1090
        id: addtoPlaylist
1095
1091
    }
 
1092
 
1096
1093
    // Converts an duration in ms to a formated string ("minutes:seconds")
1097
1094
    function __durationToString(duration) {
1098
1095
        var minutes = Math.floor((duration/1000) / 60);