summaryrefslogtreecommitdiffabout
path: root/kabc
Unidiff
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addresseedialog.cpp80
1 files changed, 61 insertions, 19 deletions
diff --git a/kabc/addresseedialog.cpp b/kabc/addresseedialog.cpp
index 648e780..19b52bb 100644
--- a/kabc/addresseedialog.cpp
+++ b/kabc/addresseedialog.cpp
@@ -1,311 +1,353 @@
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 <qlayout.h> 21#include <qlayout.h>
22#include <qpushbutton.h> 22#include <qpushbutton.h>
23#include <qgroupbox.h> 23#include <qgroupbox.h>
24#include <qapplication.h> 24#include <qapplication.h>
25#include <qregexp.h> 25#include <qregexp.h>
26#include <qvbox.h> 26#include <qvbox.h>
27#include <qlabel.h> 27#include <qlabel.h>
28 28
29#include <klocale.h> 29#include <klocale.h>
30#include <kdebug.h> 30#include <kdebug.h>
31#include <kglobalsettings.h> 31#include <kglobalsettings.h>
32 32
33#include "stdaddressbook.h" 33#include "stdaddressbook.h"
34 34
35#include "addresseedialog.h" 35#include "addresseedialog.h"
36#include "KDGanttMinimizeSplitter.h" 36#include "KDGanttMinimizeSplitter.h"
37//#include "addresseedialog.moc" 37//#include "addresseedialog.moc"
38 38
39using namespace KABC; 39using namespace KABC;
40 40
41AddresseeItem::AddresseeItem( QListView *parent, const Addressee &addressee ) : 41AddresseeItem::AddresseeItem( QListView *parent, const Addressee &addressee ) :
42 QListViewItem( parent ), 42 QListViewItem( parent ),
43 mAddressee( addressee ) 43 mAddressee( addressee )
44{ 44{
45 QString name = addressee.familyName()+", "+ addressee.givenName(); 45 QString name = addressee.familyName()+", "+ addressee.givenName();
46 if ( name.length() == 2 ) 46 if ( name.length() == 2 )
47 name = addressee.organization(); 47 name = addressee.organization();
48 setText( Name,name); 48 setText( Name,name);
49 setText( Email, addressee.preferredEmail() ); 49 setText( Email, addressee.preferredEmail() );
50} 50}
51 51
52QString AddresseeItem::key( int column, bool ) const 52QString AddresseeItem::key( int column, bool ) const
53{ 53{
54 54
55 if (column == Email) { 55 if (column == Email) {
56 QString value = text(Email); 56 QString value = text(Email);
57 int val = value.findRev("@"); 57 int val = value.findRev("@");
58 return value.mid( val) + value.left( val ); 58 return value.mid( val) + value.left( val );
59 } 59 }
60 return text(column).lower(); 60 return text(column).lower();
61} 61}
62 62
63AddresseeDialog::AddresseeDialog( QWidget *parent, bool multiple ) : 63AddresseeDialog::AddresseeDialog( QWidget *parent, bool multiple ) :
64 KDialogBase( KDialogBase::Plain, i18n("Select Addressee"), 64 KDialogBase( KDialogBase::Plain, i18n("Select Addressee"),
65 Ok|Cancel, No, parent ), mMultiple( multiple ) 65 Ok|Cancel, No, parent ), mMultiple( multiple )
66{ 66{
67 qDebug("NEW AddresseeDialog "); 67 qDebug("NEW AddresseeDialog ");
68 QWidget *topWidget = plainPage(); 68 QWidget *topWidget = plainPage();
69 69
70 QBoxLayout *topLayout = new QHBoxLayout( topWidget ); 70 QBoxLayout *topLayout = new QHBoxLayout( topWidget );
71 71
72 72
73 KDGanttMinimizeSplitter* mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, topWidget); 73 KDGanttMinimizeSplitter* mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, topWidget);
74 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 74 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
75 75
76 topLayout->addWidget(mMiniSplitter ); 76 topLayout->addWidget(mMiniSplitter );
77 77
78 QWidget *listWidget = new QWidget( mMiniSplitter ); 78 QWidget *listWidget = new QWidget( mMiniSplitter );
79 79
80 QBoxLayout *listLayout = new QVBoxLayout (listWidget) ; 80 QBoxLayout *listLayout = new QVBoxLayout (listWidget) ;
81 //topLayout->addLayout( listLayout ); 81 //topLayout->addLayout( listLayout );
82 82
83 mAddresseeList = new KListView( listWidget ); 83 mAddresseeList = new KListView( listWidget );
84 mAddresseeList->addColumn( i18n("Name") ); 84 mAddresseeList->addColumn( i18n("Name") );
85 mAddresseeList->addColumn( i18n("Email") ); 85 mAddresseeList->addColumn( i18n("Email") );
86 mAddresseeList->setAllColumnsShowFocus( true ); 86 mAddresseeList->setAllColumnsShowFocus( true );
87 mAddresseeList->setFullWidth( true ); 87 mAddresseeList->setFullWidth( true );
88 listLayout->addWidget( mAddresseeList ); 88 listLayout->addWidget( mAddresseeList );
89 connect( mAddresseeList, SIGNAL( doubleClicked( QListViewItem * ) ), 89 connect( mAddresseeList, SIGNAL( doubleClicked( QListViewItem * ) ),
90 SLOT( slotOk() ) ); 90 SLOT( slotOk() ) );
91 91
92 mAddresseeEdit = new QLineEdit( listWidget ); 92 mAddresseeEdit = new QLineEdit( listWidget );
93 connect( mAddresseeEdit, SIGNAL( returnPressed() ), 93 connect( mAddresseeEdit, SIGNAL( returnPressed() ),
94 SLOT( loadAddressBook() ) ); 94 SLOT( loadAddressBook() ) );
95 mAddresseeEdit->setFocus(); 95 mAddresseeEdit->setFocus();
96 96
97 listLayout->addWidget( mAddresseeEdit ); 97 listLayout->addWidget( mAddresseeEdit );
98 98
99 if ( mMultiple ) { 99 if ( mMultiple ) {
100 //QBoxLayout *selectedLayout = new QVBoxLayout; 100 //QBoxLayout *selectedLayout = new QVBoxLayout;
101 //topLayout->addLayout( selectedLayout ); 101 //topLayout->addLayout( selectedLayout );
102 //topLayout->setSpacing( spacingHint() ); 102 //topLayout->setSpacing( spacingHint() );
103 103
104 QVBox *selectedGroup = new QVBox( mMiniSplitter ); 104 QVBox *selectedGroup = new QVBox( mMiniSplitter );
105 new QLabel ( i18n("Selected:"), selectedGroup ); 105 new QLabel ( i18n("Selected:"), selectedGroup );
106 //selectedLayout->addWidget( selectedGroup ); 106 //selectedLayout->addWidget( selectedGroup );
107 107
108 mSelectedList = new KListView( selectedGroup ); 108 mSelectedList = new KListView( selectedGroup );
109 mSelectedList->addColumn( i18n("Name") ); 109 mSelectedList->addColumn( i18n("Name") );
110 mSelectedList->addColumn( i18n("Email") ); 110 mSelectedList->addColumn( i18n("Email") );
111 mSelectedList->setAllColumnsShowFocus( true ); 111 mSelectedList->setAllColumnsShowFocus( true );
112 mSelectedList->setFullWidth( true ); 112 mSelectedList->setFullWidth( true );
113 connect( mSelectedList, SIGNAL( doubleClicked( QListViewItem * ) ), 113 connect( mSelectedList, SIGNAL( doubleClicked( QListViewItem * ) ),
114 SLOT( removeSelected() ) ); 114 SLOT( removeSelected() ) );
115 115
116 QPushButton *unselectButton = new QPushButton( i18n("Unselect"), selectedGroup ); 116 QPushButton *unselectButton = new QPushButton( i18n("Unselect"), selectedGroup );
117 connect ( unselectButton, SIGNAL( clicked() ), SLOT( removeSelected() ) ); 117 connect ( unselectButton, SIGNAL( clicked() ), SLOT( removeSelected() ) );
118 118
119 connect( mAddresseeList, SIGNAL( clicked( QListViewItem * ) ), 119 connect( mAddresseeList, SIGNAL( clicked( QListViewItem * ) ),
120 SLOT( addSelected( QListViewItem * ) ) ); 120 SLOT( addSelected( QListViewItem * ) ) );
121 connect( mAddresseeList, SIGNAL( returnPressed( QListViewItem * ) ), 121 connect( mAddresseeList, SIGNAL( returnPressed( QListViewItem * ) ),
122 SLOT( selectNextItem( QListViewItem * ) ) ); 122 SLOT( selectNextItem( QListViewItem * ) ) );
123 123
124 } 124 }
125 125
126 mAddressBook = StdAddressBook::self( true ); 126 mAddressBook = StdAddressBook::self( true );
127 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook* ) ), 127 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook* ) ),
128 SLOT( addressBookChanged() ) ); 128 SLOT( addressBookChanged() ) );
129#if 0
129 connect( mAddressBook, SIGNAL( loadingFinished( Resource* ) ), 130 connect( mAddressBook, SIGNAL( loadingFinished( Resource* ) ),
130 SLOT( addressBookChanged() ) ); 131 SLOT( addressBookChanged() ) );
131 132#endif
132 loadAddressBook(); 133 loadAddressBook();
133 QValueList<int> splitterSize; 134 QValueList<int> splitterSize;
134 splitterSize.append( ( width() / 5 ) * 3 ); 135 splitterSize.append( ( width() / 5 ) * 3 );
135 splitterSize.append( ( width() / 5 ) *2 ); 136 splitterSize.append( ( width() / 5 ) *2 );
136 mMiniSplitter->setSizes( splitterSize ); 137 mMiniSplitter->setSizes( splitterSize );
137} 138}
138 139
139AddresseeDialog::~AddresseeDialog() 140AddresseeDialog::~AddresseeDialog()
140{ 141{
141 qDebug("DELETE AddresseeDialog "); 142 qDebug("DELETE AddresseeDialog ");
142} 143}
143 144
144void AddresseeDialog::loadAddressBook() 145void AddresseeDialog::loadAddressBook()
145{ 146{
146 mAddresseeList->clear(); 147 mAddresseeList->clear();
147 mItemDict.clear(); 148 mItemDict.clear();
148 if ( mAddresseeEdit->text().isEmpty() ) { 149 if ( mAddresseeEdit->text().isEmpty() ) {
149 AddressBook::Iterator it; 150 AddressBook::Iterator it;
150 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { 151 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
151 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 152 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
152 continue; 153 continue;
153 new AddresseeItem( mAddresseeList, (*it) ); 154 new AddresseeItem( mAddresseeList, (*it) );
154 } 155 }
155 return; 156 return;
156 } 157 }
157 //mAddresseeEdit->completionObject()->clear(); 158 //mAddresseeEdit->completionObject()->clear();
158 QRegExp re; 159 QRegExp re;
159 re.setWildcard(true); // most people understand these better. 160 re.setWildcard(true); // most people understand these better.
160 re.setCaseSensitive(false); 161 re.setCaseSensitive(false);
161 re.setPattern( "*"+ mAddresseeEdit->text() + "*"); 162 re.setPattern( "*"+ mAddresseeEdit->text() + "*");
162 163
163 AddressBook::Iterator it; 164 AddressBook::Iterator it;
164 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { 165 for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
165 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) 166 if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") )
166 continue; 167 continue;
167 QString name = (*it).familyName()+", "+ (*it).givenName(); 168 QString name = (*it).familyName()+", "+ (*it).givenName();
168 if ( name.length() == 2 ) 169 if ( name.length() == 2 )
169 name = (*it).realName(); 170 name = (*it).realName();
170 name += (*it).preferredEmail(); 171 name += (*it).preferredEmail();
171#if QT_VERSION >= 0x030000 172#if QT_VERSION >= 0x030000
172 if (re.search(name) != -1) 173 if (re.search(name) != -1)
173#else 174#else
174 if (re.match(name) != -1) 175 if (re.match(name) != -1)
175#endif 176#endif
176 AddresseeItem *item = new AddresseeItem( mAddresseeList, (*it) ); 177 AddresseeItem *item = new AddresseeItem( mAddresseeList, (*it) );
177 } 178 }
178} 179}
179 180
180void AddresseeDialog::addCompletionItem( const QString &str, QListViewItem *item ) 181void AddresseeDialog::addCompletionItem( const QString &str, QListViewItem *item )
181{ 182{
182 if ( str.isEmpty() ) return; 183 if ( str.isEmpty() ) return;
183 184
184 mItemDict.insert( str, item ); 185 mItemDict.insert( str, item );
185 //mAddresseeEdit->completionObject()->addItem( str ); 186 //mAddresseeEdit->completionObject()->addItem( str );
186} 187}
187 188
188void AddresseeDialog::selectItem( const QString &str ) 189void AddresseeDialog::selectItem( const QString &str )
189{ 190{
190 if ( str.isEmpty() ) return; 191 if ( str.isEmpty() ) return;
191 192
192 QListViewItem *item = mItemDict.find( str ); 193 QListViewItem *item = mItemDict.find( str );
193 if ( item ) { 194 if ( item ) {
194 mAddresseeList->blockSignals( true ); 195 mAddresseeList->blockSignals( true );
195 mAddresseeList->setSelected( item, true ); 196 mAddresseeList->setSelected( item, true );
196 mAddresseeList->ensureItemVisible( item ); 197 mAddresseeList->ensureItemVisible( item );
197 mAddresseeList->blockSignals( false ); 198 mAddresseeList->blockSignals( false );
198 } 199 }
199} 200}
200 201
201void AddresseeDialog::updateEdit( QListViewItem *item ) 202void AddresseeDialog::updateEdit( QListViewItem *item )
202{ 203{
203 mAddresseeEdit->setText( item->text( 0 ) ); 204 mAddresseeEdit->setText( item->text( 0 ) );
204 mAddresseeEdit->setSelection( 0, item->text( 0 ).length() ); 205 mAddresseeEdit->setSelection( 0, item->text( 0 ).length() );
205} 206}
206 207
207void AddresseeDialog::selectNextItem( QListViewItem *item ) 208void AddresseeDialog::selectNextItem( QListViewItem *item )
208{ 209{
209 addSelected( item ); 210 addSelected( item );
210 QListViewItem *next = item->nextSibling(); 211 QListViewItem *next = item->nextSibling();
211 if ( next ) { 212 if ( next ) {
212 next->setSelected( true ); 213 next->setSelected( true );
213 item->setSelected( false ); 214 item->setSelected( false );
214 mAddresseeList->setCurrentItem( next ); 215 mAddresseeList->setCurrentItem( next );
215 } 216 }
216} 217}
217void AddresseeDialog::addSelected( QListViewItem *item ) 218void AddresseeDialog::addSelected( QListViewItem *item )
218{ 219{
219 AddresseeItem *addrItem = (AddresseeItem *)( item ); 220 AddresseeItem *addrItem = (AddresseeItem *)( item );
220 if ( !addrItem ) return; 221 if ( !addrItem ) return;
221 222
222 Addressee a = addrItem->addressee(); 223 Addressee a = addrItem->addressee();
223 224
224 QListViewItem *selectedItem = mSelectedDict.find( a.uid() ); 225 QListViewItem *selectedItem = mSelectedDict.find( a.uid() );
225 if ( !selectedItem ) { 226 if ( !selectedItem ) {
226 selectedItem = new AddresseeItem( mSelectedList, a ); 227 selectedItem = new AddresseeItem( mSelectedList, a );
227 mSelectedDict.insert( a.uid(), selectedItem ); 228 mSelectedDict.insert( a.uid(), selectedItem );
228 } 229 }
229 230
230} 231}
231 232
232void AddresseeDialog::removeSelected() 233void AddresseeDialog::removeSelected()
233{ 234{
234 QListViewItem *item = mSelectedList->selectedItem(); 235 QListViewItem *item = mSelectedList->selectedItem();
235 AddresseeItem *addrItem = (AddresseeItem *)( item ); 236 AddresseeItem *addrItem = (AddresseeItem *)( item );
236 if ( !addrItem ) return; 237 if ( !addrItem ) return;
237 QListViewItem *next = item->nextSibling(); 238 QListViewItem *next = item->nextSibling();
238 mSelectedDict.remove( addrItem->addressee().uid() ); 239 mSelectedDict.remove( addrItem->addressee().uid() );
239 delete addrItem; 240 delete addrItem;
240 if ( next ) 241 if ( next )
241 next->setSelected( true ); 242 next->setSelected( true );
242} 243}
243 244
244Addressee AddresseeDialog::addressee() 245Addressee AddresseeDialog::addressee()
245{ 246{
246 AddresseeItem *aItem = 0; 247 AddresseeItem *aItem = 0;
247 248
248 if ( mMultiple ) 249 if ( mMultiple )
249 aItem = (AddresseeItem *)( mSelectedList->firstChild() ); 250 aItem = (AddresseeItem *)( mSelectedList->firstChild() );
250 else 251 else
251 aItem = (AddresseeItem *)( mAddresseeList->selectedItem() ); 252 aItem = (AddresseeItem *)( mAddresseeList->selectedItem() );
252 253
253 if (aItem) return aItem->addressee(); 254 if (aItem) return aItem->addressee();
254 return Addressee(); 255 return Addressee();
255} 256}
256 257
257Addressee::List AddresseeDialog::addressees() 258Addressee::List AddresseeDialog::addressees()
258{ 259{
259 Addressee::List al; 260 Addressee::List al;
260 AddresseeItem *aItem = 0; 261 AddresseeItem *aItem = 0;
261 262
262 if ( mMultiple ) { 263 if ( mMultiple ) {
263 QListViewItem *item = mSelectedList->firstChild(); 264 QListViewItem *item = mSelectedList->firstChild();
264 while( item ) { 265 while( item ) {
265 aItem = (AddresseeItem *)( item ); 266 aItem = (AddresseeItem *)( item );
266 if ( aItem ) al.append( aItem->addressee() ); 267 if ( aItem ) al.append( aItem->addressee() );
267 item = item->nextSibling(); 268 item = item->nextSibling();
268 } 269 }
269 } 270 }
270 else 271 else
271 { 272 {
272 aItem = (AddresseeItem *)( mAddresseeList->selectedItem() ); 273 aItem = (AddresseeItem *)( mAddresseeList->selectedItem() );
273 if (aItem) al.append( aItem->addressee() ); 274 if (aItem) al.append( aItem->addressee() );
274 } 275 }
275 276
276 return al; 277 return al;
277} 278}
278 279
279Addressee AddresseeDialog::getAddressee( QWidget *parent ) 280Addressee AddresseeDialog::getAddressee( QWidget *parent )
280{ 281{
281 AddresseeDialog *dlg = new AddresseeDialog( parent ); 282 AddresseeDialog *dlg = new AddresseeDialog( parent );
282 Addressee addressee; 283 Addressee addressee;
283 int result = dlg->exec(); 284#ifdef DESKTOP_VERSION
285 static int geoX = 0;
286 static int geoY = 0;
287 static int geoW = 0;
288 static int geoH = 0;
289 if ( !geoX && ! geoY && !geoW &&!geoH ) {
290 geoX = dlg->geometry().x();
291 geoY = dlg->geometry().y();
292 geoW = dlg->width();
293 geoH = dlg->height();
294 } else {
295 dlg->show();
296 dlg->setGeometry(geoX , geoY,geoW , geoH );
284 297
285 if ( result == QDialog::Accepted ) { 298 }
286 addressee = dlg->addressee(); 299#endif
287 } 300 int result = dlg->exec();
301#ifdef DESKTOP_VERSION
302 geoX = dlg->geometry().x();
303 geoY = dlg->geometry().y();
304 geoW = dlg->width();
305 geoH = dlg->height();
306#endif
307 if ( result == QDialog::Accepted ) {
308 addressee = dlg->addressee();
309 }
288 310
289 delete dlg; 311 delete dlg;
290 return addressee; 312 return addressee;
291} 313}
292 314
293Addressee::List AddresseeDialog::getAddressees( QWidget *parent ) 315Addressee::List AddresseeDialog::getAddressees( QWidget *parent )
294{ 316{
295 AddresseeDialog *dlg = new AddresseeDialog( parent, true ); 317 AddresseeDialog *dlg = new AddresseeDialog( parent, true );
296 Addressee::List addressees; 318 Addressee::List addressees;
297 if ( QApplication::desktop()->width() <= 640 ) 319 static int geoX = 0;
298 dlg->showMaximized(); 320 static int geoY = 0;
299 int result = dlg->exec(); 321 static int geoW = 0;
300 if ( result == QDialog::Accepted ) { 322 static int geoH = 0;
301 addressees = dlg->addressees(); 323 if ( QApplication::desktop()->width() <= 640 )
302 } 324 dlg->showMaximized();
325 else {
326 if ( !geoX && ! geoY && !geoW &&!geoH ) {
327 geoX = dlg->geometry().x();
328 geoY = dlg->geometry().y();
329 geoW = dlg->width();
330 geoH = dlg->height();
331 } else {
332 dlg->show();
333 dlg->setGeometry(geoX , geoY,geoW , geoH );
334
335 }
336 }
337 int result = dlg->exec();
338 geoX = dlg->geometry().x();
339 geoY = dlg->geometry().y();
340 geoW = dlg->width();
341 geoH = dlg->height();
342 if ( result == QDialog::Accepted ) {
343 addressees = dlg->addressees();
344 }
303 345
304 delete dlg; 346 delete dlg;
305 return addressees; 347 return addressees;
306} 348}
307 349
308void AddresseeDialog::addressBookChanged() 350void AddresseeDialog::addressBookChanged()
309{ 351{
310 loadAddressBook(); 352 loadAddressBook();
311} 353}