1/*
2 * Copyright (C) 2019
3 *      Jean-Luc Barriere <jlbarriere68@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18import QtQuick 2.9
19import QtQuick.Controls 2.2
20import NosonApp 1.0
21import NosonMediaScanner 1.0
22import "../components"
23import "../components/Delegates"
24import "../components/Flickables"
25
26MusicPage {
27    id: composerViewPage
28    objectName: "composerViewPage"
29    visible: false
30    pageFlickable: composerAlbumView
31
32    property string composer: ""
33    property var covers: []
34
35    property bool isFavorite: false
36
37    BlurredBackground {
38        id: blurredBackground
39        height: parent.height
40    }
41
42    AlbumList {
43        id: albums
44        composer: composerViewPage.composer
45        Component.onCompleted: init()
46    }
47
48    function makeFileCoverSource(hasArt, filePath, artist, album) {
49        var art = "";
50        if (hasArt)
51            art = player.makeFilePictureLocalURL(filePath);
52        return makeCoverSource(art, artist, album);
53    }
54
55    MusicGridView {
56        id: composerAlbumView
57        itemWidth: units.gu(15)
58        heightOffset: units.gu(7)
59
60        header: MusicHeader {
61            id: blurredHeader
62            height: contentHeight
63            noCover: "qrc:/images/none.png"
64            coverSources: composerViewPage.covers
65            titleColumn: Item {}
66            rightColumn: Item {
67                height: units.gu(9)
68
69                Row {
70                    id: r1
71                    anchors {
72                        left: parent.left
73                        right: parent.right
74                    }
75                    Label {
76                        id: composerLabel
77                        color: styleMusic.view.primaryColor
78                        elide: Text.ElideRight
79                        font.pointSize: units.fs("x-large")
80                        maximumLineCount: 1
81                        text: (composer !== "<Undefined>" ? composer : tr_undefined)
82                        wrapMode: Text.NoWrap
83                    }
84                }
85
86                Row {
87                    id: r2
88                    anchors {
89                        topMargin: units.gu(0.5)
90                        top: r1.bottom
91                        left: parent.left
92                        right: parent.right
93                    }
94
95                    Label {
96                        id: albumCount
97                        color: styleMusic.view.secondaryColor
98                        elide: Text.ElideRight
99                        font.pointSize: units.fs("small")
100                        maximumLineCount: 1
101                        text: qsTr("%n album(s)", "", albums.count)
102                    }
103
104                    Label {
105                        id: separator
106                        color: styleMusic.view.secondaryColor
107                        elide: Text.ElideRight
108                        font.pointSize: units.fs("small")
109                        maximumLineCount: 1
110                        text: " , "
111                        visible: songComposerModel.count > 0
112                    }
113
114                    Label {
115                        id: songCount
116                        color: styleMusic.view.secondaryColor
117                        elide: Text.ElideRight
118                        font.pointSize: units.fs("small")
119                        maximumLineCount: 1
120                        text: qsTr("%n song(s)", "", songComposerModel.count)
121                        visible: songComposerModel.count > 0
122                    }
123                }
124
125                Row {
126                    id: r3
127                    anchors {
128                        topMargin: units.gu(0.5)
129                        top: r2.bottom
130                        left: parent.left
131                        right: parent.right
132                        leftMargin: units.gu(-1)
133                    }
134
135                    Icon {
136                        height: units.gu(5)
137                        width: height
138                        source: "qrc:/images/view-list-symbolic.svg"
139                        onClicked: {
140                            stackView.push("qrc:/controls2/ThisDevice/SongsView.qml",
141                                               {
142                                                   "covers": composerViewPage.covers,
143                                                   "album": undefined,
144                                                   "artist": "",
145                                                   "genre": "",
146                                                   "composer": composerViewPage.composer,
147                                                   "pageTitle": pageTitle,
148                                                   "line1": "",
149                                                   "line2": (composerViewPage.composer !== "<Undefined>" ? composerViewPage.composer : tr_undefined)
150                                               })
151                        }
152                    }
153                }
154            }
155
156            onFirstSourceChanged: {
157                blurredBackground.art = firstSource
158            }
159        }
160
161        model: SortFilterModel {
162            model: albums
163            sort.property: "album"
164            sort.order: Qt.AscendingOrder
165            sortCaseSensitivity: Qt.CaseInsensitive
166        }
167
168        delegate: Card {
169            id: albumCard
170            height: composerAlbumView.cellHeight
171            width: composerAlbumView.cellWidth
172            coverSources: makeFileCoverSource(model.hasArt, model.filePath, model.artist, model.album)
173            primaryText: (model.album !== "<Undefined>" ? model.album : tr_undefined)
174            secondaryTextVisible: false
175
176            onImageError: model.art = "" // reset invalid url from model
177            onClicked: {
178                stackView.push("qrc:/controls2/ThisDevice/SongsView.qml",
179                                   {
180                                       "album": model.album,
181                                       "artist": model.artist,
182                                       "covers": albumCard.imageSource != "" ? [{art: albumCard.imageSource}] : coverSources,
183                                       "isAlbum": true,
184                                       "genre": "",
185                                       "composer": composerViewPage.composer,
186                                       "pageTitle": pageTitle,
187                                       "line1": (model.artist !== "<Undefined>" ? model.artist : tr_undefined),
188                                       "line2": (model.album !== "<Undefined>" ? model.album : tr_undefined)
189                                   })
190            }
191        }
192    }
193
194    // Query total count of composer's songs
195    TrackList {
196        id: songComposerModel
197        composer: composerViewPage.composer
198        Component.onCompleted: init()
199    }
200}
201