Mailcommon

snippetdialog.cpp
1/*
2 snippet feature from kdevelop/plugins/snippet/
3
4 SPDX-FileCopyrightText: 2007 Robert Gruber <rgruber@users.sourceforge.net>
5 SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org>
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 <KSharedConfig>
16#include <KWindowConfig>
17#include <MessageComposer/ConvertSnippetVariableMenu>
18#include <QDialogButtonBox>
19#include <QPushButton>
20#include <QVBoxLayout>
21#include <QWindow>
22
23using namespace MailCommon;
24namespace
25{
26static const char mySnippetDialogConfigGroupName[] = "SnippetDialog";
27}
28SnippetDialog::SnippetDialog(KActionCollection *actionCollection, bool inGroupMode, QWidget *parent)
29 : QDialog(parent)
30 , mSnippetWidget(new SnippetWidget(this))
31 , mInGroupMode(inGroupMode)
32{
33 auto mainLayout = new QVBoxLayout(this);
34 mainLayout->setObjectName(QLatin1StringView("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
58SnippetDialog::~SnippetDialog()
59{
60 if (!mInGroupMode) {
61 writeConfig();
62 }
63}
64
65void SnippetDialog::readConfig()
66{
67 create(); // ensure a window is created
68 windowHandle()->resize(QSize(300, 350));
69 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(mySnippetDialogConfigGroupName));
71 resize(windowHandle()->size()); // workaround for QTBUG-40584
72}
73
74void SnippetDialog::writeConfig()
75{
76 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(mySnippetDialogConfigGroupName));
78 group.sync();
79}
80
81void SnippetDialog::slotGroupChanged()
82{
83 mOkButton->setEnabled(snippetIsValid());
84}
85
86void SnippetDialog::setName(const QString &name)
87{
88 mSnippetWidget->setName(name);
89}
90
91QString SnippetDialog::name() const
92{
93 return mSnippetWidget->name();
94}
95
96void SnippetDialog::setText(const QString &text)
97{
98 mSnippetWidget->setText(text);
99}
100
101QString SnippetDialog::text() const
102{
103 return mSnippetWidget->text();
104}
105
106void SnippetDialog::setSubject(const QString &text)
107{
108 mSnippetWidget->setSubject(text);
109}
110
111QString SnippetDialog::subject() const
112{
113 return mSnippetWidget->subject();
114}
115
116void SnippetDialog::setKeySequence(const QKeySequence &sequence)
117{
118 mSnippetWidget->setKeySequence(sequence);
119}
120
121QKeySequence SnippetDialog::keySequence() const
122{
123 return mSnippetWidget->keySequence();
124}
125
126void SnippetDialog::setKeyword(const QString &keyword)
127{
128 mSnippetWidget->setKeyword(keyword);
129}
130
131QString SnippetDialog::keyword() const
132{
133 return mSnippetWidget->keyword();
134}
135
136void SnippetDialog::setTo(const QString &keyword)
137{
138 mSnippetWidget->setTo(keyword);
139}
140
141QString SnippetDialog::to() const
142{
143 return mSnippetWidget->to();
144}
145
146void SnippetDialog::setCc(const QString &keyword)
147{
148 mSnippetWidget->setCc(keyword);
149}
150
151QString SnippetDialog::cc() const
152{
153 return mSnippetWidget->cc();
154}
155
156void SnippetDialog::setBcc(const QString &keyword)
157{
158 mSnippetWidget->setBcc(keyword);
159}
160
161QString SnippetDialog::bcc() const
162{
163 return mSnippetWidget->bcc();
164}
165
166void SnippetDialog::setAttachment(const QString &keyword)
167{
168 mSnippetWidget->setAttachment(keyword);
169}
170
171QString SnippetDialog::attachment() const
172{
173 return mSnippetWidget->attachment();
174}
175
176void SnippetDialog::setGroupModel(QAbstractItemModel *model)
177{
178 mSnippetWidget->setGroupModel(model);
179}
180
181void SnippetDialog::setGroupIndex(const QModelIndex &index)
182{
183 mSnippetWidget->setGroupIndex(index);
184}
185
186QModelIndex SnippetDialog::groupIndex() const
187{
188 return mSnippetWidget->groupIndex();
189}
190
191void SnippetDialog::slotTextChanged()
192{
193 mOkButton->setEnabled(snippetIsValid());
194}
195
196bool SnippetDialog::snippetIsValid() const
197{
198 return mSnippetWidget->snippetIsValid();
199}
200
201#include "moc_snippetdialog.cpp"
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
The SnippetWidget class.
KCONFIGGUI_EXPORT void saveWindowSize(const QWindow *window, KConfigGroup &config, KConfigGroup::WriteConfigFlags options=KConfigGroup::Normal)
KCONFIGGUI_EXPORT void restoreWindowSize(QWindow *window, const KConfigGroup &config)
The filter dialog.
Key_Return
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void create(WId window, bool initializeWindow, bool destroyOldWindow)
void setEnabled(bool)
void resize(const QSize &)
QWindow * windowHandle() const const
void resize(const QSize &newSize)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:14:01 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.