summaryrefslogtreecommitdiff
authoreilers <eilers>2003-03-09 16:59:29 (UTC)
committer eilers <eilers>2003-03-09 16:59:29 (UTC)
commit06d6fd6ae517d560616d0864db29c7d8ae7a0a32 (patch) (unidiff)
tree36e4672fcded6fc2009a5af6a111d1d8d4dc6bb5
parent77c55432622d2821023ac73f47d3215d04cc4f58 (diff)
downloadopie-06d6fd6ae517d560616d0864db29c7d8ae7a0a32.zip
opie-06d6fd6ae517d560616d0864db29c7d8ae7a0a32.tar.gz
opie-06d6fd6ae517d560616d0864db29c7d8ae7a0a32.tar.bz2
Fixed missing table refresh after changing the primary contact order
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/addressbook/abtable.cpp13
-rw-r--r--core/pim/addressbook/abtable.h4
-rw-r--r--core/pim/addressbook/abview.cpp4
3 files changed, 19 insertions, 2 deletions
diff --git a/core/pim/addressbook/abtable.cpp b/core/pim/addressbook/abtable.cpp
index a829dc2..a2617fa 100644
--- a/core/pim/addressbook/abtable.cpp
+++ b/core/pim/addressbook/abtable.cpp
@@ -1,812 +1,821 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** Copyright (c) 2002 Stefan Eilers (eilers.stefan@epost.de) 3** Copyright (c) 2002 Stefan Eilers (eilers.stefan@epost.de)
4** 4**
5** This file is part of Qt Palmtop Environment. 5** This file is part of Qt Palmtop Environment.
6** 6**
7** This file may be distributed and/or modified under the terms of the 7** This file may be distributed and/or modified under the terms of the
8** GNU General Public License version 2 as published by the Free Software 8** GNU General Public License version 2 as published by the Free Software
9** Foundation and appearing in the file LICENSE.GPL included in the 9** Foundation and appearing in the file LICENSE.GPL included in the
10** packaging of this file. 10** packaging of this file.
11** 11**
12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14** 14**
15** See http://www.trolltech.com/gpl/ for GPL licensing information. 15** See http://www.trolltech.com/gpl/ for GPL licensing information.
16** 16**
17** Contact info@trolltech.com if any conditions of this licensing are 17** Contact info@trolltech.com if any conditions of this licensing are
18** not clear to you. 18** not clear to you.
19** 19**
20**********************************************************************/ 20**********************************************************************/
21 21
22 22
23#include <qpe/categoryselect.h> 23#include <qpe/categoryselect.h>
24#include <qpe/config.h> 24#include <qpe/config.h>
25#include <qpe/stringutil.h> 25#include <qpe/stringutil.h>
26#include <qpe/qcopenvelope_qws.h> 26#include <qpe/qcopenvelope_qws.h>
27#include <qpe/timestring.h> 27#include <qpe/timestring.h>
28#include <qpe/resource.h> 28#include <qpe/resource.h>
29 29
30#include <opie/orecordlist.h> 30#include <opie/orecordlist.h>
31 31
32#include <qasciidict.h> 32#include <qasciidict.h>
33#include <qdatetime.h> 33#include <qdatetime.h>
34#include <qfile.h> 34#include <qfile.h>
35#include <qregexp.h> 35#include <qregexp.h>
36#include <qmessagebox.h> 36#include <qmessagebox.h>
37 37
38#include "abtable.h" 38#include "abtable.h"
39 39
40#include <errno.h> 40#include <errno.h>
41#include <fcntl.h> 41#include <fcntl.h>
42#include <unistd.h> 42#include <unistd.h>
43#include <stdlib.h> 43#include <stdlib.h>
44 44
45#include <ctype.h> //toupper() for key hack 45#include <ctype.h> //toupper() for key hack
46 46
47/*! 47/*!
48 \class AbTableItem abtable.h 48 \class AbTableItem abtable.h
49 49
50 \brief QTableItem based class for showing a field of an entry 50 \brief QTableItem based class for showing a field of an entry
51*/ 51*/
52 52
53AbTableItem::AbTableItem( QTable *t, EditType et, const QString &s, 53AbTableItem::AbTableItem( QTable *t, EditType et, const QString &s,
54 const QString &secondSortKey) 54 const QString &secondSortKey)
55 : QTableItem( t, et, s ) 55 : QTableItem( t, et, s )
56{ 56{
57 // sortKey = s.lower() + QChar( '\0' ) + secondSortKey.lower(); 57 // sortKey = s.lower() + QChar( '\0' ) + secondSortKey.lower();
58 sortKey = Qtopia::buildSortKey( s, secondSortKey ); 58 sortKey = Qtopia::buildSortKey( s, secondSortKey );
59} 59}
60 60
61int AbTableItem::alignment() const 61int AbTableItem::alignment() const
62{ 62{
63 return AlignLeft|AlignVCenter; 63 return AlignLeft|AlignVCenter;
64} 64}
65 65
66QString AbTableItem::key() const 66QString AbTableItem::key() const
67{ 67{
68 return sortKey; 68 return sortKey;
69} 69}
70 70
71// A way to reset the item, without out doing a delete or a new... 71// A way to reset the item, without out doing a delete or a new...
72void AbTableItem::setItem( const QString &txt, const QString &secondKey ) 72void AbTableItem::setItem( const QString &txt, const QString &secondKey )
73{ 73{
74 setText( txt ); 74 setText( txt );
75 sortKey = Qtopia::buildSortKey( txt, secondKey ); 75 sortKey = Qtopia::buildSortKey( txt, secondKey );
76 76
77 // sortKey = txt.lower() + QChar( '\0' ) + secondKey.lower(); 77 // sortKey = txt.lower() + QChar( '\0' ) + secondKey.lower();
78} 78}
79 79
80/*! 80/*!
81 \class AbPickItem abtable.h 81 \class AbPickItem abtable.h
82 82
83 \brief QTableItem based class for showing slection of an entry 83 \brief QTableItem based class for showing slection of an entry
84*/ 84*/
85 85
86AbPickItem::AbPickItem( QTable *t ) : 86AbPickItem::AbPickItem( QTable *t ) :
87 QTableItem(t, WhenCurrent, "?") 87 QTableItem(t, WhenCurrent, "?")
88{ 88{
89} 89}
90 90
91QWidget *AbPickItem::createEditor() const 91QWidget *AbPickItem::createEditor() const
92{ 92{
93 QComboBox* combo = new QComboBox( table()->viewport() ); 93 QComboBox* combo = new QComboBox( table()->viewport() );
94 ( (AbPickItem*)this )->cb = combo; 94 ( (AbPickItem*)this )->cb = combo;
95 AbTable* t = static_cast<AbTable*>(table()); 95 AbTable* t = static_cast<AbTable*>(table());
96 QStringList c = t->choiceNames(); 96 QStringList c = t->choiceNames();
97 int cur = 0; 97 int cur = 0;
98 for (QStringList::ConstIterator it = c.begin(); it!=c.end(); ++it) { 98 for (QStringList::ConstIterator it = c.begin(); it!=c.end(); ++it) {
99 if ( *it == text() ) 99 if ( *it == text() )
100 cur = combo->count(); 100 cur = combo->count();
101 combo->insertItem(*it); 101 combo->insertItem(*it);
102 } 102 }
103 combo->setCurrentItem(cur); 103 combo->setCurrentItem(cur);
104 return combo; 104 return combo;
105} 105}
106 106
107void AbPickItem::setContentFromEditor( QWidget *w ) 107void AbPickItem::setContentFromEditor( QWidget *w )
108{ 108{
109 if ( w->inherits("QComboBox") ) 109 if ( w->inherits("QComboBox") )
110 setText( ( (QComboBox*)w )->currentText() ); 110 setText( ( (QComboBox*)w )->currentText() );
111 else 111 else
112 QTableItem::setContentFromEditor( w ); 112 QTableItem::setContentFromEditor( w );
113} 113}
114 114
115/*! 115/*!
116 \class AbTable abtable.h 116 \class AbTable abtable.h
117 117
118 \brief QTable based class for showing a list of entries 118 \brief QTable based class for showing a list of entries
119*/ 119*/
120 120
121AbTable::AbTable( const QValueList<int> order, QWidget *parent, const char *name ) 121AbTable::AbTable( const QValueList<int> order, QWidget *parent, const char *name )
122 : QTable( parent, name ), 122 : QTable( parent, name ),
123 lastSortCol( -1 ), 123 lastSortCol( -1 ),
124 asc( TRUE ), 124 asc( TRUE ),
125 intFields( order ), 125 intFields( order ),
126 enablePainting( true ), 126 enablePainting( true ),
127 columnVisible( true ), 127 columnVisible( true ),
128 countNested( 0 ) 128 countNested( 0 )
129{ 129{
130 //qWarning("C'tor start"); 130 //qWarning("C'tor start");
131 131
132 setSelectionMode( NoSelection ); 132 setSelectionMode( NoSelection );
133 init(); 133 init();
134 setSorting( TRUE ); 134 setSorting( TRUE );
135 connect( this, SIGNAL(clicked(int,int,int,const QPoint &)), 135 connect( this, SIGNAL(clicked(int,int,int,const QPoint &)),
136 this, SLOT(itemClicked(int,int)) ); 136 this, SLOT(itemClicked(int,int)) );
137 137
138 contactList.clear(); 138 contactList.clear();
139 //qWarning("C'tor end"); 139 //qWarning("C'tor end");
140} 140}
141 141
142AbTable::~AbTable() 142AbTable::~AbTable()
143{ 143{
144} 144}
145 145
146void AbTable::init() 146void AbTable::init()
147{ 147{
148 // :SX showChar = '\0'; 148 // :SX showChar = '\0';
149 setNumRows( 0 ); 149 setNumRows( 0 );
150 setNumCols( 2 ); 150 setNumCols( 2 );
151 151
152 horizontalHeader()->setLabel( 0, tr( "Full Name" )); 152 horizontalHeader()->setLabel( 0, tr( "Full Name" ));
153 horizontalHeader()->setLabel( 1, tr( "Contact" )); 153 horizontalHeader()->setLabel( 1, tr( "Contact" ));
154 setLeftMargin( 0 ); 154 setLeftMargin( 0 );
155 verticalHeader()->hide(); 155 verticalHeader()->hide();
156 columnVisible = true; 156 columnVisible = true;
157} 157}
158 158
159void AbTable::setContacts( const OContactAccess::List& viewList ) 159void AbTable::setContacts( const OContactAccess::List& viewList )
160{ 160{
161 //qWarning("AbTable::setContacts()"); 161 //qWarning("AbTable::setContacts()");
162 162
163 clear(); 163 clear();
164 m_viewList = viewList; 164 m_viewList = viewList;
165 165
166 setSorting( false ); 166 setSorting( false );
167 setPaintingEnabled( FALSE ); 167 setPaintingEnabled( FALSE );
168 168
169 OContactAccess::List::Iterator it; 169 OContactAccess::List::Iterator it;
170 setNumRows( m_viewList.count() ); 170 setNumRows( m_viewList.count() );
171 int row = 0; 171 int row = 0;
172 for ( it = m_viewList.begin(); it != m_viewList.end(); ++it ) 172 for ( it = m_viewList.begin(); it != m_viewList.end(); ++it )
173 insertIntoTable( *it, row++ ); 173 insertIntoTable( *it, row++ );
174 174
175 setSorting( true ); 175 setSorting( true );
176 176
177 resort(); 177 resort();
178 178
179 updateVisible(); 179 updateVisible();
180 180
181 setPaintingEnabled( TRUE ); 181 setPaintingEnabled( TRUE );
182 182
183} 183}
184 184
185void AbTable::setOrderedList( const QValueList<int> ordered )
186{
187 intFields = ordered;
188}
189
190
185bool AbTable::selectContact( int UID ) 191bool AbTable::selectContact( int UID )
186{ 192{
187 //qWarning( "AbTable::selectContact( %d )", UID ); 193 //qWarning( "AbTable::selectContact( %d )", UID );
188 int rows = numRows(); 194 int rows = numRows();
189 AbTableItem *abi; 195 AbTableItem *abi;
190 OContact* foundContact = 0l; 196 OContact* foundContact = 0l;
191 bool found = false; 197 bool found = false;
192 198
193 setPaintingEnabled( FALSE ); 199 setPaintingEnabled( FALSE );
194 for ( int r = 0; r < rows; ++r ) { 200 for ( int r = 0; r < rows; ++r ) {
195 abi = static_cast<AbTableItem*>( item(r, 0) ); 201 abi = static_cast<AbTableItem*>( item(r, 0) );
196 foundContact = &contactList[abi]; 202 foundContact = &contactList[abi];
197 if ( foundContact -> uid() == UID ){ 203 if ( foundContact -> uid() == UID ){
198 ensureCellVisible( r, 0 ); 204 ensureCellVisible( r, 0 );
199 setCurrentCell( r, 0 ); 205 setCurrentCell( r, 0 );
200 found = true; 206 found = true;
201 break; 207 break;
202 } 208 }
203 } 209 }
204 210
205 if ( !found ){ 211 if ( !found ){
206 ensureCellVisible( 0,0 ); 212 ensureCellVisible( 0,0 );
207 setCurrentCell( 0, 0 ); 213 setCurrentCell( 0, 0 );
208 } 214 }
209 215
210 setPaintingEnabled( TRUE ); 216 setPaintingEnabled( TRUE );
211 217
212 return true; 218 return true;
213} 219}
214 220
215void AbTable::insertIntoTable( const OContact& cnt, int row ) 221void AbTable::insertIntoTable( const OContact& cnt, int row )
216{ 222{
217 //qWarning( "void AbTable::insertIntoTable( const OContact& cnt, %d )", row ); 223 //qWarning( "void AbTable::insertIntoTable( const OContact& cnt, %d )", row );
218 QString strName; 224 QString strName;
219 ContactItem contactItem; 225 ContactItem contactItem;
220 226
221 strName = findContactName( cnt ); 227 strName = findContactName( cnt );
222 contactItem = findContactContact( cnt, row ); 228 contactItem = findContactContact( cnt, row );
223 229
224 AbTableItem *ati; 230 AbTableItem *ati;
225 ati = new AbTableItem( this, QTableItem::Never, strName, contactItem.value ); 231 ati = new AbTableItem( this, QTableItem::Never, strName, contactItem.value );
226 contactList.insert( ati, cnt ); 232 contactList.insert( ati, cnt );
227 setItem( row, 0, ati ); 233 setItem( row, 0, ati );
228 ati = new AbTableItem( this, QTableItem::Never, contactItem.value, strName); 234 ati = new AbTableItem( this, QTableItem::Never, contactItem.value, strName);
229 if ( !contactItem.icon.isNull() ) 235 if ( !contactItem.icon.isNull() )
230 ati->setPixmap( contactItem.icon ); 236 ati->setPixmap( contactItem.icon );
231 setItem( row, 1, ati ); 237 setItem( row, 1, ati );
232 238
233 //### cannot do this; table only has two columns at this point 239 //### cannot do this; table only has two columns at this point
234 // setItem( row, 2, new AbPickItem( this ) ); 240 // setItem( row, 2, new AbPickItem( this ) );
235 241
236} 242}
237 243
238 244
239 245
240void AbTable::columnClicked( int col ) 246void AbTable::columnClicked( int col )
241{ 247{
242 if ( !sorting() ) 248 if ( !sorting() )
243 return; 249 return;
244 250
245 if ( lastSortCol == -1 ) 251 if ( lastSortCol == -1 )
246 lastSortCol = col; 252 lastSortCol = col;
247 253
248 if ( col == lastSortCol ) { 254 if ( col == lastSortCol ) {
249 asc = !asc; 255 asc = !asc;
250 } else { 256 } else {
251 lastSortCol = col; 257 lastSortCol = col;
252 asc = TRUE; 258 asc = TRUE;
253 } 259 }
254 //QMessageBox::information( this, "resort", "columnClicked" ); 260 //QMessageBox::information( this, "resort", "columnClicked" );
255 resort(); 261 resort();
256} 262}
257 263
258void AbTable::resort() 264void AbTable::resort()
259{ 265{
260 //qWarning( "void AbTable::resort()" ); 266 //qWarning( "void AbTable::resort()" );
261 setPaintingEnabled( FALSE ); 267 setPaintingEnabled( FALSE );
262 if ( sorting() ) { 268 if ( sorting() ) {
263 if ( lastSortCol == -1 ) 269 if ( lastSortCol == -1 )
264 lastSortCol = 0; 270 lastSortCol = 0;
265 sortColumn( lastSortCol, asc, TRUE ); 271 sortColumn( lastSortCol, asc, TRUE );
266 //QMessageBox::information( this, "resort", "resort" ); 272 //QMessageBox::information( this, "resort", "resort" );
267 updateVisible(); 273 updateVisible();
268 } 274 }
269 setPaintingEnabled( TRUE ); 275 setPaintingEnabled( TRUE );
270} 276}
271 277
272OContact AbTable::currentEntry() 278OContact AbTable::currentEntry()
273{ 279{
274 //qWarning( "OContact AbTable::currentEntry()" ); 280 //qWarning( "OContact AbTable::currentEntry()" );
275 OContact cnt; 281 OContact cnt;
276 AbTableItem *abItem; 282 AbTableItem *abItem;
277 abItem = static_cast<AbTableItem*>(item( currentRow(), 0 )); 283 abItem = static_cast<AbTableItem*>(item( currentRow(), 0 ));
278 if ( abItem ) { 284 if ( abItem ) {
279 cnt = contactList[abItem]; 285 cnt = contactList[abItem];
280 //cnt = contactList[currentRow()]; 286 //cnt = contactList[currentRow()];
281 } 287 }
282 return cnt; 288 return cnt;
283} 289}
284 290
285int AbTable::currentEntry_UID() 291int AbTable::currentEntry_UID()
286{ 292{
287 return ( currentEntry().uid() ); 293 return ( currentEntry().uid() );
288} 294}
289 295
290void AbTable::clear() 296void AbTable::clear()
291{ 297{
292 //qWarning( "void AbTable::clear()" ); 298 //qWarning( "void AbTable::clear()" );
293 contactList.clear(); 299 contactList.clear();
294 300
295 setPaintingEnabled( FALSE ); 301 setPaintingEnabled( FALSE );
296 for ( int r = 0; r < numRows(); ++r ) { 302 for ( int r = 0; r < numRows(); ++r ) {
297 for ( int c = 0; c < numCols(); ++c ) { 303 for ( int c = 0; c < numCols(); ++c ) {
298 if ( cellWidget( r, c ) ) 304 if ( cellWidget( r, c ) )
299 clearCellWidget( r, c ); 305 clearCellWidget( r, c );
300 clearCell( r, c ); 306 clearCell( r, c );
301 } 307 }
302 } 308 }
303 setNumRows( 0 ); 309 setNumRows( 0 );
304 setPaintingEnabled( TRUE ); 310 setPaintingEnabled( TRUE );
305} 311}
306 312
307// Refresh updates column 2 if the contactsettings changed 313// Refresh updates column 2 if the contactsettings changed
308void AbTable::refresh() 314void AbTable::refresh()
309{ 315{
310 //qWarning( "void AbTable::refresh()" ); 316 //qWarning( "void AbTable::refresh()" );
311 int rows = numRows(); 317 int rows = numRows();
312 AbTableItem *abi; 318 AbTableItem *abi;
313 ContactItem contactItem; 319 ContactItem contactItem;
314 320
315 setPaintingEnabled( FALSE ); 321 setPaintingEnabled( FALSE );
316 for ( int r = 0; r < rows; ++r ) { 322 for ( int r = 0; r < rows; ++r ) {
317 abi = static_cast<AbTableItem*>( item(r, 0) ); 323 abi = static_cast<AbTableItem*>( item(r, 0) );
318 contactItem = findContactContact( contactList[abi], r ); 324 contactItem = findContactContact( contactList[abi], r );
319 static_cast<AbTableItem*>( item(r, 1) )->setItem( contactItem.value, abi->text() ); 325 static_cast<AbTableItem*>( item(r, 1) )->setItem( contactItem.value, abi->text() );
320 if ( !contactItem.icon.isNull() ) 326 if ( !contactItem.icon.isNull() ){
321 static_cast<AbTableItem*>( item(r, 1) )-> 327 static_cast<AbTableItem*>( item(r, 1) )->
322 setPixmap( contactItem.icon ); 328 setPixmap( contactItem.icon );
323 329 }else{
330 static_cast<AbTableItem*>( item(r, 1) )->
331 setPixmap( QPixmap() );
332 }
324 } 333 }
325 resort(); 334 resort();
326 setPaintingEnabled( TRUE ); 335 setPaintingEnabled( TRUE );
327} 336}
328 337
329void AbTable::keyPressEvent( QKeyEvent *e ) 338void AbTable::keyPressEvent( QKeyEvent *e )
330{ 339{
331 char key = toupper( e->ascii() ); 340 char key = toupper( e->ascii() );
332 341
333 if ( key >= 'A' && key <= 'Z' ) 342 if ( key >= 'A' && key <= 'Z' )
334 moveTo( key ); 343 moveTo( key );
335 344
336 //qWarning("Received key .."); 345 //qWarning("Received key ..");
337 switch( e->key() ) { 346 switch( e->key() ) {
338 case Qt::Key_Space: 347 case Qt::Key_Space:
339 case Qt::Key_Return: 348 case Qt::Key_Return:
340 case Qt::Key_Enter: 349 case Qt::Key_Enter:
341 emit signalSwitch(); 350 emit signalSwitch();
342 break; 351 break;
343 // case Qt::Key_Up: 352 // case Qt::Key_Up:
344 // qWarning("a"); 353 // qWarning("a");
345 // emit signalKeyUp(); 354 // emit signalKeyUp();
346 // break; 355 // break;
347 // case Qt::Key_Down: 356 // case Qt::Key_Down:
348 // qWarning("b"); 357 // qWarning("b");
349 // emit signalKeyDown(); 358 // emit signalKeyDown();
350 // break; 359 // break;
351 default: 360 default:
352 QTable::keyPressEvent( e ); 361 QTable::keyPressEvent( e );
353 } 362 }
354 363
355} 364}
356 365
357void AbTable::moveTo( char c ) 366void AbTable::moveTo( char c )
358{ 367{
359 qWarning( "void AbTable::moveTo( char c )" ); 368 qWarning( "void AbTable::moveTo( char c )" );
360 369
361 int rows = numRows(); 370 int rows = numRows();
362 QString value; 371 QString value;
363 AbTableItem *abi; 372 AbTableItem *abi;
364 int r; 373 int r;
365 if ( asc ) { 374 if ( asc ) {
366 r = 0; 375 r = 0;
367 while ( r < rows-1) { 376 while ( r < rows-1) {
368 abi = static_cast<AbTableItem*>( item(r, 0) ); 377 abi = static_cast<AbTableItem*>( item(r, 0) );
369 QChar first = abi->key()[0]; 378 QChar first = abi->key()[0];
370 //### is there a bug in QChar to char comparison??? 379 //### is there a bug in QChar to char comparison???
371 if ( first.row() || first.cell() >= c ) 380 if ( first.row() || first.cell() >= c )
372 break; 381 break;
373 r++; 382 r++;
374 } 383 }
375 } else { 384 } else {
376 //### should probably disable reverse sorting instead 385 //### should probably disable reverse sorting instead
377 r = rows - 1; 386 r = rows - 1;
378 while ( r > 0 ) { 387 while ( r > 0 ) {
379 abi = static_cast<AbTableItem*>( item(r, 0) ); 388 abi = static_cast<AbTableItem*>( item(r, 0) );
380 QChar first = abi->key()[0]; 389 QChar first = abi->key()[0];
381 //### is there a bug in QChar to char comparison??? 390 //### is there a bug in QChar to char comparison???
382 if ( first.row() || first.cell() >= c ) 391 if ( first.row() || first.cell() >= c )
383 break; 392 break;
384 r--; 393 r--;
385 } 394 }
386 } 395 }
387 setCurrentCell( r, currentColumn() ); 396 setCurrentCell( r, currentColumn() );
388} 397}
389 398
390 399
391QString AbTable::findContactName( const OContact &entry ) 400QString AbTable::findContactName( const OContact &entry )
392{ 401{
393 // We use the fileAs, then company, defaultEmail 402 // We use the fileAs, then company, defaultEmail
394 QString str; 403 QString str;
395 str = entry.fileAs(); 404 str = entry.fileAs();
396 if ( str.isEmpty() ) { 405 if ( str.isEmpty() ) {
397 str = entry.company(); 406 str = entry.company();
398 if ( str.isEmpty() ) { 407 if ( str.isEmpty() ) {
399 str = entry.defaultEmail(); 408 str = entry.defaultEmail();
400 } 409 }
401 } 410 }
402 return str; 411 return str;
403} 412}
404 413
405 414
406 415
407void AbTable::resizeRows() { 416void AbTable::resizeRows() {
408 /* 417 /*
409 if (numRows()) { 418 if (numRows()) {
410 for (int i = 0; i < numRows(); i++) { 419 for (int i = 0; i < numRows(); i++) {
411 setRowHeight( i, size ); 420 setRowHeight( i, size );
412 } 421 }
413 } 422 }
414 updateVisible(); 423 updateVisible();
415 */ 424 */
416} 425}
417 426
418 427
419void AbTable::realignTable() 428void AbTable::realignTable()
420{ 429{
421 //qWarning( "void AbTable::realignTable()" ); 430 //qWarning( "void AbTable::realignTable()" );
422 431
423 setPaintingEnabled( FALSE ); 432 setPaintingEnabled( FALSE );
424 433
425 resizeRows(); 434 resizeRows();
426 fitColumns(); 435 fitColumns();
427 436
428 setPaintingEnabled( TRUE ); 437 setPaintingEnabled( TRUE );
429 438
430} 439}
431 440
432 441
433 442
434 443
435#if QT_VERSION <= 230 444#if QT_VERSION <= 230
436#ifndef SINGLE_APP 445#ifndef SINGLE_APP
437void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch ) 446void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch )
438{ 447{
439 // Region of the rect we should draw 448 // Region of the rect we should draw
440 QRegion reg( QRect( cx, cy, cw, ch ) ); 449 QRegion reg( QRect( cx, cy, cw, ch ) );
441 // Subtract the table from it 450 // Subtract the table from it
442 reg = reg.subtract( QRect( QPoint( 0, 0 ), tableSize() ) ); 451 reg = reg.subtract( QRect( QPoint( 0, 0 ), tableSize() ) );
443 // And draw the rectangles (transformed as needed) 452 // And draw the rectangles (transformed as needed)
444 QArray<QRect> r = reg.rects(); 453 QArray<QRect> r = reg.rects();
445 for (unsigned int i=0; i<r.count(); i++) 454 for (unsigned int i=0; i<r.count(); i++)
446 p->fillRect( r[i], colorGroup().brush( QColorGroup::Base ) ); 455 p->fillRect( r[i], colorGroup().brush( QColorGroup::Base ) );
447} 456}
448#endif 457#endif
449#endif 458#endif
450 459
451 460
452// int AbTable::rowHeight( int ) const 461// int AbTable::rowHeight( int ) const
453// { 462// {
454// return 18; 463// return 18;
455// } 464// }
456 465
457// int AbTable::rowPos( int row ) const 466// int AbTable::rowPos( int row ) const
458// { 467// {
459// return 18*row; 468// return 18*row;
460// } 469// }
461 470
462// int AbTable::rowAt( int pos ) const 471// int AbTable::rowAt( int pos ) const
463// { 472// {
464// return QMIN( pos/18, numRows()-1 ); 473// return QMIN( pos/18, numRows()-1 );
465// } 474// }
466 475
467 476
468 477
469void AbTable::fitColumns() 478void AbTable::fitColumns()
470{ 479{
471 //qWarning( "void AbTable::fitColumns()" ); 480 //qWarning( "void AbTable::fitColumns()" );
472 int contentsWidth = visibleWidth() / 2; // :SX Why too low 481 int contentsWidth = visibleWidth() / 2; // :SX Why too low
473 // Fix to better value 482 // Fix to better value
474 // contentsWidth = 130; 483 // contentsWidth = 130;
475 484
476 setPaintingEnabled( FALSE ); 485 setPaintingEnabled( FALSE );
477 486
478 if ( columnVisible == false ){ 487 if ( columnVisible == false ){
479 showColumn(0); 488 showColumn(0);
480 columnVisible = true; 489 columnVisible = true;
481 } 490 }
482 491
483 //qWarning("Width: %d", contentsWidth); 492 //qWarning("Width: %d", contentsWidth);
484 493
485 setColumnWidth( 0, contentsWidth ); 494 setColumnWidth( 0, contentsWidth );
486 adjustColumn(1); 495 adjustColumn(1);
487 if ( columnWidth(1) < contentsWidth ) 496 if ( columnWidth(1) < contentsWidth )
488 setColumnWidth( 1, contentsWidth ); 497 setColumnWidth( 1, contentsWidth );
489 498
490 setPaintingEnabled( TRUE ); 499 setPaintingEnabled( TRUE );
491} 500}
492 501
493void AbTable::show() 502void AbTable::show()
494{ 503{
495 //qWarning( "void AbTable::show()" ); 504 //qWarning( "void AbTable::show()" );
496 realignTable(); 505 realignTable();
497 QTable::show(); 506 QTable::show();
498} 507}
499 508
500void AbTable::setChoiceNames( const QStringList& list) 509void AbTable::setChoiceNames( const QStringList& list)
501{ 510{
502 choicenames = list; 511 choicenames = list;
503 if ( choicenames.isEmpty() ) { 512 if ( choicenames.isEmpty() ) {
504 // hide pick column 513 // hide pick column
505 setNumCols( 2 ); 514 setNumCols( 2 );
506 } else { 515 } else {
507 // show pick column 516 // show pick column
508 setNumCols( 3 ); 517 setNumCols( 3 );
509 setColumnWidth( 2, fontMetrics().width(tr( "Pick" ))+8 ); 518 setColumnWidth( 2, fontMetrics().width(tr( "Pick" ))+8 );
510 horizontalHeader()->setLabel( 2, tr( "Pick" )); 519 horizontalHeader()->setLabel( 2, tr( "Pick" ));
511 } 520 }
512 fitColumns(); 521 fitColumns();
513} 522}
514 523
515void AbTable::itemClicked(int,int col) 524void AbTable::itemClicked(int,int col)
516{ 525{
517 //qWarning( "AbTable::itemClicked(int, col:%d)", col); 526 //qWarning( "AbTable::itemClicked(int, col:%d)", col);
518 if ( col == 2 ) { 527 if ( col == 2 ) {
519 return; 528 return;
520 } else { 529 } else {
521 // qWarning ("Emitting signalSwitch()"); 530 // qWarning ("Emitting signalSwitch()");
522 emit signalSwitch(); 531 emit signalSwitch();
523 } 532 }
524} 533}
525 534
526QStringList AbTable::choiceNames() const 535QStringList AbTable::choiceNames() const
527{ 536{
528 return choicenames; 537 return choicenames;
529} 538}
530 539
531void AbTable::setChoiceSelection( const QValueList<int>& list ) 540void AbTable::setChoiceSelection( const QValueList<int>& list )
532{ 541{
533 intFields = list; 542 intFields = list;
534} 543}
535 544
536QStringList AbTable::choiceSelection(int /*index*/) const 545QStringList AbTable::choiceSelection(int /*index*/) const
537{ 546{
538 QStringList r; 547 QStringList r;
539 /* ###### 548 /* ######
540 549
541 QString selname = choicenames.at(index); 550 QString selname = choicenames.at(index);
542 for (each row) { 551 for (each row) {
543 OContact *c = contactForRow(row); 552 OContact *c = contactForRow(row);
544 if ( text(row,2) == selname ) { 553 if ( text(row,2) == selname ) {
545 r.append(c->email); 554 r.append(c->email);
546 } 555 }
547 } 556 }
548 557
549 */ 558 */
550 return r; 559 return r;
551} 560}
552 561
553 562
554 563
555 564
556void AbTable::updateVisible() 565void AbTable::updateVisible()
557{ 566{
558 //qWarning("void AbTable::updateVisible()"); 567 //qWarning("void AbTable::updateVisible()");
559 568
560 int visible, 569 int visible,
561 totalRows, 570 totalRows,
562 row, 571 row,
563 selectedRow = 0; 572 selectedRow = 0;
564 573
565 visible = 0; 574 visible = 0;
566 575
567 setPaintingEnabled( FALSE ); 576 setPaintingEnabled( FALSE );
568 577
569 realignTable(); 578 realignTable();
570 579
571 totalRows = numRows(); 580 totalRows = numRows();
572 for ( row = 0; row < totalRows; row++ ) { 581 for ( row = 0; row < totalRows; row++ ) {
573 if ( rowHeight(row) == 0 ) { 582 if ( rowHeight(row) == 0 ) {
574 showRow( row ); 583 showRow( row );
575 adjustRow( row ); 584 adjustRow( row );
576 if ( isSelected( row,0 ) || isSelected( row,1 ) ) 585 if ( isSelected( row,0 ) || isSelected( row,1 ) )
577 selectedRow = row; 586 selectedRow = row;
578 } 587 }
579 visible++; 588 visible++;
580 } 589 }
581 590
582 if ( selectedRow ) 591 if ( selectedRow )
583 setCurrentCell( selectedRow, 0 ); 592 setCurrentCell( selectedRow, 0 );
584 593
585 if ( !visible ) 594 if ( !visible )
586 setCurrentCell( -1, 0 ); 595 setCurrentCell( -1, 0 );
587 596
588 setPaintingEnabled( TRUE ); 597 setPaintingEnabled( TRUE );
589} 598}
590 599
591 600
592void AbTable::setPaintingEnabled( bool e ) 601void AbTable::setPaintingEnabled( bool e )
593{ 602{
594 //qWarning("IN void AbTable::setPaintingEnabled( %d )->Nested: %d", e, countNested ); 603 //qWarning("IN void AbTable::setPaintingEnabled( %d )->Nested: %d", e, countNested );
595 604
596 if ( e ) { 605 if ( e ) {
597 if ( countNested > 0 ) 606 if ( countNested > 0 )
598 --countNested; 607 --countNested;
599 if ( ! countNested ){ 608 if ( ! countNested ){
600 setUpdatesEnabled( true ); 609 setUpdatesEnabled( true );
601 enablePainting = true; 610 enablePainting = true;
602 rowHeightChanged( 0 ); 611 rowHeightChanged( 0 );
603 viewport()->update(); 612 viewport()->update();
604 } 613 }
605 } else { 614 } else {
606 ++countNested; 615 ++countNested;
607 enablePainting = false; 616 enablePainting = false;
608 setUpdatesEnabled( false ); 617 setUpdatesEnabled( false );
609 } 618 }
610 //qWarning("OUT void AbTable::setPaintingEnabled( %d )->Nested: %d", e, countNested ); 619 //qWarning("OUT void AbTable::setPaintingEnabled( %d )->Nested: %d", e, countNested );
611} 620}
612 621
613void AbTable::viewportPaintEvent( QPaintEvent* e ) { 622void AbTable::viewportPaintEvent( QPaintEvent* e ) {
614 //qWarning(" void AbTable::viewportPaintEvent( QPaintEvent* e ) -> %d", enablePainting); 623 //qWarning(" void AbTable::viewportPaintEvent( QPaintEvent* e ) -> %d", enablePainting);
615 if ( enablePainting ) 624 if ( enablePainting )
616 QTable::viewportPaintEvent( e ); 625 QTable::viewportPaintEvent( e );
617} 626}
618 627
619void AbTable::paintCell(QPainter* p, int row, int col, const QRect& cr, bool ) { 628void AbTable::paintCell(QPainter* p, int row, int col, const QRect& cr, bool ) {
620 const QColorGroup &cg = colorGroup(); 629 const QColorGroup &cg = colorGroup();
621 630
622 p->save(); 631 p->save();
623 632
624 // Paint alternating background bars 633 // Paint alternating background bars
625 if ( (row % 2 ) == 0 ) { 634 if ( (row % 2 ) == 0 ) {
626 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) ); 635 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) );
627 p->setPen( QPen( cg.text() ) ); 636 p->setPen( QPen( cg.text() ) );
628 } 637 }
629 else { 638 else {
630 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Background ) ); 639 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Background ) );
631 p->setPen( QPen( cg.buttonText() ) ); 640 p->setPen( QPen( cg.buttonText() ) );
632 } 641 }
633 642
634 QFont f = p->font(); 643 QFont f = p->font();
635 QFontMetrics fm(f); 644 QFontMetrics fm(f);
636 645
637 int marg = 2; 646 int marg = 2;
638 int x = 0; 647 int x = 0;
639 int y = ( cr.height() - 14 ) / 2; 648 int y = ( cr.height() - 14 ) / 2;
640 649
641 QPixmap pic = pixmap( row, col ); 650 QPixmap pic = pixmap( row, col );
642 if ( !pic.isNull() ) 651 if ( !pic.isNull() )
643 { 652 {
644 p->drawPixmap( x + marg, y, pixmap( row, col ) ); 653 p->drawPixmap( x + marg, y, pixmap( row, col ) );
645 p->drawText( x + marg + pixmap( row, col ).width() + 4,2 + fm.ascent(), text( row, col ) ); 654 p->drawText( x + marg + pixmap( row, col ).width() + 4,2 + fm.ascent(), text( row, col ) );
646 } 655 }
647 else 656 else
648 { 657 {
649 p->drawText( x + marg,2 + fm.ascent(), text( row, col ) ); 658 p->drawText( x + marg,2 + fm.ascent(), text( row, col ) );
650 } 659 }
651 660
652 p->restore(); 661 p->restore();
653} 662}
654 663
655void AbTable::rowHeightChanged( int row ) 664void AbTable::rowHeightChanged( int row )
656{ 665{
657 if ( enablePainting ) 666 if ( enablePainting )
658 QTable::rowHeightChanged( row ); 667 QTable::rowHeightChanged( row );
659} 668}
660ContactItem AbTable::findContactContact( const OContact &entry, int /* row */ ) 669ContactItem AbTable::findContactContact( const OContact &entry, int /* row */ )
661{ 670{
662 671
663 ContactItem item; 672 ContactItem item;
664 673
665 item.value = ""; 674 item.value = "";
666 675
667 for ( QValueList<int>::ConstIterator it = intFields.begin(); 676 for ( QValueList<int>::ConstIterator it = intFields.begin();
668 it != intFields.end(); ++it ) { 677 it != intFields.end(); ++it ) {
669 switch ( *it ) { 678 switch ( *it ) {
670 default: 679 default:
671 break; 680 break;
672 case Qtopia::Title: 681 case Qtopia::Title:
673 item.value = entry.title(); 682 item.value = entry.title();
674 break; 683 break;
675 case Qtopia::Suffix: 684 case Qtopia::Suffix:
676 item.value = entry.suffix(); 685 item.value = entry.suffix();
677 break; 686 break;
678 case Qtopia::FileAs: 687 case Qtopia::FileAs:
679 item.value = entry.fileAs(); 688 item.value = entry.fileAs();
680 break; 689 break;
681 case Qtopia::DefaultEmail: 690 case Qtopia::DefaultEmail:
682 item.value = entry.defaultEmail(); 691 item.value = entry.defaultEmail();
683 if ( !item.value.isEmpty() ) 692 if ( !item.value.isEmpty() )
684 item.icon = Resource::loadPixmap( "addressbook/email" ); 693 item.icon = Resource::loadPixmap( "addressbook/email" );
685 break; 694 break;
686 case Qtopia::Emails: 695 case Qtopia::Emails:
687 item.value = entry.emails(); 696 item.value = entry.emails();
688 if ( !item.value.isEmpty() ) 697 if ( !item.value.isEmpty() )
689 item.icon = Resource::loadPixmap( "addressbook/email" ); 698 item.icon = Resource::loadPixmap( "addressbook/email" );
690 break; 699 break;
691 case Qtopia::HomeStreet: 700 case Qtopia::HomeStreet:
692 item.value = entry.homeStreet(); 701 item.value = entry.homeStreet();
693 break; 702 break;
694 case Qtopia::HomeCity: 703 case Qtopia::HomeCity:
695 item.value = entry.homeCity(); 704 item.value = entry.homeCity();
696 break; 705 break;
697 case Qtopia::HomeState: 706 case Qtopia::HomeState:
698 item.value = entry.homeState(); 707 item.value = entry.homeState();
699 break; 708 break;
700 case Qtopia::HomeZip: 709 case Qtopia::HomeZip:
701 item.value = entry.homeZip(); 710 item.value = entry.homeZip();
702 break; 711 break;
703 case Qtopia::HomeCountry: 712 case Qtopia::HomeCountry:
704 item.value = entry.homeCountry(); 713 item.value = entry.homeCountry();
705 break; 714 break;
706 case Qtopia::HomePhone: 715 case Qtopia::HomePhone:
707 item.value = entry.homePhone(); 716 item.value = entry.homePhone();
708 if ( !item.value.isEmpty() ) 717 if ( !item.value.isEmpty() )
709 item.icon = Resource::loadPixmap( "addressbook/phonehome" ); 718 item.icon = Resource::loadPixmap( "addressbook/phonehome" );
710 break; 719 break;
711 case Qtopia::HomeFax: 720 case Qtopia::HomeFax:
712 item.value = entry.homeFax(); 721 item.value = entry.homeFax();
713 if ( !item.value.isEmpty() ) 722 if ( !item.value.isEmpty() )
714 item.icon = Resource::loadPixmap( "addressbook/faxhome" ); 723 item.icon = Resource::loadPixmap( "addressbook/faxhome" );
715 break; 724 break;
716 case Qtopia::HomeMobile: 725 case Qtopia::HomeMobile:
717 item.value = entry.homeMobile(); 726 item.value = entry.homeMobile();
718 if ( !item.value.isEmpty() ) 727 if ( !item.value.isEmpty() )
719 item.icon = Resource::loadPixmap( "addressbook/mobilehome" ); 728 item.icon = Resource::loadPixmap( "addressbook/mobilehome" );
720 break; 729 break;
721 case Qtopia::HomeWebPage: 730 case Qtopia::HomeWebPage:
722 item.value = entry.homeWebpage(); 731 item.value = entry.homeWebpage();
723 if ( !item.value.isEmpty() ) 732 if ( !item.value.isEmpty() )
724 item.icon = Resource::loadPixmap( "addressbook/webpagehome" ); 733 item.icon = Resource::loadPixmap( "addressbook/webpagehome" );
725 break; 734 break;
726 case Qtopia::Company: 735 case Qtopia::Company:
727 item.value = entry.company(); 736 item.value = entry.company();
728 break; 737 break;
729 case Qtopia::BusinessCity: 738 case Qtopia::BusinessCity:
730 item.value = entry.businessCity(); 739 item.value = entry.businessCity();
731 break; 740 break;
732 case Qtopia::BusinessStreet: 741 case Qtopia::BusinessStreet:
733 item.value = entry.businessStreet(); 742 item.value = entry.businessStreet();
734 break; 743 break;
735 case Qtopia::BusinessZip: 744 case Qtopia::BusinessZip:
736 item.value = entry.businessZip(); 745 item.value = entry.businessZip();
737 break; 746 break;
738 case Qtopia::BusinessCountry: 747 case Qtopia::BusinessCountry:
739 item.value = entry.businessCountry(); 748 item.value = entry.businessCountry();
740 break; 749 break;
741 case Qtopia::BusinessWebPage: 750 case Qtopia::BusinessWebPage:
742 item.value = entry.businessWebpage(); 751 item.value = entry.businessWebpage();
743 if ( !item.value.isEmpty() ) 752 if ( !item.value.isEmpty() )
744 item.icon = Resource::loadPixmap( "addressbook/webpagework" ); 753 item.icon = Resource::loadPixmap( "addressbook/webpagework" );
745 break; 754 break;
746 case Qtopia::JobTitle: 755 case Qtopia::JobTitle:
747 item.value = entry.jobTitle(); 756 item.value = entry.jobTitle();
748 break; 757 break;
749 case Qtopia::Department: 758 case Qtopia::Department:
750 item.value = entry.department(); 759 item.value = entry.department();
751 break; 760 break;
752 case Qtopia::Office: 761 case Qtopia::Office:
753 item.value = entry.office(); 762 item.value = entry.office();
754 break; 763 break;
755 case Qtopia::BusinessPhone: 764 case Qtopia::BusinessPhone:
756 item.value = entry.businessPhone(); 765 item.value = entry.businessPhone();
757 if ( !item.value.isEmpty() ) 766 if ( !item.value.isEmpty() )
758 item.icon = Resource::loadPixmap( "addressbook/phonework" ); 767 item.icon = Resource::loadPixmap( "addressbook/phonework" );
759 break; 768 break;
760 case Qtopia::BusinessFax: 769 case Qtopia::BusinessFax:
761 item.value = entry.businessFax(); 770 item.value = entry.businessFax();
762 if ( !item.value.isEmpty() ) 771 if ( !item.value.isEmpty() )
763 item.icon = Resource::loadPixmap( "addressbook/faxwork" ); 772 item.icon = Resource::loadPixmap( "addressbook/faxwork" );
764 break; 773 break;
765 case Qtopia::BusinessMobile: 774 case Qtopia::BusinessMobile:
766 item.value = entry.businessMobile(); 775 item.value = entry.businessMobile();
767 if ( !item.value.isEmpty() ) 776 if ( !item.value.isEmpty() )
768 item.icon = Resource::loadPixmap( "addressbook/mobilework" ); 777 item.icon = Resource::loadPixmap( "addressbook/mobilework" );
769 break; 778 break;
770 case Qtopia::BusinessPager: 779 case Qtopia::BusinessPager:
771 item.value = entry.businessPager(); 780 item.value = entry.businessPager();
772 break; 781 break;
773 case Qtopia::Profession: 782 case Qtopia::Profession:
774 item.value = entry.profession(); 783 item.value = entry.profession();
775 break; 784 break;
776 case Qtopia::Assistant: 785 case Qtopia::Assistant:
777 item.value = entry.assistant(); 786 item.value = entry.assistant();
778 break; 787 break;
779 case Qtopia::Manager: 788 case Qtopia::Manager:
780 item.value = entry.manager(); 789 item.value = entry.manager();
781 break; 790 break;
782 case Qtopia::Spouse: 791 case Qtopia::Spouse:
783 item.value = entry.spouse(); 792 item.value = entry.spouse();
784 break; 793 break;
785 case Qtopia::Gender: 794 case Qtopia::Gender:
786 item.value = entry.gender(); 795 item.value = entry.gender();
787 break; 796 break;
788 case Qtopia::Birthday: 797 case Qtopia::Birthday:
789 if ( ! entry.birthday().isNull() ){ 798 if ( ! entry.birthday().isNull() ){
790 item.value = TimeString::numberDateString( entry.birthday() ); 799 item.value = TimeString::numberDateString( entry.birthday() );
791 } 800 }
792 break; 801 break;
793 case Qtopia::Anniversary: 802 case Qtopia::Anniversary:
794 if ( ! entry.anniversary().isNull() ){ 803 if ( ! entry.anniversary().isNull() ){
795 item.value = TimeString::numberDateString( entry.anniversary() ); 804 item.value = TimeString::numberDateString( entry.anniversary() );
796 } 805 }
797 break; 806 break;
798 case Qtopia::Nickname: 807 case Qtopia::Nickname:
799 item.value = entry.nickname(); 808 item.value = entry.nickname();
800 break; 809 break;
801 case Qtopia::Children: 810 case Qtopia::Children:
802 item.value = entry.children(); 811 item.value = entry.children();
803 break; 812 break;
804 case Qtopia::Notes: 813 case Qtopia::Notes:
805 item.value = entry.notes(); 814 item.value = entry.notes();
806 break; 815 break;
807 } 816 }
808 if ( !item.value.isEmpty() ) 817 if ( !item.value.isEmpty() )
809 break; 818 break;
810 } 819 }
811 return item; 820 return item;
812} 821}
diff --git a/core/pim/addressbook/abtable.h b/core/pim/addressbook/abtable.h
index 4e6b294..0f7bc29 100644
--- a/core/pim/addressbook/abtable.h
+++ b/core/pim/addressbook/abtable.h
@@ -1,148 +1,152 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** Copyright (c) 2002 Stefan Eilers (eilers.stefan@epost.de) 3** Copyright (c) 2002 Stefan Eilers (eilers.stefan@epost.de)
4** 4**
5** This file is part of Qt Palmtop Environment. 5** This file is part of Qt Palmtop Environment.
6** 6**
7** This file may be distributed and/or modified under the terms of the 7** This file may be distributed and/or modified under the terms of the
8** GNU General Public License version 2 as published by the Free Software 8** GNU General Public License version 2 as published by the Free Software
9** Foundation and appearing in the file LICENSE.GPL included in the 9** Foundation and appearing in the file LICENSE.GPL included in the
10** packaging of this file. 10** packaging of this file.
11** 11**
12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14** 14**
15** See http://www.trolltech.com/gpl/ for GPL licensing information. 15** See http://www.trolltech.com/gpl/ for GPL licensing information.
16** 16**
17** Contact info@trolltech.com if any conditions of this licensing are 17** Contact info@trolltech.com if any conditions of this licensing are
18** not clear to you. 18** not clear to you.
19** 19**
20**********************************************************************/ 20**********************************************************************/
21 21
22#ifndef ABTABLE_H 22#ifndef ABTABLE_H
23#define ABTABLE_H 23#define ABTABLE_H
24 24
25#include <qpe/categories.h> 25#include <qpe/categories.h>
26#include <opie/ocontact.h> 26#include <opie/ocontact.h>
27#include <opie/ocontactaccess.h> 27#include <opie/ocontactaccess.h>
28 28
29#include <qmap.h> 29#include <qmap.h>
30#include <qtable.h> 30#include <qtable.h>
31#include <qstringlist.h> 31#include <qstringlist.h>
32#include <qcombobox.h> 32#include <qcombobox.h>
33#include <qpixmap.h> 33#include <qpixmap.h>
34 34
35class AbTableItem : public QTableItem 35class AbTableItem : public QTableItem
36{ 36{
37public: 37public:
38 AbTableItem( QTable *t, EditType et, const QString &s, 38 AbTableItem( QTable *t, EditType et, const QString &s,
39 const QString &secondSortKey); 39 const QString &secondSortKey);
40 QString entryKey() const; 40 QString entryKey() const;
41 void setEntryKey( const QString & k ); 41 void setEntryKey( const QString & k );
42 virtual int alignment() const; 42 virtual int alignment() const;
43 virtual QString key() const; 43 virtual QString key() const;
44 void setItem( const QString &txt, const QString &secondKey ); 44 void setItem( const QString &txt, const QString &secondKey );
45 45
46private: 46private:
47 QString sortKey; 47 QString sortKey;
48}; 48};
49 49
50// This is a simple container, storing all contact 50// This is a simple container, storing all contact
51// information 51// information
52class ContactItem 52class ContactItem
53{ 53{
54 public: 54 public:
55 QPixmap icon; 55 QPixmap icon;
56 QString value; 56 QString value;
57}; 57};
58 58
59class AbPickItem : public QTableItem 59class AbPickItem : public QTableItem
60{ 60{
61public: 61public:
62 AbPickItem( QTable *t ); 62 AbPickItem( QTable *t );
63 63
64 QWidget *createEditor() const; 64 QWidget *createEditor() const;
65 void setContentFromEditor( QWidget *w ); 65 void setContentFromEditor( QWidget *w );
66 66
67private: 67private:
68 QGuardedPtr<QComboBox> cb; 68 QGuardedPtr<QComboBox> cb;
69}; 69};
70 70
71class AbTable : public QTable 71class AbTable : public QTable
72{ 72{
73 Q_OBJECT 73 Q_OBJECT
74 74
75public: 75public:
76 AbTable( const QValueList<int> ordered, QWidget *parent, const char *name=0 ); 76 AbTable( const QValueList<int> ordered, QWidget *parent, const char *name=0 );
77 ~AbTable(); 77 ~AbTable();
78 78
79 // Set the contacts shown in the table 79 // Set the contacts shown in the table
80 void setContacts( const OContactAccess::List& viewList ); 80 void setContacts( const OContactAccess::List& viewList );
81
82 // Set the list for primary contacts
83 void setOrderedList( const QValueList<int> ordered );
84
81 // Selects a contact of a specific UID 85 // Selects a contact of a specific UID
82 bool selectContact( int UID ); 86 bool selectContact( int UID );
83 87
84 // Get the current selected entry 88 // Get the current selected entry
85 OContact currentEntry(); 89 OContact currentEntry();
86 90
87 // Get the UID of the current selected Entry 91 // Get the UID of the current selected Entry
88 int currentEntry_UID(); 92 int currentEntry_UID();
89 93
90 QString findContactName( const OContact &entry ); 94 QString findContactName( const OContact &entry );
91 95
92 void init(); 96 void init();
93 void clear(); 97 void clear();
94 void refresh(); 98 void refresh();
95 99
96 void show(); 100 void show();
97 void setPaintingEnabled( bool e ); 101 void setPaintingEnabled( bool e );
98 void viewportPaintEvent( QPaintEvent* e); 102 void viewportPaintEvent( QPaintEvent* e);
99 void paintCell(QPainter* p, int row, int col, const QRect&, bool ); 103 void paintCell(QPainter* p, int row, int col, const QRect&, bool );
100 104
101 // addresspicker mode (What's that ? se) 105 // addresspicker mode (What's that ? se)
102 void setChoiceNames( const QStringList& list); 106 void setChoiceNames( const QStringList& list);
103 QStringList choiceNames() const; 107 QStringList choiceNames() const;
104 void setChoiceSelection( const QValueList<int>& list ); 108 void setChoiceSelection( const QValueList<int>& list );
105 QStringList choiceSelection(int index) const; 109 QStringList choiceSelection(int index) const;
106 110
107signals: 111signals:
108 void signalSwitch(); 112 void signalSwitch();
109 void signalEditor(); 113 void signalEditor();
110 void signalKeyDown(); 114 void signalKeyDown();
111 void signalKeyUp(); 115 void signalKeyUp();
112 116
113protected: 117protected:
114 virtual void keyPressEvent( QKeyEvent *e ); 118 virtual void keyPressEvent( QKeyEvent *e );
115 119
116// int rowHeight( int ) const; 120// int rowHeight( int ) const;
117// int rowPos( int row ) const; 121// int rowPos( int row ) const;
118// virtual int rowAt( int pos ) const; 122// virtual int rowAt( int pos ) const;
119 123
120 124
121protected slots: 125protected slots:
122 void moveTo( char ); 126 void moveTo( char );
123 virtual void columnClicked( int col ); 127 virtual void columnClicked( int col );
124 void itemClicked(int,int col); 128 void itemClicked(int,int col);
125 void rowHeightChanged( int row ); 129 void rowHeightChanged( int row );
126 130
127private: 131private:
128 void insertIntoTable( const OContact &cnt, int row ); 132 void insertIntoTable( const OContact &cnt, int row );
129 ContactItem findContactContact( const OContact &entry, int row ); 133 ContactItem findContactContact( const OContact &entry, int row );
130 void fitColumns(); 134 void fitColumns();
131 void resizeRows(); 135 void resizeRows();
132 void realignTable(); 136 void realignTable();
133 void resort(); 137 void resort();
134 void updateVisible(); 138 void updateVisible();
135 139
136 int lastSortCol; 140 int lastSortCol;
137 bool asc; 141 bool asc;
138 QMap<AbTableItem*, OContact> contactList; 142 QMap<AbTableItem*, OContact> contactList;
139 QValueList<int> intFields; 143 QValueList<int> intFields;
140 QStringList choicenames; 144 QStringList choicenames;
141 bool enablePainting; 145 bool enablePainting;
142 bool columnVisible; 146 bool columnVisible;
143 int countNested; 147 int countNested;
144 148
145 OContactAccess::List m_viewList; 149 OContactAccess::List m_viewList;
146 150
147}; 151};
148#endif // ABTABLE_H 152#endif // ABTABLE_H
diff --git a/core/pim/addressbook/abview.cpp b/core/pim/addressbook/abview.cpp
index 7da0992..b89b794 100644
--- a/core/pim/addressbook/abview.cpp
+++ b/core/pim/addressbook/abview.cpp
@@ -1,475 +1,479 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (c) 2002 Stefan Eilers (eilers.stefan@epost.de) 2** Copyright (c) 2002 Stefan Eilers (eilers.stefan@epost.de)
3** 3**
4** This file is part of Qt Palmtop Environment. 4** This file is part of Qt Palmtop Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** 14**
15**********************************************************************/ 15**********************************************************************/
16 16
17#include "abview.h" 17#include "abview.h"
18 18
19#include <qlayout.h> 19#include <qlayout.h>
20 20
21#include <qpe/global.h> 21#include <qpe/global.h>
22 22
23#include <opie/ocontactaccessbackend_vcard.h> 23#include <opie/ocontactaccessbackend_vcard.h>
24 24
25 25
26// Is defined in LibQPE 26// Is defined in LibQPE
27extern QString categoryFileName(); 27extern QString categoryFileName();
28 28
29QString addressbookPersonalVCardName() 29QString addressbookPersonalVCardName()
30{ 30{
31 QString filename = Global::applicationFileName("addressbook", 31 QString filename = Global::applicationFileName("addressbook",
32 "businesscard.vcf"); 32 "businesscard.vcf");
33 return filename; 33 return filename;
34} 34}
35 35
36 36
37AbView::AbView ( QWidget* parent, const QValueList<int>& ordered ): 37AbView::AbView ( QWidget* parent, const QValueList<int>& ordered ):
38 QWidget(parent), 38 QWidget(parent),
39 mCat(0), 39 mCat(0),
40 m_inSearch( false ), 40 m_inSearch( false ),
41 m_inPersonal( false ), 41 m_inPersonal( false ),
42 m_curr_category( -1 ), 42 m_curr_category( -1 ),
43 m_curr_View( TableView ), 43 m_curr_View( TableView ),
44 m_prev_View( TableView ), 44 m_prev_View( TableView ),
45 m_curr_Contact ( 0 ), 45 m_curr_Contact ( 0 ),
46 m_contactdb ( 0l ), 46 m_contactdb ( 0l ),
47 m_storedDB ( 0l ), 47 m_storedDB ( 0l ),
48 m_viewStack( 0l ), 48 m_viewStack( 0l ),
49 m_abTable( 0l ), 49 m_abTable( 0l ),
50 m_orderedFields( ordered ) 50 m_orderedFields( ordered )
51{ 51{
52 // Load default database and handle syncing myself.. ! 52 // Load default database and handle syncing myself.. !
53 m_contactdb = new OContactAccess ( "addressbook", 0l, 0l, false ), 53 m_contactdb = new OContactAccess ( "addressbook", 0l, 0l, false ),
54 mCat.load( categoryFileName() ); 54 mCat.load( categoryFileName() );
55 55
56 // Create Layout and put WidgetStack into it. 56 // Create Layout and put WidgetStack into it.
57 QVBoxLayout *vb = new QVBoxLayout( this ); 57 QVBoxLayout *vb = new QVBoxLayout( this );
58 m_viewStack = new QWidgetStack( this ); 58 m_viewStack = new QWidgetStack( this );
59 vb->addWidget( m_viewStack ); 59 vb->addWidget( m_viewStack );
60 60
61 // Creat TableView 61 // Creat TableView
62 QVBox* tableBox = new QVBox( m_viewStack ); 62 QVBox* tableBox = new QVBox( m_viewStack );
63 m_abTable = new AbTable( m_orderedFields, tableBox, "table" ); 63 m_abTable = new AbTable( m_orderedFields, tableBox, "table" );
64 m_abTable->setCurrentCell( 0, 0 ); 64 m_abTable->setCurrentCell( 0, 0 );
65 m_abTable->setFocus(); 65 m_abTable->setFocus();
66 66
67 // Add TableView to WidgetStack and raise it 67 // Add TableView to WidgetStack and raise it
68 m_viewStack -> addWidget( tableBox , TableView ); 68 m_viewStack -> addWidget( tableBox , TableView );
69 69
70 // Create CardView and add it to WidgetStack 70 // Create CardView and add it to WidgetStack
71 QVBox* cardBox = new QVBox( m_viewStack ); 71 QVBox* cardBox = new QVBox( m_viewStack );
72 m_ablabel = new AbLabel( cardBox, "CardView"); 72 m_ablabel = new AbLabel( cardBox, "CardView");
73 m_viewStack -> addWidget( cardBox , CardView ); 73 m_viewStack -> addWidget( cardBox , CardView );
74 74
75 // Connect views to me 75 // Connect views to me
76 connect ( m_abTable, SIGNAL( signalSwitch( void ) ), 76 connect ( m_abTable, SIGNAL( signalSwitch( void ) ),
77 this, SLOT( slotSwitch( void ) ) ); 77 this, SLOT( slotSwitch( void ) ) );
78 connect ( m_ablabel, SIGNAL( signalOkPressed( void ) ), 78 connect ( m_ablabel, SIGNAL( signalOkPressed( void ) ),
79 this, SLOT( slotSwitch( void ) ) ); 79 this, SLOT( slotSwitch( void ) ) );
80 80
81 load(); 81 load();
82} 82}
83 83
84AbView::~AbView() 84AbView::~AbView()
85{ 85{
86 m_contactdb -> save(); 86 m_contactdb -> save();
87 delete m_contactdb; 87 delete m_contactdb;
88 88
89 if ( m_storedDB ){ 89 if ( m_storedDB ){
90 m_storedDB -> save(); 90 m_storedDB -> save();
91 delete m_storedDB; 91 delete m_storedDB;
92 } 92 }
93} 93}
94 94
95 95
96void AbView::setView( Views view ) 96void AbView::setView( Views view )
97{ 97{
98 //qWarning("AbView::setView( Views view )"); 98 //qWarning("AbView::setView( Views view )");
99 m_curr_View = view; 99 m_curr_View = view;
100 load(); 100 load();
101} 101}
102 102
103void AbView::addEntry( const OContact &newContact ) 103void AbView::addEntry( const OContact &newContact )
104{ 104{
105 //qWarning("abview:AddContact"); 105 //qWarning("abview:AddContact");
106 m_contactdb->add ( newContact ); 106 m_contactdb->add ( newContact );
107 load(); 107 load();
108 108
109} 109}
110void AbView::removeEntry( const int UID ) 110void AbView::removeEntry( const int UID )
111{ 111{
112 //qWarning("abview:RemoveContact"); 112 //qWarning("abview:RemoveContact");
113 m_contactdb->remove( UID ); 113 m_contactdb->remove( UID );
114 load(); 114 load();
115} 115}
116 116
117void AbView::replaceEntry( const OContact &contact ) 117void AbView::replaceEntry( const OContact &contact )
118{ 118{
119 //qWarning("abview:ReplaceContact"); 119 //qWarning("abview:ReplaceContact");
120 m_contactdb->replace( contact ); 120 m_contactdb->replace( contact );
121 load(); 121 load();
122 122
123} 123}
124 124
125OContact AbView::currentEntry() 125OContact AbView::currentEntry()
126{ 126{
127 OContact currentContact; 127 OContact currentContact;
128 128
129 switch ( (int) m_curr_View ) { 129 switch ( (int) m_curr_View ) {
130 case TableView: 130 case TableView:
131 currentContact = m_abTable -> currentEntry(); 131 currentContact = m_abTable -> currentEntry();
132 break; 132 break;
133 case CardView: 133 case CardView:
134 currentContact = m_ablabel -> currentEntry(); 134 currentContact = m_ablabel -> currentEntry();
135 break; 135 break;
136 } 136 }
137 m_curr_Contact = currentContact.uid(); 137 m_curr_Contact = currentContact.uid();
138 return currentContact; 138 return currentContact;
139} 139}
140 140
141bool AbView::save() 141bool AbView::save()
142{ 142{
143 //qWarning("abView:Save data"); 143 //qWarning("abView:Save data");
144 144
145 return m_contactdb->save(); 145 return m_contactdb->save();
146} 146}
147 147
148void AbView::load() 148void AbView::load()
149{ 149{
150 //qWarning("abView:Load data"); 150 //qWarning("abView:Load data");
151 151
152 // Letter Search is stopped at this place 152 // Letter Search is stopped at this place
153 emit signalClearLetterPicker(); 153 emit signalClearLetterPicker();
154 154
155 if ( m_inPersonal ) 155 if ( m_inPersonal )
156 // VCard Backend does not sort.. 156 // VCard Backend does not sort..
157 m_list = m_contactdb->allRecords(); 157 m_list = m_contactdb->allRecords();
158 else{ 158 else{
159 m_list = m_contactdb->sorted( true, 0, 0, 0 ); 159 m_list = m_contactdb->sorted( true, 0, 0, 0 );
160 clearForCategory(); 160 clearForCategory();
161 } 161 }
162 162
163 //qWarning ("Number of contacts: %d", m_list.count()); 163 //qWarning ("Number of contacts: %d", m_list.count());
164 164
165 updateView( true ); 165 updateView( true );
166 166
167} 167}
168 168
169void AbView::reload() 169void AbView::reload()
170{ 170{
171 //qWarning( "void AbView::reload()" ); 171 //qWarning( "void AbView::reload()" );
172 172
173 m_contactdb->reload(); 173 m_contactdb->reload();
174 load(); 174 load();
175} 175}
176 176
177void AbView::clear() 177void AbView::clear()
178{ 178{
179 // :SX 179 // :SX
180} 180}
181 181
182void AbView::setShowByCategory( const QString& cat ) 182void AbView::setShowByCategory( const QString& cat )
183{ 183{
184 //qWarning("AbView::setShowCategory( const QString& cat )"); 184 //qWarning("AbView::setShowCategory( const QString& cat )");
185 185
186 int intCat = 0; 186 int intCat = 0;
187 187
188 // All (cat == NULL) will be stored as -1 188 // All (cat == NULL) will be stored as -1
189 if ( cat.isNull() ) 189 if ( cat.isNull() )
190 intCat = -1; 190 intCat = -1;
191 else 191 else
192 intCat = mCat.id("Contacts", cat ); 192 intCat = mCat.id("Contacts", cat );
193 193
194 // Just do anything if we really change the category 194 // Just do anything if we really change the category
195 if ( intCat != m_curr_category ){ 195 if ( intCat != m_curr_category ){
196 // qWarning ("Categories: Selected %s.. Number: %d", cat.latin1(), m_curr_category); 196 // qWarning ("Categories: Selected %s.. Number: %d", cat.latin1(), m_curr_category);
197 197
198 m_curr_category = intCat; 198 m_curr_category = intCat;
199 emit signalClearLetterPicker(); 199 emit signalClearLetterPicker();
200 200
201 load(); 201 load();
202 } 202 }
203 203
204} 204}
205 205
206void AbView::setShowToView( Views view ) 206void AbView::setShowToView( Views view )
207{ 207{
208 //qWarning("void AbView::setShowToView( View %d )", view); 208 //qWarning("void AbView::setShowToView( View %d )", view);
209 209
210 //qWarning ("Change the View (Category is: %d)", m_curr_category); 210 //qWarning ("Change the View (Category is: %d)", m_curr_category);
211 211
212 if ( m_curr_View != view ){ 212 if ( m_curr_View != view ){
213 m_prev_View = m_curr_View; 213 m_prev_View = m_curr_View;
214 m_curr_View = view; 214 m_curr_View = view;
215 215
216 updateView(); 216 updateView();
217 } 217 }
218 218
219} 219}
220 220
221void AbView::setShowByLetter( char c ) 221void AbView::setShowByLetter( char c )
222{ 222{
223 //qWarning("void AbView::setShowByLetter( %c )", c ); 223 //qWarning("void AbView::setShowByLetter( %c )", c );
224 OContact query; 224 OContact query;
225 if ( c == 0 ){ 225 if ( c == 0 ){
226 load(); 226 load();
227 return; 227 return;
228 }else{ 228 }else{
229 // If the current Backend is unable to solve the query, we will 229 // If the current Backend is unable to solve the query, we will
230 // ignore the request .. 230 // ignore the request ..
231 if ( ! m_contactdb->hasQuerySettings( OContactAccess::WildCards | OContactAccess::IgnoreCase ) ){ 231 if ( ! m_contactdb->hasQuerySettings( OContactAccess::WildCards | OContactAccess::IgnoreCase ) ){
232 return; 232 return;
233 } 233 }
234 234
235 query.setLastName( QString("%1*").arg(c) ); 235 query.setLastName( QString("%1*").arg(c) );
236 m_list = m_contactdb->queryByExample( query, OContactAccess::WildCards | OContactAccess::IgnoreCase ); 236 m_list = m_contactdb->queryByExample( query, OContactAccess::WildCards | OContactAccess::IgnoreCase );
237 clearForCategory(); 237 clearForCategory();
238 m_curr_Contact = 0; 238 m_curr_Contact = 0;
239 } 239 }
240 updateView( true ); 240 updateView( true );
241} 241}
242 242
243void AbView::setListOrder( const QValueList<int>& ordered ) 243void AbView::setListOrder( const QValueList<int>& ordered )
244{ 244{
245 m_orderedFields = ordered; 245 m_orderedFields = ordered;
246 if ( m_abTable ){
247 m_abTable->setOrderedList( ordered );
248 m_abTable->refresh();
249 }
246 updateView(); 250 updateView();
247} 251}
248 252
249 253
250QString AbView::showCategory() const 254QString AbView::showCategory() const
251{ 255{
252 return mCat.label( "Contacts", m_curr_category ); 256 return mCat.label( "Contacts", m_curr_category );
253} 257}
254 258
255void AbView::showPersonal( bool personal ) 259void AbView::showPersonal( bool personal )
256{ 260{
257 //qWarning ("void AbView::showPersonal( %d )", personal); 261 //qWarning ("void AbView::showPersonal( %d )", personal);
258 262
259 if ( personal ){ 263 if ( personal ){
260 264
261 if ( m_inPersonal ) 265 if ( m_inPersonal )
262 return; 266 return;
263 267
264 // Now switch to vCard Backend and load data. 268 // Now switch to vCard Backend and load data.
265 // The current default backend will be stored 269 // The current default backend will be stored
266 // to avoid unneeded load/stores. 270 // to avoid unneeded load/stores.
267 m_storedDB = m_contactdb; 271 m_storedDB = m_contactdb;
268 272
269 OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null, 273 OContactAccessBackend* vcard_backend = new OContactAccessBackend_VCard( QString::null,
270 addressbookPersonalVCardName() ); 274 addressbookPersonalVCardName() );
271 m_contactdb = new OContactAccess ( "addressbook", QString::null , vcard_backend, true ); 275 m_contactdb = new OContactAccess ( "addressbook", QString::null , vcard_backend, true );
272 276
273 m_inPersonal = true; 277 m_inPersonal = true;
274 m_curr_View = CardView; 278 m_curr_View = CardView;
275 279
276 }else{ 280 }else{
277 281
278 if ( !m_inPersonal ) 282 if ( !m_inPersonal )
279 return; 283 return;
280 284
281 // Remove vCard Backend and restore default 285 // Remove vCard Backend and restore default
282 m_contactdb->save(); 286 m_contactdb->save();
283 delete m_contactdb; 287 delete m_contactdb;
284 288
285 m_contactdb = m_storedDB; 289 m_contactdb = m_storedDB;
286 m_storedDB = 0l; 290 m_storedDB = 0l;
287 291
288 m_curr_View = TableView; 292 m_curr_View = TableView;
289 m_inPersonal = false; 293 m_inPersonal = false;
290 294
291 } 295 }
292 load(); 296 load();
293} 297}
294 298
295QStringList AbView::categories() 299QStringList AbView::categories()
296{ 300{
297 mCat.load( categoryFileName() ); 301 mCat.load( categoryFileName() );
298 QStringList categoryList = mCat.labels( "Contacts" ); 302 QStringList categoryList = mCat.labels( "Contacts" );
299 return categoryList; 303 return categoryList;
300} 304}
301 305
302// BEGIN: Slots 306// BEGIN: Slots
303void AbView::slotDoFind( const QString &str, bool caseSensitive, bool useRegExp, 307void AbView::slotDoFind( const QString &str, bool caseSensitive, bool useRegExp,
304 bool , QString cat ) 308 bool , QString cat )
305{ 309{
306 //qWarning( "void AbView::slotDoFind" ); 310 //qWarning( "void AbView::slotDoFind" );
307 311
308 // We reloading the data: Deselect Letterpicker 312 // We reloading the data: Deselect Letterpicker
309 emit signalClearLetterPicker(); 313 emit signalClearLetterPicker();
310 314
311 // Use the current Category if nothing else selected 315 // Use the current Category if nothing else selected
312 int category = 0; 316 int category = 0;
313 317
314 if ( cat.isEmpty() ) 318 if ( cat.isEmpty() )
315 category = m_curr_category; 319 category = m_curr_category;
316 else{ 320 else{
317 category = mCat.id("Contacts", cat ); 321 category = mCat.id("Contacts", cat );
318 } 322 }
319 323
320 //qWarning ("Find in Category %d", category); 324 //qWarning ("Find in Category %d", category);
321 325
322 QRegExp r( str ); 326 QRegExp r( str );
323 r.setCaseSensitive( caseSensitive ); 327 r.setCaseSensitive( caseSensitive );
324 r.setWildcard( !useRegExp ); 328 r.setWildcard( !useRegExp );
325 329
326 // Get all matching entries out of the database 330 // Get all matching entries out of the database
327 m_list = m_contactdb->matchRegexp( r ); 331 m_list = m_contactdb->matchRegexp( r );
328 332
329 //qWarning( "found: %d", m_list.count() ); 333 //qWarning( "found: %d", m_list.count() );
330 if ( m_list.count() == 0 ){ 334 if ( m_list.count() == 0 ){
331 emit signalNotFound(); 335 emit signalNotFound();
332 return; 336 return;
333 } 337 }
334 338
335 // Now remove all contacts with wrong category (if any selected) 339 // Now remove all contacts with wrong category (if any selected)
336 // This algorithm is a litte bit ineffective, but 340 // This algorithm is a litte bit ineffective, but
337 // we will not have a lot of matching entries.. 341 // we will not have a lot of matching entries..
338 clearForCategory(); 342 clearForCategory();
339 343
340 // Now show all found entries 344 // Now show all found entries
341 updateView( true ); 345 updateView( true );
342} 346}
343 347
344void AbView::offSearch() 348void AbView::offSearch()
345{ 349{
346 m_inSearch = false; 350 m_inSearch = false;
347 351
348 load(); 352 load();
349} 353}
350 354
351void AbView::slotSwitch(){ 355void AbView::slotSwitch(){
352 //qWarning("AbView::slotSwitch()"); 356 //qWarning("AbView::slotSwitch()");
353 357
354 m_prev_View = m_curr_View; 358 m_prev_View = m_curr_View;
355 switch ( (int) m_curr_View ){ 359 switch ( (int) m_curr_View ){
356 case TableView: 360 case TableView:
357 qWarning("Switching to CardView"); 361 qWarning("Switching to CardView");
358 m_curr_View = CardView; 362 m_curr_View = CardView;
359 break; 363 break;
360 case CardView: 364 case CardView:
361 qWarning("Switching to TableView"); 365 qWarning("Switching to TableView");
362 m_curr_View = TableView; 366 m_curr_View = TableView;
363 break; 367 break;
364 } 368 }
365 updateView(); 369 updateView();
366 370
367} 371}
368 372
369// END: Slots 373// END: Slots
370 374
371void AbView::clearForCategory() 375void AbView::clearForCategory()
372{ 376{
373 OContactAccess::List::Iterator it; 377 OContactAccess::List::Iterator it;
374 // Now remove all contacts with wrong category if any category selected 378 // Now remove all contacts with wrong category if any category selected
375 379
376 OContactAccess::List allList = m_list; 380 OContactAccess::List allList = m_list;
377 if ( m_curr_category != -1 ){ 381 if ( m_curr_category != -1 ){
378 for ( it = allList.begin(); it != allList.end(); ++it ){ 382 for ( it = allList.begin(); it != allList.end(); ++it ){
379 if ( !contactCompare( *it, m_curr_category ) ){ 383 if ( !contactCompare( *it, m_curr_category ) ){
380 // qWarning("Removing %d", (*it).uid()); 384 // qWarning("Removing %d", (*it).uid());
381 m_list.remove( (*it).uid() ); 385 m_list.remove( (*it).uid() );
382 } 386 }
383 } 387 }
384 } 388 }
385 389
386} 390}
387 391
388bool AbView::contactCompare( const OContact &cnt, int category ) 392bool AbView::contactCompare( const OContact &cnt, int category )
389{ 393{
390 //qWarning ("bool AbView::contactCompare( const OContact &cnt, %d )", category); 394 //qWarning ("bool AbView::contactCompare( const OContact &cnt, %d )", category);
391 395
392 bool returnMe; 396 bool returnMe;
393 QArray<int> cats; 397 QArray<int> cats;
394 cats = cnt.categories(); 398 cats = cnt.categories();
395 399
396 //qWarning ("Number of categories: %d", cats.count() ); 400 //qWarning ("Number of categories: %d", cats.count() );
397 401
398 returnMe = false; 402 returnMe = false;
399 if ( cats.count() == 0 && category == 0 ) 403 if ( cats.count() == 0 && category == 0 )
400 // Contacts with no category will just shown on "All" and "Unfiled" 404 // Contacts with no category will just shown on "All" and "Unfiled"
401 returnMe = true; 405 returnMe = true;
402 else { 406 else {
403 int i; 407 int i;
404 for ( i = 0; i < int(cats.count()); i++ ) { 408 for ( i = 0; i < int(cats.count()); i++ ) {
405 // qWarning("Comparing %d with %d",cats[i],category ); 409 // qWarning("Comparing %d with %d",cats[i],category );
406 if ( cats[i] == category ) { 410 if ( cats[i] == category ) {
407 returnMe = true; 411 returnMe = true;
408 break; 412 break;
409 } 413 }
410 } 414 }
411 } 415 }
412 //qWarning ("Return: %d", returnMe); 416 //qWarning ("Return: %d", returnMe);
413 return returnMe; 417 return returnMe;
414} 418}
415 419
416// In Some rare cases we have to update all lists.. 420// In Some rare cases we have to update all lists..
417void AbView::updateListinViews() 421void AbView::updateListinViews()
418{ 422{
419 m_abTable -> setContacts( m_list ); 423 m_abTable -> setContacts( m_list );
420 m_ablabel -> setContacts( m_list ); 424 m_ablabel -> setContacts( m_list );
421} 425}
422 426
423void AbView::updateView( bool newdata ) 427void AbView::updateView( bool newdata )
424{ 428{
425 //qWarning("AbView::updateView()"); 429 //qWarning("AbView::updateView()");
426 430
427 if ( m_viewStack -> visibleWidget() ){ 431 if ( m_viewStack -> visibleWidget() ){
428 m_viewStack -> visibleWidget() -> clearFocus(); 432 m_viewStack -> visibleWidget() -> clearFocus();
429 } 433 }
430 434
431 // If we switching the view, we have to store some information 435 // If we switching the view, we have to store some information
432 if ( !newdata ){ 436 if ( !newdata ){
433 if ( m_list.count() ){ 437 if ( m_list.count() ){
434 switch ( (int) m_prev_View ) { 438 switch ( (int) m_prev_View ) {
435 case TableView: 439 case TableView:
436 m_curr_Contact = m_abTable -> currentEntry_UID(); 440 m_curr_Contact = m_abTable -> currentEntry_UID();
437 break; 441 break;
438 case CardView: 442 case CardView:
439 m_curr_Contact = m_ablabel -> currentEntry_UID(); 443 m_curr_Contact = m_ablabel -> currentEntry_UID();
440 break; 444 break;
441 } 445 }
442 }else 446 }else
443 m_curr_Contact = 0; 447 m_curr_Contact = 0;
444 } 448 }
445 449
446 // Feed all views with new lists 450 // Feed all views with new lists
447 if ( newdata ) 451 if ( newdata )
448 updateListinViews(); 452 updateListinViews();
449 453
450 // Tell the world that the view is changed 454 // Tell the world that the view is changed
451 if ( m_curr_View != m_prev_View ) 455 if ( m_curr_View != m_prev_View )
452 emit signalViewSwitched ( (int) m_curr_View ); 456 emit signalViewSwitched ( (int) m_curr_View );
453 457
454 m_prev_View = m_curr_View; 458 m_prev_View = m_curr_View;
455 459
456 // Switch to new View 460 // Switch to new View
457 switch ( (int) m_curr_View ) { 461 switch ( (int) m_curr_View ) {
458 case TableView: 462 case TableView:
459 m_abTable -> setChoiceSelection( m_orderedFields ); 463 m_abTable -> setChoiceSelection( m_orderedFields );
460 if ( m_curr_Contact != 0 ) 464 if ( m_curr_Contact != 0 )
461 m_abTable -> selectContact ( m_curr_Contact ); 465 m_abTable -> selectContact ( m_curr_Contact );
462 m_abTable -> setFocus(); 466 m_abTable -> setFocus();
463 break; 467 break;
464 case CardView: 468 case CardView:
465 if ( m_curr_Contact != 0 ) 469 if ( m_curr_Contact != 0 )
466 m_ablabel -> selectContact( m_curr_Contact ); 470 m_ablabel -> selectContact( m_curr_Contact );
467 m_ablabel -> setFocus(); 471 m_ablabel -> setFocus();
468 break; 472 break;
469 } 473 }
470 474
471 // Raise the current View 475 // Raise the current View
472 m_viewStack -> raiseWidget( m_curr_View ); 476 m_viewStack -> raiseWidget( m_curr_View );
473} 477}
474 478
475 479