From a2d0e4e4a659d68d1e1d0c078382da75fedcf290 Mon Sep 17 00:00:00 2001 From: Damian Minkov Date: Thu, 26 Jan 2012 12:16:46 +0000 Subject: [PATCH] Creates chat dialog components, incoming call dialog and incoming file transfer components in swing dispatch thread. If we failed to connect to xmpp server fire connection failed for provider and clean to avoid staying not connected and seeing duplicate connection in logs. --- .../impl/gui/main/call/CallManager.java | 14 +- .../impl/gui/main/chat/ChatPanel.java | 18 ++- .../gui/main/contactlist/ContactListPane.java | 120 +++++++++++------- .../ProtocolProviderServiceJabberImpl.java | 20 ++- 4 files changed, 121 insertions(+), 51 deletions(-) diff --git a/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java b/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java index 47c63ab88..d938d1531 100644 --- a/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java +++ b/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java @@ -69,8 +69,20 @@ public static class GuiCallListener implements CallListener * ring phone sound to the user. * @param event the CallEvent */ - public void incomingCallReceived(CallEvent event) + public void incomingCallReceived(final CallEvent event) { + if(!SwingUtilities.isEventDispatchThread()) + { + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + incomingCallReceived(event); + } + }); + return; + } + Call sourceCall = event.getSourceCall(); final ReceivedCallDialog receivedCallDialog = new ReceivedCallDialog(sourceCall, event.isVideoCall()); diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/ChatPanel.java b/src/net/java/sip/communicator/impl/gui/main/chat/ChatPanel.java index ee5b22f23..c55cf3737 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/ChatPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/ChatPanel.java @@ -1947,10 +1947,22 @@ else if (subject.equals(oldSubject)) * @param date the date on which the request has been received */ public void addIncomingFileTransferRequest( - OperationSetFileTransfer fileTransferOpSet, - IncomingFileTransferRequest request, - Date date) + final OperationSetFileTransfer fileTransferOpSet, + final IncomingFileTransferRequest request, + final Date date) { + if(!SwingUtilities.isEventDispatchThread()) + { + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + addIncomingFileTransferRequest( + fileTransferOpSet, request, date); + } + }); + } + this.addActiveFileTransfer(request.getID(), request); ReceiveFileConversationComponent component diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPane.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPane.java index e64e0e5b5..2f9e23bee 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPane.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListPane.java @@ -233,69 +233,97 @@ public void messageReceived(MessageReceivedEvent evt) Contact protocolContact = evt.getSourceContact(); Message message = evt.getSourceMessage(); int eventType = evt.getEventType(); - MetaContact metaContact = GuiActivator.getContactListService() .findMetaContactByContact(protocolContact); if(metaContact != null) { - // Obtain the corresponding chat panel. - final ChatPanel chatPanel - = chatWindowManager.getContactChat( metaContact, - protocolContact, - message.getMessageUID()); - - // Show an envelope on the sender contact in the contact list and - // in the systray. - if (!chatPanel.isChatFocused()) - contactList.setActiveContact(metaContact, true); - - // Distinguish the message type, depending on the type of event that - // we have received. - String messageType = null; - - if(eventType == MessageReceivedEvent.CONVERSATION_MESSAGE_RECEIVED) - { - messageType = Chat.INCOMING_MESSAGE; - } - else if(eventType == MessageReceivedEvent.SYSTEM_MESSAGE_RECEIVED) - { - messageType = Chat.SYSTEM_MESSAGE; - } - else if(eventType == MessageReceivedEvent.SMS_MESSAGE_RECEIVED) - { - messageType = Chat.SMS_MESSAGE; - } - - chatPanel.addMessage( - protocolContact.getAddress(), - protocolContact.getDisplayName(), - evt.getTimestamp(), - messageType, - message.getContent(), - message.getContentType()); + messageReceived(protocolContact, + metaContact, message, eventType, evt.getTimestamp()); + } + else + { + if (logger.isTraceEnabled()) + logger.trace("MetaContact not found for protocol contact: " + + protocolContact + "."); + } + } - // Opens the chat panel with the new message in the UI thread. + /** + * When a message is received determines whether to open a new chat window + * or chat window tab, or to indicate that a message is received from a + * contact which already has an open chat. When the chat is found checks if + * in mode "Auto popup enabled" and if this is the case shows the message in + * the appropriate chat panel. + * + * @param protocolContact the source contact of the event + * @param metaContact the metacontact containing protocolContact + * @param message the message to deliver + * @param eventType the event type + * @param timestamp the timestamp of the event + */ + private void messageReceived(final Contact protocolContact, + final MetaContact metaContact, + final Message message, + final int eventType, + final long timestamp) + { + if(!SwingUtilities.isEventDispatchThread()) + { SwingUtilities.invokeLater(new Runnable() { public void run() { - chatWindowManager.openChat(chatPanel, false); + messageReceived(protocolContact, + metaContact, message, eventType, timestamp); } }); + return; + } + + // Obtain the corresponding chat panel. + final ChatPanel chatPanel + = chatWindowManager.getContactChat( metaContact, + protocolContact, + message.getMessageUID()); + + // Show an envelope on the sender contact in the contact list and + // in the systray. + if (!chatPanel.isChatFocused()) + contactList.setActiveContact(metaContact, true); - ChatTransport chatTransport - = chatPanel.getChatSession() - .findChatTransportForDescriptor(protocolContact); + // Distinguish the message type, depending on the type of event that + // we have received. + String messageType = null; - chatPanel.setSelectedChatTransport(chatTransport); + if(eventType == MessageReceivedEvent.CONVERSATION_MESSAGE_RECEIVED) + { + messageType = Chat.INCOMING_MESSAGE; } - else + else if(eventType == MessageReceivedEvent.SYSTEM_MESSAGE_RECEIVED) { - if (logger.isTraceEnabled()) - logger.trace("MetaContact not found for protocol contact: " - + protocolContact + "."); + messageType = Chat.SYSTEM_MESSAGE; + } + else if(eventType == MessageReceivedEvent.SMS_MESSAGE_RECEIVED) + { + messageType = Chat.SMS_MESSAGE; } + + chatPanel.addMessage( + protocolContact.getAddress(), + protocolContact.getDisplayName(), + timestamp, + messageType, + message.getContent(), + message.getContentType()); + + chatWindowManager.openChat(chatPanel, false); + + ChatTransport chatTransport + = chatPanel.getChatSession() + .findChatTransportForDescriptor(protocolContact); + + chatPanel.setSelectedChatTransport(chatTransport); } /** diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java index f0bb1f7d1..009314221 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/ProtocolProviderServiceJabberImpl.java @@ -1130,7 +1130,25 @@ else if (tlsRequired) throw new XMPPException("TLS is required by client"); } - connection.addConnectionListener(connectionListener); + if(!connection.isConnected()) + { + // connection is not connected, lets set state to our connection + // as failed seems there is some lag/problem with network + // and this way we will inform for it and later reconnect if needed + // as IllegalStateException that is thrown within + // addConnectionListener is not handled properly + disconnectAndCleanConnection(); + + fireRegistrationStateChanged(getRegistrationState(), + RegistrationState.CONNECTION_FAILED, + RegistrationStateChangeEvent.REASON_SERVER_NOT_FOUND, null); + + return ConnectState.ABORT_CONNECTING; + } + else + { + connection.addConnectionListener(connectionListener); + } if(abortConnecting) {