summaryrefslogtreecommitdiffabout
path: root/kabc/addressbook.cpp
Side-by-side diff
Diffstat (limited to 'kabc/addressbook.cpp') (more/less context) (show whitespace changes)
-rw-r--r--kabc/addressbook.cpp30
1 files changed, 15 insertions, 15 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index fe59fcb..c700897 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -8,66 +8,66 @@
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/*
Enhanced Version of the file for platform independent KDE tools.
Copyright (c) 2004 Ulf Schenk
$Id$
*/
/*US
#include <qfile.h>
#include <qregexp.h>
#include <qtimer.h>
#include <kapplication.h>
#include <kinstance.h>
#include <kstandarddirs.h>
#include "errorhandler.h"
*/
-#include <qptrlist.h>
-#include <qtextstream.h>
+#include <q3ptrlist.h>
+#include <q3textstream.h>
#include <qfile.h>
#include <qregexp.h>
#include <kglobal.h>
#include <klocale.h>
#include <kmessagebox.h>
#include <kdebug.h>
#include <libkcal/syncdefines.h>
#include <libkdepim/phoneaccess.h>
#include "addressbook.h"
#include "resource.h"
#include "vcardconverter.h"
#include "vcardparser/vcardtool.h"
//US #include "addressbook.moc"
using namespace KABC;
struct AddressBook::AddressBookData
{
Addressee::List mAddressees;
Addressee::List mRemovedAddressees;
Field::List mAllFields;
KConfig *mConfig;
KRES::Manager<Resource> *mManager;
//US ErrorHandler *mErrorHandler;
};
struct AddressBook::Iterator::IteratorData
{
Addressee::List::Iterator mIt;
};
@@ -215,65 +215,65 @@ bool AddressBook::ConstIterator::operator==( const ConstIterator &it )
{
return ( d->mIt == it.d->mIt );
}
bool AddressBook::ConstIterator::operator!=( const ConstIterator &it )
{
return ( d->mIt != it.d->mIt );
}
AddressBook::AddressBook()
{
init(0, "contact");
}
AddressBook::AddressBook( const QString &config )
{
init(config, "contact");
}
AddressBook::AddressBook( const QString &config, const QString &family )
{
init(config, family);
}
// the default family is "contact"
void AddressBook::init(const QString &config, const QString &family )
{
blockLSEchange = false;
d = new AddressBookData;
QString fami = family;
- if (config != 0) {
+ if (!config.isEmpty()) {
if ( family == "syncContact" ) {
qDebug("creating sync config ");
fami = "contact";
KConfig* con = new KConfig( locateLocal("config", "syncContactrc") );
con->setGroup( "General" );
con->writeEntry( "ResourceKeys", QString("sync") );
con->writeEntry( "Standard", QString("sync") );
con->setGroup( "Resource_sync" );
con->writeEntry( "FileName", config );
con->writeEntry( "FileFormat", QString("vcard") );
con->writeEntry( "ResourceIdentifier", QString("sync") );
con->writeEntry( "ResourceName", QString("sync_res") );
if ( config.right(4) == ".xml" )
con->writeEntry( "ResourceType", QString("qtopia") );
else if ( config == "sharp" ) {
con->writeEntry( "ResourceType", QString("sharp") );
} else {
con->writeEntry( "ResourceType", QString("file") );
}
//con->sync();
d->mConfig = con;
}
else
d->mConfig = new KConfig( locateLocal("config", config) );
// qDebug("AddressBook::init 1 config=%s",config.latin1() );
}
else {
d->mConfig = 0;
// qDebug("AddressBook::init 1 config=0");
}
//US d->mErrorHandler = 0;
@@ -352,71 +352,71 @@ bool AddressBook::load()
qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) );
}
// mark all addressees as unchanged
Addressee::List::Iterator addrIt;
for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) {
(*addrIt).setChanged( false );
QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" );
if ( !id.isEmpty() ) {
//qDebug("setId aa %s ", id.latin1());
(*addrIt).setIDStr(id );
}
}
blockLSEchange = true;
return ok;
}
bool AddressBook::save( Ticket *ticket )
{
kdDebug(5700) << "AddressBook::save()"<< endl;
if ( ticket->resource() ) {
deleteRemovedAddressees();
return ticket->resource()->save( ticket );
}
return false;
}
// exports all Addressees, which are syncable
void AddressBook::export2File( QString fileName, QString resourceName )
{
QFile outFile( fileName );
- if ( !outFile.open( IO_WriteOnly ) ) {
+ if ( !outFile.open( QIODevice::WriteOnly ) ) {
QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" );
KMessageBox::error( 0, text.arg( fileName ) );
return ;
}
- QTextStream t( &outFile );
- t.setEncoding( QTextStream::UnicodeUTF8 );
+ Q3TextStream t( &outFile );
+ t.setEncoding( Q3TextStream::UnicodeUTF8 );
Iterator it;
KABC::VCardConverter::Version version;
version = KABC::VCardConverter::v3_0;
for ( it = begin(); it != end(); ++it ) {
if ( (*it).resource() ) {
bool include = (*it).resource()->includeInSync();
if ( !resourceName.isEmpty() )
include = (resourceName == (*it).resource()->resourceName() );
if ( include ) {
//qDebug(QString ("Exporting resource %1 to file %2").arg( (*it).resource()->resourceName() ).arg( fileName ) );
if ( !(*it).IDStr().isEmpty() ) {
(*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() );
}
KABC::VCardConverter converter;
QString vcard;
//Resource *resource() const;
converter.addresseeToVCard( *it, vcard, version );
t << vcard << "\r\n";
}
}
}
t << "\r\n\r\n";
outFile.close();
}
// if QStringList uids is empty, all are exported
bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName )
{
KABC::VCardConverter converter;
QString datastream;
Iterator it;
bool all = uids.isEmpty();
for ( it = begin(); it != end(); ++it ) {
@@ -439,87 +439,87 @@ bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName )
QString vcardnew;
converter.addresseeToVCard( a, vcard );
int start = 0;
int next;
while ( (next = vcard.find("TYPE=", start) )>= 0 ) {
int semi = vcard.find(";", next);
int dopp = vcard.find(":", next);
int sep;
if ( semi < dopp && semi >= 0 )
sep = semi ;
else
sep = dopp;
vcardnew +=vcard.mid( start, next - start);
vcardnew +=vcard.mid( next+5,sep -next -5 ).upper();
start = sep;
}
vcardnew += vcard.mid( start,vcard.length() );
vcard = "";
start = 0;
while ( (next = vcardnew.find("ADR", start) )>= 0 ) {
int sep = vcardnew.find(":", next);
vcard +=vcardnew.mid( start, next - start+3);
start = sep;
}
vcard += vcardnew.mid( start,vcardnew.length() );
vcard.replace ( QRegExp(";;;") , "" );
vcard.replace ( QRegExp(";;") , "" );
datastream += vcard;
}
QFile outFile(fileName);
- if ( outFile.open(IO_WriteOnly) ) {
+ if ( outFile.open(QIODevice::WriteOnly) ) {
datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
- QTextStream t( &outFile ); // use a text stream
- t.setEncoding( QTextStream::UnicodeUTF8 );
+ Q3TextStream t( &outFile ); // use a text stream
+ t.setEncoding( Q3TextStream::UnicodeUTF8 );
t <<datastream;
t << "\r\n\r\n";
outFile.close();
} else {
qDebug("Error open temp file ");
return false;
}
return true;
}
int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld, QString resource )
{
if ( removeOld )
setUntagged( true, resource );
KABC::Addressee::List list;
QFile file( fileName );
- file.open( IO_ReadOnly );
+ file.open( QIODevice::ReadOnly );
QByteArray rawData = file.readAll();
file.close();
QString data;
if ( replaceLabel ) {
data = QString::fromLatin1( rawData.data(), rawData.size() + 1 );
data.replace ( QRegExp("LABEL") , "ADR" );
data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" );
} else
data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
KABC::VCardTool tool;
list = tool.parseVCards( data );
KABC::Addressee::List::Iterator it;
Resource * setRes = 0;
if ( !resource.isEmpty() ) {
KRES::Manager<Resource>::ActiveIterator it;
KRES::Manager<Resource> *manager = d->mManager;
for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) {
//qDebug("SaveAB::checking resource..." );
if ( (*it)->resourceName() == resource ) {
setRes = (*it);
qDebug("KA: AB: Inserting imported contacs to resource %s", resource.latin1());
break;
}
}
}
for ( it = list.begin(); it != list.end(); ++it ) {
QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
if ( !id.isEmpty() )
(*it).setIDStr(id );
(*it).setResource( setRes );
if ( replaceLabel )
@@ -605,65 +605,65 @@ void AddressBook::removeSyncInfo( QString syncProfile)
}
} else {
Addressee lse;
lse = findByUid( "last-syncAddressee-"+ syncProfile );
if ( ! lse.isEmpty() )
removeAddressee( lse );
}
}
void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync )
{
Iterator ait;
for ( ait = begin(); ait != end(); ++ait ) {
QString id = (*ait).IDStr();
(*ait).setIDStr( ":");
(*ait).setExternalUID( id );
(*ait).setOriginalExternalUID( id );
if ( isPreSync )
(*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
else {
(*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
(*ait).setID( currentSyncDevice,id );
}
}
}
void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice )
{
setUntagged();
KABC::Addressee::List list;
QFile file( fileName );
- file.open( IO_ReadOnly );
+ file.open( QIODevice::ReadOnly );
QByteArray rawData = file.readAll();
file.close();
QString data;
data = QString::fromUtf8( rawData.data(), rawData.size() + 1 );
KABC::VCardTool tool;
list = tool.parseVCards( data );
KABC::Addressee::List::Iterator it;
for ( it = list.begin(); it != list.end(); ++it ) {
Iterator ait;
for ( ait = begin(); ait != end(); ++ait ) {
if ( !(*ait).tagged() ) {
if ( (*ait).containsAdr(*it)) {
(*ait).setTagged(true);
QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
(*it).setIDStr( ":");
(*it).setID( currentSyncDevice,id );
(*it).setExternalUID( id );
(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
(*it).setUid( ( (*ait).uid() ));
break;
}
}
}
if ( ait == end() )
qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1());
}
clear();
for ( it = list.begin(); it != list.end(); ++it ) {
insertAddressee( (*it) );
}
@@ -1189,89 +1189,89 @@ bool AddressBook::addCustomField( const QString &label, int category,
QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab )
{
if (!ab.d) return s;
return s << ab.d->mAddressees;
}
QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab )
{
if (!ab.d) return s;
s >> ab.d->mAddressees;
return s;
}
bool AddressBook::addResource( Resource *resource )
{
if ( !resource->open() ) {
kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl;
return false;
}
resource->setAddressBook( this );
d->mManager->add( resource );
return true;
}
void AddressBook::removeResources()
{
//remove all possible resources. This should cleanup the configfile.
- QPtrList<KABC::Resource> mResources = resources();
+ Q3PtrList<KABC::Resource> mResources = resources();
- QPtrListIterator<KABC::Resource> it(mResources);
+ Q3PtrListIterator<KABC::Resource> it(mResources);
for ( ; it.current(); ++it ) {
KABC::Resource *res = it.current();
removeResource(res);
}
}
bool AddressBook::removeResource( Resource *resource )
{
resource->close();
if ( resource == standardResource() )
d->mManager->setStandardResource( 0 );
resource->setAddressBook( 0 );
d->mManager->remove( resource );
return true;
}
-QPtrList<Resource> AddressBook::resources()
+Q3PtrList<Resource> AddressBook::resources()
{
- QPtrList<Resource> list;
+ Q3PtrList<Resource> list;
// qDebug("AddressBook::resources() 1");
KRES::Manager<Resource>::ActiveIterator it;
for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it )
list.append( *it );
return list;
}
/*US
void AddressBook::setErrorHandler( ErrorHandler *handler )
{
delete d->mErrorHandler;
d->mErrorHandler = handler;
}
*/
void AddressBook::error( const QString& msg )
{
/*US
if ( !d->mErrorHandler ) // create default error handler
d->mErrorHandler = new ConsoleErrorHandler;
if ( d->mErrorHandler )
d->mErrorHandler->error( msg );
else
kdError(5700) << "no error handler defined" << endl;
*/
kdDebug(5700) << "msg" << endl;
qDebug(msg);
}