diff --git a/resources/languages/resources.properties b/resources/languages/resources.properties index 6a3ec5878..e99cbdfbb 100644 --- a/resources/languages/resources.properties +++ b/resources/languages/resources.properties @@ -320,6 +320,7 @@ service.gui.LAST=Last service.gui.LAST_NAME=Last name service.gui.LEAVE=&Leave service.gui.LIMIT_REACHED_FOR_IP=You have too many existing registrations from the local IP address and the {0} server doesn''t allow to open any more of them. +service.gui.LIST=List service.gui.LOADING_ROOMS=Loading rooms... service.gui.LOADING=Loading... service.gui.LOCALLY_ON_HOLD_STATUS=Locally on hold @@ -475,6 +476,7 @@ service.gui.SELECT_PROVIDERS_FOR_CHAT_ROOM=The list below contains all accounts service.gui.SELECT_PROVIDERS_WIZARD_MSG=The list below contains all registered accounts. Select the one you would like to use to communicate with the new contact. service.gui.SELECT_PROVIDERS_WIZARD=Select account service.gui.SELECT_VIDEO_CONFERENCE=Select video conference +service.gui.SERVER_CHAT_ROOMS_DIALOG_TEXT=Select chat room from the list and press OK to add it. service.gui.SEND=&Send service.gui.SEND_FILE=Send &file service.gui.SELECT_CONTACT_SUPPORTING_INFO=There is no info for this contact. @@ -488,6 +490,7 @@ service.gui.SEND_SMS_NOT_SUPPORTED=The protocol you have selected doesn't suppor service.gui.SMS=SMS service.gui.SEND_VIA=Send via service.gui.SENT=sent +service.gui.SERVER_CHAT_ROOMS=Server Chat Rooms service.gui.SET_GLOBAL_STATUS=Set global status service.gui.SET_STATUS_MESSAGE=Set status message service.gui.SET_SUBJECT=Set subject diff --git a/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomTableDialog.java b/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomTableDialog.java index cf563a0d1..6463db03d 100644 --- a/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomTableDialog.java +++ b/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ChatRoomTableDialog.java @@ -59,6 +59,12 @@ public class ChatRoomTableDialog = new JButton( GuiActivator.getResources().getI18NString( "service.gui.CANCEL")); + /** + * The list button. This button lists the existing chat rooms on the server. + */ + private final JButton listButton + = new JButton(GuiActivator.getResources().getI18NString( + "service.gui.LIST")); /** * The editor for the chat room name. @@ -85,6 +91,11 @@ public class ChatRoomTableDialog */ private SIPCommTextField subject = new SIPCommTextField(DesktopUtilActivator .getResources().getI18NString("service.gui.SUBJECT")); + + /** + * The dialog for the existing chat rooms on the server. + */ + private ServerChatRoomsChoiceDialog serverChatRoomsChoiceDialog = null; /** * The ChatRoomList.ChatRoomProviderWrapperListener instance which @@ -190,9 +201,11 @@ private void init() JPanel buttonPanel = new TransparentPanel(new BorderLayout(5, 5)); buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 15)); JPanel eastButtonPanel = new TransparentPanel(); + JPanel westButtonPanel = new TransparentPanel(); okButton.addActionListener(this); cancelButton.addActionListener(this); + listButton.addActionListener(this); okButton.setToolTipText(GuiActivator.getResources() .getI18NString("service.gui.JOIN_CHAT_ROOM")); @@ -200,8 +213,10 @@ private void init() eastButtonPanel.add(cancelButton); eastButtonPanel.add(okButton); - + westButtonPanel.add(listButton); + buttonPanel.add(eastButtonPanel, BorderLayout.EAST); + buttonPanel.add(westButtonPanel, BorderLayout.WEST); this.getContentPane().add(northPanel, BorderLayout.NORTH); this.getContentPane().add(initMoreFields(), BorderLayout.CENTER); this.getContentPane().add(buttonPanel, BorderLayout.SOUTH); @@ -234,6 +249,9 @@ public void itemStateChanged(ItemEvent event) { setNickname( (ChatRoomProviderWrapper)providersCombo.getSelectedItem()); + if(serverChatRoomsChoiceDialog != null) + serverChatRoomsChoiceDialog.changeProtocolProvider( + getSelectedProvider()); } }); //register listener to listen for newly added chat room providers @@ -376,6 +394,15 @@ else if(sourceButton.equals(cancelButton)) { dispose(); } + else if(sourceButton.equals(listButton)) + { + if(serverChatRoomsChoiceDialog == null) + { + serverChatRoomsChoiceDialog = new ServerChatRoomsChoiceDialog( + getTitle(), getSelectedProvider()); + } + serverChatRoomsChoiceDialog.setVisible(true); + } } @Override @@ -396,7 +423,12 @@ public void dispose() GuiActivator.getMUCService().removeChatRoomProviderWrapperListener( chatRoomProviderWrapperListener); - + if(serverChatRoomsChoiceDialog != null) + { + serverChatRoomsChoiceDialog.dispose(); + serverChatRoomsChoiceDialog = null; + } + super.dispose(); } @@ -410,6 +442,28 @@ public ChatRoomProviderWrapper getSelectedProvider() { return (ChatRoomProviderWrapper)providersCombo.getSelectedItem(); } + + /** + * Sets the value of chat room name field. + * @param chatRoom the chat room name. + */ + public void setChatRoomNameField(String chatRoom) + { + this.chatRoomNameField.setText(chatRoom); + } + + /** + * Sets the value of chat room name field in the current + * ChatRoomTableDialog instance. + * @param chatRoom the chat room name. + */ + public static void setChatRoomField(String chatRoom) + { + if(chatRoomTableDialog != null) + { + chatRoomTableDialog.setChatRoomNameField(chatRoom); + } + } /** * Cell renderer for the providers combo box: displays the protocol name diff --git a/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ServerChatRoomsChoiceDialog.java b/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ServerChatRoomsChoiceDialog.java new file mode 100644 index 000000000..6535daec3 --- /dev/null +++ b/src/net/java/sip/communicator/impl/gui/main/chatroomslist/ServerChatRoomsChoiceDialog.java @@ -0,0 +1,100 @@ +/* + * Jitsi, 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.gui.main.chatroomslist; + +import java.awt.*; +import java.awt.event.*; + +import net.java.sip.communicator.impl.gui.*; +import net.java.sip.communicator.impl.gui.main.contactlist.*; +import net.java.sip.communicator.impl.gui.utils.*; +import net.java.sip.communicator.service.contactsource.*; +import net.java.sip.communicator.service.gui.*; +import net.java.sip.communicator.service.muc.*; + +/** + * A dialog that lists the existing chat rooms on the server. + * + * @author Hristo Terezov + */ +public class ServerChatRoomsChoiceDialog + extends OneChoiceInviteDialog +{ + + /** + * Generated serial id. + */ + private static final long serialVersionUID = 428358553225114162L; + + /** + * The contact source that generates the list of chat rooms. + */ + private ContactSourceService contactSource; + + /** + * Creates new instance of ServerChatRoomsChoiceDialog. + * + * @param title the title of the window. + * @param pps the protocol provider service associated with the list of chat + * rooms. + */ + public ServerChatRoomsChoiceDialog(String title, + ChatRoomProviderWrapper pps) + { + super(title); + contactList.setDefaultFilter(new SearchFilter(contactList)); + contactList.removeAllContactSources(); + contactSource = GuiActivator.getMUCService() + .getServerChatRoomsContactSourceForProvider(pps); + contactList.addContactSource( + contactSource); + + setInfoText(GuiActivator.getResources().getI18NString( + "service.gui.SERVER_CHAT_ROOMS_DIALOG_TEXT")); + + contactList.applyDefaultFilter(); + this.setMinimumSize(new Dimension(300, 300)); + addOkButtonListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + UIContact uiContact = getSelectedContact(); + + if (uiContact != null) + { + ChatRoomTableDialog.setChatRoomField( + uiContact.getDisplayName()); + } + + setVisible(false); + dispose(); + } + }); + addCancelButtonListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + setVisible(false); + dispose(); + } + }); + } + + /** + * Handles provider change. + * + * @param provider the provider. + */ + public void changeProtocolProvider(ChatRoomProviderWrapper provider) + { + contactList.removeContactSource(contactSource); + contactSource = GuiActivator.getMUCService() + .getServerChatRoomsContactSourceForProvider(provider); + contactList.addContactSource(contactSource); + contactList.applyDefaultFilter(); + } +} diff --git a/src/net/java/sip/communicator/impl/muc/BaseChatRoomSourceContact.java b/src/net/java/sip/communicator/impl/muc/BaseChatRoomSourceContact.java new file mode 100644 index 000000000..03c9aec2b --- /dev/null +++ b/src/net/java/sip/communicator/impl/muc/BaseChatRoomSourceContact.java @@ -0,0 +1,136 @@ +/* + * Jitsi, 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.muc; + +import java.util.*; + +import net.java.sip.communicator.service.contactsource.*; +import net.java.sip.communicator.service.muc.*; +import net.java.sip.communicator.service.protocol.*; + +/** + * Basic source contact for the chat rooms. + * + * @author Hristo Terezov + */ +public class BaseChatRoomSourceContact + extends SortedGenericSourceContact +{ + /** + * The name of the chat room associated with the contact. + */ + private String chatRoomName; + + /** + * The ID of the chat room associated with the contact. + */ + private String chatRoomID; + + /** + * The protocol provider of the chat room associated with the contact. + */ + private ProtocolProviderService provider; + + /** + * Contsructs new chat room source contact. + * @param chatRoomName the name of the chat room associated with the room. + * @param chatRoomID the id of the chat room associated with the room. + * @param query the query associated with the contact. + * @param pps the protocol provider of the contact. + * @param isAutoJoin the auto join state. + */ + public BaseChatRoomSourceContact(String chatRoomName, + String chatRoomID, ContactQuery query, ProtocolProviderService pps) + { + super(query, query.getContactSource(), chatRoomName, + generateDefaultContactDetails(chatRoomName)); + + this.chatRoomName = chatRoomName; + this.chatRoomID = chatRoomID; + this.provider = pps; + + initContactProperties(ChatRoomPresenceStatus.CHAT_ROOM_OFFLINE); + + } + + + /** + * Sets the given presence status and the name of the chat room associated + * with the contact. + * @param status the presence status to be set. + */ + protected void initContactProperties(PresenceStatus status) + { + setPresenceStatus(status); + setContactAddress(chatRoomName); + } + + /** + * Generates the default contact details for + * BaseChatRoomSourceContact instances. + * + * @param chatRoomName the name of the chat room associated with the contact + * @return list of default ContactDetails for the contact. + */ + private static List generateDefaultContactDetails( + String chatRoomName) + { + ContactDetail contactDetail + = new ContactDetail(chatRoomName); + List> supportedOpSets + = new ArrayList>(); + + supportedOpSets.add(OperationSetMultiUserChat.class); + contactDetail.setSupportedOpSets(supportedOpSets); + + List contactDetails + = new ArrayList(); + + contactDetails.add(contactDetail); + return contactDetails; + } + + /** + * Returns the id of the chat room associated with the contact. + * + * @return the chat room id. + */ + public String getChatRoomID() + { + return chatRoomID; + } + + /** + * Returns the name of the chat room associated with the contact. + * + * @return the chat room name + */ + public String getChatRoomName() + { + return chatRoomName; + } + + /** + * Returns the provider of the chat room associated with the contact. + * + * @return the provider + */ + public ProtocolProviderService getProvider() + { + return provider; + } + + /** + * Returns the index of this source contact in its parent group. + * + * @return the index of this contact in its parent + */ + @Override + public int getIndex() + { + return -1; + } +} diff --git a/src/net/java/sip/communicator/impl/muc/ChatRoomSourceContact.java b/src/net/java/sip/communicator/impl/muc/ChatRoomSourceContact.java index f2791eeaa..f0a58a06f 100644 --- a/src/net/java/sip/communicator/impl/muc/ChatRoomSourceContact.java +++ b/src/net/java/sip/communicator/impl/muc/ChatRoomSourceContact.java @@ -7,7 +7,6 @@ import java.util.*; -import net.java.sip.communicator.service.contactsource.*; import net.java.sip.communicator.service.muc.*; import net.java.sip.communicator.service.protocol.*; @@ -17,26 +16,12 @@ * @author Hristo Terezov */ public class ChatRoomSourceContact - extends SortedGenericSourceContact + extends BaseChatRoomSourceContact { /** * The parent contact query. */ private final ChatRoomQuery parentQuery; - /** - * The name of the chat room associated with the contact. - */ - private String chatRoomName; - - /** - * The ID of the chat room associated with the contact. - */ - private String chatRoomID; - - /** - * The protocol provider of the chat room associated with the contact. - */ - private ProtocolProviderService provider; /** * The protocol provider of the chat room associated with the contact. @@ -55,17 +40,12 @@ public ChatRoomSourceContact(String chatRoomName, String chatRoomID, ChatRoomQuery query, ProtocolProviderService pps, boolean isAutoJoin) { - super(query, query.getContactSource(), chatRoomName, - generateDefaultContactDetails(chatRoomName)); + super(chatRoomName, chatRoomID, query, pps); - this.chatRoomName = chatRoomName; - this.chatRoomID = chatRoomID; - this.provider = pps; this.parentQuery = query; this.isAutoJoin = isAutoJoin; initContactProperties(getChatRoomStateByName()); - } /** @@ -78,12 +58,8 @@ public ChatRoomSourceContact(String chatRoomName, public ChatRoomSourceContact(ChatRoom chatRoom, ChatRoomQuery query, boolean isAutoJoin) { - super(query, query.getContactSource(), chatRoom.getName(), - generateDefaultContactDetails(chatRoom.getName())); - - this.chatRoomName = chatRoom.getName(); - this.chatRoomID = chatRoom.getIdentifier(); - this.provider = chatRoom.getParentProvider(); + super(chatRoom.getName(), chatRoom.getIdentifier(), query, + chatRoom.getParentProvider()); this.parentQuery = query; this.isAutoJoin = isAutoJoin; @@ -94,16 +70,6 @@ public ChatRoomSourceContact(ChatRoom chatRoom, ChatRoomQuery query, } - /** - * Sets the given presence status and the name of the chat room associated with the - * contact. - * @param status the presence status to be set. - */ - private void initContactProperties(PresenceStatus status) - { - setPresenceStatus(status); - setContactAddress(chatRoomName); - } /** * Checks if the chat room associated with the contact is joinned or not and @@ -114,10 +80,10 @@ private void initContactProperties(PresenceStatus status) private PresenceStatus getChatRoomStateByName() { for(ChatRoom room : - provider.getOperationSet(OperationSetMultiUserChat.class) + getProvider().getOperationSet(OperationSetMultiUserChat.class) .getCurrentlyJoinedChatRooms()) { - if(room.getName().equals(chatRoomName)) + if(room.getName().equals(getChatRoomName())) { return ChatRoomPresenceStatus.CHAT_ROOM_ONLINE; } @@ -125,61 +91,6 @@ private PresenceStatus getChatRoomStateByName() return ChatRoomPresenceStatus.CHAT_ROOM_OFFLINE; } - /** - * Generates the default contact details for ChatRoomSourceContact - * instances. - * - * @param chatRoomName the name of the chat room associated with the contact - * @return list of default ContactDetails for the contact. - */ - private static List generateDefaultContactDetails( - String chatRoomName) - { - ContactDetail contactDetail - = new ContactDetail(chatRoomName); - List> supportedOpSets - = new ArrayList>(); - - supportedOpSets.add(OperationSetMultiUserChat.class); - contactDetail.setSupportedOpSets(supportedOpSets); - - List contactDetails - = new ArrayList(); - - contactDetails.add(contactDetail); - return contactDetails; - } - - /** - * Returns the id of the chat room associated with the contact. - * - * @return the chat room id. - */ - public String getChatRoomID() - { - return chatRoomID; - } - - /** - * Returns the name of the chat room associated with the contact. - * - * @return the chat room name - */ - public String getChatRoomName() - { - return chatRoomName; - } - - /** - * Returns the provider of the chat room associated with the contact. - * - * @return the provider - */ - public ProtocolProviderService getProvider() - { - return provider; - } - /** * Returns the index of this source contact in its parent group. * diff --git a/src/net/java/sip/communicator/impl/muc/MUCServiceImpl.java b/src/net/java/sip/communicator/impl/muc/MUCServiceImpl.java index f773d7d89..05ec70c56 100644 --- a/src/net/java/sip/communicator/impl/muc/MUCServiceImpl.java +++ b/src/net/java/sip/communicator/impl/muc/MUCServiceImpl.java @@ -817,6 +817,12 @@ else if(SUBSCRIPTION_ALREADY_EXISTS.equals(returnCode)) } } + /** + * Finds the ChatRoomWrapper instance associated with the + * source contact. + * @param contact the source contact. + * @return the ChatRoomWrapper instance. + */ public ChatRoomWrapper findChatRoomWrapperFromSourceContact( SourceContact contact) { @@ -826,6 +832,19 @@ public ChatRoomWrapper findChatRoomWrapperFromSourceContact( return chatRoomList.findChatRoomWrapperFromChatRoomID( chatRoomContact.getChatRoomID(), chatRoomContact.getProvider()); } + + /** + * Finds the ChatRoomWrapper instance associated with the + * chat room. + * @param chatRoomID the id of the chat room. + * @param pps the provider of the chat room. + * @return the ChatRoomWrapper instance. + */ + public ChatRoomWrapper findChatRoomWrapperFromChatRoomID(String chatRoomID, + ProtocolProviderService pps) + { + return chatRoomList.findChatRoomWrapperFromChatRoomID(chatRoomID, pps); + } /** * Searches for chat room wrapper in chat room list by chat room. @@ -1043,4 +1062,16 @@ public String getDefaultNickname(ProtocolProviderService pps) return displayName; } + + /** + * Returns instance of the ServerChatRoomContactSourceService + * contact source. + * @return instance of the ServerChatRoomContactSourceService + * contact source. + */ + public ContactSourceService getServerChatRoomsContactSourceForProvider( + ChatRoomProviderWrapper pps) + { + return new ServerChatRoomContactSourceService(pps); + } } diff --git a/src/net/java/sip/communicator/impl/muc/ServerChatRoomContactSourceService.java b/src/net/java/sip/communicator/impl/muc/ServerChatRoomContactSourceService.java new file mode 100644 index 000000000..d2f19e6ec --- /dev/null +++ b/src/net/java/sip/communicator/impl/muc/ServerChatRoomContactSourceService.java @@ -0,0 +1,91 @@ +/* + * Jitsi, 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.muc; + +import net.java.sip.communicator.service.contactsource.*; +import net.java.sip.communicator.service.muc.*; + +/** + * Contact source service for the existing chat rooms on the server. + * + * @author Hristo Terezov + */ +public class ServerChatRoomContactSourceService + implements ContactSourceService +{ + private ChatRoomProviderWrapper provider = null; + public ServerChatRoomContactSourceService(ChatRoomProviderWrapper pps) + { + provider = pps; + } + + /** + * Returns the type of this contact source. + * + * @return the type of this contact source + */ + public int getType() + { + return DEFAULT_TYPE; + } + + /** + * Returns a user-friendly string that identifies this contact source. + * + * @return the display name of this contact source + */ + public String getDisplayName() + { + return MUCActivator.getResources().getI18NString( + "service.gui.SERVER_CHAT_ROOMS"); + } + + /** + * Queries this contact source for the given queryString. + * + * @param queryString the string to search for + * @return the created query + */ + @Override + public ContactQuery queryContactSource(String queryString) + { + return queryContactSource(queryString, -1); + } + + /** + * Queries this contact source for the given queryString. + * + * @param queryString the string to search for + * @param contactCount the maximum count of result contacts + * @return the created query + */ + @Override + public ContactQuery queryContactSource(String queryString, int contactCount) + { + if (queryString == null) + queryString = ""; + + ServerChatRoomQuery contactQuery + = new ServerChatRoomQuery(queryString, this, provider); + + contactQuery.start(); + + + return contactQuery; + } + + /** + * Returns the index of the contact source in the result list. + * + * @return the index of the contact source in the result list + */ + @Override + public int getIndex() + { + return -1; + } + +} diff --git a/src/net/java/sip/communicator/impl/muc/ServerChatRoomQuery.java b/src/net/java/sip/communicator/impl/muc/ServerChatRoomQuery.java new file mode 100644 index 000000000..6a5492341 --- /dev/null +++ b/src/net/java/sip/communicator/impl/muc/ServerChatRoomQuery.java @@ -0,0 +1,261 @@ +/* + * Jitsi, 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.muc; + +import java.util.*; +import java.util.regex.*; + +import net.java.sip.communicator.service.contactsource.*; +import net.java.sip.communicator.service.muc.*; +import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.util.Logger; + +/** + * The ServerChatRoomQuery is a query over the + * ServerChatRoomContactSourceService. + * + * @author Hristo Terezov + */ +public class ServerChatRoomQuery + extends AsyncContactQuery + implements ChatRoomProviderWrapperListener +{ + /** + * The query string. + */ + private String queryString; + + /** + * List with the current results for the query. + */ + private List contactResults + = new ArrayList(); + + /** + * MUC service. + */ + private MUCServiceImpl mucService; + + /** + * The number of contact query listeners. + */ + private int contactQueryListenersCount = 0; + + /** + * The provider associated with the query. + */ + private ChatRoomProviderWrapper provider = null; + + /** + * Creates an instance of ChatRoomQuery by specifying + * the parent contact source, the query string to match and the maximum + * result contacts to return. + * + * @param contactSource the parent contact source + * @param queryString the query string to match + * @param provider the provider associated with the query + * @param count the maximum result contact count + */ + public ServerChatRoomQuery(String queryString, + ServerChatRoomContactSourceService contactSource, + ChatRoomProviderWrapper provider) + { + super(contactSource, + Pattern.compile(queryString, Pattern.CASE_INSENSITIVE + | Pattern.LITERAL), true); + this.queryString = queryString; + + mucService = MUCActivator.getMUCService(); + + this.provider = provider; + } + + /** + * Adds listeners for the query + */ + private void initListeners() + { + mucService.addChatRoomProviderWrapperListener(this); + } + + @Override + protected void run() + { + if(provider == null) + { + Iterator chatRoomProviders + = mucService.getChatRoomProviders(); + while (chatRoomProviders.hasNext()) + { + ChatRoomProviderWrapper provider = chatRoomProviders.next(); + providerAdded(provider, true); + } + } + else + { + providerAdded(provider, true); + } + + if (getStatus() != QUERY_CANCELED) + setStatus(QUERY_COMPLETED); + } + + /** + * Handles adding a chat room provider. + * @param provider the provider. + * @param addQueryResult indicates whether we should add the chat room to + * the query results or fire an event without adding it to the results. + */ + private void providerAdded(ChatRoomProviderWrapper provider, + boolean addQueryResult) + { + List chatRoomNames + = MUCActivator.getMUCService().getExistingChatRooms(provider); + if(chatRoomNames == null) + return; + for(String chatRoomName : chatRoomNames) + { + addChatRoom( provider.getProtocolProvider(), chatRoomName, + chatRoomName, addQueryResult); + } + } + + + /** + * Adds found result to the query results. + * + * @param pps the protocol provider associated with the found chat room. + * @param chatRoomName the name of the chat room. + * @param chatRoomID the id of the chat room. + * @param addQueryResult indicates whether we should add the chat room to + * the query results or fire an event without adding it to the results. + * @param isAutoJoin the auto join state of the contact. + */ + private void addChatRoom(ProtocolProviderService pps, + String chatRoomName, String chatRoomID, boolean addQueryResult) + { + if((queryString == null + || ((chatRoomName.contains( + queryString) + || chatRoomID.contains(queryString) + ))) && isMatching(chatRoomID, pps)) + { + BaseChatRoomSourceContact contact + = new BaseChatRoomSourceContact(chatRoomName, chatRoomID, this, + pps); + synchronized (contactResults) + { + contactResults.add(contact); + } + + if(addQueryResult) + { + addQueryResult(contact, false); + } + else + { + fireContactReceived(contact, false); + } + } + } + + @Override + public void chatRoomProviderWrapperAdded(ChatRoomProviderWrapper provider) + { + providerAdded(provider, false); + } + + @Override + public void chatRoomProviderWrapperRemoved(ChatRoomProviderWrapper provider) + { + LinkedList tmpContactResults; + synchronized (contactResults) + { + tmpContactResults + = new LinkedList(contactResults); + + for(BaseChatRoomSourceContact contact : tmpContactResults) + { + if(contact.getProvider().equals(provider.getProtocolProvider())) + { + contactResults.remove(contact); + fireContactRemoved(contact); + } + } + } + } + + + /** + * Clears any listener we used. + */ + private void clearListeners() + { + mucService.removeChatRoomProviderWrapperListener(this); + } + + /** + * Cancels this ContactQuery. + * + * @see ContactQuery#cancel() + */ + public void cancel() + { + clearListeners(); + + super.cancel(); + } + + /** + * If query has status changed to cancel, let's clear listeners. + * @param status {@link ContactQuery#QUERY_CANCELED}, + * {@link ContactQuery#QUERY_COMPLETED} + */ + public void setStatus(int status) + { + if(status == QUERY_CANCELED) + clearListeners(); + + super.setStatus(status); + } + + @Override + public void addContactQueryListener(ContactQueryListener l) + { + super.addContactQueryListener(l); + contactQueryListenersCount++; + if(contactQueryListenersCount == 1) + { + initListeners(); + } + } + + @Override + public void removeContactQueryListener(ContactQueryListener l) + { + super.removeContactQueryListener(l); + contactQueryListenersCount--; + if(contactQueryListenersCount == 0) + { + clearListeners(); + } + } + + /** + * Checks if the contact should be added to results or not. + * @param chatRoomID the chat room id associated with the contact. + * @param pps the provider of the chat room contact. + * @return true if the result should be added to the results and + * false if not. + */ + public boolean isMatching(String chatRoomID, ProtocolProviderService pps) + { + Logger.getLogger(getClass()).info("QQQQQQQQQQQQQQQQQQQQQQ " + chatRoomID + ' ' + (MUCActivator.getMUCService().findChatRoomWrapperFromChatRoomID( + chatRoomID, pps) == null)); + return (MUCActivator.getMUCService().findChatRoomWrapperFromChatRoomID( + chatRoomID, pps) == null); + } +} \ No newline at end of file diff --git a/src/net/java/sip/communicator/service/muc/MUCService.java b/src/net/java/sip/communicator/service/muc/MUCService.java index 3f93ea933..fc4675fb1 100644 --- a/src/net/java/sip/communicator/service/muc/MUCService.java +++ b/src/net/java/sip/communicator/service/muc/MUCService.java @@ -295,5 +295,14 @@ public abstract ChatRoomWrapper findChatRoomWrapperFromChatRoom( */ public abstract String getDefaultNickname( ProtocolProviderService pps); + + /** + * Returns instance of the ServerChatRoomContactSourceService + * contact source. + * @return instance of the ServerChatRoomContactSourceService + * contact source. + */ + public abstract ContactSourceService + getServerChatRoomsContactSourceForProvider(ChatRoomProviderWrapper pps); }