Ejemplo n.º 1
0
bool BookmarkXXPort::exportContacts( const KABC::AddresseeList &list, const QString& )
{
  QString fileName = locateLocal( "data", "kabc/bookmarks.xml" );

  KBookmarkManager *mgr = KBookmarkManager::managerForFile( fileName );
  KBookmarkDomBuilder *builder = new KBookmarkDomBuilder( mgr->root(), mgr );
  builder->connectImporter( this );

  KABC::AddresseeList::ConstIterator it;
  emit newFolder( i18n( "AddressBook" ), false, "" );
  for ( it = list.begin(); it != list.end(); ++it ) {
    if ( !(*it).url().isEmpty() ) {
      QString name = (*it).givenName() + " " + (*it).familyName();
      emit newBookmark( name, (*it).url().url().latin1(), QString( "" ) );
    }
  }
  emit endFolder();
  delete builder;
  mgr->save();

  KBookmarkMenu::DynMenuInfo menu;
  menu.name = i18n( "Addressbook Bookmarks" );
  menu.location = fileName;
  menu.type = "xbel";
  menu.show = true;
  KBookmarkMenu::setDynamicBookmarks( "kabc", menu );

  return true;
}
Ejemplo n.º 2
0
void XXPortManager::slotImport(const QString &identifier, const QString &data)
{
    KAB::XXPort *obj = mXXPortObjects[ identifier ];
    if(!obj)
    {
        KMessageBox::error(mCore->widget(), i18n("<qt>No import plugin available for <b>%1</b>.</qt>").arg(identifier));
        return;
    }

    KABC::Resource *resource = mCore->requestResource(mCore->widget());
    if(!resource)
        return;

    KABC::AddresseeList list = obj->importContacts(data);
    KABC::AddresseeList::Iterator it;
    for(it = list.begin(); it != list.end(); ++it)
        (*it).setResource(resource);

    if(!list.isEmpty())
    {
        NewCommand *command = new NewCommand(mCore->addressBook(), list);
        mCore->commandHistory()->addCommand(command);
        emit modified();
    }
}
Ejemplo n.º 3
0
void CSVXXPort::doExport( QFile *fp, const KABC::AddresseeList &list )
{
  QTextStream t( fp );
  t.setCodec( QTextCodec::codecForLocale() );

  KABC::AddresseeList::ConstIterator iter;
  KABC::Field::List fields = addressBook()->fields();
  KABC::Field::List::Iterator fieldIter;
  bool first = true;

  // First output the column headings
  for ( fieldIter = fields.begin(); fieldIter != fields.end(); ++fieldIter ) {
    if ( !first )
      t << ",";

    t << "\"" << (*fieldIter)->label() << "\"";
    first = false;
  }
  t << "\n";

  // Then all the addressee objects
  KABC::Addressee addr;
  for ( iter = list.begin(); iter != list.end(); ++iter ) {
    addr = *iter;
    first = true;

    for ( fieldIter = fields.begin(); fieldIter != fields.end(); ++fieldIter ) {
      if ( !first )
        t << ",";

      t << '\"' << (*fieldIter)->value( addr ).replace( '\n', "\\n" ) << '\"';
      first = false;
    }

    t << "\n";
  }
}
Ejemplo n.º 4
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 << "####";
}
Ejemplo n.º 5
0
bool GeoXXPort::exportContacts( const KABC::AddresseeList &list, const QString& )
{
  KConfig config( "kworldclockrc" );

  // At first we read all exiting flags and compare it with ours to
  // avoid duplicated flags
  int flags = config.readNumEntry( "Flags", 0 );
  QValueList<FlagInfo> availableFlags;

  if ( flags != 0 ) {
    for ( int i = 0; i < flags; ++i ) {
      FlagInfo info;
      info.latitude = config.readDoubleNumEntry( QString( "Flag_%1_Latitude" ).arg( i ) );
      info.longitude = config.readDoubleNumEntry( QString( "Flag_%1_Longitude" ).arg( i ) );
      info.color = config.readColorEntry( QString( "Flag_%1_Color" ).arg( i ) );

      availableFlags.append( info );
    }
  }


  QValueList<FlagInfo> flagList;
  KABC::AddresseeList::ConstIterator addrIt;
  for ( addrIt = list.begin(); addrIt != list.end(); ++addrIt ) {
    KABC::Geo geo( (*addrIt).geo() );
    if ( !geo.isValid() )
      continue;

    bool available = false;
    QValueList<FlagInfo>::Iterator it;
    for ( it = availableFlags.begin(); it != availableFlags.end(); ++it ) {
      if ( !( KABS( (*it).latitude - geo.latitude() ) > DBL_EPSILON ) &&
           !( KABS( (*it).longitude - geo.longitude() ) > DBL_EPSILON ) ) {
        available = true;
        break;
      }
    }

    if ( !available ) {
      FlagInfo info;
      info.latitude = geo.latitude();
      info.longitude = geo.longitude();
      info.color = QColor( 0, 255, 0 );

      flagList.append( info );
    }
  }

  if ( flagList.count() == 0 ) // nothing to export
    return true;

  flagList += availableFlags;

  int startVal = 0;
  QValueList<FlagInfo>::Iterator it;
  for ( it = flagList.begin(); it != flagList.end(); ++it, ++startVal ) {
    config.writeEntry( QString( "Flag_%1_Color" ).arg( startVal ), (*it).color );
    config.writeEntry( QString( "Flag_%1_Latitude" ).arg( startVal ), (*it).latitude );
    config.writeEntry( QString( "Flag_%1_Longitude" ).arg( startVal ), (*it).longitude );
  }
  config.writeEntry( "Flags", startVal );

  return true;
}
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
0
bool VCardXXPort::exportContacts( const KABC::AddresseeList &addrList, const QString &data )
{
  KABC::VCardConverter converter;
  KURL url;
  KABC::AddresseeList list;

  list = filterContacts( addrList );

  bool ok = true;
  if ( list.isEmpty() ) {
    return ok;
  } else if ( list.count() == 1 ) {
    url = KFileDialog::getSaveURL( list[ 0 ].givenName() + "_" + list[ 0 ].familyName() + ".vcf" );
    if ( url.isEmpty() )
      return true;

    if ( data == "v21" )
      ok = doExport( url, converter.createVCards( list, KABC::VCardConverter::v2_1 ) );
    else
      ok = doExport( url, converter.createVCards( list, KABC::VCardConverter::v3_0 ) );
  } else {
    QString msg = i18n( "You have selected a list of contacts, shall they be "
                        "exported to several files?" );

    switch ( KMessageBox::questionYesNo( parentWidget(), msg, QString::null, i18n("Export to Several Files"), i18n("Export to One File") ) ) {
      case KMessageBox::Yes: {
        KURL baseUrl = KFileDialog::getExistingURL();
        if ( baseUrl.isEmpty() )
          return true;

        KABC::AddresseeList::ConstIterator it;
        uint counter = 0;
        for ( it = list.begin(); it != list.end(); ++it ) {
          QString testUrl;
          if ( (*it).givenName().isEmpty() && (*it).familyName().isEmpty() )
            testUrl = baseUrl.url() + "/" + (*it).organization();
          else
            testUrl = baseUrl.url() + "/" + (*it).givenName() + "_" + (*it).familyName();

          if ( KIO::NetAccess::exists( testUrl + (counter == 0 ? "" : QString::number( counter )) + ".vcf", false, parentWidget() ) ) {
            counter++;
            url = testUrl + QString::number( counter ) + ".vcf";
          } else
            url = testUrl + ".vcf";

          bool tmpOk;
          KABC::AddresseeList tmpList;
          tmpList.append( *it );

          if ( data == "v21" )
            tmpOk = doExport( url, converter.createVCards( tmpList, KABC::VCardConverter::v2_1 ) );
          else
            tmpOk = doExport( url, converter.createVCards( tmpList, KABC::VCardConverter::v3_0 ) );

          ok = ok && tmpOk;
        }
        break;
      }
      case KMessageBox::No:
      default: {
        url = KFileDialog::getSaveURL( "addressbook.vcf" );
        if ( url.isEmpty() )
          return true;

        if ( data == "v21" )
          ok = doExport( url, converter.createVCards( list, KABC::VCardConverter::v2_1 ) );
        else
          ok = doExport( url, converter.createVCards( list, KABC::VCardConverter::v3_0 ) );
      }
    }
  }

  return ok;
}