Commit a6921af7 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Fix Bug 387598 - Send As ICalendar Address Selection has problems

FIXED-IN: 5.13.0
BUG: 387598
parent 6ae54f78
......@@ -13,5 +13,5 @@ kcoreaddons_add_plugin(emailaddressselectionldapdialogplugin JSON emailaddressse
${emailaddressselectionldapdialog_SRCS} INSTALL_NAMESPACE akonadi)
target_link_libraries(emailaddressselectionldapdialogplugin
KF5::I18n KF5::AkonadiContact
KF5::I18n KF5::AkonadiContact KF5::Libkdepim
)
......@@ -18,6 +18,16 @@
*/
#include "emailaddressselectionldapdialog.h"
#include <Akonadi/Contact/RecipientsPickerWidget>
#include <KConfigGroup>
#include <KLocalizedString>
#include <KSharedConfig>
#include <Libkdepim/LdapSearchDialog>
#include <QBoxLayout>
#include <QDialogButtonBox>
#include <QPushButton>
#include <QLineEdit>
#include <QTreeView>
#include <kpluginfactory.h>
K_PLUGIN_CLASS_WITH_JSON(EmailAddressSelectionLdapDialog, "emailaddressselectionldapdialog.json")
......@@ -25,25 +35,82 @@ K_PLUGIN_CLASS_WITH_JSON(EmailAddressSelectionLdapDialog, "emailaddressselection
EmailAddressSelectionLdapDialog::EmailAddressSelectionLdapDialog(QWidget *parent, const QList<QVariant> &)
: Akonadi::AbstractEmailAddressSelectionDialog(parent)
{
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mView = new Akonadi::RecipientsPickerWidget(true, nullptr, this);
mainLayout->addWidget(mView);
connect(mView->emailAddressSelectionWidget()->view(), &QTreeView::doubleClicked, this, &QDialog::accept);
QPushButton *searchLDAPButton = new QPushButton(i18n("Search &Directory Service"), this);
connect(searchLDAPButton, &QPushButton::clicked, this, &EmailAddressSelectionLdapDialog::slotSearchLDAP);
mainLayout->addWidget(searchLDAPButton);
KConfig config(QStringLiteral("kabldaprc"));
KConfigGroup group = config.group("LDAP");
int numHosts = group.readEntry("NumSelectedHosts", 0);
if (!numHosts) {
searchLDAPButton->setVisible(false);
}
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
okButton->setDefault(true);
okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
mainLayout->addWidget(buttonBox);
readConfig();
}
EmailAddressSelectionLdapDialog::~EmailAddressSelectionLdapDialog()
void EmailAddressSelectionLdapDialog::readConfig()
{
KConfigGroup group(KSharedConfig::openConfig(), QStringLiteral("EmailAddressSelectionLdapDialog"));
const QSize size = group.readEntry("Size", QSize());
if (size.isValid()) {
resize(size);
} else {
resize(sizeHint().width(), sizeHint().height());
}
}
void EmailAddressSelectionLdapDialog::writeConfig()
{
KConfigGroup group(KSharedConfig::openConfig(), QStringLiteral("EmailAddressSelectionLdapDialog"));
group.writeEntry("Size", size());
}
EmailAddressSelectionLdapDialog::~EmailAddressSelectionLdapDialog()
{
writeConfig();
}
Akonadi::EmailAddressSelection::List EmailAddressSelectionLdapDialog::selectedAddresses() const
{
//TODO
return {};
return mView->emailAddressSelectionWidget()->selectedAddresses();
}
Akonadi::EmailAddressSelectionWidget *EmailAddressSelectionLdapDialog::view() const
{
//TODO
return nullptr;
return mView->emailAddressSelectionWidget();
}
void EmailAddressSelectionLdapDialog::slotSearchLDAP()
{
if (!mLdapSearchDialog) {
mLdapSearchDialog = new KLDAP::LdapSearchDialog(this);
connect(mLdapSearchDialog, &KLDAP::LdapSearchDialog::contactsAdded, this, &EmailAddressSelectionLdapDialog::ldapSearchResult);
}
mLdapSearchDialog->setSearchText(mView->emailAddressSelectionWidget()->searchLineEdit()->text());
mLdapSearchDialog->show();
}
void EmailAddressSelectionLdapDialog::ldapSearchResult()
{
const KContacts::Addressee::List contacts = mLdapSearchDialog->selectedContacts();
for (const KContacts::Addressee &contact : contacts) {
//TODO
}
}
#include "emailaddressselectionldapdialog.moc"
......@@ -20,8 +20,13 @@
#define EMAILADDRESSSELECTIONLDAPDIALOG_H
#include <Akonadi/Contact/AbstractEmailAddressSelectionDialog>
namespace Akonadi {
class RecipientsPickerWidget;
}
namespace KLDAP {
class LdapSearchDialog;
}
class EmailAddressSelectionLdapDialog : public Akonadi::AbstractEmailAddressSelectionDialog
{
......@@ -32,6 +37,13 @@ public:
Akonadi::EmailAddressSelection::List selectedAddresses() const override;
Akonadi::EmailAddressSelectionWidget *view() const override;
private:
void writeConfig();
void readConfig();
void slotSearchLDAP();
void ldapSearchResult();
Akonadi::RecipientsPickerWidget *mView = nullptr;
KLDAP::LdapSearchDialog *mLdapSearchDialog = nullptr;
};
#endif // EMAILADDRESSSELECTIONLDAPDIALOG_H
......@@ -29,6 +29,7 @@
#include <QTreeView>
#include <KColorScheme>
#include <memory>
#include <KPluginLoader>
K_PLUGIN_CLASS_WITH_JSON(EmailLineEdit, "emaillineedit.json")
......@@ -74,8 +75,14 @@ void EmailLineEdit::verifyAkonadiStatus()
void EmailLineEdit::slotSelectEmail()
{
std::unique_ptr<Akonadi::EmailAddressSelectionDialog> dlg(
new Akonadi::EmailAddressSelectionDialog(this));
std::unique_ptr<Akonadi::AbstractEmailAddressSelectionDialog> dlg;
KPluginLoader loader(QStringLiteral("akonadi/emailaddressselectionldapdialogplugin"));
KPluginFactory *factory = loader.factory();
if (factory) {
dlg.reset(factory->create<Akonadi::AbstractEmailAddressSelectionDialog>(this));
} else {
dlg.reset(new Akonadi::EmailAddressSelectionDialog(this));
}
dlg->setWindowTitle(i18n("Select Emails"));
dlg->view()->view()->setSelectionMode(multiSelection() ? QAbstractItemView::MultiSelection : QAbstractItemView::SingleSelection);
......
Supports Markdown
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