From 766d4bbb8f7fcaff5780a89d9ae36231d40472d2 Mon Sep 17 00:00:00 2001 From: Yana Stamcheva Date: Sat, 1 Aug 2009 10:34:37 +0000 Subject: [PATCH] Patch sumbitted by Linus Wallgren. This patch includes two methods allowing other bundles than the gui to obtain existing chats and the contact corresponding to a chat. Thanks Linus! --- .../communicator/impl/gui/UIServiceImpl.java | 35 +++++++++++++++++++ .../impl/gui/main/chat/ChatWindowManager.java | 10 ++++++ .../communicator/service/gui/UIService.java | 19 ++++++++++ 3 files changed, 64 insertions(+) diff --git a/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java b/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java index 6c8d274aa..ef82650d7 100644 --- a/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java +++ b/src/net/java/sip/communicator/impl/gui/UIServiceImpl.java @@ -1137,4 +1137,39 @@ public boolean dispatchKeyEvent(KeyEvent e) return false; } } + + /** + * Returns a list containing all open Chats + * + * @return A list of all open Chats. + */ + public List getChats() + { + List chats = new ArrayList(); + for (ChatPanel chat : chatWindowManager.getChatPanels()) + { + chats.add(chat); + } + return chats; + } + + /** + * Get the MetaContact corresponding to the chat. + * The chat must correspond to a one on one conversation, otherwise this + * method will return null. + * + * @param chat The chat to get the MetaContact from + * @return The MetaContact corresponding to the chat or null in case + * it is a chat with more then one person. + */ + public MetaContact getChatContact(Chat chat) + { + Object contact = ((ChatPanel) chat).getChatSession().getDescriptor(); + // If it is a one on one conversation this would be a MetaContact + if (contact instanceof MetaContact) + return (MetaContact) contact; + // If not, we are talking to more then one person and we return null + else + return null; + } } 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 057a6fbbf..ef2041075 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 @@ -542,6 +542,16 @@ public ChatPanel getMultiChat( ChatRoom chatRoom, } } + /** + * Returns all open ChatPanelīs + * + * @return A list of ChatPanels + */ + public List getChatPanels() + { + return chatPanels; + } + /** * Closes the selected chat tab or the window if there are no tabs. * diff --git a/src/net/java/sip/communicator/service/gui/UIService.java b/src/net/java/sip/communicator/service/gui/UIService.java index 175841ff6..6b044bccc 100644 --- a/src/net/java/sip/communicator/service/gui/UIService.java +++ b/src/net/java/sip/communicator/service/gui/UIService.java @@ -8,8 +8,10 @@ import java.awt.*; import java.util.*; +import java.util.List; import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.service.contactlist.*; /** * The UIService offers generic access to the graphical user interface @@ -211,6 +213,23 @@ public ExportedWindow getExportedWindow(WindowID windowID, Object[] params) */ public Chat getChat(ChatRoom chatRoom); + /** + * Returns a list of all open Chats + * + * @return A list of all open Chats + */ + public List getChats(); + + /** + * Get the MetaContact corresponding to the chat. + * The chat must correspond to a one on one conversation. If it is a + * group chat an exception will be thrown. + * + * @param chat The chat to get the MetaContact from + * @return The MetaContact corresponding to the chat. + */ + public MetaContact getChatContact(Chat chat); + /** * Returns the selected Chat. *