summaryrefslogtreecommitdiffabout
path: root/kabc/addresseedialog.cpp
authorzautrix <zautrix>2005-06-27 20:33:47 (UTC)
committer zautrix <zautrix>2005-06-27 20:33:47 (UTC)
commitbf664c505e66f54dd03c3518386fdeab43108e56 (patch) (unidiff)
tree2e41ba8c43b8126f643c94ceecd1bcf83800cd43 /kabc/addresseedialog.cpp
parentd730e4b5cd81965f224b69efcc91dd58253f0b98 (diff)
downloadkdepimpi-bf664c505e66f54dd03c3518386fdeab43108e56.zip
kdepimpi-bf664c505e66f54dd03c3518386fdeab43108e56.tar.gz
kdepimpi-bf664c505e66f54dd03c3518386fdeab43108e56.tar.bz2
fixes
Diffstat (limited to 'kabc/addresseedialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addresseedialog.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/kabc/addresseedialog.cpp b/kabc/addresseedialog.cpp
index 9197850..0cf75a0 100644
--- a/kabc/addresseedialog.cpp
+++ b/kabc/addresseedialog.cpp
@@ -1,161 +1,162 @@
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 setText( Name,addressee.realName()); 45 setText( Name,addressee.realName());
46 setText( Email, addressee.preferredEmail() ); 46 setText( Email, addressee.preferredEmail() );
47 setText( Category, addressee.categories().join(";") ); 47 setText( Category, addressee.categories().join(";") );
48} 48}
49 49
50QString AddresseeItem::key( int column, bool ) const 50QString AddresseeItem::key( int column, bool ) const
51{ 51{
52 52
53 if (column == Email) { 53 if (column == Email) {
54 QString value = text(Email); 54 QString value = text(Email);
55 int val = value.findRev("@"); 55 int val = value.findRev("@");
56 return value.mid( val) + value.left( val ); 56 return value.mid( val) + value.left( val );
57 } 57 }
58 return text(column).lower(); 58 return text(column).lower();
59} 59}
60 60
61AddresseeDialog::AddresseeDialog( QWidget *parent, bool multiple ) : 61AddresseeDialog::AddresseeDialog( QWidget *parent, bool multiple ) :
62 KDialogBase( KDialogBase::Plain, i18n("Select Addressee"), 62 KDialogBase( KDialogBase::Plain, i18n("Select Addressee"),
63 Ok|Cancel, No, parent ), mMultiple( multiple ) 63 Ok|Cancel, No, parent ), mMultiple( multiple )
64{ 64{
65 qDebug("NEW AddresseeDialog "); 65 qDebug("NEW AddresseeDialog ");
66
66 QWidget *topWidget = plainPage(); 67 QWidget *topWidget = plainPage();
67 68
68 QBoxLayout *topLayout = new QHBoxLayout( topWidget ); 69 QBoxLayout *topLayout = new QHBoxLayout( topWidget );
69 70
70 71
71 KDGanttMinimizeSplitter* mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, topWidget); 72 KDGanttMinimizeSplitter* mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, topWidget);
72 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); 73 mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right );
73 74
74 topLayout->addWidget(mMiniSplitter ); 75 topLayout->addWidget(mMiniSplitter );
75 76
76 QWidget *listWidget = new QWidget( mMiniSplitter ); 77 QWidget *listWidget = new QWidget( mMiniSplitter );
77 78
78 QVBoxLayout *listLayout = new QVBoxLayout (listWidget) ; 79 QVBoxLayout *listLayout = new QVBoxLayout (listWidget) ;
79 //topLayout->addLayout( listLayout ); 80 //topLayout->addLayout( listLayout );
80 81
81 mAddresseeList = new KListView( listWidget ); 82 mAddresseeList = new KListView( listWidget );
82 mAddresseeList->addColumn( i18n("Name") ); 83 mAddresseeList->addColumn( i18n("Name") );
83 mAddresseeList->addColumn( i18n("Email") ); 84 mAddresseeList->addColumn( i18n("Email") );
84 mAddresseeList->addColumn( i18n("Category") ); 85 mAddresseeList->addColumn( i18n("Category") );
85 mAddresseeList->setAllColumnsShowFocus( true ); 86 mAddresseeList->setAllColumnsShowFocus( true );
86 mAddresseeList->setFullWidth( true ); 87 mAddresseeList->setFullWidth( true );
87 listLayout->addWidget( mAddresseeList ); 88 listLayout->addWidget( mAddresseeList );
88 connect( mAddresseeList, SIGNAL( doubleClicked( QListViewItem * ) ), 89 connect( mAddresseeList, SIGNAL( doubleClicked( QListViewItem * ) ),
89 SLOT( slotOk() ) ); 90 SLOT( slotOk() ) );
90 91
91 //QHBox* searchBox = new QHBox ( listWidget ); 92 //QHBox* searchBox = new QHBox ( listWidget );
92 mAddresseeEdit = new QLineEdit( listWidget ); 93 mAddresseeEdit = new QLineEdit( listWidget );
93 connect( mAddresseeEdit, SIGNAL( returnPressed() ), 94 connect( mAddresseeEdit, SIGNAL( returnPressed() ),
94 SLOT( loadAddressBook() ) ); 95 SLOT( loadAddressBook() ) );
95 mAddresseeEdit->setFocus(); 96 mAddresseeEdit->setFocus();
96 QPushButton *searchButton = new QPushButton( i18n("Search!"), listWidget ); 97 QPushButton *searchButton = new QPushButton( i18n("Search!"), listWidget );
97 connect ( searchButton, SIGNAL( clicked() ), SLOT( loadAddressBook() ) ); 98 connect ( searchButton, SIGNAL( clicked() ), SLOT( loadAddressBook() ) );
98 99
99 QHBoxLayout *searchLayout = new QHBoxLayout (listLayout) ; 100 QHBoxLayout *searchLayout = new QHBoxLayout (listLayout) ;
100 searchLayout->addWidget( mAddresseeEdit ); 101 searchLayout->addWidget( mAddresseeEdit );
101 searchLayout->addWidget( searchButton ); 102 searchLayout->addWidget( searchButton );
102 //listLayout->addWidget( searchBox ); 103 //listLayout->addWidget( searchBox );
103 104
104 if ( mMultiple ) { 105 if ( mMultiple ) {
105 //QBoxLayout *selectedLayout = new QVBoxLayout; 106 //QBoxLayout *selectedLayout = new QVBoxLayout;
106 //topLayout->addLayout( selectedLayout ); 107 //topLayout->addLayout( selectedLayout );
107 //topLayout->setSpacing( spacingHint() ); 108 //topLayout->setSpacing( spacingHint() );
108 109
109 QVBox *selectedGroup = new QVBox( mMiniSplitter ); 110 QVBox *selectedGroup = new QVBox( mMiniSplitter );
110 new QLabel ( i18n("Selected:"), selectedGroup ); 111 new QLabel ( i18n("Selected:"), selectedGroup );
111 //selectedLayout->addWidget( selectedGroup ); 112 //selectedLayout->addWidget( selectedGroup );
112 113
113 mSelectedList = new KListView( selectedGroup ); 114 mSelectedList = new KListView( selectedGroup );
114 mSelectedList->addColumn( i18n("Name") ); 115 mSelectedList->addColumn( i18n("Name") );
115 mSelectedList->addColumn( i18n("Email") ); 116 mSelectedList->addColumn( i18n("Email") );
116 mSelectedList->setAllColumnsShowFocus( true ); 117 mSelectedList->setAllColumnsShowFocus( true );
117 mSelectedList->setFullWidth( true ); 118 mSelectedList->setFullWidth( true );
118 //connect( mSelectedList, SIGNAL( doubleClicked( QListViewItem * ) ), 119 //connect( mSelectedList, SIGNAL( doubleClicked( QListViewItem * ) ),
119 // SLOT( removeSelected() ) ); 120 // SLOT( removeSelected() ) );
120 connect( mSelectedList, SIGNAL( clicked( QListViewItem * ) ), 121 connect( mSelectedList, SIGNAL( clicked( QListViewItem * ) ),
121 SLOT( removeSelected() ) ); 122 SLOT( removeSelected() ) );
122 connect( mSelectedList, SIGNAL( returnPressed( QListViewItem *) ), 123 connect( mSelectedList, SIGNAL( returnPressed( QListViewItem *) ),
123 SLOT( removeSelected() ) ); 124 SLOT( removeSelected() ) );
124 125
125#if 0 126#if 0
126 QPushButton *unselectButton = new QPushButton( i18n("Unselect"), selectedGroup ); 127 QPushButton *unselectButton = new QPushButton( i18n("Unselect"), selectedGroup );
127 connect ( unselectButton, SIGNAL( clicked() ), SLOT( removeSelected() ) ); 128 connect ( unselectButton, SIGNAL( clicked() ), SLOT( removeSelected() ) );
128 129
129#endif 130#endif
130 connect( mAddresseeList, SIGNAL( clicked( QListViewItem * ) ), 131 connect( mAddresseeList, SIGNAL( clicked( QListViewItem * ) ),
131 SLOT( addSelected( QListViewItem * ) ) ); 132 SLOT( addSelected( QListViewItem * ) ) );
132 connect( mAddresseeList, SIGNAL( returnPressed( QListViewItem * ) ), 133 connect( mAddresseeList, SIGNAL( returnPressed( QListViewItem * ) ),
133 SLOT( selectNextItem( QListViewItem * ) ) ); 134 SLOT( selectNextItem( QListViewItem * ) ) );
134 135
135 } 136 }
136 137
137 mAddressBook = StdAddressBook::self( true ); 138 mAddressBook = StdAddressBook::self( true );
138 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook* ) ), 139 connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook* ) ),
139 SLOT( addressBookChanged() ) ); 140 SLOT( addressBookChanged() ) );
140#if 0 141#if 0
141 connect( mAddressBook, SIGNAL( loadingFinished( Resource* ) ), 142 connect( mAddressBook, SIGNAL( loadingFinished( Resource* ) ),
142 SLOT( addressBookChanged() ) ); 143 SLOT( addressBookChanged() ) );
143#endif 144#endif
144 loadAddressBook(); 145 loadAddressBook();
145 QValueList<int> splitterSize; 146 QValueList<int> splitterSize;
146 splitterSize.append( ( width() / 5 ) * 3 ); 147 splitterSize.append( ( width() / 5 ) * 3 );
147 splitterSize.append( ( width() / 5 ) *2 ); 148 splitterSize.append( ( width() / 5 ) *2 );
148 mMiniSplitter->setSizes( splitterSize ); 149 mMiniSplitter->setSizes( splitterSize );
149} 150}
150 151
151AddresseeDialog::~AddresseeDialog() 152AddresseeDialog::~AddresseeDialog()
152{ 153{
153 qDebug("DELETE AddresseeDialog "); 154 qDebug("DELETE AddresseeDialog ");
154} 155}
155 156
156void AddresseeDialog::loadAddressBook() 157void AddresseeDialog::loadAddressBook()
157{ 158{
158 mAddresseeList->clear(); 159 mAddresseeList->clear();
159 mItemDict.clear(); 160 mItemDict.clear();
160 if ( mAddresseeEdit->text().isEmpty() ) { 161 if ( mAddresseeEdit->text().isEmpty() ) {
161 AddressBook::Iterator it; 162 AddressBook::Iterator it;
@@ -231,133 +232,137 @@ void AddresseeDialog::addSelected( QListViewItem *item )
231 if ( !addrItem ) return; 232 if ( !addrItem ) return;
232 233
233 Addressee a = addrItem->addressee(); 234 Addressee a = addrItem->addressee();
234 235
235 QListViewItem *selectedItem = mSelectedDict.find( a.uid() ); 236 QListViewItem *selectedItem = mSelectedDict.find( a.uid() );
236 if ( !selectedItem ) { 237 if ( !selectedItem ) {
237 selectedItem = new AddresseeItem( mSelectedList, a ); 238 selectedItem = new AddresseeItem( mSelectedList, a );
238 mSelectedDict.insert( a.uid(), selectedItem ); 239 mSelectedDict.insert( a.uid(), selectedItem );
239 } 240 }
240 241
241} 242}
242 243
243void AddresseeDialog::removeSelected() 244void AddresseeDialog::removeSelected()
244{ 245{
245 QListViewItem *item = mSelectedList->selectedItem(); 246 QListViewItem *item = mSelectedList->selectedItem();
246 AddresseeItem *addrItem = (AddresseeItem *)( item ); 247 AddresseeItem *addrItem = (AddresseeItem *)( item );
247 if ( !addrItem ) return; 248 if ( !addrItem ) return;
248 QListViewItem *next = item->nextSibling(); 249 QListViewItem *next = item->nextSibling();
249 mSelectedDict.remove( addrItem->addressee().uid() ); 250 mSelectedDict.remove( addrItem->addressee().uid() );
250 delete addrItem; 251 delete addrItem;
251 if ( next ) 252 if ( next )
252 next->setSelected( true ); 253 next->setSelected( true );
253} 254}
254 255
255Addressee AddresseeDialog::addressee() 256Addressee AddresseeDialog::addressee()
256{ 257{
257 AddresseeItem *aItem = 0; 258 AddresseeItem *aItem = 0;
258 259
259 if ( mMultiple ) 260 if ( mMultiple )
260 aItem = (AddresseeItem *)( mSelectedList->firstChild() ); 261 aItem = (AddresseeItem *)( mSelectedList->firstChild() );
261 else 262 else
262 aItem = (AddresseeItem *)( mAddresseeList->selectedItem() ); 263 aItem = (AddresseeItem *)( mAddresseeList->selectedItem() );
263 264
264 if (aItem) return aItem->addressee(); 265 if (aItem) return aItem->addressee();
265 return Addressee(); 266 return Addressee();
266} 267}
267 268
268Addressee::List AddresseeDialog::addressees() 269Addressee::List AddresseeDialog::addressees()
269{ 270{
270 Addressee::List al; 271 Addressee::List al;
271 AddresseeItem *aItem = 0; 272 AddresseeItem *aItem = 0;
272 273
273 if ( mMultiple ) { 274 if ( mMultiple ) {
274 QListViewItem *item = mSelectedList->firstChild(); 275 QListViewItem *item = mSelectedList->firstChild();
275 while( item ) { 276 while( item ) {
276 aItem = (AddresseeItem *)( item ); 277 aItem = (AddresseeItem *)( item );
277 if ( aItem ) al.append( aItem->addressee() ); 278 if ( aItem ) al.append( aItem->addressee() );
278 item = item->nextSibling(); 279 item = item->nextSibling();
279 } 280 }
280 } 281 }
281 else 282 else
282 { 283 {
283 aItem = (AddresseeItem *)( mAddresseeList->selectedItem() ); 284 aItem = (AddresseeItem *)( mAddresseeList->selectedItem() );
284 if (aItem) al.append( aItem->addressee() ); 285 if (aItem) al.append( aItem->addressee() );
285 } 286 }
286 287
287 return al; 288 return al;
288} 289}
289 290
290Addressee AddresseeDialog::getAddressee( QWidget *parent ) 291Addressee AddresseeDialog::getAddressee( QWidget *parent )
291{ 292{
292 AddresseeDialog *dlg = new AddresseeDialog( parent ); 293 AddresseeDialog *dlg = new AddresseeDialog( parent );
293 Addressee addressee; 294 Addressee addressee;
294#ifdef DESKTOP_VERSION 295#ifdef DESKTOP_VERSION
295 static int geoX = 0; 296 static int geoX = 0;
296 static int geoY = 0; 297 static int geoY = 0;
297 static int geoW = 0; 298 static int geoW = 0;
298 static int geoH = 0; 299 static int geoH = 0;
299 if ( !geoX && ! geoY && !geoW &&!geoH ) { 300 if ( !geoX && ! geoY && !geoW &&!geoH ) {
300 geoX = dlg->geometry().x(); 301 geoX = dlg->geometry().x();
301 geoY = dlg->geometry().y(); 302 geoY = dlg->geometry().y();
302 geoW = dlg->width(); 303 geoW = dlg->width();
303 geoH = dlg->height(); 304 geoH = dlg->height();
304 } else { 305 } else {
305 dlg->show(); 306 dlg->show();
306 dlg->setGeometry(geoX , geoY,geoW , geoH ); 307 dlg->setGeometry(geoX , geoY,geoW , geoH );
307 308
308 } 309 }
309#endif 310#endif
310 int result = dlg->exec(); 311 int result = dlg->exec();
311#ifdef DESKTOP_VERSION 312#ifdef DESKTOP_VERSION
312 geoX = dlg->geometry().x(); 313 geoX = dlg->geometry().x();
313 geoY = dlg->geometry().y(); 314 geoY = dlg->geometry().y();
314 geoW = dlg->width(); 315 geoW = dlg->width();
315 geoH = dlg->height(); 316 geoH = dlg->height();
316#endif 317#endif
317 if ( result == QDialog::Accepted ) { 318 if ( result == QDialog::Accepted ) {
318 addressee = dlg->addressee(); 319 addressee = dlg->addressee();
319 } 320 }
320 321
321 delete dlg; 322 delete dlg;
322 return addressee; 323 return addressee;
323} 324}
324 325
325Addressee::List AddresseeDialog::getAddressees( QWidget *parent ) 326Addressee::List AddresseeDialog::getAddressees( QWidget *parent )
326{ 327{
327 AddresseeDialog *dlg = new AddresseeDialog( parent, true );
328 Addressee::List addressees; 328 Addressee::List addressees;
329 static bool running = false;
330 if ( running ) return addressees;
331 running = true;
332 AddresseeDialog *dlg = new AddresseeDialog( parent, true );
329 static int geoX = 0; 333 static int geoX = 0;
330 static int geoY = 0; 334 static int geoY = 0;
331 static int geoW = 0; 335 static int geoW = 0;
332 static int geoH = 0; 336 static int geoH = 0;
333 if ( QApplication::desktop()->width() <= 640 ) 337 if ( QApplication::desktop()->width() <= 640 )
334 dlg->showMaximized(); 338 dlg->showMaximized();
335 else { 339 else {
336 if ( !geoX && ! geoY && !geoW &&!geoH ) { 340 if ( !geoX && ! geoY && !geoW &&!geoH ) {
337 geoX = dlg->geometry().x(); 341 geoX = dlg->geometry().x();
338 geoY = dlg->geometry().y(); 342 geoY = dlg->geometry().y();
339 geoW = dlg->width(); 343 geoW = dlg->width();
340 geoH = dlg->height(); 344 geoH = dlg->height();
341 } else { 345 } else {
342 dlg->show(); 346 dlg->show();
343 dlg->setGeometry(geoX , geoY,geoW , geoH ); 347 dlg->setGeometry(geoX , geoY,geoW , geoH );
344 348
345 } 349 }
346 } 350 }
347 int result = dlg->exec(); 351 int result = dlg->exec();
348 geoX = dlg->geometry().x(); 352 geoX = dlg->geometry().x();
349 geoY = dlg->geometry().y(); 353 geoY = dlg->geometry().y();
350 geoW = dlg->width(); 354 geoW = dlg->width();
351 geoH = dlg->height(); 355 geoH = dlg->height();
352 if ( result == QDialog::Accepted ) { 356 if ( result == QDialog::Accepted ) {
353 addressees = dlg->addressees(); 357 addressees = dlg->addressees();
354 } 358 }
355 359
356 delete dlg; 360 delete dlg;
361 running = false;
357 return addressees; 362 return addressees;
358} 363}
359 364
360void AddresseeDialog::addressBookChanged() 365void AddresseeDialog::addressBookChanged()
361{ 366{
362 loadAddressBook(); 367 loadAddressBook();
363} 368}