| # kabc Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# agent.cpp

    00001 /*
    00002     This file is part of libkabc.
    00003     Copyright (c) 2002 Tobias Koenig <tokoe@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
    00021 #include "addressee.h"
    00022
    00023 #include "agent.h"
    00024
    00025 using namespace KABC;
    00026
    00027 Agent::Agent()
    00028   : mAddressee( 0 ), mIntern( false )
    00029 {
    00030 }
    00031
    00032 Agent::Agent( const QString &url )
    00033   : mAddressee( 0 ),mUrl( url ), mIntern( false )
    00034 {
    00035 }
    00036
    00037 Agent::Agent( Addressee *addressee )
    00038   : mAddressee( addressee ), mIntern( true )
    00039 {
    00040 }
    00041
    00042 Agent::~Agent()
    00043 {
    00044   delete mAddressee;
    00045   mAddressee = 0;
    00046 }
    00047
    00048 bool Agent::operator==( const Agent &a ) const
    00049 {
    00050   if ( mIntern != a.mIntern )
    00051     return false;
    00052
    00053   if ( !mIntern ) {
    00054     if ( mUrl != a.mUrl )
    00055       return false;
    00056   } else {
    00057     if ( mAddressee && !a.mAddressee ) return false;
    00058     if ( !mAddressee && a.mAddressee ) return false;
    00059     if ( !mAddressee && !a.mAddressee ) return false;
    00060     if ( (*mAddressee) != (*a.mAddressee) ) return false;
    00061   }
    00062
    00063   return true;
    00064 }
    00065
    00066 bool Agent::operator!=( const Agent &a ) const
    00067 {
    00068   return !( a == *this );
    00069 }
    00070
    00071 Agent &Agent::operator=(  const Agent &addr )
    00072 {
    00073   if ( this == &addr )
    00074     return *this;
    00075
    00076   if ( addr.mIntern && addr.mAddressee ) {
    00077     if ( mAddressee )
    00078       delete mAddressee;
    00079
    00080     mAddressee = new Addressee;
    00081     *mAddressee = *(addr.mAddressee);
    00082   }
    00083
    00084   mUrl = addr.mUrl;
    00085   mIntern = addr.mIntern;
    00086
    00087   return *this;
    00088 }
    00089
    00090 void Agent::setUrl( const QString &url )
    00091 {
    00092   mUrl = url;
    00093   mIntern = false;
    00094 }
    00095
    00096 void Agent::setAddressee( Addressee *addressee )
    00097 {
    00098   mAddressee = addressee;
    00099   mIntern = true;
    00100 }
    00101
    00102 bool Agent::isIntern() const
    00103 {
    00104   return mIntern;
    00105 }
    00106
    00107 QString Agent::url() const
    00108 {
    00109   return mUrl;
    00110 }
    00111
    00112 Addressee *Agent::addressee() const
    00113 {
    00114   return mAddressee;
    00115 }
    00116
    00117 QString Agent::asString() const
    00118 {
    00119   if ( mIntern )
    00120     return "intern agent";
    00121   else
    00122     return mUrl;
    00123 }
    00124
    00125 QDataStream &KABC::operator<<( QDataStream &s, const Agent &agent )
    00126 {
    00127   Q_UINT32 hasAddressee = ( agent.mAddressee != 0 );
    00128
    00129   s << agent.mIntern << agent.mUrl << hasAddressee;
    00130   if ( hasAddressee )
    00131     s << (*agent.mAddressee);
    00132
    00133   return s;
    00134 }
    00135
    00136 QDataStream &KABC::operator>>( QDataStream &s, Agent &agent )
    00137 {
    00138   Q_UINT32 hasAddressee;
    00139
    00140   s >> agent.mIntern >> agent.mUrl >> hasAddressee;
    00141
    00142   if ( hasAddressee ) {
    00143     agent.mAddressee = new Addressee;
    00144     s >> (*agent.mAddressee);
    00145   }
    00146
    00147   return s;
    00148 }

This file is part of the documentation for kabc Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:31:29 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003