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 module gio.AppInfoT; 26 27 public import gio.AppInfoIF; 28 public import gio.AppLaunchContext; 29 public import gio.AsyncResultIF; 30 public import gio.Cancellable; 31 public import gio.FileIF; 32 public import gio.IconIF; 33 public import gio.c.functions; 34 public import gio.c.types; 35 public import glib.ErrorG; 36 public import glib.GException; 37 public import glib.ListG; 38 public import glib.Str; 39 public import gobject.ObjectG; 40 public import gtkc.giotypes; 41 42 43 /** 44 * #GAppInfo and #GAppLaunchContext are used for describing and launching 45 * applications installed on the system. 46 * 47 * As of GLib 2.20, URIs will always be converted to POSIX paths 48 * (using g_file_get_path()) when using g_app_info_launch() even if 49 * the application requested an URI and not a POSIX path. For example 50 * for an desktop-file based application with Exec key `totem 51 * %U` and a single URI, `sftp://foo/file.avi`, then 52 * `/home/user/.gvfs/sftp on foo/file.avi` will be passed. This will 53 * only work if a set of suitable GIO extensions (such as gvfs 2.26 54 * compiled with FUSE support), is available and operational; if this 55 * is not the case, the URI will be passed unmodified to the application. 56 * Some URIs, such as `mailto:`, of course cannot be mapped to a POSIX 57 * path (in gvfs there's no FUSE mount for it); such URIs will be 58 * passed unmodified to the application. 59 * 60 * Specifically for gvfs 2.26 and later, the POSIX URI will be mapped 61 * back to the GIO URI in the #GFile constructors (since gvfs 62 * implements the #GVfs extension point). As such, if the application 63 * needs to examine the URI, it needs to use g_file_get_uri() or 64 * similar on #GFile. In other words, an application cannot assume 65 * that the URI passed to e.g. g_file_new_for_commandline_arg() is 66 * equal to the result of g_file_get_uri(). The following snippet 67 * illustrates this: 68 * 69 * |[ 70 * GFile *f; 71 * char *uri; 72 * 73 * file = g_file_new_for_commandline_arg (uri_from_commandline); 74 * 75 * uri = g_file_get_uri (file); 76 * strcmp (uri, uri_from_commandline) == 0; 77 * g_free (uri); 78 * 79 * if (g_file_has_uri_scheme (file, "cdda")) 80 * { 81 * // do something special with uri 82 * } 83 * g_object_unref (file); 84 * ]| 85 * 86 * This code will work when both `cdda://sr0/Track 1.wav` and 87 * `/home/user/.gvfs/cdda on sr0/Track 1.wav` is passed to the 88 * application. It should be noted that it's generally not safe 89 * for applications to rely on the format of a particular URIs. 90 * Different launcher applications (e.g. file managers) may have 91 * different ideas of what a given URI means. 92 */ 93 public template AppInfoT(TStruct) 94 { 95 /** Get the main Gtk struct */ 96 public GAppInfo* getAppInfoStruct(bool transferOwnership = false) 97 { 98 if (transferOwnership) 99 ownedRef = false; 100 return cast(GAppInfo*)getStruct(); 101 } 102 103 104 /** 105 * Adds a content type to the application information to indicate the 106 * application is capable of opening files with the given content type. 107 * 108 * Params: 109 * contentType = a string. 110 * 111 * Returns: %TRUE on success, %FALSE on error. 112 * 113 * Throws: GException on failure. 114 */ 115 public bool addSupportsType(string contentType) 116 { 117 GError* err = null; 118 119 auto p = g_app_info_add_supports_type(getAppInfoStruct(), Str.toStringz(contentType), &err) != 0; 120 121 if (err !is null) 122 { 123 throw new GException( new ErrorG(err) ); 124 } 125 126 return p; 127 } 128 129 /** 130 * Obtains the information whether the #GAppInfo can be deleted. 131 * See g_app_info_delete(). 132 * 133 * Returns: %TRUE if @appinfo can be deleted 134 * 135 * Since: 2.20 136 */ 137 public bool canDelete() 138 { 139 return g_app_info_can_delete(getAppInfoStruct()) != 0; 140 } 141 142 /** 143 * Checks if a supported content type can be removed from an application. 144 * 145 * Returns: %TRUE if it is possible to remove supported 146 * content types from a given @appinfo, %FALSE if not. 147 */ 148 public bool canRemoveSupportsType() 149 { 150 return g_app_info_can_remove_supports_type(getAppInfoStruct()) != 0; 151 } 152 153 alias delet = delete_; 154 /** 155 * Tries to delete a #GAppInfo. 156 * 157 * On some platforms, there may be a difference between user-defined 158 * #GAppInfos which can be deleted, and system-wide ones which cannot. 159 * See g_app_info_can_delete(). 160 * 161 * Returns: %TRUE if @appinfo has been deleted 162 * 163 * Since: 2.20 164 */ 165 public bool delete_() 166 { 167 return g_app_info_delete(getAppInfoStruct()) != 0; 168 } 169 170 /** 171 * Creates a duplicate of a #GAppInfo. 172 * 173 * Returns: a duplicate of @appinfo. 174 */ 175 public AppInfoIF dup() 176 { 177 auto p = g_app_info_dup(getAppInfoStruct()); 178 179 if(p is null) 180 { 181 return null; 182 } 183 184 return ObjectG.getDObject!(AppInfoIF)(cast(GAppInfo*) p, true); 185 } 186 187 /** 188 * Checks if two #GAppInfos are equal. 189 * 190 * Note that the check <emphasis>may not</emphasis> compare each individual 191 * field, and only does an identity check. In case detecting changes in the 192 * contents is needed, program code must additionally compare relevant fields. 193 * 194 * Params: 195 * appinfo2 = the second #GAppInfo. 196 * 197 * Returns: %TRUE if @appinfo1 is equal to @appinfo2. %FALSE otherwise. 198 */ 199 public bool equal(AppInfoIF appinfo2) 200 { 201 return g_app_info_equal(getAppInfoStruct(), (appinfo2 is null) ? null : appinfo2.getAppInfoStruct()) != 0; 202 } 203 204 /** 205 * Gets the commandline with which the application will be 206 * started. 207 * 208 * Returns: a string containing the @appinfo's commandline, 209 * or %NULL if this information is not available 210 * 211 * Since: 2.20 212 */ 213 public string getCommandline() 214 { 215 return Str.toString(g_app_info_get_commandline(getAppInfoStruct())); 216 } 217 218 /** 219 * Gets a human-readable description of an installed application. 220 * 221 * Returns: a string containing a description of the 222 * application @appinfo, or %NULL if none. 223 */ 224 public string getDescription() 225 { 226 return Str.toString(g_app_info_get_description(getAppInfoStruct())); 227 } 228 229 /** 230 * Gets the display name of the application. The display name is often more 231 * descriptive to the user than the name itself. 232 * 233 * Returns: the display name of the application for @appinfo, or the name if 234 * no display name is available. 235 * 236 * Since: 2.24 237 */ 238 public string getDisplayName() 239 { 240 return Str.toString(g_app_info_get_display_name(getAppInfoStruct())); 241 } 242 243 /** 244 * Gets the executable's name for the installed application. 245 * 246 * Returns: a string containing the @appinfo's application 247 * binaries name 248 */ 249 public string getExecutable() 250 { 251 return Str.toString(g_app_info_get_executable(getAppInfoStruct())); 252 } 253 254 /** 255 * Gets the icon for the application. 256 * 257 * Returns: the default #GIcon for @appinfo or %NULL 258 * if there is no default icon. 259 */ 260 public IconIF getIcon() 261 { 262 auto p = g_app_info_get_icon(getAppInfoStruct()); 263 264 if(p is null) 265 { 266 return null; 267 } 268 269 return ObjectG.getDObject!(IconIF)(cast(GIcon*) p); 270 } 271 272 /** 273 * Gets the ID of an application. An id is a string that 274 * identifies the application. The exact format of the id is 275 * platform dependent. For instance, on Unix this is the 276 * desktop file id from the xdg menu specification. 277 * 278 * Note that the returned ID may be %NULL, depending on how 279 * the @appinfo has been constructed. 280 * 281 * Returns: a string containing the application's ID. 282 */ 283 public string getId() 284 { 285 return Str.toString(g_app_info_get_id(getAppInfoStruct())); 286 } 287 288 /** 289 * Gets the installed name of the application. 290 * 291 * Returns: the name of the application for @appinfo. 292 */ 293 public string getName() 294 { 295 return Str.toString(g_app_info_get_name(getAppInfoStruct())); 296 } 297 298 /** 299 * Retrieves the list of content types that @app_info claims to support. 300 * If this information is not provided by the environment, this function 301 * will return %NULL. 302 * This function does not take in consideration associations added with 303 * g_app_info_add_supports_type(), but only those exported directly by 304 * the application. 305 * 306 * Returns: a list of content types. 307 * 308 * Since: 2.34 309 */ 310 public string[] getSupportedTypes() 311 { 312 return Str.toStringArray(g_app_info_get_supported_types(getAppInfoStruct())); 313 } 314 315 /** 316 * Launches the application. Passes @files to the launched application 317 * as arguments, using the optional @context to get information 318 * about the details of the launcher (like what screen it is on). 319 * On error, @error will be set accordingly. 320 * 321 * To launch the application without arguments pass a %NULL @files list. 322 * 323 * Note that even if the launch is successful the application launched 324 * can fail to start if it runs into problems during startup. There is 325 * no way to detect this. 326 * 327 * Some URIs can be changed when passed through a GFile (for instance 328 * unsupported URIs with strange formats like mailto:), so if you have 329 * a textual URI you want to pass in as argument, consider using 330 * g_app_info_launch_uris() instead. 331 * 332 * The launched application inherits the environment of the launching 333 * process, but it can be modified with g_app_launch_context_setenv() 334 * and g_app_launch_context_unsetenv(). 335 * 336 * On UNIX, this function sets the `GIO_LAUNCHED_DESKTOP_FILE` 337 * environment variable with the path of the launched desktop file and 338 * `GIO_LAUNCHED_DESKTOP_FILE_PID` to the process id of the launched 339 * process. This can be used to ignore `GIO_LAUNCHED_DESKTOP_FILE`, 340 * should it be inherited by further processes. The `DISPLAY` and 341 * `DESKTOP_STARTUP_ID` environment variables are also set, based 342 * on information provided in @context. 343 * 344 * Params: 345 * files = a #GList of #GFile objects 346 * context = a #GAppLaunchContext or %NULL 347 * 348 * Returns: %TRUE on successful launch, %FALSE otherwise. 349 * 350 * Throws: GException on failure. 351 */ 352 public bool launch(ListG files, AppLaunchContext context) 353 { 354 GError* err = null; 355 356 auto p = g_app_info_launch(getAppInfoStruct(), (files is null) ? null : files.getListGStruct(), (context is null) ? null : context.getAppLaunchContextStruct(), &err) != 0; 357 358 if (err !is null) 359 { 360 throw new GException( new ErrorG(err) ); 361 } 362 363 return p; 364 } 365 366 /** 367 * Launches the application. This passes the @uris to the launched application 368 * as arguments, using the optional @context to get information 369 * about the details of the launcher (like what screen it is on). 370 * On error, @error will be set accordingly. 371 * 372 * To launch the application without arguments pass a %NULL @uris list. 373 * 374 * Note that even if the launch is successful the application launched 375 * can fail to start if it runs into problems during startup. There is 376 * no way to detect this. 377 * 378 * Params: 379 * uris = a #GList containing URIs to launch. 380 * context = a #GAppLaunchContext or %NULL 381 * 382 * Returns: %TRUE on successful launch, %FALSE otherwise. 383 * 384 * Throws: GException on failure. 385 */ 386 public bool launchUris(ListG uris, AppLaunchContext context) 387 { 388 GError* err = null; 389 390 auto p = g_app_info_launch_uris(getAppInfoStruct(), (uris is null) ? null : uris.getListGStruct(), (context is null) ? null : context.getAppLaunchContextStruct(), &err) != 0; 391 392 if (err !is null) 393 { 394 throw new GException( new ErrorG(err) ); 395 } 396 397 return p; 398 } 399 400 /** 401 * Removes a supported type from an application, if possible. 402 * 403 * Params: 404 * contentType = a string. 405 * 406 * Returns: %TRUE on success, %FALSE on error. 407 * 408 * Throws: GException on failure. 409 */ 410 public bool removeSupportsType(string contentType) 411 { 412 GError* err = null; 413 414 auto p = g_app_info_remove_supports_type(getAppInfoStruct(), Str.toStringz(contentType), &err) != 0; 415 416 if (err !is null) 417 { 418 throw new GException( new ErrorG(err) ); 419 } 420 421 return p; 422 } 423 424 /** 425 * Sets the application as the default handler for the given file extension. 426 * 427 * Params: 428 * extension = a string containing the file extension 429 * (without the dot). 430 * 431 * Returns: %TRUE on success, %FALSE on error. 432 * 433 * Throws: GException on failure. 434 */ 435 public bool setAsDefaultForExtension(string extension) 436 { 437 GError* err = null; 438 439 auto p = g_app_info_set_as_default_for_extension(getAppInfoStruct(), Str.toStringz(extension), &err) != 0; 440 441 if (err !is null) 442 { 443 throw new GException( new ErrorG(err) ); 444 } 445 446 return p; 447 } 448 449 /** 450 * Sets the application as the default handler for a given type. 451 * 452 * Params: 453 * contentType = the content type. 454 * 455 * Returns: %TRUE on success, %FALSE on error. 456 * 457 * Throws: GException on failure. 458 */ 459 public bool setAsDefaultForType(string contentType) 460 { 461 GError* err = null; 462 463 auto p = g_app_info_set_as_default_for_type(getAppInfoStruct(), Str.toStringz(contentType), &err) != 0; 464 465 if (err !is null) 466 { 467 throw new GException( new ErrorG(err) ); 468 } 469 470 return p; 471 } 472 473 /** 474 * Sets the application as the last used application for a given type. 475 * This will make the application appear as first in the list returned 476 * by g_app_info_get_recommended_for_type(), regardless of the default 477 * application for that content type. 478 * 479 * Params: 480 * contentType = the content type. 481 * 482 * Returns: %TRUE on success, %FALSE on error. 483 * 484 * Throws: GException on failure. 485 */ 486 public bool setAsLastUsedForType(string contentType) 487 { 488 GError* err = null; 489 490 auto p = g_app_info_set_as_last_used_for_type(getAppInfoStruct(), Str.toStringz(contentType), &err) != 0; 491 492 if (err !is null) 493 { 494 throw new GException( new ErrorG(err) ); 495 } 496 497 return p; 498 } 499 500 /** 501 * Checks if the application info should be shown in menus that 502 * list available applications. 503 * 504 * Returns: %TRUE if the @appinfo should be shown, %FALSE otherwise. 505 */ 506 public bool shouldShow() 507 { 508 return g_app_info_should_show(getAppInfoStruct()) != 0; 509 } 510 511 /** 512 * Checks if the application accepts files as arguments. 513 * 514 * Returns: %TRUE if the @appinfo supports files. 515 */ 516 public bool supportsFiles() 517 { 518 return g_app_info_supports_files(getAppInfoStruct()) != 0; 519 } 520 521 /** 522 * Checks if the application supports reading files and directories from URIs. 523 * 524 * Returns: %TRUE if the @appinfo supports URIs. 525 */ 526 public bool supportsUris() 527 { 528 return g_app_info_supports_uris(getAppInfoStruct()) != 0; 529 } 530 }