/** * If sending im is supported check it for supporting html messages if a font is set. As it can be * slow make sure its not on our way */ private void checkImCaps() { if (ConfigurationUtils.getChatDefaultFontFamily() != null && ConfigurationUtils.getChatDefaultFontSize() > 0) { OperationSetBasicInstantMessaging imOpSet = contact.getProtocolProvider().getOperationSet(OperationSetBasicInstantMessaging.class); if (imOpSet != null) imOpSet.isContentTypeSupported(OperationSetBasicInstantMessaging.HTML_MIME_TYPE, contact); } }
/** * Leaves the given chat room. * * @param chatRoomWrapper the chat room to leave. * @return <tt>ChatRoomWrapper</tt> instance associated with the chat room. */ public ChatRoomWrapper leaveChatRoom(ChatRoomWrapper chatRoomWrapper) { ChatRoom chatRoom = chatRoomWrapper.getChatRoom(); if (chatRoom == null) { ResourceManagementService resources = MUCActivator.getResources(); MUCActivator.getAlertUIService() .showAlertDialog( resources.getI18NString("service.gui.WARNING"), resources.getI18NString("service.gui.CHAT_ROOM_LEAVE_NOT_CONNECTED")); return null; } if (chatRoom.isJoined()) chatRoom.leave(); ChatRoomWrapper existChatRoomWrapper = chatRoomList.findChatRoomWrapperFromChatRoom(chatRoom); if (existChatRoomWrapper == null) return null; // We save the choice of the user, before the chat room is really // joined, because even the join fails we want the next time when // we login to join this chat room automatically. ConfigurationUtils.updateChatRoomStatus( chatRoomWrapper.getParentProvider().getProtocolProvider(), chatRoomWrapper.getChatRoomID(), GlobalStatusEnum.OFFLINE_STATUS); return existChatRoomWrapper; }
@Override public void run() { String[] joinOptions; String subject = null; String nickName = null; nickName = ConfigurationUtils.getChatRoomProperty( chatRoomWrapper.getParentProvider().getProtocolProvider(), chatRoomWrapper.getChatRoomID(), "userNickName"); if (nickName == null) { joinOptions = ChatRoomJoinOptionsDialog.getJoinOptions( chatRoomWrapper.getParentProvider().getProtocolProvider(), chatRoomWrapper.getChatRoomID(), MUCActivator.getMUCService() .getDefaultNickname( chatRoomWrapper.getParentProvider().getProtocolProvider())); nickName = joinOptions[0]; subject = joinOptions[1]; } if (nickName != null) MUCActivator.getMUCService().joinChatRoom(chatRoomWrapper, nickName, null, subject); }
/** * Handles the <tt>ActionEvent</tt>, when one of the tool bar buttons is clicked. * * @param e the <tt>ActionEvent</tt> that notified us */ public void actionPerformed(ActionEvent e) { AbstractButton button = (AbstractButton) e.getSource(); String buttonText = button.getName(); ChatPanel chatPanel = chatContainer.getCurrentChat(); if (buttonText.equals("previous")) { chatPanel.loadPreviousPageFromHistory(); } else if (buttonText.equals("next")) { chatPanel.loadNextPageFromHistory(); } else if (buttonText.equals("sendFile")) { SipCommFileChooser scfc = GenericFileDialog.create( null, "Send file...", SipCommFileChooser.LOAD_FILE_OPERATION, ConfigurationUtils.getSendFileLastDir()); File selectedFile = scfc.getFileFromDialog(); if (selectedFile != null) { ConfigurationUtils.setSendFileLastDir(selectedFile.getParent()); chatContainer.getCurrentChat().sendFile(selectedFile); } } else if (buttonText.equals("invite")) { ChatInviteDialog inviteDialog = new ChatInviteDialog(chatPanel); inviteDialog.setVisible(true); } else if (buttonText.equals("leave")) { ChatRoomWrapper chatRoomWrapper = (ChatRoomWrapper) chatPanel.getChatSession().getDescriptor(); ChatRoomWrapper leavedRoomWrapped = GuiActivator.getMUCService().leaveChatRoom(chatRoomWrapper); } else if (buttonText.equals("call")) { call(false, false); } else if (buttonText.equals("callVideo")) { call(true, false); } else if (buttonText.equals("desktop")) { call(true, true); } else if (buttonText.equals("options")) { GuiActivator.getUIService().getConfigurationContainer().setVisible(true); } else if (buttonText.equals("font")) chatPanel.showFontChooserDialog(); else if (buttonText.equals("createConference")) { chatPanel.showChatConferenceDialog(); } }
/** * When a sent message is delivered shows it in the chat conversation panel. * * @param evt the event containing details on the message delivery */ public void messageDelivered(MessageDeliveredEvent evt) { Contact contact = evt.getDestinationContact(); MetaContact metaContact = GuiActivator.getContactListService().findMetaContactByContact(contact); if (logger.isTraceEnabled()) logger.trace("MESSAGE DELIVERED to contact: " + contact.getAddress()); ChatPanel chatPanel = chatWindowManager.getContactChat(metaContact, false); if (chatPanel != null) { Message msg = evt.getSourceMessage(); ProtocolProviderService protocolProvider = contact.getProtocolProvider(); if (logger.isTraceEnabled()) logger.trace( "MESSAGE DELIVERED: process message to chat for contact: " + contact.getAddress() + " MESSAGE: " + msg.getContent()); chatPanel.addMessage( this.mainFrame.getAccountAddress(protocolProvider), this.mainFrame.getAccountDisplayName(protocolProvider), evt.getTimestamp(), Chat.OUTGOING_MESSAGE, msg.getContent(), msg.getContentType(), msg.getMessageUID(), evt.getCorrectedMessageUID()); if (evt.isSmsMessage() && !ConfigurationUtils.isSmsNotifyTextDisabled()) { chatPanel.addMessage( contact.getDisplayName(), new Date(), Chat.ACTION_MESSAGE, GuiActivator.getResources().getI18NString("service.gui.SMS_SUCCESSFULLY_SENT"), "text"); } } }
/** * Opens a chat window for the chat room. * * @param room the chat room. */ public void openChatRoom(ChatRoomWrapper room) { if (room.getChatRoom() == null) { room = createChatRoom( room.getChatRoomName(), room.getParentProvider().getProtocolProvider(), new ArrayList<String>(), "", false, false, true); // leave the chatroom because getChatRoom().isJoined() returns true // otherwise if (room.getChatRoom().isJoined()) room.getChatRoom().leave(); } if (!room.getChatRoom().isJoined()) { String savedNick = ConfigurationUtils.getChatRoomProperty( room.getParentProvider().getProtocolProvider(), room.getChatRoomID(), "userNickName"); String subject = null; if (savedNick == null) { String[] joinOptions = ChatRoomJoinOptionsDialog.getJoinOptions( room.getParentProvider().getProtocolProvider(), room.getChatRoomID(), getDefaultNickname(room.getParentProvider().getProtocolProvider())); savedNick = joinOptions[0]; subject = joinOptions[1]; } if (savedNick != null) { joinChatRoom(room, savedNick, null, subject); } else return; } MUCActivator.getUIService().openChatRoomWindow(room); }
/** * Creates the <tt>UnknownContactPanel</tt> by specifying the parent window. * * @param window the parent window */ public UnknownContactPanel(MainFrame window) { super(new BorderLayout()); this.parentWindow = window; TransparentPanel mainPanel = new TransparentPanel(new BorderLayout()); this.add(mainPanel, BorderLayout.NORTH); if (!ConfigurationUtils.isAddContactDisabled()) { initAddContactButton(); } initCallButton(); initSMSButton(); initTextArea(); mainPanel.add(textArea, BorderLayout.CENTER); if (callButton.getParent() != null) { textArea.setText( GuiActivator.getResources() .getI18NString( "service.gui.NO_CONTACTS_FOUND", new String[] {'"' + parentWindow.getCurrentSearchText() + '"'})); } else { textArea.setText( GuiActivator.getResources().getI18NString("service.gui.NO_CONTACTS_FOUND_SHORT")); } if (buttonPanel.getComponentCount() > 0) { TransparentPanel southPanel = new TransparentPanel(new FlowLayout(FlowLayout.CENTER)); southPanel.add(buttonPanel); mainPanel.add(southPanel, BorderLayout.SOUTH); } loadSkin(); }
/** * Handles the <tt>ActionEvent</tt>, when one of the tool bar buttons is clicked. * * @param e the <tt>ActionEvent</tt> that notified us */ public void actionPerformed(ActionEvent e) { AbstractButton button = (AbstractButton) e.getSource(); String buttonText = button.getName(); ChatPanel chatPanel = chatContainer.getCurrentChat(); if (buttonText.equals("previous")) { chatPanel.loadPreviousPageFromHistory(); } else if (buttonText.equals("next")) { chatPanel.loadNextPageFromHistory(); } else if (buttonText.equals("sendFile")) { SipCommFileChooser scfc = GenericFileDialog.create( null, "Send file...", SipCommFileChooser.LOAD_FILE_OPERATION, ConfigurationUtils.getSendFileLastDir()); File selectedFile = scfc.getFileFromDialog(); if (selectedFile != null) { ConfigurationUtils.setSendFileLastDir(selectedFile.getParent()); chatContainer.getCurrentChat().sendFile(selectedFile); } } else if (buttonText.equals("history")) { HistoryWindow history; HistoryWindowManager historyWindowManager = GuiActivator.getUIService().getHistoryWindowManager(); ChatSession chatSession = chatPanel.getChatSession(); if (historyWindowManager.containsHistoryWindowForContact(chatSession.getDescriptor())) { history = historyWindowManager.getHistoryWindowForContact(chatSession.getDescriptor()); if (history.getState() == JFrame.ICONIFIED) history.setState(JFrame.NORMAL); history.toFront(); } else { history = new HistoryWindow(chatPanel.getChatSession().getDescriptor()); history.setVisible(true); historyWindowManager.addHistoryWindowForContact(chatSession.getDescriptor(), history); } } else if (buttonText.equals("invite")) { ChatInviteDialog inviteDialog = new ChatInviteDialog(chatPanel); inviteDialog.setVisible(true); } else if (buttonText.equals("leave")) { ConferenceChatManager conferenceManager = GuiActivator.getUIService().getConferenceChatManager(); conferenceManager.leaveChatRoom((ChatRoomWrapper) chatPanel.getChatSession().getDescriptor()); } else if (buttonText.equals("call")) { call(false, false); } else if (buttonText.equals("callVideo")) { call(true, false); } else if (buttonText.equals("desktop")) { call(true, true); } else if (buttonText.equals("options")) { GuiActivator.getUIService().getConfigurationContainer().setVisible(true); } else if (buttonText.equals("font")) chatPanel.showFontChooserDialog(); }
/** Initializes this component. */ protected void init() { this.setLayout(new FlowLayout(FlowLayout.LEFT, 3, 0)); this.setOpaque(false); this.add(inviteButton); // if we leave a chat room when we close the window // there is no need for this button if (!ConfigurationUtils.isLeaveChatRoomOnWindowCloseEnabled()) this.add(leaveChatRoomButton); this.add(callButton); this.add(callVideoButton); this.add(desktopSharingButton); this.add(sendFileButton); ChatPanel chatPanel = chatContainer.getCurrentChat(); if (chatPanel == null || !(chatPanel.getChatSession() instanceof MetaContactChatSession)) sendFileButton.setEnabled(false); this.addSeparator(); this.add(historyButton); this.add(previousButton); this.add(nextButton); // We only add the options button if the property SHOW_OPTIONS_WINDOW // specifies so or if it's not set. Boolean showOptionsProp = GuiActivator.getConfigurationService() .getBoolean(ConfigurationFrame.SHOW_OPTIONS_WINDOW_PROPERTY, false); if (showOptionsProp.booleanValue()) { this.add(optionsButton); } this.addSeparator(); if (ConfigurationUtils.isFontSupportEnabled()) { this.add(fontButton); fontButton.setName("font"); fontButton.setToolTipText( GuiActivator.getResources().getI18NString("service.gui.CHANGE_FONT")); fontButton.addActionListener(this); } initSmiliesSelectorBox(); this.addSeparator(); this.inviteButton.setName("invite"); this.inviteButton.setToolTipText( GuiActivator.getResources().getI18NString("service.gui.INVITE")); this.leaveChatRoomButton.setName("leave"); this.leaveChatRoomButton.setToolTipText( GuiActivator.getResources().getI18NString("service.gui.LEAVE")); this.callButton.setName("call"); this.callButton.setToolTipText( GuiActivator.getResources().getI18NString("service.gui.CALL_CONTACT")); this.callVideoButton.setName("callVideo"); this.callVideoButton.setToolTipText( GuiActivator.getResources().getI18NString("service.gui.CALL_CONTACT")); this.desktopSharingButton.setName("desktop"); this.desktopSharingButton.setToolTipText( GuiActivator.getResources().getI18NString("service.gui.SHARE_DESKTOP_WITH_CONTACT")); this.historyButton.setName("history"); this.historyButton.setToolTipText( GuiActivator.getResources().getI18NString("service.gui.HISTORY") + " Ctrl-H"); optionsButton.setName("options"); optionsButton.setToolTipText(GuiActivator.getResources().getI18NString("service.gui.OPTIONS")); this.sendFileButton.setName("sendFile"); this.sendFileButton.setToolTipText( GuiActivator.getResources().getI18NString("service.gui.SEND_FILE")); this.previousButton.setName("previous"); this.previousButton.setToolTipText( GuiActivator.getResources().getI18NString("service.gui.PREVIOUS")); this.nextButton.setName("next"); this.nextButton.setToolTipText(GuiActivator.getResources().getI18NString("service.gui.NEXT")); inviteButton.addActionListener(this); leaveChatRoomButton.addActionListener(this); callButton.addActionListener(this); callVideoButton.addActionListener(this); desktopSharingButton.addActionListener(this); historyButton.addActionListener(this); optionsButton.addActionListener(this); sendFileButton.addActionListener(this); previousButton.addActionListener(this); nextButton.addActionListener(this); }
/** * Performs UI changes after the chat room join task has finished. * * @param returnCode the result code from the chat room join task. */ private void done(String returnCode) { ConfigurationUtils.updateChatRoomStatus( chatRoomWrapper.getParentProvider().getProtocolProvider(), chatRoomWrapper.getChatRoomID(), GlobalStatusEnum.ONLINE_STATUS); String errorMessage = null; if (JOIN_AUTHENTICATION_FAILED_PROP.equals(returnCode)) { chatRoomWrapper.removePassword(); AuthenticationWindowService authWindowsService = ServiceUtils.getService(MUCActivator.bundleContext, AuthenticationWindowService.class); AuthenticationWindowService.AuthenticationWindow authWindow = authWindowsService.create( null, null, null, false, chatRoomWrapper.isPersistent(), AuthenticationWindow.getAuthenticationWindowIcon( chatRoomWrapper.getParentProvider().getProtocolProvider()), resources.getI18NString( "service.gui.AUTHENTICATION_WINDOW_TITLE", new String[] {chatRoomWrapper.getParentProvider().getName()}), resources.getI18NString( "service.gui.CHAT_ROOM_REQUIRES_PASSWORD", new String[] {chatRoomWrapper.getChatRoomName()}), "", null, isFirstAttempt ? null : resources.getI18NString( "service.gui.AUTHENTICATION_FAILED", new String[] {chatRoomWrapper.getChatRoomName()}), null); authWindow.setVisible(true); if (!authWindow.isCanceled()) { joinChatRoom( chatRoomWrapper, nickName, new String(authWindow.getPassword()).getBytes(), authWindow.isRememberPassword(), false, subject); } } else if (JOIN_REGISTRATION_REQUIRED_PROP.equals(returnCode)) { errorMessage = resources.getI18NString( "service.gui.CHAT_ROOM_REGISTRATION_REQUIRED", new String[] {chatRoomWrapper.getChatRoomName()}); } else if (JOIN_PROVIDER_NOT_REGISTERED_PROP.equals(returnCode)) { errorMessage = resources.getI18NString( "service.gui.CHAT_ROOM_NOT_CONNECTED", new String[] {chatRoomWrapper.getChatRoomName()}); } else if (JOIN_SUBSCRIPTION_ALREADY_EXISTS_PROP.equals(returnCode)) { errorMessage = resources.getI18NString( "service.gui.CHAT_ROOM_ALREADY_JOINED", new String[] {chatRoomWrapper.getChatRoomName()}); } else { errorMessage = resources.getI18NString( "service.gui.FAILED_TO_JOIN_CHAT_ROOM", new String[] {chatRoomWrapper.getChatRoomName()}); } if (!JOIN_SUCCESS_PROP.equals(returnCode) && !JOIN_AUTHENTICATION_FAILED_PROP.equals(returnCode)) { MUCActivator.getAlertUIService() .showAlertPopup(resources.getI18NString("service.gui.ERROR"), errorMessage); } if (JOIN_SUCCESS_PROP.equals(returnCode)) { if (rememberPassword) { chatRoomWrapper.savePassword(new String(password)); } if (subject != null) { try { chatRoomWrapper.getChatRoom().setSubject(subject); } catch (OperationFailedException ex) { logger.warn("Failed to set subject."); } } } chatRoomWrapper.firePropertyChange(returnCode); }
/** * Loads the tooltip with the data for current metacontact. * * @param tip the tooltip to fill. */ private void loadTooltip(final ExtendedTooltip tip) { Iterator<Contact> i = metaContact.getContacts(); ContactPhoneUtil contactPhoneUtil = ContactPhoneUtil.getPhoneUtil(metaContact); String statusMessage = null; Contact protocolContact; boolean isLoading = false; while (i.hasNext()) { protocolContact = i.next(); // Set the first found status message. if (statusMessage == null && protocolContact.getStatusMessage() != null && protocolContact.getStatusMessage().length() > 0) statusMessage = protocolContact.getStatusMessage(); if (ConfigurationUtils.isHideAccountStatusSelectorsEnabled()) break; ImageIcon protocolStatusIcon = ImageLoader.getIndexedProtocolIcon( ImageUtils.getBytesInImage(protocolContact.getPresenceStatus().getStatusIcon()), protocolContact.getProtocolProvider()); String contactAddress = protocolContact.getAddress(); // String statusMessage = protocolContact.getStatusMessage(); tip.addLine(protocolStatusIcon, contactAddress); addContactResourceTooltipLines(tip, protocolContact); if (!protocolContact.getProtocolProvider().isRegistered()) continue; contactPhoneUtil.addDetailsResponseListener( protocolContact, new OperationSetServerStoredContactInfo.DetailsResponseListener() { public void detailsRetrieved(final Iterator<GenericDetail> details) { if (!SwingUtilities.isEventDispatchThread()) { SwingUtilities.invokeLater( new Runnable() { public void run() { detailsRetrieved(details); } }); return; } // remove previously shown information // as it contains "Loading..." text tip.removeAllLines(); // load it again loadTooltip(tip); } }); List<String> phones = contactPhoneUtil.getPhones(protocolContact); if (phones != null) { addPhoneTooltipLines(tip, phones.iterator()); } else isLoading = true; } if (isLoading) tip.addLine(null, GuiActivator.getResources().getI18NString("service.gui.LOADING")); if (statusMessage != null) tip.setBottomText(statusMessage); }
/** * Initializes buttons panel. * * @param uiContact the <tt>UIContact</tt> for which we initialize the button panel */ private void initButtonsPanel(UIContact uiContact) { this.remove(chatButton); this.remove(callButton); this.remove(callVideoButton); this.remove(desktopSharingButton); this.remove(addContactButton); clearCustomActionButtons(); if (!isSelected) return; UIContactDetail imContact = null; // For now we support instance messaging only for contacts in our // contact list until it's implemented for external source contacts. if (uiContact.getDescriptor() instanceof MetaContact) imContact = uiContact.getDefaultContactDetail(OperationSetBasicInstantMessaging.class); int x = (statusIcon == null ? 0 : statusIcon.getIconWidth()) + LEFT_BORDER + H_GAP; // Re-initialize the x grid. constraints.gridx = 0; int gridX = 0; if (imContact != null) { x += addButton(chatButton, ++gridX, x, false); } UIContactDetail telephonyContact = uiContact.getDefaultContactDetail(OperationSetBasicTelephony.class); // Check if contact has additional phone numbers, if yes show the // call button ContactPhoneUtil contactPhoneUtil = null; // check for phone stored in contact info only // if telephony contact is missing if (uiContact.getDescriptor() != null && uiContact.getDescriptor() instanceof MetaContact && telephonyContact == null) { contactPhoneUtil = ContactPhoneUtil.getPhoneUtil((MetaContact) uiContact.getDescriptor()); MetaContact metaContact = (MetaContact) uiContact.getDescriptor(); Iterator<Contact> contacts = metaContact.getContacts(); while (contacts.hasNext()) // && !hasPhone) { Contact contact = contacts.next(); if (!contact.getProtocolProvider().isRegistered()) continue; contactPhoneUtil.addDetailsResponseListener( contact, new DetailsListener(treeNode, callButton, uiContact)); } } // for SourceContact in history that do not support telephony, we // show the button but disabled List<ProtocolProviderService> providers = AccountUtils.getOpSetRegisteredProviders(OperationSetBasicTelephony.class, null, null); if ((telephonyContact != null && telephonyContact.getAddress() != null) || (contactPhoneUtil != null && contactPhoneUtil.isCallEnabled() && providers.size() > 0)) { x += addButton(callButton, ++gridX, x, false); } UIContactDetail videoContact = uiContact.getDefaultContactDetail(OperationSetVideoTelephony.class); if (videoContact != null || (contactPhoneUtil != null && contactPhoneUtil.isVideoCallEnabled())) { x += addButton(callVideoButton, ++gridX, x, false); } UIContactDetail desktopContact = uiContact.getDefaultContactDetail(OperationSetDesktopSharingServer.class); if (desktopContact != null || (contactPhoneUtil != null && contactPhoneUtil.isDesktopSharingEnabled())) { x += addButton(desktopSharingButton, ++gridX, x, false); } // enable add contact button if contact source has indicated // that this is possible if (uiContact.getDescriptor() instanceof SourceContact && uiContact.getDefaultContactDetail(OperationSetPersistentPresence.class) != null && AccountUtils.getOpSetRegisteredProviders( OperationSetPersistentPresence.class, null, null) .size() > 0 && !ConfigurationUtils.isAddContactDisabled()) { x += addButton(addContactButton, ++gridX, x, false); } // The list of the contact actions // we will create a button for every action Collection<SIPCommButton> contactActions = uiContact.getContactCustomActionButtons(); int lastGridX = gridX; if (contactActions != null && contactActions.size() > 0) { lastGridX = initContactActionButtons(contactActions, gridX, x); } else { addLabels(gridX); } if (lastAddedButton != null) setButtonBg(lastAddedButton, lastGridX, true); this.setBounds(0, 0, treeContactList.getWidth(), getPreferredSize().height); }
/** * Returns the value of the chat room open automatically property * * @param pps the provider * @param chatRoomId the chat room id * @return the value of the chat room open automatically property */ public static String getChatRoomAutoOpenOption(ProtocolProviderService pps, String chatRoomId) { return ConfigurationUtils.getChatRoomProperty(pps, chatRoomId, "openAutomatically"); }
/** * Sets chat room open automatically property * * @param pps the provider * @param chatRoomId the chat room id * @param value the new value for the property */ public static void setChatRoomAutoOpenOption( ProtocolProviderService pps, String chatRoomId, String value) { ConfigurationUtils.updateChatRoomProperty(pps, chatRoomId, "openAutomatically", value); }
/** Creates an instance of <tt>PresenceFilter</tt>. */ public PresenceFilter() { isShowOffline = ConfigurationUtils.isShowOffline(); initContactSourcePreferences(); }
/** * Sets the show offline property. * * @param isShowOffline indicates if offline contacts are shown */ public void setShowOffline(boolean isShowOffline) { this.isShowOffline = isShowOffline; ConfigurationUtils.setShowOffline(isShowOffline); }