File indexing completed on 2024-06-09 05:18:06

0001 /*
0002  * SPDX-FileCopyrightText: 2004 Carsten Burghardt <burghardt@kde.org>
0003  *
0004  * SPDX-License-Identifier: GPL-2.0-only
0005  */
0006 
0007 #pragma once
0008 
0009 #include "mailcommon_export.h"
0010 
0011 #include <Akonadi/Collection>
0012 
0013 #include <QWidget>
0014 
0015 class QKeyEvent;
0016 
0017 class KJob;
0018 
0019 namespace MailCommon
0020 {
0021 /**
0022  * A widget that contains a QLineEdit which shows the current folder
0023  * and a button that fires a FolderSelectionDialog
0024  * The dialog is set to disable readonly folders by default
0025  * Search folders are excluded
0026  *
0027  * @todo This should be cleaned up and go into libakonadi. This includes:
0028  * - s/Folder/Collection/g
0029  * - Use Akonadi::CollectionDialog instead of MailCommon::FolderSelectionDialog
0030  *  - merge that into CollectionDialog
0031  *  - or allow to replace the built-in dialog by your own
0032  * - Allow to pass in an existing ETM, to remove the Kernel dependency
0033  */
0034 class FolderRequesterPrivate;
0035 class MAILCOMMON_EXPORT FolderRequester : public QWidget
0036 {
0037     Q_OBJECT
0038 
0039 public:
0040     /**
0041      * Constructor
0042      * @param parent the parent widget
0043      */
0044     explicit FolderRequester(QWidget *parent = nullptr);
0045     ~FolderRequester() override;
0046 
0047     /**
0048      * Returns the selected collection.
0049      */
0050     [[nodiscard]] Akonadi::Collection collection() const;
0051 
0052     /**
0053      * Presets the folder to the collection @p collection.
0054      * Disable fetchcollection when not necessary @p fetchCollection
0055      */
0056     void setCollection(const Akonadi::Collection &collection, bool fetchCollection = true);
0057 
0058     /**
0059      * Returns @c true if there's a valid collection set on this widget.
0060      */
0061     [[nodiscard]] bool hasCollection() const;
0062 
0063     /**
0064      * Sets if readonly folders should be disabled.
0065      * Be aware that if you disable this the user can also select the
0066      * 'Local Folders' folder which has no valid folder associated
0067      */
0068     void setMustBeReadWrite(bool readwrite);
0069 
0070     void setShowOutbox(bool show);
0071 
0072     void setNotAllowToCreateNewFolder(bool notCreateNewFolder);
0073 
0074     void setSelectFolderTitleDialog(const QString &title);
0075 
0076 protected Q_SLOTS:
0077     /**
0078      * Opens the folder dialog.
0079      */
0080     void slotOpenDialog();
0081 
0082     /**
0083      * Updates the information we have about the current folder.
0084      */
0085     void slotCollectionsReceived(KJob *);
0086 
0087 Q_SIGNALS:
0088     /**
0089      * Emitted when the folder changed.
0090      */
0091     void folderChanged(const Akonadi::Collection &);
0092     void invalidFolder();
0093 
0094 protected:
0095     /** Capture space key to open the dialog */
0096     void keyPressEvent(QKeyEvent *e) override;
0097     void setCollectionFullPath(const Akonadi::Collection &col);
0098 
0099 protected:
0100     std::unique_ptr<FolderRequesterPrivate> const d;
0101 };
0102 }