From acda64aea735ac300b38bc92d3f070fbcb4cfad4 Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Tue, 5 Nov 2019 04:41:25 +0000 Subject: [PATCH] Add certify button to cli. Make watched directory handling match that of gui --- .../groovy/com/muwire/clilanterna/FilesModel.groovy | 7 ++++--- .../groovy/com/muwire/clilanterna/FilesView.groovy | 10 ++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/FilesModel.groovy b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/FilesModel.groovy index 5bec4ac8..3db8bf76 100644 --- a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/FilesModel.groovy +++ b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/FilesModel.groovy @@ -18,7 +18,7 @@ class FilesModel { private final TextGUIThread guiThread private final Core core private final List sharedFiles = new ArrayList<>() - private final TableModel model = new TableModel("Name","Size","Comment","Search Hits","Downloaders") + private final TableModel model = new TableModel("Name","Size","Comment","Certified","Search Hits","Downloaders") FilesModel(TextGUIThread guiThread, Core core) { this.guiThread = guiThread @@ -41,7 +41,7 @@ class FilesModel { def eventBus = core.eventBus guiThread.invokeLater { core.muOptions.watchedDirectories.each { - eventBus.publish(new DirectoryWatchedEvent(directory : new File(it))) + eventBus.publish(new FileSharedEvent(file: new File(it))) } } } @@ -72,9 +72,10 @@ class FilesModel { sharedFiles.each { long size = it.getCachedLength() boolean comment = it.comment != null + boolean certified = core.certificateManager.hasLocalCertificate(it.getInfoHash()) String hits = String.valueOf(it.getHits()) String downloaders = String.valueOf(it.getDownloaders().size()) - model.addRow(new SharedFileWrapper(it), DataHelper.formatSize2(size, false)+"B", comment, hits, downloaders) + model.addRow(new SharedFileWrapper(it), DataHelper.formatSize2(size, false)+"B", comment, certified, hits, downloaders) } } } diff --git a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/FilesView.groovy b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/FilesView.groovy index 3985c716..ff60c777 100644 --- a/cli-lanterna/src/main/groovy/com/muwire/clilanterna/FilesView.groovy +++ b/cli-lanterna/src/main/groovy/com/muwire/clilanterna/FilesView.groovy @@ -17,6 +17,7 @@ import com.googlecode.lanterna.gui2.dialogs.TextInputDialog import com.googlecode.lanterna.gui2.table.Table import com.muwire.core.Core import com.muwire.core.SharedFile +import com.muwire.core.filecert.UICreateCertificateEvent import com.muwire.core.files.DirectoryUnsharedEvent import com.muwire.core.files.FileSharedEvent import com.muwire.core.files.FileUnsharedEvent @@ -42,7 +43,7 @@ class FilesView extends BasicWindow { contentPanel.setLayoutManager(new GridLayout(1)) LayoutData layoutData = GridLayout.createLayoutData(Alignment.CENTER, Alignment.CENTER, true, false) - table = new Table("Name","Size","Comment","Search Hits","Downloaders") + table = new Table("Name","Size","Comment","Certified","Search Hits","Downloaders") table.setCellSelection(false) table.setTableModel(model.model) table.setSelectAction({rowSelected()}) @@ -77,7 +78,7 @@ class FilesView extends BasicWindow { Window prompt = new BasicWindow("Unshare or add comment to "+sf.getFile().getName()+" ?") prompt.setHints([Window.Hint.CENTERED]) Panel contentPanel = new Panel() - contentPanel.setLayoutManager(new GridLayout(3)) + contentPanel.setLayoutManager(new GridLayout(4)) Button unshareButton = new Button("Unshare", { core.eventBus.publish(new FileUnsharedEvent(unsharedFile : sf)) @@ -88,11 +89,16 @@ class FilesView extends BasicWindow { AddCommentView view = new AddCommentView(textGUI, core, sf, terminalSize) textGUI.addWindowAndWait(view) }) + Button certifyButton = new Button("Certify", { + core.eventBus.publish(new UICreateCertificateEvent(sharedFile : sf)) + MessageDialog.showMessageDialog(textGUI, "Certificate Created", "Certificate has been issued", MessageDialogButton.OK) + }) Button closeButton = new Button("Close", {prompt.close()}) LayoutData layoutData = GridLayout.createLayoutData(Alignment.CENTER, Alignment.CENTER) contentPanel.addComponent(unshareButton, layoutData) contentPanel.addComponent(addCommentButton, layoutData) + contentPanel.addComponent(certifyButton, layoutData) contentPanel.addComponent(closeButton, layoutData) prompt.setComponent(contentPanel)