Mailcommon

snippetsmodel.h
1 /*
2  SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
3  SPDX-FileContributor: Tobias Koenig <[email protected]>
4 
5  SPDX-FileCopyrightText: 2019-2023 Laurent Montel <[email protected]>
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>
15 namespace MailCommon
16 {
17 class SnippetItem;
18 /**
19  * @brief The SnippetsInfo struct
20  * @author Laurent Montel <[email protected]>
21  */
22 struct 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 <[email protected]>
37  */
38 class MAILCOMMON_EXPORT SnippetsModel : public QAbstractItemModel
39 {
40  Q_OBJECT
41 public:
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  Q_REQUIRED_RESULT QVariant data(const QModelIndex &index, int role) const override;
63 
64  Q_REQUIRED_RESULT Qt::ItemFlags flags(const QModelIndex &index) const override;
65 
66  Q_REQUIRED_RESULT QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
67 
68  Q_REQUIRED_RESULT QModelIndex parent(const QModelIndex &index) const override;
69 
70  Q_REQUIRED_RESULT int rowCount(const QModelIndex &parent = QModelIndex()) const override;
71 
72  Q_REQUIRED_RESULT int columnCount(const QModelIndex &parent = QModelIndex()) const override;
73 
74  Q_REQUIRED_RESULT QStringList mimeTypes() const override;
75 
76  Q_REQUIRED_RESULT QMimeData *mimeData(const QModelIndexList &indexes) const override;
77 
78  Q_REQUIRED_RESULT bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
79 
80  Q_REQUIRED_RESULT Qt::DropActions supportedDropActions() const override;
81 
82  void save(const QString &filename = QString());
83  void load(const QString &filename = QString());
84 
85  Q_REQUIRED_RESULT QMap<QString, QString> savedVariables() const;
86  void setSavedVariables(const QMap<QString, QString> &savedVariables);
87 
88  Q_REQUIRED_RESULT QList<SnippetsInfo> snippetsInfo() const;
89 
90 protected:
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 
95 Q_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 
108 private:
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 }
124 Q_DECLARE_TYPEINFO(MailCommon::SnippetsInfo, Q_RELOCATABLE_TYPE);
UserRole
@ NameRole
The name of a snippet or group.
Definition: snippetsmodel.h:44
@ BccRole
The Cc of a snippet.
Definition: snippetsmodel.h:51
@ KeySequenceRole
The key sequence to activate a snippet.
Definition: snippetsmodel.h:46
typedef ItemFlags
@ KeywordRole
The keyword which will replace by snippet.
Definition: snippetsmodel.h:47
DropAction
@ ToRole
The To of a snippet.
Definition: snippetsmodel.h:49
@ AttachmentRole
The Attachment of a snippet.
Definition: snippetsmodel.h:52
@ TextRole
The text of a snippet.
Definition: snippetsmodel.h:45
The SnippetsModel class.
Definition: snippetsmodel.h:38
@ CcRole
The Cc of a snippet.
Definition: snippetsmodel.h:50
@ SubjectRole
The subject of a snippet.
Definition: snippetsmodel.h:48
The SnippetsInfo struct.
Definition: snippetsmodel.h:22
The filter dialog.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Sep 26 2023 03:56:34 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.