?? z79.html
字號:
</p> <p> <code><code class="FUNCDEF">gchar* <tt class= "FUNCTION"> gnome_config_get_translated_string_with_default</tt></code>(const gchar* <tt class="PARAMETER"><i>path</i></tt>, gboolean* <tt class="PARAMETER"><i> was_default</i></tt>);</code> </p> <p> <code><code class="FUNCDEF">gint <tt class= "FUNCTION"> gnome_config_get_int_with_default</tt></code>(const gchar* <tt class="PARAMETER"><i>path</i></tt>, gboolean* <tt class="PARAMETER"><i> was_default</i></tt>);</code> </p> <p> <code><code class="FUNCDEF">gdouble <tt class= "FUNCTION"> gnome_config_get_float_with_default</tt></code>(const gchar* <tt class="PARAMETER"><i>path</i></tt>, gboolean* <tt class="PARAMETER"><i> was_default</i></tt>);</code> </p> <p> <code><code class="FUNCDEF">gboolean <tt class= "FUNCTION"> gnome_config_get_bool_with_default</tt></code>(const gchar* <tt class="PARAMETER"><i>path</i></tt>, gboolean* <tt class="PARAMETER"><i> was_default</i></tt>);</code> </p> <p> <code><code class="FUNCDEF">void <tt class= "FUNCTION"> gnome_config_get_vector_with_default</tt></code>(const gchar* <tt class="PARAMETER"><i>path</i></tt>, gint* <tt class="PARAMETER"><i>argcp</i></tt>, gchar*** <tt class="PARAMETER"><i>argvp</i></tt>, gboolean* <tt class="PARAMETER"><i>was_default</i></tt>);</code> </p> <p> <code><code class="FUNCDEF">gchar* <tt class= "FUNCTION"> gnome_config_private_get_string_with_default</tt></code>(const gchar* <tt class="PARAMETER"><i>path</i></tt>, gboolean* <tt class="PARAMETER"><i> was_default</i></tt>);</code> </p> <p> <code><code class="FUNCDEF">gchar* <tt class= "FUNCTION"> gnome_config_private_get_translated_string_with_default</tt></code>(const gchar* <tt class="PARAMETER"><i>path</i></tt>, gboolean* <tt class="PARAMETER"><i> was_default</i></tt>);</code> </p> <p> <code><code class="FUNCDEF">gint <tt class= "FUNCTION"> gnome_config_private_get_int_with_default</tt></code>(const gchar* <tt class="PARAMETER"><i>path</i></tt>, gboolean* <tt class="PARAMETER"><i> was_default</i></tt>);</code> </p> <p> <code><code class="FUNCDEF">gdouble <tt class= "FUNCTION"> gnome_config_private_get_float_with_default</tt></code>(const gchar* <tt class="PARAMETER"><i>path</i></tt>, gboolean* <tt class="PARAMETER"><i> was_default</i></tt>);</code> </p> <p> <code><code class="FUNCDEF">gboolean <tt class= "FUNCTION"> gnome_config_private_get_bool_with_default</tt></code>(const gchar* <tt class="PARAMETER"><i>path</i></tt>, gboolean* <tt class="PARAMETER"><i> was_default</i></tt>);</code> </p> <p> <code><code class="FUNCDEF">void <tt class= "FUNCTION"> gnome_config_private_get_vector_with_default</tt></code>(const gchar* <tt class="PARAMETER"><i>path</i></tt>, gint* <tt class="PARAMETER"><i>argcp</i></tt>, gchar*** <tt class="PARAMETER"><i>argvp</i></tt>, gboolean* <tt class="PARAMETER"><i>was_default</i></tt>);</code> </p> </div> <p> <b>Figure 4. Retrieving data from configuration files</b> </p> </div> </div> <div class="SECT2"> <h2 class="SECT2"> <a name="Z81">Storing Data In Configuration Files</a> <p> Saving data is simply the inverse of loading it; you provide a <span class="STRUCTNAME"> "/file/section/key"</span> path in just the same way, along with the value to store. Data is not written immediately; you must call <tt class="FUNCTION"> gnome_config_sync()</tt> to ensure the file is written to disk. </p> <div class="FIGURE"> <a name="STARTUP-GNOMECONFIGSET"></a> <div class="FUNCSYNOPSIS"> <a name="STARTUP-GNOMECONFIGSET.SYNOPSIS"></a> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="FUNCSYNOPSISINFO">#include <libgnome/gnome-config.h></pre> </td> </tr> </table> <p> <code><code class="FUNCDEF">void <tt class= "FUNCTION">gnome_config_set_string</tt></code>(const gchar* <tt class="PARAMETER"><i>path</i></tt>, const gchar* <tt class="PARAMETER"><i> value</i></tt>);</code> </p> <p> <code><code class="FUNCDEF">void <tt class= "FUNCTION"> gnome_config_set_translated_string</tt></code>(const gchar* <tt class="PARAMETER"><i>path</i></tt>, const gchar* <tt class="PARAMETER"><i> value</i></tt>);</code> </p> <p> <code><code class="FUNCDEF">void <tt class= "FUNCTION">gnome_config_set_int</tt></code>(const gchar* <tt class="PARAMETER"><i>path</i></tt>, gint <tt class="PARAMETER"><i>value</i></tt>);</code> </p> <p> <code><code class="FUNCDEF">void <tt class= "FUNCTION">gnome_config_set_float</tt></code>(const gchar* <tt class="PARAMETER"><i>path</i></tt>, gdouble <tt class="PARAMETER"><i> value</i></tt>);</code> </p> <p> <code><code class="FUNCDEF">void <tt class= "FUNCTION">gnome_config_set_bool</tt></code>(const gchar* <tt class="PARAMETER"><i>path</i></tt>, gboolean <tt class="PARAMETER"><i> value</i></tt>);</code> </p> <p> <code><code class="FUNCDEF">void <tt class= "FUNCTION">gnome_config_set_vector</tt></code>(const gchar* <tt class="PARAMETER"><i>path</i></tt>, gint <tt class="PARAMETER"><i>argc</i></tt>, const gchar* const <tt class="PARAMETER"><i> argv[]</i></tt>);</code> </p> <p> <code><code class="FUNCDEF">void <tt class= "FUNCTION"> gnome_config_private_set_string</tt></code>(const gchar* <tt class="PARAMETER"><i>path</i></tt>, const gchar* <tt class="PARAMETER"><i> value</i></tt>);</code> </p> <p> <code><code class="FUNCDEF">void <tt class= "FUNCTION"> gnome_config_private_set_translated_string</tt></code>(const gchar* <tt class="PARAMETER"><i>path</i></tt>, const gchar* <tt class="PARAMETER"><i> value</i></tt>);</code> </p> <p> <code><code class="FUNCDEF">void <tt class= "FUNCTION"> gnome_config_private_set_int</tt></code>(const gchar* <tt class="PARAMETER"><i>path</i></tt>, gint <tt class="PARAMETER"><i>value</i></tt>);</code> </p> <p> <code><code class="FUNCDEF">void <tt class= "FUNCTION"> gnome_config_private_set_float</tt></code>(const gchar* <tt class="PARAMETER"><i>path</i></tt>, gdouble <tt class="PARAMETER"><i> value</i></tt>);</code> </p> <p> <code><code class="FUNCDEF">void <tt class= "FUNCTION"> gnome_config_private_set_bool</tt></code>(const gboolean <tt class="PARAMETER"><i> value</i></tt>);</code> </p> <p> <code><code class="FUNCDEF">void <tt class= "FUNCTION"> gnome_config_private_set_vector</tt></code>(const gchar* <tt class="PARAMETER"><i>path</i></tt>, gint <tt class="PARAMETER"><i>argc</i></tt>, const gchar* const <tt class="PARAMETER"><i> argv[]</i></tt>);</code> </p> </div> <p> <b>Figure 5. Saving data to configuration files</b> </p> </div> </div> <div class="SECT2"> <h2 class="SECT2"> <a name="Z82">Config File Iterators</a> </h2> <p> Iterators are used to scan the sections in a given file, or the keys in a given section. Applications can use this feature to store lists of data, by dynamically generating key or section names to save and later iterating over them to discover what was saved. The functions are summarized in <a href= "z79.html#STARTUP-GNOMECONFIGITERATORS">Figure 6 in the section called <i>Section Iterators</i></a>. </p> <p> An iterator is an opaque data type; you pass <tt class= "FUNCTION">gnome_config_init_iterator()</tt> the name of a section to iterate over and receive an iterator in return. You then call <tt class="FUNCTION"> gnome_config_iterator_next()</tt> to obtain key-value pairs from the section. The key and value returned from <tt class="FUNCTION">gnome_config_iterator_next()</tt> must be freed with <tt class="FUNCTION">g_free()</tt>, and the return value of <tt class="FUNCTION"> gnome_config_iterator_next()</tt> is a pointer to the next iterator. When <tt class="FUNCTION"> gnome_config_iterator_next()</tt> returns <span class= "STRUCTNAME">NULL</span>, all key-value pairs have been traversed. </p> <div class="SECT3"> <h3 class="SECT3"> <a name="Z83">Iteration Example from <tt class= "APPLICATION">gnome-apt</tt></a> </h3> <p> Here's an example from <tt class="APPLICATION"> gnome-apt</tt>, a C++ application used to manage packages on Debian systems. <tt class="APPLICATION"> gnome-apt</tt> loads and saves the position of some columns in a tree display. The columns are identified by the <span class="STRUCTNAME"> GAptPkgTree::ColumnType</span> enumeration. <span class="STRUCTNAME">GAptPkgTree::ColumnTypeEnd</span> is the last element in the column type enumeration, and equal to the number of valid column types. This example is frighteningly "real world" and checks for a number of error conditions. </p> <table border="0" bgcolor="#E0E0E0" width="100%"> <tr> <td><pre class="PROGRAMLISTING"> static voidload_column_order(vector<GAptPkgTree::ColumnType> & columns){ gpointer config_iterator; guint loaded = 0; config_iterator = gnome_config_init_iterator("/gnome-apt/ColumnOrder"); if (config_iterator != 0) { gchar * col, * pos; columns.reserve(GAptPkgTree::ColumnTypeEnd); loaded = 0; while ((config_iterator = gnome_config_iterator_next(config_iterator, &col, &pos))) { // shouldn't happen, but I'm paranoid if (pos == 0 || col == 0) { if (pos) g_free(pos); if (col) g_free(col); continue; } GAptPkgTree::ColumnType ct = string_to_column(col); gint index = atoi(pos); g_free(pos); pos = 0; g_free(col); col = 0; // the user could mangle the config file to make this happen if (static_cast<guint>(index) >= columns.size()) continue; columns[index] = ct; ++loaded; } } if (loaded != static_cast<guint>(GAptPkgTree::ColumnTypeEnd)) { // Either there was no saved order, or something is busted - use // default order columns.clear(); int i = 0; while (i < GAptPkgTree::ColumnTypeEnd) { columns.push_back(static_cast<GAptPkgTree::ColumnType>(i)); ++i; } // Clean the section - otherwise an old entry could // remain forever and keep screwing us up in the future. gnome_config_clean_section("/gnome-apt/ColumnOrder"); gnome_config_sync(); } g_return_if_fail(columns.size() == static_cast<guint>(GAptPkgTree::ColumnTypeEnd));} </pre> </td> </tr> </table> <p> It might be helpful to see the function that saves the column positions: </p> <table border="0" bgcolor="#E0E0E0" width="100%">
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -