diff --git a/akonadi/CMakeLists.txt b/akonadi/CMakeLists.txt index 2954a6d79..e28f9b93d 100644 --- a/akonadi/CMakeLists.txt +++ b/akonadi/CMakeLists.txt @@ -1,220 +1,224 @@ 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 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 monitor.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/collectiondialog.cpp b/akonadi/collectiondialog.cpp new file mode 100644 index 000000000..cdb7f0428 --- /dev/null +++ b/akonadi/collectiondialog.cpp @@ -0,0 +1,129 @@ +/* + Copyright 2008 Ingo Klöcker + + 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 "collectiondialog.h" + +#include +#include +#include + +#include + +using namespace Akonadi; + +class CollectionDialog::Private +{ + public: + Private(); + + CollectionModel *collectionModel; + CollectionFilterProxyModel *filterModel; + CollectionView *collectionView; +}; + +CollectionDialog::Private::Private() + : collectionModel( 0 ) + , filterModel( 0 ) + , collectionView( 0 ) +{ +} + + +CollectionDialog::CollectionDialog( QWidget *parent ) + : KDialog( parent ) + , d( new Private ) +{ + QWidget *w = mainWidget(); + + QVBoxLayout *l = new QVBoxLayout( w ); + + d->collectionModel = new CollectionModel( this ); + + d->filterModel = new CollectionFilterProxyModel( this ); + d->filterModel->setDynamicSortFilter( true ); + d->filterModel->setSortCaseSensitivity( Qt::CaseInsensitive ); + d->filterModel->setSourceModel( d->collectionModel ); + + d->collectionView = new CollectionView( w ); + d->collectionView->setModel( d->filterModel ); + l->addWidget( d->collectionView ); +} + +CollectionDialog::~CollectionDialog() +{ + delete d; +} + +Akonadi::Collection CollectionDialog::selectedCollection() const +{ + if ( selectionMode() == QAbstractItemView::SingleSelection ) + { + const QModelIndex index = d->collectionView->currentIndex(); + if ( index.isValid() ) + { + Collection col = index.model()->data( index, + CollectionModel::CollectionRole ).value(); + return col; + } + } + return Collection(); +} + +Akonadi::Collection::List CollectionDialog::selectedCollections() const +{ + Collection::List collections; + const QItemSelectionModel *selectionModel = d->collectionView->selectionModel(); + const QModelIndexList selectedIndexes = selectionModel->selectedIndexes(); + foreach ( const QModelIndex &index, selectedIndexes ) + { + if ( index.isValid() ) + { + Collection col = index.model()->data( index, + CollectionModel::CollectionRole ).value(); + if ( col.isValid() ) + { + collections.append( col ); + } + } + } + return collections; +} + +void CollectionDialog::setMimeTypeFilter( const QStringList &mimeTypes ) +{ + d->filterModel->clearFilters(); + d->filterModel->addMimeTypeFilters( mimeTypes ); +} + +QStringList CollectionDialog::mimeTypeFilter() const +{ + return d->filterModel->mimeTypeFilters(); +} + +void CollectionDialog::setSelectionMode( QAbstractItemView::SelectionMode mode ) +{ + d->collectionView->setSelectionMode( mode ); +} + +QAbstractItemView::SelectionMode CollectionDialog::selectionMode() const +{ + return d->collectionView->selectionMode(); +} + +#include "collectiondialog.moc" diff --git a/akonadi/collectiondialog.h b/akonadi/collectiondialog.h new file mode 100644 index 000000000..1796c4573 --- /dev/null +++ b/akonadi/collectiondialog.h @@ -0,0 +1,101 @@ +/* + Copyright 2008 Ingo Klöcker + + 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_COLLECTIONDIALOG_H +#define AKONADI_COLLECTIONDIALOG_H + +#include "akonadi_export.h" + +#include + +#include + +#include + +namespace Akonadi { + +/** + * @short A collection selection dialog. + * + * Provides a user (and developer) friendly way to select collections. + * + * @author Ingo Klöcker + * @since 4.3 + */ +class AKONADI_EXPORT CollectionDialog : public KDialog +{ + Q_OBJECT + Q_DISABLE_COPY( CollectionDialog ) + + public: + + /** + * Constructs a CollectionRequester widget. + */ + explicit CollectionDialog( QWidget *parent = 0 ); + + /** + * Destructs the CollectionRequester. + */ + ~CollectionDialog(); + + /** + * @returns The selected collection. + */ + Akonadi::Collection selectedCollection() const; + + /** + * @returns The list of selected collections. + */ + Akonadi::Collection::List selectedCollections() const; + + /** + * Sets the mime types any of which the selected collection(s) shall support. + * @see Akonadi::CollectionDialog::setMimeTypeFilter() + */ + void setMimeTypeFilter( const QStringList &mimeTypes ); + + /** + * @returns the mime types any of which the selected collection(s) shall support. + * @see Akonadi::CollectionDialog::mimeTypeFilter() + */ + QStringList mimeTypeFilter() const; + + /** + * Sets the selection mode. + * @see QAbstractItemView::setSelectionMode() + */ + void setSelectionMode( QAbstractItemView::SelectionMode mode ); + + /** + * @returns The selection mode. + * @see QAbstractItemView::selectionMode() + */ + QAbstractItemView::SelectionMode selectionMode() const; + + + private: + class Private; + Private * const d; + +}; + +} // namespace Akonadi + +#endif // AKONADI_COLLECTIONDIALOG_H diff --git a/akonadi/collectionrequester.cpp b/akonadi/collectionrequester.cpp new file mode 100644 index 000000000..3e3d66c5d --- /dev/null +++ b/akonadi/collectionrequester.cpp @@ -0,0 +1,159 @@ +/* + Copyright 2008 Ingo Klöcker + + 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 "collectionrequester.h" +#include "collectiondialog.h" + +#include +#include +#include +#include + +#include +#include +#include + +using namespace Akonadi; + +class CollectionRequester::Private +{ +public: + Private( CollectionRequester *parent ) + : q( parent ) + , edit( 0 ) + , button( 0 ) + , collectionDialog( 0 ) + { + } + + ~Private() + { + } + + void init(); + + // slots + void _k_slotOpenDialog(); + + CollectionRequester *q; + Collection collection; + KLineEdit *edit; + KPushButton *button; + CollectionDialog *collectionDialog; +}; + + +void CollectionRequester::Private::init() +{ + q->setMargin( 0 ); + + edit = new KLineEdit( q ); + edit->setReadOnly( true ); + edit->setClearButtonShown( false ); + + button = new KPushButton( q ); + button->setIcon( KIcon( QLatin1String("document-open") ) ); + const int buttonSize = edit->sizeHint().height(); + button->setFixedSize( buttonSize, buttonSize ); + button->setToolTip( i18n("Open collection dialog") ); + + q->setSpacing( KDialog::spacingHint() ); + + edit->installEventFilter( q ); + q->setFocusProxy( edit ); + q->setFocusPolicy( Qt::StrongFocus ); + + q->connect( button, SIGNAL(clicked()), q, SLOT(_k_slotOpenDialog()) ); + + QAction *openAction = new QAction( q ); + openAction->setShortcut( KStandardShortcut::Open ); + q->connect( openAction, SIGNAL(triggered(bool)), q, SLOT(_k_slotOpenDialog()) ); + + collectionDialog = new CollectionDialog( q ); + collectionDialog->setSelectionMode( QAbstractItemView::SingleSelection ); +} + +void CollectionRequester::Private::_k_slotOpenDialog() +{ + CollectionDialog *dlg = collectionDialog; + + if ( dlg->exec() != QDialog::Accepted ) + { + return; + } + + q->setCollection( dlg->selectedCollection() ); +} + +CollectionRequester::CollectionRequester( QWidget *parent ) + : KHBox( parent ) + , d( new Private( this ) ) +{ + d->init(); +} + + +CollectionRequester::CollectionRequester( const Akonadi::Collection &col, QWidget *parent ) + : KHBox( parent ) + , d( new Private( this ) ) +{ + d->init(); + setCollection( col ); +} + + +CollectionRequester::~CollectionRequester() +{ + delete d; +} + + +Collection CollectionRequester::collection() const +{ + return d->collection; +} + + +void CollectionRequester::setCollection( const Collection& col ) +{ + d->collection = col; + d->edit->setText( col.isValid() ? col.name() : i18n("no collection") ); +} + +void CollectionRequester::setMimeTypeFilter( const QStringList &mimeTypes ) +{ + if ( d->collectionDialog ) + { + d->collectionDialog->setMimeTypeFilter( mimeTypes ); + } +} + +QStringList CollectionRequester::mimeTypeFilter() const +{ + if ( d->collectionDialog ) + { + return d->collectionDialog->mimeTypeFilter(); + } + else + { + return QStringList(); + } +} + +#include "collectionrequester.moc" diff --git a/akonadi/collectionrequester.h b/akonadi/collectionrequester.h new file mode 100644 index 000000000..a445e9361 --- /dev/null +++ b/akonadi/collectionrequester.h @@ -0,0 +1,97 @@ +/* + Copyright 2008 Ingo Klöcker + + 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_COLLECTIONREQUESTER_H +#define AKONADI_COLLECTIONREQUESTER_H + +#include "akonadi_export.h" + +#include + +#include + +namespace Akonadi { + +/** + * @short A widget to request an Akonadi collection from the user. + * + * This class is a widget showing a read-only lineedit displaying + * the currently chosen collection and a button invoking a dialog + * for choosing a collection. + * + * @author Ingo Klöcker + * @since 4.3 + */ +class AKONADI_EXPORT CollectionRequester : public KHBox +{ + Q_OBJECT + Q_DISABLE_COPY(CollectionRequester) + +public: + /** + * Constructs a CollectionRequester widget. + */ + explicit CollectionRequester( QWidget *parent = 0 ); + + /** + * Constructs a CollectionRequester widget with initial collection @p col. + */ + explicit CollectionRequester( const Akonadi::Collection &col, QWidget *parent = 0 ); + + /** + * Destructs the CollectionRequester. + */ + ~CollectionRequester(); + + /** + * @returns the currently chosen collection. The collection may be invalid. + */ + Akonadi::Collection collection() const; + + /** + * Sets the mime types any of which the selected collection shall support. + * @see Akonadi::CollectionDialog::setMimeTypeFilter() + */ + void setMimeTypeFilter( const QStringList &mimeTypes ); + + /** + * @returns the mime types any of which the selected collection shall support. + * @see Akonadi::CollectionDialog::mimeTypeFilter() + */ + QStringList mimeTypeFilter() const; + + +public Q_SLOTS: + /** + * Sets the collection in the requester to @p col. + */ + void setCollection( const Akonadi::Collection& col ); + + +private: + class Private; + Private * const d; + + Q_PRIVATE_SLOT(d, void _k_slotOpenDialog()) + +}; + +} // namespace Akonadi + +#endif // AKONADI_COLLECTIONREQUESTER_H