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
13 changes: 7 additions & 6 deletions 3rdparty/deepin-pdfium/src/dpdfdoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "dpdfdoc.h"
#include "dpdflog.h"
#include "dpdfpage.h"

#include "public/fpdfview.h"
Expand Down Expand Up @@ -131,14 +132,14 @@ DPdfDoc::Status DPdfDocPrivate::loadFile(const QString &filePath, const QString

DPdfMutexLocker locker("DPdfDocPrivate::loadFile");

qDebug() << "deepin-pdfium正在加载PDF文档... 文档名称: " << filePath;
qCDebug(dpfLog) << "deepin-pdfium正在加载PDF文档... 文档名称: " << filePath;
void *ptr = FPDF_LoadDocument(m_filePath.toUtf8().constData(),
password.toUtf8().constData());

m_docHandler = static_cast<DPdfDocHandler *>(ptr);

m_status = m_docHandler ? DPdfDoc::SUCCESS : parseError(static_cast<int>(FPDF_GetLastError()));
qDebug() << "文档(" << filePath << ")文档加载状态: " << m_status;
qCDebug(dpfLog) << "文档(" << filePath << ")文档加载状态: " << m_status;

if (m_docHandler) {
m_pageCount = FPDF_GetPageCount(reinterpret_cast<FPDF_DOCUMENT>(m_docHandler));
Expand Down Expand Up @@ -202,7 +203,7 @@ bool DPdfDoc::isLinearized(const QString &fileName)
{
QFile file(fileName);
if (!file.open(QFile::ReadOnly)) {
qInfo() << "file open failed when isLinearized" << fileName;
qCInfo(dpfLog) << "file open failed when isLinearized" << fileName;
}
QByteArray content = file.readAll();
int len = content.length();
Expand Down Expand Up @@ -279,15 +280,15 @@ bool DPdfDoc::save()
// Rename original file to backup instead of deleting (avoids SMB file handle issues)
if (targetFile.exists()) {
if (!targetFile.rename(backupPath)) {
qWarning() << "Failed to rename original file to backup:" << targetPath;
qCWarning(dpfLog) << "Failed to rename original file to backup:" << targetPath;
return false;
}
}

// Write new file
QFile newFile(targetPath);
if (!newFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
qWarning() << "Failed to open file for writing:" << targetPath;
qCWarning(dpfLog) << "Failed to open file for writing:" << targetPath;
// Restore original file on failure
if (QFile::exists(backupPath)) {
QFile::rename(backupPath, targetPath);
Expand All @@ -296,7 +297,7 @@ bool DPdfDoc::save()
}

if (array.size() != newFile.write(array)) {
qWarning() << "Failed to write data to file:" << targetPath;
qCWarning(dpfLog) << "Failed to write data to file:" << targetPath;
result = false;
newFile.close();
newFile.remove();
Expand Down
9 changes: 6 additions & 3 deletions 3rdparty/deepin-pdfium/src/dpdfglobal.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include <QtCore>
#include <QString>
#include <QDebug>
#include "dpdfglobal.h"
#include "dpdflog.h"
#include "public/fpdfview.h"

#include <chardet.h>

Q_LOGGING_CATEGORY(dpfLog, "org.deepin.reader.pdfium")

static bool initialized = false;

const static DPdfGlobal instance = DPdfGlobal();
Expand Down Expand Up @@ -60,11 +63,11 @@ DPdfMutexLocker::DPdfMutexLocker(const QString &tmpLog): QMutexLocker<QRecursive
#endif
{
m_log = tmpLog;
qInfo() << m_log + " begin ";
qCInfo(dpfLog) << m_log + " begin ";
m_timer.start();
}

DPdfMutexLocker::~DPdfMutexLocker()
{
qInfo() << m_log + " end time = " << m_timer.elapsed();
qCInfo(dpfLog) << m_log + " end time = " << m_timer.elapsed();
}
14 changes: 14 additions & 0 deletions 3rdparty/deepin-pdfium/src/dpdflog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#ifndef DPDFLOG_H
#define DPDFLOG_H

#include <QLoggingCategory>

// deepin-pdfium 日志分类:挂在 org.deepin.reader 前缀下,
// 可被 DConfig(log_rules) 的 org.deepin.reader* 通配规则统一过滤
Q_DECLARE_LOGGING_CATEGORY(dpfLog)

#endif // DPDFLOG_H
2 changes: 2 additions & 0 deletions batch-print/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ add_library(batchprint-core STATIC

target_include_directories(batchprint-core PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
# 引用 reader/ddlog.h 的日志分类定义
${CMAKE_SOURCE_DIR}/reader
)

target_link_libraries(batchprint-core PUBLIC
Expand Down
8 changes: 5 additions & 3 deletions batch-print/batchprintapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
#include "errormessages.h"

#include <QTemporaryDir>
#include <QFileInfo>

Check warning on line 11 in batch-print/batchprintapp.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 12 in batch-print/batchprintapp.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.

#include "ddlog.h"

Check warning on line 14 in batch-print/batchprintapp.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "ddlog.h" not found.

BatchPrintApp::BatchPrintApp(ICupsApi *cupsApi)
{
if (cupsApi) {
Expand All @@ -33,12 +35,12 @@
CupsClient *cups = dynamic_cast<CupsClient *>(m_cupsApi);
if (cups) {
if (!cups->init()) {
qWarning() << "CUPS init failed";
qCWarning(batchprintLog) << "CUPS init failed";
NotifyClient::notifyError(ErrorMessages::cupsUnavailable());
return 2;
}
if (!cups->checkEnvironment()) {
qWarning() << "CUPS environment check failed";
qCWarning(batchprintLog) << "CUPS environment check failed";
NotifyClient::notifyError(ErrorMessages::noDefaultPrinter());
return 2;
}
Expand All @@ -64,7 +66,7 @@
QString errorMsg;
if (!FormatConverter::convertToPdf(filePath, tempDir.path(),
outputPdfPath, errorMsg)) {
qWarning() << errorMsg;
qCWarning(batchprintLog) << errorMsg;
failedFiles.append(QFileInfo(filePath).fileName());
continue;
}
Expand Down
8 changes: 5 additions & 3 deletions batch-print/cupsclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
#include <cups/cups.h>
#include <cups/ipp.h>

#include <QUrl>

Check warning on line 10 in batch-print/cupsclient.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 11 in batch-print/cupsclient.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.

#include "ddlog.h"

Check warning on line 13 in batch-print/cupsclient.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "ddlog.h" not found.

#include <cstdlib>

Check warning on line 15 in batch-print/cupsclient.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

typedef int (*cupsGetDests_fn)(cups_dest_t **dests);
typedef void (*cupsFreeDests_fn)(int num_dests, cups_dest_t *dests);
Expand Down Expand Up @@ -55,13 +57,13 @@
{
m_lib.setFileName(QStringLiteral("cups"));
if (!m_lib.load()) {
qWarning() << "Failed to dlopen libcups:" << m_lib.errorString();
qCWarning(batchprintLog) << "Failed to dlopen libcups:" << m_lib.errorString();
return false;
}

m_loaded = loadSymbols();
if (!m_loaded) {
qWarning() << "Failed to resolve CUPS symbols";
qCWarning(batchprintLog) << "Failed to resolve CUPS symbols";
return false;
}

Expand All @@ -74,9 +76,9 @@
return false;

cups_dest_t *dests = nullptr;
int numDest = ((cupsGetDests_fn)m_cupsGetDests)(&dests);

Check warning on line 79 in batch-print/cupsclient.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

C-style pointer casting detected. C++ offers four different kinds of casts as replacements: static_cast, const_cast, dynamic_cast and reinterpret_cast. A C-style cast could evaluate to any of those automatically, thus it is considered safer if the programmer explicitly states which kind of cast is expected.
if (numDest <= 0) {
qWarning() << "No printers found";
qCWarning(batchprintLog) << "No printers found";
return false;
}

Expand Down
7 changes: 7 additions & 0 deletions htmltopdf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: GPL-3.0-or-later

# 定义htmltopdf可执行文件
add_executable(htmltopdf
main.cpp
Expand All @@ -14,6 +18,9 @@ set_target_properties(htmltopdf PROPERTIES

find_package(Qt${QT_DESIRED_VERSION} REQUIRED COMPONENTS WebEngineWidgets)

# 引用 reader/ddlog.h 的日志分类定义
target_include_directories(htmltopdf PRIVATE ${CMAKE_SOURCE_DIR}/reader)

# 链接Qt模块
target_link_libraries(htmltopdf PRIVATE
Qt${QT_VERSION_MAJOR}::WebEngineWidgets
Expand Down
16 changes: 9 additions & 7 deletions htmltopdf/htmltopdfconverter.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
// Copyright (C) 2019 ~ 2020 Uniontech Software Technology Co.,Ltd.
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "htmltopdfconverter.h"

#include <QApplication>

Check warning on line 8 in htmltopdf/htmltopdfconverter.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

#include "ddlog.h"

Check warning on line 10 in htmltopdf/htmltopdfconverter.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "ddlog.h" not found.

HtmltoPdfConverter::HtmltoPdfConverter(const QString &inputPath, const QString &outputPath)
: m_inputPath(inputPath)
, m_outputPath(outputPath)
, m_page(new QWebEnginePage)
{
qDebug() << "HtmltoPdfConverter initialized with input:" << inputPath << "output:" << outputPath;
qCDebug(htmltopdfLog) << "HtmltoPdfConverter initialized with input:" << inputPath << "output:" << outputPath;

connect(m_page.data(), &QWebEnginePage::loadFinished,
this, &HtmltoPdfConverter::loadFinished);
Expand All @@ -22,27 +24,27 @@

int HtmltoPdfConverter::run()
{
qDebug() << "Starting HTML to PDF conversion process";
qCDebug(htmltopdfLog) << "Starting HTML to PDF conversion process";
QUrl url = QUrl::fromUserInput(m_inputPath);
qDebug() << "Loading HTML file from path:" << url;
qCDebug(htmltopdfLog) << "Loading HTML file from path:" << url;
m_page->load(url);
return QCoreApplication::exec();
}

void HtmltoPdfConverter::loadFinished(bool ok)
{
if (!ok) {
qWarning() << QString("Failed to load URL '%1'").arg(m_inputPath);
qCWarning(htmltopdfLog) << QString("Failed to load URL '%1'").arg(m_inputPath);
QCoreApplication::exit(1);
}
qInfo() << QString("Successfully loaded URL '%1'").arg(m_inputPath);
qCInfo(htmltopdfLog) << QString("Successfully loaded URL '%1'").arg(m_inputPath);
m_page->printToPdf(m_outputPath);
}

void HtmltoPdfConverter::pdfPrintingFinished(const QString &filePath, bool success)
{
if (!success) {
qWarning() << QString("Failed to print to output file '%1'").arg(filePath);
qCWarning(htmltopdfLog) << QString("Failed to print to output file '%1'").arg(filePath);
QCoreApplication::exit(1);
} else {
QCoreApplication::quit();
Expand Down
24 changes: 13 additions & 11 deletions htmltopdf/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (C) 2019 ~ 2020 Uniontech Software Technology Co.,Ltd.
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand All @@ -10,26 +10,28 @@
#include <QProcessEnvironment>
#include <QDebug>

#include "ddlog.h"

bool isWayland();

int main(int argc, char *argv[])
{
qDebug() << "Starting html2pdf converter application";
qCDebug(htmltopdfLog) << "Starting html2pdf converter application";

QApplication app(argc, argv);
QApplication::setApplicationName("html2pdf");
QApplication::setApplicationVersion("v1.0");

bool wayland = isWayland();
qDebug() << "Wayland environment detected:" << wayland;
qCDebug(htmltopdfLog) << "Wayland environment detected:" << wayland;
if (wayland) {
qDebug() << "Wayland detected, disabling GPU";
qCDebug(htmltopdfLog) << "Wayland detected, disabling GPU";
// 解决klu panguV平台使用QWebEnginePage崩溃的问题,不支持gpu渲染
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--disable-gpu");
}
// 解决__sw_64__平台使用QWebEnginePage崩溃的问题
#ifdef __sw_64__
qDebug() << "Running on __sw_64__ platform, --js-flags=--jitless";
qCDebug(htmltopdfLog) << "Running on __sw_64__ platform, --js-flags=--jitless";
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--js-flags=--jitless");
#endif

Expand All @@ -50,28 +52,28 @@ int main(int argc, char *argv[])

const QStringList requiredArguments = parser.positionalArguments();
if (requiredArguments.size() != 2) {
qCritical() << "Invalid number of arguments, expected 2 but got" << requiredArguments.size();
qCCritical(htmltopdfLog) << "Invalid number of arguments, expected 2 but got" << requiredArguments.size();
parser.showHelp(1);
}
qInfo() << "Input file:" << requiredArguments.at(0) << "Output PDF:" << requiredArguments.at(1);
qCInfo(htmltopdfLog) << "Input file:" << requiredArguments.at(0) << "Output PDF:" << requiredArguments.at(1);

qInfo() << "Creating PDF converter instance";
qCInfo(htmltopdfLog) << "Creating PDF converter instance";
HtmltoPdfConverter converter(requiredArguments.at(0), requiredArguments.at(1));
return converter.run();
}

bool isWayland()
{
qDebug() << "Checking display environment";
qCDebug(htmltopdfLog) << "Checking display environment";
auto e = QProcessEnvironment::systemEnvironment();
QString XDG_SESSION_TYPE = e.value(QStringLiteral("XDG_SESSION_TYPE"));
QString WAYLAND_DISPLAY = e.value(QStringLiteral("WAYLAND_DISPLAY"));

if (XDG_SESSION_TYPE == QLatin1String("wayland") || WAYLAND_DISPLAY.contains(QLatin1String("wayland"), Qt::CaseInsensitive)) {
qDebug() << "Wayland session detected";
qCDebug(htmltopdfLog) << "Wayland session detected";
return true;
} else {
qDebug() << "X11 session detected";
qCDebug(htmltopdfLog) << "X11 session detected";
return false;
}
}
2 changes: 1 addition & 1 deletion reader/app/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ Database::Database(QObject *parent) : QObject(parent)
m_database.setDatabaseName(QDir(path).filePath("user.db"));
qCDebug(appLog) << "Opening database:" << m_database.databaseName();
if (!m_database.open()) {
qCritical() << "Failed to open database:" << m_database.lastError();
qCCritical(appLog) << "Failed to open database:" << m_database.lastError();
}

if (m_database.isOpen()) {
Expand Down
21 changes: 12 additions & 9 deletions reader/ddlog.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
// SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2025 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-Liteense-Identifier: GPL-3.0-or-later
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef DDLOG_H
#define DDLOG_H
#ifdef DTKCORE_CLASS_DConfigFile
#include <DConfig>
#endif
#include <DLog>

DCORE_USE_NAMESPACE
#include <QDebug>
#include <QLoggingCategory>

// namespace DDLog {
// 全项目统一的日志分类:reader / batch-print / htmltopdf 共用此定义,
// 便于 DConfig(deepin-log-viewer) 按应用统一过滤
inline Q_LOGGING_CATEGORY(appLog, "org.deepin.reader")
// }

// 模块分离:batch-print 批量打印进程
inline Q_LOGGING_CATEGORY(batchprintLog, "org.deepin.reader.batchprint")

// 模块分离:htmltopdf 转换进程
inline Q_LOGGING_CATEGORY(htmltopdfLog, "org.deepin.reader.htmltopdf")

#endif // DDLOG_H
Loading
Loading