summaryrefslogtreecommitdiffabout
path: root/kabc/agent.cpp
authorzautrix <zautrix>2004-06-26 19:01:18 (UTC)
committer zautrix <zautrix>2004-06-26 19:01:18 (UTC)
commitb9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff)
tree2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /kabc/agent.cpp
downloadkdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2
Initial revision
Diffstat (limited to 'kabc/agent.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/agent.cpp155
1 files changed, 155 insertions, 0 deletions
diff --git a/kabc/agent.cpp b/kabc/agent.cpp
new file mode 100644
index 0000000..ef26cbf
--- a/dev/null
+++ b/kabc/agent.cpp
@@ -0,0 +1,155 @@
1/*
2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/*
22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk
24
25$Id$
26*/
27
28#include "addressee.h"
29
30#include "agent.h"
31
32using namespace KABC;
33
34Agent::Agent()
35 : mAddressee( 0 ), mIntern( false )
36{
37}
38
39Agent::Agent( const QString &url )
40 : mAddressee( 0 ),mUrl( url ), mIntern( false )
41{
42}
43
44Agent::Agent( Addressee *addressee )
45 : mAddressee( addressee ), mIntern( true )
46{
47}
48
49Agent::~Agent()
50{
51 delete mAddressee;
52 mAddressee = 0;
53}
54
55bool Agent::operator==( const Agent &a ) const
56{
57 if ( mIntern != a.mIntern )
58 return false;
59
60 if ( !mIntern ) {
61 if ( mUrl != a.mUrl )
62 return false;
63 } else {
64 if ( mAddressee && !a.mAddressee ) return false;
65 if ( !mAddressee && a.mAddressee ) return false;
66 if ( !mAddressee && !a.mAddressee ) return false;
67 if ( (*mAddressee) != (*a.mAddressee) ) return false;
68 }
69
70 return true;
71}
72
73bool Agent::operator!=( const Agent &a ) const
74{
75 return !( a == *this );
76}
77
78Agent &Agent::operator=( const Agent &addr )
79{
80 if ( this == &addr )
81 return *this;
82
83 if ( addr.mIntern && addr.mAddressee ) {
84 if ( mAddressee )
85 delete mAddressee;
86
87 mAddressee = new Addressee;
88 *mAddressee = *(addr.mAddressee);
89 }
90
91 mUrl = addr.mUrl;
92 mIntern = addr.mIntern;
93
94 return *this;
95}
96
97void Agent::setUrl( const QString &url )
98{
99 mUrl = url;
100 mIntern = false;
101}
102
103void Agent::setAddressee( Addressee *addressee )
104{
105 mAddressee = addressee;
106 mIntern = true;
107}
108
109bool Agent::isIntern() const
110{
111 return mIntern;
112}
113
114QString Agent::url() const
115{
116 return mUrl;
117}
118
119Addressee *Agent::addressee() const
120{
121 return mAddressee;
122}
123
124QString Agent::asString() const
125{
126 if ( mIntern )
127 return "intern agent";
128 else
129 return mUrl;
130}
131
132QDataStream &KABC::operator<<( QDataStream &s, const Agent &agent )
133{
134 Q_UINT32 hasAddressee = ( agent.mAddressee != 0 );
135
136 s << agent.mIntern << agent.mUrl << hasAddressee;
137 if ( hasAddressee )
138 s << (*agent.mAddressee);
139
140 return s;
141}
142
143QDataStream &KABC::operator>>( QDataStream &s, Agent &agent )
144{
145 Q_UINT32 hasAddressee;
146
147 s >> agent.mIntern >> agent.mUrl >> hasAddressee;
148
149 if ( hasAddressee ) {
150 agent.mAddressee = new Addressee;
151 s >> (*agent.mAddressee);
152 }
153
154 return s;
155}