File: Album.cpp

package info (click to toggle)
amarok 3.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 112,344 kB
  • sloc: cpp: 195,053; xml: 4,329; ansic: 2,634; javascript: 673; ruby: 528; python: 507; sh: 252; makefile: 12
file content (142 lines) | stat: -rw-r--r-- 4,203 bytes parent folder | download | duplicates (2)
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
/***************************************************************************
 *   Copyright (C) 2010 Ralf Engels <ralf-engels@gmx.de>                  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 ***************************************************************************/

#include "Album.h"

#include "Track.h"

#include <QDebug>
#include <QFileInfo>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>

// constructor is needed to put albums in a hash
CollectionScanner::Album::Album()
{}

CollectionScanner::Album::Album( const QString &name, const QString &artist )
    : m_name( name )
    , m_artist( artist )
{}

void
CollectionScanner::Album::addTrack( Track *track )
{
    m_tracks.append( track );
}

QString
CollectionScanner::Album::name() const
{
    return m_name;
}

QString
CollectionScanner::Album::artist() const
{
    return m_artist;
}

void
CollectionScanner::Album::setArtist( const QString &artist )
{
    m_artist = artist;
}


QString
CollectionScanner::Album::cover() const
{
    // we prefer covers included in tracks.
    // At least we know exactly that they really belong to the album
    for( const auto &track : m_tracks )
    {
        // IMPROVEMENT: skip covers that have a strange aspect ratio or are
        // unrealistically small, or do not resolve to a valid image
        if( track->hasCover() )
            return QStringLiteral("amarok-sqltrackuid://") + track->uniqueid();
    }

    // ok. Now we have to figure out which of the cover images is
    // the best.
    QString bestCover;
    int     bestRating = -1;
    qint64  bestSize = 0;

    for( const auto &cover : m_covers )
    {
        int rating = 0;

        if( cover.contains( QLatin1String("front"), Qt::CaseInsensitive ) ||
            cover.contains( QObject::tr( "front", "Front cover of an album" ), Qt::CaseInsensitive ) )
            rating += 2;

        if( cover.contains( QLatin1String("cover"), Qt::CaseInsensitive ) ||
            cover.contains( QObject::tr( "cover", "(Front) Cover of an album" ), Qt::CaseInsensitive ) )
            rating += 2;

        //next: try "folder" (some applications apparently use this)
        //using compare and not contains to not hit "Folder-Back" or something.
        if( cover.compare( QLatin1String("folder"), Qt::CaseInsensitive ) == 0)
            rating += 1;

        QFileInfo info( cover );
        if( (rating == bestRating && info.size() > bestSize) ||
            (rating > bestRating) )
        {
            bestCover = cover;
            bestRating = rating;
            bestSize = info.size();
        }
    }

    return bestCover;
}

QStringList
CollectionScanner::Album::covers() const
{
    return m_covers;
}

void
CollectionScanner::Album::setCovers( const QStringList &covers )
{
    m_covers = covers;
}



QList<CollectionScanner::Track*>
CollectionScanner::Album::tracks() const
{
    return m_tracks;
}

bool
CollectionScanner::Album::isNoCompilation() const
{
    for( const auto &track : m_tracks )
    {
        if( track->isNoCompilation() )
            return true;
    }

    return false;
}