30 #include "recentaddresses.h"
31 #include "libemailfunctions/email.h"
33 #include <kstaticdeleter.h>
34 #include <tdeconfig.h>
35 #include <tdeglobal.h>
38 #include <tdelocale.h>
39 #include <keditlistbox.h>
44 using namespace TDERecentAddress;
46 static KStaticDeleter<RecentAddresses> sd;
57 RecentAddresses::RecentAddresses(TDEConfig * config)
60 load( TDEGlobal::config() );
65 RecentAddresses::~RecentAddresses()
77 m_addresseeList.clear();
78 TDEConfigGroupSaver cs( config,
"General" );
79 m_maxCount = config->readNumEntry(
"Maximum Recent Addresses", 40 );
80 addresses = config->readListEntry(
"Recent Addresses" );
82 TDEABC::Addressee::parseEmailAddress( *it, name, email );
83 if ( !email.isEmpty() ) {
84 TDEABC::Addressee addr;
85 addr.setNameFromString( name );
86 addr.insertEmail( email,
true );
87 m_addresseeList.append( addr );
96 TDEConfigGroupSaver cs( config,
"General" );
97 config->writeEntry(
"Recent Addresses",
addresses() );
102 if ( !entry.isEmpty() && m_maxCount > 0 ) {
103 TQStringList list = KPIM::splitEmailAddrList( entry );
104 for( TQStringList::const_iterator e_it = list.begin(); e_it != list.end(); ++e_it ) {
105 KPIM::EmailParseResult errorCode = KPIM::isValidEmailAddress( *e_it );
106 if ( errorCode != KPIM::AddressOk )
110 TDEABC::Addressee addr;
112 TDEABC::Addressee::parseEmailAddress( *e_it, fullName, email );
114 for ( TDEABC::Addressee::List::Iterator it = m_addresseeList.begin();
115 it != m_addresseeList.end(); ++it )
117 if ( email == (*it).preferredEmail() ) {
119 m_addresseeList.remove( it );
123 addr.setNameFromString( fullName );
124 addr.insertEmail( email,
true );
125 m_addresseeList.prepend( addr );
137 void RecentAddresses::adjustSize()
139 while ( m_addresseeList.count() > m_maxCount )
140 m_addresseeList.remove( m_addresseeList.fromLast() );
145 m_addresseeList.clear();
152 for ( TDEABC::Addressee::List::ConstIterator it = m_addresseeList.begin();
153 it != m_addresseeList.end(); ++it )
160 RecentAddressDialog::RecentAddressDialog( TQWidget *parent,
const char *name )
161 : KDialogBase( Plain, i18n(
"Edit Recent Addresses" ), Ok | Cancel, Ok,
164 TQWidget *page = plainPage();
165 TQVBoxLayout *layout =
new TQVBoxLayout( page, 0, spacingHint() );
167 mEditor =
new KEditListBox( i18n(
"Recent Addresses" ), page,
"",
false,
168 KEditListBox::Add | KEditListBox::Remove );
169 layout->addWidget( mEditor );
172 void RecentAddressDialog::setAddresses(
const TQStringList &addrs )
175 mEditor->insertStringList( addrs );
178 TQStringList RecentAddressDialog::addresses()
const
180 return mEditor->items();
Handles a list of "recent email-addresses".
TQStringList addresses() const
void save(TDEConfig *)
Saves the list of recently used addresses to the configfile.
void add(const TQString &entry)
Adds an entry to the list.
static RecentAddresses * self(TDEConfig *config=0L)
void setMaxCount(int count)
Sets the maximum number, the list can hold.
void load(TDEConfig *)
Loads the list of recently used addresses from the configfile.
void clear()
Removes all entries from the history.