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