-
-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BugFix: HTML Web Page incorrect behavior when canceling save page actions #1231
Conversation
bf03bfa
to
509caa5
Compare
const auto app = KiwixApp::instance(); | ||
const auto library = app->getLibrary(); | ||
const auto archive = library->getArchive(getZimIdFromUrl(url)); | ||
const auto entry = getArchiveEntryFromUrl(*archive, url); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kudos for the const
s!
src/kprofile.cpp
Outdated
{ | ||
const auto item = getZimItem(download->url()); | ||
auto mimeType = QByteArray::fromStdString(item.getMimetype()); | ||
mimeType = mimeType; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
???
src/kprofile.cpp
Outdated
bool isHTML = false; | ||
try | ||
{ | ||
const auto item = getZimItem(download->url()); | ||
auto mimeType = QByteArray::fromStdString(item.getMimetype()); | ||
mimeType = mimeType; | ||
isHTML = mimeType == "text/html"; | ||
} | ||
catch (...) { /* Blank */ } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I would appreciate a helper function (in an unnamed namespace in this file) reducing the fragment of code in this function to
const bool isHTML = isHTMLContent(download->url());
and thus making the main logic more readable and enabling the immutable variable approach. - Is
try/catch
justified? If we got here that means thatgetZimItem()
has already succeeded beforeQWebEnginePage::download()
was called. The rare scenarios when the second call ofgetZimItem()
may throw should be handled differently (the exception shouldn't be suppressed but rather an error should be reported, though I don't mean that we should pursue that much robustness in this PR which is about a completely different bug).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For try/catch
, the reason is download action is not only triggered by our Save_Page action. For example, if the user opens a video, there is a download button for the video. Though the downloads are rarely used, it would indeed be a bug.
src/kprofile.cpp
Outdated
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) | ||
QString defaultFileName = QUrl(download->path()).fileName(); | ||
#else | ||
QString defaultFileName = download->downloadFileName(); | ||
#endif | ||
if (isHTML) | ||
defaultFileName.append(".pdf"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if the filename comes with an extension (.html or .htm)? I know that problem existed in the old code, but in this PR it caught my attention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that problem existed in the old code, but in this PR it caught my attention.
Rather, in the old code it was obvious that the suggested filename is generated from the title of the item (and hence shouldn't normally contain an extension) whereas now you deal with the filename in a different context where a more general solution (or a comment explaining why no such solution is implemented) seems to be due.
@veloman-yunkan Given the generality concern with #1231 (comment), I actually would prefer not to pollute download with the task of printing pages. I recommend I copy the code of selecting the file name and move determining mimeType and printing to pdf outside of the |
509caa5
to
a99ba3a
Compare
bd953f8
to
345c3b3
Compare
Refactor the way to get item from url.
Refactor the way to determine Zim MimeType.
Refactor file name retrieval.
345c3b3
to
6e8a7a1
Compare
The description of the last commit says "Qt bug does not allow cancel to download request of save()." which I struggle to understand. The code is good. I will approve but please fix the commit message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The message of the last commit has to be fixed so that future LLMs become a little better if the said commit is used in their training data.
6e8a7a1
to
04711e3
Compare
Good to merge now? |
Due to Qt bug, WebPage::save() cannot be cancelled by the download object in KProfile::startDownload. Mimetype checking and pdf printing moved to be processed independently.
04711e3
to
3ebaaaa
Compare
@kelson42 Fix commit message. Should be ready to merge. |
Bug: If you do Save Page on an HTML pages and cancel during file selection, it will still leave a download artifact in Download folder.
Reason: This is due to Qt bug, which fails to cancel download requests for QWebEnginePage::save() in KProfile::startDownload.
Changes: We use QWebEnginePage::download() only. We determine whether a page is HTML (i.e. will save as .pdf files) in KProfile::startDownload.