Example #1
0
  /**
   * Adds resources for contact.
   *
   * @param tip the tool tip
   * @param protocolContact the protocol contact, which resources we're looking for
   */
  private void addContactResourceTooltipLines(ExtendedTooltip tip, Contact protocolContact) {
    Collection<ContactResource> contactResources = protocolContact.getResources();

    if (contactResources == null) return;

    Iterator<ContactResource> resourcesIter = contactResources.iterator();

    while (resourcesIter.hasNext()) {
      ContactResource contactResource = resourcesIter.next();

      // We only add the status icon if we have more than one resources,
      // otherwise it will always be identical to the contact status icon.
      ImageIcon protocolStatusIcon = null;
      if (contactResources.size() > 1) {
        protocolStatusIcon =
            ImageLoader.getIndexedProtocolIcon(
                ImageUtils.getBytesInImage(contactResource.getPresenceStatus().getStatusIcon()),
                protocolContact.getProtocolProvider());
      }

      String resourceName =
          (contactResource.getPriority() >= 0)
              ? contactResource.getResourceName() + " (" + contactResource.getPriority() + ")"
              : contactResource.getResourceName();

      if (protocolStatusIcon == null) tip.addSubLine(protocolStatusIcon, resourceName, 27);
      else tip.addSubLine(protocolStatusIcon, resourceName, 20);
    }

    tip.revalidate();
    tip.repaint();
  }
Example #2
0
  /**
   * Searches for additional phone numbers found in contact information
   *
   * @return additional phone numbers found in contact information;
   */
  private List<UIContactDetail> getAdditionalNumbers(boolean onlyMobile) {
    List<UIContactDetail> telephonyContacts = new ArrayList<UIContactDetail>();

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

    while (contacts.hasNext()) {
      Contact contact = contacts.next();
      OperationSetServerStoredContactInfo infoOpSet =
          contact.getProtocolProvider().getOperationSet(OperationSetServerStoredContactInfo.class);
      Iterator<GenericDetail> details;
      ArrayList<String> phones = new ArrayList<String>();

      if (infoOpSet != null) {
        details = infoOpSet.getAllDetailsForContact(contact);

        while (details.hasNext()) {
          GenericDetail d = details.next();

          boolean process = false;

          if (onlyMobile) {
            if (d instanceof MobilePhoneDetail) process = true;
          } else if (d instanceof PhoneNumberDetail
              && !(d instanceof PagerDetail)
              && !(d instanceof FaxDetail)) {
            process = true;
          }

          if (process) {
            PhoneNumberDetail pnd = (PhoneNumberDetail) d;
            if (pnd.getNumber() != null && pnd.getNumber().length() > 0) {
              // skip phones which were already added
              if (phones.contains(pnd.getNumber())) continue;

              phones.add(pnd.getNumber());

              UIContactDetail cd =
                  new UIContactDetailImpl(
                      pnd.getNumber(),
                      pnd.getNumber() + " (" + getLocalizedPhoneNumber(d) + ")",
                      null,
                      new ArrayList<String>(),
                      GuiActivator.getResources().getImage("service.gui.icons.EXTERNAL_PHONE"),
                      null,
                      null,
                      pnd) {
                    @Override
                    public PresenceStatus getPresenceStatus() {
                      return null;
                    }
                  };
              telephonyContacts.add(cd);
            }
          }
        }
      }
    }

    return telephonyContacts;
  }
  /**
   * Permanently removes locally stored message history for the metacontact, remove any recent
   * contacts if any.
   */
  public void eraseLocallyStoredHistory(MetaContact contact) throws IOException {
    List<ComparableEvtObj> toRemove = null;
    synchronized (recentMessages) {
      toRemove = new ArrayList<ComparableEvtObj>();
      Iterator<Contact> iter = contact.getContacts();
      while (iter.hasNext()) {
        Contact item = iter.next();
        String id = item.getAddress();
        ProtocolProviderService provider = item.getProtocolProvider();

        for (ComparableEvtObj msc : recentMessages) {
          if (msc.getProtocolProviderService().equals(provider)
              && msc.getContactAddress().equals(id)) {
            toRemove.add(msc);
          }
        }
      }

      recentMessages.removeAll(toRemove);
    }
    if (recentQuery != null) {
      for (ComparableEvtObj msc : toRemove) {
        recentQuery.fireContactRemoved(msc);
      }
    }
  }
