diff options
author | Yoann Lopes <yoann.lopes@nokia.com> | 2011-11-03 21:26:41 +0100 |
---|---|---|
committer | Yoann Lopes <yoann.lopes@nokia.com> | 2011-11-03 21:26:41 +0100 |
commit | 97e08a249e8324bf2525fc96961fcfd5212d8da6 (patch) | |
tree | 61dd6144f75d9d0b09ccadb46cb68a2137236a65 | |
parent | 2618d786b29510c6077dee67ab00b81852d4558f (diff) |
Added album reviews.
-rw-r--r-- | libQtSpotify/qspotifyalbumbrowse.cpp | 22 | ||||
-rw-r--r-- | libQtSpotify/qspotifyalbumbrowse.h | 22 | ||||
-rw-r--r-- | qml/AlbumHeader.qml | 72 | ||||
-rw-r--r-- | qml/AlbumPage.qml | 113 |
4 files changed, 154 insertions, 75 deletions
diff --git a/libQtSpotify/qspotifyalbumbrowse.cpp b/libQtSpotify/qspotifyalbumbrowse.cpp index 71f31a9..1c41a93 100644 --- a/libQtSpotify/qspotifyalbumbrowse.cpp +++ b/libQtSpotify/qspotifyalbumbrowse.cpp @@ -5,22 +5,22 @@ ** Contact: Yoann Lopes (yoann.lopes@nokia.com) ** ** This file is part of the MeeSpot project. -** +** ** Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions ** are met: -** +** ** Redistributions of source code must retain the above copyright notice, ** this list of conditions and the following disclaimer. -** +** ** Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in the ** documentation and/or other materials provided with the distribution. -** +** ** Neither the name of Nokia Corporation and its Subsidiary(-ies) nor the names of its ** contributors may be used to endorse or promote products derived from ** this software without specific prior written permission. -** +** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS @@ -69,6 +69,7 @@ QSpotifyAlbumBrowse::QSpotifyAlbumBrowse(QObject *parent) , m_album(0) , m_albumTracks(0) , m_hasMultipleArtists(false) + , m_busy(false) { } @@ -98,6 +99,9 @@ void QSpotifyAlbumBrowse::setAlbum(QSpotifyAlbum *album) if (!m_album) return; + m_busy = true; + emit busyChanged(); + QMutexLocker lock(&g_mutex); m_sp_albumbrowse = sp_albumbrowse_create(QSpotifySession::instance()->spsession(), m_album->spalbum(), callback_albumbrowse_complete, 0); g_albumBrowseObjects.insert(m_sp_albumbrowse, this); @@ -126,6 +130,7 @@ void QSpotifyAlbumBrowse::clearData() m_albumTracks = 0; } m_hasMultipleArtists = false; + m_review.clear(); } void QSpotifyAlbumBrowse::processData() @@ -147,6 +152,13 @@ void QSpotifyAlbumBrowse::processData() m_hasMultipleArtists = true; } + m_review = QString::fromUtf8(sp_albumbrowse_review(m_sp_albumbrowse)).split(QLatin1Char('\n'), QString::SkipEmptyParts); + if (m_review.isEmpty()) + m_review << QLatin1String("No review available"); + + m_busy = false; + emit busyChanged(); + emit tracksChanged(); } } diff --git a/libQtSpotify/qspotifyalbumbrowse.h b/libQtSpotify/qspotifyalbumbrowse.h index 4895639..b440740 100644 --- a/libQtSpotify/qspotifyalbumbrowse.h +++ b/libQtSpotify/qspotifyalbumbrowse.h @@ -5,22 +5,22 @@ ** Contact: Yoann Lopes (yoann.lopes@nokia.com) ** ** This file is part of the MeeSpot project. -** +** ** Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions ** are met: -** +** ** Redistributions of source code must retain the above copyright notice, ** this list of conditions and the following disclaimer. -** +** ** Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in the ** documentation and/or other materials provided with the distribution. -** +** ** Neither the name of Nokia Corporation and its Subsidiary(-ies) nor the names of its ** contributors may be used to endorse or promote products derived from ** this software without specific prior written permission. -** +** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS @@ -43,6 +43,7 @@ #define QSPOTIFYALBUMBROWSE_H #include <QtCore/QObject> +#include <QStringList> struct sp_albumbrowse; class QSpotifyAlbum; @@ -56,6 +57,8 @@ class QSpotifyAlbumBrowse : public QObject Q_PROPERTY(int totalDuration READ totalDuration NOTIFY tracksChanged) Q_PROPERTY(bool isStarred READ isStarred WRITE setStarred NOTIFY isStarredChanged) Q_PROPERTY(bool hasMultipleArtists READ hasMultipleArtists NOTIFY albumChanged) + Q_PROPERTY(QStringList review READ review NOTIFY tracksChanged) + Q_PROPERTY(bool busy READ busy NOTIFY busyChanged) public: QSpotifyAlbumBrowse(QObject *parent = 0); ~QSpotifyAlbumBrowse(); @@ -67,6 +70,10 @@ public: int totalDuration() const; bool hasMultipleArtists() const { return m_hasMultipleArtists; } + QStringList review() const { return m_review; } + + bool busy() const { return m_busy; } + bool event(QEvent *); Q_INVOKABLE void play(); @@ -79,6 +86,7 @@ Q_SIGNALS: void albumChanged(); void tracksChanged(); void isStarredChanged(); + void busyChanged(); private: void clearData(); @@ -89,8 +97,12 @@ private: QSpotifyAlbum *m_album; QSpotifyTrackList *m_albumTracks; + QStringList m_review; + bool m_hasMultipleArtists; + bool m_busy; + friend class QSpotifyPlaylist; friend class QSpotifyUser; }; diff --git a/qml/AlbumHeader.qml b/qml/AlbumHeader.qml index bcdd1a9..2a7e703 100644 --- a/qml/AlbumHeader.qml +++ b/qml/AlbumHeader.qml @@ -5,22 +5,22 @@ ** Contact: Yoann Lopes (yoann.lopes@nokia.com) ** ** This file is part of the MeeSpot project. -** +** ** Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions ** are met: -** +** ** Redistributions of source code must retain the above copyright notice, ** this list of conditions and the following disclaimer. -** +** ** Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in the ** documentation and/or other materials provided with the distribution. -** +** ** Neither the name of Nokia Corporation and its Subsidiary(-ies) nor the names of its ** contributors may be used to endorse or promote products derived from ** this software without specific prior written permission. -** +** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS @@ -46,7 +46,6 @@ import "UIConstants.js" as UI Column { id: albumHeader signal moreClicked - property alias albumName: title.text property alias artistName: artistText.text property alias trackCount: trackCountText.text property alias timing: timingText.text @@ -58,45 +57,6 @@ Column { Item { width: parent.width - height: UI.HEADER_DEFAULT_HEIGHT_PORTRAIT - - Label { - anchors.left: parent.left - anchors.right: moreIcon.left - anchors.rightMargin: UI.MARGIN_XLARGE - anchors.verticalCenter: parent.verticalCenter - id: title - color: theme.inverted ? UI.COLOR_INVERTED_FOREGROUND : UI.COLOR_FOREGROUND - font.pixelSize: UI.FONT_LARGE - font.family: UI.FONT_FAMILY_LIGHT - elide: Text.ElideRight - opacity: moreButton.pressed ? 0.4 : 1.0 - } - - Image { - id: moreIcon - anchors.right: parent.right - anchors.verticalCenter: parent.verticalCenter - source: "image://theme/icon-s-music-video-description" - opacity: moreButton.pressed ? 0.4 : 1.0 - - MouseArea { - id: moreButton - anchors.fill: parent - anchors.margins: -15 - onClicked: { albumHeader.moreClicked(); } - } - } - - Separator { - anchors.left: parent.left - anchors.right: parent.right - anchors.bottom: parent.bottom - } - } - - Item { - width: parent.width height: 160 SpotifyImage { @@ -114,13 +74,13 @@ Column { Label { id: artistText - height: 50 + height: 35 width: parent.width font.family: UI.FONT_FAMILY_BOLD font.weight: Font.Bold font.pixelSize: UI.FONT_LSMALL elide: Text.ElideRight - verticalAlignment: Text.AlignVCenter + verticalAlignment: Text.AlignTop } Label { @@ -145,6 +105,24 @@ Column { elide: Text.ElideRight } } + + Image { + id: moreIcon + source: "image://theme/icon-s-music-video-description" + opacity: moreButton.pressed ? 0.4 : 1.0 + visible: trackCount.length > 0 + anchors.left: cover.right + anchors.leftMargin: UI.MARGIN_XLARGE + anchors.bottom: cover.bottom + anchors.bottomMargin: 4 + + MouseArea { + id: moreButton + anchors.fill: parent + anchors.margins: -15 + onClicked: { albumHeader.moreClicked(); } + } + } } Separator { diff --git a/qml/AlbumPage.qml b/qml/AlbumPage.qml index 6fefb8c..6f81749 100644 --- a/qml/AlbumPage.qml +++ b/qml/AlbumPage.qml @@ -56,6 +56,8 @@ Page { SpotifyAlbumBrowse { id: browse + + property int trackCount: browse.tracks.length; } TrackMenu { @@ -70,6 +72,29 @@ Page { artistVisible: !browse.hasMultipleArtists } + Column { + id: header + width: parent.width + anchors.top: parent.top + + Selector { + id: selector + title: album ? album.name : "" + titleFontFamily: UI.FONT_FAMILY_LIGHT + titleFontWeight: Font.Light + titleFontSize: UI.FONT_LARGE + selectedIndex: 0 + model: ListModel { + ListElement { name: "Tracks" } + ListElement { name: "Review" } + } + } + + Separator { + width: parent.width + } + } + Component { id: albumDelegate AlbumTrackDelegate { @@ -97,28 +122,80 @@ Page { } } - ListView { - id: tracks - anchors.fill: parent - - cacheBuffer: 3000 - model: browse.tracks - header: AlbumHeader { - albumName: album ? album.name : "" - artistName: album ? album.artist : "" - trackCount: tracks.count > 0 ? (tracks.count + (tracks.count > 1 ? " songs" : " song")) : "" - timing: browse.totalDuration > 0 ? spotifySession.formatDuration(browse.totalDuration) : "" - year: tracks.count > 0 && album.year > 0 ? album.year : "" - coverId: album.coverId - onMoreClicked: { albumMenu.albumBrowse = browse; albumMenu.open() } + Component { + id: reviewComponent + Label { + width: parent ? parent.width : 0 + height: paintedHeight + UI.MARGIN_XLARGE * 2 + text: "<style type=text/css> a { text-decoration: none; color:" + color + "} </style>" + modelData + textFormat: Text.RichText + wrapMode: Text.WordWrap + font.pixelSize: UI.FONT_LSMALL + verticalAlignment: Text.AlignVCenter } + } + + Item { + anchors.right: parent.right + anchors.left: parent.left + anchors.top: header.bottom + anchors.bottom: parent.bottom + anchors.topMargin: UI.MARGIN_XLARGE + anchors.rightMargin: -UI.MARGIN_XLARGE + anchors.leftMargin: -UI.MARGIN_XLARGE + clip: true + + ListView { + id: tracks + anchors.fill: parent + anchors.rightMargin: UI.MARGIN_XLARGE + anchors.leftMargin: UI.MARGIN_XLARGE + + cacheBuffer: 3000 + model: browse.tracks + header: AlbumHeader { + artistName: album ? album.artist : "" + trackCount: browse.trackCount > 0 ? (browse.trackCount + (browse.trackCount > 1 ? " songs" : " song")) : "" + timing: browse.totalDuration > 0 ? spotifySession.formatDuration(browse.totalDuration) : "" + year: browse.trackCount > 0 && album.year > 0 ? album.year : "" + coverId: album.coverId + onMoreClicked: { albumMenu.albumBrowse = browse; albumMenu.open() } + } - onCountChanged: { - delegate = browse.hasMultipleArtists ? compilationDelegate : albumDelegate + Component.onCompleted: positionViewAtBeginning() + + Connections { + target: selector + onSelectedIndexChanged: tracks.updateResults() + } + + Connections { + target: browse + onTracksChanged: tracks.updateResults() + } + + function updateResults() { + tracks.model = 0 + tracks.delegate = null + if (selector.selectedIndex === 0) { + tracks.model = browse.tracks + tracks.delegate = browse.hasMultipleArtists ? compilationDelegate : albumDelegate + } else if (selector.selectedIndex == 1) { + tracks.delegate = reviewComponent + tracks.model = browse.review + } + tracks.positionViewAtBeginning() + } } - Component.onCompleted: positionViewAtBeginning() + Scrollbar { listView: tracks } } - Scrollbar { listView: tracks } + BusyIndicator { + id: busy + running: browse.busy + visible: running + anchors.centerIn: parent + platformStyle: BusyIndicatorStyle { size: "medium" } + } } |