From c9b32fbaa830ac3d27e415d32ddfdc79ec1ae9bb Mon Sep 17 00:00:00 2001 From: Lyubomir Marinov Date: Fri, 18 Sep 2009 14:38:22 +0000 Subject: [PATCH] - In ChatWindowManager#closeChat(ChatPanel), calls closeChatPanel() for AdHocConferenceChatSession as it's called in the other branches. Confirmed by Yana Stamcheva as necessary. - Reverts back to setting the current MetaContact of PluginComponent instances to null from MainToolBar as discussed with Yana. - Adds a license header to a java file. --- .../impl/gui/main/chat/ChatPanel.java | 10 +- .../impl/gui/main/chat/ChatWindowManager.java | 2 + .../gui/main/chat/toolBars/MainToolBar.java | 10 +- ...erationSetAdHocMultiUserChatYahooImpl.java | 161 ++++++++---------- .../plugin/otr/OtrMetaContactButton.java | 23 ++- 5 files changed, 95 insertions(+), 111 deletions(-) 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 61511b8c8..fb1becfed 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 @@ -135,14 +135,10 @@ public ChatPanel(ChatWindow chatWindow) this.writeMessagePanel = new ChatWritePanel(this); int chatAreaSize = ConfigurationManager.getChatWriteAreaSize(); - - Dimension writeMessagePanelDefaultSize; - if (chatAreaSize > 0) - writeMessagePanelDefaultSize = new Dimension(500, chatAreaSize); - else - writeMessagePanelDefaultSize = new Dimension(500, 100); - + Dimension writeMessagePanelDefaultSize + = new Dimension(500, (chatAreaSize > 0) ? chatAreaSize : 100); Dimension writeMessagePanelMinSize = new Dimension(500, 45); + this.writeMessagePanel.setMinimumSize(writeMessagePanelMinSize); this.writeMessagePanel.setPreferredSize(writeMessagePanelDefaultSize); diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindowManager.java b/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindowManager.java index a9a24bb2b..8cced527a 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindowManager.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/ChatWindowManager.java @@ -322,6 +322,8 @@ else if (chatPanel.getChatSession() instanceof GuiActivator.getUIService().getConferenceChatManager() .leaveChatRoom( (AdHocChatRoomWrapper) adHocSession.getDescriptor()); + + closeChatPanel(chatPanel); } else { diff --git a/src/net/java/sip/communicator/impl/gui/main/chat/toolBars/MainToolBar.java b/src/net/java/sip/communicator/impl/gui/main/chat/toolBars/MainToolBar.java index 007b53dfe..ea97b3870 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chat/toolBars/MainToolBar.java +++ b/src/net/java/sip/communicator/impl/gui/main/chat/toolBars/MainToolBar.java @@ -150,14 +150,10 @@ protected void chatChanged(ChatPanel panel) MetaContact contact = GuiActivator.getUIService().getChatContact(panel); - if (contact != null) - { - for (PluginComponent c : pluginContainer.getPluginComponents()) - c.setCurrentContact(contact); - } + for (PluginComponent c : pluginContainer.getPluginComponents()) + c.setCurrentContact(contact); - if (panel.chatSession != null - && panel.chatSession instanceof MetaContactChatSession) + if (panel.chatSession instanceof MetaContactChatSession) { panel.chatSession.addChatTransportChangeListener( new ChatSessionChangeListener() diff --git a/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetAdHocMultiUserChatYahooImpl.java b/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetAdHocMultiUserChatYahooImpl.java index affb176d0..a51385844 100644 --- a/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetAdHocMultiUserChatYahooImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/yahoo/OperationSetAdHocMultiUserChatYahooImpl.java @@ -1,3 +1,9 @@ +/* + * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ package net.java.sip.communicator.impl.protocol.yahoo; import java.io.*; @@ -27,14 +33,14 @@ public class OperationSetAdHocMultiUserChatYahooImpl /** * A list of listeners subscribed for invitations multi user chat events. */ - private Vector invitationListeners + private final List invitationListeners = new Vector(); /** * A list of listeners subscribed for events indicating rejection of a multi * user chat invitation sent by us. */ - private Vector + private final List invitationRejectionListeners = new Vector(); @@ -42,31 +48,31 @@ public class OperationSetAdHocMultiUserChatYahooImpl * Listeners that will be notified of changes in our status in the room such * as us being kicked, banned, or granted admin permissions. */ - private Vector presenceListeners = - new Vector(); + private final List presenceListeners + = new Vector(); /** * A list of the rooms that are currently open by this account. */ - private Hashtable chatRoomCache = - new Hashtable(); + private final Hashtable chatRoomCache + = new Hashtable(); /** * The currently valid Yahoo protocol provider service implementation. */ - private ProtocolProviderServiceYahooImpl yahooProvider = null; + private final ProtocolProviderServiceYahooImpl yahooProvider; /** * The operation set for the basic instant messaging, provides some message * format functions. */ - private OperationSetBasicInstantMessagingYahooImpl opSetBasic = null; + private final OperationSetBasicInstantMessagingYahooImpl opSetBasic; /** * Message decoder allows to convert Yahoo formated messages, which can * contains some specials characters, to HTML or to plain text. */ - private MessageDecoder messageDecoder = new MessageDecoder(); + private final MessageDecoder messageDecoder = new MessageDecoder(); /** * Contacts who have been invited to a chat room during his creation (when a @@ -74,8 +80,8 @@ public class OperationSetAdHocMultiUserChatYahooImpl * room is sent to each of them). These contacts are stored here in order to * avoid them to be invited again after room's creation. */ - private Vector alreadyInvitedContactAddresses = - new Vector(); + private final List alreadyInvitedContactAddresses + = new Vector(); /** * Instantiates the user operation set with a currently valid instance of @@ -210,34 +216,11 @@ public void removePresenceListener( * * @return ChatRoom the chat room that we've just created. */ - public AdHocChatRoom createAdHocChatRoom( String roomName, - Map roomProperties) - throws OperationFailedException, - OperationNotSupportedException + public AdHocChatRoom createAdHocChatRoom(String roomName, + Map roomProperties) + throws OperationFailedException { - AdHocChatRoom chatRoom = null; - - try - { - YahooConference conference = - yahooProvider.getYahooSession().createConference( - new String[] {}, // users invited to this conference - "", // invite message / topic - yahooProvider.getYahooSession().getLoginIdentity()); - - chatRoom = createLocalChatRoomInstance(conference); - } - catch (Exception e) - { - String errorMessage - = "Failed to create chat room with name: " + roomName; - - logger.debug(errorMessage, e); - throw new OperationFailedException(errorMessage, - OperationFailedException.CHAT_ROOM_NOT_JOINED, e); - } - return chatRoom; + return createAdHocChatRoom(roomName, (String[]) null); } /** @@ -252,27 +235,41 @@ public AdHocChatRoom createAdHocChatRoom( String roomName, */ public AdHocChatRoom createAdHocChatRoom( String adHocRoomName, List contacts) + throws OperationFailedException { - AdHocChatRoom chatRoom = null; String[] invitedContacts = null; // parameter used for room's creation - int contactsIndex = 0; if (contacts != null) { + int contactsIndex = 0; + invitedContacts = new String[contacts.size()]; for (Contact contact : contacts) { - ContactYahooImpl newContact = (ContactYahooImpl) contact; - invitedContacts[contactsIndex] = newContact.getAddress(); + String contactAddress = contact.getAddress(); + + invitedContacts[contactsIndex] = contactAddress; + contactsIndex++; // contact's address is stored here in order to avoid this // contact to be invited again in the chat room implementation: - this.alreadyInvitedContactAddresses - .add(newContact.getAddress()); - contactsIndex++; + this.alreadyInvitedContactAddresses.add(contactAddress); } } + return createAdHocChatRoom(adHocRoomName, invitedContacts); + } + + private AdHocChatRoom createAdHocChatRoom( + String roomName, + String[] invitedContacts) + throws OperationFailedException + { + if (invitedContacts == null) + invitedContacts = new String[0]; + + AdHocChatRoom chatRoom = null; + try { YahooConference conference = @@ -282,11 +279,15 @@ public AdHocChatRoom createAdHocChatRoom( String adHocRoomName, yahooProvider.getYahooSession().getLoginIdentity()); chatRoom = createLocalChatRoomInstance(conference); - } catch (Exception e) { - logger.debug("Failed to create the chat Room" + e); + String errorMessage + = "Failed to create chat room with name: " + roomName; + + logger.debug(errorMessage, e); + throw new OperationFailedException(errorMessage, + OperationFailedException.CHAT_ROOM_NOT_JOINED, e); } return chatRoom; } @@ -349,11 +350,10 @@ private AdHocChatRoomYahooImpl getLocalChatRoomInstance( */ public boolean isMultiChatSupportedByContact(Contact contact) { - if (contact.getProtocolProvider().getOperationSet( - OperationSetAdHocMultiUserChat.class) != null) - return true; - - return false; + return + (contact.getProtocolProvider() + .getOperationSet(OperationSetAdHocMultiUserChat.class) + != null); } /** @@ -399,21 +399,16 @@ public void fireInvitationEvent(AdHocChatRoom targetChatRoom, new AdHocChatRoomInvitationReceivedEvent(this, invitation, new Date(System.currentTimeMillis())); - Iterator listeners = null; + Iterable listeners; synchronized (invitationListeners) { - listeners = - new ArrayList( - invitationListeners).iterator(); + listeners + = new ArrayList( + invitationListeners); } - while (listeners.hasNext()) - { - AdHocChatRoomInvitationListener listener = - (AdHocChatRoomInvitationListener) listeners.next(); - + for (AdHocChatRoomInvitationListener listener : listeners) listener.invitationReceived(evt); - } } /** @@ -432,21 +427,16 @@ public void fireInvitationRejectedEvent(AdHocChatRoom sourceChatRoom, (OperationSetAdHocMultiUserChat) this, sourceChatRoom, invitee, reason, new Date(System.currentTimeMillis())); - Iterator listeners = null; + Iterable listeners; synchronized (invitationRejectionListeners) { - listeners = - new ArrayList( - invitationRejectionListeners).iterator(); + listeners + = new ArrayList( + invitationRejectionListeners); } - while (listeners.hasNext()) - { - AdHocChatRoomInvitationRejectionListener listener = - (AdHocChatRoomInvitationRejectionListener) listeners.next(); - + for (AdHocChatRoomInvitationRejectionListener listener : listeners) listener.invitationRejected(evt); - } } /** @@ -466,21 +456,16 @@ public void fireLocalUserPresenceEvent(AdHocChatRoom chatRoom, (OperationSetAdHocMultiUserChat) this, chatRoom, eventType, reason); - Iterator listeners = null; + Iterable listeners; synchronized (presenceListeners) { listeners = new ArrayList( - presenceListeners).iterator(); + presenceListeners); } - while (listeners.hasNext()) - { - LocalUserAdHocChatRoomPresenceListener listener = - (LocalUserAdHocChatRoomPresenceListener) listeners.next(); - + for (LocalUserAdHocChatRoomPresenceListener listener : listeners) listener.localUserAdHocPresenceChanged(evt); - } } /** @@ -489,7 +474,7 @@ public void fireLocalUserPresenceEvent(AdHocChatRoom chatRoom, * * @return Vector contact addresses */ - public Vector getAlreadyInvitedContactAddresses() + public List getAlreadyInvitedContactAddresses() { return alreadyInvitedContactAddresses; } @@ -668,16 +653,10 @@ public void conferenceMessageReceived(SessionConferenceEvent ev) // if the message is decorated by Yahoo, we try to "decode" it // first. if (formattedMessage.startsWith("\u001b")) - { - formattedMessage = - opSetBasic.processLinks(messageDecoder - .decodeToHTML(formattedMessage)); - } - else - { - formattedMessage = - opSetBasic.processLinks(formattedMessage); - } + formattedMessage + = messageDecoder.decodeToHTML(formattedMessage); + + formattedMessage = opSetBasic.processLinks(formattedMessage); // now, we try to fix a wrong usage of the size attribute in the // HTML element diff --git a/src/net/java/sip/communicator/plugin/otr/OtrMetaContactButton.java b/src/net/java/sip/communicator/plugin/otr/OtrMetaContactButton.java index baec85eb5..341740c46 100644 --- a/src/net/java/sip/communicator/plugin/otr/OtrMetaContactButton.java +++ b/src/net/java/sip/communicator/plugin/otr/OtrMetaContactButton.java @@ -139,17 +139,28 @@ public String getName() public void setCurrentContact(Contact contact) { - this.contact = contact; - this.setStatus(OtrActivator.scOtrEngine.getSessionStatus(contact)); - this.setPolicy(OtrActivator.scOtrEngine.getContactPolicy(contact)); + if (this.contact != contact) + { + this.contact = contact; + + this.setStatus(OtrActivator.scOtrEngine.getSessionStatus(contact)); + this.setPolicy(OtrActivator.scOtrEngine.getContactPolicy(contact)); + } } public void setCurrentContact(MetaContact metaContact) { - Contact defaultContact = metaContact.getDefaultContact(); + /* + * TODO What if metaContact is null? Does it mean that this.contact + * should become null? + */ + if (metaContact != null) + { + Contact defaultContact = metaContact.getDefaultContact(); - if (defaultContact != null) - setCurrentContact(defaultContact); + if (defaultContact != null) + setCurrentContact(defaultContact); + } } private void setPolicy(OtrPolicy contactPolicy)