Example #4
0
  /**
   * Returns <tt>true</tt> if the given meta contact is online, <tt>false</tt> otherwise.
   *
   * @param contact the meta contact
   * @return <tt>true</tt> if the given meta contact is online, <tt>false</tt> otherwise
   */
  private boolean isContactOnline(MetaContact contact) {
    // If for some reason the default contact is null we return false.
    Contact defaultContact = contact.getDefaultContact();
    if (defaultContact == null) return false;

    // Lays on the fact that the default contact is the most connected.
    return defaultContact.getPresenceStatus().getStatus() >= PresenceStatus.ONLINE_THRESHOLD;
  }
Example #5
0
    public void run() {
      if (telephony == null) return;

      Call createdCall = null;

      if (contacts != null) {
        Contact contact = (Contact) contacts.get(0);

        // NOTE: The multi user call is not yet implemented!
        // We just get the first contact and create a call for him.
        try {
          createdCall = telephony.createCall(contact);
        } catch (OperationFailedException e) {
          logger.error("The call could not be created: " + e);

          callPanel.getParticipantPanel(contact.getDisplayName()).setState(e.getMessage());

          removeCallPanelWait(callPanel);
        }

        // If the call is successfully created we set the created
        // Call instance to the already existing CallPanel and we
        // add this call to the active calls.
        if (createdCall != null) {
          callPanel.setCall(createdCall, GuiCallParticipantRecord.OUTGOING_CALL);

          activeCalls.put(createdCall, callPanel);
        }
      } else {
        try {
          createdCall = telephony.createCall(stringContact);
        } catch (ParseException e) {
          logger.error("The call could not be created: " + e);

          callPanel.getParticipantPanel(stringContact).setState(e.getMessage());

          removeCallPanelWait(callPanel);
        } catch (OperationFailedException e) {
          logger.error("The call could not be created: " + e);

          callPanel.getParticipantPanel(stringContact).setState(e.getMessage());

          removeCallPanelWait(callPanel);
        }

        // If the call is successfully created we set the created
        // Call instance to the already existing CallPanel and we
        // add this call to the active calls.
        if (createdCall != null) {
          callPanel.setCall(createdCall, GuiCallParticipantRecord.OUTGOING_CALL);

          activeCalls.put(createdCall, callPanel);
        }
      }
    }
Example #6
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 #7
0
  /**
   * Shows a warning message to the user when message delivery has failed.
   *
   * @param evt the event containing details on the message delivery failure
   */
  public void messageDeliveryFailed(MessageDeliveryFailedEvent evt) {
    logger.error(evt.getReason());

    String errorMsg = null;

    Message sourceMessage = (Message) evt.getSource();

    Contact sourceContact = evt.getDestinationContact();

    MetaContact metaContact =
        GuiActivator.getContactListService().findMetaContactByContact(sourceContact);

    if (evt.getErrorCode() == MessageDeliveryFailedEvent.OFFLINE_MESSAGES_NOT_SUPPORTED) {
      errorMsg =
          GuiActivator.getResources()
              .getI18NString(
                  "service.gui.MSG_DELIVERY_NOT_SUPPORTED",
                  new String[] {sourceContact.getDisplayName()});
    } else if (evt.getErrorCode() == MessageDeliveryFailedEvent.NETWORK_FAILURE) {
      errorMsg = GuiActivator.getResources().getI18NString("service.gui.MSG_NOT_DELIVERED");
    } else if (evt.getErrorCode() == MessageDeliveryFailedEvent.PROVIDER_NOT_REGISTERED) {
      errorMsg =
          GuiActivator.getResources().getI18NString("service.gui.MSG_SEND_CONNECTION_PROBLEM");
    } else if (evt.getErrorCode() == MessageDeliveryFailedEvent.INTERNAL_ERROR) {
      errorMsg =
          GuiActivator.getResources().getI18NString("service.gui.MSG_DELIVERY_INTERNAL_ERROR");
    } else {
      errorMsg = GuiActivator.getResources().getI18NString("service.gui.MSG_DELIVERY_ERROR");
    }

    String reason = evt.getReason();
    if (reason != null)
      errorMsg +=
          " "
              + GuiActivator.getResources()
                  .getI18NString("service.gui.ERROR_WAS", new String[] {reason});

    ChatPanel chatPanel = chatWindowManager.getContactChat(metaContact, sourceContact);

    chatPanel.addMessage(
        sourceContact.getAddress(),
        metaContact.getDisplayName(),
        new Date(),
        Chat.OUTGOING_MESSAGE,
        sourceMessage.getContent(),
        sourceMessage.getContentType(),
        sourceMessage.getMessageUID(),
        evt.getCorrectedMessageUID());

    chatPanel.addErrorMessage(metaContact.getDisplayName(), errorMsg);

    chatWindowManager.openChat(chatPanel, false);
  }
  @Override
  public void supportedOperationSetsChanged(ContactCapabilitiesEvent event) {
    Contact contact = event.getSourceContact();

    if (contact == null) return;

    for (ComparableEvtObj msc : recentMessages) {
      if (contact.equals(msc.getContact())) {
        if (recentQuery != null) recentQuery.updateCapabilities(msc, contact);

        return;
      }
    }
  }
