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
19 changes: 19 additions & 0 deletions reader/app/Global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
#include "Global.h"
#include "ddlog.h"

#include <QMimeType>

Check warning on line 9 in reader/app/Global.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 9 in reader/app/Global.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

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

Check warning on line 10 in reader/app/Global.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 10 in reader/app/Global.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

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

Check warning on line 11 in reader/app/Global.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.

Check warning on line 11 in reader/app/Global.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.
#include <QStorageInfo>

Check warning on line 12 in reader/app/Global.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 12 in reader/app/Global.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

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

Check warning on line 13 in reader/app/Global.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 13 in reader/app/Global.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

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

namespace Dr {
FileType fileType(const QString &filePath)
Expand Down Expand Up @@ -57,4 +58,22 @@
return fileType;
}

bool isNetworkPath(const QString &filePath)

Check warning on line 61 in reader/app/Global.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'isNetworkPath' is never used.

Check warning on line 61 in reader/app/Global.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

The function 'isNetworkPath' is never used.
{
const QStorageInfo storage(filePath);
if (!storage.isValid() || storage.isRoot())
return false;

const QByteArray fsType = storage.fileSystemType().toLower();
if (fsType.contains("nfs") || fsType.contains("cifs") ||
fsType.contains("smb") || fsType.contains("sshfs") ||
fsType.contains("gvfsd"))
return true;

if (filePath.startsWith("/run/user/") && filePath.contains("/gvfs/"))
return true;

return false;
}

}
2 changes: 2 additions & 0 deletions reader/app/Global.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

#include "DebugTimeManager.h"

#include <QString>

Check warning on line 11 in reader/app/Global.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.

Check warning on line 11 in reader/app/Global.h

View workflow job for this annotation

GitHub Actions / static-check / static-check

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

Check warning on line 12 in reader/app/Global.h

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 12 in reader/app/Global.h

View workflow job for this annotation

GitHub Actions / static-check / static-check

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

namespace Dr {

Expand Down Expand Up @@ -45,6 +46,7 @@
#endif
};
FileType fileType(const QString &filePath);
bool isNetworkPath(const QString &filePath);

/**
* @brief The Rotation enum
Expand Down
4 changes: 2 additions & 2 deletions reader/document/DjVuModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ QImage DjVuPage::render(int width, int height, const QRect &slice)const
return image;
}

deepin_reader::DjVuDocument *DjVuDocument::loadDocument(const QString &filePath, deepin_reader::Document::Error &error)
deepin_reader::DjVuDocument *DjVuDocument::loadDocument(const QString &filePath, deepin_reader::Document::Error &error, const QString &displayFilePath)
{
qCInfo(appLog) << "Starting to load DjVu document from path:" << filePath;
ddjvu_context_t *context = ddjvu_context_create("deepin_reader");
Expand Down Expand Up @@ -549,7 +549,7 @@ deepin_reader::DjVuDocument *DjVuDocument::loadDocument(const QString &filePath,

DjVuDocument *djvuDocument = new DjVuDocument(context, document);

djvuDocument->m_filePath = filePath;
djvuDocument->m_filePath = displayFilePath.isEmpty() ? filePath : displayFilePath;

error = Document::NoError;
qCInfo(appLog) << "Successfully loaded DjVu document from:" << filePath << "with" << djvuDocument->pageCount() << "pages";
Expand Down
2 changes: 1 addition & 1 deletion reader/document/DjVuModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class DjVuDocument : public Document

Properties properties() const override;

static deepin_reader::DjVuDocument *loadDocument(const QString &filePath, deepin_reader::Document::Error &error);
static deepin_reader::DjVuDocument *loadDocument(const QString &filePath, deepin_reader::Document::Error &error, const QString &displayFilePath = "");

private:
DjVuDocument(ddjvu_context_t *context, ddjvu_document_t *document);
Expand Down
18 changes: 17 additions & 1 deletion reader/document/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
#include <QProcess>
#include <QFile>
#include <QDir>
#include <QTimer>

Check warning on line 19 in reader/document/Model.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 19 in reader/document/Model.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

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

Check warning on line 20 in reader/document/Model.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 20 in reader/document/Model.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

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


namespace {
Expand Down Expand Up @@ -94,7 +95,22 @@
document = deepin_reader::PDFDocument::loadDocument(filePath, password, error);
} else if (Dr::DJVU == fileType) {
qCDebug(appLog) << "Handling DJVU document";
document = deepin_reader::DjVuDocument::loadDocument(filePath, error);
if (Dr::isNetworkPath(filePath) && !convertedFileDir.isEmpty()) {
qCInfo(appLog) << "DJVU file is on network path, copying to local temp dir";
QString localFilePath = convertedFileDir + "/temp.djvu";
if (QFile::exists(localFilePath))
QFile::remove(localFilePath);

if (!QFile::copy(filePath, localFilePath)) {
qCritical() << "Failed to copy network DJVU file from" << filePath << "to" << localFilePath;
error = deepin_reader::Document::FileError;
} else {
qCInfo(appLog) << "Copied network DJVU to local:" << localFilePath;
document = deepin_reader::DjVuDocument::loadDocument(localFilePath, error, filePath);
}
} else {
document = deepin_reader::DjVuDocument::loadDocument(filePath, error);
}
#ifdef XPS_SUPPORT_ENABLED
} else if (Dr::XPS == fileType) {
qCDebug(appLog) << "Handling XPS document";
Expand Down
3 changes: 3 additions & 0 deletions reader/uiframe/DocSheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,9 @@ QString DocSheet::openedFilePath()
if (Dr::DOCX == fileType())
return convertedFileDir() + "/temp.pdf";

if (Dr::DJVU == fileType() && Dr::isNetworkPath(filePath()))
return convertedFileDir() + "/temp.djvu";

return filePath();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/document/ut_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ PDFDocument *loadpdfDocument_stub(const QString &, const QString &, deepin_reade
return nullptr;
}

DjVuDocument *loaddjvuDocument_stub(const QString &, deepin_reader::Document::Error &error)
DjVuDocument *loaddjvuDocument_stub(const QString &, deepin_reader::Document::Error &error, const QString & = "")
{
error = Document::FileError;
return nullptr;
Expand Down
Loading