-rw-r--r-- | kabc/distributionlist.cpp | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/kabc/distributionlist.cpp b/kabc/distributionlist.cpp index aa2725d..45b9dda 100644 --- a/kabc/distributionlist.cpp +++ b/kabc/distributionlist.cpp | |||
@@ -70,224 +70,220 @@ void DistributionList::insertEntry( const Addressee &a, const QString &email ) | |||
70 | mEntries.append( e ); | 70 | mEntries.append( e ); |
71 | } | 71 | } |
72 | 72 | ||
73 | void DistributionList::removeEntry( const Addressee &a, const QString &email ) | 73 | void DistributionList::removeEntry( const Addressee &a, const QString &email ) |
74 | { | 74 | { |
75 | QValueList<Entry>::Iterator it; | 75 | QValueList<Entry>::Iterator it; |
76 | for( it = mEntries.begin(); it != mEntries.end(); ++it ) { | 76 | for( it = mEntries.begin(); it != mEntries.end(); ++it ) { |
77 | if ( (*it).addressee.uid() == a.uid() && (*it).email == email ) { | 77 | if ( (*it).addressee.uid() == a.uid() && (*it).email == email ) { |
78 | mEntries.remove( it ); | 78 | mEntries.remove( it ); |
79 | return; | 79 | return; |
80 | } | 80 | } |
81 | } | 81 | } |
82 | } | 82 | } |
83 | 83 | ||
84 | QStringList DistributionList::emails() const | 84 | QStringList DistributionList::emails() const |
85 | { | 85 | { |
86 | QStringList emails; | 86 | QStringList emails; |
87 | 87 | ||
88 | Entry::List::ConstIterator it; | 88 | Entry::List::ConstIterator it; |
89 | for( it = mEntries.begin(); it != mEntries.end(); ++it ) { | 89 | for( it = mEntries.begin(); it != mEntries.end(); ++it ) { |
90 | Addressee a = (*it).addressee; | 90 | Addressee a = (*it).addressee; |
91 | QString email = (*it).email.isEmpty() ? a.fullEmail() : | 91 | QString email = (*it).email.isEmpty() ? a.fullEmail() : |
92 | a.fullEmail( (*it).email ); | 92 | a.fullEmail( (*it).email ); |
93 | 93 | ||
94 | if ( !email.isEmpty() ) { | 94 | if ( !email.isEmpty() ) { |
95 | emails.append( email ); | 95 | emails.append( email ); |
96 | } | 96 | } |
97 | } | 97 | } |
98 | 98 | ||
99 | return emails; | 99 | return emails; |
100 | } | 100 | } |
101 | 101 | ||
102 | DistributionList::Entry::List DistributionList::entries() const | 102 | DistributionList::Entry::List DistributionList::entries() const |
103 | { | 103 | { |
104 | return mEntries; | 104 | return mEntries; |
105 | } | 105 | } |
106 | 106 | ||
107 | 107 | ||
108 | DistributionListManager::DistributionListManager( AddressBook *ab ) : | 108 | DistributionListManager::DistributionListManager( AddressBook *ab ) : |
109 | mAddressBook( ab ) | 109 | mAddressBook( ab ) |
110 | { | 110 | { |
111 | } | 111 | } |
112 | 112 | ||
113 | DistributionListManager::~DistributionListManager() | 113 | DistributionListManager::~DistributionListManager() |
114 | { | 114 | { |
115 | } | 115 | } |
116 | 116 | ||
117 | DistributionList *DistributionListManager::list( const QString &name ) | 117 | DistributionList *DistributionListManager::list( const QString &name ) |
118 | { | 118 | { |
119 | DistributionList *list; | 119 | DistributionList *list; |
120 | for( list = mLists.first(); list; list = mLists.next() ) { | 120 | for( list = mLists.first(); list; list = mLists.next() ) { |
121 | if ( list->name() == name ) return list; | 121 | if ( list->name() == name ) return list; |
122 | } | 122 | } |
123 | 123 | ||
124 | return 0; | 124 | return 0; |
125 | } | 125 | } |
126 | 126 | ||
127 | void DistributionListManager::insert( DistributionList *l ) | 127 | void DistributionListManager::insert( DistributionList *l ) |
128 | { | 128 | { |
129 | DistributionList *list; | 129 | DistributionList *list; |
130 | for( list = mLists.first(); list; list = mLists.next() ) { | 130 | for( list = mLists.first(); list; list = mLists.next() ) { |
131 | if ( list->name() == l->name() ) { | 131 | if ( list->name() == l->name() ) { |
132 | mLists.remove( list ); | 132 | mLists.remove( list ); |
133 | break; | 133 | break; |
134 | } | 134 | } |
135 | } | 135 | } |
136 | mLists.append( l ); | 136 | mLists.append( l ); |
137 | } | 137 | } |
138 | 138 | ||
139 | void DistributionListManager::remove( DistributionList *l ) | 139 | void DistributionListManager::remove( DistributionList *l ) |
140 | { | 140 | { |
141 | DistributionList *list; | 141 | DistributionList *list; |
142 | for( list = mLists.first(); list; list = mLists.next() ) { | 142 | for( list = mLists.first(); list; list = mLists.next() ) { |
143 | if ( list->name() == l->name() ) { | 143 | if ( list->name() == l->name() ) { |
144 | mLists.remove( list ); | 144 | mLists.remove( list ); |
145 | return; | 145 | return; |
146 | } | 146 | } |
147 | } | 147 | } |
148 | } | 148 | } |
149 | 149 | ||
150 | QStringList DistributionListManager::listNames() | 150 | QStringList DistributionListManager::listNames() |
151 | { | 151 | { |
152 | QStringList names; | 152 | QStringList names; |
153 | 153 | ||
154 | DistributionList *list; | 154 | DistributionList *list; |
155 | for( list = mLists.first(); list; list = mLists.next() ) { | 155 | for( list = mLists.first(); list; list = mLists.next() ) { |
156 | names.append( list->name() ); | 156 | names.append( list->name() ); |
157 | } | 157 | } |
158 | 158 | ||
159 | return names; | 159 | return names; |
160 | } | 160 | } |
161 | 161 | ||
162 | bool DistributionListManager::load() | 162 | bool DistributionListManager::load() |
163 | { | 163 | { |
164 | KSimpleConfig cfg( locateLocal( "data", "kabc/distlists" ) ); | 164 | KSimpleConfig cfg( locateLocal( "data", "kabc/distlists" ) ); |
165 | 165 | ||
166 | #ifndef KAB_EMBEDDED | 166 | /*US |
167 | |||
168 | QMap<QString,QString> entryMap = cfg.entryMap( mAddressBook->identifier() ); | 167 | QMap<QString,QString> entryMap = cfg.entryMap( mAddressBook->identifier() ); |
169 | if ( entryMap.isEmpty() ) { | 168 | if ( entryMap.isEmpty() ) { |
170 | kdDebug(5700) << "No distlists for '" << mAddressBook->identifier() << "'" << endl; | 169 | kdDebug(5700) << "No distlists for '" << mAddressBook->identifier() << "'" << endl; |
171 | return false; | 170 | return false; |
172 | } | 171 | } |
173 | 172 | ||
174 | cfg.setGroup( mAddressBook->identifier() ); | 173 | cfg.setGroup( mAddressBook->identifier() ); |
175 | 174 | ||
176 | QMap<QString,QString>::ConstIterator it; | 175 | QMap<QString,QString>::ConstIterator it; |
177 | for( it = entryMap.begin(); it != entryMap.end(); ++it ) { | 176 | for( it = entryMap.begin(); it != entryMap.end(); ++it ) { |
178 | QString name = it.key(); | 177 | QString name = it.key(); |
179 | 178 | */ | |
180 | #else //KAB_EMBEDDED | ||
181 | cfg.setGroup( mAddressBook->identifier() ); | 179 | cfg.setGroup( mAddressBook->identifier() ); |
182 | //US we work in microkde with a list of distributionlists | 180 | //US we work in microkde with a list of distributionlists |
183 | QStringList distlists = cfg.readListEntry( "Lists" ); | 181 | QStringList distlists = cfg.readListEntry( "Lists" ); |
184 | if ( distlists.isEmpty() ) { | 182 | if ( distlists.isEmpty() ) { |
185 | kdDebug(5700) << "No distlists for '" << mAddressBook->identifier() << "'" << endl; | 183 | kdDebug(5700) << "No distlists for '" << mAddressBook->identifier() << "'" << endl; |
186 | return false; | 184 | return false; |
187 | } | 185 | } |
188 | 186 | ||
189 | QStringList::ConstIterator it; | 187 | QStringList::ConstIterator it; |
190 | for( it = distlists.begin(); it != distlists.end(); ++it ) { | 188 | for( it = distlists.begin(); it != distlists.end(); ++it ) { |
191 | QString name = *it; | 189 | QString name = *it; |
192 | 190 | ||
193 | #endif //KAB_EMBEDDED | ||
194 | 191 | ||
195 | QStringList value = cfg.readListEntry( name ); | 192 | QStringList value = cfg.readListEntry( name ); |
196 | 193 | ||
197 | kdDebug(5700) << "DLM::load(): " << name << ": " << value.join(",") << endl; | 194 | kdDebug(5700) << "DLM::load(): " << name << ": " << value.join(",") << endl; |
198 | 195 | ||
199 | DistributionList *list = new DistributionList( this, name ); | 196 | DistributionList *list = new DistributionList( this, name ); |
200 | 197 | ||
201 | QStringList::ConstIterator it2 = value.begin(); | 198 | QStringList::ConstIterator it2 = value.begin(); |
202 | while( it2 != value.end() ) { | 199 | while( it2 != value.end() ) { |
203 | QString id = *it2++; | 200 | QString id = *it2++; |
204 | QString email = *it2; | 201 | QString email = *it2; |
205 | 202 | ||
206 | kdDebug(5700) << "----- Entry " << id << endl; | 203 | kdDebug(5700) << "----- Entry " << id << endl; |
207 | 204 | ||
208 | Addressee a = mAddressBook->findByUid( id ); | 205 | Addressee a = mAddressBook->findByUid( id ); |
209 | if ( !a.isEmpty() ) { | 206 | if ( !a.isEmpty() ) { |
210 | list->insertEntry( a, email ); | 207 | list->insertEntry( a, email ); |
211 | } | 208 | } |
212 | 209 | ||
213 | if ( it2 == value.end() ) break; | 210 | if ( it2 == value.end() ) break; |
214 | ++it2; | 211 | ++it2; |
215 | } | 212 | } |
216 | } | 213 | } |
217 | 214 | ||
218 | return true; | 215 | return true; |
219 | } | 216 | } |
220 | 217 | ||
221 | bool DistributionListManager::save() | 218 | bool DistributionListManager::save() |
222 | { | 219 | { |
223 | kdDebug(5700) << "DistListManager::save()" << endl; | 220 | kdDebug(5700) << "DistListManager::save()" << endl; |
224 | 221 | ||
225 | KSimpleConfig cfg( locateLocal( "data", "kabc/distlists" ) ); | 222 | KSimpleConfig cfg( locateLocal( "data", "kabc/distlists" ) ); |
226 | 223 | ||
227 | cfg.deleteGroup( mAddressBook->identifier() ); | 224 | cfg.deleteGroup( mAddressBook->identifier() ); |
228 | cfg.setGroup( mAddressBook->identifier() ); | 225 | cfg.setGroup( mAddressBook->identifier() ); |
229 | 226 | ||
230 | DistributionList *list; | 227 | DistributionList *list; |
231 | for( list = mLists.first(); list; list = mLists.next() ) { | 228 | for( list = mLists.first(); list; list = mLists.next() ) { |
232 | kdDebug(5700) << " Saving '" << list->name() << "'" << endl; | 229 | kdDebug(5700) << " Saving '" << list->name() << "'" << endl; |
233 | QStringList value; | 230 | QStringList value; |
234 | DistributionList::Entry::List entries = list->entries(); | 231 | DistributionList::Entry::List entries = list->entries(); |
235 | DistributionList::Entry::List::ConstIterator it; | 232 | DistributionList::Entry::List::ConstIterator it; |
236 | for( it = entries.begin(); it != entries.end(); ++it ) { | 233 | for( it = entries.begin(); it != entries.end(); ++it ) { |
237 | value.append( (*it).addressee.uid() ); | 234 | value.append( (*it).addressee.uid() ); |
238 | value.append( (*it).email ); | 235 | value.append( (*it).email ); |
239 | } | 236 | } |
240 | cfg.writeEntry( list->name(), value ); | 237 | cfg.writeEntry( list->name(), value ); |
241 | } | 238 | } |
242 | 239 | ||
243 | #ifdef KAB_EMBEDDED | ||
244 | //US for microKDE we have not yet sophisticated methods to load maps. | 240 | //US for microKDE we have not yet sophisticated methods to load maps. |
245 | // Because of that we store also a list of all distributionlists. | 241 | // Because of that we store also a list of all distributionlists. |
246 | QStringList namelist; | 242 | QStringList namelist; |
247 | for( list = mLists.first(); list; list = mLists.next() ) { | 243 | for( list = mLists.first(); list; list = mLists.next() ) { |
248 | namelist.append( list->name() ); | 244 | namelist.append( list->name() ); |
249 | } | 245 | } |
250 | cfg.writeEntry( "Lists", namelist ); | 246 | cfg.writeEntry( "Lists", namelist ); |
251 | 247 | ||
252 | #endif //KAB_EMBEDDED | 248 | |
253 | 249 | ||
250 | |||
251 | |||
252 | |||
254 | cfg.sync(); | 253 | cfg.sync(); |
255 | 254 | ||
256 | return true; | 255 | return true; |
257 | } | 256 | } |
258 | 257 | ||
259 | DistributionListWatcher* DistributionListWatcher::mSelf = 0; | 258 | DistributionListWatcher* DistributionListWatcher::mSelf = 0; |
260 | 259 | ||
261 | DistributionListWatcher::DistributionListWatcher() | 260 | DistributionListWatcher::DistributionListWatcher() |
262 | : QObject( 0, "DistributionListWatcher" ) | 261 | : QObject( 0, "DistributionListWatcher" ) |
263 | { | 262 | { |
264 | #ifndef KAB_EMBEDDED | 263 | /*US |
265 | mDirWatch = new KDirWatch; | 264 | mDirWatch = new KDirWatch; |
266 | mDirWatch->addFile( locateLocal( "data", "kabc/distlists" ) ); | 265 | mDirWatch->addFile( locateLocal( "data", "kabc/distlists" ) ); |
267 | 266 | ||
268 | connect( mDirWatch, SIGNAL( dirty( const QString& ) ), SIGNAL( changed() ) ); | 267 | connect( mDirWatch, SIGNAL( dirty( const QString& ) ), SIGNAL( changed() ) ); |
269 | mDirWatch->startScan(); | 268 | mDirWatch->startScan(); |
270 | #endif //KAB_EMBEDDED | 269 | */ |
271 | } | 270 | } |
272 | 271 | ||
273 | DistributionListWatcher::~DistributionListWatcher() | 272 | DistributionListWatcher::~DistributionListWatcher() |
274 | { | 273 | { |
275 | #ifndef KAB_EMBEDDED | 274 | /*US |
276 | delete mDirWatch; | 275 | delete mDirWatch; |
277 | mDirWatch = 0; | 276 | mDirWatch = 0; |
278 | #endif //KAB_EMBEDDED | 277 | */ |
279 | } | 278 | } |
280 | 279 | ||
281 | DistributionListWatcher *DistributionListWatcher::self() | 280 | DistributionListWatcher *DistributionListWatcher::self() |
282 | { | 281 | { |
283 | if ( !mSelf ) | 282 | if ( !mSelf ) |
284 | mSelf = new DistributionListWatcher(); | 283 | mSelf = new DistributionListWatcher(); |
285 | 284 | ||
286 | return mSelf; | 285 | return mSelf; |
287 | } | 286 | } |
288 | 287 | ||
289 | 288 | //US #include "distributionlist.moc" | |
290 | #ifndef KAB_EMBEDDED | ||
291 | #include "distributionlist.moc" | ||
292 | #endif //KAB_EMBEDDED | ||
293 | 289 | ||