Diffstat (limited to 'core/pim/addressbook/abtable.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/pim/addressbook/abtable.cpp | 444 |
1 files changed, 118 insertions, 326 deletions
diff --git a/core/pim/addressbook/abtable.cpp b/core/pim/addressbook/abtable.cpp index 3fa1a7c..08c6d0a 100644 --- a/core/pim/addressbook/abtable.cpp +++ b/core/pim/addressbook/abtable.cpp | |||
@@ -25,10 +25,13 @@ | |||
25 | #include <qpe/stringutil.h> | 25 | #include <qpe/stringutil.h> |
26 | #include <qpe/qcopenvelope_qws.h> | 26 | #include <qpe/qcopenvelope_qws.h> |
27 | 27 | ||
28 | #include <opie/orecordlist.h> | ||
29 | |||
28 | #include <qasciidict.h> | 30 | #include <qasciidict.h> |
29 | #include <qdatetime.h> | 31 | #include <qdatetime.h> |
30 | #include <qfile.h> | 32 | #include <qfile.h> |
31 | #include <qregexp.h> | 33 | #include <qregexp.h> |
34 | #include <qmessagebox.h> | ||
32 | 35 | ||
33 | #include "abtable.h" | 36 | #include "abtable.h" |
34 | 37 | ||
@@ -39,16 +42,7 @@ | |||
39 | 42 | ||
40 | #include <ctype.h> //toupper() for key hack | 43 | #include <ctype.h> //toupper() for key hack |
41 | 44 | ||
42 | static bool contactCompare( const Contact &cnt, const QRegExp &r, int category ); | 45 | static bool contactCompare( const OContact &cnt, const QRegExp &r, int category ); |
43 | |||
44 | //### qtmail/addresslist.cpp hardcodes this filename as well | ||
45 | static QString journalFileName() | ||
46 | { | ||
47 | QString str = getenv("HOME"); | ||
48 | str +="/.abjournal"; | ||
49 | return str; | ||
50 | } | ||
51 | |||
52 | 46 | ||
53 | 47 | ||
54 | /*! | 48 | /*! |
@@ -135,7 +129,8 @@ AbTable::AbTable( const QValueList<int> *order, QWidget *parent, const char *nam | |||
135 | asc( TRUE ), | 129 | asc( TRUE ), |
136 | intFields( order ), | 130 | intFields( order ), |
137 | currFindRow( -2 ), | 131 | currFindRow( -2 ), |
138 | mCat( 0 ) | 132 | mCat( 0 ), |
133 | m_contactdb ("addressbook") | ||
139 | { | 134 | { |
140 | mCat.load( categoryFileName() ); | 135 | mCat.load( categoryFileName() ); |
141 | setSelectionMode( NoSelection ); | 136 | setSelectionMode( NoSelection ); |
@@ -159,6 +154,7 @@ void AbTable::init() | |||
159 | horizontalHeader()->setLabel( 1, tr( "Contact" )); | 154 | horizontalHeader()->setLabel( 1, tr( "Contact" )); |
160 | setLeftMargin( 0 ); | 155 | setLeftMargin( 0 ); |
161 | verticalHeader()->hide(); | 156 | verticalHeader()->hide(); |
157 | columnVisible = true; | ||
162 | } | 158 | } |
163 | 159 | ||
164 | void AbTable::columnClicked( int col ) | 160 | void AbTable::columnClicked( int col ) |
@@ -175,6 +171,7 @@ void AbTable::columnClicked( int col ) | |||
175 | lastSortCol = col; | 171 | lastSortCol = col; |
176 | asc = TRUE; | 172 | asc = TRUE; |
177 | } | 173 | } |
174 | //QMessageBox::information( this, "resort", "columnClicked" ); | ||
178 | resort(); | 175 | resort(); |
179 | } | 176 | } |
180 | 177 | ||
@@ -184,38 +181,35 @@ void AbTable::resort() | |||
184 | if ( lastSortCol == -1 ) | 181 | if ( lastSortCol == -1 ) |
185 | lastSortCol = 0; | 182 | lastSortCol = 0; |
186 | sortColumn( lastSortCol, asc, TRUE ); | 183 | sortColumn( lastSortCol, asc, TRUE ); |
184 | //QMessageBox::information( this, "resort", "resort" ); | ||
187 | updateVisible(); | 185 | updateVisible(); |
188 | } | 186 | } |
189 | } | 187 | } |
190 | 188 | ||
191 | Contact AbTable::currentEntry() | 189 | OContact AbTable::currentEntry() |
192 | { | 190 | { |
193 | Contact cnt; | 191 | OContact cnt; |
194 | AbTableItem *abItem; | 192 | AbTableItem *abItem; |
195 | abItem = static_cast<AbTableItem*>(item( currentRow(), 0 )); | 193 | abItem = static_cast<AbTableItem*>(item( currentRow(), 0 )); |
196 | if ( abItem ) { | 194 | if ( abItem ) { |
197 | cnt = contactList[abItem]; | 195 | cnt = contactList[abItem]; |
196 | //cnt = contactList[currentRow()]; | ||
198 | } | 197 | } |
199 | return cnt; | 198 | return cnt; |
200 | } | 199 | } |
201 | 200 | ||
202 | void AbTable::replaceCurrentEntry( const Contact &newContact ) | 201 | void AbTable::replaceCurrentEntry( const OContact &newContact ) |
203 | { | 202 | { |
204 | int row = currentRow(); | 203 | int row = currentRow(); |
205 | updateJournal( newContact, Contact::ACTION_REPLACE, row ); | ||
206 | updateVisible(); | 204 | updateVisible(); |
207 | 205 | ||
208 | journalFreeReplace( newContact, row ); | 206 | journalFreeReplace( newContact, row ); |
207 | |||
209 | } | 208 | } |
210 | 209 | ||
211 | void AbTable::deleteCurrentEntry() | 210 | void AbTable::deleteCurrentEntry() |
212 | { | 211 | { |
213 | int row = currentRow(); | 212 | int row = currentRow(); |
214 | AbTableItem *abItem; | ||
215 | abItem = static_cast<AbTableItem*>(item( row, 0 )); | ||
216 | Contact oldContact; | ||
217 | oldContact = contactList[abItem]; | ||
218 | updateJournal( oldContact, Contact::ACTION_REMOVE, row ); | ||
219 | 213 | ||
220 | // a little wasteful, but it ensure's there is only one place | 214 | // a little wasteful, but it ensure's there is only one place |
221 | // where we delete. | 215 | // where we delete. |
@@ -224,6 +218,7 @@ void AbTable::deleteCurrentEntry() | |||
224 | 218 | ||
225 | if ( numRows() == 0 ) | 219 | if ( numRows() == 0 ) |
226 | emit empty( TRUE ); | 220 | emit empty( TRUE ); |
221 | |||
227 | } | 222 | } |
228 | 223 | ||
229 | void AbTable::clear() | 224 | void AbTable::clear() |
@@ -244,9 +239,15 @@ void AbTable::refresh() | |||
244 | int rows = numRows(); | 239 | int rows = numRows(); |
245 | QString value; | 240 | QString value; |
246 | AbTableItem *abi; | 241 | AbTableItem *abi; |
242 | |||
243 | // hide columns so no flashing ? | ||
244 | if ( showBk == "Cards" ) { | ||
245 | hideColumn(0); | ||
246 | hideColumn(1); | ||
247 | } | ||
247 | for ( int r = 0; r < rows; ++r ) { | 248 | for ( int r = 0; r < rows; ++r ) { |
248 | abi = static_cast<AbTableItem*>( item(r, 0) ); | 249 | abi = static_cast<AbTableItem*>( item(r, 0) ); |
249 | value = findContactContact( contactList[abi] ); | 250 | value = findContactContact( contactList[abi], r ); |
250 | static_cast<AbTableItem*>( item(r, 1) )->setItem( value, abi->text() ); | 251 | static_cast<AbTableItem*>( item(r, 1) )->setItem( value, abi->text() ); |
251 | } | 252 | } |
252 | resort(); | 253 | resort(); |
@@ -303,7 +304,7 @@ void AbTable::moveTo( char c ) | |||
303 | } | 304 | } |
304 | 305 | ||
305 | 306 | ||
306 | QString AbTable::findContactName( const Contact &entry ) | 307 | QString AbTable::findContactName( const OContact &entry ) |
307 | { | 308 | { |
308 | // We use the fileAs, then company, defaultEmail | 309 | // We use the fileAs, then company, defaultEmail |
309 | QString str; | 310 | QString str; |
@@ -317,7 +318,7 @@ QString AbTable::findContactName( const Contact &entry ) | |||
317 | return str; | 318 | return str; |
318 | } | 319 | } |
319 | 320 | ||
320 | QString AbTable::findContactContact( const Contact &entry ) | 321 | QString AbTable::findContactContact( const OContact &entry, int /* row */ ) |
321 | { | 322 | { |
322 | QString value; | 323 | QString value; |
323 | value = ""; | 324 | value = ""; |
@@ -443,305 +444,65 @@ QString AbTable::findContactContact( const Contact &entry ) | |||
443 | return value; | 444 | return value; |
444 | } | 445 | } |
445 | 446 | ||
446 | void AbTable::addEntry( const Contact &newCnt ) | 447 | void AbTable::addEntry( const OContact &newCnt ) |
447 | { | 448 | { |
448 | int row = numRows(); | 449 | int row = numRows(); |
450 | |||
449 | setNumRows( row + 1 ); | 451 | setNumRows( row + 1 ); |
450 | updateJournal( newCnt, Contact::ACTION_ADD ); | ||
451 | insertIntoTable( newCnt, row ); | 452 | insertIntoTable( newCnt, row ); |
453 | |||
454 | qWarning("abtable:AddContact"); | ||
455 | m_contactdb.add ( newCnt ); | ||
456 | |||
452 | setCurrentCell( row, 0 ); | 457 | setCurrentCell( row, 0 ); |
453 | updateVisible(); | 458 | // updateVisible(); |
454 | } | 459 | } |
455 | 460 | ||
456 | void AbTable::resizeRows( int size ) { | 461 | void AbTable::resizeRows() { |
457 | /* | 462 | /* |
458 | if (numRows()) { | 463 | if (numRows()) { |
459 | for (int i = 0; i < numRows(); i++) { | 464 | for (int i = 0; i < numRows(); i++) { |
460 | setRowHeight( i, size ); | 465 | setRowHeight( i, size ); |
461 | } | 466 | } |
462 | }*/ | 467 | } |
463 | updateVisible(); | 468 | updateVisible(); |
469 | */ | ||
464 | } | 470 | } |
465 | 471 | ||
466 | void AbTable::updateJournal( const Contact &cnt, | 472 | |
467 | Contact::journal_action action, int row ) | 473 | bool AbTable::save( const QString& /* fn */ ) |
468 | { | ||
469 | QFile f( journalFileName() ); | ||
470 | if ( !f.open(IO_WriteOnly|IO_Append) ) | ||
471 | return; | ||
472 | QString buf; | ||
473 | QCString str; | ||
474 | buf = "<Contact "; | ||
475 | cnt.save( buf ); | ||
476 | buf += " action=\"" + QString::number( (int)action ) + "\" "; | ||
477 | if ( action == Contact::ACTION_REMOVE || action == Contact::ACTION_REPLACE) | ||
478 | buf += " actionrow=\"" + QString::number(row) + "\" "; | ||
479 | buf += "/>\n"; | ||
480 | QCString cstr = buf.utf8(); | ||
481 | f.writeBlock( cstr.data(), cstr.length() ); | ||
482 | QCopEnvelope( "QPE/PIM", "addressbookUpdated()" ); | ||
483 | } | ||
484 | |||
485 | bool AbTable::save( const QString &fn ) | ||
486 | { | 474 | { |
487 | // QTime t; | 475 | // QTime t; |
488 | // t.start(); | 476 | // t.start(); |
477 | qWarning("abtable:Save data"); | ||
478 | m_contactdb.save(); | ||
489 | 479 | ||
490 | QString strNewFile = fn + ".new"; | ||
491 | QFile f( strNewFile ); | ||
492 | if ( !f.open( IO_WriteOnly|IO_Raw ) ) | ||
493 | return false; | ||
494 | |||
495 | int total_written; | ||
496 | QString out; | ||
497 | out = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE Addressbook ><AddressBook>\n" | ||
498 | " <Groups>\n" | ||
499 | " </Groups>\n" | ||
500 | " <Contacts>\n"; | ||
501 | QMapIterator<AbTableItem*, Contact> it; | ||
502 | for ( it = contactList.begin(); it != contactList.end(); ++it ) { | ||
503 | out += "<Contact "; | ||
504 | it.data().save( out ); | ||
505 | out += "/>\n"; | ||
506 | QCString cstr = out.utf8(); | ||
507 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | ||
508 | if ( total_written != int(cstr.length()) ) { | ||
509 | f.close(); | ||
510 | QFile::remove( strNewFile ); | ||
511 | return false; | ||
512 | } | ||
513 | out = ""; | ||
514 | } | ||
515 | out += " </Contacts>\n</AddressBook>\n"; | ||
516 | |||
517 | QCString cstr = out.utf8(); | ||
518 | total_written = f.writeBlock( cstr.data(), cstr.length() ); | ||
519 | if ( total_written != int(cstr.length()) ) { | ||
520 | f.close(); | ||
521 | QFile::remove( strNewFile ); | ||
522 | return false; | ||
523 | } | ||
524 | f.close(); | ||
525 | |||
526 | // qDebug("saving: %d", t.elapsed() ); | ||
527 | |||
528 | // move the file over, I'm just going to use the system call | ||
529 | // because, I don't feel like using QDir. | ||
530 | if ( ::rename( strNewFile.latin1(), fn.latin1() ) < 0 ) { | ||
531 | qWarning( "problem renaming file %s to %s, errno: %d", | ||
532 | strNewFile.latin1(), fn.latin1(), errno ); | ||
533 | // remove the tmp file... | ||
534 | QFile::remove( strNewFile ); | ||
535 | } | ||
536 | // remove the journal... | ||
537 | QFile::remove( journalFileName() ); | ||
538 | return true; | 480 | return true; |
539 | } | 481 | } |
540 | 482 | ||
541 | void AbTable::load( const QString &fn ) | 483 | void AbTable::load( const QString& /* fn */ ) |
542 | { | 484 | { |
543 | setSorting( false ); | 485 | setSorting( false ); |
544 | loadFile( fn, false ); | 486 | setUpdatesEnabled( FALSE ); |
545 | // merge in the journal | ||
546 | if ( QFile::exists( journalFileName() ) ) { | ||
547 | loadFile( journalFileName(), true ); | ||
548 | save( fn ); | ||
549 | } | ||
550 | setSorting( true ); | ||
551 | resort(); | ||
552 | } | ||
553 | 487 | ||
554 | void AbTable::loadFile( const QString &strFile, bool journalFile ) | 488 | qWarning("abtable:Load data"); |
555 | { | ||
556 | // QTime t; | ||
557 | // t.start(); | ||
558 | QFile f( strFile ); | ||
559 | if ( !f.open(IO_ReadOnly) ) | ||
560 | return; | ||
561 | QList<Contact> list; | ||
562 | list.setAutoDelete( TRUE ); | ||
563 | QByteArray ba = f.readAll(); | ||
564 | f.close(); | ||
565 | if (ba.isEmpty() ) | ||
566 | return; | ||
567 | char *uc = ba.data();//(QChar *)data.unicode(); | ||
568 | int len = ba.size();//data.length(); | ||
569 | bool foundAction = false; | ||
570 | Contact::journal_action action; | ||
571 | bool foundKey = false; | ||
572 | int journalKey = 0; | ||
573 | |||
574 | const int JOURNALACTION = Qtopia::Notes + 1; | ||
575 | const int JOURNALROW = JOURNALACTION + 1; | ||
576 | |||
577 | // ********************************** | ||
578 | // CHANGE THE SIZE OF THE DICT IF YOU ADD ANY MORE FIELDS!!!! | ||
579 | // ********************************** | ||
580 | QAsciiDict<int> dict( 47 ); | ||
581 | dict.setAutoDelete( TRUE ); | ||
582 | dict.insert( "Uid", new int(Qtopia::AddressUid) ); | ||
583 | dict.insert( "Title", new int(Qtopia::Title) ); | ||
584 | dict.insert( "FirstName", new int(Qtopia::FirstName) ); | ||
585 | dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); | ||
586 | dict.insert( "LastName", new int(Qtopia::LastName) ); | ||
587 | dict.insert( "Suffix", new int(Qtopia::Suffix) ); | ||
588 | dict.insert( "FileAs", new int(Qtopia::FileAs) ); | ||
589 | dict.insert( "Categories", new int(Qtopia::AddressCategory) ); | ||
590 | dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); | ||
591 | dict.insert( "Emails", new int(Qtopia::Emails) ); | ||
592 | dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); | ||
593 | dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); | ||
594 | dict.insert( "HomeState", new int(Qtopia::HomeState) ); | ||
595 | dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); | ||
596 | dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); | ||
597 | dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); | ||
598 | dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); | ||
599 | dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); | ||
600 | dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); | ||
601 | dict.insert( "Company", new int(Qtopia::Company) ); | ||
602 | dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); | ||
603 | dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); | ||
604 | dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); | ||
605 | dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); | ||
606 | dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); | ||
607 | dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); | ||
608 | dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); | ||
609 | dict.insert( "Department", new int(Qtopia::Department) ); | ||
610 | dict.insert( "Office", new int(Qtopia::Office) ); | ||
611 | dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); | ||
612 | dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); | ||
613 | dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); | ||
614 | dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); | ||
615 | dict.insert( "Profession", new int(Qtopia::Profession) ); | ||
616 | dict.insert( "Assistant", new int(Qtopia::Assistant) ); | ||
617 | dict.insert( "Manager", new int(Qtopia::Manager) ); | ||
618 | dict.insert( "Spouse", new int(Qtopia::Spouse) ); | ||
619 | dict.insert( "Children", new int(Qtopia::Children) ); | ||
620 | dict.insert( "Gender", new int(Qtopia::Gender) ); | ||
621 | dict.insert( "Birthday", new int(Qtopia::Birthday) ); | ||
622 | dict.insert( "Anniversary", new int(Qtopia::Anniversary) ); | ||
623 | dict.insert( "Nickname", new int(Qtopia::Nickname) ); | ||
624 | dict.insert( "Notes", new int(Qtopia::Notes) ); | ||
625 | dict.insert( "action", new int(JOURNALACTION) ); | ||
626 | dict.insert( "actionrow", new int(JOURNALROW) ); | ||
627 | |||
628 | int i = 0; | ||
629 | int num = 0; | ||
630 | char *point; | ||
631 | while ( (point = strstr( uc+i, "<Contact " ) ) != NULL ) { | ||
632 | i = point - uc; | ||
633 | // if we are reading the standard file, we just need to | ||
634 | // insert info, so just say we'll do an insert... | ||
635 | action = Contact::ACTION_ADD; | ||
636 | // new Contact | ||
637 | Contact *cnt = new Contact; | ||
638 | i += 9; | ||
639 | while ( 1 ) { | ||
640 | while ( i < len && (uc[i] == ' ' || uc[i] == '\n' || uc[i] == '\r') ) | ||
641 | i++; | ||
642 | if ( i >= len-2 || (uc[i] == '/' && uc[i+1] == '>') ) | ||
643 | break; | ||
644 | // we have another attribute read it. | ||
645 | int j = i; | ||
646 | while ( j < len && uc[j] != '=' ) | ||
647 | j++; | ||
648 | char *attr = uc+i; | ||
649 | uc[j] = '\0'; | ||
650 | //qDebug("attr=%s", attr.latin1() ); | ||
651 | i = ++j; // skip = | ||
652 | while ( i < len && uc[i] != '"' ) | ||
653 | i++; | ||
654 | j = ++i; | ||
655 | bool haveEnt = FALSE; | ||
656 | bool haveUtf = FALSE; | ||
657 | while ( j < len && uc[j] != '"' ) { | ||
658 | if ( uc[j] == '&' ) | ||
659 | haveEnt = TRUE; | ||
660 | if ( ((unsigned char)uc[j]) > 0x7f ) | ||
661 | haveUtf = TRUE; | ||
662 | j++; | ||
663 | } | ||
664 | |||
665 | if ( j == i ) { | ||
666 | // empty value | ||
667 | i = j + 1; | ||
668 | continue; | ||
669 | } | ||
670 | |||
671 | QString value = haveUtf ? QString::fromUtf8( uc+i, j-i ) | ||
672 | : QString::fromLatin1( uc+i, j-i ); | ||
673 | if ( haveEnt ) | ||
674 | value = Qtopia::plainString( value ); | ||
675 | i = j + 1; | ||
676 | |||
677 | int *find = dict[ attr ]; | ||
678 | if ( !find ) { | ||
679 | cnt->setCustomField(attr, value); | ||
680 | continue; | ||
681 | } | ||
682 | #if 1 | ||
683 | switch( *find ) { | ||
684 | case Qtopia::AddressUid: | ||
685 | cnt->setUid( value.toInt() ); | ||
686 | break; | ||
687 | case Qtopia::AddressCategory: | ||
688 | cnt->setCategories( Qtopia::Record::idsFromString( value )); | ||
689 | break; | ||
690 | case JOURNALACTION: | ||
691 | action = Contact::journal_action(value.toInt()); | ||
692 | break; | ||
693 | case JOURNALROW: | ||
694 | journalKey = value.toInt(); | ||
695 | break; | ||
696 | 489 | ||
697 | default: | 490 | OContactAccess::List list = m_contactdb.allRecords(); |
698 | cnt->insert( *find, value ); | 491 | OContactAccess::List::Iterator it; |
699 | break; | 492 | setNumRows( list.count() ); |
700 | } | 493 | int row = 0; |
701 | #endif | 494 | for ( it = list.begin(); it != list.end(); ++it ) |
702 | } | 495 | insertIntoTable( *it, row++ ); |
703 | 496 | ||
704 | // sadly we can't delay adding of items from the journal to get | 497 | resort(); |
705 | // the proper effect, but then, the journal should _never_ be | 498 | |
706 | // that huge, and recovering from a crash is not necessarily | 499 | setUpdatesEnabled( TRUE ); |
707 | // a *fast* thing. | ||
708 | switch ( action ) { | ||
709 | case Contact::ACTION_ADD: | ||
710 | if ( journalFile ) { | ||
711 | int myrows = numRows(); | ||
712 | setNumRows( myrows + 1 ); | ||
713 | insertIntoTable( *cnt, myrows ); | ||
714 | delete cnt; | ||
715 | } | ||
716 | else | ||
717 | list.append( cnt ); | ||
718 | break; | ||
719 | case Contact::ACTION_REMOVE: | ||
720 | // yup, we don't use the entry to remove the object... | ||
721 | journalFreeRemove( journalKey ); | ||
722 | delete cnt; | ||
723 | break; | ||
724 | case Contact::ACTION_REPLACE: | ||
725 | journalFreeReplace( *cnt, journalKey ); | ||
726 | delete cnt; | ||
727 | break; | ||
728 | default: | ||
729 | break; | ||
730 | } | ||
731 | num++; | ||
732 | foundAction = false; | ||
733 | foundKey = false; | ||
734 | // if ( num % 100 == 0 ) { | ||
735 | // qDebug("loading file, num=%d, t=%d", num, t.elapsed() ); | ||
736 | // } | ||
737 | } | ||
738 | if ( list.count() > 0 ) { | ||
739 | internalAddEntries( list ); | ||
740 | } | ||
741 | // qDebug("done loading %d, t=%d", num, t.elapsed() ); | ||
742 | 500 | ||
501 | setSorting( true ); | ||
502 | //resort(); | ||
743 | } | 503 | } |
744 | 504 | ||
505 | |||
745 | void AbTable::realignTable( int row ) | 506 | void AbTable::realignTable( int row ) |
746 | { | 507 | { |
747 | QTableItem *ti1, | 508 | QTableItem *ti1, |
@@ -761,13 +522,14 @@ void AbTable::realignTable( int row ) | |||
761 | resort(); | 522 | resort(); |
762 | } | 523 | } |
763 | 524 | ||
764 | void AbTable::insertIntoTable( const Contact &cnt, int row ) | 525 | // Add contact into table. |
526 | void AbTable::insertIntoTable( const OContact &cnt, int row ) | ||
765 | { | 527 | { |
766 | QString strName, | 528 | QString strName, |
767 | strContact; | 529 | strContact; |
768 | 530 | ||
769 | strName = findContactName( cnt ); | 531 | strName = findContactName( cnt ); |
770 | strContact = findContactContact( cnt ); | 532 | strContact = findContactContact( cnt, row ); |
771 | 533 | ||
772 | AbTableItem *ati; | 534 | AbTableItem *ati; |
773 | ati = new AbTableItem( this, QTableItem::Never, strName, strContact); | 535 | ati = new AbTableItem( this, QTableItem::Never, strName, strContact); |
@@ -782,51 +544,59 @@ void AbTable::insertIntoTable( const Contact &cnt, int row ) | |||
782 | // resort at some point? | 544 | // resort at some point? |
783 | } | 545 | } |
784 | 546 | ||
785 | void AbTable::internalAddEntries( QList<Contact> &list ) | ||
786 | { | ||
787 | setUpdatesEnabled( FALSE ); | ||
788 | setNumRows( list.count() ); | ||
789 | int row = 0; | ||
790 | Contact *it; | ||
791 | for ( it = list.first(); it; it = list.next() ) | ||
792 | insertIntoTable( *it, row++ ); | ||
793 | resort(); | ||
794 | setUpdatesEnabled( TRUE ); | ||
795 | } | ||
796 | |||
797 | 547 | ||
798 | void AbTable::journalFreeReplace( const Contact &cnt, int row ) | 548 | // Replace or add an entry |
549 | void AbTable::journalFreeReplace( const OContact &cnt, int row ) | ||
799 | { | 550 | { |
800 | QString strName, | 551 | QString strName, |
801 | strContact; | 552 | strContact; |
802 | AbTableItem *ati = 0l; | 553 | AbTableItem *ati = 0l; |
803 | 554 | ||
804 | strName = findContactName( cnt ); | 555 | strName = findContactName( cnt ); |
805 | strContact = findContactContact( cnt ); | 556 | strContact = findContactContact( cnt, row ); |
806 | ati = static_cast<AbTableItem*>(item(row, 0)); | 557 | ati = static_cast<AbTableItem*>(item(row, 0)); |
807 | if ( ati != 0 ) { | 558 | |
559 | // Replace element if found in row "row" | ||
560 | // or add this element if not. | ||
561 | if ( ati != 0 ) { // replace | ||
562 | // :SX db access -> replace | ||
563 | qWarning ("Replace Contact in DB ! UID: %d", contactList[ati].uid() ); | ||
564 | m_contactdb.replace ( cnt ); | ||
565 | |||
808 | contactList.remove( ati ); | 566 | contactList.remove( ati ); |
809 | ati->setItem( strName, strContact ); | 567 | ati->setItem( strName, strContact ); |
810 | contactList.insert( ati, cnt ); | 568 | contactList.insert( ati, cnt ); |
811 | 569 | ||
812 | ati = static_cast<AbTableItem*>(item(row, 1)); | 570 | ati = static_cast<AbTableItem*>(item(row, 1)); |
813 | ati->setItem( strContact, strName ); | 571 | ati->setItem( strContact, strName ); |
814 | }else{ | 572 | |
573 | }else{ // add | ||
815 | int myrows = numRows(); | 574 | int myrows = numRows(); |
816 | setNumRows( myrows + 1 ); | 575 | setNumRows( myrows + 1 ); |
817 | insertIntoTable( cnt, myrows ); | 576 | insertIntoTable( cnt, myrows ); |
818 | // gets deleted when returning | 577 | // gets deleted when returning -- Why ? (se) |
578 | // :SX db access -> add | ||
579 | qWarning ("Are you sure to add to database ? -> Currently disabled !!"); | ||
580 | // m_contactdb.add( cnt ); | ||
819 | } | 581 | } |
820 | } | 582 | } |
821 | 583 | ||
584 | // Remove entry | ||
822 | void AbTable::journalFreeRemove( int row ) | 585 | void AbTable::journalFreeRemove( int row ) |
823 | { | 586 | { |
824 | AbTableItem *ati; | 587 | AbTableItem *ati; |
825 | ati = static_cast<AbTableItem*>(item(row, 0)); | 588 | ati = static_cast<AbTableItem*>(item(row, 0)); |
826 | if ( !ati ) | 589 | if ( !ati ) |
827 | return; | 590 | return; |
591 | |||
592 | // :SX db access -> remove | ||
593 | qWarning ("Remove Contact from DB ! UID: %d",contactList[ati].uid() ); | ||
594 | m_contactdb.remove( contactList[ati].uid() ); | ||
595 | |||
828 | contactList.remove( ati ); | 596 | contactList.remove( ati ); |
597 | |||
829 | realignTable( row ); | 598 | realignTable( row ); |
599 | |||
830 | } | 600 | } |
831 | 601 | ||
832 | #if QT_VERSION <= 230 | 602 | #if QT_VERSION <= 230 |
@@ -867,8 +637,7 @@ void AbTable::slotDoFind( const QString &findString, bool caseSensitive, | |||
867 | if ( currFindRow < -1 ) | 637 | if ( currFindRow < -1 ) |
868 | currFindRow = currentRow() - 1; | 638 | currFindRow = currentRow() - 1; |
869 | clearSelection( TRUE ); | 639 | clearSelection( TRUE ); |
870 | int rows, | 640 | int rows, row; |
871 | row; | ||
872 | AbTableItem *ati; | 641 | AbTableItem *ati; |
873 | QRegExp r( findString ); | 642 | QRegExp r( findString ); |
874 | r.setCaseSensitive( caseSensitive ); | 643 | r.setCaseSensitive( caseSensitive ); |
@@ -879,13 +648,14 @@ void AbTable::slotDoFind( const QString &findString, bool caseSensitive, | |||
879 | for ( row = currFindRow + 1; row < rows; row++ ) { | 648 | for ( row = currFindRow + 1; row < rows; row++ ) { |
880 | ati = static_cast<AbTableItem*>( item(row, 0) ); | 649 | ati = static_cast<AbTableItem*>( item(row, 0) ); |
881 | if ( contactCompare( contactList[ati], r, category ) ) | 650 | if ( contactCompare( contactList[ati], r, category ) ) |
651 | //if ( contactCompare( contactList[row], r, category ) ) | ||
882 | break; | 652 | break; |
883 | |||
884 | } | 653 | } |
885 | } else { | 654 | } else { |
886 | for ( row = currFindRow - 1; row > -1; row-- ) { | 655 | for ( row = currFindRow - 1; row > -1; row-- ) { |
887 | ati = static_cast<AbTableItem*>( item(row, 0) ); | 656 | ati = static_cast<AbTableItem*>( item(row, 0) ); |
888 | if ( contactCompare( contactList[ati], r, category ) ) | 657 | if ( contactCompare( contactList[ati], r, category ) ) |
658 | //if ( contactCompare( contactList[row], r, category ) ) | ||
889 | break; | 659 | break; |
890 | } | 660 | } |
891 | } | 661 | } |
@@ -912,7 +682,7 @@ void AbTable::slotDoFind( const QString &findString, bool caseSensitive, | |||
912 | } | 682 | } |
913 | } | 683 | } |
914 | 684 | ||
915 | static bool contactCompare( const Contact &cnt, const QRegExp &r, int category ) | 685 | static bool contactCompare( const OContact &cnt, const QRegExp &r, int category ) |
916 | { | 686 | { |
917 | bool returnMe; | 687 | bool returnMe; |
918 | QArray<int> cats; | 688 | QArray<int> cats; |
@@ -930,16 +700,29 @@ static bool contactCompare( const Contact &cnt, const QRegExp &r, int category ) | |||
930 | } | 700 | } |
931 | } | 701 | } |
932 | } | 702 | } |
703 | |||
933 | return returnMe; | 704 | return returnMe; |
934 | } | 705 | } |
935 | 706 | ||
936 | void AbTable::fitColumns() | 707 | void AbTable::fitColumns() |
937 | { | 708 | { |
938 | int contentsWidth = visibleWidth(); | 709 | int contentsWidth = visibleWidth() / 2; |
939 | int n = numCols(); | 710 | |
940 | int pw = n == 3 ? columnWidth(2) : 0; | 711 | if ( showBk == "Cards" ) { |
941 | setColumnWidth( 0, contentsWidth - contentsWidth / 2 ); | 712 | showColumn(1); |
942 | setColumnWidth( 1, contentsWidth / 2 - pw ); | 713 | //adjustColumn(1); |
714 | setColumnWidth( 1, visibleWidth() ); | ||
715 | columnVisible = false; | ||
716 | } else { | ||
717 | if ( columnVisible == false ){ | ||
718 | showColumn(0); | ||
719 | columnVisible = true; | ||
720 | } | ||
721 | setColumnWidth( 0, contentsWidth ); | ||
722 | adjustColumn(1); | ||
723 | if ( columnWidth(1) < contentsWidth ) | ||
724 | setColumnWidth( 1, contentsWidth ); | ||
725 | } | ||
943 | } | 726 | } |
944 | 727 | ||
945 | void AbTable::show() | 728 | void AbTable::show() |
@@ -983,14 +766,14 @@ void AbTable::setChoiceSelection(int /*index*/, const QStringList& /*list*/) | |||
983 | 766 | ||
984 | QString selname = choicenames.at(index); | 767 | QString selname = choicenames.at(index); |
985 | for (each row) { | 768 | for (each row) { |
986 | Contact *c = contactForRow(row); | 769 | OContact *c = contactForRow(row); |
987 | if ( list.contains(c->email) ) { | 770 | if ( list.contains(c->email) ) { |
988 | list.remove(c->email); | 771 | list.remove(c->email); |
989 | setText(row, 2, selname); | 772 | setText(row, 2, selname); |
990 | } | 773 | } |
991 | } | 774 | } |
992 | for (remaining list items) { | 775 | for (remaining list items) { |
993 | Contact *c = new contact(item); | 776 | OContact *c = new contact(item); |
994 | setText(newrow, 2, selname); | 777 | setText(newrow, 2, selname); |
995 | } | 778 | } |
996 | 779 | ||
@@ -1004,7 +787,7 @@ QStringList AbTable::choiceSelection(int /*index*/) const | |||
1004 | 787 | ||
1005 | QString selname = choicenames.at(index); | 788 | QString selname = choicenames.at(index); |
1006 | for (each row) { | 789 | for (each row) { |
1007 | Contact *c = contactForRow(row); | 790 | OContact *c = contactForRow(row); |
1008 | if ( text(row,2) == selname ) { | 791 | if ( text(row,2) == selname ) { |
1009 | r.append(c->email); | 792 | r.append(c->email); |
1010 | } | 793 | } |
@@ -1014,10 +797,15 @@ QStringList AbTable::choiceSelection(int /*index*/) const | |||
1014 | return r; | 797 | return r; |
1015 | } | 798 | } |
1016 | 799 | ||
1017 | void AbTable::setShowCategory( const QString &c ) | 800 | void AbTable::setShowCategory( const QString &b, const QString &c ) |
1018 | { | 801 | { |
802 | showBk = b; | ||
1019 | showCat = c; | 803 | showCat = c; |
1020 | updateVisible(); | 804 | //QMessageBox::information( this, "setShowCategory", "setShowCategory" ); |
805 | //updateVisible(); | ||
806 | refresh(); | ||
807 | ensureCellVisible( currentRow(), 0 ); | ||
808 | updateVisible(); // :SX | ||
1021 | } | 809 | } |
1022 | 810 | ||
1023 | void AbTable::setShowByLetter( char c ) | 811 | void AbTable::setShowByLetter( char c ) |
@@ -1031,6 +819,10 @@ QString AbTable::showCategory() const | |||
1031 | return showCat; | 819 | return showCat; |
1032 | } | 820 | } |
1033 | 821 | ||
822 | QString AbTable::showBook() const | ||
823 | { | ||
824 | return showBk; | ||
825 | } | ||
1034 | 826 | ||
1035 | QStringList AbTable::categories() | 827 | QStringList AbTable::categories() |
1036 | { | 828 | { |
@@ -1049,7 +841,7 @@ void AbTable::updateVisible() | |||
1049 | row; | 841 | row; |
1050 | bool hide; | 842 | bool hide; |
1051 | AbTableItem *ati; | 843 | AbTableItem *ati; |
1052 | Contact *cnt; | 844 | OContact *cnt; |
1053 | QString fileAsName; | 845 | QString fileAsName; |
1054 | QString tmpStr; | 846 | QString tmpStr; |
1055 | visible = 0; | 847 | visible = 0; |