Bug 412978 - Okular creates tabs for deleted files
Summary: Okular creates tabs for deleted files
Status: RESOLVED FIXED
Alias: None
Product: okular
Classification: Applications
Component: general (show other bugs)
Version: 1.8.1
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Okular developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-10-15 16:10 UTC by postix
Modified: 2020-02-11 10:30 UTC (History)
3 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 postix 2019-10-15 16:10:05 UTC
SUMMARY

Okular throws an error if a non available file is opened, but creates an empty tab then.


STEPS TO REPRODUCE
1. Open a PDF in Okular
2. Move it or delete the PDF
3. Close the tab in Okular 
4. Open the deleted PDF via File->Recently Opened Files
5. Warning appears and a tab is created for the non existing PDF

EXPECTED RESULT

Don't create a tab, but if so, make CTRL+W available.


SOFTWARE/OS VERSIONS
Operating System: Manjaro Linux 
KDE Plasma Version: 5.16.5
KDE Frameworks Version: 5.63.0
Qt Version: 5.13.1

ADDITIONAL INFORMATION

It is no longer possible to close the empty tab by CTRL+W
Comment 1 Andi Sardina 2019-10-15 17:12:24 UTC
I was able to reproduce this. You can't close the document with CTRL+W, but you can close the tab. I will work on this.
Comment 2 Yuri Chornoivan 2019-10-15 17:19:56 UTC
(In reply to Andi Sardina from comment #1)
> I was able to reproduce this. You can't close the document with CTRL+W, but
> you can close the tab. I will work on this.

Just one of the possible solutions if you are going to create an MR on gitlab:

diff --git a/shell/shell.cpp b/shell/shell.cpp
index 8c0c62e5b..4f397ef0b 100644
--- a/shell/shell.cpp
+++ b/shell/shell.cpp
@@ -675,7 +675,10 @@ void Shell::openNewTab( const QUrl& url, const QString &serializedOptions )
     if( part->openUrl(url) )
         m_recent->addUrl( url );
     else
+    {
         setActiveTab( previousActiveTab );
+        closeTab( m_tabs.size() - 1 );
+    }
 }
 
 void Shell::applyOptionsToPart( QObject* part, const QString &serializedOptions )
Comment 3 Andi Sardina 2019-10-15 17:23:56 UTC
Hi Yuri Chornoivan,

 You can create the PR if that solves the issue!!
Comment 4 Andi Sardina 2019-10-15 17:29:36 UTC
I will suggest removing the document from the recent documents menu.
Comment 5 postix 2019-10-15 17:40:47 UTC
(In reply to Andi Sardina from comment #4)
> I will suggest removing the document from the recent documents menu.

It makes sense that, that once Okular has detected that a file no longer exists, the entry of the deleted file in the "recently opened files" panel should either be removed or (as I'd prefer) be marked as unavailable (grayed out, striked out) with a hint maybe.

By the way, you can also trigger the bug by invoking
> okular file_which_does_not_exist.pdf
in a terminal, with the exact same effects as described above.


The solution of this issue should however definitely hinder Okular to create senseless tabs.
Comment 6 Yuri Chornoivan 2019-10-15 17:49:13 UTC
(In reply to Andi Sardina from comment #3)
> Hi Yuri Chornoivan,
> 
>  You can create the PR if that solves the issue!!

https://invent.kde.org/kde/okular/merge_requests/53
Comment 7 Andi Sardina 2019-10-15 17:52:48 UTC
Yuri Chornoivan, your solution doesn't solve the problem.

Try this:

* Open one document. Let's call this document A.
* Now move or delete the document A.
* Press CTRL+W and close the document A.
* Now open a new document. Let's call it document B.
* Now close document B with CTRL+W.
* Try to open document A now from the recent menu. With your proposed solution the tab won't be opened.
* Finally open document B again from the recent menu. You will see that two tabs are created, one for document A and one for document B.
Comment 8 postix 2019-10-15 17:55:47 UTC
A(In reply to Andi Sardina from comment #7)
> Yuri Chornoivan, your solution doesn't solve the problem.
> 
> Try this:

With that you just have described bug #412979, which you can now confirm. :)
Comment 9 Yuri Chornoivan 2019-10-15 17:59:27 UTC
(In reply to Andi Sardina from comment #7)
> Yuri Chornoivan, your solution doesn't solve the problem.
> 
> Try this:
> 
> * Open one document. Let's call this document A.
> * Now move or delete the document A.
> * Press CTRL+W and close the document A.
> * Now open a new document. Let's call it document B.
> * Now close document B with CTRL+W.
> * Try to open document A now from the recent menu. With your proposed
> solution the tab won't be opened.
> * Finally open document B again from the recent menu. You will see that two
> tabs are created, one for document A and one for document B.

Ok. Now you can fix both bugs with your patch without my useless intrusion. ;)
Comment 10 Andi Sardina 2019-10-15 18:36:29 UTC
Yuri Chornoivan,

  I used your idea to solve both problems. We only needed to add that line in the function Shell::openUrl.
Comment 11 postix 2019-10-15 19:40:01 UTC
>  I used your idea to solve both problems. 
> We only needed to add that line
> [closeTab( m_tabs.size() - 1 );] 
> in the function Shell::openUrl.

Great that you could have resolve it.

As I am not quiet familiar with the Okular shell code:
To me it sounds like you implement kind of workaround with this line, as a faulty tab is created and closed.
Should it not be created at all in the first place?
Comment 12 Andi Sardina 2019-10-15 19:52:06 UTC
Postix,

  I notice it, but the problem is that the function to open the file is in the part (KParts::ReadWritePart), which is created and added to the tab widget before know if the file will be opened successfully or not. Maybe there is a way to do update the UI after. 

 I am trying to write an autotest right now, and it will take me a bit because I haven't written a test in Qt before. But after I finish this, I will try to solve it!
Comment 13 Andi Sardina 2019-10-24 18:33:12 UTC
@Postix I was wrong about what I said in my last comment. The code for updating the UI is in a different place. I have moved it to only show a tab when the file is successfully opened.
Comment 14 Albert Astals Cid 2020-02-10 23:22:09 UTC
Git commit c549d28f7f963607075fb39322115d39e837d854 by Albert Astals Cid, on behalf of Andi Sardina Ramos.
Committed on 10/02/2020 at 23:22.
Pushed by aacid into branch 'master'.

Solving the creation of an additional tab for a deleted file.
Related: bug 412979

M  +2    -2    autotests/CMakeLists.txt
A  +41   -0    autotests/closedialoghelper.cpp     [License: UNKNOWN]  *
A  +39   -0    autotests/closedialoghelper.h     [License: UNKNOWN]  *
M  +61   -1    autotests/mainshelltest.cpp
M  +21   -65   autotests/parttest.cpp
M  +1    -1    autotests/testingutils.cpp
M  +1    -0    autotests/testingutils.h
M  +21   -2    core/document.cpp
M  +8    -0    core/document.h
M  +2    -0    core/document_p.h
M  +3    -1    part.cpp
M  +20   -10   shell/shell.cpp

The files marked with a * at the end have a non valid license. Please read: https://community.kde.org/Policies/Licensing_Policy and use the headers which are listed at that page.


https://invent.kde.org/kde/okular/commit/c549d28f7f963607075fb39322115d39e837d854
Comment 15 postix 2020-02-11 10:30:41 UTC
Thank you, Albert! :)