-rw-r--r-- | kabc/agent.cpp | 155 |
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 | /* | ||
22 | Enhanced Version of the file for platform independent KDE tools. | ||
23 | Copyright (c) 2004 Ulf Schenk | ||
24 | |||
25 | $Id$ | ||
26 | */ | ||
27 | |||
28 | #include "addressee.h" | ||
29 | |||
30 | #include "agent.h" | ||
31 | |||
32 | using namespace KABC; | ||
33 | |||
34 | Agent::Agent() | ||
35 | : mAddressee( 0 ), mIntern( false ) | ||
36 | { | ||
37 | } | ||
38 | |||
39 | Agent::Agent( const QString &url ) | ||
40 | : mAddressee( 0 ),mUrl( url ), mIntern( false ) | ||
41 | { | ||
42 | } | ||
43 | |||
44 | Agent::Agent( Addressee *addressee ) | ||
45 | : mAddressee( addressee ), mIntern( true ) | ||
46 | { | ||
47 | } | ||
48 | |||
49 | Agent::~Agent() | ||
50 | { | ||
51 | delete mAddressee; | ||
52 | mAddressee = 0; | ||
53 | } | ||
54 | |||
55 | bool 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 | |||
73 | bool Agent::operator!=( const Agent &a ) const | ||
74 | { | ||
75 | return !( a == *this ); | ||
76 | } | ||
77 | |||
78 | Agent &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 | |||
97 | void Agent::setUrl( const QString &url ) | ||
98 | { | ||
99 | mUrl = url; | ||
100 | mIntern = false; | ||
101 | } | ||
102 | |||
103 | void Agent::setAddressee( Addressee *addressee ) | ||
104 | { | ||
105 | mAddressee = addressee; | ||
106 | mIntern = true; | ||
107 | } | ||
108 | |||
109 | bool Agent::isIntern() const | ||
110 | { | ||
111 | return mIntern; | ||
112 | } | ||
113 | |||
114 | QString Agent::url() const | ||
115 | { | ||
116 | return mUrl; | ||
117 | } | ||
118 | |||
119 | Addressee *Agent::addressee() const | ||
120 | { | ||
121 | return mAddressee; | ||
122 | } | ||
123 | |||
124 | QString Agent::asString() const | ||
125 | { | ||
126 | if ( mIntern ) | ||
127 | return "intern agent"; | ||
128 | else | ||
129 | return mUrl; | ||
130 | } | ||
131 | |||
132 | QDataStream &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 | |||
143 | QDataStream &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 | } | ||