diff --git a/akonadi/CMakeLists.txt b/akonadi/CMakeLists.txt index f3c0e0bc1..884c903e8 100644 --- a/akonadi/CMakeLists.txt +++ b/akonadi/CMakeLists.txt @@ -1,225 +1,227 @@ project(akonadi-kde) if (KDE4_BUILD_TESTS) # only with this macro the AKONADI_TESTS_EXPORT macro will do something add_definitions(-DCOMPILING_TESTS) endif (KDE4_BUILD_TESTS) add_subdirectory( tests ) add_definitions( -DQT_NO_CAST_FROM_ASCII ) add_definitions( -DQT_NO_CAST_TO_ASCII ) add_subdirectory( kabc ) add_subdirectory( kmime ) include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${QT_QTDBUS_INCLUDE_DIR} ${Boost_INCLUDE_DIR} ${KDE4_INCLUDE_DIR} ${AKONADI_INCLUDE_DIR} ${AKONADI_INCLUDE_DIR}/akonadi/private ) # libakonadi-kde set( akonadikde_LIB_SRC entity.cpp # keep it at top to not break enable-final agentbase.cpp agentfilterproxymodel.cpp agentinstance.cpp agentinstancecreatejob.cpp agentinstancemodel.cpp agentinstancewidget.cpp agentmanager.cpp agenttype.cpp agenttypemodel.cpp agenttypewidget.cpp agenttypedialog.cpp attribute.cpp attributefactory.cpp cachepolicy.cpp cachepolicypage.cpp changerecorder.cpp collection.cpp collectioncopyjob.cpp collectioncreatejob.cpp collectiondeletejob.cpp collectiondialog.cpp collectionfilterproxymodel.cpp collectiongeneralpropertiespage.cpp collectionfetchjob.cpp collectionmodel.cpp collectionmodel_p.cpp collectionmodifyjob.cpp collectionpathresolver.cpp collectionpropertiesdialog.cpp collectionpropertiespage.cpp collectionrequester.cpp collectionrightsattribute.cpp collectionselectjob.cpp collectionstatistics.cpp collectionstatisticsdelegate.cpp collectionstatisticsjob.cpp collectionstatisticsmodel.cpp collectionsync.cpp collectionview.cpp control.cpp entitydisplayattribute.cpp #entitysortfilterproxymodel.cpp erroroverlay.cpp expungejob.cpp firstrun.cpp flatcollectionproxymodel.cpp item.cpp itemcreatejob.cpp itemcopyjob.cpp itemdeletejob.cpp itemfetchjob.cpp itemfetchscope.cpp itemmodel.cpp itemmonitor.cpp itemmovejob.cpp itemserializer.cpp itemserializerplugin.cpp itemmodifyjob.cpp itemsync.cpp itemview.cpp job.cpp linkjob.cpp + mimetypechecker.cpp monitor.cpp monitor_p.cpp pastehelper.cpp protocolhelper.cpp resourcebase.cpp resourcescheduler.cpp searchcreatejob.cpp selftestdialog.cpp session.cpp servermanager.cpp standardactionmanager.cpp subscriptionjob.cpp subscriptionchangeproxymodel.cpp subscriptiondialog.cpp subscriptionmodel.cpp transactionjobs.cpp transactionsequence.cpp unlinkjob.cpp # Temporary until ported to Qt-plugin framework pluginloader.cpp ) # DBus interfaces and adaptors set(akonadi_xml ${AKONADI_DBUS_INTERFACES_DIR}/org.freedesktop.Akonadi.NotificationManager.xml) set_source_files_properties(${akonadi_xml} PROPERTIES INCLUDE "notificationmessage_p.h") qt4_add_dbus_interface( akonadikde_LIB_SRC ${akonadi_xml} notificationmanagerinterface ) qt4_add_dbus_interfaces( akonadikde_LIB_SRC ${AKONADI_DBUS_INTERFACES_DIR}/org.freedesktop.Akonadi.AgentManager.xml ) qt4_add_dbus_interfaces( akonadikde_LIB_SRC ${AKONADI_DBUS_INTERFACES_DIR}/org.freedesktop.Akonadi.Tracer.xml ) qt4_add_dbus_adaptor( akonadikde_LIB_SRC ${AKONADI_DBUS_INTERFACES_DIR}/org.freedesktop.Akonadi.Resource.xml resourcebase.h Akonadi::ResourceBase ) qt4_add_dbus_adaptor( akonadikde_LIB_SRC ${AKONADI_DBUS_INTERFACES_DIR}/org.freedesktop.Akonadi.Agent.Status.xml agentbase.h Akonadi::AgentBase ) qt4_add_dbus_adaptor( akonadikde_LIB_SRC ${AKONADI_DBUS_INTERFACES_DIR}/org.freedesktop.Akonadi.Agent.Control.xml agentbase.h Akonadi::AgentBase ) kde4_add_ui_files( akonadikde_LIB_SRC cachepolicypage.ui collectiongeneralpropertiespage.ui subscriptiondialog.ui controlprogressindicator.ui selftestdialog.ui ) kde4_add_library( akonadi-kde SHARED ${akonadikde_LIB_SRC} ) macro_ensure_version( "4.2.0" ${KDE_VERSION} KDE_IS_AT_LEAST_42 ) target_link_libraries( akonadi-kde ${KDE4_SOLID_LIBS} ${QT_QTNETWORK_LIBRARY} ${QT_QTDBUS_LIBRARY} ${QT_QTSQL_LIBRARY} ${KDE4_KDEUI_LIBS} ${KDE4_KIO_LIBS} ${AKONADI_COMMON_LIBRARIES} ) set( AKONADI_KDE_DEPS ${KDE4_KDEUI_LIBS} ${QT_QTDBUS_LIBRARY} ${QT_QTCORE_LIBRARY} ) if(${KDE_IS_AT_LEAST_42}) target_link_libraries( akonadi-kde LINK_INTERFACE_LIBRARIES ${AKONADI_KDE_DEPS}) else(${KDE_IS_AT_LEAST_42}) target_link_libraries( akonadi-kde ${AKONADI_KDE_DEPS}) endif(${KDE_IS_AT_LEAST_42}) set_target_properties( akonadi-kde PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} ) install( TARGETS akonadi-kde EXPORT kdepimlibsLibraryTargets ${INSTALL_TARGETS_DEFAULT_ARGS} ) ########### install files ############### install( FILES akonadi_export.h agentbase.h agentfilterproxymodel.h agentinstance.h agentinstancecreatejob.h agentinstancemodel.h agentinstancewidget.h agentmanager.h agenttype.h agenttypemodel.h agenttypewidget.h agenttypedialog.h attribute.h attributefactory.h cachepolicy.h changerecorder.h collection.h collectioncopyjob.h collectioncreatejob.h collectiondeletejob.h collectiondialog.h collectionfilterproxymodel.h collectionfetchjob.h collectionmodel.h collectionmodifyjob.h collectionpropertiesdialog.h collectionpropertiespage.h collectionrequester.h collectionstatisticsdelegate.h collectionstatisticsmodel.h collectionstatistics.h collectionstatisticsjob.h collectionview.h control.h entity.h entitydisplayattribute.h # entitysortfilterproxymodel.h item.h itemcreatejob.h itemcopyjob.h itemdeletejob.h itemfetchjob.h itemfetchscope.h itemmodel.h itemmodifyjob.h itemmonitor.h itemmovejob.h itempayloadinternals_p.h itemserializerplugin.h itemsync.h itemview.h job.h linkjob.h + mimetypechecker.h monitor.h qtest_akonadi.h resourcebase.h searchcreatejob.h session.h servermanager.h standardactionmanager.h transactionjobs.h transactionsequence.h unlinkjob.h DESTINATION ${INCLUDE_INSTALL_DIR}/akonadi COMPONENT Devel ) install( FILES collectionpathresolver_p.h DESTINATION ${INCLUDE_INSTALL_DIR}/akonadi/private COMPONENT Devel ) install( FILES kcfg2dbus.xsl DESTINATION ${DATA_INSTALL_DIR}/akonadi-kde ) diff --git a/akonadi/mimetypechecker.cpp b/akonadi/mimetypechecker.cpp new file mode 100644 index 000000000..e509dc7aa --- /dev/null +++ b/akonadi/mimetypechecker.cpp @@ -0,0 +1,138 @@ +/* + Copyright (c) 2009 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 "mimetypechecker.h" + +#include "mimetypechecker_p.h" + +#include "collection.h" +#include "item.h" + +using namespace Akonadi; + +MimeTypeChecker::MimeTypeChecker() +{ + d = new MimeTypeCheckerPrivate(); +} + +MimeTypeChecker::MimeTypeChecker( const MimeTypeChecker &other ) + : d( other.d ) +{ +} + +MimeTypeChecker::~MimeTypeChecker() +{ +} + +MimeTypeChecker &MimeTypeChecker::operator=( const MimeTypeChecker &other ) +{ + if ( &other != this ) + d = other.d; + + return *this; +} + +QStringList MimeTypeChecker::wantedMimeTypes() const +{ + return d->mWantedMimeTypes.values(); +} + +void MimeTypeChecker::setWantedMimeTypes( const QStringList &mimeTypes ) +{ + d->mWantedMimeTypes = QSet::fromList( mimeTypes ); +} + +void MimeTypeChecker::addWantedMimeType( const QString &mimeType ) +{ + d->mWantedMimeTypes.insert( mimeType ); +} + +bool MimeTypeChecker::isWantedItem( const Item &item ) const +{ + if ( d->mWantedMimeTypes.isEmpty() || !item.isValid() ) + return false; + + const QString mimeType = item.mimeType(); + if ( mimeType.isEmpty() ) + return false; + + return d->isWantedMimeType( mimeType ); +} + +bool MimeTypeChecker::isWantedCollection( const Collection &collection ) const +{ + if ( d->mWantedMimeTypes.isEmpty() || !collection.isValid() ) + return false; + + const QStringList contentMimeTypes = collection.contentMimeTypes(); + if ( contentMimeTypes.isEmpty() ) + return false; + + foreach ( const QString &mimeType, contentMimeTypes ) { + if ( mimeType.isEmpty() ) + continue; + + if ( d->isWantedMimeType( mimeType ) ) + return true; + } + + return false; +} + +bool MimeTypeChecker::isWantedItem( const Item &item, const QString &wantedMimeType ) +{ + if ( wantedMimeType.isEmpty() || !item.isValid() ) + return false; + + const QString mimeType = item.mimeType(); + if ( mimeType.isEmpty() ) + return false; + + KMimeType::Ptr mimeTypePtr = KMimeType::mimeType( mimeType, KMimeType::ResolveAliases ); + if ( mimeTypePtr.isNull() ) + return false; + + return mimeTypePtr->is( wantedMimeType ); +} + +bool MimeTypeChecker::isWantedCollection( const Collection &collection, const QString &wantedMimeType ) +{ + if ( wantedMimeType.isEmpty() || !collection.isValid() ) + return false; + + const QStringList contentMimeTypes = collection.contentMimeTypes(); + if ( contentMimeTypes.isEmpty() ) + return false; + + foreach ( const QString &mimeType, contentMimeTypes ) { + if ( mimeType.isEmpty() ) + continue; + + KMimeType::Ptr mimeTypePtr = KMimeType::mimeType( mimeType, KMimeType::ResolveAliases ); + if ( mimeTypePtr.isNull() ) + continue; + + if ( mimeTypePtr->is( wantedMimeType ) ) + return true; + } + + return false; +} + +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/akonadi/mimetypechecker.h b/akonadi/mimetypechecker.h new file mode 100644 index 000000000..7008a9ed3 --- /dev/null +++ b/akonadi/mimetypechecker.h @@ -0,0 +1,224 @@ +/* + Copyright (c) 2009 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 MIMETYPECHECKER_H +#define MIMETYPECHECKER_H + +#include "akonadi_export.h" + +#include + +class QString; +class QStringList; + +namespace Akonadi { + class Collection; + class Item; + class MimeTypeCheckerPrivate; + +/** + * @short Helper for checking MIME types of Collections and Items. + * + * When it is necessary to decide whether an item has a certain MIME type + * or whether a collection can contain a certain MIME type, direct string + * comparison might not render the desired result because MIME types can + * have aliases and be a node in an "inheritance" hierachy. + * + * For example a check like this + * @code + * if ( item.mimeType() == QLatin1String( "text/directory" ) ) + * @endcode + * would fail to detect @c "text/x-vcard" as being the same MIME type. + * + * @note KDE deals with this inside the KMimeType framework, this class is just + * a convenience helper for common Akonadi related checks. + * + * Example: Checking whether an Akonadi::Item is contact MIME type + * @code + * Akonadi::MimeTypeChecker checker; + * checker.addWantedMimeType( KABC::Addressee::mimeType() ); + * + * if ( checker.isWantedItem( item ) ){ + * // item.mimeType() is equal KABC::Addressee::mimeType(), an aliases + * // or a sub type. + * } + * @endcode + * + * Example: Checking whether an Akonadi::Collection could contain calendar + * items + * @code + * Akonadi::MimeTypeChecker checker; + * checker.addWantedMimeType( QLatin1String( "text/calendar" ) ); + * + * if ( checker.isWantedCollection( collection ) ) { + * // collection.contentMimeTypes() contains @c "text/calendar" + * // or a sub type. + * } + * @endcode + * + * Example: Checking whether an Akonadi::Collection could contain + * Calendar Event items (i.e. KCal::Event), making use of the respective + * MIME type "subclassing" provided by Akonadi's MIME type extensions. + * @code + * Akonadi::MimeTypeChecker checker; + * checker.addWantedMimeType( QLatin1String( "application/x-vnd.akonadi.calendar.event" ) ); + * + * if ( checker.isWantedCollection( collection ) ) { + * // collection.contentMimeTypes() contains @c "application/x-vnd.akonadi.calendar.event" + * // or a sub type, but just containing @c "text/calendar" would not + * // get here + * } + * @endcode + * + * Example: Checking for items of more than one MIME type and treat one + * of them specially. + * @code + * Akonadi::MimeTypeChecker mimeFilter; + * mimeFilter.setWantedMimeTypes( QStringList() << KABC::Addressee::mimeType() + * << KABC::ContactGroup::mimeType() ); + * + * if ( mimeFilter.isWantedItem( item ) ) { + * if ( Akonadi::MimeTypeChecker::isWantedItem( item, KABC::ContactGroup::mimeType() ) { + * // treat contact group's differently + * } + * } + * @endcode + * + * This class is implicitly shared. + * + * @author Kevin Krammer + * + * @since 4.3 + */ +class AKONADI_EXPORT MimeTypeChecker +{ + public: + /** + * Creates an empty MIME type checker. + * + * An empty checker will not report any items or collections as wanted. + */ + MimeTypeChecker(); + + /** + * Creates a new MIME type checker from an @p other. + */ + MimeTypeChecker( const MimeTypeChecker &other ); + + /** + * Destroys the MIME type checker. + */ + ~MimeTypeChecker(); + + /** + * Assigns the @p other to this checker and returns a reference to this checker. + */ + MimeTypeChecker &operator=( const MimeTypeChecker &other ); + + /** + * Returns the list of wanted MIME types this instance checks against. + * + * @see setWantedMimeTypes() + */ + QStringList wantedMimeTypes() const; + + /** + * Sets the list of wanted MIME types this instance checks against. + * + * @param mimeTypes The list of MIME types to check against. + * + * @see wantedMimeTypes() + */ + void setWantedMimeTypes( const QStringList &mimeTypes ); + + /** + * Adds another MIME type to the list of wanted MIME types this instance checks against. + * + * @param mimeType The MIME types to add to the checklist. + * + * @see setWantedMimeTypes() + */ + void addWantedMimeType( const QString &mimeType ); + + /** + * Checks whether a given @p item has one of the wanted MIME types + * + * @param item The item to check the MIME type of. + * + * @return @c true if the @p item MIME type is one of the wanted ones, + * @c false if it isn't, the item is invalid or has an empty MIME type. + * + * @see setWantedMimeTypes() + * @see Item::mimeType() + */ + bool isWantedItem( const Item &item ) const; + + /** + * Checks whether a given @p collection has one of the wanted MIME types + * + * @param item The collection to check the content MIME types of. + * + * @return @c true if one of the @p collection content MIME types is + * one of the wanted ones, @c false if non is, the collection + * is invalid or has an empty content MIME type list. + * + * @see setWantedMimeTypes() + * @see Collection::contentMimeTypes() + */ + bool isWantedCollection( const Collection &collection ) const; + + /** + * Checks whether a given @p item has the given wanted MIME type + * + * @param item The item to check the MIME type of. + * @param wantedMimeType The MIME type to check against. + * + * @return @c true if the @p item MIME type is the given one, + * @c false if it isn't, the item is invalid or has an empty MIME type. + * + * @see setWantedMimeTypes() + * @see Item::mimeType() + */ + static bool isWantedItem( const Item &item, const QString &wantedMimeType ); + + /** + * Checks whether a given @p collection has the given MIME type + * + * @param item The collection to check the content MIME types of. + * @param wantedMimeType The MIME type to check against. + * + * @return @c true if one of the @p collection content MIME types is + * the given wanted one, @c false if it isn't, the collection + * is invalid or has an empty content MIME type list. + * + * @see setWantedMimeTypes() + * @see Collection::contentMimeTypes() + */ + static bool isWantedCollection( const Collection &collection, const QString &wantedMimeType ); + + private: + //@cond PRIVATE + QSharedDataPointer d; + //@endcond +}; + +} + +#endif +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/akonadi/mimetypechecker_p.h b/akonadi/mimetypechecker_p.h new file mode 100644 index 000000000..016280680 --- /dev/null +++ b/akonadi/mimetypechecker_p.h @@ -0,0 +1,70 @@ +/* + Copyright (c) 2009 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 MIMETYPECHECKER_P_H +#define MIMETYPECHECKER_P_H + +#include + +#include +#include + +namespace Akonadi { + +/** + * @internal + */ +class MimeTypeCheckerPrivate : public QSharedData +{ + public: + MimeTypeCheckerPrivate() + { + } + + MimeTypeCheckerPrivate( const MimeTypeCheckerPrivate &other ) + : QSharedData( other ) + { + mWantedMimeTypes = other.mWantedMimeTypes; + } + + bool isWantedMimeType( const QString &mimeType ) const + { + if ( mWantedMimeTypes.contains( mimeType ) ) + return true; + + KMimeType::Ptr mimeTypePtr = KMimeType::mimeType( mimeType, KMimeType::ResolveAliases ); + if ( mimeTypePtr.isNull() ) + return false; + + foreach ( const QString &wantedMimeType, mWantedMimeTypes ) { + if ( mimeTypePtr->is( wantedMimeType ) ) + return true; + } + + return false; + } + + public: + QSet mWantedMimeTypes; +}; + +} + +#endif +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/akonadi/tests/CMakeLists.txt b/akonadi/tests/CMakeLists.txt index 92c850d1a..50bd983e9 100644 --- a/akonadi/tests/CMakeLists.txt +++ b/akonadi/tests/CMakeLists.txt @@ -1,109 +1,110 @@ if(${EXECUTABLE_OUTPUT_PATH}) set( PREVIOUS_EXEC_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH} ) else(${EXECUTABLE_OUTPUT_PATH}) set( PREVIOUS_EXEC_OUTPUT_PATH . ) endif(${EXECUTABLE_OUTPUT_PATH}) set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} ) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}" ) include_directories( ${CMAKE_SOURCE_DIR}/akonadi ${CMAKE_CURRENT_SOURCE_DIR}/../ ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}/../ ${Boost_INCLUDE_DIR} ${AKONADI_INCLUDE_DIR} ) # add testrunner (application for managing a self-contained test # environment) add_subdirectory(testrunner) # add benchmarker add_subdirectory(benchmarker) # convenience macro to add akonadi demo application macro(add_akonadi_demo _source) set(_test ${_source}) get_filename_component(_name ${_source} NAME_WE) kde4_add_executable(${_name} TEST ${_test}) target_link_libraries(${_name} akonadi-kde akonadi-kmime ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${KDE4_KDECORE_LIBS} ${KDE4_KDEUI_LIBS}) endmacro(add_akonadi_demo) # convenience macro to add akonadi qtestlib unit-tests macro(add_akonadi_test _source) set(_test ${_source}) get_filename_component(_name ${_source} NAME_WE) kde4_add_unit_test(${_name} TESTNAME libakonadi-${_name} ${_test}) target_link_libraries(${_name} akonadi-kde akonadi-kmime ${QT_QTTEST_LIBRARY} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${KDE4_KDECORE_LIBS} ${AKONADI_COMMON_LIBRARIES}) endmacro(add_akonadi_test) # convenience macro to add akonadi testrunner unit-tests macro(add_akonadi_isolated_test _source) set(_test ${_source}) get_filename_component(_name ${_source} NAME_WE) kde4_add_executable(${_name} TEST ${_test}) target_link_libraries(${_name} akonadi-kde akonadi-kmime ${QT_QTTEST_LIBRARY} ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${KDE4_KDECORE_LIBS} ${AKONADI_COMMON_LIBRARIES}) # based on kde4_add_unit_test if (WIN32) get_target_property( _loc ${_name} LOCATION ) set(_executable ${_loc}.bat) set(_testrunner ${PREVIOUS_EXEC_OUTPUT_PATH}/akonaditest.bat) else (WIN32) set(_executable ${EXECUTABLE_OUTPUT_PATH}/${_name}) set(_testrunner ${PREVIOUS_EXEC_OUTPUT_PATH}/akonaditest) endif (WIN32) if (UNIX) set(_executable ${_executable}.shell) set(_testrunner ${_testrunner}.shell) endif (UNIX) add_test( libakonadi-${_name} ${_testrunner} -c ${CMAKE_CURRENT_SOURCE_DIR}/unittestenv/config.xml ${_executable} ) endmacro(add_akonadi_isolated_test) # demo applications add_akonadi_demo(itemdumper.cpp) add_akonadi_demo(subscriber.cpp) add_akonadi_demo(headfetcher.cpp) add_akonadi_demo(agentinstancewidgettest.cpp) add_akonadi_demo(agenttypewidgettest.cpp) add_akonadi_demo(pluginloadertest.cpp) add_akonadi_demo(selftester.cpp) kde4_add_executable( akonadi-firstrun TEST ../firstrun.cpp firstrunner.cpp ) target_link_libraries( akonadi-firstrun akonadi-kde ${KDE4_KDEUI_LIBS} ) # qtestlib unit tests add_akonadi_test(imapparsertest.cpp) add_akonadi_test(imapsettest.cpp) add_akonadi_test(itemhydratest.cpp) add_akonadi_test(itemtest.cpp) add_akonadi_test(itemserializertest.cpp) +add_akonadi_test(mimetypecheckertest.cpp) add_akonadi_test(notificationmessagetest.cpp) # testrunner tests add_akonadi_isolated_test(testenvironmenttest.cpp) add_akonadi_isolated_test(collectionjobtest.cpp) add_akonadi_isolated_test(collectionpathresolvertest.cpp) add_akonadi_isolated_test(collectionattributetest.cpp) add_akonadi_isolated_test(itemfetchtest.cpp) add_akonadi_isolated_test(itemappendtest.cpp) add_akonadi_isolated_test(itemstoretest.cpp) add_akonadi_isolated_test(monitortest.cpp) add_akonadi_isolated_test(searchjobtest.cpp) add_akonadi_isolated_test(changerecordertest.cpp) add_akonadi_isolated_test(resourcetest.cpp) add_akonadi_isolated_test(subscriptiontest.cpp) add_akonadi_isolated_test(transactiontest.cpp) add_akonadi_isolated_test(itemcopytest.cpp) add_akonadi_isolated_test(itemmovetest.cpp) add_akonadi_isolated_test(collectioncopytest.cpp) add_akonadi_isolated_test(collectionmovetest.cpp) add_akonadi_isolated_test(itemsynctest.cpp) add_akonadi_isolated_test(linktest.cpp) add_akonadi_isolated_test(servermanagertest.cpp) add_akonadi_isolated_test(collectioncreator.cpp) diff --git a/akonadi/tests/mimetypecheckertest.cpp b/akonadi/tests/mimetypecheckertest.cpp new file mode 100644 index 000000000..7d5219d4e --- /dev/null +++ b/akonadi/tests/mimetypecheckertest.cpp @@ -0,0 +1,247 @@ +/* + Copyright (c) 2009 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 "mimetypecheckertest.h" +#include "testattribute.h" + +#include "akonadi/collection.h" +#include "akonadi/item.h" + +#include + +QTEST_KDEMAIN( MimeTypeCheckerTest, NoGUI ) + +using namespace Akonadi; + +MimeTypeCheckerTest::MimeTypeCheckerTest( QObject *parent ) + : QObject( parent ) +{ + mCalendarSubTypes << "application/x-vnd.akonadi.calendar.event" + << "application/x-vnd.akonadi.calendar.todo"; +} + +void MimeTypeCheckerTest::initTestCase() +{ + MimeTypeChecker emptyChecker; + MimeTypeChecker calendarChecker; + MimeTypeChecker subTypeChecker; + MimeTypeChecker aliasChecker; + + // for testing reset through assignments + const QLatin1String textPlain = QLatin1String( "text/plain" ); + mEmptyChecker.addWantedMimeType( textPlain ); + QVERIFY( !mEmptyChecker.wantedMimeTypes().isEmpty() ); + + const QLatin1String textCalendar = QLatin1String( "text/calendar" ); + calendarChecker.addWantedMimeType( textCalendar ); + QCOMPARE( calendarChecker.wantedMimeTypes().count(), 1 ); + + subTypeChecker.setWantedMimeTypes( mCalendarSubTypes ); + QCOMPARE( subTypeChecker.wantedMimeTypes().count(), 2 ); + + const QLatin1String textVCard = QLatin1String( "text/directory" ); + aliasChecker.addWantedMimeType( textVCard ); + QCOMPARE( aliasChecker.wantedMimeTypes().count(), 1 ); + + // test assignment works correctly + mEmptyChecker = emptyChecker; + mCalendarChecker = calendarChecker; + mSubTypeChecker = subTypeChecker; + mAliasChecker = aliasChecker; + + QVERIFY( mEmptyChecker.wantedMimeTypes().isEmpty() ); + + QCOMPARE( mCalendarChecker.wantedMimeTypes().count(), 1 ); + QCOMPARE( mCalendarChecker.wantedMimeTypes(), QStringList() << textCalendar ); + + QCOMPARE( mSubTypeChecker.wantedMimeTypes().count(), 2 ); + const QSet calendarSubTypes = QSet::fromList( mCalendarSubTypes ); + const QSet wantedSubTypes = QSet::fromList( mSubTypeChecker.wantedMimeTypes() ); + QCOMPARE( wantedSubTypes, calendarSubTypes ); + + QCOMPARE( mAliasChecker.wantedMimeTypes().count(), 1 ); + QCOMPARE( mAliasChecker.wantedMimeTypes(), QStringList() << textVCard ); +} + +void MimeTypeCheckerTest::testCollectionCheck() +{ + Collection invalidCollection; + Collection emptyCollection( 1 ); + Collection calendarCollection( 2 ); + Collection eventCollection( 3 ); + Collection journalCollection( 4 ); + Collection vcardCollection( 5 ); + Collection aliasCollection( 6 ); + + const QLatin1String textCalendar = QLatin1String( "text/calendar" ); + calendarCollection.setContentMimeTypes( QStringList() << textCalendar); + const QLatin1String akonadiEvent = QLatin1String( "application/x-vnd.akonadi.calendar.event" ); + eventCollection.setContentMimeTypes( QStringList() << akonadiEvent ); + journalCollection.setContentMimeTypes( QStringList() << QLatin1String( "application/x-vnd.akonadi.calendar.journal" ) ); + const QLatin1String textDirectory = QLatin1String( "text/directory" ); + vcardCollection.setContentMimeTypes( QStringList() << textDirectory ); + aliasCollection.setContentMimeTypes( QStringList() << QLatin1String( "text/x-vcard" ) ); + + Collection::List voidCollections; + voidCollections << invalidCollection << emptyCollection; + + Collection::List subTypeCollections; + subTypeCollections << eventCollection << journalCollection; + + Collection::List calendarCollections = subTypeCollections; + calendarCollections << calendarCollection; + + Collection::List contactCollections; + contactCollections << vcardCollection << aliasCollection; + + //// empty checker fails for all + Collection::List collections = voidCollections + calendarCollections + contactCollections; + foreach ( const Collection &collection, collections ) { + QVERIFY( !mEmptyChecker.isWantedCollection( collection ) ); + QVERIFY( !MimeTypeChecker::isWantedCollection( collection, QString() ) ); + } + + //// calendar checker fails for void and contact collections + collections = voidCollections + contactCollections; + foreach ( const Collection &collection, collections ) { + QVERIFY( !mCalendarChecker.isWantedCollection( collection ) ); + QVERIFY( !MimeTypeChecker::isWantedCollection( collection, textCalendar ) ); + } + + // but accepts all calendar collections + collections = calendarCollections; + foreach ( const Collection &collection, collections ) { + QVERIFY( mCalendarChecker.isWantedCollection( collection ) ); + QVERIFY( MimeTypeChecker::isWantedCollection( collection, textCalendar ) ); + } + + //// sub type checker fails for all but the event collection + collections = voidCollections + calendarCollections + contactCollections; + collections.removeAll( eventCollection ); + foreach ( const Collection &collection, collections ) { + QVERIFY( !mSubTypeChecker.isWantedCollection( collection ) ); + QVERIFY( !MimeTypeChecker::isWantedCollection( collection, akonadiEvent ) ); + } + + // but accepts the event collection + collections = Collection::List() << eventCollection; + foreach ( const Collection &collection, collections ) { + QVERIFY( mSubTypeChecker.isWantedCollection( collection ) ); + QVERIFY( MimeTypeChecker::isWantedCollection( collection, akonadiEvent ) ); + } + + //// alias checker fails for void and calendar collections + collections = voidCollections + calendarCollections; + foreach ( const Collection &collection, collections ) { + QVERIFY( !mAliasChecker.isWantedCollection( collection ) ); + QVERIFY( !MimeTypeChecker::isWantedCollection( collection, textDirectory ) ); + } + + // but accepts all contact collections + collections = contactCollections; + foreach ( const Collection &collection, collections ) { + QVERIFY( mAliasChecker.isWantedCollection( collection ) ); + QVERIFY( MimeTypeChecker::isWantedCollection( collection, textDirectory ) ); + } +} + +void MimeTypeCheckerTest::testItemCheck() +{ + Item invalidItem; + Item emptyItem( 1 ); + Item calendarItem( 2 ); + Item eventItem( 3 ); + Item journalItem( 4 ); + Item vcardItem( 5 ); + Item aliasItem( 6 ); + + const QLatin1String textCalendar = QLatin1String( "text/calendar" ); + calendarItem.setMimeType( textCalendar ); + const QLatin1String akonadiEvent = QLatin1String( "application/x-vnd.akonadi.calendar.event" ); + eventItem.setMimeType( akonadiEvent ); + journalItem.setMimeType( QLatin1String( "application/x-vnd.akonadi.calendar.journal" ) ); + const QLatin1String textDirectory = QLatin1String( "text/directory" ); + vcardItem.setMimeType( textDirectory ); + aliasItem.setMimeType( QLatin1String( "text/x-vcard" ) ); + + Item::List voidItems; + voidItems << invalidItem << emptyItem; + + Item::List subTypeItems; + subTypeItems << eventItem << journalItem; + + Item::List calendarItems = subTypeItems; + calendarItems << calendarItem; + + Item::List contactItems; + contactItems << vcardItem << aliasItem; + + //// empty checker fails for all + Item::List items = voidItems + calendarItems + contactItems; + foreach ( const Item &item, items ) { + QVERIFY( !mEmptyChecker.isWantedItem( item ) ); + QVERIFY( !MimeTypeChecker::isWantedItem( item, QString() ) ); + } + + //// calendar checker fails for void and contact items + items = voidItems + contactItems; + foreach ( const Item &item, items ) { + QVERIFY( !mCalendarChecker.isWantedItem( item ) ); + QVERIFY( !MimeTypeChecker::isWantedItem( item, textCalendar ) ); + } + + // but accepts all calendar items + items = calendarItems; + foreach ( const Item &item, items ) { + QVERIFY( mCalendarChecker.isWantedItem( item ) ); + QVERIFY( MimeTypeChecker::isWantedItem( item, textCalendar ) ); + } + + //// sub type checker fails for all but the event item + items = voidItems + calendarItems + contactItems; + items.removeAll( eventItem ); + foreach ( const Item &item, items ) { + QVERIFY( !mSubTypeChecker.isWantedItem( item ) ); + QVERIFY( !MimeTypeChecker::isWantedItem( item, akonadiEvent ) ); + } + + // but accepts the event item + items = Item::List() << eventItem; + foreach ( const Item &item, items ) { + QVERIFY( mSubTypeChecker.isWantedItem( item ) ); + QVERIFY( MimeTypeChecker::isWantedItem( item, akonadiEvent ) ); + } + + //// alias checker fails for void and calendar items + items = voidItems + calendarItems; + foreach ( const Item &item, items ) { + QVERIFY( !mAliasChecker.isWantedItem( item ) ); + QVERIFY( !MimeTypeChecker::isWantedItem( item, textDirectory ) ); + } + + // but accepts all contact items + items = contactItems; + foreach ( const Item &item, items ) { + QVERIFY( mAliasChecker.isWantedItem( item ) ); + QVERIFY( MimeTypeChecker::isWantedItem( item, textDirectory ) ); + } +} + +#include "mimetypecheckertest.moc" +// kate: space-indent on; indent-width 2; replace-tabs on; diff --git a/akonadi/tests/mimetypecheckertest.h b/akonadi/tests/mimetypecheckertest.h new file mode 100644 index 000000000..59c8811a0 --- /dev/null +++ b/akonadi/tests/mimetypecheckertest.h @@ -0,0 +1,50 @@ +/* + Copyright (c) 2009 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 AKONADI_MIMETYPECHECKERTEST_H +#define AKONADI_MIMETYPECHECKERTEST_H + +#include "akonadi/mimetypechecker.h" + +#include +#include + +class MimeTypeCheckerTest : public QObject +{ + Q_OBJECT + public: + explicit MimeTypeCheckerTest( QObject *parent = 0 ); + + private: + QStringList mCalendarSubTypes; + + Akonadi::MimeTypeChecker mEmptyChecker; + Akonadi::MimeTypeChecker mCalendarChecker; + Akonadi::MimeTypeChecker mSubTypeChecker; + Akonadi::MimeTypeChecker mAliasChecker; + + private slots: + void initTestCase(); + void testCollectionCheck(); + void testItemCheck(); +}; + + +#endif +// kate: space-indent on; indent-width 2; replace-tabs on;