From 01d14e83823f1cacc3136591cb628c0089fb1c93 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Sat, 15 Nov 2025 13:16:11 +0100 Subject: [PATCH] implement feed group deletion --- .../kotlin/de/unixwork/rssreader/Database.kt | 11 +++++ .../de/unixwork/rssreader/FeedSourceList.kt | 7 +++ .../de/unixwork/rssreader/MainWindow.kt | 44 ++++++++++++++++++- .../java/de/unixwork/ui/ListViewBuilder.java | 2 +- .../java/de/unixwork/ui/ToggleBuilder.java | 9 ++++ .../kotlin/de/unixwork/ui/kotlin/Toplevel.kt | 10 +++++ 6 files changed, 81 insertions(+), 2 deletions(-) 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 22380bb..820b312 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt @@ -413,6 +413,17 @@ object Database { } } + public fun deleteFeedGroup(feedGroup: FeedGroup) { + dataSource.connection.use { conn -> + conn.prepareStatement(""" + delete from groups where group_id = ? + """.trimIndent()).use { stmt -> + stmt.setInt(1, feedGroup.id) + stmt.execute() + } + } + } + public fun getPendingFeeds(defaultInterval: Int) : MutableList { val feeds = mutableListOf() diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedSourceList.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedSourceList.kt index 873bd50..cb3c696 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedSourceList.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedSourceList.kt @@ -31,6 +31,13 @@ class FeedSourceList : Document() { groups.add(group) } + fun removeFeedGroup(group: FeedGroup) { + val index = groups.indexOf(group) + groups.removeAt(index) + feeds.remove(index) + feeds.update() + } + fun swapFeedCollections(group: Int, feed1: Int, feed2: Int) { if(group < 0 || group >= groups.size) { return 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 21a7d74..438006f 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt @@ -1,6 +1,7 @@ package de.unixwork.rssreader import de.unixwork.ui.ColumnType +import de.unixwork.ui.LabelStyle import de.unixwork.ui.LinkButtonType import de.unixwork.ui.Menu import de.unixwork.ui.SubListItem @@ -122,7 +123,48 @@ class MainWindow() { } } } else { - // TODO + val feedGroup = sourceList.groups[evt.sublistIndex] + var move:UiInteger? = null + var groups:UiList? = null + val dialog = dialogWindow( + parent = window.ui, + title = "Delete", + lbutton1 = "Cancel", + rbutton4 = "Delete", + defaultButton = 4, + showCloseButton = false, + onClick = { ev -> + if(ev.intValue == 4) { + sourceList.removeFeedGroup(feedGroup) + if(move!!.booleanValue() && groups!!.selected != null) { + // move and delete + } else { + // delete + GlobalScope.launch(Dispatchers.IO) { + Database.deleteFeedGroup(feedGroup) + } + } + } + ev.`object`.close() + }) + { + move = ui.integer() + groups = ui.list() + groups.addAll(sourceList.groups.filter { it != feedGroup }) + + grid(margin = 12, columnspacing = 8, rowspacing = 8, fill = true) { + row { + label(label = "Delete ${feedGroup.name}?", colspan = 2, style = LabelStyle.TITLE, hexpand = true, hfill = true) + } + row { + checkbox(label = "Move feeds to other group", value = move, vfill = true, enableState = 1) + dropdown(value = groups, vfill = true, states = intArrayOf(1)) { elm, i -> + elm.name + } + } + } + } + dialog.show() } } separator() diff --git a/ui-java/src/main/java/de/unixwork/ui/ListViewBuilder.java b/ui-java/src/main/java/de/unixwork/ui/ListViewBuilder.java index 8bdc17f..2818135 100644 --- a/ui-java/src/main/java/de/unixwork/ui/ListViewBuilder.java +++ b/ui-java/src/main/java/de/unixwork/ui/ListViewBuilder.java @@ -286,7 +286,7 @@ public class ListViewBuilder extends AbstractWidgetBuilder { if(states != null) { MemorySegment st = arena.allocate(ValueLayout.JAVA_INT, states.length); MemorySegment.copy(states, 0, st, ValueLayout.JAVA_INT, 0, states.length); - ui.list_args_set_groups.invoke(args, st); + ui.list_args_set_groups.invoke(args, st, states.length); } return args; diff --git a/ui-java/src/main/java/de/unixwork/ui/ToggleBuilder.java b/ui-java/src/main/java/de/unixwork/ui/ToggleBuilder.java index 2c2324d..9b82236 100644 --- a/ui-java/src/main/java/de/unixwork/ui/ToggleBuilder.java +++ b/ui-java/src/main/java/de/unixwork/ui/ToggleBuilder.java @@ -27,6 +27,7 @@ public class ToggleBuilder extends AbstractWidgetBuilder { private int labelType; private String varname; private UiInteger value; + private int enableState; private EventHandler onChange; private int[] states; @@ -141,6 +142,11 @@ public class ToggleBuilder extends AbstractWidgetBuilder { return this; } + public ToggleBuilder enableState(int enableState) { + this.enableState = enableState; + return this; + } + public ToggleBuilder onChange(EventHandler onChange) { this.onChange = onChange; return this; @@ -223,6 +229,9 @@ public class ToggleBuilder extends AbstractWidgetBuilder { if(value != null) { ui.toggle_args_set_value.invoke(args, value.valuePtr); } + if(enableState > 0) { + ui.toggle_args_set_enablegroup.invoke(args, enableState); + } if(states != null) { MemorySegment st = arena.allocate(ValueLayout.JAVA_INT, states.length); MemorySegment.copy(states, 0, st, ValueLayout.JAVA_INT, 0, states.length); diff --git a/ui-kotlin/src/main/kotlin/de/unixwork/ui/kotlin/Toplevel.kt b/ui-kotlin/src/main/kotlin/de/unixwork/ui/kotlin/Toplevel.kt index 130ad5b..f4784b7 100644 --- a/ui-kotlin/src/main/kotlin/de/unixwork/ui/kotlin/Toplevel.kt +++ b/ui-kotlin/src/main/kotlin/de/unixwork/ui/kotlin/Toplevel.kt @@ -1001,6 +1001,7 @@ class Toplevel(obj: UiObject) { tooltip: String? = null, varname: String? = null, value: UiInteger? = null, + enableState: Int = 0, fill: Boolean = false, hexpand: Boolean = false, vexpand: Boolean = false, @@ -1031,6 +1032,9 @@ class Toplevel(obj: UiObject) { value?.let { button.value(it) } + if(enableState > 0) { + button.enableState(enableState) + } if(fill) { button.fill(fill); } @@ -1091,6 +1095,7 @@ class Toplevel(obj: UiObject) { tooltip: String? = null, varname: String? = null, value: UiInteger? = null, + enableState: Int = 0, fill: Boolean = false, hexpand: Boolean = false, vexpand: Boolean = false, @@ -1116,6 +1121,7 @@ class Toplevel(obj: UiObject) { tooltip = tooltip, varname = varname, value = value, + enableState = enableState, fill = fill, hexpand = hexpand, vexpand = vexpand, @@ -1142,6 +1148,7 @@ class Toplevel(obj: UiObject) { tooltip: String? = null, varname: String? = null, value: UiInteger? = null, + enableState: Int = 0, fill: Boolean = false, hexpand: Boolean = false, vexpand: Boolean = false, @@ -1167,6 +1174,7 @@ class Toplevel(obj: UiObject) { tooltip = tooltip, varname = varname, value = value, + enableState = enableState, fill = fill, hexpand = hexpand, vexpand = vexpand, @@ -1193,6 +1201,7 @@ class Toplevel(obj: UiObject) { tooltip: String? = null, varname: String? = null, value: UiInteger? = null, + enableState: Int = 0, fill: Boolean = false, hexpand: Boolean = false, vexpand: Boolean = false, @@ -1218,6 +1227,7 @@ class Toplevel(obj: UiObject) { tooltip = tooltip, varname = varname, value = value, + enableState = enableState, fill = fill, hexpand = hexpand, vexpand = vexpand, -- 2.47.3