1 /***************************************************************************
2     Copyright (C) 2003-2009 Robby Stephenson <robby@periapsis.org>
3  ***************************************************************************/
4 
5 /***************************************************************************
6  *                                                                         *
7  *   This program is free software; you can redistribute it and/or         *
8  *   modify it under the terms of the GNU General Public License as        *
9  *   published by the Free Software Foundation; either version 2 of        *
10  *   the License or (at your option) version 3 or any later version        *
11  *   accepted by the membership of KDE e.V. (or its successor approved     *
12  *   by the membership of KDE e.V.), which shall act as a proxy            *
13  *   defined in Section 14 of version 3 of the license.                    *
14  *                                                                         *
15  *   This program is distributed in the hope that it will be useful,       *
16  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
17  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
18  *   GNU General Public License for more details.                          *
19  *                                                                         *
20  *   You should have received a copy of the GNU General Public License     *
21  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
22  *                                                                         *
23  ***************************************************************************/
24 
25 #ifndef BIBTEXCOLLECTION_H
26 #define BIBTEXCOLLECTION_H
27 
28 #include "../collection.h"
29 
30 #include <QHash>
31 
32 namespace Tellico {
33   namespace Data {
34 
35 /**
36  * A collection specifically for bibliographies, in Bibtex format.
37  *
38  * @author Robby Stephenson
39  */
40 class BibtexCollection : public Collection {
41 Q_OBJECT
42 
43 public:
44   /**
45    * The constructor
46    *
47    * @param title The title of the collection
48    */
49   explicit BibtexCollection(bool addDefaultFields, const QString& title = QString());
50   /**
51    */
~BibtexCollection()52   virtual ~BibtexCollection() {}
53 
type()54   virtual Type type() const Q_DECL_OVERRIDE { return Bibtex; }
55   virtual bool addField(FieldPtr field) Q_DECL_OVERRIDE;
56   virtual bool modifyField(FieldPtr field) Q_DECL_OVERRIDE;
57   virtual bool removeField(FieldPtr field, bool force=false) Q_DECL_OVERRIDE;
58   virtual bool removeField(const QString& name, bool force=false) Q_DECL_OVERRIDE;
59 
60   FieldPtr fieldByBibtexName(const QString& name) const;
61   EntryPtr entryByBibtexKey(const QString& key) const;
preamble()62   const QString& preamble() const { return m_preamble; }
setPreamble(const QString & preamble)63   void setPreamble(const QString& preamble) { m_preamble = preamble; }
macroList()64   const StringMap& macroList() const { return m_macros; }
setMacroList(const StringMap & map)65   void setMacroList(const StringMap& map) { m_macros = map; }
addMacro(const QString & key,const QString & value)66   void addMacro(const QString& key, const QString& value) { m_macros.insert(key, value); }
removeMacro(const QString & key)67   void removeMacro(const QString& key) { m_macros.remove(key); }
68 
69   virtual QString prepareText(const QString& text) const Q_DECL_OVERRIDE;
70   virtual int sameEntry(Data::EntryPtr entry1, Data::EntryPtr entry2) const Q_DECL_OVERRIDE;
71 
72   EntryList duplicateBibtexKeys() const;
73 
74   static FieldList defaultFields();
75   static CollPtr convertBookCollection(CollPtr coll);
76   static bool setFieldValue(EntryPtr entry, const QString& bibtexField, const QString& value, CollPtr existingCollection);
77 
78 private:
79   QHash<QString, Data::Field*> m_bibtexFieldDict;
80   QString m_preamble;
81   StringMap m_macros;
82 };
83 
84   } // end namespace
85 } // end namespace
86 #endif
87