kde-extraapps/okular/generators/txt/document.cpp
Ivailo Monev a3d30e304b okular: use QTextCodec::codecForText() for codec detection in txt generator
QTextCodec::codecForUtfText() can detect only unicode signatures (on
purpose) while QTextCodec::codecForText() can detect more

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
2022-12-02 21:35:27 +02:00

41 lines
1.2 KiB
C++

/***************************************************************************
* Copyright (C) 2013 by Azat Khuzhin <a3at.mail@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include <QFile>
#include <QDataStream>
#include <QTextCodec>
#include <kdebug.h>
#include "document.h"
using namespace Txt;
Document::Document( const QString &fileName )
{
#ifdef TXT_DEBUG
kDebug() << "Opening file" << fileName;
#endif
QFile plainFile( fileName );
if ( !plainFile.open( QIODevice::ReadOnly | QIODevice::Text ) )
{
kDebug() << "Can't open file" << plainFile.fileName();
return;
}
const QByteArray buffer = plainFile.readAll();
QTextCodec *codec = QTextCodec::codecForText(buffer);
setPlainText( codec->toUnicode( buffer ) );
}
Document::~Document()
{
}