Warning, file /office/calligra/libs/odf/KoOdfBibliographyConfiguration.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2011 Smit Patel <smitpatel24@gmail.com> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Library General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Library General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Library General Public License 0015 * along with this library; see the file COPYING.LIB. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 #include "KoOdfBibliographyConfiguration.h" 0020 0021 #include <OdfDebug.h> 0022 #include "KoXmlNS.h" 0023 #include "KoXmlWriter.h" 0024 0025 #include <QList> 0026 0027 const QList<QString> KoOdfBibliographyConfiguration::bibTypes = QList<QString>() << "article" << "book" << "booklet" << "conference" 0028 << "email" << "inbook" << "incollection" 0029 << "inproceedings" << "journal" << "manual" 0030 << "mastersthesis" << "misc" << "phdthesis" 0031 << "proceedings" << "techreport" << "unpublished" 0032 << "www" << "custom1" << "custom2" 0033 << "custom3" << "custom4" << "custom5"; 0034 0035 const QList<QString> KoOdfBibliographyConfiguration::bibDataFields = QList<QString>() << "address" << "annote" << "author" 0036 << "bibliography-type" << "booktitle" 0037 << "chapter" << "custom1" << "custom2" 0038 << "custom3" << "custom4" << "custom5" 0039 << "edition" << "editor" << "howpublished" 0040 << "identifier" << "institution" << "isbn" 0041 << "issn" << "journal" << "month" << "note" 0042 << "number" << "organizations" << "pages" 0043 << "publisher" << "report-type" << "school" 0044 << "series" << "title" << "url" << "volume" 0045 << "year"; 0046 0047 class Q_DECL_HIDDEN KoOdfBibliographyConfiguration::Private 0048 { 0049 public: 0050 QString prefix; 0051 QString suffix; 0052 bool numberedEntries; 0053 bool sortByPosition; 0054 QString sortAlgorithm; 0055 QVector<SortKeyPair> sortKeys; 0056 }; 0057 0058 KoOdfBibliographyConfiguration::KoOdfBibliographyConfiguration() 0059 : d(new Private()) 0060 { 0061 d->prefix = "["; 0062 d->suffix = "]"; 0063 d->numberedEntries = false; 0064 d->sortByPosition = true; 0065 } 0066 0067 KoOdfBibliographyConfiguration::~KoOdfBibliographyConfiguration() 0068 { 0069 delete d; 0070 } 0071 0072 KoOdfBibliographyConfiguration::KoOdfBibliographyConfiguration(const KoOdfBibliographyConfiguration &other) 0073 : QObject(), d(new Private()) 0074 { 0075 *this = other; 0076 } 0077 0078 KoOdfBibliographyConfiguration &KoOdfBibliographyConfiguration::operator=(const KoOdfBibliographyConfiguration &other) 0079 { 0080 d->prefix = other.d->prefix; 0081 d->suffix = other.d->suffix; 0082 d->numberedEntries = other.d->numberedEntries; 0083 d->sortAlgorithm = other.d->sortAlgorithm; 0084 d->sortByPosition = other.d->sortByPosition; 0085 d->sortKeys = other.d->sortKeys; 0086 0087 return *this; 0088 } 0089 0090 0091 void KoOdfBibliographyConfiguration::loadOdf(const KoXmlElement &element) 0092 { 0093 d->prefix = element.attributeNS(KoXmlNS::text, "prefix", QString()); 0094 d->suffix = element.attributeNS(KoXmlNS::text, "suffix", QString()); 0095 d->numberedEntries = (element.attributeNS(KoXmlNS::text, "numbered-entries", QString("false")) == "true") 0096 ? true : false; 0097 d->sortByPosition = (element.attributeNS(KoXmlNS::text, "sort-by-position", QString("true")) == "true") 0098 ? true : false; 0099 d->sortAlgorithm = element.attributeNS(KoXmlNS::text, "sort-algorithm", QString()); 0100 0101 for (KoXmlNode node = element.firstChild(); !node.isNull(); node = node.nextSibling()) 0102 { 0103 KoXmlElement child = node.toElement(); 0104 0105 if (child.namespaceURI() == KoXmlNS::text && child.localName() == "sort-key") { 0106 QString key = child.attributeNS(KoXmlNS::text, "key", QString()); 0107 Qt::SortOrder order = (child.attributeNS(KoXmlNS::text, "sort-ascending", "true") == "true") 0108 ? (Qt::AscendingOrder): (Qt::DescendingOrder); 0109 if(!key.isNull() && KoOdfBibliographyConfiguration::bibDataFields.contains(key)) { 0110 d->sortKeys << QPair<QString, Qt::SortOrder>(key,order); 0111 } 0112 } 0113 } 0114 } 0115 0116 void KoOdfBibliographyConfiguration::saveOdf(KoXmlWriter *writer) const 0117 { 0118 writer->startElement("text:bibliography-configuration"); 0119 0120 if (!d->prefix.isNull()) { 0121 writer->addAttribute("text:prefix", d->prefix); 0122 } 0123 0124 if (!d->suffix.isNull()) { 0125 writer->addAttribute("text:suffix", d->suffix); 0126 } 0127 0128 if (!d->sortAlgorithm.isNull()) { 0129 writer->addAttribute("text:sort-algorithm", d->sortAlgorithm); 0130 } 0131 0132 writer->addAttribute("text:numbered-entries", d->numberedEntries ? "true" : "false"); 0133 writer->addAttribute("text:sort-by-position", d->sortByPosition ? "true" : "false"); 0134 0135 foreach (const SortKeyPair &key, d->sortKeys) { 0136 writer->startElement("text:sort-key"); 0137 writer->addAttribute("text:key", key.first); 0138 writer->addAttribute("text:sort-ascending",key.second); 0139 writer->endElement(); 0140 } 0141 writer->endElement(); 0142 } 0143 0144 QString KoOdfBibliographyConfiguration::prefix() const 0145 { 0146 return d->prefix; 0147 } 0148 0149 QString KoOdfBibliographyConfiguration::suffix() const 0150 { 0151 return d->suffix; 0152 } 0153 0154 QString KoOdfBibliographyConfiguration::sortAlgorithm() const 0155 { 0156 return d->sortAlgorithm; 0157 } 0158 0159 bool KoOdfBibliographyConfiguration::sortByPosition() const 0160 { 0161 return d->sortByPosition; 0162 } 0163 0164 QVector<SortKeyPair> KoOdfBibliographyConfiguration::sortKeys() const 0165 { 0166 return d->sortKeys; 0167 } 0168 0169 bool KoOdfBibliographyConfiguration::numberedEntries() const 0170 { 0171 return d->numberedEntries; 0172 } 0173 0174 void KoOdfBibliographyConfiguration::setNumberedEntries(bool enable) 0175 { 0176 d->numberedEntries = enable; 0177 } 0178 0179 void KoOdfBibliographyConfiguration::setPrefix(const QString &prefixValue) 0180 { 0181 d->prefix = prefixValue; 0182 } 0183 0184 void KoOdfBibliographyConfiguration::setSuffix(const QString &suffixValue) 0185 { 0186 d->suffix = suffixValue; 0187 } 0188 0189 void KoOdfBibliographyConfiguration::setSortAlgorithm(const QString &algorithm) 0190 { 0191 d->sortAlgorithm = algorithm; 0192 } 0193 0194 void KoOdfBibliographyConfiguration::setSortByPosition(bool enable) 0195 { 0196 d->sortByPosition = enable; 0197 } 0198 0199 void KoOdfBibliographyConfiguration::setSortKeys(const QVector<SortKeyPair> &sortKeys) 0200 { 0201 d->sortKeys = sortKeys; 0202 }