File indexing completed on 2024-05-26 05:14:41

0001 /*
0002     SPDX-FileCopyrightText: 2008 Ingo Klöcker <kloecker@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "akonadiwidgets_export.h"
0010 #include "collectiondialog.h"
0011 // AkonadiCore
0012 #include "akonadi/collection.h"
0013 
0014 #include <QWidget>
0015 
0016 #include <memory>
0017 
0018 namespace Akonadi
0019 {
0020 class CollectionRequesterPrivate;
0021 
0022 /**
0023  * @short A widget to request an Akonadi collection from the user.
0024  *
0025  * This class is a widget showing a read-only lineedit displaying
0026  * the currently chosen collection and a button invoking a dialog
0027  * for choosing a collection.
0028  *
0029  * Example:
0030  *
0031  * @code
0032  *
0033  * // create a collection requester to select a collection of contacts
0034  * Akonadi::CollectionRequester requester( Akonadi::Collection::root(), this );
0035  * requester.setMimeTypeFilter( QStringList() << QString( "text/directory" ) );
0036  *
0037  * ...
0038  *
0039  * const Akonadi::Collection collection = requester.collection();
0040  * if ( collection.isValid() ) {
0041  *   ...
0042  * }
0043  *
0044  * @endcode
0045  *
0046  * @author Ingo Klöcker <kloecker@kde.org>
0047  * @since 4.3
0048  */
0049 class AKONADIWIDGETS_EXPORT CollectionRequester : public QWidget
0050 {
0051     Q_OBJECT
0052     Q_DISABLE_COPY(CollectionRequester)
0053 
0054 public:
0055     /**
0056      * Creates a collection requester.
0057      *
0058      * @param parent The parent widget.
0059      */
0060     explicit CollectionRequester(QWidget *parent = nullptr);
0061 
0062     /**
0063      * Creates a collection requester with an initial @p collection.
0064      *
0065      * @param collection The initial collection.
0066      * @param parent The parent widget.
0067      */
0068     explicit CollectionRequester(const Akonadi::Collection &collection, QWidget *parent = nullptr);
0069 
0070     /**
0071      * Destroys the collection requester.
0072      */
0073     ~CollectionRequester() override;
0074 
0075     /**
0076      * Returns the currently chosen collection, or an empty collection if none
0077      * none was chosen.
0078      */
0079     [[nodiscard]] Akonadi::Collection collection() const;
0080 
0081     /**
0082      * Sets the mime types any of which the selected collection shall support.
0083      */
0084     void setMimeTypeFilter(const QStringList &mimeTypes);
0085 
0086     /**
0087      * Returns the mime types any of which the selected collection shall support.
0088      */
0089     [[nodiscard]] QStringList mimeTypeFilter() const;
0090 
0091     /**
0092      * Sets the access @p rights that the listed collections shall match with.
0093      * @param rights the access rights to set
0094      * @since 4.4
0095      */
0096     void setAccessRightsFilter(Collection::Rights rights);
0097 
0098     /**
0099      * Returns the access rights that the listed collections shall match with.
0100      * @since 4.4
0101      */
0102     [[nodiscard]] Collection::Rights accessRightsFilter() const;
0103 
0104     /**
0105      * @param options new collection dialog options
0106      */
0107     void changeCollectionDialogOptions(CollectionDialog::CollectionDialogOptions options);
0108 
0109     /**
0110      * Allow to specify collection content mimetype when we create new one.
0111      * @since 4.14.6
0112      */
0113     void setContentMimeTypes(const QStringList &mimetypes);
0114 
0115 protected:
0116     void changeEvent(QEvent *event) override;
0117 
0118 public Q_SLOTS:
0119     /**
0120      * Sets the @p collection of the requester.
0121      */
0122     void setCollection(const Akonadi::Collection &collection);
0123 
0124 Q_SIGNALS:
0125     /**
0126      * This signal is emitted when the selected collection has changed.
0127      *
0128      * @param collection The selected collection.
0129      *
0130      * @since 4.5
0131      */
0132     void collectionChanged(const Akonadi::Collection &collection);
0133 
0134 private:
0135     std::unique_ptr<CollectionRequesterPrivate> const d;
0136 };
0137 
0138 } // namespace Akonadi