Mailcommon

snippetsmodel.h
1/*
2 SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
3 SPDX-FileContributor: Tobias Koenig <tokoe@kdab.com>
4
5 SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
10#pragma once
11
12#include "mailcommon_export.h"
13#include <QAbstractItemModel>
14#include <QKeySequence>
15namespace MailCommon
16{
17class SnippetItem;
18/**
19 * @brief The SnippetsInfo struct
20 * @author Laurent Montel <montel@kde.org>
21 */
22struct MAILCOMMON_EXPORT SnippetsInfo {
23 QString newName;
24 QKeySequence keySequence;
25 QString text;
26 QString keyword;
27 QString subject;
28 QString to;
29 QString cc;
30 QString bcc;
31 QString attachment;
32};
33
34/**
35 * @brief The SnippetsModel class
36 * @author Laurent Montel <montel@kde.org>
37 */
38class MAILCOMMON_EXPORT SnippetsModel : public QAbstractItemModel
39{
40 Q_OBJECT
41public:
42 enum Role {
43 IsGroupRole = Qt::UserRole + 1, ///< Returns whether the index represents a group
44 NameRole, ///< The name of a snippet or group
45 TextRole, ///< The text of a snippet
46 KeySequenceRole, ///< The key sequence to activate a snippet
47 KeywordRole, ///< The keyword which will replace by snippet
48 SubjectRole, ///< The subject of a snippet
49 ToRole, ///< The To of a snippet
50 CcRole, ///< The Cc of a snippet
51 BccRole, ///< The Cc of a snippet
52 AttachmentRole, ///< The Attachment of a snippet
53 };
54
55 static SnippetsModel *instance();
56
57 explicit SnippetsModel(QObject *parent = nullptr);
58 ~SnippetsModel() override;
59
60 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
61
62 [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override;
63
64 [[nodiscard]] Qt::ItemFlags flags(const QModelIndex &index) const override;
65
66 [[nodiscard]] QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
67
68 [[nodiscard]] QModelIndex parent(const QModelIndex &index) const override;
69
70 [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
71
72 [[nodiscard]] int columnCount(const QModelIndex &parent = QModelIndex()) const override;
73
74 [[nodiscard]] QStringList mimeTypes() const override;
75
76 [[nodiscard]] QMimeData *mimeData(const QModelIndexList &indexes) const override;
77
78 [[nodiscard]] bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
79
80 [[nodiscard]] Qt::DropActions supportedDropActions() const override;
81
82 void save(const QString &filename = QString());
83 void load(const QString &filename = QString());
84
85 [[nodiscard]] QMap<QString, QString> savedVariables() const;
86 void setSavedVariables(const QMap<QString, QString> &savedVariables);
87
88 [[nodiscard]] QList<SnippetsInfo> snippetsInfo() const;
89
90protected:
91 bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
92
93 bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
94
95Q_SIGNALS:
96 void dndDone();
97 void addNewDndSnippset(const QString &);
98 void updateActionCollection(const QString &oldName,
99 const QString &newName,
100 const QKeySequence &keySequence,
101 const QString &text,
102 const QString &subject,
103 const QString &to,
104 const QString &cc,
105 const QString &bcc,
106 const QString &attachment);
107
108private:
109 MAILCOMMON_NO_EXPORT QModelIndex createGroup(const QString &groupName);
110 MAILCOMMON_NO_EXPORT void createSnippet(const QModelIndex &groupIndex,
111 const QString &snippetName,
112 const QString &snippetText,
113 const QString &snippetKeySequence,
114 const QString &snippetKeyword,
115 const QString &snippetSubject,
116 const QString &to,
117 const QString &cc,
118 const QString &bcc,
119 const QString &attachment);
120 SnippetItem *mRootItem = nullptr;
121 QMap<QString, QString> mSavedVariables;
122};
123}
124Q_DECLARE_TYPEINFO(MailCommon::SnippetsInfo, Q_RELOCATABLE_TYPE);
The SnippetsModel class.
@ AttachmentRole
The Attachment of a snippet.
@ KeywordRole
The keyword which will replace by snippet.
@ CcRole
The Cc of a snippet.
@ SubjectRole
The subject of a snippet.
@ BccRole
The Cc of a snippet.
@ KeySequenceRole
The key sequence to activate a snippet.
@ ToRole
The To of a snippet.
@ NameRole
The name of a snippet or group.
@ TextRole
The text of a snippet.
The filter dialog.
DropAction
UserRole
typedef ItemFlags
The SnippetsInfo struct.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:50:03 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.