6 #include "kmlineeditspell.h" 8 #include "recentaddresses.h" 10 #include "globalsettings.h" 11 #include "stringutil.h" 13 #include <libtdepim/kvcarddrag.h> 14 #include <libemailfunctions/email.h> 16 #include <tdeabc/vcardconverter.h> 17 #include <tdeio/netaccess.h> 19 #include <tdepopupmenu.h> 22 #include <tdemessagebox.h> 23 #include <tdecompletionbox.h> 24 #include <tdelocale.h> 28 #include <tqcstring.h> 32 KMLineEdit::KMLineEdit(
bool useCompletion,
33 TQWidget *parent,
const char *name)
34 :
KPIM::AddresseeLineEdit(parent,useCompletion,name)
36 allowSemiColonAsSeparator( GlobalSettings::allowSemicolonAsAddressSeparator() );
41 void KMLineEdit::keyPressEvent(TQKeyEvent *e)
43 if ((e->key() == Key_Enter || e->key() == Key_Return) &&
44 !completionBox()->isVisible())
47 AddresseeLineEdit::keyPressEvent(e);
50 if (e->key() == Key_Up)
55 if (e->key() == Key_Down)
60 AddresseeLineEdit::keyPressEvent(e);
64 void KMLineEdit::insertEmails(
const TQStringList & emails )
69 TQString contents = text();
70 if ( !contents.isEmpty() )
73 if ( emails.size() == 1 ) {
74 setText( contents + emails.front() );
78 TDEPopupMenu menu(
this,
"Addresschooser" );
79 for ( TQStringList::const_iterator it = emails.begin(), end = emails.end() ; it != end; ++it )
80 menu.insertItem( *it );
81 const int result = menu.exec( TQCursor::pos() );
84 setText( contents + menu.text( result ) );
87 void KMLineEdit::dropEvent( TQDropEvent *event )
93 if ( KVCardDrag::canDecode( event ) ) {
94 TDEABC::Addressee::List list;
95 KVCardDrag::decode( event, list );
97 TDEABC::Addressee::List::Iterator ait;
98 for ( ait = list.begin(); ait != list.end(); ++ait ){
99 insertEmails( (*ait).emails() );
106 else if ( KURLDrag::decode( event, urls ) ) {
107 KURL::List::Iterator it = urls.begin();
108 TDEABC::Addressee::List list;
109 for ( it = urls.begin(); it != urls.end(); ++it ) {
113 if ( (*it).protocol() ==
"mailto" ) {
114 TDEABC::Addressee addressee;
120 TDEABC::VCardConverter converter;
122 if ( TDEIO::NetAccess::download( (*it), fileName, parentWidget() ) ) {
123 TQFile file( fileName );
124 file.open( IO_ReadOnly );
125 const TQByteArray data = file.readAll();
127 #if defined(KABC_VCARD_ENCODING_FIX) 128 list += converter.parseVCardsRaw( data.data() );
130 list += converter.parseVCards( data );
132 TDEIO::NetAccess::removeTempFile( fileName );
134 TQString caption( i18n(
"vCard Import Failed" ) );
135 TQString text = i18n(
"<qt>Unable to access <b>%1</b>.</qt>" ).arg( (*it).url() );
136 KMessageBox::error( parentWidget(), text, caption );
140 TDEABC::Addressee::List::Iterator ait;
141 for ( ait = list.begin(); ait != list.end(); ++ait )
142 insertEmails( (*ait).emails() );
148 KPIM::AddresseeLineEdit::dropEvent( event );
152 TQPopupMenu *KMLineEdit::createPopupMenu()
154 TQPopupMenu *menu = KPIM::AddresseeLineEdit::createPopupMenu();
158 menu->insertSeparator();
159 menu->insertItem( i18n(
"Edit Recent Addresses..." ),
160 this, TQT_SLOT( editRecentAddresses() ) );
165 void KMLineEdit::editRecentAddresses()
167 TDERecentAddress::RecentAddressDialog dlg(
this );
168 dlg.setAddresses( TDERecentAddress::RecentAddresses::self( KMKernel::config() )->addresses() );
171 TDERecentAddress::RecentAddresses::self( KMKernel::config() )->clear();
172 const TQStringList addrList = dlg.addresses();
173 for ( TQStringList::const_iterator it = addrList.begin(), end = addrList.end() ; it != end ; ++it )
174 TDERecentAddress::RecentAddresses::self( KMKernel::config() )->add( *it );
180 void KMLineEdit::loadContacts()
182 AddresseeLineEdit::loadContacts();
184 if ( GlobalSettings::self()->showRecentAddressesInComposer() ){
186 TQStringList recent =
187 TDERecentAddress::RecentAddresses::self( KMKernel::config() )->addresses();
188 TQStringList::Iterator it = recent.begin();
189 TQString name, email;
191 TDEConfig config(
"kpimcompletionorder" );
192 config.setGroup(
"CompletionWeights" );
193 int weight = config.readEntry(
"Recent Addresses",
"10" ).toInt();
194 int idx = addCompletionSource( i18n(
"Recent Addresses" ), weight );
195 for ( ; it != recent.end(); ++it ) {
196 TDEABC::Addressee addr;
197 KPIM::getNameAndMail(*it, name, email);
198 name = KPIM::quoteNameIfNecessary( name );
199 if ( ( name[0] ==
'"' ) && ( name[name.length() - 1] ==
'"' ) ) {
201 name.truncate( name.length() - 1 );
203 addr.setNameFromString( name );
204 addr.insertEmail( email,
true );
205 addContact( addr, weight, idx );
212 KMLineEditSpell::KMLineEditSpell(
bool useCompletion,
213 TQWidget *parent,
const char *name)
214 : KMLineEdit(useCompletion,parent,name)
219 void KMLineEditSpell::highLightWord(
unsigned int length,
unsigned int pos )
221 setSelection ( pos, length );
224 void KMLineEditSpell::spellCheckDone(
const TQString &s )
230 void KMLineEditSpell::spellCheckerMisspelling(
const TQString &_text,
const TQStringList&,
unsigned int pos)
232 highLightWord( _text.length(),pos );
235 void KMLineEditSpell::spellCheckerCorrected(
const TQString &old,
const TQString &corr,
unsigned int pos)
239 setSelection ( pos, old.length() );
241 setSelection ( pos, corr.length() );
242 emit subjectTextSpellChecked();
247 #include "kmlineeditspell.moc" static KMKernel * self()
normal control stuff
TQString decodeMailtoUrl(const TQString &url)
Decodes a mailto URL.