File indexing completed on 2024-05-12 05:09:23
0001 /*************************************************************************** 0002 Copyright (C) 2005-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 "filecatalog.h" 0026 #include "../entrycomparison.h" 0027 0028 #include <KLocalizedString> 0029 0030 namespace { 0031 static const char* file_general = I18N_NOOP("General"); 0032 } 0033 0034 using Tellico::Data::FileCatalog; 0035 0036 FileCatalog::FileCatalog(bool addDefaultFields_, const QString& title_) 0037 : Collection(title_.isEmpty() ? i18n("My Files") : title_) { 0038 setDefaultGroupField(QStringLiteral("volume")); 0039 if(addDefaultFields_) { 0040 addFields(defaultFields()); 0041 } 0042 } 0043 0044 Tellico::Data::FieldList FileCatalog::defaultFields() { 0045 FieldList list; 0046 FieldPtr field; 0047 0048 field = Field::createDefaultField(Field::TitleField); 0049 field->setTitle(i18n("Name")); 0050 field->setFormatType(FieldFormat::FormatNone); 0051 list.append(field); 0052 0053 field = new Field(QStringLiteral("url"), i18n("URL"), Field::URL); 0054 field->setCategory(i18n(file_general)); 0055 list.append(field); 0056 0057 field = new Field(QStringLiteral("description"), i18n("Description")); 0058 field->setCategory(i18n(file_general)); 0059 field->setFlags(Field::AllowCompletion | Field::AllowGrouped); 0060 list.append(field); 0061 0062 field = new Field(QStringLiteral("volume"), i18nc("File catalog", "Volume")); 0063 field->setCategory(i18n(file_general)); 0064 field->setFlags(Field::AllowCompletion | Field::AllowGrouped); 0065 list.append(field); 0066 0067 field = new Field(QStringLiteral("folder"), i18n("Folder")); 0068 field->setCategory(i18n(file_general)); 0069 field->setFlags(Field::AllowCompletion | Field::AllowGrouped); 0070 list.append(field); 0071 0072 field = new Field(QStringLiteral("mimetype"), i18n("Mimetype")); 0073 field->setCategory(i18n(file_general)); 0074 field->setFlags(Field::AllowCompletion | Field::AllowGrouped); 0075 list.append(field); 0076 0077 field = new Field(QStringLiteral("size"), i18n("Size")); 0078 field->setCategory(i18n(file_general)); 0079 list.append(field); 0080 0081 field = new Field(QStringLiteral("permissions"), i18n("Permissions")); 0082 field->setCategory(i18n(file_general)); 0083 field->setFlags(Field::AllowCompletion | Field::AllowGrouped); 0084 list.append(field); 0085 0086 field = new Field(QStringLiteral("owner"), i18n("Owner")); 0087 field->setCategory(i18n(file_general)); 0088 field->setFlags(Field::AllowCompletion | Field::AllowGrouped); 0089 list.append(field); 0090 0091 field = new Field(QStringLiteral("group"), i18n("Group")); 0092 field->setCategory(i18n(file_general)); 0093 field->setFlags(Field::AllowCompletion | Field::AllowGrouped); 0094 list.append(field); 0095 0096 // these dates are string fields, not dates, since the time is included 0097 field = new Field(QStringLiteral("created"), i18n("Created")); 0098 field->setCategory(i18n(file_general)); 0099 list.append(field); 0100 0101 field = new Field(QStringLiteral("modified"), i18n("Modified")); 0102 field->setCategory(i18n(file_general)); 0103 list.append(field); 0104 0105 field = new Field(QStringLiteral("metainfo"), i18n("Meta Info"), Field::Table); 0106 field->setProperty(QStringLiteral("columns"), QStringLiteral("2")); 0107 field->setProperty(QStringLiteral("column1"), i18n("Property")); 0108 field->setProperty(QStringLiteral("column2"), i18n("Value")); 0109 list.append(field); 0110 0111 field = new Field(QStringLiteral("icon"), i18n("Icon"), Field::Image); 0112 list.append(field); 0113 0114 return list; 0115 } 0116 0117 int FileCatalog::sameEntry(Tellico::Data::EntryPtr entry1_, Tellico::Data::EntryPtr entry2_) const { 0118 // equal urls are always equal, even if modification time or something is different 0119 if(EntryComparison::score(entry1_, entry2_, QStringLiteral("url"), this) > 0) { 0120 return EntryComparison::ENTRY_PERFECT_MATCH; 0121 } 0122 // if volume or created time is different, it can't be same entry 0123 const int bad = EntryComparison::MATCH_VALUE_BAD; 0124 if(EntryComparison::score(entry1_, entry2_, QStringLiteral("volume"), this) == bad || 0125 EntryComparison::score(entry1_, entry2_, QStringLiteral("created"), this) == bad || 0126 EntryComparison::score(entry1_, entry2_, QStringLiteral("size"), this) == bad) { 0127 return EntryComparison::ENTRY_BAD_MATCH; 0128 } 0129 int res = 0; 0130 res += EntryComparison::MATCH_WEIGHT_MED*EntryComparison::score(entry1_, entry2_, QStringLiteral("title"), this); 0131 res += EntryComparison::MATCH_WEIGHT_MED*EntryComparison::score(entry1_, entry2_, QStringLiteral("mimetype"), this); 0132 res += EntryComparison::MATCH_WEIGHT_HIGH*EntryComparison::score(entry1_, entry2_, QStringLiteral("size"), this); 0133 if(res >= EntryComparison::ENTRY_PERFECT_MATCH) return res; 0134 0135 res += EntryComparison::MATCH_WEIGHT_MED*EntryComparison::score(entry1_, entry2_, QStringLiteral("volume"), this); 0136 if(res >= EntryComparison::ENTRY_PERFECT_MATCH) return res; 0137 0138 // description is less helpful 0139 res += EntryComparison::MATCH_WEIGHT_LOW*EntryComparison::score(entry1_, entry2_, QStringLiteral("description"), this); 0140 return res; 0141 }