File indexing completed on 2024-05-05 04:48:42

0001 /****************************************************************************************
0002  * Copyright (c) 2010 Alexander Potashev <aspotashev@gmail.com>                         *
0003  * Copyright (c) 2012 Ralf Engels <ralf-engels@gmx.de>                                  *
0004  *                                                                                      *
0005  * This program is free software; you can redistribute it and/or modify it under        *
0006  * the terms of the GNU General Public License as published by the Free Software        *
0007  * Foundation; either version 2 of the License, or (at your option) version 3 or        *
0008  * any later version accepted by the membership of KDE e.V. (or its successor approved  *
0009  * by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of  *
0010  * version 3 of the license.                                                            *
0011  *                                                                                      *
0012  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0013  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0014  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0015  *                                                                                      *
0016  * You should have received a copy of the GNU General Public License along with         *
0017  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0018  ****************************************************************************************/
0019 
0020 #include "PlaylistDefines.h"
0021 #include "core/meta/support/MetaConstants.h"
0022 
0023 #include <KLocalizedString>
0024 
0025 
0026 QStringList *Playlist::PlaylistColumnInfos::s_internalNames = nullptr;
0027 QStringList *Playlist::PlaylistColumnInfos::s_names = nullptr;
0028 QStringList *Playlist::PlaylistColumnInfos::s_icons = nullptr;
0029 QList<Playlist::Column> *Playlist::PlaylistColumnInfos::s_groups = nullptr;
0030 
0031 Playlist::PlaylistColumnInfos::PlaylistColumnInfos()
0032 {}
0033 
0034 const QStringList &
0035 Playlist::PlaylistColumnInfos::internalNames()
0036 {
0037     if( !s_internalNames )
0038     {
0039         // the order is important. See PlaylistDefines
0040         //this list is used internally and for reading writing config files and sths should not be translated!
0041 
0042         s_internalNames = new QStringList();
0043         *s_internalNames << QStringLiteral( "Placeholder" )
0044             << QStringLiteral( "Album" )
0045             << QStringLiteral( "Album artist" )
0046             << QStringLiteral( "Artist" )
0047             << QStringLiteral( "Bitrate" )
0048             << QStringLiteral( "Bpm" )
0049             << QStringLiteral( "Comment" )
0050             << QStringLiteral( "Composer" )
0051             << QStringLiteral( "Cover image" )
0052             << QStringLiteral( "Directory" )
0053             << QStringLiteral( "Disc number" )
0054             << QStringLiteral( "Divider" )
0055             << QStringLiteral( "File name" )
0056             << QStringLiteral( "File size" )
0057             << QStringLiteral( "Genre" )
0058             << QStringLiteral( "Group length" )
0059             << QStringLiteral( "Group tracks" )
0060             << QStringLiteral( "Labels" )
0061             << QStringLiteral( "Last played" )
0062             << QStringLiteral( "Length" )
0063             << QStringLiteral( "Length (seconds)" )
0064             << QStringLiteral( "Mood" )
0065             << QStringLiteral( "Moodbar" )
0066             << QStringLiteral( "Play count" )
0067             << QStringLiteral( "Rating" )
0068             << QStringLiteral( "Sample rate" )
0069             << QStringLiteral( "Score" )
0070             << QStringLiteral( "Source" )
0071             << QStringLiteral( "SourceEmblem" )
0072             << QStringLiteral( "Title" )
0073             << QStringLiteral( "Title (with track number)" )
0074             << QStringLiteral( "Track number" )
0075             << QStringLiteral( "Type" )
0076             << QStringLiteral( "Year" );
0077     }
0078 
0079     return *s_internalNames;
0080 }
0081 
0082 const QStringList &
0083 Playlist::PlaylistColumnInfos::names()
0084 {
0085     if( !s_names )
0086     {
0087         // the order is important. See PlaylistDefines
0088         s_names = new QStringList();
0089         *s_names << i18nc( "Empty placeholder token used for spacing in playlist layouts", "Placeholder" )
0090             << Meta::i18nForField( Meta::valAlbum )
0091             << Meta::i18nForField( Meta::valAlbumArtist )
0092             << Meta::i18nForField( Meta::valArtist )
0093             << Meta::i18nForField( Meta::valBitrate )
0094             << Meta::i18nForField( Meta::valBpm )
0095             << Meta::i18nForField( Meta::valComment )
0096             << Meta::i18nForField( Meta::valComposer )
0097             << i18nc( "'Cover image' playlist column name and token for playlist layouts", "Cover image" )
0098             << i18nc( "'Directory' playlist column name and token for playlist layouts", "Directory" )
0099             << Meta::i18nForField( Meta::valDiscNr )
0100             << i18nc( "'Divider' token for playlist layouts representing a small visual divider", "Divider" )
0101             << i18nc( "'File name' playlist column name and token for playlist layouts", "File name" )
0102             << Meta::i18nForField( Meta::valFilesize )
0103             << Meta::i18nForField( Meta::valGenre )
0104             << i18nc( "'Group length' (total play time of group) playlist column name and token for playlist layouts", "Group length" )
0105             << i18nc( "'Group tracks' (number of tracks in group) playlist column name and token for playlist layouts", "Group tracks" )
0106             << i18nc( "'Labels' playlist column name and token for playlist layouts", "Labels" )
0107             << Meta::i18nForField( Meta::valLastPlayed )
0108             << Meta::i18nForField( Meta::valLength )
0109             << Meta::i18nForField( Meta::valLength ) // this is length in seconds
0110             << i18nc( "'Mood' playlist column name and token for playlist layouts", "Mood" )
0111             << i18nc( "'Moodbar' playlist column name and token for playlist layouts", "Moodbar" )
0112             << Meta::i18nForField( Meta::valPlaycount )
0113             << Meta::i18nForField( Meta::valRating )
0114             << Meta::i18nForField( Meta::valSamplerate )
0115             << Meta::i18nForField( Meta::valScore )
0116             << i18nc( "'Source' (local collection, Magnatune.com, last.fm, ... ) playlist column name and token for playlist layouts", "Source" )
0117             << i18nc( "'SourceEmblem' playlist column name and token for playlist layouts", "SourceEmblem" )
0118             << i18nc( "'Title' (track name) playlist column name and token for playlist layouts", "Title" )
0119             << i18nc( "'Title (with track number)' (track name prefixed with the track number) playlist column name and token for playlist layouts", "Title (with track number)" )
0120             << Meta::i18nForField( Meta::valTrackNr )
0121             << Meta::i18nForField( Meta::valFormat )
0122             << Meta::i18nForField( Meta::valYear );
0123     }
0124 
0125     return *s_names;
0126 }
0127 
0128 const QStringList &
0129 Playlist::PlaylistColumnInfos::icons()
0130 {
0131     if( !s_icons )
0132     {
0133         // the order is important. See PlaylistDefines
0134         // should be kept in sync with Meta::iconForField() for shared fields
0135         s_icons = new QStringList();
0136         *s_icons << QStringLiteral("filename-space-amarok")
0137             << Meta::iconForField( Meta::valAlbum )
0138             << Meta::iconForField( Meta::valAlbumArtist )
0139             << Meta::iconForField( Meta::valArtist )
0140             << Meta::iconForField( Meta::valBitrate )
0141             << Meta::iconForField( Meta::valBpm )
0142             << Meta::iconForField( Meta::valComment )
0143             << Meta::iconForField( Meta::valComposer )
0144             << QLatin1String("") // cover image
0145             << QStringLiteral("folder-blue") // directory
0146             << Meta::iconForField( Meta::valDiscNr )
0147             << QStringLiteral("filename-divider")
0148             << QStringLiteral("filename-filetype-amarok") // filename
0149             << Meta::iconForField( Meta::valFilesize )
0150             << Meta::iconForField( Meta::valGenre )
0151             << QStringLiteral("filename-group-length")
0152             << QStringLiteral("filename-group-tracks")
0153             << Meta::iconForField( Meta::valLabel )
0154             << Meta::iconForField( Meta::valLastPlayed )
0155             << Meta::iconForField( Meta::valLength )
0156             << Meta::iconForField( Meta::valLength )
0157             << QLatin1String("")
0158             << QStringLiteral("filename-moodbar")
0159             << Meta::iconForField( Meta::valPlaycount )
0160             << Meta::iconForField( Meta::valRating )
0161             << Meta::iconForField( Meta::valSamplerate )
0162             << Meta::iconForField( Meta::valScore )
0163             << QStringLiteral("internet-services")
0164             << QLatin1String("") // source emblem
0165             << Meta::iconForField( Meta::valTitle )
0166             << Meta::iconForField( Meta::valTitle )
0167             << Meta::iconForField( Meta::valTrackNr )
0168             << Meta::iconForField( Meta::valFormat )
0169             << Meta::iconForField( Meta::valYear );
0170     }
0171 
0172     return *s_icons;
0173 }
0174 
0175 
0176 const QList<Playlist::Column> &
0177 Playlist::PlaylistColumnInfos::groups()
0178 {
0179     if( !s_groups )
0180     {
0181         s_groups = new QList<Playlist::Column>();
0182         *s_groups << Album
0183         << Artist
0184         << Composer
0185         << Directory
0186         << Genre
0187         << Rating
0188         << Source
0189         << Year;
0190     }
0191     return *s_groups;
0192 }
0193 
0194 bool
0195 Playlist::isEditableColumn( Column c )
0196 {
0197     return c == Album ||
0198         c == Artist ||
0199         c == Comment ||
0200         c == Composer ||
0201         c == DiscNumber ||
0202         c == Genre ||
0203         c == Rating ||
0204         c == Title ||
0205         c == TitleWithTrackNum ||
0206         c == TrackNumber ||
0207         c == Year ||
0208         c == Bpm;
0209 }
0210 
0211 
0212 bool
0213 Playlist::isSortableColumn( Column c )
0214 {
0215     return c == Album ||
0216         c == AlbumArtist ||
0217         c == Artist ||
0218         c == Bitrate ||
0219         c == Bpm ||
0220         c == Comment ||
0221         c == Composer ||
0222         c == Directory ||
0223         c == DiscNumber ||
0224         c == Filename ||
0225         c == Genre ||
0226         c == LastPlayed ||
0227         c == LengthInSeconds ||
0228         c == PlayCount ||
0229         c == Rating ||
0230         c == SampleRate ||
0231         c == Score ||
0232         c == Source ||
0233         c == Title ||
0234         c == TrackNumber ||
0235         c == Type ||
0236         c == Year;
0237 }
0238 
0239