Example #1
0
  /** Initializes all search strings for this <tt>MetaUIGroup</tt>. */
  private void initSearchStrings() {
    searchStrings.add(metaContact.getDisplayName());

    Iterator<Contact> contacts = metaContact.getContacts();
    while (contacts.hasNext()) {
      Contact contact = contacts.next();

      searchStrings.add(contact.getDisplayName());
      searchStrings.add(contact.getAddress());
    }
  }
Example #2
0
  /**
   * Returns the tool tip opened on mouse over.
   *
   * @return the tool tip opened on mouse over
   */
  public ExtendedTooltip getToolTip() {
    ExtendedTooltip tip = new ExtendedTooltip(true);

    byte[] avatarImage = metaContact.getAvatar();

    if (avatarImage != null && avatarImage.length > 0) tip.setImage(new ImageIcon(avatarImage));

    tip.setTitle(metaContact.getDisplayName());

    loadTooltip(tip);

    return tip;
  }
Example #3
0
  /**
   * Returns a list of all <tt>UIContactDetail</tt>s within this <tt>UIContact</tt>.
   *
   * @return a list of all <tt>UIContactDetail</tt>s within this <tt>UIContact</tt>
   */
  public List<UIContactDetail> getContactDetails() {
    List<UIContactDetail> resultList = new LinkedList<UIContactDetail>();

    Iterator<Contact> contacts = metaContact.getContacts();

    while (contacts.hasNext()) {
      resultList.add(new MetaContactDetail(contacts.next()));
    }
    return resultList;
  }
Example #4
0
  /**
   * Returns a list of <tt>UIContactDetail</tt>s supporting the given <tt>OperationSet</tt> class.
   *
   * @param opSetClass the <tt>OperationSet</tt> class we're interested in
   * @return a list of <tt>UIContactDetail</tt>s supporting the given <tt>OperationSet</tt> class
   */
  public List<UIContactDetail> getContactDetailsForOperationSet(
      Class<? extends OperationSet> opSetClass) {
    List<UIContactDetail> resultList = new LinkedList<UIContactDetail>();

    Iterator<Contact> contacts = metaContact.getContactsForOperationSet(opSetClass).iterator();

    while (contacts.hasNext()) {
      resultList.add(new MetaContactDetail(contacts.next()));
    }
    return resultList;
  }
Example #5
0
  /**
   * Returns the display name of this <tt>MetaUIContact</tt>.
   *
   * @return the display name of this <tt>MetaUIContact</tt>
   */
  public String getDisplayName() {
    String displayName = metaContact.getDisplayName();

    /*
     * If the MetaContact doesn't tell us a display name, make up a display
     * name so that we don't end up with "Unknown user".
     */
    if ((displayName == null) || (displayName.trim().length() == 0)) {
      /*
       * Try to get a display name from one of the Contacts of the
       * MetaContact. If that doesn't cut it, use the address of a
       * Contact. Because it's not really clear which address to display
       * when there are multiple Contacts, use the address only when
       * there's a single Contact in the MetaContact.
       */
      Iterator<Contact> contactIter = metaContact.getContacts();
      int contactCount = 0;
      String address = null;

      while (contactIter.hasNext()) {
        Contact contact = contactIter.next();

        contactCount++;

        displayName = contact.getDisplayName();
        if ((displayName == null) || (displayName.trim().length() == 0)) {
          /*
           * As said earlier, only use an address if there's a single
           * Contact in the MetaContact.
           */
          address = (contactCount == 1) ? contact.getAddress() : null;
        } else break;
      }
      if ((address != null)
          && (address.trim().length() != 0)
          && ((displayName == null) || (displayName.trim().length() == 0))) displayName = address;
    }
    return displayName;
  }
