subscribe button

This commit is contained in:
Zlatin Balevsky
2019-07-02 14:35:52 +01:00
parent 8573ab2850
commit cafc5f582e
2 changed files with 42 additions and 2 deletions

View File

@ -14,6 +14,7 @@ import javax.inject.Inject
import com.muwire.core.Constants
import com.muwire.core.Core
import com.muwire.core.Persona
import com.muwire.core.SharedFile
import com.muwire.core.download.DownloadStartedEvent
import com.muwire.core.download.UIDownloadCancelledEvent
@ -26,6 +27,7 @@ import com.muwire.core.search.QueryEvent
import com.muwire.core.search.SearchEvent
import com.muwire.core.trust.TrustEvent
import com.muwire.core.trust.TrustLevel
import com.muwire.core.trust.TrustSubscriptionEvent
@ArtifactProviderFor(GriffonController)
class MainFrameController {
@ -184,7 +186,7 @@ class MainFrameController {
}
private void markTrust(String tableName, TrustLevel level, def list) {
int row = builder.getVariable(tableName).getSelectedRow()
int row = view.getSelectedTrustTablesRow(tableName)
if (row < 0)
return
core.eventBus.publish(new TrustEvent(persona : list[row], level : level))
@ -210,6 +212,15 @@ class MainFrameController {
markTrust("trusted-table", TrustLevel.NEUTRAL, model.trusted)
}
@ControllerAction
void subscribe() {
int row = view.getSelectedTrustTablesRow("trusted-table")
if (row < 0)
return
Persona p = model.trusted[row]
core.eventBus.publish(new TrustSubscriptionEvent(persona : p, subscribe : true))
}
void unshareSelectedFile() {
SharedFile sf = view.selectedSharedFile()
if (sf == null)

View File

@ -54,6 +54,7 @@ class MainFrameView {
def lastDownloadSortEvent
def lastSharedSortEvent
def lastWatchedSortEvent
def trustTablesSortEvents = [:]
void initUI() {
UISettings settings = application.context.get("ui-settings")
@ -267,6 +268,7 @@ class MainFrameView {
gridBagLayout()
button(text : "Mark Neutral", constraints : gbc(gridx: 0, gridy: 0), markNeutralFromTrustedAction)
button(text : "Mark Distrusted", constraints : gbc(gridx: 0, gridy:1), markDistrustedAction)
button(text : "Subscribe", constraints : gbc(gridx: 0, gridy : 2), subscribeAction)
}
}
panel (border : etchedBorder()){
@ -298,7 +300,10 @@ class MainFrameView {
closureColumn(header : "Distrusted", type: Integer, read : {it.bad.size()})
closureColumn(header : "Status", type: String, read : {it.status.toString()})
closureColumn(header : "Last Updated", type : String, read : {
String.valueOf(new Date(it.timestamp))
if (it.timestamp == 0)
return "Never"
else
return String.valueOf(new Date(it.timestamp))
})
}
}
@ -453,6 +458,20 @@ class MainFrameView {
}
})
// subscription table
def subscriptionTable = builder.getVariable("subscription-table")
subscriptionTable.rowSorter.addRowSorterListener({evt -> trustTablesSortEvents["subscription-table"] = evt})
subscriptionTable.rowSorter.setSortsOnUpdates(true)
// trusted table
def trustedTable = builder.getVariable("trusted-table")
trustedTable.rowSorter.addRowSortListener({evt -> trustTablesSortEvents["trusted-table"] = evt})
trustedTable.rowSorter.setSortsOnUpdates(true)
// distrusted table
def distrustedTable = builder.getVariable("distrusted-table")
distrustedTable.rowSorter.addRowSortListener({evt -> trustTablesSortEvents["distrusted-table"] = evt})
distrustedTable.rowSorter.setSortsOnUpdates(true)
}
private static void showPopupMenu(JPopupMenu menu, MouseEvent event) {
@ -617,4 +636,14 @@ class MainFrameView {
selectedRow = watchedTable.rowSorter.convertRowIndexToModel(selectedRow)
model.watched[selectedRow]
}
int getSelectedTrustTablesRow(String tableName) {
def table = builder.getVariable(tableName)
int selectedRow = table.getSelectedRow()
if (selectedRow < 0)
return -1
if (trustTablesSortEvents.get(tableName) != null)
selectedRow = table.rowSorter.convertRowIndexToModel(selectedRow)
selectedRow
}
}