File indexing completed on 2025-01-05 04:49:51
0001 /* 0002 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "selectimapwidget.h" 0008 #include "imapfoldercompletionplugin_debug.h" 0009 #include "selectimapfolderdialog.h" 0010 #include "selectimaplineedit.h" 0011 #include <KLocalizedString> 0012 #include <QHBoxLayout> 0013 #include <QToolButton> 0014 0015 #include <KPluginFactory> 0016 K_PLUGIN_CLASS_WITH_JSON(SelectImapWidget, "imapfoldercompletion.json") 0017 0018 SelectImapWidget::SelectImapWidget(QWidget *parent, const QList<QVariant> &) 0019 : KSieveUi::AbstractMoveImapFolderWidget(parent) 0020 , mToolButton(new QToolButton(this)) 0021 , mLineEdit(new SelectImapLineEdit(this)) 0022 { 0023 auto layout = new QHBoxLayout(this); 0024 layout->setObjectName(QLatin1StringView("mainlayout")); 0025 layout->setContentsMargins({}); 0026 mLineEdit->setObjectName(QLatin1StringView("lineedit")); 0027 layout->addWidget(mLineEdit); 0028 0029 mToolButton->setText(QStringLiteral("...")); 0030 mToolButton->setObjectName(QLatin1StringView("toolbutton")); 0031 mToolButton->setToolTip(i18n("Select IMAP folder")); 0032 mToolButton->hide(); 0033 layout->addWidget(mToolButton); 0034 connect(mToolButton, &QToolButton::clicked, this, &SelectImapWidget::slotOpenSelectImapFolder); 0035 } 0036 0037 SelectImapWidget::~SelectImapWidget() 0038 { 0039 delete mSelectImapFolderDialog; 0040 } 0041 0042 void SelectImapWidget::setText(const QString &str) 0043 { 0044 mLineEdit->setText(str); 0045 } 0046 0047 QString SelectImapWidget::text() const 0048 { 0049 return mLineEdit->text(); 0050 } 0051 0052 void SelectImapWidget::setSieveImapAccountSettings(const KSieveCore::SieveImapAccountSettings &account) 0053 { 0054 mAccount = account; 0055 if (mAccount.isValid()) { 0056 mToolButton->show(); 0057 mLineEdit->setSieveImapAccountSettings(account); 0058 mLineEdit->setPlaceholderText(i18n("Click on button for selecting folder...")); 0059 } else { 0060 qCDebug(IMAPFOLDERCOMPLETIONPLUGIN_LOG) << "Account is not defined"; 0061 } 0062 } 0063 0064 SelectImapFolderDialog *SelectImapWidget::selectFolderDialog() 0065 { 0066 if (mSelectImapFolderDialog.isNull()) { 0067 mSelectImapFolderDialog = new SelectImapFolderDialog(mAccount, this); 0068 mSelectImapFolderDialog->setModal(true); 0069 } 0070 return mSelectImapFolderDialog; 0071 } 0072 0073 void SelectImapWidget::slotOpenSelectImapFolder() 0074 { 0075 QPointer<SelectImapFolderDialog> dlg(selectFolderDialog()); 0076 if (dlg->exec()) { 0077 mLineEdit->setText(dlg->selectedFolderName()); 0078 } 0079 // Don't delete it. 0080 } 0081 0082 #include "selectimapwidget.moc" 0083 0084 #include "moc_selectimapwidget.cpp"