diff --git a/kabc/CMakeLists.txt b/kabc/CMakeLists.txt index 361c1ffbd..1475c4865 100644 --- a/kabc/CMakeLists.txt +++ b/kabc/CMakeLists.txt @@ -1,136 +1,132 @@ project(kabc) include_directories( ${KDE4_KIO_INCLUDES} ) add_definitions(${QDBUS_DEFINITIONS} -DKDE_DEFAULT_DEBUG_AREA=5700 ) # these apply also for all subdirs include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/kab ${CMAKE_CURRENT_BINARY_DIR}/kab ${CMAKE_CURRENT_SOURCE_DIR}/vcardparser ) # kabc/vcardparser/Makefile.am: vcards set(vcards_STAT_SRCS vcardparser/vcard.cpp vcardparser/vcardline.cpp vcardparser/vcardparser.cpp ) add_subdirectory( vcardparser ) add_subdirectory( formats ) add_subdirectory( plugins ) add_subdirectory( tests ) #add_subdirectory( scripts ) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/scripts) add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/field.cpp ${CMAKE_CURRENT_BINARY_DIR}/addressee.h ${CMAKE_CURRENT_BINARY_DIR}/addressee.cpp WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/scripts COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/makeaddressee DEPENDS scripts/makeaddressee scripts/addressee.src.cpp scripts/addressee.src.h scripts/entrylist scripts/field.src.cpp ) ########### next target ############### set(kabc_LIB_SRCS address.cpp addressbook.cpp ${CMAKE_CURRENT_BINARY_DIR}/addressee.cpp ${CMAKE_CURRENT_BINARY_DIR}/addressee.h ${CMAKE_CURRENT_BINARY_DIR}/field.cpp addresseedialog.cpp distributionlist.cpp distributionlistdialog.cpp emailselectdialog.cpp errorhandler.cpp formatfactory.cpp geo.cpp key.cpp phonenumber.cpp picture.cpp plugin.cpp resource.cpp resourceabc.cpp resourcecached.cpp secrecy.cpp sound.cpp stdaddressbook.cpp vcardconverter.cpp timezone.cpp vcardformat.cpp ldifconverter.cpp addresslineedit.cpp addresseelist.cpp vcardtool.cpp addresseehelper.cpp lock.cpp locknull.cpp sortmode.cpp ${vcards_STAT_SRCS} - contactgroup.cpp - contactgrouptool.cpp ) kde4_add_library(kabc SHARED ${kabc_LIB_SRCS}) target_link_libraries(kabc kresources kldap ${KDE4_KDEUI_LIBS} ${KDE4_KDECORE_LIBS}) target_link_libraries(kabc LINK_INTERFACE_LIBRARIES kresources ${KDE4_KDEUI_LIBS}) set_target_properties(kabc PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} ) install(TARGETS kabc EXPORT kdepimlibsLibraryTargets ${INSTALL_TARGETS_DEFAULT_ARGS}) ########### install files ############### install( FILES countrytransl.map DESTINATION ${DATA_INSTALL_DIR}/kabc ) install( FILES kabc_manager.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kresources ) install( FILES kabc_export.h address.h addressbook.h ${CMAKE_CURRENT_BINARY_DIR}/addressee.h addresseelist.h addresseedialog.h addresslineedit.h - contactgroup.h - contactgrouptool.h distributionlist.h distributionlistdialog.h emailselectdialog.h errorhandler.h field.h format.h formatfactory.h geo.h key.h ldifconverter.h lock.h locknull.h phonenumber.h picture.h plugin.h resource.h resourceabc.h resourcecached.h secrecy.h sortmode.h sound.h stdaddressbook.h timezone.h vcardformat.h vcardconverter.h DESTINATION ${INCLUDE_INSTALL_DIR}/kabc COMPONENT Devel) diff --git a/kabc/contactgroup.cpp b/kabc/contactgroup.cpp deleted file mode 100644 index 2740f17d2..000000000 --- a/kabc/contactgroup.cpp +++ /dev/null @@ -1,363 +0,0 @@ -/* - This file is part of libkabc. - Copyright (c) 2008 Tobias Koenig - - 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. -*/ - -#include "contactgroup.h" - -#include -#include -#include -#include - -using namespace KABC; - -class ContactGroup::Reference::ReferencePrivate : public QSharedData -{ - public: - ReferencePrivate() - : QSharedData() - { - } - - ReferencePrivate( const ReferencePrivate &other ) - : QSharedData( other ) - { - mUid = other.mUid; - mPreferredEmail = other.mPreferredEmail; - mCustoms = other.mCustoms; - } - - QString mUid; - QString mPreferredEmail; - QMap mCustoms; -}; - -ContactGroup::Reference::Reference() - : d( new ReferencePrivate ) -{ -} - -ContactGroup::Reference::Reference( const Reference &other ) - : d( other.d ) -{ -} - -ContactGroup::Reference::Reference( const QString &uid ) - : d( new ReferencePrivate ) -{ - d->mUid = uid; -} - -ContactGroup::Reference::~Reference() -{ -} - -void ContactGroup::Reference::setUid( const QString &uid ) -{ - d->mUid = uid; -} - -QString ContactGroup::Reference::uid() const -{ - return d->mUid; -} - -void ContactGroup::Reference::setPreferredEmail( const QString &email ) -{ - d->mPreferredEmail = email; -} - -QString ContactGroup::Reference::preferredEmail() const -{ - return d->mPreferredEmail; -} - -void ContactGroup::Reference::insertCustom( const QString &key, const QString &value ) -{ - d->mCustoms.insert( key, value ); -} - -void ContactGroup::Reference::removeCustom( const QString &key ) -{ - d->mCustoms.remove( key ); -} - -QString ContactGroup::Reference::custom( const QString &key ) const -{ - return d->mCustoms.value( key ); -} - -ContactGroup::Reference &ContactGroup::Reference::operator=( const ContactGroup::Reference &other ) -{ - if ( this != &other ) { - d = other.d; - } - - return *this; -} - -bool ContactGroup::Reference::operator==( const Reference &other ) const -{ - return d->mUid == other.d->mUid && - d->mPreferredEmail == other.d->mPreferredEmail && - d->mCustoms == other.d->mCustoms; -} - -class ContactGroup::Data::DataPrivate : public QSharedData -{ - public: - DataPrivate() - : QSharedData() - { - } - - DataPrivate( const DataPrivate &other ) - : QSharedData( other ) - { - mName = other.mName; - mEmail = other.mEmail; - mCustoms = other.mCustoms; - } - - QString mName; - QString mEmail; - QMap mCustoms; -}; - -ContactGroup::Data::Data() - : d( new DataPrivate ) -{ -} - -ContactGroup::Data::Data( const Data &other ) - : d( other.d ) -{ -} - -ContactGroup::Data::Data( const QString &name, const QString &email ) - : d( new DataPrivate ) -{ - d->mName = name; - d->mEmail = email; -} - -ContactGroup::Data::~Data() -{ -} - -void ContactGroup::Data::setName( const QString &name ) -{ - d->mName = name; -} - -QString ContactGroup::Data::name() const -{ - return d->mName; -} - -void ContactGroup::Data::setEmail( const QString &email ) -{ - d->mEmail = email; -} - -QString ContactGroup::Data::email() const -{ - return d->mEmail; -} - -void ContactGroup::Data::insertCustom( const QString &key, const QString &value ) -{ - d->mCustoms.insert( key, value ); -} - -void ContactGroup::Data::removeCustom( const QString &key ) -{ - d->mCustoms.remove( key ); -} - -QString ContactGroup::Data::custom( const QString &key ) const -{ - return d->mCustoms.value( key ); -} - -ContactGroup::Data &ContactGroup::Data::operator=( const ContactGroup::Data &other ) -{ - if ( this != &other ) { - d = other.d; - } - - return *this; -} - -bool ContactGroup::Data::operator==( const Data &other ) const -{ - return d->mName == other.d->mName && - d->mEmail == other.d->mEmail && - d->mCustoms == other.d->mCustoms; -} - -class ContactGroup::Private : public QSharedData -{ - public: - Private() - : QSharedData(), - mIdentifier( QUuid::createUuid().toString() ) - { - } - - Private( const Private &other ) - : QSharedData( other ) - { - mIdentifier = other.mIdentifier; - mName = other.mName; - mReferences = other.mReferences; - mDataObjects = other.mDataObjects; - } - - QString mIdentifier; - QString mName; - ContactGroup::Reference::List mReferences; - ContactGroup::Data::List mDataObjects; -}; - -ContactGroup::ContactGroup() - : d( new Private ) -{ -} - -ContactGroup::ContactGroup( const ContactGroup &other ) - : d( other.d ) -{ -} - -ContactGroup::ContactGroup( const QString &name ) - : d( new Private ) -{ - d->mName = name; -} - -ContactGroup::~ContactGroup() -{ -} - -void ContactGroup::setName( const QString &name ) -{ - d->mName = name; -} - -QString ContactGroup::name() const -{ - return d->mName; -} - -void ContactGroup::setId( const QString &id ) -{ - d->mIdentifier = id; -} - -QString ContactGroup::id() const -{ - return d->mIdentifier; -} - -unsigned int ContactGroup::count() const -{ - return d->mReferences.count() + d->mDataObjects.count(); -} - -unsigned int ContactGroup::referencesCount() const -{ - return d->mReferences.count(); -} - -unsigned int ContactGroup::dataCount() const -{ - return d->mDataObjects.count(); -} - -ContactGroup::Reference &ContactGroup::reference( unsigned int index ) -{ - Q_ASSERT_X( index < d->mReferences.count(), "reference()", "index out of range" ); - - return d->mReferences[ index ]; -} - -const ContactGroup::Reference &ContactGroup::reference( unsigned int index ) const -{ - Q_ASSERT_X( index < d->mReferences.count(), "reference()", "index out of range" ); - - return d->mReferences[ index ]; -} - -ContactGroup::Data &ContactGroup::data( unsigned int index ) -{ - Q_ASSERT_X( index < d->mDataObjects.count(), "data()", "index out of range" ); - - return d->mDataObjects[ index ]; -} - -const ContactGroup::Data &ContactGroup::data( unsigned int index ) const -{ - Q_ASSERT_X( index < d->mDataObjects.count(), "data()", "index out of range" ); - - return d->mDataObjects[ index ]; -} - -void ContactGroup::append( const Reference &reference ) -{ - d->mReferences.append( reference ); -} - -void ContactGroup::append( const Data &data ) -{ - d->mDataObjects.append( data ); -} - -void ContactGroup::remove( const Reference &reference ) -{ - d->mReferences.removeOne( reference ); -} - -void ContactGroup::remove( const Data &data ) -{ - d->mDataObjects.removeOne( data ); -} - -ContactGroup &ContactGroup::operator=( const ContactGroup &other ) -{ - if ( this != &other ) { - d = other.d; - } - - return *this; -} - -bool ContactGroup::operator==( const ContactGroup &other ) const -{ - return d->mIdentifier == other.d->mIdentifier && - d->mName == other.d->mName && - d->mReferences == other.d->mReferences && - d->mDataObjects == other.d->mDataObjects; -} - -QString ContactGroup::mimeType() -{ - return QLatin1String( "application/x-vnd.kde.contactgroup" ); -} diff --git a/kabc/contactgroup.h b/kabc/contactgroup.h deleted file mode 100644 index e6bfba6e1..000000000 --- a/kabc/contactgroup.h +++ /dev/null @@ -1,346 +0,0 @@ -/* - This file is part of libkabc. - Copyright (c) 2008 Tobias Koenig - - 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. -*/ - -#ifndef KABC_CONTACTGROUP_H -#define KABC_CONTACTGROUP_H - -#include -#include - -#include "kabc_export.h" - -class QString; - -namespace KABC { - -/** - * This class represents a group of contacts. - * - * It can contain two types of contacts, either a reference - * or data. - * The reference entry is just an unique identifier which - * identifies the real contact in the system. - * The data entry contains a name and an email address. - * - * @since 4.2 - */ -class KABC_EXPORT ContactGroup -{ - public: - - /** - * This class represents a contact reference - */ - class KABC_EXPORT Reference - { - public: - /** - * A list of contact references. - */ - typedef QList List; - - /** - * Creates an empty contact reference. - */ - Reference(); - - /** - * Creates a contact reference from an @p other reference. - */ - Reference( const Reference &other ); - - /** - * Creates a contact reference for the given contact @p uid. - */ - Reference( const QString &uid ); - - /** - * Destroys the contact reference. - */ - ~Reference(); - - /** - * Sets the contact uid of the contact reference. - */ - void setUid( const QString &uid ); - - /** - * Returns the contact uid of the contact reference. - */ - QString uid() const; - - /** - * Sets the preferred email address. - */ - void setPreferredEmail( const QString &email ); - - /** - * Returns the preferred email address, or an empty string - * if no preferred email address is set. - */ - QString preferredEmail() const; - - /** - * Inserts a custom entry. - * If an entry with the same @p key already exists, it is - * overwritten. - * - * @param key The unique key. - * @param value The value. - */ - void insertCustom( const QString &key, const QString &value ); - - /** - * Removes the custom entry with the given @p key. - */ - void removeCustom( const QString &key ); - - /** - * Returns the value for the given @p key, or an empty string - * if the entry for that key does not exists. - */ - QString custom( const QString &key ) const; - - /** - * @internal - */ - Reference &operator=( const Reference & ); - - /** - * @internal - */ - bool operator==( const Reference & ) const; - - private: - class ReferencePrivate; - QSharedDataPointer d; - }; - - /** - * This class represents a contact data object - */ - class KABC_EXPORT Data - { - public: - /** - * A list of contact data. - */ - typedef QList List; - - /** - * Creates an empty contact data object. - */ - Data(); - - /** - * Creates a contact data object from an @p other data object. - */ - Data( const Data &other ); - - /** - * Creates a contact data object with the given @p name and @p email address. - */ - Data( const QString &name, const QString &email ); - - /** - * Destroys the contact data object. - */ - ~Data(); - - /** - * Sets the @p name of the contact data object. - */ - void setName( const QString &name ); - - /** - * Returns the name of the contact data object. - */ - QString name() const; - - /** - * Sets the @p email address of the contact data object. - */ - void setEmail( const QString &email ); - - /** - * Returns the email address of the contact data object. - */ - QString email() const; - - /** - * Inserts a custom entry. - * If an entry with the same @p key already exists, it is - * overwritten. - * - * @param key The unique key. - * @param value The value. - */ - void insertCustom( const QString &key, const QString &value ); - - /** - * Removes the custom entry with the given @p key. - */ - void removeCustom( const QString &key ); - - /** - * Returns the value for the given @p key, or an empty string - * if the entry for that key does not exists. - */ - QString custom( const QString &key ) const; - - /** - * @internal - */ - Data &operator=( const Data & ); - - /** - * @internal - */ - bool operator==( const Data & ) const; - - private: - class DataPrivate; - QSharedDataPointer d; - }; - - /** - * A list of contact groups. - */ - typedef QList List; - - /** - * Creates an empty contact group. - */ - ContactGroup(); - - /** - * Creates a contact group from an @p other group. - */ - ContactGroup( const ContactGroup &other ); - - /** - * Creates a contact group with the given name. - */ - ContactGroup( const QString &name ); - - /** - * Destroys the contact group. - */ - ~ContactGroup(); - - /** - * Sets the unique @p id of the contact group. - */ - void setId( const QString &id ); - - /** - * Returns the unique id of the contact group. - */ - QString id() const; - - /** - * Sets the i18n'd @p name of the contact group. - */ - void setName( const QString &name ); - - /** - * Returns the i18n'd name of the contact group. - */ - QString name() const; - - /** - * Returns the number of contacts in this group. - * That includes the contact references and contact data. - */ - unsigned int count() const; - - /** - * Returns the number of contact references in this group. - */ - unsigned int referencesCount() const; - - /** - * Returns the number of contact data objects in this group. - */ - unsigned int dataCount() const; - - /** - * Returns the contact reference at the given @p index. - */ - Reference &reference( unsigned int index ); - - /** - * Returns the contact reference at the given @p index. - */ - const Reference &reference( unsigned int index ) const; - - /** - * Returns the contact data object at the given @p index. - */ - Data &data( unsigned int index ); - - /** - * Returns the contact data object at the given @p index. - */ - const Data &data( unsigned int index ) const; - - /** - * Appends a new contact @p reference to the contact group. - */ - void append( const Reference &reference ); - - /** - * Appends a new contact @p data object to the contact group. - */ - void append( const Data &data ); - - /** - * Removes the given contact @p reference from the contact group. - */ - void remove( const Reference &reference ); - - /** - * Removes the given contact @p data object from the contact group. - */ - void remove( const Data &data ); - - /** - * @internal - */ - ContactGroup &operator=( const ContactGroup & ); - - /** - * @internal - */ - bool operator==( const ContactGroup & ) const; - - /** - * Returns the MIME type used for Contact Groups - */ - static QString mimeType(); - - private: - class Private; - QSharedDataPointer d; -}; - -} - -#endif diff --git a/kabc/contactgroup.xsd b/kabc/contactgroup.xsd deleted file mode 100644 index ba486b656..000000000 --- a/kabc/contactgroup.xsd +++ /dev/null @@ -1,76 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/kabc/contactgrouptool.cpp b/kabc/contactgrouptool.cpp deleted file mode 100644 index aa884dc96..000000000 --- a/kabc/contactgrouptool.cpp +++ /dev/null @@ -1,331 +0,0 @@ -/* - This file is part of libkabc. - Copyright (c) 2008 Tobias Koenig - Copyright (c) 2008 Kevin Krammer - - 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. -*/ - -#include "contactgrouptool.h" -#include "contactgroup.h" - -#include -#include -#include - -#include -#include - -using namespace KABC; - -class XmlContactGroupWriter : public QXmlStreamWriter -{ - public: - XmlContactGroupWriter(); - - void write( const ContactGroup &group, QIODevice *device ); - void write( const QList &groupLis, QIODevice *device ); - - private: - void writeGroup( const ContactGroup &group ); - void writeReference( const ContactGroup::Reference & ); - void writeData( const ContactGroup::Data & ); -}; - -XmlContactGroupWriter::XmlContactGroupWriter() -{ - setAutoFormatting( true ); -} - -void XmlContactGroupWriter::write( const ContactGroup &group, QIODevice *device ) -{ - setDevice( device ); - - writeStartDocument(); - - writeGroup( group ); - - writeEndDocument(); -} - -void XmlContactGroupWriter::write( const QList &groupList, QIODevice *device ) -{ - setDevice( device ); - - writeStartDocument(); - - writeStartElement( "contactGroupList" ); - - foreach ( const ContactGroup & group, groupList ) { - writeGroup( group ); - } - - writeEndElement(); - - writeEndDocument(); -} - -void XmlContactGroupWriter::writeGroup( const ContactGroup &group ) -{ - writeStartElement( "contactGroup" ); - writeAttribute( "uid", group.id() ); - writeAttribute( "name", group.name() ); - - for ( uint i = 0; i < group.referencesCount(); ++i ) { - writeReference( group.reference( i ) ); - } - - for ( uint i = 0; i < group.dataCount(); ++i ) { - writeData( group.data( i ) ); - } - - writeEndElement(); -} - -void XmlContactGroupWriter::writeReference( const ContactGroup::Reference &reference ) -{ - writeStartElement( "contactReference" ); - writeAttribute( "uid", reference.uid() ); - if ( !reference.preferredEmail().isEmpty() ) { - writeAttribute( "preferredEmail", reference.preferredEmail() ); - } - - // TODO: customs - - writeEndElement(); -} - -void XmlContactGroupWriter::writeData( const ContactGroup::Data &data ) -{ - writeStartElement( "contactData" ); - writeAttribute( "name", data.name() ); - writeAttribute( "email", data.email() ); - - // TODO: customs - - writeEndElement(); -} - -class XmlContactGroupReader : public QXmlStreamReader -{ - public: - XmlContactGroupReader(); - - bool read( QIODevice *device, ContactGroup &group ); - bool read( QIODevice *device, QList &groupList ); - - private: - bool readGroup( ContactGroup &group ); - bool readReference( ContactGroup::Reference &reference ); - bool readData( ContactGroup::Data &data ); -}; - -XmlContactGroupReader::XmlContactGroupReader() -{ -} - -bool XmlContactGroupReader::read( QIODevice *device, ContactGroup &group ) -{ - setDevice( device ); - - while ( !atEnd() ) { - readNext(); - if ( isStartElement() ) { - if ( name() == QLatin1String( "contactGroup" ) ) { - return readGroup( group ); - } else { - raiseError( "The document does not describe a ContactGroup" ); - } - } - } - - return error() == NoError; -} - -bool XmlContactGroupReader::read( QIODevice *device, QList &groupList ) -{ - setDevice( device ); - - int depth = 0; - - while ( !atEnd() ) { - readNext(); - if ( isStartElement() ) { - ++depth; - if ( depth == 1 ) { - if ( name() == QLatin1String( "contactGroupList" ) ) { - continue; - } else { - raiseError( "The document does not describe a list of ContactGroup" ); - } - } else if ( depth == 2 ) { - if ( name() == QLatin1String( "contactGroup" ) ) { - ContactGroup group; - if ( !readGroup( group ) ) { - return false; - } - - groupList.append( group ); - } else { - raiseError( "The document does not describe a list of ContactGroup" ); - } - } - } - - if ( isEndElement() ) { - --depth; - } - } - - return error() == NoError; -} - -bool XmlContactGroupReader::readGroup( ContactGroup &group ) -{ - const QXmlStreamAttributes elementAttributes = attributes(); - const QStringRef uid = elementAttributes.value( "uid" ); - if ( uid.isEmpty() ) { - raiseError( "ContactGroup is missing a uid" ); - return false; - } - - const QStringRef groupName = elementAttributes.value( "name" ); - if ( groupName.isEmpty() ) { - raiseError( "ContactGroup is missing a name" ); - return false; - } - - group.setId( uid.toString() ); - group.setName( groupName.toString() ); - - while ( !atEnd() ) { - readNext(); - if ( isStartElement() ) { - if ( name() == QLatin1String( "contactData" ) ) { - ContactGroup::Data data; - if ( !readData( data ) ) { - return false; - } - group.append( data ); - } else if ( name() == QLatin1String( "contactReference" ) ) { - ContactGroup::Reference reference; - if ( !readReference( reference ) ) { - return false; - } - group.append( reference ); - } else { - raiseError( "The document does not describe a ContactGroup" ); - } - } - - if ( isEndElement() ) { - if ( name() == QLatin1String( "contactGroup" ) ) { - return true; - } - } - } - - return false; -} - -bool XmlContactGroupReader::readData( ContactGroup::Data &data ) -{ - const QXmlStreamAttributes elementAttributes = attributes(); - const QStringRef email = elementAttributes.value( "email" ); - if ( email.isEmpty() ) { - raiseError( "ContactData is missing an email address" ); - return false; - } - - const QStringRef name = elementAttributes.value( "name" ); - if ( name.isEmpty() ) { - raiseError( "ContactData is missing a name" ); - return false; - } - - data.setName( name.toString() ); - data.setEmail( email.toString() ); - - return true; -} - -bool XmlContactGroupReader::readReference( ContactGroup::Reference &reference ) -{ - const QXmlStreamAttributes elementAttributes = attributes(); - const QStringRef uid = elementAttributes.value( "uid" ); - if ( uid.isEmpty() ) { - raiseError( "ContactReference is missing a uid" ); - return false; - } - - reference.setUid( uid.toString() ); - - return true; -} - -bool ContactGroupTool::convertFromXml( QIODevice *device, ContactGroup &group, - QString *errorMessage ) -{ - Q_UNUSED( errorMessage ); - - XmlContactGroupReader reader; - - bool ok = reader.read( device, group ); - - if ( !ok && errorMessage != 0 ) { - *errorMessage = reader.errorString(); - } - - return ok; -} - -bool ContactGroupTool::convertToXml( const ContactGroup &group, QIODevice *device, - QString *errorMessage ) -{ - Q_UNUSED( errorMessage ); - - XmlContactGroupWriter writer; - writer.write( group, device ); - - return true; -} - -bool ContactGroupTool::convertFromXml( QIODevice *device, QList &groupList, - QString *errorMessage ) -{ - Q_UNUSED( errorMessage ); - - XmlContactGroupReader reader; - - bool ok = reader.read( device, groupList ); - - if ( !ok && errorMessage != 0 ) { - *errorMessage = reader.errorString(); - } - - return ok; -} - -bool ContactGroupTool::convertToXml( const QList &groupList, - QIODevice *device, QString *errorMessage ) -{ - Q_UNUSED( errorMessage ); - - XmlContactGroupWriter writer; - writer.write( groupList, device ); - - return true; -} diff --git a/kabc/contactgrouptool.h b/kabc/contactgrouptool.h deleted file mode 100644 index 3d648cf8e..000000000 --- a/kabc/contactgrouptool.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - This file is part of libkabc. - Copyright (c) 2008 Tobias Koenig - Copyright (c) 2008 Kevin Krammer - - 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. -*/ - -#ifndef KABC_CONTACTGROUPTOOL_H -#define KABC_CONTACTGROUPTOOL_H - -#include "kabc_export.h" - -class QIODevice; -class QString; - -template class QList; - -namespace KABC { - -class ContactGroup; - -/** - * @since 4.2 - */ -class KABC_EXPORT ContactGroupTool -{ - public: - static bool convertFromXml( QIODevice *device, ContactGroup &group, - QString *errorMessage = 0 ); - - static bool convertToXml( const ContactGroup &group, QIODevice *device, - QString *errorMessage = 0 ); - - static bool convertFromXml( QIODevice *device, - QList &groupList, - QString *errorMessage = 0 ); - - static bool convertToXml( const QList &groupList, - QIODevice *device, QString *errorMessage = 0 ); -}; - -} - -#endif diff --git a/kabc/tests/CMakeLists.txt b/kabc/tests/CMakeLists.txt index f4f5efbb5..39a087b3f 100644 --- a/kabc/tests/CMakeLists.txt +++ b/kabc/tests/CMakeLists.txt @@ -1,175 +1,167 @@ set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} ) include_directories( ${CMAKE_SOURCE_DIR}/kabc ) ########### next target ############### set(addresstest_SRCS addresstest.cpp) kde4_add_unit_test(addresstest TESTNAME kabc-addresstest ${addresstest_SRCS}) target_link_libraries(addresstest ${KDE4_KDECORE_LIBS} kabc ${QT_QTTEST_LIBRARY} ${QT_QTGUI_LIBRARY}) ########### next target ############### set(addresseetest_SRCS addresseetest.cpp) kde4_add_unit_test(addresseetest TESTNAME kabc-addresseetest ${addresseetest_SRCS}) target_link_libraries(addresseetest ${KDE4_KDECORE_LIBS} kabc ${QT_QTTEST_LIBRARY} ${QT_QTGUI_LIBRARY}) ########### next target ############### set(geotest_SRCS geotest.cpp) kde4_add_unit_test(geotest TESTNAME kabc-geotest ${geotest_SRCS}) target_link_libraries(geotest ${KDE4_KDECORE_LIBS} kabc ${QT_QTTEST_LIBRARY} ${QT_QTGUI_LIBRARY}) ########### next target ############### set(keytest_SRCS keytest.cpp) kde4_add_unit_test(keytest TESTNAME kabc-keytest ${keytest_SRCS}) target_link_libraries(keytest ${KDE4_KDECORE_LIBS} kabc ${QT_QTTEST_LIBRARY} ${QT_QTGUI_LIBRARY}) ########### next target ############### set(phonenumbertest_SRCS phonenumbertest.cpp) kde4_add_unit_test(phonenumbertest TESTNAME kabc-phonenumbertest ${phonenumbertest_SRCS}) target_link_libraries(phonenumbertest ${KDE4_KDECORE_LIBS} kabc ${QT_QTTEST_LIBRARY} ${QT_QTGUI_LIBRARY}) ########### next target ############### set(picturetest_SRCS picturetest.cpp) kde4_add_unit_test(picturetest TESTNAME kabc-picturetest ${picturetest_SRCS}) target_link_libraries(picturetest ${KDE4_KDECORE_LIBS} kabc ${QT_QTTEST_LIBRARY} ${QT_QTGUI_LIBRARY}) ########### next target ############### set(secrecytest_SRCS secrecytest.cpp) kde4_add_unit_test(secrecytest TESTNAME kabc-secrecytest ${secrecytest_SRCS}) target_link_libraries(secrecytest ${KDE4_KDECORE_LIBS} kabc ${QT_QTTEST_LIBRARY} ${QT_QTGUI_LIBRARY}) ########### next target ############### set(soundtest_SRCS soundtest.cpp) kde4_add_unit_test(soundtest TESTNAME kabc-soundtest ${soundtest_SRCS}) target_link_libraries(soundtest ${KDE4_KDECORE_LIBS} kabc ${QT_QTTEST_LIBRARY} ${QT_QTGUI_LIBRARY}) ########### next target ############### set(timezonetest_SRCS timezonetest.cpp) kde4_add_unit_test(timezonetest TESTNAME kabc-timezonetest ${timezonetest_SRCS}) target_link_libraries(timezonetest ${KDE4_KDECORE_LIBS} kabc ${QT_QTTEST_LIBRARY} ${QT_QTGUI_LIBRARY}) ########### next target ############### set(testlock_SRCS testlock.cpp) kde4_add_executable(testlock TEST ${testlock_SRCS}) target_link_libraries(testlock ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS} kabc ${QT_QTTEST_LIBRARY} ${QT_QTGUI_LIBRARY}) ########### next target ############### set(testkabc_SRCS testkabc.cpp) kde4_add_executable(testkabc TEST ${testkabc_SRCS}) target_link_libraries(testkabc ${KDE4_KDECORE_LIBS} kabc ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS}) ########### next target ############### set(testkabcdlg_SRCS testkabcdlg.cpp) kde4_add_executable(testkabcdlg TEST ${testkabcdlg_SRCS}) target_link_libraries(testkabcdlg ${KDE4_KDECORE_LIBS} kabc ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS}) ########### next target ############### if (UNIX) set(bigread_SRCS bigread.cpp) kde4_add_executable(bigread TEST ${bigread_SRCS}) target_link_libraries(bigread ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBS} kabc kabc_file_core ) endif (UNIX) ########### next target ############### if (UNIX) set(bigwrite_SRCS bigwrite.cpp) kde4_add_executable(bigwrite TEST ${bigwrite_SRCS}) target_link_libraries(bigwrite ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBS} kabc kabc_file_core ) endif (UNIX) ########### next target ############### #set(testaddresseelist_SRCS testaddresseelist.cpp) #kde4_add_unit_test(testaddresseelist TESTNAME kabc-testaddresseelist ${testaddresseelist_SRCS}) #target_link_libraries(testaddresseelist ${KDE4_KDECORE_LIBS} kabc ${QT_QTTEST_LIBRARY}) ########### next target ############### set(kabcargl_SRCS kabcargl.cpp) kde4_add_executable(kabcargl TEST ${kabcargl_SRCS}) target_link_libraries(kabcargl ${KDE4_KDECORE_LIBS} kabc ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS} ) ########### next target ############### set(testaddresslineedit_SRCS testaddresslineedit.cpp) kde4_add_executable(testaddresslineedit TEST ${testaddresslineedit_SRCS}) target_link_libraries(testaddresslineedit ${KDE4_KDECORE_LIBS} kabc ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS}) -########### next target ############### - -set(contactgrouptest_SRCS contactgrouptest.cpp) - - -kde4_add_unit_test(contactgrouptest TESTNAME kabc-contactgrouptest ${contactgrouptest_SRCS}) - -target_link_libraries(contactgrouptest ${KDE4_KDECORE_LIBS} kabc ${QT_QTTEST_LIBRARY}) diff --git a/kabc/tests/contactgrouptest.cpp b/kabc/tests/contactgrouptest.cpp deleted file mode 100644 index a297b64db..000000000 --- a/kabc/tests/contactgrouptest.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* - This file is part of libkabc. - Copyright (c) 2008 Kevin Krammer - - 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. -*/ - -#include - -#include "kabc/contactgroup.h" -#include "kabc/contactgrouptool.h" - -#include - -using namespace KABC; - -class ContactGroupTest : public QObject -{ - Q_OBJECT - - private Q_SLOTS: - void testGroupRoundTrip(); - void testGroupListRoundTrip(); -}; - -QTEST_KDEMAIN( ContactGroupTest, NoGUI ) - -void ContactGroupTest::testGroupRoundTrip() -{ - // TODO should also test empty group - - ContactGroup group( "TestGroup" ); - group.append( ContactGroup::Reference( "Xggdjetw" ) ); - group.append( ContactGroup::Data( "Tobias Koenig", "tokoe@kde.org" ) ); - group.append( ContactGroup::Data( "Kevin Krammer", "kevin.krammer@gmx.at" ) ); - - QBuffer buffer; - buffer.open( QIODevice::WriteOnly ); - - QString errorMessage; - bool result = ContactGroupTool::convertToXml( group, &buffer, &errorMessage ); - - QVERIFY( result ); - QVERIFY( errorMessage.isEmpty() ); - buffer.close(); - QVERIFY( buffer.size() > 0 ); - buffer.open( QIODevice::ReadOnly ); - - ContactGroup group2; - result = ContactGroupTool::convertFromXml( &buffer, group2, &errorMessage ); - QVERIFY( result ); - QVERIFY( errorMessage.isEmpty() ); - QCOMPARE( group, group2 ); -} - -void ContactGroupTest::testGroupListRoundTrip() -{ - // TODO should also test empty list - - ContactGroup::List list; - - ContactGroup group1( "TestGroup1" ); - group1.append( ContactGroup::Reference( "Xggdjetw" ) ); - group1.append( ContactGroup::Data( "Tobias Koenig", "tokoe@kde.org" ) ); - group1.append( ContactGroup::Data( "Kevin Krammer", "kevin.krammer@gmx.at" ) ); - - list.append( group1 ); - - ContactGroup group2( "TestGroup2" ); - group2.append( ContactGroup::Reference( "Xggdjetw" ) ); - group2.append( ContactGroup::Data( "Tobias Koenig", "tokoe@kde.org" ) ); - group2.append( ContactGroup::Data( "Kevin Krammer", "kevin.krammer@gmx.at" ) ); - - list.append( group2 ); - - QBuffer buffer; - buffer.open( QIODevice::WriteOnly ); - - QString errorMessage; - bool result = ContactGroupTool::convertToXml( list, &buffer, &errorMessage ); - - QVERIFY( result ); - QVERIFY( errorMessage.isEmpty() ); - buffer.close(); - QVERIFY( buffer.size() > 0 ); - - buffer.open( QIODevice::ReadOnly ); - - ContactGroup::List list2; - result = ContactGroupTool::convertFromXml( &buffer, list2, &errorMessage ); - QVERIFY( result ); - QVERIFY( errorMessage.isEmpty() ); - QVERIFY( list2.size() == 2 ); - QCOMPARE( list2[0], group1 ); - QCOMPARE( list2[1], group2 ); -} - -#include "contactgrouptest.moc" - -// kate: space-indent on; indent-width 2; replace-tabs on;