author | zautrix <zautrix> | 2004-07-03 23:38:18 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-07-03 23:38:18 (UTC) |
commit | 260befadfaa64d94de7d38d7f6cad0d22f52c226 (patch) (unidiff) | |
tree | 96923d1ac1304e8f07028941e830437465bb9558 | |
parent | 00fe3539778c859d22f595e516733b3cc792e167 (diff) | |
download | kdepimpi-260befadfaa64d94de7d38d7f6cad0d22f52c226.zip kdepimpi-260befadfaa64d94de7d38d7f6cad0d22f52c226.tar.gz kdepimpi-260befadfaa64d94de7d38d7f6cad0d22f52c226.tar.bz2 |
fixed distribution lists
-rw-r--r-- | kabc/distributionlist.cpp | 32 | ||||
-rw-r--r-- | kabc/distributionlisteditor.cpp | 1 |
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 | |||
@@ -1,289 +1,295 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 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 | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <ksimpleconfig.h> | 21 | #include <ksimpleconfig.h> |
22 | #include <kstandarddirs.h> | 22 | #include <kstandarddirs.h> |
23 | #include <kdebug.h> | 23 | #include <kdebug.h> |
24 | 24 | ||
25 | #include "distributionlist.h" | 25 | #include "distributionlist.h" |
26 | 26 | ||
27 | using namespace KABC; | 27 | using namespace KABC; |
28 | 28 | ||
29 | DistributionList::DistributionList( DistributionListManager *manager, | 29 | DistributionList::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 | ||
36 | DistributionList::~DistributionList() | 36 | DistributionList::~DistributionList() |
37 | { | 37 | { |
38 | mManager->remove( this ); | 38 | mManager->remove( this ); |
39 | } | 39 | } |
40 | 40 | ||
41 | void DistributionList::setName( const QString &name ) | 41 | void DistributionList::setName( const QString &name ) |
42 | { | 42 | { |
43 | mName = name; | 43 | mName = name; |
44 | } | 44 | } |
45 | 45 | ||
46 | QString DistributionList::name() const | 46 | QString DistributionList::name() const |
47 | { | 47 | { |
48 | return mName; | 48 | return mName; |
49 | } | 49 | } |
50 | 50 | ||
51 | void DistributionList::insertEntry( const Addressee &a, const QString &email ) | 51 | void 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 | ||
73 | void DistributionList::removeEntry( const Addressee &a, const QString &email ) | 75 | void 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 | ||
84 | QStringList DistributionList::emails() const | 86 | QStringList 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 ) { |
90 | Addressee a = (*it).addressee; | 92 | Addressee a = (*it).addressee; |
91 | QString email = (*it).email.isEmpty() ? a.fullEmail() : | 93 | QString email = (*it).email.isEmpty() ? a.fullEmail() : |
92 | a.fullEmail( (*it).email ); | 94 | a.fullEmail( (*it).email ); |
93 | 95 | ||
94 | if ( !email.isEmpty() ) { | 96 | if ( !email.isEmpty() ) { |
95 | emails.append( email ); | 97 | emails.append( email ); |
96 | } | 98 | } |
97 | } | 99 | } |
98 | 100 | ||
99 | return emails; | 101 | return emails; |
100 | } | 102 | } |
101 | 103 | ||
102 | DistributionList::Entry::List DistributionList::entries() const | 104 | DistributionList::Entry::List DistributionList::entries() const |
103 | { | 105 | { |
104 | return mEntries; | 106 | return mEntries; |
105 | } | 107 | } |
106 | 108 | ||
107 | 109 | ||
108 | DistributionListManager::DistributionListManager( AddressBook *ab ) : | 110 | DistributionListManager::DistributionListManager( AddressBook *ab ) : |
109 | mAddressBook( ab ) | 111 | mAddressBook( ab ) |
110 | { | 112 | { |
111 | } | 113 | } |
112 | 114 | ||
113 | DistributionListManager::~DistributionListManager() | 115 | DistributionListManager::~DistributionListManager() |
114 | { | 116 | { |
115 | } | 117 | } |
116 | 118 | ||
117 | DistributionList *DistributionListManager::list( const QString &name ) | 119 | DistributionList *DistributionListManager::list( const QString &name ) |
118 | { | 120 | { |
119 | DistributionList *list; | 121 | DistributionList *list; |
120 | for( list = mLists.first(); list; list = mLists.next() ) { | 122 | for( list = mLists.first(); list; list = mLists.next() ) { |
121 | if ( list->name() == name ) return list; | 123 | if ( list->name() == name ) return list; |
122 | } | 124 | } |
123 | 125 | ||
124 | return 0; | 126 | return 0; |
125 | } | 127 | } |
126 | 128 | ||
127 | void DistributionListManager::insert( DistributionList *l ) | 129 | void DistributionListManager::insert( DistributionList *l ) |
128 | { | 130 | { |
129 | DistributionList *list; | 131 | DistributionList *list; |
130 | for( list = mLists.first(); list; list = mLists.next() ) { | 132 | for( list = mLists.first(); list; list = mLists.next() ) { |
131 | if ( list->name() == l->name() ) { | 133 | if ( list->name() == l->name() ) { |
132 | mLists.remove( list ); | 134 | mLists.remove( list ); |
133 | break; | 135 | break; |
134 | } | 136 | } |
135 | } | 137 | } |
136 | mLists.append( l ); | 138 | mLists.append( l ); |
137 | } | 139 | } |
138 | 140 | ||
139 | void DistributionListManager::remove( DistributionList *l ) | 141 | void DistributionListManager::remove( DistributionList *l ) |
140 | { | 142 | { |
141 | DistributionList *list; | 143 | DistributionList *list; |
142 | for( list = mLists.first(); list; list = mLists.next() ) { | 144 | for( list = mLists.first(); list; list = mLists.next() ) { |
143 | if ( list->name() == l->name() ) { | 145 | if ( list->name() == l->name() ) { |
144 | mLists.remove( list ); | 146 | mLists.remove( list ); |
145 | return; | 147 | return; |
146 | } | 148 | } |
147 | } | 149 | } |
148 | } | 150 | } |
149 | 151 | ||
150 | QStringList DistributionListManager::listNames() | 152 | QStringList DistributionListManager::listNames() |
151 | { | 153 | { |
152 | QStringList names; | 154 | QStringList names; |
153 | 155 | ||
154 | DistributionList *list; | 156 | DistributionList *list; |
155 | for( list = mLists.first(); list; list = mLists.next() ) { | 157 | for( list = mLists.first(); list; list = mLists.next() ) { |
156 | names.append( list->name() ); | 158 | names.append( list->name() ); |
157 | } | 159 | } |
158 | 160 | ||
159 | return names; | 161 | return names; |
160 | } | 162 | } |
161 | 163 | ||
162 | bool DistributionListManager::load() | 164 | bool 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 | ||
218 | bool DistributionListManager::save() | 220 | bool 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 | ||
258 | DistributionListWatcher* DistributionListWatcher::mSelf = 0; | 264 | DistributionListWatcher* DistributionListWatcher::mSelf = 0; |
259 | 265 | ||
260 | DistributionListWatcher::DistributionListWatcher() | 266 | DistributionListWatcher::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 | } |
271 | 277 | ||
272 | DistributionListWatcher::~DistributionListWatcher() | 278 | DistributionListWatcher::~DistributionListWatcher() |
273 | { | 279 | { |
274 | /*US | 280 | /*US |
275 | delete mDirWatch; | 281 | delete mDirWatch; |
276 | mDirWatch = 0; | 282 | mDirWatch = 0; |
277 | */ | 283 | */ |
278 | } | 284 | } |
279 | 285 | ||
280 | DistributionListWatcher *DistributionListWatcher::self() | 286 | DistributionListWatcher *DistributionListWatcher::self() |
281 | { | 287 | { |
282 | if ( !mSelf ) | 288 | if ( !mSelf ) |
283 | mSelf = new DistributionListWatcher(); | 289 | mSelf = new DistributionListWatcher(); |
284 | 290 | ||
285 | return mSelf; | 291 | return mSelf; |
286 | } | 292 | } |
287 | 293 | ||
288 | //US #include "distributionlist.moc" | 294 | //US #include "distributionlist.moc" |
289 | 295 | ||
diff --git a/kabc/distributionlisteditor.cpp b/kabc/distributionlisteditor.cpp index 8b485d8..bad1efc 100644 --- a/kabc/distributionlisteditor.cpp +++ b/kabc/distributionlisteditor.cpp | |||
@@ -1,317 +1,318 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 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 | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #include <qlistview.h> | 21 | #include <qlistview.h> |
22 | #include <qlayout.h> | 22 | #include <qlayout.h> |
23 | #include <qpushbutton.h> | 23 | #include <qpushbutton.h> |
24 | #include <qcombobox.h> | 24 | #include <qcombobox.h> |
25 | #include <qinputdialog.h> | 25 | #include <qinputdialog.h> |
26 | #include <qbuttongroup.h> | 26 | #include <qbuttongroup.h> |
27 | #include <qradiobutton.h> | 27 | #include <qradiobutton.h> |
28 | 28 | ||
29 | #include <klocale.h> | 29 | #include <klocale.h> |
30 | #include <kdebug.h> | 30 | #include <kdebug.h> |
31 | 31 | ||
32 | #include "addressbook.h" | 32 | #include "addressbook.h" |
33 | #include "addresseedialog.h" | 33 | #include "addresseedialog.h" |
34 | #include "distributionlist.h" | 34 | #include "distributionlist.h" |
35 | 35 | ||
36 | #include "distributionlisteditor.h" | 36 | #include "distributionlisteditor.h" |
37 | 37 | ||
38 | //US #include "distributionlisteditor.moc" | 38 | //US #include "distributionlisteditor.moc" |
39 | 39 | ||
40 | using namespace KABC; | 40 | using namespace KABC; |
41 | 41 | ||
42 | EmailSelectDialog::EmailSelectDialog( const QStringList &emails, const QString ¤t, | 42 | EmailSelectDialog::EmailSelectDialog( const QStringList &emails, const QString ¤t, |
43 | QWidget *parent ) : | 43 | QWidget *parent ) : |
44 | KDialogBase( KDialogBase::Plain, i18n("Select Email Address"), Ok, Ok, | 44 | KDialogBase( KDialogBase::Plain, i18n("Select Email Address"), Ok, Ok, |
45 | parent ) | 45 | parent ) |
46 | { | 46 | { |
47 | QFrame *topFrame = plainPage(); | 47 | QFrame *topFrame = plainPage(); |
48 | QBoxLayout *topLayout = new QVBoxLayout( topFrame ); | 48 | QBoxLayout *topLayout = new QVBoxLayout( topFrame ); |
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 | ||
63 | QString EmailSelectDialog::selected() | 63 | QString 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 | ||
70 | QString EmailSelectDialog::getEmail( const QStringList &emails, const QString ¤t, | 70 | QString EmailSelectDialog::getEmail( const QStringList &emails, const QString ¤t, |
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 | ||
83 | class EditEntryItem : public QListViewItem | 84 | class 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 { |
97 | setText( 1, email ); | 98 | setText( 1, email ); |
98 | setText( 2, i18n("No") ); | 99 | setText( 2, i18n("No") ); |
99 | } | 100 | } |
100 | } | 101 | } |
101 | 102 | ||
102 | Addressee addressee() const | 103 | Addressee addressee() const |
103 | { | 104 | { |
104 | return mAddressee; | 105 | return mAddressee; |
105 | } | 106 | } |
106 | 107 | ||
107 | QString email() const | 108 | QString email() const |
108 | { | 109 | { |
109 | return mEmail; | 110 | return mEmail; |
110 | } | 111 | } |
111 | 112 | ||
112 | private: | 113 | private: |
113 | Addressee mAddressee; | 114 | Addressee mAddressee; |
114 | QString mEmail; | 115 | QString mEmail; |
115 | }; | 116 | }; |
116 | 117 | ||
117 | DistributionListEditor::DistributionListEditor( AddressBook *addressBook, QWidget *parent) : | 118 | DistributionListEditor::DistributionListEditor( AddressBook *addressBook, QWidget *parent) : |
118 | QWidget( parent ), | 119 | QWidget( parent ), |
119 | mAddressBook( addressBook ) | 120 | mAddressBook( addressBook ) |
120 | { | 121 | { |
121 | kdDebug(5700) << "DistributionListEditor()" << endl; | 122 | kdDebug(5700) << "DistributionListEditor()" << endl; |
122 | 123 | ||
123 | QBoxLayout *topLayout = new QVBoxLayout( this ); | 124 | QBoxLayout *topLayout = new QVBoxLayout( this ); |
124 | topLayout->setMargin( KDialog::marginHint() ); | 125 | topLayout->setMargin( KDialog::marginHint() ); |
125 | topLayout->setSpacing( KDialog::spacingHint() ); | 126 | topLayout->setSpacing( KDialog::spacingHint() ); |
126 | 127 | ||
127 | QBoxLayout *nameLayout = new QHBoxLayout( topLayout) ; | 128 | QBoxLayout *nameLayout = new QHBoxLayout( topLayout) ; |
128 | 129 | ||
129 | mNameCombo = new QComboBox( this ); | 130 | mNameCombo = new QComboBox( this ); |
130 | nameLayout->addWidget( mNameCombo ); | 131 | nameLayout->addWidget( mNameCombo ); |
131 | connect( mNameCombo, SIGNAL( activated( int ) ), SLOT( updateEntryView() ) ); | 132 | connect( mNameCombo, SIGNAL( activated( int ) ), SLOT( updateEntryView() ) ); |
132 | 133 | ||
133 | newButton = new QPushButton( i18n("New List"), this ); | 134 | newButton = new QPushButton( i18n("New List"), this ); |
134 | nameLayout->addWidget( newButton ); | 135 | nameLayout->addWidget( newButton ); |
135 | connect( newButton, SIGNAL( clicked() ), SLOT( newList() ) ); | 136 | connect( newButton, SIGNAL( clicked() ), SLOT( newList() ) ); |
136 | 137 | ||
137 | removeButton = new QPushButton( i18n("Remove List"), this ); | 138 | removeButton = new QPushButton( i18n("Remove List"), this ); |
138 | nameLayout->addWidget( removeButton ); | 139 | nameLayout->addWidget( removeButton ); |
139 | connect( removeButton, SIGNAL( clicked() ), SLOT( removeList() ) ); | 140 | connect( removeButton, SIGNAL( clicked() ), SLOT( removeList() ) ); |
140 | 141 | ||
141 | mEntryView = new QListView( this ); | 142 | mEntryView = new QListView( this ); |
142 | mEntryView->addColumn( i18n("Name") ); | 143 | mEntryView->addColumn( i18n("Name") ); |
143 | mEntryView->addColumn( i18n("Email") ); | 144 | mEntryView->addColumn( i18n("Email") ); |
144 | mEntryView->addColumn( i18n("Use Preferred") ); | 145 | mEntryView->addColumn( i18n("Use Preferred") ); |
145 | topLayout->addWidget( mEntryView ); | 146 | topLayout->addWidget( mEntryView ); |
146 | connect(mEntryView,SIGNAL(selectionChanged ()),this, SLOT(slotSelectionEntryViewChanged())); | 147 | connect(mEntryView,SIGNAL(selectionChanged ()),this, SLOT(slotSelectionEntryViewChanged())); |
147 | 148 | ||
148 | changeEmailButton = new QPushButton( i18n("Change Email"), this ); | 149 | changeEmailButton = new QPushButton( i18n("Change Email"), this ); |
149 | topLayout->addWidget( changeEmailButton ); | 150 | topLayout->addWidget( changeEmailButton ); |
150 | connect( changeEmailButton, SIGNAL( clicked() ), SLOT( changeEmail() ) ); | 151 | connect( changeEmailButton, SIGNAL( clicked() ), SLOT( changeEmail() ) ); |
151 | 152 | ||
152 | removeEntryButton = new QPushButton( i18n("Remove Entry"), this ); | 153 | removeEntryButton = new QPushButton( i18n("Remove Entry"), this ); |
153 | topLayout->addWidget( removeEntryButton ); | 154 | topLayout->addWidget( removeEntryButton ); |
154 | connect( removeEntryButton, SIGNAL( clicked() ), SLOT( removeEntry() ) ); | 155 | connect( removeEntryButton, SIGNAL( clicked() ), SLOT( removeEntry() ) ); |
155 | 156 | ||
156 | addEntryButton = new QPushButton( i18n("Add Entry"), this ); | 157 | addEntryButton = new QPushButton( i18n("Add Entry"), this ); |
157 | topLayout->addWidget( addEntryButton ); | 158 | topLayout->addWidget( addEntryButton ); |
158 | connect( addEntryButton, SIGNAL( clicked() ), SLOT( addEntry() ) ); | 159 | connect( addEntryButton, SIGNAL( clicked() ), SLOT( addEntry() ) ); |
159 | 160 | ||
160 | mAddresseeView = new QListView( this ); | 161 | mAddresseeView = new QListView( this ); |
161 | mAddresseeView->addColumn( i18n("Name") ); | 162 | mAddresseeView->addColumn( i18n("Name") ); |
162 | mAddresseeView->addColumn( i18n("Preferred Email") ); | 163 | mAddresseeView->addColumn( i18n("Preferred Email") ); |
163 | topLayout->addWidget( mAddresseeView ); | 164 | topLayout->addWidget( mAddresseeView ); |
164 | 165 | ||
165 | 166 | ||
166 | connect(mAddresseeView,SIGNAL(selectionChanged ()),this, SLOT(slotSelectionAddresseeViewChanged())); | 167 | connect(mAddresseeView,SIGNAL(selectionChanged ()),this, SLOT(slotSelectionAddresseeViewChanged())); |
167 | 168 | ||
168 | mManager = new DistributionListManager( mAddressBook ); | 169 | mManager = new DistributionListManager( mAddressBook ); |
169 | mManager->load(); | 170 | mManager->load(); |
170 | 171 | ||
171 | updateAddresseeView(); | 172 | updateAddresseeView(); |
172 | updateNameCombo(); | 173 | updateNameCombo(); |
173 | removeButton->setEnabled(!mManager->listNames().isEmpty()); | 174 | removeButton->setEnabled(!mManager->listNames().isEmpty()); |
174 | } | 175 | } |
175 | 176 | ||
176 | DistributionListEditor::~DistributionListEditor() | 177 | DistributionListEditor::~DistributionListEditor() |
177 | { | 178 | { |
178 | kdDebug(5700) << "~DistributionListEditor()" << endl; | 179 | kdDebug(5700) << "~DistributionListEditor()" << endl; |
179 | 180 | ||
180 | mManager->save(); | 181 | mManager->save(); |
181 | delete mManager; | 182 | delete mManager; |
182 | } | 183 | } |
183 | 184 | ||
184 | void DistributionListEditor::slotSelectionEntryViewChanged() | 185 | void DistributionListEditor::slotSelectionEntryViewChanged() |
185 | { | 186 | { |
186 | //US EditEntryItem *entryItem = dynamic_cast<EditEntryItem *>( mEntryView->selectedItem() ); | 187 | //US EditEntryItem *entryItem = dynamic_cast<EditEntryItem *>( mEntryView->selectedItem() ); |
187 | EditEntryItem *entryItem = (EditEntryItem *)( mEntryView->selectedItem() ); | 188 | EditEntryItem *entryItem = (EditEntryItem *)( mEntryView->selectedItem() ); |
188 | bool state = (entryItem != 0L); | 189 | bool state = (entryItem != 0L); |
189 | 190 | ||
190 | changeEmailButton->setEnabled(state); | 191 | changeEmailButton->setEnabled(state); |
191 | removeEntryButton->setEnabled(state); | 192 | removeEntryButton->setEnabled(state); |
192 | } | 193 | } |
193 | 194 | ||
194 | void DistributionListEditor::newList() | 195 | void DistributionListEditor::newList() |
195 | { | 196 | { |
196 | bool ok = false; | 197 | bool ok = false; |
197 | QString name = QInputDialog::getText( i18n("New Distribution List"), | 198 | QString name = QInputDialog::getText( i18n("New Distribution List"), |
198 | i18n("Please enter name:"), | 199 | i18n("Please enter name:"), |
199 | QLineEdit::Normal, QString::null, &ok, | 200 | QLineEdit::Normal, QString::null, &ok, |
200 | this ); | 201 | this ); |
201 | if ( !ok || name.isEmpty() ) return; | 202 | if ( !ok || name.isEmpty() ) return; |
202 | 203 | ||
203 | new DistributionList( mManager, name ); | 204 | new DistributionList( mManager, name ); |
204 | 205 | ||
205 | mNameCombo->insertItem( name ); | 206 | mNameCombo->insertItem( name ); |
206 | removeButton->setEnabled(true); | 207 | removeButton->setEnabled(true); |
207 | updateEntryView(); | 208 | updateEntryView(); |
208 | } | 209 | } |
209 | 210 | ||
210 | void DistributionListEditor::removeList() | 211 | void DistributionListEditor::removeList() |
211 | { | 212 | { |
212 | delete mManager->list( mNameCombo->currentText() ); | 213 | delete mManager->list( mNameCombo->currentText() ); |
213 | mNameCombo->removeItem( mNameCombo->currentItem() ); | 214 | mNameCombo->removeItem( mNameCombo->currentItem() ); |
214 | removeButton->setEnabled(!mManager->listNames().isEmpty()); | 215 | removeButton->setEnabled(!mManager->listNames().isEmpty()); |
215 | addEntryButton->setEnabled( !mNameCombo->currentText().isEmpty()); | 216 | addEntryButton->setEnabled( !mNameCombo->currentText().isEmpty()); |
216 | updateEntryView(); | 217 | updateEntryView(); |
217 | } | 218 | } |
218 | 219 | ||
219 | void DistributionListEditor::addEntry() | 220 | void DistributionListEditor::addEntry() |
220 | { | 221 | { |
221 | /*US | 222 | /*US |
222 | AddresseeItem *addresseeItem = | 223 | AddresseeItem *addresseeItem = |
223 | dynamic_cast<AddresseeItem *>( mAddresseeView->selectedItem() ); | 224 | dynamic_cast<AddresseeItem *>( mAddresseeView->selectedItem() ); |
224 | */ | 225 | */ |
225 | AddresseeItem *addresseeItem = | 226 | AddresseeItem *addresseeItem = |
226 | (AddresseeItem *)( mAddresseeView->selectedItem() ); | 227 | (AddresseeItem *)( mAddresseeView->selectedItem() ); |
227 | 228 | ||
228 | 229 | ||
229 | if( !addresseeItem ) { | 230 | if( !addresseeItem ) { |
230 | kdDebug(5700) << "DLE::addEntry(): No addressee selected." << endl; | 231 | kdDebug(5700) << "DLE::addEntry(): No addressee selected." << endl; |
231 | return; | 232 | return; |
232 | } | 233 | } |
233 | 234 | ||
234 | DistributionList *list = mManager->list( mNameCombo->currentText() ); | 235 | DistributionList *list = mManager->list( mNameCombo->currentText() ); |
235 | if ( !list ) { | 236 | if ( !list ) { |
236 | kdDebug(5700) << "DLE::addEntry(): No dist list '" << mNameCombo->currentText() << "'" << endl; | 237 | kdDebug(5700) << "DLE::addEntry(): No dist list '" << mNameCombo->currentText() << "'" << endl; |
237 | return; | 238 | return; |
238 | } | 239 | } |
239 | 240 | ||
240 | list->insertEntry( addresseeItem->addressee() ); | 241 | list->insertEntry( addresseeItem->addressee() ); |
241 | updateEntryView(); | 242 | updateEntryView(); |
242 | slotSelectionAddresseeViewChanged(); | 243 | slotSelectionAddresseeViewChanged(); |
243 | } | 244 | } |
244 | 245 | ||
245 | void DistributionListEditor::removeEntry() | 246 | void DistributionListEditor::removeEntry() |
246 | { | 247 | { |
247 | DistributionList *list = mManager->list( mNameCombo->currentText() ); | 248 | DistributionList *list = mManager->list( mNameCombo->currentText() ); |
248 | if ( !list ) return; | 249 | if ( !list ) return; |
249 | 250 | ||
250 | //US EditEntryItem *entryItem = dynamic_cast<EditEntryItem *>( mEntryView->selectedItem() ); | 251 | //US EditEntryItem *entryItem = dynamic_cast<EditEntryItem *>( mEntryView->selectedItem() ); |
251 | EditEntryItem *entryItem = (EditEntryItem *)( mEntryView->selectedItem() ); | 252 | EditEntryItem *entryItem = (EditEntryItem *)( mEntryView->selectedItem() ); |
252 | if ( !entryItem ) return; | 253 | if ( !entryItem ) return; |
253 | 254 | ||
254 | list->removeEntry( entryItem->addressee(), entryItem->email() ); | 255 | list->removeEntry( entryItem->addressee(), entryItem->email() ); |
255 | delete entryItem; | 256 | delete entryItem; |
256 | } | 257 | } |
257 | 258 | ||
258 | void DistributionListEditor::changeEmail() | 259 | void DistributionListEditor::changeEmail() |
259 | { | 260 | { |
260 | DistributionList *list = mManager->list( mNameCombo->currentText() ); | 261 | DistributionList *list = mManager->list( mNameCombo->currentText() ); |
261 | if ( !list ) return; | 262 | if ( !list ) return; |
262 | 263 | ||
263 | //US EditEntryItem *entryItem = dynamic_cast<EditEntryItem *>( mEntryView->selectedItem() ); | 264 | //US EditEntryItem *entryItem = dynamic_cast<EditEntryItem *>( mEntryView->selectedItem() ); |
264 | EditEntryItem *entryItem = (EditEntryItem *)( mEntryView->selectedItem() ); | 265 | EditEntryItem *entryItem = (EditEntryItem *)( mEntryView->selectedItem() ); |
265 | if ( !entryItem ) return; | 266 | if ( !entryItem ) return; |
266 | 267 | ||
267 | QString email = EmailSelectDialog::getEmail( entryItem->addressee().emails(), | 268 | QString email = EmailSelectDialog::getEmail( entryItem->addressee().emails(), |
268 | entryItem->email(), this ); | 269 | entryItem->email(), this ); |
269 | list->removeEntry( entryItem->addressee(), entryItem->email() ); | 270 | list->removeEntry( entryItem->addressee(), entryItem->email() ); |
270 | list->insertEntry( entryItem->addressee(), email ); | 271 | list->insertEntry( entryItem->addressee(), email ); |
271 | 272 | ||
272 | updateEntryView(); | 273 | updateEntryView(); |
273 | } | 274 | } |
274 | 275 | ||
275 | void DistributionListEditor::updateEntryView() | 276 | void DistributionListEditor::updateEntryView() |
276 | { | 277 | { |
277 | DistributionList *list = mManager->list( mNameCombo->currentText() ); | 278 | DistributionList *list = mManager->list( mNameCombo->currentText() ); |
278 | if ( !list ) return; | 279 | if ( !list ) return; |
279 | 280 | ||
280 | mEntryView->clear(); | 281 | mEntryView->clear(); |
281 | DistributionList::Entry::List entries = list->entries(); | 282 | DistributionList::Entry::List entries = list->entries(); |
282 | DistributionList::Entry::List::ConstIterator it; | 283 | DistributionList::Entry::List::ConstIterator it; |
283 | for( it = entries.begin(); it != entries.end(); ++it ) { | 284 | for( it = entries.begin(); it != entries.end(); ++it ) { |
284 | new EditEntryItem( mEntryView, (*it).addressee, (*it).email ); | 285 | new EditEntryItem( mEntryView, (*it).addressee, (*it).email ); |
285 | } | 286 | } |
286 | //US EditEntryItem *entryItem = dynamic_cast<EditEntryItem *>( mEntryView->selectedItem() ); | 287 | //US EditEntryItem *entryItem = dynamic_cast<EditEntryItem *>( mEntryView->selectedItem() ); |
287 | EditEntryItem *entryItem = (EditEntryItem *)( mEntryView->selectedItem() ); | 288 | EditEntryItem *entryItem = (EditEntryItem *)( mEntryView->selectedItem() ); |
288 | bool state = (entryItem != 0L); | 289 | bool state = (entryItem != 0L); |
289 | 290 | ||
290 | changeEmailButton->setEnabled(state); | 291 | changeEmailButton->setEnabled(state); |
291 | removeEntryButton->setEnabled(state); | 292 | removeEntryButton->setEnabled(state); |
292 | } | 293 | } |
293 | 294 | ||
294 | void DistributionListEditor::updateAddresseeView() | 295 | void DistributionListEditor::updateAddresseeView() |
295 | { | 296 | { |
296 | mAddresseeView->clear(); | 297 | mAddresseeView->clear(); |
297 | 298 | ||
298 | AddressBook::Iterator it; | 299 | AddressBook::Iterator it; |
299 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { | 300 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { |
300 | new AddresseeItem( mAddresseeView, *it ); | 301 | new AddresseeItem( mAddresseeView, *it ); |
301 | } | 302 | } |
302 | } | 303 | } |
303 | 304 | ||
304 | void DistributionListEditor::updateNameCombo() | 305 | void DistributionListEditor::updateNameCombo() |
305 | { | 306 | { |
306 | mNameCombo->insertStringList( mManager->listNames() ); | 307 | mNameCombo->insertStringList( mManager->listNames() ); |
307 | 308 | ||
308 | updateEntryView(); | 309 | updateEntryView(); |
309 | } | 310 | } |
310 | 311 | ||
311 | void DistributionListEditor::slotSelectionAddresseeViewChanged() | 312 | void DistributionListEditor::slotSelectionAddresseeViewChanged() |
312 | { | 313 | { |
313 | //US AddresseeItem *addresseeItem = dynamic_cast<AddresseeItem *>( mAddresseeView->selectedItem() ); | 314 | //US AddresseeItem *addresseeItem = dynamic_cast<AddresseeItem *>( mAddresseeView->selectedItem() ); |
314 | AddresseeItem *addresseeItem = (AddresseeItem *)( mAddresseeView->selectedItem() ); | 315 | AddresseeItem *addresseeItem = (AddresseeItem *)( mAddresseeView->selectedItem() ); |
315 | bool state = (addresseeItem != 0L); | 316 | bool state = (addresseeItem != 0L); |
316 | addEntryButton->setEnabled( state && !mNameCombo->currentText().isEmpty()); | 317 | addEntryButton->setEnabled( state && !mNameCombo->currentText().isEmpty()); |
317 | } | 318 | } |