9#ifdef TDEPIM_NEW_DISTRLISTS
10#include "distributionlist.h"
12#include <tdeabc/distributionlist.h>
15#include <tdeapplication.h>
18#include <tdemessagebox.h>
19#include <tdeabc/resource.h>
20#include <tdeabc/stdaddressbook.h>
21#include <tdeabc/vcardconverter.h>
22#include <tdeabc/errorhandler.h>
23#include <tderesources/selectdialog.h>
25#include <dcopclient.h>
27#include <tqeventloop.h>
33void KAddrBookExternal::openEmail(
const TQString &addr, TQWidget *parent ) {
37 TDEABC::Addressee::parseEmailAddress( addr, name, email );
39 TDEABC::AddressBook *ab = TDEABC::StdAddressBook::self(
true );
48 while ( !ab->loadingHasFinished() ) {
49 TQApplication::eventLoop()->processEvents( TQEventLoop::ExcludeUserInput );
56 TDEABC::Addressee::List addressees = ab->findByEmail( email );
58 if ( addressees.count() > 0 ) {
59 if ( tdeApp->dcopClient()->isApplicationRegistered(
"kaddressbook" ) ){
62 DCOPRef call (
"kaddressbook",
"kaddressbook" );
63 call.send(
"newInstance()" );
65 tdeApp->startServiceByDesktopName(
"kaddressbook" );
68 DCOPRef call(
"kaddressbook",
"KAddressBookIface" );
69 call.send(
"showContactEditor(TQString)", addressees.first().uid() );
73 TQString text = i18n(
"<qt>The email address <b>%1</b> cannot be "
74 "found in your addressbook.</qt>").arg( email );
76 TQString text = email +
" " + i18n(
"is not in address book" );
78 KMessageBox::information( parent, text, TQString(),
"notInAddressBook" );
83void KAddrBookExternal::addEmail(
const TQString& addr, TQWidget *parent) {
87 TDEABC::Addressee::parseEmailAddress( addr, name, email );
89 TDEABC::AddressBook *ab = TDEABC::StdAddressBook::self(
true );
91 ab->setErrorHandler(
new TDEABC::GuiErrorHandler( parent ) );
100 while ( !ab->loadingHasFinished() ) {
101 TQApplication::eventLoop()->processEvents( TQEventLoop::ExcludeUserInput );
108 TDEABC::Addressee::List addressees = ab->findByEmail( email );
110 if ( addressees.isEmpty() ) {
112 a.setNameFromString( name );
113 a.insertEmail( email,
true );
116 TDEConfig config(
"kaddressbookrc" );
117 config.setGroup(
"General" );
118 int type = config.readNumEntry(
"FormattedNameType", 1 );
123 name = a.givenName() +
" " + a.familyName();
126 name = a.assembledName();
129 name = a.familyName() +
", " + a.givenName();
132 name = a.familyName() +
" " + a.givenName();
135 name = a.organization();
141 name.simplifyWhiteSpace();
143 a.setFormattedName( name );
146 if ( KAddrBookExternal::addAddressee( a ) ) {
147 TQString text = i18n(
"<qt>The email address <b>%1</b> was added to your "
148 "addressbook; you can add more information to this "
149 "entry by opening the addressbook.</qt>").arg( addr );
150 KMessageBox::information( parent, text, TQString(),
"addedtokabc" );
153 TQString text = i18n(
"<qt>The email address <b>%1</b> is already in your "
154 "addressbook.</qt>").arg( addr );
155 KMessageBox::information( parent, text, TQString(),
156 "alreadyInAddressBook" );
158 ab->setErrorHandler( 0 );
161void KAddrBookExternal::openAddressBook(TQWidget *) {
162 tdeApp->startServiceByDesktopName(
"kaddressbook" );
165void KAddrBookExternal::addNewAddressee( TQWidget* )
167 tdeApp->startServiceByDesktopName(
"kaddressbook");
168 DCOPRef call(
"kaddressbook",
"KAddressBookIface");
169 call.send(
"newContact()");
172bool KAddrBookExternal::addVCard(
const TDEABC::Addressee& addressee, TQWidget *parent )
174 TDEABC::AddressBook *ab = TDEABC::StdAddressBook::self(
true );
175 bool inserted =
false;
177 ab->setErrorHandler(
new TDEABC::GuiErrorHandler( parent ) );
179 TDEABC::Addressee::List addressees =
180 ab->findByEmail( addressee.preferredEmail() );
182 if ( addressees.isEmpty() ) {
183 if ( KAddrBookExternal::addAddressee( addressee ) ) {
184 TQString text = i18n(
"The VCard was added to your addressbook; "
185 "you can add more information to this "
186 "entry by opening the addressbook.");
187 KMessageBox::information( parent, text, TQString(),
"addedtokabc" );
191 TQString text = i18n(
"The VCard's primary email address is already in "
192 "your addressbook; however, you may save the VCard "
193 "into a file and import it into the addressbook "
195 KMessageBox::information( parent, text );
199 ab->setErrorHandler( 0 );
203bool KAddrBookExternal::addAddressee(
const TDEABC::Addressee& addr )
205 TDEABC::AddressBook *addressBook = TDEABC::StdAddressBook::self(
true );
206 TDEABC::Resource *tdeabcResource = selectResourceForSaving( addressBook );
207 if( !tdeabcResource )
209 TDEABC::Ticket *ticket = addressBook->requestSaveTicket( tdeabcResource );
212 TDEABC::Addressee addressee( addr );
213 addressee.setResource( tdeabcResource );
214 addressBook->insertAddressee( addressee );
215 saved = addressBook->save( ticket );
217 addressBook->releaseSaveTicket( ticket );
220 addressBook->emitAddressBookChanged();
225TQString KAddrBookExternal::expandDistributionList(
const TQString& listName )
227 if ( listName.isEmpty() )
230 const TQString lowerListName = listName.lower();
231 TDEABC::AddressBook *addressBook = TDEABC::StdAddressBook::self(
true );
232#ifdef TDEPIM_NEW_DISTRLISTS
233 KPIM::DistributionList distrList = KPIM::DistributionList::findByName( addressBook, lowerListName,
false );
234 if ( !distrList.isEmpty() ) {
235 return distrList.
emails( addressBook ).join(
", " );
238 TDEABC::DistributionListManager manager( addressBook );
240 const TQStringList listNames = manager.listNames();
242 for ( TQStringList::ConstIterator it = listNames.begin();
243 it != listNames.end(); ++it) {
244 if ( (*it).lower() == lowerListName ) {
245 const TQStringList addressList = manager.list( *it )->emails();
246 return addressList.join(
", " );
253TDEABC::Resource* KAddrBookExternal::selectResourceForSaving( TDEABC::AddressBook *addressBook )
256 while ( !addressBook->loadingHasFinished() ) {
257 TQApplication::eventLoop()->processEvents( TQEventLoop::ExcludeUserInput );
265 TQPtrList<TDEABC::Resource> tdeabcResources = addressBook->resources();
267 TQPtrList<KRES::Resource> kresResources;
268 TQPtrListIterator<TDEABC::Resource> resIt( tdeabcResources );
269 TDEABC::Resource *tdeabcResource;
270 while ( ( tdeabcResource = resIt.current() ) != 0 ) {
272 if ( !tdeabcResource->readOnly() ) {
273 KRES::Resource *res =
static_cast<KRES::Resource*
>( tdeabcResource );
275 kresResources.append( res );
279 return static_cast<TDEABC::Resource*
>( KRES::SelectDialog::getResource( kresResources, 0 ) );
Distribution list of email addresses.
TQStringList emails(TDEABC::AddressBook *book) const
Return list of email addresses, which belong to this distributon list.