10 #ifdef TDEPIM_NEW_DISTRLISTS 11 #include "distributionlist.h" 13 #include <tdeabc/distributionlist.h> 16 #include <tdeapplication.h> 18 #include <tdelocale.h> 19 #include <tdemessagebox.h> 20 #include <tdeversion.h> 21 #include <tdeabc/resource.h> 22 #include <tdeabc/stdaddressbook.h> 23 #include <tdeabc/vcardconverter.h> 24 #include <tdeabc/errorhandler.h> 25 #include <tderesources/selectdialog.h> 27 #include <dcopclient.h> 29 #include <tqeventloop.h> 35 void KAddrBookExternal::openEmail(
const TQString &addr, TQWidget *parent ) {
39 TDEABC::Addressee::parseEmailAddress( addr, name, email );
41 TDEABC::AddressBook *ab = TDEABC::StdAddressBook::self(
true );
49 #if KDE_IS_VERSION(3,4,89) 51 while ( !ab->loadingHasFinished() ) {
52 TQApplication::eventLoop()->processEvents( TQEventLoop::ExcludeUserInput );
59 TDEABC::Addressee::List addressees = ab->findByEmail( email );
61 if ( addressees.count() > 0 ) {
62 if ( kapp->dcopClient()->isApplicationRegistered(
"kaddressbook" ) ){
65 DCOPRef call (
"kaddressbook",
"kaddressbook" );
66 call.send(
"newInstance()" );
68 kapp->startServiceByDesktopName(
"kaddressbook" );
71 DCOPRef call(
"kaddressbook",
"KAddressBookIface" );
72 call.send(
"showContactEditor(TQString)", addressees.first().uid() );
76 TQString text = i18n(
"<qt>The email address <b>%1</b> cannot be " 77 "found in your addressbook.</qt>").arg( email );
79 TQString text = email +
" " + i18n(
"is not in address book" );
81 KMessageBox::information( parent, text, TQString(),
"notInAddressBook" );
86 void KAddrBookExternal::addEmail(
const TQString& addr, TQWidget *parent) {
90 TDEABC::Addressee::parseEmailAddress( addr, name, email );
92 TDEABC::AddressBook *ab = TDEABC::StdAddressBook::self(
true );
94 ab->setErrorHandler(
new TDEABC::GuiErrorHandler( parent ) );
102 #if KDE_IS_VERSION(3,4,89) 104 while ( !ab->loadingHasFinished() ) {
105 TQApplication::eventLoop()->processEvents( TQEventLoop::ExcludeUserInput );
112 TDEABC::Addressee::List addressees = ab->findByEmail( email );
114 if ( addressees.isEmpty() ) {
116 a.setNameFromString( name );
117 a.insertEmail( email,
true );
120 TDEConfig config(
"kaddressbookrc" );
121 config.setGroup(
"General" );
122 int type = config.readNumEntry(
"FormattedNameType", 1 );
127 name = a.givenName() +
" " + a.familyName();
130 name = a.assembledName();
133 name = a.familyName() +
", " + a.givenName();
136 name = a.familyName() +
" " + a.givenName();
139 name = a.organization();
145 name.simplifyWhiteSpace();
147 a.setFormattedName( name );
150 if ( KAddrBookExternal::addAddressee( a ) ) {
151 TQString text = i18n(
"<qt>The email address <b>%1</b> was added to your " 152 "addressbook; you can add more information to this " 153 "entry by opening the addressbook.</qt>").arg( addr );
154 KMessageBox::information( parent, text, TQString(),
"addedtokabc" );
157 TQString text = i18n(
"<qt>The email address <b>%1</b> is already in your " 158 "addressbook.</qt>").arg( addr );
159 KMessageBox::information( parent, text, TQString(),
160 "alreadyInAddressBook" );
162 ab->setErrorHandler( 0 );
165 void KAddrBookExternal::openAddressBook(TQWidget *) {
166 kapp->startServiceByDesktopName(
"kaddressbook" );
169 void KAddrBookExternal::addNewAddressee( TQWidget* )
171 kapp->startServiceByDesktopName(
"kaddressbook");
172 DCOPRef call(
"kaddressbook",
"KAddressBookIface");
173 call.send(
"newContact()");
176 bool KAddrBookExternal::addVCard(
const TDEABC::Addressee& addressee, TQWidget *parent )
178 TDEABC::AddressBook *ab = TDEABC::StdAddressBook::self(
true );
179 bool inserted =
false;
181 ab->setErrorHandler(
new TDEABC::GuiErrorHandler( parent ) );
183 TDEABC::Addressee::List addressees =
184 ab->findByEmail( addressee.preferredEmail() );
186 if ( addressees.isEmpty() ) {
187 if ( KAddrBookExternal::addAddressee( addressee ) ) {
188 TQString text = i18n(
"The VCard was added to your addressbook; " 189 "you can add more information to this " 190 "entry by opening the addressbook.");
191 KMessageBox::information( parent, text, TQString(),
"addedtokabc" );
195 TQString text = i18n(
"The VCard's primary email address is already in " 196 "your addressbook; however, you may save the VCard " 197 "into a file and import it into the addressbook " 199 KMessageBox::information( parent, text );
203 ab->setErrorHandler( 0 );
207 bool KAddrBookExternal::addAddressee(
const TDEABC::Addressee& addr )
209 TDEABC::AddressBook *addressBook = TDEABC::StdAddressBook::self(
true );
210 TDEABC::Resource *tdeabcResource = selectResourceForSaving( addressBook );
211 if( !tdeabcResource )
213 TDEABC::Ticket *ticket = addressBook->requestSaveTicket( tdeabcResource );
216 TDEABC::Addressee addressee( addr );
217 addressee.setResource( tdeabcResource );
218 addressBook->insertAddressee( addressee );
219 saved = addressBook->save( ticket );
221 addressBook->releaseSaveTicket( ticket );
224 addressBook->emitAddressBookChanged();
229 TQString KAddrBookExternal::expandDistributionList(
const TQString& listName )
231 if ( listName.isEmpty() )
234 const TQString lowerListName = listName.lower();
235 TDEABC::AddressBook *addressBook = TDEABC::StdAddressBook::self(
true );
236 #ifdef TDEPIM_NEW_DISTRLISTS 237 KPIM::DistributionList distrList = KPIM::DistributionList::findByName( addressBook, lowerListName,
false );
238 if ( !distrList.isEmpty() ) {
239 return distrList.
emails( addressBook ).join(
", " );
242 TDEABC::DistributionListManager manager( addressBook );
244 const TQStringList listNames = manager.listNames();
246 for ( TQStringList::ConstIterator it = listNames.begin();
247 it != listNames.end(); ++it) {
248 if ( (*it).lower() == lowerListName ) {
249 const TQStringList addressList = manager.list( *it )->emails();
250 return addressList.join(
", " );
257 TDEABC::Resource* KAddrBookExternal::selectResourceForSaving( TDEABC::AddressBook *addressBook )
259 #if KDE_IS_VERSION(3,4,89) 261 while ( !addressBook->loadingHasFinished() ) {
262 TQApplication::eventLoop()->processEvents( TQEventLoop::ExcludeUserInput );
270 TQPtrList<TDEABC::Resource> tdeabcResources = addressBook->resources();
272 TQPtrList<KRES::Resource> kresResources;
273 TQPtrListIterator<TDEABC::Resource> resIt( tdeabcResources );
274 TDEABC::Resource *tdeabcResource;
275 while ( ( tdeabcResource = resIt.current() ) != 0 ) {
277 if ( !tdeabcResource->readOnly() ) {
278 KRES::Resource *res =
static_cast<KRES::Resource*
>( tdeabcResource );
280 kresResources.append( res );
284 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.