diff --git a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/BrowseModel.groovy b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/BrowseModel.groovy index e4bd0366..a4294f2b 100644 --- a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/BrowseModel.groovy +++ b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/BrowseModel.groovy @@ -17,7 +17,7 @@ class BrowseModel { private final Persona persona private final Core core private final TextGUIThread guiThread - private final TableModel model = new TableModel("Name","Size","Hash","Comment") + private final TableModel model = new TableModel("Name","Size","Hash","Comment","Certificates") private Map rootToResult = new HashMap<>() private int totalResults @@ -53,7 +53,7 @@ class BrowseModel { String size = DataHelper.formatSize2Decimal(e.size, false) + "B" String infoHash = Base64.encode(e.infohash.getRoot()) String comment = String.valueOf(e.comment != null) - model.addRow(e.name, size, infoHash, comment) + model.addRow(e.name, size, infoHash, comment, e.certificates) rootToResult.put(infoHash, e) String percentageString = "" diff --git a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/BrowseView.groovy b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/BrowseView.groovy index bb5c9719..01a6e82a 100644 --- a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/BrowseView.groovy +++ b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/BrowseView.groovy @@ -49,7 +49,7 @@ class BrowseView extends BasicWindow { topPanel.addComponent(percentageLabel, layoutData) contentPanel.addComponent(topPanel, layoutData) - table = new Table("Name","Size","Hash","Comment") + table = new Table("Name","Size","Hash","Comment","Certificates") table.with { setCellSelection(false) setTableModel(model.model) @@ -71,14 +71,16 @@ class BrowseView extends BasicWindow { int selectedRow = table.getSelectedRow() def row = model.model.getRow(selectedRow) String infoHash = row[2] - boolean comment = Boolean.parseBoolean(row[3]) - if (comment) { + boolean comment = Boolean.parseBoolean(row[3]) + boolean certificates = Integer.parseInt(row[4]) > 0 + if (comment || certificates) { Window prompt = new BasicWindow("Download Or View Comment") prompt.setHints([Window.Hint.CENTERED]) Panel contentPanel = new Panel() - contentPanel.setLayoutManager(new GridLayout(3)) + contentPanel.setLayoutManager(new GridLayout(4)) Button downloadButton = new Button("Download", {download(infoHash)}) Button viewButton = new Button("View Comment", {viewComment(infoHash)}) + Button viewCertificate = new Button("View Certificates",{viewCertificates(infoHash)}) Button closeButton = new Button("Cancel", {prompt.close()}) contentPanel.with { @@ -105,7 +107,14 @@ class BrowseView extends BasicWindow { private void viewComment(String infoHash) { UIResultEvent result = model.rootToResult[infoHash] - ViewCommentView view = new ViewCommentView(result, terminalSize) + ViewCommentView view = new ViewCommentView(result.comment, result.name, terminalSize) + textGUI.addWindowAndWait(view) + } + + private void viewCertificates(String infoHash) { + UIResultEvent result = model.rootToResult[infoHash] + ViewCertificatesModel model = new ViewCertificatesModel(result, core, textGUI.getGUIThread()) + ViewCertificatesView view = new ViewCertificatesView(model, textGUI, core, terminalSize) textGUI.addWindowAndWait(view) } } diff --git a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/CertificateWrapper.groovy b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/CertificateWrapper.groovy new file mode 100644 index 00000000..4c9f199f --- /dev/null +++ b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/CertificateWrapper.groovy @@ -0,0 +1,14 @@ +package com.muwire.clilanterna + +import com.muwire.core.filecert.Certificate + +class CertificateWrapper { + private final Certificate certificate + CertificateWrapper(Certificate certificate) { + this.certificate = certificate + } + + public String toString() { + certificate.issuer.getHumanReadableName() + } +} diff --git a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/ResultsView.groovy b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/ResultsView.groovy index 3803a911..ceedbde9 100644 --- a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/ResultsView.groovy +++ b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/ResultsView.groovy @@ -99,7 +99,7 @@ class ResultsView extends BasicWindow { private void viewComment(String infohash) { UIResultEvent result = model.rootToResult[infohash] - ViewCommentView view = new ViewCommentView(result, terminalSize) + ViewCommentView view = new ViewCommentView(result.comment, result.name, terminalSize) textGUI.addWindowAndWait(view) } diff --git a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/ViewCertificatesModel.groovy b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/ViewCertificatesModel.groovy index 4c6da862..262e168c 100644 --- a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/ViewCertificatesModel.groovy +++ b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/ViewCertificatesModel.groovy @@ -17,8 +17,7 @@ class ViewCertificatesModel { private final Core core private final TextGUIThread guiThread - private final TableModel model = new TableModel("Issuer","File Name","Timestamp") - private final Map> byIssuer = new HashMap<>() + private final TableModel model = new TableModel("Issuer","File Name","Comment","Timestamp") private int totalCerts @@ -53,14 +52,7 @@ class ViewCertificatesModel { void onCertificateFetchedEvent(CertificateFetchedEvent e) { guiThread.invokeLater { Date date = new Date(e.certificate.timestamp) - model.addRow(new PersonaWrapper(e.certificate.issuer), e.certificate.name.name, date) - - Set set = byIssuer.get(e.certificate.issuer) - if (set == null) { - set = new HashSet<>() - byIssuer.put(e.certificate.issuer, set) - } - set.add(e.certificate) + model.addRow(new CertificateWrapper(e.certificate), e.certificate.name.name, e.certificate.comment != null, date) String percentageString = "" if (totalCerts > 0) { diff --git a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/ViewCertificatesView.groovy b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/ViewCertificatesView.groovy index e2ea441f..7914eb0c 100644 --- a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/ViewCertificatesView.groovy +++ b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/ViewCertificatesView.groovy @@ -49,7 +49,7 @@ class ViewCertificatesView extends BasicWindow { topPanel.addComponent(percentageLabel, layoutData) contentPanel.addComponent(topPanel, layoutData) - table = new Table("Issuer","File Name","Timestamp") + table = new Table("Issuer","File Name","Comment","Timestamp") table.with { setCellSelection(false) setTableModel(model.model) @@ -69,16 +69,21 @@ class ViewCertificatesView extends BasicWindow { private void rowSelected() { int selectedRow = table.getSelectedRow() def row = model.model.getRow(selectedRow) - Persona persona = row[0].persona + Certificate certificate = row[0].certificate Window prompt = new BasicWindow("Import Certificate?") prompt.setHints([Window.Hint.CENTERED]) Panel contentPanel = new Panel() - contentPanel.setLayoutManager(new GridLayout(2)) - Button importButton = new Button("Import", {importCert(persona)}) + contentPanel.setLayoutManager(new GridLayout(3)) + Button importButton = new Button("Import", {importCert(certificate)}) + + Button viewCommentButton = new Button("View Comment", {viewComment(certificate)}) + Button closeButton = new Button("Close", {prompt.close()}) contentPanel.addComponent(importButton, layoutData) + if (certificate.comment != null) + contentPanel.addComponent(viewCommentButton, layoutData) contentPanel.addComponent(closeButton, layoutData) prompt.setComponent(contentPanel) @@ -86,11 +91,13 @@ class ViewCertificatesView extends BasicWindow { textGUI.addWindowAndWait(prompt) } - private void importCert(Persona persona) { - Set certs = model.byIssuer.get(persona) - certs.each { - core.eventBus.publish(new UIImportCertificateEvent(certificate : it)) - } + private void importCert(Certificate certificate) { + core.eventBus.publish(new UIImportCertificateEvent(certificate : certificate)) MessageDialog.showMessageDialog(textGUI, "Certificate(s) Imported", "", MessageDialogButton.OK) } + + private void viewComment(Certificate certificate) { + ViewCommentView view = new ViewCommentView(certificate.comment.name, "Certificate Comment", terminalSize) + textGUI.addWindowAndWait(view) + } } diff --git a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/ViewCommentView.groovy b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/ViewCommentView.groovy index 801411bd..19351ff8 100644 --- a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/ViewCommentView.groovy +++ b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/ViewCommentView.groovy @@ -19,8 +19,8 @@ class ViewCommentView extends BasicWindow { private final TextBox textBox private final LayoutData layoutData = GridLayout.createLayoutData(Alignment.CENTER, Alignment.CENTER) - ViewCommentView(UIResultEvent result, TerminalSize terminalSize) { - super("View Comments For "+result.getName()) + ViewCommentView(String text, String title, TerminalSize terminalSize) { + super("View Comments For "+title) setHints([Window.Hint.CENTERED]) @@ -28,7 +28,7 @@ class ViewCommentView extends BasicWindow { contentPanel.setLayoutManager(new GridLayout(1)) TerminalSize boxSize = new TerminalSize((terminalSize.getColumns() / 2).toInteger(), (terminalSize.getRows() / 2).toInteger()) - textBox = new TextBox(boxSize, result.comment, TextBox.Style.MULTI_LINE) + textBox = new TextBox(boxSize, text, TextBox.Style.MULTI_LINE) contentPanel.addComponent(textBox, layoutData) Button closeButton = new Button("Close", {close()})