File indexing completed on 2024-11-24 04:43:06

0001 /*
0002    SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "sendvcardsplugininterface.h"
0008 #include "kaddressbook_sendvcardsplugin_debug.h"
0009 #include "sendvcardsjob.h"
0010 
0011 #include <KActionCollection>
0012 #include <KLocalizedString>
0013 #include <KMessageBox>
0014 #include <QAction>
0015 
0016 SendVcardsPluginInterface::SendVcardsPluginInterface(QObject *parent)
0017     : PimCommon::GenericPluginInterface(parent)
0018 {
0019 }
0020 
0021 SendVcardsPluginInterface::~SendVcardsPluginInterface() = default;
0022 
0023 void SendVcardsPluginInterface::updateActions(int numberOfSelectedItems, int numberOfSelectedCollections)
0024 {
0025     Q_UNUSED(numberOfSelectedCollections)
0026     if (mAction) {
0027         mAction->setEnabled(numberOfSelectedItems > 0);
0028     }
0029 }
0030 
0031 void SendVcardsPluginInterface::createAction(KActionCollection *ac)
0032 {
0033     mAction = ac->addAction(QStringLiteral("send_vcards"));
0034     mAction->setText(i18n("Send vCards..."));
0035     mAction->setIcon(QIcon::fromTheme(QStringLiteral("mail-message-new")));
0036     connect(mAction, &QAction::triggered, this, &SendVcardsPluginInterface::slotActivated);
0037     const PimCommon::ActionType type(mAction, PimCommon::ActionType::Action);
0038     addActionType(type);
0039 }
0040 
0041 void SendVcardsPluginInterface::slotActivated()
0042 {
0043     Q_EMIT emitPluginActivated(this);
0044 }
0045 
0046 void SendVcardsPluginInterface::setCurrentItems(const Akonadi::Item::List &items)
0047 {
0048     mListItems = items;
0049 }
0050 
0051 PimCommon::GenericPluginInterface::RequireTypes SendVcardsPluginInterface::requiresFeatures() const
0052 {
0053     return PimCommon::GenericPluginInterface::CurrentItems;
0054 }
0055 
0056 void SendVcardsPluginInterface::exec()
0057 {
0058     if (!mListItems.isEmpty()) {
0059         auto sendVcards = new KABSendVCards::SendVcardsJob(mListItems, this);
0060         connect(sendVcards, &KABSendVCards::SendVcardsJob::sendVCardsError, this, &SendVcardsPluginInterface::slotSendVcardsError);
0061         if (!sendVcards->start()) {
0062             qCDebug(KADDRESSBOOK_SENDVCARDS_LOG) << "Impossible to send vcard";
0063         }
0064     }
0065 }
0066 
0067 void SendVcardsPluginInterface::slotSendVcardsError(const QString &error)
0068 {
0069     KMessageBox::error(parentWidget(), error);
0070 }
0071 
0072 #include "moc_sendvcardsplugininterface.cpp"