diff options
author | Sebastien Vincent <seb@jitsi.org> | 2011-11-30 09:52:19 +0000 |
---|---|---|
committer | Sebastien Vincent <seb@jitsi.org> | 2011-11-30 09:52:19 +0000 |
commit | 3c49ac87730a7a7786eee914975139b8efccc302 (patch) | |
tree | 9bee63f9e1bf6e4997b0134eaeed9fdd7a723fed /src/net/java/sip | |
parent | 101a989d7f1880d2589f00dfb4803fbb007a946f (diff) | |
download | jitsi-3c49ac87730a7a7786eee914975139b8efccc302.zip jitsi-3c49ac87730a7a7786eee914975139b8efccc302.tar.gz jitsi-3c49ac87730a7a7786eee914975139b8efccc302.tar.bz2 |
Fixes outgoing calls not being hangup via global shortcut, fixes NPE in CallShortcut/UIShortcut. Also disable global shortcut when we set a shortcut and if we type same global shortcut as another entry, we set the previous entry to Disabled.
Diffstat (limited to 'src/net/java/sip')
5 files changed, 168 insertions, 17 deletions
diff --git a/src/net/java/sip/communicator/impl/globalshortcut/CallShortcut.java b/src/net/java/sip/communicator/impl/globalshortcut/CallShortcut.java index c6a17ed..a7bad4f 100644 --- a/src/net/java/sip/communicator/impl/globalshortcut/CallShortcut.java +++ b/src/net/java/sip/communicator/impl/globalshortcut/CallShortcut.java @@ -43,6 +43,11 @@ public class CallShortcut private ArrayList<Call> incomingCalls = new ArrayList<Call>(); /** + * List of outgoing calls. + */ + private ArrayList<Call> outgoingCalls = new ArrayList<Call>(); + + /** * Constructor. */ public CallShortcut() @@ -58,7 +63,6 @@ public class CallShortcut { AWTKeyStroke keystroke = evt.getKeyStroke(); GlobalKeybindingSet set = keybindingsService.getGlobalBindings(); - Call choosenCall = null; for(Map.Entry<String, List<AWTKeyStroke>> entry : @@ -66,6 +70,9 @@ public class CallShortcut { for(AWTKeyStroke ks : entry.getValue()) { + if(ks == null) + continue; + if(entry.getKey().equals("answer") && keystroke.getKeyCode() == ks.getKeyCode() && keystroke.getModifiers() == ks.getModifiers()) @@ -101,11 +108,14 @@ public class CallShortcut { try { - opSet.answerCallPeer(cCall.getCallPeers().next()); + opSet.answerCallPeer( + cCall.getCallPeers().next()); } catch(OperationFailedException e) { - logger.info("Failed to answer call via global shortcut", e); + logger.info( + "Failed to answer call via global shortcut", + e); } } }.start(); @@ -115,6 +125,7 @@ public class CallShortcut keystroke.getModifiers() == ks.getModifiers()) { Call incomingCall = null; + Call outgoingCall = null; synchronized(incomingCalls) { @@ -125,16 +136,45 @@ public class CallShortcut Call c = incomingCalls.get(i); if(c.getCallPeers().next().getState() == + CallPeerState.INCOMING_CALL && + incomingCall == null) + { + incomingCall = c; + break; + } + else if(c.getCallPeers().next().getState() == CallPeerState.CONNECTED) { choosenCall = c; break; } + } + } + + synchronized(outgoingCalls) + { + int size = outgoingCalls.size(); + + for(int i = 0 ; i < size ; i++) + { + Call c = outgoingCalls.get(i); + + if((c.getCallPeers().next().getState() == + CallPeerState.CONNECTING || + c.getCallPeers().next().getState() == + CallPeerState.ALERTING_REMOTE_SIDE) && + outgoingCall == null) + { + outgoingCall = c; + break; + } else if(c.getCallPeers().next().getState() == - CallPeerState.INCOMING_CALL && incomingCall == null) + CallPeerState.CONNECTED) { - incomingCall = c; + choosenCall = c; + break; } + } } @@ -143,6 +183,11 @@ public class CallShortcut // maybe we just want to hangup (refuse) incoming call choosenCall = incomingCall; } + if(choosenCall == null && outgoingCall != null) + { + // maybe we just want to hangup (cancel) outgoing call + choosenCall = outgoingCall; + } if(choosenCall == null) return; @@ -158,12 +203,14 @@ public class CallShortcut { try { - - opSet.hangupCallPeer(cCall.getCallPeers().next()); + opSet.hangupCallPeer( + cCall.getCallPeers().next()); } catch(OperationFailedException e) { - logger.info("Failed to answer call via global shortcut", e); + logger.info( + "Failed to answer call via global shortcut", + e); } } }.start(); @@ -184,12 +231,19 @@ public class CallShortcut public void outgoingCallCreated(CallEvent event) { - /* do nothing */ + synchronized(outgoingCalls) + { + outgoingCalls.add(event.getSourceCall()); + } } public void callEnded(CallEvent event) { Call sourceCall = event.getSourceCall(); - incomingCalls.remove(sourceCall); + + if(incomingCalls.contains(sourceCall)) + incomingCalls.remove(sourceCall); + else if(outgoingCalls.contains(sourceCall)) + outgoingCalls.remove(sourceCall); } } diff --git a/src/net/java/sip/communicator/impl/globalshortcut/GlobalShortcutServiceImpl.java b/src/net/java/sip/communicator/impl/globalshortcut/GlobalShortcutServiceImpl.java index c205c52..af7f731 100644 --- a/src/net/java/sip/communicator/impl/globalshortcut/GlobalShortcutServiceImpl.java +++ b/src/net/java/sip/communicator/impl/globalshortcut/GlobalShortcutServiceImpl.java @@ -74,6 +74,19 @@ public class GlobalShortcutServiceImpl public void registerShortcut(GlobalShortcutListener listener, AWTKeyStroke keyStroke) { + registerShortcut(listener, keyStroke, true); + } + + /** + * Registers an action to execute when the keystroke is typed. + * + * @param listener listener to notify when keystroke is typed + * @param keyStroke keystroke that will trigger the action + * @param add add the listener/keystrokes to map + */ + public void registerShortcut(GlobalShortcutListener listener, + AWTKeyStroke keyStroke, boolean add) + { synchronized(mapActions) { List<AWTKeyStroke> keystrokes = mapActions.get(listener); @@ -88,7 +101,8 @@ public class GlobalShortcutServiceImpl if(keyboardHook.registerShortcut(keyStroke.getKeyCode(), getModifiers(keyStroke))) { - keystrokes.add(keyStroke); + if(add) + keystrokes.add(keyStroke); } } else @@ -97,11 +111,13 @@ public class GlobalShortcutServiceImpl if(keyboardHook.registerShortcut(keyStroke.getKeyCode(), getModifiers(keyStroke))) { - keystrokes.add(keyStroke); + if(add) + keystrokes.add(keyStroke); } } - mapActions.put(listener, keystrokes); + if(add) + mapActions.put(listener, keystrokes); } } @@ -330,6 +346,42 @@ public class GlobalShortcutServiceImpl } /** + * Enable or not global shortcut. + * + * @param enable enable or not global shortcut + */ + public void setEnable(boolean enable) + { + if(mapActions.size() > 0) + { + if(enable) + { + for(Map.Entry<GlobalShortcutListener, List<AWTKeyStroke>> entry + : mapActions.entrySet()) + { + GlobalShortcutListener l = entry.getKey(); + for(AWTKeyStroke e : entry.getValue()) + { + registerShortcut(l, e, false); + } + } + } + else + { + for(Map.Entry<GlobalShortcutListener, List<AWTKeyStroke>> entry + : mapActions.entrySet()) + { + GlobalShortcutListener l = entry.getKey(); + for(AWTKeyStroke e : entry.getValue()) + { + unregisterShortcut(l, e, false); + } + } + } + } + } + + /** * Simple test. */ public void test() diff --git a/src/net/java/sip/communicator/impl/globalshortcut/UIShortcut.java b/src/net/java/sip/communicator/impl/globalshortcut/UIShortcut.java index 5d73562..bdf9b65 100644 --- a/src/net/java/sip/communicator/impl/globalshortcut/UIShortcut.java +++ b/src/net/java/sip/communicator/impl/globalshortcut/UIShortcut.java @@ -43,6 +43,9 @@ public class UIShortcut { for(AWTKeyStroke ks : entry.getValue()) { + if(ks == null) + continue; + if(entry.getKey().equals("contactlist") && keystroke.getKeyCode() == ks.getKeyCode() && keystroke.getModifiers() == ks.getModifiers()) diff --git a/src/net/java/sip/communicator/plugin/keybindingchooser/globalchooser/GlobalShortcutConfigForm.java b/src/net/java/sip/communicator/plugin/keybindingchooser/globalchooser/GlobalShortcutConfigForm.java index 7773c7d..382af8d 100644 --- a/src/net/java/sip/communicator/plugin/keybindingchooser/globalchooser/GlobalShortcutConfigForm.java +++ b/src/net/java/sip/communicator/plugin/keybindingchooser/globalchooser/GlobalShortcutConfigForm.java @@ -14,8 +14,6 @@ import java.util.List; import javax.swing.*; import javax.swing.event.*; -import com.sun.corba.se.impl.oa.poa.ActiveObjectMap.*; - import net.java.sip.communicator.plugin.keybindingchooser.*; import net.java.sip.communicator.service.globalshortcut.*; import net.java.sip.communicator.service.keybindings.*; @@ -120,7 +118,11 @@ public class GlobalShortcutConfigForm else if(column == 2) GlobalShortcutConfigForm.this.tableModel.getEntryAt( row).setEditShortcut2(true); + else + return; + KeybindingChooserActivator.getGlobalShortcutService(). + setEnable(false); refresh(); shortcutsTable.setRowSelectionInterval(row, row); } @@ -202,11 +204,43 @@ public class GlobalShortcutConfigForm return; } - currentRow = -1; - currentColumn = -1; en.setShortcuts(kss); en.setEditShortcut1(false); en.setEditShortcut2(false); + + kss = new ArrayList<AWTKeyStroke>(); + List<GlobalShortcutEntry> lst = tableModel.getEntries(); + + for(GlobalShortcutEntry e : lst) + { + boolean isEntry = (e == en); + AWTKeyStroke s1 = isEntry && + currentColumn == 1 ? null : e.getShortcut(); + AWTKeyStroke s2 = isEntry && + currentColumn == 2 ? null : e.getShortcut2(); + + if(s1 != null && + s1.getKeyCode() == input.getKeyCode() && + s1.getModifiers() == input.getModifiers()) + { + kss.add(null); + kss.add(e.getShortcut2()); + e.setShortcuts(kss); + break; + } + else if(s2 != null && + s2.getKeyCode() == input.getKeyCode() && + s2.getModifiers() == input.getModifiers()) + { + kss.add(e.getShortcut()); + kss.add(null); + e.setShortcuts(kss); + break; + } + } + + currentRow = -1; + currentColumn = -1; GlobalShortcutConfigForm.this.saveConfig(); GlobalShortcutConfigForm.this.refresh(); } @@ -308,6 +342,7 @@ public class GlobalShortcutConfigForm gBindings.put(desc, kss); } + // save in configuration and reload the global shortcuts keybindingService.saveGlobalShortcutFromConfiguration(); globalShortcutService.reloadGlobalShortcuts(); } diff --git a/src/net/java/sip/communicator/service/globalshortcut/GlobalShortcutService.java b/src/net/java/sip/communicator/service/globalshortcut/GlobalShortcutService.java index 17f3e77..2753c92 100644 --- a/src/net/java/sip/communicator/service/globalshortcut/GlobalShortcutService.java +++ b/src/net/java/sip/communicator/service/globalshortcut/GlobalShortcutService.java @@ -38,4 +38,11 @@ public interface GlobalShortcutService * Reload global shortcuts. */ public void reloadGlobalShortcuts(); + + /** + * Enable or not global shortcut. + * + * @param enable enable or not global shortcut + */ + public void setEnable(boolean enable); }
\ No newline at end of file |