/** Returns the reverse of this address map by swapping each address in the * address map with its mapped address. The expiration times are unaltered. */ AddressMap AddressMap::reverse() const { AddressMap reverseMap; foreach (QString from, keys()) { /* Flip the "from" and the "to" addresses and retain the expiry time. */ AddressMapEntry entry = value(from); reverseMap.add(entry.first, from, entry.second); }
int main() { typedef map<string, string> AddressMap; AddressMap addresses; addresses["davek"] = "*****@*****.**"; addresses["nikki"] = "*****@*****.**"; addresses["angie"] = "*****@*****.**"; addresses["billg"] = "*****@*****.**"; AddressMap::iterator myIter; for (myIter = addresses.begin(); myIter != addresses.end(); myIter++) { const string& nickname = myIter->first; const string& email = myIter->second; cout << "Nickname: \t" << nickname << " \tEmail: \t" << email << endl; } }
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; }