implement restore session
This commit is contained in:
@@ -53,7 +53,7 @@ class MainFrameController {
|
|||||||
|
|
||||||
@ControllerAction
|
@ControllerAction
|
||||||
void search(ActionEvent evt) {
|
void search(ActionEvent evt) {
|
||||||
if (evt.getActionCommand() == null)
|
if (evt?.getActionCommand() == null)
|
||||||
return
|
return
|
||||||
def cardsPanel = builder.getVariable("cards-panel")
|
def cardsPanel = builder.getVariable("cards-panel")
|
||||||
cardsPanel.getLayout().show(cardsPanel, "search window")
|
cardsPanel.getLayout().show(cardsPanel, "search window")
|
||||||
@@ -61,6 +61,12 @@ class MainFrameController {
|
|||||||
def searchField = builder.getVariable("search-field")
|
def searchField = builder.getVariable("search-field")
|
||||||
def search = searchField.getSelectedItem()
|
def search = searchField.getSelectedItem()
|
||||||
searchField.model.addElement(search)
|
searchField.model.addElement(search)
|
||||||
|
performSearch(search)
|
||||||
|
}
|
||||||
|
|
||||||
|
private void performSearch(String search) {
|
||||||
|
|
||||||
|
model.sessionRestored = true
|
||||||
|
|
||||||
search = search.trim()
|
search = search.trim()
|
||||||
if (search.length() == 0)
|
if (search.length() == 0)
|
||||||
@@ -98,16 +104,17 @@ class MainFrameController {
|
|||||||
def nonEmpty = []
|
def nonEmpty = []
|
||||||
terms.each { if (it.length() > 0) nonEmpty << it }
|
terms.each { if (it.length() > 0) nonEmpty << it }
|
||||||
payload = String.join(" ",nonEmpty).getBytes(StandardCharsets.UTF_8)
|
payload = String.join(" ",nonEmpty).getBytes(StandardCharsets.UTF_8)
|
||||||
searchEvent = new SearchEvent(searchTerms : nonEmpty, uuid : uuid, oobInfohash: true,
|
searchEvent = new SearchEvent(searchTerms : nonEmpty, uuid : uuid, oobInfohash: true,
|
||||||
searchComments : core.muOptions.searchComments, compressedResults : true)
|
searchComments : core.muOptions.searchComments, compressedResults : true)
|
||||||
}
|
}
|
||||||
boolean firstHop = core.muOptions.allowUntrusted || core.muOptions.searchExtraHop
|
boolean firstHop = core.muOptions.allowUntrusted || core.muOptions.searchExtraHop
|
||||||
|
|
||||||
Signature sig = DSAEngine.getInstance().sign(payload, core.spk)
|
Signature sig = DSAEngine.getInstance().sign(payload, core.spk)
|
||||||
|
|
||||||
core.eventBus.publish(new QueryEvent(searchEvent : searchEvent, firstHop : firstHop,
|
core.eventBus.publish(new QueryEvent(searchEvent : searchEvent, firstHop : firstHop,
|
||||||
replyTo: core.me.destination, receivedOn: core.me.destination,
|
replyTo: core.me.destination, receivedOn: core.me.destination,
|
||||||
originator : core.me, sig : sig.data))
|
originator : core.me, sig : sig.data))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void search(String infoHash, String tabTitle) {
|
void search(String infoHash, String tabTitle) {
|
||||||
@@ -313,6 +320,14 @@ class MainFrameController {
|
|||||||
void clearUploads() {
|
void clearUploads() {
|
||||||
model.uploads.removeAll { it.finished }
|
model.uploads.removeAll { it.finished }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ControllerAction
|
||||||
|
void restoreSession() {
|
||||||
|
model.sessionRestored = true
|
||||||
|
view.settings.openTabs.each {
|
||||||
|
performSearch(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void saveMuWireSettings() {
|
void saveMuWireSettings() {
|
||||||
core.saveMuSettings()
|
core.saveMuSettings()
|
||||||
|
|||||||
@@ -88,6 +88,8 @@ class MainFrameModel {
|
|||||||
def trusted = []
|
def trusted = []
|
||||||
def distrusted = []
|
def distrusted = []
|
||||||
def subscriptions = []
|
def subscriptions = []
|
||||||
|
|
||||||
|
boolean sessionRestored
|
||||||
|
|
||||||
@Observable int connections
|
@Observable int connections
|
||||||
@Observable String me
|
@Observable String me
|
||||||
@@ -295,6 +297,8 @@ class MainFrameModel {
|
|||||||
runInsideUIAsync {
|
runInsideUIAsync {
|
||||||
connections = core.connectionManager.getConnections().size()
|
connections = core.connectionManager.getConnections().size()
|
||||||
|
|
||||||
|
view.showRestoreOrEmpty()
|
||||||
|
|
||||||
if (connections > 0) {
|
if (connections > 0) {
|
||||||
def topPanel = builder.getVariable("top-panel")
|
def topPanel = builder.getVariable("top-panel")
|
||||||
topPanel.getLayout().show(topPanel, "top-search-panel")
|
topPanel.getLayout().show(topPanel, "top-search-panel")
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ class MainFrameView {
|
|||||||
def lastSharedSortEvent
|
def lastSharedSortEvent
|
||||||
def trustTablesSortEvents = [:]
|
def trustTablesSortEvents = [:]
|
||||||
def expansionListener = new TreeExpansions()
|
def expansionListener = new TreeExpansions()
|
||||||
|
|
||||||
|
|
||||||
UISettings settings
|
UISettings settings
|
||||||
|
|
||||||
@@ -159,9 +160,23 @@ class MainFrameView {
|
|||||||
}
|
}
|
||||||
panel (id: "cards-panel", constraints : BorderLayout.CENTER) {
|
panel (id: "cards-panel", constraints : BorderLayout.CENTER) {
|
||||||
cardLayout()
|
cardLayout()
|
||||||
panel (constraints : "search window") {
|
panel (id : "search window", constraints : "search window") {
|
||||||
borderLayout()
|
cardLayout()
|
||||||
tabbedPane(id : "result-tabs", constraints: BorderLayout.CENTER)
|
panel (constraints : "tabs-panel") {
|
||||||
|
borderLayout()
|
||||||
|
tabbedPane(id : "result-tabs", constraints: BorderLayout.CENTER)
|
||||||
|
}
|
||||||
|
panel(constraints : "restore session") {
|
||||||
|
borderLayout()
|
||||||
|
panel (constraints : BorderLayout.CENTER) {
|
||||||
|
gridBagLayout()
|
||||||
|
label(text : "Saved Tabs:", constraints : gbc(gridx : 0, gridy : 0))
|
||||||
|
scrollPane (constraints : gbc(gridx : 0, gridy : 1)) {
|
||||||
|
list(items : new ArrayList(settings.openTabs))
|
||||||
|
}
|
||||||
|
button(text : "Restore Session", constraints : gbc(gridx :0, gridy : 2), restoreSessionAction)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
panel (constraints: "downloads window") {
|
panel (constraints: "downloads window") {
|
||||||
gridLayout(rows : 1, cols : 1)
|
gridLayout(rows : 1, cols : 1)
|
||||||
@@ -725,6 +740,9 @@ class MainFrameView {
|
|||||||
|
|
||||||
// show tree by default
|
// show tree by default
|
||||||
showSharedFilesTree.call()
|
showSharedFilesTree.call()
|
||||||
|
|
||||||
|
// show search panel by default
|
||||||
|
showSearchWindow.call()
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void showPopupMenu(JPopupMenu menu, MouseEvent event) {
|
private static void showPopupMenu(JPopupMenu menu, MouseEvent event) {
|
||||||
@@ -869,10 +887,23 @@ class MainFrameView {
|
|||||||
|
|
||||||
showPopupMenu(menu, e)
|
showPopupMenu(menu, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void showRestoreOrEmpty() {
|
||||||
|
def searchWindow = builder.getVariable("search window")
|
||||||
|
String id
|
||||||
|
if (!model.sessionRestored && !settings.openTabs.isEmpty())
|
||||||
|
id = model.connections > 0 ? "restore session" : "tabs-panel"
|
||||||
|
else
|
||||||
|
id = "tabs-panel"
|
||||||
|
searchWindow.getLayout().show(searchWindow, id)
|
||||||
|
}
|
||||||
|
|
||||||
def showSearchWindow = {
|
def showSearchWindow = {
|
||||||
def cardsPanel = builder.getVariable("cards-panel")
|
def cardsPanel = builder.getVariable("cards-panel")
|
||||||
cardsPanel.getLayout().show(cardsPanel, "search window")
|
cardsPanel.getLayout().show(cardsPanel, "search window")
|
||||||
|
|
||||||
|
showRestoreOrEmpty()
|
||||||
|
|
||||||
model.searchesPaneButtonEnabled = false
|
model.searchesPaneButtonEnabled = false
|
||||||
model.downloadsPaneButtonEnabled = true
|
model.downloadsPaneButtonEnabled = true
|
||||||
model.uploadsPaneButtonEnabled = true
|
model.uploadsPaneButtonEnabled = true
|
||||||
@@ -971,10 +1002,20 @@ class MainFrameView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void closeApplication() {
|
private void closeApplication() {
|
||||||
|
Core core = application.getContext().get("core")
|
||||||
|
|
||||||
|
def tabbedPane = builder.getVariable("result-tabs")
|
||||||
|
settings.openTabs.clear()
|
||||||
|
int count = tabbedPane.getTabCount()
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
settings.openTabs.add(tabbedPane.getTitleAt(i))
|
||||||
|
|
||||||
|
File uiPropsFile = new File(core.home, "gui.properties")
|
||||||
|
uiPropsFile.withOutputStream { settings.write(it) }
|
||||||
|
|
||||||
def mainFrame = builder.getVariable("main-frame")
|
def mainFrame = builder.getVariable("main-frame")
|
||||||
mainFrame.setVisible(false)
|
mainFrame.setVisible(false)
|
||||||
application.getWindowManager().findWindow("shutdown-window").setVisible(true)
|
application.getWindowManager().findWindow("shutdown-window").setVisible(true)
|
||||||
Core core = application.getContext().get("core")
|
|
||||||
if (core != null) {
|
if (core != null) {
|
||||||
Thread t = new Thread({
|
Thread t = new Thread({
|
||||||
core.shutdown()
|
core.shutdown()
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ class UISettings {
|
|||||||
boolean clearUploads
|
boolean clearUploads
|
||||||
boolean storeSearchHistory
|
boolean storeSearchHistory
|
||||||
Set<String> searchHistory
|
Set<String> searchHistory
|
||||||
|
Set<String> openTabs
|
||||||
|
|
||||||
UISettings(Properties props) {
|
UISettings(Properties props) {
|
||||||
lnf = props.getProperty("lnf", "system")
|
lnf = props.getProperty("lnf", "system")
|
||||||
@@ -35,6 +36,7 @@ class UISettings {
|
|||||||
storeSearchHistory = Boolean.parseBoolean(props.getProperty("storeSearchHistory","true"))
|
storeSearchHistory = Boolean.parseBoolean(props.getProperty("storeSearchHistory","true"))
|
||||||
|
|
||||||
searchHistory = DataUtil.readEncodedSet(props, "searchHistory")
|
searchHistory = DataUtil.readEncodedSet(props, "searchHistory")
|
||||||
|
openTabs = DataUtil.readEncodedSet(props, "openTabs")
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(OutputStream out) throws IOException {
|
void write(OutputStream out) throws IOException {
|
||||||
@@ -55,6 +57,7 @@ class UISettings {
|
|||||||
props.setProperty("font", font)
|
props.setProperty("font", font)
|
||||||
|
|
||||||
DataUtil.writeEncodedSet(searchHistory, "searchHistory", props)
|
DataUtil.writeEncodedSet(searchHistory, "searchHistory", props)
|
||||||
|
DataUtil.writeEncodedSet(openTabs, "openTabs", props)
|
||||||
|
|
||||||
props.store(out, "UI Properties")
|
props.store(out, "UI Properties")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user