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

0001 /*
0002     SPDX-FileCopyrightText: 2008 Volker Krause <vkrause@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 "collectionpropertiespage.h"
0011 
0012 #include <QDialog>
0013 
0014 #include <memory>
0015 
0016 namespace Akonadi
0017 {
0018 class Collection;
0019 class CollectionPropertiesDialogPrivate;
0020 
0021 /**
0022  * @short A generic and extensible dialog for collection properties.
0023  *
0024  * This dialog allows you to show or modify the properties of a collection.
0025  *
0026  * @code
0027  *
0028  * Akonadi::Collection collection = ...
0029  *
0030  * CollectionPropertiesDialog dlg( collection, this );
0031  * dlg.exec();
0032  *
0033  * @endcode
0034  *
0035  * It can be extended by custom pages, which contains gui elements for custom
0036  * properties.
0037  *
0038  * @see Akonadi::CollectionPropertiesPage
0039  *
0040  * @author Volker Krause <vkrause@kde.org>
0041  */
0042 class AKONADIWIDGETS_EXPORT CollectionPropertiesDialog : public QDialog
0043 {
0044     Q_OBJECT
0045 public:
0046     /**
0047      * Enumerates the registered default pages which can be displayed.
0048      *
0049      * @since 4.7
0050      */
0051     enum DefaultPage {
0052         GeneralPage, //!< General properties page
0053         CachePage //!< Cache properties page
0054     };
0055 
0056     /**
0057      * Creates a new collection properties dialog.
0058      *
0059      * @param collection The collection which properties should be shown.
0060      * @param parent The parent widget.
0061      */
0062     explicit CollectionPropertiesDialog(const Collection &collection, QWidget *parent = nullptr);
0063 
0064     /**
0065      * Creates a new collection properties dialog.
0066      *
0067      * This constructor allows to specify the subset of registered pages that will
0068      * be shown as well as their order. The pages have to set an objectName in their
0069      * constructor to make it work. If an empty list is passed, all registered pages
0070      * will be loaded. Use defaultPageObjectName() to fetch the object name for a
0071      * registered default page.
0072      *
0073      * @param collection The collection which properties should be shown.
0074      * @param pages The object names of the pages that shall be loaded.
0075      * @param parent The parent widget.
0076      *
0077      * @since 4.6
0078      */
0079     CollectionPropertiesDialog(const Collection &collection, const QStringList &pages, QWidget *parent = nullptr);
0080 
0081     /**
0082      * Destroys the collection properties dialog.
0083      *
0084      * @note Never call manually, the dialog is deleted automatically once all changes
0085      *       are written back to the Akonadi storage.
0086      */
0087     ~CollectionPropertiesDialog() override;
0088 
0089     /**
0090      * Register custom pages for the collection properties dialog.
0091      *
0092      * @param factory The properties page factory that provides the custom page.
0093      *
0094      * @see Akonadi::CollectionPropertiesPageFactory
0095      */
0096     static void registerPage(CollectionPropertiesPageFactory *factory);
0097 
0098     /**
0099      * Sets whether to @p use default page or not.
0100      *
0101      * @since 4.4
0102      * @param use mode of default page's usage
0103      */
0104     static void useDefaultPage(bool use);
0105 
0106     /**
0107      * Returns the object name of one of the dialog's registered default pages.
0108      * The object name may be used in the QStringList constructor parameter to
0109      * specify which default pages should be shown.
0110      *
0111      * @param page the desired page
0112      * @return the page's object name
0113      *
0114      * @since 4.7
0115      */
0116     [[nodiscard]] static QString defaultPageObjectName(DefaultPage page);
0117 
0118     /**
0119      * Sets the page to be shown in the tab widget.
0120      *
0121      * @param name The object name of the page that is to be shown.
0122      *
0123      * @since 4.10
0124      */
0125     void setCurrentPage(const QString &name);
0126 
0127 Q_SIGNALS:
0128     void settingsSaved();
0129 
0130 private:
0131     /// @cond PRIVATE
0132     std::unique_ptr<CollectionPropertiesDialogPrivate> const d;
0133     /// @endcond
0134 };
0135 
0136 }