kabc Library API Documentation

addressee.src.cpp

00001 /*
00002     This file is part of libkabc.
00003     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018     Boston, MA 02111-1307, USA.
00019 */
00020 #include <ksharedptr.h>
00021 #include <kdebug.h>
00022 #include <kapplication.h>
00023 #include <klocale.h>
00024 
00025 #include "resource.h"
00026 #include "addressee.h"
00027 
00028 using namespace KABC;
00029 
00030 bool matchBinaryPattern( int value, int pattern, int max );
00031 
00032 struct Addressee::AddresseeData : public KShared
00033 {
00034   --VARIABLES--
00035 
00036   PhoneNumber::List phoneNumbers;
00037   Address::List addresses;
00038   Key::List keys;
00039   QStringList emails;
00040   QStringList categories;
00041   QStringList custom;
00042 
00043   Resource *resource;
00044 
00045   bool empty;
00046   bool changed;
00047 };
00048 
00049 Addressee::Addressee()
00050 {
00051   mData = new AddresseeData;
00052   mData->uid = KApplication::randomString( 10 );
00053   mData->empty = true;
00054   mData->changed = false;
00055   mData->resource = 0;
00056 }
00057 
00058 Addressee::~Addressee()
00059 {
00060 }
00061 
00062 Addressee::Addressee( const Addressee &a )
00063 {
00064   mData = a.mData;
00065 }
00066 
00067 Addressee &Addressee::operator=( const Addressee &a )
00068 {
00069   mData = a.mData;
00070   return (*this);
00071 }
00072 
00073 Addressee Addressee::copy()
00074 {
00075   Addressee a;
00076   *(a.mData) = *mData;
00077   return a;
00078 }
00079 
00080 void Addressee::detach()
00081 {
00082   if ( mData.count() == 1 ) return;
00083   *this = copy();
00084 }
00085 
00086 bool Addressee::operator==( const Addressee &a ) const
00087 {
00088   --EQUALSTEST--
00089   if ( ( mData->url.isValid() || a.mData->url.isValid() ) &&
00090        ( mData->url != a.mData->url ) ) return false;
00091   if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false;
00092   if ( mData->addresses != a.mData->addresses ) return false;
00093   if ( mData->keys != a.mData->keys ) return false;
00094   if ( mData->emails != a.mData->emails ) return false;
00095   if ( mData->categories != a.mData->categories ) return false;
00096   if ( mData->custom != a.mData->custom ) return false;
00097 
00098   return true;
00099 }
00100 
00101 bool Addressee::operator!=( const Addressee &a ) const
00102 {
00103   return !( a == *this );
00104 }
00105 
00106 bool Addressee::isEmpty() const
00107 {
00108   return mData->empty;
00109 }
00110 
00111 --DEFINITIONS--
00112 
00113 void Addressee::setNameFromString( const QString &str )
00114 {
00115   setFormattedName( str );
00116   setName( str );
00117 
00118   QStringList titles;
00119   titles += i18n( "Dr." );
00120   titles += i18n( "Miss" );
00121   titles += i18n( "Mr." );
00122   titles += i18n( "Mrs." );
00123   titles += i18n( "Ms." );
00124   titles += i18n( "Prof." );
00125 
00126   QStringList suffixes;
00127   suffixes += i18n( "I" );
00128   suffixes += i18n( "II" );
00129   suffixes += i18n( "III" );
00130   suffixes += i18n( "Jr." );
00131   suffixes += i18n( "Sr." );
00132 
00133   QStringList prefixes;
00134   prefixes += "van";
00135   prefixes += "von";
00136   prefixes += "de";
00137 
00138   // clear all name parts
00139   setPrefix( "" );
00140   setGivenName( "" );
00141   setAdditionalName( "" );
00142   setFamilyName( "" );
00143   setSuffix( "" );
00144 
00145   if ( str.isEmpty() )
00146     return;
00147 
00148   int i = str.find(',');
00149   if( i < 0 ) {
00150     QStringList parts = QStringList::split( " ", str );
00151     int leftOffset = 0;
00152     int rightOffset = parts.count() - 1;
00153 
00154     QString suffix;
00155     while ( rightOffset >= 0 ) {
00156       if ( suffixes.contains( parts[ rightOffset ] ) ) {
00157         suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " "));
00158         rightOffset--;
00159       } else
00160         break;
00161     }
00162     setSuffix( suffix );
00163 
00164     if ( rightOffset < 0 )
00165       return;
00166 
00167     if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) {
00168       setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] );
00169       rightOffset--;
00170     } else
00171       setFamilyName( parts[ rightOffset ] );
00172 
00173     QString prefix;
00174     while ( leftOffset < rightOffset ) {
00175       if ( titles.contains( parts[ leftOffset ] ) ) {
00176         prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
00177         leftOffset++;
00178       } else
00179         break;
00180     }
00181     setPrefix( prefix );
00182 
00183     if ( leftOffset < rightOffset ) {
00184       setGivenName( parts[ leftOffset ] );
00185       leftOffset++;
00186     }
00187 
00188     QString additionalName;
00189     while ( leftOffset < rightOffset ) {
00190       additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] );
00191       leftOffset++;
00192     }
00193     setAdditionalName( additionalName );
00194   } else {
00195     QString part1 = str.left( i );
00196     QString part2 = str.mid( i + 1 );
00197 
00198     QStringList parts = QStringList::split( " ", part1 );
00199     int leftOffset = 0;
00200     int rightOffset = parts.count() - 1;
00201 
00202     QString suffix;
00203     while ( rightOffset >= 0 ) {
00204       if ( suffixes.contains( parts[ rightOffset ] ) ) {
00205         suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " "));
00206         rightOffset--;
00207       } else
00208         break;
00209     }
00210     setSuffix( suffix );
00211 
00212     if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) {
00213       setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] );
00214       rightOffset--;
00215     } else
00216       setFamilyName( parts[ rightOffset ] );
00217 
00218     QString prefix;
00219     while ( leftOffset < rightOffset ) {
00220       if ( titles.contains( parts[ leftOffset ] ) ) {
00221         prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
00222         leftOffset++;
00223       } else
00224         break;
00225     }
00226 
00227     parts = QStringList::split( " ", part2 );
00228 
00229     leftOffset = 0;
00230     rightOffset = parts.count();
00231 
00232     while ( leftOffset < rightOffset ) {
00233       if ( titles.contains( parts[ leftOffset ] ) ) {
00234         prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] );
00235         leftOffset++;
00236       } else
00237         break;
00238     }
00239     setPrefix( prefix );
00240 
00241     if ( leftOffset < rightOffset ) {
00242       setGivenName( parts[ leftOffset ] );
00243       leftOffset++;
00244     }
00245 
00246     QString additionalName;
00247     while ( leftOffset < rightOffset ) {
00248       additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] );
00249       leftOffset++;
00250     }
00251     setAdditionalName( additionalName );
00252   }
00253 }
00254 
00255 QString Addressee::realName() const
00256 {
00257   if ( !formattedName().isEmpty() )
00258     return formattedName();
00259 
00260   QString n = assembledName();
00261 
00262   if ( n.isEmpty() )
00263     n = name();
00264   
00265   return n;
00266 }
00267 
00268 QString Addressee::assembledName() const
00269 {
00270   QString name = prefix() + " " + givenName() + " " + additionalName() + " " +
00271               familyName() + " " + suffix();
00272 
00273   return name.simplifyWhiteSpace();
00274 }
00275 
00276 QString Addressee::fullEmail( const QString &email ) const
00277 {
00278   QString e;
00279   if ( email.isNull() ) {
00280     e = preferredEmail();
00281   } else {
00282     e = email;
00283   }
00284   if ( e.isEmpty() ) return QString::null;
00285   
00286   QString text;
00287   if ( !realName().isEmpty() ) text = realName() + " ";
00288   text.append( "<" + e + ">" );
00289 
00290   return text;
00291 }
00292 
00293 void Addressee::insertEmail( const QString &email, bool preferred )
00294 {
00295   detach();
00296 
00297   QStringList::Iterator it = mData->emails.find( email );
00298 
00299   if ( it != mData->emails.end() ) {
00300     if ( !preferred || it == mData->emails.begin() ) return;
00301     mData->emails.remove( it );
00302     mData->emails.prepend( email );
00303   } else {
00304     if ( preferred ) {
00305       mData->emails.prepend( email );
00306     } else {
00307       mData->emails.append( email );
00308     }
00309   }
00310 }
00311 
00312 void Addressee::removeEmail( const QString &email )
00313 {
00314   detach();
00315 
00316   QStringList::Iterator it = mData->emails.find( email );
00317   if ( it == mData->emails.end() ) return;
00318 
00319   mData->emails.remove( it );
00320 }
00321 
00322 QString Addressee::preferredEmail() const
00323 {
00324   if ( mData->emails.count() == 0 ) return QString::null;
00325   else return mData->emails.first();
00326 }
00327 
00328 QStringList Addressee::emails() const
00329 {
00330   return mData->emails;
00331 }
00332 
00333 void Addressee::insertPhoneNumber( const PhoneNumber &phoneNumber )
00334 {
00335   detach();
00336   mData->empty = false;
00337 
00338   PhoneNumber::List::Iterator it;
00339   for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
00340     if ( (*it).id() == phoneNumber.id() ) {
00341       *it = phoneNumber;
00342       return;
00343     }
00344   }
00345   mData->phoneNumbers.append( phoneNumber );
00346 }
00347 
00348 void Addressee::removePhoneNumber( const PhoneNumber &phoneNumber )
00349 {
00350   detach();
00351 
00352   PhoneNumber::List::Iterator it;
00353   for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
00354     if ( (*it).id() == phoneNumber.id() ) {
00355       mData->phoneNumbers.remove( it );
00356       return;
00357     }
00358   }
00359 }
00360 
00361 PhoneNumber Addressee::phoneNumber( int type ) const
00362 {
00363   PhoneNumber phoneNumber( "", type );
00364   PhoneNumber::List::ConstIterator it;
00365   for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
00366     if ( matchBinaryPattern( (*it).type(), type, PhoneNumber::Pager ) ) {
00367       if ( (*it).type() & PhoneNumber::Pref )
00368         return (*it);
00369       else if ( phoneNumber.number().isEmpty() )
00370         phoneNumber = (*it);
00371     }
00372   }
00373 
00374   return phoneNumber;
00375 }
00376 
00377 PhoneNumber::List Addressee::phoneNumbers() const
00378 {
00379   return mData->phoneNumbers;
00380 }
00381 
00382 PhoneNumber::List Addressee::phoneNumbers( int type ) const
00383 {
00384   PhoneNumber::List list;
00385 
00386   PhoneNumber::List::ConstIterator it;
00387   for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
00388     if ( matchBinaryPattern( (*it).type(), type, PhoneNumber::Pager ) ) {
00389       list.append( *it );
00390     }
00391   }
00392   return list;
00393 }
00394 
00395 PhoneNumber Addressee::findPhoneNumber( const QString &id ) const
00396 {
00397   PhoneNumber::List::ConstIterator it;
00398   for( it = mData->phoneNumbers.begin(); it != mData->phoneNumbers.end(); ++it ) {
00399     if ( (*it).id() == id ) {
00400       return *it;
00401     }
00402   }
00403   return PhoneNumber();
00404 }
00405 
00406 void Addressee::insertKey( const Key &key )
00407 {
00408   detach();
00409   mData->empty = false;
00410 
00411   Key::List::Iterator it;
00412   for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
00413     if ( (*it).id() == key.id() ) {
00414       *it = key;
00415       return;
00416     }
00417   }
00418   mData->keys.append( key );
00419 }
00420 
00421 void Addressee::removeKey( const Key &key )
00422 {
00423   detach();
00424 
00425   Key::List::Iterator it;
00426   for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
00427     if ( (*it).id() == key.id() ) {
00428       mData->keys.remove( key );
00429       return;
00430     }
00431   }
00432 }
00433 
00434 Key Addressee::key( int type, QString customTypeString ) const
00435 {
00436   Key::List::ConstIterator it;
00437   for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
00438     if ( (*it).type() == type ) {
00439       if ( type == Key::Custom ) {
00440         if ( customTypeString.isEmpty() ) {
00441           return *it;
00442         } else {
00443           if ( (*it).customTypeString() == customTypeString )
00444             return (*it);
00445         }
00446       } else {
00447         return *it;
00448       }
00449     }
00450   }
00451   return Key( QString(), type );
00452 }
00453 
00454 Key::List Addressee::keys() const
00455 {
00456   return mData->keys;
00457 }
00458 
00459 Key::List Addressee::keys( int type, QString customTypeString ) const
00460 {
00461   Key::List list;
00462 
00463   Key::List::ConstIterator it;
00464   for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
00465     if ( (*it).type() == type ) {
00466       if ( type == Key::Custom ) {
00467         if ( customTypeString.isEmpty() ) {
00468           list.append(*it);
00469         } else {
00470           if ( (*it).customTypeString() == customTypeString )
00471             list.append(*it);
00472         }
00473       } else {
00474         list.append(*it);
00475       }
00476     }
00477   }
00478   return list;
00479 }
00480 
00481 Key Addressee::findKey( const QString &id ) const
00482 {
00483   Key::List::ConstIterator it;
00484   for( it = mData->keys.begin(); it != mData->keys.end(); ++it ) {
00485     if ( (*it).id() == id ) {
00486       return *it;
00487     }
00488   }
00489   return Key();
00490 }
00491 
00492 QString Addressee::asString() const
00493 {
00494   return "Smith, special agent Smith...";
00495 }
00496 
00497 void Addressee::dump() const
00498 {
00499   kdDebug(5700) << "Addressee {" << endl;
00500 
00501   --DEBUG--
00502   
00503   kdDebug(5700) << "  Emails {" << endl;
00504   QStringList e = emails();
00505   QStringList::ConstIterator it;
00506   for( it = e.begin(); it != e.end(); ++it ) {
00507     kdDebug(5700) << "    " << (*it) << endl;
00508   }
00509   kdDebug(5700) << "  }" << endl;
00510 
00511   kdDebug(5700) << "  PhoneNumbers {" << endl;
00512   PhoneNumber::List p = phoneNumbers();
00513   PhoneNumber::List::ConstIterator it2;
00514   for( it2 = p.begin(); it2 != p.end(); ++it2 ) {
00515     kdDebug(5700) << "    Type: " << int((*it2).type()) << " Number: " << (*it2).number() << endl;
00516   }
00517   kdDebug(5700) << "  }" << endl;
00518 
00519   Address::List a = addresses();
00520   Address::List::ConstIterator it3;
00521   for( it3 = a.begin(); it3 != a.end(); ++it3 ) {
00522     (*it3).dump();
00523   }
00524 
00525   kdDebug(5700) << "  Keys {" << endl;
00526   Key::List k = keys();
00527   Key::List::ConstIterator it4;
00528   for( it4 = k.begin(); it4 != k.end(); ++it4 ) {
00529     kdDebug(5700) << "    Type: " << int((*it4).type()) <<
00530                      " Key: " << (*it4).textData() <<
00531                      " CustomString: " << (*it4).customTypeString() << endl;
00532   }
00533   kdDebug(5700) << "  }" << endl;
00534 
00535   kdDebug(5700) << "}" << endl;
00536 }
00537 
00538 
00539 void Addressee::insertAddress( const Address &address )
00540 {
00541   detach();
00542   mData->empty = false;
00543 
00544   Address::List::Iterator it;
00545   for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
00546     if ( (*it).id() == address.id() ) {
00547       *it = address;
00548       return;
00549     }
00550   }
00551   mData->addresses.append( address );
00552 }
00553 
00554 void Addressee::removeAddress( const Address &address )
00555 {
00556   detach();
00557 
00558   Address::List::Iterator it;
00559   for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
00560     if ( (*it).id() == address.id() ) {
00561       mData->addresses.remove( it );
00562       return;
00563     }
00564   }
00565 }
00566 
00567 Address Addressee::address( int type ) const
00568 {
00569   Address address( type );
00570   Address::List::ConstIterator it;
00571   for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
00572     if ( matchBinaryPattern( (*it).type(), type, Address::Pref ) ) {
00573       if ( (*it).type() & Address::Pref )
00574         return (*it);
00575       else if ( address.isEmpty() )
00576         address = (*it);
00577     }
00578   }
00579 
00580   return address;
00581 }
00582 
00583 Address::List Addressee::addresses() const
00584 {
00585   return mData->addresses;
00586 }
00587 
00588 Address::List Addressee::addresses( int type ) const
00589 {
00590   Address::List list;
00591 
00592   Address::List::ConstIterator it;
00593   for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
00594     if ( matchBinaryPattern( (*it).type(), type , Address::Pref ) ) {
00595       list.append( *it );
00596     }
00597   }
00598 
00599   return list;
00600 }
00601 
00602 Address Addressee::findAddress( const QString &id ) const
00603 {
00604   Address::List::ConstIterator it;
00605   for( it = mData->addresses.begin(); it != mData->addresses.end(); ++it ) {
00606     if ( (*it).id() == id ) {
00607       return *it;
00608     }
00609   }
00610   return Address();
00611 }
00612 
00613 void Addressee::insertCategory( const QString &c )
00614 {
00615   detach();
00616   mData->empty = false;
00617 
00618   if ( mData->categories.contains( c ) ) return;
00619 
00620   mData->categories.append( c );
00621 }
00622 
00623 void Addressee::removeCategory( const QString &c )
00624 {
00625   detach();
00626 
00627   QStringList::Iterator it = mData->categories.find( c );
00628   if ( it == mData->categories.end() ) return;
00629 
00630   mData->categories.remove( it );
00631 }
00632 
00633 bool Addressee::hasCategory( const QString &c ) const
00634 {
00635   return ( mData->categories.contains( c ) );
00636 }
00637 
00638 void Addressee::setCategories( const QStringList &c )
00639 {
00640   detach();
00641   mData->empty = false;
00642 
00643   mData->categories = c;
00644 }
00645 
00646 QStringList Addressee::categories() const
00647 {
00648   return mData->categories;
00649 }
00650 
00651 void Addressee::insertCustom( const QString &app, const QString &name,
00652                               const QString &value )
00653 {
00654   if ( value.isNull() || name.isEmpty() || app.isEmpty() ) return;
00655 
00656   detach();
00657   mData->empty = false;
00658   
00659   QString qualifiedName = app + "-" + name + ":";
00660   
00661   QStringList::Iterator it;
00662   for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
00663     if ( (*it).startsWith( qualifiedName ) ) {
00664       (*it) = qualifiedName + value;
00665       return;
00666     }
00667   }
00668   
00669   mData->custom.append( qualifiedName + value );
00670 }
00671 
00672 void Addressee::removeCustom( const QString &app, const QString &name)
00673 {
00674   detach();
00675   
00676   QString qualifiedName = app + "-" + name + ":";
00677   
00678   QStringList::Iterator it;
00679   for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
00680     if ( (*it).startsWith( qualifiedName ) ) {
00681       mData->custom.remove( it );
00682       return;
00683     }
00684   }
00685 }
00686 
00687 QString Addressee::custom( const QString &app, const QString &name ) const
00688 {
00689   QString qualifiedName = app + "-" + name + ":";
00690   QString value;
00691   
00692   QStringList::ConstIterator it;
00693   for( it = mData->custom.begin(); it != mData->custom.end(); ++it ) {
00694     if ( (*it).startsWith( qualifiedName ) ) {
00695       value = (*it).mid( (*it).find( ":" ) + 1 );
00696       break;
00697     }
00698   }
00699   
00700   return value;
00701 }
00702 
00703 void Addressee::setCustoms( const QStringList &l )
00704 {
00705   detach();
00706   mData->empty = false;
00707   
00708   mData->custom = l;
00709 }
00710 
00711 QStringList Addressee::customs() const
00712 {
00713   return mData->custom;
00714 }
00715 
00716 void Addressee::parseEmailAddress( const QString &rawEmail, QString &fullName, 
00717                                    QString &email)
00718 {
00719   int startPos, endPos, len;
00720   QString partA, partB, result;
00721   char endCh = '>';
00722   
00723   startPos = rawEmail.find('<');
00724   if (startPos < 0)
00725   {
00726     startPos = rawEmail.find('(');
00727     endCh = ')';
00728   }
00729   if (startPos < 0)
00730   {
00731     // We couldn't find any separators, so we assume the whole string
00732     // is the email address
00733     email = rawEmail;
00734     fullName = "";
00735   }
00736   else 
00737   {
00738     // We have a start position, try to find an end
00739     endPos = rawEmail.find(endCh, startPos+1);
00740     
00741     if (endPos < 0) 
00742     {
00743       // We couldn't find the end of the email address. We can only
00744       // assume the entire string is the email address.
00745       email = rawEmail;
00746       fullName = "";
00747     }
00748     else
00749     {
00750       // We have a start and end to the email address
00751       
00752       // Grab the name part
00753       fullName = rawEmail.left(startPos).stripWhiteSpace();
00754       
00755       // grab the email part
00756       email = rawEmail.mid(startPos+1, endPos-startPos-1).stripWhiteSpace();
00757 
00758       // Check that we do not have any extra characters on the end of the
00759       // strings
00760       len = fullName.length();
00761       if (fullName[0]=='"' && fullName[len-1]=='"')
00762         fullName = fullName.mid(1, len-2);
00763       else if (fullName[0]=='<' && fullName[len-1]=='>')
00764         fullName = fullName.mid(1, len-2);
00765       else if (fullName[0]=='(' && fullName[len-1]==')')
00766         fullName = fullName.mid(1, len-2);
00767     }
00768   }
00769 }
00770 
00771 void Addressee::setResource( Resource *resource )
00772 {
00773     detach();
00774     mData->resource = resource;
00775 } 
00776 
00777 Resource *Addressee::resource() const
00778 {
00779     return mData->resource;
00780 }
00781 
00782 void Addressee::setChanged( bool value )
00783 {
00784     detach();
00785     mData->changed = value;
00786 }
00787 
00788 bool Addressee::changed() const
00789 {
00790     return mData->changed;
00791 }
00792 
00793 QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a )
00794 {
00795   if (!a.mData) return s;
00796 
00797   --STREAMOUT--
00798   s << a.mData->phoneNumbers;
00799   s << a.mData->addresses;
00800   s << a.mData->emails;
00801   s << a.mData->categories;
00802   s << a.mData->custom;
00803   s << a.mData->keys;
00804   return s;
00805 }
00806 
00807 QDataStream &KABC::operator>>( QDataStream &s, Addressee &a )
00808 {
00809   if (!a.mData) return s;
00810 
00811   --STREAMIN--
00812   s >> a.mData->phoneNumbers;
00813   s >> a.mData->addresses;
00814   s >> a.mData->emails;
00815   s >> a.mData->categories;
00816   s >> a.mData->custom;
00817   s >> a.mData->keys;
00818 
00819   a.mData->empty = false;
00820 
00821   return s;
00822 }
00823 
00824 bool matchBinaryPattern( int value, int pattern, int max )
00825 {
00826   if ( pattern == 0 ) {
00827     if ( value != 0 )
00828       return false;
00829     else
00830       return true;
00831   }
00832 
00833   int counter = 0;
00834   while ( 1 ) {
00835     if ( ( pattern & ( 1 << counter ) ) && !( value & ( 1 << counter ) ) )
00836       return false;
00837 
00838     if ( ( 1 << counter ) == max )
00839       break;
00840 
00841     counter++;
00842   }
00843 
00844   return true;
00845 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:22:07 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001