Skip to content
Closed
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
14 changes: 14 additions & 0 deletions reader/uiframe/DocSheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
#include "MainWindow.h"
#include "ddlog.h"

#include <DSpinner>

Check warning on line 24 in reader/uiframe/DocSheet.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 25 in reader/uiframe/DocSheet.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 26 in reader/uiframe/DocSheet.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 27 in reader/uiframe/DocSheet.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

#include <QJsonDocument>

Check warning on line 29 in reader/uiframe/DocSheet.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 <QJsonObject>

Check warning on line 30 in reader/uiframe/DocSheet.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QJsonObject> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QStackedWidget>
#include <QMimeData>
#include <QUuid>
Expand Down Expand Up @@ -1031,6 +1032,7 @@

void DocSheet::onPrintRequested(DPrinter *printer, const QVector<int> &pageRange)
{
m_printPrinter = printer;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High · Direct-path saves skip detection

When DTK handles a setPrintFromPath() print without emitting paintRequested, m_printPrinter stays null because its only assignment is in onPrintRequested; the accepted handler then skips the warning, leaving failed saves on this route silent.

Capture the printer independently of paintRequested, or connect failure detection to the direct-path save operation.

Also at reader/uiframe/DocSheet.cpp:2091.

Prompt for AI agents
In `reader/uiframe/DocSheet.cpp` at line 1035:

**Direct-path saves skip detection**

When DTK handles a `setPrintFromPath()` print without emitting `paintRequested`, `m_printPrinter` stays null because its only assignment is in `onPrintRequested`; the accepted handler then skips the warning, leaving failed saves on this route silent.

Capture the printer independently of `paintRequested`, or connect failure detection to the direct-path save operation.

Also at `reader/uiframe/DocSheet.cpp:2091`.

qCDebug(appLog) << "Print requested for pages:" << pageRange;
if (pageRange.isEmpty()) {
qCWarning(appLog) << "Empty page range for printing";
Expand Down Expand Up @@ -1134,6 +1136,7 @@

void DocSheet::onPrintRequested(DPrinter *printer)
{
m_printPrinter = printer;
// qCDebug(appLog) << "onPrintRequested";
printer->setDocName(QFileInfo(filePath()).fileName());

Expand Down Expand Up @@ -2082,6 +2085,17 @@
//图片打印
connect(preview, QOverload<DPrinter *>::of(&DPrintPreviewDialog::paintRequested), this, QOverload<DPrinter *>::of(&DocSheet::onPrintRequested));
#endif
m_printPrinter = nullptr;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Earlier preview can crash

When two preview dialogs for the same DocSheet remain active and the later one closes first, m_printPrinter is shared and reset or overwritten by the later request, so the earlier dialog's accepted handler reads its printer, possibly after deletion, missing its save result or dereferencing a stale pointer and crashing.

Capture and use each preview's own printer in its accepted handler instead of reading m_printPrinter.

Also at reader/uiframe/DocSheet.cpp:1035, reader/uiframe/DocSheet.cpp:2091.

Prompt for AI agents
In `reader/uiframe/DocSheet.cpp` at line 2089:

**Earlier preview can crash**

When two preview dialogs for the same `DocSheet` remain active and the later one closes first, `m_printPrinter` is shared and reset or overwritten by the later request, so the earlier dialog's accepted handler reads its printer, possibly after deletion, missing its save result or dereferencing a stale pointer and crashing.

Capture and use each preview's own printer in its accepted handler instead of reading `m_printPrinter`.

Also at `reader/uiframe/DocSheet.cpp:1035`, `reader/uiframe/DocSheet.cpp:2091`.

connect(preview, &QDialog::accepted, this, [this]() {
if (m_printPrinter && !m_printPrinter->outputFileName().isEmpty()) {
QString savePath = m_printPrinter->outputFileName();
if (!QFile::exists(savePath)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Save feedback misreports outcomes

When the destination exists, a failed write leaves a partial file, a non-permission failure leaves no file, or a volume disconnects after writing, QFile::exists(savePath) suppresses warnings for failed overwrites or partial writes, but warns after a successful write followed by disconnection and labels other missing-output failures as permission problems; users get incorrect save feedback.

Use the print/write result to decide whether to warn, not file existence.

Also at reader/uiframe/DocSheet.cpp:2095.

Prompt for AI agents
In `reader/uiframe/DocSheet.cpp` at line 2093:

**Save feedback misreports outcomes**

When the destination exists, a failed write leaves a partial file, a non-permission failure leaves no file, or a volume disconnects after writing, `QFile::exists(savePath)` suppresses warnings for failed overwrites or partial writes, but warns after a successful write followed by disconnection and labels other missing-output failures as permission problems; users get incorrect save feedback.

Use the print/write result to decide whether to warn, not file existence.

Also at `reader/uiframe/DocSheet.cpp:2095`.

DMessageBox::warning(this, tr("打印"), tr("保存失败,目标目录可能没有写入权限。"));
}
}
});

preview->open();
qCDebug(appLog) << "onPopPrintDialog end";
}
Expand Down
1 change: 1 addition & 0 deletions reader/uiframe/DocSheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,7 @@ private slots:
bool m_needsRestoreTip = false;
// 缓存的内容哈希,避免自动保存时反复读盘计算
QString m_cachedContentHash;
Dtk::Widget::DPrinter *m_printPrinter = nullptr; //打印预览对话框的打印机指针,用于关闭后检测保存是否成功

public:
QProcess *m_process = nullptr; //当前调用的命令的进程地址
Expand Down
Loading