From: Olaf Wintermann Date: Thu, 16 Oct 2025 14:23:56 +0000 (+0200) Subject: move feed config dialog to a separate class X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=683b7d31c12a988b0138b766c5e74918c1f01a7c;p=rssreader.git move feed config dialog to a separate class --- diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedConfig.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedConfig.kt new file mode 100644 index 0000000..46525cb --- /dev/null +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedConfig.kt @@ -0,0 +1,138 @@ +package de.unixwork.rssreader + +import de.unixwork.ui.Button.button +import de.unixwork.ui.UiInteger +import de.unixwork.ui.UiList +import de.unixwork.ui.UiObject +import de.unixwork.ui.UiString +import de.unixwork.ui.UiText +import de.unixwork.ui.kotlin.Toplevel +import de.unixwork.ui.kotlin.dialogWindow +import de.unixwork.ui.kotlin.openFileDialog + +class FeedConfig(toplevel: Toplevel) { + val window = toplevel + + val groups: UiList + val name: UiString + val urls: UiText + val user: UiString + val password: UiString + val cert: UiString + val readstatus: UiList + val maxItemAge: UiInteger + + init { + groups = window.ui.list() + name = window.ui.string() + urls = window.ui.text() + readstatus = window.ui.list() + user = window.ui.string() + password = window.ui.string() + cert = window.ui.string() + maxItemAge = window.ui.integer() + + // data + maxItemAge.setIntValue(-1) + 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") + } + + fun createUI() { + window() { + grid( + margin = 12, + columnspacing = 8, + rowspacing = 8, + defhfill = true, + defvfill = true, + fill = true) + { + row { + rlabel("Category") + 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("Read Status", hfill = true) + dropdown(value = readstatus, hfill = true, colspan = 2) { elm, col -> + elm + } + } + 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]) + } + } + } + } + } + } + } + + fun addFeed() { + 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 + if(itemStateMode < 0 || itemStateMode > 2) { + itemStateMode = 0 + } + println("groupSel: ${groups?.selectedIndex}, feedName: $feedName, urlStr: $urlStr") + parent?.let { + try { + val feedCol = Database.newFeeds( + parent = it, + name = feedName, + uris = uris, + user = user.toString(), + password = password.toString(), + cert = cert.toString(), + internalBrowser = false, + updateInterval = 0, // TODO + maxItemAge = maxItemAge, + itemStateMode = itemStateMode + ) + + parent.feeds.update() + + App.window?.newFeedPrevGroup = groups?.selectedIndex ?: 0 + println("new prev group: $App.window.newFeedPrevGroup") + } catch (e: Exception) { + e.printStackTrace() + } + } + } +} \ No newline at end of file diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt index e464f37..43cd8c1 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt @@ -206,15 +206,7 @@ class MainWindow() { } private fun createFeedDialog() { - var groups: UiList? = null - var name: UiString? = null - var urls: UiText? = null - var user: UiString? = null - var password: UiString? = null - var cert: UiString? = null - var readstatus: UiList? = null - var maxItemAge: UiInteger? = null - + var feedConfig: FeedConfig? = null val w = dialogWindow( parent = window.ui, title = "Add Feed", @@ -227,118 +219,13 @@ class MainWindow() { height = 450, onClick = { ev -> if(ev.intValue == 1) { - 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 - if(itemStateMode < 0 || itemStateMode > 2) { - itemStateMode = 0 - } - println("groupSel: ${groups?.selectedIndex}, feedName: $feedName, urlStr: $urlStr") - parent?.let { - try { - val feedCol = Database.newFeeds( - parent = it, - name = feedName, - uris = uris, - user = user.toString(), - password = password.toString(), - cert = cert.toString(), - internalBrowser = false, - updateInterval = 0, // TODO - maxItemAge = maxItemAge, - itemStateMode = itemStateMode - ) - - parent.feeds.update() - - newFeedPrevGroup = groups?.selectedIndex ?: 0 - println("new prev group: $newFeedPrevGroup") - } catch (e: Exception) { - e.printStackTrace() - } - } + feedConfig?.addFeed() } ev.`object`.close() - }) - { - // data - groups = ui.list() - name = ui.string() - urls = ui.text() - readstatus = ui.list() - user = ui.string() - password = ui.string() - cert = ui.string() - maxItemAge = ui.integer() - maxItemAge?.setIntValue(-1) - - groups.addAll(sourceList.groups) - println("prev group: $newFeedPrevGroup") - - readstatus.add("Mark items individually") - readstatus.add("Mark entire feed when opened") - readstatus.add("Don't show number of unread items") - - // UI - grid( - margin = 12, - columnspacing = 8, - rowspacing = 8, - defhfill = true, - defvfill = true, - fill = true) - { - row { - rlabel("Category") - 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("Read Status", hfill = true) - dropdown(value = readstatus, hfill = true, colspan = 2) { elm, col -> - elm - } - } - 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]) - } - } - } - } - } - } - groups?.setSelectedIndex(newFeedPrevGroup) + }, + ui = null) + feedConfig = FeedConfig(w) + feedConfig.createUI() w.show() }