From: Olaf Wintermann Date: Sun, 7 Dec 2025 17:31:12 +0000 (+0100) Subject: add Database method for updating feedcollections X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=977b506478811b64b1c2697be4c716f7e7c2b156;p=rssreader.git add Database method for updating feedcollections --- diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt index f1fcb7e..92e26d4 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt @@ -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, + 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 { val items = mutableListOf() diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedCollection.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedCollection.kt index 5a0bba3..a1ba7ed 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedCollection.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedCollection.kt @@ -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() var itemsLoaded = false 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 be5c1d7..e6bfc70 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedConfig.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedConfig.kt @@ -11,6 +11,8 @@ import de.unixwork.ui.kotlin.openFileDialog class FeedConfig(toplevel: Toplevel) { val window = toplevel + var feedCollection: FeedCollection? = null + val groups: UiList 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 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 7ef0f34..37a373e 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt @@ -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