File indexing completed on 2025-01-05 04:47:07
0001 /* 0002 SPDX-FileCopyrightText: 2008 Ingo Klöcker <kloecker@kde.org> 0003 SPDX-FileCopyrightText: 2010-2024 Laurent Montel <montel@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include "akonadiwidgets_export.h" 0011 // AkonadiCore 0012 #include "akonadi/collection.h" 0013 0014 #include <QAbstractItemView> 0015 #include <QDialog> 0016 0017 #include <memory> 0018 0019 namespace Akonadi 0020 { 0021 class CollectionDialogPrivate; 0022 0023 /** 0024 * @short A collection selection dialog. 0025 * 0026 * Provides a dialog that lists collections that are available 0027 * on the Akonadi storage and allows the selection of one or multiple 0028 * collections. 0029 * 0030 * The list of shown collections can be filtered by mime type and access 0031 * rights. Note that mime types are not enabled by default, so 0032 * setMimeTypeFilter() must be called to enable the desired mime types. 0033 * 0034 * Example: 0035 * 0036 * @code 0037 * 0038 * using namespace Akonadi; 0039 * 0040 * // Show the user a dialog to select a writable collection of contacts 0041 * CollectionDialog dlg( this ); 0042 * dlg.setMimeTypeFilter( QStringList() << KContacts::Addressee::mimeType() ); 0043 * dlg.setAccessRightsFilter( Collection::CanCreateItem ); 0044 * dlg.setDescription( i18n( "Select an address book for saving:" ) ); 0045 * 0046 * if ( dlg.exec() ) { 0047 * const Collection collection = dlg.selectedCollection(); 0048 * ... 0049 * } 0050 * 0051 * @endcode 0052 * 0053 * @author Ingo Klöcker <kloecker@kde.org> 0054 * @since 4.3 0055 */ 0056 class AKONADIWIDGETS_EXPORT CollectionDialog : public QDialog 0057 { 0058 Q_OBJECT 0059 Q_DISABLE_COPY(CollectionDialog) 0060 0061 public: 0062 /* @since 4.6 0063 */ 0064 enum CollectionDialogOption { 0065 None = 0, 0066 AllowToCreateNewChildCollection = 1, 0067 KeepTreeExpanded = 2, 0068 }; 0069 0070 Q_DECLARE_FLAGS(CollectionDialogOptions, CollectionDialogOption) 0071 0072 /** 0073 * Creates a new collection dialog. 0074 * 0075 * @param parent The parent widget. 0076 */ 0077 explicit CollectionDialog(QWidget *parent = nullptr); 0078 0079 /** 0080 * Creates a new collection dialog with a custom @p model. 0081 * 0082 * The filtering by content mime type and access rights is done 0083 * on top of the custom model. 0084 * 0085 * @param model The custom model to use. 0086 * @param parent The parent widget. 0087 * 0088 * @since 4.4 0089 */ 0090 explicit CollectionDialog(QAbstractItemModel *model, QWidget *parent = nullptr); 0091 0092 /** 0093 * Creates a new collection dialog with a custom @p model. 0094 * 0095 * The filtering by content mime type and access rights is done 0096 * on top of the custom model. 0097 * 0098 * @param options The collection dialog options. 0099 * @param model The custom model to use. 0100 * @param parent The parent widget. 0101 * 0102 * @since 4.6 0103 */ 0104 0105 explicit CollectionDialog(CollectionDialogOptions options, QAbstractItemModel *model = nullptr, QWidget *parent = nullptr); 0106 0107 /** 0108 * Destroys the collection dialog. 0109 */ 0110 ~CollectionDialog() override; 0111 0112 /** 0113 * Sets the mime types any of which the selected collection(s) shall support. 0114 * Note that mime types are not enabled by default. 0115 * @param mimeTypes MIME type filter values 0116 */ 0117 void setMimeTypeFilter(const QStringList &mimeTypes); 0118 0119 /** 0120 * Returns the mime types any of which the selected collection(s) shall support. 0121 */ 0122 [[nodiscard]] QStringList mimeTypeFilter() const; 0123 0124 /** 0125 * Sets the access @p rights that the listed collections shall match with. 0126 * @param rights access rights filter values 0127 * @since 4.4 0128 */ 0129 void setAccessRightsFilter(Collection::Rights rights); 0130 0131 /** 0132 * Sets the access @p rights that the listed collections shall match with. 0133 * 0134 * @since 4.4 0135 */ 0136 [[nodiscard]] Collection::Rights accessRightsFilter() const; 0137 0138 /** 0139 * Sets the @p text that will be shown in the dialog. 0140 * @param text the dialog's description text 0141 * @since 4.4 0142 */ 0143 void setDescription(const QString &text); 0144 0145 /** 0146 * Sets the @p collection that shall be selected by default. 0147 * @param collection the dialog's pre-selected collection 0148 * @since 4.4 0149 */ 0150 void setDefaultCollection(const Collection &collection); 0151 0152 /** 0153 * Sets the selection mode. The initial default mode is 0154 * QAbstractItemView::SingleSelection. 0155 * @param mode the selection mode to use 0156 * @see QAbstractItemView::setSelectionMode() 0157 */ 0158 void setSelectionMode(QAbstractItemView::SelectionMode mode); 0159 0160 /** 0161 * Returns the selection mode. 0162 * @see QAbstractItemView::selectionMode() 0163 */ 0164 [[nodiscard]] QAbstractItemView::SelectionMode selectionMode() const; 0165 0166 /** 0167 * Returns the selected collection if the selection mode is 0168 * QAbstractItemView::SingleSelection. If another selection mode was set, 0169 * or nothing is selected, an invalid collection is returned. 0170 */ 0171 [[nodiscard]] Akonadi::Collection selectedCollection() const; 0172 0173 /** 0174 * Returns the list of selected collections. 0175 */ 0176 [[nodiscard]] Akonadi::Collection::List selectedCollections() const; 0177 0178 /** 0179 * Change collection dialog options. 0180 * @param options the collection dialog options to change 0181 * @since 4.6 0182 */ 0183 void changeCollectionDialogOptions(CollectionDialogOptions options); 0184 0185 /** 0186 * @since 4.13 0187 */ 0188 void setUseFolderByDefault(bool b); 0189 /** 0190 * @since 4.13 0191 */ 0192 [[nodiscard]] bool useFolderByDefault() const; 0193 /** 0194 * Allow to specify collection content mimetype when we create new one. 0195 * @since 4.14.6 0196 */ 0197 void setContentMimeTypes(const QStringList &mimetypes); 0198 0199 private: 0200 /// @cond PRIVATE 0201 std::unique_ptr<CollectionDialogPrivate> const d; 0202 /// @endcond 0203 }; 0204 0205 } // namespace Akonadi