summaryrefslogtreecommitdiffabout
path: root/kabc
Side-by-side diff
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/addressbook.cpp3
-rw-r--r--kabc/addressbook.h2
-rw-r--r--kabc/plugins/sharpdtm/resourcesharpdtm.cpp4
3 files changed, 5 insertions, 4 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index c584c35..3641c0c 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -432,129 +432,130 @@ bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName )
QString vcard;
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) ) {
datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" );
QTextStream t( &outFile ); // use a text stream
t.setEncoding( QTextStream::UnicodeUTF8 );
t <<datastream;
t << "\r\n\r\n";
outFile.close();
} else {
qDebug("Error open temp file ");
return false;
}
return true;
}
-void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld )
+int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld )
{
if ( removeOld )
setUntagged( true );
KABC::Addressee::List list;
QFile file( fileName );
file.open( IO_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;
for ( it = list.begin(); it != list.end(); ++it ) {
QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" );
if ( !id.isEmpty() )
(*it).setIDStr(id );
(*it).setResource( 0 );
if ( replaceLabel )
(*it).removeVoice();
if ( removeOld )
(*it).setTagged( true );
insertAddressee( (*it), false, true );
}
if ( removeOld )
removeUntagged();
+ return list.count();
}
void AddressBook::setUntagged(bool setNonSyncTagged) // = false)
{
Iterator ait;
for ( ait = begin(); ait != end(); ++ait ) {
if ( setNonSyncTagged ) {
if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) {
(*ait).setTagged( true );
} else
(*ait).setTagged( false );
} else
(*ait).setTagged( false );
}
}
void AddressBook::removeUntagged()
{
Iterator ait;
bool todelete = false;
Iterator todel;
for ( ait = begin(); ait != end(); ++ait ) {
if ( todelete )
removeAddressee( todel );
if (!(*ait).tagged()) {
todelete = true;
todel = ait;
} else
todelete = false;
}
if ( todelete )
removeAddressee( todel );
deleteRemovedAddressees();
}
void AddressBook::smplifyAddressees()
{
Iterator ait;
for ( ait = begin(); ait != end(); ++ait ) {
(*ait).simplifyEmails();
(*ait).simplifyPhoneNumbers();
(*ait).simplifyPhoneNumberTypes();
(*ait).simplifyAddresses();
}
}
void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync )
{
Iterator ait;
for ( ait = begin(); ait != end(); ++ait ) {
QString id = (*ait).IDStr();
(*ait).setIDStr( ":");
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index 23bba02..5edca06 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -102,97 +102,97 @@ class AddressBook : public QObject
ConstIterator &operator++(int);
ConstIterator &operator--();
ConstIterator &operator--(int);
bool operator==( const ConstIterator &it );
bool operator!=( const ConstIterator &it );
struct ConstIteratorData;
ConstIteratorData *d;
};
/**
Constructs a address book object.
@param format File format class.
*/
AddressBook();
AddressBook( const QString &config );
AddressBook( const QString &config, const QString &family );
virtual ~AddressBook();
/**
Requests a ticket for saving the addressbook. Calling this function locks
the addressbook for all other processes. If the address book is already
locked the function returns 0. You need the returned @ref Ticket object
for calling the @ref save() function.
@see save()
*/
Ticket *requestSaveTicket( Resource *resource=0 );
/**
Load address book from file.
*/
bool load();
/**
Save address book. The address book is saved to the file, the Ticket
object has been requested for by @ref requestSaveTicket().
@param ticket a ticket object returned by @ref requestSaveTicket()
*/
bool save( Ticket *ticket );
bool saveAB( );
bool saveABphone( QString fileName );
void smplifyAddressees();
void preparePhoneSync( QString currentSyncDevice, bool isPreSync );
void export2File( QString fileName );
bool export2PhoneFormat( QStringList uids ,QString fileName );
- void importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false );
+ int importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false );
void setUntagged( bool setNonSyncTagged = false );
void removeUntagged();
void findNewExtIds( QString fileName, QString currentSyncDevice );
/**
Returns a iterator for first entry of address book.
*/
Iterator begin();
/**
Returns a const iterator for first entry of address book.
*/
ConstIterator begin() const;
/**
Returns a iterator for first entry of address book.
*/
Iterator end();
/**
Returns a const iterator for first entry of address book.
*/
ConstIterator end() const;
/**
Removes all entries from address book.
*/
void clear();
/**
Insert an Addressee object into address book. If an object with the same
unique id already exists in the address book it it replaced by the new
one. If not the new object is appended to the address book.
*/
void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false);
/**
Removes entry from the address book.
*/
void removeAddressee( const Addressee & );
/**
This is like @ref removeAddressee() just above, with the difference that
the first element is a iterator, returned by @ref begin().
*/
void removeAddressee( const Iterator & );
/**
Find the specified entry in address book. Returns end(), if the entry
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
index 2cdf4bf..ba17c50 100644
--- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
+++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp
@@ -27,98 +27,98 @@ $Id$
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <qdir.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <qregexp.h>
//US #include <qtimer.h>
#include <kapplication.h>
#include <kconfig.h>
#include <kdebug.h>
#include <klocale.h>
//US #include <ksavefile.h>
#include <kstandarddirs.h>
#include <kmessagebox.h>
#include <sl/slzdb.h>
#include <libkdepim/ksyncprofile.h>
#include "resourcesharpdtmconfig.h"
#include "resourcesharpdtm.h"
#include "stdaddressbook.h"
#include "sharpdtmconverter.h"
//#define ALLOW_LOCKING
using namespace KABC;
extern "C"
{
void *init_microkabc_sharpdtm()
{
return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig>();
}
}
ResourceSharpDTM::ResourceSharpDTM( const KConfig *config )
: Resource( config ), mConverter (0)
{
// we can not choose the filename. Therefore use the default to display
QString fileName = SlZDataBase::addressbookFileName();
init( fileName );
}
-ResourceSharpDTM::ResourceSharpDTM( const QString &fileName, bool syncable )
- : Resource( 0, syncable )
+ResourceSharpDTM::ResourceSharpDTM( const QString &fileName )
+ : Resource( 0 )
{
init( fileName );
}
void ResourceSharpDTM::init( const QString &fileName )
{
connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
setFileName( fileName );
}
ResourceSharpDTM::~ResourceSharpDTM()
{
if (mConverter != 0)
delete mConverter;
if(mAccess != 0)
delete mAccess;
}
void ResourceSharpDTM::writeConfig( KConfig *config )
{
Resource::writeConfig( config );
}
Ticket *ResourceSharpDTM::requestSaveTicket()
{
qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1());
if ( !addressBook() ) return 0;
#ifdef ALLOW_LOCKING
if ( !lock( fileName() ) ) {
qDebug("ResourceSharpDTM::requestSaveTicket(): Unable to lock file ");
return 0;
}
#endif
return createTicket( this );
}
bool ResourceSharpDTM::doOpen()
{