Пример #1
0
void AddressEditDialog::updateAddressEdits()
{
  if ( mPreviousAddress )
    saveAddress( *mPreviousAddress );

  KABC::Address::List::Iterator it = mTypeCombo->selectedElement();
  KABC::Address a = *it;
  mPreviousAddress = &(*it);

  bool tmp = mChanged;

  mStreetTextEdit->setText( a.street() );
  mRegionEdit->setText( a.region() );
  mLocalityEdit->setText( a.locality() );
  mPostalCodeEdit->setText( a.postalCode() );
  mPOBoxEdit->setText( a.postOfficeBox() );
  mCountryCombo->setCurrentText( a.country() );
  mLabel = a.label();

  mPreferredCheckBox->setChecked( a.type() & KABC::Address::Pref );

  if ( a.isEmpty() )
    mCountryCombo->setCurrentText( KGlobal::locale()->twoAlphaToCountryName( KGlobal::locale()->country() ) );

  mStreetTextEdit->setFocus();

  mChanged = tmp;
}
Пример #2
0
void AddressEditWidget::fixPreferredAddress( const KABC::Address &preferredAddress )
{
  // as the preferred address is mutual exclusive, we have to
  // remove the flag from all other addresses
  if ( preferredAddress.type() & KABC::Address::Pref ) {
    for ( int i = 0; i < mAddressList.count(); ++i ) {
      KABC::Address &address = mAddressList[ i ];
      address.setType( address.type() & ~KABC::Address::Pref );
    }
  }
}
Пример #3
0
void AddressEditDialog::saveAddress( KABC::Address &addr )
{
  addr.setLocality( mLocalityEdit->text() );
  addr.setRegion( mRegionEdit->text() );
  addr.setPostalCode( mPostalCodeEdit->text() );
  addr.setCountry( mCountryCombo->currentText() );
  addr.setPostOfficeBox( mPOBoxEdit->text() );
  addr.setStreet( mStreetTextEdit->text() );
  addr.setLabel( mLabel );


  if ( mPreferredCheckBox->isChecked() ) {
    KABC::Address::List::Iterator it;
    for ( it = mAddressList.begin(); it != mAddressList.end(); ++it )
      (*it).setType( (*it).type() & ~( KABC::Address::Pref ) );

    addr.setType( addr.type() | KABC::Address::Pref );
  } else
    addr.setType( addr.type() & ~( KABC::Address::Pref ) );
}
Пример #4
0
void AddressEditWidget::updateAddressEdit()
{
  KABC::Address::List::Iterator it = mTypeCombo->selectedElement();

  bool block = signalsBlocked();
  blockSignals( true );

  mAddressField->setText( "" );

  if ( it != mAddressList.end() ) {
    KABC::Address a = *it;
    if ( !a.isEmpty() ) {
#if KDE_VERSION >= 319
      if ( a.type() & KABC::Address::Work && mAddressee.realName() != mAddressee.organization() ) {
        mAddressField->setText( a.formattedAddress( mAddressee.realName(),
                                   mAddressee.organization() ) );
      } else {
        mAddressField->setText( a.formattedAddress( mAddressee.realName() ) );
      }
#else
      QString text;
      if ( !a.street().isEmpty() )
        text += a.street() + "\n";

      if ( !a.postOfficeBox().isEmpty() )
        text += a.postOfficeBox() + "\n";

      text += a.locality() + QString(" ") + a.region();

      if ( !a.postalCode().isEmpty() )
        text += QString(", ") + a.postalCode();

      text += "\n";

      if ( !a.country().isEmpty() )
        text += a.country() + "\n";

      text += a.extended();

      mAddressField->setText( text );
#endif
    }
  }

  blockSignals( block );
}
Пример #5
0
QString Contact::toXml(const KABC::Addressee &addr)
{
    /**
     * Handle distribution lists.
     */
    if(KPIM::DistributionList::isDistributionList(addr))
    {
        if(s_distListMap)
            return (*s_distListMap)[ addr.uid() ];
        else
            return QString();
    }

    /**
     * Handle normal contacts.
     */
    QString xml;
    xml += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    xml += "<contact>\n";

    xml += "<direct_ref>" + addr.uid() + "</direct_ref>\n";
    xml += "<sensitivity>" + custom("sensitivity", addr, "0") + "</sensitivity>\n";

    xml += "<message_class>IPM.Contact</message_class>\n";
    xml += "<is_recurring>" + custom("is_recurring", addr, "false") + "</is_recurring>\n";
    xml += "<reminder_set>" + custom("reminder_set", addr, "false") + "</reminder_set>\n";
    xml += "<send_rich_info>" + custom("send_rich_info", addr, "false") + "</send_rich_info>\n";
    xml += "<subject>" + addr.formattedName() + "</subject>\n";
    xml += "<last_modification_time>" + addr.revision().toString(Qt::ISODate) + "</last_modification_time>\n";

    xml += "<display_name_prefix>" + addr.prefix() + "</display_name_prefix>\n";
    xml += "<first_name>" + addr.givenName() + "</first_name>\n";
    xml += "<middle_name>" + addr.additionalName() + "</middle_name>\n";
    xml += "<last_name>" + addr.familyName() + "</last_name>\n";
    xml += "<suffix>" + addr.suffix() + "</suffix>\n";
    xml += "<display_name>" + addr.assembledName() + "</display_name>\n";
    xml += "<file_as>" + addr.formattedName() + "</file_as>\n";
    xml += "<nickname>" + addr.nickName() + "</nickname>\n";

    xml += "<web_page_address>" + addr.url().url() + "</web_page_address>\n";
    xml += "<company_name>" + addr.organization() + "</company_name>\n";
    xml += "<job_title>" + addr.title() + "</job_title>\n";

    QStringList emails = addr.emails();
    for(uint i = 0; i < 3; ++i)
    {
        QString type, address, comment, display;

        if(i < emails.count())
        {
            type = "SMTP";
            address = emails[ i ];

            /**
             * If the contact was created by kontact use the email address as
             * display name and the formatted name as comment, otherwise we use
             * the values from the server.
             */
            if(custom("comes_from_scalix", addr) != "true")
            {
                comment = addr.formattedName();
                display = emails[ i ];
            }
            else
            {
                comment = custom(QString("email%1_address_with_comment").arg(i + 1), addr);
                display = custom(QString("email%1_display_name").arg(i + 1), addr);
            }
        }

        xml += QString("<email%1_address_type>").arg(i + 1) + type +
               QString("</email%1_address_type>").arg(i + 1) + "\n";
        xml += QString("<email%1_address>").arg(i + 1) + address +
               QString("</email%1_address>").arg(i + 1) + "\n";
        xml += QString("<email%1_address_with_comment>").arg(i + 1) + comment +
               QString("</email%1_address_with_comment>").arg(i + 1) + "\n";
        xml += QString("<email%1_display_name>").arg(i + 1) + display +
               QString("</email%1_display_name>").arg(i + 1) + "\n";
    }

    KABC::PhoneNumber phone = addr.phoneNumber(KABC::PhoneNumber::Home);
    xml += "<home_phone_number>" + phone.number() + "</home_phone_number>\n";

    phone = addr.phoneNumber(KABC::PhoneNumber::Work);
    xml += "<work_phone_number>" + phone.number() + "</work_phone_number>\n";

    phone = addr.phoneNumber(KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax);
    xml += "<work_fax_number>" + phone.number() + "</work_fax_number>\n";

    phone = addr.phoneNumber(KABC::PhoneNumber::Cell);
    xml += "<mobile_phone_number>" + phone.number() + "</mobile_phone_number>\n";

    const KABC::Address workAddress = addr.address(KABC::Address::Work);
    xml += "<work_address_street>" + workAddress.street() + "</work_address_street>\n";
    xml += "<work_address_zip>" + workAddress.postalCode() + "</work_address_zip>\n";
    xml += "<work_address_city>" + workAddress.locality() + "</work_address_city>\n";
    xml += "<work_address_state>" + workAddress.region() + "</work_address_state>\n";
    xml += "<work_address_country>" + workAddress.country() + "</work_address_country>\n";

    const KABC::Address homeAddress = addr.address(KABC::Address::Home);
    xml += "<home_address_street>" + homeAddress.street() + "</home_address_street>\n";
    xml += "<home_address_zip>" + homeAddress.postalCode() + "</home_address_zip>\n";
    xml += "<home_address_city>" + homeAddress.locality() + "</home_address_city>\n";
    xml += "<home_address_state>" + homeAddress.region() + "</home_address_state>\n";
    xml += "<home_address_country>" + homeAddress.country() + "</home_address_country>\n";

    const KABC::Address otherAddress = addr.address(KABC::Address::Dom);
    xml += "<other_address_street>" + otherAddress.street() + "</other_address_street>\n";
    xml += "<other_address_zip>" + otherAddress.postalCode() + "</other_address_zip>\n";
    xml += "<other_address_city>" + otherAddress.locality() + "</other_address_city>\n";
    xml += "<other_address_state>" + otherAddress.region() + "</other_address_state>\n";
    xml += "<other_address_country>" + otherAddress.country() + "</other_address_country>\n";

    if(homeAddress.type() & KABC::Address::Pref)
        xml += "<selected_mailing_address>1</selected_mailing_address>\n";
    else if(workAddress.type() & KABC::Address::Pref)
        xml += "<selected_mailing_address>2</selected_mailing_address>\n";
    else if(otherAddress.type() & KABC::Address::Pref)
        xml += "<selected_mailing_address>3</selected_mailing_address>\n";

    xml += "<im_address>" + addr.custom("KADDRESSBOOK", "X-IMAddress") + "</im_address>\n";
    xml += "<manager>" + addr.custom("KADDRESSBOOK", "X-ManagersName") + "</manager>\n";
    xml += "<department>" + addr.custom("KADDRESSBOOK", "X-Department") + "</department>\n";
    xml += "<assistant>" + addr.custom("KADDRESSBOOK", "X-AssistantsName") + "</assistant>\n";
    xml += "<profession>" + addr.custom("KADDRESSBOOK", "X-Profession") + "</profession>\n";
    xml += "<office_location>" + addr.custom("KADDRESSBOOK", "X-Office") + "</office_location>\n";
    xml += "<spouse>" + addr.custom("KADDRESSBOOK", "X-SpousesName") + "</spouse>\n";

    xml += "<bday>" + addr.birthday().toString(Qt::ISODate) + "</bday>\n";
    xml += "<anniversary>" + addr.custom("KADDRESSBOOK", "X-Anniversary") + "</anniversary>\n";

    xml += "<mapi_charset>" + custom("mapi_charset", addr, "UTF8") + "</mapi_charset>";

    xml += "</contact>\n";

    return xml;
}