Class DesktopAppInfo
GDesktopAppInfo
is an implementation of AppInfo
based on
desktop files.
Note that <gio/gdesktopappinfo.h>
belongs to the UNIX-specific
GIO interfaces, thus you have to use the gio-unix-2.0.pc
pkg-config
file or the GioUnix-2.0
GIR namespace when using it.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
DesktopAppInfo.Builder<B extends DesktopAppInfo.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static class
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
Nested classes/interfaces inherited from interface org.gnome.gio.AppInfo
AppInfo.AppInfoIface, AppInfo.AppInfoImpl
-
Constructor Summary
ConstructorDescriptionDesktopAppInfo
(MemorySegment address) Create a DesktopAppInfo proxy instance for the provided memory address.DesktopAppInfo
(String desktopId) Creates a newDesktopAppInfo
based on a desktop file ID. -
Method Summary
Modifier and TypeMethodDescriptionprotected DesktopAppInfo
asParent()
Returns this instance as if it were its parent type.static DesktopAppInfo.Builder
<? extends DesktopAppInfo.Builder> builder()
ADesktopAppInfo.Builder
object constructs aDesktopAppInfo
with the specified properties.static DesktopAppInfo
fromFilename
(String filename) Creates a newDesktopAppInfo
.static DesktopAppInfo
fromKeyfile
(KeyFile keyFile) Creates a newDesktopAppInfo
.getActionName
(String actionName) Gets the user-visible display name of the ‘additional application actions’ specified byactionName
.boolean
getBoolean
(String key) Looks up a boolean value in the keyfile backing this DesktopAppInfo.Gets the categories from the desktop file.When this DesktopAppInfo was created from a known filename, return it.Gets the generic name from the desktop file.static List
<DesktopAppInfo> getImplementations
(String interface_) Gets all applications that implementinterface_
.boolean
A desktop file is hidden if theHidden
key in it is set toTrue
.String[]
Gets the keywords from the desktop file.getLocaleString
(String key) Looks up a localized string value in the keyfile backing this DesktopAppInfo translated to the current locale.boolean
Gets the value of theNoDisplay
key which helps determine if the application info should be shown in menus.boolean
Checks if the application info should be shown in menus that list available applications for a specific name of the desktop, based on theOnlyShowIn
andNotShowIn
keys.Retrieves theStartupWMClass
field from this DesktopAppInfo.Looks up a string value in the keyfile backing this DesktopAppInfo.String[]
getStringList
(String key) Looks up a string list value in the keyfile backing this DesktopAppInfo.static Type
getType()
Get the GType of the DesktopAppInfo classboolean
Returns whetherkey
exists in theDesktop Entry
group of the keyfile backing this DesktopAppInfo.void
launchAction
(String actionName, @Nullable AppLaunchContext launchContext) Activates the named application action.boolean
launchUrisAsManager
(List<String> uris, @Nullable AppLaunchContext launchContext, Set<SpawnFlags> spawnFlags, @Nullable SpawnChildSetupFunc userSetup, @Nullable DesktopAppLaunchCallback pidCallback) This function performs the equivalent ofAppInfo.launchUris(org.gnome.glib.List<java.lang.String>, org.gnome.gio.AppLaunchContext)
, but is intended primarily for operating system components that launch applications.boolean
launchUrisAsManager
(List<String> uris, @Nullable AppLaunchContext launchContext, SpawnFlags spawnFlags, @Nullable SpawnChildSetupFunc userSetup, @Nullable DesktopAppLaunchCallback pidCallback) This function performs the equivalent ofAppInfo.launchUris(org.gnome.glib.List<java.lang.String>, org.gnome.gio.AppLaunchContext)
, but is intended primarily for operating system components that launch applications.boolean
launchUrisAsManagerWithFds
(List<String> uris, @Nullable AppLaunchContext launchContext, Set<SpawnFlags> spawnFlags, @Nullable SpawnChildSetupFunc userSetup, @Nullable DesktopAppLaunchCallback pidCallback, int stdinFd, int stdoutFd, int stderrFd) Equivalent tolaunchUrisAsManager(org.gnome.glib.List<java.lang.String>, org.gnome.gio.AppLaunchContext, java.util.Set<org.gnome.glib.SpawnFlags>, org.gnome.glib.SpawnChildSetupFunc, org.gnome.gio.DesktopAppLaunchCallback)
but allows you to pass in file descriptors for the stdin, stdout and stderr streams of the launched process.boolean
launchUrisAsManagerWithFds
(List<String> uris, @Nullable AppLaunchContext launchContext, SpawnFlags spawnFlags, @Nullable SpawnChildSetupFunc userSetup, @Nullable DesktopAppLaunchCallback pidCallback, int stdinFd, int stdoutFd, int stderrFd) Equivalent tolaunchUrisAsManager(org.gnome.glib.List<java.lang.String>, org.gnome.gio.AppLaunchContext, java.util.Set<org.gnome.glib.SpawnFlags>, org.gnome.glib.SpawnChildSetupFunc, org.gnome.gio.DesktopAppLaunchCallback)
but allows you to pass in file descriptors for the stdin, stdout and stderr streams of the launched process.String[]
Returns the list of ‘additional application actions’ supported on the desktop file, as per the desktop file specification.static String[][]
Searches desktop files for ones that matchsearchString
.static void
setDesktopEnv
(String desktopEnv) Deprecated.do not use this API.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.gnome.gio.AppInfo
addSupportsType, canDelete, canRemoveSupportsType, delete, dup, equal, getCommandline, getDescription, getDisplayName, getExecutable, getIcon, getId, getName, getSupportedTypes, launch, launchUris, launchUrisAsync, launchUrisFinish, removeSupportsType, setAsDefaultForExtension, setAsDefaultForType, setAsLastUsedForType, shouldShow, supportsFiles, supportsUris
-
Constructor Details
-
DesktopAppInfo
Create a DesktopAppInfo proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
DesktopAppInfo
Creates a newDesktopAppInfo
based on a desktop file ID.A desktop file ID is the basename of the desktop file, including the
.desktop
extension. GIO is looking for a desktop file with this name in theapplications
subdirectories of the XDG data directories (i.e. the directories specified in theXDG_DATA_HOME
andXDG_DATA_DIRS
environment variables). GIO also supports the prefix-to-subdirectory mapping that is described in the Menu Spec (i.e. a desktop ID ofkde-foo.desktop
will match/usr/share/applications/kde/foo.desktop
).- Parameters:
desktopId
- the desktop file ID- Throws:
UnsupportedPlatformException
- when run on a platform other than linux
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
fromFilename
Creates a newDesktopAppInfo
.- Parameters:
filename
- the path of a desktop file, in the GLib filename encoding- Returns:
- a new
DesktopAppInfo
orNULL
on error. - Throws:
UnsupportedPlatformException
- when run on a platform other than linux
-
fromKeyfile
Creates a newDesktopAppInfo
.- Parameters:
keyFile
- an openedGLib.KeyFile
- Returns:
- a new
DesktopAppInfo
orNULL
on error. - Throws:
UnsupportedPlatformException
- when run on a platform other than linux
-
getImplementations
public static List<DesktopAppInfo> getImplementations(String interface_) throws UnsupportedPlatformException Gets all applications that implementinterface_
.An application implements an interface if that interface is listed in the
Implements
line of the desktop file of the application.- Parameters:
interface_
- the name of the interface- Returns:
- a list of
DesktopAppInfo
objects. - Throws:
UnsupportedPlatformException
- when run on a platform other than linux
-
search
Searches desktop files for ones that matchsearchString
.The return value is an array of strvs. Each strv contains a list of applications that matched
searchString
with an equal score. The outer list is sorted by score so that the first strv contains the best-matching applications, and so on. The algorithm for determining matches is undefined and may change at any time.None of the search results are subjected to the normal validation checks performed by
DesktopAppInfo(java.lang.String)
(for example, checking that the executable referenced by a result exists), and so it is possible forDesktopAppInfo(java.lang.String)
to returnNULL
when passed an app ID returned by this function. It is expected that calling code will do this when subsequently creating aDesktopAppInfo
for each result.- Parameters:
searchString
- the search string to use- Returns:
- a
list of strvs. Free each item with
GLib.strfreev(java.lang.foreign.MemorySegment)
and free the outer list withGLib.free(java.lang.foreign.MemorySegment)
. - Throws:
UnsupportedPlatformException
- when run on a platform other than linux
-
setDesktopEnv
Deprecated.do not use this API. Since 2.42 the value of theXDG_CURRENT_DESKTOP
environment variable will be used.Sets the name of the desktop that the application is running in.This is used by
AppInfo.shouldShow()
andgetShowIn(java.lang.String)
to evaluate theOnlyShowIn
andNotShowIn
keys.Should be called only once; subsequent calls are ignored.
- Parameters:
desktopEnv
- a string specifying what desktop this is- Throws:
UnsupportedPlatformException
- when run on a platform other than linux
-
getActionName
Gets the user-visible display name of the ‘additional application actions’ specified byactionName
.This corresponds to the
Name
key within the keyfile group for the action.- Parameters:
actionName
- the name of the action as fromlistActions()
- Returns:
- the locale-specific action name
-
getBoolean
Looks up a boolean value in the keyfile backing this DesktopAppInfo.The
key
is looked up in theDesktop Entry
group.- Parameters:
key
- the key to look up- Returns:
- the boolean value, or
FALSE
if the key is not found
-
getCategories
Gets the categories from the desktop file.- Returns:
- The unparsed
Categories
key from the desktop file; i.e. no attempt is made to split it by;
or validate it.
-
getFilename
When this DesktopAppInfo was created from a known filename, return it. In some situations such as aDesktopAppInfo
returned fromfromKeyfile(org.gnome.glib.KeyFile)
, this function will returnNULL
.- Returns:
- The full path to the file for this DesktopAppInfo,
or
NULL
if not known.
-
getGenericName
Gets the generic name from the desktop file.- Returns:
- The value of the
GenericName
key
-
getIsHidden
public boolean getIsHidden()A desktop file is hidden if theHidden
key in it is set toTrue
.- Returns:
TRUE
if hidden,FALSE
otherwise.
-
getKeywords
Gets the keywords from the desktop file.- Returns:
- The value of the
Keywords
key
-
getLocaleString
Looks up a localized string value in the keyfile backing this DesktopAppInfo translated to the current locale.The
key
is looked up in theDesktop Entry
group.- Parameters:
key
- the key to look up- Returns:
- a newly allocated string, or
NULL
if the key is not found
-
getNodisplay
public boolean getNodisplay()Gets the value of theNoDisplay
key which helps determine if the application info should be shown in menus. SeeG_KEY_FILE_DESKTOP_KEY_NO_DISPLAY
andAppInfo.shouldShow()
.- Returns:
- The value of the
NoDisplay
key
-
getShowIn
Checks if the application info should be shown in menus that list available applications for a specific name of the desktop, based on theOnlyShowIn
andNotShowIn
keys.desktopEnv
should typically be given asNULL
, in which case theXDG_CURRENT_DESKTOP
environment variable is consulted. If you want to override the default mechanism then you may specifydesktopEnv
, but this is not recommended.Note that
AppInfo.shouldShow()
for this DesktopAppInfo will include this check (withNULL
fordesktopEnv
) as well as additional checks.- Parameters:
desktopEnv
- a string specifying a desktop name- Returns:
TRUE
if the this DesktopAppInfo should be shown indesktopEnv
according to theOnlyShowIn
andNotShowIn
keys,FALSE
otherwise.
-
getStartupWmClass
Retrieves theStartupWMClass
field from this DesktopAppInfo. This represents theWM_CLASS
property of the main window of the application, if launched through this DesktopAppInfo.- Returns:
- the startup WM class, or
NULL
if none is set in the desktop file.
-
getString
-
getStringList
Looks up a string list value in the keyfile backing this DesktopAppInfo.The
key
is looked up in theDesktop Entry
group.- Parameters:
key
- the key to look up- Returns:
- a
NULL
-terminated string array orNULL
if the specified key cannot be found. The array should be freed withGLib.strfreev(java.lang.foreign.MemorySegment)
.
-
hasKey
Returns whetherkey
exists in theDesktop Entry
group of the keyfile backing this DesktopAppInfo.- Parameters:
key
- the key to look up- Returns:
TRUE
if thekey
exists
-
launchAction
Activates the named application action.You may only call this function on action names that were returned from
listActions()
.Note that if the main entry of the desktop file indicates that the application supports startup notification, and
launchContext
is non-NULL
, then startup notification will be used when activating the action (and as such, invocation of the action on the receiving side must signal the end of startup notification when it is completed). This is the expected behaviour of applications declaring additional actions, as per the desktop file specification.As with
AppInfo.launch(org.gnome.glib.List<org.gnome.gio.File>, org.gnome.gio.AppLaunchContext)
there is no way to detect failures that occur while using this function.- Parameters:
actionName
- the name of the action as fromlistActions()
launchContext
- aAppLaunchContext
-
launchUrisAsManager
public boolean launchUrisAsManager(List<String> uris, @Nullable @Nullable AppLaunchContext launchContext, Set<SpawnFlags> spawnFlags, @Nullable @Nullable SpawnChildSetupFunc userSetup, @Nullable @Nullable DesktopAppLaunchCallback pidCallback) throws GErrorException This function performs the equivalent ofAppInfo.launchUris(org.gnome.glib.List<java.lang.String>, org.gnome.gio.AppLaunchContext)
, but is intended primarily for operating system components that launch applications. Ordinary applications should useAppInfo.launchUris(org.gnome.glib.List<java.lang.String>, org.gnome.gio.AppLaunchContext)
.If the application is launched via GSpawn, then
spawnFlags
,userSetup
anduserSetupData
are used for the call toGLib.spawnAsync(java.lang.String, java.lang.String[], java.lang.String[], java.util.Set<org.gnome.glib.SpawnFlags>, org.gnome.glib.SpawnChildSetupFunc, org.gnome.glib.Pid)
. Additionally,pidCallback
(withpidCallbackData
) will be called to inform about the PID of the created process. SeeGLib.spawnAsyncWithPipes(java.lang.String, java.lang.String[], java.lang.String[], java.util.Set<org.gnome.glib.SpawnFlags>, org.gnome.glib.SpawnChildSetupFunc, org.gnome.glib.Pid, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>)
for information on certain parameter conditions that can enable an optimizedposix_spawn()
) code path to be used.If application launching occurs via some other mechanism (for example, D-Bus activation) then
spawnFlags
,userSetup
,userSetupData
,pidCallback
andpidCallbackData
are ignored.- Parameters:
uris
- List of URIslaunchContext
- aAppLaunchContext
spawnFlags
-GLib.SpawnFlags
, used for each processuserSetup
- aGLib.SpawnChildSetupFunc
, used once for each process.pidCallback
- Callback for child processes- Returns:
TRUE
on successful launch,FALSE
otherwise.- Throws:
GErrorException
- seeGError
-
launchUrisAsManager
public boolean launchUrisAsManager(List<String> uris, @Nullable @Nullable AppLaunchContext launchContext, SpawnFlags spawnFlags, @Nullable @Nullable SpawnChildSetupFunc userSetup, @Nullable @Nullable DesktopAppLaunchCallback pidCallback) throws GErrorException This function performs the equivalent ofAppInfo.launchUris(org.gnome.glib.List<java.lang.String>, org.gnome.gio.AppLaunchContext)
, but is intended primarily for operating system components that launch applications. Ordinary applications should useAppInfo.launchUris(org.gnome.glib.List<java.lang.String>, org.gnome.gio.AppLaunchContext)
.If the application is launched via GSpawn, then
spawnFlags
,userSetup
anduserSetupData
are used for the call toGLib.spawnAsync(java.lang.String, java.lang.String[], java.lang.String[], java.util.Set<org.gnome.glib.SpawnFlags>, org.gnome.glib.SpawnChildSetupFunc, org.gnome.glib.Pid)
. Additionally,pidCallback
(withpidCallbackData
) will be called to inform about the PID of the created process. SeeGLib.spawnAsyncWithPipes(java.lang.String, java.lang.String[], java.lang.String[], java.util.Set<org.gnome.glib.SpawnFlags>, org.gnome.glib.SpawnChildSetupFunc, org.gnome.glib.Pid, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>, io.github.jwharm.javagi.base.Out<java.lang.Integer>)
for information on certain parameter conditions that can enable an optimizedposix_spawn()
) code path to be used.If application launching occurs via some other mechanism (for example, D-Bus activation) then
spawnFlags
,userSetup
,userSetupData
,pidCallback
andpidCallbackData
are ignored.- Parameters:
uris
- List of URIslaunchContext
- aAppLaunchContext
spawnFlags
-GLib.SpawnFlags
, used for each processuserSetup
- aGLib.SpawnChildSetupFunc
, used once for each process.pidCallback
- Callback for child processes- Returns:
TRUE
on successful launch,FALSE
otherwise.- Throws:
GErrorException
- seeGError
-
launchUrisAsManagerWithFds
public boolean launchUrisAsManagerWithFds(List<String> uris, @Nullable @Nullable AppLaunchContext launchContext, Set<SpawnFlags> spawnFlags, @Nullable @Nullable SpawnChildSetupFunc userSetup, @Nullable @Nullable DesktopAppLaunchCallback pidCallback, int stdinFd, int stdoutFd, int stderrFd) throws GErrorException Equivalent tolaunchUrisAsManager(org.gnome.glib.List<java.lang.String>, org.gnome.gio.AppLaunchContext, java.util.Set<org.gnome.glib.SpawnFlags>, org.gnome.glib.SpawnChildSetupFunc, org.gnome.gio.DesktopAppLaunchCallback)
but allows you to pass in file descriptors for the stdin, stdout and stderr streams of the launched process.If application launching occurs via some non-spawn mechanism (e.g. D-Bus activation) then
stdinFd
,stdoutFd
andstderrFd
are ignored.- Parameters:
uris
- List of URIslaunchContext
- aAppLaunchContext
spawnFlags
-GLib.SpawnFlags
, used for each processuserSetup
- aGLib.SpawnChildSetupFunc
, used once for each process.pidCallback
- Callback for child processesstdinFd
- file descriptor to use for child’s stdin, or-1
stdoutFd
- file descriptor to use for child’s stdout, or-1
stderrFd
- file descriptor to use for child’s stderr, or-1
- Returns:
TRUE
on successful launch,FALSE
otherwise.- Throws:
GErrorException
- seeGError
-
launchUrisAsManagerWithFds
public boolean launchUrisAsManagerWithFds(List<String> uris, @Nullable @Nullable AppLaunchContext launchContext, SpawnFlags spawnFlags, @Nullable @Nullable SpawnChildSetupFunc userSetup, @Nullable @Nullable DesktopAppLaunchCallback pidCallback, int stdinFd, int stdoutFd, int stderrFd) throws GErrorException Equivalent tolaunchUrisAsManager(org.gnome.glib.List<java.lang.String>, org.gnome.gio.AppLaunchContext, java.util.Set<org.gnome.glib.SpawnFlags>, org.gnome.glib.SpawnChildSetupFunc, org.gnome.gio.DesktopAppLaunchCallback)
but allows you to pass in file descriptors for the stdin, stdout and stderr streams of the launched process.If application launching occurs via some non-spawn mechanism (e.g. D-Bus activation) then
stdinFd
,stdoutFd
andstderrFd
are ignored.- Parameters:
uris
- List of URIslaunchContext
- aAppLaunchContext
spawnFlags
-GLib.SpawnFlags
, used for each processuserSetup
- aGLib.SpawnChildSetupFunc
, used once for each process.pidCallback
- Callback for child processesstdinFd
- file descriptor to use for child’s stdin, or-1
stdoutFd
- file descriptor to use for child’s stdout, or-1
stderrFd
- file descriptor to use for child’s stderr, or-1
- Returns:
TRUE
on successful launch,FALSE
otherwise.- Throws:
GErrorException
- seeGError
-
listActions
Returns the list of ‘additional application actions’ supported on the desktop file, as per the desktop file specification.As per the specification, this is the list of actions that are explicitly listed in the
Actions
key of theDesktop Entry
group.- Returns:
- a
list of strings, always non-
NULL
-
builder
ADesktopAppInfo.Builder
object constructs aDesktopAppInfo
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withDesktopAppInfo.Builder.build()
.
-