Commit 8071c0e1 authored by Laurent Montel's avatar Laurent Montel 😁

Add akonadi plugin for selecting email when we use redirect action in sieveeditor.

we don't start akonadi if system doesn't have it
parent 45888aa5
......@@ -85,7 +85,7 @@ set(AKONADICALENDAR_LIB_VERSION "5.7.80")
set(CALENDAR_UTILS_VERSION "5.7.80")
set(KPIMTEXTEDIT_LIB_VERSION "5.7.80")
set(KIMAP_LIB_VERSION "5.7.80")
set(LIBKSIEVE_LIB_VERSION "5.7.80")
set(LIBKSIEVE_LIB_VERSION "5.7.81")
set(KMAILTRANSPORT_LIB_VERSION "5.7.80")
set(AKONADICONTACT_LIB_VERSION "5.7.80")
set(IMPORTWIZARD_LIB_VERSION "5.7.80")
......
......@@ -29,3 +29,4 @@ org.kde.pim.pkpass kdepim-addons (pkpass formater)
org.kde.pim.messageviewer.semantic kdepim-addons (Semantic plugin)
org.kde.pim.kmail_expertplugin kdepim-addons (kmail expert plugin)
org.kde.pim.kmail_insertshorturl kdepim-addons (kmail insert short url plugin)
org.kde.pim.sieveeditoremaillinedit kdepim-addons (SieveEditor email line plugin)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
set(sieveeditoremaillinedit_plugin_categories_SRCS)
ecm_qt_declare_logging_category(sieveeditoremaillinedit_plugin_categories_SRCS HEADER sieveeditoremaillineditplugin_debug.h IDENTIFIER
EMAILLINEEDITPLUGIN_LOG CATEGORY_NAME org.kde.pim.sieveeditoremaillinedit)
set(sieveeditoremaillineditplugin_SRCS
emaillineedit.cpp
${sieveeditoremaillinedit_plugin_categories_SRCS}
)
kcoreaddons_add_plugin(emaillineeditplugin JSON emaillineedit.json SOURCES
${sieveeditoremaillineditplugin_SRCS} INSTALL_NAMESPACE libksieve)
target_link_libraries(emaillineeditplugin
KF5::I18n KF5::KSieveUi KF5::AkonadiContact
)
if(BUILD_TESTING)
add_subdirectory(tests)
add_subdirectory(autotests)
......
......@@ -18,17 +18,19 @@
*/
#include "emaillineedit.h"
#include "regexpeditorlineeditplugin_debug.h"
#include "sieveeditoremaillineditplugin_debug.h"
#include <kpluginfactory.h>
#include <Akonadi/Contact/EmailAddressSelectionDialog>
#include <AkonadiCore/ServerManager>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QToolButton>
#include <KLocalizedString>
#include <KServiceTypeTrader>
#include <QDialog>
#include <KTextWidgets/kregexpeditorinterface.h>
#include <QTreeView>
#include <KColorScheme>
#include <memory>
K_PLUGIN_CLASS_WITH_JSON(EmailLineEdit, "emaillineedit.json")
......@@ -40,7 +42,7 @@ EmailLineEdit::EmailLineEdit(QWidget *parent, const QList<QVariant> &)
mainLayout->setMargin(0);
mLineEdit = new QLineEdit(this);
//FIXME connect(mLineEdit, &QLineEdit::textChanged, this, &EmailLineEdit::textChanged);
connect(mLineEdit, &QLineEdit::textChanged, this, &EmailLineEdit::slotTextChanged);
mLineEdit->setObjectName(QStringLiteral("lineedit"));
mainLayout->addWidget(mLineEdit);
......@@ -49,12 +51,36 @@ EmailLineEdit::EmailLineEdit(QWidget *parent, const QList<QVariant> &)
mEmailButton->setObjectName(QStringLiteral("emailbutton"));
mEmailButton->setToolTip(i18n("Select Emails"));
mainLayout->addWidget(mEmailButton);
connect(mEmailButton, &QToolButton::clicked, this, &EmailLineEdit::slotSelectEmail);
verifyAkonadiStatus();
}
EmailLineEdit::~EmailLineEdit()
{
}
void EmailLineEdit::verifyAkonadiStatus()
{
Akonadi::ServerManager::State state = Akonadi::ServerManager::self()->state();
mEmailButton->setVisible(state == Akonadi::ServerManager::Running);
}
void EmailLineEdit::slotSelectEmail()
{
std::unique_ptr<Akonadi::EmailAddressSelectionDialog> dlg(
new Akonadi::EmailAddressSelectionDialog(this));
dlg->setWindowTitle(i18n("Select Emails"));
dlg->view()->view()->setSelectionMode(QAbstractItemView::SingleSelection);
if (dlg->exec()) {
QStringList addresses;
const Akonadi::EmailAddressSelection::List lstAddress = dlg->selectedAddresses();
if (!lstAddress.isEmpty()) {
mLineEdit->setText(lstAddress.constFirst().email());
}
}
}
void EmailLineEdit::setText(const QString &str)
{
mLineEdit->setText(str);
......@@ -65,4 +91,29 @@ QString EmailLineEdit::text() const
return mLineEdit->text();
}
void EmailLineEdit::slotTextChanged()
{
verifyAddress();
Q_EMIT valueChanged();
}
void EmailLineEdit::verifyAddress()
{
#ifndef QT_NO_STYLE_STYLESHEET
QString styleSheet;
const QString lineEditText = text();
if (!lineEditText.isEmpty()) {
const bool incorrectEmail = !lineEditText.contains(QLatin1Char('@'));
if (mNegativeBackground.isEmpty()) {
KStatefulBrush bgBrush = KStatefulBrush(KColorScheme::View, KColorScheme::NegativeText);
mNegativeBackground = QStringLiteral("QLineEdit{ color:%1 }").arg(bgBrush.brush(this).color().name());
}
if (incorrectEmail) {
styleSheet = mNegativeBackground;
}
}
mLineEdit->setStyleSheet(styleSheet);
#endif
}
#include "emaillineedit.moc"
......@@ -36,6 +36,11 @@ public:
void setText(const QString &str) override;
QString text() const override;
private:
void slotTextChanged();
void verifyAddress();
void slotSelectEmail();
void verifyAkonadiStatus();
QString mNegativeBackground;
QLineEdit *mLineEdit = nullptr;
QToolButton *mEmailButton = nullptr;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment