mirror of https://github.com/zlatinb/muwire
add contact dialog
parent
500be6945b
commit
2cffe59ec6
|
@ -171,4 +171,9 @@ mvcGroups {
|
|||
view = "com.muwire.gui.NewMessageView"
|
||||
controller = "com.muwire.gui.NewMessageController"
|
||||
}
|
||||
'add-contact' {
|
||||
model = "com.muwire.gui.AddContactModel"
|
||||
view = "com.muwire.gui.AddContactView"
|
||||
controller = "com.muwire.gui.AddContactController"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package com.muwire.gui
|
||||
|
||||
import griffon.core.artifact.GriffonController
|
||||
import static com.muwire.gui.Translator.trans
|
||||
import griffon.core.controller.ControllerAction
|
||||
import griffon.inject.MVCMember
|
||||
import griffon.metadata.ArtifactProviderFor
|
||||
import net.i2p.data.Base64
|
||||
|
||||
import javax.annotation.Nonnull
|
||||
import javax.swing.JOptionPane
|
||||
|
||||
import com.muwire.core.Persona
|
||||
import com.muwire.core.trust.TrustEvent
|
||||
import com.muwire.core.trust.TrustLevel
|
||||
|
||||
@ArtifactProviderFor(GriffonController)
|
||||
class AddContactController {
|
||||
@MVCMember @Nonnull
|
||||
AddContactModel model
|
||||
@MVCMember @Nonnull
|
||||
AddContactView view
|
||||
|
||||
@ControllerAction
|
||||
void add() {
|
||||
String text = view.idArea.getText().trim()
|
||||
Persona p
|
||||
try {
|
||||
p = new Persona(new ByteArrayInputStream(Base64.decode(text)))
|
||||
TrustEvent e = new TrustEvent(persona : p, level : TrustLevel.TRUSTED, reason : view.reasonArea.getText())
|
||||
model.core.eventBus.publish(e)
|
||||
cancel()
|
||||
} catch (Exception e) {
|
||||
JOptionPane.showMessageDialog(null, trans("ADD_CONTACT_INVALID_ID_BODY"),
|
||||
trans("ADD_CONTACT_INVALID_ID_TITLE"), JOptionPane.WARNING_MESSAGE)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@ControllerAction
|
||||
void cancel() {
|
||||
view.dialog.setVisible(false)
|
||||
mvcGroup.destroy()
|
||||
}
|
||||
}
|
|
@ -243,6 +243,13 @@ class MainFrameController {
|
|||
model.clearButtonEnabled = false
|
||||
|
||||
}
|
||||
|
||||
@ControllerAction
|
||||
void addContact() {
|
||||
def params = [:]
|
||||
params.core = core
|
||||
mvcGroup.createMVCGroup("add-contact", params)
|
||||
}
|
||||
|
||||
private void markTrust(String tableName, TrustLevel level, def list) {
|
||||
int row = view.getSelectedTrustTablesRow(tableName)
|
||||
|
|
|
@ -191,6 +191,7 @@ VIEW_CERTIFICATES=View Certificates
|
|||
# Trust pane
|
||||
TRUSTED_USERS=Trusted Users
|
||||
REASON=Reason
|
||||
ADD_CONTACT=Add Contact
|
||||
SUBSCRIBE=Subscribe
|
||||
MARK_NEUTRAL=Mark Neutral
|
||||
MARK_DISTRUSTED=Mark Distrusted
|
||||
|
@ -593,3 +594,9 @@ SUBJECT_TOO_LONG=Subject too long
|
|||
SUBJECT_TOO_LONG_BODY=Your subject is {0} characters. The maximum length is {1} characters.
|
||||
NO_RECIPIENTS=No Recipients
|
||||
NO_RECIPIENTS_BODY=Please add at least one recipient.
|
||||
|
||||
## Add Contact dialog
|
||||
ADD_CONTACT_TITLE=Add a new contact
|
||||
ADD_CONTACT_BODY=Copy-paste the full MuWire ID of your new contact below.
|
||||
ADD_CONTACT_INVALID_ID_TITLE=Invalid full MuWire ID
|
||||
ADD_CONTACT_INVALID_ID_BODY=You have entered an invalid full MuWire ID.
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package com.muwire.gui
|
||||
|
||||
import com.muwire.core.Core
|
||||
|
||||
import griffon.core.artifact.GriffonModel
|
||||
import griffon.transform.Observable
|
||||
import griffon.metadata.ArtifactProviderFor
|
||||
|
||||
@ArtifactProviderFor(GriffonModel)
|
||||
class AddContactModel {
|
||||
Core core
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package com.muwire.gui
|
||||
|
||||
import griffon.core.artifact.GriffonView
|
||||
|
||||
import static com.muwire.gui.Translator.trans
|
||||
|
||||
import java.awt.BorderLayout
|
||||
import java.awt.event.WindowAdapter
|
||||
import java.awt.event.WindowEvent
|
||||
|
||||
import griffon.inject.MVCMember
|
||||
import griffon.metadata.ArtifactProviderFor
|
||||
|
||||
import javax.swing.JDialog
|
||||
import javax.swing.JTextArea
|
||||
import javax.swing.SwingConstants
|
||||
import javax.annotation.Nonnull
|
||||
|
||||
@ArtifactProviderFor(GriffonView)
|
||||
class AddContactView {
|
||||
@MVCMember @Nonnull
|
||||
FactoryBuilderSupport builder
|
||||
@MVCMember @Nonnull
|
||||
AddContactModel model
|
||||
|
||||
def mainFrame
|
||||
def dialog
|
||||
def p
|
||||
JTextArea idArea
|
||||
JTextArea reasonArea
|
||||
|
||||
void initUI() {
|
||||
mainFrame = application.windowManager.findWindow("main-frame")
|
||||
dialog = new JDialog(mainFrame, trans("ADD_CONTACT_TITLE"), true)
|
||||
dialog.setResizable(false)
|
||||
|
||||
p = builder.panel {
|
||||
gridLayout(rows : 2, cols : 1)
|
||||
panel {
|
||||
borderLayout()
|
||||
panel(constraints : BorderLayout.NORTH) {
|
||||
label(text : trans("ADD_CONTACT_BODY"))
|
||||
}
|
||||
scrollPane(constraints : BorderLayout.CENTER) {
|
||||
idArea = textArea(editable : true, lineWrap : true, wrapStyleWord : true)
|
||||
}
|
||||
}
|
||||
panel {
|
||||
borderLayout()
|
||||
panel(constraints : BorderLayout.NORTH) {
|
||||
label(text : trans("ENTER_REASON_OPTIONAL"))
|
||||
}
|
||||
scrollPane(constraints : BorderLayout.CENTER) {
|
||||
reasonArea = textArea(editable : true, lineWrap : true, wrapStyleWord : true)
|
||||
}
|
||||
panel(constraints : BorderLayout.SOUTH) {
|
||||
button(text : trans("ADD_CONTACT"), addAction)
|
||||
button(text : trans("CANCEL"), cancelAction)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void mvcGroupInit(Map<String,String> args) {
|
||||
dialog.getContentPane().add(p)
|
||||
dialog.pack()
|
||||
dialog.setLocationRelativeTo(mainFrame)
|
||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE)
|
||||
dialog.addWindowListener( new WindowAdapter() {
|
||||
public void windowClosed(WindowEvent e) {
|
||||
mvcGroup.destroy()
|
||||
}
|
||||
})
|
||||
dialog.show()
|
||||
}
|
||||
}
|
|
@ -614,13 +614,23 @@ class MainFrameView {
|
|||
}
|
||||
}
|
||||
panel (constraints : BorderLayout.SOUTH) {
|
||||
gridBagLayout()
|
||||
button(text : trans("SUBSCRIBE"), enabled : bind {model.subscribeButtonEnabled}, constraints : gbc(gridx: 0, gridy : 0), subscribeAction)
|
||||
button(text : trans("MARK_NEUTRAL"), enabled : bind {model.markNeutralFromTrustedButtonEnabled}, constraints : gbc(gridx: 1, gridy: 0), markNeutralFromTrustedAction)
|
||||
button(text : trans("MARK_DISTRUSTED"), enabled : bind {model.markDistrustedButtonEnabled}, constraints : gbc(gridx: 2, gridy:0), markDistrustedAction)
|
||||
button(text : trans("BROWSE"), enabled : bind{model.browseFromTrustedButtonEnabled}, constraints:gbc(gridx:3, gridy:0), browseFromTrustedAction)
|
||||
button(text : trans("CHAT"), enabled : bind{model.chatFromTrustedButtonEnabled} ,constraints : gbc(gridx:4, gridy:0), chatFromTrustedAction)
|
||||
button(text : trans("MESSAGE_VERB"), enabled : bind{model.messageFromTrustedButtonEnabled}, constraints : gbc(gridx:5, gridy:0), messageFromTrustedAction)
|
||||
gridLayout(rows : 1, cols : 3)
|
||||
panel (border : etchedBorder()){
|
||||
gridBagLayout()
|
||||
button(text : trans("ADD_CONTACT"), constraints : gbc(gridx : 0, gridy : 0), addContactAction)
|
||||
button(text : trans("SUBSCRIBE"), enabled : bind {model.subscribeButtonEnabled}, constraints : gbc(gridx: 1, gridy : 0), subscribeAction)
|
||||
}
|
||||
panel (border : etchedBorder()){
|
||||
gridBagLayout()
|
||||
button(text : trans("MARK_NEUTRAL"), enabled : bind {model.markNeutralFromTrustedButtonEnabled}, constraints : gbc(gridx: 0, gridy: 0), markNeutralFromTrustedAction)
|
||||
button(text : trans("MARK_DISTRUSTED"), enabled : bind {model.markDistrustedButtonEnabled}, constraints : gbc(gridx: 1, gridy:0), markDistrustedAction)
|
||||
}
|
||||
panel (border : etchedBorder()){
|
||||
gridBagLayout()
|
||||
button(text : trans("BROWSE"), enabled : bind{model.browseFromTrustedButtonEnabled}, constraints:gbc(gridx:0, gridy:0), browseFromTrustedAction)
|
||||
button(text : trans("CHAT"), enabled : bind{model.chatFromTrustedButtonEnabled} ,constraints : gbc(gridx:1, gridy:0), chatFromTrustedAction)
|
||||
button(text : trans("MESSAGE_VERB"), enabled : bind{model.messageFromTrustedButtonEnabled}, constraints : gbc(gridx:2, gridy:0), messageFromTrustedAction)
|
||||
}
|
||||
}
|
||||
}
|
||||
panel (border : etchedBorder()){
|
||||
|
|
Loading…
Reference in New Issue