package de.unixwork.rssreader
+import de.unixwork.ui.Text.passwordfield
import de.unixwork.ui.UiInteger
import de.unixwork.ui.UiList
import de.unixwork.ui.UiString
val password: UiString
val cert: UiString
val readstatus: UiList<String>
+ val customUpdateInterval: UiInteger
+ val updateInterval: UiInteger
+ val autoDeleteOptions: UiList<String>
val maxItemAge: UiInteger
+ val itemContent: UiList<String>
companion object {
+ val CUSTOM_UPDATE_INTERVAL = 100000
+ val AUTO_DELETE_ITEMS = 100001
+
var PreviousGroup: FeedGroup? = null
}
user = window.ui.string()
password = window.ui.string()
cert = window.ui.string()
+ customUpdateInterval = window.ui.integer()
+ updateInterval = window.ui.integer()
+ autoDeleteOptions = window.ui.list()
maxItemAge = window.ui.integer()
+ itemContent = window.ui.list()
// data
- maxItemAge.setIntValue(-1)
+ maxItemAge.setIntValue(100)
App.window?.sourceList?.groups?.let { groups.addAll(it) }
readstatus.add("Mark items individually")
readstatus.add("Mark entire feed when opened")
readstatus.add("Don't show number of unread items")
+
+ autoDeleteOptions.add("Default")
+ autoDeleteOptions.add("Never")
+ autoDeleteOptions.add("After max age")
+
+ itemContent.add("Description")
+ itemContent.add("Open item link in internal browser")
+
+ updateInterval.setIntValue(3600)
}
fun createUI() {
window() {
- grid(
- margin = 12,
- columnspacing = 8,
- rowspacing = 8,
- defhfill = true,
- defvfill = true,
- fill = true)
- {
- row {
- rlabel("Folder")
- dropdown<FeedGroup>(value = groups, hexpand = true, colspan = 2) { elm, column ->
- elm.name
+ tabview(margin = 12, fill = true) {
+ tab("Feed") {
+ grid(margin = 12, columnspacing = 8, rowspacing = 8, fill = true, defhfill = true, defvfill = true) {
+ row {
+ rlabel("Folder")
+ dropdown<FeedGroup>(value = groups, hexpand = true, colspan = 2) { elm, column ->
+ elm.name
+ }
+ }
+ row {
+ rlabel("Name")
+ textfield(value = name, hexpand = true, colspan = 2)
+ }
+ row {
+ rlabel("URLs", overrideDefaults = true, hfill = true) // overrideDefaults for disabling default vfill
+ textarea(value = urls, hexpand = true, vexpand = true, vfill = true, colspan = 2)
+ }
}
}
- row {
- rlabel("Name")
- textfield(value = name, hexpand = true, colspan = 2)
- }
- row {
- rlabel("URLs", overrideDefaults = true, hfill = true) // overrideDefaults for disabling default vfill
- textarea(value = urls, hexpand = true, vexpand = true, vfill = true, colspan = 2)
- }
- row {
- rlabel("Read Status", hfill = true)
- dropdown<String>(value = readstatus, hfill = true, colspan = 2) { elm, col ->
- elm
+
+ tab("Settings") {
+ grid(margin = 12, columnspacing = 8, rowspacing = 8, fill = true, defhfill = true, defvfill = true) {
+ row {
+ rlabel("Read Status", colspan = 2)
+ dropdown<String>(value = readstatus, hexpand = true, colspan = 2) { elm, col ->
+ elm
+ }
+ }
+
+ row {
+ rlabel("Item Content", colspan = 2)
+ dropdown<String>(value = itemContent, colspan = 2) { elm, col ->
+ elm
+ }
+ }
+
+ row {
+ rlabel("Auto Delete Items", colspan = 2)
+ dropdown<String>(
+ value = autoDeleteOptions,
+ colspan = 2,
+ onActivate = { event ->
+ if(event.intValue == 2) {
+ window.ui.setState(FeedConfig.AUTO_DELETE_ITEMS)
+ } else {
+ window.ui.unsetState(FeedConfig.AUTO_DELETE_ITEMS)
+ }
+ }
+ ) { elm, col ->
+ elm
+ }
+ }
+
+ row {
+ rlabel("Max Age", colspan = 2)
+ spinbox(intValue = maxItemAge, min = 1.0, max = 100000.0, step = 1.0,
+ states = intArrayOf(FeedConfig.AUTO_DELETE_ITEMS))
+ llabel("Days")
+ }
+
+ row {
+ checkbox(value = customUpdateInterval, enableState = FeedConfig.CUSTOM_UPDATE_INTERVAL)
+ rlabel("Custom Update Interval")
+
+ spinbox(intValue = updateInterval, min = 1.0, max = 100000.0, step = 1.0,
+ states = intArrayOf(FeedConfig.CUSTOM_UPDATE_INTERVAL))
+ llabel("Seconds")
+ }
}
}
- row {
- rlabel("Max Item Age (Days)")
- spinbox(intValue = maxItemAge, min = -1.0, max = 100000.0, step = 1.0, colspan = 2)
- }
- row {
- rlabel("User")
- textfield(value = user, hexpand = true, colspan = 2)
- }
- row {
- rlabel("Password")
- passwordField(value = password, hexpand = true, colspan = 2)
- }
- row {
- rlabel("Client Certificate")
- textfield(value = cert, hexpand = true)
- button(icon = "document-open") {
- openFileDialog(ui) { event ->
- val files = event.fileListEventData;
- if(files.size > 0) {
- cert!!.setString(files[0])
- }
+ tab("Authentication") {
+ grid(margin = 12, columnspacing = 8, rowspacing = 8, fill = true, defhfill = true, defvfill = true) {
+ row {
+ rlabel("User")
+ textfield(value = user, hexpand = true, colspan = 2)
+ }
+ row {
+ rlabel("Password")
+ passwordField(value = password, hexpand = true, colspan = 2)
}
}
}
}
fun addFeed() {
- val parent = groups?.selected
+ val parent = groups.selected
val feedName = name.toString()
val urlStr = urls.toString()
val uris = urlStr.split("\n").map { it.trim() }.filter { it.isNotBlank() }
- var itemStateMode = readstatus?.selectedIndex ?: 0
- val maxItemAge = maxItemAge?.intValue() ?: -1
+ var itemStateMode = readstatus.selectedIndex
+ val internalBrowser = itemContent.selectedIndex == 1
+ var autoDelete = autoDeleteOptions.selectedIndex
+ var maxItemAge = maxItemAge.intValue()
+ var updateIntv = updateInterval.longValue()
+ if(!customUpdateInterval.booleanValue()) {
+ updateIntv = 0
+ }
+ if(autoDelete == 0) {
+ // default
+ maxItemAge = 0
+ } else if(autoDelete == 1) {
+ // never
+ maxItemAge = -1
+ }
if(itemStateMode < 0 || itemStateMode > 2) {
itemStateMode = 0
}
- println("groupSel: ${groups?.selectedIndex}, feedName: $feedName, urlStr: $urlStr")
+ println("groupSel: ${groups.selectedIndex}, feedName: $feedName, urlStr: $urlStr")
parent?.let {
FeedConfig.PreviousGroup = it
try {
user = user.toString(),
password = password.toString(),
cert = cert.toString(),
- internalBrowser = false,
- updateInterval = 0, // TODO
+ internalBrowser = internalBrowser,
+ updateInterval = updateIntv,
maxItemAge = maxItemAge,
itemStateMode = itemStateMode
)
parent.feeds.update()
- App.window?.newFeedPrevGroup = groups?.selectedIndex ?: 0
+ App.window?.newFeedPrevGroup = groups.selectedIndex
println("new prev group: $App.window.newFeedPrevGroup")
} catch (e: Exception) {
e.printStackTrace()