Skip to content

Commit

Permalink
get rid codecs
Browse files Browse the repository at this point in the history
  • Loading branch information
psemiletov committed Apr 28, 2024
1 parent ee71340 commit 7d8e3d2
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 27 deletions.
16 changes: 9 additions & 7 deletions src/document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ code from qwriter:
#include <bitset>
#include <algorithm>

#include <QTextCodec>
//#include <QTextCodec>
#include <QApplication>
#include <QClipboard>
#include <QSettings>
Expand Down Expand Up @@ -1529,14 +1529,16 @@ bool CDocument::file_save_with_name_plain (const QString &fileName)
if (! file.open (QFile::WriteOnly))
return false;

QTextCodec *codec = QTextCodec::codecForName (charset.toUtf8().data());
if (! codec)
return false;

QByteArray ba = codec->fromUnicode (toPlainText());
file_save_with_name (fileName, charset);
//QTextCodec *codec = QTextCodec::codecForName (charset.toUtf8().data());
//if (! codec)
// return false;

//QByteArray ba = codec->fromUnicode (toPlainText());

file.write (ba);
file.close();
//file.write (ba);
//file.close();

holder->update_current_files_menu();

Expand Down
36 changes: 26 additions & 10 deletions src/spellchecker.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***************************************************************************
* 2007-2021 by Peter Semiletov *
* 2007-2024 by Peter Semiletov *
* peter.semiletov@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
Expand Down Expand Up @@ -31,13 +31,14 @@
#endif


#include <QTextCodec>
//#include <QTextCodec>
#include <QDir>
#include <QMessageBox>
#include <QObject>

#include "spellchecker.h"
#include "utils.h"
#include "enc.h"


#ifdef ASPELL_ENABLE
Expand Down Expand Up @@ -303,6 +304,10 @@ void CHunspellChecker::load_dict()
encoding = speller->get_dic_encoding();
#else
str_encoding = speller->get_dict_encoding();

// std::cout << "str_encoding : " << str_encoding << std::endl;
qDebug() << "str_encoding : " << str_encoding;

#endif


Expand Down Expand Up @@ -367,14 +372,16 @@ void CHunspellChecker::add_to_user_dict (const QString &word)
{
if (! loaded || word.isEmpty())
return;

/*
#if !defined (H_DEPRECATED)
QTextCodec *codec = QTextCodec::codecForName (encoding);
#else
QTextCodec *codec = QTextCodec::codecForName (str_encoding.data());
#endif
QByteArray es = codec->fromUnicode (word);
QByteArray es = codec->fromUnicode (word);*/

QByteArray es = word.toUtf8();
speller->add (es.data());
user_words.append (word);
save_user_dict();
Expand All @@ -391,14 +398,16 @@ bool CHunspellChecker::check (const QString &word)

if (! loaded)
load_dict();

/*
#if ! defined (H_DEPRECATED)
QTextCodec *codec = QTextCodec::codecForName (encoding);
#else
QTextCodec *codec = QTextCodec::codecForName (str_encoding.data());
#endif
*/
//QByteArray es = codec->fromUnicode (word);

QByteArray es = codec->fromUnicode (word);
QByteArray es = word.toUtf8();

#ifndef H_DEPRECATED
return speller->spell (es.constData());
Expand All @@ -413,14 +422,17 @@ void CHunspellChecker::remove_from_user_dict (const QString &word)
{
if (! loaded || word.isEmpty())
return;

/*
#ifndef H_DEPRECATED
QTextCodec *codec = QTextCodec::codecForName (encoding);
#else
QTextCodec *codec = QTextCodec::codecForName (str_encoding.data());
#endif
*/
// QByteArray es = codec->fromUnicode (word);

QByteArray es = word.toUtf8();

QByteArray es = codec->fromUnicode (word);
speller->remove (es.data());
int i = user_words.indexOf (word);
if (i != -1)
Expand Down Expand Up @@ -459,22 +471,26 @@ QStringList CHunspellChecker::get_suggestions_list (const QString &word)

if (! loaded || word.isEmpty())
return sl;

/*
#if !defined (H_DEPRECATED)
QTextCodec *codec = QTextCodec::codecForName (encoding);
#else
QTextCodec *codec = QTextCodec::codecForName (str_encoding.data());
#endif
QByteArray es = codec->fromUnicode (word);
*/

QByteArray es = word.toUtf8();

#ifndef H_DEPRECATED
char **slst;

int size = speller->suggest (&slst, es.data());

for (int i = 0; i < size; i++)
sl.append (codec->toUnicode (slst[i]));
//sl.append (codec->toUnicode (slst[i]));
sl.append (QString::fromUtf8 slst[i]);

speller->free_list (&slst, size);

Expand Down
8 changes: 5 additions & 3 deletions src/tea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ C++/Qt branch started at 08 November 2007
#include <QGroupBox>
#include <QImageWriter>
#include <QColorDialog>
#include <QTextCodec>
//#include <QTextCodec>
#include <QMimeData>
#include <QScrollArea>
#include <QXmlStreamReader>
Expand Down Expand Up @@ -9447,8 +9447,10 @@ void CTEA::process_readyReadStandardOutput()
{
QProcess *p = qobject_cast<QProcess *>(sender());
QByteArray a = p->readAllStandardOutput()/*.data()*/;
QTextCodec *c = QTextCodec::codecForLocale();
QString t = c->toUnicode (a);
// QTextCodec *c = QTextCodec::codecForLocale();
// QString t = c->toUnicode (a);
QString t = QString::fromUtf8 (a.data());


log->terminal_output = true;
log->log (t);
Expand Down
14 changes: 8 additions & 6 deletions src/tio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ DJVU read code taken fromdvutxt.c:
#include <QDataStream>
#include <QTextStream>
#include <QDebug>
#include <QTextCodec>
//#include <QTextCodec>
#include <QTextBrowser>
#include <QSettings>

Expand Down Expand Up @@ -705,7 +705,7 @@ bool is_valid_utf8 (const char *string)
QString CCharsetMagic::guess_for_file (const QString &fname)
{
QString enc = "UTF-8";

/*
QByteArray bafile = file_load (fname);
QString ext = file_get_ext (fname);
Expand All @@ -731,7 +731,7 @@ QString CCharsetMagic::guess_for_file (const QString &fname)
return enc;
}
}

*/
return enc;
}

Expand Down Expand Up @@ -1088,11 +1088,11 @@ CTioRTF::CTioRTF()
extensions.append ("rtf");
}


//BROKEN
bool CTioRTF::load (const QString &fname)
{
QByteArray ba = file_load (fname);

/*
QString text;
text.reserve (ba.size());
Expand Down Expand Up @@ -1150,7 +1150,9 @@ bool CTioRTF::load (const QString &fname)
data = rtf_strip (text);
return true;
return true;*/

return false;
}

#if defined (POPPLER_ENABLE)
Expand Down
2 changes: 1 addition & 1 deletion src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Peter Semiletov


#include <QTextStream>
#include <QTextCodec>
//#include <QTextCodec>
#include <QDebug>
#include <QDir>
#include <QImageReader>
Expand Down

0 comments on commit 7d8e3d2

Please sign in to comment.