File indexing completed on 2024-05-12 05:10:08

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 TELLICO_BIBTEXIMPORTER_H
0026 #define TELLICO_BIBTEXIMPORTER_H
0027 
0028 #include "importer.h"
0029 #include "../datavectors.h"
0030 
0031 #include <config.h>
0032 #ifdef ENABLE_BTPARSE
0033 extern "C" {
0034 #ifdef HAVE_LIBBTPARSE
0035 /* btparse has a struct member 'class' */
0036 #define class errclass
0037 #include <btparse.h>
0038 #undef class
0039 #else
0040 #include "btparse/btparse.h"
0041 #endif
0042 }
0043 #else
0044 class AST;
0045 #endif
0046 
0047 #include <QList>
0048 #include <QHash>
0049 
0050 class QRadioButton;
0051 
0052 namespace Tellico {
0053   namespace Import {
0054 
0055 /**
0056  * Bibtex files are used for bibliographies within LaTex. The btparse library is used to
0057  * parse the text and generate a @ref BibtexCollection.
0058  *
0059  * @author Robby Stephenson
0060  */
0061 class BibtexImporter : public Importer {
0062 Q_OBJECT
0063 
0064 public:
0065   /**
0066    * Initializes the btparse library
0067    *
0068    * @param url The url of the bibtex file
0069    */
0070   BibtexImporter(const QList<QUrl>& urls);
0071   BibtexImporter(const QString& text);
0072   /*
0073    * Some cleanup is done for the btparse library
0074    */
0075   virtual ~BibtexImporter();
0076 
0077   /**
0078    * Returns a pointer to a @ref BibtexCollection created on the stack. All entries
0079    * in the bibtex file are added, including any preamble, all macro strings, and each entry.
0080    *
0081    * @return A pointer to a @ref BibtexCollection, or 0 if none can be created.
0082    */
0083   virtual Data::CollPtr collection() Q_DECL_OVERRIDE;
0084   virtual QWidget* widget(QWidget* parent) Q_DECL_OVERRIDE;
0085   virtual bool canImport(int type) const Q_DECL_OVERRIDE;
0086 
0087   static bool maybeBibtex(const QUrl& url);
0088   static bool maybeBibtex(const QString& text, const QUrl& url = QUrl());
0089 
0090 public Q_SLOTS:
0091   void slotCancel() Q_DECL_OVERRIDE;
0092 
0093 private:
0094   void init();
0095   Data::CollPtr readCollection(const QString& text, int n);
0096   void parseText(const QString& text);
0097   void appendCollection(Data::CollPtr newColl);
0098 
0099   QList<AST*> m_nodes;
0100   QHash<QString, QString> m_macros;
0101 
0102   Data::CollPtr m_coll;
0103   QWidget* m_widget;
0104   QRadioButton* m_readUTF8;
0105   QRadioButton* m_readLocale;
0106   bool m_cancelled : 1;
0107 
0108   static int s_initCount;
0109 };
0110 
0111   } // end namespace
0112 } // end namespace
0113 #endif