Ejemplo n.º 1
0
  private void importButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_importButtonActionPerformed
    // get selected items from list and try to start import ..
    List<VCard> selectedContacts = new ArrayList<VCard>();
    DefaultTableModel tableModel = (DefaultTableModel) importContactsTable.getModel();
    if (tableModel.getRowCount() == 0) {
      JOptionPane.showMessageDialog(
          this,
          bundle.getString("list.of.contacts.is.empty"),
          bundle.getString("error"),
          JOptionPane.ERROR_MESSAGE);
    } else {
      int[] sel = importContactsTable.getSelectedRows();
      for (int i = 0; i < sel.length; i++) {
        VCard v = (VCard) tableModel.getValueAt(sel[i], 0);
        selectedContacts.add(v);
      }

      if (selectedContacts.size() == 0) {
        JOptionPane.showMessageDialog(
            this,
            bundle.getString("no.contacts.selected"),
            bundle.getString("error"),
            JOptionPane.ERROR_MESSAGE);
      } else {
        // start import of selected contacts
        client.importContacts(
            selectedContacts.toArray(new VCard[selectedContacts.size()]), isVCFVerified);
        this.dispose();
      }
      for (VCard vc : selectedContacts) {
        System.out.println(vc.getStructuredName().getFamily());
      }
    }
  } // GEN-LAST:event_importButtonActionPerformed
Ejemplo n.º 2
0
 protected void _validate(List list, VCardVersion vcardversion, VCard vcard1) {
   if (url == null && vcard == null) {
     list.add("Property has neither a URL nor an embedded vCard.");
   }
   if (vcard != null) {
     for (vcard1 = vcard.validate(vcardversion).iterator(); vcard1.hasNext(); ) {
       Object obj = (ezvcard.ValidationWarnings.WarningsGroup) vcard1.next();
       vcardversion = ((ezvcard.ValidationWarnings.WarningsGroup) (obj)).getProperty();
       if (vcardversion == null) {
         vcardversion = "";
       } else {
         vcardversion =
             (new StringBuilder())
                 .append("[")
                 .append(vcardversion.getClass().getSimpleName())
                 .append("]: ")
                 .toString();
       }
       obj = ((ezvcard.ValidationWarnings.WarningsGroup) (obj)).getMessages().iterator();
       while (((Iterator) (obj)).hasNext()) {
         String s = (String) ((Iterator) (obj)).next();
         list.add((new StringBuilder()).append(vcardversion).append(s).toString());
       }
     }
   }
 }
Ejemplo n.º 3
0
  /**
   * If properties contain "PREF" parameters and they're being marshalled to 2.1/3.0, then it should
   * find the type with the lowest PREF value and add "TYPE=pref" to it.
   */
  @Test
  public void prepareParameters_pref_parameter() {
    // TODO move this test to VCardPropertyScribeTest (except for the "label" part)
    VCard vcard = new VCard();

    Address adr2 = new Address();
    adr2.setPref(2);
    vcard.addAddress(adr2);

    Address adr1 = new Address();
    adr1.setPref(1);
    vcard.addAddress(adr1);

    Address adr3 = new Address();
    vcard.addAddress(adr3);

    // 2.1 and 3.0 converts the lowest PREF parameter to "TYPE=pref", and removes all the rest
    sensei
        .assertPrepareParams(adr1)
        .versions(V2_1, V3_0)
        .vcard(vcard)
        .expected("TYPE", "pref")
        .run();
    sensei.assertPrepareParams(adr2).versions(V2_1, V3_0).vcard(vcard).run();
    sensei.assertPrepareParams(adr3).versions(V2_1, V3_0).vcard(vcard).run();

    // 4.0 keeps it
    sensei.assertPrepareParams(adr1).versions(V4_0).vcard(vcard).expected("PREF", "1").run();
    sensei.assertPrepareParams(adr2).versions(V4_0).vcard(vcard).expected("PREF", "2").run();
    sensei.assertPrepareParams(adr3).versions(V4_0).vcard(vcard).run();
  }
