示例#1
0
QString LocationMap::createUrl( const KABC::Address &addr )
{
    /**
      This method makes substitutions for the following place holders:
        %s street
        %r region
        %l locality
        %z zip code
        %c country (in ISO format)
     */

    QString urlTemplate = KABPrefs::instance()->locationMapURL().arg( KGlobal::locale()->country() );
    if ( urlTemplate.isEmpty() ) {
        KMessageBox::error( 0, i18n( "No service provider available for map lookup!\nPlease add one in the configuration dialog." ) );
        return QString::null;
    }

#if KDE_VERSION >= 319
    return urlTemplate.replace( "%s", addr.street() ).
           replace( "%r", addr.region() ).
           replace( "%l", addr.locality() ).
           replace( "%z", addr.postalCode() ).
           replace( "%c", addr.countryToISO( addr.country() ) );
#else
    return urlTemplate.replace( "%s", addr.street() ).
           replace( "%r", addr.region() ).
           replace( "%l", addr.locality() ).
           replace( "%z", addr.postalCode() ).
           replace( "%c", "" );
#endif
}
示例#2
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;
}
示例#3
0
void KABC::ResourceSlox::createAddressFields( QDomDocument &doc, QDomElement &parent,
                                               const QString &prefix, const KABC::Address &addr )
{
  WebdavHandler::addSloxElement( this, doc, parent, prefix + fieldName( Street ), addr.street() );
  WebdavHandler::addSloxElement( this, doc, parent, prefix + fieldName( PostalCode ), addr.postalCode() );
  WebdavHandler::addSloxElement( this, doc, parent, prefix + fieldName( City ), addr.locality() );
  WebdavHandler::addSloxElement( this, doc, parent, prefix + fieldName( State ), addr.region() );
  WebdavHandler::addSloxElement( this, doc, parent, prefix + fieldName( Country ), addr.country() );
}
示例#4
0
void AddressEditWidget::updateAddressView()
{
  const KABC::Address address = mAddressSelectionWidget->currentAddress();

  if ( address.isEmpty() ) {
    mAddressView->setText( QString() );
  } else {
    mAddressView->setText( address.formattedAddress( mName ) );
  }
}
示例#5
0
void AddressEditWidget::storeContact( KABC::Addressee &contact ) const
{
  // delete all previous addresses
  const KABC::Address::List oldAddresses = contact.addresses();
  for ( int i = 0; i < oldAddresses.count(); ++i ) {
    contact.removeAddress( oldAddresses.at( i ) );
  }

  // insert the new ones
  for ( int i = 0; i < mAddressList.count(); ++i ) {
    const KABC::Address address( mAddressList.at( i ) );
    if ( !address.isEmpty() ) {
      contact.insertAddress( address );
    }
  }
}
示例#6
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 );
    }
  }
}
示例#7
0
KABC::Address VCard21Parser::readAddressFromQStringList(const QStringList &data, const int type)
{
    KABC::Address mAddress;
    mAddress.setType(type);

    if(data.count() > 0)
        mAddress.setPostOfficeBox(data[0]);
    if(data.count() > 1)
        mAddress.setExtended(data[1]);
    if(data.count() > 2)
        mAddress.setStreet(data[2]);
    if(data.count() > 3)
        mAddress.setLocality(data[3]);
    if(data.count() > 4)
        mAddress.setRegion(data[4]);
    if(data.count() > 5)
        mAddress.setPostalCode(data[5]);
    if(data.count() > 6)
        mAddress.setCountry(data[6]);

    return mAddress;
}
示例#8
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 );
}
示例#9
0
static void setOtherStreet(const QString &value, KABC::Address &address)
{
    address.setStreet(value);
}
示例#10
0
KABC::AddresseeList GMXXXPort::importContacts( const QString& ) const
{
  KABC::AddresseeList addrList;

  QString fileName = KFileDialog::getOpenFileName( ":xxport_gmx", 
                      GMX_FILESELECTION_STRING, 0 );
  if ( fileName.isEmpty() )
    return addrList;

  QFile file( fileName );
  if ( !file.open( IO_ReadOnly ) ) {
    QString msg = i18n( "<qt>Unable to open <b>%1</b> for reading.</qt>" );
    KMessageBox::error( parentWidget(), msg.arg( fileName ) );
    return addrList;
  }

  QDateTime dt;
  QTextStream gmxStream( &file );
  gmxStream.setEncoding( QTextStream::Latin1 );
  QString line, line2;
  line  = gmxStream.readLine();
  line2 = gmxStream.readLine();
  if (!line.startsWith("AB_ADDRESSES:") || !line2.startsWith("Address_id")) {
	KMessageBox::error( parentWidget(), i18n("%1 is not a GMX address book file.").arg(fileName) );
	return addrList;
  }

  QStringList strList;
  typedef QMap<QString, KABC::Addressee *> AddressMap;
  AddressMap addrMap;

  // "Address_id,Nickname,Firstname,Lastname,Title,Birthday,Comments,Change_date,Status,Address_link_id,Categories"
  line = gmxStream.readLine();
  while (!line.startsWith("####") && !gmxStream.atEnd()) {
    while (1) {
       strList = QStringList::split('#', line, true);
       if (strList.count() >= 11) 
           break;
       line.append('\n');
       line.append(gmxStream.readLine());
    };

    KABC::Addressee *addr = new KABC::Addressee;
    addr->setNickName(strList[1]);
    addr->setGivenName(strList[2]);
    addr->setFamilyName(strList[3]);
    addr->setTitle(strList[4]);

    if (addr->formattedName().isEmpty())
	addr->setFormattedName(addr->realName());

    if (checkDateTime(strList[5],dt)) addr->setBirthday(dt);
    addr->setNote(strList[6]);
    if (checkDateTime(strList[7],dt)) addr->setRevision(dt);
    // addr->setStatus(strList[8]); Status
    // addr->xxx(strList[9]); Address_link_id 
    // addr->setCategory(strList[10]); Categories
    addrMap[strList[0]] = addr;

    line = gmxStream.readLine();
  }

  // now read the address records
  line  = gmxStream.readLine();
  if (!line.startsWith("AB_ADDRESS_RECORDS:")) {
	kdWarning() << "Could not find address records!\n";
	return addrList;
  }
  // Address_id,Record_id,Street,Country,Zipcode,City,Phone,Fax,Mobile,Mobile_type,Email,
  // Homepage,Position,Comments,Record_type_id,Record_type,Company,Department,Change_date,Preferred,Status
  line = gmxStream.readLine();
  line = gmxStream.readLine();

  while (!line.startsWith("####") && !gmxStream.atEnd()) {
    while (1) {
       strList = QStringList::split('#', line, true);
       if (strList.count() >= 21) 
           break;
       line.append('\n');
       line.append(gmxStream.readLine());
    };

    KABC::Addressee *addr = addrMap[strList[0]];
    if (addr) {
	for ( QStringList::Iterator it = strList.begin(); it != strList.end(); ++it )
		*it = (*it).simplifyWhiteSpace();
	// strList[1] = Record_id (numbered item, ignore here)
	int id = strList[14].toInt(); // Record_type_id (0=work,1=home,2=other)
	int type = (id==0) ? KABC::Address::Work : KABC::Address::Home;
	if (!strList[19].isEmpty() && strList[19].toInt()!=0)
		type |= KABC::Address::Pref; // Preferred address (seems to be bitfield for telephone Prefs)
        KABC::Address adr = addr->address(type);
	adr.setStreet(strList[2]);
	adr.setCountry(strList[3]);
	adr.setPostalCode(strList[4]);
	adr.setLocality(strList[5]);
	addr->insertPhoneNumber( KABC::PhoneNumber(strList[6], KABC::PhoneNumber::Home) );
	addr->insertPhoneNumber( KABC::PhoneNumber(strList[7], KABC::PhoneNumber::Fax) );
	int celltype = KABC::PhoneNumber::Cell;
	// strList[9]=Mobile_type // always 0 or -1(default phone).
	if (strList[9].toInt()) celltype |= KABC::PhoneNumber::Pref;
	addr->insertPhoneNumber( KABC::PhoneNumber(strList[8], celltype) );
	addr->insertEmail(strList[10]);
	if (!strList[11].isEmpty()) addr->setUrl(strList[11]);
	if (!strList[12].isEmpty()) addr->setRole(strList[12]);
	// strList[13]=Comments
	// strList[14]=Record_type_id (0,1,2) - see above
	// strList[15]=Record_type (name of this additional record entry)
	if (!strList[16].isEmpty()) addr->setOrganization(strList[16]); // Company
	if (!strList[17].isEmpty()) addr->insertCustom( 
			"KADDRESSBOOK", "X-Department", strList[17]); // Department
        if (checkDateTime(strList[18],dt)) addr->setRevision(dt); // Change_date
	// strList[19]=Preferred (see above)
	// strList[20]=Status (should always be "1")
	addr->insertAddress(adr);
    } else {
	kdWarning() << "unresolved line: " << line << endl;
    }

    line = gmxStream.readLine();
  }

  // now add the addresses to to addrList
  for ( AddressMap::Iterator it = addrMap.begin(); it != addrMap.end(); ++it ) {
     KABC::Addressee *addr = it.data();
     addrList.append(*addr);
     delete addr;
  }

  file.close();
  return addrList;
}
示例#11
0
void GMXXXPort::doExport( QFile *fp, const KABC::AddresseeList &list )
{
  if (!fp || !list.count())
    return;

  QTextStream t( fp );
  t.setEncoding( QTextStream::Latin1 );

  KABC::AddresseeList::ConstIterator it;
  typedef QMap<int, const KABC::Addressee *> AddressMap;
  AddressMap addrMap;
  const KABC::Addressee *addr;

  t << "AB_ADDRESSES:\n";
  t << "Address_id,Nickname,Firstname,Lastname,Title,Birthday,Comments,"
       "Change_date,Status,Address_link_id,Categories\n";

  int no = 0;
  const QChar DELIM('#');
  for ( it = list.begin(); it != list.end(); ++it ) {
     addr = &(*it);
     if (addr->isEmpty())
        continue;
     addrMap[++no] = addr;
     t << no << DELIM			// Address_id
	<< addr->nickName() << DELIM	// Nickname
	<< addr->givenName() << DELIM	// Firstname
	<< addr->familyName() << DELIM	// Lastname
	<< addr->title() << DELIM	// Title
	<< dateString(addr->birthday()) << DELIM   // Birthday
	<< addr->note() /*.replace('\n',"\r\n")*/ << DELIM // Comments
	<< dateString(addr->revision()) << DELIM   // Change_date
	<< "1##0\n";			// Status, Address_link_id, Categories
  }

  t << "####\n";
  t << "AB_ADDRESS_RECORDS:\n";
  t << "Address_id,Record_id,Street,Country,Zipcode,City,Phone,Fax,Mobile,"
       "Mobile_type,Email,Homepage,Position,Comments,Record_type_id,Record_type,"
       "Company,Department,Change_date,Preferred,Status\n";

  no = 1;
  while ( (addr = addrMap[no]) != NULL ) {
    for (unsigned int record_id=0; record_id<3; record_id++) {

	KABC::Address address;
  	KABC::PhoneNumber phone, fax, cell;


        if (record_id == 0) {
		address = addr->address(KABC::Address::Work);
		phone = addr->phoneNumber(KABC::PhoneNumber::Work);
		fax   = addr->phoneNumber(KABC::PhoneNumber::Fax);
		cell  = addr->phoneNumber(KABC::PhoneNumber::Work | KABC::PhoneNumber::Cell);
	} else {
		address = addr->address(KABC::Address::Home);
		phone = addr->phoneNumber(KABC::PhoneNumber::Home);
		cell  = addr->phoneNumber(KABC::PhoneNumber::Cell);
	}

	const QStringList emails = addr->emails();
	QString email;
	if (emails.count()>record_id) email = emails[record_id];

	t << no << DELIM			// Address_id
	  << record_id << DELIM			// Record_id
	  << address.street() << DELIM		// Street
	  << address.country() << DELIM 	// Country
	  << address.postalCode() << DELIM	// Zipcode
	  << address.locality() << DELIM	// City
	  << phone.number() << DELIM		// Phone
	  << fax.number() << DELIM		// Fax
	  << cell.number() << DELIM		// Mobile
	  << ((cell.type()&KABC::PhoneNumber::Pref)?-1:0) << DELIM // Mobile_type
	  << email << DELIM			// Email
	  << ((record_id==0)?addr->url().url():QString::null) << DELIM // Homepage
	  << ((record_id==0)?addr->role():QString::null) << DELIM	// Position
	  << DELIM				// Comments
	  << record_id << DELIM			// Record_type_id (0,1,2) - see above
	  << DELIM				// Record_type (name of this additional record entry)
	  << ((record_id==0)?addr->organization():QString::null) << DELIM // Company
	  << ((record_id==0)?addr->custom("KADDRESSBOOK", "X-Department"):QString::null) << DELIM // Department
	  << dateString(addr->revision()) << DELIM	// Change_date
	  << 5 << DELIM				// Preferred
	  << 1 << endl;				// Status (should always be "1")
    }

    ++no;
  };

  t << "####";
}
示例#12
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;
}
示例#13
0
static void setOtherCity(const QString &value, KABC::Address &address)
{
    address.setLocality(value);
}
示例#14
0
QString KTnef::msTNEFToVPart( const QByteArray &tnef )
{
  bool bOk = false;

  KTNEFParser parser;
  QByteArray b( tnef );
  QBuffer buf( &b );
  MemoryCalendar::Ptr cal( new MemoryCalendar( KDateTime::UTC ) );
  KABC::Addressee addressee;
  ICalFormat calFormat;
  Event::Ptr event( new Event() );

  if ( parser.openDevice( &buf ) ) {
    KTNEFMessage *tnefMsg = parser.message();
    //QMap<int,KTNEFProperty*> props = parser.message()->properties();

    // Everything depends from property PR_MESSAGE_CLASS
    // (this is added by KTNEFParser):
    QString msgClass = tnefMsg->findProp( 0x001A, QString(), true ).toUpper();
    if ( !msgClass.isEmpty() ) {
      // Match the old class names that might be used by Outlook for
      // compatibility with Microsoft Mail for Windows for Workgroups 3.1.
      bool bCompatClassAppointment = false;
      bool bCompatMethodRequest = false;
      bool bCompatMethodCancled = false;
      bool bCompatMethodAccepted = false;
      bool bCompatMethodAcceptedCond = false;
      bool bCompatMethodDeclined = false;
      if ( msgClass.startsWith( QLatin1String( "IPM.MICROSOFT SCHEDULE." ) ) ) {
        bCompatClassAppointment = true;
        if ( msgClass.endsWith( QLatin1String( ".MTGREQ" ) ) ) {
          bCompatMethodRequest = true;
        }
        if ( msgClass.endsWith( QLatin1String( ".MTGCNCL" ) ) ) {
          bCompatMethodCancled = true;
        }
        if ( msgClass.endsWith( QLatin1String( ".MTGRESPP" ) ) ) {
          bCompatMethodAccepted = true;
        }
        if ( msgClass.endsWith( QLatin1String( ".MTGRESPA" ) ) ) {
          bCompatMethodAcceptedCond = true;
        }
        if ( msgClass.endsWith( QLatin1String( ".MTGRESPN" ) ) ) {
          bCompatMethodDeclined = true;
        }
      }
      bool bCompatClassNote = ( msgClass == "IPM.MICROSOFT MAIL.NOTE" );

      if ( bCompatClassAppointment || "IPM.APPOINTMENT" == msgClass ) {
        // Compose a vCal
        bool bIsReply = false;
        QString prodID = "-//Microsoft Corporation//Outlook ";
        prodID += tnefMsg->findNamedProp( "0x8554", "9.0" );
        prodID += "MIMEDIR/EN\n";
        prodID += "VERSION:2.0\n";
        calFormat.setApplication( "Outlook", prodID );

        iTIPMethod method;
        if ( bCompatMethodRequest ) {
          method = iTIPRequest;
        } else if ( bCompatMethodCancled ) {
          method = iTIPCancel;
        } else if ( bCompatMethodAccepted || bCompatMethodAcceptedCond ||
                 bCompatMethodDeclined ) {
          method = iTIPReply;
          bIsReply = true;
        } else {
          // pending(khz): verify whether "0x0c17" is the right tag ???
          //
          // at the moment we think there are REQUESTS and UPDATES
          //
          // but WHAT ABOUT REPLIES ???
          //
          //

          if ( tnefMsg->findProp(0x0c17) == "1" ) {
            bIsReply = true;
          }
          method = iTIPRequest;
        }

        /// ###  FIXME Need to get this attribute written
        ScheduleMessage schedMsg( event, method, ScheduleMessage::Unknown );

        QString sSenderSearchKeyEmail( tnefMsg->findProp( 0x0C1D ) );

        if ( !sSenderSearchKeyEmail.isEmpty() ) {
          int colon = sSenderSearchKeyEmail.indexOf( ':' );
          // May be e.g. "SMTP:[email protected]"
          if ( sSenderSearchKeyEmail.indexOf( ':' ) == -1 ) {
            sSenderSearchKeyEmail.remove( 0, colon+1 );
          }
        }

        QString s( tnefMsg->findProp( 0x8189 ) );
        const QStringList attendees = s.split( ';' );
        if ( attendees.count() ) {
          for ( QStringList::const_iterator it = attendees.begin();
               it != attendees.end(); ++it ) {
            // Skip all entries that have no '@' since these are
            // no mail addresses
            if ( (*it).indexOf( '@' ) == -1 ) {
              s = (*it).trimmed();

              Attendee::Ptr attendee( new Attendee( s, s, true ) );
              if ( bIsReply ) {
                if ( bCompatMethodAccepted ) {
                  attendee->setStatus( Attendee::Accepted );
                }
                if ( bCompatMethodDeclined ) {
                  attendee->setStatus( Attendee::Declined );
                }
                if ( bCompatMethodAcceptedCond ) {
                  attendee->setStatus( Attendee::Tentative );
                }
              } else {
                attendee->setStatus( Attendee::NeedsAction );
                attendee->setRole( Attendee::ReqParticipant );
              }
              event->addAttendee( attendee );
            }
          }
        } else {
          // Oops, no attendees?
          // This must be old style, let us use the PR_SENDER_SEARCH_KEY.
          s = sSenderSearchKeyEmail;
          if ( !s.isEmpty() ) {
            Attendee::Ptr attendee( new Attendee( QString(), QString(), true ) );
            if ( bIsReply ) {
              if ( bCompatMethodAccepted ) {
                attendee->setStatus( Attendee::Accepted );
              }
              if ( bCompatMethodAcceptedCond ) {
                attendee->setStatus( Attendee::Declined );
              }
              if ( bCompatMethodDeclined ) {
                attendee->setStatus( Attendee::Tentative );
              }
            } else {
              attendee->setStatus( Attendee::NeedsAction );
              attendee->setRole( Attendee::ReqParticipant );
            }
            event->addAttendee( attendee );
          }
        }
        s = tnefMsg->findProp( 0x3ff8 ); // look for organizer property
        if ( s.isEmpty() && !bIsReply ) {
          s = sSenderSearchKeyEmail;
        }
        // TODO: Use the common name?
        if ( !s.isEmpty() ) {
          event->setOrganizer( s );
        }

        s = tnefMsg->findProp( 0x819b ).remove( QChar( '-' ) ).remove( QChar( ':' ) );
        event->setDtStart( KDateTime::fromString( s ) ); // ## Format??

        s = tnefMsg->findProp( 0x819c ).remove( QChar( '-' ) ).remove( QChar( ':' ) );
        event->setDtEnd( KDateTime::fromString( s ) );

        s = tnefMsg->findProp( 0x810d );
        event->setLocation( s );
        // is it OK to set this to OPAQUE always ??
        //vPart += "TRANSP:OPAQUE\n"; ###FIXME, portme!
        //vPart += "SEQUENCE:0\n";

        // is "0x0023" OK  -  or should we look for "0x0003" ??
        s = tnefMsg->findProp( 0x0023 );
        event->setUid( s );

        // PENDING(khz): is this value in local timezone? Must it be
        // adjusted? Most likely this is a bug in the server or in
        // Outlook - we ignore it for now.
        s = tnefMsg->findProp( 0x8202 ).remove( QChar( '-' ) ).remove( QChar( ':' ) );
        // ### kcal always uses currentDateTime()
        // event->setDtStamp( QDateTime::fromString( s ) );

        s = tnefMsg->findNamedProp( "Keywords" );
        event->setCategories( s );

        s = tnefMsg->findProp( 0x1000 );
        event->setDescription( s );

        s = tnefMsg->findProp( 0x0070 );
        event->setSummary( s );

        s = tnefMsg->findProp( 0x0026 );
        event->setPriority( s.toInt() );
        // is reminder flag set ?
        if ( !tnefMsg->findProp( 0x8503 ).isEmpty() ) {
          Alarm::Ptr alarm( new Alarm( event.data() ) ); // TODO: fix when KCalCore::Alarm is fixed
          KDateTime highNoonTime =
            pureISOToLocalQDateTime( tnefMsg->findProp( 0x8502 ).
                                     remove( QChar( '-' ) ).remove( QChar( ':' ) ) );
          KDateTime wakeMeUpTime =
            pureISOToLocalQDateTime( tnefMsg->findProp( 0x8560, "" ).
                                     remove( QChar( '-' ) ).remove( QChar( ':' ) ) );
          alarm->setTime( wakeMeUpTime );

          if ( highNoonTime.isValid() && wakeMeUpTime.isValid() ) {
            alarm->setStartOffset( Duration( highNoonTime, wakeMeUpTime ) );
          } else {
            // default: wake them up 15 minutes before the appointment
            alarm->setStartOffset( Duration( 15 * 60 ) );
          }
          alarm->setDisplayAlarm( i18n( "Reminder" ) );

          // Sorry: the different action types are not known (yet)
          //        so we always set 'DISPLAY' (no sounds, no images...)
          event->addAlarm( alarm );
        }
        //ensure we have a uid for this event
        if ( event->uid().isEmpty() ) {
          event->setUid( CalFormat::createUniqueId() );
        }
        cal->addEvent( event );
        bOk = true;
        // we finished composing a vCal
      } else if ( bCompatClassNote || "IPM.CONTACT" == msgClass ) {
        addressee.setUid( stringProp( tnefMsg, attMSGID ) );
        addressee.setFormattedName( stringProp( tnefMsg, MAPI_TAG_PR_DISPLAY_NAME ) );
        addressee.insertEmail( sNamedProp( tnefMsg, MAPI_TAG_CONTACT_EMAIL1EMAILADDRESS ), true );
        addressee.insertEmail( sNamedProp( tnefMsg, MAPI_TAG_CONTACT_EMAIL2EMAILADDRESS ), false );
        addressee.insertEmail( sNamedProp( tnefMsg, MAPI_TAG_CONTACT_EMAIL3EMAILADDRESS ), false );
        addressee.insertCustom( "KADDRESSBOOK", "X-IMAddress",
                                sNamedProp( tnefMsg, MAPI_TAG_CONTACT_IMADDRESS ) );
        addressee.insertCustom( "KADDRESSBOOK", "X-SpousesName",
                                stringProp( tnefMsg, MAPI_TAG_PR_SPOUSE_NAME ) );
        addressee.insertCustom( "KADDRESSBOOK", "X-ManagersName",
                                stringProp( tnefMsg, MAPI_TAG_PR_MANAGER_NAME ) );
        addressee.insertCustom( "KADDRESSBOOK", "X-AssistantsName",
                                stringProp( tnefMsg, MAPI_TAG_PR_ASSISTANT ) );
        addressee.insertCustom( "KADDRESSBOOK", "X-Department",
                                stringProp( tnefMsg, MAPI_TAG_PR_DEPARTMENT_NAME ) );
        addressee.insertCustom( "KADDRESSBOOK", "X-Office",
                                stringProp( tnefMsg, MAPI_TAG_PR_OFFICE_LOCATION ) );
        addressee.insertCustom( "KADDRESSBOOK", "X-Profession",
                                stringProp( tnefMsg, MAPI_TAG_PR_PROFESSION ) );

        QString s = tnefMsg->findProp( MAPI_TAG_PR_WEDDING_ANNIVERSARY ).
                    remove( QChar( '-' ) ).remove( QChar( ':' ) );
        if ( !s.isEmpty() ) {
          addressee.insertCustom( "KADDRESSBOOK", "X-Anniversary", s );
        }

        addressee.setUrl( KUrl( sNamedProp( tnefMsg, MAPI_TAG_CONTACT_WEBPAGE ) ) );

        // collect parts of Name entry
        addressee.setFamilyName( stringProp( tnefMsg, MAPI_TAG_PR_SURNAME ) );
        addressee.setGivenName( stringProp( tnefMsg, MAPI_TAG_PR_GIVEN_NAME ) );
        addressee.setAdditionalName( stringProp( tnefMsg, MAPI_TAG_PR_MIDDLE_NAME ) );
        addressee.setPrefix( stringProp( tnefMsg, MAPI_TAG_PR_DISPLAY_NAME_PREFIX ) );
        addressee.setSuffix( stringProp( tnefMsg, MAPI_TAG_PR_GENERATION ) );

        addressee.setNickName( stringProp( tnefMsg, MAPI_TAG_PR_NICKNAME ) );
        addressee.setRole( stringProp( tnefMsg, MAPI_TAG_PR_TITLE ) );
        addressee.setOrganization( stringProp( tnefMsg, MAPI_TAG_PR_COMPANY_NAME ) );
        /*
        the MAPI property ID of this (multiline) )field is unknown:
        vPart += stringProp(tnefMsg, "\n","NOTE", ... , "" );
        */

        KABC::Address adr;
        adr.setPostOfficeBox( stringProp( tnefMsg, MAPI_TAG_PR_HOME_ADDRESS_PO_BOX ) );
        adr.setStreet( stringProp( tnefMsg, MAPI_TAG_PR_HOME_ADDRESS_STREET ) );
        adr.setLocality( stringProp( tnefMsg, MAPI_TAG_PR_HOME_ADDRESS_CITY ) );
        adr.setRegion( stringProp( tnefMsg, MAPI_TAG_PR_HOME_ADDRESS_STATE_OR_PROVINCE ) );
        adr.setPostalCode( stringProp( tnefMsg, MAPI_TAG_PR_HOME_ADDRESS_POSTAL_CODE ) );
        adr.setCountry( stringProp( tnefMsg, MAPI_TAG_PR_HOME_ADDRESS_COUNTRY ) );
        adr.setType( KABC::Address::Home );
        addressee.insertAddress( adr );

        adr.setPostOfficeBox( sNamedProp( tnefMsg, MAPI_TAG_CONTACT_BUSINESSADDRESSPOBOX ) );
        adr.setStreet( sNamedProp( tnefMsg, MAPI_TAG_CONTACT_BUSINESSADDRESSSTREET ) );
        adr.setLocality( sNamedProp( tnefMsg, MAPI_TAG_CONTACT_BUSINESSADDRESSCITY ) );
        adr.setRegion( sNamedProp( tnefMsg, MAPI_TAG_CONTACT_BUSINESSADDRESSSTATE ) );
        adr.setPostalCode( sNamedProp( tnefMsg, MAPI_TAG_CONTACT_BUSINESSADDRESSPOSTALCODE ) );
        adr.setCountry( sNamedProp( tnefMsg, MAPI_TAG_CONTACT_BUSINESSADDRESSCOUNTRY ) );
        adr.setType( KABC::Address::Work );
        addressee.insertAddress( adr );

        adr.setPostOfficeBox( stringProp( tnefMsg, MAPI_TAG_PR_OTHER_ADDRESS_PO_BOX ) );
        adr.setStreet( stringProp( tnefMsg, MAPI_TAG_PR_OTHER_ADDRESS_STREET ) );
        adr.setLocality( stringProp( tnefMsg, MAPI_TAG_PR_OTHER_ADDRESS_CITY ) );
        adr.setRegion( stringProp( tnefMsg, MAPI_TAG_PR_OTHER_ADDRESS_STATE_OR_PROVINCE ) );
        adr.setPostalCode( stringProp( tnefMsg, MAPI_TAG_PR_OTHER_ADDRESS_POSTAL_CODE ) );
        adr.setCountry( stringProp( tnefMsg, MAPI_TAG_PR_OTHER_ADDRESS_COUNTRY ) );
        adr.setType( KABC::Address::Dom );
        addressee.insertAddress( adr );

        // problem: the 'other' address was stored by KOrganizer in
        //          a line looking like the following one:
        // vPart += "\nADR;TYPE=dom;TYPE=intl;TYPE=parcel;TYPE=postal;TYPE=work;"
        //          "TYPE=home:other_pobox;;other_str1\nother_str2;other_loc;other_region;"
        //          "other_pocode;other_country"

        QString nr;
        nr = stringProp( tnefMsg, MAPI_TAG_PR_HOME_TELEPHONE_NUMBER );
        addressee.insertPhoneNumber(
          KABC::PhoneNumber( nr, KABC::PhoneNumber::Home ) );
        nr = stringProp( tnefMsg, MAPI_TAG_PR_BUSINESS_TELEPHONE_NUMBER );
        addressee.insertPhoneNumber(
          KABC::PhoneNumber( nr, KABC::PhoneNumber::Work ) );
        nr = stringProp( tnefMsg, MAPI_TAG_PR_MOBILE_TELEPHONE_NUMBER );
        addressee.insertPhoneNumber(
          KABC::PhoneNumber( nr, KABC::PhoneNumber::Cell ) );
        nr = stringProp( tnefMsg, MAPI_TAG_PR_HOME_FAX_NUMBER );
        addressee.insertPhoneNumber(
          KABC::PhoneNumber( nr, KABC::PhoneNumber::Fax | KABC::PhoneNumber::Home ) );
        nr = stringProp( tnefMsg, MAPI_TAG_PR_BUSINESS_FAX_NUMBER );
        addressee.insertPhoneNumber(
          KABC::PhoneNumber( nr, KABC::PhoneNumber::Fax | KABC::PhoneNumber::Work ) );

        s = tnefMsg->findProp( MAPI_TAG_PR_BIRTHDAY ).
            remove( QChar( '-' ) ).remove( QChar( ':' ) );
        if ( !s.isEmpty() ) {
          addressee.setBirthday( QDateTime::fromString( s ) );
        }

        bOk = ( !addressee.isEmpty() );
      } else if ( "IPM.NOTE" == msgClass ) {

      } // else if ... and so on ...
    }
  }

  // Compose return string
  // KDAB_TODO: Interesting, without the explicit QString the toString call is
  //            reported to be ambigious with toString( const Incidence::Ptr & ).
  const QString iCal = calFormat.toString( cal, QString() );
  if ( !iCal.isEmpty() ) {
    // This was an iCal
    return iCal;
  }

  // Not an iCal - try a vCard
  KABC::VCardConverter converter;
  return QString::fromUtf8( converter.createVCard( addressee ) );
}
示例#15
0
static void setOtherState(const QString &value, KABC::Address &address)
{
    address.setRegion(value);
}
示例#16
0
QString KWMailMergeKABC::getValue( const QString &name, int record ) const
{
    kdDebug() << "KWMailMergeKABC::getValue(" << name << ", " << record << ")" << endl;
    if ( record < 0 )
        return name;

    // This doesn't ever happen, right? So why is it there? Dirk Schmidt
    if ( record == -1 && _iterator == _addressBook->end() )
        return "";

    //
    // Set the iterator to the asked Addressee.
    //
    bool uidAvailable = false;
    if ( record != -1 )
    {
        int counter = 0;

        for ( _UIDIterator = _exclusiveUIDs.begin(); _UIDIterator != _exclusiveUIDs.end()
                && counter < record; _UIDIterator++ )
        {
            counter++;
        }

        for ( _iterator = _addressBook->begin(); _iterator != _addressBook->end(); ++_iterator )
        {

            if( _iterator->uid() == *_UIDIterator )
            {
                uidAvailable = true;
                break;
            }
        }
    }

    if( !uidAvailable )
    {
        return ( i18n ( "KAddressbook entry '%1' not available." ).arg( *_UIDIterator ) );
    }


    KABC::Addressee addr = *_iterator;
    _iterator++; // Don't know why. Could be removed? Dirk Schmidt


    //
    // Return the asked variable.
    //
    if ( name == "KAddressbook identifier" )
        return addr.uid();
    if ( name == "Name" )
        return addr.name();
    if ( name == "Formatted name" )
        return addr.formattedName();
    if ( name == "Family names" )
        return addr.familyName();
    if ( name == "Given name" )
        return addr.givenName();
    if ( name == "Additional names" )
        return addr.additionalName();
    if ( name == "Honorific prefixes" )
        return addr.prefix();
    if ( name == "Honorific suffixes" )
        return addr.suffix();
    if ( name == "Nick name" )
        return addr.nickName();
    if ( name == "Birthday" )
        return KGlobal::locale()->formatDate( addr.birthday().date() );

    if ( name == "Home address: Street" )
    {
        KABC::Address a = addr.address( KABC::Address::Home );
        return a.street();
    }
    if ( name == "Home address: Locality" )
    {
        KABC::Address a = addr.address( KABC::Address::Home );
        return a.locality();
    }
    if ( name == "Home address: Region" )
    {
        KABC::Address a = addr.address( KABC::Address::Home );
        return a.region();
    }
    if ( name == "Home address: Postal code" )
    {
        KABC::Address a = addr.address( KABC::Address::Home );
        return a.postalCode();
    }
    if ( name == "Home address: Country" )
    {
        KABC::Address a = addr.address( KABC::Address::Home );
        return a.country();
    }
    if ( name == "Home address: Label" )
    {
        KABC::Address a = addr.address( KABC::Address::Home );
        return a.label();
    }

    if ( name == "Business address: Street" )
    {
        KABC::Address a = addr.address( KABC::Address::Work );
        return a.street();
    }
    if ( name == "Business address: Locality" )
    {
        KABC::Address a = addr.address( KABC::Address::Work );
        return a.locality();
    }
    if ( name == "Business address: Region" )
    {
        KABC::Address a = addr.address( KABC::Address::Work );
        return a.region();
    }
    if ( name == "Business address: Postal code" )
    {
        KABC::Address a = addr.address( KABC::Address::Work );
        return a.postalCode();
    }
    if ( name == "Business address: Country" )
    {
        KABC::Address a = addr.address( KABC::Address::Work );
        return a.country();
    }
    if ( name == "Business address: Label" )
    {
        KABC::Address a = addr.address( KABC::Address::Work );
        return a.label();
    }

    if ( name == "Prefered address: Street" )
    {
        KABC::Address a = addr.address( KABC::Address::Pref );
        return a.street();
    }

    if ( name == "Prefered address: Locality" )
    {
        KABC::Address a = addr.address( KABC::Address::Pref );
        return a.locality();
    }
    if ( name == "Prefered address: Region" )
    {
        KABC::Address a = addr.address( KABC::Address::Pref );
        return a.region();
    }
    if ( name == "Prefered address: Postal code" )
    {
        KABC::Address a = addr.address( KABC::Address::Pref );
        return a.postalCode();
    }
    if ( name == "Prefered address: Country" )
    {
        KABC::Address a = addr.address( KABC::Address::Pref );
        return a.country();
    }
    if ( name == "Prefered address: Label" )
    {
        KABC::Address a = addr.address( KABC::Address::Pref );
        return a.label();
    }

    if ( name == "Home phone" )
    {
        KABC::PhoneNumber phone = addr.phoneNumber( KABC::PhoneNumber::Home );
        return phone.number();
    }
    if ( name == "Business phone" )
    {
        KABC::PhoneNumber phone = addr.phoneNumber( KABC::PhoneNumber::Work );
        return phone.number();
    }
    if ( name == "Mobile phone" )
    {
        KABC::PhoneNumber phone = addr.phoneNumber( KABC::PhoneNumber::Cell );
        return phone.number();
    }
    if ( name == "Home fax" )
    {
        KABC::PhoneNumber phone = addr.phoneNumber( KABC::PhoneNumber::Home | KABC::PhoneNumber::Fax );
        return phone.number();
    }
    if ( name == "Business fax" )
    {
        KABC::PhoneNumber phone = addr.phoneNumber( KABC::PhoneNumber::Work | KABC::PhoneNumber::Fax );
        return phone.number();
    }
    if ( name == "Car phone" )
    {
        KABC::PhoneNumber phone = addr.phoneNumber( KABC::PhoneNumber::Car );
        return phone.number();
    }
    if ( name == "ISDN" )
    {
        KABC::PhoneNumber phone = addr.phoneNumber( KABC::PhoneNumber::Isdn );
        return phone.number();
    }
    if ( name == "Pager" )
    {
        KABC::PhoneNumber phone = addr.phoneNumber( KABC::PhoneNumber::Pager );
        return phone.number();
    }

    if ( name == "Email" )
        return addr.preferredEmail();
    if ( name == "Mailer" )
        return addr.mailer();
    if ( name == "Time zone" )
    {
        KABC::TimeZone zone = addr.timeZone();
        return QString::number( zone.offset() );
    }
    if ( name == "Geographic position" )
    {
        KABC::Geo geo = addr.geo();
        QString lat;
        QString longi;
        if(  geo.latitude()<0 )
            lat = QString( i18n("%1 South") ).arg( -geo.latitude() );
        else
            lat = QString( i18n("%1 North") ).arg( geo.latitude() );

        if(  geo.longitude()<0 )
            // There is something going wrong, because "W" is replaced by "q ".
            // Needs fix.
            longi = QString( i18n("%1 West") ).arg( -geo.longitude() );
        else
            longi = QString( i18n("%1 East") ).arg( geo.longitude() );

        return i18n( "Geographic coordinates", "%1, %2" ).arg ( lat, longi );
    }

    if ( name == "Title" )
        return addr.title();
    if ( name == "Role" )
        return addr.role();
    if ( name == "Organization" )
        return addr.organization();
    if ( name == "Note" )
        return addr.note();
    if ( name == "productId" )
        return addr.productId();
    if ( name == "Revision" )
        return KGlobal::locale()->formatDate( addr.revision().date() );
    if ( name == "sortString" )
        return addr.sortString();
    if ( name == "URL" )
        return addr.url().url();
    if ( name == "Secrecy" )
    {
        KABC::Secrecy secrecy = addr.secrecy();
        return KABC::Secrecy::typeLabel( secrecy.type() );
    }

    return ( i18n("Unkown mail merge variable: %1").arg ( name ) ) ;
}
示例#17
0
void ReportGenerator::contactToTemplate( TextTemplate *tmpl, const QString& prefix, const KABC::Addressee& contact )
{
  if( contact.isEmpty() ) return;

  tmpl->setValue( ADDRESS_TAG( prefix, "NAME" ),  escapeTrml2pdfXML( contact.realName() ) );
  QString co = contact.organization();
  if( co.isEmpty() ) {
    co = contact.realName();
  }
  tmpl->setValue( ADDRESS_TAG( prefix, "ORGANISATION" ), escapeTrml2pdfXML( co ) );
  tmpl->setValue( ADDRESS_TAG( prefix, "URL" ),   escapeTrml2pdfXML( contact.url().prettyUrl() ) );
  tmpl->setValue( ADDRESS_TAG( prefix, "EMAIL" ), escapeTrml2pdfXML( contact.preferredEmail() ) );
  tmpl->setValue( ADDRESS_TAG( prefix, "PHONE" ), escapeTrml2pdfXML( contact.phoneNumber( KABC::PhoneNumber::Work ).number() ) );
  tmpl->setValue( ADDRESS_TAG( prefix, "FAX" ),   escapeTrml2pdfXML( contact.phoneNumber( KABC::PhoneNumber::Fax ).number() ) );
  tmpl->setValue( ADDRESS_TAG( prefix, "CELL" ),  escapeTrml2pdfXML( contact.phoneNumber( KABC::PhoneNumber::Cell ).number() ) );

  KABC::Address address;
  address = contact.address( KABC::Address::Pref );
  if( address.isEmpty() )
    address = contact.address(KABC::Address::Work );
  if( address.isEmpty() )
    address = contact.address(KABC::Address::Home );
  if( address.isEmpty() )
    address = contact.address(KABC::Address::Postal );

  tmpl->setValue( ADDRESS_TAG( prefix, "POSTBOX" ),
                  escapeTrml2pdfXML( address.postOfficeBox() ) );

  tmpl->setValue( ADDRESS_TAG( prefix, "EXTENDED" ),
                  escapeTrml2pdfXML( address.extended() ) );
  tmpl->setValue( ADDRESS_TAG( prefix, "STREET" ),
                  escapeTrml2pdfXML( address.street() ) );
  tmpl->setValue( ADDRESS_TAG( prefix, "LOCALITY" ),
                  escapeTrml2pdfXML( address.locality() ) );
  tmpl->setValue( ADDRESS_TAG( prefix, "REGION" ),
                  escapeTrml2pdfXML( address.region() ) );
  tmpl->setValue( ADDRESS_TAG( prefix, "POSTCODE" ),
                  escapeTrml2pdfXML( address.postalCode() ) );
  tmpl->setValue( ADDRESS_TAG( prefix, "COUNTRY" ),
                  escapeTrml2pdfXML( address.country() ) );
  tmpl->setValue( ADDRESS_TAG( prefix, "REGION" ),
                  escapeTrml2pdfXML( address.region() ) );
  tmpl->setValue( ADDRESS_TAG( prefix,"LABEL" ),
                  escapeTrml2pdfXML( address.label() ) );


}
示例#18
0
    d->m_authorUi->leFullName->setText(addr.formattedName());
    d->m_authorUi->leInitials->setText(addr.givenName()[ 0 ] + ". " +
                                       addr.familyName()[ 0 ] + '.');
    d->m_authorUi->leTitle->setText(addr.title());
    d->m_authorUi->leCompany->setText(addr.organization());
    d->m_authorUi->leEmail->setText(addr.preferredEmail());

    KABC::PhoneNumber phone = addr.phoneNumber(KABC::PhoneNumber::Home);
    d->m_authorUi->lePhoneHome->setText(phone.number());
    phone = addr.phoneNumber(KABC::PhoneNumber::Work);
    d->m_authorUi->lePhoneWork->setText(phone.number());

    phone = addr.phoneNumber(KABC::PhoneNumber::Fax);
    d->m_authorUi->leFax->setText(phone.number());

    KABC::Address a = addr.address(KABC::Address::Home);
    d->m_authorUi->leCountry->setText(a.country());
    d->m_authorUi->lePostal->setText(a.postalCode());
    d->m_authorUi->leCity->setText(a.locality());
    d->m_authorUi->leStreet->setText(a.street());
