📄 libgnome-gnome-program.html
字号:
<a class="indexterm" name="id2786420"></a><pre class="programlisting">typedef struct { const char *name; const char *version; const char *description; GnomeModuleRequirement *requirements; /* last element has NULL version */ GnomeModuleHook instance_init; GnomeModuleHook pre_args_parse, post_args_parse;#ifdef GNOME_DISABLE_DEPRECATED struct poptOption *_options;#else struct poptOption *options;#endif GnomeModuleInitHook init_pass; GnomeModuleClassInitHook class_init; const char *opt_prefix; GnomeModuleGetGOptionGroupFunc get_goption_group_func;} GnomeModuleInfo;</pre><p>A structure containing information about a module. This contains descriptiveinformation about the module, as well as how to initialise it and what itsdependencies are (chained via the <em class="parameter"><code>requirements</code></em> parameter).</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term">const char *<em class="structfield"><code>name</code></em>;</span></td><td>The module name.</td></tr><tr><td><span class="term">const char *<em class="structfield"><code>version</code></em>;</span></td><td>The module's version string.</td></tr><tr><td><span class="term">const char *<em class="structfield"><code>description</code></em>;</span></td><td>A string describing the module (can be <ahref="/usr/share/gtk-doc/html/liboil/liboil-liboiljunk.html#NULL:CAPS"><code class="literal">NULL</code></a>).</td></tr><tr><td><span class="term"><a href="libgnome-gnome-program.html#GnomeModuleRequirement">GnomeModuleRequirement</a> *<em class="structfield"><code>requirements</code></em>;</span></td><td>A pointer to an array of modules that are required by thismodule. The last module in the array should have its required_version field setto <ahref="/usr/share/gtk-doc/html/liboil/liboil-liboiljunk.html#NULL:CAPS"><code class="literal">NULL</code></a>.</td></tr><tr><td><span class="term"><a href="libgnome-gnome-program.html#GnomeModuleHook">GnomeModuleHook</a> <em class="structfield"><code>instance_init</code></em>;</span></td><td>A function to call to initialise an instance of this module(can be <ahref="/usr/share/gtk-doc/html/liboil/liboil-liboiljunk.html#NULL:CAPS"><code class="literal">NULL</code></a>).</td></tr><tr><td><span class="term"><a href="libgnome-gnome-program.html#GnomeModuleHook">GnomeModuleHook</a> <em class="structfield"><code>pre_args_parse</code></em>;</span></td><td>A function to call before parsing the arguments for thismodule (can be <ahref="/usr/share/gtk-doc/html/liboil/liboil-liboiljunk.html#NULL:CAPS"><code class="literal">NULL</code></a>).</td></tr><tr><td><span class="term"><a href="libgnome-gnome-program.html#GnomeModuleHook">GnomeModuleHook</a> <em class="structfield"><code>post_args_parse</code></em>;</span></td><td>A function to call after parsing the arguments for thismodule (can be <ahref="/usr/share/gtk-doc/html/liboil/liboil-liboiljunk.html#NULL:CAPS"><code class="literal">NULL</code></a>).</td></tr><tr><td><span class="term"><a href="libgnome-gnome-program.html#GnomeModuleClassInitHook">GnomeModuleClassInitHook</a> <em class="structfield"><code>class_init</code></em>;</span></td><td>A function to call to initialise this module prior to creating anyinstances (can be <ahref="/usr/share/gtk-doc/html/liboil/liboil-liboiljunk.html#NULL:CAPS"><code class="literal">NULL</code></a>).</td></tr><tr><td><span class="term">const char *<em class="structfield"><code>opt_prefix</code></em>;</span></td><td>Unused.</td></tr><tr><td><span class="term">GnomeModuleGetGOptionGroupFunc <em class="structfield"><code>get_goption_group_func</code></em>;</span></td><td>A function which must return a non-<ahref="/usr/share/gtk-doc/html/liboil/liboil-liboiljunk.html#NULL:CAPS"><code class="literal">NULL</code></a> <ahref="/usr/share/gtk-doc/html/glib/glib-Commandline-option-parser.html#GOptionGroup"><span class="type">GOptionGroup</span></a>,which will be added to the <a href="libgnome-gnome-program.html#GnomeProgram"><span class="type">GnomeProgram</span></a> s <ahref="/usr/share/gtk-doc/html/glib/glib-Commandline-option-parser.html#GOptionContext"><span class="type">GOptionContext</span></a> during#<a href="libgnome-gnome-program.html#gnome-program-init"><code class="function">gnome_program_init()</code></a>.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2786787"></a><h3><a name="GnomeModuleRequirement"></a>GnomeModuleRequirement</h3><a class="indexterm" name="id2786799"></a><pre class="programlisting">typedef struct { const char *required_version; const GnomeModuleInfo *module_info;} GnomeModuleRequirement;</pre><p>A structure which allows a module to specify the minimum required versions ofmodules it depends upon.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term">const char *<em class="structfield"><code>required_version</code></em>;</span></td><td>The version required by the parent module.</td></tr><tr><td><span class="term">const <a href="libgnome-gnome-program.html#GnomeModuleInfo">GnomeModuleInfo</a> *<em class="structfield"><code>module_info</code></em>;</span></td><td>A <a href="libgnome-gnome-program.html#GnomeModuleInfo"><span class="type">GnomeModuleInfo</span></a> structure detailing the required module.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2786875"></a><h3><a name="GnomeModuleInitHook"></a>GnomeModuleInitHook ()</h3><a class="indexterm" name="id2786888"></a><pre class="programlisting">void (*GnomeModuleInitHook) (const <a href="libgnome-gnome-program.html#GnomeModuleInfo">GnomeModuleInfo</a> *mod_info);</pre><p>A function that will be called to allow a module to do any pre-initialisationit might need to do prior to having arguments parsed by the controlling parentmodule (the parent will do the argument parsing for all modules in thehierarchy).</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>mod_info</code></em> :</span></td><td>The current module.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2786939"></a><h3><a name="GnomeModuleClassInitHook"></a>GnomeModuleClassInitHook ()</h3><a class="indexterm" name="id2786952"></a><pre class="programlisting">void (*GnomeModuleClassInitHook) (GnomeProgramClass *klass, const <a href="libgnome-gnome-program.html#GnomeModuleInfo">GnomeModuleInfo</a> *mod_info);</pre><p>A function called to perform any class specific setup that is required by eachmodule.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>klass</code></em> :</span></td><td>The class of the parent module (which could be this module's class).This will usually be <span class="type">GnomeProgramClass</span>.</td></tr><tr><td><span class="term"><em class="parameter"><code>mod_info</code></em> :</span></td><td>The current module.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2787032"></a><h3><a name="GnomeModuleHook"></a>GnomeModuleHook ()</h3><a class="indexterm" name="id2787044"></a><pre class="programlisting">void (*GnomeModuleHook) (<a href="libgnome-gnome-program.html#GnomeProgram">GnomeProgram</a> *program, <a href="libgnome-gnome-program.html#GnomeModuleInfo">GnomeModuleInfo</a> *mod_info);</pre><p>A function that is called to perform some intialisation in a module (whichcould be either the main init function or the pre or post argument parsingphase).</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>program</code></em> :</span></td><td>The <a href="libgnome-gnome-program.html#GnomeProgram"><span class="type">GnomeProgram</span></a> instance which is being initialised.</td></tr><tr><td><span class="term"><em class="parameter"><code>mod_info</code></em> :</span></td><td>The current module's <a href="libgnome-gnome-program.html#GnomeModuleInfo"><span class="type">GnomeModuleInfo</span></a> structure.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id2787133"></a><h3><a name="gnome-program-init"></a>gnome_program_init ()</h3><a class="indexterm" name="id2787146"></a><pre class="programlisting"><a href="libgnome-gnome-program.html#GnomeProgram">GnomeProgram</a>* gnome_program_init (const char *app_id, const char *app_version, const <a href="libgnome-gnome-program.html#GnomeModuleInfo">GnomeModuleInfo</a> *module_info, int argc, char **argv, const char *first_property_name, ...);</pre><p>Initialises the current GNOME libraries for use by the application.</p><p>Every GNOME application will need to call this function (or<a href="libgnome-gnome-program.html#gnome-program-initv"><code class="function">gnome_program_initv()</code></a>) early in its lifetime to initialize the various GNOMElibraries in a consistent fashion. This function is very flexible in allowingthe user to specify which modules should be initialised and any specialparamter values that should be passed to these modules (along with processingcommandline options).</p><p>It loads the specified <em class="parameter"><code>module_info</code></em>, which is normally <a href="libgnome-gnome-init.html#LIBGNOME-MODULE:CAPS"><span class="type">LIBGNOME_MODULE</span></a> or<ahref="/usr/share/gtk-doc/html/libgnomeui/libgnomeui-gnome-ui-init.html#LIBGNOMEUI-MODULE:CAPS"><span class="type">LIBGNOMEUI_MODULE</span></a> and pulls in all the dependencies. Programs that are notrunning in setuid or setgid mode will also load modules specified in the<em class="parameter"><code>--load-modules</code></em> and also in the <em class="parameter"><code>GNOME_MODULES</code></em> environment variable.</p><p>After setting up the module loading, this function then calls (in order)<a href="libgnome-gnome-program.html#gnome-program-preinit"><code class="function">gnome_program_preinit()</code></a>, <a href="libgnome-gnome-program.html#gnome-program-parse-args"><code class="function">gnome_program_parse_args()</code></a> and<a href="libgnome-gnome-program.html#gnome-program-postinit"><code class="function">gnome_program_postinit()</code></a>.</p><p>The following example shows how one might initialise a typical programusing a goption table that is defined elsewhere.</p><div class="example"><a name="id2787327"></a><p class="title"><b>Example 1. Initializing a GNOME application (deprecated, using popt)</b></p><pre class="programlisting">int main(int argc, char **argv) { GnomeProgram *my_app; GOptionContext *option_context; /* We assume PACKAGE and VERSION are set to the program name and version * number respectively. Also, assume that 'options' is a global array of * poptOptions. */ option_context = g_option_context_new (PACKAGE); g_option_context_add_main_entries (option_context, options, NULL); my_app = gnome_program_init(PACKAGE, VERSION, LIBGNOMEUI_MODULE, argc, argv, GNOME_PARAM_GOPTION_CONTEXT, option_context, GNOME_PARAM_NONE); /* Now process any extra args, etc ... */}</pre></div><p>Even though many applications still use popt for command-line option parsing,it has been deprecated in Gnome-2.14 and its use is discouraged fornewly-written code. GNOME applications should aim to use the new<span class="type">GOption</span> API. Here an example that shows how one might initialize a typicalprogram using a GOptionEntry table (see the GLib documentation for a moreelaborate example of an option entry table):</p><div class="example"><a name="id2787369"></a><p class="title"><b>Example 2. Initializing a GNOME application (new, using GOption)</b></p><pre class="programlisting">int main(int argc, char **argv) { gchar **remaining_args = NULL; GOptionEntry option_entries[] = { /* ... your application's command line options go here ... */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -