Reading default preferences in C++
When I attempt to read a default preference via
nsIPrefBranch::GetCharPref, I'm getting what I think is a chrome URI
instead of the pref I see when I load about:config.
Considering the following:
nsresult rv;
nsCOMPtr<nsIPrefBranch> prefBranch;
char *pszHomePage;
rv = prefService->GetBranch("", getter_AddRefs(prefBranch));
rv = prefBranch->GetCharPref("browser.startup.homepage",
&pszHomePage);
When my home page is user set I can retrieve it. However, when it is
the default ("http://www.google.com/firefox?client=firefox-
a&rls=org.mozilla:en-US:official"), I'm receiving "resource:/
browserconfig.properties"
I'd like to get the actual URL (the google one), not the file that
contains the value. Anyone know what I'm doing wrong?
Thanks,
Dave
Re: Reading default preferences in C++
[email]test1033@gmail.com[/email] wrote:
[color=blue]
>When I attempt to read a default preference via nsIPrefBranch::GetCharPref, I'm getting what I think is a chrome URI instead of the pref I see when I load about:config.
>
>[/color]
That's because it's a localised pref, so you need to call
GetComplexValue to retrieve the actual URL:
nsCOMPtr<nsIPrefLocalisedString> urlString;
prefBranch->GetComplexValue("browser.startup.homepage",
NS_GET_IID(nsIPrefLocalisedString), getter_AddRefs(urlString));
if (urlString) {
nsXPIDLString data;
urlString->GetData(getter_Copies(data));
}
--
Warning: May contain traces of nuts.
Re: Reading default preferences in C++
Sir, I owe you a beer.
Thanks!
Dave