Diffstat (limited to 'core/pim/addressbook/abtable.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/addressbook/abtable.cpp | 914 |
1 files changed, 285 insertions, 629 deletions
diff --git a/core/pim/addressbook/abtable.cpp b/core/pim/addressbook/abtable.cpp index 5222f16..b8127e9 100644 --- a/core/pim/addressbook/abtable.cpp +++ b/core/pim/addressbook/abtable.cpp | |||
@@ -1,6 +1,7 @@ | |||
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 | ** | 4 | ** |
4 | ** This file is part of Qt Palmtop Environment. | 5 | ** This file is part of Qt Palmtop Environment. |
5 | ** | 6 | ** |
6 | ** 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 |
@@ -17,9 +18,8 @@ | |||
17 | ** not clear to you. | 18 | ** not clear to you. |
18 | ** | 19 | ** |
19 | **********************************************************************/ | 20 | **********************************************************************/ |
20 | 21 | ||
21 | #define QTOPIA_INTERNAL_CONTACT_MRE | ||
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> |
@@ -42,11 +42,8 @@ | |||
42 | #include <stdlib.h> | 42 | #include <stdlib.h> |
43 | 43 | ||
44 | #include <ctype.h> //toupper() for key hack | 44 | #include <ctype.h> //toupper() for key hack |
45 | 45 | ||
46 | static bool contactCompare( const OContact &cnt, const QRegExp &r, int category ); | ||
47 | |||
48 | |||
49 | /*! | 46 | /*! |
50 | \class AbTableItem abtable.h | 47 | \class AbTableItem abtable.h |
51 | 48 | ||
52 | \brief QTableItem based class for showing a field of an entry | 49 | \brief QTableItem based class for showing a field of an entry |
@@ -119,37 +116,35 @@ void AbPickItem::setContentFromEditor( QWidget *w ) | |||
119 | 116 | ||
120 | \brief QTable based class for showing a list of entries | 117 | \brief QTable based class for showing a list of entries |
121 | */ | 118 | */ |
122 | 119 | ||
123 | AbTable::AbTable( const QValueList<int> *order, QWidget *parent, const char *name ) | 120 | AbTable::AbTable( const QValueList<int> order, QWidget *parent, const char *name ) |
124 | // #ifdef QT_QTABLE_NOHEADER_CONSTRUCTOR | ||
125 | // : QTable( 0, 0, parent, name, TRUE ), | ||
126 | // #else | ||
127 | : QTable( parent, name ), | 121 | : QTable( parent, name ), |
128 | // #endif | 122 | lastSortCol( -1 ), |
129 | lastSortCol( -1 ), | 123 | asc( TRUE ), |
130 | asc( TRUE ), | 124 | intFields( order ), |
131 | intFields( order ), | 125 | enablePainting( true ), |
132 | currFindRow( -1 ), | 126 | columnVisible( true ) |
133 | mCat( 0 ), | ||
134 | m_inSearch (false), | ||
135 | m_contactdb ("addressbook", 0l, 0l, false) // Handle syncing myself.. ! | ||
136 | { | 127 | { |
137 | mCat.load( categoryFileName() ); | 128 | qWarning("C'tor start"); |
129 | |||
138 | setSelectionMode( NoSelection ); | 130 | setSelectionMode( NoSelection ); |
139 | init(); | 131 | init(); |
140 | setSorting( TRUE ); | 132 | setSorting( TRUE ); |
141 | connect( this, SIGNAL(clicked(int,int,int,const QPoint &)), | 133 | connect( this, SIGNAL(clicked(int,int,int,const QPoint &)), |
142 | this, SLOT(itemClicked(int,int)) ); | 134 | this, SLOT(itemClicked(int,int)) ); |
135 | |||
136 | contactList.clear(); | ||
137 | qWarning("C'tor end"); | ||
143 | } | 138 | } |
144 | 139 | ||
145 | AbTable::~AbTable() | 140 | AbTable::~AbTable() |
146 | { | 141 | { |
147 | } | 142 | } |
148 | 143 | ||
149 | void AbTable::init() | 144 | void AbTable::init() |
150 | { | 145 | { |
151 | showChar = '\0'; | 146 | // :SX showChar = '\0'; |
152 | setNumRows( 0 ); | 147 | setNumRows( 0 ); |
153 | setNumCols( 2 ); | 148 | setNumCols( 2 ); |
154 | 149 | ||
155 | horizontalHeader()->setLabel( 0, tr( "Full Name" )); | 150 | horizontalHeader()->setLabel( 0, tr( "Full Name" )); |
@@ -158,8 +153,84 @@ void AbTable::init() | |||
158 | verticalHeader()->hide(); | 153 | verticalHeader()->hide(); |
159 | columnVisible = true; | 154 | columnVisible = true; |
160 | } | 155 | } |
161 | 156 | ||
157 | void AbTable::setContacts( const OContactAccess::List& viewList ) | ||
158 | { | ||
159 | qWarning("AbTable::setContacts()"); | ||
160 | |||
161 | clear(); | ||
162 | m_viewList = viewList; | ||
163 | |||
164 | setSorting( false ); | ||
165 | setUpdatesEnabled( FALSE ); | ||
166 | |||
167 | OContactAccess::List::Iterator it; | ||
168 | setNumRows( m_viewList.count() ); | ||
169 | int row = 0; | ||
170 | for ( it = m_viewList.begin(); it != m_viewList.end(); ++it ) | ||
171 | insertIntoTable( *it, row++ ); | ||
172 | |||
173 | setUpdatesEnabled( TRUE ); | ||
174 | |||
175 | setSorting( true ); | ||
176 | |||
177 | resort(); | ||
178 | |||
179 | updateVisible(); | ||
180 | |||
181 | } | ||
182 | |||
183 | bool AbTable::selectContact( int UID ) | ||
184 | { | ||
185 | qWarning( "AbTable::selectContact( %d )", UID ); | ||
186 | int rows = numRows(); | ||
187 | AbTableItem *abi; | ||
188 | OContact* foundContact = 0l; | ||
189 | bool found = false; | ||
190 | |||
191 | for ( int r = 0; r < rows; ++r ) { | ||
192 | abi = static_cast<AbTableItem*>( item(r, 0) ); | ||
193 | foundContact = &contactList[abi]; | ||
194 | if ( foundContact -> uid() == UID ){ | ||
195 | ensureCellVisible( r, 0 ); | ||
196 | setCurrentCell( r, 0 ); | ||
197 | found = true; | ||
198 | break; | ||
199 | } | ||
200 | } | ||
201 | |||
202 | if ( !found ){ | ||
203 | ensureCellVisible( 0,0 ); | ||
204 | setCurrentCell( 0, 0 ); | ||
205 | } | ||
206 | |||
207 | return true; | ||
208 | } | ||
209 | |||
210 | void AbTable::insertIntoTable( const OContact& cnt, int row ) | ||
211 | { | ||
212 | // qWarning( "void AbTable::insertIntoTable( const OContact& cnt, %d )", row ); | ||
213 | QString strName, | ||
214 | strContact; | ||
215 | |||
216 | strName = findContactName( cnt ); | ||
217 | strContact = findContactContact( cnt, row ); | ||
218 | |||
219 | AbTableItem *ati; | ||
220 | ati = new AbTableItem( this, QTableItem::Never, strName, strContact); | ||
221 | contactList.insert( ati, cnt ); | ||
222 | setItem( row, 0, ati ); | ||
223 | ati = new AbTableItem( this, QTableItem::Never, strContact, strName); | ||
224 | setItem( row, 1, ati ); | ||
225 | |||
226 | //### cannot do this; table only has two columns at this point | ||
227 | // setItem( row, 2, new AbPickItem( this ) ); | ||
228 | |||
229 | } | ||
230 | |||
231 | |||
232 | |||
162 | void AbTable::columnClicked( int col ) | 233 | void AbTable::columnClicked( int col ) |
163 | { | 234 | { |
164 | if ( !sorting() ) | 235 | if ( !sorting() ) |
165 | return; | 236 | return; |
@@ -178,8 +249,9 @@ void AbTable::columnClicked( int col ) | |||
178 | } | 249 | } |
179 | 250 | ||
180 | void AbTable::resort() | 251 | void AbTable::resort() |
181 | { | 252 | { |
253 | qWarning( "void AbTable::resort()" ); | ||
182 | if ( sorting() ) { | 254 | if ( sorting() ) { |
183 | if ( lastSortCol == -1 ) | 255 | if ( lastSortCol == -1 ) |
184 | lastSortCol = 0; | 256 | lastSortCol = 0; |
185 | sortColumn( lastSortCol, asc, TRUE ); | 257 | sortColumn( lastSortCol, asc, TRUE ); |
@@ -189,8 +261,9 @@ void AbTable::resort() | |||
189 | } | 261 | } |
190 | 262 | ||
191 | OContact AbTable::currentEntry() | 263 | OContact AbTable::currentEntry() |
192 | { | 264 | { |
265 | qWarning( "OContact AbTable::currentEntry()" ); | ||
193 | OContact cnt; | 266 | OContact cnt; |
194 | AbTableItem *abItem; | 267 | AbTableItem *abItem; |
195 | abItem = static_cast<AbTableItem*>(item( currentRow(), 0 )); | 268 | abItem = static_cast<AbTableItem*>(item( currentRow(), 0 )); |
196 | if ( abItem ) { | 269 | if ( abItem ) { |
@@ -199,33 +272,16 @@ OContact AbTable::currentEntry() | |||
199 | } | 272 | } |
200 | return cnt; | 273 | return cnt; |
201 | } | 274 | } |
202 | 275 | ||
203 | void AbTable::replaceCurrentEntry( const OContact &newContact ) | 276 | int AbTable::currentEntry_UID() |
204 | { | 277 | { |
205 | int row = currentRow(); | 278 | return ( currentEntry().uid() ); |
206 | updateVisible(); | ||
207 | |||
208 | journalFreeReplace( newContact, row ); | ||
209 | |||
210 | } | ||
211 | |||
212 | void AbTable::deleteCurrentEntry() | ||
213 | { | ||
214 | int row = currentRow(); | ||
215 | |||
216 | // a little wasteful, but it ensure's there is only one place | ||
217 | // where we delete. | ||
218 | journalFreeRemove( row ); | ||
219 | updateVisible(); | ||
220 | |||
221 | if ( numRows() == 0 ) | ||
222 | emit empty( TRUE ); | ||
223 | |||
224 | } | 279 | } |
225 | 280 | ||
226 | void AbTable::clear() | 281 | void AbTable::clear() |
227 | { | 282 | { |
283 | qWarning( "void AbTable::clear()" ); | ||
228 | contactList.clear(); | 284 | contactList.clear(); |
229 | for ( int r = 0; r < numRows(); ++r ) { | 285 | for ( int r = 0; r < numRows(); ++r ) { |
230 | for ( int c = 0; c < numCols(); ++c ) { | 286 | for ( int c = 0; c < numCols(); ++c ) { |
231 | if ( cellWidget( r, c ) ) | 287 | if ( cellWidget( r, c ) ) |
@@ -235,19 +291,16 @@ void AbTable::clear() | |||
235 | } | 291 | } |
236 | setNumRows( 0 ); | 292 | setNumRows( 0 ); |
237 | } | 293 | } |
238 | 294 | ||
295 | // Refresh updates column 2 if the contactsettings changed | ||
239 | void AbTable::refresh() | 296 | void AbTable::refresh() |
240 | { | 297 | { |
298 | qWarning( "void AbTable::refresh()" ); | ||
241 | int rows = numRows(); | 299 | int rows = numRows(); |
242 | QString value; | 300 | QString value; |
243 | AbTableItem *abi; | 301 | AbTableItem *abi; |
244 | 302 | ||
245 | // hide columns so no flashing ? | ||
246 | if ( showBk == "Cards" ) { | ||
247 | hideColumn(0); | ||
248 | hideColumn(1); | ||
249 | } | ||
250 | for ( int r = 0; r < rows; ++r ) { | 303 | for ( int r = 0; r < rows; ++r ) { |
251 | abi = static_cast<AbTableItem*>( item(r, 0) ); | 304 | abi = static_cast<AbTableItem*>( item(r, 0) ); |
252 | value = findContactContact( contactList[abi], r ); | 305 | value = findContactContact( contactList[abi], r ); |
253 | static_cast<AbTableItem*>( item(r, 1) )->setItem( value, abi->text() ); | 306 | static_cast<AbTableItem*>( item(r, 1) )->setItem( value, abi->text() ); |
@@ -261,47 +314,32 @@ void AbTable::keyPressEvent( QKeyEvent *e ) | |||
261 | 314 | ||
262 | if ( key >= 'A' && key <= 'Z' ) | 315 | if ( key >= 'A' && key <= 'Z' ) |
263 | moveTo( key ); | 316 | moveTo( key ); |
264 | 317 | ||
265 | if ( m_inSearch ) { | 318 | qWarning("Received key .."); |
266 | // Running in seach-mode, therefore we will interprete | 319 | switch( e->key() ) { |
267 | // some key differently | 320 | case Qt::Key_Space: |
268 | qWarning("Received key in search mode"); | 321 | case Qt::Key_Return: |
269 | switch( e->key() ) { | 322 | case Qt::Key_Enter: |
270 | case Qt::Key_Space: | 323 | emit signalSwitch(); |
271 | case Qt::Key_Return: | 324 | break; |
272 | case Qt::Key_Enter: | 325 | // case Qt::Key_Up: |
273 | emit details(); | 326 | // qWarning("a"); |
274 | break; | 327 | // emit signalKeyUp(); |
275 | case Qt::Key_Up: | 328 | // break; |
276 | qWarning("a"); | 329 | // case Qt::Key_Down: |
277 | emit signalSearchBackward(); | 330 | // qWarning("b"); |
278 | break; | 331 | // emit signalKeyDown(); |
279 | case Qt::Key_Down: | 332 | // break; |
280 | qWarning("b"); | 333 | default: |
281 | emit signalSearchNext(); | 334 | QTable::keyPressEvent( e ); |
282 | break; | ||
283 | default: | ||
284 | QTable::keyPressEvent( e ); | ||
285 | } | ||
286 | |||
287 | } else { | ||
288 | qWarning("Received key in NON search mode"); | ||
289 | |||
290 | switch( e->key() ) { | ||
291 | case Qt::Key_Space: | ||
292 | case Qt::Key_Return: | ||
293 | case Qt::Key_Enter: | ||
294 | emit details(); | ||
295 | break; | ||
296 | default: | ||
297 | QTable::keyPressEvent( e ); | ||
298 | } | ||
299 | } | 335 | } |
336 | |||
300 | } | 337 | } |
301 | 338 | ||
302 | void AbTable::moveTo( char c ) | 339 | void AbTable::moveTo( char c ) |
303 | { | 340 | { |
341 | qWarning( "void AbTable::moveTo( char c )" ); | ||
304 | 342 | ||
305 | int rows = numRows(); | 343 | int rows = numRows(); |
306 | QString value; | 344 | QString value; |
307 | AbTableItem *abi; | 345 | AbTableItem *abi; |
@@ -345,147 +383,9 @@ QString AbTable::findContactName( const OContact &entry ) | |||
345 | } | 383 | } |
346 | return str; | 384 | return str; |
347 | } | 385 | } |
348 | 386 | ||
349 | QString AbTable::findContactContact( const OContact &entry, int /* row */ ) | ||
350 | { | ||
351 | QString value; | ||
352 | value = ""; | ||
353 | for ( QValueList<int>::ConstIterator it = intFields->begin(); | ||
354 | it != intFields->end(); ++it ) { | ||
355 | switch ( *it ) { | ||
356 | default: | ||
357 | break; | ||
358 | case Qtopia::Title: | ||
359 | value = entry.title(); | ||
360 | break; | ||
361 | case Qtopia::Suffix: | ||
362 | value = entry.suffix(); | ||
363 | break; | ||
364 | case Qtopia::FileAs: | ||
365 | value = entry.fileAs(); | ||
366 | break; | ||
367 | case Qtopia::DefaultEmail: | ||
368 | value = entry.defaultEmail(); | ||
369 | case Qtopia::Emails: | ||
370 | value = entry.emails(); | ||
371 | break; | ||
372 | case Qtopia::HomeStreet: | ||
373 | value = entry.homeStreet(); | ||
374 | break; | ||
375 | case Qtopia::HomeCity: | ||
376 | value = entry.homeCity(); | ||
377 | break; | ||
378 | case Qtopia::HomeState: | ||
379 | value = entry.homeState(); | ||
380 | break; | ||
381 | case Qtopia::HomeZip: | ||
382 | value = entry.homeZip(); | ||
383 | break; | ||
384 | case Qtopia::HomeCountry: | ||
385 | value = entry.homeCountry(); | ||
386 | break; | ||
387 | case Qtopia::HomePhone: | ||
388 | value = entry.homePhone(); | ||
389 | break; | ||
390 | case Qtopia::HomeFax: | ||
391 | value = entry.homeFax(); | ||
392 | break; | ||
393 | case Qtopia::HomeMobile: | ||
394 | value = entry.homeMobile(); | ||
395 | break; | ||
396 | case Qtopia::HomeWebPage: | ||
397 | value = entry.homeWebpage(); | ||
398 | break; | ||
399 | case Qtopia::Company: | ||
400 | value = entry.company(); | ||
401 | break; | ||
402 | case Qtopia::BusinessCity: | ||
403 | value = entry.businessCity(); | ||
404 | break; | ||
405 | case Qtopia::BusinessStreet: | ||
406 | value = entry.businessStreet(); | ||
407 | break; | ||
408 | case Qtopia::BusinessZip: | ||
409 | value = entry.businessZip(); | ||
410 | break; | ||
411 | case Qtopia::BusinessCountry: | ||
412 | value = entry.businessCountry(); | ||
413 | break; | ||
414 | case Qtopia::BusinessWebPage: | ||
415 | value = entry.businessWebpage(); | ||
416 | break; | ||
417 | case Qtopia::JobTitle: | ||
418 | value = entry.jobTitle(); | ||
419 | break; | ||
420 | case Qtopia::Department: | ||
421 | value = entry.department(); | ||
422 | break; | ||
423 | case Qtopia::Office: | ||
424 | value = entry.office(); | ||
425 | break; | ||
426 | case Qtopia::BusinessPhone: | ||
427 | value = entry.businessPhone(); | ||
428 | break; | ||
429 | case Qtopia::BusinessFax: | ||
430 | value = entry.businessFax(); | ||
431 | break; | ||
432 | case Qtopia::BusinessMobile: | ||
433 | value = entry.businessMobile(); | ||
434 | break; | ||
435 | case Qtopia::BusinessPager: | ||
436 | value = entry.businessPager(); | ||
437 | break; | ||
438 | case Qtopia::Profession: | ||
439 | value = entry.profession(); | ||
440 | break; | ||
441 | case Qtopia::Assistant: | ||
442 | value = entry.assistant(); | ||
443 | break; | ||
444 | case Qtopia::Manager: | ||
445 | value = entry.manager(); | ||
446 | break; | ||
447 | case Qtopia::Spouse: | ||
448 | value = entry.spouse(); | ||
449 | break; | ||
450 | case Qtopia::Gender: | ||
451 | value = entry.gender(); | ||
452 | break; | ||
453 | case Qtopia::Birthday: | ||
454 | value = TimeString::numberDateString( entry.birthday() ); | ||
455 | break; | ||
456 | case Qtopia::Anniversary: | ||
457 | value = TimeString::numberDateString( entry.anniversary() ); | ||
458 | break; | ||
459 | case Qtopia::Nickname: | ||
460 | value = entry.nickname(); | ||
461 | break; | ||
462 | case Qtopia::Children: | ||
463 | value = entry.children(); | ||
464 | break; | ||
465 | case Qtopia::Notes: | ||
466 | value = entry.notes(); | ||
467 | break; | ||
468 | } | ||
469 | if ( !value.isEmpty() ) | ||
470 | break; | ||
471 | } | ||
472 | return value; | ||
473 | } | ||
474 | 387 | ||
475 | void AbTable::addEntry( const OContact &newCnt ) | ||
476 | { | ||
477 | int row = numRows(); | ||
478 | |||
479 | setNumRows( row + 1 ); | ||
480 | insertIntoTable( newCnt, row ); | ||
481 | |||
482 | qWarning("abtable:AddContact"); | ||
483 | m_contactdb.add ( newCnt ); | ||
484 | |||
485 | setCurrentCell( row, 0 ); | ||
486 | // updateVisible(); | ||
487 | } | ||
488 | 388 | ||
489 | void AbTable::resizeRows() { | 389 | void AbTable::resizeRows() { |
490 | /* | 390 | /* |
491 | if (numRows()) { | 391 | if (numRows()) { |
@@ -497,139 +397,23 @@ void AbTable::resizeRows() { | |||
497 | */ | 397 | */ |
498 | } | 398 | } |
499 | 399 | ||
500 | 400 | ||
501 | bool AbTable::save() | 401 | void AbTable::realignTable() |
502 | { | ||
503 | // QTime t; | ||
504 | // t.start(); | ||
505 | qWarning("abtable:Save data"); | ||
506 | |||
507 | return m_contactdb.save(); | ||
508 | } | ||
509 | |||
510 | void AbTable::load() | ||
511 | { | 402 | { |
512 | setSorting( false ); | 403 | qWarning( "void AbTable::realignTable()" ); |
513 | setUpdatesEnabled( FALSE ); | ||
514 | |||
515 | qWarning("abtable:Load data"); | ||
516 | |||
517 | OContactAccess::List list = m_contactdb.allRecords(); | ||
518 | OContactAccess::List::Iterator it; | ||
519 | setNumRows( list.count() ); | ||
520 | int row = 0; | ||
521 | for ( it = list.begin(); it != list.end(); ++it ) | ||
522 | insertIntoTable( *it, row++ ); | ||
523 | |||
524 | setUpdatesEnabled( TRUE ); | ||
525 | 404 | ||
526 | setSorting( true ); | 405 | setPaintingEnabled( FALSE ); |
527 | resort(); | ||
528 | } | ||
529 | 406 | ||
407 | resizeRows(); | ||
408 | fitColumns(); | ||
530 | 409 | ||
531 | void AbTable::reload() | 410 | setPaintingEnabled( TRUE ); |
532 | { | ||
533 | m_contactdb.reload(); | ||
534 | load(); | ||
535 | } | ||
536 | 411 | ||
537 | void AbTable::realignTable( int row ) | ||
538 | { | ||
539 | QTableItem *ti1, | ||
540 | *ti2; | ||
541 | int totalRows = numRows(); | ||
542 | for ( int curr = row; curr < totalRows - 1; curr++ ) { | ||
543 | // the same info from the todo list still applies, but I | ||
544 | // don't think it is _too_ bad. | ||
545 | ti1 = item( curr + 1, 0 ); | ||
546 | ti2 = item( curr + 1, 1 ); | ||
547 | takeItem( ti1 ); | ||
548 | takeItem( ti2 ); | ||
549 | setItem( curr, 0, ti1 ); | ||
550 | setItem( curr, 1, ti2 ); | ||
551 | } | ||
552 | setNumRows( totalRows - 1 ); | ||
553 | resort(); | ||
554 | } | 412 | } |
555 | 413 | ||
556 | // Add contact into table. | ||
557 | void AbTable::insertIntoTable( const OContact &cnt, int row ) | ||
558 | { | ||
559 | QString strName, | ||
560 | strContact; | ||
561 | |||
562 | strName = findContactName( cnt ); | ||
563 | strContact = findContactContact( cnt, row ); | ||
564 | |||
565 | AbTableItem *ati; | ||
566 | ati = new AbTableItem( this, QTableItem::Never, strName, strContact); | ||
567 | contactList.insert( ati, cnt ); | ||
568 | setItem( row, 0, ati ); | ||
569 | ati = new AbTableItem( this, QTableItem::Never, strContact, strName); | ||
570 | setItem( row, 1, ati ); | ||
571 | |||
572 | //### cannot do this; table only has two columns at this point | ||
573 | // setItem( row, 2, new AbPickItem( this ) ); | ||
574 | |||
575 | // resort at some point? | ||
576 | } | ||
577 | 414 | ||
578 | 415 | ||
579 | // Replace or add an entry | ||
580 | void AbTable::journalFreeReplace( const OContact &cnt, int row ) | ||
581 | { | ||
582 | QString strName, | ||
583 | strContact; | ||
584 | AbTableItem *ati = 0l; | ||
585 | |||
586 | strName = findContactName( cnt ); | ||
587 | strContact = findContactContact( cnt, row ); | ||
588 | ati = static_cast<AbTableItem*>(item(row, 0)); | ||
589 | |||
590 | // Replace element if found in row "row" | ||
591 | // or add this element if not. | ||
592 | if ( ati != 0 ) { // replace | ||
593 | // :SX db access -> replace | ||
594 | qWarning ("Replace Contact in DB ! UID: %d", contactList[ati].uid() ); | ||
595 | m_contactdb.replace ( cnt ); | ||
596 | |||
597 | contactList.remove( ati ); | ||
598 | ati->setItem( strName, strContact ); | ||
599 | contactList.insert( ati, cnt ); | ||
600 | |||
601 | ati = static_cast<AbTableItem*>(item(row, 1)); | ||
602 | ati->setItem( strContact, strName ); | ||
603 | |||
604 | }else{ // add | ||
605 | int myrows = numRows(); | ||
606 | setNumRows( myrows + 1 ); | ||
607 | insertIntoTable( cnt, myrows ); | ||
608 | // gets deleted when returning -- Why ? (se) | ||
609 | // :SX db access -> add | ||
610 | qWarning ("Are you sure to add to database ? -> Currently disabled !!"); | ||
611 | // m_contactdb.add( cnt ); | ||
612 | } | ||
613 | } | ||
614 | |||
615 | // Remove entry | ||
616 | void AbTable::journalFreeRemove( int row ) | ||
617 | { | ||
618 | AbTableItem *ati; | ||
619 | ati = static_cast<AbTableItem*>(item(row, 0)); | ||
620 | if ( !ati ) | ||
621 | return; | ||
622 | |||
623 | // :SX db access -> remove | ||
624 | qWarning ("Remove Contact from DB ! UID: %d",contactList[ati].uid() ); | ||
625 | m_contactdb.remove( contactList[ati].uid() ); | ||
626 | |||
627 | contactList.remove( ati ); | ||
628 | |||
629 | realignTable( row ); | ||
630 | |||
631 | } | ||
632 | 416 | ||
633 | #if QT_VERSION <= 230 | 417 | #if QT_VERSION <= 230 |
634 | #ifndef SINGLE_APP | 418 | #ifndef SINGLE_APP |
635 | void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch ) | 419 | void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch ) |
@@ -661,128 +445,34 @@ void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch ) | |||
661 | // { | 445 | // { |
662 | // return QMIN( pos/18, numRows()-1 ); | 446 | // return QMIN( pos/18, numRows()-1 ); |
663 | // } | 447 | // } |
664 | 448 | ||
665 | void AbTable::slotDoFind( const QString &findString, bool caseSensitive, bool useRegExp, | ||
666 | bool backwards, QString cat /* int category */ ) | ||
667 | { | ||
668 | int category = 0; | ||
669 | |||
670 | // Use the current Category if nothing else selected | ||
671 | if ( cat.isEmpty() ) | ||
672 | category = mCat.id( "Contacts", showCat ); | ||
673 | else{ | ||
674 | category = mCat.id("Contacts", cat ); | ||
675 | } | ||
676 | |||
677 | qWarning ("Found in Category %d", category); | ||
678 | |||
679 | if ( currFindRow < -1 ) | ||
680 | currFindRow = - 1; | ||
681 | 449 | ||
682 | clearSelection( TRUE ); | ||
683 | int rows, row; | ||
684 | AbTableItem *ati; | ||
685 | QRegExp r( findString ); | ||
686 | r.setCaseSensitive( caseSensitive ); | ||
687 | r.setWildcard( !useRegExp ); | ||
688 | rows = numRows(); | ||
689 | static bool wrapAround = true; | ||
690 | bool try_again = false; | ||
691 | |||
692 | // We will loop until we found an entry or found nothing. | ||
693 | do { | ||
694 | if ( !backwards ) { | ||
695 | for ( row = currFindRow + 1; row < rows; row++ ) { | ||
696 | ati = static_cast<AbTableItem*>( item(row, 0) ); | ||
697 | if ( contactCompare( contactList[ati], r, category ) ){ | ||
698 | try_again = false; | ||
699 | break; | ||
700 | } | ||
701 | } | ||
702 | } else { | ||
703 | for ( row = currFindRow - 1; row > -1; row-- ) { | ||
704 | ati = static_cast<AbTableItem*>( item(row, 0) ); | ||
705 | if ( contactCompare( contactList[ati], r, category ) ){ | ||
706 | try_again = false; | ||
707 | break; | ||
708 | } | ||
709 | } | ||
710 | } | ||
711 | if ( row >= rows || row < 0 ) { | ||
712 | if ( row < 0 ) | ||
713 | currFindRow = rows; | ||
714 | else | ||
715 | currFindRow = -1; | ||
716 | |||
717 | if ( wrapAround ){ | ||
718 | emit signalWrapAround(); | ||
719 | try_again = true; | ||
720 | }else{ | ||
721 | emit signalNotFound(); | ||
722 | try_again = false; | ||
723 | } | ||
724 | |||
725 | wrapAround = !wrapAround; | ||
726 | } else { | ||
727 | currFindRow = row; | ||
728 | QTableSelection foundSelection; | ||
729 | foundSelection.init( currFindRow, 0 ); | ||
730 | foundSelection.expandTo( currFindRow, numCols() - 1 ); | ||
731 | addSelection( foundSelection ); | ||
732 | setCurrentCell( currFindRow, 0 /* numCols() - 1 */ ); | ||
733 | wrapAround = true; | ||
734 | try_again = false; | ||
735 | } | ||
736 | } while ( try_again ); | ||
737 | } | ||
738 | 450 | ||
739 | static bool contactCompare( const OContact &cnt, const QRegExp &r, int category ) | 451 | void AbTable::fitColumns() |
740 | { | 452 | { |
741 | bool returnMe; | 453 | qWarning( "void AbTable::fitColumns()" ); |
742 | QArray<int> cats; | 454 | int contentsWidth = visibleWidth() / 2; // :SX Why too low |
743 | cats = cnt.categories(); | 455 | // Fix to better value |
456 | // contentsWidth = 130; | ||
744 | 457 | ||
745 | returnMe = false; | 458 | if ( columnVisible == false ){ |
746 | if ( (cats.count() == 0) || (category == 0) ) | 459 | showColumn(0); |
747 | returnMe = cnt.match( r ); | 460 | columnVisible = true; |
748 | else { | ||
749 | int i; | ||
750 | for ( i = 0; i < int(cats.count()); i++ ) { | ||
751 | if ( cats[i] == category ) { | ||
752 | returnMe = cnt.match( r ); | ||
753 | break; | ||
754 | } | ||
755 | } | ||
756 | } | 461 | } |
757 | 462 | ||
758 | return returnMe; | 463 | qWarning("Width: %d", contentsWidth); |
759 | } | ||
760 | 464 | ||
761 | void AbTable::fitColumns() | 465 | setColumnWidth( 0, contentsWidth ); |
762 | { | 466 | adjustColumn(1); |
763 | int contentsWidth = visibleWidth() / 2; | 467 | if ( columnWidth(1) < contentsWidth ) |
764 | 468 | setColumnWidth( 1, contentsWidth ); | |
765 | if ( showBk == "Cards" ) { | ||
766 | showColumn(1); | ||
767 | //adjustColumn(1); | ||
768 | setColumnWidth( 1, visibleWidth() ); | ||
769 | columnVisible = false; | ||
770 | } else { | ||
771 | if ( columnVisible == false ){ | ||
772 | showColumn(0); | ||
773 | columnVisible = true; | ||
774 | } | ||
775 | setColumnWidth( 0, contentsWidth ); | ||
776 | adjustColumn(1); | ||
777 | if ( columnWidth(1) < contentsWidth ) | ||
778 | setColumnWidth( 1, contentsWidth ); | ||
779 | } | ||
780 | } | 469 | } |
781 | 470 | ||
782 | void AbTable::show() | 471 | void AbTable::show() |
783 | { | 472 | { |
784 | fitColumns(); | 473 | qWarning( "void AbTable::show()" ); |
474 | realignTable(); | ||
785 | QTable::show(); | 475 | QTable::show(); |
786 | } | 476 | } |
787 | 477 | ||
788 | void AbTable::setChoiceNames( const QStringList& list) | 478 | void AbTable::setChoiceNames( const QStringList& list) |
@@ -801,38 +491,25 @@ void AbTable::setChoiceNames( const QStringList& list) | |||
801 | } | 491 | } |
802 | 492 | ||
803 | void AbTable::itemClicked(int,int col) | 493 | void AbTable::itemClicked(int,int col) |
804 | { | 494 | { |
495 | qWarning( "AbTable::itemClicked(int, col:%d)", col); | ||
805 | if ( col == 2 ) { | 496 | if ( col == 2 ) { |
806 | return; | 497 | return; |
807 | } else { | 498 | } else { |
808 | emit details(); | 499 | qWarning ("Emitting signalSwitch()"); |
500 | emit signalSwitch(); | ||
809 | } | 501 | } |
810 | } | 502 | } |
811 | 503 | ||
812 | QStringList AbTable::choiceNames() const | 504 | QStringList AbTable::choiceNames() const |
813 | { | 505 | { |
814 | return choicenames; | 506 | return choicenames; |
815 | } | 507 | } |
816 | 508 | ||
817 | void AbTable::setChoiceSelection(int /*index*/, const QStringList& /*list*/) | 509 | void AbTable::setChoiceSelection( const QValueList<int>& list ) |
818 | { | 510 | { |
819 | /* ###### | 511 | intFields = list; |
820 | |||
821 | QString selname = choicenames.at(index); | ||
822 | for (each row) { | ||
823 | OContact *c = contactForRow(row); | ||
824 | if ( list.contains(c->email) ) { | ||
825 | list.remove(c->email); | ||
826 | setText(row, 2, selname); | ||
827 | } | ||
828 | } | ||
829 | for (remaining list items) { | ||
830 | OContact *c = new contact(item); | ||
831 | setText(newrow, 2, selname); | ||
832 | } | ||
833 | |||
834 | */ | ||
835 | } | 512 | } |
836 | 513 | ||
837 | QStringList AbTable::choiceSelection(int /*index*/) const | 514 | QStringList AbTable::choiceSelection(int /*index*/) const |
838 | { | 515 | { |
@@ -850,190 +527,44 @@ QStringList AbTable::choiceSelection(int /*index*/) const | |||
850 | */ | 527 | */ |
851 | return r; | 528 | return r; |
852 | } | 529 | } |
853 | 530 | ||
854 | void AbTable::setShowCategory( const QString &b, const QString &c ) | ||
855 | { | ||
856 | showBk = b; | ||
857 | showCat = c; | ||
858 | //QMessageBox::information( this, "setShowCategory", "setShowCategory" ); | ||
859 | //updateVisible(); | ||
860 | refresh(); | ||
861 | ensureCellVisible( currentRow(), 0 ); | ||
862 | updateVisible(); // :SX | ||
863 | } | ||
864 | 531 | ||
865 | void AbTable::setShowByLetter( char c ) | ||
866 | { | ||
867 | showChar = tolower(c); | ||
868 | updateVisible(); | ||
869 | } | ||
870 | 532 | ||
871 | QString AbTable::showCategory() const | ||
872 | { | ||
873 | return showCat; | ||
874 | } | ||
875 | |||
876 | QString AbTable::showBook() const | ||
877 | { | ||
878 | return showBk; | ||
879 | } | ||
880 | |||
881 | QStringList AbTable::categories() | ||
882 | { | ||
883 | mCat.load( categoryFileName() ); | ||
884 | QStringList categoryList = mCat.labels( "Contacts" ); | ||
885 | return categoryList; | ||
886 | } | ||
887 | 533 | ||
888 | void AbTable::updateVisible() | 534 | void AbTable::updateVisible() |
889 | { | 535 | { |
890 | int visible, | 536 | int visible, |
891 | totalRows, | 537 | totalRows, |
892 | id, | 538 | row, |
893 | totalCats, | 539 | selectedRow = 0; |
894 | it, | 540 | |
895 | row; | ||
896 | bool hide; | ||
897 | AbTableItem *ati; | ||
898 | OContact *cnt; | ||
899 | QString fileAsName; | ||
900 | QString tmpStr; | ||
901 | visible = 0; | 541 | visible = 0; |
902 | 542 | ||
543 | realignTable(); | ||
544 | |||
903 | setPaintingEnabled( FALSE ); | 545 | setPaintingEnabled( FALSE ); |
904 | 546 | ||
905 | totalRows = numRows(); | 547 | totalRows = numRows(); |
906 | id = mCat.id( "Contacts", showCat ); | ||
907 | QArray<int> cats; | ||
908 | for ( row = 0; row < totalRows; row++ ) { | 548 | for ( row = 0; row < totalRows; row++ ) { |
909 | ati = static_cast<AbTableItem*>( item(row, 0) ); | 549 | if ( rowHeight(row) == 0 ) { |
910 | cnt = &contactList[ati]; | 550 | showRow( row ); |
911 | cats = cnt->categories(); | 551 | adjustRow( row ); |
912 | fileAsName = cnt->fileAs(); | 552 | if ( isSelected( row,0 ) || isSelected( row,1 ) ) |
913 | hide = false; | 553 | selectedRow = row; |
914 | if ( !showCat.isEmpty() ) { | ||
915 | if ( showCat == tr( "Unfiled" ) ) { | ||
916 | if ( cats.count() > 0 ) | ||
917 | hide = true; | ||
918 | } else { | ||
919 | // do some comparing | ||
920 | if ( !hide ) { | ||
921 | hide = true; | ||
922 | totalCats = int(cats.count()); | ||
923 | for ( it = 0; it < totalCats; it++ ) { | ||
924 | if ( cats[it] == id ) { | ||
925 | hide = false; | ||
926 | break; | ||
927 | } | ||
928 | } | ||
929 | } | ||
930 | } | ||
931 | } | ||
932 | if ( showChar != '\0' ) { | ||
933 | tmpStr = fileAsName.left(1); | ||
934 | tmpStr = tmpStr.lower(); | ||
935 | if ( tmpStr != QString(QChar(showChar)) && showChar != '#' ) { | ||
936 | hide = true; | ||
937 | } | ||
938 | if ( showChar == '#' ) { | ||
939 | if (tmpStr == "a") | ||
940 | hide = true; | ||
941 | |||
942 | if (tmpStr == "b") | ||
943 | hide = true; | ||
944 | |||
945 | if (tmpStr == "c") | ||
946 | hide = true; | ||
947 | |||
948 | if (tmpStr == "d") | ||
949 | hide = true; | ||
950 | |||
951 | if (tmpStr == "e") | ||
952 | hide = true; | ||
953 | |||
954 | if (tmpStr == "f") | ||
955 | hide = true; | ||
956 | |||
957 | if (tmpStr == "g") | ||
958 | hide = true; | ||
959 | |||
960 | if (tmpStr == "h") | ||
961 | hide = true; | ||
962 | |||
963 | if (tmpStr == "i") | ||
964 | hide = true; | ||
965 | |||
966 | if (tmpStr == "j") | ||
967 | hide = true; | ||
968 | |||
969 | if (tmpStr == "k") | ||
970 | hide = true; | ||
971 | |||
972 | if (tmpStr == "l") | ||
973 | hide = true; | ||
974 | |||
975 | if (tmpStr == "m") | ||
976 | hide = true; | ||
977 | |||
978 | if (tmpStr == "n") | ||
979 | hide = true; | ||
980 | |||
981 | if (tmpStr == "o") | ||
982 | hide = true; | ||
983 | |||
984 | if (tmpStr == "p") | ||
985 | hide = true; | ||
986 | |||
987 | if (tmpStr == "q") | ||
988 | hide = true; | ||
989 | |||
990 | if (tmpStr == "r") | ||
991 | hide = true; | ||
992 | |||
993 | if (tmpStr == "s") | ||
994 | hide = true; | ||
995 | |||
996 | if (tmpStr == "t") | ||
997 | hide = true; | ||
998 | |||
999 | if (tmpStr == "u") | ||
1000 | hide = true; | ||
1001 | |||
1002 | if (tmpStr == "v") | ||
1003 | hide = true; | ||
1004 | |||
1005 | if (tmpStr == "w") | ||
1006 | hide = true; | ||
1007 | |||
1008 | if (tmpStr == "x") | ||
1009 | hide = true; | ||
1010 | |||
1011 | if (tmpStr == "y") | ||
1012 | hide = true; | ||
1013 | |||
1014 | if (tmpStr == "z") | ||
1015 | hide = true; | ||
1016 | } | ||
1017 | |||
1018 | } | ||
1019 | if ( hide ) { | ||
1020 | if ( currentRow() == row ) | ||
1021 | setCurrentCell( -1, 0 ); | ||
1022 | if ( rowHeight(row) > 0 ) | ||
1023 | hideRow( row ); | ||
1024 | } else { | ||
1025 | if ( rowHeight(row) == 0 ) { | ||
1026 | showRow( row ); | ||
1027 | adjustRow( row ); | ||
1028 | } | ||
1029 | visible++; | ||
1030 | } | 554 | } |
555 | visible++; | ||
1031 | } | 556 | } |
557 | |||
558 | if ( selectedRow ) | ||
559 | setCurrentCell( selectedRow, 0 ); | ||
560 | |||
1032 | if ( !visible ) | 561 | if ( !visible ) |
1033 | setCurrentCell( -1, 0 ); | 562 | setCurrentCell( -1, 0 ); |
1034 | 563 | ||
1035 | setPaintingEnabled( TRUE ); | 564 | setPaintingEnabled( TRUE ); |
565 | |||
566 | |||
1036 | } | 567 | } |
1037 | 568 | ||
1038 | 569 | ||
1039 | void AbTable::setPaintingEnabled( bool e ) | 570 | void AbTable::setPaintingEnabled( bool e ) |
@@ -1053,4 +584,129 @@ void AbTable::rowHeightChanged( int row ) | |||
1053 | { | 584 | { |
1054 | if ( enablePainting ) | 585 | if ( enablePainting ) |
1055 | QTable::rowHeightChanged( row ); | 586 | QTable::rowHeightChanged( row ); |
1056 | } | 587 | } |
588 | QString AbTable::findContactContact( const OContact &entry, int /* row */ ) | ||
589 | { | ||
590 | QString value; | ||
591 | value = ""; | ||
592 | for ( QValueList<int>::ConstIterator it = intFields.begin(); | ||
593 | it != intFields.end(); ++it ) { | ||
594 | switch ( *it ) { | ||
595 | default: | ||
596 | break; | ||
597 | case Qtopia::Title: | ||
598 | value = entry.title(); | ||
599 | break; | ||
600 | case Qtopia::Suffix: | ||
601 | value = entry.suffix(); | ||
602 | break; | ||
603 | case Qtopia::FileAs: | ||
604 | value = entry.fileAs(); | ||
605 | break; | ||
606 | case Qtopia::DefaultEmail: | ||
607 | value = entry.defaultEmail(); | ||
608 | case Qtopia::Emails: | ||
609 | value = entry.emails(); | ||
610 | break; | ||
611 | case Qtopia::HomeStreet: | ||
612 | value = entry.homeStreet(); | ||
613 | break; | ||
614 | case Qtopia::HomeCity: | ||
615 | value = entry.homeCity(); | ||
616 | break; | ||
617 | case Qtopia::HomeState: | ||
618 | value = entry.homeState(); | ||
619 | break; | ||
620 | case Qtopia::HomeZip: | ||
621 | value = entry.homeZip(); | ||
622 | break; | ||
623 | case Qtopia::HomeCountry: | ||
624 | value = entry.homeCountry(); | ||
625 | break; | ||
626 | case Qtopia::HomePhone: | ||
627 | value = entry.homePhone(); | ||
628 | break; | ||
629 | case Qtopia::HomeFax: | ||
630 | value = entry.homeFax(); | ||
631 | break; | ||
632 | case Qtopia::HomeMobile: | ||
633 | value = entry.homeMobile(); | ||
634 | break; | ||
635 | case Qtopia::HomeWebPage: | ||
636 | value = entry.homeWebpage(); | ||
637 | break; | ||
638 | case Qtopia::Company: | ||
639 | value = entry.company(); | ||
640 | break; | ||
641 | case Qtopia::BusinessCity: | ||
642 | value = entry.businessCity(); | ||
643 | break; | ||
644 | case Qtopia::BusinessStreet: | ||
645 | value = entry.businessStreet(); | ||
646 | break; | ||
647 | case Qtopia::BusinessZip: | ||
648 | value = entry.businessZip(); | ||
649 | break; | ||
650 | case Qtopia::BusinessCountry: | ||
651 | value = entry.businessCountry(); | ||
652 | break; | ||
653 | case Qtopia::BusinessWebPage: | ||
654 | value = entry.businessWebpage(); | ||
655 | break; | ||
656 | case Qtopia::JobTitle: | ||
657 | value = entry.jobTitle(); | ||
658 | break; | ||
659 | case Qtopia::Department: | ||
660 | value = entry.department(); | ||
661 | break; | ||
662 | case Qtopia::Office: | ||
663 | value = entry.office(); | ||
664 | break; | ||
665 | case Qtopia::BusinessPhone: | ||
666 | value = entry.businessPhone(); | ||
667 | break; | ||
668 | case Qtopia::BusinessFax: | ||
669 | value = entry.businessFax(); | ||
670 | break; | ||
671 | case Qtopia::BusinessMobile: | ||
672 | value = entry.businessMobile(); | ||
673 | break; | ||
674 | case Qtopia::BusinessPager: | ||
675 | value = entry.businessPager(); | ||
676 | break; | ||
677 | case Qtopia::Profession: | ||
678 | value = entry.profession(); | ||
679 | break; | ||
680 | case Qtopia::Assistant: | ||
681 | value = entry.assistant(); | ||
682 | break; | ||
683 | case Qtopia::Manager: | ||
684 | value = entry.manager(); | ||
685 | break; | ||
686 | case Qtopia::Spouse: | ||
687 | value = entry.spouse(); | ||
688 | break; | ||
689 | case Qtopia::Gender: | ||
690 | value = entry.gender(); | ||
691 | break; | ||
692 | case Qtopia::Birthday: | ||
693 | value = TimeString::numberDateString( entry.birthday() ); | ||
694 | break; | ||
695 | case Qtopia::Anniversary: | ||
696 | value = TimeString::numberDateString( entry.anniversary() ); | ||
697 | break; | ||
698 | case Qtopia::Nickname: | ||
699 | value = entry.nickname(); | ||
700 | break; | ||
701 | case Qtopia::Children: | ||
702 | value = entry.children(); | ||
703 | break; | ||
704 | case Qtopia::Notes: | ||
705 | value = entry.notes(); | ||
706 | break; | ||
707 | } | ||
708 | if ( !value.isEmpty() ) | ||
709 | break; | ||
710 | } | ||
711 | return value; | ||
712 | } | ||