[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-pim
Subject: Re: [Kde-pim] kabc/distributionlist: Entry class returns references
From: Kevin Krammer <kevin.krammer () gmx ! at>
Date: 2007-09-20 21:03:38
Message-ID: 200709202303.46949.kevin.krammer () gmx ! at
[Download RAW message or body]
[Attachment #2 (multipart/signed)]
[Attachment #4 (multipart/mixed)]
Hi Tobias,
On Sunday 09 September 2007, Tobias Koenig wrote:
> An extension to KABC::Resource. All kabc resources should have the
> possibility to provide distribution lists. So maybe we should create a
> new subclass of ResourceFile then (e.g. ResourceStdFile), which loads the
> contacts from $HOME/.kde/share/kabc/std.vcf and the distribution lists from
> $HOME/.kde/share/kabc/distlists.
I haven't done the loading/saving yet since I am not sure which file to add it
to.
kabc.diff: the changes in kdepimlibs/kabc
libkdepim.diff, kmail.diff and kaddressbook.diff are for kdepim. These
patchset are quite "experimental", i.e. I tried to replace old code with new
one but don't necessarily got all requirements of the surrounding code.
Cheers,
Kevin
--
Kevin Krammer, KDE developer, xdg-utils developer
KDE user support, developer mentoring
["kabc.diff" (text/x-diff)]
Index: addressbook.cpp
===================================================================
--- addressbook.cpp (Revision 714883)
+++ addressbook.cpp (Arbeitskopie)
@@ -19,6 +19,7 @@
*/
#include "addressbook.h"
+#include "distributionlist.h"
#include "errorhandler.h"
#include "resource.h"
@@ -591,6 +592,18 @@
return end();
}
+AddressBook::ConstIterator AddressBook::find( const Addressee &a ) const
+{
+ ConstIterator it;
+ for ( it = begin(); it != end(); ++it ) {
+ if ( a.uid() == (*it).uid() ) {
+ return it;
+ }
+ }
+
+ return end();
+}
+
Addressee AddressBook::findByUid( const QString &uid ) const
{
KRES::Manager<Resource>::ActiveIterator it;
@@ -652,6 +665,70 @@
return results;
}
+DistributionList* AddressBook::createDistributionList( const QString &name, \
Resource* resource ) +{
+ if ( resource == 0 )
+ resource = standardResource();
+
+ return new DistributionList( resource, name );
+}
+
+void AddressBook::removeDistributionList( DistributionList *list )
+{
+ if ( !list || !list->resource() )
+ return;
+
+ list->resource()->removeDistributionList( list );
+}
+
+DistributionList* AddressBook::findDistributionListByIdentifier( const QString \
&identifier ) +{
+ KRES::Manager<Resource>::ActiveIterator it;
+ for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
+ DistributionList* list = (*it)->findDistributionListByIdentifier( identifier );
+ if ( list )
+ return list;
+ }
+
+ return 0;
+}
+
+DistributionList* AddressBook::findDistributionListByName( const QString &name, \
Qt::CaseSensitivity caseSensitivity ) +{
+ KRES::Manager<Resource>::ActiveIterator it;
+ for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
+ DistributionList* list = (*it)->findDistributionListByName( name, \
caseSensitivity ); + if ( list )
+ return list;
+ }
+
+ return 0;
+}
+
+QList<DistributionList*> AddressBook::allDistributionLists()
+{
+ QList<DistributionList*> results;
+
+ KRES::Manager<Resource>::ActiveIterator it;
+ for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
+ results += (*it)->allDistributionLists();
+ }
+
+ return results;
+}
+
+QStringList AddressBook::allDistributionListNames() const
+{
+ QStringList results;
+
+ KRES::Manager<Resource>::ActiveIterator it;
+ for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) {
+ results += (*it)->allDistributionListNames();
+ }
+
+ return results;
+}
+
void AddressBook::dump() const
{
kDebug(5700) << "AddressBook::dump() --- begin ---";
Index: distributionlistdialog.cpp
===================================================================
--- distributionlistdialog.cpp (Revision 714883)
+++ distributionlistdialog.cpp (Arbeitskopie)
@@ -156,12 +156,10 @@
Private( AddressBook *addressBook, DistributionListEditorWidget *parent )
: mParent( parent ), mAddressBook( addressBook )
{
- mManager = new DistributionListManager( mAddressBook );
}
~Private()
{
- delete mManager;
}
void newList();
@@ -184,7 +182,6 @@
QTreeWidget *mAddresseeView;
AddressBook *mAddressBook;
- DistributionListManager *mManager;
QPushButton *mNewButton, *mEditButton, *mRemoveButton;
QPushButton *mChangeEmailButton, *mRemoveEntryButton, *mAddEntryButton;
};
@@ -259,8 +256,6 @@
gridLayout->addWidget( d->mRemoveEntryButton, 2, 2 );
connect( d->mRemoveEntryButton, SIGNAL( clicked() ), SLOT( removeEntry() ) );
- d->mManager->load();
-
d->updateAddresseeView();
d->updateNameCombo();
}
@@ -272,7 +267,9 @@
void DistributionListEditorWidget::Private::save()
{
- mManager->save();
+ // FIXME new distribution list handling
+ // do we need extra save?
+ //mManager->save();
}
void DistributionListEditorWidget::Private::slotSelectionEntryViewChanged()
@@ -292,10 +289,10 @@
return;
}
- new DistributionList( mManager, name );
+ mAddressBook->createDistributionList( name );
mNameCombo->clear();
- mNameCombo->addItems( mManager->listNames() );
+ mNameCombo->addItems( mAddressBook->allDistributionListNames() );
mNameCombo->setCurrentIndex( mNameCombo->count() - 1 );
updateEntryView();
@@ -312,11 +309,12 @@
return;
}
- DistributionList *list = mManager->list( oldName );
- list->setName( name );
+ DistributionList *list = mAddressBook->findDistributionListByName( oldName );
+ if ( list )
+ list->setName( name );
mNameCombo->clear();
- mNameCombo->addItems( mManager->listNames() );
+ mNameCombo->addItems( mAddressBook->allDistributionListNames() );
mNameCombo->setCurrentIndex( mNameCombo->count() - 1 );
updateEntryView();
@@ -333,8 +331,13 @@
return;
}
- mManager->remove( mManager->list( mNameCombo->currentText() ) );
- mNameCombo->removeItem( mNameCombo->currentIndex() );
+ DistributionList *list = mAddressBook->findDistributionListByName( \
mNameCombo->currentText() ); + if ( list ) {
+ // FIXME new distribution list handling
+ // list should be deleted, no?
+ mAddressBook->removeDistributionList( list );
+ mNameCombo->removeItem( mNameCombo->currentIndex() );
+ }
updateEntryView();
slotSelectionAddresseeViewChanged();
@@ -350,7 +353,7 @@
AddresseeItem *addresseeItem =
static_cast<AddresseeItem *>( selected.at( 0 ) );
- DistributionList *list = mManager->list( mNameCombo->currentText() );
+ DistributionList *list = mAddressBook->findDistributionListByName( \
mNameCombo->currentText() ); if ( !list ) {
kDebug(5700) << "DLE::addEntry(): No dist list '" << mNameCombo->currentText() \
<< "'"; return;
@@ -363,7 +366,7 @@
void DistributionListEditorWidget::Private::removeEntry()
{
- DistributionList *list = mManager->list( mNameCombo->currentText() );
+ DistributionList *list = mAddressBook->findDistributionListByName( \
mNameCombo->currentText() ); if ( !list ) {
return;
}
@@ -382,7 +385,7 @@
void DistributionListEditorWidget::Private::changeEmail()
{
- DistributionList *list = mManager->list( mNameCombo->currentText() );
+ DistributionList *list = mAddressBook->findDistributionListByName( \
mNameCombo->currentText() ); if ( !list ) {
return;
}
@@ -414,7 +417,7 @@
mEntryView->clear();
- DistributionList *list = mManager->list( mNameCombo->currentText() );
+ DistributionList *list = mAddressBook->findDistributionListByName( \
mNameCombo->currentText() ); if ( !list ) {
mEditButton->setEnabled( false );
mRemoveButton->setEnabled( false );
@@ -455,7 +458,7 @@
void DistributionListEditorWidget::Private::updateNameCombo()
{
- mNameCombo->addItems( mManager->listNames() );
+ mNameCombo->addItems( mAddressBook->allDistributionListNames() );
updateEntryView();
}
Index: addressbook.h
===================================================================
--- addressbook.h (Revision 714883)
+++ addressbook.h (Arbeitskopie)
@@ -31,6 +31,7 @@
namespace KABC {
+class DistributionList;
class ErrorHandler;
class Resource;
class Ticket;
@@ -393,11 +394,19 @@
Returns an iterator pointing to the specified addressee. It will return
end() if no addressee matched.
- @param addr The addresee you are looking for.
+ @param addr The addressee you are looking for.
*/
- Iterator find( const Addressee &addr ); // KDE4: const
+ Iterator find( const Addressee &addr );
/**
+ Returns an iterator pointing to the specified addressee. It will return
+ end() if no addressee matched.
+
+ @param addr The addressee you are looking for.
+ */
+ ConstIterator find( const Addressee &addr ) const;
+
+ /**
Searches an addressee with the specified unique identifier.
@param uid The unique identifier you are looking for.
@@ -436,6 +445,59 @@
Addressee::List findByCategory( const QString &category ) const;
/**
+ Creates a distribution list with a given @p name storing it in a
+ given @p resource
+
+ @note The newly created list will be added to the addressbook
+ automatically on creation.
+
+ @param name The localized name of the new distribution list.
+ @param resource The resource which should save the list. If @c 0
+ (default) the addressbook's standard resource will be used.
+
+ @see standardResource()
+ */
+ DistributionList* createDistributionList( const QString &name, Resource* \
resource = 0 ); +
+ /**
+ Removes a distribution @p list from its associated resource.
+
+ @param list The list to remove.
+ */
+ void removeDistributionList( DistributionList *list );
+
+ /**
+ Returns a distribution list for the given @p identifier or @c 0
+
+ @param identifier The ID of the list for look for.
+ */
+ DistributionList* findDistributionListByIdentifier( const QString &identifier );
+
+ /**
+ Returns a distribution list with the given @p name or @c 0
+
+ @param name The localized name of the list for look for.
+ @param caseSensitivity Whether to do string matching case sensitive or
+ case insensitive. Default is @c Qt::CaseSensitive
+ */
+ DistributionList* findDistributionListByName( const QString &name, \
Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive ); +
+ /**
+ Returns a list of all distribution lists of all resources of this
+ address book
+ */
+ QList<DistributionList*> allDistributionLists();
+
+ /**
+ Returns a list of names of all distribution lists of all resources
+ of this address book.
+
+ Convenience function, equal to iterate over the list returned
+ by allDistributionLists()
+ */
+ QStringList allDistributionListNames() const;
+
+ /**
Returns a string identifying this addressbook. The identifier is
created by concatenation of the resource identifiers.
*/
Index: addresslineedit.cpp
===================================================================
--- addresslineedit.cpp (Revision 714883)
+++ addresslineedit.cpp (Arbeitskopie)
@@ -36,7 +36,6 @@
#include <kstandarddirs.h>
#include <kstandardshortcut.h>
-#include "distributionlist.h"
#include "stdaddressbook.h"
//=============================================================================
@@ -155,9 +154,7 @@
}
}
- KABC::DistributionListManager manager( addressBook );
- manager.load();
- result += manager.listNames();
+ result += addressBook->allDistributionListNames();
QApplication::restoreOverrideCursor();
Index: distributionlist.h
===================================================================
--- distributionlist.h (Revision 714883)
+++ distributionlist.h (Arbeitskopie)
@@ -27,7 +27,8 @@
namespace KABC {
-class DistributionListManager;
+//class DistributionListManager;
+class Resource;
/**
@short Distribution list of email addresses
@@ -90,14 +91,14 @@
/**
Returns the addressee of the list entry.
*/
- Addressee &addressee() const;
+ Addressee addressee() const;
/**
Returns the email address of the list entry.
@return @c QString() if no specific email address has been set
*/
- QString &email() const;
+ QString email() const;
private:
class Private;
@@ -110,17 +111,40 @@
@param manager Managing object of this list.
@param name Name of this list.
*/
- DistributionList( DistributionListManager *manager, const QString &name );
+ DistributionList( Resource *resource, const QString &name );
/**
+ Create distribution list object.
+
+ @param manager Managing object of this list.
+ @param identifier Identifier of this list.
+ @param name Name of this list.
+ */
+ DistributionList( Resource *resource, const QString &identifier,
+ const QString &name );
+
+ /**
Destructor.
*/
~DistributionList();
/**
- Set name of this list. The name is used as key by the
- DistributinListManager.
+ Sets the @p identifier of this list which is used as key by resources
+
+ @param identifier A unique identifier of the distribution list
*/
+ void setIdentifier( const QString &identifier );
+
+ /**
+ Returns the distribution list's identifier
+ */
+ QString identifier() const;
+
+ /**
+ Set name of this list.
+
+ This is a i18n string for display to the user
+ */
void setName( const QString & );
/**
@@ -161,6 +185,8 @@
*/
Entry::List entries() const;
+ Resource* resource() const;
+
private:
class Private;
Private *const d;
@@ -169,64 +195,10 @@
};
/**
- @short Manager of distribution lists
-
- This class represents a collection of distribution lists, which are associated
- with a given address book.
+ Typedef for map from IDs to respective DistribtionList
*/
-class KABC_EXPORT DistributionListManager
-{
- public:
- /**
- Create manager for given address book.
- */
- DistributionListManager( AddressBook * );
+typedef QMap<QString, DistributionList*> DistributionListMap;
- /**
- Destructor.
- */
- ~DistributionListManager();
-
- /**
- Return distribution list with given name.
- */
- DistributionList *list( const QString &name,
- Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive \
);
-
- /**
- Insert distribution list. If a list with this name already exists, nothing
- happens. The passed object is deleted by the manager.
- */
- void insert( DistributionList * );
-
- /**
- Remove distribution list. If a list with this name doesn't exist, nothing
- happens.
- */
- void remove( DistributionList * );
-
- /**
- Return names of all distribution lists managed by this manager.
- */
- QStringList listNames();
-
- /**
- Load distribution lists form disk.
- */
- bool load();
-
- /**
- Save distribution lists to disk.
- */
- bool save();
-
- private:
- class Private;
- Private *const d;
-
- Q_DISABLE_COPY( DistributionListManager )
-};
-
/**
@short Watchdog for distribution lists
Index: resource.h
===================================================================
--- resource.h (Revision 714883)
+++ resource.h (Arbeitskopie)
@@ -22,6 +22,7 @@
#define KABC_RESOURCE_H
#include "addressbook.h"
+#include "distributionlist.h"
#include "plugin.h"
#include "kresources/resource.h"
@@ -405,11 +406,54 @@
virtual Addressee::List findByCategory( const QString &category );
/**
- Removes all addressees from the resource.
+ Removes all addressees and distribution lists from the resource.
*/
virtual void clear();
/**
+ Adds a distribution @p list into this resource.
+
+ @param list The list to insert.
+ */
+ virtual void insertDistributionList( DistributionList *list );
+
+ /**
+ Removes a distribution @p list from this resource.
+
+ @param list The list to remove.
+ */
+ virtual void removeDistributionList( DistributionList *list );
+
+ /**
+ Returns a distribution list for the given @p identifier or @c 0
+
+ @param identifier The ID of the list for look for.
+ */
+ virtual DistributionList* findDistributionListByIdentifier( const QString& \
identifier ); +
+ /**
+ Returns a distribution list with the given @p name or @c 0
+
+ @param name The localized name of the list for look for.
+ @param caseSensitivity Whether to do string matching case sensitive or
+ case insensitive. Default is @c Qt::CaseSensitive
+ */
+ virtual DistributionList* findDistributionListByName( const QString &name, \
Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive ); +
+ /**
+ Returns a list of all distribution lists of this resource.
+ */
+ virtual QList<DistributionList*> allDistributionLists();
+
+ /**
+ Returns a list of names of all distribution lists of this resource.
+
+ Convenience function, equal to iterate over the list returned
+ by allDistributionLists()
+ */
+ virtual QStringList allDistributionListNames() const;
+
+ /**
@internal
Sets the address book of the resource.
@@ -468,6 +512,11 @@
*/
Addressee::Map mAddrMap;
+ /**
+ A mapping from unique identifiers to the respective distribution list.
+ */
+ DistributionListMap mDistListMap;
+
private:
class Private;
Private *const d;
Index: distributionlist.cpp
===================================================================
--- distributionlist.cpp (Revision 714883)
+++ distributionlist.cpp (Arbeitskopie)
@@ -19,8 +19,10 @@
*/
#include "distributionlist.h"
+#include "resource.h"
#include <kconfig.h>
+#include <krandom.h>
#include <kstandarddirs.h>
#include <kdebug.h>
@@ -67,12 +69,12 @@
return *this;
}
-Addressee &DistributionList::Entry::addressee() const
+Addressee DistributionList::Entry::addressee() const
{
return d->addressee;
}
-QString &DistributionList::Entry::email() const
+QString DistributionList::Entry::email() const
{
return d->email;
}
@@ -80,29 +82,47 @@
class DistributionList::Private
{
public:
- Private( DistributionListManager *manager, const QString &name )
- : mManager( manager ), mName( name )
+ Private( Resource *resource, const QString &identifier,
+ const QString &name )
+ : mResource( resource ), mIdentifier( identifier ), mName( name )
{
}
- DistributionListManager *mManager;
+ Resource *mResource;
+ QString mIdentifier;
QString mName;
Entry::List mEntries;
};
-DistributionList::DistributionList( DistributionListManager *manager, const QString \
&name )
- : d( new Private( manager, name ) )
+DistributionList::DistributionList( Resource *resource, const QString &name )
+ : d( new Private( resource, KRandom::randomString(10), name ) )
{
- d->mManager->insert( this );
+ d->mResource->insertDistributionList( this );
}
+DistributionList::DistributionList( Resource *resource, const QString &identifier, \
const QString &name ) + : d( new Private( resource, identifier, name ) )
+{
+ d->mResource->insertDistributionList( this );
+}
+
DistributionList::~DistributionList()
{
- d->mManager->remove( this );
+ d->mResource->removeDistributionList( this );
delete d;
}
+void DistributionList::setIdentifier( const QString &identifier )
+{
+ d->mIdentifier = identifier;
+}
+
+QString DistributionList::identifier() const
+{
+ return d->mIdentifier;
+}
+
void DistributionList::setName( const QString &name )
{
d->mName = name;
@@ -169,8 +189,14 @@
return d->mEntries;
}
+Resource* DistributionList::resource() const
+{
+ return d->mResource;
+}
+
typedef QList< QPair<QString, QString> > MissingEntryList;
+#if 0
class DistributionListManager::Private
{
public:
@@ -288,7 +314,8 @@
kDebug(5700) << "DLM::load():" << name << ":" << value.join( "," );
- DistributionList *list = new DistributionList( this, name );
+ // FIXME new distribution list handling
+ DistributionList *list = 0;//new DistributionList( this, name );
MissingEntryList missingEntries;
QStringList::ConstIterator entryIt = value.constBegin();
@@ -354,7 +381,7 @@
return true;
}
-
+#endif
class DistributionListWatcher::Private
{
public:
Index: resource.cpp
===================================================================
--- resource.cpp (Revision 714883)
+++ resource.cpp (Arbeitskopie)
@@ -226,6 +226,7 @@
Resource::~Resource()
{
delete d;
+ qDeleteAll( mDistListMap );
}
Resource::Iterator Resource::begin()
@@ -348,8 +349,85 @@
void Resource::clear()
{
mAddrMap.clear();
+
+ qDeleteAll( mDistListMap );
}
+void Resource::insertDistributionList( DistributionList *list )
+{
+ Q_ASSERT( list );
+
+ mDistListMap.insert( list->identifier(), list );
+}
+
+void Resource::removeDistributionList( DistributionList *list )
+{
+ Q_ASSERT( list );
+
+ DistributionListMap::iterator it = mDistListMap.find( list->identifier() );
+ if ( it != mDistListMap.end() ) {
+ if ( it.value() == list ) {
+ mDistListMap.erase( it );
+ }
+ }
+}
+
+DistributionList* Resource::findDistributionListByIdentifier( const QString& \
identifier ) +{
+ DistributionListMap::const_iterator it = mDistListMap.find( identifier );
+ if ( it != mDistListMap.end() )
+ return it.value();
+
+ return 0;
+}
+
+DistributionList* Resource::findDistributionListByName( const QString &name, \
Qt::CaseSensitivity caseSensitivity ) +{
+ QString searchName = name;
+ if ( caseSensitivity == Qt::CaseInsensitive )
+ searchName = name.toLower();
+
+ DistributionListMap::const_iterator it = mDistListMap.begin();
+ DistributionListMap::const_iterator endIt = mDistListMap.end();
+ for ( ; it != endIt; ++it ) {
+ if ( caseSensitivity == Qt::CaseSensitive ) {
+ if ( searchName == it.key() )
+ return it.value();
+ } else {
+ if ( searchName == it.key().toLower() )
+ return it.value();
+ }
+ }
+
+ return 0;
+}
+
+QList<DistributionList*> Resource::allDistributionLists()
+{
+ QList<DistributionList*> results;
+
+ DistributionListMap::const_iterator it = mDistListMap.begin();
+ DistributionListMap::const_iterator endIt = mDistListMap.end();
+ for ( ; it != endIt; ++it ) {
+ results += it.value();
+ }
+
+ return results;
+}
+
+QStringList Resource::allDistributionListNames() const
+{
+ QStringList results;
+
+ DistributionListMap::const_iterator it = mDistListMap.begin();
+ DistributionListMap::const_iterator endIt = mDistListMap.end();
+ for ( ; it != endIt; ++it ) {
+ results += it.value()->name();
+ }
+
+ return results;
+}
+
bool Resource::asyncLoad()
{
bool ok = load();
["kmail.diff" (text/x-diff)]
Index: recipientspicker.h
===================================================================
--- recipientspicker.h (Revision 714893)
+++ recipientspicker.h (Arbeitskopie)
@@ -43,7 +43,6 @@
#else
namespace KABC {
class DistributionList;
-class DistributionListManager;
}
#endif
@@ -216,10 +215,6 @@
RecipientsCollection *mAllRecipients;
RecipientsCollection *mSelectedRecipients;
-#ifndef KDEPIM_NEW_DISTRLISTS
- KABC::DistributionListManager *mDistributionListManager;
-#endif
-
Recipient::Type mDefaultType;
};
Index: recipientspicker.cpp
===================================================================
--- recipientspicker.cpp (Revision 714893)
+++ recipientspicker.cpp (Arbeitskopie)
@@ -303,9 +303,6 @@
RecipientsPicker::RecipientsPicker( QWidget *parent )
: QDialog( parent )
-#ifndef KDEPIM_NEW_DISTRLISTS
- , mDistributionListManager( 0 )
-#endif
{
setObjectName("RecipientsPicker");
setWindowTitle( i18n("Select Recipient") );
@@ -407,10 +404,6 @@
{
writeConfig();
-#ifndef KDEPIM_NEW_DISTRLISTS
- delete mDistributionListManager;
-#endif
-
mAllRecipients->deleteAll();
QMap<int,RecipientsCollection *>::ConstIterator it;
@@ -514,17 +507,8 @@
collection->addItem( item );
}
#else
- delete mDistributionListManager;
- mDistributionListManager =
- new KABC::DistributionListManager( KABC::StdAddressBook::self( true ) );
-
- mDistributionListManager->load();
-
- QStringList lists = mDistributionListManager->listNames();
-
- QStringList::Iterator listIt;
- for ( listIt = lists.begin(); listIt != lists.end(); ++listIt ) {
- KABC::DistributionList *list = mDistributionListManager->list( *listIt );
+ QList<KABC::DistributionList*> lists = mAddressBook->allDistributionLists();
+ foreach ( KABC::DistributionList *list, lists ) {
RecipientItem *item = new RecipientItem;
item->setDistributionList( list );
mAllRecipients->addItem( item );
Index: distributionlistdialog.cpp
===================================================================
--- distributionlistdialog.cpp (Revision 714893)
+++ distributionlistdialog.cpp (Arbeitskopie)
@@ -185,11 +185,6 @@
return;
}
-#ifndef KDEPIM_NEW_DISTRLISTS
- KABC::DistributionListManager manager( ab );
- manager.load();
-#endif
-
QString name = mTitleEdit->text();
if ( name.isEmpty() ) {
@@ -203,7 +198,7 @@
#ifdef KDEPIM_NEW_DISTRLISTS
if ( !KPIM::DistributionList::findByName( ab, name ).isEmpty() ) {
#else
- if ( manager.list( name ) ) {
+ if ( ab->findDistributionListByName( name ) ) {
#endif
KMessageBox::information( this,
i18n( "<qt>Distribution list with the given name <b>%1</b> "
@@ -233,7 +228,7 @@
ab->insertAddressee( dlist );
#else
- KABC::DistributionList *dlist = new KABC::DistributionList( &manager, name );
+ KABC::DistributionList *dlist = ab->createDistributionList( name );
for (int i = 0; i < mRecipientsList->topLevelItemCount(); ++i) {
DistributionListItem *item = static_cast<DistributionListItem *>(
@@ -264,8 +259,5 @@
if ( saveError )
kWarning(5006) <<" Couldn't save new addresses in the distribution list just \
created to the address book";
-#ifndef KDEPIM_NEW_DISTRLISTS
- manager.save();
-#endif
close();
}
Index: folderdialogacltab.cpp
===================================================================
--- folderdialogacltab.cpp (Revision 714893)
+++ folderdialogacltab.cpp (Arbeitskopie)
@@ -199,11 +199,7 @@
void load( const ACLListEntry& entry );
void save( ACLList& list,
-#ifdef KDEPIM_NEW_DISTRLISTS
KABC::AddressBook* abook,
-#else
- KABC::DistributionListManager& manager,
-#endif
IMAPUserIdFormat userIdFormat );
QString userId() const { return text( 0 ); }
@@ -265,11 +261,7 @@
}
void KMail::FolderDialogACLTab::ListViewItem::save( ACLList& aclList,
-#ifdef KDEPIM_NEW_DISTRLISTS
KABC::AddressBook* addressBook,
-#else
- KABC::DistributionListManager& \
manager,
-#endif
IMAPUserIdFormat userIdFormat )
{
// expand distribution lists
@@ -288,8 +280,7 @@
aclList.append( entry );
}
#else
- // kaddrbook.cpp has a strange two-pass case-insensitive lookup; is it ok to be \
case sensitive?
- KABC::DistributionList* list = manager.list( userId() );
+ KABC::DistributionList* list = addressBook->findDistributionListByName( userId(), \
Qt::CaseInsensitive ); if ( list ) {
Q_ASSERT( mModified ); // it has to be new, it couldn't be stored as a distr \
list name.... KABC::DistributionList::Entry::List entryList = list->entries();
@@ -671,19 +662,11 @@
// listviewitems at the same time sounds dangerous, so let's just save into
// ACLList and reload that.
KABC::AddressBook *addressBook = KABC::StdAddressBook::self( true );
-#ifndef KDEPIM_NEW_DISTRLISTS
- KABC::DistributionListManager manager( addressBook );
- manager.load();
-#endif
ACLList aclList;
for ( Q3ListViewItem* item = mListView->firstChild(); item; item = \
item->nextSibling() ) { ListViewItem* ACLitem = static_cast<ListViewItem *>( item );
ACLitem->save( aclList,
-#ifdef KDEPIM_NEW_DISTRLISTS
addressBook,
-#else
- manager,
-#endif
mUserIdFormat );
}
loadListView( aclList );
Index: kmaddrbook.cpp
===================================================================
--- kmaddrbook.cpp (Revision 714893)
+++ kmaddrbook.cpp (Arbeitskopie)
@@ -26,7 +26,6 @@
#include <klocale.h>
#include <kmessagebox.h>
#include <kabc/stdaddressbook.h>
-#include <kabc/distributionlist.h>
#include <kabc/vcardconverter.h>
#include <QRegExp>
@@ -74,10 +73,9 @@
}
}
}
- KABC::DistributionListManager manager( addressBook );
- manager.load();
- result += manager.listNames();
+ result += addressBook->allDistributionListNames();
+
result.sort();
}
["libkdepim.diff" (text/x-diff)]
Index: kaddrbookexternal.cpp
===================================================================
--- kaddrbookexternal.cpp (Revision 714893)
+++ kaddrbookexternal.cpp (Arbeitskopie)
@@ -221,15 +221,10 @@
return distrList.emails( addressBook ).join( ", " );
}
#else
- KABC::DistributionListManager manager( addressBook );
- manager.load();
- const QStringList listNames = manager.listNames();
+ KABC::DistributionList* list = addressBook->findDistributionListByName( listName, \
Qt::CaseInsensitive );
- for ( QStringList::ConstIterator it = listNames.begin(); it != listNames.end(); \
++it ) {
- if ( (*it).toLower() == lowerListName ) {
- const QStringList addressList = manager.list( *it )->emails();
- return addressList.join( ", " );
- }
+ if ( list ) {
+ return list->emails().join( ", " );
}
#endif
return QString();
Index: addressesdialog.cpp
===================================================================
--- addressesdialog.cpp (Revision 714893)
+++ addressesdialog.cpp (Arbeitskopie)
@@ -32,6 +32,8 @@
#include <kabc/resource.h>
#else
#include <kabc/distributionlist.h>
+#include <kabc/resource.h>
+#include <kresources/selectdialog.h>
#endif
#include <kabc/stdaddressbook.h>
@@ -403,10 +405,12 @@
}
}
#else
- KABC::DistributionListManager manager( abook );
- manager.load();
for ( QStringList::ConstIterator it = dList.begin(); it != dList.end(); ++it ) {
- const QList<KABC::DistributionList::Entry> eList = manager.list( *it \
)->entries(); + KABC::DistributionList *list = abook->findDistributionListByName( \
*it ); + if ( !list )
+ continue;
+
+ const QList<KABC::DistributionList::Entry> eList = list->entries();
QList<KABC::DistributionList::Entry>::ConstIterator eit;
for( eit = eList.begin(); eit != eList.end(); ++eit ) {
KABC::Addressee a = (*eit).addressee();
@@ -844,7 +848,9 @@
d->ui->mSaveAs->setEnabled(d->ui->mSelectedView->firstChild() != 0);
}
-#ifdef KDEPIM_NEW_DISTRLISTS
+// FIXME new distribution list handling
+// should probably be moved as suggested in the comment below
+//#ifdef KDEPIM_NEW_DISTRLISTS
// copied from kabcore.cpp :(
// KDE4: should be in libkabc I think
@@ -865,16 +871,11 @@
KRES::Resource *res = KRES::SelectDialog::getResource( kresResources, parent );
return static_cast<KABC::Resource*>( res );
}
-#endif
+//#endif
void
AddressesDialog::saveAs()
{
-#ifndef KDEPIM_NEW_DISTRLISTS
- KABC::DistributionListManager manager( KABC::StdAddressBook::self( true ) );
- manager.load();
-#endif
-
if ( !d->ui->mSelectedView->firstChild() ) {
KMessageBox::information( 0,
i18n("There are no addresses in your list. "
@@ -897,7 +898,8 @@
KPIM::DistributionList dlist = KPIM::DistributionList::findByName( abook, name );
alreadyExists = !dlist.isEmpty();
#else
- alreadyExists = manager.list( name );
+ KABC::AddressBook* abook = KABC::StdAddressBook::self( true );
+ alreadyExists = abook->findDistributionListByName( name ) != 0;
#endif
if ( alreadyExists ) {
@@ -922,14 +924,16 @@
}
abook->insertAddressee( dlist );
#else
- KABC::DistributionList *dlist = new KABC::DistributionList( &manager, name );
+ KABC::Resource *resource = requestResource( abook, this );
+ if ( !resource )
+ return;
+
+ KABC::DistributionList *dlist = abook->createDistributionList( name, resource );
KABC::Addressee::List addrl = allAddressee( d->ui->mSelectedView, false );
for ( KABC::Addressee::List::iterator itr = addrl.begin();
itr != addrl.end(); ++itr ) {
dlist->insertEntry( *itr );
}
-
- manager.save();
#endif
}
@@ -1044,10 +1048,7 @@
const QList<KPIM::DistributionList> distLists =
KPIM::DistributionList::allDistributionLists( abook );
#else
- KABC::DistributionListManager manager( abook );
- manager.load();
-
- QStringList distLists = manager.listNames();
+ const QList<KABC::DistributionList*> distLists = abook->allDistributionLists();
#endif
if ( distLists.isEmpty() )
@@ -1059,14 +1060,14 @@
#ifdef KDEPIM_NEW_DISTRLISTS
QList<KPIM::DistributionList>::ConstIterator listIt;
#else
- QStringList::Iterator listIt;
+ QList<KABC::DistributionList*>::ConstIterator listIt;
#endif
for ( listIt = distLists.begin(); listIt != distLists.end(); ++listIt ) {
#ifdef KDEPIM_NEW_DISTRLISTS
KPIM::DistributionList dlist = *listIt;
KPIM::DistributionList::Entry::List entries = dlist.entries(abook);
#else
- KABC::DistributionList& dlist = *manager.list( *listIt );
+ KABC::DistributionList& dlist = *( *listIt );
KABC::DistributionList::Entry::List entries = dlist.entries();
#endif
Index: addresseeselector.cpp
===================================================================
--- addresseeselector.cpp (Revision 714893)
+++ addresseeselector.cpp (Arbeitskopie)
@@ -229,7 +229,7 @@
};
AddresseeSelector::AddresseeSelector( Selection *selection, QWidget *parent, const \
char *name )
- : QWidget( parent ), mSelection( selection ), mManager( 0 )
+ : QWidget( parent ), mSelection( selection )
{
setObjectName(name);
mMoveMapper = new QSignalMapper( this );
@@ -246,9 +246,6 @@
AddresseeSelector::~AddresseeSelector()
{
- delete mManager;
- mManager = 0;
-
delete mAddressBookManager;
mAddressBookManager = 0;
}
@@ -474,8 +471,10 @@
void AddresseeSelector::reloadAddressBook()
{
+ KABC::AddressBook* addressBook = KABC::StdAddressBook::self( true );
+
// load contacts
- KABC::Addressee::List list = KABC::StdAddressBook::self( true )->allAddressees();
+ KABC::Addressee::List list = addressBook->allAddressees();
KABC::Addressee::List::Iterator it;
SelectionItem::List selectedItems;
@@ -518,16 +517,8 @@
}
// load distribution lists
- delete mManager;
- mManager = new KABC::DistributionListManager( KABC::StdAddressBook::self( true ) \
);
-
- mManager->load();
-
- QStringList lists = mManager->listNames();
-
- QStringList::Iterator listIt;
- for ( listIt = lists.begin(); listIt != lists.end(); ++listIt ) {
- KABC::DistributionList *list = mManager->list( *listIt );
+ QList<KABC::DistributionList*> lists = addressBook->allDistributionLists();
+ foreach ( KABC::DistributionList *list, lists ) {
SelectionItem item( list, 0 );
mSelectionItems.append( item );
}
@@ -537,7 +528,7 @@
// update address book combo
mAddressBookCombo->clear();
- QList<KABC::Resource*> resources = KABC::StdAddressBook::self( true \
)->resources(); + QList<KABC::Resource*> resources = addressBook->resources();
QListIterator<KABC::Resource*> resIt( resources );
while ( resIt.hasNext() ) {
KABC::Resource *res = resIt.next();
Index: addresseelineedit.cpp
===================================================================
--- addresseelineedit.cpp (Revision 714893)
+++ addresseelineedit.cpp (Arbeitskopie)
@@ -34,7 +34,6 @@
#ifdef KDEPIM_NEW_DISTRLISTS
#include "distributionlist.h"
#else
-#include <kabc/distributionlist.h>
#endif
#include <kabc/stdaddressbook.h>
@@ -544,9 +543,9 @@
#ifndef KDEPIM_NEW_DISTRLISTS // new distr lists are normal contact, already done \
above int weight = config.readEntry( "DistributionLists", 60 );
- KABC::DistributionListManager manager( addressBook );
- manager.load();
- const QStringList distLists = manager.listNames();
+
+ const QStringList distLists = addressBook->allDistributionListNames();
+
QStringList::const_iterator listIt;
int idx = addCompletionSource( i18n( "Distribution Lists" ) );
for ( listIt = distLists.begin(); listIt != distLists.end(); ++listIt ) {
Index: addresseeselector.h
===================================================================
--- addresseeselector.h (Revision 714893)
+++ addresseeselector.h (Arbeitskopie)
@@ -206,8 +206,6 @@
QSignalMapper *mMoveMapper;
QSignalMapper *mRemoveMapper;
- KABC::DistributionListManager *mManager;
-
class AddressBookManager;
AddressBookManager *mAddressBookManager;
};
["kaddressbook.diff" (text/x-diff)]
Index: features/distributionlistwidget.cpp
===================================================================
--- features/distributionlistwidget.cpp (Revision 714893)
+++ features/distributionlistwidget.cpp (Arbeitskopie)
@@ -151,9 +151,6 @@
DistributionListWidget::DistributionListWidget( KAB::Core *core, QWidget *parent )
: KAB::ExtensionWidget( core, parent )
-#ifndef KDEPIM_NEW_DISTRLISTS
- , mManager( 0 )
-#endif
{
QGridLayout *topLayout = new QGridLayout( this );
topLayout->setSpacing( KDialog::spacingHint() );
@@ -202,17 +199,10 @@
topLayout->addWidget( mRemoveContactButton, 2, 3 );
connect( mRemoveContactButton, SIGNAL( clicked() ), SLOT( removeContact() ) );
-#ifdef KDEPIM_NEW_DISTRLISTS
// When contacts are changed, update both distr list combo and contents of \
displayed distr list connect( core, SIGNAL( contactsUpdated() ),
this, SLOT( updateNameCombo() ) );
-#else
- mManager = new KABC::DistributionListManager( core->addressBook() );
- connect( KABC::DistributionListWatcher::self(), SIGNAL( changed() ),
- this, SLOT( updateNameCombo() ) );
-#endif
-
connect( core->addressBook(), SIGNAL( addressBookChanged( AddressBook* ) ),
this, SLOT( updateNameCombo() ) );
@@ -227,15 +217,14 @@
DistributionListWidget::~DistributionListWidget()
{
-#ifndef KDEPIM_NEW_DISTRLISTS
- delete mManager;
-#endif
}
void DistributionListWidget::save()
{
#ifndef KDEPIM_NEW_DISTRLISTS
- mManager->save();
+ // FIXME new distribution list handling
+ // explicit save necessary?
+ //mManager->save();
#endif
}
@@ -254,7 +243,7 @@
#ifdef KDEPIM_NEW_DISTRLISTS
return core()->distributionListNames().contains( distrListName );
#else
- return mManager->listNames().contains( distrListName );
+ return core()->addressBook()->findDistributionListByName( distrListName ) != 0;
#endif
}
@@ -284,7 +273,11 @@
core()->addressBook()->insertAddressee( dist );
#else
- new KABC::DistributionList( mManager, newName );
+ KABC::Resource* resource = core()->requestResource( this );
+ if ( !resource )
+ return;
+
+ core()->addressBook()->createDistributionList( newName, resource );
changed();
updateNameCombo();
@@ -321,10 +314,11 @@
changed( dist );
#else
- KABC::DistributionList *list = mManager->list( oldName );
- list->setName( newName );
- mManager->save();
- updateNameCombo();
+ KABC::DistributionList *list = core()->addressBook()->findDistributionListByName( \
oldName ); + if ( list ) {
+ list->setName( newName );
+ updateNameCombo();
+ }
#endif
// Select the new name in the list (updateNameCombo couldn't know we wanted that \
one) @@ -351,12 +345,15 @@
emit deleted( QStringList( dist.uid() ) );
core()->addressBook()->removeAddressee( dist );
#else
- mManager->remove( mManager->list( mNameCombo->currentText() ) );
- mNameCombo->removeItem( mNameCombo->currentIndex() );
+ KABC::DistributionList* list = core()->addressBook()->findDistributionListByName( \
mNameCombo->currentText() ); + if ( list ) {
+ core()->addressBook()->removeDistributionList( list );
+ mNameCombo->removeItem( mNameCombo->currentIndex() );
- updateContactView();
+ updateContactView();
- changed();
+ changed();
+ }
#endif
}
@@ -370,7 +367,7 @@
return;
}
#else
- KABC::DistributionList *list = mManager->list( mNameCombo->currentText() );
+ KABC::DistributionList *list = core()->addressBook()->findDistributionListByName( \
mNameCombo->currentText() ); if ( !list )
return;
KABC::DistributionList& dist = *list;
@@ -398,7 +395,7 @@
if ( dist.isEmpty() ) // not found
return;
#else
- KABC::DistributionList *list = mManager->list( mNameCombo->currentText() );
+ KABC::DistributionList *list = core()->addressBook()->findDistributionListByName( \
mNameCombo->currentText() ); if ( !list )
return;
KABC::DistributionList& dist = *list;
@@ -428,7 +425,7 @@
if ( dist.isEmpty() ) // not found
return;
#else
- KABC::DistributionList *list = mManager->list( mNameCombo->currentText() );
+ KABC::DistributionList *list = core()->addressBook()->findDistributionListByName( \
mNameCombo->currentText() ); if ( !list )
return;
KABC::DistributionList& dist = *list;
@@ -468,7 +465,7 @@
core()->addressBook(), mNameCombo->currentText() );
isListSelected = !dist.isEmpty();
#else
- KABC::DistributionList *list = mManager->list( mNameCombo->currentText() );
+ KABC::DistributionList *list = core()->addressBook()->findDistributionListByName( \
mNameCombo->currentText() ); isListSelected = list != 0;
#endif
if ( !isListSelected ) {
@@ -510,8 +507,7 @@
#ifdef KDEPIM_NEW_DISTRLISTS
const QStringList names = core()->distributionListNames();
#else
- mManager->load();
- const QStringList names = mManager->listNames();
+ const QStringList names = core()->addressBook()->allDistributionListNames();
#endif
mNameCombo->addItems( names );
mNameCombo->setCurrentIndex( qMin( pos, (int)names.count() - 1 ) );
@@ -530,7 +526,7 @@
if ( dist.isEmpty() )
return;
#else
- KABC::DistributionList *list = mManager->list( mNameCombo->currentText() );
+ KABC::DistributionList *list = core()->addressBook()->findDistributionListByName( \
mNameCombo->currentText() ); if ( !list )
return;
KABC::DistributionList& dist = *list;
Index: features/distributionlistwidget.h
===================================================================
--- features/distributionlistwidget.h (Revision 714893)
+++ features/distributionlistwidget.h (Arbeitskopie)
@@ -46,7 +46,6 @@
namespace KABC {
class AddressBook;
-class DistributionListManager;
}
class DistributionListWidget : public KAB::ExtensionWidget
@@ -94,9 +93,6 @@
QLabel *mEntryCountLabel;
DistributionListView *mContactView;
-#ifndef KDEPIM_NEW_DISTRLISTS
- KABC::DistributionListManager *mManager;
-#endif
QPushButton *mCreateListButton;
QPushButton *mEditListButton;
QPushButton *mRemoveListButton;
["signature.asc" (application/pgp-signature)]
_______________________________________________
KDE PIM mailing list kde-pim@kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic