File indexing completed on 2024-05-26 05:28:41

0001 /* Copyright (C) 2013 Pali Rohár <pali.rohar@gmail.com>
0002 
0003    This file is part of the Trojita Qt IMAP e-mail client,
0004    http://trojita.flaska.net/
0005 
0006    This program is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU General Public License as
0008    published by the Free Software Foundation; either version 2 of
0009    the License or (at your option) version 3 or any later version
0010    accepted by the membership of KDE e.V. (or its successor approved
0011    by the membership of KDE e.V.), which shall act as a proxy
0012    defined in Section 14 of version 3 of the license.
0013 
0014    This program is distributed in the hope that it will be useful,
0015    but WITHOUT ANY WARRANTY; without even the implied warranty of
0016    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017    GNU General Public License for more details.
0018 
0019    You should have received a copy of the GNU General Public License
0020    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021 */
0022 
0023 #ifndef PLUGIN_MANAGER
0024 #define PLUGIN_MANAGER
0025 
0026 #include <memory>
0027 #include <QObject>
0028 #include <QString>
0029 #include <QStringList>
0030 #include <QMap>
0031 #include <QPluginLoader>
0032 #include <QPointer>
0033 
0034 #include "Plugins/AddressbookPlugin.h"
0035 #include "Plugins/PasswordPlugin.h"
0036 #include "Plugins/SpellcheckerPlugin.h"
0037 
0038 class QSettings;
0039 
0040 namespace Cryptography {
0041 class PartReplacer;
0042 }
0043 
0044 namespace Plugins {
0045 
0046 class AddressbookPluginInterface;
0047 class PasswordPluginInterface;
0048 class SpellcheckerPluginInterface;
0049 
0050 class PLUGINMANAGER_EXPORT PluginManager : public QObject
0051 {
0052     Q_OBJECT
0053 public:
0054     using MimePartReplacers = std::vector<std::shared_ptr<Cryptography::PartReplacer>>;
0055     /** @short Create plugin manager instance and load plugins */
0056     PluginManager(QObject *parent, QSettings *settings, const QString &addressbookKey, const QString &passwordKey, const QString &spellcheckerKey);
0057 
0058     virtual ~PluginManager();
0059 
0060     /** @short Return list of addressbook plugin pairs (name, description) */
0061     QMap<QString, QString> availableAddressbookPlugins() const;
0062 
0063     /** @short Return list of password plugin pairs (name, description) */
0064     QMap<QString, QString> availablePasswordPlugins() const;
0065 
0066     /** @short What sleppcheckers are available? */
0067     QMap<QString, QString> availableSpellcheckerPlugins() const;
0068 
0069     /** @short Return name of addressbook plugin */
0070     QString addressbookPlugin() const;
0071 
0072     /** @short Return name of password plugin */
0073     QString passwordPlugin() const;
0074 
0075     /** @short Name of the spellchecking plugin */
0076     QString spellcheckerPlugin() const;
0077 
0078     /** @short Change the addressbook plugin and start using it */
0079     void setAddressbookPlugin(const QString &name);
0080 
0081     /** @short Change the password plugin and start using it */
0082     void setPasswordPlugin(const QString &name);
0083 
0084     /** @short Set the spellchecker plugin */
0085     void setSpellcheckerPlugin(const QString &name);
0086 
0087     /** @short Return interface of addressbook plugin or nullptr when plugin was not found */
0088     Plugins::AddressbookPlugin *addressbook() const;
0089 
0090     /** @short Return interface of password plugin or nullptr when plugin was not found */
0091     Plugins::PasswordPlugin *password() const;
0092 
0093     /** @short Interface of a sleppchecking plugin, or a nullptr when plugin was not found */
0094     Plugins::SpellcheckerPlugin *spellchecker() const;
0095 
0096     const MimePartReplacers &mimePartReplacers() const;
0097     void setMimePartReplacers(const MimePartReplacers &replacers);
0098 
0099 signals:
0100     void pluginsChanged();
0101     void pluginError(const QString &errorMessage);
0102 
0103 private slots:
0104     void loadPlugins();
0105 
0106 private:
0107     void loadPlugin(QObject *pluginInstance);
0108 
0109     QSettings *m_settings;
0110     QString m_addressbookKey;
0111     QString m_passwordKey;
0112     QString m_spellcheckerKey;
0113 
0114     QMap<QString, AddressbookPluginInterface *> m_availableAddressbookPlugins;
0115     QMap<QString, PasswordPluginInterface *> m_availablePasswordPlugins;
0116     QMap<QString, SpellcheckerPluginInterface *> m_availableSpellcheckPlugins;
0117 
0118     QString m_addressbookName;
0119     QString m_passwordName;
0120     QString m_spellcheckerName;
0121 
0122     QPointer<Plugins::AddressbookPlugin> m_addressbook;
0123     QPointer<Plugins::PasswordPlugin> m_password;
0124     QPointer<Plugins::SpellcheckerPlugin> m_spellchecker;
0125 
0126     MimePartReplacers m_mimePartReplacers;
0127 };
0128 
0129 } //namespace Common
0130 
0131 #endif //PLUGIN_MANAGER
0132 
0133 // vim: set et ts=4 sts=4 sw=4