summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--kabc/addressbook.cpp26
-rw-r--r--kabc/addressbook.h4
-rw-r--r--kabc/addressee.cpp12
-rw-r--r--kabc/addressee.h3
-rw-r--r--kaddressbook/kabcore.cpp2
5 files changed, 42 insertions, 5 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp
index 1050f55..ff05f7e 100644
--- a/kabc/addressbook.cpp
+++ b/kabc/addressbook.cpp
@@ -398,22 +398,23 @@ void AddressBook::export2File( QString fileName )
QString vcard;
//Resource *resource() const;
converter.addresseeToVCard( *it, vcard, version );
t << vcard << "\r\n";
}
t << "\r\n\r\n";
outFile.close();
}
-void AddressBook::importFromFile( QString fileName, bool replaceLabel )
+void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld )
{
+ if ( removeOld )
+ setUntagged();
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") , "" );
@@ -421,21 +422,40 @@ void AddressBook::importFromFile( QString fileName, bool replaceLabel )
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 ) {
(*it).setResource( 0 );
if ( replaceLabel )
(*it).removeVoice();
+ if ( removeOld )
+ (*it).setTagged( true );
insertAddressee( (*it), false, true );
}
-
+ if ( removeOld )
+ removeUntagged();
+}
+void AddressBook::setUntagged()
+{
+ Iterator ait;
+ for ( ait = begin(); ait != end(); ++ait ) {
+ (*ait).setTagged( false );
+ }
+}
+void AddressBook::removeUntagged()
+{
+ Iterator ait;
+ for ( ait = begin(); ait != end(); ++ait ) {
+ if (!(*ait).tagged())
+ removeAddressee( ait );
}
+ deleteRemovedAddressees();
+}
bool AddressBook::saveAB()
{
bool ok = true;
deleteRemovedAddressees();
Iterator ait;
for ( ait = begin(); ait != end(); ++ait ) {
if ( !(*ait).IDStr().isEmpty() ) {
diff --git a/kabc/addressbook.h b/kabc/addressbook.h
index cea1b03..532e05d 100644
--- a/kabc/addressbook.h
+++ b/kabc/addressbook.h
@@ -138,17 +138,19 @@ class AddressBook : public QObject
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( );
void export2File( QString fileName );
- void importFromFile( QString fileName, bool replaceLabel = false );
+ void importFromFile( QString fileName, bool replaceLabel = false, bool removeOld = false );
+ void setUntagged();
+ void removeUntagged();
/**
Returns a iterator for first entry of address book.
*/
Iterator begin();
/**
Returns a const iterator for first entry of address book.
*/
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp
index 3f3d5c0..607ae26 100644
--- a/kabc/addressee.cpp
+++ b/kabc/addressee.cpp
@@ -83,16 +83,17 @@ struct Addressee::AddresseeData : public KShared
QStringList emails;
QStringList categories;
QStringList custom;
int mTempSyncStat;
Resource *resource;
bool empty :1;
bool changed :1;
+ bool tagged :1;
};
Addressee::Addressee()
{
mData = new AddresseeData;
mData->empty = true;
mData->changed = false;
mData->resource = 0;
@@ -1816,16 +1817,27 @@ void Addressee::setChanged( bool value )
mData->changed = value;
}
bool Addressee::changed() const
{
return mData->changed;
}
+void Addressee::setTagged( bool value )
+{
+ detach();
+ mData->tagged = value;
+}
+
+bool Addressee::tagged() const
+{
+ return mData->tagged;
+}
+
QDataStream &KABC::operator<<( QDataStream &s, const Addressee &a )
{
if (!a.mData) return s;
s << a.uid();
s << a.mData->name;
s << a.mData->formattedName;
diff --git a/kabc/addressee.h b/kabc/addressee.h
index 9336edc..0aa2c51 100644
--- a/kabc/addressee.h
+++ b/kabc/addressee.h
@@ -828,16 +828,19 @@ class Addressee
*/
void setChanged( bool value );
/**
Return whether the addressee is changed.
*/
bool changed() const;
+ void setTagged( bool value );
+ bool tagged() const;
+
private:
Addressee copy();
void detach();
struct AddresseeData;
mutable KSharedPtr<AddresseeData> mData;
};
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 7ec3fca..452f1bc 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -2871,17 +2871,17 @@ bool KABCore::syncExternal(KSyncManager* manager, QString resource)
void KABCore::getFile( bool success )
{
QTimer::singleShot( 15000, this , SLOT ( setCaptionBack()));
if ( ! success ) {
setCaption( i18n("Error receiving file. Nothing changed!") );
return;
}
- mAddressBook->importFromFile( sentSyncFile() );
+ mAddressBook->importFromFile( sentSyncFile() , false, true );
topLevelWidget()->setCaption( i18n("Pi-Sync successful!") );
mViewManager->refreshView();
}
void KABCore::syncFileRequest()
{
mAddressBook->export2File( sentSyncFile() );
}
QString KABCore::sentSyncFile()