ksync
addressbooksyncee.cpp
00001 /* 00002 This file is part of ksync. 00003 00004 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 00022 #include <kdebug.h> 00023 #include <kabc/resource.h> 00024 #include <kresources/manager.h> 00025 00026 #include "addressbooksyncee.h" 00027 00028 AddressBookSyncEntry::AddressBookSyncEntry( const KABC::Addressee &a ) : 00029 mAddressee( a ) 00030 { 00031 } 00032 00033 QString AddressBookSyncEntry::name() 00034 { 00035 return mAddressee.realName(); 00036 } 00037 00038 QString AddressBookSyncEntry::id() 00039 { 00040 return mAddressee.uid(); 00041 } 00042 00043 QString AddressBookSyncEntry::timestamp() 00044 { 00045 return QString::null; 00046 } 00047 00048 bool AddressBookSyncEntry::equals( KSyncEntry *entry ) 00049 { 00050 AddressBookSyncEntry *abEntry = dynamic_cast<AddressBookSyncEntry *>(entry); 00051 if ( !abEntry ) { 00052 kdDebug() << "AddressBookSyncee::equals(): Wrong type." << endl; 00053 return false; 00054 } 00055 00056 if ( mAddressee == abEntry->addressee() ) { 00057 kdDebug() << "AddressBookSyncEntry::equals(): '" << entry->name() << "':" 00058 << "equal" << endl; 00059 return true; 00060 } else { 00061 kdDebug() << "AddressBookSyncEntry::equals(): '" << entry->name() << "':" 00062 << "not equal" << endl; 00063 return false; 00064 } 00065 } 00066 00067 AddressBookSyncee::AddressBookSyncee() 00068 { 00069 mAddressBook = new KABC::AddressBook; 00070 00071 mEntries.setAutoDelete(true); 00072 } 00073 00074 AddressBookSyncee::~AddressBookSyncee() 00075 { 00076 delete mAddressBook; 00077 } 00078 00079 bool AddressBookSyncee::read() 00080 { 00081 KRES::Manager<KABC::Resource> manager( "contact" ); 00082 KABC::Resource *resource = manager.createResource( "file" ); 00083 mAddressBook->addResource( resource ); 00084 return mAddressBook->load(); 00085 } 00086 00087 bool AddressBookSyncee::write() 00088 { 00089 KABC::Ticket *ticket = mAddressBook->requestSaveTicket(); 00090 if ( !ticket ) return false; 00091 return mAddressBook->save( ticket ); 00092 } 00093 00094 00095 AddressBookSyncEntry *AddressBookSyncee::firstEntry() 00096 { 00097 mAddressBookIterator = mAddressBook->begin(); 00098 return createEntry( *mAddressBookIterator ); 00099 } 00100 00101 AddressBookSyncEntry *AddressBookSyncee::nextEntry() 00102 { 00103 ++mAddressBookIterator; 00104 return createEntry( *mAddressBookIterator ); 00105 } 00106 00107 #if 0 00108 AddressBookSyncEntry *AddressBookSyncee::findEntry(const QString &id) 00109 { 00110 Event *event = mAddressBook->getEvent(id); 00111 return createEntry(event); 00112 } 00113 #endif 00114 00115 void AddressBookSyncee::addEntry( KSyncEntry *entry ) 00116 { 00117 AddressBookSyncEntry *abEntry = dynamic_cast<AddressBookSyncEntry *>(entry); 00118 if (!abEntry) { 00119 kdDebug() << "AddressBookSyncee::addEntry(): SyncEntry has wrong type." 00120 << endl; 00121 } else { 00122 mAddressBook->insertAddressee( abEntry->addressee() ); 00123 } 00124 } 00125 00126 void AddressBookSyncee::removeEntry( KSyncEntry *entry ) 00127 { 00128 AddressBookSyncEntry *abEntry = dynamic_cast<AddressBookSyncEntry *>(entry); 00129 if ( !abEntry ) { 00130 kdDebug() << "AddressBookSyncee::removeEntry(): SyncEntry has wrong type." 00131 << endl; 00132 } else { 00133 mAddressBook->removeAddressee( abEntry->addressee() ); 00134 } 00135 } 00136 00137 AddressBookSyncEntry *AddressBookSyncee::createEntry( const KABC::Addressee &a ) 00138 { 00139 if ( !a.isEmpty() ) { 00140 AddressBookSyncEntry *entry = new AddressBookSyncEntry( a ); 00141 mEntries.append( entry ); 00142 return entry; 00143 } else { 00144 return 0; 00145 } 00146 }