File indexing completed on 2024-05-12 05:09:23
0001 /*************************************************************************** 0002 Copyright (C) 2003-2009 Robby Stephenson <robby@periapsis.org> 0003 ***************************************************************************/ 0004 0005 /*************************************************************************** 0006 * * 0007 * This program is free software; you can redistribute it and/or * 0008 * modify it under the terms of the GNU General Public License as * 0009 * published by the Free Software Foundation; either version 2 of * 0010 * the License or (at your option) version 3 or any later version * 0011 * accepted by the membership of KDE e.V. (or its successor approved * 0012 * by the membership of KDE e.V.), which shall act as a proxy * 0013 * defined in Section 14 of version 3 of the license. * 0014 * * 0015 * This program is distributed in the hope that it will be useful, * 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0018 * GNU General Public License for more details. * 0019 * * 0020 * You should have received a copy of the GNU General Public License * 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 0022 * * 0023 ***************************************************************************/ 0024 0025 #include "musiccollection.h" 0026 #include "../entrycomparison.h" 0027 0028 #include <KLocalizedString> 0029 0030 namespace { 0031 static const char* music_general = I18N_NOOP("General"); 0032 static const char* music_personal = I18N_NOOP("Personal"); 0033 } 0034 0035 using Tellico::Data::MusicCollection; 0036 0037 MusicCollection::MusicCollection(bool addDefaultFields_, const QString& title_) 0038 : Collection(title_.isEmpty() ? i18n("My Music") : title_) { 0039 setDefaultGroupField(QStringLiteral("artist")); 0040 if(addDefaultFields_) { 0041 addFields(defaultFields()); 0042 } 0043 } 0044 0045 Tellico::Data::FieldList MusicCollection::defaultFields() { 0046 FieldList list; 0047 FieldPtr field; 0048 0049 field = Field::createDefaultField(Field::TitleField); 0050 field->setTitle(i18n("Album")); 0051 list.append(field); 0052 0053 QStringList media; 0054 media << i18n("Compact Disc") << i18n("DVD") << i18n("Cassette") << i18n("Vinyl"); 0055 field = new Field(QStringLiteral("medium"), i18n("Medium"), media); 0056 field->setCategory(i18n(music_general)); 0057 field->setFlags(Field::AllowGrouped); 0058 list.append(field); 0059 0060 field = new Field(QStringLiteral("artist"), i18n("Artist")); 0061 field->setCategory(i18n(music_general)); 0062 field->setFlags(Field::AllowCompletion | Field::AllowGrouped | Field::AllowMultiple); 0063 field->setFormatType(FieldFormat::FormatTitle); // don't use FormatName 0064 list.append(field); 0065 0066 field = new Field(QStringLiteral("label"), i18n("Label")); 0067 field->setCategory(i18n(music_general)); 0068 field->setFlags(Field::AllowCompletion | Field::AllowGrouped | Field::AllowMultiple); 0069 field->setFormatType(FieldFormat::FormatPlain); 0070 list.append(field); 0071 0072 field = new Field(QStringLiteral("year"), i18n("Year"), Field::Number); 0073 field->setCategory(i18n(music_general)); 0074 field->setFlags(Field::AllowGrouped); 0075 list.append(field); 0076 0077 field = new Field(QStringLiteral("genre"), i18n("Genre")); 0078 field->setCategory(i18n(music_general)); 0079 field->setFlags(Field::AllowCompletion | Field::AllowMultiple | Field::AllowGrouped); 0080 field->setFormatType(FieldFormat::FormatPlain); 0081 list.append(field); 0082 0083 field = new Field(QStringLiteral("track"), i18n("Tracks"), Field::Table); 0084 field->setFormatType(FieldFormat::FormatTitle); 0085 field->setProperty(QStringLiteral("columns"), QStringLiteral("3")); 0086 field->setProperty(QStringLiteral("column1"), i18n("Title")); 0087 field->setProperty(QStringLiteral("column2"), i18n("Artist")); 0088 field->setProperty(QStringLiteral("column3"), i18n("Length")); 0089 list.append(field); 0090 0091 field = new Field(QStringLiteral("rating"), i18n("Rating"), Field::Rating); 0092 field->setCategory(i18n(music_personal)); 0093 field->setFlags(Field::AllowGrouped); 0094 list.append(field); 0095 0096 field = new Field(QStringLiteral("pur_date"), i18n("Purchase Date")); 0097 field->setCategory(i18n(music_personal)); 0098 field->setFormatType(FieldFormat::FormatDate); 0099 list.append(field); 0100 0101 field = new Field(QStringLiteral("gift"), i18n("Gift"), Field::Bool); 0102 field->setCategory(i18n(music_personal)); 0103 list.append(field); 0104 0105 field = new Field(QStringLiteral("pur_price"), i18n("Purchase Price")); 0106 field->setCategory(i18n(music_personal)); 0107 list.append(field); 0108 0109 field = new Field(QStringLiteral("loaned"), i18n("Loaned"), Field::Bool); 0110 field->setCategory(i18n(music_personal)); 0111 list.append(field); 0112 0113 field = new Field(QStringLiteral("keyword"), i18n("Keywords")); 0114 field->setCategory(i18n(music_personal)); 0115 field->setFlags(Field::AllowCompletion | Field::AllowMultiple | Field::AllowGrouped); 0116 list.append(field); 0117 0118 field = new Field(QStringLiteral("cover"), i18n("Cover"), Field::Image); 0119 list.append(field); 0120 0121 field = new Field(QStringLiteral("comments"), i18n("Comments"), Field::Para); 0122 field->setCategory(i18n(music_personal)); 0123 list.append(field); 0124 0125 list.append(Field::createDefaultField(Field::IDField)); 0126 list.append(Field::createDefaultField(Field::CreatedDateField)); 0127 list.append(Field::createDefaultField(Field::ModifiedDateField)); 0128 0129 return list; 0130 } 0131 0132 int MusicCollection::sameEntry(Tellico::Data::EntryPtr entry1_, Tellico::Data::EntryPtr entry2_) const { 0133 // not enough for title to be equal, must also have another field 0134 int res = 0; 0135 res += EntryComparison::MATCH_WEIGHT_MED*EntryComparison::score(entry1_, entry2_, QStringLiteral("title"), this); 0136 res += EntryComparison::MATCH_WEIGHT_MED*EntryComparison::score(entry1_, entry2_, QStringLiteral("artist"), this); 0137 if(res >= EntryComparison::ENTRY_PERFECT_MATCH) return res; 0138 0139 res += EntryComparison::MATCH_WEIGHT_LOW*EntryComparison::score(entry1_, entry2_, QStringLiteral("year"), this); 0140 if(res >= EntryComparison::ENTRY_PERFECT_MATCH) return res; 0141 0142 res += EntryComparison::MATCH_WEIGHT_LOW*EntryComparison::score(entry1_, entry2_, QStringLiteral("label"), this); 0143 if(res >= EntryComparison::ENTRY_PERFECT_MATCH) return res; 0144 0145 res += EntryComparison::MATCH_WEIGHT_LOW*EntryComparison::score(entry1_, entry2_, QStringLiteral("medium"), this); 0146 return res; 0147 }