File indexing completed on 2024-05-12 05:09:25
0001 /*************************************************************************** 0002 Copyright (C) 2006-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 "tellico_config.h" 0026 #include "../collection.h" 0027 0028 #define COLL Data::Collection:: 0029 #define CLASS Config:: 0030 #define P1 ( 0031 #define P2 ) 0032 #define CASE1(a,b) case COLL b: return CLASS a ## b P1 P2; 0033 #define CASE2(a,b,c) case COLL b: CLASS a ## b P1 c P2; break; 0034 #define GET(name,type) \ 0035 CASE1(name,type) 0036 #define SET(name,type,value) \ 0037 CASE2(name,type,value) 0038 #define ALL_GET(name) \ 0039 GET(name, Base) \ 0040 GET(name, Book) \ 0041 GET(name, Video) \ 0042 GET(name, Album) \ 0043 GET(name, Bibtex) \ 0044 GET(name, ComicBook) \ 0045 GET(name, Wine) \ 0046 GET(name, Coin) \ 0047 GET(name, Stamp) \ 0048 GET(name, Card) \ 0049 GET(name, Game) \ 0050 GET(name, File) \ 0051 GET(name, BoardGame) 0052 #define ALL_SET(name,value) \ 0053 SET(name, Base, value) \ 0054 SET(name, Book, value) \ 0055 SET(name, Video, value) \ 0056 SET(name, Album, value) \ 0057 SET(name, Bibtex, value) \ 0058 SET(name, ComicBook, value) \ 0059 SET(name, Wine, value) \ 0060 SET(name, Coin, value) \ 0061 SET(name, Stamp, value) \ 0062 SET(name, Card, value) \ 0063 SET(name, Game, value) \ 0064 SET(name, File, value) \ 0065 SET(name, BoardGame, value) 0066 0067 using Tellico::Config; 0068 0069 QStringList Config::m_noCapitalizationList; 0070 QStringList Config::m_articleList; 0071 QStringList Config::m_articleAposList; 0072 QStringList Config::m_nameSuffixList; 0073 QStringList Config::m_surnamePrefixList; 0074 QStringList Config::m_surnamePrefixTokens; 0075 0076 QRegularExpression Config::commaSplit() { 0077 static const QRegularExpression rx(QLatin1String("\\s*,\\s*")); 0078 return rx; 0079 } 0080 0081 void Config::checkArticleList() { 0082 // I don't know of a way to update the list when the string changes 0083 // so just keep a cached copy 0084 static QString cacheValue; 0085 if(cacheValue != Config::articlesString()) { 0086 cacheValue = Config::articlesString(); 0087 m_articleList = cacheValue.split(commaSplit()); 0088 m_articleAposList.clear(); 0089 foreach(const QString& article, m_articleList) { 0090 if(article.endsWith(QLatin1Char('\''))) { 0091 m_articleAposList += article; 0092 } 0093 } 0094 } 0095 } 0096 0097 QStringList Config::noCapitalizationList() { 0098 static QString cacheValue; 0099 if(cacheValue != Config::noCapitalizationString()) { 0100 cacheValue = Config::noCapitalizationString(); 0101 m_noCapitalizationList = cacheValue.split(commaSplit()); 0102 } 0103 return m_noCapitalizationList; 0104 } 0105 0106 QStringList Config::articleList() { 0107 // articles should all be in lower-case 0108 checkArticleList(); 0109 return m_articleList; 0110 } 0111 0112 QStringList Config::articleAposList() { 0113 checkArticleList(); 0114 return m_articleAposList; 0115 } 0116 0117 QStringList Config::nameSuffixList() { 0118 static QString cacheValue; 0119 if(cacheValue != Config::nameSuffixesString()) { 0120 cacheValue = Config::nameSuffixesString(); 0121 m_nameSuffixList = cacheValue.split(commaSplit()); 0122 } 0123 return m_nameSuffixList; 0124 } 0125 0126 QStringList Config::surnamePrefixList() { 0127 static QString cacheValue; 0128 if(cacheValue != Config::surnamePrefixesString()) { 0129 cacheValue = Config::surnamePrefixesString(); 0130 m_surnamePrefixList = cacheValue.split(commaSplit()); 0131 } 0132 return m_surnamePrefixList; 0133 } 0134 0135 // In a previous version of Tellico, using a prefix such as "van der" (with a space) would work 0136 // because QStringList::contains did substring matching, but now need to add a function for tokenizing 0137 // the list with whitespace as well as comma 0138 QStringList Config::surnamePrefixTokens() { 0139 static QString cacheValue; 0140 if(cacheValue != Config::surnamePrefixesString()) { 0141 cacheValue = Config::surnamePrefixesString(); 0142 static const QRegularExpression commaSpaceSplit(QLatin1String("\\s*[, ]\\s*")); 0143 m_surnamePrefixTokens = cacheValue.split(commaSpaceSplit); 0144 } 0145 return m_surnamePrefixTokens; 0146 } 0147 0148 QString Config::templateName(int type_) { 0149 switch(type_) { 0150 ALL_GET(template); 0151 } 0152 return QString(); 0153 } 0154 0155 QFont Config::templateFont(int type_) { 0156 switch(type_) { 0157 ALL_GET(font); 0158 } 0159 return QFont(); 0160 } 0161 0162 QColor Config::templateBaseColor(int type_) { 0163 switch(type_) { 0164 ALL_GET(baseColor) 0165 } 0166 return QColor(); 0167 } 0168 0169 QColor Config::templateTextColor(int type_) { 0170 switch(type_) { 0171 ALL_GET(textColor) 0172 } 0173 return QColor(); 0174 } 0175 0176 QColor Config::templateHighlightedBaseColor(int type_) { 0177 switch(type_) { 0178 ALL_GET(highlightedBaseColor) 0179 } 0180 return QColor(); 0181 } 0182 0183 QColor Config::templateHighlightedTextColor(int type_) { 0184 switch(type_) { 0185 ALL_GET(highlightedTextColor) 0186 } 0187 return QColor(); 0188 } 0189 0190 QColor Config::templateLinkColor(int type_) { 0191 switch(type_) { 0192 ALL_GET(linkColor) 0193 } 0194 return QColor(); 0195 } 0196 0197 void Config::setTemplateName(int type_, const QString& name_) { 0198 switch(type_) { 0199 ALL_SET(setTemplate,name_) 0200 } 0201 } 0202 0203 void Config::setTemplateFont(int type_, const QFont& font_) { 0204 switch(type_) { 0205 ALL_SET(setFont,font_) 0206 } 0207 } 0208 0209 void Config::setTemplateBaseColor(int type_, const QColor& color_) { 0210 switch(type_) { 0211 ALL_SET(setBaseColor,color_) 0212 } 0213 } 0214 0215 void Config::setTemplateTextColor(int type_, const QColor& color_) { 0216 switch(type_) { 0217 ALL_SET(setTextColor,color_) 0218 } 0219 } 0220 0221 void Config::setTemplateHighlightedBaseColor(int type_, const QColor& color_) { 0222 switch(type_) { 0223 ALL_SET(setHighlightedBaseColor,color_) 0224 } 0225 } 0226 0227 void Config::setTemplateHighlightedTextColor(int type_, const QColor& color_) { 0228 switch(type_) { 0229 ALL_SET(setHighlightedTextColor,color_) 0230 } 0231 } 0232 0233 void Config::setTemplateLinkColor(int type_, const QColor& color_) { 0234 switch(type_) { 0235 ALL_SET(setLinkColor,color_) 0236 } 0237 } 0238 0239 #undef COLL 0240 #undef CLASS 0241 #undef P1 0242 #undef P2 0243 #undef CASE1 0244 #undef CASE2 0245 #undef GET 0246 #undef SET 0247 #undef ALL_GET 0248 #undef ALL_SET