Bug 316890 - Intelligent automatic reload
Summary: Intelligent automatic reload
Status: REPORTED
Alias: None
Product: okular
Classification: Applications
Component: general (show other bugs)
Version: 0.16.0
Platform: Other Linux
: NOR wishlist
Target Milestone: ---
Assignee: Okular developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-17 09:07 UTC by Dennis Nienhüser
Modified: 2024-02-13 22:52 UTC (History)
6 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dennis Nienhüser 2013-03-17 09:07:16 UTC
I'm working on a larger PDF file produced by kile/pdflatex which takes about 30 seconds to build. When I initiate a build in kile, the PDF document gets cleared immediately (the PDF file is truncated) and only shown again 30 seconds later after the build is finished and the new PDF file complete. Alternatively I can switch off auto-reload in okular, but have to reload the document manually later on.

Instead I'd like okular to reload the document automatically, but only when the build is finished.

My guess what is happening in auto reload mode currently is the following:

1) PDF file is ok, shown in okular
2) Initiate build, pdflatex truncates pdf
3) okular notices file change, tries reload. File is not complete, nothing shown
4) pdflatex writes some chunks to the file.
5) The pdf might not be complete, back to 3). Otherwise okular displays the new file

What I'd find more convenient would be
1) PDF file is ok, shown in okular
2) Initiate build, pdflatex truncates pdf
3) okular notices file change, tries reload. File is not complete. Old file is still shown, along with a "file vanished on disc" indicator in the user interface
4) pdflatex writes some chunks to the file.
5) The pdf might not be complete, back to 3). Otherwise okular displays the new file, removes "file vanished on disc" indicator

The main difference is that I can continue reading the (outdated, but still useful) PDF while it is updated.

Is that doable or would that break e.g. loading of other pages which are not in memory?
Comment 1 Franz Trischberger 2013-03-17 09:21:30 UTC
You might want to get some inspiration from this HowTo:
http://linuxunderthesky.blogspot.de/2011/09/synctex-in-kile-and-okular.html
Comment 2 Albert Astals Cid 2013-03-17 11:57:26 UTC
How do we know the file is finished changing?
Comment 3 Michel Ludwig 2013-03-17 12:03:10 UTC
(In reply to comment #0)
> What I'd find more convenient would be
> 1) PDF file is ok, shown in okular
> 2) Initiate build, pdflatex truncates pdf
> 3) okular notices file change, tries reload. File is not complete. Old file
> is still shown, along with a "file vanished on disc" indicator in the user
> interface
> 4) pdflatex writes some chunks to the file.
> 5) The pdf might not be complete, back to 3). Otherwise okular displays the
> new file, removes "file vanished on disc" indicator
> 
> The main difference is that I can continue reading the (outdated, but still
> useful) PDF while it is updated.

Just to relate to this, the live preview feature in the upcoming version 3.0 of Kile will only reload the PDF file once LaTeX is finished. Hence, this problem won't occur anymore.
Comment 4 Michel Ludwig 2013-03-17 12:07:03 UTC
(In reply to comment #1)
> You might want to get some inspiration from this HowTo:
> http://linuxunderthesky.blogspot.de/2011/09/synctex-in-kile-and-okular.html

There is also no need to modify the configuration of the tools as it's described there - just choose the 'Modern' configuration of (PDF)LaTeX.
Comment 5 Dennis Nienhüser 2013-03-17 12:51:38 UTC
(In reply to comment #2)
> How do we know the file is finished changing?

Currently there seem to be a couple of load attempts by okular while the file is being written, each of them failing. So I'd try with "the file is finished when it can be opened correctly". I know too little about PDF internals though to judge if that is sane.
Comment 6 Albert Astals Cid 2013-03-17 17:35:40 UTC
What if the dude Ctrl+C the pdflatex process or the generated pdf is never valid?
Comment 7 Dennis Nienhüser 2013-03-17 18:03:55 UTC
Then you're left with a stale opened PDF file, the same as if you had configured okular not to do automatic reloading at all.
Comment 8 Albert Astals Cid 2013-03-17 21:53:59 UTC
But that is wrong, you asked your pdf to be reloaded and it hasn't been reloaded (to it's broken state) So if that happens you may close okular, attach the pdf to your boss and then discover you sent a broken pdf
Comment 9 Christoph Feck 2013-04-14 16:43:55 UTC
I am not really sure, but I think Nepomuk developers found a way to only get notified when a file is finally closed after writing (e.g. download finished), instead of whenever it is modified.
Comment 10 Albert Astals Cid 2013-04-14 21:00:45 UTC
Nepomuk friends, can anyone conform Christoph's comment?
Comment 11 Vishesh Handa 2013-04-15 07:45:12 UTC
inotify has a 2 modification events - 

IN_MODIFY - Emitted anytime a file is modified
IN_CLOSE_WRITE - when a file that is opened with a write flag is closed regardless of the modifications. 

For Nepomuk we only use the IN_CLOSE_WRITE signal and then manually check if the mtime of the file has changed. Many programs open files under write mode even when no modifications are to be made -eg Taglib. Some programs, such as KTorrent, are even worse and keep opening and closing files with write flags when seeding.

I had a look at KDirWatch and it only checks for the IN_MODIFY signal. I'm not sure how one would go along implementing IN_CLOSE_WRITE. Nepomuk uses inotify directly cause of our special requirements instead of going through KDirWatch.
Comment 12 Albert Astals Cid 2013-04-15 18:33:13 UTC
Anything that means not using KDirWatch or something cross platform is not acceptable
Comment 13 flindeberg 2020-09-14 15:04:15 UTC
It looks like this is still around. 

I looked into KDirWatch and it seems it only has support for file changes (i.e. the "dirty" signal), so it is impossible to know when the file is closed for writing (lua/xe/pdflatex all seem to write multiple chunks and close the file now and then as well). 

Wouldn't it work if okular shows a warning when the pdf-file changes, and waits with updating the graphical layout until it has successfully loaded the new pdf-file? I mean a warning along the lines of in big red letters "The current file is corrupt, showing the last known good state from %time". This behavior should only be the default for "greedy"-mode as well I think, since those of us who would benefit from it are probably all using greedy anyhow and it could, as previously stated, cause some confusion that the pdf shown is not the exact version on the disk at that moment. 

I'm currently working around this with a last `cp file.pdf file-view.pdf` in my makefiles, so a fix to this issue is, at least for me, a matter of convenience.
Comment 14 Albert Astals Cid 2020-09-14 21:13:05 UTC
That means a lot of architectural changes, to be able to open a file, you must close the file, that's how Okular works, if you want to do what you suggest you need to be able to not do that.

Is it possible? probably