1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = GApplicationCommandLine.html
27  * outPack = gio
28  * outFile = ApplicationCommandLine
29  * strct   = GApplicationCommandLine
30  * realStrct=
31  * ctorStrct=
32  * clss    = ApplicationCommandLine
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_application_command_line_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- glib.Variant
48  * 	- gio.File
49  * 	- gio.InputStream
50  * structWrap:
51  * 	- GFile* -> File
52  * 	- GInputStream* -> InputStream
53  * 	- GVariant* -> Variant
54  * module aliases:
55  * local aliases:
56  * overrides:
57  */
58 
59 module gio.ApplicationCommandLine;
60 
61 public  import gtkc.giotypes;
62 
63 private import gtkc.gio;
64 private import glib.ConstructionException;
65 private import gobject.ObjectG;
66 
67 
68 private import glib.Str;
69 private import glib.Variant;
70 private import gio.File;
71 private import gio.InputStream;
72 
73 
74 
75 private import gobject.ObjectG;
76 
77 /**
78  * GApplicationCommandLine represents a command-line invocation of
79  * an application. It is created by GApplication and emitted
80  * in the "command-line" signal and virtual function.
81  *
82  * The class contains the list of arguments that the program was invoked
83  * with. It is also possible to query if the commandline invocation was
84  * local (ie: the current process is running in direct response to the
85  * invocation) or remote (ie: some other process forwarded the
86  * commandline to this process).
87  *
88  * The GApplicationCommandLine object can provide the argc and argv
89  * parameters for use with the GOptionContext command-line parsing API,
90  * with the g_application_command_line_get_arguments() function. See
91  *  Example 24, “Deferred commandline handling” for an example.
92  *
93  * The exit status of the originally-invoked process may be set and
94  * messages can be printed to stdout or stderr of that process. The
95  * lifecycle of the originally-invoked process is tied to the lifecycle
96  * of this object (ie: the process exits when the last reference is
97  * dropped).
98  *
99  * The main use for GApplicationCommandLine (and the
100  * "command-line" signal) is 'Emacs server' like use cases:
101  * You can set the EDITOR environment variable to have
102  * e.g. git use your favourite editor to edit commit messages, and if you
103  * already have an instance of the editor running, the editing will happen
104  * in the running instance, instead of opening a new one. An important
105  * aspect of this use case is that the process that gets started by git
106  * does not return until the editing is done.
107  *
108  * $(DDOC_COMMENT example)
109  *
110  * $(DDOC_COMMENT example)
111  *
112  * $(DDOC_COMMENT example)
113  */
114 public class ApplicationCommandLine : ObjectG
115 {
116 	
117 	/** the main Gtk struct */
118 	protected GApplicationCommandLine* gApplicationCommandLine;
119 	
120 	
121 	public GApplicationCommandLine* getApplicationCommandLineStruct()
122 	{
123 		return gApplicationCommandLine;
124 	}
125 	
126 	
127 	/** the main Gtk struct as a void* */
128 	protected override void* getStruct()
129 	{
130 		return cast(void*)gApplicationCommandLine;
131 	}
132 	
133 	/**
134 	 * Sets our main struct and passes it to the parent class
135 	 */
136 	public this (GApplicationCommandLine* gApplicationCommandLine)
137 	{
138 		super(cast(GObject*)gApplicationCommandLine);
139 		this.gApplicationCommandLine = gApplicationCommandLine;
140 	}
141 	
142 	protected override void setStruct(GObject* obj)
143 	{
144 		super.setStruct(obj);
145 		gApplicationCommandLine = cast(GApplicationCommandLine*)obj;
146 	}
147 	
148 	/**
149 	 */
150 	
151 	/**
152 	 * Gets the list of arguments that was passed on the command line.
153 	 * The strings in the array may contain non-utf8 data.
154 	 * The return value is NULL-terminated and should be freed using
155 	 * g_strfreev().
156 	 * Since 2.28
157 	 * Returns: the string array containing the arguments (the argv). [array length=argc][transfer full]
158 	 */
159 	public string[] getArguments()
160 	{
161 		// gchar ** g_application_command_line_get_arguments  (GApplicationCommandLine *cmdline,  int *argc);
162 		int argc;
163 		auto p = g_application_command_line_get_arguments(gApplicationCommandLine, &argc);
164 		
165 		string[] strArray = null;
166 		foreach ( cstr; p[0 .. argc] )
167 		{
168 			strArray ~= Str.toString(cstr);
169 		}
170 		
171 		return strArray;
172 	}
173 	
174 	/**
175 	 * Gets the working directory of the command line invocation.
176 	 * The string may contain non-utf8 data.
177 	 * It is possible that the remote application did not send a working
178 	 * directory, so this may be NULL.
179 	 * The return value should not be modified or freed and is valid for as
180 	 * long as cmdline exists.
181 	 * Since 2.28
182 	 * Returns: the current directory, or NULL
183 	 */
184 	public string getCwd()
185 	{
186 		// const gchar * g_application_command_line_get_cwd (GApplicationCommandLine *cmdline);
187 		return Str.toString(g_application_command_line_get_cwd(gApplicationCommandLine));
188 	}
189 	
190 	/**
191 	 * Gets the contents of the 'environ' variable of the command line
192 	 * invocation, as would be returned by g_get_environ(), ie as a
193 	 * NULL-terminated list of strings in the form 'NAME=VALUE'.
194 	 * The strings may contain non-utf8 data.
195 	 * The remote application usually does not send an environment. Use
196 	 * G_APPLICATION_SEND_ENVIRONMENT to affect that. Even with this flag
197 	 * set it is possible that the environment is still not available (due
198 	 * to invocation messages from other applications).
199 	 * The return value should not be modified or freed and is valid for as
200 	 * long as cmdline exists.
201 	 * See g_application_command_line_getenv() if you are only interested
202 	 * in the value of a single environment variable.
203 	 * Since 2.28
204 	 * Returns: the environment strings, or NULL if they were not sent. [array zero-terminated=1][transfer none]
205 	 */
206 	public string[] getEnviron()
207 	{
208 		// const gchar * const * g_application_command_line_get_environ  (GApplicationCommandLine *cmdline);
209 		return Str.toStringArray(g_application_command_line_get_environ(gApplicationCommandLine));
210 	}
211 	
212 	/**
213 	 * Gets the stdin of the invoking process.
214 	 * The GInputStream can be used to read data passed to the standard
215 	 * input of the invoking process.
216 	 * This doesn't work on all platforms. Presently, it is only available
217 	 * on UNIX when using a DBus daemon capable of passing file descriptors.
218 	 * If stdin is not available then NULL will be returned. In the
219 	 * future, support may be expanded to other platforms.
220 	 * You must only call this function once per commandline invocation.
221 	 * Since 2.34
222 	 * Returns: a GInputStream for stdin. [transfer full]
223 	 */
224 	public InputStream getStdin()
225 	{
226 		// GInputStream * g_application_command_line_get_stdin  (GApplicationCommandLine *cmdline);
227 		auto p = g_application_command_line_get_stdin(gApplicationCommandLine);
228 		
229 		if(p is null)
230 		{
231 			return null;
232 		}
233 		
234 		return ObjectG.getDObject!(InputStream)(cast(GInputStream*) p);
235 	}
236 	
237 	/**
238 	 * Creates a GFile corresponding to a filename that was given as part
239 	 * of the invocation of cmdline.
240 	 * This differs from g_file_new_for_commandline_arg() in that it
241 	 * resolves relative pathnames using the current working directory of
242 	 * the invoking process rather than the local process.
243 	 * Since 2.36
244 	 * Params:
245 	 * arg = an argument from cmdline
246 	 * Returns: a new GFile. [transfer full]
247 	 */
248 	public File createFileForArg(string arg)
249 	{
250 		// GFile * g_application_command_line_create_file_for_arg  (GApplicationCommandLine *cmdline,  const gchar *arg);
251 		auto p = g_application_command_line_create_file_for_arg(gApplicationCommandLine, Str.toStringz(arg));
252 		
253 		if(p is null)
254 		{
255 			return null;
256 		}
257 		
258 		return ObjectG.getDObject!(File)(cast(GFile*) p);
259 	}
260 	
261 	/**
262 	 * Gets the value of a particular environment variable of the command
263 	 * line invocation, as would be returned by g_getenv(). The strings may
264 	 * contain non-utf8 data.
265 	 * The remote application usually does not send an environment. Use
266 	 * G_APPLICATION_SEND_ENVIRONMENT to affect that. Even with this flag
267 	 * set it is possible that the environment is still not available (due
268 	 * to invocation messages from other applications).
269 	 * The return value should not be modified or freed and is valid for as
270 	 * long as cmdline exists.
271 	 * Since 2.28
272 	 * Params:
273 	 * name = the environment variable to get
274 	 * Returns: the value of the variable, or NULL if unset or unsent
275 	 */
276 	public string getenv(string name)
277 	{
278 		// const gchar * g_application_command_line_getenv (GApplicationCommandLine *cmdline,  const gchar *name);
279 		return Str.toString(g_application_command_line_getenv(gApplicationCommandLine, Str.toStringz(name)));
280 	}
281 	
282 	/**
283 	 * Determines if cmdline represents a remote invocation.
284 	 * Since 2.28
285 	 * Returns: TRUE if the invocation was remote
286 	 */
287 	public int getIsRemote()
288 	{
289 		// gboolean g_application_command_line_get_is_remote  (GApplicationCommandLine *cmdline);
290 		return g_application_command_line_get_is_remote(gApplicationCommandLine);
291 	}
292 	
293 	/**
294 	 * Gets the platform data associated with the invocation of cmdline.
295 	 * This is a GVariant dictionary containing information about the
296 	 * context in which the invocation occurred. It typically contains
297 	 * information like the current working directory and the startup
298 	 * notification ID.
299 	 * For local invocation, it will be NULL.
300 	 * Since 2.28
301 	 * Returns: the platform data, or NULL. [allow-none]
302 	 */
303 	public Variant getPlatformData()
304 	{
305 		// GVariant * g_application_command_line_get_platform_data  (GApplicationCommandLine *cmdline);
306 		auto p = g_application_command_line_get_platform_data(gApplicationCommandLine);
307 		
308 		if(p is null)
309 		{
310 			return null;
311 		}
312 		
313 		return ObjectG.getDObject!(Variant)(cast(GVariant*) p);
314 	}
315 	
316 	/**
317 	 * Sets the exit status that will be used when the invoking process
318 	 * exits.
319 	 * The return value of the "command-line" signal is
320 	 * passed to this function when the handler returns. This is the usual
321 	 * way of setting the exit status.
322 	 * In the event that you want the remote invocation to continue running
323 	 * and want to decide on the exit status in the future, you can use this
324 	 * call. For the case of a remote invocation, the remote process will
325 	 * typically exit when the last reference is dropped on cmdline. The
326 	 * exit status of the remote process will be equal to the last value
327 	 * that was set with this function.
328 	 * In the case that the commandline invocation is local, the situation
329 	 * is slightly more complicated. If the commandline invocation results
330 	 * in the mainloop running (ie: because the use-count of the application
331 	 * increased to a non-zero value) then the application is considered to
332 	 * have been 'successful' in a certain sense, and the exit status is
333 	 * always zero. If the application use count is zero, though, the exit
334 	 * status of the local GApplicationCommandLine is used.
335 	 * Since 2.28
336 	 * Params:
337 	 * exitStatus = the exit status
338 	 */
339 	public void setExitStatus(int exitStatus)
340 	{
341 		// void g_application_command_line_set_exit_status  (GApplicationCommandLine *cmdline,  int exit_status);
342 		g_application_command_line_set_exit_status(gApplicationCommandLine, exitStatus);
343 	}
344 	
345 	/**
346 	 * Gets the exit status of cmdline. See
347 	 * g_application_command_line_set_exit_status() for more information.
348 	 * Since 2.28
349 	 * Returns: the exit status
350 	 */
351 	public int getExitStatus()
352 	{
353 		// int g_application_command_line_get_exit_status  (GApplicationCommandLine *cmdline);
354 		return g_application_command_line_get_exit_status(gApplicationCommandLine);
355 	}
356 }