summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-07-03 23:38:18 (UTC)
committer zautrix <zautrix>2004-07-03 23:38:18 (UTC)
commit260befadfaa64d94de7d38d7f6cad0d22f52c226 (patch) (side-by-side diff)
tree96923d1ac1304e8f07028941e830437465bb9558
parent00fe3539778c859d22f595e516733b3cc792e167 (diff)
downloadkdepimpi-260befadfaa64d94de7d38d7f6cad0d22f52c226.zip
kdepimpi-260befadfaa64d94de7d38d7f6cad0d22f52c226.tar.gz
kdepimpi-260befadfaa64d94de7d38d7f6cad0d22f52c226.tar.bz2
fixed distribution lists
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--kabc/distributionlist.cpp30
-rw-r--r--kabc/distributionlisteditor.cpp1
2 files changed, 19 insertions, 12 deletions
diff --git a/kabc/distributionlist.cpp b/kabc/distributionlist.cpp
index 45b9dda..0735aba 100644
--- a/kabc/distributionlist.cpp
+++ b/kabc/distributionlist.cpp
@@ -1,289 +1,295 @@
/*
This file is part of libkabc.
Copyright (c) 2001 Cornelius Schumacher <schumacher@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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <ksimpleconfig.h>
#include <kstandarddirs.h>
#include <kdebug.h>
#include "distributionlist.h"
using namespace KABC;
DistributionList::DistributionList( DistributionListManager *manager,
const QString &name ) :
mManager( manager ), mName( name )
{
mManager->insert( this );
}
DistributionList::~DistributionList()
{
mManager->remove( this );
}
void DistributionList::setName( const QString &name )
{
mName = name;
}
QString DistributionList::name() const
{
return mName;
}
void DistributionList::insertEntry( const Addressee &a, const QString &email )
{
- Entry e( a, email );
-
+ QString em = email;
+ if (em.isNull() )
+ em = a.preferredEmail();
+ Entry e( a, em );
QValueList<Entry>::Iterator it;
for( it = mEntries.begin(); it != mEntries.end(); ++it ) {
if ( (*it).addressee.uid() == a.uid() ) {
/**
We have to check if both email addresses contains no data,
a simple 'email1 == email2' wont work here
*/
- if ( ( (*it).email.isNull() && email.isEmpty() ) ||
- ( (*it).email.isEmpty() && email.isNull() ) ||
- ( (*it).email == email ) ) {
- *it = e;
+ if ( ( (*it).email.isNull() && em.isEmpty() ) ||
+ ( (*it).email.isEmpty() && em.isNull() ) ||
+ ( (*it).email == em ) ) {
+ //*it = e;
return;
}
}
}
mEntries.append( e );
}
void DistributionList::removeEntry( const Addressee &a, const QString &email )
{
QValueList<Entry>::Iterator it;
for( it = mEntries.begin(); it != mEntries.end(); ++it ) {
if ( (*it).addressee.uid() == a.uid() && (*it).email == email ) {
mEntries.remove( it );
return;
}
}
}
QStringList DistributionList::emails() const
{
QStringList emails;
Entry::List::ConstIterator it;
for( it = mEntries.begin(); it != mEntries.end(); ++it ) {
Addressee a = (*it).addressee;
QString email = (*it).email.isEmpty() ? a.fullEmail() :
a.fullEmail( (*it).email );
if ( !email.isEmpty() ) {
emails.append( email );
}
}
return emails;
}
DistributionList::Entry::List DistributionList::entries() const
{
return mEntries;
}
DistributionListManager::DistributionListManager( AddressBook *ab ) :
mAddressBook( ab )
{
}
DistributionListManager::~DistributionListManager()
{
}
DistributionList *DistributionListManager::list( const QString &name )
{
DistributionList *list;
for( list = mLists.first(); list; list = mLists.next() ) {
if ( list->name() == name ) return list;
}
return 0;
}
void DistributionListManager::insert( DistributionList *l )
{
DistributionList *list;
for( list = mLists.first(); list; list = mLists.next() ) {
if ( list->name() == l->name() ) {
mLists.remove( list );
break;
}
}
mLists.append( l );
}
void DistributionListManager::remove( DistributionList *l )
{
DistributionList *list;
for( list = mLists.first(); list; list = mLists.next() ) {
if ( list->name() == l->name() ) {
mLists.remove( list );
return;
}
}
}
QStringList DistributionListManager::listNames()
{
QStringList names;
DistributionList *list;
for( list = mLists.first(); list; list = mLists.next() ) {
names.append( list->name() );
}
return names;
}
bool DistributionListManager::load()
{
KSimpleConfig cfg( locateLocal( "data", "kabc/distlists" ) );
/*US
QMap<QString,QString> entryMap = cfg.entryMap( mAddressBook->identifier() );
if ( entryMap.isEmpty() ) {
kdDebug(5700) << "No distlists for '" << mAddressBook->identifier() << "'" << endl;
return false;
}
cfg.setGroup( mAddressBook->identifier() );
QMap<QString,QString>::ConstIterator it;
for( it = entryMap.begin(); it != entryMap.end(); ++it ) {
QString name = it.key();
*/
cfg.setGroup( mAddressBook->identifier() );
//US we work in microkde with a list of distributionlists
- QStringList distlists = cfg.readListEntry( "Lists" );
+ QStringList distlists = cfg.readListEntry( "__Lists__List__" );
if ( distlists.isEmpty() ) {
- kdDebug(5700) << "No distlists for '" << mAddressBook->identifier() << "'" << endl;
+ qDebug("no distlist for AB ");
return false;
}
QStringList::ConstIterator it;
for( it = distlists.begin(); it != distlists.end(); ++it ) {
QString name = *it;
QStringList value = cfg.readListEntry( name );
- kdDebug(5700) << "DLM::load(): " << name << ": " << value.join(",") << endl;
+
DistributionList *list = new DistributionList( this, name );
QStringList::ConstIterator it2 = value.begin();
while( it2 != value.end() ) {
QString id = *it2++;
QString email = *it2;
- kdDebug(5700) << "----- Entry " << id << endl;
+
Addressee a = mAddressBook->findByUid( id );
if ( !a.isEmpty() ) {
list->insertEntry( a, email );
}
if ( it2 == value.end() ) break;
++it2;
}
}
return true;
}
bool DistributionListManager::save()
{
- kdDebug(5700) << "DistListManager::save()" << endl;
+
KSimpleConfig cfg( locateLocal( "data", "kabc/distlists" ) );
cfg.deleteGroup( mAddressBook->identifier() );
cfg.setGroup( mAddressBook->identifier() );
DistributionList *list;
for( list = mLists.first(); list; list = mLists.next() ) {
kdDebug(5700) << " Saving '" << list->name() << "'" << endl;
QStringList value;
DistributionList::Entry::List entries = list->entries();
DistributionList::Entry::List::ConstIterator it;
for( it = entries.begin(); it != entries.end(); ++it ) {
value.append( (*it).addressee.uid() );
+ if (( *it).email.isEmpty())
+ value.append( " " );
+ else
value.append( (*it).email );
+ // qDebug("uid *%s* email *%s* ", (*it).addressee.uid().latin1(),(*it).email.latin1() );
}
cfg.writeEntry( list->name(), value );
}
//US for microKDE we have not yet sophisticated methods to load maps.
// Because of that we store also a list of all distributionlists.
QStringList namelist;
for( list = mLists.first(); list; list = mLists.next() ) {
namelist.append( list->name() );
}
- cfg.writeEntry( "Lists", namelist );
+ cfg.writeEntry( "__Lists__List__", namelist );
cfg.sync();
return true;
}
DistributionListWatcher* DistributionListWatcher::mSelf = 0;
DistributionListWatcher::DistributionListWatcher()
: QObject( 0, "DistributionListWatcher" )
{
/*US
mDirWatch = new KDirWatch;
mDirWatch->addFile( locateLocal( "data", "kabc/distlists" ) );
connect( mDirWatch, SIGNAL( dirty( const QString& ) ), SIGNAL( changed() ) );
mDirWatch->startScan();
*/
}
DistributionListWatcher::~DistributionListWatcher()
{
/*US
delete mDirWatch;
mDirWatch = 0;
*/
}
DistributionListWatcher *DistributionListWatcher::self()
{
if ( !mSelf )
mSelf = new DistributionListWatcher();
return mSelf;
}
//US #include "distributionlist.moc"
diff --git a/kabc/distributionlisteditor.cpp b/kabc/distributionlisteditor.cpp
index 8b485d8..bad1efc 100644
--- a/kabc/distributionlisteditor.cpp
+++ b/kabc/distributionlisteditor.cpp
@@ -1,317 +1,318 @@
/*
This file is part of libkabc.
Copyright (c) 2001 Cornelius Schumacher <schumacher@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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <qlistview.h>
#include <qlayout.h>
#include <qpushbutton.h>
#include <qcombobox.h>
#include <qinputdialog.h>
#include <qbuttongroup.h>
#include <qradiobutton.h>
#include <klocale.h>
#include <kdebug.h>
#include "addressbook.h"
#include "addresseedialog.h"
#include "distributionlist.h"
#include "distributionlisteditor.h"
//US #include "distributionlisteditor.moc"
using namespace KABC;
EmailSelectDialog::EmailSelectDialog( const QStringList &emails, const QString &current,
QWidget *parent ) :
KDialogBase( KDialogBase::Plain, i18n("Select Email Address"), Ok, Ok,
parent )
{
QFrame *topFrame = plainPage();
QBoxLayout *topLayout = new QVBoxLayout( topFrame );
mButtonGroup = new QButtonGroup( 1, Horizontal, i18n("Email Addresses"),
topFrame );
topLayout->addWidget( mButtonGroup );
QStringList::ConstIterator it;
for( it = emails.begin(); it != emails.end(); ++it ) {
QRadioButton *button = new QRadioButton( *it, mButtonGroup );
if ( (*it) == current ) {
button->setDown( true );
}
}
}
QString EmailSelectDialog::selected()
{
QButton *button = mButtonGroup->selected();
if ( button ) return button->text();
return QString::null;
}
QString EmailSelectDialog::getEmail( const QStringList &emails, const QString &current,
QWidget *parent )
{
+
EmailSelectDialog *dlg = new EmailSelectDialog( emails, current, parent );
dlg->exec();
QString result = dlg->selected();
delete dlg;
return result;
}
class EditEntryItem : public QListViewItem
{
public:
EditEntryItem( QListView *parent, const Addressee &addressee,
const QString &email=QString::null ) :
QListViewItem( parent ),
mAddressee( addressee ),
mEmail( email )
{
setText( 0, addressee.realName() );
if( email.isEmpty() ) {
setText( 1, addressee.preferredEmail() );
setText( 2, i18n("Yes") );
} else {
setText( 1, email );
setText( 2, i18n("No") );
}
}
Addressee addressee() const
{
return mAddressee;
}
QString email() const
{
return mEmail;
}
private:
Addressee mAddressee;
QString mEmail;
};
DistributionListEditor::DistributionListEditor( AddressBook *addressBook, QWidget *parent) :
QWidget( parent ),
mAddressBook( addressBook )
{
kdDebug(5700) << "DistributionListEditor()" << endl;
QBoxLayout *topLayout = new QVBoxLayout( this );
topLayout->setMargin( KDialog::marginHint() );
topLayout->setSpacing( KDialog::spacingHint() );
QBoxLayout *nameLayout = new QHBoxLayout( topLayout) ;
mNameCombo = new QComboBox( this );
nameLayout->addWidget( mNameCombo );
connect( mNameCombo, SIGNAL( activated( int ) ), SLOT( updateEntryView() ) );
newButton = new QPushButton( i18n("New List"), this );
nameLayout->addWidget( newButton );
connect( newButton, SIGNAL( clicked() ), SLOT( newList() ) );
removeButton = new QPushButton( i18n("Remove List"), this );
nameLayout->addWidget( removeButton );
connect( removeButton, SIGNAL( clicked() ), SLOT( removeList() ) );
mEntryView = new QListView( this );
mEntryView->addColumn( i18n("Name") );
mEntryView->addColumn( i18n("Email") );
mEntryView->addColumn( i18n("Use Preferred") );
topLayout->addWidget( mEntryView );
connect(mEntryView,SIGNAL(selectionChanged ()),this, SLOT(slotSelectionEntryViewChanged()));
changeEmailButton = new QPushButton( i18n("Change Email"), this );
topLayout->addWidget( changeEmailButton );
connect( changeEmailButton, SIGNAL( clicked() ), SLOT( changeEmail() ) );
removeEntryButton = new QPushButton( i18n("Remove Entry"), this );
topLayout->addWidget( removeEntryButton );
connect( removeEntryButton, SIGNAL( clicked() ), SLOT( removeEntry() ) );
addEntryButton = new QPushButton( i18n("Add Entry"), this );
topLayout->addWidget( addEntryButton );
connect( addEntryButton, SIGNAL( clicked() ), SLOT( addEntry() ) );
mAddresseeView = new QListView( this );
mAddresseeView->addColumn( i18n("Name") );
mAddresseeView->addColumn( i18n("Preferred Email") );
topLayout->addWidget( mAddresseeView );
connect(mAddresseeView,SIGNAL(selectionChanged ()),this, SLOT(slotSelectionAddresseeViewChanged()));
mManager = new DistributionListManager( mAddressBook );
mManager->load();
updateAddresseeView();
updateNameCombo();
removeButton->setEnabled(!mManager->listNames().isEmpty());
}
DistributionListEditor::~DistributionListEditor()
{
kdDebug(5700) << "~DistributionListEditor()" << endl;
mManager->save();
delete mManager;
}
void DistributionListEditor::slotSelectionEntryViewChanged()
{
//US EditEntryItem *entryItem = dynamic_cast<EditEntryItem *>( mEntryView->selectedItem() );
EditEntryItem *entryItem = (EditEntryItem *)( mEntryView->selectedItem() );
bool state = (entryItem != 0L);
changeEmailButton->setEnabled(state);
removeEntryButton->setEnabled(state);
}
void DistributionListEditor::newList()
{
bool ok = false;
QString name = QInputDialog::getText( i18n("New Distribution List"),
i18n("Please enter name:"),
QLineEdit::Normal, QString::null, &ok,
this );
if ( !ok || name.isEmpty() ) return;
new DistributionList( mManager, name );
mNameCombo->insertItem( name );
removeButton->setEnabled(true);
updateEntryView();
}
void DistributionListEditor::removeList()
{
delete mManager->list( mNameCombo->currentText() );
mNameCombo->removeItem( mNameCombo->currentItem() );
removeButton->setEnabled(!mManager->listNames().isEmpty());
addEntryButton->setEnabled( !mNameCombo->currentText().isEmpty());
updateEntryView();
}
void DistributionListEditor::addEntry()
{
/*US
AddresseeItem *addresseeItem =
dynamic_cast<AddresseeItem *>( mAddresseeView->selectedItem() );
*/
AddresseeItem *addresseeItem =
(AddresseeItem *)( mAddresseeView->selectedItem() );
if( !addresseeItem ) {
kdDebug(5700) << "DLE::addEntry(): No addressee selected." << endl;
return;
}
DistributionList *list = mManager->list( mNameCombo->currentText() );
if ( !list ) {
kdDebug(5700) << "DLE::addEntry(): No dist list '" << mNameCombo->currentText() << "'" << endl;
return;
}
list->insertEntry( addresseeItem->addressee() );
updateEntryView();
slotSelectionAddresseeViewChanged();
}
void DistributionListEditor::removeEntry()
{
DistributionList *list = mManager->list( mNameCombo->currentText() );
if ( !list ) return;
//US EditEntryItem *entryItem = dynamic_cast<EditEntryItem *>( mEntryView->selectedItem() );
EditEntryItem *entryItem = (EditEntryItem *)( mEntryView->selectedItem() );
if ( !entryItem ) return;
list->removeEntry( entryItem->addressee(), entryItem->email() );
delete entryItem;
}
void DistributionListEditor::changeEmail()
{
DistributionList *list = mManager->list( mNameCombo->currentText() );
if ( !list ) return;
//US EditEntryItem *entryItem = dynamic_cast<EditEntryItem *>( mEntryView->selectedItem() );
EditEntryItem *entryItem = (EditEntryItem *)( mEntryView->selectedItem() );
if ( !entryItem ) return;
QString email = EmailSelectDialog::getEmail( entryItem->addressee().emails(),
entryItem->email(), this );
list->removeEntry( entryItem->addressee(), entryItem->email() );
list->insertEntry( entryItem->addressee(), email );
updateEntryView();
}
void DistributionListEditor::updateEntryView()
{
DistributionList *list = mManager->list( mNameCombo->currentText() );
if ( !list ) return;
mEntryView->clear();
DistributionList::Entry::List entries = list->entries();
DistributionList::Entry::List::ConstIterator it;
for( it = entries.begin(); it != entries.end(); ++it ) {
new EditEntryItem( mEntryView, (*it).addressee, (*it).email );
}
//US EditEntryItem *entryItem = dynamic_cast<EditEntryItem *>( mEntryView->selectedItem() );
EditEntryItem *entryItem = (EditEntryItem *)( mEntryView->selectedItem() );
bool state = (entryItem != 0L);
changeEmailButton->setEnabled(state);
removeEntryButton->setEnabled(state);
}
void DistributionListEditor::updateAddresseeView()
{
mAddresseeView->clear();
AddressBook::Iterator it;
for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) {
new AddresseeItem( mAddresseeView, *it );
}
}
void DistributionListEditor::updateNameCombo()
{
mNameCombo->insertStringList( mManager->listNames() );
updateEntryView();
}
void DistributionListEditor::slotSelectionAddresseeViewChanged()
{
//US AddresseeItem *addresseeItem = dynamic_cast<AddresseeItem *>( mAddresseeView->selectedItem() );
AddresseeItem *addresseeItem = (AddresseeItem *)( mAddresseeView->selectedItem() );
bool state = (addresseeItem != 0L);
addEntryButton->setEnabled( state && !mNameCombo->currentText().isEmpty());
}