]> uap-core.de Git - rssreader.git/commitdiff
add Database method for updating feedcollections
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 7 Dec 2025 17:31:12 +0000 (18:31 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 7 Dec 2025 17:31:12 +0000 (18:31 +0100)
rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/FeedCollection.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/FeedConfig.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt

index f1fcb7e1680395298016ed3eb730f0dd375a75e7..92e26d4fee857c47f27ec6feb4c5750a8a56aaf0 100644 (file)
@@ -75,7 +75,8 @@ object Database {
                         auth_user VARCHAR,
                         auth_password VARCHAR,
                         certpath VARCHAR,
-                        last_update TIMESTAMP
+                        last_update TIMESTAMP,
+                        disabled BOOLEAN DEFAULT FALSE
                     )
                 """.trimIndent())
 
@@ -278,6 +279,62 @@ object Database {
         return feedCol
     }
 
+    public fun updateFeedCollection(
+        feed: FeedCollection,
+        uris: Collection<String>,
+        user: String? = null,
+        password: String? = null,
+        cert: String? = null)
+    {
+        dataSource.connection.use { conn ->
+            conn.prepareStatement("""
+                update feedcollections set
+                    internal_browser = ?,
+                    name = ?,
+                    update_interval = ?,
+                    max_item_age = ?,
+                    item_state_mode = ?,
+                    add_url_param = ?
+                where feedcollection_id = ?
+            """.trimIndent()).use { stmt ->
+                stmt.setBoolean(1, feed.internalBrowser)
+                stmt.setString(2, feed.name)
+                stmt.setLong(3, feed.updateInterval)
+                stmt.setInt(4, feed.maxItemAge)
+                stmt.setInt(5, feed.itemStateMode)
+                stmt.setString(6, feed.addUrlParam)
+                stmt.setInt(7, feed.id)
+                stmt.execute()
+            }
+
+            uris.forEach { uri ->
+                // disable all feeds first and then re-activate all feeds from the uri list
+                conn.prepareStatement("update feeds set disabled = TRUE where feedcollection_id = ?").use { stmt ->
+                    stmt.setInt(1, feed.id)
+                    stmt.execute()
+                }
+
+                conn.prepareStatement("""
+                    update feeds set
+                        url = ?,
+                        auth_user = ?,
+                        auth_password = ?,
+                        certpath = ?,
+                        disabled = FALSE
+                    where feedcollection_id = ? and url = ?
+                """.trimMargin()).use { stmt ->
+                    stmt.setString(1, uri)
+                    stmt.setString(2, user)
+                    stmt.setString(3, password)
+                    stmt.setString(4, cert)
+                    stmt.setInt(5, feed.id)
+                    stmt.setString(6, uri)
+                    stmt.execute()
+                }
+            }
+        }
+    }
+
     public fun getItems(feedCollection: FeedCollection, maxItems: Int) : MutableList<Item> {
         val items = mutableListOf<Item>()
 
index 5a0bba3cedb47daeb9c3e3075fd638759abf9c4c..a1ba7edaa9cd32f7d61b3d6dc6a9f393ffb90f6c 100644 (file)
@@ -4,11 +4,12 @@ import de.unixwork.ui.Document
 
 class FeedCollection(id: Int, name: String)  {
     val id = id
-    val name = name
+    var name = name
     var updateInterval: Long = 0
     var itemStateMode = 0
     var unreadItemsCount = 0
     var internalBrowser = false
+    var maxItemAge = 0
 
     var items = mutableListOf<Item>()
     var itemsLoaded = false
index be5c1d79dc2ebcb355f59767131cd495da5fa671..e6bfc704f0eae46673f96b97393f2aee55973a11 100644 (file)
@@ -11,6 +11,8 @@ import de.unixwork.ui.kotlin.openFileDialog
 class FeedConfig(toplevel: Toplevel) {
     val window = toplevel
 
+    var feedCollection: FeedCollection? = null
+
     val groups: UiList<FeedGroup>
     val name: UiString
     val urls: UiText
@@ -205,4 +207,55 @@ class FeedConfig(toplevel: Toplevel) {
             }
         }
     }
+
+    public fun updateFeed() {
+        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
+        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
+        }
+
+        var user: String? = null
+        var password: String? = null
+        var cert: String? = null
+
+        val u = user.toString()
+        val p = password.toString()
+        if(u.isNotBlank()) {
+            user = u
+        }
+        if(p.isNotBlank()) {
+            password = p
+        }
+
+        feedCollection?.let {
+            it.name = feedName
+            it.updateInterval = updateIntv
+            it.itemStateMode = itemStateMode
+            it.internalBrowser = internalBrowser
+
+            try {
+                Database.updateFeedCollection(it, uris, user, password, cert)
+            } catch (e: Exception) {
+                e.printStackTrace()
+            }
+        }
+    }
 }
\ No newline at end of file
index 7ef0f34b4935b7ae2d740ff1f19e12572fe550b4..37a373e70ba619bf6cb904b5eaa2f5b491a09b3f 100644 (file)
@@ -169,6 +169,12 @@ class MainWindow() {
         }
         separator()
         menuItem("Settings") { event ->
+            val evt = event.subListEventData
+            if(evt.sublistIndex >= 0 && evt.rowIndex >= 0) {
+                val feedCollection = sourceList.groups[evt.sublistIndex].feeds[evt.rowIndex]
+                editFeedDialog(feedCollection)
+            }
+
         }
     }
 
@@ -424,4 +430,29 @@ class MainWindow() {
     fun show() {
         window.show()
     }
+
+    fun editFeedDialog(collection: FeedCollection) {
+        var feedConfig: FeedConfig? = null
+        val w = dialogWindow(
+            parent = window.ui,
+            title = "Edit Feed",
+            defaultButton = 1,
+            lbutton1 = "Save",
+            rbutton4 = "Cancel",
+            modal = true,
+            showCloseButton = false,
+            width = 600,
+            height = 450,
+            onClick = { ev ->
+                if(ev.intValue == 1) {
+                    feedConfig?.updateFeed()
+                }
+                ev.`object`.close()
+            },
+            ui = null)
+        feedConfig = FeedConfig(w)
+        feedConfig.feedCollection = collection
+        feedConfig.createUI()
+        w.show()
+    }
 }
\ No newline at end of file