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

Implemented Save Page #1134

Merged
merged 5 commits into from
Aug 30, 2024
Merged

Implemented Save Page #1134

merged 5 commits into from
Aug 30, 2024

Conversation

ShaopengLin
Copy link
Collaborator

Fix #77
Changes:

  • Re-enabled file menu item and shortcut Ctrl + Shift + S for save page.
  • Saves the HTML of the page on the current tab to PDF.
  • Saves non-HTML pages directly as files.
  • Remembers the last directory saved when opening file selection dialoge.

src/webview.cpp Outdated
{
QString fileName = QFileDialog::getSaveFileName(
app->getMainWindow(), gt("save-file-as-window-title"),
suggestedPath, gt("pdf-files-filter") + " (*.pdf)");
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is the gt for the filter text needed? I didn't see one for our .zim filters but I added it just in case.

Copy link
Collaborator

Choose a reason for hiding this comment

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

To me it seems mandatory, otherwise how would you get a translated message?! Or I get it wrong?! @veloman-yunkan

@ShaopengLin
Copy link
Collaborator Author

ShaopengLin commented Jun 21, 2024

Actually, we should hold off until #1132 is merged as we have to test how that works with this save page. I am also seeing some places of improvement for this PR.

@kelson42
Copy link
Collaborator

@ShaopengLin I will review this PR, can you please rebase and fix the conflict?

@ShaopengLin
Copy link
Collaborator Author

@kelson42 done

@kelson42
Copy link
Collaborator

kelson42 commented Jul 13, 2024

  • Why CTRL + shift + S? usual (Web Browser) shortcut is CTRL + S, at least on linux. (otherwise it works)
  • Saving a mp4 video directly does not work, it proposes to save a PDF file, not directly the .mp4 file. You can check https://tmp.kiwix.org/ci/tests_fr_reg-videos_2024-05.zim
  • If I want to save the article "AC/DC" then it tries to create DC.pdf, please create a function which sanitise properly the filename and propose something like AC_DC.pdf, so replacing all unallowed charatecer on the filesystem by an _ character. Actually I would recommend to implement a slugify() function.

@ShaopengLin
Copy link
Collaborator Author

ShaopengLin commented Jul 14, 2024

If I want to save the article "AC/DC" then it tries to create DC.pdf

Edit: Okay I believe I misunderstood the proposed change. You meant if the article name IS AC/DC, we would like to sanitize it to AC_DC.
@kelson42 I may be wrong I believe your case happens like this: The native/Qt window manager would treat it as if AC is a directory and DC.pdf is the name. The path will be path/AC/DC.pdf which simply fails to save. For this case, there is no way for us to know if the user intended for it to be a path element or a file name when the results get back to us. I don't think we have a choice here but just report an error.

In most cases, native Linux window manager simply doesn't allow this to happen and reports the error while keeping the save dialog open. I don't believe windows' window manager will allow saves to invalid file names either.

@ShaopengLin ShaopengLin force-pushed the Issue#77-implement-save-page branch 2 times, most recently from e3762e7 to 76d5477 Compare July 15, 2024 05:09
@ShaopengLin
Copy link
Collaborator Author

ShaopengLin commented Jul 15, 2024

@kelson42 Done.

Saving a mp4 video directly does not work, it proposes to save a PDF file, not directly the .mp4 file.

The video/contents that can be saved are these ones opened directly as a video file in the tab:
Screenshot from 2024-07-15 01-14-42

For the ones embedded inside an HTML web page, we would not be able to identify those as they are indeed web pages:
Screenshot from 2024-07-15 01-15-02

These videos can just be downloaded using the provided download button:
Screenshot from 2024-07-15 01-15-11

@kelson42
Copy link
Collaborator

kelson42 commented Jul 15, 2024

@ShaopengLin Please update me on each point I have given. In general this is very important to be very clear about what is done and why. The reviewer has a limited amount of time and therefore the goal is to implement PR so the reviewer has just to approve it without having to ask questions and obviously ask for changes.

Here I have no clue if you have fixed the "bad" shortcut, why it was bad in a first place

@ShaopengLin
Copy link
Collaborator Author

ShaopengLin commented Jul 15, 2024

@kelson42

  1. The shortcut for save is now Ctrl + S. Qt's "Save As" shortcut is Ctrl + Shift + S as it assumes a desktop environment instead of a browser one.
  2. The issue is explained in my previous comment.
  3. We now do a simple sanitization on the appearances of reserved characters of the OS in the file name by replacing them with '_'. This prevents our code from parsing a file name "AC/DC" as file "DC" in the directory "AC". All we care about here is preventing any side effects from using the title text as file name, as it should just be a placeholder name. Determining the file name validity is the job of the OS file window manager.

@kelson42 kelson42 force-pushed the Issue#77-implement-save-page branch from dbec9ce to 8862b10 Compare July 19, 2024 05:56
@kelson42
Copy link
Collaborator

I have rebased as we are approaching the time to make the code review and the PR is already quite old.

@kelson42
Copy link
Collaborator

@veloman-yunkan @ShaopengLin I would recommend to move the string slugification method to libkiwix stringTools.cpp. What do you think?

@kelson42
Copy link
Collaborator

@ShaopengLin Looks good to me finally. Could you please add as well the the contextual menu like on a Web Browser?
@veloman-yunkan Ready to code review.

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.

LGTM

@ShaopengLin
Copy link
Collaborator Author

ShaopengLin commented Jul 22, 2024

I would be fine with moving slugification to libkiwix. Note this doesn't guarantee the file name is 100% valid in Windows. They have a lot of rules extra rules.

@ShaopengLin
Copy link
Collaborator Author

@kelson42 Do you want me to just PR from fork to libkiwix, or create a branch like we do here? If the latter I will need to be a collaborator.

@kelson42
Copy link
Collaborator

@kelson42 Do you want me to just PR from fork to libkiwix, or create a branch like we do here? If the latter I will need to be a collaborator.

Sorry, you should just have received an invitation to be member of the team and have write permission.

@kelson42
Copy link
Collaborator

Blocked by kiwix/libkiwix#1105

@ShaopengLin
Copy link
Collaborator Author

@kelson42 @veloman-yunkan Ready for review. Updated change from kiwix/libkiwix#1105.

@kelson42
Copy link
Collaborator

@ShaopengLin I want to test it, but would be very nice if you could rebase it (once again).

@ShaopengLin
Copy link
Collaborator Author

@kelson42 Done.

@kelson42 kelson42 force-pushed the Issue#77-implement-save-page branch 2 times, most recently from 1a6f621 to 3392531 Compare August 23, 2024 14:15
resources/i18n/en.json Outdated Show resolved Hide resolved
src/kiwixapp.cpp Outdated Show resolved Hide resolved
src/kprofile.cpp Outdated
Comment on lines 35 to 36
QString extension =
isSavePageDownload ? ".pdf" : "." + defaultFileName.section('.', -1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can't the extension now be derived only from defaultFileName (due to page()->save(suggestedFileName + ".pdf"); in this commit? If yes, you can also get rid of the isSavePageDownload variable and put download->isSavePageDownload() in the only remaining point of usage directly.

src/library.cpp Outdated 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.

If it were not for the pagr typo I might have approved. But since we are going to go through another iteration I chose not to silence the perfectionist side of me :)

src/library.cpp Outdated Show resolved Hide resolved
src/library.h Outdated Show resolved Hide resolved
resources/i18n/qqq.json Outdated Show resolved Hide resolved
src/kprofile.cpp Outdated 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.

The commit that dropped category translations was lost. Was that a mistake?

Sorry, I confused this PR with #1175 :)

src/urlschemehandler.cpp Outdated Show resolved Hide resolved
Retrieval function now includes parsing of path. Prepares future change.
Page saved as either pdf or file based on content
Document folder is default.
Convert reserved chars to '_' before parsing
@kelson42 kelson42 force-pushed the Issue#77-implement-save-page branch from cf71bcb to 7fcd6b5 Compare August 30, 2024 10:41
@kelson42 kelson42 merged commit 0c7b60c into main Aug 30, 2024
5 checks passed
@kelson42 kelson42 deleted the Issue#77-implement-save-page branch August 30, 2024 11:02
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.

Implement "Save page"
3 participants