Example #9
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 #10
0
  public void setCurrentContact(Contact contact, String resourceName) {
    if (contact == null) {
      this.otrContact = null;
      this.setPolicy(null);
      this.setStatus(ScSessionStatus.PLAINTEXT);
      return;
    }

    if (resourceName == null) {
      OtrContact otrContact = OtrContactManager.getOtrContact(contact, null);
      if (this.otrContact == otrContact) return;
      this.otrContact = otrContact;
      this.setStatus(OtrActivator.scOtrEngine.getSessionStatus(otrContact));
      this.setPolicy(OtrActivator.scOtrEngine.getContactPolicy(contact));
      return;
    }
    for (ContactResource resource : contact.getResources()) {
      if (resource.getResourceName().equals(resourceName)) {
        OtrContact otrContact = OtrContactManager.getOtrContact(contact, resource);
        if (this.otrContact == otrContact) return;
        this.otrContact = otrContact;
        this.setStatus(OtrActivator.scOtrEngine.getSessionStatus(otrContact));
        this.setPolicy(OtrActivator.scOtrEngine.getContactPolicy(contact));
        return;
      }
    }
    logger.debug("Could not find resource for contact " + contact);
  }
Example #11
0
 public void contactPolicyChanged(Contact contact) {
   // OtrMetaContactButton.this.contact can be null.
   if (OtrMetaContactButton.this.otrContact != null
       && contact.equals(OtrMetaContactButton.this.otrContact.contact)) {
     setPolicy(OtrActivator.scOtrEngine.getContactPolicy(contact));
   }
 }
  /**
   * If a contact is renamed update the locally stored message if any.
   *
   * @param evt the <tt>ContactPropertyChangeEvent</tt> containing the source
   */
  @Override
  public void contactModified(ContactPropertyChangeEvent evt) {
    if (!evt.getPropertyName().equals(ContactPropertyChangeEvent.PROPERTY_DISPLAY_NAME)) return;

    Contact contact = evt.getSourceContact();

    if (contact == null) return;

    for (ComparableEvtObj msc : recentMessages) {
      if (contact.equals(msc.getContact())) {
        if (recentQuery != null)
          recentQuery.updateContactDisplayName(msc, contact.getDisplayName());

        return;
      }
    }
  }
