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
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ if (USE_PDFIUM_BUNDLE)
add_subdirectory(3rdparty/deepin-pdfium)
endif()

add_subdirectory(batch-print)

# Install context-menus (batch print)
install(FILES src/context-menus/deepin-reader-batchprint.conf
DESTINATION ${CMAKE_INSTALL_DATADIR}/applications/context-menus)

# 单元测试(可选)
option(BUILD_TESTS "Build unit tests" OFF)
if (BUILD_TESTS)
Expand Down
125 changes: 125 additions & 0 deletions batch-print/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
#
# SPDX-License-Identifier: GPL-3.0-or-later

# [v4] Batch print unit tests switch (default OFF)
# Unit tests moved to top-level tests/batch-print (built under BUILD_TESTS)

# Find Qt components needed by batch-print modules (DBus for notifications, PrintSupport for QPdfWriter)
pkg_check_modules(FREETYPE REQUIRED freetype2)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS DBus PrintSupport Sql)

# Import the system pdfium target in this scope (reader/ creates it only for its own subtree)
if (NOT USE_PDFIUM_BUNDLE)
pkg_check_modules(Deepin-pdfium REQUIRED IMPORTED_TARGET deepin-pdfium)
endif()

# batchprint-core: CupsClient + NotifyClient + PrintSettings + ErrorMessages (no reader source dependency)
add_library(batchprint-core STATIC
cupsclient.h cupsclient.cpp
icupsapi.h
notifyclient.h notifyclient.cpp
printsettings.h printsettings.cpp
errormessages.h errormessages.cpp
)

target_include_directories(batchprint-core PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
)

target_link_libraries(batchprint-core PUBLIC
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::DBus
)

# batchprint-convert: FormatConverter (depends on selected reader/document sources + deepin-pdfium)
# Explicitly list only the reader source files needed for document loading/rendering,
# NOT the entire reader GUI (browser/sidebar/widgets/uiframe).
set(BATCHPRINT_READER_SOURCES
${CMAKE_SOURCE_DIR}/reader/app/Global.cpp
${CMAKE_SOURCE_DIR}/reader/document/Model.cpp
${CMAKE_SOURCE_DIR}/reader/document/PDFModel.cpp
${CMAKE_SOURCE_DIR}/reader/document/DjVuModel.cpp
${CMAKE_SOURCE_DIR}/reader/document/XpsDocumentAdapter.cpp
${CMAKE_SOURCE_DIR}/reader/document/XpsTextExtractor.cpp
)

add_library(batchprint-convert STATIC
formatconverter.h formatconverter.cpp
${BATCHPRINT_READER_SOURCES}
)

set_target_properties(batchprint-convert PROPERTIES
AUTOMOC ON
AUTOUIC ON
)

target_include_directories(batchprint-convert PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/reader
${CMAKE_SOURCE_DIR}/reader/app
${CMAKE_SOURCE_DIR}/reader/document
${PDFIUM_INCLUDE_DIRS}
$<$<BOOL:${XPS_SUPPORT_ENABLED}>:${XPS_DEPS_INCLUDE_DIRS}>
)

target_compile_definitions(batchprint-convert PRIVATE
INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}"
INSTALL_LIBDIR="${CMAKE_INSTALL_LIBDIR}"
APP_VERSION="1.0.0"
)

target_link_libraries(batchprint-convert PUBLIC
batchprint-core
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::PrintSupport
Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::Svg
Qt${QT_VERSION_MAJOR}::Concurrent
Qt${QT_VERSION_MAJOR}::Sql
Qt${QT_VERSION_MAJOR}::Xml
${DDJVU_LIBRARIES}
${LIBJPEG_LIBRARIES}
${FREETYPE_LIBRARIES}
$<$<BOOL:${XPS_SUPPORT_ENABLED}>:${XPS_DEPS_LIBRARIES}>
)

# DTK linking
if(DTK_USE_TARGETS)
target_link_libraries(batchprint-convert PUBLIC
Dtk${DTK_VERSION_MAJOR}::Widget
Dtk${DTK_VERSION_MAJOR}::Gui
Dtk${DTK_VERSION_MAJOR}::Core
)
endif()

if (QT_VERSION_MAJOR MATCHES 6)
target_link_libraries(batchprint-convert PUBLIC Qt${QT_VERSION_MAJOR}::Core5Compat)
endif()

