1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>
Gnome Application Basics
</title>
<meta name="GENERATOR" content=
"Modular DocBook HTML Stylesheet Version 1.45">
<link rel="HOME" title="GTK+ / Gnome Application Development"
href="ggad.html">
<link rel="UP" title="Building a Gnome Application" href=
"build-app.html">
<link rel="PREVIOUS" title="Installing Support Files" href=
"z72.html">
<link rel="NEXT" title="Internationalization" href=
"sec-i18n.html">
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink=
"#840084" alink="#0000FF">
<div class="NAVHEADER">
<table width="100%" border="0" bgcolor="#ffffff" cellpadding=
"1" cellspacing="0">
<tr>
<th colspan="4" align="center">
<font color="#000000" size="2">GTK+ / Gnome Application
Development</font>
</th>
</tr>
<tr>
<td width="25%" bgcolor="#ffffff" align="left">
<a href="z72.html"><font color="#0000ff" size="2"><b>
<<< Previous</b></font></a>
</td>
<td width="25%" colspan="2" bgcolor="#ffffff" align=
"center">
<font color="#0000ff" size="2"><b><a href="ggad.html">
<font color="#0000ff" size="2"><b>
Home</b></font></a></b></font>
</td>
<td width="25%" bgcolor="#ffffff" align="right">
<a href="sec-i18n.html"><font color="#0000ff" size="2">
<b>Next >>></b></font></a>
</td>
</tr>
</table>
</div>
<div class="CHAPTER">
<h1>
<a name="CHA-STARTUP">Gnome Application Basics</a>
</h1>
<div class="TOC">
<dl>
<dt>
<b>Table of Contents</b>
</dt>
<dt>
<a href="cha-startup.html#Z76">Initializing the
Libraries</a>
</dt>
<dt>
<a href="sec-i18n.html">Internationalization</a>
</dt>
<dt>
<a href="z77.html">Argument Parsing with <tt class=
"APPLICATION">popt</tt></a>
</dt>
<dt>
<a href="z79.html">Saving Configuration Information</a>
</dt>
<dt>
<a href="sec-sessionmanagement.html">Session
Management</a>
</dt>
</dl>
</div>
<p>
This chapter describes the most rudimentary aspects of a
Gnome application, including initializing the libraries,
marking strings for translation, parsing command line
arguments, saving configuration files, and responding to
requests from the session manager. From here on, the book
assumes you know how to write a simple GTK+-only
application.
</p>
<div class="SECT1">
<h1 class="SECT1">
<a name="Z76">Initializing the Libraries</a>
</h1>
<p>
On startup, your application must initialize the GTK+ and
Gnome libraries with a call to <tt class="FUNCTION">
gnome_init()</tt>. <tt class="FUNCTION">gnome_init()</tt>
(<a href="cha-startup.html#FL-GNOMEINIT">Figure 1</a>)
takes the place of <tt class="FUNCTION">gtk_init()</tt>
for Gnome apps (it calls <tt class="FUNCTION">
gtk_init()</tt> for you).
</p>
<p>
The first argument to <tt class="FUNCTION">
gnome_init()</tt> is a short name for your application,
and the second is a string representing the application's
version. These are used internally by the Gnome libraries
(in some default messages provided by the argument
parser, for example).
</p>
<div class="FIGURE">
<a name="FL-GNOMEINIT"></a>
<div class="FUNCSYNOPSIS">
<a name="FL-GNOMEINIT.SYNOPSIS"></a>
<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="FUNCSYNOPSISINFO">
#include <libgnomeui/gnome-init.h>
</pre>
</td>
</tr>
</table>
<p>
<code><code class="FUNCDEF">int <tt class="FUNCTION">
gnome_init</tt></code>(const char* <tt class=
"PARAMETER"><i>app_id</i></tt>, const char* <tt
class="PARAMETER"><i>app_version</i></tt>, int <tt
class="PARAMETER"><i>argc</i></tt>, char** <tt class=
"PARAMETER"><i>argv</i></tt>);</code>
</p>
</div>
<p>
<b>Figure 1. Initializing Gnome</b>
</p>
</div>
<p>
Like <tt class="FUNCTION">gtk_init()</tt>, <tt class=
"FUNCTION">gnome_init()</tt> parses the command-line
arguments; unlike <tt class="FUNCTION">gtk_init()</tt>,
it will not change <span class="STRUCTNAME">argc</span>
and <span class="STRUCTNAME">argv</span>. If you want to
parse application-specific options, you should use <tt
class="FUNCTION">gnome_init_with_popt_table()</tt>,
described in the next section.
</p>
<p>
The return value from <tt class="FUNCTION">
gnome_init()</tt> is supposed to be non-zero if
initialization fails, but the current implementation
always returns 0. (<tt class="FUNCTION">gnome_init()</tt>
will simply abort if there's a problem, such as a missing
X server.) Common practice is to ignore this return
value, at least in Gnome 1.0, but it's a good idea to
check it anyway in case future versions do return an
error.
</p>
<p>
[FOOTNOTE - reference after "always returns 0."] Most
people consider this a misfeature, but <tt class=
"FUNCTION">gtk_init()</tt> shared the same problem until
just before Gnome 1.0, so there was little to be done.
Future versions will hopefully fix the problem.
</p>
</div>
</div>
<div class="NAVFOOTER">
<br>
<br>
<table width="100%" border="0" bgcolor="#ffffff" cellpadding=
"1" cellspacing="0">
<tr>
<td width="25%" bgcolor="#ffffff" align="left">
<a href="z72.html"><font color="#0000ff" size="2"><b>
<<< Previous</b></font></a>
</td>
<td width="25%" colspan="2" bgcolor="#ffffff" align=
"center">
<font color="#0000ff" size="2"><b><a href="ggad.html">
<font color="#0000ff" size="2"><b>
Home</b></font></a></b></font>
</td>
<td width="25%" bgcolor="#ffffff" align="right">
<a href="sec-i18n.html"><font color="#0000ff" size="2">
<b>Next >>></b></font></a>
</td>
</tr>
<tr>
<td colspan="2" align="left">
<font color="#000000" size="2"><b>Installing Support
Files</b></font>
</td>
<td colspan="2" align="right">
<font color="#000000" size="2"><b>
Internationalization</b></font>
</td>
</tr>
</table>
</div>
</body>
</html>
|