summaryrefslogtreecommitdiff
authorzecke <zecke>2002-06-19 17:38:11 (UTC)
committer zecke <zecke>2002-06-19 17:38:11 (UTC)
commit23ac56db3aa77b298f20b288aadf503fd09a23a9 (patch) (unidiff)
treefe820ec743bbf829d31ae3ab1436a41a69b1855c
parentdee5f6c5a3bd982913d0b234fb9392ce68d5df63 (diff)
downloadopie-23ac56db3aa77b298f20b288aadf503fd09a23a9.zip
opie-23ac56db3aa77b298f20b288aadf503fd09a23a9.tar.gz
opie-23ac56db3aa77b298f20b288aadf503fd09a23a9.tar.bz2
Tille ask Diana how she was able to trigger that bug?
I nominate her for the bug finding queen 2002. Ok I just fixed two possible crashes with the risk of losing data.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/addressbook/abtable.cpp25
1 files changed, 17 insertions, 8 deletions
diff --git a/core/pim/addressbook/abtable.cpp b/core/pim/addressbook/abtable.cpp
index e9e6a0b..3fa1a7c 100644
--- a/core/pim/addressbook/abtable.cpp
+++ b/core/pim/addressbook/abtable.cpp
@@ -517,96 +517,98 @@ bool AbTable::save( const QString &fn )
517 QCString cstr = out.utf8(); 517 QCString cstr = out.utf8();
518 total_written = f.writeBlock( cstr.data(), cstr.length() ); 518 total_written = f.writeBlock( cstr.data(), cstr.length() );
519 if ( total_written != int(cstr.length()) ) { 519 if ( total_written != int(cstr.length()) ) {
520 f.close(); 520 f.close();
521 QFile::remove( strNewFile ); 521 QFile::remove( strNewFile );
522 return false; 522 return false;
523 } 523 }
524 f.close(); 524 f.close();
525 525
526// qDebug("saving: %d", t.elapsed() ); 526// qDebug("saving: %d", t.elapsed() );
527 527
528 // move the file over, I'm just going to use the system call 528 // move the file over, I'm just going to use the system call
529 // because, I don't feel like using QDir. 529 // because, I don't feel like using QDir.
530 if ( ::rename( strNewFile.latin1(), fn.latin1() ) < 0 ) { 530 if ( ::rename( strNewFile.latin1(), fn.latin1() ) < 0 ) {
531 qWarning( "problem renaming file %s to %s, errno: %d", 531 qWarning( "problem renaming file %s to %s, errno: %d",
532 strNewFile.latin1(), fn.latin1(), errno ); 532 strNewFile.latin1(), fn.latin1(), errno );
533 // remove the tmp file... 533 // remove the tmp file...
534 QFile::remove( strNewFile ); 534 QFile::remove( strNewFile );
535 } 535 }
536 // remove the journal... 536 // remove the journal...
537 QFile::remove( journalFileName() ); 537 QFile::remove( journalFileName() );
538 return true; 538 return true;
539} 539}
540 540
541void AbTable::load( const QString &fn ) 541void AbTable::load( const QString &fn )
542{ 542{
543 setSorting( false ); 543 setSorting( false );
544 loadFile( fn, false ); 544 loadFile( fn, false );
545 // merge in the journal 545 // merge in the journal
546 if ( QFile::exists( journalFileName() ) ) { 546 if ( QFile::exists( journalFileName() ) ) {
547 loadFile( journalFileName(), true ); 547 loadFile( journalFileName(), true );
548 save( fn ); 548 save( fn );
549 } 549 }
550 setSorting( true ); 550 setSorting( true );
551 resort(); 551 resort();
552} 552}
553 553
554void AbTable::loadFile( const QString &strFile, bool journalFile ) 554void AbTable::loadFile( const QString &strFile, bool journalFile )
555{ 555{
556// QTime t; 556// QTime t;
557// t.start(); 557// t.start();
558 QFile f( strFile ); 558 QFile f( strFile );
559 if ( !f.open(IO_ReadOnly) ) 559 if ( !f.open(IO_ReadOnly) )
560 return; 560 return;
561 QList<Contact> list; 561 QList<Contact> list;
562 list.setAutoDelete( TRUE ); 562 list.setAutoDelete( TRUE );
563 QByteArray ba = f.readAll(); 563 QByteArray ba = f.readAll();
564 f.close(); 564 f.close();
565 if (ba.isEmpty() )
566 return;
565 char *uc = ba.data();//(QChar *)data.unicode(); 567 char *uc = ba.data();//(QChar *)data.unicode();
566 int len = ba.size();//data.length(); 568 int len = ba.size();//data.length();
567 bool foundAction = false; 569 bool foundAction = false;
568 Contact::journal_action action; 570 Contact::journal_action action;
569 bool foundKey = false; 571 bool foundKey = false;
570 int journalKey = 0; 572 int journalKey = 0;
571 573
572 const int JOURNALACTION = Qtopia::Notes + 1; 574 const int JOURNALACTION = Qtopia::Notes + 1;
573 const int JOURNALROW = JOURNALACTION + 1; 575 const int JOURNALROW = JOURNALACTION + 1;
574 576
575 // ********************************** 577 // **********************************
576 // CHANGE THE SIZE OF THE DICT IF YOU ADD ANY MORE FIELDS!!!! 578 // CHANGE THE SIZE OF THE DICT IF YOU ADD ANY MORE FIELDS!!!!
577 // ********************************** 579 // **********************************
578 QAsciiDict<int> dict( 47 ); 580 QAsciiDict<int> dict( 47 );
579 dict.setAutoDelete( TRUE ); 581 dict.setAutoDelete( TRUE );
580 dict.insert( "Uid", new int(Qtopia::AddressUid) ); 582 dict.insert( "Uid", new int(Qtopia::AddressUid) );
581 dict.insert( "Title", new int(Qtopia::Title) ); 583 dict.insert( "Title", new int(Qtopia::Title) );
582 dict.insert( "FirstName", new int(Qtopia::FirstName) ); 584 dict.insert( "FirstName", new int(Qtopia::FirstName) );
583 dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); 585 dict.insert( "MiddleName", new int(Qtopia::MiddleName) );
584 dict.insert( "LastName", new int(Qtopia::LastName) ); 586 dict.insert( "LastName", new int(Qtopia::LastName) );
585 dict.insert( "Suffix", new int(Qtopia::Suffix) ); 587 dict.insert( "Suffix", new int(Qtopia::Suffix) );
586 dict.insert( "FileAs", new int(Qtopia::FileAs) ); 588 dict.insert( "FileAs", new int(Qtopia::FileAs) );
587 dict.insert( "Categories", new int(Qtopia::AddressCategory) ); 589 dict.insert( "Categories", new int(Qtopia::AddressCategory) );
588 dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); 590 dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) );
589 dict.insert( "Emails", new int(Qtopia::Emails) ); 591 dict.insert( "Emails", new int(Qtopia::Emails) );
590 dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); 592 dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) );
591 dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); 593 dict.insert( "HomeCity", new int(Qtopia::HomeCity) );
592 dict.insert( "HomeState", new int(Qtopia::HomeState) ); 594 dict.insert( "HomeState", new int(Qtopia::HomeState) );
593 dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); 595 dict.insert( "HomeZip", new int(Qtopia::HomeZip) );
594 dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); 596 dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) );
595 dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); 597 dict.insert( "HomePhone", new int(Qtopia::HomePhone) );
596 dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); 598 dict.insert( "HomeFax", new int(Qtopia::HomeFax) );
597 dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); 599 dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) );
598 dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); 600 dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) );
599 dict.insert( "Company", new int(Qtopia::Company) ); 601 dict.insert( "Company", new int(Qtopia::Company) );
600 dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); 602 dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) );
601 dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); 603 dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) );
602 dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); 604 dict.insert( "BusinessState", new int(Qtopia::BusinessState) );
603 dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); 605 dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) );
604 dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); 606 dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) );
605 dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); 607 dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) );
606 dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); 608 dict.insert( "JobTitle", new int(Qtopia::JobTitle) );
607 dict.insert( "Department", new int(Qtopia::Department) ); 609 dict.insert( "Department", new int(Qtopia::Department) );
608 dict.insert( "Office", new int(Qtopia::Office) ); 610 dict.insert( "Office", new int(Qtopia::Office) );
609 dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); 611 dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) );
610 dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); 612 dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) );
611 dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); 613 dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) );
612 dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); 614 dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) );
@@ -752,107 +754,114 @@ void AbTable::realignTable( int row )
752 ti2 = item( curr + 1, 1 ); 754 ti2 = item( curr + 1, 1 );
753 takeItem( ti1 ); 755 takeItem( ti1 );
754 takeItem( ti2 ); 756 takeItem( ti2 );
755 setItem( curr, 0, ti1 ); 757 setItem( curr, 0, ti1 );
756 setItem( curr, 1, ti2 ); 758 setItem( curr, 1, ti2 );
757 } 759 }
758 setNumRows( totalRows - 1 ); 760 setNumRows( totalRows - 1 );
759 resort(); 761 resort();
760} 762}
761 763
762void AbTable::insertIntoTable( const Contact &cnt, int row ) 764void AbTable::insertIntoTable( const Contact &cnt, int row )
763{ 765{
764 QString strName, 766 QString strName,
765 strContact; 767 strContact;
766 768
767 strName = findContactName( cnt ); 769 strName = findContactName( cnt );
768 strContact = findContactContact( cnt ); 770 strContact = findContactContact( cnt );
769 771
770 AbTableItem *ati; 772 AbTableItem *ati;
771 ati = new AbTableItem( this, QTableItem::Never, strName, strContact); 773 ati = new AbTableItem( this, QTableItem::Never, strName, strContact);
772 contactList.insert( ati, cnt ); 774 contactList.insert( ati, cnt );
773 setItem( row, 0, ati ); 775 setItem( row, 0, ati );
774 ati = new AbTableItem( this, QTableItem::Never, strContact, strName); 776 ati = new AbTableItem( this, QTableItem::Never, strContact, strName);
775 setItem( row, 1, ati ); 777 setItem( row, 1, ati );
776 778
777 //### cannot do this; table only has two columns at this point 779 //### cannot do this; table only has two columns at this point
778 // setItem( row, 2, new AbPickItem( this ) ); 780 // setItem( row, 2, new AbPickItem( this ) );
779 781
780 // resort at some point? 782 // resort at some point?
781} 783}
782 784
783void AbTable::internalAddEntries( QList<Contact> &list ) 785void AbTable::internalAddEntries( QList<Contact> &list )
784{ 786{
785 setUpdatesEnabled( FALSE ); 787 setUpdatesEnabled( FALSE );
786 setNumRows( list.count() ); 788 setNumRows( list.count() );
787 int row = 0; 789 int row = 0;
788 Contact *it; 790 Contact *it;
789 for ( it = list.first(); it; it = list.next() ) 791 for ( it = list.first(); it; it = list.next() )
790 insertIntoTable( *it, row++ ); 792 insertIntoTable( *it, row++ );
791 resort(); 793 resort();
792 setUpdatesEnabled( TRUE ); 794 setUpdatesEnabled( TRUE );
793} 795}
794 796
795 797
796void AbTable::journalFreeReplace( const Contact &cnt, int row ) 798void AbTable::journalFreeReplace( const Contact &cnt, int row )
797{ 799{
798 QString strName, 800 QString strName,
799 strContact; 801 strContact;
800 AbTableItem *ati; 802 AbTableItem *ati = 0l;
801 803
802 strName = findContactName( cnt ); 804 strName = findContactName( cnt );
803 strContact = findContactContact( cnt ); 805 strContact = findContactContact( cnt );
804 ati = static_cast<AbTableItem*>(item(row, 0)); 806 ati = static_cast<AbTableItem*>(item(row, 0));
805 contactList.remove( ati ); 807 if ( ati != 0 ) {
806 ati->setItem( strName, strContact ); 808 contactList.remove( ati );
807 contactList.insert( ati, cnt ); 809 ati->setItem( strName, strContact );
808 810 contactList.insert( ati, cnt );
809 ati = static_cast<AbTableItem*>(item(row, 1)); 811
810 ati->setItem( strContact, strName ); 812 ati = static_cast<AbTableItem*>(item(row, 1));
813 ati->setItem( strContact, strName );
814 }else{
815 int myrows = numRows();
816 setNumRows( myrows + 1 );
817 insertIntoTable( cnt, myrows );
818 // gets deleted when returning
819 }
811} 820}
812 821
813void AbTable::journalFreeRemove( int row ) 822void AbTable::journalFreeRemove( int row )
814{ 823{
815 AbTableItem *ati; 824 AbTableItem *ati;
816 ati = static_cast<AbTableItem*>(item(row, 0)); 825 ati = static_cast<AbTableItem*>(item(row, 0));
817 if ( !ati ) 826 if ( !ati )
818 return; 827 return;
819 contactList.remove( ati ); 828 contactList.remove( ati );
820 realignTable( row ); 829 realignTable( row );
821} 830}
822 831
823#if QT_VERSION <= 230 832#if QT_VERSION <= 230
824#ifndef SINGLE_APP 833#ifndef SINGLE_APP
825void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch ) 834void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch )
826{ 835{
827 // Region of the rect we should draw 836 // Region of the rect we should draw
828 QRegion reg( QRect( cx, cy, cw, ch ) ); 837 QRegion reg( QRect( cx, cy, cw, ch ) );
829 // Subtract the table from it 838 // Subtract the table from it
830 reg = reg.subtract( QRect( QPoint( 0, 0 ), tableSize() ) ); 839 reg = reg.subtract( QRect( QPoint( 0, 0 ), tableSize() ) );
831 // And draw the rectangles (transformed as needed) 840 // And draw the rectangles (transformed as needed)
832 QArray<QRect> r = reg.rects(); 841 QArray<QRect> r = reg.rects();
833 for (unsigned int i=0; i<r.count(); i++) 842 for (unsigned int i=0; i<r.count(); i++)
834 p->fillRect( r[i], colorGroup().brush( QColorGroup::Base ) ); 843 p->fillRect( r[i], colorGroup().brush( QColorGroup::Base ) );
835} 844}
836#endif 845#endif
837#endif 846#endif
838 847
839 848
840// int AbTable::rowHeight( int ) const 849// int AbTable::rowHeight( int ) const
841// { 850// {
842// return 18; 851// return 18;
843// } 852// }
844 853
845// int AbTable::rowPos( int row ) const 854// int AbTable::rowPos( int row ) const
846// { 855// {
847// return 18*row; 856// return 18*row;
848// } 857// }
849 858
850// int AbTable::rowAt( int pos ) const 859// int AbTable::rowAt( int pos ) const
851// { 860// {
852// return QMIN( pos/18, numRows()-1 ); 861// return QMIN( pos/18, numRows()-1 );
853// } 862// }
854 863
855void AbTable::slotDoFind( const QString &findString, bool caseSensitive, 864void AbTable::slotDoFind( const QString &findString, bool caseSensitive,
856 bool backwards, int category ) 865 bool backwards, int category )
857{ 866{
858 if ( currFindRow < -1 ) 867 if ( currFindRow < -1 )
@@ -1038,97 +1047,97 @@ void AbTable::updateVisible()
1038 totalCats, 1047 totalCats,
1039 it, 1048 it,
1040 row; 1049 row;
1041 bool hide; 1050 bool hide;
1042 AbTableItem *ati; 1051 AbTableItem *ati;
1043 Contact *cnt; 1052 Contact *cnt;
1044 QString fileAsName; 1053 QString fileAsName;
1045 QString tmpStr; 1054 QString tmpStr;
1046 visible = 0; 1055 visible = 0;
1047 1056
1048 setPaintingEnabled( FALSE ); 1057 setPaintingEnabled( FALSE );
1049 1058
1050 totalRows = numRows(); 1059 totalRows = numRows();
1051 id = mCat.id( "Contacts", showCat ); 1060 id = mCat.id( "Contacts", showCat );
1052 QArray<int> cats; 1061 QArray<int> cats;
1053 for ( row = 0; row < totalRows; row++ ) { 1062 for ( row = 0; row < totalRows; row++ ) {
1054 ati = static_cast<AbTableItem*>( item(row, 0) ); 1063 ati = static_cast<AbTableItem*>( item(row, 0) );
1055 cnt = &contactList[ati]; 1064 cnt = &contactList[ati];
1056 cats = cnt->categories(); 1065 cats = cnt->categories();
1057 fileAsName = cnt->fileAs(); 1066 fileAsName = cnt->fileAs();
1058 hide = false; 1067 hide = false;
1059 if ( !showCat.isEmpty() ) { 1068 if ( !showCat.isEmpty() ) {
1060 if ( showCat == tr( "Unfiled" ) ) { 1069 if ( showCat == tr( "Unfiled" ) ) {
1061 if ( cats.count() > 0 ) 1070 if ( cats.count() > 0 )
1062 hide = true; 1071 hide = true;
1063 } else { 1072 } else {
1064 // do some comparing 1073 // do some comparing
1065 if ( !hide ) { 1074 if ( !hide ) {
1066 hide = true; 1075 hide = true;
1067 totalCats = int(cats.count()); 1076 totalCats = int(cats.count());
1068 for ( it = 0; it < totalCats; it++ ) { 1077 for ( it = 0; it < totalCats; it++ ) {
1069 if ( cats[it] == id ) { 1078 if ( cats[it] == id ) {
1070 hide = false; 1079 hide = false;
1071 break; 1080 break;
1072 } 1081 }
1073 } 1082 }
1074 } 1083 }
1075 } 1084 }
1076 } 1085 }
1077 if ( showChar != '\0' ) { 1086 if ( showChar != '\0' ) {
1078 tmpStr = fileAsName.left(1); 1087 tmpStr = fileAsName.left(1);
1079 tmpStr = tmpStr.lower(); 1088 tmpStr = tmpStr.lower();
1080 if ( tmpStr != QString(QChar(showChar)) && showChar != '#' ) { 1089 if ( tmpStr != QString(QChar(showChar)) && showChar != '#' ) {
1081 hide = true; 1090 hide = true;
1082 } 1091 }
1083 if ( showChar == '#' ) { 1092 if ( showChar == '#' ) {
1084 if (tmpStr == "a") 1093 if (tmpStr == "a")
1085 hide = true; 1094 hide = true;
1086 1095
1087 if (tmpStr == "b") 1096 if (tmpStr == "b")
1088 hide = true; 1097 hide = true;
1089 1098
1090 if (tmpStr == "c") 1099 if (tmpStr == "c")
1091 hide = true; 1100 hide = true;
1092 1101
1093 if (tmpStr == "d") 1102 if (tmpStr == "d")
1094 hide = true; 1103 hide = true;
1095 1104
1096 if (tmpStr == "e") 1105 if (tmpStr == "e")
1097 hide = true; 1106 hide = true;
1098 1107
1099 if (tmpStr == "f") 1108 if (tmpStr == "f")
1100 hide = true; 1109 hide = true;
1101 1110
1102 if (tmpStr == "g") 1111 if (tmpStr == "g")
1103 hide = true; 1112 hide = true;
1104 1113
1105 if (tmpStr == "h") 1114 if (tmpStr == "h")
1106 hide = true; 1115 hide = true;
1107 1116
1108 if (tmpStr == "i") 1117 if (tmpStr == "i")
1109 hide = true; 1118 hide = true;
1110 1119
1111 if (tmpStr == "j") 1120 if (tmpStr == "j")
1112 hide = true; 1121 hide = true;
1113 1122
1114 if (tmpStr == "k") 1123 if (tmpStr == "k")
1115 hide = true; 1124 hide = true;
1116 1125
1117 if (tmpStr == "l") 1126 if (tmpStr == "l")
1118 hide = true; 1127 hide = true;
1119 1128
1120 if (tmpStr == "m") 1129 if (tmpStr == "m")
1121 hide = true; 1130 hide = true;
1122 1131
1123 if (tmpStr == "n") 1132 if (tmpStr == "n")
1124 hide = true; 1133 hide = true;
1125 1134
1126 if (tmpStr == "o") 1135 if (tmpStr == "o")
1127 hide = true; 1136 hide = true;
1128 1137
1129 if (tmpStr == "p") 1138 if (tmpStr == "p")
1130 hide = true; 1139 hide = true;
1131 1140
1132 if (tmpStr == "q") 1141 if (tmpStr == "q")
1133 hide = true; 1142 hide = true;
1134 1143