Revision 68671 of Using preferences from application code

  • Revision slug: Mozilla/Preferences/Using_preferences_from_application_code
  • Revision title: Using preferences from application code
  • Revision id: 68671
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment 61 words added

Revision Content

{{ gecko_minversion_header("6.0") }}

{{ draft() }}

Firefox 6 introduced static functions, as part of the C++ Preferences class, for accessing preferences efficiently from within application code. This API is not available for add-ons, but if you're working on a Gecko application, this API is the preferred way to access preferences.

Due to the relatively limited target audience for this API, we don't have a thorough API reference at this time (although if you have some time, feel free to add one!). The examples below and the self-explanatory nature of most of the API should do the trick. Take a look at the source: {{ Source("modules/libpref/public/Preferences.h") }}.

Examples

Simply retrieving the value of a Boolean preference can be done like this:

PRBool myPref = Preferences::GetBool("preference.name.string", PR_TRUE);

This returns the value of the preference named "preference.name.string", using the default value PR_TRUE if the preference doesn't exist.

See also

Revision Source

<p>{{ gecko_minversion_header("6.0") }}</p>
<p>{{ draft() }}</p>
<p>Firefox 6 introduced static functions, as part of the C++ <code>Preferences</code> class, for accessing preferences efficiently from within application code. This API is not available for add-ons, but if you're working on a Gecko application, this API is the preferred way to access preferences.</p>
<p>Due to the relatively limited target audience for this API, we don't have a thorough API reference at this time (although if you have some time, feel free to add one!). The examples below and the self-explanatory nature of most of the API should do the trick. Take a look at the source: {{ Source("modules/libpref/public/Preferences.h") }}.</p>
<h2>Examples</h2>
<p>Simply retrieving the value of a Boolean preference can be done like this:</p>
<pre>PRBool myPref = Preferences::GetBool("preference.name.string", PR_TRUE);
</pre>
<p>This returns the value of the preference named "preference.name.string", using the default value <code>PR_TRUE</code> if the preference doesn't exist.</p>
<h2>See also</h2>
<ul> <li><a href="/en/Preferences" title="en/Preferences">Preferences</a></li>
</ul>
Revert to this revision