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

tdeabc

  • tdeabc
distributionlist.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 <tqapplication.h>
22#include <tqpair.h>
23#include <tqvaluelist.h>
24
25#include <ksimpleconfig.h>
26#include <tdestandarddirs.h>
27#include <kdebug.h>
28
29#include "distributionlist.h"
30
31using namespace TDEABC;
32
33DistributionList::DistributionList( DistributionListManager *manager,
34 const TQString &name ) :
35 mManager( manager ), mName( name )
36{
37 mManager->insert( this );
38}
39
40DistributionList::~DistributionList()
41{
42 mManager->remove( this );
43}
44
45void DistributionList::setName( const TQString &name )
46{
47 mName = name;
48}
49
50TQString DistributionList::name() const
51{
52 return mName;
53}
54
55void DistributionList::insertEntry( const Addressee &a, const TQString &email )
56{
57 Entry e( a, email );
58
59 TQValueList<Entry>::Iterator it;
60 for( it = mEntries.begin(); it != mEntries.end(); ++it ) {
61 if ( (*it).addressee.uid() == a.uid() ) {
66 if ( ( (*it).email.isNull() && email.isEmpty() ) ||
67 ( (*it).email.isEmpty() && email.isNull() ) ||
68 ( (*it).email == email ) ) {
69 *it = e;
70 return;
71 }
72 }
73 }
74 mEntries.append( e );
75}
76
77void DistributionList::removeEntry( const Addressee &a, const TQString &email )
78{
79 TQValueList<Entry>::Iterator it;
80 for( it = mEntries.begin(); it != mEntries.end(); ++it ) {
81 if ( (*it).addressee.uid() == a.uid() && (*it).email == email ) {
82 mEntries.remove( it );
83 return;
84 }
85 }
86}
87
88TQStringList DistributionList::emails() const
89{
90 TQStringList emails;
91
92 Entry::List::ConstIterator it;
93 for( it = mEntries.begin(); it != mEntries.end(); ++it ) {
94 Addressee a = (*it).addressee;
95 TQString email = (*it).email.isEmpty() ? a.fullEmail() :
96 a.fullEmail( (*it).email );
97
98 if ( !email.isEmpty() ) {
99 emails.append( email );
100 }
101 }
102
103 return emails;
104}
105
106DistributionList::Entry::List DistributionList::entries() const
107{
108 return mEntries;
109}
110
111typedef TQValueList< TQPair<TQString, TQString> > MissingEntryList;
112
113class DistributionListManager::DistributionListManagerPrivate
114{
115 public:
116 AddressBook *mAddressBook;
117 TQMap< TQString, MissingEntryList > mMissingEntries;
118};
119
120DistributionListManager::DistributionListManager( AddressBook *ab )
121 : d( new DistributionListManagerPrivate )
122{
123 d->mAddressBook = ab;
124 mLists.setAutoDelete( true );
125}
126
127DistributionListManager::~DistributionListManager()
128{
129 mLists.clear();
130
131 delete d;
132 d = 0;
133}
134
135DistributionList *DistributionListManager::list( const TQString &name )
136{
137 DistributionList *list;
138 for( list = mLists.first(); list; list = mLists.next() ) {
139 if ( list->name() == name ) return list;
140 }
141
142 return 0;
143}
144
145void DistributionListManager::insert( DistributionList *l )
146{
147 if ( !l )
148 return;
149
150 DistributionList *list;
151 for( list = mLists.first(); list; list = mLists.next() ) {
152 if ( list->name() == l->name() ) {
153 mLists.remove( list );
154 break;
155 }
156 }
157 mLists.append( l );
158}
159
160void DistributionListManager::remove( DistributionList *l )
161{
162 if ( !l )
163 return;
164
165 DistributionList *list;
166 for( list = mLists.first(); list; list = mLists.next() ) {
167 if ( list->name() == l->name() ) {
168 mLists.remove( list );
169 return;
170 }
171 }
172}
173
174TQStringList DistributionListManager::listNames()
175{
176 TQStringList names;
177
178 DistributionList *list;
179 for( list = mLists.first(); list; list = mLists.next() ) {
180 names.append( list->name() );
181 }
182
183 return names;
184}
185
186bool DistributionListManager::load()
187{
188 KSimpleConfig cfg( locateLocal( "data", "tdeabc/distlists" ) );
189
190 TQMap<TQString,TQString> entryMap = cfg.entryMap( "DistributionLists" );
191 cfg.setGroup( "DistributionLists" );
192
193 // clear old lists
194 mLists.clear();
195 d->mMissingEntries.clear();
196
197 TQMap<TQString,TQString>::ConstIterator it;
198 for( it = entryMap.constBegin(); it != entryMap.constEnd(); ++it ) {
199 TQString name = it.key();
200 TQStringList value = cfg.readListEntry( name );
201
202 kdDebug(5700) << "DLM::load(): " << name << ": " << value.join(",") << endl;
203
204 DistributionList *list = new DistributionList( this, name );
205
206 MissingEntryList missingEntries;
207 TQStringList::ConstIterator entryIt = value.constBegin();
208 while( entryIt != value.constEnd() ) {
209 TQString id = *entryIt++;
210 TQString email = *entryIt;
211
212 kdDebug(5700) << "----- Entry " << id << endl;
213
214 Addressee a = d->mAddressBook->findByUid( id );
215 if ( !a.isEmpty() ) {
216 list->insertEntry( a, email );
217 } else {
218 missingEntries.append( qMakePair( id, email ) );
219 }
220
221 if ( entryIt == value.end() )
222 break;
223 ++entryIt;
224 }
225
226 d->mMissingEntries.insert( name, missingEntries );
227 }
228
229 return true;
230}
231
232bool DistributionListManager::save()
233{
234 kdDebug(5700) << "DistListManager::save()" << endl;
235
236 KSimpleConfig cfg( locateLocal( "data", "tdeabc/distlists" ) );
237
238 cfg.deleteGroup( "DistributionLists" );
239 cfg.setGroup( "DistributionLists" );
240
241 DistributionList *list;
242 for( list = mLists.first(); list; list = mLists.next() ) {
243 kdDebug(5700) << " Saving '" << list->name() << "'" << endl;
244
245 TQStringList value;
246 const DistributionList::Entry::List entries = list->entries();
247 DistributionList::Entry::List::ConstIterator it;
248 for( it = entries.begin(); it != entries.end(); ++it ) {
249 value.append( (*it).addressee.uid() );
250 value.append( (*it).email );
251 }
252
253 if ( d->mMissingEntries.find( list->name() ) != d->mMissingEntries.end() ) {
254 const MissingEntryList missList = d->mMissingEntries[ list->name() ];
255 MissingEntryList::ConstIterator missIt;
256 for ( missIt = missList.begin(); missIt != missList.end(); ++missIt ) {
257 value.append( (*missIt).first );
258 value.append( (*missIt).second );
259 }
260 }
261
262 cfg.writeEntry( list->name(), value );
263 }
264
265 cfg.sync();
266
267 return true;
268}
269
270DistributionListWatcher* DistributionListWatcher::mSelf = 0;
271
272DistributionListWatcher::DistributionListWatcher()
273 : TQObject( tqApp, "DistributionListWatcher" )
274{
275 mDirWatch = new KDirWatch;
276 mDirWatch->addFile( locateLocal( "data", "tdeabc/distlists" ) );
277
278 connect( mDirWatch, TQ_SIGNAL( dirty( const TQString& ) ), TQ_SIGNAL( changed() ) );
279 mDirWatch->startScan();
280}
281
282DistributionListWatcher::~DistributionListWatcher()
283{
284 delete mDirWatch;
285 mDirWatch = 0;
286}
287
288DistributionListWatcher *DistributionListWatcher::self()
289{
290 kdWarning( !tqApp ) << "No TQApplication object available, you'll get a memleak!" << endl;
291
292 if ( !mSelf )
293 mSelf = new DistributionListWatcher();
294
295 return mSelf;
296}
297
298#include "distributionlist.moc"
KSimpleConfig
KSimpleConfig::sync
virtual void sync()
TDEABC::AddressBook
Address Book.
Definition: addressbook.h:44
TDEABC::Addressee
address book entry
Definition: addressee.src.h:75
TDEABC::Addressee::fullEmail
TQString fullEmail(const TQString &email=TQString::null) const
Return email address including real name.
Definition: addressee.src.cpp:386
TDEABC::Addressee::isEmpty
bool isEmpty() const
Return, if the address book entry is empty.
Definition: addressee.src.cpp:161
TDEABC::Addressee::uid
TQString uid() const
Return unique identifier.
Definition: addressee.src.cpp:174
TDEABC::DistributionListManager
Manager of distribution lists.
Definition: distributionlist.h:123
TDEABC::DistributionListManager::list
DistributionList * list(const TQString &name)
Return distribution list with given name.
Definition: distributionlist.cpp:135
TDEABC::DistributionListManager::~DistributionListManager
~DistributionListManager()
Destructor.
Definition: distributionlist.cpp:127
TDEABC::DistributionListManager::load
bool load()
Load distribution lists form disk.
Definition: distributionlist.cpp:186
TDEABC::DistributionListManager::insert
void insert(DistributionList *)
Insert distribution list.
Definition: distributionlist.cpp:145
TDEABC::DistributionListManager::save
bool save()
Save distribution lists to disk.
Definition: distributionlist.cpp:232
TDEABC::DistributionListManager::remove
void remove(DistributionList *)
Remove distribution list.
Definition: distributionlist.cpp:160
TDEABC::DistributionListManager::listNames
TQStringList listNames()
Return names of all distribution lists managed by this manager.
Definition: distributionlist.cpp:174
TDEABC::DistributionListManager::DistributionListManager
DistributionListManager(AddressBook *)
Create manager for given address book.
Definition: distributionlist.cpp:120
TDEABC::DistributionListWatcher
Watchdog for distribution lists.
Definition: distributionlist.h:190
TDEABC::DistributionListWatcher::self
static DistributionListWatcher * self()
Returns the watcher object.
Definition: distributionlist.cpp:288
TDEABC::DistributionList
Distribution list of email addresses.
Definition: distributionlist.h:40
TDEABC::DistributionList::setName
void setName(const TQString &)
Set name of this list.
Definition: distributionlist.cpp:45
TDEABC::DistributionList::~DistributionList
~DistributionList()
Destructor.
Definition: distributionlist.cpp:40
TDEABC::DistributionList::insertEntry
void insertEntry(const Addressee &, const TQString &email=TQString::null)
Insert an entry into this distribution list.
Definition: distributionlist.cpp:55
TDEABC::DistributionList::removeEntry
void removeEntry(const Addressee &, const TQString &email=TQString::null)
Remove an entry from this distribution list.
Definition: distributionlist.cpp:77
TDEABC::DistributionList::name
TQString name() const
Get name of this list.
Definition: distributionlist.cpp:50
TDEABC::DistributionList::entries
Entry::List entries() const
Return list of entries belonging to this distribution list.
Definition: distributionlist.cpp:106
TDEABC::DistributionList::emails
TQStringList emails() const
Return list of email addresses, which belong to this distributon list.
Definition: distributionlist.cpp:88
TDEConfigBase::deleteGroup
bool deleteGroup(const TQString &group, bool bDeep=true, bool bGlobal=false)
TDEConfigBase::readListEntry
int readListEntry(const TQString &pKey, TQStrList &list, char sep=',') const
TDEConfigBase::writeEntry
void writeEntry(const TQString &pKey, const TQString &pValue, bool bPersistent=true, bool bGlobal=false, bool bNLS=false)
TDEConfigBase::setGroup
void setGroup(const TQString &group)
TDEConfig::entryMap
virtual TQMap< TQString, TQString > entryMap(const TQString &pGroup) const
kdWarning
kdbgstream kdWarning(int area=0)
endl
kndbgstream & endl(kndbgstream &s)
kdDebug
kdbgstream kdDebug(int area=0)
locateLocal
TQString locateLocal(const char *type, const TQString &filename, const TDEInstance *instance=TDEGlobal::instance())
TDEABC
static data, shared by ALL addressee objects
Definition: address.h:48
TDEABC::DistributionList::Entry
Distribution List Entry.
Definition: distributionlist.h:50

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.4
This website is maintained by Timothy Pearson.