• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeabc
 

tdeabc

  • tdeabc
resource.cpp
1 /*
2  This file is part of libtdeabc.
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 <kdebug.h>
22 #include <tdelocale.h>
23 
24 #include "resource.h"
25 
26 using namespace TDEABC;
27 
28 Ticket::Ticket( Resource *resource )
29  : mResource( resource )
30 {
31 }
32 
33 Ticket::~Ticket()
34 {
35 /* FIXME: avoid cycle deletion
36  if ( mResource )
37  mResource->releaseSaveTicket( this );
38 */
39 }
40 
41 Resource *Ticket::resource()
42 {
43  return mResource;
44 }
45 
46 struct Resource::Iterator::IteratorData
47 {
48  Addressee::Map::Iterator mIt;
49 };
50 
51 struct Resource::ConstIterator::ConstIteratorData
52 {
53  Addressee::Map::ConstIterator mIt;
54 };
55 
56 Resource::Iterator::Iterator()
57 {
58  d = new IteratorData;
59 }
60 
61 Resource::Iterator::Iterator( const Resource::Iterator &i )
62 {
63  d = new IteratorData;
64  d->mIt = i.d->mIt;
65 }
66 
67 Resource::Iterator &Resource::Iterator::operator=( const Resource::Iterator &i )
68 {
69  if ( this == &i )
70  return *this;
71  delete d;
72 
73  d = new IteratorData;
74  d->mIt = i.d->mIt;
75  return *this;
76 }
77 
78 Resource::Iterator::~Iterator()
79 {
80  delete d;
81 }
82 
83 const Addressee &Resource::Iterator::operator*() const
84 {
85  return d->mIt.data();
86 }
87 
88 Addressee &Resource::Iterator::operator*()
89 {
90  return d->mIt.data();
91 }
92 
93 Resource::Iterator &Resource::Iterator::operator++()
94 {
95  (d->mIt)++;
96  return *this;
97 }
98 
99 Resource::Iterator &Resource::Iterator::operator++( int )
100 {
101  (d->mIt)++;
102  return *this;
103 }
104 
105 Resource::Iterator &Resource::Iterator::operator--()
106 {
107  (d->mIt)--;
108  return *this;
109 }
110 
111 Resource::Iterator &Resource::Iterator::operator--( int )
112 {
113  (d->mIt)--;
114  return *this;
115 }
116 
117 bool Resource::Iterator::operator==( const Iterator &it )
118 {
119  return ( d->mIt == it.d->mIt );
120 }
121 
122 bool Resource::Iterator::operator!=( const Iterator &it )
123 {
124  return ( d->mIt != it.d->mIt );
125 }
126 
127 Resource::ConstIterator::ConstIterator()
128 {
129  d = new ConstIteratorData;
130 }
131 
132 Resource::ConstIterator::ConstIterator( const Resource::ConstIterator &i )
133 {
134  d = new ConstIteratorData;
135  d->mIt = i.d->mIt;
136 }
137 
138 Resource::ConstIterator::ConstIterator( const Resource::Iterator &i )
139 {
140  d = new ConstIteratorData;
141  d->mIt = i.d->mIt;
142 }
143 
144 Resource::ConstIterator &Resource::ConstIterator::operator=( const Resource::ConstIterator &i )
145 {
146  if ( this == &i )
147  return *this;
148  delete d;
149 
150  d = new ConstIteratorData;
151  d->mIt = i.d->mIt;
152  return *this;
153 }
154 
155 Resource::ConstIterator::~ConstIterator()
156 {
157  delete d;
158 }
159 
160 const Addressee &Resource::ConstIterator::operator*() const
161 {
162  return *(d->mIt);
163 }
164 
165 Resource::ConstIterator &Resource::ConstIterator::operator++()
166 {
167  (d->mIt)++;
168  return *this;
169 }
170 
171 Resource::ConstIterator &Resource::ConstIterator::operator++( int )
172 {
173  (d->mIt)++;
174  return *this;
175 }
176 
177 Resource::ConstIterator &Resource::ConstIterator::operator--()
178 {
179  (d->mIt)--;
180  return *this;
181 }
182 
183 Resource::ConstIterator &Resource::ConstIterator::operator--( int )
184 {
185  (d->mIt)--;
186  return *this;
187 }
188 
189 bool Resource::ConstIterator::operator==( const ConstIterator &it )
190 {
191  return ( d->mIt == it.d->mIt );
192 }
193 
194 bool Resource::ConstIterator::operator!=( const ConstIterator &it )
195 {
196  return ( d->mIt != it.d->mIt );
197 }
198 
199 
200 Resource::Resource( const TDEConfig *config )
201  : KRES::Resource( config ), mAddressBook( 0 )
202 {
203 }
204 
205 Resource::~Resource()
206 {
207 }
208 
209 Resource::Iterator Resource::begin()
210 {
211  Iterator it;
212  it.d->mIt = mAddrMap.begin();
213 
214  return it;
215 }
216 
217 Resource::ConstIterator Resource::begin() const
218 {
219  ConstIterator it;
220  it.d->mIt = mAddrMap.constBegin();
221  return it;
222 }
223 
224 Resource::Iterator Resource::end()
225 {
226  Iterator it;
227  it.d->mIt = mAddrMap.end();
228 
229  return it;
230 }
231 
232 Resource::ConstIterator Resource::end() const
233 {
234  ConstIterator it;
235  it.d->mIt = mAddrMap.constEnd();
236  return it;
237 }
238 
239 void Resource::writeConfig( TDEConfig *config )
240 {
241  KRES::Resource::writeConfig( config );
242 }
243 
244 void Resource::setAddressBook( AddressBook *ab )
245 {
246  mAddressBook = ab;
247 }
248 
249 AddressBook *Resource::addressBook()
250 {
251  return mAddressBook;
252 }
253 
254 Ticket *Resource::createTicket( Resource *resource )
255 {
256  return new Ticket( resource );
257 }
258 
259 void Resource::insertAddressee( const Addressee &addr )
260 {
261  mAddrMap.insert( addr.uid(), addr );
262 }
263 
264 void Resource::removeAddressee( const Addressee &addr )
265 {
266  mAddrMap.erase( addr.uid() );
267 }
268 
269 Addressee Resource::findByUid( const TQString &uid )
270 {
271  Addressee::Map::ConstIterator it = mAddrMap.find( uid );
272 
273  if ( it != mAddrMap.end() )
274  return it.data();
275 
276  return Addressee();
277 }
278 
279 Addressee::List Resource::findByName( const TQString &name )
280 {
281  Addressee::List results;
282 
283  ConstIterator it;
284  for ( it = begin(); it != end(); ++it ) {
285  if ( name == (*it).name() )
286  results.append( *it );
287  }
288 
289  return results;
290 }
291 
292 Addressee::List Resource::findByEmail( const TQString &email )
293 {
294  Addressee::List results;
295  const TQString lowerEmail = email.lower();
296 
297  ConstIterator it;
298  for ( it = begin(); it != end(); ++it ) {
299  const TQStringList mailList = (*it).emails();
300  for ( TQStringList::ConstIterator ite = mailList.begin(); ite != mailList.end(); ++ite ) {
301  if ( lowerEmail == (*ite).lower() )
302  results.append( *it );
303  }
304  }
305 
306  return results;
307 }
308 
309 Addressee::List Resource::findByCategory( const TQString &category )
310 {
311  Addressee::List results;
312 
313  ConstIterator it;
314  for ( it = begin(); it != end(); ++it ) {
315  if ( (*it).hasCategory( category) ) {
316  results.append( *it );
317  }
318  }
319 
320  return results;
321 }
322 
323 void Resource::clear()
324 {
325  mAddrMap.clear();
326 }
327 
328 bool Resource::asyncLoad()
329 {
330  bool ok = load();
331  if ( !ok )
332  emit loadingError( this, i18n( "Loading resource '%1' failed!" )
333  .arg( resourceName() ) );
334  else
335  emit loadingFinished( this );
336 
337  return ok;
338 }
339 
340 bool Resource::asyncSave( Ticket *ticket ) {
341  bool ok = save( ticket );
342  if ( !ok )
343  emit savingError( this, i18n( "Saving resource '%1' failed!" )
344  .arg( resourceName() ) );
345  else
346  emit savingFinished( this );
347 
348  return ok;
349 }
350 
351 #include "resource.moc"
TDEABC::AddressBook
Address Book.
Definition: addressbook.h:44
TDEABC::Addressee
address book entry
Definition: addressee.src.h:75
TDEABC::Addressee::uid
TQString uid() const
Return unique identifier.
Definition: addressee.src.cpp:174
TDEABC::Resource::ConstIterator
Resource Const Iterator.
Definition: resource.h:95
TDEABC::Resource::Iterator
Resource Iterator.
Definition: resource.h:69
TDEABC::Ticket
Helper class for handling coordinated save of address books.
Definition: resource.h:38
TDEConfig
TDEABC
static data, shared by ALL addressee objects
Definition: address.h:48
TDEStdAccel::end
const TDEShortcut & end()
TDEStdAccel::save
const TDEShortcut & save()
tdelocale.h

tdeabc

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

tdeabc

Skip menu "tdeabc"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeabc by doxygen 1.9.1
This website is maintained by Timothy Pearson.