Tizen 2.1 base
[platform/upstream/glib2.0.git] / docs / reference / gio / html / GApplicationCommandLine.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <title>GApplicationCommandLine</title>
6 <meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
7 <link rel="home" href="index.html" title="GIO Reference Manual">
8 <link rel="up" href="application.html" title="Application support">
9 <link rel="prev" href="GApplication.html" title="GApplication">
10 <link rel="next" href="GActionGroup.html" title="GActionGroup">
11 <meta name="generator" content="GTK-Doc V1.18 (XML mode)">
12 <link rel="stylesheet" href="style.css" type="text/css">
13 </head>
14 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
15 <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
16 <tr valign="middle">
17 <td><a accesskey="p" href="GApplication.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
18 <td><a accesskey="u" href="application.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
19 <td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
20 <th width="100%" align="center">GIO Reference Manual</th>
21 <td><a accesskey="n" href="GActionGroup.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
22 </tr>
23 <tr><td colspan="5" class="shortcuts">
24 <a href="#GApplicationCommandLine.synopsis" class="shortcut">Top</a>
25                    | 
26                   <a href="#GApplicationCommandLine.description" class="shortcut">Description</a>
27                    | 
28                   <a href="#GApplicationCommandLine.object-hierarchy" class="shortcut">Object Hierarchy</a>
29 </td></tr>
30 </table>
31 <div class="refentry">
32 <a name="GApplicationCommandLine"></a><div class="titlepage"></div>
33 <div class="refnamediv"><table width="100%"><tr>
34 <td valign="top">
35 <h2><span class="refentrytitle"><a name="GApplicationCommandLine.top_of_page"></a>GApplicationCommandLine</span></h2>
36 <p>GApplicationCommandLine — A command-line invocation of an application</p>
37 </td>
38 <td valign="top" align="right"></td>
39 </tr></table></div>
40 <div class="refsynopsisdiv">
41 <a name="GApplicationCommandLine.synopsis"></a><h2>Synopsis</h2>
42 <pre class="synopsis">                    <a class="link" href="GApplicationCommandLine.html#GApplicationCommandLine-struct" title="GApplicationCommandLine">GApplicationCommandLine</a>;
43 struct              <a class="link" href="GApplicationCommandLine.html#GApplicationCommandLineClass" title="struct GApplicationCommandLineClass">GApplicationCommandLineClass</a>;
44
45 <a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="returnvalue">gchar</span></a> **            <a class="link" href="GApplicationCommandLine.html#g-application-command-line-get-arguments" title="g_application_command_line_get_arguments ()">g_application_command_line_get_arguments</a>
46                                                         (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>,
47                                                          <em class="parameter"><code><span class="type">int</span> *argc</code></em>);
48 const <a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="returnvalue">gchar</span></a> *       <a class="link" href="GApplicationCommandLine.html#g-application-command-line-get-cwd" title="g_application_command_line_get_cwd ()">g_application_command_line_get_cwd</a>  (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>);
49 const <a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="returnvalue">gchar</span></a> * const * <a class="link" href="GApplicationCommandLine.html#g-application-command-line-get-environ" title="g_application_command_line_get_environ ()">g_application_command_line_get_environ</a>
50                                                         (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>);
51 const <a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="returnvalue">gchar</span></a> *       <a class="link" href="GApplicationCommandLine.html#g-application-command-line-getenv" title="g_application_command_line_getenv ()">g_application_command_line_getenv</a>   (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>,
52                                                          <em class="parameter"><code>const <a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *name</code></em>);
53 <a href="./../glib/glib/glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>            <a class="link" href="GApplicationCommandLine.html#g-application-command-line-get-is-remote" title="g_application_command_line_get_is_remote ()">g_application_command_line_get_is_remote</a>
54                                                         (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>);
55 <a href="./../glib/glib/glib-GVariant.html#GVariant"><span class="returnvalue">GVariant</span></a> *          <a class="link" href="GApplicationCommandLine.html#g-application-command-line-get-platform-data" title="g_application_command_line_get_platform_data ()">g_application_command_line_get_platform_data</a>
56                                                         (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>);
57
58 <span class="returnvalue">void</span>                <a class="link" href="GApplicationCommandLine.html#g-application-command-line-set-exit-status" title="g_application_command_line_set_exit_status ()">g_application_command_line_set_exit_status</a>
59                                                         (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>,
60                                                          <em class="parameter"><code><span class="type">int</span> exit_status</code></em>);
61 <span class="returnvalue">int</span>                 <a class="link" href="GApplicationCommandLine.html#g-application-command-line-get-exit-status" title="g_application_command_line_get_exit_status ()">g_application_command_line_get_exit_status</a>
62                                                         (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>);
63
64 <span class="returnvalue">void</span>                <a class="link" href="GApplicationCommandLine.html#g-application-command-line-print" title="g_application_command_line_print ()">g_application_command_line_print</a>    (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>,
65                                                          <em class="parameter"><code>const <a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *format</code></em>,
66                                                          <em class="parameter"><code>...</code></em>);
67 <span class="returnvalue">void</span>                <a class="link" href="GApplicationCommandLine.html#g-application-command-line-printerr" title="g_application_command_line_printerr ()">g_application_command_line_printerr</a> (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>,
68                                                          <em class="parameter"><code>const <a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *format</code></em>,
69                                                          <em class="parameter"><code>...</code></em>);
70 </pre>
71 </div>
72 <div class="refsect1">
73 <a name="GApplicationCommandLine.object-hierarchy"></a><h2>Object Hierarchy</h2>
74 <pre class="synopsis">
75   <a href="./../gobject/gobject/gobject-The-Base-Object-Type.html#GObject">GObject</a>
76    +----GApplicationCommandLine
77 </pre>
78 </div>
79 <div class="refsect1">
80 <a name="GApplicationCommandLine.description"></a><h2>Description</h2>
81 <p>
82 <a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> represents a command-line invocation of
83 an application.  It is created by <a class="link" href="GApplication.html" title="GApplication"><span class="type">GApplication</span></a> and emitted
84 in the <a class="link" href="GApplication.html#GApplication-command-line" title='The "command-line" signal'><span class="type">"command-line"</span></a> signal and virtual function.
85 </p>
86 <p>
87 The class contains the list of arguments that the program was invoked
88 with.  It is also possible to query if the commandline invocation was
89 local (ie: the current process is running in direct response to the
90 invocation) or remote (ie: some other process forwarded the
91 commandline to this process).
92 </p>
93 <p>
94 The GApplicationCommandLine object can provide the <em class="parameter"><code>argc</code></em> and <em class="parameter"><code>argv</code></em>
95 parameters for use with the <a href="./../glib/glib/glib-Commandline-option-parser.html#GOptionContext"><span class="type">GOptionContext</span></a> command-line parsing API,
96 with the <a class="link" href="GApplicationCommandLine.html#g-application-command-line-get-arguments" title="g_application_command_line_get_arguments ()"><code class="function">g_application_command_line_get_arguments()</code></a> function. See
97 <a class="xref" href="GApplicationCommandLine.html#gapplication-example-cmdline3" title="Example 19. Deferred commandline handling">Example 19, “Deferred commandline handling”</a> for an example.
98 </p>
99 <p>
100 The exit status of the originally-invoked process may be set and
101 messages can be printed to stdout or stderr of that process.  The
102 lifecycle of the originally-invoked process is tied to the lifecycle
103 of this object (ie: the process exits when the last reference is
104 dropped).
105 </p>
106 <p>
107 The main use for <a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> (and the
108 <a class="link" href="GApplication.html#GApplication-command-line" title='The "command-line" signal'><span class="type">"command-line"</span></a> signal) is 'Emacs server' like use cases:
109 You can set the <code class="envar">EDITOR</code> environment variable to have
110 e.g. git use your favourite editor to edit commit messages, and if you
111 already have an instance of the editor running, the editing will happen
112 in the running instance, instead of opening a new one. An important
113 aspect of this use case is that the process that gets started by git
114 does not return until the editing is done.
115 </p>
116 <p>
117 </p>
118 <div class="example">
119 <a name="gapplication-example-cmdline"></a><p class="title"><b>Example 17. Handling commandline arguments with GApplication</b></p>
120 <div class="example-contents">
121 <p>
122 A simple example where the commandline is completely handled
123 in the <a class="link" href="GApplication.html#GApplication-command-line" title='The "command-line" signal'><span class="type">"command-line"</span></a> handler. The launching instance exits
124 once the signal handler in the primary instance has returned, and the
125 return value of the signal handler becomes the exit status of the launching
126 instance.
127 </p>
128 <pre class="programlisting">
129 #include &lt;gio/gio.h&gt;
130 #include &lt;stdlib.h&gt;
131 #include &lt;string.h&gt;
132
133 static int
134 command_line (GApplication            *application,
135               GApplicationCommandLine *cmdline)
136 {
137   gchar **argv;
138   gint argc;
139   gint i;
140
141   argv = g_application_command_line_get_arguments (cmdline, &amp;argc);
142
143   g_application_command_line_print (cmdline,
144                                     "This text is written back\n"
145                                     "to stdout of the caller\n");
146
147   for (i = 0; i &lt; argc; i++)
148     g_print ("argument %d: %s\n", i, argv[i]);
149
150   g_strfreev (argv);
151
152   return 0;
153 }
154
155 int
156 main (int argc, char **argv)
157 {
158   GApplication *app;
159   int status;
160
161   app = g_application_new ("org.gtk.TestApplication",
162                            G_APPLICATION_HANDLES_COMMAND_LINE);
163   g_signal_connect (app, "command-line", G_CALLBACK (command_line), NULL);
164   g_application_set_inactivity_timeout (app, 10000);
165
166   status = g_application_run (app, argc, argv);
167
168   g_object_unref (app);
169
170   return status;
171 }
172
173 </pre>
174 </div>
175 </div>
176 <p><br class="example-break">
177 </p>
178 <p>
179 </p>
180 <div class="example">
181 <a name="gapplication-example-cmdline2"></a><p class="title"><b>Example 18. Split commandline handling</b></p>
182 <div class="example-contents">
183 <p>
184 An example of split commandline handling. Options that start with
185 <code class="literal">--local-</code> are handled locally, all other options are
186 passed to the <a class="link" href="GApplication.html#GApplication-command-line" title='The "command-line" signal'><span class="type">"command-line"</span></a> handler which runs in the primary
187 instance.
188 </p>
189 <pre class="programlisting">
190 #include &lt;gio/gio.h&gt;
191 #include &lt;stdlib.h&gt;
192 #include &lt;string.h&gt;
193
194 static int
195 command_line (GApplication            *application,
196               GApplicationCommandLine *cmdline)
197 {
198   gchar **argv;
199   gint argc;
200   gint i;
201
202   argv = g_application_command_line_get_arguments (cmdline, &amp;argc);
203
204   for (i = 0; i &lt; argc; i++)
205     g_print ("handling argument %s remotely\n", argv[i]);
206
207   g_strfreev (argv);
208
209   return 0;
210 }
211
212 static gboolean
213 test_local_cmdline (GApplication   *application,
214                     gchar        ***arguments,
215                     gint           *exit_status)
216 {
217   gint i, j;
218   gchar **argv;
219
220   argv = *arguments;
221
222   i = 1;
223   while (argv[i])
224     {
225       if (g_str_has_prefix (argv[i], "--local-"))
226         {
227           g_print ("handling argument %s locally\n", argv[i]);
228           g_free (argv[i]);
229           for (j = i; argv[j]; j++)
230             argv[j] = argv[j + 1];
231         }
232       else
233         {
234           g_print ("not handling argument %s locally\n", argv[i]);
235           i++;
236         }
237     }
238
239   *exit_status = 0;
240
241   return FALSE;
242 }
243
244 typedef GApplication TestApplication;
245 typedef GApplicationClass TestApplicationClass;
246
247 static GType test_application_get_type (void);
248 G_DEFINE_TYPE (TestApplication, test_application, G_TYPE_APPLICATION)
249
250 static void
251 test_application_finalize (GObject *object)
252 {
253   G_OBJECT_CLASS (test_application_parent_class)-&gt;finalize (object);
254 }
255
256 static void
257 test_application_init (TestApplication *app)
258 {
259 }
260
261 static void
262 test_application_class_init (TestApplicationClass *class)
263 {
264   G_OBJECT_CLASS (class)-&gt;finalize = test_application_finalize;
265   G_APPLICATION_CLASS (class)-&gt;local_command_line = test_local_cmdline;
266 }
267
268 static GApplication *
269 test_application_new (const gchar       *application_id,
270                       GApplicationFlags  flags)
271 {
272   g_return_val_if_fail (g_application_id_is_valid (application_id), NULL);
273
274   g_type_init ();
275
276   return g_object_new (test_application_get_type (),
277                        "application-id", application_id,
278                        "flags", flags,
279                        NULL);
280 }
281
282 int
283 main (int argc, char **argv)
284 {
285   GApplication *app;
286   int status;
287
288   app = test_application_new ("org.gtk.TestApplication", 0);
289   g_application_set_inactivity_timeout (app, 10000);
290   g_signal_connect (app, "command-line", G_CALLBACK (command_line), NULL);
291
292   status = g_application_run (app, argc, argv);
293
294   g_object_unref (app);
295
296   return status;
297 }
298
299 </pre>
300 </div>
301 </div>
302 <p><br class="example-break">
303 </p>
304 <p>
305 </p>
306 <div class="example">
307 <a name="gapplication-example-cmdline3"></a><p class="title"><b>Example 19. Deferred commandline handling</b></p>
308 <div class="example-contents">
309 <p>
310 An example of deferred commandline handling. Here, the commandline is
311 not completely handled before the <a class="link" href="GApplication.html#GApplication-command-line" title='The "command-line" signal'><span class="type">"command-line"</span></a> handler
312 returns. Instead, we keep a reference to the GApplicationCommandLine
313 object and handle it later(in this example, in an idle). Note that it
314 is necessary to hold the application until you are done with the
315 commandline.
316 </p>
317 <p>
318 This example also shows how to use <a href="./../glib/glib/glib-Commandline-option-parser.html#GOptionContext"><span class="type">GOptionContext</span></a> for parsing the
319 commandline arguments. Note that it is necessary to disable the
320 built-in help-handling of <a href="./../glib/glib/glib-Commandline-option-parser.html#GOptionContext"><span class="type">GOptionContext</span></a>, since it calls <code class="function">exit()</code>
321 after printing help, which is not what you want to happen in
322 the primary instance.
323 </p>
324 <pre class="programlisting">
325 #include &lt;gio/gio.h&gt;
326 #include &lt;stdlib.h&gt;
327 #include &lt;string.h&gt;
328
329 static gboolean
330 my_cmdline_handler (gpointer data)
331 {
332   GApplicationCommandLine *cmdline = data;
333   gchar **args;
334   gchar **argv;
335   gint argc;
336   gint arg1;
337   gboolean arg2;
338   gboolean help;
339   GOptionContext *context;
340   GOptionEntry entries[] = {
341     { "arg1", 0, 0, G_OPTION_ARG_INT, &amp;arg1, NULL, NULL },
342     { "arg2", 0, 0, G_OPTION_ARG_NONE, &amp;arg2, NULL, NULL },
343     { "help", '?', 0, G_OPTION_ARG_NONE, &amp;help, NULL, NULL },
344     { NULL }
345   };
346   GError *error;
347   gint i;
348
349   args = g_application_command_line_get_arguments (cmdline, &amp;argc);
350
351   /* We have to make an extra copy of the array, since g_option_context_parse()
352    * assumes that it can remove strings from the array without freeing them.
353    */
354   argv = g_new (gchar*, argc + 1);
355   for (i = 0; i &lt;= argc; i++)
356     argv[i] = args[i];
357
358   context = g_option_context_new (NULL);
359   g_option_context_set_help_enabled (context, FALSE);
360   g_option_context_add_main_entries (context, entries, NULL);
361
362   arg1 = 0;
363   arg2 = FALSE;
364   help = FALSE;
365   error = NULL;
366   if (!g_option_context_parse (context, &amp;argc, &amp;argv, &amp;error))
367     {
368       g_application_command_line_printerr (cmdline, "%s\n", error-&gt;message);
369       g_error_free (error);
370       g_application_command_line_set_exit_status (cmdline, 1);
371     }
372   else if (help)
373     {
374       gchar *text;
375       text = g_option_context_get_help (context, FALSE, NULL);
376       g_application_command_line_print (cmdline, "%s",  text);
377       g_free (text);
378     }
379   else
380     {
381       g_application_command_line_print (cmdline, "arg1 is %d and arg2 is %s\n",
382                                         arg1, arg2 ? "TRUE" : "FALSE");
383       g_application_command_line_set_exit_status (cmdline, 0);
384     }
385
386   g_free (argv);
387   g_strfreev (args);
388
389   g_option_context_free (context);
390
391   /* we are done handling this commandline */
392   g_object_unref (cmdline);
393
394   return G_SOURCE_REMOVE;
395 }
396
397 static int
398 command_line (GApplication            *application,
399               GApplicationCommandLine *cmdline)
400 {
401   /* keep the application running until we are done with this commandline */
402   g_application_hold (application);
403
404   g_object_set_data_full (G_OBJECT (cmdline),
405                           "application", application,
406                           (GDestroyNotify)g_application_release);
407
408   g_object_ref (cmdline);
409   g_idle_add (my_cmdline_handler, cmdline);
410
411   return 0;
412 }
413
414 int
415 main (int argc, char **argv)
416 {
417   GApplication *app;
418   int status;
419
420   app = g_application_new ("org.gtk.TestApplication",
421                            G_APPLICATION_HANDLES_COMMAND_LINE);
422   g_signal_connect (app, "command-line", G_CALLBACK (command_line), NULL);
423   g_application_set_inactivity_timeout (app, 10000);
424
425   status = g_application_run (app, argc, argv);
426
427   g_object_unref (app);
428
429   return status;
430 }
431
432 </pre>
433 </div>
434 </div>
435 <p><br class="example-break">
436 </p>
437 </div>
438 <div class="refsect1">
439 <a name="GApplicationCommandLine.details"></a><h2>Details</h2>
440 <div class="refsect2">
441 <a name="GApplicationCommandLine-struct"></a><h3>GApplicationCommandLine</h3>
442 <pre class="programlisting">typedef struct _GApplicationCommandLine GApplicationCommandLine;</pre>
443 </div>
444 <hr>
445 <div class="refsect2">
446 <a name="GApplicationCommandLineClass"></a><h3>struct GApplicationCommandLineClass</h3>
447 <pre class="programlisting">struct GApplicationCommandLineClass {
448 };
449 </pre>
450 <p>
451 The <span class="structname">GApplicationCommandLineClass</span> structure
452 contains private data only
453 </p>
454 <p class="since">Since 2.28</p>
455 </div>
456 <hr>
457 <div class="refsect2">
458 <a name="g-application-command-line-get-arguments"></a><h3>g_application_command_line_get_arguments ()</h3>
459 <pre class="programlisting"><a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="returnvalue">gchar</span></a> **            g_application_command_line_get_arguments
460                                                         (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>,
461                                                          <em class="parameter"><code><span class="type">int</span> *argc</code></em>);</pre>
462 <p>
463 Gets the list of arguments that was passed on the command line.
464 </p>
465 <p>
466 The strings in the array may contain non-utf8 data.
467 </p>
468 <p>
469 The return value is <a href="./../glib/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>-terminated and should be freed using
470 <a href="./../glib/glib/glib-String-Utility-Functions.html#g-strfreev"><code class="function">g_strfreev()</code></a>.
471 </p>
472 <div class="variablelist"><table border="0">
473 <col align="left" valign="top">
474 <tbody>
475 <tr>
476 <td><p><span class="term"><em class="parameter"><code>cmdline</code></em> :</span></p></td>
477 <td>a <a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a>
478 </td>
479 </tr>
480 <tr>
481 <td><p><span class="term"><em class="parameter"><code>argc</code></em> :</span></p></td>
482 <td>the length of the arguments array, or <a href="./../glib/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. <span class="annotation">[<acronym title="Parameter for returning results. Default is transfer full."><span class="acronym">out</span></acronym>][<acronym title="NULL is ok, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span>
483 </td>
484 </tr>
485 <tr>
486 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
487 <td>the string array
488 containing the arguments (the argv). <span class="annotation">[<acronym title="Parameter points to an array of items."><span class="acronym">array</span></acronym> length=argc][<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>]</span>
489 </td>
490 </tr>
491 </tbody>
492 </table></div>
493 <p class="since">Since 2.28</p>
494 </div>
495 <hr>
496 <div class="refsect2">
497 <a name="g-application-command-line-get-cwd"></a><h3>g_application_command_line_get_cwd ()</h3>
498 <pre class="programlisting">const <a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="returnvalue">gchar</span></a> *       g_application_command_line_get_cwd  (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>);</pre>
499 <p>
500 Gets the working directory of the command line invocation.
501 The string may contain non-utf8 data.
502 </p>
503 <p>
504 It is possible that the remote application did not send a working
505 directory, so this may be <a href="./../glib/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>.
506 </p>
507 <p>
508 The return value should not be modified or freed and is valid for as
509 long as <em class="parameter"><code>cmdline</code></em> exists.
510 </p>
511 <div class="variablelist"><table border="0">
512 <col align="left" valign="top">
513 <tbody>
514 <tr>
515 <td><p><span class="term"><em class="parameter"><code>cmdline</code></em> :</span></p></td>
516 <td>a <a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a>
517 </td>
518 </tr>
519 <tr>
520 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
521 <td>the current directory, or <a href="./../glib/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>
522 </td>
523 </tr>
524 </tbody>
525 </table></div>
526 <p class="since">Since 2.28</p>
527 </div>
528 <hr>
529 <div class="refsect2">
530 <a name="g-application-command-line-get-environ"></a><h3>g_application_command_line_get_environ ()</h3>
531 <pre class="programlisting">const <a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="returnvalue">gchar</span></a> * const * g_application_command_line_get_environ
532                                                         (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>);</pre>
533 <p>
534 Gets the contents of the 'environ' variable of the command line
535 invocation, as would be returned by <a href="./../glib/glib/glib-Miscellaneous-Utility-Functions.html#g-get-environ"><code class="function">g_get_environ()</code></a>, ie as a
536 <a href="./../glib/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>-terminated list of strings in the form 'NAME=VALUE'.
537 The strings may contain non-utf8 data.
538 </p>
539 <p>
540 The remote application usually does not send an environment.  Use
541 <a class="link" href="GApplication.html#G-APPLICATION-SEND-ENVIRONMENT:CAPS"><code class="literal">G_APPLICATION_SEND_ENVIRONMENT</code></a> to affect that.  Even with this flag
542 set it is possible that the environment is still not available (due
543 to invocation messages from other applications).
544 </p>
545 <p>
546 The return value should not be modified or freed and is valid for as
547 long as <em class="parameter"><code>cmdline</code></em> exists.
548 </p>
549 <p>
550 See <a class="link" href="GApplicationCommandLine.html#g-application-command-line-getenv" title="g_application_command_line_getenv ()"><code class="function">g_application_command_line_getenv()</code></a> if you are only interested
551 in the value of a single environment variable.
552 </p>
553 <div class="variablelist"><table border="0">
554 <col align="left" valign="top">
555 <tbody>
556 <tr>
557 <td><p><span class="term"><em class="parameter"><code>cmdline</code></em> :</span></p></td>
558 <td>a <a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a>
559 </td>
560 </tr>
561 <tr>
562 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
563 <td>the environment
564 strings, or <a href="./../glib/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> if they were not sent. <span class="annotation">[<acronym title="Parameter points to an array of items."><span class="acronym">array</span></acronym> zero-terminated=1][<acronym title="Don't free data after the code is done."><span class="acronym">transfer none</span></acronym>]</span>
565 </td>
566 </tr>
567 </tbody>
568 </table></div>
569 <p class="since">Since 2.28</p>
570 </div>
571 <hr>
572 <div class="refsect2">
573 <a name="g-application-command-line-getenv"></a><h3>g_application_command_line_getenv ()</h3>
574 <pre class="programlisting">const <a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="returnvalue">gchar</span></a> *       g_application_command_line_getenv   (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>,
575                                                          <em class="parameter"><code>const <a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *name</code></em>);</pre>
576 <p>
577 Gets the value of a particular environment variable of the command
578 line invocation, as would be returned by <a href="./../glib/glib/glib-Miscellaneous-Utility-Functions.html#g-getenv"><code class="function">g_getenv()</code></a>.  The strings may
579 contain non-utf8 data.
580 </p>
581 <p>
582 The remote application usually does not send an environment.  Use
583 <a class="link" href="GApplication.html#G-APPLICATION-SEND-ENVIRONMENT:CAPS"><code class="literal">G_APPLICATION_SEND_ENVIRONMENT</code></a> to affect that.  Even with this flag
584 set it is possible that the environment is still not available (due
585 to invocation messages from other applications).
586 </p>
587 <p>
588 The return value should not be modified or freed and is valid for as
589 long as <em class="parameter"><code>cmdline</code></em> exists.
590 </p>
591 <div class="variablelist"><table border="0">
592 <col align="left" valign="top">
593 <tbody>
594 <tr>
595 <td><p><span class="term"><em class="parameter"><code>cmdline</code></em> :</span></p></td>
596 <td>a <a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a>
597 </td>
598 </tr>
599 <tr>
600 <td><p><span class="term"><em class="parameter"><code>name</code></em> :</span></p></td>
601 <td>the environment variable to get</td>
602 </tr>
603 <tr>
604 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
605 <td>the value of the variable, or <a href="./../glib/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> if unset or unsent</td>
606 </tr>
607 </tbody>
608 </table></div>
609 <p class="since">Since 2.28</p>
610 </div>
611 <hr>
612 <div class="refsect2">
613 <a name="g-application-command-line-get-is-remote"></a><h3>g_application_command_line_get_is_remote ()</h3>
614 <pre class="programlisting"><a href="./../glib/glib/glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>            g_application_command_line_get_is_remote
615                                                         (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>);</pre>
616 <p>
617 Determines if <em class="parameter"><code>cmdline</code></em> represents a remote invocation.
618 </p>
619 <div class="variablelist"><table border="0">
620 <col align="left" valign="top">
621 <tbody>
622 <tr>
623 <td><p><span class="term"><em class="parameter"><code>cmdline</code></em> :</span></p></td>
624 <td>a <a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a>
625 </td>
626 </tr>
627 <tr>
628 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
629 <td>
630 <a href="./../glib/glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if the invocation was remote</td>
631 </tr>
632 </tbody>
633 </table></div>
634 <p class="since">Since 2.28</p>
635 </div>
636 <hr>
637 <div class="refsect2">
638 <a name="g-application-command-line-get-platform-data"></a><h3>g_application_command_line_get_platform_data ()</h3>
639 <pre class="programlisting"><a href="./../glib/glib/glib-GVariant.html#GVariant"><span class="returnvalue">GVariant</span></a> *          g_application_command_line_get_platform_data
640                                                         (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>);</pre>
641 <p>
642 Gets the platform data associated with the invocation of <em class="parameter"><code>cmdline</code></em>.
643 </p>
644 <p>
645 This is a <a href="./../glib/glib/glib-GVariant.html#GVariant"><span class="type">GVariant</span></a> dictionary containing information about the
646 context in which the invocation occurred.  It typically contains
647 information like the current working directory and the startup
648 notification ID.
649 </p>
650 <p>
651 For local invocation, it will be <a href="./../glib/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>.
652 </p>
653 <div class="variablelist"><table border="0">
654 <col align="left" valign="top">
655 <tbody>
656 <tr>
657 <td><p><span class="term"><em class="parameter"><code>cmdline</code></em> :</span></p></td>
658 <td><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a></td>
659 </tr>
660 <tr>
661 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
662 <td>the platform data, or <a href="./../glib/glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. <span class="annotation">[<acronym title="NULL is ok, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span>
663 </td>
664 </tr>
665 </tbody>
666 </table></div>
667 <p class="since">Since 2.28</p>
668 </div>
669 <hr>
670 <div class="refsect2">
671 <a name="g-application-command-line-set-exit-status"></a><h3>g_application_command_line_set_exit_status ()</h3>
672 <pre class="programlisting"><span class="returnvalue">void</span>                g_application_command_line_set_exit_status
673                                                         (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>,
674                                                          <em class="parameter"><code><span class="type">int</span> exit_status</code></em>);</pre>
675 <p>
676 Sets the exit status that will be used when the invoking process
677 exits.
678 </p>
679 <p>
680 The return value of the <a class="link" href="GApplication.html#GApplication-command-line" title='The "command-line" signal'><span class="type">"command-line"</span></a> signal is
681 passed to this function when the handler returns.  This is the usual
682 way of setting the exit status.
683 </p>
684 <p>
685 In the event that you want the remote invocation to continue running
686 and want to decide on the exit status in the future, you can use this
687 call.  For the case of a remote invocation, the remote process will
688 typically exit when the last reference is dropped on <em class="parameter"><code>cmdline</code></em>.  The
689 exit status of the remote process will be equal to the last value
690 that was set with this function.
691 </p>
692 <p>
693 In the case that the commandline invocation is local, the situation
694 is slightly more complicated.  If the commandline invocation results
695 in the mainloop running (ie: because the use-count of the application
696 increased to a non-zero value) then the application is considered to
697 have been 'successful' in a certain sense, and the exit status is
698 always zero.  If the application use count is zero, though, the exit
699 status of the local <a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> is used.
700 </p>
701 <div class="variablelist"><table border="0">
702 <col align="left" valign="top">
703 <tbody>
704 <tr>
705 <td><p><span class="term"><em class="parameter"><code>cmdline</code></em> :</span></p></td>
706 <td>a <a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a>
707 </td>
708 </tr>
709 <tr>
710 <td><p><span class="term"><em class="parameter"><code>exit_status</code></em> :</span></p></td>
711 <td>the exit status</td>
712 </tr>
713 </tbody>
714 </table></div>
715 <p class="since">Since 2.28</p>
716 </div>
717 <hr>
718 <div class="refsect2">
719 <a name="g-application-command-line-get-exit-status"></a><h3>g_application_command_line_get_exit_status ()</h3>
720 <pre class="programlisting"><span class="returnvalue">int</span>                 g_application_command_line_get_exit_status
721                                                         (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>);</pre>
722 <p>
723 Gets the exit status of <em class="parameter"><code>cmdline</code></em>.  See
724 <a class="link" href="GApplicationCommandLine.html#g-application-command-line-set-exit-status" title="g_application_command_line_set_exit_status ()"><code class="function">g_application_command_line_set_exit_status()</code></a> for more information.
725 </p>
726 <div class="variablelist"><table border="0">
727 <col align="left" valign="top">
728 <tbody>
729 <tr>
730 <td><p><span class="term"><em class="parameter"><code>cmdline</code></em> :</span></p></td>
731 <td>a <a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a>
732 </td>
733 </tr>
734 <tr>
735 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
736 <td>the exit status</td>
737 </tr>
738 </tbody>
739 </table></div>
740 <p class="since">Since 2.28</p>
741 </div>
742 <hr>
743 <div class="refsect2">
744 <a name="g-application-command-line-print"></a><h3>g_application_command_line_print ()</h3>
745 <pre class="programlisting"><span class="returnvalue">void</span>                g_application_command_line_print    (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>,
746                                                          <em class="parameter"><code>const <a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *format</code></em>,
747                                                          <em class="parameter"><code>...</code></em>);</pre>
748 <p>
749 Formats a message and prints it using the stdout print handler in the
750 invoking process.
751 </p>
752 <p>
753 If <em class="parameter"><code>cmdline</code></em> is a local invocation then this is exactly equivalent to
754 <a href="./../glib/glib/glib-Warnings-and-Assertions.html#g-print"><code class="function">g_print()</code></a>.  If <em class="parameter"><code>cmdline</code></em> is remote then this is equivalent to calling
755 <a href="./../glib/glib/glib-Warnings-and-Assertions.html#g-print"><code class="function">g_print()</code></a> in the invoking process.
756 </p>
757 <div class="variablelist"><table border="0">
758 <col align="left" valign="top">
759 <tbody>
760 <tr>
761 <td><p><span class="term"><em class="parameter"><code>cmdline</code></em> :</span></p></td>
762 <td>a <a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a>
763 </td>
764 </tr>
765 <tr>
766 <td><p><span class="term"><em class="parameter"><code>format</code></em> :</span></p></td>
767 <td>a printf-style format string</td>
768 </tr>
769 <tr>
770 <td><p><span class="term"><em class="parameter"><code>...</code></em> :</span></p></td>
771 <td>arguments, as per <em class="parameter"><code>format</code></em>
772 </td>
773 </tr>
774 </tbody>
775 </table></div>
776 <p class="since">Since 2.28</p>
777 </div>
778 <hr>
779 <div class="refsect2">
780 <a name="g-application-command-line-printerr"></a><h3>g_application_command_line_printerr ()</h3>
781 <pre class="programlisting"><span class="returnvalue">void</span>                g_application_command_line_printerr (<em class="parameter"><code><a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a> *cmdline</code></em>,
782                                                          <em class="parameter"><code>const <a href="./../glib/glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *format</code></em>,
783                                                          <em class="parameter"><code>...</code></em>);</pre>
784 <p>
785 Formats a message and prints it using the stderr print handler in the
786 invoking process.
787 </p>
788 <p>
789 If <em class="parameter"><code>cmdline</code></em> is a local invocation then this is exactly equivalent to
790 <a href="./../glib/glib/glib-Warnings-and-Assertions.html#g-printerr"><code class="function">g_printerr()</code></a>.  If <em class="parameter"><code>cmdline</code></em> is remote then this is equivalent to
791 calling <a href="./../glib/glib/glib-Warnings-and-Assertions.html#g-printerr"><code class="function">g_printerr()</code></a> in the invoking process.
792 </p>
793 <div class="variablelist"><table border="0">
794 <col align="left" valign="top">
795 <tbody>
796 <tr>
797 <td><p><span class="term"><em class="parameter"><code>cmdline</code></em> :</span></p></td>
798 <td>a <a class="link" href="GApplicationCommandLine.html" title="GApplicationCommandLine"><span class="type">GApplicationCommandLine</span></a>
799 </td>
800 </tr>
801 <tr>
802 <td><p><span class="term"><em class="parameter"><code>format</code></em> :</span></p></td>
803 <td>a printf-style format string</td>
804 </tr>
805 <tr>
806 <td><p><span class="term"><em class="parameter"><code>...</code></em> :</span></p></td>
807 <td>arguments, as per <em class="parameter"><code>format</code></em>
808 </td>
809 </tr>
810 </tbody>
811 </table></div>
812 <p class="since">Since 2.28</p>
813 </div>
814 </div>
815 <div class="refsect1">
816 <a name="GApplicationCommandLine.see-also"></a><h2>See Also</h2>
817 <a class="link" href="GApplication.html" title="GApplication"><span class="type">GApplication</span></a>
818 </div>
819 </div>
820 <div class="footer">
821 <hr>
822           Generated by GTK-Doc V1.18</div>
823 </body>
824 </html>