File indexing completed on 2024-05-12 16:06:49
0001 /* 0002 SPDX-FileCopyrightText: 2013 Azat Khuzhin <a3at.mail@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "document.h" 0008 0009 #include <QDataStream> 0010 #include <QFile> 0011 0012 #include <QDebug> 0013 #include <QStringDecoder> 0014 0015 #include "debug_txt.h" 0016 0017 using namespace Txt; 0018 0019 Document::Document(const QString &fileName) 0020 { 0021 #ifdef TXT_DEBUG 0022 qCDebug(OkularTxtDebug) << "Opening file" << fileName; 0023 #endif 0024 0025 QFile plainFile(fileName); 0026 if (!plainFile.open(QIODevice::ReadOnly | QIODevice::Text)) { 0027 qCDebug(OkularTxtDebug) << "Can't open file" << plainFile.fileName(); 0028 return; 0029 } 0030 0031 const QByteArray buffer = plainFile.readAll(); 0032 setPlainText(toUnicode(buffer)); 0033 } 0034 0035 Document::~Document() 0036 { 0037 } 0038 0039 QString Document::toUnicode(const QByteArray &array) 0040 { 0041 auto encoding = QStringConverter::encodingForHtml(array); 0042 QStringDecoder decoder {encoding.value_or(QStringConverter::Encoding::Utf8)}; 0043 return decoder.decode(array); 0044 } 0045 0046 Q_LOGGING_CATEGORY(OkularTxtDebug, "org.kde.okular.generators.txt", QtWarningMsg)