Ejemplo n.º 4
0
    @Override
    public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {

      if (value instanceof VCard) {
        VCard vc = (VCard) value;
        StructuredName sn = vc.getStructuredName();
        String name =
            sn.getGiven() + " " + sn.getFamily() + " (" + vc.getEmails().get(0).getValue() + ")";
        return super.getTableCellRendererComponent(table, name, isSelected, hasFocus, row, column);
      } else {
        return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
      }
    }
  @Override
  public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

    switch (getItemViewType(position)) {
      case TYPE_ACCOUNT:
        Account account = mDataset.get(position);
        VCard vcard =
            VCardUtils.loadLocalProfileFromDisk(
                mContext.getFilesDir(),
                account.getAccountID(),
                mContext.getString(R.string.unknown));
        if (!vcard.getPhotos().isEmpty()) {
          Bitmap photo = BitmapUtils.cropImageToCircle(vcard.getPhotos().get(0).getData());
          ((AccountView) holder).photo.setImageBitmap(photo);
        } else {
          Drawable photo =
              ResourcesCompat.getDrawable(
                  mContext.getResources(), R.drawable.ic_contact_picture, null);
          ((AccountView) holder).photo.setImageDrawable(photo);
        }
        ((AccountView) holder).alias.setText(vcard.getFormattedName().getValue());
        if (account.isRing()) {
          String username = account.getRegisteredName();
          if (!account.registeringUsername && !TextUtils.isEmpty(username)) {
            ((AccountView) holder).host.setText(username);
          } else {
            ((AccountView) holder).host.setText(account.getUsername());
          }
        } else if (account.isSip() && !account.isIP2IP()) {
          ((AccountView) holder).host.setText(account.getUsername() + "@" + account.getHost());
        } else {
          ((AccountView) holder).host.setText(R.string.account_type_ip2ip);
        }

        ((AccountView) holder)
            .error.setVisibility(account.isRegistered() ? View.GONE : View.VISIBLE);
        break;
      case TYPE_ADD_SIP_ACCOUNT:
        ((AddAccountView) holder).icon.setImageResource(R.drawable.ic_add_black_24dp);
        ((AddAccountView) holder).title.setText(R.string.add_sip_account_title);
        break;
      case TYPE_ADD_RING_ACCOUNT:
        ((AddAccountView) holder).icon.setImageResource(R.drawable.ic_add_black_24dp);
        ((AddAccountView) holder).title.setText(R.string.add_ring_account_title);
        break;
      default:
        break;
    }
  }
Ejemplo n.º 6
0
  @Test
  public void prepareParameters_pref_parameter() {
    Email property = new Email("*****@*****.**");
    property.setPref(1);

    VCard vcard = new VCard();
    vcard.addEmail(property);

    sensei
        .assertPrepareParams(property)
        .versions(V2_1, V3_0)
        .vcard(vcard)
        .expected("TYPE", "pref")
        .run();
    sensei.assertPrepareParams(property).versions(V4_0).vcard(vcard).expected("PREF", "1").run();
  }
Ejemplo n.º 7
0
    public void readProperty(
        String group,
        String propertyName,
        VCardParameters parameters,
        VCardDataType dataType,
        JCardValue value) {
      if ("version".equalsIgnoreCase(propertyName)) {
        // don't unmarshal "version" because we don't treat it as a property
        versionFound = true;

        VCardVersion version = VCardVersion.valueOfByStr(value.asSingle());
        if (version != VCardVersion.V4_0) {
          warnings.add(reader.getLineNum(), propertyName, 30);
        }
        return;
      }

      VCardPropertyScribe<? extends VCardProperty> scribe = index.getPropertyScribe(propertyName);
      if (scribe == null) {
        scribe = new RawPropertyScribe(propertyName);
      }

      Result<? extends VCardProperty> result;
      try {
        result = scribe.parseJson(value, dataType, parameters);
        for (String warning : result.getWarnings()) {
          warnings.add(reader.getLineNum(), warning, propertyName);
        }
      } catch (SkipMeException e) {
        warnings.add(reader.getLineNum(), propertyName, 22, e.getMessage());
        return;
      } catch (CannotParseException e) {
        scribe = new RawPropertyScribe(propertyName);
        result = scribe.parseJson(value, dataType, parameters);

        VCardProperty property = result.getProperty();
        String valueStr = ((RawProperty) property).getValue();
        warnings.add(reader.getLineNum(), propertyName, 25, valueStr, e.getMessage());
      } catch (EmbeddedVCardException e) {
        warnings.add(reader.getLineNum(), propertyName, 31);
        return;
      }

      VCardProperty property = result.getProperty();
      property.setGroup(group);
      vcard.addProperty(property);
    }
Ejemplo n.º 8
0
 public void beginVCard() {
   vcard = new VCard();
   vcard.setVersion(VCardVersion.V4_0);
 }