summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--kaddressbook/xxport/csv_xxport.cpp2
-rw-r--r--kaddressbook/xxport/opie/opie_xxport.cpp2
-rw-r--r--kaddressbook/xxport/vcard_xxport.cpp2
3 files changed, 3 insertions, 3 deletions
diff --git a/kaddressbook/xxport/csv_xxport.cpp b/kaddressbook/xxport/csv_xxport.cpp
index caee66d..d4d5475 100644
--- a/kaddressbook/xxport/csv_xxport.cpp
+++ b/kaddressbook/xxport/csv_xxport.cpp
@@ -27,166 +27,166 @@ Copyright (c) 2004 Ulf Schenk
$Id$
*/
#include <qfile.h>
#include <qregexp.h>
#include <qtextstream.h>
#include <kfiledialog.h>
#ifndef KAB_EMBEDDED
#include <kio/netaccess.h>
#endif //KAB_EMBEDDED
#include <klocale.h>
#include <kmessagebox.h>
#include <ktempfile.h>
#include <kurl.h>
#include "csvimportdialog.h"
#include "csv_xxport.h"
#ifndef KAB_EMBEDDED
class CSVXXPortFactory : public XXPortFactory
{
public:
XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
{
return new CSVXXPort( ab, parent, name );
}
};
#endif //KAB_EMBEDDED
extern "C"
{
#ifndef KAB_EMBEDDED
void *init_libkaddrbk_csv_xxport()
#else //KAB_EMBEDDED
void *init_kaddrbk_csv_xxport()
#endif //KAB_EMBEDDED
{
return ( new CSVXXPortFactory() );
}
}
CSVXXPort::CSVXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
: XXPortObject( ab, parent, name )
{
createImportAction( i18n( "Import CSV List..." ) );
createExportAction( i18n( "Export CSV List..." ) );
}
bool CSVXXPort::exportContacts( const KABC::AddresseeList &list, const QString& )
{
#ifndef KAB_EMBEDDED
KURL url = KFileDialog::getSaveURL( "addressbook.csv" );
if ( url.isEmpty() )
return true;
if ( !url.isLocalFile() ) {
KTempFile tmpFile;
if ( tmpFile.status() != 0 ) {
QString txt = i18n( "<qt>Unable to open file <b>%1</b>.%2.</qt>" );
KMessageBox::error( parentWidget(), txt.arg( url.url() )
.arg( strerror( tmpFile.status() ) ) );
return false;
}
doExport( tmpFile.file(), list );
tmpFile.close();
return KIO::NetAccess::upload( tmpFile.name(), url, parentWidget() );
} else {
QFile file( url.path() );
if ( !file.open( IO_WriteOnly ) ) {
QString txt = i18n( "<qt>Unable to open file <b>%1</b>.</qt>" );
KMessageBox::error( parentWidget(), txt.arg( url.path() ) );
return false;
}
doExport( &file, list );
file.close();
return true;
}
#else //KAB_EMBEDDED
QString fileName = KFileDialog::getSaveFileName( "addressbook.csv", i18n("Save file"), parentWidget() );
if ( fileName.isEmpty() )
- return true;
+ return false;
QFile file( fileName );
if ( !file.open( IO_WriteOnly ) ) {
QString txt = i18n( "<qt>Unable to open file <b>%1</b>.</qt>" );
KMessageBox::error( parentWidget(), txt.arg( fileName ) );
return false;
}
doExport( &file, list );
file.close();
return true;
#endif //KAB_EMBEDDED
}
KABC::AddresseeList CSVXXPort::importContacts( const QString& ) const
{
CSVImportDialog dlg( addressBook(), parentWidget() );
if ( dlg.exec() )
return dlg.contacts();
else
return KABC::AddresseeList();
}
void CSVXXPort::doExport( QFile *fp, const KABC::AddresseeList &list )
{
QTextStream t( fp );
KABC::AddresseeList::ConstIterator iter;
KABC::Field::List fields = addressBook()->fields();
KABC::Field::List::Iterator fieldIter;
bool first = true;
// First output the column headings
for ( fieldIter = fields.begin(); fieldIter != fields.end(); ++fieldIter ) {
if ( !first )
t << ",";
t << "\"" << (*fieldIter)->label() << "\"";
first = false;
}
t << "\n";
// Then all the addressee objects
KABC::Addressee addr;
for ( iter = list.begin(); iter != list.end(); ++iter ) {
addr = *iter;
first = true;
for ( fieldIter = fields.begin(); fieldIter != fields.end(); ++fieldIter ) {
if ( !first )
t << ",";
t << "\"" << (*fieldIter)->value( addr ).replace( QRegExp("\n"), "\\n" ) << "\"";
first = false;
}
t << "\n";
}
}
#ifndef KAB_EMBEDDED
#include "csv_xxport.moc"
#endif //KAB_EMBEDDED
diff --git a/kaddressbook/xxport/opie/opie_xxport.cpp b/kaddressbook/xxport/opie/opie_xxport.cpp
index db30d34..c9b0163 100644
--- a/kaddressbook/xxport/opie/opie_xxport.cpp
+++ b/kaddressbook/xxport/opie/opie_xxport.cpp
@@ -3,193 +3,193 @@
Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, permission is given to link this program
with any edition of Qt, and distribute the resulting executable,
without including the source code for Qt in the source distribution.
*/
/*
Enhanced Version of the file for platform independent KDE tools.
Copyright (c) 2004 Ulf Schenk
$Id$
*/
#include <qdir.h>
#include <kfiledialog.h>
#include <kmessagebox.h>
#include <opie/ocontactaccess.h>
#include <opie/ocontactaccessbackend_xml.h>
#include "stdaddressbook.h"
/*US
#include <qfile.h>
#include <qtextstream.h>
#include <kabc/vcardconverter.h>
#ifndef KAB_EMBEDDED
#include <kio/netaccess.h>
#endif //KAB_EMBEDDED
#include <klocale.h>
#include <kmessagebox.h>
#include <ktempfile.h>
#include <kurl.h>
*/
#include "xxportmanager.h"
#include "opieconverter.h"
#include "opie_xxport.h"
class OpieXXPortFactory : public XXPortFactory
{
public:
XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
{
return new OpieXXPort( ab, parent, name );
}
};
extern "C"
{
void *init_microkaddrbk_opie_xxport()
{
return ( new OpieXXPortFactory() );
}
}
OpieXXPort::OpieXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
: XXPortObject( ab, parent, name )
{
createImportAction( i18n( "Import Opie..." ) );
createExportAction( i18n( "Export Opie..." ) );
}
bool OpieXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data )
{
QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
#ifndef KAB_EMBEDDED
QString fileName = KFileDialog::getSaveFileName( name );
#else //KAB_EMBEDDED
QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() );
#endif //KAB_EMBEDDED
if ( fileName.isEmpty() )
- return true;
+ return false;
OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KA/Pi", fileName );
OContactAccess* access = new OContactAccess("KA/Pi", 0l, backend, false);
if ( !access ) {
qDebug("Unable to access file() %s", fileName.latin1());
addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) );
return false;
}
KABC::OpieConverter mConverter;
bool res = mConverter.init();
if (!res)
{
QString text( i18n( "Unable to initialize opie converter.<br>Most likely a problem with the category file." ) );
qDebug(text);
KMessageBox::error( parentWidget(), text );
delete access;
return false;
}
//Now check if the file has already entries, and ask the user if he wants to delete them first.
OContactAccess::List contactList = access->allRecords();
if (contactList.count() > 0)
{
QString text( i18n( "Do you want to remove<br>all existing entries from<br>%1<br>before exporting.?" ) );
if ( KMessageBox::questionYesNo( parentWidget(), text.arg( fileName ) ) == KMessageBox::Yes ) {
// Clean the database..
access->clear();
}
}
KABC::Addressee::List::ConstIterator it;
for ( it = list.begin(); it != list.end(); ++it ) {
OContact c;
KABC::Addressee addressee = (*it);
res = mConverter.addresseeToOpie( *it, c );
if (res == true)
{
res = access->add(c);
if (res == false)
qDebug("Unable to append Contact %s", c.fullName().latin1());
}
else
{
qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1());
}
}
access->save();
delete access;
//US the deletion of the access object deletes the backend object as well.
return true;
}
KABC::AddresseeList OpieXXPort::importContacts( const QString& ) const
{
KABC::AddresseeList adrlst;
QString name = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml";
#ifndef KAB_EMBEDDED
QString fileName = KFileDialog::getOpenFileName( name );
#else //KAB_EMBEDDED
QString fileName = KFileDialog::getOpenFileName( name, i18n("Load file"), parentWidget() );
#endif //KAB_EMBEDDED
if ( fileName.isEmpty() )
return KABC::AddresseeList();
OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KA/Pi", fileName );
OContactAccess* access = new OContactAccess("KA/Pi", 0l, backend, false);
if ( !access ) {
qDebug("Unable to access file() %s", fileName.latin1());
addressBook()->error( i18n( "Unable to access file '%1'." ).arg( fileName ) );
return KABC::AddresseeList();
}
access -> setReadAhead( 32 ); // Use ReadAhead-Cache if available
KABC::OpieConverter mConverter;
bool res = mConverter.init();
if (!res)
{
QString text( i18n( "Unable to initialize opie converter.<br>Most likely a problem with the category file." ) );
qDebug(text);
KMessageBox::error( parentWidget(), text );
delete access;
return KABC::AddresseeList();
diff --git a/kaddressbook/xxport/vcard_xxport.cpp b/kaddressbook/xxport/vcard_xxport.cpp
index adf47cd..4819341 100644
--- a/kaddressbook/xxport/vcard_xxport.cpp
+++ b/kaddressbook/xxport/vcard_xxport.cpp
@@ -5,193 +5,193 @@
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, permission is given to link this program
with any edition of Qt, and distribute the resulting executable,
without including the source code for Qt in the source distribution.
*/
/*
Enhanced Version of the file for platform independent KDE tools.
Copyright (c) 2004 Ulf Schenk
$Id$
*/
#include <qfile.h>
#include <qtextstream.h>
#include <kabc/vcardconverter.h>
#include <kabc/vcardparser/vcardtool.h>
#include <kfiledialog.h>
#ifndef KAB_EMBEDDED
#include <kio/netaccess.h>
#endif //KAB_EMBEDDED
#include <klocale.h>
#include <kmessagebox.h>
#include <ktempfile.h>
#include <kurl.h>
#include "xxportmanager.h"
#include "vcard_xxport.h"
#ifndef KAB_EMBEDDED
class VCardXXPortFactory : public XXPortFactory
{
public:
XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name )
{
return new VCardXXPort( ab, parent, name );
}
};
#endif //KAB_EMBEDDED
extern "C"
{
#ifndef KAB_EMBEDDED
void *init_libkaddrbk_vcard_xxport()
#else //KAB_EMBEDDED
void *init_kaddrbk_vcard_xxport()
#endif //KAB_EMBEDDED
{
return ( new VCardXXPortFactory() );
}
}
VCardXXPort::VCardXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name )
: XXPortObject( ab, parent, name )
{
createImportAction( i18n( "Import vCard..." ) );
//US KABC::VCardConverter does not support the export of 2.1 addressbooks.
//US createExportAction( i18n( "Export vCard 2.1..." ), "v21" );
createExportAction( i18n( "Export vCard 3.0..." ), "v30" );
}
bool VCardXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data )
{
QString name;
if ( list.count() == 1 )
name = list[ 0 ].givenName() + "_" + list[ 0 ].familyName() + ".vcf";
else
name = "addressbook.vcf";
#ifndef KAB_EMBEDDED
QString fileName = KFileDialog::getSaveFileName( name );
#else //KAB_EMBEDDED
QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() );
#endif //KAB_EMBEDDED
if ( fileName.isEmpty() )
- return true;
+ return false;
QFile outFile( fileName );
if ( !outFile.open( IO_WriteOnly ) ) {
QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" );
KMessageBox::error( parentWidget(), text.arg( fileName ) );
return false;
}
QTextStream t( &outFile );
t.setEncoding( QTextStream::UnicodeUTF8 );
KABC::Addressee::List::ConstIterator it;
for ( it = list.begin(); it != list.end(); ++it ) {
KABC::VCardConverter converter;
QString vcard;
KABC::VCardConverter::Version version;
if ( data == "v21" )
version = KABC::VCardConverter::v2_1;
else
version = KABC::VCardConverter::v3_0;
converter.addresseeToVCard( *it, vcard, version );
t << vcard << "\r\n\r\n";
}
outFile.close();
return true;
}
KABC::AddresseeList VCardXXPort::importContacts( const QString& ) const
{
QString fileName;
KABC::AddresseeList addrList;
KURL url;
#ifndef KAB_EMBEDDED
if ( !XXPortManager::importData.isEmpty() )
addrList = parseVCard( XXPortManager::importData );
else {
if ( XXPortManager::importURL.isEmpty() )
{
url = KFileDialog::getLoadFileName( QString::null, i18n("Select vCard to Import"), parentWidget() );
}
else
url = XXPortManager::importURL;
if ( url.isEmpty() )
return addrList;
QString caption( i18n( "vCard Import Failed" ) );
if ( KIO::NetAccess::download( url, fileName ) ) {
QFile file( fileName );
file.open( IO_ReadOnly );
QByteArray rawData = file.readAll();
file.close();
QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
addrList = parseVCard( data );
if ( !url.isLocalFile() )
KIO::NetAccess::removeTempFile( fileName );
} else {
QString text = i18n( "<qt>Unable to access <b>%1</b>.</qt>" );
KMessageBox::error( parentWidget(), text.arg( url.url() ), caption );
}
}
#else //KAB_EMBEDDED
if ( !XXPortManager::importData.isEmpty() )
addrList = parseVCard( XXPortManager::importData );
else {
if ( XXPortManager::importURL.isEmpty() )
{
fileName = KFileDialog::getOpenFileName( QString::null, i18n("Select vCard to Import"), parentWidget() );
if ( fileName.isEmpty() )
return addrList;
}
else
{
//US url = XXPortManager::importURL;
qDebug("VCardXXPort::importContacts Urls at the moment not supported");
if ( url.isEmpty() )
return addrList;
}