/** * We fill the protocolProviderTable with all running protocol providers at the start of the * bundle. */ private void init() { SystrayActivator.bundleContext.addServiceListener(new ProtocolProviderServiceListener()); ServiceReference[] protocolProviderRefs = null; try { protocolProviderRefs = SystrayActivator.bundleContext.getServiceReferences( ProtocolProviderService.class.getName(), null); } catch (InvalidSyntaxException ex) { // this shouldn't happen since we're providing no parameter string // but let's log just in case. logger.error("Error while retrieving service refs", ex); return; } // in case we found any if (protocolProviderRefs != null) { for (int i = 0; i < protocolProviderRefs.length; i++) { ProtocolProviderService provider = (ProtocolProviderService) SystrayActivator.bundleContext.getService(protocolProviderRefs[i]); boolean isHidden = provider.getAccountID().getAccountProperties().get("HIDDEN_PROTOCOL") != null; if (!isHidden) this.addAccount(provider); } } }
/** * Returns list of <tt>ChatTransport</tt> (i.e. contact) that supports the specified * <tt>OperationSet</tt>. * * @param transports list of <tt>ChatTransport</tt> * @param opSetClass <tt>OperationSet</tt> to find * @return list of <tt>ChatTransport</tt> (i.e. contact) that supports the specified * <tt>OperationSet</tt>. */ private List<ChatTransport> getOperationSetForCapabilities( List<ChatTransport> transports, Class<? extends OperationSet> opSetClass) { List<ChatTransport> list = new ArrayList<ChatTransport>(); for (ChatTransport transport : transports) { ProtocolProviderService protocolProvider = transport.getProtocolProvider(); OperationSetContactCapabilities capOpSet = protocolProvider.getOperationSet(OperationSetContactCapabilities.class); OperationSetPersistentPresence presOpSet = protocolProvider.getOperationSet(OperationSetPersistentPresence.class); if (capOpSet == null) { list.add(transport); } else if (presOpSet != null) { Contact contact = presOpSet.findContactByID(transport.getName()); if ((contact != null) && (capOpSet.getOperationSet(contact, opSetClass) != null)) { // It supports OpSet for at least one of its // ChatTransports list.add(transport); } } } return list; }
/** Fired when an account has changed its status. We update the icon in the menu. */ public void providerStatusChanged(ProviderPresenceStatusChangeEvent evt) { ProtocolProviderService pps = evt.getProvider(); StatusSelector selectorBox = (StatusSelector) accountSelectors.get(pps.getAccountID()); if (selectorBox == null) return; selectorBox.updateStatus(evt.getNewStatus()); }
/** * Creates an instance of <tt>NewStatusMessageDialog</tt>. * * @param protocolProvider the <tt>ProtocolProviderService</tt>. */ public NewStatusMessageDialog(ProtocolProviderService protocolProvider) { presenceOpSet = (OperationSetPersistentPresence) protocolProvider.getOperationSet(OperationSetPresence.class); this.init(); pack(); }
/** * Adds the account corresponding to the given protocol provider to this menu. * * @param protocolProvider the protocol provider corresponding to the account to add */ private void addAccount(ProtocolProviderService protocolProvider) { OperationSetPresence presence = (OperationSetPresence) protocolProvider.getOperationSet(OperationSetPresence.class); if (presence == null) { StatusSimpleSelector simpleSelector = new StatusSimpleSelector(parentSystray, protocolProvider); this.accountSelectors.put(protocolProvider.getAccountID(), simpleSelector); this.add(simpleSelector); } else { StatusSelector statusSelector = new StatusSelector(parentSystray, protocolProvider, presence); this.accountSelectors.put(protocolProvider.getAccountID(), statusSelector); this.add(statusSelector); presence.addProviderPresenceStatusListener(new SystrayProviderPresenceStatusListener()); } }
public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { ProtocolProviderService pps = (ProtocolProviderService) value; OperationSetPresence presence = pps.getOperationSet(OperationSetPresence.class); if (presence != null) { byte[] protocolStatusImage = presence.getPresenceStatus().getStatusIcon(); if (protocolStatusImage != null) { this.setIcon(new ImageIcon(protocolStatusImage)); } else { this.setIcon(null); } } this.setText(pps.getAccountID().getDisplayName()); if (isSelected) this.setBackground(table.getSelectionBackground()); else this.setBackground(UIManager.getColor("Table.background")); return this; }
/** * Creates an account for the given user and password. * * @param providerFactory the ProtocolProviderFactory which will create the account * @param user the user identifier * @return the <tt>ProtocolProviderService</tt> for the new account. */ public ProtocolProviderService installAccount( ProtocolProviderFactory providerFactory, String user) throws OperationFailedException { Hashtable<String, String> accountProperties = new Hashtable<String, String>(); accountProperties.put( ProtocolProviderFactory.ACCOUNT_ICON_PATH, "resources/images/protocol/gibberish/gibberish32x32.png"); if (registration.isRememberPassword()) { accountProperties.put(ProtocolProviderFactory.PASSWORD, registration.getPassword()); } if (isModification()) { providerFactory.uninstallAccount(protocolProvider.getAccountID()); this.protocolProvider = null; setModification(false); } try { AccountID accountID = providerFactory.installAccount(user, accountProperties); ServiceReference serRef = providerFactory.getProviderForAccount(accountID); protocolProvider = (ProtocolProviderService) GibberishAccRegWizzActivator.bundleContext.getService(serRef); } catch (IllegalStateException exc) { logger.warn(exc.getMessage()); throw new OperationFailedException( "Account already exists.", OperationFailedException.IDENTIFICATION_CONFLICT); } catch (Exception exc) { logger.warn(exc.getMessage()); throw new OperationFailedException( "Failed to add account", OperationFailedException.GENERAL_ERROR); } return protocolProvider; }
/** * Removes the account corresponding to the given protocol provider from this menu. * * @param protocolProvider the protocol provider corresponding to the account to remove. */ private void removeAccount(ProtocolProviderService protocolProvider) { Component c = (Component) this.accountSelectors.get(protocolProvider.getAccountID()); this.remove(c); }
/** * Implements the ContactListListener.contactSelected method. * * @param evt the <tt>ContactListEvent</tt> that notified us */ public void contactClicked(ContactListEvent evt) { // We're interested only in two click events. if (evt.getClickCount() < 2) return; UIContact descriptor = evt.getSourceContact(); // We're currently only interested in MetaContacts. if (descriptor.getDescriptor() instanceof MetaContact) { MetaContact metaContact = (MetaContact) descriptor.getDescriptor(); // Searching for the right proto contact to use as default for the // chat conversation. Contact defaultContact = metaContact.getDefaultContact(OperationSetBasicInstantMessaging.class); // do nothing if (defaultContact == null) { defaultContact = metaContact.getDefaultContact(OperationSetSmsMessaging.class); if (defaultContact == null) return; } ProtocolProviderService defaultProvider = defaultContact.getProtocolProvider(); OperationSetBasicInstantMessaging defaultIM = defaultProvider.getOperationSet(OperationSetBasicInstantMessaging.class); ProtocolProviderService protoContactProvider; OperationSetBasicInstantMessaging protoContactIM; boolean isOfflineMessagingSupported = defaultIM != null && !defaultIM.isOfflineMessagingSupported(); if (defaultContact.getPresenceStatus().getStatus() < 1 && (!isOfflineMessagingSupported || !defaultProvider.isRegistered())) { Iterator<Contact> protoContacts = metaContact.getContacts(); while (protoContacts.hasNext()) { Contact contact = protoContacts.next(); protoContactProvider = contact.getProtocolProvider(); protoContactIM = protoContactProvider.getOperationSet(OperationSetBasicInstantMessaging.class); if (protoContactIM != null && protoContactIM.isOfflineMessagingSupported() && protoContactProvider.isRegistered()) { defaultContact = contact; } } } ContactEventHandler contactHandler = mainFrame.getContactHandler(defaultContact.getProtocolProvider()); contactHandler.contactClicked(defaultContact, evt.getClickCount()); } else if (descriptor.getDescriptor() instanceof SourceContact) { SourceContact contact = (SourceContact) descriptor.getDescriptor(); List<ContactDetail> imDetails = contact.getContactDetails(OperationSetBasicInstantMessaging.class); List<ContactDetail> mucDetails = contact.getContactDetails(OperationSetMultiUserChat.class); if (imDetails != null && imDetails.size() > 0) { ProtocolProviderService pps = imDetails.get(0).getPreferredProtocolProvider(OperationSetBasicInstantMessaging.class); GuiActivator.getUIService() .getChatWindowManager() .startChat(contact.getContactAddress(), pps); } else if (mucDetails != null && mucDetails.size() > 0) { ChatRoomWrapper room = GuiActivator.getMUCService().findChatRoomWrapperFromSourceContact(contact); if (room == null) { // lets check by id ProtocolProviderService pps = mucDetails.get(0).getPreferredProtocolProvider(OperationSetMultiUserChat.class); room = GuiActivator.getMUCService() .findChatRoomWrapperFromChatRoomID(contact.getContactAddress(), pps); if (room == null) { GuiActivator.getMUCService() .createChatRoom( contact.getContactAddress(), pps, new ArrayList<String>(), "", false, false, false); } } if (room != null) GuiActivator.getMUCService().openChatRoom(room); } else { List<ContactDetail> smsDetails = contact.getContactDetails(OperationSetSmsMessaging.class); if (smsDetails != null && smsDetails.size() > 0) { GuiActivator.getUIService() .getChatWindowManager() .startChat(contact.getContactAddress(), true); } } } }