File indexing completed on 2025-01-05 04:49:19
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 "ldapimportexportplugininterface.h" 0008 #include <KActionCollection> 0009 #include <KAddressBookImportExport/ImportExportEngine> 0010 #include <KLocalizedString> 0011 #include <PimCommonAkonadi/LdapSearchDialog> 0012 #include <QAction> 0013 #include <QPointer> 0014 0015 LDapImportExportPluginInterface::LDapImportExportPluginInterface(QObject *parent) 0016 : KAddressBookImportExport::PluginInterface(parent) 0017 { 0018 } 0019 0020 LDapImportExportPluginInterface::~LDapImportExportPluginInterface() = default; 0021 0022 void LDapImportExportPluginInterface::createAction(KActionCollection *ac) 0023 { 0024 QAction *action = ac->addAction(QStringLiteral("file_import_ldap")); 0025 action->setText(i18n("Import From LDAP server...")); 0026 action->setWhatsThis(i18n("Import contacts from an LDAP server.")); 0027 setImportActions({action}); 0028 connect(action, &QAction::triggered, this, &LDapImportExportPluginInterface::slotImportLdap); 0029 } 0030 0031 void LDapImportExportPluginInterface::exec() 0032 { 0033 switch (mImportExportAction) { 0034 case Import: 0035 importLdap(); 0036 break; 0037 case Export: 0038 break; 0039 } 0040 } 0041 0042 void LDapImportExportPluginInterface::slotImportLdap() 0043 { 0044 mImportExportAction = Import; 0045 Q_EMIT emitPluginActivated(this); 0046 } 0047 0048 void LDapImportExportPluginInterface::importLdap() 0049 { 0050 KAddressBookImportExport::ContactList contactList; 0051 QPointer<PimCommon::LdapSearchDialog> dlg = new PimCommon::LdapSearchDialog(parentWidget()); 0052 0053 if (dlg->exec()) { 0054 contactList.setAddressList(dlg->selectedContacts()); 0055 } 0056 0057 delete dlg; 0058 auto engine = new KAddressBookImportExport::ImportExportEngine(this); 0059 engine->setContactList(contactList); 0060 engine->setDefaultAddressBook(defaultCollection()); 0061 engine->importContacts(); 0062 } 0063 0064 #include "moc_ldapimportexportplugininterface.cpp"