kabc
distributionlist.cpp
00001 /* 00002 This file is part of libkabc. 00003 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public License 00016 along with this library; see the file COPYING.LIB. If not, write to 00017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00018 Boston, MA 02110-1301, USA. 00019 */ 00020 00021 #include "distributionlist.h" 00022 #include "resource.h" 00023 00024 #include <kconfig.h> 00025 #include <krandom.h> 00026 #include <kstandarddirs.h> 00027 #include <kdebug.h> 00028 00029 #include <QtGui/QApplication> 00030 #include <QtCore/QPair> 00031 #include <QtCore/QPointer> 00032 00033 using namespace KABC; 00034 00035 class DistributionList::Entry::Private 00036 { 00037 public: 00038 Private() {} 00039 Private( Addressee _addressee, const QString &_email ) 00040 : addressee( _addressee ), email( _email ) {} 00041 00042 Addressee addressee; 00043 QString email; 00044 }; 00045 00046 DistributionList::Entry::Entry() 00047 : d( new Private() ) 00048 { 00049 } 00050 00051 DistributionList::Entry::Entry( const DistributionList::Entry &entry ) 00052 : d( new Private( entry.d->addressee, entry.d->email ) ) 00053 { 00054 } 00055 00056 DistributionList::Entry::Entry( const Addressee &_addressee, const QString &_email ) 00057 : d( new Private( _addressee, _email ) ) 00058 { 00059 } 00060 00061 DistributionList::Entry::~Entry() 00062 { 00063 delete d; 00064 } 00065 00066 DistributionList::Entry &DistributionList::Entry::operator=( const DistributionList::Entry &entry ) 00067 { 00068 d->addressee = entry.d->addressee; 00069 d->email = entry.d->email; 00070 00071 return *this; 00072 } 00073 00074 Addressee DistributionList::Entry::addressee() const 00075 { 00076 return d->addressee; 00077 } 00078 00079 QString DistributionList::Entry::email() const 00080 { 00081 return d->email; 00082 } 00083 00084 class DistributionList::Private 00085 { 00086 public: 00087 Private( Resource *resource, const QString &identifier, 00088 const QString &name ) 00089 : mResource( resource ), mIdentifier( identifier ), mName( name ) 00090 { 00091 } 00092 00093 QPointer<Resource> mResource; 00094 QString mIdentifier; 00095 QString mName; 00096 Entry::List mEntries; 00097 }; 00098 00099 DistributionList::DistributionList( Resource *resource, const QString &name ) 00100 : d( new Private( resource, KRandom::randomString(10), name ) ) 00101 { 00102 d->mResource->insertDistributionList( this ); 00103 } 00104 00105 DistributionList::DistributionList( Resource *resource, 00106 const QString &identifier, const QString &name ) 00107 : d( new Private( resource, identifier, name ) ) 00108 { 00109 d->mResource->insertDistributionList( this ); 00110 } 00111 00112 DistributionList::~DistributionList() 00113 { 00114 if ( d->mResource ) { 00115 d->mResource->removeDistributionList( this ); 00116 } 00117 00118 delete d; 00119 } 00120 00121 void DistributionList::setIdentifier( const QString &identifier ) 00122 { 00123 d->mIdentifier = identifier; 00124 } 00125 00126 QString DistributionList::identifier() const 00127 { 00128 return d->mIdentifier; 00129 } 00130 00131 void DistributionList::setName( const QString &name ) 00132 { 00133 d->mName = name; 00134 } 00135 00136 QString DistributionList::name() const 00137 { 00138 return d->mName; 00139 } 00140 00141 void DistributionList::insertEntry( const Addressee &a, const QString &email ) 00142 { 00143 Entry e( a, email ); 00144 00145 QList<Entry>::Iterator it; 00146 for ( it = d->mEntries.begin(); it != d->mEntries.end(); ++it ) { 00147 if ( (*it).addressee().uid() == a.uid() ) { 00152 if ( ( (*it).email().isNull() && email.isEmpty() ) || 00153 ( (*it).email().isEmpty() && email.isNull() ) || 00154 ( (*it).email() == email ) ) { 00155 *it = e; 00156 return; 00157 } 00158 } 00159 } 00160 d->mEntries.append( e ); 00161 } 00162 00163 void DistributionList::removeEntry( const Addressee &a, const QString &email ) 00164 { 00165 QList<Entry>::Iterator it; 00166 for ( it = d->mEntries.begin(); it != d->mEntries.end(); ++it ) { 00167 if ( (*it).addressee().uid() == a.uid() && (*it).email() == email ) { 00168 d->mEntries.erase( it ); 00169 return; 00170 } 00171 } 00172 } 00173 00174 QStringList DistributionList::emails() const 00175 { 00176 QStringList emails; 00177 00178 Entry::List::ConstIterator it; 00179 for ( it = d->mEntries.constBegin(); it != d->mEntries.constEnd(); ++it ) { 00180 const Addressee a = (*it).addressee(); 00181 QString email = (*it).email().isEmpty() ? a.fullEmail() : 00182 a.fullEmail( (*it).email() ); 00183 00184 if ( !email.isEmpty() ) { 00185 emails.append( email ); 00186 } 00187 } 00188 00189 return emails; 00190 } 00191 00192 DistributionList::Entry::List DistributionList::entries() const 00193 { 00194 return d->mEntries; 00195 } 00196 00197 Resource *DistributionList::resource() const 00198 { 00199 return d->mResource; 00200 } 00201 00202 typedef QList< QPair<QString, QString> > MissingEntryList;
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 22:20:24 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 22:20:24 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.