From 45971e65a6114fbd1f91ae354da485450001166f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sl=C3=A1vek=20Banko?= Date: Tue, 3 Sep 2013 20:02:44 +0200 Subject: Additional k => tde renaming and fixes --- kopete/libkopete/CMakeLists.txt | 4 +- kopete/libkopete/Makefile.am | 8 +- kopete/libkopete/avdevice/Makefile.am | 2 +- kopete/libkopete/kabcpersistence.cpp | 452 ---------------------- kopete/libkopete/kabcpersistence.h | 108 ------ kopete/libkopete/kopeteaccount.cpp | 2 +- kopete/libkopete/kopetecontact.cpp | 4 +- kopete/libkopete/kopetecontactlist.cpp | 2 +- kopete/libkopete/kopeteglobal.h | 6 +- kopete/libkopete/kopetemetacontact.cpp | 32 +- kopete/libkopete/kopetemetacontact.h | 4 +- kopete/libkopete/kopeteprotocol.cpp | 12 +- kopete/libkopete/kopetetransfermanager.h | 2 +- kopete/libkopete/tdeabcpersistence.cpp | 452 ++++++++++++++++++++++ kopete/libkopete/tdeabcpersistence.h | 108 ++++++ kopete/libkopete/tests/kopetecontactlist_test.cpp | 4 +- kopete/libkopete/tests/kopeteemoticontest.cpp | 4 +- kopete/libkopete/tests/kopetemessage_test.cpp | 4 +- kopete/libkopete/tests/kopetepropertiestest.cpp | 4 +- kopete/libkopete/tests/template_test.cpp | 4 +- kopete/libkopete/ui/addressbookselectorwidget.cpp | 2 +- kopete/libkopete/ui/addresseeitem.h | 2 +- 22 files changed, 611 insertions(+), 611 deletions(-) delete mode 100644 kopete/libkopete/kabcpersistence.cpp delete mode 100644 kopete/libkopete/kabcpersistence.h create mode 100644 kopete/libkopete/tdeabcpersistence.cpp create mode 100644 kopete/libkopete/tdeabcpersistence.h (limited to 'kopete/libkopete') diff --git a/kopete/libkopete/CMakeLists.txt b/kopete/libkopete/CMakeLists.txt index 113289cb..7c1130ea 100644 --- a/kopete/libkopete/CMakeLists.txt +++ b/kopete/libkopete/CMakeLists.txt @@ -46,7 +46,7 @@ install( FILES kopetemimetypehandler.h kopeteonlinestatus.h kopeteonlinestatusmanager.h kopetepasswordedaccount.h kopetepassword.h kopeteplugin.h kopeteprotocol.h kopetesimplemessagehandler.h kopetetask.h - kopetetransfermanager.h kopeteuiglobal.h kabcpersistence.h + kopetetransfermanager.h kopeteuiglobal.h tdeabcpersistence.h managedconnectionaccount.h kopetenotifydataobject.h kopeteversion.h kopeteprefs.h kopetepicture.h webcamwidget.h kopetepluginmanager.h kopeteblacklister.h @@ -80,7 +80,7 @@ tde_add_library( kopete SHARED AUTOMOC kopetetask.cpp kopetemimesourcefactory.cpp kopeteeventpresentation.cpp kopetenotifyevent.cpp kopetenotifydataobject.cpp kopeteblacklister.cpp kopetemessageevent.cpp kopetemessagehandler.cpp kopetemessagehandlerchain.cpp - kopetesimplemessagehandler.cpp kopeteproperties.cpp kabcpersistence.cpp + kopetesimplemessagehandler.cpp kopeteproperties.cpp tdeabcpersistence.cpp connectionmanager.skel clientiface.stub managedconnectionaccount.cpp networkstatuscommon.h kopeteconfig.kcfgc kopeteutils.cpp kopeteprefs.cpp kopetepicture.cpp webcamwidget.cpp diff --git a/kopete/libkopete/Makefile.am b/kopete/libkopete/Makefile.am index 07d661f8..56fd99bb 100644 --- a/kopete/libkopete/Makefile.am +++ b/kopete/libkopete/Makefile.am @@ -30,19 +30,19 @@ libkopete_la_SOURCES = knotification.cpp connectionmanager.cpp kopeteonlinestatu kopetemimetypehandler.cpp kopetetask.cpp kopetemimesourcefactory.cpp \ kopeteeventpresentation.cpp kopetenotifyevent.cpp kopetenotifydataobject.cpp kopeteblacklister.cpp \ kopetemessageevent.cpp kopetemessagehandler.cpp kopetemessagehandlerchain.cpp \ - kopetesimplemessagehandler.cpp kopeteproperties.cpp kabcpersistence.cpp connectionmanager.skel \ + kopetesimplemessagehandler.cpp kopeteproperties.cpp tdeabcpersistence.cpp connectionmanager.skel \ clientiface.stub managedconnectionaccount.cpp networkstatuscommon.h kopeteconfig.kcfgc kopeteutils.cpp \ kopeteprefs.cpp kopetepicture.cpp webcamwidget.cpp libkopete_la_LDFLAGS = -no-undefined -version-info 1:0:0 $(all_libraries) -libkopete_la_LIBADD = -ltdeabc ui/libkopeteui.la $(COMPAT_LIBS) $(LIB_KIO) $(LIB_XSS) $(LIB_XRENDER) +libkopete_la_LIBADD = -ltdeabc ui/libkopeteui.la $(COMPAT_LIBS) $(LIB_TDEIO) $(LIB_XSS) $(LIB_XRENDER) kde_kcfg_DATA = kopete.kcfg #AM_CXXFLAGS = -DQT_PLUGIN #kde_widget_LTLIBRARIES = libkopetewidgets.la #libkopetewidgets_la_LDFLAGS = $(KDE_PLUGIN) -module $(all_libraries) -#libkopetewidgets_la_LIBADD = $(LIB_KIO) libkopete.la ui/libkopeteui.la +#libkopetewidgets_la_LIBADD = $(LIB_TDEIO) libkopete.la ui/libkopeteui.la #libkopetewidgets_la_SOURCES = ui/kopetewidgets.cpp kopetewidgets.cpp: $(srcdir)/kopete.widgets @@ -62,7 +62,7 @@ kopeteinclude_HEADERS = kopeteaccount.h kopeteaccountmanager.h kopeteawayaction. kopetechatsession.h kopetechatsessionmanager.h kopetemetacontact.h kopetemimetypehandler.h \ kopeteonlinestatus.h kopeteonlinestatusmanager.h kopetepasswordedaccount.h \ kopetepassword.h kopeteplugin.h kopeteprotocol.h kopetesimplemessagehandler.h kopetetask.h \ - kopetetransfermanager.h kopeteuiglobal.h kabcpersistence.h managedconnectionaccount.h \ + kopetetransfermanager.h kopeteuiglobal.h tdeabcpersistence.h managedconnectionaccount.h \ kopetenotifydataobject.h kopeteversion.h kopeteprefs.h kopetepicture.h webcamwidget.h \ kopetepluginmanager.h diff --git a/kopete/libkopete/avdevice/Makefile.am b/kopete/libkopete/avdevice/Makefile.am index 474d6a67..9036b3f2 100644 --- a/kopete/libkopete/avdevice/Makefile.am +++ b/kopete/libkopete/avdevice/Makefile.am @@ -5,7 +5,7 @@ AM_CPPFLAGS = -DKDE_NO_COMPAT -DQT_NO_COMPAT -DQT_NO_CAST_ASCII -DQT_NO_ASCII_CA METASOURCES = AUTO lib_LTLIBRARIES = libkopete_videodevice.la noinst_LTLIBRARIES = libkvideoio.la -libkopete_videodevice_la_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_KIO) -ltdetexteditor +libkopete_videodevice_la_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_TDEIO) -ltdetexteditor noinst_HEADERS = kxv.h qvideo.h qvideostream.h videocontrol.h videodevice.h \ videodevicemodelpool.h videodevicepool.h videoinput.h \ diff --git a/kopete/libkopete/kabcpersistence.cpp b/kopete/libkopete/kabcpersistence.cpp deleted file mode 100644 index 0d03fc07..00000000 --- a/kopete/libkopete/kabcpersistence.cpp +++ /dev/null @@ -1,452 +0,0 @@ -/* - addressbooklink.cpp - Manages operations involving the KDE Address Book - - Copyright (c) 2005 Will Stephenson - - Kopete (c) 2002-2004 by the Kopete developers - - ************************************************************************* - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - ************************************************************************* -*/ - -#include -#include - -#include -#include -#include -#include - -// UI related includes used for importing from KABC -#include -#include -#include -#include "accountselector.h" -#include "kopeteuiglobal.h" - -#include - -#include "kopeteaccount.h" -#include "kopeteaccountmanager.h" -#include "kopetecontact.h" -#include "kopetemetacontact.h" -#include "kopetepluginmanager.h" -#include "kopeteprotocol.h" - -#include "kabcpersistence.h" - -namespace Kopete -{ - -/** - * utility function to merge two TQStrings containing individual elements separated by 0xE000 - */ -static TQString unionContents( TQString arg1, TQString arg2 ) -{ - TQChar separator( 0xE000 ); - TQStringList outList = TQStringList::split( separator, arg1 ); - TQStringList arg2List = TQStringList::split( separator, arg2 ); - for ( TQStringList::iterator it = arg2List.begin(); it != arg2List.end(); ++it ) - if ( !outList.contains( *it ) ) - outList.append( *it ); - TQString out = outList.join( separator ); - return out; -} - -KABCPersistence::KABCPersistence( TQObject * parent, const char * name ) : TQObject( parent, name ) -{ - s_pendingResources.setAutoDelete( false ); -} - -KABCPersistence::~KABCPersistence() -{ -} - -KABCPersistence *KABCPersistence::s_self = 0L; - -bool KABCPersistence::s_addrBookWritePending = false; - -TQPtrList KABCPersistence::s_pendingResources; - -TDEABC::AddressBook* KABCPersistence::s_addressBook = 0; - -KABCPersistence *KABCPersistence::self() -{ - static KStaticDeleter deleter; - if(!s_self) - deleter.setObject( s_self, new KABCPersistence() ); - return s_self; -} - -TDEABC::AddressBook* KABCPersistence::addressBook() -{ - if ( s_addressBook == 0L ) - { - s_addressBook = TDEABC::StdAddressBook::self(); - TDEABC::StdAddressBook::setAutomaticSave( false ); - } - return s_addressBook; -} - -void KABCPersistence::write( MetaContact * mc ) -{ - // Save any changes in each contact's addressBookFields to KABC - TDEABC::AddressBook* ab = addressBook(); - - kdDebug( 14010 ) << k_funcinfo << "looking up Addressee for " << mc->displayName() << "..." << endl; - // Look up the address book entry - TDEABC::Addressee theAddressee = ab->findByUid( mc->metaContactId() ); - // Check that if addressee is not deleted or if the link is spurious - // (inherited from Kopete < 0.8, where all metacontacts had random ids) - if ( theAddressee.isEmpty() ) - { - // not found in currently enabled addressbooks - may be in a disabled resource... - return; - } - else - { - // collate the instant messaging data to be inserted into the address book - TQMap addressMap; - TQPtrList contacts = mc->contacts(); - TQPtrListIterator cIt( contacts ); - while ( Contact * c = cIt.current() ) - { - TQStringList addresses = addressMap[ c->protocol()->addressBookIndexField() ]; - addresses.append( c->contactId() ); - addressMap.insert( c->protocol()->addressBookIndexField(), addresses ); - ++cIt; - } - - // insert a custom field for each protocol - TQMap::ConstIterator it = addressMap.begin(); - for ( ; it != addressMap.end(); ++it ) - { - // read existing data for this key - TQString currentCustomForProtocol = theAddressee.custom( it.key(), TQString::fromLatin1( "All" ) ); - // merge without duplicating - TQString toWrite = unionContents( currentCustomForProtocol, it.data().join( TQChar( 0xE000 ) ) ); - // Note if nothing ends up in the KABC data, this is because insertCustom does nothing if any param is empty. - kdDebug( 14010 ) << k_funcinfo << "Writing: " << it.key() << ", " << "All" << ", " << toWrite << endl; - theAddressee.insertCustom( it.key(), TQString::fromLatin1( "All" ), toWrite ); - TQString check = theAddressee.custom( it.key(), TQString::fromLatin1( "All" ) ); - } - ab->insertAddressee( theAddressee ); - //kdDebug( 14010 ) << k_funcinfo << "dumping addressbook before write " << endl; - //dumpAB(); - writeAddressBook( theAddressee.resource() ); - //theAddressee.dump(); - } - -/* // Wipe out the existing addressBook entries - d->addressBook.clear(); - // This causes each Kopete::Protocol subclass to serialise its contacts' data into the metacontact's plugin data and address book data - emit aboutToSave(this); - - kdDebug( 14010 ) << k_funcinfo << "...FOUND ONE!" << endl; - // Store address book fields - TQMap >::ConstIterator appIt = d->addressBook.begin(); - for( ; appIt != d->addressBook.end(); ++appIt ) - { - TQMap::ConstIterator addrIt = appIt.data().begin(); - for( ; addrIt != appIt.data().end(); ++addrIt ) - { - // read existing data for this key - TQString currentCustom = theAddressee.custom( appIt.key(), addrIt.key() ); - // merge without duplicating - TQString toWrite = unionContents( currentCustom, addrIt.data() ); - // write the result - // Note if nothing ends up in the KABC data, this is because insertCustom does nothing if any param is empty. - kdDebug( 14010 ) << k_funcinfo << "Writing: " << appIt.key() << ", " << addrIt.key() << ", " << toWrite << endl; - theAddressee.insertCustom( appIt.key(), addrIt.key(), toWrite ); - } - } - ab->insertAddressee( theAddressee ); - writeAddressBook(); - }*/ -} - -void KABCPersistence::writeAddressBook( const TDEABC::Resource * res) -{ - if ( !s_pendingResources.containsRef( res ) ) - s_pendingResources.append( res ); - if ( !s_addrBookWritePending ) - { - s_addrBookWritePending = true; - TQTimer::singleShot( 2000, this, TQT_SLOT( slotWriteAddressBook() ) ); - } -} - -void KABCPersistence::slotWriteAddressBook() -{ - //kdDebug( 14010 ) << k_funcinfo << endl; - TDEABC::AddressBook* ab = addressBook(); - TQPtrListIterator it( s_pendingResources ); - for ( ; it.current(); ++it ) - { - //kdDebug( 14010 ) << "Writing resource " << it.current()->resourceName() << endl; - TDEABC::Ticket *ticket = ab->requestSaveTicket( it.current() ); - if ( !ticket ) - kdWarning( 14010 ) << "WARNING: Resource is locked by other application!" << endl; - else - { - if ( !ab->save( ticket ) ) - { - kdWarning( 14010 ) << "ERROR: Saving failed!" << endl; - ab->releaseSaveTicket( ticket ); - } - } - //kdDebug( 14010 ) << "Finished writing KABC" << endl; - } - s_pendingResources.clear(); - s_addrBookWritePending = false; -} - -void KABCPersistence::removeKABC( MetaContact *) -{ -/* // remove any data this KMC has written to the TDE address book - // Save any changes in each contact's addressBookFields to KABC - TDEABC::AddressBook* ab = addressBook(); - - // Wipe out the existing addressBook entries - d->addressBook.clear(); - // This causes each Kopete::Protocol subclass to serialise its contacts' data into the metacontact's plugin data and address book data - emit aboutToSave(this); - - // If the metacontact is linked to a kabc entry - if ( !d->metaContactId.isEmpty() ) - { - //kdDebug( 14010 ) << k_funcinfo << "looking up Addressee for " << displayName() << "..." << endl; - // Look up the address book entry - TDEABC::Addressee theAddressee = ab->findByUid( metaContactId() ); - - if ( theAddressee.isEmpty() ) - { - // remove the link - //kdDebug( 14010 ) << k_funcinfo << "...not found." << endl; - d->metaContactId=TQString(); - } - else - { - //kdDebug( 14010 ) << k_funcinfo << "...FOUND ONE!" << endl; - // Remove address book fields - TQMap >::ConstIterator appIt = d->addressBook.begin(); - for( ; appIt != d->addressBook.end(); ++appIt ) - { - TQMap::ConstIterator addrIt = appIt.data().begin(); - for( ; addrIt != appIt.data().end(); ++addrIt ) - { - // FIXME: This assumes Kopete is the only app writing these fields - kdDebug( 14010 ) << k_funcinfo << "Removing: " << appIt.key() << ", " << addrIt.key() << endl; - theAddressee.removeCustom( appIt.key(), addrIt.key() ); - } - } - ab->insertAddressee( theAddressee ); - - writeAddressBook(); - } - } -// kdDebug(14010) << k_funcinfo << kdBacktrace() <findByUid( mc->metaContactId() ); - - if ( !addr.isEmpty() ) // if we are associated with KABC - { -// load the set of addresses from KABC - TQStringList customs = addr.customs(); - - TQStringList::ConstIterator it; - for ( it = customs.begin(); it != customs.end(); ++it ) - { - TQString app, name, value; - splitField( *it, app, name, value ); - kdDebug( 14010 ) << "app=" << app << " name=" << name << " value=" << value << endl; - - if ( app.startsWith( TQString::fromLatin1( "messaging/" ) ) ) - { - if ( name == TQString::fromLatin1( "All" ) ) - { - kdDebug( 14010 ) << " syncing \"" << app << ":" << name << " with contactlist " << endl; - // Get the protocol name from the custom field - // by chopping the 'messaging/' prefix from the custom field app name - TQString protocolName = app.right( app.length() - 10 ); - // munge Jabber hack - if ( protocolName == TQString::fromLatin1( "xmpp" ) ) - protocolName = TQString::fromLatin1( "jabber" ); - - // Check Kopete supports it - Protocol * proto = dynamic_cast( PluginManager::self()->loadPlugin( TQString::fromLatin1( "kopete_" ) + protocolName ) ); - if ( !proto ) - { - KMessageBox::queuedMessageBox( Kopete::UI::Global::mainWidget(), KMessageBox::Sorry, - i18n( "\"%1\" is not supported by Kopete." ).arg( protocolName ), - i18n( "Could Not Sync with TDE Address Book" ) ); - continue; - } - - // See if we need to add each contact in this protocol - TQStringList addresses = TQStringList::split( TQChar( 0xE000 ), value ); - TQStringList::iterator end = addresses.end(); - for ( TQStringList::iterator it = addresses.begin(); it != end; ++it ) - { - // check whether each one is present in Kopete - // Is it in the contact list? - // First discard anything after an 0xE120, this is used by IRC to separate nick and server group name, but - // IRC doesn't support this properly yet, so the user will have to select an appropriate account manually - int separatorPos = (*it).find( TQChar( 0xE120 ) ); - if ( separatorPos != -1 ) - *it = (*it).left( separatorPos ); - - TQDict accounts = Kopete::AccountManager::self()->accounts( proto ); - TQDictIterator acs(accounts); - Kopete::MetaContact *otherMc = 0; - for ( acs.toFirst(); acs.current(); ++acs ) - { - Kopete::Contact *c= acs.current()->contacts()[*it]; - if(c) - { - otherMc=c->metaContact(); - break; - } - } - - if ( otherMc ) // Is it in another metacontact? - { - // Is it already in this metacontact? If so, we needn't do anything - if ( otherMc == mc ) - { - kdDebug( 14010 ) << *it << " already a child of this metacontact." << endl; - continue; - } - kdDebug( 14010 ) << *it << " already exists in OTHER metacontact, move here?" << endl; - // find the Kopete::Contact and attempt to move it to this metacontact. - otherMc->findContact( proto->pluginId(), TQString(), *it )->setMetaContact( mc ); - } - else - { - // if not, prompt to add it - kdDebug( 14010 ) << proto->pluginId() << "://" << *it << " was not found in the contact list. Prompting to add..." << endl; - if ( KMessageBox::Yes == KMessageBox::questionYesNo( Kopete::UI::Global::mainWidget(), - i18n( "An address was added to this contact by another application.
Would you like to use it in Kopete?
Protocol: %1
Address: %2
" ).arg( proto->displayName() ).arg( *it ), i18n( "Import Address From Address Book" ), i18n("Use"), i18n("Do Not Use"), TQString::fromLatin1( "ImportFromKABC" ) ) ) - { - // Check the accounts for this protocol are all connected - // Most protocols do not allow you to add contacts while offline - // Would be better to have a virtual bool Kopete::Account::readyToAddContact() - bool allAccountsConnected = true; - for ( acs.toFirst(); acs.current(); ++acs ) - if ( !acs.current()->isConnected() ) - { allAccountsConnected = false; - break; - } - if ( !allAccountsConnected ) - { - KMessageBox::queuedMessageBox( Kopete::UI::Global::mainWidget(), KMessageBox::Sorry, - i18n( "One or more of your accounts using %1 are offline. Most systems have to be connected to add contacts. Please connect these accounts and try again." ).arg( protocolName ), - i18n( "Not Connected" ) ); - continue; - } - - // we have got a contact to add, our accounts are connected, so add it. - // Do we need to choose an account - Kopete::Account *chosen = 0; - if ( accounts.count() > 1 ) - { // if we have >1 account in this protocol, prompt for the protocol. - KDialogBase *chooser = new KDialogBase(0, "chooser", true, - i18n("Choose Account"), KDialogBase::Ok|KDialogBase::Cancel, - KDialogBase::Ok, false); - AccountSelector *accSelector = new AccountSelector(proto, chooser, - "accSelector"); - chooser->setMainWidget(accSelector); - if ( chooser->exec() == TQDialog::Rejected ) - continue; - chosen = accSelector->selectedItem(); - - delete chooser; - } - else if ( accounts.isEmpty() ) - { - KMessageBox::queuedMessageBox( Kopete::UI::Global::mainWidget(), KMessageBox::Sorry, - i18n( "You do not have an account configured for %1 yet. Please create an account, connect it, and try again." ).arg( protocolName ), - i18n( "No Account Found" ) ); - continue; - } - else // if we have 1 account in this protocol, choose it - { - chosen = acs.toFirst(); - } - - // add the contact to the chosen account - if ( chosen ) - { - kdDebug( 14010 ) << "Adding " << *it << " to " << chosen->accountId() << endl; - if ( chosen->addContact( *it, mc ) ) - contactAdded = true; - else - KMessageBox::queuedMessageBox( Kopete::UI::Global::mainWidget(), KMessageBox::Sorry, - i18n( "It was not possible to add the contact." ), - i18n( "Could Not Add Contact") ) ; - } - } - else - kdDebug( 14010 ) << " user declined to add " << *it << " to contactlist " << endl; - } - } - kdDebug( 14010 ) << " all " << addresses.count() << " contacts in " << proto->pluginId() << " checked " << endl; - } - else - kdDebug( 14010 ) << "not interested in name=" << name << endl; - - } - else - kdDebug( 14010 ) << "not interested in app=" << app << endl; - } - } - return contactAdded; - return false; -} - -// FIXME: Remove when IM address API is in KABC (KDE 4) -void KABCPersistence::splitField( const TQString &str, TQString &app, TQString &name, TQString &value ) -{ - int colon = str.find( ':' ); - if ( colon != -1 ) { - TQString tmp = str.left( colon ); - value = str.mid( colon + 1 ); - - int dash = tmp.find( '-' ); - if ( dash != -1 ) { - app = tmp.left( dash ); - name = tmp.mid( dash + 1 ); - } - } -} - -void KABCPersistence::dumpAB() -{ - TDEABC::AddressBook * ab = addressBook(); - kdDebug( 14010 ) << k_funcinfo << " DUMPING ADDRESSBOOK" << endl; - TDEABC::AddressBook::ConstIterator dumpit = ab->begin(); - for ( ; dumpit != ab->end(); ++dumpit ) - { - (*dumpit).dump(); - } -} - - -} // end namespace Kopete - - // dump addressbook contents - -#include "kabcpersistence.moc" diff --git a/kopete/libkopete/kabcpersistence.h b/kopete/libkopete/kabcpersistence.h deleted file mode 100644 index 3c5f4b0b..00000000 --- a/kopete/libkopete/kabcpersistence.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - addressbooklink.h - Manages operations involving the KDE Address Book - - Copyright (c) 2005 Will Stephenson - - Kopete (c) 2002-2004 by the Kopete developers - - ************************************************************************* - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Lesser General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - ************************************************************************* -*/ - -#ifndef KOPETEADDRESSBOOKLINK_H -#define KOPETEADDRESSBOOKLINK_H - -#include "kopete_export.h" - -// Goal is to have all the address book modifying code in one place -// Currently in -// *) Add Contact Wizard -// *) KopeteMetaContact -// *) KopeteAddrBookExport -// *) KABC Export Wizard - TODO - think about sequence of events when adding addressees AND writing their IM data. - Extra save should be unnecessary because we are sharing a kabc instance -// *) Select addressbook entry - -namespace TDEABC -{ - class AddressBook; - class Resource; -} - -namespace Kopete -{ - - class MetaContact; - -class KOPETE_EXPORT KABCPersistence : public TQObject -{ - Q_OBJECT - - public: - /** - * \brief Retrieve the instance of AccountManager. - * - * The account manager is a singleton class of which only a single - * instance will exist. If no manager exists yet this function will - * create one for you. - * - * \return the instance of the AccountManager - */ - static KABCPersistence* self(); - - KABCPersistence( TQObject * parent = 0, const char * name = 0 ); - ~KABCPersistence(); - /** - * @brief Access Kopete's KDE address book instance - */ - static TDEABC::AddressBook* addressBook(); - /** - * @brief Change the KABC data associated with this metacontact - * - * The KABC exposed data changed, so change it in KABC. - * Replaces Kopete::MetaContact::updateKABC() - */ - void write( MetaContact * mc ); - - /** - * @brief Remove any KABC data for this meta contact - */ - void removeKABC( MetaContact * mc ); - - /** - * Check for any new addresses added to this contact's KABC entry - * and prompt if they should be added in Kopete too. - * @return whether any contacts were added from KABC. - */ - bool syncWithKABC( MetaContact * mc ); - - /** - * Request an address book write, will be delayed to bundle any others happening around the same time - */ - void writeAddressBook( const TDEABC::Resource * res ); - protected: - - static void splitField( const TQString &str, TQString &app, TQString &name, TQString &value ); - - void dumpAB(); - protected slots: - /** - * Perform a delayed address book write - */ - void slotWriteAddressBook(); - private: - static KABCPersistence * s_self; - static TDEABC::AddressBook* s_addressBook; - static bool s_addrBookWritePending; - static TQPtrList s_pendingResources; -}; - -} // end namespace Kopete - -#endif - diff --git a/kopete/libkopete/kopeteaccount.cpp b/kopete/libkopete/kopeteaccount.cpp index 623fd2fd..4ea6909c 100644 --- a/kopete/libkopete/kopeteaccount.cpp +++ b/kopete/libkopete/kopeteaccount.cpp @@ -31,7 +31,7 @@ #include #include -#include "kabcpersistence.h" +#include "tdeabcpersistence.h" #include "kopetecontactlist.h" #include "kopeteaccount.h" #include "kopeteaccountmanager.h" diff --git a/kopete/libkopete/kopetecontact.cpp b/kopete/libkopete/kopetecontact.cpp index 322a46f3..b1d9005e 100644 --- a/kopete/libkopete/kopetecontact.cpp +++ b/kopete/libkopete/kopetecontact.cpp @@ -26,7 +26,7 @@ #include #include -#include +#include #include #include #include @@ -343,7 +343,7 @@ void Contact::setMetaContact( MetaContact *m ) m->addContact( this ); m->insertChild( this ); // it is necessary to call this write here, because MetaContact::addContact() does not differentiate - // between adding completely new contacts (which should be written to kabc) and restoring upon restart + // between adding completely new contacts (which should be written to tdeabc) and restoring upon restart // (where no write is needed). KABCPersistence::self()->write( m ); connect( d->metaContact, TQT_SIGNAL( aboutToSave( Kopete::MetaContact * ) ), diff --git a/kopete/libkopete/kopetecontactlist.cpp b/kopete/libkopete/kopetecontactlist.cpp index 394527d6..2a8d69c6 100644 --- a/kopete/libkopete/kopetecontactlist.cpp +++ b/kopete/libkopete/kopetecontactlist.cpp @@ -1097,7 +1097,7 @@ void ContactList::slotSaveLater() void ContactList::slotKABCChanged() { // TODO: react to changes in KABC, replacing this function, post 3.4 (Will) - // call syncWithKABC on each metacontact to check if its associated kabc entry has changed. + // call syncWithKABC on each metacontact to check if its associated tdeabc entry has changed. /* for ( MetaContact * mc = d->contacts.first(); mc; mc = d->contacts.next() ) mc->syncWithKABC();*/ diff --git a/kopete/libkopete/kopeteglobal.h b/kopete/libkopete/kopeteglobal.h index 7ecc6f5b..926e2645 100644 --- a/kopete/libkopete/kopeteglobal.h +++ b/kopete/libkopete/kopeteglobal.h @@ -39,13 +39,13 @@ namespace Global * \brief Installs one or more kopete emoticon themes from a tarball * (either .kopete-emoticons or .tar.gz or .tar.bz2) * - * @p localPath Full path to a local emoticon archive, use KIO to download + * @p localPath Full path to a local emoticon archive, use TDEIO to download * files in case their are non-local. * * @return true in case install was successful, false otherwise. Errors are - * displayed by either KIO or by using KMessagebox directly. + * displayed by either TDEIO or by using KMessagebox directly. * - * TODO: If possible, port it to KIO instead of using ugly blocking KTar + * TODO: If possible, port it to TDEIO instead of using ugly blocking KTar **/ KOPETE_EXPORT void installEmoticonTheme(const TQString &localPath); diff --git a/kopete/libkopete/kopetemetacontact.cpp b/kopete/libkopete/kopetemetacontact.cpp index 65d61106..68b77535 100644 --- a/kopete/libkopete/kopetemetacontact.cpp +++ b/kopete/libkopete/kopetemetacontact.cpp @@ -30,7 +30,7 @@ #include #include -#include "kabcpersistence.h" +#include "tdeabcpersistence.h" #include "kopetecontactlist.h" #include "kopetecontact.h" #include "kopeteaccountmanager.h" @@ -74,7 +74,7 @@ class MetaContact::Private Contact *displayNameSourceContact; Contact *photoSourceContact; - // used when source is kabc + // used when source is tdeabc TQString metaContactId; // used when source is custom @@ -93,7 +93,7 @@ class MetaContact::Private TQString photoSourcePID, photoSourceAID, photoSourceCID; // The photo cache. Reduce disk access and CPU usage. - Picture customPicture, contactPicture, kabcPicture; + Picture customPicture, contactPicture, tdeabcPicture; }; MetaContact::MetaContact() @@ -610,8 +610,8 @@ TQString MetaContact::displayName() const PropertySource source = displayNameSource(); if ( source == SourceKABC ) { - // kabc source, try to get from addressbook - // if the metacontact has a kabc association + // tdeabc source, try to get from addressbook + // if the metacontact has a tdeabc association if ( !metaContactId().isEmpty() ) return nameFromKABC(metaContactId()); } @@ -652,7 +652,7 @@ TQString nameFromKABC( const TQString &id ) /*const*/ return theAddressee.formattedName(); } } - // no kabc association, return null image + // no tdeabc association, return null image return TQString(); } @@ -700,7 +700,7 @@ Picture &MetaContact::picture() const { if ( photoSource() == SourceKABC ) { - return d->kabcPicture; + return d->tdeabcPicture; } else if ( photoSource() == SourceContact ) { @@ -762,7 +762,7 @@ TQImage photoFromKABC( const TQString &id ) /*const*/ } } } - // no kabc association, return null image + // no tdeabc association, return null image return TQImage(); } @@ -1190,7 +1190,7 @@ bool MetaContact::fromXML( const TQDomElement& element ) else { // lets do the best conversion for the old name tracking - // if the custom display name is the same as kabc name, set the source to kabc + // if the custom display name is the same as tdeabc name, set the source to tdeabc if ( !d->metaContactId.isEmpty() && ( d->displayName == nameFromKABC(d->metaContactId)) ) setDisplayNameSource(SourceKABC); else @@ -1304,7 +1304,7 @@ void MetaContact::slotUpdateAddressBookPicture() if ( pic.data().isNull() && pic.url().isEmpty() ) pic = theAddressee.logo(); - d->kabcPicture.setPicture(pic); + d->tdeabcPicture.setPicture(pic); } } } @@ -1350,13 +1350,13 @@ void MetaContact::setMetaContactId( const TQString& newMetaContactId ) return; // 1) Check the Id is not already used by another contact - // 2) cause a kabc write ( only in response to metacontactLVIProps calling this, or will + // 2) cause a tdeabc write ( only in response to metacontactLVIProps calling this, or will // write be called twice when creating a brand new MC? ) - // 3) What about changing from one valid kabc to another, are kabc fields removed? - // 4) May be called with Null to remove an invalid kabc uid by KMC::toKABC() + // 3) What about changing from one valid tdeabc to another, are tdeabc fields removed? + // 4) May be called with Null to remove an invalid tdeabc uid by KMC::toKABC() // 5) Is called when reading the saved contact list - // Don't remove IM addresses from kabc if we are changing contacts; + // Don't remove IM addresses from tdeabc if we are changing contacts; // other programs may have written that data and depend on it d->metaContactId = newMetaContactId; KABCPersistence::self()->write( this ); @@ -1412,8 +1412,8 @@ void MetaContact::setPhotoSyncedWithKABC(bool b) { // Some protocols like MSN save the photo as a url in // contact properties, we should not use this url - // to sync with kabc but try first to embed the - // photo data in the kabc addressee, because it could + // to sync with tdeabc but try first to embed the + // photo data in the tdeabc addressee, because it could // be remote resource and the local url makes no sense TQImage fallBackImage = TQImage(newValue.toString()); if(fallBackImage.isNull()) diff --git a/kopete/libkopete/kopetemetacontact.h b/kopete/libkopete/kopetemetacontact.h index 2f918c73..15d82228 100644 --- a/kopete/libkopete/kopetemetacontact.h +++ b/kopete/libkopete/kopetemetacontact.h @@ -262,7 +262,7 @@ public: void setPhotoSourceContact( Contact* contact ); /** - * @return true if when a subcontact change his photo, the photo will be set to the kabc contact. + * @return true if when a subcontact change his photo, the photo will be set to the tdeabc contact. */ bool isPhotoSyncedWithKABC() const; @@ -373,7 +373,7 @@ public: * cannot be altered! * * @param p The Plugin by which uses this field - * @param app refers to the application id in the libkabc database. + * @param app refers to the application id in the libtdeabc database. * This should be a standardized format to make sense in the address * book in the first place - if you could use "" as application * then probably you should use the plugin data API instead of the diff --git a/kopete/libkopete/kopeteprotocol.cpp b/kopete/libkopete/kopeteprotocol.cpp index b0758128..6a2d3279 100644 --- a/kopete/libkopete/kopeteprotocol.cpp +++ b/kopete/libkopete/kopeteprotocol.cpp @@ -194,7 +194,7 @@ void Protocol::slotMetaContactAboutToSave( MetaContact *metaContact ) // The Unicode chars E000-F800 are non-printable and reserved for // private use in applications. For more details, see also // http://www.unicode.org/charts/PDF/UE000.pdf. - // Inside libkabc the use of TQChar( 0xE000 ) has been standardized + // Inside libtdeabc the use of TQChar( 0xE000 ) has been standardized // as separator for the string lists, use this also for the 'normal' // serialized data. if( serializedData.contains( it.key() ) ) @@ -222,9 +222,9 @@ void Protocol::slotMetaContactAboutToSave( MetaContact *metaContact ) // FIXME: This is a terrible hack to check the key name for the phrase "messaging/" // to indicate what app name to use, but for now it's by far the easiest // way to get this working. - // Once all this is in CVS and the actual storage in libkabc is working + // Once all this is in CVS and the actual storage in libtdeabc is working // we can devise a better API, but with the constantly changing - // requirements every time I learn more about kabc I'd better no touch + // requirements every time I learn more about tdeabc I'd better no touch // the API yet - Martijn if( it.key().startsWith( TQString::fromLatin1( "messaging/" ) ) ) { @@ -283,12 +283,12 @@ void Protocol::deserialize( MetaContact *metaContact, const TQMap ad; - TQStringList kabcFields = addressBookFields(); - for( TQStringList::Iterator fieldIt = kabcFields.begin(); fieldIt != kabcFields.end(); ++fieldIt ) + TQStringList tdeabcFields = addressBookFields(); + for( TQStringList::Iterator fieldIt = tdeabcFields.begin(); fieldIt != tdeabcFields.end(); ++fieldIt ) { // FIXME: This hack is even more ugly, and has the same reasons as the similar // hack in the serialize code. - // Once this code is actually capable of talking to kabc this hack + // Once this code is actually capable of talking to tdeabc this hack // should be removed ASAP! - Martijn if( ( *fieldIt ).startsWith( TQString::fromLatin1( "messaging/" ) ) ) ad[ *fieldIt ] = metaContact->addressBookField( this, *fieldIt, TQString::fromLatin1( "All" ) ); diff --git a/kopete/libkopete/kopetetransfermanager.h b/kopete/libkopete/kopetetransfermanager.h index 0333fc5a..3df90adc 100644 --- a/kopete/libkopete/kopetetransfermanager.h +++ b/kopete/libkopete/kopetetransfermanager.h @@ -129,7 +129,7 @@ private: }; /** - * A KIO job for a kopete file transfer. + * A TDEIO job for a kopete file transfer. * @author Richard Smith */ class KOPETE_EXPORT Transfer : public TDEIO::Job diff --git a/kopete/libkopete/tdeabcpersistence.cpp b/kopete/libkopete/tdeabcpersistence.cpp new file mode 100644 index 00000000..1fc46098 --- /dev/null +++ b/kopete/libkopete/tdeabcpersistence.cpp @@ -0,0 +1,452 @@ +/* + addressbooklink.cpp - Manages operations involving the KDE Address Book + + Copyright (c) 2005 Will Stephenson + + Kopete (c) 2002-2004 by the Kopete developers + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#include +#include + +#include +#include +#include +#include + +// UI related includes used for importing from KABC +#include +#include +#include +#include "accountselector.h" +#include "kopeteuiglobal.h" + +#include + +#include "kopeteaccount.h" +#include "kopeteaccountmanager.h" +#include "kopetecontact.h" +#include "kopetemetacontact.h" +#include "kopetepluginmanager.h" +#include "kopeteprotocol.h" + +#include "tdeabcpersistence.h" + +namespace Kopete +{ + +/** + * utility function to merge two TQStrings containing individual elements separated by 0xE000 + */ +static TQString unionContents( TQString arg1, TQString arg2 ) +{ + TQChar separator( 0xE000 ); + TQStringList outList = TQStringList::split( separator, arg1 ); + TQStringList arg2List = TQStringList::split( separator, arg2 ); + for ( TQStringList::iterator it = arg2List.begin(); it != arg2List.end(); ++it ) + if ( !outList.contains( *it ) ) + outList.append( *it ); + TQString out = outList.join( separator ); + return out; +} + +KABCPersistence::KABCPersistence( TQObject * parent, const char * name ) : TQObject( parent, name ) +{ + s_pendingResources.setAutoDelete( false ); +} + +KABCPersistence::~KABCPersistence() +{ +} + +KABCPersistence *KABCPersistence::s_self = 0L; + +bool KABCPersistence::s_addrBookWritePending = false; + +TQPtrList KABCPersistence::s_pendingResources; + +TDEABC::AddressBook* KABCPersistence::s_addressBook = 0; + +KABCPersistence *KABCPersistence::self() +{ + static KStaticDeleter deleter; + if(!s_self) + deleter.setObject( s_self, new KABCPersistence() ); + return s_self; +} + +TDEABC::AddressBook* KABCPersistence::addressBook() +{ + if ( s_addressBook == 0L ) + { + s_addressBook = TDEABC::StdAddressBook::self(); + TDEABC::StdAddressBook::setAutomaticSave( false ); + } + return s_addressBook; +} + +void KABCPersistence::write( MetaContact * mc ) +{ + // Save any changes in each contact's addressBookFields to KABC + TDEABC::AddressBook* ab = addressBook(); + + kdDebug( 14010 ) << k_funcinfo << "looking up Addressee for " << mc->displayName() << "..." << endl; + // Look up the address book entry + TDEABC::Addressee theAddressee = ab->findByUid( mc->metaContactId() ); + // Check that if addressee is not deleted or if the link is spurious + // (inherited from Kopete < 0.8, where all metacontacts had random ids) + if ( theAddressee.isEmpty() ) + { + // not found in currently enabled addressbooks - may be in a disabled resource... + return; + } + else + { + // collate the instant messaging data to be inserted into the address book + TQMap addressMap; + TQPtrList contacts = mc->contacts(); + TQPtrListIterator cIt( contacts ); + while ( Contact * c = cIt.current() ) + { + TQStringList addresses = addressMap[ c->protocol()->addressBookIndexField() ]; + addresses.append( c->contactId() ); + addressMap.insert( c->protocol()->addressBookIndexField(), addresses ); + ++cIt; + } + + // insert a custom field for each protocol + TQMap::ConstIterator it = addressMap.begin(); + for ( ; it != addressMap.end(); ++it ) + { + // read existing data for this key + TQString currentCustomForProtocol = theAddressee.custom( it.key(), TQString::fromLatin1( "All" ) ); + // merge without duplicating + TQString toWrite = unionContents( currentCustomForProtocol, it.data().join( TQChar( 0xE000 ) ) ); + // Note if nothing ends up in the KABC data, this is because insertCustom does nothing if any param is empty. + kdDebug( 14010 ) << k_funcinfo << "Writing: " << it.key() << ", " << "All" << ", " << toWrite << endl; + theAddressee.insertCustom( it.key(), TQString::fromLatin1( "All" ), toWrite ); + TQString check = theAddressee.custom( it.key(), TQString::fromLatin1( "All" ) ); + } + ab->insertAddressee( theAddressee ); + //kdDebug( 14010 ) << k_funcinfo << "dumping addressbook before write " << endl; + //dumpAB(); + writeAddressBook( theAddressee.resource() ); + //theAddressee.dump(); + } + +/* // Wipe out the existing addressBook entries + d->addressBook.clear(); + // This causes each Kopete::Protocol subclass to serialise its contacts' data into the metacontact's plugin data and address book data + emit aboutToSave(this); + + kdDebug( 14010 ) << k_funcinfo << "...FOUND ONE!" << endl; + // Store address book fields + TQMap >::ConstIterator appIt = d->addressBook.begin(); + for( ; appIt != d->addressBook.end(); ++appIt ) + { + TQMap::ConstIterator addrIt = appIt.data().begin(); + for( ; addrIt != appIt.data().end(); ++addrIt ) + { + // read existing data for this key + TQString currentCustom = theAddressee.custom( appIt.key(), addrIt.key() ); + // merge without duplicating + TQString toWrite = unionContents( currentCustom, addrIt.data() ); + // write the result + // Note if nothing ends up in the KABC data, this is because insertCustom does nothing if any param is empty. + kdDebug( 14010 ) << k_funcinfo << "Writing: " << appIt.key() << ", " << addrIt.key() << ", " << toWrite << endl; + theAddressee.insertCustom( appIt.key(), addrIt.key(), toWrite ); + } + } + ab->insertAddressee( theAddressee ); + writeAddressBook(); + }*/ +} + +void KABCPersistence::writeAddressBook( const TDEABC::Resource * res) +{ + if ( !s_pendingResources.containsRef( res ) ) + s_pendingResources.append( res ); + if ( !s_addrBookWritePending ) + { + s_addrBookWritePending = true; + TQTimer::singleShot( 2000, this, TQT_SLOT( slotWriteAddressBook() ) ); + } +} + +void KABCPersistence::slotWriteAddressBook() +{ + //kdDebug( 14010 ) << k_funcinfo << endl; + TDEABC::AddressBook* ab = addressBook(); + TQPtrListIterator it( s_pendingResources ); + for ( ; it.current(); ++it ) + { + //kdDebug( 14010 ) << "Writing resource " << it.current()->resourceName() << endl; + TDEABC::Ticket *ticket = ab->requestSaveTicket( it.current() ); + if ( !ticket ) + kdWarning( 14010 ) << "WARNING: Resource is locked by other application!" << endl; + else + { + if ( !ab->save( ticket ) ) + { + kdWarning( 14010 ) << "ERROR: Saving failed!" << endl; + ab->releaseSaveTicket( ticket ); + } + } + //kdDebug( 14010 ) << "Finished writing KABC" << endl; + } + s_pendingResources.clear(); + s_addrBookWritePending = false; +} + +void KABCPersistence::removeKABC( MetaContact *) +{ +/* // remove any data this KMC has written to the TDE address book + // Save any changes in each contact's addressBookFields to KABC + TDEABC::AddressBook* ab = addressBook(); + + // Wipe out the existing addressBook entries + d->addressBook.clear(); + // This causes each Kopete::Protocol subclass to serialise its contacts' data into the metacontact's plugin data and address book data + emit aboutToSave(this); + + // If the metacontact is linked to a tdeabc entry + if ( !d->metaContactId.isEmpty() ) + { + //kdDebug( 14010 ) << k_funcinfo << "looking up Addressee for " << displayName() << "..." << endl; + // Look up the address book entry + TDEABC::Addressee theAddressee = ab->findByUid( metaContactId() ); + + if ( theAddressee.isEmpty() ) + { + // remove the link + //kdDebug( 14010 ) << k_funcinfo << "...not found." << endl; + d->metaContactId=TQString(); + } + else + { + //kdDebug( 14010 ) << k_funcinfo << "...FOUND ONE!" << endl; + // Remove address book fields + TQMap >::ConstIterator appIt = d->addressBook.begin(); + for( ; appIt != d->addressBook.end(); ++appIt ) + { + TQMap::ConstIterator addrIt = appIt.data().begin(); + for( ; addrIt != appIt.data().end(); ++addrIt ) + { + // FIXME: This assumes Kopete is the only app writing these fields + kdDebug( 14010 ) << k_funcinfo << "Removing: " << appIt.key() << ", " << addrIt.key() << endl; + theAddressee.removeCustom( appIt.key(), addrIt.key() ); + } + } + ab->insertAddressee( theAddressee ); + + writeAddressBook(); + } + } +// kdDebug(14010) << k_funcinfo << kdBacktrace() <findByUid( mc->metaContactId() ); + + if ( !addr.isEmpty() ) // if we are associated with KABC + { +// load the set of addresses from KABC + TQStringList customs = addr.customs(); + + TQStringList::ConstIterator it; + for ( it = customs.begin(); it != customs.end(); ++it ) + { + TQString app, name, value; + splitField( *it, app, name, value ); + kdDebug( 14010 ) << "app=" << app << " name=" << name << " value=" << value << endl; + + if ( app.startsWith( TQString::fromLatin1( "messaging/" ) ) ) + { + if ( name == TQString::fromLatin1( "All" ) ) + { + kdDebug( 14010 ) << " syncing \"" << app << ":" << name << " with contactlist " << endl; + // Get the protocol name from the custom field + // by chopping the 'messaging/' prefix from the custom field app name + TQString protocolName = app.right( app.length() - 10 ); + // munge Jabber hack + if ( protocolName == TQString::fromLatin1( "xmpp" ) ) + protocolName = TQString::fromLatin1( "jabber" ); + + // Check Kopete supports it + Protocol * proto = dynamic_cast( PluginManager::self()->loadPlugin( TQString::fromLatin1( "kopete_" ) + protocolName ) ); + if ( !proto ) + { + KMessageBox::queuedMessageBox( Kopete::UI::Global::mainWidget(), KMessageBox::Sorry, + i18n( "\"%1\" is not supported by Kopete." ).arg( protocolName ), + i18n( "Could Not Sync with TDE Address Book" ) ); + continue; + } + + // See if we need to add each contact in this protocol + TQStringList addresses = TQStringList::split( TQChar( 0xE000 ), value ); + TQStringList::iterator end = addresses.end(); + for ( TQStringList::iterator it = addresses.begin(); it != end; ++it ) + { + // check whether each one is present in Kopete + // Is it in the contact list? + // First discard anything after an 0xE120, this is used by IRC to separate nick and server group name, but + // IRC doesn't support this properly yet, so the user will have to select an appropriate account manually + int separatorPos = (*it).find( TQChar( 0xE120 ) ); + if ( separatorPos != -1 ) + *it = (*it).left( separatorPos ); + + TQDict accounts = Kopete::AccountManager::self()->accounts( proto ); + TQDictIterator acs(accounts); + Kopete::MetaContact *otherMc = 0; + for ( acs.toFirst(); acs.current(); ++acs ) + { + Kopete::Contact *c= acs.current()->contacts()[*it]; + if(c) + { + otherMc=c->metaContact(); + break; + } + } + + if ( otherMc ) // Is it in another metacontact? + { + // Is it already in this metacontact? If so, we needn't do anything + if ( otherMc == mc ) + { + kdDebug( 14010 ) << *it << " already a child of this metacontact." << endl; + continue; + } + kdDebug( 14010 ) << *it << " already exists in OTHER metacontact, move here?" << endl; + // find the Kopete::Contact and attempt to move it to this metacontact. + otherMc->findContact( proto->pluginId(), TQString(), *it )->setMetaContact( mc ); + } + else + { + // if not, prompt to add it + kdDebug( 14010 ) << proto->pluginId() << "://" << *it << " was not found in the contact list. Prompting to add..." << endl; + if ( KMessageBox::Yes == KMessageBox::questionYesNo( Kopete::UI::Global::mainWidget(), + i18n( "An address was added to this contact by another application.
Would you like to use it in Kopete?
Protocol: %1
Address: %2
" ).arg( proto->displayName() ).arg( *it ), i18n( "Import Address From Address Book" ), i18n("Use"), i18n("Do Not Use"), TQString::fromLatin1( "ImportFromKABC" ) ) ) + { + // Check the accounts for this protocol are all connected + // Most protocols do not allow you to add contacts while offline + // Would be better to have a virtual bool Kopete::Account::readyToAddContact() + bool allAccountsConnected = true; + for ( acs.toFirst(); acs.current(); ++acs ) + if ( !acs.current()->isConnected() ) + { allAccountsConnected = false; + break; + } + if ( !allAccountsConnected ) + { + KMessageBox::queuedMessageBox( Kopete::UI::Global::mainWidget(), KMessageBox::Sorry, + i18n( "One or more of your accounts using %1 are offline. Most systems have to be connected to add contacts. Please connect these accounts and try again." ).arg( protocolName ), + i18n( "Not Connected" ) ); + continue; + } + + // we have got a contact to add, our accounts are connected, so add it. + // Do we need to choose an account + Kopete::Account *chosen = 0; + if ( accounts.count() > 1 ) + { // if we have >1 account in this protocol, prompt for the protocol. + KDialogBase *chooser = new KDialogBase(0, "chooser", true, + i18n("Choose Account"), KDialogBase::Ok|KDialogBase::Cancel, + KDialogBase::Ok, false); + AccountSelector *accSelector = new AccountSelector(proto, chooser, + "accSelector"); + chooser->setMainWidget(accSelector); + if ( chooser->exec() == TQDialog::Rejected ) + continue; + chosen = accSelector->selectedItem(); + + delete chooser; + } + else if ( accounts.isEmpty() ) + { + KMessageBox::queuedMessageBox( Kopete::UI::Global::mainWidget(), KMessageBox::Sorry, + i18n( "You do not have an account configured for %1 yet. Please create an account, connect it, and try again." ).arg( protocolName ), + i18n( "No Account Found" ) ); + continue; + } + else // if we have 1 account in this protocol, choose it + { + chosen = acs.toFirst(); + } + + // add the contact to the chosen account + if ( chosen ) + { + kdDebug( 14010 ) << "Adding " << *it << " to " << chosen->accountId() << endl; + if ( chosen->addContact( *it, mc ) ) + contactAdded = true; + else + KMessageBox::queuedMessageBox( Kopete::UI::Global::mainWidget(), KMessageBox::Sorry, + i18n( "It was not possible to add the contact." ), + i18n( "Could Not Add Contact") ) ; + } + } + else + kdDebug( 14010 ) << " user declined to add " << *it << " to contactlist " << endl; + } + } + kdDebug( 14010 ) << " all " << addresses.count() << " contacts in " << proto->pluginId() << " checked " << endl; + } + else + kdDebug( 14010 ) << "not interested in name=" << name << endl; + + } + else + kdDebug( 14010 ) << "not interested in app=" << app << endl; + } + } + return contactAdded; + return false; +} + +// FIXME: Remove when IM address API is in KABC (KDE 4) +void KABCPersistence::splitField( const TQString &str, TQString &app, TQString &name, TQString &value ) +{ + int colon = str.find( ':' ); + if ( colon != -1 ) { + TQString tmp = str.left( colon ); + value = str.mid( colon + 1 ); + + int dash = tmp.find( '-' ); + if ( dash != -1 ) { + app = tmp.left( dash ); + name = tmp.mid( dash + 1 ); + } + } +} + +void KABCPersistence::dumpAB() +{ + TDEABC::AddressBook * ab = addressBook(); + kdDebug( 14010 ) << k_funcinfo << " DUMPING ADDRESSBOOK" << endl; + TDEABC::AddressBook::ConstIterator dumpit = ab->begin(); + for ( ; dumpit != ab->end(); ++dumpit ) + { + (*dumpit).dump(); + } +} + + +} // end namespace Kopete + + // dump addressbook contents + +#include "tdeabcpersistence.moc" diff --git a/kopete/libkopete/tdeabcpersistence.h b/kopete/libkopete/tdeabcpersistence.h new file mode 100644 index 00000000..ea2b922a --- /dev/null +++ b/kopete/libkopete/tdeabcpersistence.h @@ -0,0 +1,108 @@ +/* + addressbooklink.h - Manages operations involving the KDE Address Book + + Copyright (c) 2005 Will Stephenson + + Kopete (c) 2002-2004 by the Kopete developers + + ************************************************************************* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + ************************************************************************* +*/ + +#ifndef KOPETEADDRESSBOOKLINK_H +#define KOPETEADDRESSBOOKLINK_H + +#include "kopete_export.h" + +// Goal is to have all the address book modifying code in one place +// Currently in +// *) Add Contact Wizard +// *) KopeteMetaContact +// *) KopeteAddrBookExport +// *) KABC Export Wizard - TODO - think about sequence of events when adding addressees AND writing their IM data. - Extra save should be unnecessary because we are sharing a tdeabc instance +// *) Select addressbook entry + +namespace TDEABC +{ + class AddressBook; + class Resource; +} + +namespace Kopete +{ + + class MetaContact; + +class KOPETE_EXPORT KABCPersistence : public TQObject +{ + Q_OBJECT + + public: + /** + * \brief Retrieve the instance of AccountManager. + * + * The account manager is a singleton class of which only a single + * instance will exist. If no manager exists yet this function will + * create one for you. + * + * \return the instance of the AccountManager + */ + static KABCPersistence* self(); + + KABCPersistence( TQObject * parent = 0, const char * name = 0 ); + ~KABCPersistence(); + /** + * @brief Access Kopete's KDE address book instance + */ + static TDEABC::AddressBook* addressBook(); + /** + * @brief Change the KABC data associated with this metacontact + * + * The KABC exposed data changed, so change it in KABC. + * Replaces Kopete::MetaContact::updateKABC() + */ + void write( MetaContact * mc ); + + /** + * @brief Remove any KABC data for this meta contact + */ + void removeKABC( MetaContact * mc ); + + /** + * Check for any new addresses added to this contact's KABC entry + * and prompt if they should be added in Kopete too. + * @return whether any contacts were added from KABC. + */ + bool syncWithKABC( MetaContact * mc ); + + /** + * Request an address book write, will be delayed to bundle any others happening around the same time + */ + void writeAddressBook( const TDEABC::Resource * res ); + protected: + + static void splitField( const TQString &str, TQString &app, TQString &name, TQString &value ); + + void dumpAB(); + protected slots: + /** + * Perform a delayed address book write + */ + void slotWriteAddressBook(); + private: + static KABCPersistence * s_self; + static TDEABC::AddressBook* s_addressBook; + static bool s_addrBookWritePending; + static TQPtrList s_pendingResources; +}; + +} // end namespace Kopete + +#endif + diff --git a/kopete/libkopete/tests/kopetecontactlist_test.cpp b/kopete/libkopete/tests/kopetecontactlist_test.cpp index 6fb0db26..71dade85 100644 --- a/kopete/libkopete/tests/kopetecontactlist_test.cpp +++ b/kopete/libkopete/tests/kopetecontactlist_test.cpp @@ -23,8 +23,8 @@ using namespace KUnitTest; -KUNITTEST_MODULE( tdeunittest_kopetecontactlist_test, "KopeteSuite"); -KUNITTEST_MODULE_REGISTER_TESTER( KopeteContactList_Test ); +TDEUNITTEST_MODULE( tdeunittest_kopetecontactlist_test, "KopeteSuite"); +TDEUNITTEST_MODULE_REGISTER_TESTER( KopeteContactList_Test ); void KopeteContactList_Test::allTests() { diff --git a/kopete/libkopete/tests/kopeteemoticontest.cpp b/kopete/libkopete/tests/kopeteemoticontest.cpp index f57becaa..7121ff19 100644 --- a/kopete/libkopete/tests/kopeteemoticontest.cpp +++ b/kopete/libkopete/tests/kopeteemoticontest.cpp @@ -34,8 +34,8 @@ using namespace KUnitTest; -KUNITTEST_MODULE( tdeunittest_kopeteemoticontest, "KopeteSuite"); -KUNITTEST_MODULE_REGISTER_TESTER( KopeteEmoticonTest ); +TDEUNITTEST_MODULE( tdeunittest_kopeteemoticontest, "KopeteSuite"); +TDEUNITTEST_MODULE_REGISTER_TESTER( KopeteEmoticonTest ); /* There are three sets of tests, the Kopete 0.7 baseline with tests that were diff --git a/kopete/libkopete/tests/kopetemessage_test.cpp b/kopete/libkopete/tests/kopetemessage_test.cpp index 43f66f88..59b24396 100644 --- a/kopete/libkopete/tests/kopetemessage_test.cpp +++ b/kopete/libkopete/tests/kopetemessage_test.cpp @@ -37,8 +37,8 @@ using namespace KUnitTest; -KUNITTEST_MODULE( tdeunittest_kopetemessage_test, "KopeteSuite"); -KUNITTEST_MODULE_REGISTER_TESTER( KopeteMessage_Test ); +TDEUNITTEST_MODULE( tdeunittest_kopetemessage_test, "KopeteSuite"); +TDEUNITTEST_MODULE_REGISTER_TESTER( KopeteMessage_Test ); /* There are four sets of tests: for each of plain text and html, we have those diff --git a/kopete/libkopete/tests/kopetepropertiestest.cpp b/kopete/libkopete/tests/kopetepropertiestest.cpp index 19dcff47..cec5f9ec 100644 --- a/kopete/libkopete/tests/kopetepropertiestest.cpp +++ b/kopete/libkopete/tests/kopetepropertiestest.cpp @@ -32,8 +32,8 @@ using namespace KUnitTest; -KUNITTEST_MODULE( tdeunittest_kopetepropertiestest, "KopeteSuite"); -KUNITTEST_MODULE_REGISTER_TESTER( KopetePropertiesTest ); +TDEUNITTEST_MODULE( tdeunittest_kopetepropertiestest, "KopeteSuite"); +TDEUNITTEST_MODULE_REGISTER_TESTER( KopetePropertiesTest ); using namespace Kopete::Properties; diff --git a/kopete/libkopete/tests/template_test.cpp b/kopete/libkopete/tests/template_test.cpp index 919d25e0..8f349ac8 100644 --- a/kopete/libkopete/tests/template_test.cpp +++ b/kopete/libkopete/tests/template_test.cpp @@ -20,8 +20,8 @@ using namespace KUnitTest; -KUNITTEST_MODULE( tdeunittest_template_test, "KopeteSuite"); -KUNITTEST_MODULE_REGISTER_TESTER( Template_Test ); +TDEUNITTEST_MODULE( tdeunittest_template_test, "KopeteSuite"); +TDEUNITTEST_MODULE_REGISTER_TESTER( Template_Test ); void Template_Test::allTests() { diff --git a/kopete/libkopete/ui/addressbookselectorwidget.cpp b/kopete/libkopete/ui/addressbookselectorwidget.cpp index 2ff65529..3df1ea9a 100644 --- a/kopete/libkopete/ui/addressbookselectorwidget.cpp +++ b/kopete/libkopete/ui/addressbookselectorwidget.cpp @@ -45,7 +45,7 @@ #include "addressbookselectorwidget.h" #include -#include "kabcpersistence.h" +#include "tdeabcpersistence.h" using namespace Kopete::UI; diff --git a/kopete/libkopete/ui/addresseeitem.h b/kopete/libkopete/ui/addresseeitem.h index 786db604..b69cdeee 100644 --- a/kopete/libkopete/ui/addresseeitem.h +++ b/kopete/libkopete/ui/addresseeitem.h @@ -1,5 +1,5 @@ /* - This file is part of libkabc. + This file is part of libtdeabc. Copyright (c) 2001 Cornelius Schumacher This library is free software; you can redistribute it and/or -- cgit v1.2.1