#endif
}

void KoDocumentInfoDlg::slotSaveEncryption()
{
    if (!d->m_applyToggleEncryption)
        return;

    KoDocument* doc = dynamic_cast< KoDocument* >(d->m_info->parent());
    if (!doc)
        return;
示例#19
0
void ContactsHandler::compare(Akonadi::AbstractDifferencesReporter *reporter,
                              const Akonadi::Item &leftItem, const Akonadi::Item &rightItem)
{
    Q_ASSERT(leftItem.hasPayload<KABC::Addressee>());
    Q_ASSERT(rightItem.hasPayload<KABC::Addressee>());

    const KABC::Addressee leftContact = leftItem.payload<KABC::Addressee>();
    const KABC::Addressee rightContact = rightItem.payload<KABC::Addressee>();

    const QString modifiedBy = mSession->userName();
    const QString modifiedOn = formatDate(getDateModified(rightContact));

    reporter->setLeftPropertyValueTitle(i18nc("@title:column", "Local Contact"));
    reporter->setRightPropertyValueTitle(
        i18nc("@title:column", "Serverside Contact: modified by %1 on %2",
              modifiedBy, modifiedOn));

    bool seenPrimaryAddress = false;
    bool seenOtherAddress = false;
    ContactAccessorHash::const_iterator it    = mAccessors->constBegin();
    ContactAccessorHash::const_iterator endIt = mAccessors->constEnd();
    for (; it != endIt; ++it) {
        // check if this is a read-only field
        if ((*it)->getter == 0) {
            continue;
        }

        QString leftValue = (*it)->getter(leftContact);
        QString rightValue = (*it)->getter(rightContact);

        QString diffName = (*it)->diffName;
        if (diffName.isEmpty()) {
            // check for special fields
            if (isAddressValue(it.key())) {
                if (isPrimaryAddressValue(it.key())) {
                    if (!seenPrimaryAddress) {
                        diffName = i18nc("item:intable", "Primary Address");
                        seenPrimaryAddress = true;
                        const KABC::Address leftAddress =
                            leftContact.address(KABC::Address::Work | KABC::Address::Pref);
                        const KABC::Address rightAddress =
                            rightContact.address(KABC::Address::Work | KABC::Address::Pref);

                        leftValue = leftAddress.formattedAddress();
                        rightValue = rightAddress.formattedAddress();
                    } else {
                        // already printed, skip
                        continue;
                    }
                } else {
                    if (!seenOtherAddress) {
                        seenOtherAddress = true;
                        diffName = i18nc("item:intable", "Other Address");
                        const KABC::Address leftAddress =
                            leftContact.address(KABC::Address::Home);
                        const KABC::Address rightAddress =
                            rightContact.address(KABC::Address::Home);

                        leftValue = leftAddress.formattedAddress();
                        rightValue = rightAddress.formattedAddress();
                    } else {
                        // already printed, skip
                        continue;
                    }
                }
            } else if (it.key() == "do_not_call") {
                diffName = i18nc("@item:intable", "Do Not Call");
                leftValue = getDoNotCall(leftContact) == QLatin1String("1")
                            ? QLatin1String("Yes") : QLatin1String("No");
                rightValue = getDoNotCall(rightContact) == QLatin1String("1")
                             ? QLatin1String("Yes") : QLatin1String("No");
            } else {
                // internal field, skip
                continue;
            }
        }

        if (leftValue.isEmpty() && rightValue.isEmpty()) {
            continue;
        }

        if (leftValue.isEmpty()) {
            reporter->addProperty(Akonadi::AbstractDifferencesReporter::AdditionalRightMode,
                                  diffName, leftValue, rightValue);
        } else if (rightValue.isEmpty()) {
            reporter->addProperty(Akonadi::AbstractDifferencesReporter::AdditionalLeftMode,
                                  diffName, leftValue, rightValue);
        } else if (leftValue != rightValue) {
            reporter->addProperty(Akonadi::AbstractDifferencesReporter::ConflictMode,
                                  diffName, leftValue, rightValue);
        }
    }
}
示例#20
0
static void setOtherCountry(const QString &value, KABC::Address &address)
{
    address.setCountry(value);
}
示例#21
0
static void setOtherPostalcode(const QString &value, KABC::Address &address)
{
    address.setPostalCode(value);
}
bool VCard_LDIFCreator::readContents( const QString &path )
{
  // read file contents
  QFile file( path );
  if ( !file.open( QIODevice::ReadOnly ) )
    return false;

  QString info;
  text.truncate(0);

  // read the file
  QByteArray contents = file.readAll();
  file.close();

  // convert the file contents to a KABC::Addressee address
  KABC::Addressee::List addrList;
  KABC::Addressee addr;
  KABC::VCardConverter converter;

  addrList = converter.parseVCards( contents);
  if ( addrList.count() == 0 ) {
    KABC::AddresseeList l; // FIXME porting
    if ( !KABC::LDIFConverter::LDIFToAddressee( contents, l ) )
	return false;
    // FIXME porting
    KABC::AddresseeList::ConstIterator it( l.constBegin() );
    for ( ; it != l.constEnd(); ++ it ) {
        addrList.append( *it );
    }
  }
  if ( addrList.count()>1 ) {
    // create an overview (list of all names)
    name = i18np("One contact found:", "%1 contacts found:", addrList.count());
    int no, linenr;
    for (linenr=no=0; linenr<30 && no<addrList.count(); ++no) {
       addr = addrList[no];
       info = addr.formattedName().simplified();
       if (info.isEmpty())
          info = addr.givenName() + ' ' + addr.familyName();
       info = info.simplified();
       if (info.isEmpty())
         continue;
       text.append(info);
       text.append("\n");
       ++linenr;
    }
    return true;
  }

  // create card for _one_ contact
  addr = addrList[ 0 ];

  // prepare the text
  name = addr.formattedName().simplified();
  if ( name.isEmpty() )
    name = addr.givenName() + ' ' + addr.familyName();
  name = name.simplified();


  KABC::PhoneNumber::List pnList = addr.phoneNumbers();
  QStringList phoneNumbers;
  for (int no=0; no<pnList.count(); ++no) {
    QString pn = pnList[no].number().simplified();
    if (!pn.isEmpty() && !phoneNumbers.contains(pn))
      phoneNumbers.append(pn);
  }
  if ( !phoneNumbers.isEmpty() )
      text += phoneNumbers.join("\n") + '\n';

  info = addr.organization().simplified();
  if ( !info.isEmpty() )
    text += info + '\n';

  // get an address
  KABC::Address address = addr.address(KABC::Address::Work);
  if (address.isEmpty())
    address = addr.address(KABC::Address::Home);
  if (address.isEmpty())
    address = addr.address(KABC::Address::Pref);
  info = address.formattedAddress();
  if ( !info.isEmpty() )
    text += info + '\n';

  return true;
}
示例#23
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 ) );
}
示例#24
0
QString AddresseeDiffAlgo::toString(const KABC::Address &addr)
{
    return addr.formattedAddress();
}
示例#25
0
static gn_error read_phone_entry_highlevel( int index, const gn_memory_type memtype, KABC::Addressee *a )
{
  gn_phonebook_entry entry;
  QStringList addrlist;
  QString s, country;
  KABC::Address *addr;
  gn_error error;

//  if (index > (memstat.used + memstat.free))
//	return GN_ERR_INVALIDLOCATION;

  error = read_phone_entry( index, memtype, &entry );
  if (error != GN_ERR_NONE)
      return error;

  GNOKII_DEBUG(QString("%1: %2, num=%3, location=%4, group=%5, count=%6\n").arg(index).arg(entry.name)
	.arg(entry.number).arg(entry.location).arg(entry.caller_group).arg(entry.subentries_count));

  // try to split Name into FamilyName and GivenName
  s = QString(entry.name).simplifyWhiteSpace();
  a->setFormattedName(s);
  if (s.find(',')!=-1) {
  	addrlist = QStringList::split(',', s);
	if (addrlist.count()==2) {
		a->setFamilyName(addrlist[0].simplifyWhiteSpace());
		a->setGivenName(addrlist[1].simplifyWhiteSpace());
	  } else
		a->setGivenName(s);
  } else {
  	addrlist = QStringList::split(' ', s);
	  if (addrlist.count()==2) {
		a->setFamilyName(addrlist[1].simplifyWhiteSpace());
		a->setGivenName(addrlist[0].simplifyWhiteSpace());
	  } else
		a->setGivenName(s);
  }

  a->insertCustom(APP, "X_GSM_CALLERGROUP", s.setNum(entry.caller_group));
  a->insertCustom(APP, "X_GSM_STORE_AT", QString("%1_%2").arg(GN_MT_ME).arg(entry.location));

  // set ProductId
  a->setProductId(PhoneProductId);

  // evaluate timestamp (ignore timezone)
  QDateTime datetime;
  if (entry.date.year<1998)
	datetime = QDateTime::currentDateTime();
  else
	datetime = QDateTime( QDate(entry.date.year, entry.date.month, entry.date.day), 
			  QTime(entry.date.hour, entry.date.minute, entry.date.second) );
  GNOKII_DEBUG(QString(" date=%1\n").arg(datetime.toString()));
  a->setRevision(datetime);

  if (!entry.subentries_count)
	a->insertPhoneNumber(KABC::PhoneNumber(entry.number, KABC::PhoneNumber::Work | KABC::PhoneNumber::Pref));

  /* scan sub-entries */
  if (entry.subentries_count)
	 for (int n=0; n<entry.subentries_count; n++) {
		QString s = QString(entry.subentries[n].data.number).simplifyWhiteSpace();
		GNOKII_DEBUG(QString(" Subentry#%1, entry_type=%2, number_type=%3, number=%4\n")
			.arg(n).arg(entry.subentries[n].entry_type)
			.arg(entry.subentries[n].number_type).arg(s));
		if (s.isEmpty())
			continue;
		switch(entry.subentries[n].entry_type) {
		   case GN_PHONEBOOK_ENTRY_Name:
				a->setName(s);
				break;
		   case GN_PHONEBOOK_ENTRY_Email:
				a->insertEmail(s);
				break;
		   case GN_PHONEBOOK_ENTRY_Postal:
				addrlist = QStringList::split(',', s, true);
				addr = new KABC::Address(KABC::Address::Work);
				switch (addrlist.count()) {
				 case 4:	addr->setStreet(addrlist[0].simplifyWhiteSpace());
						addr->setLocality(addrlist[1].simplifyWhiteSpace());
						addr->setPostalCode(addrlist[2].simplifyWhiteSpace());
						country = addrlist[3].simplifyWhiteSpace();
						if (!country.isEmpty())
							addr->setCountry(i18n(country.utf8()));
						break;
				 case 3:	addr->setLocality(addrlist[0].simplifyWhiteSpace());
						addr->setPostalCode(addrlist[1].simplifyWhiteSpace());
						country = addrlist[2].simplifyWhiteSpace();
						if (!country.isEmpty())
							addr->setCountry(i18n(country.utf8()));
						break;
				 default:	addr->setStreet(s.simplifyWhiteSpace());
				}
				a->insertAddress(*addr);
				delete addr;
				break;
		   case GN_PHONEBOOK_ENTRY_Note:
				if (!a->note().isEmpty())
					s = "\n" + s;
				a->setNote(a->note()+s);
				break;
		   case GN_PHONEBOOK_ENTRY_Number:
				enum KABC::PhoneNumber::Types phonetype;
				switch (entry.subentries[n].number_type) {
				 case GN_PHONEBOOK_NUMBER_Mobile: phonetype = KABC::PhoneNumber::Cell; break;
				 case GN_PHONEBOOK_NUMBER_Fax:    phonetype = KABC::PhoneNumber::Fax;  break;
				 case GN_PHONEBOOK_NUMBER_General:
				 case GN_PHONEBOOK_NUMBER_Work:   phonetype = KABC::PhoneNumber::Work; break;
				 default:
				 case GN_PHONEBOOK_NUMBER_Home:   phonetype = KABC::PhoneNumber::Home; break;
				}
				//if (s == entry.number)
				//  type = (KABC::PhoneNumber::Types) (phonetype | KABC::PhoneNumber::Pref);
				a->insertPhoneNumber(KABC::PhoneNumber(s, phonetype));
				break;
		   case GN_PHONEBOOK_ENTRY_URL:
				a->setUrl(s);
				break;
		   case GN_PHONEBOOK_ENTRY_Group:
				a->insertCategory(s);
				break;
		   default:
				GNOKII_DEBUG(QString(" Not handled id=%1, entry=%2\n")
					.arg(entry.subentries[n].entry_type).arg(s));
				break;
		  } // switch()
	} // for(subentry)

  GNOKII_CHECK_ERROR(error);
  return error;
}
QVariant ContactsTreeModel::entityData( const Item &item, int column, int role ) const
{
  if ( item.mimeType() == KABC::Addressee::mimeType() ) {
    if ( !item.hasPayload<KABC::Addressee>() ) {

      // Pass modeltest
      if ( role == Qt::DisplayRole )
        return item.remoteId();

      return QVariant();
    }

    const KABC::Addressee contact = item.payload<KABC::Addressee>();

    if ( role == Qt::DecorationRole ) {
      if ( column == 0 ) {
        const KABC::Picture picture = contact.photo();
        if ( picture.isIntern() ) {
          return picture.data().scaled( QSize( 16, 16 ), Qt::KeepAspectRatio );
        } else {
          return KIcon( QLatin1String( "x-office-contact" ) );
        }
      }
      return QVariant();
    } else if ( (role == Qt::DisplayRole) || (role == Qt::EditRole) ) {
      switch ( mColumns.at( column ) ) {
        case FullName:
          return contact.realName();
          break;
        case Birthday:
          if ( contact.birthday().isValid() )
            return KGlobal::locale()->formatDate( contact.birthday().date() );
          break;
        case HomeAddress:
          {
            const KABC::Address address = contact.address( KABC::Address::Home );
            if ( !address.isEmpty() )
              return address.formattedAddress();
          }
          break;
        case BusinessAddress:
          {
            const KABC::Address address = contact.address( KABC::Address::Work );
            if ( !address.isEmpty() )
              return address.formattedAddress();
          }
          break;
        case PhoneNumbers:
          {
            QStringList values;

            const KABC::PhoneNumber::List numbers = contact.phoneNumbers();
            foreach ( const KABC::PhoneNumber &number, numbers )
              values += number.number();

            return values.join( "\n" );
          }
          break;
        case PreferredEmail:
          return contact.preferredEmail();
          break;
        case AllEmails:
          return contact.emails().join( "\n" );
          break;
        case Organization:
          return contact.organization();
          break;
        case Homepage:
          return contact.url().url();
          break;
        case Note:
          return contact.note();
          break;
      }
    }
  } else if ( item.mimeType() == KABC::ContactGroup::mimeType() ) {
示例#27
0
/**
  Parses a snippet of an address template
  @param tsection   the template string to be parsed
  @param result     QString reference in which the result will be stored
  @return           true if at least one tag evaluated positively, else false
*/
static bool parseAddressTemplateSection( const QString &tsection, QString &result,
                                         const QString &realName, const QString &orgaName,
                                         const KABC::Address &address )
{
  // This method first parses and substitutes any bracketed sections and
  // after that replaces any tags with their values. If a bracketed section
  // or a tag evaluate to zero, they are not just removed but replaced
  // with a placeholder. This is because in the last step conditionals are
  // resolved which depend on information about zero-evaluations.
  result = tsection;
  int stpos = 0;
  bool ret = false;

  // first check for brackets that have to be evaluated first
  int fpos = result.indexOf( KABC_FMTTAG_purgeempty, stpos );
  while ( -1 != fpos ) {
    int bpos1 = fpos + KABC_FMTTAG_purgeempty.length();
    int bpos2;
    // expect opening bracket and find next balanced closing bracket. If
    // next char is no opening bracket, continue parsing (no valid tag)
    if ( QLatin1Char( '(' ) == result[bpos1] ) {
      bpos2 = findBalancedBracket( result, bpos1 );
      if ( -1 != bpos2 ) {
        // we have balanced brackets, recursively parse:
        QString rplstr;
        bool purge = !parseAddressTemplateSection( result.mid( bpos1+1,
                                                   bpos2-bpos1-1 ), rplstr,
                                                   realName, orgaName, address );
        if ( purge ) {
          // purge -> remove all
          // replace with !_P_!, so conditional tags work later
          result.replace( fpos, bpos2 - fpos + 1, QLatin1String( "!_P_!" ) );
          // leave stpos as it is
        } else {
          // no purge -> replace with recursively parsed string
          result.replace( fpos, bpos2 - fpos + 1, rplstr );
          ret = true;
          stpos = fpos + rplstr.length();
        }
      } else {
        // unbalanced brackets:  keep on parsing (should not happen
        // and will result in bad formatting)
        stpos = bpos1;
      }
    }
    fpos = result.indexOf( KABC_FMTTAG_purgeempty, stpos );
  }

  // after sorting out all purge tags, we just search'n'replace the rest,
  // keeping track of whether at least one tag evaluates to something.
  // The following macro needs QString for R_FIELD
  // It substitutes !_P_! for empty fields so conditional tags work later
#define REPLTAG(R_TAG,R_FIELD) \
  if ( result.indexOf( R_TAG, false ) != -1 ) { \
    QString rpl = R_FIELD.isEmpty() ? QLatin1String( "!_P_!" ) : R_FIELD; \
    result.replace( R_TAG, rpl ); \
    if ( !R_FIELD.isEmpty() ) { \
      ret = true; \
    } \
  }
  REPLTAG( KABC_FMTTAG_realname, realName );
  REPLTAG( KABC_FMTTAG_REALNAME, realName.toUpper() );
  REPLTAG( KABC_FMTTAG_company, orgaName );
  REPLTAG( KABC_FMTTAG_COMPANY, orgaName.toUpper() );
  REPLTAG( KABC_FMTTAG_pobox, address.postOfficeBox() );
  REPLTAG( KABC_FMTTAG_street, address.street() );
  REPLTAG( KABC_FMTTAG_STREET, address.street().toUpper() );
  REPLTAG( KABC_FMTTAG_zipcode, address.postalCode() );
  REPLTAG( KABC_FMTTAG_location, address.locality() );
  REPLTAG( KABC_FMTTAG_LOCATION, address.locality().toUpper() );
  REPLTAG( KABC_FMTTAG_region, address.region() );
  REPLTAG( KABC_FMTTAG_REGION, address.region().toUpper() );
  result.replace( KABC_FMTTAG_newline, QLatin1String( "\n" ) );
#undef REPLTAG

  // conditional comma
  fpos = result.indexOf( KABC_FMTTAG_condcomma, 0 );
  while ( -1 != fpos ) {
    const QString str1 = result.mid( fpos - 5, 5 );
    const QString str2 = result.mid( fpos + 2, 5 );
    if ( str1 != QLatin1String( "!_P_!" ) && str2 != QLatin1String( "!_P_!" ) ) {
      result.replace( fpos, 2, QLatin1String( ", " ) );
    } else {
      result.remove( fpos, 2 );
    }
    fpos = result.indexOf( KABC_FMTTAG_condcomma, fpos );
  }
  // conditional whitespace
  fpos = result.indexOf( KABC_FMTTAG_condwhite, 0 );
  while ( -1 != fpos ) {
    const QString str1 = result.mid( fpos - 5, 5 );
    const QString str2 = result.mid( fpos + 2, 5 );
    if ( str1 != QLatin1String( "!_P_!" ) && str2 != QLatin1String( "!_P_!" ) ) {
      result.replace( fpos, 2, QLatin1String( " " ) );
    } else {
      result.remove( fpos, 2 );
    }
    fpos = result.indexOf( KABC_FMTTAG_condwhite, fpos );
  }

  // remove purged:
  result.remove( QLatin1String( "!_P_!" ) );

  return ret;
}