From d33f8eafaaacc08950791dee48df4b7ec7cd944f Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Fri, 14 Nov 2025 20:06:39 +0100 Subject: [PATCH] implement feed deletion --- .../kotlin/de/unixwork/rssreader/Database.kt | 13 +++++++++++- .../de/unixwork/rssreader/MainWindow.kt | 21 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) 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 ea7e136..22380bb 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt @@ -86,7 +86,7 @@ object Database { createStmt.addBatch(""" CREATE TABLE items ( item_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, - feed_id INT NOT NULL REFERENCES feeds(feed_id), + feed_id INT NOT NULL REFERENCES feeds(feed_id) ON DELETE CASCADE, title VARCHAR NOT NULL, link VARCHAR NOT NULL, category VARCHAR, @@ -402,6 +402,17 @@ object Database { return feeds } + public fun deleteFeedCollection(feedCollection: FeedCollection) { + dataSource.connection.use { conn -> + conn.prepareStatement(""" + delete from feedcollections where feedcollection_id = ? + """.trimIndent()).use { stmt -> + stmt.setInt(1, feedCollection.id) + stmt.execute() + } + } + } + public fun getPendingFeeds(defaultInterval: Int) : MutableList { val feeds = mutableListOf() 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 46258bb..21a7d74 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt @@ -11,6 +11,7 @@ import de.unixwork.ui.UiList import de.unixwork.ui.UiString import de.unixwork.ui.UiText import de.unixwork.ui.kotlin.Toplevel +import de.unixwork.ui.kotlin.dialog import de.unixwork.ui.kotlin.dialogWindow import de.unixwork.ui.kotlin.menuBuilder import de.unixwork.ui.kotlin.menuItem @@ -103,6 +104,26 @@ class MainWindow() { } menuItem("Delete") { event -> val evt = event.subListEventData + if(evt.sublistIndex >= 0 && evt.rowIndex >= 0) { + val feedCollection = sourceList.groups[evt.sublistIndex].feeds[evt.rowIndex] + dialog( + parent = window.ui, + title = "Delete Feed", + content = "Delete ${feedCollection.name}?", + button1Label = "Cancel", + button2Label = "Delete") + { event -> + if(event.intValue == 2) { + GlobalScope.launch(Dispatchers.IO) { + Database.deleteFeedCollection(feedCollection) + } + sourceList.groups[evt.sublistIndex].feeds.remove(feedCollection) + sourceList.groups[evt.sublistIndex].feeds.update() + } + } + } else { + // TODO + } } separator() menuItem("Settings") { event -> -- 2.47.3