From 69d3e9a5ceeb6d0a78916f1fc8b5dfad83552ca7 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Mon, 1 Dec 2025 18:29:06 +0100 Subject: [PATCH] redesign the New Feed dialog --- .../de/unixwork/rssreader/FeedConfig.kt | 170 ++++++++++++------ 1 file changed, 117 insertions(+), 53 deletions(-) diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedConfig.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedConfig.kt index 6cfdcc5..cd60091 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedConfig.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedConfig.kt @@ -1,5 +1,6 @@ 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 @@ -17,9 +18,16 @@ class FeedConfig(toplevel: Toplevel) { val password: UiString val cert: UiString val readstatus: UiList + val customUpdateInterval: UiInteger + val updateInterval: UiInteger + val autoDeleteOptions: UiList val maxItemAge: UiInteger + val itemContent: UiList companion object { + val CUSTOM_UPDATE_INTERVAL = 100000 + val AUTO_DELETE_ITEMS = 100001 + var PreviousGroup: FeedGroup? = null } @@ -31,69 +39,112 @@ class FeedConfig(toplevel: Toplevel) { 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(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(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(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(value = readstatus, hexpand = true, colspan = 2) { elm, col -> + elm + } + } + + row { + rlabel("Item Content", colspan = 2) + dropdown(value = itemContent, colspan = 2) { elm, col -> + elm + } + } + + row { + rlabel("Auto Delete Items", colspan = 2) + dropdown( + 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) } } } @@ -106,16 +157,29 @@ class FeedConfig(toplevel: Toplevel) { } 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 { @@ -126,15 +190,15 @@ class FeedConfig(toplevel: Toplevel) { 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() -- 2.47.3