kmail

kmaddrbook.cpp
1 /*
2  * kmail: KDE mail client
3  * Copyright (c) 1996-1998 Stefan Taferner <taferner@kde.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  */
20 #include <config.h>
21 #include <unistd.h>
22 
23 #include "kmaddrbook.h"
24 #include "kcursorsaver.h"
25 
26 #include <tdeapplication.h>
27 #include <kdebug.h>
28 #include <tdelocale.h>
29 #include <tdemessagebox.h>
30 #include <tdeabc/stdaddressbook.h>
31 #include <tdeabc/distributionlist.h>
32 #include <dcopref.h>
33 
34 #include <tqregexp.h>
35 
36 void KabcBridge::addresses(TQStringList& result) // includes lists
37 {
38  KCursorSaver busy(KBusyPtr::busy()); // loading might take a while
39 
40  TDEABC::AddressBook *addressBook = TDEABC::StdAddressBook::self( true );
41  TDEABC::AddressBook::ConstIterator it;
42  for( it = addressBook->begin(); it != addressBook->end(); ++it ) {
43  const TQStringList emails = (*it).emails();
44  TQString n = (*it).prefix() + " " +
45  (*it).givenName() + " " +
46  (*it).additionalName() + " " +
47  (*it).familyName() + " " +
48  (*it).suffix();
49  n = n.simplifyWhiteSpace();
50 
51  TQRegExp needQuotes("[^ 0-9A-Za-z\\x0080-\\xFFFF]");
52  TQString endQuote = "\" ";
53  TQStringList::ConstIterator mit;
54  TQString addr, email;
55 
56  for ( mit = emails.begin(); mit != emails.end(); ++mit ) {
57  email = *mit;
58  if (!email.isEmpty()) {
59  if (n.isEmpty() || (email.find( '<' ) != -1))
60  addr = TQString();
61  else { // do we really need quotes around this name ?
62  if (n.find(needQuotes) != -1)
63  addr = '"' + n + endQuote;
64  else
65  addr = n + ' ';
66  }
67 
68  if (!addr.isEmpty() && (email.find( '<' ) == -1)
69  && (email.find( '>' ) == -1)
70  && (email.find( ',' ) == -1))
71  addr += '<' + email + '>';
72  else
73  addr += email;
74  addr = addr.stripWhiteSpace();
75  result.append( addr );
76  }
77  }
78  }
79  TDEABC::DistributionListManager manager( addressBook );
80  manager.load();
81  result += manager.listNames();
82 
83  result.sort();
84 }
85 
86 TQStringList KabcBridge::addresses()
87 {
88  TQStringList entries;
89  TDEABC::AddressBook::ConstIterator it;
90 
91  const TDEABC::AddressBook *addressBook = TDEABC::StdAddressBook::self( true );
92  for( it = addressBook->begin(); it != addressBook->end(); ++it ) {
93  entries += (*it).fullEmail();
94  }
95  return entries;
96 }
97 
98 //-----------------------------------------------------------------------------
99 TQString KabcBridge::expandNickName( const TQString& nickName )
100 {
101  if ( nickName.isEmpty() )
102  return TQString();
103 
104  const TQString lowerNickName = nickName.lower();
105  const TDEABC::AddressBook *addressBook = TDEABC::StdAddressBook::self( true );
106  for( TDEABC::AddressBook::ConstIterator it = addressBook->begin();
107  it != addressBook->end(); ++it ) {
108  if ( (*it).nickName().lower() == lowerNickName )
109  return (*it).fullEmail();
110  }
111  return TQString();
112 }
113 
114 
115 //-----------------------------------------------------------------------------
116 
117 TQStringList KabcBridge::categories()
118 {
119  TDEABC::AddressBook *addressBook = TDEABC::StdAddressBook::self( true );
120  TDEABC::Addressee::List addresses = addressBook->allAddressees();
121  TQStringList allcategories, aux;
122 
123  for ( TDEABC::Addressee::List::Iterator it = addresses.begin();
124  it != addresses.end(); ++it ) {
125  aux = ( *it ).categories();
126  for ( TQStringList::ConstIterator itAux = aux.begin();
127  itAux != aux.end(); ++itAux ) {
128  // don't have duplicates in allcategories
129  if ( allcategories.find( *itAux ) == allcategories.end() )
130  allcategories += *itAux;
131  }
132  }
133  return allcategories;
134 }
sets a cursor and makes sure it's restored on destruction Create a KCursorSaver object when you want ...
Definition: kcursorsaver.h:14