Mailcommon

snippetdialog.cpp
1 /*
2  snippet feature from kdevelop/plugins/snippet/
3 
4  SPDX-FileCopyrightText: 2007 Robert Gruber <[email protected]>
5  SPDX-FileCopyrightText: 2019-2022 Laurent Montel <[email protected]>
6 
7  SPDX-License-Identifier: GPL-2.0-or-later
8 */
9 
10 #include "snippetdialog.h"
11 #include "snippetwidget.h"
12 
13 #include <KActionCollection>
14 #include <KConfigGroup>
15 #include <KPIMTextEdit/PlainTextEditor>
16 #include <KSharedConfig>
17 #include <MessageComposer/ConvertSnippetVariableMenu>
18 #include <QDialogButtonBox>
19 #include <QPushButton>
20 #include <QVBoxLayout>
21 
22 using namespace MailCommon;
23 namespace
24 {
25 static const char mySnippetDialogConfigGroupName[] = "SnippetDialog";
26 }
27 SnippetDialog::SnippetDialog(KActionCollection *actionCollection, bool inGroupMode, QWidget *parent)
28  : QDialog(parent)
29  , mActionCollection(actionCollection)
30  , mSnippetWidget(new SnippetWidget(this))
31  , mInGroupMode(inGroupMode)
32 {
33  auto mainLayout = new QVBoxLayout(this);
34  mainLayout->setObjectName(QStringLiteral("mainLayout"));
35 
36  mainLayout->addWidget(mSnippetWidget);
37 
39  mOkButton = buttonBox->button(QDialogButtonBox::Ok);
40  mOkButton->setDefault(true);
41  mOkButton->setShortcut(Qt::CTRL | Qt::Key_Return);
42  connect(buttonBox, &QDialogButtonBox::accepted, this, &SnippetDialog::accept);
43  connect(buttonBox, &QDialogButtonBox::rejected, this, &SnippetDialog::reject);
44  mainLayout->addWidget(buttonBox);
45 
46  mSnippetWidget->setCheckActionCollections(QList<KActionCollection *>() << actionCollection);
47  mOkButton->setEnabled(false);
48 
49  connect(mSnippetWidget, &MailCommon::SnippetWidget::textChanged, this, &SnippetDialog::slotTextChanged);
50  connect(mSnippetWidget, &MailCommon::SnippetWidget::groupChanged, this, &SnippetDialog::slotGroupChanged);
51 
52  mSnippetWidget->setGroupSelected(mInGroupMode);
53  if (!mInGroupMode) {
54  readConfig();
55  }
56 }
57 
58 SnippetDialog::~SnippetDialog()
59 {
60  if (!mInGroupMode) {
61  writeConfig();
62  }
63 }
64 
65 void SnippetDialog::writeConfig()
66 {
67  KConfigGroup group(KSharedConfig::openStateConfig(), mySnippetDialogConfigGroupName);
68  group.writeEntry("Size", size());
69 }
70 
71 void SnippetDialog::readConfig()
72 {
73  KConfigGroup group(KSharedConfig::openStateConfig(), mySnippetDialogConfigGroupName);
74  const QSize sizeDialog = group.readEntry("Size", QSize(300, 350));
75  if (sizeDialog.isValid()) {
76  resize(sizeDialog);
77  }
78 }
79 
80 void SnippetDialog::slotGroupChanged()
81 {
82  mOkButton->setEnabled(snippetIsValid());
83 }
84 
85 void SnippetDialog::setName(const QString &name)
86 {
87  mSnippetWidget->setName(name);
88 }
89 
90 QString SnippetDialog::name() const
91 {
92  return mSnippetWidget->name();
93 }
94 
95 void SnippetDialog::setText(const QString &text)
96 {
97  mSnippetWidget->setText(text);
98 }
99 
100 QString SnippetDialog::text() const
101 {
102  return mSnippetWidget->text();
103 }
104 
105 void SnippetDialog::setSubject(const QString &text)
106 {
107  mSnippetWidget->setSubject(text);
108 }
109 
110 QString SnippetDialog::subject() const
111 {
112  return mSnippetWidget->subject();
113 }
114 
115 void SnippetDialog::setKeySequence(const QKeySequence &sequence)
116 {
117  mSnippetWidget->setKeySequence(sequence);
118 }
119 
120 QKeySequence SnippetDialog::keySequence() const
121 {
122  return mSnippetWidget->keySequence();
123 }
124 
125 void SnippetDialog::setKeyword(const QString &keyword)
126 {
127  mSnippetWidget->setKeyword(keyword);
128 }
129 
130 QString SnippetDialog::keyword() const
131 {
132  return mSnippetWidget->keyword();
133 }
134 
135 void SnippetDialog::setTo(const QString &keyword)
136 {
137  mSnippetWidget->setTo(keyword);
138 }
139 
140 QString SnippetDialog::to() const
141 {
142  return mSnippetWidget->to();
143 }
144 
145 void SnippetDialog::setCc(const QString &keyword)
146 {
147  mSnippetWidget->setCc(keyword);
148 }
149 
150 QString SnippetDialog::cc() const
151 {
152  return mSnippetWidget->cc();
153 }
154 
155 void SnippetDialog::setBcc(const QString &keyword)
156 {
157  mSnippetWidget->setBcc(keyword);
158 }
159 
160 QString SnippetDialog::bcc() const
161 {
162  return mSnippetWidget->bcc();
163 }
164 
165 void SnippetDialog::setAttachment(const QString &keyword)
166 {
167  mSnippetWidget->setAttachment(keyword);
168 }
169 
170 QString SnippetDialog::attachment() const
171 {
172  return mSnippetWidget->attachment();
173 }
174 
175 void SnippetDialog::setGroupModel(QAbstractItemModel *model)
176 {
177  mSnippetWidget->setGroupModel(model);
178 }
179 
180 void SnippetDialog::setGroupIndex(const QModelIndex &index)
181 {
182  mSnippetWidget->setGroupIndex(index);
183 }
184 
185 QModelIndex SnippetDialog::groupIndex() const
186 {
187  return mSnippetWidget->groupIndex();
188 }
189 
190 void SnippetDialog::slotTextChanged()
191 {
192  mOkButton->setEnabled(snippetIsValid());
193 }
194 
195 bool SnippetDialog::snippetIsValid() const
196 {
197  return mSnippetWidget->snippetIsValid();
198 }
bool isValid() const const
void readConfig()
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
Key_Return
The SnippetWidget class.
Definition: snippetwidget.h:20
The filter dialog.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Sep 24 2022 03:58:15 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.