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