Example #1
0
void AddressEditWidget::setAddresses( const KABC::Addressee &addr,
                                      const KABC::Address::List &list )
{
  mAddressee = addr;

  mAddressList.clear();

  // Insert types for existing numbers.
  mTypeCombo->insertTypeList( list );

  QValueList<int> defaultTypes;
  defaultTypes << KABC::Address::Home;
  defaultTypes << KABC::Address::Work;

  AddresseeConfig config( mAddressee );
  const QValueList<int> configList = config.noDefaultAddrTypes();
  QValueList<int>::ConstIterator it;
  for ( it = configList.begin(); it != configList.end(); ++it )
    defaultTypes.remove( *it );

  // Insert default types.
  // Doing this for mPrefCombo is enough because the list is shared by all
  // combos.
  for ( it = defaultTypes.begin(); it != defaultTypes.end(); ++it ) {
    if ( !mTypeCombo->hasType( *it ) )
      mTypeCombo->insertType( list, *it, Address( *it ) );
  }

  mTypeCombo->updateTypes();

  // find preferred address which will be shown
  int preferred = KABC::Address::Home;  // default if no preferred address set
  KABC::Address::List::ConstIterator addrIt;
  for ( addrIt = list.begin(); addrIt != list.end(); ++addrIt )
    if ( (*addrIt).type() & KABC::Address::Pref ) {
      preferred = (*addrIt).type();
      break;
    }

  mTypeCombo->selectType( preferred );

  updateAddressEdit();
}
Example #2
0
Addressee::List VCardTool::parseVCards(const QString &vcard)
{
    static const QChar semicolonSep(';');
    static const QChar commaSep(',');
    QString identifier;

    Addressee::List addrList;
    const VCard::List vCardList = VCardParser::parseVCards(vcard);

    VCard::List::ConstIterator cardIt;
    VCard::List::ConstIterator listEnd(vCardList.end());
    for(cardIt = vCardList.begin(); cardIt != listEnd; ++cardIt)
    {
        Addressee addr;

        const QStringList idents = (*cardIt).identifiers();
        QStringList::ConstIterator identIt;
        QStringList::ConstIterator identEnd(idents.end());
        for(identIt = idents.begin(); identIt != identEnd; ++identIt)
        {
            const VCardLine::List lines = (*cardIt).lines((*identIt));
            VCardLine::List::ConstIterator lineIt;

            // iterate over the lines
            for(lineIt = lines.begin(); lineIt != lines.end(); ++lineIt)
            {
                identifier = (*lineIt).identifier().lower();
                // ADR
                if(identifier == "adr")
                {
                    Address address;
                    const QStringList addrParts = splitString(semicolonSep, (*lineIt).value().asString());
                    if(addrParts.count() > 0)
                        address.setPostOfficeBox(addrParts[0]);
                    if(addrParts.count() > 1)
                        address.setExtended(addrParts[1]);
                    if(addrParts.count() > 2)
                        address.setStreet(addrParts[2]);
                    if(addrParts.count() > 3)
                        address.setLocality(addrParts[3]);
                    if(addrParts.count() > 4)
                        address.setRegion(addrParts[4]);
                    if(addrParts.count() > 5)
                        address.setPostalCode(addrParts[5]);
                    if(addrParts.count() > 6)
                        address.setCountry(addrParts[6]);

                    int type = 0;

                    const QStringList types = (*lineIt).parameters("type");
                    for(QStringList::ConstIterator it = types.begin(); it != types.end(); ++it)
                        type += mAddressTypeMap[(*it).lower()];

                    address.setType(type);
                    addr.insertAddress(address);
                }

                // AGENT
                else if(identifier == "agent")
                    addr.setAgent(parseAgent(*lineIt));

                // BDAY
                else if(identifier == "bday")
                    addr.setBirthday(parseDateTime((*lineIt).value().asString()));

                // CATEGORIES
                else if(identifier == "categories")
                {
                    const QStringList categories = splitString(commaSep, (*lineIt).value().asString());
                    addr.setCategories(categories);
                }

                // CLASS
                else if(identifier == "class")
                    addr.setSecrecy(parseSecrecy(*lineIt));

                // EMAIL
                else if(identifier == "email")
                {
                    const QStringList types = (*lineIt).parameters("type");
                    addr.insertEmail((*lineIt).value().asString(), types.findIndex("PREF") != -1);
                }

                // FN
                else if(identifier == "fn")
                    addr.setFormattedName((*lineIt).value().asString());

                // GEO
                else if(identifier == "geo")
                {
                    Geo geo;

                    const QStringList geoParts = QStringList::split(';', (*lineIt).value().asString(), true);
                    geo.setLatitude(geoParts[0].toFloat());
                    geo.setLongitude(geoParts[1].toFloat());

                    addr.setGeo(geo);
                }

                // KEY
                else if(identifier == "key")
                    addr.insertKey(parseKey(*lineIt));

                // LABEL
                else if(identifier == "label")
                {
                    int type = 0;

                    const QStringList types = (*lineIt).parameters("type");
                    for(QStringList::ConstIterator it = types.begin(); it != types.end(); ++it)
                        type += mAddressTypeMap[(*it).lower()];

                    bool available = false;
                    KABC::Address::List addressList = addr.addresses();
                    KABC::Address::List::Iterator it;
                    for(it = addressList.begin(); it != addressList.end(); ++it)
                    {
                        if((*it).type() == type)
                        {
                            (*it).setLabel((*lineIt).value().asString());
                            addr.insertAddress(*it);
                            available = true;
                            break;
                        }
                    }

                    if(!available)
                    { // a standalone LABEL tag
                        KABC::Address address(type);
                        address.setLabel((*lineIt).value().asString());
                        addr.insertAddress(address);
                    }
                }

                // LOGO
                else if(identifier == "logo")
                    addr.setLogo(parsePicture(*lineIt));

                // MAILER
                else if(identifier == "mailer")
                    addr.setMailer((*lineIt).value().asString());

                // N
                else if(identifier == "n")
                {
                    const QStringList nameParts = splitString(semicolonSep, (*lineIt).value().asString());
                    if(nameParts.count() > 0)
                        addr.setFamilyName(nameParts[0]);
                    if(nameParts.count() > 1)
                        addr.setGivenName(nameParts[1]);
                    if(nameParts.count() > 2)
                        addr.setAdditionalName(nameParts[2]);
                    if(nameParts.count() > 3)
                        addr.setPrefix(nameParts[3]);
                    if(nameParts.count() > 4)
                        addr.setSuffix(nameParts[4]);
                }

                // NAME
                else if(identifier == "name")
                    addr.setName((*lineIt).value().asString());

                // NICKNAME
                else if(identifier == "nickname")
                    addr.setNickName((*lineIt).value().asString());

                // NOTE
                else if(identifier == "note")
                    addr.setNote((*lineIt).value().asString());

                // ORGANIZATION
                else if(identifier == "org")
                {
                    const QStringList orgParts = splitString(semicolonSep, (*lineIt).value().asString());
                    if(orgParts.count() > 0)
                        addr.setOrganization(orgParts[0]);
                    if(orgParts.count() > 1)
                        addr.setDepartment(orgParts[1]);
                }

                // PHOTO
                else if(identifier == "photo")
                    addr.setPhoto(parsePicture(*lineIt));

                // PROID
                else if(identifier == "prodid")
                    addr.setProductId((*lineIt).value().asString());

                // REV
                else if(identifier == "rev")
                    addr.setRevision(parseDateTime((*lineIt).value().asString()));

                // ROLE
                else if(identifier == "role")
                    addr.setRole((*lineIt).value().asString());

                // SORT-STRING
                else if(identifier == "sort-string")
                    addr.setSortString((*lineIt).value().asString());

                // SOUND
                else if(identifier == "sound")
                    addr.setSound(parseSound(*lineIt));

                // TEL
                else if(identifier == "tel")
                {
                    PhoneNumber phone;
                    phone.setNumber((*lineIt).value().asString());

                    int type = 0;

                    const QStringList types = (*lineIt).parameters("type");
                    for(QStringList::ConstIterator it = types.begin(); it != types.end(); ++it)
                        type += mPhoneTypeMap[(*it).upper()];

                    phone.setType(type);

                    addr.insertPhoneNumber(phone);
                }

                // TITLE
                else if(identifier == "title")
                    addr.setTitle((*lineIt).value().asString());

                // TZ
                else if(identifier == "tz")
                {
                    TimeZone tz;
                    const QString date = (*lineIt).value().asString();

                    int hours = date.mid(1, 2).toInt();
                    int minutes = date.mid(4, 2).toInt();
                    int offset = (hours * 60) + minutes;
                    offset = offset * (date[0] == '+' ? 1 : -1);

                    tz.setOffset(offset);
                    addr.setTimeZone(tz);
                }

                // UID
                else if(identifier == "uid")
                    addr.setUid((*lineIt).value().asString());

                // URL
                else if(identifier == "url")
                    addr.setUrl(KURL((*lineIt).value().asString()));

                // X-
                else if(identifier.startsWith("x-"))
                {
                    const QString key = (*lineIt).identifier().mid(2);
                    int dash = key.find("-");
                    addr.insertCustom(key.left(dash), key.mid(dash + 1), (*lineIt).value().asString());
                }
            }
        }

        addrList.append(addr);
    }

    return addrList;
}
Example #3
0
void AddresseeEditorWidget::save()
{
  if ( !mDirty ) return;

  mAddressee.setRole( mRoleEdit->text() );
  mAddressee.setOrganization( mOrgEdit->text() );
#if KDE_IS_VERSION(3,5,8)
  mAddressee.setDepartment( mDepartmentEdit->text() );
#else
  if ( !mDepartmentEdit->text().isEmpty() )
    mAddressee.insertCustom( "KADDRESSBOOK", "X-Department", mDepartmentEdit->text() );
  else
    mAddressee.removeCustom( "KADDRESSBOOK", "X-Department" );
#endif

  QString homepage = mURLEdit->text().stripWhiteSpace();
  if ( homepage.isEmpty() )
     mAddressee.setUrl( KURL() );
  else {
     if( !homepage.startsWith("http") )
       homepage = "http://" + homepage;
     mAddressee.setUrl( KURL( homepage ) );
  }
  if ( !mBlogEdit->text().isEmpty() )
    mAddressee.insertCustom( "KADDRESSBOOK", "BlogFeed", mBlogEdit->text() );
  else
    mAddressee.removeCustom( "KADDRESSBOOK", "BlogFeed" );

  mAddressee.setNote( mNoteEdit->text() );
  if ( mBirthdayPicker->date().isValid() )
    mAddressee.setBirthday( QDateTime( mBirthdayPicker->date() ) );
  else
    mAddressee.setBirthday( QDateTime() );

  mAddressee.setNickName( mNicknameEdit->text() );
  mAddressee.setCategories( QStringList::split( ",", mCategoryEdit->text() ) );

  mAddressee.setSecrecy( mSecrecyWidget->secrecy() );

  // save custom fields
  if ( !mIMWidget->preferredIM().isEmpty() )
    mAddressee.insertCustom( "KADDRESSBOOK", "X-IMAddress", mIMWidget->preferredIM() );
  else
    mAddressee.removeCustom( "KADDRESSBOOK", "X-IMAddress" );
  if ( !mSpouseEdit->text().isEmpty() )
    mAddressee.insertCustom( "KADDRESSBOOK", "X-SpousesName", mSpouseEdit->text() );
  else
    mAddressee.removeCustom( "KADDRESSBOOK", "X-SpousesName" );
  if ( !mManagerEdit->text().isEmpty() )
    mAddressee.insertCustom( "KADDRESSBOOK", "X-ManagersName", mManagerEdit->text() );
  else
    mAddressee.removeCustom( "KADDRESSBOOK", "X-ManagersName" );
  if ( !mAssistantEdit->text().isEmpty() )
    mAddressee.insertCustom( "KADDRESSBOOK", "X-AssistantsName", mAssistantEdit->text() );
  else
    mAddressee.removeCustom( "KADDRESSBOOK", "X-AssistantsName" );

  if ( !mOfficeEdit->text().isEmpty() )
    mAddressee.insertCustom( "KADDRESSBOOK", "X-Office", mOfficeEdit->text() );
  else
    mAddressee.removeCustom( "KADDRESSBOOK", "X-Office" );
  if ( !mProfessionEdit->text().isEmpty() )
    mAddressee.insertCustom( "KADDRESSBOOK", "X-Profession", mProfessionEdit->text() );
  else
    mAddressee.removeCustom( "KADDRESSBOOK", "X-Profession" );

  if ( mAnniversaryPicker->date().isValid() )
    mAddressee.insertCustom( "KADDRESSBOOK", "X-Anniversary",
                             mAnniversaryPicker->date().toString( Qt::ISODate ) );
  else
    mAddressee.removeCustom( "KADDRESSBOOK", "X-Anniversary" );

  mAddressee.setTitle( mTitleEdit->text() );

  // Save the email addresses
  mAddressee.setEmails( mEmailWidget->emails() );

  // Save the phone numbers
  KABC::PhoneNumber::List phoneNumbers;
  KABC::PhoneNumber::List::ConstIterator phoneIter;
  phoneNumbers = mAddressee.phoneNumbers();
  for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end();
        ++phoneIter )
    mAddressee.removePhoneNumber( *phoneIter );

  phoneNumbers = mPhoneEditWidget->phoneNumbers();
  for ( phoneIter = phoneNumbers.begin(); phoneIter != phoneNumbers.end();
        ++phoneIter )
    mAddressee.insertPhoneNumber( *phoneIter );

  // Save the addresses
  KABC::Address::List addresses;
  KABC::Address::List::ConstIterator addressIter;
  addresses = mAddressee.addresses();
  for ( addressIter = addresses.begin(); addressIter != addresses.end();
        ++addressIter )
    mAddressee.removeAddress( *addressIter );

  addresses = mAddressEditWidget->addresses();
  for ( addressIter = addresses.begin(); addressIter != addresses.end();
        ++addressIter )
    mAddressee.insertAddress( *addressIter );

  QDictIterator<ContactEditorTabPage> it( mTabPages );
  for ( ; it.current(); ++it )
    it.current()->storeContact( &mAddressee );

  mDirty = false;
}
Example #4
0
KABC::AddresseeList VCardXXPort::filterContacts( const KABC::AddresseeList &addrList )
{
  KABC::AddresseeList list;

  if ( addrList.isEmpty() )
    return addrList;

  VCardExportSelectionDialog dlg( parentWidget() );
  if ( !dlg.exec() )
    return list;

  KABC::AddresseeList::ConstIterator it;
  for ( it = addrList.begin(); it != addrList.end(); ++it ) {
    KABC::Addressee addr;

    addr.setUid( (*it).uid() );
    addr.setFormattedName( (*it).formattedName() );
    addr.setPrefix( (*it).prefix() );
    addr.setGivenName( (*it).givenName() );
    addr.setAdditionalName( (*it).additionalName() );
    addr.setFamilyName( (*it).familyName() );
    addr.setSuffix( (*it).suffix() );
    addr.setNickName( (*it).nickName() );
    addr.setMailer( (*it).mailer() );
    addr.setTimeZone( (*it).timeZone() );
    addr.setGeo( (*it).geo() );
    addr.setProductId( (*it).productId() );
    addr.setSortString( (*it).sortString() );
    addr.setUrl( (*it).url() );
    addr.setSecrecy( (*it).secrecy() );
    addr.setSound( (*it).sound() );
    addr.setEmails( (*it).emails() );
    addr.setCategories( (*it).categories() );

    if ( dlg.exportPrivateFields() ) {
      addr.setBirthday( (*it).birthday() );
      addr.setNote( (*it).note() );
      addr.setPhoto( (*it).photo() );
    }

    if ( dlg.exportBusinessFields() ) {
      addr.setTitle( (*it).title() );
      addr.setRole( (*it).role() );
      addr.setOrganization( (*it).organization() );

      addr.setLogo( (*it).logo() );

      KABC::PhoneNumber::List phones = (*it).phoneNumbers( KABC::PhoneNumber::Work );
      KABC::PhoneNumber::List::Iterator phoneIt;
      for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt )
        addr.insertPhoneNumber( *phoneIt );

      KABC::Address::List addresses = (*it).addresses( KABC::Address::Work );
      KABC::Address::List::Iterator addrIt;
      for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt )
        addr.insertAddress( *addrIt );
    }

    KABC::PhoneNumber::List phones = (*it).phoneNumbers();
    KABC::PhoneNumber::List::Iterator phoneIt;
    for ( phoneIt = phones.begin(); phoneIt != phones.end(); ++phoneIt ) {
      int type = (*phoneIt).type();

      if ( type & KABC::PhoneNumber::Home && dlg.exportPrivateFields() )
        addr.insertPhoneNumber( *phoneIt );
      else if ( type & KABC::PhoneNumber::Work && dlg.exportBusinessFields() )
        addr.insertPhoneNumber( *phoneIt );
      else if ( dlg.exportOtherFields() )
        addr.insertPhoneNumber( *phoneIt );
    }

    KABC::Address::List addresses = (*it).addresses();
    KABC::Address::List::Iterator addrIt;
    for ( addrIt = addresses.begin(); addrIt != addresses.end(); ++addrIt ) {
      int type = (*addrIt).type();

      if ( type & KABC::Address::Home && dlg.exportPrivateFields() )
        addr.insertAddress( *addrIt );
      else if ( type & KABC::Address::Work && dlg.exportBusinessFields() )
        addr.insertAddress( *addrIt );
      else if ( dlg.exportOtherFields() )
        addr.insertAddress( *addrIt );
    }

    if ( dlg.exportOtherFields() )
      addr.setCustoms( (*it).customs() );

    if ( dlg.exportEncryptionKeys() ) {
      addKey( addr, KABC::Key::PGP );
      addKey( addr, KABC::Key::X509 );
    }

    list.append( addr );
  }

  return list;
}