5 #include "kmlineeditspell.h"
7 #include "recentaddresses.h"
9 #include "globalsettings.h"
10 #include "stringutil.h"
12 #include <libtdepim/kvcarddrag.h>
13 #include <libemailfunctions/email.h>
15 #include <tdeabc/vcardconverter.h>
16 #include <tdeio/netaccess.h>
18 #include <tdepopupmenu.h>
21 #include <tdemessagebox.h>
22 #include <tdecompletionbox.h>
23 #include <tdelocale.h>
27 #include <tqcstring.h>
31 KMLineEdit::KMLineEdit(
bool useCompletion,
32 TQWidget *parent,
const char *name)
33 : KPIM::AddresseeLineEdit(parent,useCompletion,name)
35 allowSemiColonAsSeparator( GlobalSettings::allowSemicolonAsAddressSeparator() );
40 void KMLineEdit::keyPressEvent(TQKeyEvent *e)
42 if ((e->key() == Key_Enter || e->key() == Key_Return) &&
43 !completionBox()->isVisible())
46 AddresseeLineEdit::keyPressEvent(e);
49 if (e->key() == Key_Up)
54 if (e->key() == Key_Down)
59 AddresseeLineEdit::keyPressEvent(e);
63 void KMLineEdit::insertEmails(
const TQStringList & emails )
68 TQString contents = text();
69 if ( !contents.isEmpty() )
72 if ( emails.size() == 1 ) {
73 setText( contents + emails.front() );
77 TDEPopupMenu menu(
this,
"Addresschooser" );
78 for ( TQStringList::const_iterator it = emails.begin(), end = emails.end() ; it != end; ++it )
79 menu.insertItem( *it );
80 const int result = menu.exec( TQCursor::pos() );
83 setText( contents + menu.text( result ) );
86 void KMLineEdit::dropEvent( TQDropEvent *event )
92 if ( KVCardDrag::canDecode( event ) ) {
93 TDEABC::Addressee::List list;
94 KVCardDrag::decode( event, list );
96 TDEABC::Addressee::List::Iterator ait;
97 for ( ait = list.begin(); ait != list.end(); ++ait ){
98 insertEmails( (*ait).emails() );
105 else if ( KURLDrag::decode( event, urls ) ) {
106 KURL::List::Iterator it = urls.begin();
107 TDEABC::Addressee::List list;
108 for ( it = urls.begin(); it != urls.end(); ++it ) {
112 if ( (*it).protocol() ==
"mailto" ) {
113 TDEABC::Addressee addressee;
119 TDEABC::VCardConverter converter;
121 if ( TDEIO::NetAccess::download( (*it), fileName, parentWidget() ) ) {
122 TQFile file( fileName );
123 file.open( IO_ReadOnly );
124 const TQByteArray data = file.readAll();
126 #if defined(KABC_VCARD_ENCODING_FIX)
127 list += converter.parseVCardsRaw( data.data() );
129 list += converter.parseVCards( data );
131 TDEIO::NetAccess::removeTempFile( fileName );
133 TQString caption( i18n(
"vCard Import Failed" ) );
134 TQString text = i18n(
"<qt>Unable to access <b>%1</b>.</qt>" ).arg( (*it).url() );
135 KMessageBox::error( parentWidget(), text, caption );
139 TDEABC::Addressee::List::Iterator ait;
140 for ( ait = list.begin(); ait != list.end(); ++ait )
141 insertEmails( (*ait).emails() );
147 KPIM::AddresseeLineEdit::dropEvent( event );
151 TQPopupMenu *KMLineEdit::createPopupMenu()
153 TQPopupMenu *menu = KPIM::AddresseeLineEdit::createPopupMenu();
157 menu->insertSeparator();
158 menu->insertItem( i18n(
"Edit Recent Addresses..." ),
159 this, TQ_SLOT( editRecentAddresses() ) );
164 void KMLineEdit::editRecentAddresses()
166 TDERecentAddress::RecentAddressDialog dlg(
this );
167 dlg.setAddresses( TDERecentAddress::RecentAddresses::self( KMKernel::config() )->addresses() );
170 TDERecentAddress::RecentAddresses::self( KMKernel::config() )->clear();
171 const TQStringList addrList = dlg.addresses();
172 for ( TQStringList::const_iterator it = addrList.begin(), end = addrList.end() ; it != end ; ++it )
173 TDERecentAddress::RecentAddresses::self( KMKernel::config() )->add( *it );
179 void KMLineEdit::loadContacts()
181 AddresseeLineEdit::loadContacts();
183 if ( GlobalSettings::self()->showRecentAddressesInComposer() ){
185 TQStringList recent =
186 TDERecentAddress::RecentAddresses::self( KMKernel::config() )->addresses();
187 TQStringList::Iterator it = recent.begin();
188 TQString name, email;
190 TDEConfig config(
"kpimcompletionorder" );
191 config.setGroup(
"CompletionWeights" );
192 int weight = config.readEntry(
"Recent Addresses",
"10" ).toInt();
193 int idx = addCompletionSource( i18n(
"Recent Addresses" ), weight );
194 for ( ; it != recent.end(); ++it ) {
195 TDEABC::Addressee addr;
196 KPIM::getNameAndMail(*it, name, email);
197 name = KPIM::quoteNameIfNecessary( name );
198 if ( ( name[0] ==
'"' ) && ( name[name.length() - 1] ==
'"' ) ) {
200 name.truncate( name.length() - 1 );
202 addr.setNameFromString( name );
203 addr.insertEmail( email,
true );
204 addContact( addr, weight, idx );
211 KMLineEditSpell::KMLineEditSpell(
bool useCompletion,
212 TQWidget *parent,
const char *name)
213 : KMLineEdit(useCompletion,parent,name)
218 void KMLineEditSpell::highLightWord(
unsigned int length,
unsigned int pos )
220 setSelection ( pos, length );
223 void KMLineEditSpell::spellCheckDone(
const TQString &s )
229 void KMLineEditSpell::spellCheckerMisspelling(
const TQString &_text,
const TQStringList&,
unsigned int pos)
231 highLightWord( _text.length(),pos );
234 void KMLineEditSpell::spellCheckerCorrected(
const TQString &old,
const TQString &corr,
unsigned int pos)
238 setSelection ( pos, old.length() );
240 setSelection ( pos, corr.length() );
241 emit subjectTextSpellChecked();
246 #include "kmlineeditspell.moc"
static KMKernel * self()
normal control stuff
TQString decodeMailtoUrl(const TQString &url)
Decodes a mailto URL.