summaryrefslogtreecommitdiffabout
path: root/kabc/addresseedialog.cpp
Unidiff
Diffstat (limited to 'kabc/addresseedialog.cpp') (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
@@ -81,99 +81,100 @@ AddresseeDialog::AddresseeDialog( QWidget *parent, bool multiple ) :
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
@@ -233,79 +234,120 @@ void 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}