You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
611 lines
17 KiB
611 lines
17 KiB
15 years ago
|
/*
|
||
|
This file is part of libkabc.
|
||
|
Copyright (c) 2002 Helge Deller <deller@gmx.de>
|
||
|
2002 Lubos Lunak <llunak@suse.cz>
|
||
|
2001,2003 Carsten Pfeiffer <pfeiffer@kde.org>
|
||
|
2001 Waldo Bastian <bastian@kde.org>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
// $Id$
|
||
|
|
||
|
#include "addresslineedit.h"
|
||
|
|
||
15 years ago
|
#include <tqapplication.h>
|
||
|
#include <tqobject.h>
|
||
|
#include <tqptrlist.h>
|
||
|
#include <tqregexp.h>
|
||
|
#include <tqevent.h>
|
||
|
#include <tqdragobject.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdecompletionbox.h>
|
||
12 years ago
|
#include <tdeconfig.h>
|
||
15 years ago
|
#include <kcursor.h>
|
||
|
#include <kstandarddirs.h>
|
||
|
#include <kstaticdeleter.h>
|
||
12 years ago
|
#include <tdestdaccel.h>
|
||
15 years ago
|
#include <kurldrag.h>
|
||
|
|
||
12 years ago
|
#include <tdeabc/stdaddressbook.h>
|
||
|
#include <tdeabc/distributionlist.h>
|
||
15 years ago
|
#include "ldapclient.h"
|
||
|
|
||
|
#include <kdebug.h>
|
||
|
|
||
|
//=============================================================================
|
||
|
//
|
||
|
// Class AddressLineEdit
|
||
|
//
|
||
|
//=============================================================================
|
||
|
|
||
|
|
||
|
using namespace KABC;
|
||
|
|
||
12 years ago
|
TDECompletion * AddressLineEdit::s_completion = 0L;
|
||
15 years ago
|
bool AddressLineEdit::s_addressesDirty = false;
|
||
15 years ago
|
TQTimer* AddressLineEdit::s_LDAPTimer = 0L;
|
||
15 years ago
|
LdapSearch* AddressLineEdit::s_LDAPSearch = 0L;
|
||
15 years ago
|
TQString* AddressLineEdit::s_LDAPText = 0L;
|
||
15 years ago
|
AddressLineEdit* AddressLineEdit::s_LDAPLineEdit = 0L;
|
||
12 years ago
|
TDEConfig *AddressLineEdit::s_config = 0L;
|
||
15 years ago
|
|
||
12 years ago
|
static KStaticDeleter<TDECompletion> completionDeleter;
|
||
15 years ago
|
static KStaticDeleter<TQTimer> ldapTimerDeleter;
|
||
15 years ago
|
static KStaticDeleter<LdapSearch> ldapSearchDeleter;
|
||
15 years ago
|
static KStaticDeleter<TQString> ldapTextDeleter;
|
||
12 years ago
|
static KStaticDeleter<TDEConfig> configDeleter;
|
||
15 years ago
|
|
||
15 years ago
|
AddressLineEdit::AddressLineEdit(TQWidget* parent,
|
||
15 years ago
|
bool useCompletion,
|
||
|
const char *name)
|
||
|
: KLineEdit(parent,name)
|
||
|
{
|
||
|
m_useCompletion = useCompletion;
|
||
|
m_completionInitialized = false;
|
||
|
m_smartPaste = false;
|
||
|
|
||
|
init();
|
||
|
|
||
|
// Whenever a new AddressLineEdit is created (== a new composer is created),
|
||
|
// we set a dirty flag to reload the addresses upon the first completion.
|
||
|
// The address completions are shared between all AddressLineEdits.
|
||
|
// Is there a signal that tells us about addressbook updates?
|
||
|
if (m_useCompletion)
|
||
|
s_addressesDirty = true;
|
||
|
}
|
||
|
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
void AddressLineEdit::init()
|
||
|
{
|
||
|
if ( !s_completion ) {
|
||
12 years ago
|
completionDeleter.setObject( s_completion, new TDECompletion() );
|
||
|
s_completion->setOrder( TDECompletion::Sorted );
|
||
15 years ago
|
s_completion->setIgnoreCase( true );
|
||
|
}
|
||
|
|
||
|
if( m_useCompletion ) {
|
||
|
if( !s_LDAPTimer ) {
|
||
15 years ago
|
ldapTimerDeleter.setObject( s_LDAPTimer, new TQTimer );
|
||
15 years ago
|
ldapSearchDeleter.setObject( s_LDAPSearch, new LdapSearch );
|
||
15 years ago
|
ldapTextDeleter.setObject( s_LDAPText, new TQString );
|
||
15 years ago
|
}
|
||
15 years ago
|
connect( s_LDAPTimer, TQT_SIGNAL( timeout()), TQT_SLOT( slotStartLDAPLookup()));
|
||
|
connect( s_LDAPSearch, TQT_SIGNAL( searchData( const TQStringList& )),
|
||
|
TQT_SLOT( slotLDAPSearchData( const TQStringList& )));
|
||
15 years ago
|
}
|
||
|
|
||
|
if ( m_useCompletion && !m_completionInitialized )
|
||
|
{
|
||
|
setCompletionObject( s_completion, false ); // we handle it ourself
|
||
15 years ago
|
connect( this, TQT_SIGNAL( completion(const TQString&)),
|
||
|
this, TQT_SLOT(slotCompletion() ));
|
||
15 years ago
|
|
||
12 years ago
|
TDECompletionBox *box = completionBox();
|
||
15 years ago
|
connect( box, TQT_SIGNAL( highlighted( const TQString& )),
|
||
|
this, TQT_SLOT( slotPopupCompletion( const TQString& ) ));
|
||
|
connect( box, TQT_SIGNAL( userCancelled( const TQString& )),
|
||
|
TQT_SLOT( userCancelled( const TQString& )));
|
||
15 years ago
|
|
||
|
m_completionInitialized = true; // don't connect muliple times. That's
|
||
|
// ugly, tho, better have completionBox()
|
||
|
// virtual in KDE 4
|
||
|
// Why? This is only called once. Why should this be called more
|
||
|
// than once? And why was this protected?
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
AddressLineEdit::~AddressLineEdit()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
|
||
12 years ago
|
TDEConfig* AddressLineEdit::config()
|
||
15 years ago
|
{
|
||
|
if ( !s_config )
|
||
12 years ago
|
configDeleter.setObject( s_config, new TDEConfig( "kabldaprc", false, false ) ); // Open read-write, no kdeglobals
|
||
15 years ago
|
|
||
|
return s_config;
|
||
|
}
|
||
|
|
||
15 years ago
|
void AddressLineEdit::setFont( const TQFont& font )
|
||
15 years ago
|
{
|
||
|
KLineEdit::setFont( font );
|
||
|
if ( m_useCompletion )
|
||
|
completionBox()->setFont( font );
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
15 years ago
|
void AddressLineEdit::keyPressEvent(TQKeyEvent *e)
|
||
15 years ago
|
{
|
||
|
bool accept = false;
|
||
|
|
||
12 years ago
|
if (TDEStdAccel::shortcut(TDEStdAccel::SubstringCompletion).contains(KKey(e)))
|
||
15 years ago
|
{
|
||
|
doCompletion(true);
|
||
|
accept = true;
|
||
|
}
|
||
12 years ago
|
else if (TDEStdAccel::shortcut(TDEStdAccel::TextCompletion).contains(KKey(e)))
|
||
15 years ago
|
{
|
||
|
int len = text().length();
|
||
|
|
||
|
if (len == cursorPosition()) // at End?
|
||
|
{
|
||
|
doCompletion(true);
|
||
|
accept = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if( !accept )
|
||
|
KLineEdit::keyPressEvent( e );
|
||
|
|
||
|
if( e->isAccepted())
|
||
|
{
|
||
|
if( m_useCompletion && s_LDAPTimer != NULL )
|
||
|
{
|
||
|
if( *s_LDAPText != text())
|
||
|
stopLDAPLookup();
|
||
|
*s_LDAPText = text();
|
||
|
s_LDAPLineEdit = this;
|
||
|
s_LDAPTimer->start( 500, true );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
void AddressLineEdit::mouseReleaseEvent( TQMouseEvent * e )
|
||
15 years ago
|
{
|
||
14 years ago
|
if (m_useCompletion && (e->button() == Qt::MidButton))
|
||
15 years ago
|
{
|
||
|
m_smartPaste = true;
|
||
|
KLineEdit::mouseReleaseEvent(e);
|
||
|
m_smartPaste = false;
|
||
|
return;
|
||
|
}
|
||
|
KLineEdit::mouseReleaseEvent(e);
|
||
|
}
|
||
|
|
||
15 years ago
|
void AddressLineEdit::insert(const TQString &t)
|
||
15 years ago
|
{
|
||
|
if (!m_smartPaste)
|
||
|
{
|
||
|
KLineEdit::insert(t);
|
||
|
return;
|
||
|
}
|
||
15 years ago
|
TQString newText = t.stripWhiteSpace();
|
||
15 years ago
|
if (newText.isEmpty())
|
||
|
return;
|
||
|
|
||
|
// remove newlines in the to-be-pasted string as well as an eventual
|
||
|
// mailto: protocol
|
||
14 years ago
|
newText.replace( TQRegExp("\r?\n"), ", " );
|
||
15 years ago
|
if ( newText.startsWith( "mailto:" ) )
|
||
|
{
|
||
|
KURL u(newText);
|
||
|
newText = u.path();
|
||
|
}
|
||
13 years ago
|
else if (newText.find(" at ") != -1)
|
||
15 years ago
|
{
|
||
|
// Anti-spam stuff
|
||
14 years ago
|
newText.replace( " at ", "@" );
|
||
|
newText.replace( " dot ", "." );
|
||
15 years ago
|
}
|
||
13 years ago
|
else if (newText.find("(at)") != -1)
|
||
15 years ago
|
{
|
||
14 years ago
|
newText.replace( TQRegExp("\\s*\\(at\\)\\s*"), "@" );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
TQString contents = text();
|
||
15 years ago
|
int start_sel = 0;
|
||
|
int end_sel = 0;
|
||
|
int pos = cursorPosition();
|
||
|
if (getSelection(&start_sel, &end_sel))
|
||
|
{
|
||
|
// Cut away the selection.
|
||
|
if (pos > end_sel)
|
||
|
pos -= (end_sel - start_sel);
|
||
|
else if (pos > start_sel)
|
||
|
pos = start_sel;
|
||
|
contents = contents.left(start_sel) + contents.right(end_sel+1);
|
||
|
}
|
||
|
|
||
|
int eot = contents.length();
|
||
|
while ((eot > 0) && contents[eot-1].isSpace()) eot--;
|
||
|
if (eot == 0)
|
||
|
{
|
||
15 years ago
|
contents = TQString::null;
|
||
15 years ago
|
}
|
||
|
else if (pos >= eot)
|
||
|
{
|
||
|
if (contents[eot-1] == ',')
|
||
|
eot--;
|
||
|
contents.truncate(eot);
|
||
|
contents += ", ";
|
||
|
pos = eot+2;
|
||
|
}
|
||
|
|
||
|
contents = contents.left(pos)+newText+contents.mid(pos);
|
||
|
setText(contents);
|
||
|
setCursorPosition(pos+newText.length());
|
||
|
}
|
||
|
|
||
|
void AddressLineEdit::paste()
|
||
|
{
|
||
|
if (m_useCompletion)
|
||
|
m_smartPaste = true;
|
||
|
KLineEdit::paste();
|
||
|
m_smartPaste = false;
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
void AddressLineEdit::cursorAtEnd()
|
||
|
{
|
||
|
setCursorPosition( text().length() );
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
void AddressLineEdit::enableCompletion(bool enable)
|
||
|
{
|
||
|
m_useCompletion = enable;
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
void AddressLineEdit::doCompletion(bool ctrlT)
|
||
|
{
|
||
|
if ( !m_useCompletion )
|
||
|
return;
|
||
|
|
||
15 years ago
|
TQString prevAddr;
|
||
15 years ago
|
|
||
15 years ago
|
TQString s(text());
|
||
13 years ago
|
int n = s.findRev(',');
|
||
15 years ago
|
|
||
|
if (n >= 0)
|
||
|
{
|
||
|
n++; // Go past the ","
|
||
|
|
||
|
int len = s.length();
|
||
|
|
||
|
// Increment past any whitespace...
|
||
|
while( n < len && s[n].isSpace() )
|
||
|
n++;
|
||
|
|
||
|
prevAddr = s.left(n);
|
||
|
s = s.mid(n,255).stripWhiteSpace();
|
||
|
}
|
||
|
|
||
|
if ( s_addressesDirty )
|
||
|
loadAddresses();
|
||
|
|
||
|
if ( ctrlT )
|
||
|
{
|
||
15 years ago
|
TQStringList completions = s_completion->substringCompletion( s );
|
||
15 years ago
|
if (completions.count() > 1) {
|
||
|
m_previousAddresses = prevAddr;
|
||
|
setCompletedItems( completions );
|
||
|
}
|
||
|
else if (completions.count() == 1)
|
||
|
setText(prevAddr + completions.first());
|
||
|
|
||
|
cursorAtEnd();
|
||
|
return;
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEGlobalSettings::Completion mode = completionMode();
|
||
15 years ago
|
|
||
|
switch ( mode )
|
||
|
{
|
||
12 years ago
|
case TDEGlobalSettings::CompletionPopupAuto:
|
||
15 years ago
|
{
|
||
|
if (s.isEmpty())
|
||
|
break;
|
||
|
}
|
||
12 years ago
|
case TDEGlobalSettings::CompletionPopup:
|
||
15 years ago
|
{
|
||
|
m_previousAddresses = prevAddr;
|
||
15 years ago
|
TQStringList items = s_completion->allMatches( s );
|
||
15 years ago
|
items += s_completion->allMatches( "\"" + s );
|
||
|
items += s_completion->substringCompletion( '<' + s );
|
||
|
uint beforeDollarCompletionCount = items.count();
|
||
|
|
||
13 years ago
|
if( s.find( ' ' ) == -1 ) // one word, possibly given name
|
||
15 years ago
|
items += s_completion->allMatches( "$$" + s );
|
||
|
|
||
|
if ( !items.isEmpty() )
|
||
|
{
|
||
|
if ( items.count() > beforeDollarCompletionCount )
|
||
|
{
|
||
|
// remove the '$$whatever$' part
|
||
15 years ago
|
for( TQStringList::Iterator it = items.begin();
|
||
15 years ago
|
it != items.end();
|
||
|
++it )
|
||
|
{
|
||
13 years ago
|
int pos = (*it).find( '$', 2 );
|
||
15 years ago
|
if( pos < 0 ) // ???
|
||
|
continue;
|
||
|
(*it)=(*it).mid( pos + 1 );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
items = removeMailDupes( items );
|
||
|
|
||
|
// We do not want KLineEdit::setCompletedItems to perform text
|
||
|
// completion (suggestion) since it does not know how to deal
|
||
|
// with providing proper completions for different items on the
|
||
|
// same line, e.g. comma-separated list of email addresses.
|
||
12 years ago
|
bool autoSuggest = (mode != TDEGlobalSettings::CompletionPopupAuto);
|
||
15 years ago
|
setCompletedItems( items, autoSuggest );
|
||
|
|
||
|
if (!autoSuggest)
|
||
|
{
|
||
13 years ago
|
int index = items.first().find( s );
|
||
15 years ago
|
TQString newText = prevAddr + items.first().mid( index );
|
||
15 years ago
|
//kdDebug() << "OLD TEXT: " << text() << endl;
|
||
|
//kdDebug() << "NEW TEXT: " << newText << endl;
|
||
|
setUserSelection(false);
|
||
|
setCompletedText(newText,true);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
break;
|
||
|
}
|
||
|
|
||
12 years ago
|
case TDEGlobalSettings::CompletionShell:
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString match = s_completion->makeCompletion( s );
|
||
15 years ago
|
if ( !match.isNull() && match != s )
|
||
|
{
|
||
|
setText( prevAddr + match );
|
||
|
cursorAtEnd();
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
|
||
12 years ago
|
case TDEGlobalSettings::CompletionMan: // Short-Auto in fact
|
||
|
case TDEGlobalSettings::CompletionAuto:
|
||
15 years ago
|
{
|
||
|
if (!s.isEmpty())
|
||
|
{
|
||
15 years ago
|
TQString match = s_completion->makeCompletion( s );
|
||
15 years ago
|
if ( !match.isNull() && match != s )
|
||
|
{
|
||
15 years ago
|
TQString adds = prevAddr + match;
|
||
15 years ago
|
setCompletedText( adds );
|
||
|
}
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
12 years ago
|
case TDEGlobalSettings::CompletionNone:
|
||
15 years ago
|
default: // fall through
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
15 years ago
|
void AddressLineEdit::slotPopupCompletion( const TQString& completion )
|
||
15 years ago
|
{
|
||
|
setText( m_previousAddresses + completion );
|
||
|
cursorAtEnd();
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
|
void AddressLineEdit::loadAddresses()
|
||
|
{
|
||
|
s_completion->clear();
|
||
|
s_addressesDirty = false;
|
||
|
|
||
15 years ago
|
TQStringList adrs = addresses();
|
||
|
for( TQStringList::ConstIterator it = adrs.begin(); it != adrs.end(); ++it)
|
||
15 years ago
|
addAddress( *it );
|
||
|
}
|
||
|
|
||
15 years ago
|
void AddressLineEdit::addAddress( const TQString& adr )
|
||
15 years ago
|
{
|
||
|
s_completion->addItem( adr );
|
||
13 years ago
|
int pos = adr.find( '<' );
|
||
15 years ago
|
if( pos >= 0 )
|
||
|
{
|
||
|
++pos;
|
||
13 years ago
|
int pos2 = adr.find( pos, '>' );
|
||
15 years ago
|
if( pos2 >= 0 )
|
||
|
s_completion->addItem( adr.mid( pos, pos2 - pos ));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void AddressLineEdit::slotStartLDAPLookup()
|
||
|
{
|
||
|
if( !s_LDAPSearch->isAvailable() || s_LDAPLineEdit != this )
|
||
|
return;
|
||
|
startLoadingLDAPEntries();
|
||
|
}
|
||
|
|
||
|
void AddressLineEdit::stopLDAPLookup()
|
||
|
{
|
||
|
s_LDAPSearch->cancelSearch();
|
||
|
s_LDAPLineEdit = NULL;
|
||
|
}
|
||
|
|
||
|
void AddressLineEdit::startLoadingLDAPEntries()
|
||
|
{
|
||
15 years ago
|
TQString s( *s_LDAPText );
|
||
15 years ago
|
// TODO cache last?
|
||
15 years ago
|
TQString prevAddr;
|
||
13 years ago
|
int n = s.findRev(',');
|
||
15 years ago
|
if (n>= 0)
|
||
|
{
|
||
|
prevAddr = s.left(n+1) + ' ';
|
||
|
s = s.mid(n+1,255).stripWhiteSpace();
|
||
|
}
|
||
|
if( s.length() == 0 )
|
||
|
return;
|
||
|
|
||
|
loadAddresses(); // TODO reuse these?
|
||
|
s_LDAPSearch->startSearch( s );
|
||
|
}
|
||
|
|
||
15 years ago
|
void AddressLineEdit::slotLDAPSearchData( const TQStringList& adrs )
|
||
15 years ago
|
{
|
||
|
if( s_LDAPLineEdit != this )
|
||
|
return;
|
||
15 years ago
|
for( TQStringList::ConstIterator it = adrs.begin(); it != adrs.end(); ++it ) {
|
||
|
TQString name(*it);
|
||
13 years ago
|
int pos = name.find( " <" );
|
||
|
int pos_comma = name.find( ',' );
|
||
15 years ago
|
// put name in quotes, if we have a comma in the name
|
||
|
if (pos>0 && pos_comma>0 && pos_comma<pos) {
|
||
|
name.insert(pos, '\"');
|
||
|
name.prepend('\"');
|
||
|
}
|
||
|
addAddress( name );
|
||
|
}
|
||
|
|
||
|
if( hasFocus() || completionBox()->hasFocus())
|
||
|
{
|
||
12 years ago
|
if( completionMode() != TDEGlobalSettings::CompletionNone )
|
||
15 years ago
|
{
|
||
|
doCompletion( false );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
15 years ago
|
TQStringList AddressLineEdit::removeMailDupes( const TQStringList& adrs )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQStringList src = adrs;
|
||
15 years ago
|
qHeapSort( src );
|
||
15 years ago
|
TQString last;
|
||
|
for( TQStringList::Iterator it = src.begin(); it != src.end(); ) {
|
||
15 years ago
|
if( *it == last )
|
||
|
{
|
||
|
it = src.remove( it );
|
||
|
continue; // dupe
|
||
|
}
|
||
|
last = *it;
|
||
|
++it;
|
||
|
}
|
||
|
return src;
|
||
|
}
|
||
|
|
||
|
//-----------------------------------------------------------------------------
|
||
15 years ago
|
void AddressLineEdit::dropEvent(TQDropEvent *e)
|
||
15 years ago
|
{
|
||
|
KURL::List uriList;
|
||
|
if(KURLDrag::canDecode(e) && KURLDrag::decode( e, uriList ))
|
||
|
{
|
||
15 years ago
|
TQString ct = text();
|
||
15 years ago
|
KURL::List::Iterator it = uriList.begin();
|
||
|
for (; it != uriList.end(); ++it)
|
||
|
{
|
||
|
if (!ct.isEmpty()) ct.append(", ");
|
||
|
KURL u(*it);
|
||
|
if ((*it).protocol() == "mailto")
|
||
|
ct.append( (*it).path() );
|
||
|
else
|
||
|
ct.append( (*it).url() );
|
||
|
}
|
||
|
setText(ct);
|
||
|
setEdited( true );
|
||
|
}
|
||
|
else {
|
||
|
if (m_useCompletion)
|
||
|
m_smartPaste = true;
|
||
15 years ago
|
TQLineEdit::dropEvent(e);
|
||
15 years ago
|
m_smartPaste = false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
TQStringList AddressLineEdit::addresses()
|
||
15 years ago
|
{
|
||
15 years ago
|
TQApplication::setOverrideCursor( KCursor::waitCursor() ); // loading might take a while
|
||
15 years ago
|
|
||
15 years ago
|
TQStringList result;
|
||
|
TQString space(" ");
|
||
|
TQRegExp needQuotes("[^ 0-9A-Za-z\\x0080-\\xFFFF]");
|
||
|
TQString endQuote("\" ");
|
||
|
TQString addr, email;
|
||
15 years ago
|
|
||
|
KABC::AddressBook *addressBook = KABC::StdAddressBook::self();
|
||
|
KABC::AddressBook::Iterator it;
|
||
|
for( it = addressBook->begin(); it != addressBook->end(); ++it ) {
|
||
15 years ago
|
TQStringList emails = (*it).emails();
|
||
15 years ago
|
|
||
15 years ago
|
TQString n = (*it).prefix() + space +
|
||
15 years ago
|
(*it).givenName() + space +
|
||
|
(*it).additionalName() + space +
|
||
|
(*it).familyName() + space +
|
||
|
(*it).suffix();
|
||
|
|
||
|
n = n.simplifyWhiteSpace();
|
||
|
|
||
15 years ago
|
TQStringList::ConstIterator mit;
|
||
15 years ago
|
|
||
|
for ( mit = emails.begin(); mit != emails.end(); ++mit ) {
|
||
|
email = *mit;
|
||
|
if (!email.isEmpty()) {
|
||
13 years ago
|
if (n.isEmpty() || (email.find( '<' ) != -1))
|
||
15 years ago
|
addr = TQString::null;
|
||
15 years ago
|
else { /* do we really need quotes around this name ? */
|
||
13 years ago
|
if (n.find(needQuotes) != -1)
|
||
15 years ago
|
addr = '"' + n + endQuote;
|
||
|
else
|
||
|
addr = n + space;
|
||
|
}
|
||
|
|
||
13 years ago
|
if (!addr.isEmpty() && (email.find( '<' ) == -1)
|
||
|
&& (email.find( '>' ) == -1)
|
||
|
&& (email.find( ',' ) == -1))
|
||
15 years ago
|
addr += '<' + email + '>';
|
||
|
else
|
||
|
addr += email;
|
||
|
addr = addr.stripWhiteSpace();
|
||
|
result.append( addr );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
KABC::DistributionListManager manager( addressBook );
|
||
|
manager.load();
|
||
|
result += manager.listNames();
|
||
|
|
||
15 years ago
|
TQApplication::restoreOverrideCursor();
|
||
15 years ago
|
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
#include "addresslineedit.moc"
|