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

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 #ifndef BIBTEXCOLLECTION_H
0026 #define BIBTEXCOLLECTION_H
0027 
0028 #include "../collection.h"
0029 
0030 #include <QHash>
0031 
0032 namespace Tellico {
0033   namespace Data {
0034 
0035 /**
0036  * A collection specifically for bibliographies, in Bibtex format.
0037  *
0038  * @author Robby Stephenson
0039  */
0040 class BibtexCollection : public Collection {
0041 Q_OBJECT
0042 
0043 public:
0044   /**
0045    * The constructor
0046    *
0047    * @param title The title of the collection
0048    */
0049   explicit BibtexCollection(bool addDefaultFields, const QString& title = QString());
0050   /**
0051    */
0052   virtual ~BibtexCollection() {}
0053 
0054   virtual Type type() const Q_DECL_OVERRIDE { return Bibtex; }
0055   virtual bool addField(FieldPtr field) Q_DECL_OVERRIDE;
0056   virtual bool modifyField(FieldPtr field) Q_DECL_OVERRIDE;
0057   virtual bool removeField(FieldPtr field, bool force=false) Q_DECL_OVERRIDE;
0058   virtual bool removeField(const QString& name, bool force=false) Q_DECL_OVERRIDE;
0059 
0060   FieldPtr fieldByBibtexName(const QString& name) const;
0061   EntryPtr entryByBibtexKey(const QString& key) const;
0062   const QString& preamble() const { return m_preamble; }
0063   void setPreamble(const QString& preamble) { m_preamble = preamble; }
0064   const StringMap& macroList() const { return m_macros; }
0065   void setMacroList(const StringMap& map) { m_macros = map; }
0066   void addMacro(const QString& key, const QString& value) { m_macros.insert(key, value); }
0067   void removeMacro(const QString& key) { m_macros.remove(key); }
0068 
0069   virtual QString prepareText(const QString& text) const Q_DECL_OVERRIDE;
0070   virtual int sameEntry(Data::EntryPtr entry1, Data::EntryPtr entry2) const Q_DECL_OVERRIDE;
0071 
0072   EntryList duplicateBibtexKeys() const;
0073 
0074   static FieldList defaultFields();
0075   static CollPtr convertBookCollection(CollPtr coll);
0076   static bool setFieldValue(EntryPtr entry, const QString& bibtexField, const QString& value, CollPtr existingCollection);
0077 
0078 private:
0079   QHash<QString, Data::Field*> m_bibtexFieldDict;
0080   QString m_preamble;
0081   StringMap m_macros;
0082 };
0083 
0084   } // end namespace
0085 } // end namespace
0086 #endif