author | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-07-04 11:23:42 (UTC) |
commit | a08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff) | |
tree | 8ee90d686081c52e7c69b5ce946e9b1a7d690001 /kabc/distributionlist.cpp | |
parent | 11edc920afe4f274c0964436633aa632c8288a40 (diff) | |
download | kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.zip kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.gz kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.bz2 |
initial public commit of qt4 portp1
-rw-r--r-- | kabc/distributionlist.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/kabc/distributionlist.cpp b/kabc/distributionlist.cpp index d34ba0b..cf5afa6 100644 --- a/kabc/distributionlist.cpp +++ b/kabc/distributionlist.cpp | |||
@@ -1,269 +1,271 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 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 | 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, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <ksimpleconfig.h> | 21 | #include <ksimpleconfig.h> |
22 | #include <kstandarddirs.h> | 22 | #include <kstandarddirs.h> |
23 | #include <kdebug.h> | 23 | #include <kdebug.h> |
24 | 24 | ||
25 | #include "distributionlist.h" | 25 | #include "distributionlist.h" |
26 | //Added by qt3to4: | ||
27 | #include <Q3ValueList> | ||
26 | 28 | ||
27 | using namespace KABC; | 29 | using namespace KABC; |
28 | 30 | ||
29 | DistributionList::DistributionList( DistributionListManager *manager, | 31 | DistributionList::DistributionList( DistributionListManager *manager, |
30 | const QString &name ) : | 32 | const QString &name ) : |
31 | mManager( manager ), mName( name ) | 33 | mManager( manager ), mName( name ) |
32 | { | 34 | { |
33 | mManager->insert( this ); | 35 | mManager->insert( this ); |
34 | } | 36 | } |
35 | 37 | ||
36 | DistributionList::~DistributionList() | 38 | DistributionList::~DistributionList() |
37 | { | 39 | { |
38 | mManager->remove( this ); | 40 | mManager->remove( this ); |
39 | } | 41 | } |
40 | 42 | ||
41 | void DistributionList::setName( const QString &name ) | 43 | void DistributionList::setName( const QString &name ) |
42 | { | 44 | { |
43 | mName = name; | 45 | mName = name; |
44 | } | 46 | } |
45 | 47 | ||
46 | QString DistributionList::name() const | 48 | QString DistributionList::name() const |
47 | { | 49 | { |
48 | return mName; | 50 | return mName; |
49 | } | 51 | } |
50 | 52 | ||
51 | void DistributionList::insertEntry( const Addressee &a, const QString &email ) | 53 | void DistributionList::insertEntry( const Addressee &a, const QString &email ) |
52 | { | 54 | { |
53 | QString em = email; | 55 | QString em = email; |
54 | if (em.isNull() ) | 56 | if (em.isNull() ) |
55 | em = a.preferredEmail(); | 57 | em = a.preferredEmail(); |
56 | Entry e( a, em ); | 58 | Entry e( a, em ); |
57 | QValueList<Entry>::Iterator it; | 59 | Q3ValueList<Entry>::Iterator it; |
58 | for( it = mEntries.begin(); it != mEntries.end(); ++it ) { | 60 | for( it = mEntries.begin(); it != mEntries.end(); ++it ) { |
59 | if ( (*it).addressee.uid() == a.uid() ) { | 61 | if ( (*it).addressee.uid() == a.uid() ) { |
60 | /** | 62 | /** |
61 | We have to check if both email addresses contains no data, | 63 | We have to check if both email addresses contains no data, |
62 | a simple 'email1 == email2' wont work here | 64 | a simple 'email1 == email2' wont work here |
63 | */ | 65 | */ |
64 | if ( ( (*it).email.isNull() && em.isEmpty() ) || | 66 | if ( ( (*it).email.isNull() && em.isEmpty() ) || |
65 | ( (*it).email.isEmpty() && em.isNull() ) || | 67 | ( (*it).email.isEmpty() && em.isNull() ) || |
66 | ( (*it).email == em ) ) { | 68 | ( (*it).email == em ) ) { |
67 | //*it = e; | 69 | //*it = e; |
68 | return; | 70 | return; |
69 | } | 71 | } |
70 | } | 72 | } |
71 | } | 73 | } |
72 | mEntries.append( e ); | 74 | mEntries.append( e ); |
73 | } | 75 | } |
74 | 76 | ||
75 | void DistributionList::removeEntry( const Addressee &a, const QString &email ) | 77 | void DistributionList::removeEntry( const Addressee &a, const QString &email ) |
76 | { | 78 | { |
77 | QValueList<Entry>::Iterator it; | 79 | Q3ValueList<Entry>::Iterator it; |
78 | for( it = mEntries.begin(); it != mEntries.end(); ++it ) { | 80 | for( it = mEntries.begin(); it != mEntries.end(); ++it ) { |
79 | if ( (*it).addressee.uid() == a.uid() && (*it).email == email ) { | 81 | if ( (*it).addressee.uid() == a.uid() && (*it).email == email ) { |
80 | mEntries.remove( it ); | 82 | mEntries.remove( it ); |
81 | return; | 83 | return; |
82 | } | 84 | } |
83 | } | 85 | } |
84 | } | 86 | } |
85 | 87 | ||
86 | QStringList DistributionList::emails() const | 88 | QStringList DistributionList::emails() const |
87 | { | 89 | { |
88 | QStringList emails; | 90 | QStringList emails; |
89 | 91 | ||
90 | Entry::List::ConstIterator it; | 92 | Entry::List::ConstIterator it; |
91 | for( it = mEntries.begin(); it != mEntries.end(); ++it ) { | 93 | for( it = mEntries.begin(); it != mEntries.end(); ++it ) { |
92 | Addressee a = (*it).addressee; | 94 | Addressee a = (*it).addressee; |
93 | QString email = (*it).email.isEmpty() ? a.fullEmail() : | 95 | QString email = (*it).email.isEmpty() ? a.fullEmail() : |
94 | a.fullEmail( (*it).email ); | 96 | a.fullEmail( (*it).email ); |
95 | 97 | ||
96 | if ( !email.isEmpty() ) { | 98 | if ( !email.isEmpty() ) { |
97 | emails.append( email ); | 99 | emails.append( email ); |
98 | } | 100 | } |
99 | } | 101 | } |
100 | 102 | ||
101 | return emails; | 103 | return emails; |
102 | } | 104 | } |
103 | 105 | ||
104 | DistributionList::Entry::List DistributionList::entries() const | 106 | DistributionList::Entry::List DistributionList::entries() const |
105 | { | 107 | { |
106 | return mEntries; | 108 | return mEntries; |
107 | } | 109 | } |
108 | 110 | ||
109 | 111 | ||
110 | DistributionListManager::DistributionListManager( AddressBook *ab ) : | 112 | DistributionListManager::DistributionListManager( AddressBook *ab ) : |
111 | mAddressBook( ab ) | 113 | mAddressBook( ab ) |
112 | { | 114 | { |
113 | } | 115 | } |
114 | 116 | ||
115 | DistributionListManager::~DistributionListManager() | 117 | DistributionListManager::~DistributionListManager() |
116 | { | 118 | { |
117 | } | 119 | } |
118 | 120 | ||
119 | DistributionList *DistributionListManager::list( const QString &name ) | 121 | DistributionList *DistributionListManager::list( const QString &name ) |
120 | { | 122 | { |
121 | DistributionList *list; | 123 | DistributionList *list; |
122 | for( list = mLists.first(); list; list = mLists.next() ) { | 124 | for( list = mLists.first(); list; list = mLists.next() ) { |
123 | if ( list->name() == name ) return list; | 125 | if ( list->name() == name ) return list; |
124 | } | 126 | } |
125 | 127 | ||
126 | return 0; | 128 | return 0; |
127 | } | 129 | } |
128 | 130 | ||
129 | void DistributionListManager::insert( DistributionList *l ) | 131 | void DistributionListManager::insert( DistributionList *l ) |
130 | { | 132 | { |
131 | DistributionList *list; | 133 | DistributionList *list; |
132 | for( list = mLists.first(); list; list = mLists.next() ) { | 134 | for( list = mLists.first(); list; list = mLists.next() ) { |
133 | if ( list->name() == l->name() ) { | 135 | if ( list->name() == l->name() ) { |
134 | mLists.remove( list ); | 136 | mLists.remove( list ); |
135 | break; | 137 | break; |
136 | } | 138 | } |
137 | } | 139 | } |
138 | mLists.append( l ); | 140 | mLists.append( l ); |
139 | } | 141 | } |
140 | 142 | ||
141 | void DistributionListManager::remove( DistributionList *l ) | 143 | void DistributionListManager::remove( DistributionList *l ) |
142 | { | 144 | { |
143 | DistributionList *list; | 145 | DistributionList *list; |
144 | for( list = mLists.first(); list; list = mLists.next() ) { | 146 | for( list = mLists.first(); list; list = mLists.next() ) { |
145 | if ( list->name() == l->name() ) { | 147 | if ( list->name() == l->name() ) { |
146 | mLists.remove( list ); | 148 | mLists.remove( list ); |
147 | return; | 149 | return; |
148 | } | 150 | } |
149 | } | 151 | } |
150 | } | 152 | } |
151 | 153 | ||
152 | QStringList DistributionListManager::listNames() | 154 | QStringList DistributionListManager::listNames() |
153 | { | 155 | { |
154 | QStringList names; | 156 | QStringList names; |
155 | 157 | ||
156 | DistributionList *list; | 158 | DistributionList *list; |
157 | for( list = mLists.first(); list; list = mLists.next() ) { | 159 | for( list = mLists.first(); list; list = mLists.next() ) { |
158 | names.append( list->name() ); | 160 | names.append( list->name() ); |
159 | } | 161 | } |
160 | 162 | ||
161 | return names; | 163 | return names; |
162 | } | 164 | } |
163 | 165 | ||
164 | bool DistributionListManager::load() | 166 | bool DistributionListManager::load() |
165 | { | 167 | { |
166 | KSimpleConfig cfg( locateLocal( "data", "kabc/distlists" ) ); | 168 | KSimpleConfig cfg( locateLocal( "data", "kabc/distlists" ) ); |
167 | 169 | ||
168 | /*US | 170 | /*US |
169 | QMap<QString,QString> entryMap = cfg.entryMap( mAddressBook->identifier() ); | 171 | QMap<QString,QString> entryMap = cfg.entryMap( mAddressBook->identifier() ); |
170 | if ( entryMap.isEmpty() ) { | 172 | if ( entryMap.isEmpty() ) { |
171 | kdDebug(5700) << "No distlists for '" << mAddressBook->identifier() << "'" << endl; | 173 | kdDebug(5700) << "No distlists for '" << mAddressBook->identifier() << "'" << endl; |
172 | return false; | 174 | return false; |
173 | } | 175 | } |
174 | 176 | ||
175 | cfg.setGroup( mAddressBook->identifier() ); | 177 | cfg.setGroup( mAddressBook->identifier() ); |
176 | 178 | ||
177 | QMap<QString,QString>::ConstIterator it; | 179 | QMap<QString,QString>::ConstIterator it; |
178 | for( it = entryMap.begin(); it != entryMap.end(); ++it ) { | 180 | for( it = entryMap.begin(); it != entryMap.end(); ++it ) { |
179 | QString name = it.key(); | 181 | QString name = it.key(); |
180 | */ | 182 | */ |
181 | cfg.setGroup( mAddressBook->identifier() ); | 183 | cfg.setGroup( mAddressBook->identifier() ); |
182 | //US we work in microkde with a list of distributionlists | 184 | //US we work in microkde with a list of distributionlists |
183 | QStringList distlists = cfg.readListEntry( "__Lists__List__" ); | 185 | QStringList distlists = cfg.readListEntry( "__Lists__List__" ); |
184 | if ( distlists.isEmpty() ) { | 186 | if ( distlists.isEmpty() ) { |
185 | qDebug("no distlist for AB "); | 187 | qDebug("no distlist for AB "); |
186 | return false; | 188 | return false; |
187 | } | 189 | } |
188 | 190 | ||
189 | QStringList::ConstIterator it; | 191 | QStringList::ConstIterator it; |
190 | for( it = distlists.begin(); it != distlists.end(); ++it ) { | 192 | for( it = distlists.begin(); it != distlists.end(); ++it ) { |
191 | QString name = *it; | 193 | QString name = *it; |
192 | 194 | ||
193 | 195 | ||
194 | QStringList value = cfg.readListEntry( name ); | 196 | QStringList value = cfg.readListEntry( name ); |
195 | 197 | ||
196 | 198 | ||
197 | 199 | ||
198 | DistributionList *list = new DistributionList( this, name ); | 200 | DistributionList *list = new DistributionList( this, name ); |
199 | 201 | ||
200 | QStringList::ConstIterator it2 = value.begin(); | 202 | QStringList::ConstIterator it2 = value.begin(); |
201 | while( it2 != value.end() ) { | 203 | while( it2 != value.end() ) { |
202 | QString id = *it2++; | 204 | QString id = *it2++; |
203 | QString email = *it2; | 205 | QString email = *it2; |
204 | 206 | ||
205 | 207 | ||
206 | 208 | ||
207 | Addressee a = mAddressBook->findByUid( id ); | 209 | Addressee a = mAddressBook->findByUid( id ); |
208 | if ( !a.isEmpty() ) { | 210 | if ( !a.isEmpty() ) { |
209 | list->insertEntry( a, email ); | 211 | list->insertEntry( a, email ); |
210 | } | 212 | } |
211 | 213 | ||
212 | if ( it2 == value.end() ) break; | 214 | if ( it2 == value.end() ) break; |
213 | ++it2; | 215 | ++it2; |
214 | } | 216 | } |
215 | } | 217 | } |
216 | 218 | ||
217 | return true; | 219 | return true; |
218 | } | 220 | } |
219 | 221 | ||
220 | bool DistributionListManager::save() | 222 | bool DistributionListManager::save() |
221 | { | 223 | { |
222 | 224 | ||
223 | 225 | ||
224 | KSimpleConfig cfg( locateLocal( "data", "kabc/distlists" ) ); | 226 | KSimpleConfig cfg( locateLocal( "data", "kabc/distlists" ) ); |
225 | 227 | ||
226 | cfg.deleteGroup( mAddressBook->identifier() ); | 228 | cfg.deleteGroup( mAddressBook->identifier() ); |
227 | cfg.setGroup( mAddressBook->identifier() ); | 229 | cfg.setGroup( mAddressBook->identifier() ); |
228 | 230 | ||
229 | DistributionList *list; | 231 | DistributionList *list; |
230 | for( list = mLists.first(); list; list = mLists.next() ) { | 232 | for( list = mLists.first(); list; list = mLists.next() ) { |
231 | kdDebug(5700) << " Saving '" << list->name() << "'" << endl; | 233 | kdDebug(5700) << " Saving '" << list->name() << "'" << endl; |
232 | QStringList value; | 234 | QStringList value; |
233 | DistributionList::Entry::List entries = list->entries(); | 235 | DistributionList::Entry::List entries = list->entries(); |
234 | DistributionList::Entry::List::ConstIterator it; | 236 | DistributionList::Entry::List::ConstIterator it; |
235 | for( it = entries.begin(); it != entries.end(); ++it ) { | 237 | for( it = entries.begin(); it != entries.end(); ++it ) { |
236 | value.append( (*it).addressee.uid() ); | 238 | value.append( (*it).addressee.uid() ); |
237 | if (( *it).email.isEmpty()) | 239 | if (( *it).email.isEmpty()) |
238 | value.append( " " ); | 240 | value.append( " " ); |
239 | else | 241 | else |
240 | value.append( (*it).email ); | 242 | value.append( (*it).email ); |
241 | // qDebug("uid *%s* email *%s* ", (*it).addressee.uid().latin1(),(*it).email.latin1() ); | 243 | // qDebug("uid *%s* email *%s* ", (*it).addressee.uid().latin1(),(*it).email.latin1() ); |
242 | } | 244 | } |
243 | cfg.writeEntry( list->name(), value ); | 245 | cfg.writeEntry( list->name(), value ); |
244 | } | 246 | } |
245 | 247 | ||
246 | //US for microKDE we have not yet sophisticated methods to load maps. | 248 | //US for microKDE we have not yet sophisticated methods to load maps. |
247 | // Because of that we store also a list of all distributionlists. | 249 | // Because of that we store also a list of all distributionlists. |
248 | QStringList namelist; | 250 | QStringList namelist; |
249 | for( list = mLists.first(); list; list = mLists.next() ) { | 251 | for( list = mLists.first(); list; list = mLists.next() ) { |
250 | namelist.append( list->name() ); | 252 | namelist.append( list->name() ); |
251 | } | 253 | } |
252 | cfg.writeEntry( "__Lists__List__", namelist ); | 254 | cfg.writeEntry( "__Lists__List__", namelist ); |
253 | 255 | ||
254 | 256 | ||
255 | 257 | ||
256 | 258 | ||
257 | 259 | ||
258 | 260 | ||
259 | cfg.sync(); | 261 | cfg.sync(); |
260 | 262 | ||
261 | return true; | 263 | return true; |
262 | } | 264 | } |
263 | #if 0 | 265 | #if 0 |
264 | DistributionListWatcher* DistributionListWatcher::mSelf = 0; | 266 | DistributionListWatcher* DistributionListWatcher::mSelf = 0; |
265 | 267 | ||
266 | DistributionListWatcher::DistributionListWatcher() | 268 | DistributionListWatcher::DistributionListWatcher() |
267 | : QObject( 0, "DistributionListWatcher" ) | 269 | : QObject( 0, "DistributionListWatcher" ) |
268 | { | 270 | { |
269 | 271 | ||