PDA

View Full Version : Default Browser



OldJohnB
23rd July 2007, 10:10 PM
I am writing an application in C++ qt3 and want to launch a web page using the default browser from within the application using QProcess. My problem is how do I know which browser has been set as default by the user? If I knew which config file held the default browser name I could search it and then launch appropriately. The environmental variable $BROWSER is not always set on some systems, so that does not help. Is there a command line utility or library function that returns the default browser name?

Anyone help?

unixguru88
24th July 2007, 04:30 AM
What is the definition of default browser? I would suggest you give an option asking what browser should be used when the user starts the program for the first time.

brunson
24th July 2007, 05:19 AM
use the command "gnome-open" to open the file and it will call the correct application. Or use "htmlview", which is a script written to do exactly what you're trying to. It's a pretty interesting read.

OldJohnB
24th July 2007, 06:19 AM
What is the definition of default browser? I would suggest you give an option asking what browser should be used when the user starts the program for the first time.
What is the definition of default browser? I would suggest you give an option asking what browser should be used when the user starts the program for the first time.

unixguru88, I am not sure what you mean by definition but to me the default browser is the browser the user sets to open html files and links. That is the one the user prefers to use? As a work around I have done as you suggest and programmed a dialog to allow the user to choose from Firefox or konqueror or name a custom browser. But I would prefer just to be able to read the name of the default browser from a configuration file and use it without user intervention.
Thanks.

OldJohnB
24th July 2007, 06:24 AM
use the command "gnome-open" to open the file and it will call the correct application. Or use "htmlview", which is a script written to do exactly what you're trying to. It's a pretty interesting read.
Thanks for the suggestions. I normally use KDE so I am not familiar with gnome-open but I assume it only works if running gnome? htmlview sounds more interesting so I will check it out in the morning - its getting past my bedtime!

brunson
24th July 2007, 06:32 AM
I saw mention of KDE settings in the htmlview script, it could be what you're looking for. Gnome-open is, as you guessed, gnome-only. :-)

OldJohnB
25th July 2007, 12:11 AM
The htmlview script works fine with my app running on KDE - just what I needed. I have had a look at the scipt and can see it was written mainly for Gnome but will run under KDE. I program mainly in C and C++ and have only written very elementary bash scripts so I don't fully understand how htmlview works. However, I plan to use it as a learning exercise and try to figure out where it gets its default browser information from. It seems to search through a list of browsers i.e. konqueror, kfmbrowser, mozilla, epiphany, galeon, netscape, presumeably to find the one that is the default. Which implies that the browser itself contains the information that it is set as the default browser, rather than some configuration file some where? What do you think?

brunson
25th July 2007, 04:23 PM
I just had a quick read through the script. It's sophisticated enough to query gnome settings to determine the default browser in gnome, but uses a pretty naive approach under KDE. I don't think the browser has any innate knowledge of itself being the default, you'd have to start the browser for it to be able to decide. I don't know how KDE stores its preferences, so maybe someone more familiar with that environ can comment.

OldJohnB
26th July 2007, 11:49 PM
Just to follow up. I have been experimenting with htmlview script and although I haven't understood all the code as yet, by trial and error I have determined that the key component is the program "gnome-default-applications-properties". When run by itself it pops up a GUI that allows you to set the default browser and default email client. When run in a script it also seems to set the environmental variable $GCONF to contain the name of your default browser. Similarly it probably sets a variable for the email client but I don't know what its called. This works when running KDE but of course depends upon having "gnome-default-applications-properties" on your system.
What I would still like to know is where this default information is stored so that I can access it directly. This may be important since both htmlview and gnome-default-applications-properties programs are designated as "deprecated" and due to be replaced in the future. I am not sure how to find the source code for gnome-default-applications-properties without downloading the whole GNOME tarball and searching through it, which could be a tedious exercise.