File indexing completed on 2025-01-05 04:49:29

0001 /*
0002    SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QObject>
0010 
0011 #include <memory>
0012 
0013 class QAbstractItemModel;
0014 class QItemSelectionModel;
0015 class QuicktextManagerPrivate;
0016 namespace MailCommon
0017 {
0018 class SnippetsModel;
0019 }
0020 class QuicktextManager : public QObject
0021 {
0022     Q_OBJECT
0023 public:
0024     /**
0025      * Creates a new snippets manager.
0026      *
0027      * @param parent The parent object.
0028      * @param widget The widget.
0029      */
0030     explicit QuicktextManager(QObject *parent = nullptr, QWidget *widget = nullptr);
0031 
0032     /**
0033      * Destroys the snippets manager.
0034      */
0035     ~QuicktextManager() override;
0036     /**
0037      * Returns the model that represents the snippets.
0038      */
0039     QAbstractItemModel *model() const;
0040 
0041     /**
0042      * Returns the selection model that is used by the manager to select the
0043      * snippet or snippet group to work on.
0044      */
0045     QItemSelectionModel *selectionModel() const;
0046 
0047     /**
0048      * Returns whether the currently selected item is a snippet group.
0049      */
0050     [[nodiscard]] bool snippetGroupSelected() const;
0051 
0052     /**
0053      * Returns the name of the currently selected snippet or snippet group.
0054      */
0055     [[nodiscard]] QString selectedName() const;
0056 
0057     void save();
0058 
0059     [[nodiscard]] QModelIndex currentGroupIndex() const;
0060 
0061     void importQuickText();
0062     void exportQuickText();
0063 
0064 Q_SIGNALS:
0065     void insertPlainText(const QString &snippetText);
0066 
0067 private:
0068     MailCommon::SnippetsModel *mModel = nullptr;
0069     QItemSelectionModel *mSelectionModel = nullptr;
0070     QWidget *const mParent;
0071 };