mirror of https://github.com/zlatinb/muwire
show warning when unsharing files in collections
parent
71c53ef643
commit
033d3bc552
|
@ -161,4 +161,9 @@ mvcGroups {
|
||||||
view = 'com.muwire.gui.CollectionTabView'
|
view = 'com.muwire.gui.CollectionTabView'
|
||||||
controller = 'com.muwire.gui.CollectionTabController'
|
controller = 'com.muwire.gui.CollectionTabController'
|
||||||
}
|
}
|
||||||
|
'collection-warning' {
|
||||||
|
model = "com.muwire.gui.CollectionWarningModel"
|
||||||
|
view = "com.muwire.gui.CollectionWarningView"
|
||||||
|
controller = "com.muwire.gui.CollectionWarningController"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.muwire.gui
|
||||||
|
|
||||||
|
import griffon.core.artifact.GriffonController
|
||||||
|
import griffon.core.controller.ControllerAction
|
||||||
|
import griffon.inject.MVCMember
|
||||||
|
import griffon.metadata.ArtifactProviderFor
|
||||||
|
import javax.annotation.Nonnull
|
||||||
|
|
||||||
|
@ArtifactProviderFor(GriffonController)
|
||||||
|
class CollectionWarningController {
|
||||||
|
@MVCMember @Nonnull
|
||||||
|
CollectionWarningModel model
|
||||||
|
@MVCMember @Nonnull
|
||||||
|
CollectionWarningView view
|
||||||
|
|
||||||
|
@ControllerAction
|
||||||
|
void unshare() {
|
||||||
|
model.answer[0] = true
|
||||||
|
|
||||||
|
if (view.rememberCheckbox.model.isSelected()) {
|
||||||
|
model.settings.collectionWarning = false
|
||||||
|
File propsFile = new File(model.home, "gui.properties")
|
||||||
|
propsFile.withOutputStream {
|
||||||
|
model.settings.write(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cancel()
|
||||||
|
}
|
||||||
|
|
||||||
|
@ControllerAction
|
||||||
|
void cancel() {
|
||||||
|
view.dialog.setVisible(false)
|
||||||
|
mvcGroup.destroy()
|
||||||
|
}
|
||||||
|
}
|
|
@ -403,11 +403,31 @@ class MainFrameController {
|
||||||
}
|
}
|
||||||
|
|
||||||
void unshareSelectedFile() {
|
void unshareSelectedFile() {
|
||||||
def sf = view.selectedSharedFiles()
|
def sfs = view.selectedSharedFiles()
|
||||||
if (sf == null)
|
if (sfs == null)
|
||||||
return
|
return
|
||||||
sf.each {
|
sfs.each { SharedFile sf ->
|
||||||
core.eventBus.publish(new FileUnsharedEvent(unsharedFile : it))
|
|
||||||
|
if (view.settings.collectionWarning) {
|
||||||
|
Set<InfoHash> collectionsInfoHashes = core.collectionManager.collectionsForFile(new InfoHash(sf.root))
|
||||||
|
if (collectionsInfoHashes != null) {
|
||||||
|
String[] affected = collectionsInfoHashes.collect({core.collectionManager.getByInfoHash(it)}).collect{it.name}.toArray(new String[0])
|
||||||
|
|
||||||
|
boolean [] answer = new boolean[1]
|
||||||
|
def props = [:]
|
||||||
|
props.collections = affected
|
||||||
|
props.answer = answer
|
||||||
|
props.fileName = sf.file.getName()
|
||||||
|
props.settings = view.settings
|
||||||
|
props.home = core.home
|
||||||
|
def mvc = mvcGroup.createMVCGroup("collection-warning", props)
|
||||||
|
mvc.destroy()
|
||||||
|
if (!answer[0])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
core.eventBus.publish(new FileUnsharedEvent(unsharedFile : sf))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -555,3 +555,9 @@ COLLECTION_VIEWS=Collection views
|
||||||
COLLECTION_SELECT=Select a collection to view it's description
|
COLLECTION_SELECT=Select a collection to view it's description
|
||||||
DESCRIPTION=Description
|
DESCRIPTION=Description
|
||||||
COLLECTION_DOWNLOAD=Download Full Collection
|
COLLECTION_DOWNLOAD=Download Full Collection
|
||||||
|
|
||||||
|
## Collections warning dialog
|
||||||
|
COLLECTION_WARNING_TITLE=Collections will be deleted
|
||||||
|
COLLECTION_WARNING_BODY1=The file {0} is part of one or more collections.
|
||||||
|
COLLECTION_WARNING_BODY2=If you unshare this file the following collections will be deleted.
|
||||||
|
UNSHARE=Unshare
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.muwire.gui
|
||||||
|
|
||||||
|
import com.muwire.core.collections.FileCollection
|
||||||
|
|
||||||
|
import griffon.core.artifact.GriffonModel
|
||||||
|
import griffon.transform.Observable
|
||||||
|
import griffon.metadata.ArtifactProviderFor
|
||||||
|
|
||||||
|
@ArtifactProviderFor(GriffonModel)
|
||||||
|
class CollectionWarningModel {
|
||||||
|
String[] collections
|
||||||
|
String fileName
|
||||||
|
boolean [] answer
|
||||||
|
UISettings settings
|
||||||
|
File home
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
package com.muwire.gui
|
||||||
|
|
||||||
|
import griffon.core.artifact.GriffonView
|
||||||
|
|
||||||
|
import griffon.inject.MVCMember
|
||||||
|
import griffon.metadata.ArtifactProviderFor
|
||||||
|
|
||||||
|
import javax.swing.JCheckBox
|
||||||
|
import javax.swing.JDialog
|
||||||
|
import javax.swing.SwingConstants
|
||||||
|
import javax.annotation.Nonnull
|
||||||
|
|
||||||
|
import static com.muwire.gui.Translator.trans
|
||||||
|
|
||||||
|
import java.awt.BorderLayout
|
||||||
|
import java.awt.event.WindowAdapter
|
||||||
|
import java.awt.event.WindowEvent
|
||||||
|
|
||||||
|
@ArtifactProviderFor(GriffonView)
|
||||||
|
class CollectionWarningView {
|
||||||
|
@MVCMember @Nonnull
|
||||||
|
FactoryBuilderSupport builder
|
||||||
|
@MVCMember @Nonnull
|
||||||
|
CollectionWarningModel model
|
||||||
|
|
||||||
|
JCheckBox rememberCheckbox
|
||||||
|
|
||||||
|
def mainFrame
|
||||||
|
def dialog
|
||||||
|
def mainPanel
|
||||||
|
|
||||||
|
void initUI() {
|
||||||
|
mainFrame = application.windowManager.findWindow("main-frame")
|
||||||
|
dialog = new JDialog(mainFrame, trans("COLLECTION_WARNING_TITLE"), true)
|
||||||
|
dialog.setResizable(true)
|
||||||
|
|
||||||
|
mainPanel = builder.panel {
|
||||||
|
borderLayout()
|
||||||
|
panel(constraints : BorderLayout.NORTH) {
|
||||||
|
label(text : trans("COLLECTION_WARNING_BODY1", model.fileName))
|
||||||
|
label(text : trans("COLLECTION_WARNING_BODY2"))
|
||||||
|
}
|
||||||
|
scrollPane(constraints : BorderLayout.CENTER) {
|
||||||
|
list(items : model.collections)
|
||||||
|
}
|
||||||
|
panel(constraints : BorderLayout.SOUTH) {
|
||||||
|
rememberCheckbox = checkBox(selected : false)
|
||||||
|
label(text : trans("REMEMBER_DECISION"))
|
||||||
|
button(text : trans("UNSHARE"), unshareAction )
|
||||||
|
button(text : trans("CANCEL"), cancelAction)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dialog.getContentPane().add(mainPanel)
|
||||||
|
dialog.pack()
|
||||||
|
dialog.setResizable(false)
|
||||||
|
dialog.setLocationRelativeTo(mainFrame)
|
||||||
|
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE)
|
||||||
|
dialog.addWindowListener(new WindowAdapter() {
|
||||||
|
public void windowClosed(WindowEvent e) {
|
||||||
|
dialog.setVisible(false)
|
||||||
|
mvcGroup.destroy()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
void mvcGroupInit(Map<String,String> args) {
|
||||||
|
dialog.show()
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,6 +18,7 @@ class UISettings {
|
||||||
boolean excludeLocalResult
|
boolean excludeLocalResult
|
||||||
boolean showSearchHashes
|
boolean showSearchHashes
|
||||||
boolean closeWarning
|
boolean closeWarning
|
||||||
|
boolean collectionWarning
|
||||||
boolean certificateWarning
|
boolean certificateWarning
|
||||||
boolean exitOnClose
|
boolean exitOnClose
|
||||||
boolean clearUploads
|
boolean clearUploads
|
||||||
|
@ -40,6 +41,7 @@ class UISettings {
|
||||||
fontSize = Integer.parseInt(props.getProperty("fontSize","12"))
|
fontSize = Integer.parseInt(props.getProperty("fontSize","12"))
|
||||||
fontStyle = Integer.parseInt(props.getProperty("fontStyle", String.valueOf(Font.PLAIN)))
|
fontStyle = Integer.parseInt(props.getProperty("fontStyle", String.valueOf(Font.PLAIN)))
|
||||||
closeWarning = Boolean.parseBoolean(props.getProperty("closeWarning","true"))
|
closeWarning = Boolean.parseBoolean(props.getProperty("closeWarning","true"))
|
||||||
|
collectionWarning = Boolean.parseBoolean(props.getProperty("collectionWarning", "true"))
|
||||||
certificateWarning = Boolean.parseBoolean(props.getProperty("certificateWarning","true"))
|
certificateWarning = Boolean.parseBoolean(props.getProperty("certificateWarning","true"))
|
||||||
exitOnClose = Boolean.parseBoolean(props.getProperty("exitOnClose","false"))
|
exitOnClose = Boolean.parseBoolean(props.getProperty("exitOnClose","false"))
|
||||||
clearUploads = Boolean.parseBoolean(props.getProperty("clearUploads","false"))
|
clearUploads = Boolean.parseBoolean(props.getProperty("clearUploads","false"))
|
||||||
|
@ -66,6 +68,7 @@ class UISettings {
|
||||||
props.setProperty("autoFontSize", String.valueOf(autoFontSize))
|
props.setProperty("autoFontSize", String.valueOf(autoFontSize))
|
||||||
props.setProperty("fontSize", String.valueOf(fontSize))
|
props.setProperty("fontSize", String.valueOf(fontSize))
|
||||||
props.setProperty("closeWarning", String.valueOf(closeWarning))
|
props.setProperty("closeWarning", String.valueOf(closeWarning))
|
||||||
|
props.setProperty("collectionWarning", String.valueOf(collectionWarning))
|
||||||
props.setProperty("certificateWarning", String.valueOf(certificateWarning))
|
props.setProperty("certificateWarning", String.valueOf(certificateWarning))
|
||||||
props.setProperty("exitOnClose", String.valueOf(exitOnClose))
|
props.setProperty("exitOnClose", String.valueOf(exitOnClose))
|
||||||
props.setProperty("clearUploads", String.valueOf(clearUploads))
|
props.setProperty("clearUploads", String.valueOf(clearUploads))
|
||||||
|
|
Loading…
Reference in New Issue