Example #6
0
  /**
   * Gets the avatar of a specific <tt>MetaContact</tt> in the form of an <tt>ImageIcon</tt> value.
   *
   * @param isSelected indicates if the contact is selected
   * @param width the desired icon width
   * @param height the desired icon height
   * @return an <tt>ImageIcon</tt> which represents the avatar of the specified <tt>MetaContact</tt>
   */
  public ImageIcon getAvatar(boolean isSelected, int width, int height) {
    byte[] avatarBytes = metaContact.getAvatar(true);

    // If there's no avatar we have nothing more to do here.
    if ((avatarBytes == null) || (avatarBytes.length <= 0)) {
      if (!subscribed) {
        return ImageUtils.getScaledRoundedIcon(
            ImageLoader.getImage(ImageLoader.UNAUTHORIZED_CONTACT_PHOTO), width, height);
      }

      return null;
    }

    // If the cell is selected we return a zoomed version of the avatar
    // image.
    if (isSelected) return ImageUtils.getScaledRoundedIcon(avatarBytes, width, height);

    // In any other case try to get the avatar from the cache.
    Object[] avatarCache = (Object[]) metaContact.getData(AVATAR_DATA_KEY);
    ImageIcon avatar = null;

    if ((avatarCache != null) && (avatarCache[0] == avatarBytes))
      avatar = (ImageIcon) avatarCache[1];

    // If the avatar isn't available or it's not up-to-date, create it.
    if (avatar == null) {
      avatar = ImageUtils.getScaledRoundedIcon(avatarBytes, width, height);
    }

    // Cache the avatar in case it has changed.
    if (avatarCache == null) {
      if (avatar != null) metaContact.setData(AVATAR_DATA_KEY, new Object[] {avatarBytes, avatar});
    } else {
      avatarCache[0] = avatarBytes;
      avatarCache[1] = avatar;
    }

    return avatar;
  }
Example #7
0
  /**
   * Returns the general status icon of the given MetaContact. Detects the status using the priority
   * status table. The priority is defined on the "availability" factor and here the most
   * "available" status is returned.
   *
   * @return PresenceStatus The most "available" status from all sub-contact statuses.
   */
  public ImageIcon getStatusIcon() {
    PresenceStatus status = null;
    Iterator<Contact> i = metaContact.getContacts();
    while (i.hasNext()) {
      Contact protoContact = i.next();
      PresenceStatus contactStatus = protoContact.getPresenceStatus();

      if (status == null) status = contactStatus;
      else status = (contactStatus.compareTo(status) > 0) ? contactStatus : status;
    }

    if (status != null) return new ImageIcon(Constants.getStatusIcon(status));

    return null;
  }
Example #8
0
  /**
   * Returns the display details for the underlying <tt>MetaContact</tt>.
   *
   * @return the display details for the underlying <tt>MetaContact</tt>
   */
  public String getDisplayDetails() {
    String displayDetails = null;

    Iterator<Contact> protoContacts = metaContact.getContacts();

    String subscriptionDetails = null;

    while (protoContacts.hasNext()) {
      Contact protoContact = protoContacts.next();

      OperationSetExtendedAuthorizations authOpSet =
          protoContact
              .getProtocolProvider()
              .getOperationSet(OperationSetExtendedAuthorizations.class);

      if (authOpSet != null
          && authOpSet.getSubscriptionStatus(protoContact) != null
          && !authOpSet.getSubscriptionStatus(protoContact).equals(SubscriptionStatus.Subscribed)) {
        SubscriptionStatus status = authOpSet.getSubscriptionStatus(protoContact);

        if (status.equals(SubscriptionStatus.SubscriptionPending))
          subscriptionDetails =
              GuiActivator.getResources().getI18NString("service.gui.WAITING_AUTHORIZATION");
        else if (status.equals(SubscriptionStatus.NotSubscribed))
          subscriptionDetails =
              GuiActivator.getResources().getI18NString("service.gui.NOT_AUTHORIZED");
      } else if (protoContact.getStatusMessage() != null
          && protoContact.getStatusMessage().length() > 0) {
        subscribed = true;
        displayDetails = protoContact.getStatusMessage();
        break;
      } else {
        subscribed = true;
      }
    }

    if ((displayDetails == null || displayDetails.length() <= 0)
        && !subscribed
        && subscriptionDetails != null
        && subscriptionDetails.length() > 0) displayDetails = subscriptionDetails;

    return displayDetails;
  }
Example #9
0
  /**
   * 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);
  }
Example #10
0
 /**
  * Returns the index of the underlying <tt>MetaContact</tt> in its <tt>MetaContactListService</tt>
  * parent group.
  *
  * @return the source index of the underlying <tt>MetaContact</tt>
  */
 public int getSourceIndex() {
   MetaContactGroup parentMetaContactGroup = metaContact.getParentMetaContactGroup();
   if (parentMetaContactGroup == null) return -1;
   return parentMetaContactGroup.indexOf(metaContact);
 }
  /**
   * 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);
  }