Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/common/CSyntaxHighlighter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,28 @@ CSyntaxHighlighter::CSyntaxHighlighter(QObject *parent):
SyntaxHighlighter (parent),
m_bHighlight(false)
{

qDebug() << "CSyntaxHighlighter constructor";
}

CSyntaxHighlighter::CSyntaxHighlighter(QTextDocument *pDocument):
SyntaxHighlighter (pDocument),m_bHighlight(false)
{

qDebug() << "CSyntaxHighlighter constructor with QTextDocument*";
}

void CSyntaxHighlighter::setEnableHighlight(bool isEnable)
{
qDebug() << "CSyntaxHighlighter::setEnableHighlight()" << isEnable;
m_bHighlight = isEnable;
}

void CSyntaxHighlighter::highlightBlock(const QString &text)
{
if (!m_bHighlight) {
qDebug() << "CSyntaxHighlighter::highlightBlock() is disabled";
return;
}

qDebug() << "CSyntaxHighlighter::highlightBlock()";
KSyntaxHighlighting::SyntaxHighlighter::highlightBlock(text);
}
10 changes: 8 additions & 2 deletions src/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ const QString g_keyEnablePatchedIconv = "enablePatchedIconv";
*/
bool detectIconvUse2005Standard()
{
qDebug() << "Detecting iconv use GB18030-2005 standard";
iconv_t handle = iconv_open("UTF-8", "GB18030");
if (handle == reinterpret_cast<iconv_t>(-1)) {
qWarning() << "Failed to open iconv handle for GB18030";
return true;
}

Expand All @@ -41,15 +43,16 @@ bool detectIconvUse2005Standard()
iconv_close(handle);

if (ret == static_cast<size_t>(-1)) {
qWarning() << "Failed to convert GB18030 to UTF-8";
return true;
}

if (!output.contains("\uE816")) {
qInfo() << "Current iconv gb18030 standard is 2005.";
qInfo() << "Current iconv uses GB18030-2005 standard";
return true;
}

qInfo() << "Current iconv gb18030 standard is 2022.";
qInfo() << "Current iconv uses GB18030-2022 standard";
return false;
}

