• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.3 API Reference
  • KDE Home
  • Contact Us
 

kabc

  • kabc
resource.cpp
1 /*
2  This file is part of libkabc.
3  Copyright (c) 2001 Cornelius Schumacher <schumacher@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., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "resource.h"
22 
23 #include <kdebug.h>
24 #include <klocale.h>
25 
26 using namespace KABC;
27 
28 class Ticket::Private
29 {
30  public:
31  Private( Resource *resource )
32  : mResource( resource )
33  {
34  }
35 
36  Resource *mResource;
37 };
38 
39 Ticket::Ticket( Resource *resource )
40  : d( new Private( resource ) )
41 {
42 }
43 
44 Ticket::~Ticket()
45 {
46  delete d;
47 }
48 
49 Resource *Ticket::resource()
50 {
51  return d->mResource;
52 }
53 
54 class Resource::Iterator::Private
55 {
56  public:
57  Addressee::Map::Iterator mIt;
58 };
59 
60 class Resource::ConstIterator::Private
61 {
62  public:
63  Addressee::Map::ConstIterator mIt;
64 };
65 
66 Resource::Iterator::Iterator()
67  : d( new Private )
68 {
69 }
70 
71 Resource::Iterator::Iterator( const Resource::Iterator &other )
72  : d( new Private )
73 {
74  d->mIt = other.d->mIt;
75 }
76 
77 Resource::Iterator &Resource::Iterator::operator=( const Resource::Iterator &other )
78 {
79  if ( this != &other ) {
80  d->mIt = other.d->mIt;
81  }
82 
83  return *this;
84 }
85 
86 Resource::Iterator::~Iterator()
87 {
88  delete d;
89 }
90 
91 const Addressee &Resource::Iterator::operator*() const
92 {
93  return d->mIt.value();
94 }
95 
96 Addressee &Resource::Iterator::operator*()
97 {
98  return d->mIt.value();
99 }
100 
101 Resource::Iterator &Resource::Iterator::operator++()
102 {
103  (d->mIt)++;
104  return *this;
105 }
106 
107 Resource::Iterator &Resource::Iterator::operator++( int )
108 {
109  (d->mIt)++;
110  return *this;
111 }
112 
113 Resource::Iterator &Resource::Iterator::operator--()
114 {
115  (d->mIt)--;
116  return *this;
117 }
118 
119 Resource::Iterator &Resource::Iterator::operator--( int )
120 {
121  (d->mIt)--;
122  return *this;
123 }
124 
125 bool Resource::Iterator::operator==( const Iterator &it ) const
126 {
127  return d->mIt == it.d->mIt;
128 }
129 
130 bool Resource::Iterator::operator!=( const Iterator &it ) const
131 {
132  return d->mIt != it.d->mIt;
133 }
134 
135 Resource::ConstIterator::ConstIterator()
136  : d( new Private )
137 {
138 }
139 
140 Resource::ConstIterator::ConstIterator( const Resource::ConstIterator &other )
141  : d( new Private )
142 {
143  d->mIt = other.d->mIt;
144 }
145 
146 #ifndef QT_STRICT_ITERATORS
147 Resource::ConstIterator::ConstIterator( const Resource::Iterator &other )
148  : d( new Private )
149 {
150  d->mIt = other.d->mIt;
151 }
152 #endif
153 
154 Resource::ConstIterator &Resource::ConstIterator::operator=( const Resource::ConstIterator &other )
155 {
156  if ( this != &other ) {
157  d->mIt = other.d->mIt;
158  }
159 
160  return *this;
161 }
162 
163 Resource::ConstIterator::~ConstIterator()
164 {
165  delete d;
166 }
167 
168 const Addressee &Resource::ConstIterator::operator*() const
169 {
170  return *(d->mIt);
171 }
172 
173 Resource::ConstIterator &Resource::ConstIterator::operator++()
174 {
175  (d->mIt)++;
176  return *this;
177 }
178 
179 Resource::ConstIterator &Resource::ConstIterator::operator++( int )
180 {
181  (d->mIt)++;
182  return *this;
183 }
184 
185 Resource::ConstIterator &Resource::ConstIterator::operator--()
186 {
187  --(d->mIt);
188  return *this;
189 }
190 
191 Resource::ConstIterator &Resource::ConstIterator::operator--( int )
192 {
193  --(d->mIt);
194  return *this;
195 }
196 
197 bool Resource::ConstIterator::operator==( const ConstIterator &it ) const
198 {
199  return d->mIt == it.d->mIt;
200 }
201 
202 bool Resource::ConstIterator::operator!=( const ConstIterator &it ) const
203 {
204  return d->mIt != it.d->mIt;
205 }
206 
207 class Resource::Private
208 {
209  public:
210  Private()
211  : mAddressBook( 0 )
212  {
213  }
214 
215  AddressBook *mAddressBook;
216 };
217 
218 Resource::Resource()
219  : KRES::Resource(), d( new Private )
220 {
221 }
222 
223 Resource::Resource( const KConfigGroup &group )
224  : KRES::Resource( group ), d( new Private )
225 {
226 }
227 
228 Resource::~Resource()
229 {
230  clear();
231  delete d;
232 }
233 
234 Resource::Iterator Resource::begin()
235 {
236  Iterator it;
237  it.d->mIt = mAddrMap.begin();
238 
239  return it;
240 }
241 
242 Resource::ConstIterator Resource::begin() const
243 {
244  ConstIterator it;
245  it.d->mIt = mAddrMap.constBegin();
246  return it;
247 }
248 
249 Resource::Iterator Resource::end()
250 {
251  Iterator it;
252  it.d->mIt = mAddrMap.end();
253 
254  return it;
255 }
256 
257 Resource::ConstIterator Resource::end() const
258 {
259  ConstIterator it;
260  it.d->mIt = mAddrMap.constEnd();
261  return it;
262 }
263 
264 void Resource::writeConfig( KConfigGroup &group )
265 {
266  KRES::Resource::writeConfig( group );
267 }
268 
269 void Resource::setAddressBook( AddressBook *ab )
270 {
271  d->mAddressBook = ab;
272 }
273 
274 AddressBook *Resource::addressBook()
275 {
276  return d->mAddressBook;
277 }
278 
279 Ticket *Resource::createTicket( Resource *resource )
280 {
281  return new Ticket( resource );
282 }
283 
284 void Resource::insertAddressee( const Addressee &addr )
285 {
286  mAddrMap.insert( addr.uid(), addr );
287 }
288 
289 void Resource::removeAddressee( const Addressee &addr )
290 {
291  mAddrMap.remove( addr.uid() );
292 }
293 
294 Addressee Resource::findByUid( const QString &uid )
295 {
296  Addressee::Map::ConstIterator it = mAddrMap.constFind( uid );
297 
298  if ( it != mAddrMap.constEnd() ) {
299  return it.value();
300  }
301 
302  return Addressee();
303 }
304 
305 Addressee::List Resource::findByName( const QString &name ) // TODO: const
306 {
307  Addressee::List results;
308 
309  ConstIterator it;
310  for ( it = constBegin(); it != constEnd(); ++it ) {
311  if ( name == (*it).name() ) {
312  results.append( *it );
313  }
314  }
315 
316  return results;
317 }
318 
319 Addressee::List Resource::findByEmail( const QString &email ) // TODO: const
320 {
321  Addressee::List results;
322  const QString lowerEmail = email.toLower();
323 
324  ConstIterator it;
325  for ( it = constBegin(); it != constEnd(); ++it ) {
326  const QStringList mailList = (*it).emails();
327  for ( QStringList::ConstIterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
328  if ( lowerEmail == (*ite).toLower() ) {
329  results.append( *it );
330  }
331  }
332  }
333 
334  return results;
335 }
336 
337 Addressee::List Resource::findByCategory( const QString &category ) // TODO: const
338 {
339  Addressee::List results;
340 
341  ConstIterator it;
342  for ( it = constBegin(); it != constEnd(); ++it ) {
343  if ( (*it).hasCategory( category ) ) {
344  results.append( *it );
345  }
346  }
347 
348  return results;
349 }
350 
351 void Resource::clear()
352 {
353  mAddrMap.clear();
354 
355  // take a copy of mDistListMap, then clear it and finally qDeleteAll
356  // the copy to avoid problems with removeDistributionList() called by
357  // ~DistributionList().
358  DistributionListMap tempDistListMap( mDistListMap );
359  mDistListMap.clear();
360  qDeleteAll( tempDistListMap );
361 }
362 
363 void Resource::insertDistributionList( DistributionList *list )
364 {
365  Q_ASSERT( list );
366 
367  mDistListMap.insert( list->identifier(), list );
368 }
369 
370 void Resource::removeDistributionList( DistributionList *list )
371 {
372  Q_ASSERT( list );
373 
374  DistributionListMap::iterator it = mDistListMap.find( list->identifier() );
375  if ( it != mDistListMap.end() ) {
376  if ( it.value() == list ) {
377  mDistListMap.erase( it );
378  }
379  }
380 }
381 
382 DistributionList *Resource::findDistributionListByIdentifier( const QString &identifier )
383 {
384  return mDistListMap.value( identifier );
385 }
386 
387 DistributionList *Resource::findDistributionListByName( const QString &name,
388  Qt::CaseSensitivity caseSensitivity )
389 {
390  QString searchName = name;
391  if ( caseSensitivity == Qt::CaseInsensitive ) {
392  searchName = name.toLower();
393  }
394 
395  DistributionListMap::const_iterator it = mDistListMap.constBegin();
396  DistributionListMap::const_iterator endIt = mDistListMap.constEnd();
397  for ( ; it != endIt; ++it ) {
398  if ( caseSensitivity == Qt::CaseSensitive ) {
399  if ( searchName == it.value()->name() ) {
400  return it.value();
401  }
402  } else {
403  if ( searchName == it.value()->name().toLower() ) {
404  return it.value();
405  }
406  }
407  }
408 
409  return 0;
410 }
411 
412 QList<DistributionList*> Resource::allDistributionLists()
413 {
414  return mDistListMap.values();
415 }
416 
417 QStringList Resource::allDistributionListNames() const
418 {
419  QStringList results;
420 
421  DistributionListMap::const_iterator it = mDistListMap.constBegin();
422  DistributionListMap::const_iterator endIt = mDistListMap.constEnd();
423  for ( ; it != endIt; ++it ) {
424  results += it.value()->name();
425  }
426 
427  return results;
428 }
429 
430 bool Resource::asyncLoad()
431 {
432  bool ok = load();
433  if ( !ok ) {
434  emit loadingError( this, i18n( "Loading resource '%1' failed.", resourceName() ) );
435  } else {
436  emit loadingFinished( this );
437  }
438 
439  return ok;
440 }
441 
442 bool Resource::asyncSave( Ticket *ticket )
443 {
444  bool ok = save( ticket );
445  if ( !ok ) {
446  emit savingError( this, i18n( "Saving resource '%1' failed.", resourceName() ) );
447  } else {
448  emit savingFinished( this );
449  }
450 
451  return ok;
452 }
453 
454 #include "resource.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Wed Nov 28 2012 21:59:34 by doxygen 1.8.1.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kabc

Skip menu "kabc"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Related Pages

kdepimlibs-4.9.3 API Reference

Skip menu "kdepimlibs-4.9.3 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal