Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Show Open/Save dialog on downloading files #1123

wants to merge 5 commits into from

Conversation

juuz0
Copy link
Collaborator

@juuz0 juuz0 commented Jun 4, 2024

Fix #697

Superseeds #1070

@kelson42
Copy link
Collaborator

kelson42 commented Jun 4, 2024

@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?

@juuz0
Copy link
Collaborator Author

juuz0 commented Jun 4, 2024

@kelson42 Yes I believe so.

Copy link
Collaborator

@kelson42 kelson42 left a 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").

resources/i18n/en.json Outdated Show resolved Hide resolved
src/kprofile.cpp Outdated Show resolved Hide resolved
src/kprofile.cpp Outdated Show resolved Hide resolved
src/kprofile.h Outdated Show resolved Hide resolved
src/kprofile.h Outdated Show resolved Hide resolved
src/kprofile.cpp Outdated
Comment on lines 34 to 54
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 {
Copy link
Collaborator

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 deleted. You can create the QTemporaryFile object on the stack (rather than on the heap) and disable auto-remove.

Copy link
Collaborator Author

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?

Copy link
Collaborator

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.

src/kprofile.cpp Outdated Show resolved Hide resolved
@juuz0
Copy link
Collaborator Author

juuz0 commented Jun 13, 2024

Can you please have a better choice of directory following #1058 (comment). Actually it could use the same settings (to keep directory path, would be the same as "import").

@kelson42 done! please check.

And I also rebased it on main (CI seems to be failing because of that?)

@juuz0
Copy link
Collaborator Author

juuz0 commented Jun 13, 2024

Fixed an issue where the compilation was failing for QT6 (i was still at 5.15 so it slipped, upgraded now)

src/kprofile.cpp Outdated Show resolved Hide resolved
src/kprofile.h Outdated Show resolved Hide resolved
src/kprofile.cpp Show resolved Hide resolved
@juuz0 juuz0 force-pushed the pdfSmth branch 2 times, most recently from 241f310 to 46f2513 Compare June 14, 2024 14:46
src/kprofile.cpp Outdated Show resolved Hide resolved
src/kprofile.cpp Outdated Show resolved Hide resolved
src/kprofile.cpp Show resolved Hide resolved
Copy link
Collaborator

@veloman-yunkan veloman-yunkan left a 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.

src/kiwixmessagebox.cpp Show resolved Hide resolved
@juuz0 juuz0 force-pushed the pdfSmth branch 2 times, most recently from 6b9f9c8 to bc0c97b Compare June 16, 2024 16:57
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);
Copy link
Collaborator

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?

Copy link
Collaborator Author

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)

Copy link
Collaborator

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?

Copy link
Collaborator

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.

Copy link
Collaborator Author

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...)

Copy link
Collaborator

@veloman-yunkan veloman-yunkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My review for the new changes came in the form of two more comments (1, 2) on a previous thread. I am posting this response to the most recent review request to make it explicit that it has not been ignored.

@kelson42
Copy link
Collaborator

@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").

@juuz0 It seems this part is not implemented... it seems to always propose to save in the current path which is really not correct.

@juuz0 juuz0 force-pushed the pdfSmth branch 2 times, most recently from cdf3935 to 27895d5 Compare July 3, 2024 10:03
@juuz0 juuz0 requested a review from veloman-yunkan July 3, 2024 10:09
@juuz0
Copy link
Collaborator Author

juuz0 commented Jul 3, 2024

@kelson42 It works for me, can you please recheck? (unless I misunderstood what was needed)

In the attached video, original location is common, I save the file, then start another save file session - save it in tmp and in the following saves, it remembers tmp

Screencast.from.2024-07-03.15-57-18.webm

@veloman-yunkan
Copy link
Collaborator

I will review the PR again after @kelson42 approves it from user's perspective.

@kelson42
Copy link
Collaborator

kelson42 commented Jul 13, 2024

@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.

@kelson42
Copy link
Collaborator

kelson42 commented Jul 19, 2024

@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 main to resolve red CI

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.
The last downloaded file's location is remembered and the "Save File" dialog opens in the same directory.
@kelson42
Copy link
Collaborator

@juuz0 ?

@juuz0
Copy link
Collaborator Author

juuz0 commented Jul 27, 2024

@kelson42 sooon! (im still trying to figure out how to get the open-with selection).
QDesktopServices calls xdg-open which thinks the file manager/picker is the correct application for that specific file. I'll try finding a workaround.

@kelson42
Copy link
Collaborator

kelson42 commented Aug 2, 2024

@juuz0 Any update? Would really like to merge this PR which is slowly getting old.

@kelson42
Copy link
Collaborator

@juuz0 Any update? We need this PR for 2.4.0!

@kelson42
Copy link
Collaborator

kelson42 commented Sep 1, 2024

@veloman-yunkan Can younplease rebase an complete this PR so we can complete 2.4.0 milestone?

@juuz0
Copy link
Collaborator Author

juuz0 commented Sep 9, 2024

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:
The issue is xdg-open (called by QDesktopServices) which thinks the file manager/picker is the correct application for that specific file (it works ok for pdf but epub files open the manager).

One workaround is using xdg-mime. For mime-types which dont have a specific application set, xdg-mime returns nothing so if we can disable the Open button when xdg-mime query is empty, that could help.
BUT remember xdg-mime is not available on windows obviously - its possible QDesktopServices opens the application-picker-menu on windows though...up to testing!

@kelson42
Copy link
Collaborator

@veloman-yunkan AFAIK this is the last piece of work which is assigned to you in the 2.4.0 milestone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PDF file dialog box should allow to open PDF file directly with PDF reader
3 participants