summaryrefslogtreecommitdiffstats
path: root/kaddressbook/xxport/vcard_xxport.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-09-01 00:37:02 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-09-01 00:37:02 +0000
commitcc29364f06178f8f6b457384f2ec37a042bd9d43 (patch)
tree7c77a3184c698bbf9d98cef09fb1ba8124daceba /kaddressbook/xxport/vcard_xxport.cpp
parent4f6c584bacc8c3c694228f36ada3de77a76614a6 (diff)
downloadtdepim-cc29364f06178f8f6b457384f2ec37a042bd9d43.tar.gz
tdepim-cc29364f06178f8f6b457384f2ec37a042bd9d43.zip
* Massive set of changes to bring in all fixes and enhancements from the Enterprise PIM branch
* Ensured that the Trinity changes were applied on top of those enhancements, and any redundancy removed * Added journal read support to the CalDAV resource * Fixed CalDAV resource to use events URL for tasks and journals when separate URL checkbox unchecked git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1170461 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kaddressbook/xxport/vcard_xxport.cpp')
-rw-r--r--kaddressbook/xxport/vcard_xxport.cpp79
1 files changed, 73 insertions, 6 deletions
diff --git a/kaddressbook/xxport/vcard_xxport.cpp b/kaddressbook/xxport/vcard_xxport.cpp
index 85cf8c763..1dfc9bcc4 100644
--- a/kaddressbook/xxport/vcard_xxport.cpp
+++ b/kaddressbook/xxport/vcard_xxport.cpp
@@ -118,9 +118,15 @@ bool VCardXXPort::exportContacts( const KABC::AddresseeList &addrList, const TQS
return true;
if ( data == "v21" )
+#if defined(KABC_VCARD_ENCODING_FIX)
+ ok = doExport( url, converter.createVCardsRaw( list, KABC::VCardConverter::v2_1 ) );
+ else
+ ok = doExport( url, converter.createVCardsRaw( list, KABC::VCardConverter::v3_0 ) );
+#else
ok = doExport( url, converter.createVCards( list, KABC::VCardConverter::v2_1 ) );
else
ok = doExport( url, converter.createVCards( list, KABC::VCardConverter::v3_0 ) );
+#endif
} else {
TQString msg = i18n( "You have selected a list of contacts, shall they be "
"exported to several files?" );
@@ -151,10 +157,15 @@ bool VCardXXPort::exportContacts( const KABC::AddresseeList &addrList, const TQS
tmpList.append( *it );
if ( data == "v21" )
+#if defined(KABC_VCARD_ENCODING_FIX)
+ tmpOk = doExport( url, converter.createVCardsRaw( tmpList, KABC::VCardConverter::v2_1 ) );
+ else
+ tmpOk = doExport( url, converter.createVCardsRaw( tmpList, KABC::VCardConverter::v3_0 ) );
+#else
tmpOk = doExport( url, converter.createVCards( tmpList, KABC::VCardConverter::v2_1 ) );
else
tmpOk = doExport( url, converter.createVCards( tmpList, KABC::VCardConverter::v3_0 ) );
-
+#endif
ok = ok && tmpOk;
}
break;
@@ -166,9 +177,15 @@ bool VCardXXPort::exportContacts( const KABC::AddresseeList &addrList, const TQS
return true;
if ( data == "v21" )
+#if defined(KABC_VCARD_ENCODING_FIX)
+ ok = doExport( url, converter.createVCardsRaw( list, KABC::VCardConverter::v2_1 ) );
+ else
+ ok = doExport( url, converter.createVCardsRaw( list, KABC::VCardConverter::v3_0 ) );
+#else
ok = doExport( url, converter.createVCards( list, KABC::VCardConverter::v2_1 ) );
else
ok = doExport( url, converter.createVCards( list, KABC::VCardConverter::v3_0 ) );
+#endif
}
}
}
@@ -182,9 +199,14 @@ KABC::AddresseeList VCardXXPort::importContacts( const TQString& ) const
KABC::AddresseeList addrList;
KURL::List urls;
- if ( !XXPortManager::importData.isEmpty() )
+ if ( !XXPortManager::importData.isEmpty() ) {
+#if defined(KABC_VCARD_ENCODING_FIX)
+ TQCString data = XXPortManager::importData.ascii();
+ addrList = parseVCard( data );
+#else
addrList = parseVCard( XXPortManager::importData );
- else {
+#endif
+ } else {
if ( XXPortManager::importURL.isEmpty() )
urls = KFileDialog::getOpenURLs( TQString::null, "*.vcf|vCards", parentWidget(),
i18n( "Select vCard to Import" ) );
@@ -203,11 +225,28 @@ KABC::AddresseeList VCardXXPort::importContacts( const TQString& ) const
TQFile file( fileName );
if ( file.open( IO_ReadOnly ) ) {
+#if defined(KABC_VCARD_ENCODING_FIX)
+ TQByteArray data = file.readAll();
+ file.close();
+ if ( data.size() > 0 )
+ addrList += parseVCard( data );
+#else
TQByteArray rawData = file.readAll();
file.close();
- if ( rawData.size() > 0 )
- addrList += parseVCard( rawData );
-
+ if ( rawData.size() > 0 ) {
+
+ TQString vCardText;
+
+ // With version 3.0, vCards are encoded with UTF-8 by default. Otherwise, use fromLatin1()
+ // and hope that are fields are encoded correctly.
+ if ( TQString::fromLatin1( rawData ).lower().contains( "version:3.0" ) ) {
+ vCardText = TQString::fromUtf8( rawData );
+ } else {
+ vCardText = TQString::fromLatin1( rawData );
+ }
+ addrList += parseVCard( vCardText );
+ }
+#endif
KIO::NetAccess::removeTempFile( fileName );
} else {
TQString text = i18n( "<qt>When trying to read the vCard, there was an error opening the file '%1': %2</qt>" );
@@ -243,6 +282,29 @@ KABC::AddresseeList VCardXXPort::importContacts( const TQString& ) const
return addrList;
}
+#if defined(KABC_VCARD_ENCODING_FIX)
+KABC::AddresseeList VCardXXPort::parseVCard( const TQByteArray &data ) const
+{
+ KABC::VCardConverter converter;
+
+ return converter.parseVCardsRaw( data.data() );
+}
+
+bool VCardXXPort::doExport( const KURL &url, const TQByteArray &data )
+{
+ if( TQFileInfo(url.path()).exists() ) {
+ if(KMessageBox::questionYesNo( parentWidget(), i18n("Do you want to overwrite file \"%1\"").arg( url.path()) ) == KMessageBox::No)
+ return false;
+ }
+ KTempFile tmpFile;
+ tmpFile.setAutoDelete( true );
+
+ tmpFile.file()->writeBlock( data.data(), data.size() );
+ tmpFile.close();
+
+ return KIO::NetAccess::upload( tmpFile.name(), url, parentWidget() );
+}
+#else
KABC::AddresseeList VCardXXPort::parseVCard( const TQString &data ) const
{
KABC::VCardConverter converter;
@@ -252,6 +314,10 @@ KABC::AddresseeList VCardXXPort::parseVCard( const TQString &data ) const
bool VCardXXPort::doExport( const KURL &url, const TQString &data )
{
+ if( TQFileInfo(url.path()).exists() ) {
+ if(KMessageBox::questionYesNo( parentWidget(), i18n("Do you want to overwrite file \"%1\"").arg( url.path()) ) == KMessageBox::No)
+ return false;
+ }
KTempFile tmpFile;
tmpFile.setAutoDelete( true );
@@ -263,6 +329,7 @@ bool VCardXXPort::doExport( const KURL &url, const TQString &data )
return KIO::NetAccess::upload( tmpFile.name(), url, parentWidget() );
}
+#endif
KABC::AddresseeList VCardXXPort::filterContacts( const KABC::AddresseeList &addrList )
{