示例#1
0
  /**
   * Returns the url of the avatar belonging to this contact.
   *
   * @return the url of the avatar.
   * @throws MalformedURLException thrown if the address is invalid.
   */
  public URL getAvatarURL() throws MalformedURLException {
    contactsDir.mkdirs();

    if (ModelUtil.hasLength(hash)) {
      final File imageFile = new File(contactsDir, hash);
      if (imageFile.exists()) {
        return imageFile.toURI().toURL();
      }
    }

    return SparkManager.getVCardManager().getAvatarURLIfAvailable(getJID());
  }
示例#2
0
  // I would normally use the command pattern, but
  // have no real use when dealing with just a couple options.
  public void actionPerformed(ActionEvent e) {

    if (e.getSource() == infoButton) {
      VCardManager vcard = SparkManager.getVCardManager();
      vcard.viewProfile(participantJID, SparkManager.getChatManager().getChatContainer());
    } else if (e.getSource() == addToRosterButton) {
      RosterDialog rosterDialog = new RosterDialog();
      rosterDialog.setDefaultJID(participantJID);
      rosterDialog.setDefaultNickname(getParticipantNickname());
      rosterDialog.showRosterDialog(
          SparkManager.getChatManager().getChatContainer().getChatFrame());
    } else {
      super.actionPerformed(e);
    }
  }
  /**
   * Calls an individual user by their VCard information.
   *
   * @param jid the users JID.
   */
  public void callByJID(String jid) {
    if (getStatus() == SipRegisterStatus.Registered) {
      final VCard vcard =
          SparkManager.getVCardManager().getVCard(XmppStringUtils.parseBareJid(jid));

      if (vcard != null) {
        String number = vcard.getPhoneWork("VOICE");
        if (!ModelUtil.hasLength(number)) {
          number = vcard.getPhoneHome("VOICE");
        }

        if (ModelUtil.hasLength(number)) {
          getDefaultGuiManager().dial(number);
        }
      }
    }
  }
示例#4
0
  /** Saves the VCard. */
  private void saveVCard() {
    final VCard vcard = new VCard();

    // Save personal info
    vcard.setFirstName(personalPanel.getFirstName());
    vcard.setLastName(personalPanel.getLastName());
    vcard.setMiddleName(personalPanel.getMiddleName());
    vcard.setEmailHome(personalPanel.getEmailAddress());
    vcard.setNickName(personalPanel.getNickname());

    // Save business info
    vcard.setOrganization(businessPanel.getCompany());
    vcard.setAddressFieldWork("STREET", businessPanel.getStreetAddress());
    vcard.setAddressFieldWork("LOCALITY", businessPanel.getCity());
    vcard.setAddressFieldWork("REGION", businessPanel.getState());
    vcard.setAddressFieldWork("PCODE", businessPanel.getZipCode());
    vcard.setAddressFieldWork("CTRY", businessPanel.getCountry());
    vcard.setField("TITLE", businessPanel.getJobTitle());
    vcard.setOrganizationUnit(businessPanel.getDepartment());
    vcard.setPhoneWork("VOICE", businessPanel.getPhone());
    vcard.setPhoneWork("FAX", businessPanel.getFax());
    vcard.setPhoneWork("PAGER", businessPanel.getPager());
    vcard.setPhoneWork("CELL", businessPanel.getMobile());
    vcard.setField("URL", businessPanel.getWebPage());

    // Save Home Info
    vcard.setAddressFieldHome("STREET", homePanel.getStreetAddress());
    vcard.setAddressFieldHome("LOCALITY", homePanel.getCity());
    vcard.setAddressFieldHome("REGION", homePanel.getState());
    vcard.setAddressFieldHome("PCODE", homePanel.getZipCode());
    vcard.setAddressFieldHome("CTRY", homePanel.getCountry());
    vcard.setPhoneHome("VOICE", homePanel.getPhone());
    vcard.setPhoneHome("FAX", homePanel.getFax());
    vcard.setPhoneHome("PAGER", homePanel.getPager());
    vcard.setPhoneHome("CELL", homePanel.getMobile());

    // Save Avatar
    final File avatarFile = avatarPanel.getAvatarFile();
    byte[] avatarBytes = avatarPanel.getAvatarBytes();

    if (avatarFile != null) {
      try {
        // Make it 48x48
        ImageIcon icon = new ImageIcon(avatarFile.toURI().toURL());
        Image image = icon.getImage();
        image = image.getScaledInstance(-1, 48, Image.SCALE_SMOOTH);
        avatarBytes = GraphicUtils.getBytesFromImage(image);
      } catch (MalformedURLException e) {
        Log.error("Unable to set avatar.", e);
      }
    }

    // If avatar bytes, persist as vcard.
    if (avatarBytes != null) {
      vcard.setAvatar(avatarBytes);
    }

    try {
      final VCardManager vcardManager = SparkManager.getVCardManager();
      vcardManager.setPersonalVCard(vcard);

      vcard.save(SparkManager.getConnection());

      // Notify users.
      if (avatarFile != null || avatarBytes != null) {
        Presence presence = SparkManager.getWorkspace().getStatusBar().getPresence();
        Presence newPresence =
            new Presence(
                presence.getType(),
                presence.getStatus(),
                presence.getPriority(),
                presence.getMode());

        // Change my own presence
        SparkManager.getSessionManager().changePresence(newPresence);

        // Chnage avatar in status bar.
        StatusBar statusBar = SparkManager.getWorkspace().getStatusBar();
        statusBar.setAvatar(new ImageIcon(vcard.getAvatar()));
      } else {
        String firstName = vcard.getFirstName();
        String lastName = vcard.getLastName();
        StatusBar statusBar = SparkManager.getWorkspace().getStatusBar();
        if (ModelUtil.hasLength(firstName) && ModelUtil.hasLength(lastName)) {
          statusBar.setNickname(firstName + " " + lastName);
        } else if (ModelUtil.hasLength(firstName)) {
          statusBar.setNickname(firstName);
        }

        statusBar.setAvatar(null);
      }

      // Notify listenres
      SparkManager.getVCardManager().notifyVCardListeners();
    } catch (XMPPException e) {
      Log.error(e);
      JOptionPane.showMessageDialog(
          SparkManager.getMainWindow(),
          Res.getString("message.vcard.not.supported"),
          Res.getString("title.error"),
          JOptionPane.ERROR_MESSAGE);
    }
  }
