|
@@ -8,7 +8,7 @@ import org.ini4j.Profile.Section
|
|
|
import org.ini4j.Wini
|
|
import org.ini4j.Wini
|
|
|
import java.io.File
|
|
import java.io.File
|
|
|
|
|
|
|
|
-@Suppress("unused", "MemberVisibilityCanBePrivate", "ConstPropertyName")
|
|
|
|
|
|
|
+@Suppress("unused", "MemberVisibilityCanBePrivate", "ConstPropertyName", "PropertyName")
|
|
|
class DesktopFile(
|
|
class DesktopFile(
|
|
|
val file: File,
|
|
val file: File,
|
|
|
val content: Ini = Wini(file),
|
|
val content: Ini = Wini(file),
|
|
@@ -20,167 +20,217 @@ class DesktopFile(
|
|
|
get() = content.map { if (it is Section) it else null }.filterNotNull().associateBy { it.value.toString() }
|
|
get() = content.map { if (it is Section) it else null }.filterNotNull().associateBy { it.value.toString() }
|
|
|
|
|
|
|
|
val desktopSection
|
|
val desktopSection
|
|
|
- get() = content[DesktopFileType.DesktopEntry.text]
|
|
|
|
|
|
|
+ get() = content[DesktopFileType.DesktopEntry.text]?.let { DesktopSectionScope(it) }
|
|
|
|
|
|
|
|
val themeSection
|
|
val themeSection
|
|
|
- get() = content[DesktopFileType.Theme.text]
|
|
|
|
|
|
|
+ get() = content[DesktopFileType.Theme.text]?.let { ThemeSectionScope(it) }
|
|
|
|
|
|
|
|
fun section(
|
|
fun section(
|
|
|
type: DesktopFileType,
|
|
type: DesktopFileType,
|
|
|
block: Section.() -> Unit
|
|
block: Section.() -> Unit
|
|
|
) = (content[type.text] ?: content.add(type.text))?.apply(block)
|
|
) = (content[type.text] ?: content.add(type.text))?.apply(block)
|
|
|
|
|
|
|
|
- fun write() {
|
|
|
|
|
- if (file.exists()) file.delete()
|
|
|
|
|
- file.createNewFile()
|
|
|
|
|
- content.store(file)
|
|
|
|
|
|
|
+ fun desktopSection(
|
|
|
|
|
+ block: DesktopSectionScope.() -> Unit
|
|
|
|
|
+ ) = section(DesktopFile.DesktopFileType.DesktopEntry) {
|
|
|
|
|
+ DesktopSectionScope(this).apply(block)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- enum class DesktopFileType(val text: String) {
|
|
|
|
|
- Unknown(""),
|
|
|
|
|
- DesktopEntry("Desktop Entry"),
|
|
|
|
|
- Application("Application"),
|
|
|
|
|
- Theme("X-GNOME-Metatheme");
|
|
|
|
|
|
|
+ fun themeSection(
|
|
|
|
|
+ block: ThemeSectionScope.() -> Unit
|
|
|
|
|
+ ) = section(DesktopFile.DesktopFileType.Theme) {
|
|
|
|
|
+ ThemeSectionScope(this).apply(block)
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- companion object {
|
|
|
|
|
- operator fun invoke(
|
|
|
|
|
- value: String?
|
|
|
|
|
- ): DesktopFileType = value.orEmpty().trim().let { v ->
|
|
|
|
|
- entries.firstOrNull { e -> e.text.contentEquals(v, true) } ?: Unknown
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ fun write() {
|
|
|
|
|
+ if (file.exists()) {
|
|
|
|
|
+ file.delete()
|
|
|
}
|
|
}
|
|
|
|
|
+ file.createNewFile()
|
|
|
|
|
+ content.store(file)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- companion object {
|
|
|
|
|
- const val Prop_Type = "Type"
|
|
|
|
|
- const val Prop_Version = "Version"
|
|
|
|
|
- const val Prop_Path = "Path"
|
|
|
|
|
- const val Prop_Name = "Name"
|
|
|
|
|
- const val Prop_Comment = "Comment"
|
|
|
|
|
- const val Prop_Exec = "Exec"
|
|
|
|
|
- const val Prop_StartupNotify = "StartupNotify"
|
|
|
|
|
- const val Prop_Terminal = "Terminal"
|
|
|
|
|
- const val Prop_Icon = "Icon"
|
|
|
|
|
- const val Prop_Categories = "Categories"
|
|
|
|
|
- const val Prop_GenericName = "GenericName"
|
|
|
|
|
- const val Prop_MimeType = "MimeType"
|
|
|
|
|
- const val Prop_Actions = "Actions"
|
|
|
|
|
- const val Prop_DBusActivatable = "DBusActivatable"
|
|
|
|
|
- const val Prop_Encoding = "Encoding"
|
|
|
|
|
-
|
|
|
|
|
- const val Prop_X_GNOME_UsesNotifications = "X-GNOME-UsesNotifications"
|
|
|
|
|
- const val Prop_X_Purism_FormFactor = "X-Purism-FormFactor"
|
|
|
|
|
- const val Prop_X_Unity_IconBackgroundColor = "X-Unity-IconBackgroundColor"
|
|
|
|
|
- const val Prop_X_Ubuntu_Gettext_Domain = "X-Ubuntu-Gettext-Domain"
|
|
|
|
|
-
|
|
|
|
|
- const val Prop_GtkTheme = "GtkTheme"
|
|
|
|
|
- const val Prop_MetacityTheme = "MetacityTheme"
|
|
|
|
|
- const val Prop_IconTheme = "IconTheme"
|
|
|
|
|
- const val Prop_CursorTheme = "CursorTheme"
|
|
|
|
|
- const val Prop_ButtonLayout = "ButtonLayout"
|
|
|
|
|
- const val Prop_X_Ubuntu_UseOverlayScrollbars = "X-Ubuntu-UseOverlayScrollbars"
|
|
|
|
|
|
|
+ interface ISectionScope {
|
|
|
|
|
+ val section: Section
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- var Section.Type: DesktopFileType
|
|
|
|
|
- get() = DesktopFileType(this[Prop_Type])
|
|
|
|
|
|
|
+ class DesktopSectionScope(
|
|
|
|
|
+ override val section: Section
|
|
|
|
|
+ ) : ISectionScope {
|
|
|
|
|
+ var Type: DesktopFileType
|
|
|
|
|
+ get() = DesktopFileType(section[Prop_Type])
|
|
|
set(value) {
|
|
set(value) {
|
|
|
- this[Prop_Type] = value.text
|
|
|
|
|
|
|
+ section[Prop_Type] = value.text
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var Section.Version: String
|
|
|
|
|
- get() = ParsedString(this[Prop_Version])
|
|
|
|
|
|
|
+ var Version: String
|
|
|
|
|
+ get() = ParsedString(section[Prop_Version])
|
|
|
set(value) {
|
|
set(value) {
|
|
|
- this[Prop_Version] = value
|
|
|
|
|
|
|
+ section[Prop_Version] = value
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var Section.Name: String
|
|
|
|
|
- get() = ParsedString(this[Prop_Name])
|
|
|
|
|
|
|
+ var Name: String
|
|
|
|
|
+ get() = ParsedString(section[Prop_Name])
|
|
|
set(value) {
|
|
set(value) {
|
|
|
- this[Prop_Name] = value
|
|
|
|
|
|
|
+ section[Prop_Name] = value
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var Section.Comment: String
|
|
|
|
|
- get() = ParsedString(this[Prop_Comment])
|
|
|
|
|
|
|
+ var Comment: String
|
|
|
|
|
+ get() = ParsedString(section[Prop_Comment])
|
|
|
set(value) {
|
|
set(value) {
|
|
|
- this[Prop_Comment] = value
|
|
|
|
|
|
|
+ section[Prop_Comment] = value
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var Section.Path: String
|
|
|
|
|
- get() = ParsedString(this[Prop_Path])
|
|
|
|
|
|
|
+ var Path: String
|
|
|
|
|
+ get() = ParsedString(section[Prop_Path])
|
|
|
set(value) {
|
|
set(value) {
|
|
|
- this[Prop_Path] = value
|
|
|
|
|
|
|
+ section[Prop_Path] = value
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var Section.Exec: String
|
|
|
|
|
- get() = ParsedString(this[Prop_Exec])
|
|
|
|
|
|
|
+ var Exec: String
|
|
|
|
|
+ get() = ParsedString(section[Prop_Exec])
|
|
|
set(value) {
|
|
set(value) {
|
|
|
- this[Prop_Exec] = value
|
|
|
|
|
|
|
+ section[Prop_Exec] = value
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var Section.Icon: String
|
|
|
|
|
- get() = ParsedString(this[Prop_Icon])
|
|
|
|
|
|
|
+ var Icon: String
|
|
|
|
|
+ get() = ParsedString(section[Prop_Icon])
|
|
|
set(value) {
|
|
set(value) {
|
|
|
- this[Prop_Icon] = value
|
|
|
|
|
|
|
+ section[Prop_Icon] = value
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- var Section.Encoding: String
|
|
|
|
|
- get() = ParsedString(this[Prop_Encoding])
|
|
|
|
|
|
|
+ var Encoding: String
|
|
|
|
|
+ get() = ParsedString(section[Prop_Encoding])
|
|
|
set(value) {
|
|
set(value) {
|
|
|
- this[Prop_Encoding] = value
|
|
|
|
|
|
|
+ section[Prop_Encoding] = value
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- var Section.NotifyOnStart: Boolean
|
|
|
|
|
- get() = ParsedBoolean(this[Prop_StartupNotify])
|
|
|
|
|
|
|
+ var NotifyOnStart: Boolean
|
|
|
|
|
+ get() = ParsedBoolean(section[Prop_StartupNotify])
|
|
|
set(value) {
|
|
set(value) {
|
|
|
- this[Prop_StartupNotify] = value.toString()
|
|
|
|
|
|
|
+ section[Prop_StartupNotify] = value.toString()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var Section.RunInTerminal: Boolean
|
|
|
|
|
- get() = ParsedBoolean(this[Prop_Terminal])
|
|
|
|
|
|
|
+ var RunInTerminal: Boolean
|
|
|
|
|
+ get() = ParsedBoolean(section[Prop_Terminal])
|
|
|
set(value) {
|
|
set(value) {
|
|
|
- this[Prop_Terminal] = value.toString()
|
|
|
|
|
|
|
+ section[Prop_Terminal] = value.toString()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var Section.Categories: MutableList<String>
|
|
|
|
|
- get() = ParsedList(this[Prop_Categories])
|
|
|
|
|
|
|
+ var Categories: MutableList<String>
|
|
|
|
|
+ get() = ParsedList(section[Prop_Categories])
|
|
|
set(value) {
|
|
set(value) {
|
|
|
- this[Prop_Categories] = value.joinToString { "$it;" }
|
|
|
|
|
|
|
+ section[Prop_Categories] = value.joinToString { "$it;" }
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- var Section.GtkTheme: String
|
|
|
|
|
- get() = ParsedString(this[Prop_GtkTheme])
|
|
|
|
|
|
|
+ class ThemeSectionScope(
|
|
|
|
|
+ override val section: Section
|
|
|
|
|
+ ) : ISectionScope {
|
|
|
|
|
+ var GtkTheme: String
|
|
|
|
|
+ get() = ParsedString(section[Prop_GtkTheme])
|
|
|
set(value) {
|
|
set(value) {
|
|
|
- this[Prop_GtkTheme] = value
|
|
|
|
|
|
|
+ section[Prop_GtkTheme] = value
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var Section.MetacityTheme: String
|
|
|
|
|
- get() = ParsedString(this[Prop_MetacityTheme])
|
|
|
|
|
|
|
+ var MetacityTheme: String
|
|
|
|
|
+ get() = ParsedString(section[Prop_MetacityTheme])
|
|
|
set(value) {
|
|
set(value) {
|
|
|
- this[Prop_MetacityTheme] = value
|
|
|
|
|
|
|
+ section[Prop_MetacityTheme] = value
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var Section.IconTheme: String
|
|
|
|
|
- get() = ParsedString(this[Prop_IconTheme])
|
|
|
|
|
|
|
+ var IconTheme: String
|
|
|
|
|
+ get() = ParsedString(section[Prop_IconTheme])
|
|
|
set(value) {
|
|
set(value) {
|
|
|
- this[Prop_IconTheme] = value
|
|
|
|
|
|
|
+ section[Prop_IconTheme] = value
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var Section.CursorTheme: String
|
|
|
|
|
- get() = ParsedString(this[Prop_CursorTheme])
|
|
|
|
|
|
|
+ var CursorTheme: String
|
|
|
|
|
+ get() = ParsedString(section[Prop_CursorTheme])
|
|
|
set(value) {
|
|
set(value) {
|
|
|
- this[Prop_CursorTheme] = value
|
|
|
|
|
|
|
+ section[Prop_CursorTheme] = value
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var Section.ButtonLayout: String
|
|
|
|
|
- get() = ParsedString(this[Prop_ButtonLayout])
|
|
|
|
|
|
|
+ var ButtonLayout: String
|
|
|
|
|
+ get() = ParsedString(section[Prop_ButtonLayout])
|
|
|
set(value) {
|
|
set(value) {
|
|
|
- this[Prop_ButtonLayout] = value
|
|
|
|
|
|
|
+ section[Prop_ButtonLayout] = value
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var Section.UseOverlayScrollbars: Boolean
|
|
|
|
|
- get() = ParsedBoolean(this[Prop_X_Ubuntu_UseOverlayScrollbars])
|
|
|
|
|
|
|
+ var UseOverlayScrollbars: Boolean
|
|
|
|
|
+ get() = ParsedBoolean(section[Prop_X_Ubuntu_UseOverlayScrollbars])
|
|
|
set(value) {
|
|
set(value) {
|
|
|
- this[Prop_X_Ubuntu_UseOverlayScrollbars] = value.toString()
|
|
|
|
|
|
|
+ section[Prop_X_Ubuntu_UseOverlayScrollbars] = value.toString()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ enum class DesktopFileType(val text: String) {
|
|
|
|
|
+ Unknown(""),
|
|
|
|
|
+ DesktopEntry("Desktop Entry"),
|
|
|
|
|
+ Application("Application"),
|
|
|
|
|
+ Theme("X-GNOME-Metatheme");
|
|
|
|
|
+
|
|
|
|
|
+ companion object {
|
|
|
|
|
+ operator fun invoke(
|
|
|
|
|
+ value: String?
|
|
|
|
|
+ ): DesktopFileType = value.orEmpty().trim().let { v ->
|
|
|
|
|
+ entries.firstOrNull { e -> e.text.contentEquals(v, true) } ?: Unknown
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fun mkDirs(): DesktopFile {
|
|
|
|
|
+ if (!file.parentFile.exists()) file.parentFile.mkdirs()
|
|
|
|
|
+ return this
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fun deleteFile(): DesktopFile {
|
|
|
|
|
+ if (file.exists()) file.delete()
|
|
|
|
|
+ return this
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fun createNewFile(): DesktopFile {
|
|
|
|
|
+ file.createNewFile()
|
|
|
|
|
+ return this
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ fun newFile(): DesktopFile {
|
|
|
|
|
+ mkDirs()
|
|
|
|
|
+ deleteFile()
|
|
|
|
|
+ createNewFile()
|
|
|
|
|
+ return this
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ companion object {
|
|
|
|
|
+ const val Prop_Type = "Type"
|
|
|
|
|
+ const val Prop_Version = "Version"
|
|
|
|
|
+ const val Prop_Path = "Path"
|
|
|
|
|
+ const val Prop_Name = "Name"
|
|
|
|
|
+ const val Prop_Comment = "Comment"
|
|
|
|
|
+ const val Prop_Exec = "Exec"
|
|
|
|
|
+ const val Prop_StartupNotify = "StartupNotify"
|
|
|
|
|
+ const val Prop_Terminal = "Terminal"
|
|
|
|
|
+ const val Prop_Icon = "Icon"
|
|
|
|
|
+ const val Prop_Categories = "Categories"
|
|
|
|
|
+ const val Prop_GenericName = "GenericName"
|
|
|
|
|
+ const val Prop_MimeType = "MimeType"
|
|
|
|
|
+ const val Prop_Actions = "Actions"
|
|
|
|
|
+ const val Prop_DBusActivatable = "DBusActivatable"
|
|
|
|
|
+ const val Prop_Encoding = "Encoding"
|
|
|
|
|
+
|
|
|
|
|
+ const val Prop_X_GNOME_UsesNotifications = "X-GNOME-UsesNotifications"
|
|
|
|
|
+ const val Prop_X_Purism_FormFactor = "X-Purism-FormFactor"
|
|
|
|
|
+ const val Prop_X_Unity_IconBackgroundColor = "X-Unity-IconBackgroundColor"
|
|
|
|
|
+ const val Prop_X_Ubuntu_Gettext_Domain = "X-Ubuntu-Gettext-Domain"
|
|
|
|
|
+
|
|
|
|
|
+ const val Prop_GtkTheme = "GtkTheme"
|
|
|
|
|
+ const val Prop_MetacityTheme = "MetacityTheme"
|
|
|
|
|
+ const val Prop_IconTheme = "IconTheme"
|
|
|
|
|
+ const val Prop_CursorTheme = "CursorTheme"
|
|
|
|
|
+ const val Prop_ButtonLayout = "ButtonLayout"
|
|
|
|
|
+ const val Prop_X_Ubuntu_UseOverlayScrollbars = "X-Ubuntu-UseOverlayScrollbars"
|
|
|
|
|
|
|
|
|
|
+ fun desktopFile(
|
|
|
|
|
+ file: File,
|
|
|
|
|
+ block: DesktopFile.() -> Unit
|
|
|
|
|
+ ) = DesktopFile(file).apply(block)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|