]> uap-core.de Git - rssreader.git/commitdiff
move feed config dialog to a separate class
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 16 Oct 2025 14:23:56 +0000 (16:23 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Thu, 16 Oct 2025 14:23:56 +0000 (16:23 +0200)
rss-application/src/main/kotlin/de/unixwork/rssreader/FeedConfig.kt [new file with mode: 0644]
rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt

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 (file)
index 0000000..46525cb
--- /dev/null
@@ -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<FeedGroup>
+    val name: UiString
+    val urls: UiText
+    val user: UiString
+    val password: UiString
+    val cert: UiString
+    val readstatus: UiList<String>
+    val maxItemAge: UiInteger
+
+    init {
+        groups = window.ui.list<FeedGroup>()
+        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<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("Read Status", hfill = true)
+                    dropdown<String>(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
index e464f37ada67efbebcb660f02ed1a19ec94cf93d..43cd8c134de1d1ce6142cfa0e207074e3dc70b9e 100644 (file)
@@ -206,15 +206,7 @@ class MainWindow() {
     }
 
     private fun createFeedDialog() {
-        var groups: UiList<FeedGroup>? = null
-        var name: UiString? = null
-        var urls: UiText? = null
-        var user: UiString? = null
-        var password: UiString? = null
-        var cert: UiString? = null
-        var readstatus: UiList<String>? = 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<FeedGroup>()
-            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<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("Read Status", hfill = true)
-                    dropdown<String>(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()
     }