auth_user VARCHAR,
auth_password VARCHAR,
certpath VARCHAR,
- last_update TIMESTAMP
+ last_update TIMESTAMP,
+ disabled BOOLEAN DEFAULT FALSE
)
""".trimIndent())
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>()
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
class FeedConfig(toplevel: Toplevel) {
val window = toplevel
+ var feedCollection: FeedCollection? = null
+
val groups: UiList<FeedGroup>
val name: UiString
val urls: UiText
}
}
}
+
+ 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
}
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)
+ }
+
}
}
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