author | zecke <zecke> | 2002-06-19 17:38:11 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-06-19 17:38:11 (UTC) |
commit | 23ac56db3aa77b298f20b288aadf503fd09a23a9 (patch) (side-by-side diff) | |
tree | fe820ec743bbf829d31ae3ab1436a41a69b1855c | |
parent | dee5f6c5a3bd982913d0b234fb9392ce68d5df63 (diff) | |
download | opie-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.
-rw-r--r-- | core/pim/addressbook/abtable.cpp | 25 |
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 ) QCString cstr = out.utf8(); total_written = f.writeBlock( cstr.data(), cstr.length() ); if ( total_written != int(cstr.length()) ) { f.close(); QFile::remove( strNewFile ); return false; } f.close(); // qDebug("saving: %d", t.elapsed() ); // move the file over, I'm just going to use the system call // because, I don't feel like using QDir. if ( ::rename( strNewFile.latin1(), fn.latin1() ) < 0 ) { qWarning( "problem renaming file %s to %s, errno: %d", strNewFile.latin1(), fn.latin1(), errno ); // remove the tmp file... QFile::remove( strNewFile ); } // remove the journal... QFile::remove( journalFileName() ); return true; } void AbTable::load( const QString &fn ) { setSorting( false ); loadFile( fn, false ); // merge in the journal if ( QFile::exists( journalFileName() ) ) { loadFile( journalFileName(), true ); save( fn ); } setSorting( true ); resort(); } void AbTable::loadFile( const QString &strFile, bool journalFile ) { // QTime t; // t.start(); QFile f( strFile ); if ( !f.open(IO_ReadOnly) ) return; QList<Contact> list; list.setAutoDelete( TRUE ); QByteArray ba = f.readAll(); f.close(); + if (ba.isEmpty() ) + return; char *uc = ba.data();//(QChar *)data.unicode(); int len = ba.size();//data.length(); bool foundAction = false; Contact::journal_action action; bool foundKey = false; int journalKey = 0; const int JOURNALACTION = Qtopia::Notes + 1; const int JOURNALROW = JOURNALACTION + 1; // ********************************** // CHANGE THE SIZE OF THE DICT IF YOU ADD ANY MORE FIELDS!!!! // ********************************** QAsciiDict<int> dict( 47 ); dict.setAutoDelete( TRUE ); dict.insert( "Uid", new int(Qtopia::AddressUid) ); dict.insert( "Title", new int(Qtopia::Title) ); dict.insert( "FirstName", new int(Qtopia::FirstName) ); dict.insert( "MiddleName", new int(Qtopia::MiddleName) ); dict.insert( "LastName", new int(Qtopia::LastName) ); dict.insert( "Suffix", new int(Qtopia::Suffix) ); dict.insert( "FileAs", new int(Qtopia::FileAs) ); dict.insert( "Categories", new int(Qtopia::AddressCategory) ); dict.insert( "DefaultEmail", new int(Qtopia::DefaultEmail) ); dict.insert( "Emails", new int(Qtopia::Emails) ); dict.insert( "HomeStreet", new int(Qtopia::HomeStreet) ); dict.insert( "HomeCity", new int(Qtopia::HomeCity) ); dict.insert( "HomeState", new int(Qtopia::HomeState) ); dict.insert( "HomeZip", new int(Qtopia::HomeZip) ); dict.insert( "HomeCountry", new int(Qtopia::HomeCountry) ); dict.insert( "HomePhone", new int(Qtopia::HomePhone) ); dict.insert( "HomeFax", new int(Qtopia::HomeFax) ); dict.insert( "HomeMobile", new int(Qtopia::HomeMobile) ); dict.insert( "HomeWebPage", new int(Qtopia::HomeWebPage) ); dict.insert( "Company", new int(Qtopia::Company) ); dict.insert( "BusinessStreet", new int(Qtopia::BusinessStreet) ); dict.insert( "BusinessCity", new int(Qtopia::BusinessCity) ); dict.insert( "BusinessState", new int(Qtopia::BusinessState) ); dict.insert( "BusinessZip", new int(Qtopia::BusinessZip) ); dict.insert( "BusinessCountry", new int(Qtopia::BusinessCountry) ); dict.insert( "BusinessWebPage", new int(Qtopia::BusinessWebPage) ); dict.insert( "JobTitle", new int(Qtopia::JobTitle) ); dict.insert( "Department", new int(Qtopia::Department) ); dict.insert( "Office", new int(Qtopia::Office) ); dict.insert( "BusinessPhone", new int(Qtopia::BusinessPhone) ); dict.insert( "BusinessFax", new int(Qtopia::BusinessFax) ); dict.insert( "BusinessMobile", new int(Qtopia::BusinessMobile) ); dict.insert( "BusinessPager", new int(Qtopia::BusinessPager) ); @@ -752,107 +754,114 @@ void AbTable::realignTable( int row ) ti2 = item( curr + 1, 1 ); takeItem( ti1 ); takeItem( ti2 ); setItem( curr, 0, ti1 ); setItem( curr, 1, ti2 ); } setNumRows( totalRows - 1 ); resort(); } void AbTable::insertIntoTable( const Contact &cnt, int row ) { QString strName, strContact; strName = findContactName( cnt ); strContact = findContactContact( cnt ); AbTableItem *ati; ati = new AbTableItem( this, QTableItem::Never, strName, strContact); contactList.insert( ati, cnt ); setItem( row, 0, ati ); ati = new AbTableItem( this, QTableItem::Never, strContact, strName); setItem( row, 1, ati ); //### cannot do this; table only has two columns at this point // setItem( row, 2, new AbPickItem( this ) ); // resort at some point? } void AbTable::internalAddEntries( QList<Contact> &list ) { setUpdatesEnabled( FALSE ); setNumRows( list.count() ); int row = 0; Contact *it; for ( it = list.first(); it; it = list.next() ) insertIntoTable( *it, row++ ); resort(); setUpdatesEnabled( TRUE ); } void AbTable::journalFreeReplace( const Contact &cnt, int row ) { QString strName, strContact; - AbTableItem *ati; + AbTableItem *ati = 0l; strName = findContactName( cnt ); strContact = findContactContact( cnt ); ati = static_cast<AbTableItem*>(item(row, 0)); - contactList.remove( ati ); - ati->setItem( strName, strContact ); - contactList.insert( ati, cnt ); - - ati = static_cast<AbTableItem*>(item(row, 1)); - ati->setItem( strContact, strName ); + if ( ati != 0 ) { + contactList.remove( ati ); + ati->setItem( strName, strContact ); + contactList.insert( ati, cnt ); + + ati = static_cast<AbTableItem*>(item(row, 1)); + ati->setItem( strContact, strName ); + }else{ + int myrows = numRows(); + setNumRows( myrows + 1 ); + insertIntoTable( cnt, myrows ); + // gets deleted when returning + } } void AbTable::journalFreeRemove( int row ) { AbTableItem *ati; ati = static_cast<AbTableItem*>(item(row, 0)); if ( !ati ) return; contactList.remove( ati ); realignTable( row ); } #if QT_VERSION <= 230 #ifndef SINGLE_APP void QTable::paintEmptyArea( QPainter *p, int cx, int cy, int cw, int ch ) { // Region of the rect we should draw QRegion reg( QRect( cx, cy, cw, ch ) ); // Subtract the table from it reg = reg.subtract( QRect( QPoint( 0, 0 ), tableSize() ) ); // And draw the rectangles (transformed as needed) QArray<QRect> r = reg.rects(); for (unsigned int i=0; i<r.count(); i++) p->fillRect( r[i], colorGroup().brush( QColorGroup::Base ) ); } #endif #endif // int AbTable::rowHeight( int ) const // { // return 18; // } // int AbTable::rowPos( int row ) const // { // return 18*row; // } // int AbTable::rowAt( int pos ) const // { // return QMIN( pos/18, numRows()-1 ); // } void AbTable::slotDoFind( const QString &findString, bool caseSensitive, bool backwards, int category ) { if ( currFindRow < -1 ) @@ -1038,97 +1047,97 @@ void AbTable::updateVisible() totalCats, it, row; bool hide; AbTableItem *ati; Contact *cnt; QString fileAsName; QString tmpStr; visible = 0; setPaintingEnabled( FALSE ); totalRows = numRows(); id = mCat.id( "Contacts", showCat ); QArray<int> cats; for ( row = 0; row < totalRows; row++ ) { ati = static_cast<AbTableItem*>( item(row, 0) ); cnt = &contactList[ati]; cats = cnt->categories(); fileAsName = cnt->fileAs(); hide = false; if ( !showCat.isEmpty() ) { if ( showCat == tr( "Unfiled" ) ) { if ( cats.count() > 0 ) hide = true; } else { // do some comparing if ( !hide ) { hide = true; totalCats = int(cats.count()); for ( it = 0; it < totalCats; it++ ) { if ( cats[it] == id ) { hide = false; break; } } } } } if ( showChar != '\0' ) { tmpStr = fileAsName.left(1); tmpStr = tmpStr.lower(); if ( tmpStr != QString(QChar(showChar)) && showChar != '#' ) { hide = true; } if ( showChar == '#' ) { if (tmpStr == "a") hide = true; - + if (tmpStr == "b") hide = true; if (tmpStr == "c") hide = true; if (tmpStr == "d") hide = true; if (tmpStr == "e") hide = true; if (tmpStr == "f") hide = true; if (tmpStr == "g") hide = true; if (tmpStr == "h") hide = true; if (tmpStr == "i") hide = true; if (tmpStr == "j") hide = true; if (tmpStr == "k") hide = true; if (tmpStr == "l") hide = true; if (tmpStr == "m") hide = true; if (tmpStr == "n") hide = true; if (tmpStr == "o") hide = true; if (tmpStr == "p") hide = true; if (tmpStr == "q") hide = true; |