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
@@ -541,48 +541,50 @@ bool AbTable::save( const QString &fn )
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) );
@@ -776,59 +778,66 @@ void AbTable::insertIntoTable( const Contact &cnt, int row )
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 ) );
@@ -1062,49 +1071,49 @@ void AbTable::updateVisible()
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