File indexing completed on 2024-05-19 05:05:31

0001 /***************************************************************************
0002  *   SPDX-License-Identifier: GPL-2.0-or-later
0003  *                                                                         *
0004  *   SPDX-FileCopyrightText: 2004-2021 Thomas Fischer <fischer@unix-ag.uni-kl.de>
0005  *                                                                         *
0006  *   This program is free software; you can redistribute it and/or modify  *
0007  *   it under the terms of the GNU General Public License as published by  *
0008  *   the Free Software Foundation; either version 2 of the License, or     *
0009  *   (at your option) any later version.                                   *
0010  *                                                                         *
0011  *   This program is distributed in the hope that it will be useful,       *
0012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0014  *   GNU General Public License for more details.                          *
0015  *                                                                         *
0016  *   You should have received a copy of the GNU General Public License     *
0017  *   along with this program; if not, see <https://www.gnu.org/licenses/>. *
0018  ***************************************************************************/
0019 
0020 #ifndef KBIBTEX_IO_BIBUTILS_H
0021 #define KBIBTEX_IO_BIBUTILS_H
0022 
0023 #include <QIODevice>
0024 
0025 #ifdef HAVE_KF
0026 #include "kbibtexio_export.h"
0027 #endif // HAVE_KF
0028 
0029 /**
0030  * This class encapsulates calling the various binary programs of the BibUtils program set.
0031  * BibUtils is available at https://sourceforge.net/projects/bibutils/
0032  *
0033  * This class is inherited by @see FileImporterBibUtils and @see FileExporterBibUtils,
0034  * which make use of its protected functions.
0035  * Using this class directly should only happen to call its public static functions.
0036  *
0037  * @author Thomas Fischer <fischer@unix-ag.uni-kl.de>
0038  */
0039 class KBIBTEXIO_EXPORT BibUtils
0040 {
0041 public:
0042     ~BibUtils();
0043 
0044     enum class Format { InvalidFormat = -1, MODS = 0, BibTeX = 1, BibLaTeX = 2, ISI = 5, RIS = 6, EndNote = 10, EndNoteXML = 11, ADS = 15, WordBib = 16, Copac = 17, Med = 18 };
0045 
0046     BibUtils::Format format() const;
0047     void setFormat(const BibUtils::Format format);
0048 
0049     /**
0050      * Test if BibUtils is installed. This test checks if a number of known
0051      * BibUtils binaries are available (i.e. found in PATH). If any binary
0052      * is missing, it is assumed that BibUtils is not available. The test is
0053      * performed only once and the result cached for future calls to this function.
0054      * @return true if BibUtils is correctly installed, false otherwise
0055      */
0056     static bool available();
0057 
0058 protected:
0059     explicit BibUtils();
0060 
0061     // TODO migrate to KJob or KCompositeJob
0062     bool convert(QIODevice &source, const BibUtils::Format sourceFormat, QIODevice &destination, const BibUtils::Format destinationFormat) const;
0063 
0064 private:
0065     Q_DISABLE_COPY(BibUtils)
0066 
0067     class Private;
0068     Private *const d;
0069 };
0070 
0071 KBIBTEXIO_EXPORT QDebug operator<<(QDebug dbg, const BibUtils::Format &format);
0072 
0073 #endif // KBIBTEX_IO_BIBUTILS_H