Example #13
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 #14
0
  /**
   * 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");
      }
    }
  }
Example #15
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());
      }
    }
  /**
   * Tries to match the event object to already existing ComparableEvtObj in the supplied list.
   *
   * @param obj the object that we will try to match.
   * @param list the list we will search in.
   * @return the found ComparableEvtObj
   */
  private static ComparableEvtObj findRecentMessage(EventObject obj, List<ComparableEvtObj> list) {
    Contact contact = null;
    ChatRoom chatRoom = null;

    if (obj instanceof MessageDeliveredEvent) {
      contact = ((MessageDeliveredEvent) obj).getDestinationContact();
    } else if (obj instanceof MessageReceivedEvent) {
      contact = ((MessageReceivedEvent) obj).getSourceContact();
    } else if (obj instanceof ChatRoomMessageDeliveredEvent) {
      chatRoom = ((ChatRoomMessageDeliveredEvent) obj).getSourceChatRoom();
    } else if (obj instanceof ChatRoomMessageReceivedEvent) {
      chatRoom = ((ChatRoomMessageReceivedEvent) obj).getSourceChatRoom();
    }

    for (ComparableEvtObj evt : list) {
      if ((contact != null && contact.equals(evt.getContact()))
          || (chatRoom != null && chatRoom.equals(evt.getRoom()))) return evt;
    }

    return null;
  }
Example #17
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 #18
0
  /**
   * Implements ListSelectionListener.valueChanged. Enables or disables call and hangup buttons
   * depending on the selection in the contactlist.
   */
  public void valueChanged(ListSelectionEvent e) {
    Object o = mainFrame.getContactListPanel().getContactList().getSelectedValue();

    if ((e.getFirstIndex() != -1 || e.getLastIndex() != -1) && (o instanceof MetaContact)) {
      setCallMetaContact(true);

      // Switch automatically to the appropriate pps in account selector
      // box and enable callButton if telephony is supported.
      Contact contact = ((MetaContact) o).getDefaultContact(OperationSetBasicTelephony.class);

      if (contact != null) {
        callButton.setEnabled(true);

        if (contact.getProtocolProvider().isRegistered())
          getAccountSelectorBox().setSelected(contact.getProtocolProvider());
      } else {
        callButton.setEnabled(false);
      }
    } else if (phoneNumberCombo.isComboFieldEmpty()) {
      callButton.setEnabled(false);
    }
  }
    /**
     * Extract values from <tt>EventObject</tt>.
     *
     * @param source
     */
    public void update(EventObject source) {
      this.eventObject = source;

      if (source instanceof MessageDeliveredEvent) {
        MessageDeliveredEvent e = (MessageDeliveredEvent) source;

        this.contact = e.getDestinationContact();

        this.address = contact.getAddress();
        this.ppService = contact.getProtocolProvider();
        this.timestamp = e.getTimestamp();
      } else if (source instanceof MessageReceivedEvent) {
        MessageReceivedEvent e = (MessageReceivedEvent) source;

        this.contact = e.getSourceContact();

        this.address = contact.getAddress();
        this.ppService = contact.getProtocolProvider();
        this.timestamp = e.getTimestamp();
      } else if (source instanceof ChatRoomMessageDeliveredEvent) {
        ChatRoomMessageDeliveredEvent e = (ChatRoomMessageDeliveredEvent) source;

        this.room = e.getSourceChatRoom();

        this.address = room.getIdentifier();
        this.ppService = room.getParentProvider();
        this.timestamp = e.getTimestamp();
      } else if (source instanceof ChatRoomMessageReceivedEvent) {
        ChatRoomMessageReceivedEvent e = (ChatRoomMessageReceivedEvent) source;

        this.room = e.getSourceChatRoom();

        this.address = room.getIdentifier();
        this.ppService = room.getParentProvider();
        this.timestamp = e.getTimestamp();
      }
    }
  /**
   * Initialize (a new) Whiteboard with contact
   *
   * @param contact Contact used to init whiteboard
   */
  public void initWhiteboard(final Contact contact) {
    opSetWb =
        (OperationSetWhiteboarding)
            contact.getProtocolProvider().getOperationSet(OperationSetWhiteboarding.class);

    if (opSetWb == null) {
      logger.info("Contact does not support whiteboarding");
      return;
    }

    WhiteboardFrame wbf = getWhiteboardFrame(contact);
    if (wbf != null) {
      wbf.setVisible(true);
      return;
    }

    new Thread() {
      public void run() {
        try {
          WhiteboardSession wbSession =
              opSetWb.createWhiteboardSession(contact.getDisplayName(), null);

          WhiteboardFrame wbFrame = new WhiteboardFrame(WhiteboardSessionManager.this, wbSession);

          wbFrames.add(wbFrame);
          wbFrame.setContact(contact);
          wbFrame.setVisible(true);

          wbSession.join();

          wbSession.invite(contact.getAddress());

        } catch (OperationFailedException e) {
          logger.error("Creating a whiteboard session failed.", e);
        } catch (OperationNotSupportedException e) {
          logger.error("Do not support create of whiteboard session", e);
        }
      }
    }.start();
  }
