AppInfo and AppLaunchContext are used for
describing and launching applications installed on the system.
As of GLib 2.20, URIs will always be converted to POSIX paths (using get_path
) when using launch even if the application requested an URI and not a
POSIX path. For example for a desktop-file based application with Exec key `totem u` and a single URI,
`sftp://foo/file.avi`, then `/home/user/.gvfs/sftp on foo/file.avi` will be passed. This will only work if a set of suitable GIO
extensions (such as gvfs 2.26 compiled with FUSE support), is available and operational; if this is not the case, the URI will be passed
unmodified to the application. Some URIs, such as `mailto:`, of course cannot be mapped to a POSIX path (in gvfs there's no FUSE mount for
it); such URIs will be passed unmodified to the application.
Specifically for gvfs 2.26 and later, the POSIX URI will be mapped back to the GIO URI in the
File constructors (since gvfs implements the Vfs extension point). As such, if the
application needs to examine the URI, it needs to use get_uri or similar on
File. In other words, an application cannot assume that the URI passed to e.g.
new_for_commandline_arg is equal to the result of
get_uri. The following snippet illustrates this:
GFile *f;
char *uri;
file = g_file_new_for_commandline_arg (uri_from_commandline);
uri = g_file_get_uri (file);
strcmp (uri, uri_from_commandline) == 0;
g_free (uri);
if (g_file_has_uri_scheme (file, "cdda"))
{
// do something special with uri
}
g_object_unref (file);
This code will work when both `cdda://sr0/Track 1.wav` and `/home/user/.gvfs/cdda on sr0/Track 1.wav` is passed to the application. It
should be noted that it's generally not safe for applications to rely on the format of a particular URIs. Different launcher applications
(e.g. file managers) may have different ideas of what a given URI means.
Example: AppInfo:
public static int main (string[] args) {
try {
AppInfo appinfo = AppInfo.get_default_for_type ("text/x-vala", true);
print ("%s\n", appinfo.supports_files ().to_string ());
print ("%s\n", appinfo.supports_uris ().to_string ());
print ("%s\n", appinfo.get_commandline ());
print ("%s\n", appinfo.get_name ());
appinfo.launch (null, null);
} catch (Error e) {
print ("Error: %s\n", e.message);
}
return 0;
}
valac --pkg gio-2.0 GLib.AppInfo.vala
- public abstract bool @delete ()
Tries to delete a AppInfo.
- public abstract bool add_supports_type (string content_type) throws Error
Adds a content type to the application information to indicate the
application is capable of opening files with the given content type.
- public abstract bool can_delete ()
Obtains the information whether the AppInfo
can be deleted.
- public abstract bool can_remove_supports_type ()
Checks if a supported content type can be removed from an application.
- public abstract AppInfo dup ()
Creates a duplicate of a AppInfo.
- public abstract bool equal (AppInfo appinfo2)
Checks if two AppInfos are equal.
- public abstract unowned string? get_commandline ()
Gets the commandline with which the application will be started.
- public abstract unowned string? get_description ()
Gets a human-readable description of an installed application.
- public abstract unowned string get_display_name ()
Gets the display name of the application.
- public abstract unowned string get_executable ()
Gets the executable's name for the installed application.
- public abstract unowned Icon? get_icon ()
Gets the icon for the application.
- public abstract unowned string? get_id ()
Gets the ID of an application.
- public abstract unowned string get_name ()
Gets the installed name of the application.
- public abstract unowned string[] get_supported_types ()
Retrieves the list of content types that app_info
claims
to support.
- public abstract bool launch (List<File>? files, AppLaunchContext? context) throws Error
Launches the application.
- public abstract bool launch_uris (List<string>? uris, AppLaunchContext? context) throws Error
Launches the application.
- public abstract async bool launch_uris_async (List<string>? uris, AppLaunchContext? context, Cancellable? cancellable = null) throws Error
- public abstract bool remove_supports_type (string content_type) throws Error
Removes a supported type from an application, if possible.
- public abstract bool set_as_default_for_extension (string extension) throws Error
Sets the application as the default handler for the given file
extension.
- public abstract bool set_as_default_for_type (string content_type) throws Error
Sets the application as the default handler for a given type.
- public abstract bool set_as_last_used_for_type (string content_type) throws Error
Sets the application as the last used application for a given type.
- public abstract bool should_show ()
Checks if the application info should be shown in menus that list
available applications.
- public abstract bool supports_files ()
Checks if the application accepts files as arguments.
- public abstract bool supports_uris ()
Checks if the application supports reading files and directories from
URIs.