• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 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 <klocalizedstring.h>
25
26using namespace KABC;
27
28class Ticket::Private
29{
30 public:
31 Private( Resource *resource )
32 : mResource( resource )
33 {
34 }
35
36 Resource *mResource;
37};
38
39Ticket::Ticket( Resource *resource )
40 : d( new Private( resource ) )
41{
42}
43
44Ticket::~Ticket()
45{
46 delete d;
47}
48
49Resource *Ticket::resource()
50{
51 return d->mResource;
52}
53
54class Resource::Iterator::Private
55{
56 public:
57 Addressee::Map::Iterator mIt;
58};
59
60class Resource::ConstIterator::Private
61{
62 public:
63 Addressee::Map::ConstIterator mIt;
64};
65
66Resource::Iterator::Iterator()
67 : d( new Private )
68{
69}
70
71Resource::Iterator::Iterator( const Resource::Iterator &other )
72 : d( new Private )
73{
74 d->mIt = other.d->mIt;
75}
76
77Resource::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
86Resource::Iterator::~Iterator()
87{
88 delete d;
89}
90
91const Addressee &Resource::Iterator::operator*() const
92{
93 return d->mIt.value();
94}
95
96Addressee &Resource::Iterator::operator*()
97{
98 return d->mIt.value();
99}
100
101Resource::Iterator &Resource::Iterator::operator++()
102{
103 ( d->mIt )++;
104 return *this;
105}
106
107Resource::Iterator &Resource::Iterator::operator++( int )
108{
109 ( d->mIt )++;
110 return *this;
111}
112
113Resource::Iterator &Resource::Iterator::operator--()
114{
115 ( d->mIt )--;
116 return *this;
117}
118
119Resource::Iterator &Resource::Iterator::operator--( int )
120{
121 ( d->mIt )--;
122 return *this;
123}
124
125bool Resource::Iterator::operator==( const Iterator &it ) const
126{
127 return d->mIt == it.d->mIt;
128}
129
130bool Resource::Iterator::operator!=( const Iterator &it ) const
131{
132 return d->mIt != it.d->mIt;
133}
134
135Resource::ConstIterator::ConstIterator()
136 : d( new Private )
137{
138}
139
140Resource::ConstIterator::ConstIterator( const Resource::ConstIterator &other )
141 : d( new Private )
142{
143 d->mIt = other.d->mIt;
144}
145
146#ifndef QT_STRICT_ITERATORS
147Resource::ConstIterator::ConstIterator( const Resource::Iterator &other )
148 : d( new Private )
149{
150 d->mIt = other.d->mIt;
151}
152#endif
153
154Resource::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
163Resource::ConstIterator::~ConstIterator()
164{
165 delete d;
166}
167
168const Addressee &Resource::ConstIterator::operator*() const
169{
170 return *( d->mIt );
171}
172
173Resource::ConstIterator &Resource::ConstIterator::operator++()
174{
175 ( d->mIt )++;
176 return *this;
177}
178
179Resource::ConstIterator &Resource::ConstIterator::operator++( int )
180{
181 ( d->mIt )++;
182 return *this;
183}
184
185Resource::ConstIterator &Resource::ConstIterator::operator--()
186{
187 --( d->mIt );
188 return *this;
189}
190
191Resource::ConstIterator &Resource::ConstIterator::operator--( int )
192{
193 --( d->mIt );
194 return *this;
195}
196
197bool Resource::ConstIterator::operator==( const ConstIterator &it ) const
198{
199 return d->mIt == it.d->mIt;
200}
201
202bool Resource::ConstIterator::operator!=( const ConstIterator &it ) const
203{
204 return d->mIt != it.d->mIt;
205}
206
207class Resource::Private
208{
209 public:
210 Private()
211 : mAddressBook( 0 )
212 {
213 }
214
215 AddressBook *mAddressBook;
216};
217
218Resource::Resource()
219 : KRES::Resource(), d( new Private )
220{
221}
222
223Resource::Resource( const KConfigGroup &group )
224 : KRES::Resource( group ), d( new Private )
225{
226}
227
228Resource::~Resource()
229{
230 clear();
231 delete d;
232}
233
234Resource::Iterator Resource::begin()
235{
236 Iterator it;
237 it.d->mIt = mAddrMap.begin();
238
239 return it;
240}
241
242Resource::ConstIterator Resource::begin() const
243{
244 ConstIterator it;
245 it.d->mIt = mAddrMap.constBegin();
246 return it;
247}
248
249Resource::Iterator Resource::end()
250{
251 Iterator it;
252 it.d->mIt = mAddrMap.end();
253
254 return it;
255}
256
257Resource::ConstIterator Resource::end() const
258{
259 ConstIterator it;
260 it.d->mIt = mAddrMap.constEnd();
261 return it;
262}
263
264void Resource::writeConfig( KConfigGroup &group )
265{
266 KRES::Resource::writeConfig( group );
267}
268
269void Resource::setAddressBook( AddressBook *ab )
270{
271 d->mAddressBook = ab;
272}
273
274AddressBook *Resource::addressBook()
275{
276 return d->mAddressBook;
277}
278
279Ticket *Resource::createTicket( Resource *resource )
280{
281 return new Ticket( resource );
282}
283
284void Resource::insertAddressee( const Addressee &addr )
285{
286 mAddrMap.insert( addr.uid(), addr );
287}
288
289void Resource::removeAddressee( const Addressee &addr )
290{
291 mAddrMap.remove( addr.uid() );
292}
293
294Addressee 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
305Addressee::List Resource::findByName( const QString &name ) // TODO: const
306{
307 Addressee::List results;
308
309 ConstIterator it;
310 ConstIterator end( constEnd() );
311 for ( it = constBegin(); it != end; ++it ) {
312 if ( name == ( *it ).name() ) {
313 results.append( *it );
314 }
315 }
316
317 return results;
318}
319
320Addressee::List Resource::findByEmail( const QString &email ) // TODO: const
321{
322 Addressee::List results;
323 const QString lowerEmail = email.toLower();
324
325 ConstIterator it;
326 for ( it = constBegin(); it != constEnd(); ++it ) {
327 const QStringList mailList = ( *it ).emails();
328 const QStringList::ConstIterator end( mailList.end() );
329 for ( QStringList::ConstIterator ite = mailList.begin(); ite != end; ++ite ) {
330 if ( lowerEmail == ( *ite ).toLower() ) {
331 results.append( *it );
332 }
333 }
334 }
335
336 return results;
337}
338
339Addressee::List Resource::findByCategory( const QString &category ) // TODO: const
340{
341 Addressee::List results;
342
343 ConstIterator it;
344 ConstIterator end( constEnd() );
345 for ( it = constBegin(); it != end; ++it ) {
346 if ( ( *it ).hasCategory( category ) ) {
347 results.append( *it );
348 }
349 }
350
351 return results;
352}
353
354void Resource::clear()
355{
356 mAddrMap.clear();
357
358 // take a copy of mDistListMap, then clear it and finally qDeleteAll
359 // the copy to avoid problems with removeDistributionList() called by
360 // ~DistributionList().
361 DistributionListMap tempDistListMap( mDistListMap );
362 mDistListMap.clear();
363 qDeleteAll( tempDistListMap );
364}
365
366void Resource::insertDistributionList( DistributionList *list )
367{
368 Q_ASSERT( list );
369
370 mDistListMap.insert( list->identifier(), list );
371}
372
373void Resource::removeDistributionList( DistributionList *list )
374{
375 Q_ASSERT( list );
376
377 DistributionListMap::iterator it = mDistListMap.find( list->identifier() );
378 if ( it != mDistListMap.end() ) {
379 if ( it.value() == list ) {
380 mDistListMap.erase( it );
381 }
382 }
383}
384
385DistributionList *Resource::findDistributionListByIdentifier( const QString &identifier )
386{
387 return mDistListMap.value( identifier );
388}
389
390DistributionList *Resource::findDistributionListByName( const QString &name,
391 Qt::CaseSensitivity caseSensitivity )
392{
393 QString searchName = name;
394 if ( caseSensitivity == Qt::CaseInsensitive ) {
395 searchName = name.toLower();
396 }
397
398 DistributionListMap::const_iterator it = mDistListMap.constBegin();
399 DistributionListMap::const_iterator endIt = mDistListMap.constEnd();
400 for ( ; it != endIt; ++it ) {
401 if ( caseSensitivity == Qt::CaseSensitive ) {
402 if ( searchName == it.value()->name() ) {
403 return it.value();
404 }
405 } else {
406 if ( searchName == it.value()->name().toLower() ) {
407 return it.value();
408 }
409 }
410 }
411
412 return 0;
413}
414
415QList<DistributionList*> Resource::allDistributionLists()
416{
417 return mDistListMap.values();
418}
419
420QStringList Resource::allDistributionListNames() const
421{
422 QStringList results;
423
424 DistributionListMap::const_iterator it = mDistListMap.constBegin();
425 DistributionListMap::const_iterator endIt = mDistListMap.constEnd();
426 for ( ; it != endIt; ++it ) {
427 results += it.value()->name();
428 }
429
430 return results;
431}
432
433bool Resource::asyncLoad()
434{
435 bool ok = load();
436 if ( !ok ) {
437 emit loadingError( this, i18n( "Loading resource '%1' failed.", resourceName() ) );
438 } else {
439 emit loadingFinished( this );
440 }
441
442 return ok;
443}
444
445bool Resource::asyncSave( Ticket *ticket )
446{
447 bool ok = save( ticket );
448 if ( !ok ) {
449 emit savingError( this, i18n( "Saving resource '%1' failed.", resourceName() ) );
450 } else {
451 emit savingFinished( this );
452 }
453
454 return ok;
455}
456
KABC::AddressBook
Address Book.
Definition: addressbook.h:47
KABC::AddresseeList
a QValueList of Addressee, with sorting functionality
Definition: addresseelist.h:289
KABC::Addressee
address book entry
Definition: addressee.h:79
KABC::Addressee::uid
QString uid() const
Return unique identifier.
Definition: addressee.cpp:442
KABC::DistributionList
Distribution list of email addresses.
Definition: distributionlist.h:46
KABC::DistributionList::identifier
QString identifier() const
Returns the distribution list's identifier.
Definition: distributionlist.cpp:126
KABC::Resource::ConstIterator
Resource Const Iterator.
Definition: resource.h:166
KABC::Resource::ConstIterator::operator=
virtual ConstIterator & operator=(const ConstIterator &)
Assignment operator.
Definition: resource.cpp:154
KABC::Resource::ConstIterator::operator--
virtual ConstIterator & operator--()
Predecrement operator.
Definition: resource.cpp:185
KABC::Resource::ConstIterator::operator++
virtual ConstIterator & operator++()
Preincrement operator.
Definition: resource.cpp:173
KABC::Resource::ConstIterator::operator*
virtual const Addressee & operator*() const
Constant Dereference operator.
Definition: resource.cpp:168
KABC::Resource::ConstIterator::operator!=
virtual bool operator!=(const ConstIterator &it) const
Inequality operator.
Definition: resource.cpp:202
KABC::Resource::ConstIterator::ConstIterator
ConstIterator()
Default constructor.
Definition: resource.cpp:135
KABC::Resource::ConstIterator::operator==
virtual bool operator==(const ConstIterator &it) const
Equality operator.
Definition: resource.cpp:197
KABC::Resource
Definition: resource.h:65
KABC::Resource::insertDistributionList
virtual void insertDistributionList(DistributionList *list)
Adds a distribution list into this resource.
Definition: resource.cpp:366
KABC::Resource::save
virtual bool save(Ticket *ticket)=0
Saves all addressees synchronously.
KABC::Resource::~Resource
virtual ~Resource()
Destructor.
Definition: resource.cpp:228
KABC::Resource::createTicket
Ticket * createTicket(Resource *)
Factory method, just creates and returns a new Ticket for the given resource.
Definition: resource.cpp:279
KABC::Resource::savingFinished
void savingFinished(Resource *resource)
This signal is emitted when the resource has finished the saving of all addressees from the internal ...
KABC::Resource::asyncLoad
virtual bool asyncLoad()
Loads all addressees asyncronously.
Definition: resource.cpp:433
KABC::Resource::allDistributionLists
virtual QList< DistributionList * > allDistributionLists()
Returns a list of all distribution lists of this resource.
Definition: resource.cpp:415
KABC::Resource::end
virtual ConstIterator end() const
Returns an iterator pointing to the last addressee in the resource.
Definition: resource.cpp:257
KABC::Resource::findDistributionListByName
virtual DistributionList * findDistributionListByName(const QString &name, Qt::CaseSensitivity caseSensitivity=Qt::CaseSensitive)
Returns a distribution list with the given name or 0.
Definition: resource.cpp:390
KABC::Resource::load
virtual bool load()=0
Loads all addressees synchronously.
KABC::Resource::allDistributionListNames
virtual QStringList allDistributionListNames() const
Returns a list of names of all distribution lists of this resource.
Definition: resource.cpp:420
KABC::Resource::mAddrMap
Addressee::Map mAddrMap
A mapping from KABC UIDs to the respective addressee.
Definition: resource.h:527
KABC::Resource::findDistributionListByIdentifier
virtual DistributionList * findDistributionListByIdentifier(const QString &identifier)
Returns a distribution list for the given identifier or 0.
Definition: resource.cpp:385
KABC::Resource::Resource
Resource()
Default constructor.
Definition: resource.cpp:218
KABC::Resource::findByName
virtual Addressee::List findByName(const QString &name)
Searches all addressees which match the specified name.
Definition: resource.cpp:305
KABC::Resource::removeAddressee
virtual void removeAddressee(const Addressee &addr)
Removes an addressee from resource.
Definition: resource.cpp:289
KABC::Resource::savingError
void savingError(Resource *resource, const QString &msg)
This signal is emitted when an error occurred during saving the addressees from the internal cache to...
KABC::Resource::addressBook
AddressBook * addressBook()
Returns a pointer to the addressbook.
Definition: resource.cpp:274
KABC::Resource::clear
virtual void clear()
Removes all addressees and distribution lists from the resource.
Definition: resource.cpp:354
KABC::Resource::insertAddressee
virtual void insertAddressee(const Addressee &addr)
Insert an addressee into the resource.
Definition: resource.cpp:284
KABC::Resource::findByUid
virtual Addressee findByUid(const QString &uid)
Searches an addressee with the specified unique identifier.
Definition: resource.cpp:294
KABC::Resource::asyncSave
virtual bool asyncSave(Ticket *ticket)
Saves all addressees asynchronously.
Definition: resource.cpp:445
KABC::Resource::mDistListMap
DistributionListMap mDistListMap
A mapping from unique identifiers to the respective distribution list.
Definition: resource.h:532
KABC::Resource::findByCategory
virtual Addressee::List findByCategory(const QString &category)
Searches all addressees which belongs to the specified category.
Definition: resource.cpp:339
KABC::Resource::findByEmail
virtual Addressee::List findByEmail(const QString &email)
Searches all addressees which match the specified email address.
Definition: resource.cpp:320
KABC::Resource::writeConfig
virtual void writeConfig(KConfigGroup &group)
Writes the resource specific config to file.
Definition: resource.cpp:264
KABC::Resource::loadingError
void loadingError(Resource *resource, const QString &msg)
This signal is emitted when an error occurred during loading the addressees from the backend to the i...
KABC::Resource::loadingFinished
void loadingFinished(Resource *resource)
This signal is emitted when the resource has finished the loading of all addressees from the backend ...
KABC::Resource::setAddressBook
void setAddressBook(AddressBook *addr)
Definition: resource.cpp:269
KABC::Resource::begin
virtual ConstIterator begin() const
Returns an iterator pointing to the first addressee in the resource.
Definition: resource.cpp:242
KABC::Resource::removeDistributionList
virtual void removeDistributionList(DistributionList *list)
Removes a distribution list from this resource.
Definition: resource.cpp:373
KABC::Ticket
Helper class for handling coordinated save of address books.
Definition: resource.h:38
KABC::Ticket::~Ticket
~Ticket()
Destroys the Ticket instance.
Definition: resource.cpp:44
KABC::Ticket::resource
Resource * resource()
Returns the resource for which this ticket has been created.
Definition: resource.cpp:49
KRES
KRES::Resource::identifier
QString identifier() const
KRES::Resource::resourceName
virtual QString resourceName() const
KRES::Resource::writeConfig
virtual void writeConfig(KConfigGroup &group)
KABC
Class that holds a Calendar Url (FBURL/CALADRURI/CALURI)
Definition: address.h:29
KABC::DistributionListMap
QMap< QString, DistributionList * > DistributionListMap
Typedef for map from IDs to respective DistribtionList.
Definition: distributionlist.h:205
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jul 21 2022 00:00:00 by doxygen 1.9.5 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.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • 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