示例#1
0
  /**
   * 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;
  }
示例#2
0
  /**
   * Sends a typing notification state.
   *
   * @param typingState the typing notification state to send
   * @return the result of this operation. One of the TYPING_NOTIFICATION_XXX constants defined in
   *     this class
   */
  public int sendTypingNotification(int typingState) {
    // If this chat transport does not support sms messaging we do
    // nothing here.
    if (!allowsTypingNotifications()) return -1;

    ProtocolProviderService protocolProvider = contact.getProtocolProvider();
    OperationSetTypingNotifications tnOperationSet =
        protocolProvider.getOperationSet(OperationSetTypingNotifications.class);

    // if protocol is not registered or contact is offline don't
    // try to send typing notifications
    if (protocolProvider.isRegistered()
        && contact.getPresenceStatus().getStatus() >= PresenceStatus.ONLINE_THRESHOLD) {
      try {
        tnOperationSet.sendTypingNotification(contact, typingState);

        return ChatPanel.TYPING_NOTIFICATION_SUCCESSFULLY_SENT;
      } catch (Exception ex) {
        logger.error("Failed to send typing notifications.", ex);

        return ChatPanel.TYPING_NOTIFICATION_SEND_FAILED;
      }
    }

    return ChatPanel.TYPING_NOTIFICATION_SEND_FAILED;
  }
示例#3
0
  /**
   * 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);
      }
    }
  }
示例#4
0
    /** 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();
  }
示例#6
0
  /**
   * 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());
    }
  }
示例#7
0
    /**
     * Creates an instance of <tt>MetaContactDetail</tt> by specifying the underlying protocol
     * <tt>Contact</tt>.
     *
     * @param contact the protocol contact, on which this implementation is based
     */
    public MetaContactDetail(Contact contact) {
      super(
          contact.getAddress(),
          contact.getDisplayName(),
          new ImageIcon(contact.getPresenceStatus().getStatusIcon()),
          contact);

      this.contact = contact;

      ProtocolProviderService parentProvider = contact.getProtocolProvider();

      Iterator<Class<? extends OperationSet>> opSetClasses =
          parentProvider.getSupportedOperationSetClasses().iterator();

      while (opSetClasses.hasNext()) {
        Class<? extends OperationSet> opSetClass = opSetClasses.next();

        addPreferredProtocolProvider(opSetClass, parentProvider);
        addPreferredProtocol(opSetClass, parentProvider.getProtocolName());
      }
    }
    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;
    }
示例#9
0
  /**
   * 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);
  }
示例#10
0
  /**
   * 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);
        }
      }
    }
  }