Skip to content

Commit

Permalink
Move Save HTML Page to WebView::saveViewContent
Browse files Browse the repository at this point in the history
Qt bug does not allow cancel to download request of save(). For better generalization, make startDownload single responsibility and move printing to saveViewContent.
  • Loading branch information
ShaopengLin committed Oct 28, 2024
1 parent a99ba3a commit bd953f8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 0 additions & 4 deletions src/kprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ void KProfile::startDownload(QWebEngineDownloadRequest* download)
}
app->savePrevSaveDir(QFileInfo(fileName).absolutePath());

if (download->isSavePageDownload()) {
download->page()->printToPdf(fileName);
return;
}
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
download->setPath(fileName);
#else
Expand Down
14 changes: 13 additions & 1 deletion src/webview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,19 @@ void WebView::saveViewContent()
*/
QString suggestedFileName = QString::fromStdString(kiwix::getSlugifiedFileName(item.getTitle()));
if (isHTMLContent(item))
page()->save(suggestedFileName + ".pdf");
{
const auto app = KiwixApp::instance();
suggestedFileName = app->getPrevSaveDir() + "/" + suggestedFileName + ".pdf";
QString fileName = QFileDialog::getSaveFileName(
app->getMainWindow(), gt("save-file-as-window-title"),
suggestedFileName, "(*pdf)");

if (fileName.isEmpty())
return;
app->savePrevSaveDir(QFileInfo(fileName).absolutePath());

page()->printToPdf(fileName);
}
else
page()->download(this->url(), suggestedFileName);
}
Expand Down

0 comments on commit bd953f8

Please sign in to comment.