summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-07-03 23:38:18 (UTC)
committer zautrix <zautrix>2004-07-03 23:38:18 (UTC)
commit260befadfaa64d94de7d38d7f6cad0d22f52c226 (patch) (unidiff)
tree96923d1ac1304e8f07028941e830437465bb9558
parent00fe3539778c859d22f595e516733b3cc792e167 (diff)
downloadkdepimpi-260befadfaa64d94de7d38d7f6cad0d22f52c226.zip
kdepimpi-260befadfaa64d94de7d38d7f6cad0d22f52c226.tar.gz
kdepimpi-260befadfaa64d94de7d38d7f6cad0d22f52c226.tar.bz2
fixed distribution lists
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/distributionlist.cpp32
-rw-r--r--kabc/distributionlisteditor.cpp1
2 files changed, 20 insertions, 13 deletions
diff --git a/kabc/distributionlist.cpp b/kabc/distributionlist.cpp
index 45b9dda..0735aba 100644
--- a/kabc/distributionlist.cpp
+++ b/kabc/distributionlist.cpp
@@ -29,61 +29,63 @@ using namespace KABC;
29DistributionList::DistributionList( DistributionListManager *manager, 29DistributionList::DistributionList( DistributionListManager *manager,
30 const QString &name ) : 30 const QString &name ) :
31 mManager( manager ), mName( name ) 31 mManager( manager ), mName( name )
32{ 32{
33 mManager->insert( this ); 33 mManager->insert( this );
34} 34}
35 35
36DistributionList::~DistributionList() 36DistributionList::~DistributionList()
37{ 37{
38 mManager->remove( this ); 38 mManager->remove( this );
39} 39}
40 40
41void DistributionList::setName( const QString &name ) 41void DistributionList::setName( const QString &name )
42{ 42{
43 mName = name; 43 mName = name;
44} 44}
45 45
46QString DistributionList::name() const 46QString DistributionList::name() const
47{ 47{
48 return mName; 48 return mName;
49} 49}
50 50
51void DistributionList::insertEntry( const Addressee &a, const QString &email ) 51void DistributionList::insertEntry( const Addressee &a, const QString &email )
52{ 52{
53 Entry e( a, email ); 53 QString em = email;
54 54 if (em.isNull() )
55 em = a.preferredEmail();
56 Entry e( a, em );
55 QValueList<Entry>::Iterator it; 57 QValueList<Entry>::Iterator it;
56 for( it = mEntries.begin(); it != mEntries.end(); ++it ) { 58 for( it = mEntries.begin(); it != mEntries.end(); ++it ) {
57 if ( (*it).addressee.uid() == a.uid() ) { 59 if ( (*it).addressee.uid() == a.uid() ) {
58 /** 60 /**
59 We have to check if both email addresses contains no data, 61 We have to check if both email addresses contains no data,
60 a simple 'email1 == email2' wont work here 62 a simple 'email1 == email2' wont work here
61 */ 63 */
62 if ( ( (*it).email.isNull() && email.isEmpty() ) || 64 if ( ( (*it).email.isNull() && em.isEmpty() ) ||
63 ( (*it).email.isEmpty() && email.isNull() ) || 65 ( (*it).email.isEmpty() && em.isNull() ) ||
64 ( (*it).email == email ) ) { 66 ( (*it).email == em ) ) {
65 *it = e; 67 //*it = e;
66 return; 68 return;
67 } 69 }
68 } 70 }
69 } 71 }
70 mEntries.append( e ); 72 mEntries.append( e );
71} 73}
72 74
73void DistributionList::removeEntry( const Addressee &a, const QString &email ) 75void DistributionList::removeEntry( const Addressee &a, const QString &email )
74{ 76{
75 QValueList<Entry>::Iterator it; 77 QValueList<Entry>::Iterator it;
76 for( it = mEntries.begin(); it != mEntries.end(); ++it ) { 78 for( it = mEntries.begin(); it != mEntries.end(); ++it ) {
77 if ( (*it).addressee.uid() == a.uid() && (*it).email == email ) { 79 if ( (*it).addressee.uid() == a.uid() && (*it).email == email ) {
78 mEntries.remove( it ); 80 mEntries.remove( it );
79 return; 81 return;
80 } 82 }
81 } 83 }
82} 84}
83 85
84QStringList DistributionList::emails() const 86QStringList DistributionList::emails() const
85{ 87{
86 QStringList emails; 88 QStringList emails;
87 89
88 Entry::List::ConstIterator it; 90 Entry::List::ConstIterator it;
89 for( it = mEntries.begin(); it != mEntries.end(); ++it ) { 91 for( it = mEntries.begin(); it != mEntries.end(); ++it ) {
@@ -157,114 +159,118 @@ QStringList DistributionListManager::listNames()
157 } 159 }
158 160
159 return names; 161 return names;
160} 162}
161 163
162bool DistributionListManager::load() 164bool DistributionListManager::load()
163{ 165{
164 KSimpleConfig cfg( locateLocal( "data", "kabc/distlists" ) ); 166 KSimpleConfig cfg( locateLocal( "data", "kabc/distlists" ) );
165 167
166/*US 168/*US
167 QMap<QString,QString> entryMap = cfg.entryMap( mAddressBook->identifier() ); 169 QMap<QString,QString> entryMap = cfg.entryMap( mAddressBook->identifier() );
168 if ( entryMap.isEmpty() ) { 170 if ( entryMap.isEmpty() ) {
169 kdDebug(5700) << "No distlists for '" << mAddressBook->identifier() << "'" << endl; 171 kdDebug(5700) << "No distlists for '" << mAddressBook->identifier() << "'" << endl;
170 return false; 172 return false;
171 } 173 }
172 174
173 cfg.setGroup( mAddressBook->identifier() ); 175 cfg.setGroup( mAddressBook->identifier() );
174 176
175 QMap<QString,QString>::ConstIterator it; 177 QMap<QString,QString>::ConstIterator it;
176 for( it = entryMap.begin(); it != entryMap.end(); ++it ) { 178 for( it = entryMap.begin(); it != entryMap.end(); ++it ) {
177 QString name = it.key(); 179 QString name = it.key();
178*/ 180*/
179 cfg.setGroup( mAddressBook->identifier() ); 181 cfg.setGroup( mAddressBook->identifier() );
180 //US we work in microkde with a list of distributionlists 182 //US we work in microkde with a list of distributionlists
181 QStringList distlists = cfg.readListEntry( "Lists" ); 183 QStringList distlists = cfg.readListEntry( "__Lists__List__" );
182 if ( distlists.isEmpty() ) { 184 if ( distlists.isEmpty() ) {
183 kdDebug(5700) << "No distlists for '" << mAddressBook->identifier() << "'" << endl; 185 qDebug("no distlist for AB ");
184 return false; 186 return false;
185 } 187 }
186 188
187 QStringList::ConstIterator it; 189 QStringList::ConstIterator it;
188 for( it = distlists.begin(); it != distlists.end(); ++it ) { 190 for( it = distlists.begin(); it != distlists.end(); ++it ) {
189 QString name = *it; 191 QString name = *it;
190 192
191 193
192 QStringList value = cfg.readListEntry( name ); 194 QStringList value = cfg.readListEntry( name );
193 195
194 kdDebug(5700) << "DLM::load(): " << name << ": " << value.join(",") << endl; 196
195 197
196 DistributionList *list = new DistributionList( this, name ); 198 DistributionList *list = new DistributionList( this, name );
197 199
198 QStringList::ConstIterator it2 = value.begin(); 200 QStringList::ConstIterator it2 = value.begin();
199 while( it2 != value.end() ) { 201 while( it2 != value.end() ) {
200 QString id = *it2++; 202 QString id = *it2++;
201 QString email = *it2; 203 QString email = *it2;
202 204
203 kdDebug(5700) << "----- Entry " << id << endl; 205
204 206
205 Addressee a = mAddressBook->findByUid( id ); 207 Addressee a = mAddressBook->findByUid( id );
206 if ( !a.isEmpty() ) { 208 if ( !a.isEmpty() ) {
207 list->insertEntry( a, email ); 209 list->insertEntry( a, email );
208 } 210 }
209 211
210 if ( it2 == value.end() ) break; 212 if ( it2 == value.end() ) break;
211 ++it2; 213 ++it2;
212 } 214 }
213 } 215 }
214 216
215 return true; 217 return true;
216} 218}
217 219
218bool DistributionListManager::save() 220bool DistributionListManager::save()
219{ 221{
220 kdDebug(5700) << "DistListManager::save()" << endl; 222
221 223
222 KSimpleConfig cfg( locateLocal( "data", "kabc/distlists" ) ); 224 KSimpleConfig cfg( locateLocal( "data", "kabc/distlists" ) );
223 225
224 cfg.deleteGroup( mAddressBook->identifier() ); 226 cfg.deleteGroup( mAddressBook->identifier() );
225 cfg.setGroup( mAddressBook->identifier() ); 227 cfg.setGroup( mAddressBook->identifier() );
226 228
227 DistributionList *list; 229 DistributionList *list;
228 for( list = mLists.first(); list; list = mLists.next() ) { 230 for( list = mLists.first(); list; list = mLists.next() ) {
229 kdDebug(5700) << " Saving '" << list->name() << "'" << endl; 231 kdDebug(5700) << " Saving '" << list->name() << "'" << endl;
230 QStringList value; 232 QStringList value;
231 DistributionList::Entry::List entries = list->entries(); 233 DistributionList::Entry::List entries = list->entries();
232 DistributionList::Entry::List::ConstIterator it; 234 DistributionList::Entry::List::ConstIterator it;
233 for( it = entries.begin(); it != entries.end(); ++it ) { 235 for( it = entries.begin(); it != entries.end(); ++it ) {
234 value.append( (*it).addressee.uid() ); 236 value.append( (*it).addressee.uid() );
235 value.append( (*it).email ); 237 if (( *it).email.isEmpty())
238 value.append( " " );
239 else
240 value.append( (*it).email );
241 // qDebug("uid *%s* email *%s* ", (*it).addressee.uid().latin1(),(*it).email.latin1() );
236 } 242 }
237 cfg.writeEntry( list->name(), value ); 243 cfg.writeEntry( list->name(), value );
238 } 244 }
239 245
240//US for microKDE we have not yet sophisticated methods to load maps. 246//US for microKDE we have not yet sophisticated methods to load maps.
241// Because of that we store also a list of all distributionlists. 247// Because of that we store also a list of all distributionlists.
242 QStringList namelist; 248 QStringList namelist;
243 for( list = mLists.first(); list; list = mLists.next() ) { 249 for( list = mLists.first(); list; list = mLists.next() ) {
244 namelist.append( list->name() ); 250 namelist.append( list->name() );
245 } 251 }
246 cfg.writeEntry( "Lists", namelist ); 252 cfg.writeEntry( "__Lists__List__", namelist );
247 253
248 254
249 255
250 256
251 257
252 258
253 cfg.sync(); 259 cfg.sync();
254 260
255 return true; 261 return true;
256} 262}
257 263
258DistributionListWatcher* DistributionListWatcher::mSelf = 0; 264DistributionListWatcher* DistributionListWatcher::mSelf = 0;
259 265
260DistributionListWatcher::DistributionListWatcher() 266DistributionListWatcher::DistributionListWatcher()
261 : QObject( 0, "DistributionListWatcher" ) 267 : QObject( 0, "DistributionListWatcher" )
262{ 268{
263/*US 269/*US
264 mDirWatch = new KDirWatch; 270 mDirWatch = new KDirWatch;
265 mDirWatch->addFile( locateLocal( "data", "kabc/distlists" ) ); 271 mDirWatch->addFile( locateLocal( "data", "kabc/distlists" ) );
266 272
267 connect( mDirWatch, SIGNAL( dirty( const QString& ) ), SIGNAL( changed() ) ); 273 connect( mDirWatch, SIGNAL( dirty( const QString& ) ), SIGNAL( changed() ) );
268 mDirWatch->startScan(); 274 mDirWatch->startScan();
269*/ 275*/
270} 276}
diff --git a/kabc/distributionlisteditor.cpp b/kabc/distributionlisteditor.cpp
index 8b485d8..bad1efc 100644
--- a/kabc/distributionlisteditor.cpp
+++ b/kabc/distributionlisteditor.cpp
@@ -49,48 +49,49 @@ EmailSelectDialog::EmailSelectDialog( const QStringList &emails, const QString &
49 49
50 mButtonGroup = new QButtonGroup( 1, Horizontal, i18n("Email Addresses"), 50 mButtonGroup = new QButtonGroup( 1, Horizontal, i18n("Email Addresses"),
51 topFrame ); 51 topFrame );
52 topLayout->addWidget( mButtonGroup ); 52 topLayout->addWidget( mButtonGroup );
53 53
54 QStringList::ConstIterator it; 54 QStringList::ConstIterator it;
55 for( it = emails.begin(); it != emails.end(); ++it ) { 55 for( it = emails.begin(); it != emails.end(); ++it ) {
56 QRadioButton *button = new QRadioButton( *it, mButtonGroup ); 56 QRadioButton *button = new QRadioButton( *it, mButtonGroup );
57 if ( (*it) == current ) { 57 if ( (*it) == current ) {
58 button->setDown( true ); 58 button->setDown( true );
59 } 59 }
60 } 60 }
61} 61}
62 62
63QString EmailSelectDialog::selected() 63QString EmailSelectDialog::selected()
64{ 64{
65 QButton *button = mButtonGroup->selected(); 65 QButton *button = mButtonGroup->selected();
66 if ( button ) return button->text(); 66 if ( button ) return button->text();
67 return QString::null; 67 return QString::null;
68} 68}
69 69
70QString EmailSelectDialog::getEmail( const QStringList &emails, const QString &current, 70QString EmailSelectDialog::getEmail( const QStringList &emails, const QString &current,
71 QWidget *parent ) 71 QWidget *parent )
72{ 72{
73
73 EmailSelectDialog *dlg = new EmailSelectDialog( emails, current, parent ); 74 EmailSelectDialog *dlg = new EmailSelectDialog( emails, current, parent );
74 dlg->exec(); 75 dlg->exec();
75 76
76 QString result = dlg->selected(); 77 QString result = dlg->selected();
77 78
78 delete dlg; 79 delete dlg;
79 80
80 return result; 81 return result;
81} 82}
82 83
83class EditEntryItem : public QListViewItem 84class EditEntryItem : public QListViewItem
84{ 85{
85 public: 86 public:
86 EditEntryItem( QListView *parent, const Addressee &addressee, 87 EditEntryItem( QListView *parent, const Addressee &addressee,
87 const QString &email=QString::null ) : 88 const QString &email=QString::null ) :
88 QListViewItem( parent ), 89 QListViewItem( parent ),
89 mAddressee( addressee ), 90 mAddressee( addressee ),
90 mEmail( email ) 91 mEmail( email )
91 { 92 {
92 setText( 0, addressee.realName() ); 93 setText( 0, addressee.realName() );
93 if( email.isEmpty() ) { 94 if( email.isEmpty() ) {
94 setText( 1, addressee.preferredEmail() ); 95 setText( 1, addressee.preferredEmail() );
95 setText( 2, i18n("Yes") ); 96 setText( 2, i18n("Yes") );
96 } else { 97 } else {