Show trust status in View Profile and enable only relevant buttons. GitHub issue #152

dbus-notify
Zlatin Balevsky 2022-06-24 14:51:50 +01:00
parent 8802e70226
commit 9314f9c7e3
No known key found for this signature in database
GPG Key ID: A72832072D525E41
2 changed files with 27 additions and 3 deletions

View File

@ -7,6 +7,8 @@ import com.muwire.core.profile.MWProfileFetchEvent
import com.muwire.core.profile.MWProfileFetchStatus import com.muwire.core.profile.MWProfileFetchStatus
import com.muwire.core.profile.MWProfileHeader import com.muwire.core.profile.MWProfileHeader
import com.muwire.core.profile.UIProfileFetchEvent import com.muwire.core.profile.UIProfileFetchEvent
import com.muwire.core.trust.TrustEvent
import com.muwire.core.trust.TrustLevel
import com.muwire.gui.HTMLSanitizer import com.muwire.gui.HTMLSanitizer
import griffon.core.artifact.GriffonModel import griffon.core.artifact.GriffonModel
import griffon.inject.MVCMember import griffon.inject.MVCMember
@ -29,6 +31,8 @@ class ViewProfileModel {
@Observable MWProfileFetchStatus status @Observable MWProfileFetchStatus status
MWProfile profile MWProfile profile
@Observable TrustLevel trustLevel
private boolean registered private boolean registered
void mvcGroupInit(Map<String, String> args) { void mvcGroupInit(Map<String, String> args) {
@ -36,6 +40,9 @@ class ViewProfileModel {
profileHeader = profile.getHeader() profileHeader = profile.getHeader()
if (profileHeader != null) if (profileHeader != null)
profileTitle = HTMLSanitizer.sanitize(profileHeader.getTitle()) profileTitle = HTMLSanitizer.sanitize(profileHeader.getTitle())
setTrustLevel(core.getTrustService().getLevel(persona.getDestination()))
core.getEventBus().register(TrustEvent.class, this)
} }
boolean fetchEnabled() { boolean fetchEnabled() {
@ -54,6 +61,7 @@ class ViewProfileModel {
} }
void mvcGroupDestroy() { void mvcGroupDestroy() {
core.getEventBus().unregister(TrustEvent.class, this)
if (registered) if (registered)
core.getEventBus().unregister(MWProfileFetchEvent.class, this) core.getEventBus().unregister(MWProfileFetchEvent.class, this)
} }
@ -70,4 +78,12 @@ class ViewProfileModel {
} }
} }
} }
void onTrustEvent(TrustEvent event) {
if (event.persona != persona)
return
runInsideUIAsync {
trustLevel = event.level
}
}
} }

View File

@ -2,6 +2,7 @@ package com.muwire.gui.profile
import com.muwire.core.profile.MWProfile import com.muwire.core.profile.MWProfile
import com.muwire.core.profile.MWProfileFetchStatus import com.muwire.core.profile.MWProfileFetchStatus
import com.muwire.core.trust.TrustLevel
import com.muwire.gui.HTMLSanitizer import com.muwire.gui.HTMLSanitizer
import javax.imageio.ImageIO import javax.imageio.ImageIO
@ -104,16 +105,23 @@ class ViewProfileView {
panel(constraints: BorderLayout.SOUTH) { panel(constraints: BorderLayout.SOUTH) {
gridLayout(rows:1, cols: 4) gridLayout(rows:1, cols: 4)
panel { panel {
label(text : bind { model.status == null ? "" : trans(model.status.name())}) borderLayout()
panel(constraints: BorderLayout.WEST) {
label(text: trans("YOUR_TRUST") + " : ")
label(text: bind {trans(model.trustLevel.name())})
}
panel(constraints: BorderLayout.EAST) {
label(text: bind { model.status == null ? "" : trans(model.status.name()) })
}
} }
panel { panel {
button(text: trans("COPY_FULL_ID"), copyFullAction) button(text: trans("COPY_FULL_ID"), copyFullAction)
} }
panel { panel {
button(text: trans("ADD_CONTACT"), toolTipText: trans("TOOLTIP_PROFILE_VIEWER_ADD_CONTACT"), button(text: trans("ADD_CONTACT"), toolTipText: trans("TOOLTIP_PROFILE_VIEWER_ADD_CONTACT"),
addContactAction) enabled: bind {model.trustLevel != TrustLevel.TRUSTED}, addContactAction)
button(text: trans("PROFILE_VIEWER_BLOCK"), toolTipText: trans("TOOLTIP_PROFILE_VIEWER_BLOCK"), button(text: trans("PROFILE_VIEWER_BLOCK"), toolTipText: trans("TOOLTIP_PROFILE_VIEWER_BLOCK"),
blockAction) enabled: bind {model.trustLevel != TrustLevel.DISTRUSTED}, blockAction)
} }
panel { panel {
button(text : trans("CLOSE"), closeAction) button(text : trans("CLOSE"), closeAction)