示例#5
0
 /** Persists the avatar locally based on the new hash. */
 private void updateAvatar() {
   SparkManager.getVCardManager().addToQueue(getJID());
 }
  /** Builds the part of the incoming call UI with the Callers information. */
  private void buildCallerBlock(String callerID, String phoneNumber) {
    final JPanel panel = new JPanel(new GridBagLayout());
    panel.setBackground(Color.white);
    panel.setBorder(BorderFactory.createLineBorder(new Color(197, 213, 230), 1));

    // Add Avatar
    panel.add(
        avatarLabel,
        new GridBagConstraints(
            0,
            0,
            1,
            3,
            0.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.NONE,
            new Insets(5, 0, 5, 0),
            0,
            0));

    // Add Avatar information
    panel.add(
        titleLabel,
        new GridBagConstraints(
            1,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 0, 0),
            0,
            0));
    panel.add(
        professionLabel,
        new GridBagConstraints(
            1,
            1,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 7, 0, 0),
            0,
            0));
    panel.add(
        phoneLabel,
        new GridBagConstraints(
            1,
            2,
            1,
            1,
            0.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(0, 7, 0, 0),
            0,
            0));

    // Add History labels
    panel.add(
        lastCalledLabel,
        new GridBagConstraints(
            0,
            3,
            2,
            1,
            0.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(15, 5, 0, 0),
            0,
            0));
    panel.add(
        durationLabel,
        new GridBagConstraints(
            0,
            4,
            2,
            1,
            0.0,
            0.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.HORIZONTAL,
            new Insets(5, 5, 0, 0),
            0,
            0));

    // Set default settings
    titleLabel.setForeground(new Color(64, 103, 162));
    titleLabel.setFont(new Font("Dialog", Font.BOLD, 16));

    final VCard vcard = SparkManager.getVCardManager().searchPhoneNumber(phoneNumber);
    if (vcard != null) {
      handleVCardInformation(vcard, phoneNumber);
    } else {
      avatarLabel.setVisible(false);
      professionLabel.setVisible(false);
      phoneLabel.setVisible(true);

      titleLabel.setText(callerID);
      phoneLabel.setText(phoneNumber);
    }

    // Update with previous call history.
    Date lastDate = null;
    long callLength = 0;
    for (HistoryCall call : SoftPhoneManager.getInstance().getLogManager().getCallHistory()) {
      String number = TelephoneUtils.removeInvalidChars(call.getNumber());
      if (number.equals(TelephoneUtils.removeInvalidChars(phoneNumber))) {
        lastDate = new Date(call.getTime());
      }

      callLength = call.getCallLength();
    }

    final StringBuilder builder = new StringBuilder();
    builder.append(PhoneRes.getIString("phone.lastcalled") + ": ");
    if (lastDate == null) {
      builder.append(PhoneRes.getIString("phone.never"));
      durationLabel.setVisible(false);
    } else {
      builder.append(formatter.format(lastDate));
      durationLabel.setText(
          PhoneRes.getIString("phone.duration")
              + ": "
              + ModelUtil.getTimeFromLong(callLength * 1000));
    }

    lastCalledLabel.setText(builder.toString());

    // Add To Panel
    add(
        panel,
        new GridBagConstraints(
            0,
            1,
            1,
            1,
            1.0,
            1.0,
            GridBagConstraints.NORTHWEST,
            GridBagConstraints.BOTH,
            new Insets(5, 5, 5, 5),
            0,
            0));
  }