diff --git a/reader/app/Global.cpp b/reader/app/Global.cpp index 77fee3b4..28d82f15 100644 --- a/reader/app/Global.cpp +++ b/reader/app/Global.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include namespace Dr { @@ -57,4 +58,22 @@ FileType fileType(const QString &filePath) return fileType; } +bool isNetworkPath(const QString &filePath) +{ + 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; +} + } diff --git a/reader/app/Global.h b/reader/app/Global.h index 7641c2b2..f34d8c3b 100644 --- a/reader/app/Global.h +++ b/reader/app/Global.h @@ -9,6 +9,7 @@ #include "DebugTimeManager.h" #include +#include namespace Dr { @@ -45,6 +46,7 @@ enum FileType { #endif }; FileType fileType(const QString &filePath); +bool isNetworkPath(const QString &filePath); /** * @brief The Rotation enum diff --git a/reader/document/DjVuModel.cpp b/reader/document/DjVuModel.cpp index 81da93df..cee199aa 100644 --- a/reader/document/DjVuModel.cpp +++ b/reader/document/DjVuModel.cpp @@ -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"); @@ -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"; diff --git a/reader/document/DjVuModel.h b/reader/document/DjVuModel.h index e306e335..ad8e3982 100644 --- a/reader/document/DjVuModel.h +++ b/reader/document/DjVuModel.h @@ -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); diff --git a/reader/document/Model.cpp b/reader/document/Model.cpp index 684083eb..b768b79a 100644 --- a/reader/document/Model.cpp +++ b/reader/document/Model.cpp @@ -19,6 +19,7 @@ #include #include #include +#include "Global.h" namespace { @@ -94,7 +95,22 @@ deepin_reader::Document *deepin_reader::DocumentFactory::getDocument(const int & 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"; diff --git a/reader/uiframe/DocSheet.cpp b/reader/uiframe/DocSheet.cpp index 23990b88..ea4c72bb 100644 --- a/reader/uiframe/DocSheet.cpp +++ b/reader/uiframe/DocSheet.cpp @@ -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(); } diff --git a/tests/document/ut_model.cpp b/tests/document/ut_model.cpp index 64606094..4885d369 100644 --- a/tests/document/ut_model.cpp +++ b/tests/document/ut_model.cpp @@ -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;