-rw-r--r-- | kabc/addresseedialog.cpp | 65 |
1 files changed, 24 insertions, 41 deletions
diff --git a/kabc/addresseedialog.cpp b/kabc/addresseedialog.cpp index 0cf75a0..671787e 100644 --- a/kabc/addresseedialog.cpp +++ b/kabc/addresseedialog.cpp | |||
@@ -3,177 +3,160 @@ | |||
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 | ||
39 | using namespace KABC; | 39 | using namespace KABC; |
40 | 40 | ||
41 | AddresseeItem::AddresseeItem( QListView *parent, const Addressee &addressee ) : | 41 | AddresseeItem::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 | ||
50 | QString AddresseeItem::key( int column, bool ) const | 50 | QString 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 | ||
61 | AddresseeDialog::AddresseeDialog( QWidget *parent, bool multiple ) : | 61 | AddresseeDialog::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 | ||
67 | QWidget *topWidget = plainPage(); | ||
68 | 67 | ||
69 | QBoxLayout *topLayout = new QHBoxLayout( topWidget ); | 68 | KDGanttMinimizeSplitter* mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this ); |
70 | |||
71 | |||
72 | KDGanttMinimizeSplitter* mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, topWidget); | ||
73 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); | 69 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); |
74 | 70 | setMainWidget( mMiniSplitter ); | |
75 | topLayout->addWidget(mMiniSplitter ); | ||
76 | 71 | ||
77 | QWidget *listWidget = new QWidget( mMiniSplitter ); | 72 | QWidget *listWidget = new QWidget( mMiniSplitter ); |
78 | 73 | ||
79 | QVBoxLayout *listLayout = new QVBoxLayout (listWidget) ; | 74 | QVBoxLayout *listLayout = new QVBoxLayout (listWidget) ; |
80 | //topLayout->addLayout( listLayout ); | 75 | //topLayout->addLayout( listLayout ); |
81 | 76 | ||
82 | mAddresseeList = new KListView( listWidget ); | 77 | mAddresseeList = new KListView( listWidget ); |
83 | mAddresseeList->addColumn( i18n("Name") ); | 78 | mAddresseeList->addColumn( i18n("Name") ); |
84 | mAddresseeList->addColumn( i18n("Email") ); | 79 | mAddresseeList->addColumn( i18n("Email") ); |
85 | mAddresseeList->addColumn( i18n("Category") ); | 80 | mAddresseeList->addColumn( i18n("Category") ); |
86 | mAddresseeList->setAllColumnsShowFocus( true ); | 81 | mAddresseeList->setAllColumnsShowFocus( true ); |
87 | mAddresseeList->setFullWidth( true ); | 82 | mAddresseeList->setFullWidth( true ); |
88 | listLayout->addWidget( mAddresseeList ); | 83 | listLayout->addWidget( mAddresseeList ); |
89 | connect( mAddresseeList, SIGNAL( doubleClicked( QListViewItem * ) ), | 84 | connect( mAddresseeList, SIGNAL( doubleClicked( QListViewItem * ) ), |
90 | SLOT( slotOk() ) ); | 85 | SLOT( slotOk() ) ); |
91 | |||
92 | //QHBox* searchBox = new QHBox ( listWidget ); | 86 | //QHBox* searchBox = new QHBox ( listWidget ); |
93 | mAddresseeEdit = new QLineEdit( listWidget ); | 87 | QHBox * hb = new QHBox ( listWidget ); |
88 | listLayout->addWidget ( hb ); | ||
89 | mAddresseeEdit = new QLineEdit( hb ); | ||
94 | connect( mAddresseeEdit, SIGNAL( returnPressed() ), | 90 | connect( mAddresseeEdit, SIGNAL( returnPressed() ), |
95 | SLOT( loadAddressBook() ) ); | 91 | SLOT( loadAddressBook() ) ); |
96 | mAddresseeEdit->setFocus(); | 92 | mAddresseeEdit->setFocus(); |
97 | QPushButton *searchButton = new QPushButton( i18n("Search!"), listWidget ); | 93 | QPushButton *searchButton = new QPushButton( i18n("Search!"), hb ); |
98 | connect ( searchButton, SIGNAL( clicked() ), SLOT( loadAddressBook() ) ); | 94 | connect ( searchButton, SIGNAL( clicked() ), SLOT( loadAddressBook() ) ); |
99 | 95 | if ( mMultiple ) { | |
100 | QHBoxLayout *searchLayout = new QHBoxLayout (listLayout) ; | 96 | |
101 | searchLayout->addWidget( mAddresseeEdit ); | 97 | mSelectedList = new KListView( mMiniSplitter ); |
102 | searchLayout->addWidget( searchButton ); | 98 | mSelectedList->addColumn( i18n("Selected Name") ); |
103 | //listLayout->addWidget( searchBox ); | ||
104 | |||
105 | if ( mMultiple ) { | ||
106 | //QBoxLayout *selectedLayout = new QVBoxLayout; | ||
107 | //topLayout->addLayout( selectedLayout ); | ||
108 | //topLayout->setSpacing( spacingHint() ); | ||
109 | |||
110 | QVBox *selectedGroup = new QVBox( mMiniSplitter ); | ||
111 | new QLabel ( i18n("Selected:"), selectedGroup ); | ||
112 | //selectedLayout->addWidget( selectedGroup ); | ||
113 | |||
114 | mSelectedList = new KListView( selectedGroup ); | ||
115 | mSelectedList->addColumn( i18n("Name") ); | ||
116 | mSelectedList->addColumn( i18n("Email") ); | 99 | mSelectedList->addColumn( i18n("Email") ); |
117 | mSelectedList->setAllColumnsShowFocus( true ); | 100 | mSelectedList->setAllColumnsShowFocus( true ); |
118 | mSelectedList->setFullWidth( true ); | 101 | mSelectedList->setFullWidth( true ); |
119 | //connect( mSelectedList, SIGNAL( doubleClicked( QListViewItem * ) ), | 102 | //connect( mSelectedList, SIGNAL( doubleClicked( QListViewItem * ) ), |
120 | // SLOT( removeSelected() ) ); | 103 | // SLOT( removeSelected() ) ); |
121 | connect( mSelectedList, SIGNAL( clicked( QListViewItem * ) ), | 104 | connect( mSelectedList, SIGNAL( clicked( QListViewItem * ) ), |
122 | SLOT( removeSelected() ) ); | 105 | SLOT( removeSelected() ) ); |
123 | connect( mSelectedList, SIGNAL( returnPressed( QListViewItem *) ), | 106 | connect( mSelectedList, SIGNAL( returnPressed( QListViewItem *) ), |
124 | SLOT( removeSelected() ) ); | 107 | SLOT( removeSelected() ) ); |
125 | 108 | ||
126 | #if 0 | 109 | #if 0 |
127 | QPushButton *unselectButton = new QPushButton( i18n("Unselect"), selectedGroup ); | 110 | QPushButton *unselectButton = new QPushButton( i18n("Unselect"), selectedGroup ); |
128 | connect ( unselectButton, SIGNAL( clicked() ), SLOT( removeSelected() ) ); | 111 | connect ( unselectButton, SIGNAL( clicked() ), SLOT( removeSelected() ) ); |
129 | 112 | ||
130 | #endif | 113 | #endif |
131 | connect( mAddresseeList, SIGNAL( clicked( QListViewItem * ) ), | 114 | connect( mAddresseeList, SIGNAL( clicked( QListViewItem * ) ), |
132 | SLOT( addSelected( QListViewItem * ) ) ); | 115 | SLOT( addSelected( QListViewItem * ) ) ); |
133 | connect( mAddresseeList, SIGNAL( returnPressed( QListViewItem * ) ), | 116 | connect( mAddresseeList, SIGNAL( returnPressed( QListViewItem * ) ), |
134 | SLOT( selectNextItem( QListViewItem * ) ) ); | 117 | SLOT( selectNextItem( QListViewItem * ) ) ); |
135 | 118 | ||
136 | } | 119 | } |
137 | 120 | ||
138 | mAddressBook = StdAddressBook::self( true ); | 121 | mAddressBook = StdAddressBook::self( true ); |
139 | connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook* ) ), | 122 | connect( mAddressBook, SIGNAL( addressBookChanged( AddressBook* ) ), |
140 | SLOT( addressBookChanged() ) ); | 123 | SLOT( addressBookChanged() ) ); |
141 | #if 0 | 124 | #if 0 |
142 | connect( mAddressBook, SIGNAL( loadingFinished( Resource* ) ), | 125 | connect( mAddressBook, SIGNAL( loadingFinished( Resource* ) ), |
143 | SLOT( addressBookChanged() ) ); | 126 | SLOT( addressBookChanged() ) ); |
144 | #endif | 127 | #endif |
145 | loadAddressBook(); | 128 | loadAddressBook(); |
146 | QValueList<int> splitterSize; | 129 | QValueList<int> splitterSize; |
147 | splitterSize.append( ( width() / 5 ) * 3 ); | 130 | splitterSize.append( ( width() / 5 ) * 3 ); |
148 | splitterSize.append( ( width() / 5 ) *2 ); | 131 | splitterSize.append( ( width() / 5 ) *2 ); |
149 | mMiniSplitter->setSizes( splitterSize ); | 132 | mMiniSplitter->setSizes( splitterSize ); |
150 | } | 133 | } |
151 | 134 | ||
152 | AddresseeDialog::~AddresseeDialog() | 135 | AddresseeDialog::~AddresseeDialog() |
153 | { | 136 | { |
154 | qDebug("DELETE AddresseeDialog "); | 137 | qDebug("DELETE AddresseeDialog "); |
155 | } | 138 | } |
156 | 139 | ||
157 | void AddresseeDialog::loadAddressBook() | 140 | void AddresseeDialog::loadAddressBook() |
158 | { | 141 | { |
159 | mAddresseeList->clear(); | 142 | mAddresseeList->clear(); |
160 | mItemDict.clear(); | 143 | mItemDict.clear(); |
161 | if ( mAddresseeEdit->text().isEmpty() ) { | 144 | if ( mAddresseeEdit->text().isEmpty() ) { |
162 | AddressBook::Iterator it; | 145 | AddressBook::Iterator it; |
163 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { | 146 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { |
164 | if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) | 147 | if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) |
165 | continue; | 148 | continue; |
166 | new AddresseeItem( mAddresseeList, (*it) ); | 149 | new AddresseeItem( mAddresseeList, (*it) ); |
167 | } | 150 | } |
168 | return; | 151 | return; |
169 | } | 152 | } |
170 | //mAddresseeEdit->completionObject()->clear(); | 153 | //mAddresseeEdit->completionObject()->clear(); |
171 | QRegExp re; | 154 | QRegExp re; |
172 | re.setWildcard(true); // most people understand these better. | 155 | re.setWildcard(true); // most people understand these better. |
173 | re.setCaseSensitive(false); | 156 | re.setCaseSensitive(false); |
174 | re.setPattern( "*"+ mAddresseeEdit->text() + "*"); | 157 | re.setPattern( "*"+ mAddresseeEdit->text() + "*"); |
175 | 158 | ||
176 | AddressBook::Iterator it; | 159 | AddressBook::Iterator it; |
177 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { | 160 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { |
178 | if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) | 161 | if ( (*it).uid().left(2) == "la" && (*it).uid().left(19) == QString("last-syncAddressee-") ) |
179 | continue; | 162 | continue; |
@@ -269,100 +252,100 @@ Addressee AddresseeDialog::addressee() | |||
269 | Addressee::List AddresseeDialog::addressees() | 252 | Addressee::List AddresseeDialog::addressees() |
270 | { | 253 | { |
271 | Addressee::List al; | 254 | Addressee::List al; |
272 | AddresseeItem *aItem = 0; | 255 | AddresseeItem *aItem = 0; |
273 | 256 | ||
274 | if ( mMultiple ) { | 257 | if ( mMultiple ) { |
275 | QListViewItem *item = mSelectedList->firstChild(); | 258 | QListViewItem *item = mSelectedList->firstChild(); |
276 | while( item ) { | 259 | while( item ) { |
277 | aItem = (AddresseeItem *)( item ); | 260 | aItem = (AddresseeItem *)( item ); |
278 | if ( aItem ) al.append( aItem->addressee() ); | 261 | if ( aItem ) al.append( aItem->addressee() ); |
279 | item = item->nextSibling(); | 262 | item = item->nextSibling(); |
280 | } | 263 | } |
281 | } | 264 | } |
282 | else | 265 | else |
283 | { | 266 | { |
284 | aItem = (AddresseeItem *)( mAddresseeList->selectedItem() ); | 267 | aItem = (AddresseeItem *)( mAddresseeList->selectedItem() ); |
285 | if (aItem) al.append( aItem->addressee() ); | 268 | if (aItem) al.append( aItem->addressee() ); |
286 | } | 269 | } |
287 | 270 | ||
288 | return al; | 271 | return al; |
289 | } | 272 | } |
290 | 273 | ||
291 | Addressee AddresseeDialog::getAddressee( QWidget *parent ) | 274 | Addressee AddresseeDialog::getAddressee( QWidget *parent ) |
292 | { | 275 | { |
293 | AddresseeDialog *dlg = new AddresseeDialog( parent ); | 276 | AddresseeDialog *dlg = new AddresseeDialog( parent ); |
294 | Addressee addressee; | 277 | Addressee addressee; |
295 | #ifdef DESKTOP_VERSION | 278 | #ifdef DESKTOP_VERSION |
296 | static int geoX = 0; | 279 | static int geoX = 0; |
297 | static int geoY = 0; | 280 | static int geoY = 0; |
298 | static int geoW = 0; | 281 | static int geoW = 0; |
299 | static int geoH = 0; | 282 | static int geoH = 0; |
300 | if ( !geoX && ! geoY && !geoW &&!geoH ) { | 283 | if ( !geoX && ! geoY && !geoW &&!geoH ) { |
301 | geoX = dlg->geometry().x(); | 284 | geoX = dlg->geometry().x(); |
302 | geoY = dlg->geometry().y(); | 285 | geoY = dlg->geometry().y(); |
303 | geoW = dlg->width(); | 286 | geoW = dlg->width(); |
304 | geoH = dlg->height(); | 287 | geoH = dlg->height(); |
305 | } else { | 288 | } else { |
306 | dlg->show(); | 289 | dlg->show(); |
307 | dlg->setGeometry(geoX , geoY,geoW , geoH ); | 290 | dlg->setGeometry(geoX , geoY,geoW , geoH ); |
308 | 291 | ||
309 | } | 292 | } |
310 | #endif | 293 | #endif |
311 | int result = dlg->exec(); | 294 | int result = dlg->exec(); |
312 | #ifdef DESKTOP_VERSION | 295 | #ifdef DESKTOP_VERSION |
313 | geoX = dlg->geometry().x(); | 296 | geoX = dlg->geometry().x(); |
314 | geoY = dlg->geometry().y(); | 297 | geoY = dlg->geometry().y(); |
315 | geoW = dlg->width(); | 298 | geoW = dlg->width(); |
316 | geoH = dlg->height(); | 299 | geoH = dlg->height(); |
317 | #endif | 300 | #endif |
318 | if ( result == QDialog::Accepted ) { | 301 | if ( result == QDialog::Accepted ) { |
319 | addressee = dlg->addressee(); | 302 | addressee = dlg->addressee(); |
320 | } | 303 | } |
321 | 304 | ||
322 | delete dlg; | 305 | delete dlg; |
323 | return addressee; | 306 | return addressee; |
324 | } | 307 | } |
325 | 308 | ||
326 | Addressee::List AddresseeDialog::getAddressees( QWidget *parent ) | 309 | Addressee::List AddresseeDialog::getAddressees( QWidget *parent ) |
327 | { | 310 | { |
328 | Addressee::List addressees; | 311 | Addressee::List addressees; |
329 | static bool running = false; | 312 | static bool running = false; |
330 | if ( running ) return addressees; | 313 | if ( running ) return addressees; |
331 | running = true; | 314 | running = true; |
332 | AddresseeDialog *dlg = new AddresseeDialog( parent, true ); | 315 | AddresseeDialog *dlg = new AddresseeDialog( parent, true ); |
316 | #ifdef DESKTOP_VERSION | ||
333 | static int geoX = 0; | 317 | static int geoX = 0; |
334 | static int geoY = 0; | 318 | static int geoY = 0; |
335 | static int geoW = 0; | 319 | static int geoW = 0; |
336 | static int geoH = 0; | 320 | static int geoH = 0; |
337 | if ( QApplication::desktop()->width() <= 640 ) | 321 | if ( !geoX && ! geoY && !geoW &&!geoH ) { |
338 | dlg->showMaximized(); | 322 | geoX = dlg->geometry().x(); |
339 | else { | 323 | geoY = dlg->geometry().y(); |
340 | if ( !geoX && ! geoY && !geoW &&!geoH ) { | 324 | geoW = dlg->width(); |
341 | geoX = dlg->geometry().x(); | 325 | geoH = dlg->height(); |
342 | geoY = dlg->geometry().y(); | 326 | } |
343 | geoW = dlg->width(); | 327 | dlg->show(); |
344 | geoH = dlg->height(); | 328 | dlg->setGeometry(geoX , geoY,geoW , geoH ); |
345 | } else { | 329 | #else |
346 | dlg->show(); | 330 | dlg->showMaximized(); |
347 | dlg->setGeometry(geoX , geoY,geoW , geoH ); | 331 | #endif |
348 | |||
349 | } | ||
350 | } | ||
351 | int result = dlg->exec(); | 332 | int result = dlg->exec(); |
333 | #ifdef DESKTOP_VERSION | ||
352 | geoX = dlg->geometry().x(); | 334 | geoX = dlg->geometry().x(); |
353 | geoY = dlg->geometry().y(); | 335 | geoY = dlg->geometry().y(); |
354 | geoW = dlg->width(); | 336 | geoW = dlg->width(); |
355 | geoH = dlg->height(); | 337 | geoH = dlg->height(); |
338 | #endif | ||
356 | if ( result == QDialog::Accepted ) { | 339 | if ( result == QDialog::Accepted ) { |
357 | addressees = dlg->addressees(); | 340 | addressees = dlg->addressees(); |
358 | } | 341 | } |
359 | 342 | ||
360 | delete dlg; | 343 | delete dlg; |
361 | running = false; | 344 | running = false; |
362 | return addressees; | 345 | return addressees; |
363 | } | 346 | } |
364 | 347 | ||
365 | void AddresseeDialog::addressBookChanged() | 348 | void AddresseeDialog::addressBookChanged() |
366 | { | 349 | { |
367 | loadAddressBook(); | 350 | loadAddressBook(); |
368 | } | 351 | } |