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

0001 /***************************************************************************
0002  *   SPDX-License-Identifier: GPL-2.0-or-later
0003  *                                                                         *
0004  *   SPDX-FileCopyrightText: 2004-2023 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 #include "fileimporterbibutils.h"
0021 
0022 #include <QBuffer>
0023 
0024 #include <File>
0025 #include "fileimporterbibtex.h"
0026 #include "fileimporter_p.h"
0027 #include "logging_io.h"
0028 
0029 class FileImporterBibUtils::Private
0030 {
0031 private:
0032     // UNUSED FileImporterBibUtils *p;
0033 
0034 public:
0035     FileImporterBibTeX *bibtexImporter;
0036 
0037     Private(FileImporterBibUtils *parent)
0038     // UNUSED : p(parent)
0039     {
0040         bibtexImporter = new FileImporterBibTeX(parent);
0041         connect(bibtexImporter, &FileImporterBibTeX::message, parent, &FileImporterBibUtils::message);
0042     }
0043 
0044     ~Private() {
0045         delete bibtexImporter;
0046     }
0047 };
0048 
0049 FileImporterBibUtils::FileImporterBibUtils(QObject *parent)
0050         : FileImporter(parent), BibUtils(), d(new FileImporterBibUtils::Private(this))
0051 {
0052     /// nothing
0053 }
0054 
0055 FileImporterBibUtils::~FileImporterBibUtils()
0056 {
0057     delete d;
0058 }
0059 
0060 File *FileImporterBibUtils::load(QIODevice *iodevice)
0061 {
0062     check_if_iodevice_invalid(iodevice);
0063 
0064     QBuffer buffer;
0065     const bool result = convert(*iodevice, format(), buffer, BibUtils::Format::BibTeX);
0066     iodevice->close();
0067 
0068     if (result)
0069         return d->bibtexImporter->load(&buffer);
0070     else
0071         return nullptr;
0072 }