File indexing completed on 2024-05-12 05:09:23

0001 /***************************************************************************
0002     Copyright (C) 2003-2016 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 "comicbookcollection.h"
0026 #include "../entrycomparison.h"
0027 
0028 #include <KLocalizedString>
0029 
0030 namespace {
0031   static const char* comic_general = I18N_NOOP("General");
0032   static const char* comic_publishing = I18N_NOOP("Publishing");
0033   static const char* comic_classification = I18N_NOOP("Classification");
0034   static const char* comic_personal = I18N_NOOP("Personal");
0035 }
0036 
0037 using Tellico::Data::ComicBookCollection;
0038 
0039 ComicBookCollection::ComicBookCollection(bool addDefaultFields_, const QString& title_)
0040    : Collection(title_.isEmpty() ? i18n("My Comic Books") : title_) {
0041   setDefaultGroupField(QStringLiteral("series"));
0042   if(addDefaultFields_) {
0043     addFields(defaultFields());
0044   }
0045 }
0046 
0047 Tellico::Data::FieldList ComicBookCollection::defaultFields() {
0048   FieldList list;
0049   FieldPtr field;
0050 
0051   list.append(Field::createDefaultField(Field::TitleField));
0052 
0053   field = new Field(QStringLiteral("subtitle"), i18n("Subtitle"));
0054   field->setCategory(i18n(comic_general));
0055   field->setFormatType(FieldFormat::FormatTitle);
0056   list.append(field);
0057 
0058   field = new Field(QStringLiteral("writer"), i18n("Writer"));
0059   field->setCategory(i18n(comic_general));
0060   field->setFlags(Field::AllowCompletion | Field::AllowMultiple | Field::AllowGrouped);
0061   field->setFormatType(FieldFormat::FormatName);
0062   list.append(field);
0063 
0064   field = new Field(QStringLiteral("artist"), i18nc("Comic Book Illustrator", "Artist"));
0065   field->setCategory(i18n(comic_general));
0066   field->setFlags(Field::AllowCompletion | Field::AllowMultiple | Field::AllowGrouped);
0067   field->setFormatType(FieldFormat::FormatName);
0068   list.append(field);
0069 
0070   field = new Field(QStringLiteral("series"), i18n("Series"));
0071   field->setCategory(i18n(comic_general));
0072   field->setFlags(Field::AllowCompletion | Field::AllowGrouped);
0073   field->setFormatType(FieldFormat::FormatTitle);
0074   list.append(field);
0075 
0076   field = new Field(QStringLiteral("issue"), i18n("Issue"), Field::Number);
0077   field->setCategory(i18n(comic_general));
0078   field->setFlags(Field::AllowMultiple);
0079   list.append(field);
0080 
0081   field = new Field(QStringLiteral("publisher"), i18n("Publisher"));
0082   field->setCategory(i18n(comic_publishing));
0083   field->setFlags(Field::AllowCompletion | Field::AllowGrouped);
0084   field->setFormatType(FieldFormat::FormatPlain);
0085   list.append(field);
0086 
0087   field = new Field(QStringLiteral("edition"), i18n("Edition"));
0088   field->setCategory(i18n(comic_publishing));
0089   field->setFlags(Field::AllowCompletion);
0090   field->setFormatType(FieldFormat::FormatPlain);
0091   list.append(field);
0092 
0093   field = new Field(QStringLiteral("pub_year"), i18n("Publication Year"),  Field::Number);
0094   field->setCategory(i18n(comic_publishing));
0095   field->setFlags(Field::AllowGrouped);
0096   list.append(field);
0097 
0098   field = new Field(QStringLiteral("pages"), i18n("Pages"), Field::Number);
0099   field->setCategory(i18n(comic_publishing));
0100   list.append(field);
0101 
0102   field = new Field(QStringLiteral("country"), i18n("Country"));
0103   field->setCategory(i18n(comic_publishing));
0104   field->setFlags(Field::AllowCompletion | Field::AllowGrouped | Field::AllowMultiple);
0105   field->setFormatType(FieldFormat::FormatPlain);
0106   list.append(field);
0107 
0108   field = new Field(QStringLiteral("language"), i18n("Language"));
0109   field->setCategory(i18n(comic_publishing));
0110   field->setFlags(Field::AllowCompletion | Field::AllowGrouped | Field::AllowMultiple);
0111   field->setFormatType(FieldFormat::FormatPlain);
0112   list.append(field);
0113 
0114   field = new Field(QStringLiteral("genre"), i18n("Genre"));
0115   field->setCategory(i18n(comic_classification));
0116   field->setFlags(Field::AllowCompletion | Field::AllowMultiple | Field::AllowGrouped);
0117   field->setFormatType(FieldFormat::FormatPlain);
0118   list.append(field);
0119 
0120   field = new Field(QStringLiteral("keyword"), i18n("Keywords"));
0121   field->setCategory(i18n(comic_classification));
0122   field->setFlags(Field::AllowCompletion | Field::AllowMultiple | Field::AllowGrouped);
0123   list.append(field);
0124 
0125   auto cond = FieldFormat::splitValue(i18nc("Comic book grade levels - "
0126                                             "Mint,Near Mint,Very Fine,Fine,Very Good,Good,Fair,Poor",
0127                                             "Mint,Near Mint,Very Fine,Fine,Very Good,Good,Fair,Poor"),
0128                                       FieldFormat::CommaRegExpSplit);
0129   field = new Field(QStringLiteral("condition"), i18n("Condition"), cond);
0130   field->setCategory(i18n(comic_classification));
0131   field->setFlags(Field::AllowGrouped);
0132   list.append(field);
0133 
0134   field = new Field(QStringLiteral("pur_date"), i18n("Purchase Date"));
0135   field->setCategory(i18n(comic_personal));
0136   field->setFormatType(FieldFormat::FormatDate);
0137   list.append(field);
0138 
0139   field = new Field(QStringLiteral("pur_price"), i18n("Purchase Price"));
0140   field->setCategory(i18n(comic_personal));
0141   list.append(field);
0142 
0143   field = new Field(QStringLiteral("signed"), i18n("Signed"), Field::Bool);
0144   field->setCategory(i18n(comic_personal));
0145   list.append(field);
0146 
0147   field = new Field(QStringLiteral("gift"), i18n("Gift"), Field::Bool);
0148   field->setCategory(i18n(comic_personal));
0149   list.append(field);
0150 
0151   field = new Field(QStringLiteral("loaned"), i18n("Loaned"), Field::Bool);
0152   field->setCategory(i18n(comic_personal));
0153   list.append(field);
0154 
0155   field = new Field(QStringLiteral("rating"), i18n("Rating"), Field::Rating);
0156   field->setCategory(i18n(comic_personal));
0157   field->setFlags(Field::AllowGrouped);
0158   list.append(field);
0159 
0160   list.append(Field::createDefaultField(Field::FrontCoverField));
0161 
0162   field = new Field(QStringLiteral("plot"), i18n("Plot Summary"), Field::Para);
0163   list.append(field);
0164 
0165   field = new Field(QStringLiteral("comments"), i18n("Comments"), Field::Para);
0166   list.append(field);
0167 
0168   list.append(Field::createDefaultField(Field::IDField));
0169   list.append(Field::createDefaultField(Field::CreatedDateField));
0170   list.append(Field::createDefaultField(Field::ModifiedDateField));
0171 
0172   return list;
0173 }
0174 
0175 int ComicBookCollection::sameEntry(Tellico::Data::EntryPtr entry1_, Tellico::Data::EntryPtr entry2_) const {
0176   if(!entry1_ || !entry2_) {
0177     return 0;
0178   }
0179 
0180   if(EntryComparison::score(entry1_, entry2_, QStringLiteral("isbn"), this) > 0) {
0181     return EntryComparison::ENTRY_PERFECT_MATCH;
0182   }
0183 
0184   int res = 0;
0185   res += EntryComparison::MATCH_WEIGHT_HIGH*EntryComparison::score(entry1_, entry2_, QStringLiteral("title"), this);
0186   if(res >= EntryComparison::ENTRY_PERFECT_MATCH) return res;
0187 
0188   res += EntryComparison::MATCH_WEIGHT_MED *EntryComparison::score(entry1_, entry2_, QStringLiteral("series"), this);
0189   if(res >= EntryComparison::ENTRY_PERFECT_MATCH) return res;
0190 
0191   res += EntryComparison::MATCH_WEIGHT_LOW *EntryComparison::score(entry1_, entry2_, QStringLiteral("pub_year"), this);
0192   if(res >= EntryComparison::ENTRY_PERFECT_MATCH) return res;
0193 
0194   res += EntryComparison::MATCH_WEIGHT_MED *EntryComparison::score(entry1_, entry2_, QStringLiteral("writer"), this);
0195   if(res >= EntryComparison::ENTRY_PERFECT_MATCH) return res;
0196 
0197   res += EntryComparison::MATCH_WEIGHT_LOW *EntryComparison::score(entry1_, entry2_, QStringLiteral("artist"), this);
0198   if(res >= EntryComparison::ENTRY_PERFECT_MATCH) return res;
0199 
0200   res += EntryComparison::MATCH_WEIGHT_LOW *EntryComparison::score(entry1_, entry2_, QStringLiteral("issue"), this);
0201   if(res >= EntryComparison::ENTRY_PERFECT_MATCH) return res;
0202 
0203   res += EntryComparison::MATCH_WEIGHT_LOW *EntryComparison::score(entry1_, entry2_, QStringLiteral("publisher"), this);
0204   return res;
0205 }