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  * structWrap:
49  * 	- GVariant* -> Variant
50  * module aliases:
51  * local aliases:
52  * overrides:
53  */
54 
55 module gio.ApplicationCommandLine;
56 
57 public  import gtkc.giotypes;
58 
59 private import gtkc.gio;
60 private import glib.ConstructionException;
61 private import gobject.ObjectG;
62 
63 
64 private import glib.Str;
65 private import glib.Variant;
66 
67 
68 
69 private import gobject.ObjectG;
70 
71 /**
72  * Description
73  * GApplicationCommandLine represents a command-line invocation of
74  * an application. It is created by GApplication and emitted
75  * in the "command-line" signal and virtual function.
76  * The class contains the list of arguments that the program was invoked
77  * with. It is also possible to query if the commandline invocation was
78  * local (ie: the current process is running in direct response to the
79  * invocation) or remote (ie: some other process forwarded the
80  * commandline to this process).
81  * The GApplicationCommandLine object can provide the argc and argv
82  * parameters for use with the GOptionContext command-line parsing API,
83  * with the g_application_command_line_get_arguments() function. See
84  *  Example 17, “Deferred commandline handling” for an example.
85  * The exit status of the originally-invoked process may be set and
86  * messages can be printed to stdout or stderr of that process. The
87  * lifecycle of the originally-invoked process is tied to the lifecycle
88  * of this object (ie: the process exits when the last reference is
89  * dropped).
90  * The main use for GApplicationCommandline (and the
91  * "command-line" signal) is 'Emacs server' like use cases:
92  * You can set the EDITOR environment variable to have
93  * e.g. git use your favourite editor to edit commit messages, and if you
94  * already have an instance of the editor running, the editing will happen
95  * in the running instance, instead of opening a new one. An important
96  * aspect of this use case is that the process that gets started by git
97  * does not return until the editing is done.
98  * $(DDOC_COMMENT example)
99  * $(DDOC_COMMENT example)
100  * $(DDOC_COMMENT example)
101  */
102 public class ApplicationCommandLine : ObjectG
103 {
104 	
105 	/** the main Gtk struct */
106 	protected GApplicationCommandLine* gApplicationCommandLine;
107 	
108 	
109 	public GApplicationCommandLine* getApplicationCommandLineStruct()
110 	{
111 		return gApplicationCommandLine;
112 	}
113 	
114 	
115 	/** the main Gtk struct as a void* */
116 	protected override void* getStruct()
117 	{
118 		return cast(void*)gApplicationCommandLine;
119 	}
120 	
121 	/**
122 	 * Sets our main struct and passes it to the parent class
123 	 */
124 	public this (GApplicationCommandLine* gApplicationCommandLine)
125 	{
126 		super(cast(GObject*)gApplicationCommandLine);
127 		this.gApplicationCommandLine = gApplicationCommandLine;
128 	}
129 	
130 	protected override void setStruct(GObject* obj)
131 	{
132 		super.setStruct(obj);
133 		gApplicationCommandLine = cast(GApplicationCommandLine*)obj;
134 	}
135 	
136 	/**
137 	 */
138 	
139 	/**
140 	 * Gets the list of arguments that was passed on the command line.
141 	 * The strings in the array may contain non-utf8 data.
142 	 * The return value is NULL-terminated and should be freed using
143 	 * g_strfreev().
144 	 * Since 2.28
145 	 * Returns: the string array containing the arguments (the argv). [array length=argc][transfer full]
146 	 */
147 	public string[] getArguments()
148 	{
149 		// gchar ** g_application_command_line_get_arguments  (GApplicationCommandLine *cmdline,  int *argc);
150 		int argc;
151 		auto p = g_application_command_line_get_arguments(gApplicationCommandLine, &argc);
152 		
153 		string[] strArray = null;
154 		foreach ( cstr; p[0 .. argc] )
155 		{
156 			strArray ~= Str.toString(cstr);
157 		}
158 		
159 		return strArray;
160 	}
161 	
162 	/**
163 	 * Gets the working directory of the command line invocation.
164 	 * The string may contain non-utf8 data.
165 	 * It is possible that the remote application did not send a working
166 	 * directory, so this may be NULL.
167 	 * The return value should not be modified or freed and is valid for as
168 	 * long as cmdline exists.
169 	 * Since 2.28
170 	 * Returns: the current directory, or NULL
171 	 */
172 	public string getCwd()
173 	{
174 		// const gchar * g_application_command_line_get_cwd  (GApplicationCommandLine *cmdline);
175 		return Str.toString(g_application_command_line_get_cwd(gApplicationCommandLine));
176 	}
177 	
178 	/**
179 	 * Gets the contents of the 'environ' variable of the command line
180 	 * invocation, as would be returned by g_get_environ(), ie as a
181 	 * NULL-terminated list of strings in the form 'NAME=VALUE'.
182 	 * The strings may contain non-utf8 data.
183 	 * The remote application usually does not send an environment. Use
184 	 * G_APPLICATION_SEND_ENVIRONMENT to affect that. Even with this flag
185 	 * set it is possible that the environment is still not available (due
186 	 * to invocation messages from other applications).
187 	 * The return value should not be modified or freed and is valid for as
188 	 * long as cmdline exists.
189 	 * See g_application_command_line_getenv() if you are only interested
190 	 * in the value of a single environment variable.
191 	 * Since 2.28
192 	 * Returns: the environment strings, or NULL if they were not sent. [array zero-terminated=1][transfer none]
193 	 */
194 	public string[] getEnviron()
195 	{
196 		// const gchar * const * g_application_command_line_get_environ  (GApplicationCommandLine *cmdline);
197 		return Str.toStringArray(g_application_command_line_get_environ(gApplicationCommandLine));
198 	}
199 	
200 	/**
201 	 * Gets the value of a particular environment variable of the command
202 	 * line invocation, as would be returned by g_getenv(). The strings may
203 	 * contain non-utf8 data.
204 	 * The remote application usually does not send an environment. Use
205 	 * G_APPLICATION_SEND_ENVIRONMENT to affect that. Even with this flag
206 	 * set it is possible that the environment is still not available (due
207 	 * to invocation messages from other applications).
208 	 * The return value should not be modified or freed and is valid for as
209 	 * long as cmdline exists.
210 	 * Since 2.28
211 	 * Params:
212 	 * name = the environment variable to get
213 	 * Returns: the value of the variable, or NULL if unset or unsent
214 	 */
215 	public string getenv(string name)
216 	{
217 		// const gchar * g_application_command_line_getenv  (GApplicationCommandLine *cmdline,  const gchar *name);
218 		return Str.toString(g_application_command_line_getenv(gApplicationCommandLine, Str.toStringz(name)));
219 	}
220 	
221 	/**
222 	 * Determines if cmdline represents a remote invocation.
223 	 * Since 2.28
224 	 * Returns: TRUE if the invocation was remote
225 	 */
226 	public int getIsRemote()
227 	{
228 		// gboolean g_application_command_line_get_is_remote  (GApplicationCommandLine *cmdline);
229 		return g_application_command_line_get_is_remote(gApplicationCommandLine);
230 	}
231 	
232 	/**
233 	 * Gets the platform data associated with the invocation of cmdline.
234 	 * This is a GVariant dictionary containing information about the
235 	 * context in which the invocation occured. It typically contains
236 	 * information like the current working directory and the startup
237 	 * notification ID.
238 	 * For local invocation, it will be NULL.
239 	 * Since 2.28
240 	 * Returns: the platform data, or NULL
241 	 */
242 	public Variant getPlatformData()
243 	{
244 		// GVariant * g_application_command_line_get_platform_data  (GApplicationCommandLine *cmdline);
245 		auto p = g_application_command_line_get_platform_data(gApplicationCommandLine);
246 		
247 		if(p is null)
248 		{
249 			return null;
250 		}
251 		
252 		return ObjectG.getDObject!(Variant)(cast(GVariant*) p);
253 	}
254 	
255 	/**
256 	 * Sets the exit status that will be used when the invoking process
257 	 * exits.
258 	 * The return value of the "command-line" signal is
259 	 * passed to this function when the handler returns. This is the usual
260 	 * way of setting the exit status.
261 	 * In the event that you want the remote invocation to continue running
262 	 * and want to decide on the exit status in the future, you can use this
263 	 * call. For the case of a remote invocation, the remote process will
264 	 * typically exit when the last reference is dropped on cmdline. The
265 	 * exit status of the remote process will be equal to the last value
266 	 * that was set with this function.
267 	 * In the case that the commandline invocation is local, the situation
268 	 * is slightly more complicated. If the commandline invocation results
269 	 * in the mainloop running (ie: because the use-count of the application
270 	 * increased to a non-zero value) then the application is considered to
271 	 * have been 'successful' in a certain sense, and the exit status is
272 	 * always zero. If the application use count is zero, though, the exit
273 	 * status of the local GApplicationCommandLine is used.
274 	 * Since 2.28
275 	 * Params:
276 	 * exitStatus = the exit status
277 	 */
278 	public void setExitStatus(int exitStatus)
279 	{
280 		// void g_application_command_line_set_exit_status  (GApplicationCommandLine *cmdline,  int exit_status);
281 		g_application_command_line_set_exit_status(gApplicationCommandLine, exitStatus);
282 	}
283 	
284 	/**
285 	 * Gets the exit status of cmdline. See
286 	 * g_application_command_line_set_exit_status() for more information.
287 	 * Since 2.28
288 	 * Returns: the exit status
289 	 */
290 	public int getExitStatus()
291 	{
292 		// int g_application_command_line_get_exit_status  (GApplicationCommandLine *cmdline);
293 		return g_application_command_line_get_exit_status(gApplicationCommandLine);
294 	}
295 }