if (USE_PDFIUM_BUNDLE)
target_link_libraries(batchprint-convert PUBLIC deepin-pdfium-reader)
else()
target_link_libraries(batchprint-convert PUBLIC PkgConfig::Deepin-pdfium)
endif()

if (XPS_SUPPORT_ENABLED)
target_compile_definitions(batchprint-convert PUBLIC XPS_SUPPORT_ENABLED)
target_compile_options(batchprint-convert PUBLIC ${XPS_DEPS_CFLAGS_OTHER})
endif()

# Executable
add_executable(deepin-reader-batchprint
main.cpp
batchprintapp.h batchprintapp.cpp
)

target_link_libraries(deepin-reader-batchprint PRIVATE
batchprint-core
batchprint-convert
)

install(TARGETS deepin-reader-batchprint
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
88 changes: 88 additions & 0 deletions batch-print/batchprintapp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "batchprintapp.h"
#include "formatconverter.h"
#include "notifyclient.h"
#include "errormessages.h"

#include <QTemporaryDir>

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

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTemporaryDir> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#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.

BatchPrintApp::BatchPrintApp(ICupsApi *cupsApi)
{
if (cupsApi) {
m_cupsApi = cupsApi;
m_ownsCupsApi = false;
} else {
m_cupsApi = new CupsClient();

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

View workflow job for this annotation

GitHub Actions / cppcheck

Class 'BatchPrintApp' does not have a operator= which is recommended since it has dynamic memory/resource allocation(s).

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

View workflow job for this annotation

GitHub Actions / cppcheck

Class 'BatchPrintApp' does not have a copy constructor which is recommended since it has dynamic memory/resource allocation(s).
m_ownsCupsApi = true;
}
}

BatchPrintApp::~BatchPrintApp()
{
if (m_ownsCupsApi)
delete m_cupsApi;
}

int BatchPrintApp::run(const QStringList &fileList)
{
CupsClient *cups = dynamic_cast<CupsClient *>(m_cupsApi);
if (cups) {
if (!cups->init()) {
qWarning() << "CUPS init failed";
NotifyClient::notifyError(ErrorMessages::cupsUnavailable());
return 2;
}
if (!cups->checkEnvironment()) {
qWarning() << "CUPS environment check failed";
NotifyClient::notifyError(ErrorMessages::noDefaultPrinter());
return 2;
}
if (cups->isColorSupported()) {
m_settings.colorMode = ColorMode::Auto;
} else {
m_settings.colorMode = ColorMode::Gray;
}
}

int total = fileList.size();
int succeeded = 0;
QStringList failedFiles;

for (const QString &filePath : fileList) {
QTemporaryDir tempDir;
if (!tempDir.isValid()) {
failedFiles.append(QFileInfo(filePath).fileName());
continue;
}

QString outputPdfPath;
QString errorMsg;
if (!FormatConverter::convertToPdf(filePath, tempDir.path(),
outputPdfPath, errorMsg)) {
qWarning() << errorMsg;
failedFiles.append(QFileInfo(filePath).fileName());
continue;
}

QString jobTitle = QFileInfo(filePath).fileName();
bool printOk = m_cupsApi->submitJob(outputPdfPath, jobTitle, m_settings);

if (!printOk) {
failedFiles.append(QFileInfo(filePath).fileName());
continue;
}

++succeeded;
}

NotifyClient::notifyResult(total, succeeded, failedFiles);

if (succeeded == total)
return 0;
return 1;
}
28 changes: 28 additions & 0 deletions batch-print/batchprintapp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef BATCHPRINTAPP_H
#define BATCHPRINTAPP_H

#include "cupsclient.h"
#include "printsettings.h"

#include <QString>

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

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 12 in batch-print/batchprintapp.h

View workflow job for this annotation

GitHub Actions / cppcheck

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

class BatchPrintApp
{
public:
explicit BatchPrintApp(ICupsApi *cupsApi = nullptr);
~BatchPrintApp();

int run(const QStringList &fileList);

private:
ICupsApi *m_cupsApi = nullptr;
bool m_ownsCupsApi = false;
PrintSettings m_settings;
};

#endif // BATCHPRINTAPP_H
Loading
Loading