-
-
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
Show Open/Save dialog on downloading files #1123
base: main
Are you sure you want to change the base?
Conversation
@juuz0 Thx a lot for your PR. Il will test ot in the next hours. Just to be sure: you went through all the comments of the superseeded PR to ensure we are on rge right track? |
@kelson42 Yes I believe so. |
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.
@juuz0 Works almost exactly like it should. Just one comment: Can you please have a better choice of directory following this logic. Actually it could use the same settings (to keep directory path, would be the same as "import").
src/kprofile.cpp
Outdated
QTemporaryFile *tempFile = new QTemporaryFile(QDir::tempPath() + "/XXXXXX." + QFileInfo(defaultFileName).suffix()); | ||
if (tempFile->open()) { | ||
QString tempFilePath = tempFile->fileName(); | ||
tempFile->close(); | ||
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) | ||
download->setPath(tempFilePath); | ||
#else | ||
download->setDownloadFileName(tempFilePath); | ||
#endif | ||
connect(download, &QWebEngineDownloadItem::finished, [tempFilePath]() { | ||
if(!QDesktopServices::openUrl(QUrl::fromLocalFile(tempFilePath))) | ||
showInfoBox(gt("error-title"), gt("error-opening-file-with"), KiwixApp::instance()->getMainWindow()); | ||
}); | ||
download->accept(); | ||
} else { |
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.
Memory leak - tempFile
is not delete
d. You can create the QTemporaryFile
object on the stack (rather than on the heap) and disable auto-remove
.
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.
Its on the stack now but I havent disabled auto-remove, why do we need that?
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.
Then the file will be deleted when tempFile
goes out of scope. Since the file is opened asynchronously (after its download is finished) that operation may fail.
@kelson42 done! please check. And I also rebased it on main (CI seems to be failing because of that?) |
Fixed an issue where the compilation was failing for QT6 (i was still at 5.15 so it slipped, upgraded now) |
241f310
to
46f2513
Compare
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.
Please rebase and fixup (which should require some manual conflict resolution) for the next (hopefully, final) iteration.
6b9f9c8
to
bc0c97b
Compare
src/kiwixmessagebox.cpp
Outdated
KiwixMessageBox::Result showKiwixMessageBox(QString title, QString text, QWidget *parent, QString leftTitle, QString rightTitle) | ||
{ | ||
KiwixMessageBox *dialog = new KiwixMessageBox(title, text, false, parent, leftTitle, rightTitle); | ||
dialog->setAttribute(Qt::WA_DeleteOnClose); |
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.
This is an interesting finding. Can't we use the same trick in showInfoBox()
? Or maybe even move it into the constructor of KiwixMessageBox
?
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.
Moving into the constructor is a nice idea, I did it in the new fixup.
showConfirmBox()
also uses execDialog() now - It looks more natural to me that a confirmBox() is high prio and should be handled before interacting with other windows (hence the exec()
call)
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.
Now that I looked into the documentation of QDialog::exec()
and Qt::WA_DeleteOnClose
, I have some doubts. When QDialog::exec()
returns the dialog should have closed and hence deleted. Therefore KiwixMessageBox::execDialog()
will execute its last few instructions on a deleted object. Am I wrong?
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.
Also, I am also concerned with QDialog::exec()
being a blocking function. I wonder how download updater code will react to the the main thread being blocked.
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.
Now that I looked into the documentation of QDialog::exec() and Qt::WA_DeleteOnClose ..........
Sorry for the delay, life happened!
You're right, I looked into qdialog's source code and when deleteOnClose is enabled it deletes it instantly. I reverted it to the old way of ours - a simple deleteLater().
Also, I am also concerned with QDialog::exec() being a blocking function.....
I don't really get this, we aren't starting the download until open/save is clicked (unless you mean the Download Books functionality, which I agree could've been an issue and already reverted...)
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.
@juuz0 It seems this part is not implemented... it seems to always propose to save in the current path which is really not correct. |
cdf3935
to
27895d5
Compare
@kelson42 It works for me, can you please recheck? (unless I misunderstood what was needed) In the attached video, original location is Screencast.from.2024-07-03.15-57-18.webm |
I will review the PR again after @kelson42 approves it from user's perspective. |
@juuz0 Retested and indeed it work fine but I have a last topic: what happens if there is no known app to open the file? I though I would have a choice of app to open the file? But instead I get a filepicker, this is not correct. If the app to open the file is not known, then we should display the list of app and the user should choose which app he wants to use to open the file. If this is not possible, then we should probably just disabled the button in the dialog box so the user can only save to a file. |
@juuz0 Beside answering to my last comment, can you please also give feedback to all discussion points open and close them if necessary? Rebasing on |
@juuz0 ? |
@kelson42 sooon! (im still trying to figure out how to get the open-with selection). |
@juuz0 Any update? Would really like to merge this PR which is slowly getting old. |
@juuz0 Any update? We need this PR for |
@veloman-yunkan Can younplease rebase an complete this PR so we can complete 2.4.0 milestone? |
Apologies @kelson42, I'm equipped with several things IRL - cant get the time, and yeah if someone is willing to take over it, please do! :> My 2 cents: One workaround is using |
@veloman-yunkan AFAIK this is the last piece of work which is assigned to you in the |
It started as a simple yes/no box but is now being used as an InfoBox, ConfirmBox and a customized MessageBox (in further commits) - this sounds better!
Added a function to show custom choices instead of yes/no. The chosen option is returned A closeButton is also added to the dialog.
f046af2
to
16325ce
Compare
The said two commits use different settings for remembering the previous directory used for open/save operations:
I think that behaviour 2. is more appropriate since the content being saved from a ZIM file is of a different kind and shouldn't affect the location for opening ZIM files. |
QWebEngineDownloadItem of Qt 5 was replaced with QWebEngineDownloadRequest in Qt 6. Besides the API of QWebEngineDownloadItem has slightly changed in Qt 5.14. This commit reduces the pollution of the code by conditional compilation needed to support all those versions of Qt.
16325ce
to
7e04b42
Compare
@kelson42 What do you mean by filepicker? In my case (on Ubuntu 22.04) I only get an error message:
Qt doesn't seem to provide a way of finding out the application that will be used to open the given file. In my case it didn't even detect that the attempt to open the file failed, which is a documented known issue:
|
Fix #697
Superseeds #1070