diff options
author | Emanoil Kotsev <deloptes@gmail.com> | 2016-05-29 02:31:06 +0200 |
---|---|---|
committer | Slávek Banko <slavek.banko@axis.cz> | 2017-07-22 15:56:45 +0200 |
commit | 787be02d8623d61291d1778aff87c122142f1448 (patch) | |
tree | 1449071179b3898049ceb724b57ba20fbcd3aef8 /kabc/plugins/file/resourcefile.cpp | |
parent | 2deafc497132f3e413ef0fa64c656e0ce9b9a8a7 (diff) | |
download | tdelibs-787be02d8623d61291d1778aff87c122142f1448.tar.gz tdelibs-787be02d8623d61291d1778aff87c122142f1448.zip |
Fix utf8 support in tdeabc vCard parser
This resolves bug 2625
Signed-off-by: Emanoil Kotsev <deloptes@gmail.com>
(cherry picked from commit 4ceb2b158b3ed1ba1c78ab886b08a0bf40577d51)
Diffstat (limited to 'kabc/plugins/file/resourcefile.cpp')
-rw-r--r-- | kabc/plugins/file/resourcefile.cpp | 82 |
1 files changed, 53 insertions, 29 deletions
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp index b391dffa5..bc59fd877 100644 --- a/kabc/plugins/file/resourcefile.cpp +++ b/kabc/plugins/file/resourcefile.cpp @@ -164,33 +164,45 @@ bool ResourceFile::doOpen() if ( file.size() == 0 ) { file.close(); - kdDebug() << "File size is zero. Evaluating backups" << endl; + kdDebug(5700) << "File size is zero. Evaluating backups" << endl; for (int i=0; i!=20; i++) { TQFile backup( mFileName + "__" + TQString::number(i) ); - kdDebug() << "Evaluating" << backup.name() << " size: " << backup.size() << endl; + kdDebug(5700) << "Evaluating" << backup.name() << " size: " << backup.size() << endl; if ( backup.size() != 0 ) { - kdDebug() << "Restoring backup " << i << endl; + kdDebug(5700) << "Restoring backup " << i << endl; const TQString src = mFileName + "__" + TQString::number(i); const TQString dest = mFileName; + // copy src to dest + if ( ! backup.open( IO_ReadOnly ) ) { +// const TQByteArray data = backup.readAll(); + kdDebug(5700) << "can not open source for reading " << src << endl; + continue; + } + // remove dest TQFile::remove( dest ); - // copy src to dest - if ( backup.open( IO_ReadOnly ) ) { - const TQByteArray data = backup.readAll(); - - TQFile out( dest ); - if ( out.open( IO_WriteOnly ) ) { - out.writeBlock( data ); - out.close(); - } - - backup.close(); - } - return true; + TQString text; + TQTextStream instream( &backup ); + instream.setEncoding( TQTextStream::UnicodeUTF8 ); + text = instream.read(); + backup.close(); + + TQFile out( dest ); + if ( ! out.open( IO_WriteOnly ) ) { +// out.writeBlock( data ); + kdDebug(5700) << "can not open target for writing " << dest << endl; + continue; + } + TQTextStream outstream( &out ); + outstream.setEncoding( TQTextStream::UnicodeUTF8 ); + outstream << text; + out.close(); + + return true; } } return true; @@ -248,7 +260,7 @@ bool ResourceFile::save( Ticket * ) TQFile file( mFileName + "__0" ); if ( file.size() != 0 ) { const TQString last = mFileName + "__20"; - kdDebug() << "deleting " << last << endl; + kdDebug(5700) << "deleting " << last << endl; TQFile::remove( last ); @@ -260,28 +272,40 @@ bool ResourceFile::save( Ticket * ) // copy src to dest TQFile in( src ); - if ( in.open( IO_ReadOnly ) ) { - const TQByteArray data = in.readAll(); - - TQFile out( dest ); - if ( out.open( IO_WriteOnly ) ) { - out.writeBlock( data ); - out.close(); - } - - in.close(); + if ( ! in.exists() ) + continue; + if ( ! in.open( IO_ReadOnly ) ) { +// const TQByteArray data = in.readAll(); + kdDebug(5700) << "can not open source for reading " << src << endl; + return false; } + TQString text; + TQTextStream instream( &in ); + + instream.setEncoding( TQTextStream::UnicodeUTF8 ); + text = instream.read(); + in.close(); + + TQFile out( dest ); + if ( ! out.open( IO_WriteOnly ) ) { +// out.writeBlock( data ); + kdDebug(5700) << "can not open target for writing " << dest << endl; + return false; + } + TQTextStream outstream( &out ); + outstream.setEncoding( TQTextStream::UnicodeUTF8 ); + outstream << text; + out.close(); // remove src TQFile::remove( src ); } } else - kdDebug() << "Not starting logrotate __0 is 0 bytes." << endl; + kdDebug(5700) << "Not starting logrotate __0 is 0 bytes." << endl; TQString extension = "__0"; (void) KSaveFile::backupFile( mFileName, TQString::null /*directory*/, extension ); - mDirWatch.stopScan(); KSaveFile saveFile( mFileName ); |