mirror of https://github.com/zlatinb/muwire
reindexing progress bar
parent
c45ad1b88c
commit
daa2af3255
|
@ -29,6 +29,7 @@ class LibrarySyncController {
|
|||
|
||||
@ControllerAction
|
||||
void reindex() {
|
||||
|
||||
view.startReindex()
|
||||
model.startReindex()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -778,7 +778,8 @@ LIBRARY_SCAN_PREVIEW_COLUMN_FILE=File
|
|||
LIBRARY_SCAN_PREVIEW_COLUMN_SHARED=Shared
|
||||
LIBRARY_SCAN_PREVIEW_COLUMN_MODIFIED=Modified
|
||||
LIBRARY_SCAN_PREVIEW_COLLECTIONS_BODY=The following collections may be affected
|
||||
LIBRARY_SCAN_PREVIEW_REINDEX=Re-Index
|
||||
LIBRARY_SCAN_PREVIEW_REINDEX=Re-index
|
||||
LIBRARY_SCAN_REINDEX_TITLE=Re-indexing files that are out of sync
|
||||
|
||||
## Tooltips
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@ import com.muwire.core.Core
|
|||
import com.muwire.core.InfoHash
|
||||
import com.muwire.core.SharedFile
|
||||
import com.muwire.core.collections.FileCollection
|
||||
import com.muwire.core.files.FileHashedEvent
|
||||
import com.muwire.core.files.FileModifiedEvent
|
||||
import griffon.core.artifact.GriffonModel
|
||||
import griffon.inject.MVCMember
|
||||
import griffon.metadata.ArtifactProviderFor
|
||||
|
@ -72,4 +74,28 @@ class LibrarySyncModel {
|
|||
view.scanFinished()
|
||||
}
|
||||
}
|
||||
|
||||
void startReindex() {
|
||||
def observer = new ReindexObserver()
|
||||
core.eventBus.register(FileHashedEvent.class, observer)
|
||||
def event = new FileModifiedEvent(sharedFiles: staleFiles)
|
||||
core.eventBus.publish(event)
|
||||
}
|
||||
|
||||
private class ReindexObserver {
|
||||
private final Set<SharedFile> remaining = new HashSet<>(staleFiles)
|
||||
private final int total = remaining.size()
|
||||
void onFileHashedEvent(FileHashedEvent event) {
|
||||
runInsideUIAsync {
|
||||
if (!remaining.remove(event.original))
|
||||
return
|
||||
int percentage = (int)((total - remaining.size()) * 100 / total)
|
||||
view.updateReindexProgressBar(percentage)
|
||||
if (remaining.isEmpty()) {
|
||||
core.eventBus.unregister(FileHashedEvent.class, this)
|
||||
view.reindexComplete()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ import javax.swing.JProgressBar
|
|||
import javax.swing.JTable
|
||||
import java.awt.BorderLayout
|
||||
import java.awt.Dimension
|
||||
import java.awt.event.WindowAdapter
|
||||
import java.awt.event.WindowEvent
|
||||
|
||||
import static com.muwire.gui.Translator.trans
|
||||
|
||||
|
@ -43,6 +45,8 @@ class LibrarySyncView {
|
|||
private JProgressBar scanProgressBar
|
||||
JProgressBar reindexProgressBar
|
||||
|
||||
private final CloseAdapter closeAdapter = new CloseAdapter()
|
||||
|
||||
void initUI() {
|
||||
mainFrame = (JFrame) application.windowManager.findWindow("main-frame")
|
||||
rowHeight = (int)application.context.get("row-height")
|
||||
|
@ -61,6 +65,7 @@ class LibrarySyncView {
|
|||
}
|
||||
|
||||
scanDialog.with {
|
||||
addWindowListener(closeAdapter)
|
||||
getContentPane().add(scanPanel)
|
||||
pack()
|
||||
setLocationRelativeTo(mainFrame)
|
||||
|
@ -146,6 +151,7 @@ class LibrarySyncView {
|
|||
|
||||
Dimension dimension = mainFrame.getSize()
|
||||
previewDialog.with {
|
||||
addWindowListener(closeAdapter)
|
||||
getContentPane().add(previewPanel)
|
||||
setSize((int)(dimension.getWidth() - 100), (int)(dimension.getHeight() - 100))
|
||||
setLocationRelativeTo(mainFrame)
|
||||
|
@ -157,4 +163,42 @@ class LibrarySyncView {
|
|||
nextDialog = null
|
||||
previewDialog.setVisible(false)
|
||||
}
|
||||
|
||||
void startReindex() {
|
||||
previewDialog.setVisible(false)
|
||||
reindexDialog = new JDialog(mainFrame, trans("LIBRARY_SCAN_REINDEX_TITLE"), true)
|
||||
nextDialog = reindexDialog
|
||||
|
||||
JPanel reindexPanel = builder.panel {
|
||||
borderLayout()
|
||||
panel(constraints: BorderLayout.NORTH) {
|
||||
label(text: trans("LIBRARY_SCAN_REINDEX_TITLE"))
|
||||
}
|
||||
reindexProgressBar = progressBar(constraints: BorderLayout.CENTER)
|
||||
}
|
||||
|
||||
reindexDialog.with {
|
||||
addWindowListener(closeAdapter)
|
||||
getContentPane().add(reindexPanel)
|
||||
pack()
|
||||
setLocationRelativeTo(mainFrame)
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE)
|
||||
}
|
||||
}
|
||||
|
||||
void updateReindexProgressBar(int value) {
|
||||
reindexProgressBar.setValue(value)
|
||||
}
|
||||
|
||||
void reindexComplete() {
|
||||
nextDialog = null
|
||||
reindexDialog.setVisible(false)
|
||||
}
|
||||
|
||||
private class CloseAdapter extends WindowAdapter {
|
||||
void windowClosed(WindowEvent e) {
|
||||
nextDialog?.setVisible(false)
|
||||
nextDialog = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue