Warning, file /pim/mailcommon/src/snippets/snippetdialog.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 snippet feature from kdevelop/plugins/snippet/ 0003 0004 SPDX-FileCopyrightText: 2007 Robert Gruber <rgruber@users.sourceforge.net> 0005 SPDX-FileCopyrightText: 2019-2024 Laurent Montel <montel@kde.org> 0006 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #include "snippetdialog.h" 0011 #include "snippetwidget.h" 0012 0013 #include <KActionCollection> 0014 #include <KConfigGroup> 0015 #include <KSharedConfig> 0016 #include <KWindowConfig> 0017 #include <MessageComposer/ConvertSnippetVariableMenu> 0018 #include <QDialogButtonBox> 0019 #include <QPushButton> 0020 #include <QVBoxLayout> 0021 #include <QWindow> 0022 0023 using namespace MailCommon; 0024 namespace 0025 { 0026 static const char mySnippetDialogConfigGroupName[] = "SnippetDialog"; 0027 } 0028 SnippetDialog::SnippetDialog(KActionCollection *actionCollection, bool inGroupMode, QWidget *parent) 0029 : QDialog(parent) 0030 , mSnippetWidget(new SnippetWidget(this)) 0031 , mInGroupMode(inGroupMode) 0032 { 0033 auto mainLayout = new QVBoxLayout(this); 0034 mainLayout->setObjectName(QLatin1StringView("mainLayout")); 0035 0036 mainLayout->addWidget(mSnippetWidget); 0037 0038 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 0039 mOkButton = buttonBox->button(QDialogButtonBox::Ok); 0040 mOkButton->setDefault(true); 0041 mOkButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0042 connect(buttonBox, &QDialogButtonBox::accepted, this, &SnippetDialog::accept); 0043 connect(buttonBox, &QDialogButtonBox::rejected, this, &SnippetDialog::reject); 0044 mainLayout->addWidget(buttonBox); 0045 0046 mSnippetWidget->setCheckActionCollections(QList<KActionCollection *>() << actionCollection); 0047 mOkButton->setEnabled(false); 0048 0049 connect(mSnippetWidget, &MailCommon::SnippetWidget::textChanged, this, &SnippetDialog::slotTextChanged); 0050 connect(mSnippetWidget, &MailCommon::SnippetWidget::groupChanged, this, &SnippetDialog::slotGroupChanged); 0051 0052 mSnippetWidget->setGroupSelected(mInGroupMode); 0053 if (!mInGroupMode) { 0054 readConfig(); 0055 } 0056 } 0057 0058 SnippetDialog::~SnippetDialog() 0059 { 0060 if (!mInGroupMode) { 0061 writeConfig(); 0062 } 0063 } 0064 0065 void SnippetDialog::readConfig() 0066 { 0067 create(); // ensure a window is created 0068 windowHandle()->resize(QSize(300, 350)); 0069 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(mySnippetDialogConfigGroupName)); 0070 KWindowConfig::restoreWindowSize(windowHandle(), group); 0071 resize(windowHandle()->size()); // workaround for QTBUG-40584 0072 } 0073 0074 void SnippetDialog::writeConfig() 0075 { 0076 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(mySnippetDialogConfigGroupName)); 0077 KWindowConfig::saveWindowSize(windowHandle(), group); 0078 group.sync(); 0079 } 0080 0081 void SnippetDialog::slotGroupChanged() 0082 { 0083 mOkButton->setEnabled(snippetIsValid()); 0084 } 0085 0086 void SnippetDialog::setName(const QString &name) 0087 { 0088 mSnippetWidget->setName(name); 0089 } 0090 0091 QString SnippetDialog::name() const 0092 { 0093 return mSnippetWidget->name(); 0094 } 0095 0096 void SnippetDialog::setText(const QString &text) 0097 { 0098 mSnippetWidget->setText(text); 0099 } 0100 0101 QString SnippetDialog::text() const 0102 { 0103 return mSnippetWidget->text(); 0104 } 0105 0106 void SnippetDialog::setSubject(const QString &text) 0107 { 0108 mSnippetWidget->setSubject(text); 0109 } 0110 0111 QString SnippetDialog::subject() const 0112 { 0113 return mSnippetWidget->subject(); 0114 } 0115 0116 void SnippetDialog::setKeySequence(const QKeySequence &sequence) 0117 { 0118 mSnippetWidget->setKeySequence(sequence); 0119 } 0120 0121 QKeySequence SnippetDialog::keySequence() const 0122 { 0123 return mSnippetWidget->keySequence(); 0124 } 0125 0126 void SnippetDialog::setKeyword(const QString &keyword) 0127 { 0128 mSnippetWidget->setKeyword(keyword); 0129 } 0130 0131 QString SnippetDialog::keyword() const 0132 { 0133 return mSnippetWidget->keyword(); 0134 } 0135 0136 void SnippetDialog::setTo(const QString &keyword) 0137 { 0138 mSnippetWidget->setTo(keyword); 0139 } 0140 0141 QString SnippetDialog::to() const 0142 { 0143 return mSnippetWidget->to(); 0144 } 0145 0146 void SnippetDialog::setCc(const QString &keyword) 0147 { 0148 mSnippetWidget->setCc(keyword); 0149 } 0150 0151 QString SnippetDialog::cc() const 0152 { 0153 return mSnippetWidget->cc(); 0154 } 0155 0156 void SnippetDialog::setBcc(const QString &keyword) 0157 { 0158 mSnippetWidget->setBcc(keyword); 0159 } 0160 0161 QString SnippetDialog::bcc() const 0162 { 0163 return mSnippetWidget->bcc(); 0164 } 0165 0166 void SnippetDialog::setAttachment(const QString &keyword) 0167 { 0168 mSnippetWidget->setAttachment(keyword); 0169 } 0170 0171 QString SnippetDialog::attachment() const 0172 { 0173 return mSnippetWidget->attachment(); 0174 } 0175 0176 void SnippetDialog::setGroupModel(QAbstractItemModel *model) 0177 { 0178 mSnippetWidget->setGroupModel(model); 0179 } 0180 0181 void SnippetDialog::setGroupIndex(const QModelIndex &index) 0182 { 0183 mSnippetWidget->setGroupIndex(index); 0184 } 0185 0186 QModelIndex SnippetDialog::groupIndex() const 0187 { 0188 return mSnippetWidget->groupIndex(); 0189 } 0190 0191 void SnippetDialog::slotTextChanged() 0192 { 0193 mOkButton->setEnabled(snippetIsValid()); 0194 } 0195 0196 bool SnippetDialog::snippetIsValid() const 0197 { 0198 return mSnippetWidget->snippetIsValid(); 0199 } 0200 0201 #include "moc_snippetdialog.cpp"