summaryrefslogtreecommitdiffstats
path: root/kmail/kmlineeditspell.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-09-01 00:37:02 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-09-01 00:37:02 +0000
commitcc29364f06178f8f6b457384f2ec37a042bd9d43 (patch)
tree7c77a3184c698bbf9d98cef09fb1ba8124daceba /kmail/kmlineeditspell.cpp
parent4f6c584bacc8c3c694228f36ada3de77a76614a6 (diff)
downloadtdepim-cc29364f06178f8f6b457384f2ec37a042bd9d43.tar.gz
tdepim-cc29364f06178f8f6b457384f2ec37a042bd9d43.zip
* Massive set of changes to bring in all fixes and enhancements from the Enterprise PIM branch
* Ensured that the Trinity changes were applied on top of those enhancements, and any redundancy removed * Added journal read support to the CalDAV resource * Fixed CalDAV resource to use events URL for tasks and journals when separate URL checkbox unchecked git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1170461 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kmail/kmlineeditspell.cpp')
-rw-r--r--kmail/kmlineeditspell.cpp93
1 files changed, 62 insertions, 31 deletions
diff --git a/kmail/kmlineeditspell.cpp b/kmail/kmlineeditspell.cpp
index 835421873..dde827bec 100644
--- a/kmail/kmlineeditspell.cpp
+++ b/kmail/kmlineeditspell.cpp
@@ -8,6 +8,7 @@
#include "recentaddresses.h"
#include "kmkernel.h"
#include "globalsettings.h"
+#include "stringutil.h"
#include <libkdepim/kvcarddrag.h>
#include <libemailfunctions/email.h>
@@ -78,52 +79,74 @@ void KMLineEdit::insertEmails( const TQStringList & emails )
for ( TQStringList::const_iterator it = emails.begin(), end = emails.end() ; it != end; ++it )
menu.insertItem( *it );
const int result = menu.exec( TQCursor::pos() );
- if ( result < 0 )
+ if ( result == -1 )
return;
setText( contents + menu.text( result ) );
}
-void KMLineEdit::dropEvent(TQDropEvent *event)
+void KMLineEdit::dropEvent( TQDropEvent *event )
{
- TQString vcards;
- KVCardDrag::decode( event, vcards );
- if ( !vcards.isEmpty() ) {
- KABC::VCardConverter converter;
- KABC::Addressee::List list = converter.parseVCards( vcards );
+ KURL::List urls;
+
+ // Case one: The user dropped a text/directory (i.e. vcard), so decode its
+ // contents
+ if ( KVCardDrag::canDecode( event ) ) {
+ KABC::Addressee::List list;
+ KVCardDrag::decode( event, list );
+
KABC::Addressee::List::Iterator ait;
for ( ait = list.begin(); ait != list.end(); ++ait ){
insertEmails( (*ait).emails() );
}
- } else {
- KURL::List urls;
- if ( KURLDrag::decode( event, urls) ) {
- //kdDebug(5006) << "urlList" << endl;
- KURL::List::Iterator it = urls.begin();
- KABC::VCardConverter converter;
- KABC::Addressee::List list;
- TQString fileName;
- TQString caption( i18n( "vCard Import Failed" ) );
- for ( it = urls.begin(); it != urls.end(); ++it ) {
- if ( KIO::NetAccess::download( *it, fileName, parentWidget() ) ) {
+ }
+
+ // Case two: The user dropped a list or Urls.
+ // Iterate over that list. For mailto: Urls, just add the addressee to the list,
+ // and for other Urls, download the Url and assume it points to a vCard
+ else if ( KURLDrag::decode( event, urls ) ) {
+ KURL::List::Iterator it = urls.begin();
+ KABC::Addressee::List list;
+ for ( it = urls.begin(); it != urls.end(); ++it ) {
+
+ // First, let's deal with mailto Urls. The path() part contains the
+ // email-address.
+ if ( (*it).protocol() == "mailto" ) {
+ KABC::Addressee addressee;
+ addressee.insertEmail( KMail::StringUtil::decodeMailtoUrl( (*it).path() ), true /* preferred */ );
+ list += addressee;
+ }
+ // Otherwise, download the vCard to which the Url points
+ else {
+ KABC::VCardConverter converter;
+ TQString fileName;
+ if ( KIO::NetAccess::download( (*it), fileName, parentWidget() ) ) {
TQFile file( fileName );
file.open( IO_ReadOnly );
- TQByteArray rawData = file.readAll();
+ const TQByteArray data = file.readAll();
file.close();
- TQString data = TQString::fromUtf8( rawData.data(), rawData.size() + 1 );
+#if defined(KABC_VCARD_ENCODING_FIX)
+ list += converter.parseVCardsRaw( data.data() );
+#else
list += converter.parseVCards( data );
+#endif
KIO::NetAccess::removeTempFile( fileName );
} else {
- TQString text = i18n( "<qt>Unable to access <b>%1</b>.</qt>" );
- KMessageBox::error( parentWidget(), text.arg( (*it).url() ), caption );
+ TQString caption( i18n( "vCard Import Failed" ) );
+ TQString text = i18n( "<qt>Unable to access <b>%1</b>.</qt>" ).arg( (*it).url() );
+ KMessageBox::error( parentWidget(), text, caption );
}
- KABC::Addressee::List::Iterator ait;
- for ( ait = list.begin(); ait != list.end(); ++ait )
- insertEmails((*ait).emails());
}
- } else {
- KPIM::AddresseeLineEdit::dropEvent( event );
+ // Now, let the user choose which addressee to add.
+ KABC::Addressee::List::Iterator ait;
+ for ( ait = list.begin(); ait != list.end(); ++ait )
+ insertEmails( (*ait).emails() );
}
}
+
+ // Case three: Let AddresseeLineEdit deal with the rest
+ else {
+ KPIM::AddresseeLineEdit::dropEvent( event );
+ }
}
TQPopupMenu *KMLineEdit::createPopupMenu()
@@ -156,7 +179,6 @@ void KMLineEdit::editRecentAddresses()
//-----------------------------------------------------------------------------
void KMLineEdit::loadContacts()
{
- // was: KABC::AddressLineEdit::loadAddresses()
AddresseeLineEdit::loadContacts();
if ( GlobalSettings::self()->showRecentAddressesInComposer() ){
@@ -165,13 +187,22 @@ void KMLineEdit::loadContacts()
KRecentAddress::RecentAddresses::self( KMKernel::config() )->addresses();
TQStringList::Iterator it = recent.begin();
TQString name, email;
- int idx = addCompletionSource( i18n( "Recent Addresses" ) );
+
+ KConfig config( "kpimcompletionorder" );
+ config.setGroup( "CompletionWeights" );
+ int weight = config.readEntry( "Recent Addresses", "10" ).toInt();
+ int idx = addCompletionSource( i18n( "Recent Addresses" ), weight );
for ( ; it != recent.end(); ++it ) {
KABC::Addressee addr;
KPIM::getNameAndMail(*it, name, email);
- addr.setNameFromString( KPIM::quoteNameIfNecessary( name ));
+ name = KPIM::quoteNameIfNecessary( name );
+ if ( ( name[0] == '"' ) && ( name[name.length() - 1] == '"' ) ) {
+ name.remove( 0, 1 );
+ name.truncate( name.length() - 1 );
+ }
+ addr.setNameFromString( name );
addr.insertEmail( email, true );
- addContact( addr, 120, idx ); // more weight than kabc entries and more than ldap results
+ addContact( addr, weight, idx );
}
}
}