new messages update taskbar badge
This commit is contained in:
@@ -71,6 +71,7 @@ class ChatRoomController {
|
|||||||
params['console'] = false
|
params['console'] = false
|
||||||
params['host'] = model.host
|
params['host'] = model.host
|
||||||
params['roomTabName'] = newRoom
|
params['roomTabName'] = newRoom
|
||||||
|
params['chatNotificator'] = view.chatNotificator
|
||||||
|
|
||||||
mvcGroup.parentGroup.createMVCGroup("chat-room", model.host.getHumanReadableName()+"-"+newRoom, params)
|
mvcGroup.parentGroup.createMVCGroup("chat-room", model.host.getHumanReadableName()+"-"+newRoom, params)
|
||||||
}
|
}
|
||||||
@@ -110,6 +111,7 @@ class ChatRoomController {
|
|||||||
params['privateChat'] = true
|
params['privateChat'] = true
|
||||||
params['host'] = model.host
|
params['host'] = model.host
|
||||||
params['roomTabName'] = p.getHumanReadableName()
|
params['roomTabName'] = p.getHumanReadableName()
|
||||||
|
params['chatNotificator'] = view.chatNotificator
|
||||||
|
|
||||||
mvcGroup.parentGroup.createMVCGroup("chat-room", groupId, params)
|
mvcGroup.parentGroup.createMVCGroup("chat-room", groupId, params)
|
||||||
}
|
}
|
||||||
@@ -191,6 +193,7 @@ class ChatRoomController {
|
|||||||
runInsideUIAsync {
|
runInsideUIAsync {
|
||||||
view.roomTextArea.append(toDisplay)
|
view.roomTextArea.append(toDisplay)
|
||||||
trimLines()
|
trimLines()
|
||||||
|
view.chatNotificator.onMessage(mvcGroup.mvcId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -458,6 +458,7 @@ class MainFrameController {
|
|||||||
def params = [:]
|
def params = [:]
|
||||||
params['core'] = model.core
|
params['core'] = model.core
|
||||||
params['host'] = model.core.me
|
params['host'] = model.core.me
|
||||||
|
params['chatNotificator'] = view.chatNotificator
|
||||||
mvcGroup.createMVCGroup("chat-server","local-chat-server", params)
|
mvcGroup.createMVCGroup("chat-server","local-chat-server", params)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -489,6 +490,7 @@ class MainFrameController {
|
|||||||
def params = [:]
|
def params = [:]
|
||||||
params['core'] = model.core
|
params['core'] = model.core
|
||||||
params['host'] = p
|
params['host'] = p
|
||||||
|
params['chatNotificator'] = view.chatNotificator
|
||||||
mvcGroup.createMVCGroup("chat-server", p.getHumanReadableName(), params)
|
mvcGroup.createMVCGroup("chat-server", p.getHumanReadableName(), params)
|
||||||
} else
|
} else
|
||||||
mvcGroup.getChildrenGroups().get(p.getHumanReadableName()).model.connect()
|
mvcGroup.getChildrenGroups().get(p.getHumanReadableName()).model.connect()
|
||||||
|
@@ -2,6 +2,8 @@ package com.muwire.gui
|
|||||||
|
|
||||||
import java.util.logging.Level
|
import java.util.logging.Level
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull
|
||||||
|
|
||||||
import com.muwire.core.Core
|
import com.muwire.core.Core
|
||||||
import com.muwire.core.Persona
|
import com.muwire.core.Persona
|
||||||
import com.muwire.core.chat.ChatCommand
|
import com.muwire.core.chat.ChatCommand
|
||||||
@@ -13,6 +15,7 @@ import com.muwire.core.chat.ChatMessageEvent
|
|||||||
import com.muwire.core.chat.UIConnectChatEvent
|
import com.muwire.core.chat.UIConnectChatEvent
|
||||||
|
|
||||||
import griffon.core.artifact.GriffonModel
|
import griffon.core.artifact.GriffonModel
|
||||||
|
import griffon.inject.MVCMember
|
||||||
import griffon.transform.Observable
|
import griffon.transform.Observable
|
||||||
import groovy.util.logging.Log
|
import groovy.util.logging.Log
|
||||||
import griffon.metadata.ArtifactProviderFor
|
import griffon.metadata.ArtifactProviderFor
|
||||||
@@ -20,6 +23,9 @@ import griffon.metadata.ArtifactProviderFor
|
|||||||
@Log
|
@Log
|
||||||
@ArtifactProviderFor(GriffonModel)
|
@ArtifactProviderFor(GriffonModel)
|
||||||
class ChatServerModel {
|
class ChatServerModel {
|
||||||
|
@MVCMember @Nonnull
|
||||||
|
ChatServerView view
|
||||||
|
|
||||||
Persona host
|
Persona host
|
||||||
Core core
|
Core core
|
||||||
|
|
||||||
@@ -133,6 +139,7 @@ class ChatServerModel {
|
|||||||
params['privateChat'] = true
|
params['privateChat'] = true
|
||||||
params['host'] = host
|
params['host'] = host
|
||||||
params['roomTabName'] = e.sender.getHumanReadableName()
|
params['roomTabName'] = e.sender.getHumanReadableName()
|
||||||
|
params['chatNotificator'] = view.chatNotificator
|
||||||
|
|
||||||
mvcGroup.createMVCGroup("chat-room",groupId, params)
|
mvcGroup.createMVCGroup("chat-room",groupId, params)
|
||||||
}
|
}
|
||||||
|
@@ -29,6 +29,8 @@ class ChatRoomView {
|
|||||||
@MVCMember @Nonnull
|
@MVCMember @Nonnull
|
||||||
ChatRoomController controller
|
ChatRoomController controller
|
||||||
|
|
||||||
|
ChatNotificator chatNotificator
|
||||||
|
|
||||||
def pane
|
def pane
|
||||||
def parent
|
def parent
|
||||||
def sayField
|
def sayField
|
||||||
@@ -92,6 +94,7 @@ class ChatRoomView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SmartScroller smartScroller = new SmartScroller(textScrollPane)
|
SmartScroller smartScroller = new SmartScroller(textScrollPane)
|
||||||
|
pane.putClientProperty("mvcId", mvcGroup.mvcId)
|
||||||
}
|
}
|
||||||
|
|
||||||
void mvcGroupInit(Map<String,String> args) {
|
void mvcGroupInit(Map<String,String> args) {
|
||||||
@@ -173,6 +176,7 @@ class ChatRoomView {
|
|||||||
int index = parent.indexOfComponent(pane)
|
int index = parent.indexOfComponent(pane)
|
||||||
parent.removeTabAt(index)
|
parent.removeTabAt(index)
|
||||||
controller.leaveRoom()
|
controller.leaveRoom()
|
||||||
|
chatNotificator.roomClosed(mvcGroup.mvcId)
|
||||||
mvcGroup.destroy()
|
mvcGroup.destroy()
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -19,14 +19,17 @@ class ChatServerView {
|
|||||||
ChatServerModel model
|
ChatServerModel model
|
||||||
@MVCMember @Nonnull
|
@MVCMember @Nonnull
|
||||||
ChatServerController controller
|
ChatServerController controller
|
||||||
|
|
||||||
|
ChatNotificator chatNotificator
|
||||||
|
|
||||||
def pane
|
def pane
|
||||||
def parent
|
def parent
|
||||||
|
def childPane
|
||||||
|
|
||||||
void initUI() {
|
void initUI() {
|
||||||
pane = builder.panel {
|
pane = builder.panel {
|
||||||
borderLayout()
|
borderLayout()
|
||||||
tabbedPane(id : model.host.getHumanReadableName()+"-chat-rooms", constraints : BorderLayout.CENTER)
|
childPane = tabbedPane(id : model.host.getHumanReadableName()+"-chat-rooms", constraints : BorderLayout.CENTER)
|
||||||
panel(constraints : BorderLayout.SOUTH) {
|
panel(constraints : BorderLayout.SOUTH) {
|
||||||
gridLayout(rows : 1, cols : 3)
|
gridLayout(rows : 1, cols : 3)
|
||||||
panel {}
|
panel {}
|
||||||
@@ -39,6 +42,9 @@ class ChatServerView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pane.putClientProperty("mvcId",mvcGroup.mvcId)
|
||||||
|
pane.putClientProperty("childPane", childPane)
|
||||||
|
childPane.addChangeListener({e -> chatNotificator.roomTabChanged(e.getSource())})
|
||||||
}
|
}
|
||||||
|
|
||||||
void mvcGroupInit(Map<String,String> args) {
|
void mvcGroupInit(Map<String,String> args) {
|
||||||
@@ -69,6 +75,7 @@ class ChatServerView {
|
|||||||
params['roomTabName'] = 'Console'
|
params['roomTabName'] = 'Console'
|
||||||
params['console'] = true
|
params['console'] = true
|
||||||
params['host'] = model.host
|
params['host'] = model.host
|
||||||
|
params['chatNotificator'] = chatNotificator
|
||||||
mvcGroup.createMVCGroup("chat-room",model.host.getHumanReadableName()+"-"+ChatServer.CONSOLE, params)
|
mvcGroup.createMVCGroup("chat-room",model.host.getHumanReadableName()+"-"+ChatServer.CONSOLE, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -78,8 +78,10 @@ class MainFrameView {
|
|||||||
|
|
||||||
|
|
||||||
UISettings settings
|
UISettings settings
|
||||||
|
ChatNotificator chatNotificator
|
||||||
|
|
||||||
void initUI() {
|
void initUI() {
|
||||||
|
chatNotificator = new ChatNotificator(application.getMvcGroupManager())
|
||||||
settings = application.context.get("ui-settings")
|
settings = application.context.get("ui-settings")
|
||||||
int rowHeight = application.context.get("row-height")
|
int rowHeight = application.context.get("row-height")
|
||||||
builder.with {
|
builder.with {
|
||||||
@@ -522,6 +524,7 @@ class MainFrameView {
|
|||||||
|
|
||||||
mainFrame.addWindowListener(new WindowAdapter(){
|
mainFrame.addWindowListener(new WindowAdapter(){
|
||||||
public void windowClosing(WindowEvent e) {
|
public void windowClosing(WindowEvent e) {
|
||||||
|
chatNotificator.mainWindowDeactivated()
|
||||||
if (application.getContext().get("tray-icon")) {
|
if (application.getContext().get("tray-icon")) {
|
||||||
if (settings.closeWarning) {
|
if (settings.closeWarning) {
|
||||||
runInsideUIAsync {
|
runInsideUIAsync {
|
||||||
@@ -535,6 +538,13 @@ class MainFrameView {
|
|||||||
} else {
|
} else {
|
||||||
closeApplication()
|
closeApplication()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
public void windowDeactivated(WindowEvent e) {
|
||||||
|
chatNotificator.mainWindowDeactivated()
|
||||||
|
}
|
||||||
|
public void windowActivated(WindowEvent e) {
|
||||||
|
if (!model.chatPaneButtonEnabled)
|
||||||
|
chatNotificator.mainWindowActivated()
|
||||||
}})
|
}})
|
||||||
|
|
||||||
// search field
|
// search field
|
||||||
@@ -831,6 +841,10 @@ class MainFrameView {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// chat tabs
|
||||||
|
def chatTabbedPane = builder.getVariable("chat-tabs")
|
||||||
|
chatTabbedPane.addChangeListener({e -> chatNotificator.serverTabChanged(e.getSource())})
|
||||||
|
|
||||||
// show tree by default
|
// show tree by default
|
||||||
showSharedFilesTree.call()
|
showSharedFilesTree.call()
|
||||||
|
|
||||||
@@ -1033,6 +1047,7 @@ class MainFrameView {
|
|||||||
model.monitorPaneButtonEnabled = true
|
model.monitorPaneButtonEnabled = true
|
||||||
model.trustPaneButtonEnabled = true
|
model.trustPaneButtonEnabled = true
|
||||||
model.chatPaneButtonEnabled = true
|
model.chatPaneButtonEnabled = true
|
||||||
|
chatNotificator.mainWindowDeactivated()
|
||||||
}
|
}
|
||||||
|
|
||||||
def showDownloadsWindow = {
|
def showDownloadsWindow = {
|
||||||
@@ -1044,6 +1059,7 @@ class MainFrameView {
|
|||||||
model.monitorPaneButtonEnabled = true
|
model.monitorPaneButtonEnabled = true
|
||||||
model.trustPaneButtonEnabled = true
|
model.trustPaneButtonEnabled = true
|
||||||
model.chatPaneButtonEnabled = true
|
model.chatPaneButtonEnabled = true
|
||||||
|
chatNotificator.mainWindowDeactivated()
|
||||||
}
|
}
|
||||||
|
|
||||||
def showUploadsWindow = {
|
def showUploadsWindow = {
|
||||||
@@ -1055,6 +1071,7 @@ class MainFrameView {
|
|||||||
model.monitorPaneButtonEnabled = true
|
model.monitorPaneButtonEnabled = true
|
||||||
model.trustPaneButtonEnabled = true
|
model.trustPaneButtonEnabled = true
|
||||||
model.chatPaneButtonEnabled = true
|
model.chatPaneButtonEnabled = true
|
||||||
|
chatNotificator.mainWindowDeactivated()
|
||||||
}
|
}
|
||||||
|
|
||||||
def showMonitorWindow = {
|
def showMonitorWindow = {
|
||||||
@@ -1066,6 +1083,7 @@ class MainFrameView {
|
|||||||
model.monitorPaneButtonEnabled = false
|
model.monitorPaneButtonEnabled = false
|
||||||
model.trustPaneButtonEnabled = true
|
model.trustPaneButtonEnabled = true
|
||||||
model.chatPaneButtonEnabled = true
|
model.chatPaneButtonEnabled = true
|
||||||
|
chatNotificator.mainWindowDeactivated()
|
||||||
}
|
}
|
||||||
|
|
||||||
def showTrustWindow = {
|
def showTrustWindow = {
|
||||||
@@ -1077,6 +1095,7 @@ class MainFrameView {
|
|||||||
model.monitorPaneButtonEnabled = true
|
model.monitorPaneButtonEnabled = true
|
||||||
model.trustPaneButtonEnabled = false
|
model.trustPaneButtonEnabled = false
|
||||||
model.chatPaneButtonEnabled = true
|
model.chatPaneButtonEnabled = true
|
||||||
|
chatNotificator.mainWindowDeactivated()
|
||||||
}
|
}
|
||||||
|
|
||||||
def showChatWindow = {
|
def showChatWindow = {
|
||||||
@@ -1088,6 +1107,7 @@ class MainFrameView {
|
|||||||
model.monitorPaneButtonEnabled = true
|
model.monitorPaneButtonEnabled = true
|
||||||
model.trustPaneButtonEnabled = true
|
model.trustPaneButtonEnabled = true
|
||||||
model.chatPaneButtonEnabled = false
|
model.chatPaneButtonEnabled = false
|
||||||
|
chatNotificator.mainWindowActivated()
|
||||||
}
|
}
|
||||||
|
|
||||||
def showSharedFilesTable = {
|
def showSharedFilesTable = {
|
||||||
|
91
gui/src/main/groovy/com/muwire/gui/ChatNotificator.groovy
Normal file
91
gui/src/main/groovy/com/muwire/gui/ChatNotificator.groovy
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
package com.muwire.gui
|
||||||
|
|
||||||
|
import java.awt.Taskbar
|
||||||
|
import java.awt.Taskbar.Feature
|
||||||
|
|
||||||
|
import javax.swing.JPanel
|
||||||
|
import javax.swing.JTabbedPane
|
||||||
|
|
||||||
|
import griffon.core.mvc.MVCGroupManager
|
||||||
|
|
||||||
|
class ChatNotificator {
|
||||||
|
|
||||||
|
private final MVCGroupManager groupManager
|
||||||
|
|
||||||
|
private boolean chatInFocus
|
||||||
|
private String currentServerTab
|
||||||
|
private String currentRoomTab
|
||||||
|
|
||||||
|
private final Map<String, Integer> roomsWithMessages = new HashMap<>()
|
||||||
|
|
||||||
|
ChatNotificator(MVCGroupManager groupManager) {
|
||||||
|
this.groupManager = groupManager
|
||||||
|
}
|
||||||
|
|
||||||
|
void serverTabChanged(JTabbedPane source) {
|
||||||
|
JPanel panel = source.getSelectedComponent()
|
||||||
|
String mvcId = panel.getClientProperty("mvcId")
|
||||||
|
def group = groupManager.getGroups().get(mvcId)
|
||||||
|
JTabbedPane childPane = panel.getClientProperty("childPane")
|
||||||
|
JPanel roomPanel = childPane.getSelectedComponent()
|
||||||
|
|
||||||
|
currentServerTab = mvcId
|
||||||
|
currentRoomTab = childPane.getSelectedComponent()?.getClientProperty("mvcId")
|
||||||
|
|
||||||
|
if (currentRoomTab != null) {
|
||||||
|
roomsWithMessages.remove(currentRoomTab)
|
||||||
|
updateBadge()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void roomTabChanged(JTabbedPane source) {
|
||||||
|
JPanel panel = source.getSelectedComponent()
|
||||||
|
currentRoomTab = panel.getClientProperty("mvcId")
|
||||||
|
roomsWithMessages.remove(currentRoomTab)
|
||||||
|
updateBadge()
|
||||||
|
}
|
||||||
|
|
||||||
|
void roomClosed(String mvcId) {
|
||||||
|
roomsWithMessages.remove(mvcId)
|
||||||
|
updateBadge()
|
||||||
|
}
|
||||||
|
|
||||||
|
void mainWindowDeactivated() {
|
||||||
|
chatInFocus = false
|
||||||
|
}
|
||||||
|
|
||||||
|
void mainWindowActivated() {
|
||||||
|
chatInFocus = true
|
||||||
|
if (currentRoomTab != null)
|
||||||
|
roomsWithMessages.remove(currentRoomTab)
|
||||||
|
updateBadge()
|
||||||
|
}
|
||||||
|
|
||||||
|
void onMessage(String roomId) {
|
||||||
|
if (roomId != currentRoomTab || !chatInFocus) {
|
||||||
|
Integer previous = roomsWithMessages[roomId]
|
||||||
|
if (previous == null)
|
||||||
|
roomsWithMessages[roomId] = 1
|
||||||
|
else
|
||||||
|
roomsWithMessages[roomId] = previous + 1
|
||||||
|
}
|
||||||
|
updateBadge()
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateBadge() {
|
||||||
|
if (!Taskbar.isTaskbarSupported())
|
||||||
|
return
|
||||||
|
def taskBar = Taskbar.getTaskbar()
|
||||||
|
if (!taskBar.isSupported(Feature.ICON_BADGE_NUMBER))
|
||||||
|
return
|
||||||
|
if (roomsWithMessages.isEmpty())
|
||||||
|
taskBar.setIconBadge("")
|
||||||
|
else {
|
||||||
|
int total = 0
|
||||||
|
roomsWithMessages.values().each {
|
||||||
|
total += it
|
||||||
|
}
|
||||||
|
taskBar.setIconBadge(String.valueOf(total))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user