- java.lang.Object
-
- org.scijava.desktop.platform.linux.DesktopFile
-
public class DesktopFile extends Object
Parser and writer for Linux .desktop files.Instance-based API for reading and writing .desktop files. Supports all standard [Desktop Entry] section fields plus custom keys. This class provides a convenient way to manage desktop files for both application launching and URI scheme registration.
Note: This class will eventually move to
org.scijava.util.DesktopFilein scijava-common once the design is finalized.- Author:
- Curtis Rueden
-
-
Constructor Summary
Constructors Constructor Description DesktopFile(Path path)Creates a DesktopFile instance for the given path.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMimeType(String mimeType)Adds a MIME type to the MimeType field.voiddelete()Deletes the file from disk.booleanexists()Checks if the file exists on disk.Stringget(String key)Gets the value for a key.StringgetCategories()StringgetComment()StringgetExec()StringgetGenericName()StringgetIcon()StringgetName()StringgetPath()booleangetStartupNotify()StringgetStartupWMClass()booleangetTerminal()StringgetTryExec()StringgetType()StringgetVersion()booleanhasMimeType(String mimeType)Checks if a MimeType entry contains a specific MIME type.voidload()Loads the .desktop file from disk.static DesktopFileparse(Path path)Parses a .desktop file from disk (static convenience method).Pathpath()Gets the file path for this desktop file.voidremoveMimeType(String mimeType)Removes a MIME type from the MimeType field.voidsave()Saves the .desktop file to disk.voidset(String key, String value)Sets a key-value pair.voidsetCategories(String categories)voidsetComment(String comment)voidsetExec(String exec)voidsetGenericName(String genericName)voidsetIcon(String icon)voidsetName(String name)voidsetPath(String path)voidsetStartupNotify(boolean startupNotify)voidsetStartupWMClass(String startupWMClass)voidsetTerminal(boolean terminal)voidsetTryExec(String tryExec)voidsetType(String type)voidsetVersion(String version)voidwriteTo(Path path)Writes the .desktop file to disk (for backward compatibility).
-
-
-
Constructor Detail
-
DesktopFile
public DesktopFile(Path path)
Creates a DesktopFile instance for the given path.If the file exists, it will be loaded when
load()is called. If it doesn't exist, the entries map will be empty until populated programmatically orload()is called.- Parameters:
path- the path to the .desktop file
-
-
Method Detail
-
path
public Path path()
Gets the file path for this desktop file.- Returns:
- the path
-
exists
public boolean exists()
Checks if the file exists on disk.- Returns:
- true if the file exists
-
load
public void load() throws IOExceptionLoads the .desktop file from disk.Clears any existing entries and comments, then reads from the file. If the file doesn't exist, entries will be empty after this call.
- Throws:
IOException- if reading fails
-
save
public void save() throws IOExceptionSaves the .desktop file to disk.Creates parent directories if needed. Overwrites any existing file.
- Throws:
IOException- if writing fails
-
delete
public void delete() throws IOExceptionDeletes the file from disk.- Throws:
IOException- if deletion fails
-
parse
public static DesktopFile parse(Path path) throws IOException
Parses a .desktop file from disk (static convenience method).- Parameters:
path- Path to the .desktop file- Returns:
- Parsed DesktopFile
- Throws:
IOException- if reading fails
-
writeTo
public void writeTo(Path path) throws IOException
Writes the .desktop file to disk (for backward compatibility).- Parameters:
path- Path to write to- Throws:
IOException- if writing fails
-
get
public String get(String key)
Gets the value for a key.- Parameters:
key- The key- Returns:
- The value, or null if not present
-
set
public void set(String key, String value)
Sets a key-value pair.- Parameters:
key- The keyvalue- The value
-
getType
public String getType()
-
setType
public void setType(String type)
-
getVersion
public String getVersion()
-
setVersion
public void setVersion(String version)
-
getName
public String getName()
-
setName
public void setName(String name)
-
getGenericName
public String getGenericName()
-
setGenericName
public void setGenericName(String genericName)
-
getComment
public String getComment()
-
setComment
public void setComment(String comment)
-
getExec
public String getExec()
-
setExec
public void setExec(String exec)
-
getIcon
public String getIcon()
-
setIcon
public void setIcon(String icon)
-
getPath
public String getPath()
-
setPath
public void setPath(String path)
-
getTerminal
public boolean getTerminal()
-
setTerminal
public void setTerminal(boolean terminal)
-
getCategories
public String getCategories()
-
setCategories
public void setCategories(String categories)
-
getTryExec
public String getTryExec()
-
setTryExec
public void setTryExec(String tryExec)
-
getStartupNotify
public boolean getStartupNotify()
-
setStartupNotify
public void setStartupNotify(boolean startupNotify)
-
getStartupWMClass
public String getStartupWMClass()
-
setStartupWMClass
public void setStartupWMClass(String startupWMClass)
-
hasMimeType
public boolean hasMimeType(String mimeType)
Checks if a MimeType entry contains a specific MIME type.- Parameters:
mimeType- The MIME type to check (e.g., "x-scheme-handler/myapp")- Returns:
- true if the MimeType field contains this type
-
addMimeType
public void addMimeType(String mimeType)
Adds a MIME type to the MimeType field.The MimeType field is a semicolon-separated list. This method appends the new type if it's not already present.
- Parameters:
mimeType- The MIME type to add (e.g., "x-scheme-handler/myapp")
-
removeMimeType
public void removeMimeType(String mimeType)
Removes a MIME type from the MimeType field.- Parameters:
mimeType- The MIME type to remove
-
-