Expand All @@ -64,6 +67,7 @@ Config::Config(QObject *parent)
: QObject(parent)
, encoding("UTF-8")
{
qDebug() << "Initializing Config instance";
#ifdef DTKCORE_CLASS_DConfigFile
dconfig = DConfig::create("org.deepin.editor", "org.deepin.editor");
if (dconfig->isValid()) {
Expand Down Expand Up @@ -103,6 +107,7 @@ Config::Config(QObject *parent)

Config::~Config()
{
qDebug() << "Destroying Config instance";
#ifdef DTKCORE_CLASS_DConfigFile
if (dconfig) {
delete dconfig;
Expand All @@ -112,6 +117,7 @@ Config::~Config()

Config *Config::instance()
{
qDebug() << "Getting Config singleton instance";
static Config config;
return &config;
}
Expand Down
4 changes: 4 additions & 0 deletions src/common/dbusinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

#include "dbusinterface.h"

#include <QDebug>

Check warning on line 7 in src/common/dbusinterface.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 7 in src/common/dbusinterface.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.

SaveFileInterface::SaveFileInterface(const QString &service, const QString &path, const QDBusConnection &connection, QObject *parent)
: QDBusAbstractInterface(service, path, staticInterfaceName(), connection, parent)
{
qDebug() << "SaveFileInterface created for" << service << path;
}

SaveFileInterface::~SaveFileInterface()
{
qDebug() << "SaveFileInterface destroyed for" << service() << path();
}
11 changes: 9 additions & 2 deletions src/common/eventlogutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,42 @@

#include "eventlogutils.h"
#include <QLibrary>
#include <QDir>

Check warning on line 7 in src/common/eventlogutils.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QDir> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 7 in src/common/eventlogutils.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDir> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QLibraryInfo>

Check warning on line 8 in src/common/eventlogutils.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QLibraryInfo> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 8 in src/common/eventlogutils.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QLibraryInfo> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QJsonDocument>

Check warning on line 9 in src/common/eventlogutils.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QJsonDocument> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 9 in src/common/eventlogutils.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QJsonDocument> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDebug>

Check warning on line 10 in src/common/eventlogutils.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 10 in src/common/eventlogutils.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Eventlogutils *Eventlogutils::m_pInstance = nullptr;
Eventlogutils *Eventlogutils::GetInstance()

Check warning on line 13 in src/common/eventlogutils.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

The function 'GetInstance' is never used.

Check warning on line 13 in src/common/eventlogutils.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'GetInstance' is never used.
{
qDebug() << "Eventlogutils::GetInstance()";
if (m_pInstance == nullptr) {
m_pInstance = new Eventlogutils();
}
return m_pInstance;
}

void Eventlogutils::writeLogs(QJsonObject &data)

Check warning on line 22 in src/common/eventlogutils.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

The function 'writeLogs' is never used.

Check warning on line 22 in src/common/eventlogutils.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'writeLogs' is never used.
{
if (!writeEventLogFunc)
if (!writeEventLogFunc) {
qWarning() << "writeEventLogFunc is not initialized";
return;
}

writeEventLogFunc(QJsonDocument(data).toJson(QJsonDocument::Compact).toStdString());
}

Eventlogutils::Eventlogutils()
{
qDebug() << "Eventlogutils::Eventlogutils()";
QLibrary library("libdeepin-event-log.so");
initFunc = reinterpret_cast<bool (*)(const std::string &, bool)>(library.resolve("Initialize"));
writeEventLogFunc = reinterpret_cast<void (*)(const std::string &)>(library.resolve("WriteEventLog"));

if (!initFunc)
if (!initFunc) {
qWarning() << "Failed to load libdeepin-event-log.so";
return;
}

initFunc("deepin-editor", true);
}
17 changes: 15 additions & 2 deletions src/common/fileloadthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ FileLoadThread::FileLoadThread(const QString &filepath, QObject *parent)
: QThread(parent),
m_strFilePath(filepath)
{

qDebug() << "Creating FileLoadThread for file:" << filepath;
}

FileLoadThread::~FileLoadThread()
{
qDebug() << "Destroying FileLoadThread for file:" << m_strFilePath;
}

void FileLoadThread::run()
{
qDebug() << "Starting file load thread for:" << m_strFilePath;
QFile file(m_strFilePath);

if (file.open(QIODevice::ReadOnly)) {
Expand All @@ -30,9 +32,11 @@ void FileLoadThread::run()
// 判断文件大小是否超过40MB, 超过40MB的文件过大,需要调整读取策略,优先加载头部文件
static const int s_maxDirectReadLen = 40 * DATA_SIZE_1024 * DATA_SIZE_1024;
if (file.size() > s_maxDirectReadLen) {
qDebug() << "Large file detected (" << file.size() << " bytes), using optimized loading strategy";
// 先读取1MB数据
indata = file.read(DATA_SIZE_1024 * DATA_SIZE_1024);
encode = DetectCode::GetFileEncodingFormat(m_strFilePath, indata);
qDebug() << "Initial encoding detection result:" << encode;

// 发送文件头信息,用于预先加载数据
QString textEncode = QString::fromLocal8Bit(encode);
Expand All @@ -47,18 +51,21 @@ void FileLoadThread::run()

// 读取申请开辟内存空间时,捕获可能出现的 std::bad_alloc() 异常,防止闪退。
try {
qDebug() << "Reading remaining file content";
// reads all remaining data from the file.
indata += file.read(file.size());
file.close();
qDebug() << "Total bytes read:" << indata.size();
} catch (const std::exception &e) {
qWarning() << Q_FUNC_INFO << "Read file data error, " << QString(e.what());
qWarning() << "FileLoadThread read error:" << e.what() << "at" << m_strFilePath;

file.close();
emit sigLoadFinished(encode, indata, true);
return;
}

if (encode.isEmpty()) {
qDebug() << "Performing full encoding detection";
//编码识别,如果文件数据大于1M,则只裁剪出1M文件数据去做编码探测
QByteArray dateUsedForCodeIdentify;
if (indata.length() > DATA_SIZE_1024 * DATA_SIZE_1024) {
Expand All @@ -70,15 +77,21 @@ void FileLoadThread::run()
}

QString textEncode = QString::fromLocal8Bit(encode);
qDebug() << "Final encoding detected:" << textEncode;
if (textEncode.contains("ASCII", Qt::CaseInsensitive) || textEncode.contains("UTF-8", Qt::CaseInsensitive)) {
qDebug() << "Using original encoding, no conversion needed";
emit sigLoadFinished(encode, indata, false);
} else {
qDebug() << "Converting from" << textEncode << "to UTF-8";
QByteArray outData;
DetectCode::ChangeFileEncodingFormat(indata, outData, textEncode, QString("UTF-8"));
emit sigLoadFinished(encode, outData, false);
qDebug() << "Encoding conversion completed, output size:" << outData.size();
}
}

qDebug() << "FileLoadThread finished processing:" << m_strFilePath;
this->quit();
this->deleteLater();
qDebug() << "FileLoadThread resources cleaned up";
}
Loading
Loading