Example #21
0
 /**
  * Returns the presence status of the underlying protocol <tt>Contact</tt>.
  *
  * @return the presence status of the underlying protocol <tt>Contact</tt>
  */
 public PresenceStatus getPresenceStatus() {
   return contact.getPresenceStatus();
 }
Example #22
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);
        }
      }
    }
  }
Example #23
0
  /**
   * When a message is received determines whether to open a new chat window or chat window tab, or
   * to indicate that a message is received from a contact which already has an open chat. When the
   * chat is found checks if in mode "Auto popup enabled" and if this is the case shows the message
   * in the appropriate chat panel.
   *
   * @param protocolContact the source contact of the event
   * @param contactResource the resource from which the contact is writing
   * @param metaContact the metacontact containing <tt>protocolContact</tt>
   * @param message the message to deliver
   * @param eventType the event type
   * @param timestamp the timestamp of the event
   * @param correctedMessageUID the identifier of the corrected message
   * @param isPrivateMessaging if <tt>true</tt> the message is received from private messaging
   *     contact.
   * @param privateContactRoom the chat room associated with the private messaging contact.
   */
  private void messageReceived(
      final Contact protocolContact,
      final ContactResource contactResource,
      final MetaContact metaContact,
      final Message message,
      final int eventType,
      final Date timestamp,
      final String correctedMessageUID,
      final boolean isPrivateMessaging,
      final ChatRoom privateContactRoom) {
    if (!SwingUtilities.isEventDispatchThread()) {
      SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              messageReceived(
                  protocolContact,
                  contactResource,
                  metaContact,
                  message,
                  eventType,
                  timestamp,
                  correctedMessageUID,
                  isPrivateMessaging,
                  privateContactRoom);
            }
          });
      return;
    }

    // Obtain the corresponding chat panel.
    final ChatPanel chatPanel =
        chatWindowManager.getContactChat(
            metaContact, protocolContact, contactResource, message.getMessageUID());

    // Show an envelope on the sender contact in the contact list and
    // in the systray.
    if (!chatPanel.isChatFocused()) contactList.setActiveContact(metaContact, true);

    // Distinguish the message type, depending on the type of event that
    // we have received.
    String messageType = null;

    if (eventType == MessageReceivedEvent.CONVERSATION_MESSAGE_RECEIVED) {
      messageType = Chat.INCOMING_MESSAGE;
    } else if (eventType == MessageReceivedEvent.SYSTEM_MESSAGE_RECEIVED) {
      messageType = Chat.SYSTEM_MESSAGE;
    } else if (eventType == MessageReceivedEvent.SMS_MESSAGE_RECEIVED) {
      messageType = Chat.SMS_MESSAGE;
    }

    String contactAddress =
        (contactResource != null)
            ? protocolContact.getAddress() + " (" + contactResource.getResourceName() + ")"
            : protocolContact.getAddress();

    chatPanel.addMessage(
        contactAddress,
        protocolContact.getDisplayName(),
        timestamp,
        messageType,
        message.getContent(),
        message.getContentType(),
        message.getMessageUID(),
        correctedMessageUID);

    String resourceName = (contactResource != null) ? contactResource.getResourceName() : null;

    if (isPrivateMessaging) {
      chatWindowManager.openPrivateChatForChatRoomMember(privateContactRoom, protocolContact);
    } else {
      chatWindowManager.openChat(chatPanel, false);
    }

    ChatTransport chatTransport =
        chatPanel.getChatSession().findChatTransportForDescriptor(protocolContact, resourceName);

    chatPanel.setSelectedChatTransport(chatTransport, true);
  }
Example #24
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);
  }
  /**
   * 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);
  }