This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 119629 - Improve detection of the preferred PDF viewer
Summary: Improve detection of the preferred PDF viewer
Status: VERIFIED FIXED
Alias: None
Product: utilities
Classification: Unclassified
Component: PDF (show other bugs)
Version: 6.x
Hardware: All All
: P3 blocker (vote)
Assignee: tim_sa
URL:
Keywords: SIMPLEFIX
Depends on:
Blocks:
 
Reported: 2007-10-22 11:16 UTC by Marian Petras
Modified: 2011-09-22 14:51 UTC (History)
6 users (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
OpenPDF using Desktop functionality (22.13 KB, patch)
2011-09-21 07:14 UTC, tim_sa
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Marian Petras 2007-10-22 11:17:20 UTC
Improve the algorithm for decision about the preferred PDF viewer on Unix-like systems (except Mac OS).

Suggested solution:
1) Try to find xdg-open (in /usr/bin, /usr/local/bin, possibly in the whole PATH)
2) If xdg-open was found, run: xdg-open <filename>
   If the execution was successful, finish.
3) Try to detect whether the current GDM is Gnome or KDE:
    - Gnome: system variable GNOME_DESKTOP_SESSION_ID is defined
    - KDE:   system variable KDE_FULL_SESSION is defined
4) If Gnome or KDE is detected, try one or more predefined PDF viewers
   (again, try to find them in /usr/bin, /usr/local/bin, possibly in the whole PATH)
    - Gnome: evince, ggv
    - KDE: kpdf, kghostview
   If the execution is successful, finish.
5) Try to find some other PDF viewer (in /usr/bin, /usr/local/bin, possibly in the whole PATH):
    - acroread, xpdf
Comment 1 Marian Petras 2007-10-22 11:19:39 UTC
This enhancement would be implemented in file

    utilities/src/org/netbeans/modules/pdf/PDFOpenSupport.java
Comment 2 elotter 2011-08-15 21:38:37 UTC
Would going the JDK6 Desktop.getDesktop() route be an acceptable solution in this case? The file open support there does very good detection on my Linux systems, presumably also on Windows.
Comment 3 tomwheeler 2011-08-28 15:10:19 UTC
I believe that Tim Sparg is going to work on this issue for the First Patch program, with the help of Tushar Joshi.   But in response to Ernest's question of 15 August, yes, I think the Desktop API is probably the best solution.  

I imagine that the reason it was not originally developed this way is because the Desktop API was introduced in JDK 6, but the IDE still had to support earlier versions of the JDK.  However, that is no longer a concern because JDK 6 or higher is required for current versions of NetBeans:

  http://netbeans.org/community/releases/70/relnotes.html#system_requirements

Here is a helpful article on the Desktop API:

  http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/desktop_api/
Comment 4 tim_sa 2011-09-02 07:49:31 UTC
I agree with TomWheeler, the Dektop API looks to be a valid replacement for the logic that looks up the PDF-Viewer

I see 2 ways of accomplishing this
1) rewrite the open() method of PDFOpenSupport so that it jus wraps the call to Desktop.open()
2) doing the above and falling back on the old code if the Desktop.open() call fails

I think that the first option is much cleaner, it allows you to remove alot of code that exists to support the implementation of the searching logic.
Comment 5 Jaroslav Havlin 2011-09-06 13:29:07 UTC
I also think that the first option is the right one, as it is much simpler and
cleaner.

Tim, it would be great if you could provide your patch.
Comment 6 tusharvjoshi 2011-09-06 15:54:05 UTC
In addition to Tom, elotter@netbeans.org and jhavlin@netbeans.org I also agree that using Desktop API from Java SE 6 is the most standard and platform independent way of making this happen.

Tim, try implementing the first option in your local environment and send me the patch and I will help you test the fix on platforms like Mac OS X Lion, Windows 7 and Ubuntu 11.04
Comment 7 tim_sa 2011-09-21 07:14:31 UTC
Created attachment 110940 [details]
OpenPDF using Desktop functionality 

Hi all 

I've created the patch as per the suggestions above (Using the built in Desktop.open() functionality).

If there are any changes required please let me know and I will amend the patch
Comment 8 Jaroslav Havlin 2011-09-21 07:18:36 UTC
Thank you very much, Tim. I am going to apply your patch.
Comment 9 tusharvjoshi 2011-09-21 10:05:54 UTC
In response to Comment #7

I have checked this patch and verified the functionality on Max OS X Lion and WIndows 7.  I found this patch working as expected on these platform.

On Mac - PDF opens in Preview app
On Windows 7 - PDF Opens in system PDF viewer, in my case Foxit reader

I also tried simulating the error condition by making conditions of PDF file on Mac as 000 and it shows error in a dialog.

with regards
Tushar Joshi, Nagpur
Comment 10 Jaroslav Havlin 2011-09-21 10:25:06 UTC
Thank you, Tim.
Thank you, Tushar.

Great job! We really appreciate your helpful contribution.
Now the code is clean and simple - exactly as it should be.

Best regards,
 Jarda
Comment 11 Jaroslav Havlin 2011-09-21 10:37:15 UTC
I only slightly changed the patch to avoid using deprecated class NotifyDescriptor.Exception.

Verified on Windows 7 and Ubuntu Linux 11.04. Works well.

core-main/rev/eaa80748af72
Fixed.
Comment 12 tusharvjoshi 2011-09-21 11:03:35 UTC
In response to Comment #11

Wow! Thanks Jarda for this quick turnaround.
Tim here goes your blood into the veins of NetBeans IDE now, congrats.

with regards
Tushar
Comment 13 Jesse Glick 2011-09-21 15:54:09 UTC
Works on Ubuntu 10.04 / GNOME - opens evince as expected.
Comment 14 Quality Engineering 2011-09-22 14:51:05 UTC
Integrated into 'main-golden'
Changeset: http://hg.netbeans.org/main-golden/rev/eaa80748af72
User: Jaroslav Havlin <jhavlin@netbeans.org>
Log: #119629 - Improve detection of the preferred PDF viewer