views:

48

answers:

2

Hey all,

I'm working on a Firefox NPAPI plugin + XPCOM component. I've run into a dilemma: Given a file downloaded from the Internet (say a PDF or PNG) how do I start the default helper application to display that file on Linux using C/C++?

Currently I'm using the system function call to invoke the gnome-open command and passing it the file path. This works on GNOME Desktops, however it won't work across Linux platforms with different desktop environments (including KDE).

So my question is: Is there a standard uniform method to go about this? Are there any recommendations? Any help would be greatly appreciated!

+1  A: 

There is no standard tool to open a file using default application in Linux. It depends on a desktop environment. For Gnome, there is a "gnome-open" tool as you figured out. KDE has its "kde-open" for the same purpose. I would check for gnome-open first and if it doesn't exist, check for kde-open. Otherwise report an error to the user.

Another option is to use Firefox itself to open a file using "file://" protocol. Firefox is able to display PDF files if appropriate plugin is installed, display text files etcetera.

Vlad Lazarenko
+1  A: 

The xdg-open command is the standard way to open a file or URL in the user's preferred application.

It should work correctly in different desktop environments.

caf