File indexing completed on 2024-11-24 04:53:25

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 ADDRESSBOOK_INTERFACE
0024 #define ADDRESSBOOK_INTERFACE
0025 
0026 #include <QList>
0027 #include <QObject>
0028 #include <QPair>
0029 #include <QString>
0030 #include <QStringList>
0031 
0032 #include "PluginJob.h"
0033 
0034 namespace Plugins
0035 {
0036 
0037 struct PLUGINMANAGER_EXPORT NameEmail
0038 {
0039     NameEmail(const QString &n, const QString &e) : name(n), email(e) {}
0040     QString name;
0041     QString email;
0042 };
0043 
0044 typedef QList<NameEmail> NameEmailList;
0045 
0046 class PLUGINMANAGER_EXPORT AddressbookJob : public PluginJob
0047 {
0048     Q_OBJECT
0049 
0050 public:
0051     /** @short Error emitted by error signal */
0052     enum Error {
0053         UnknownError, /**< Unknown error */
0054         Stopped /**< Emitted when job stopped */
0055     };
0056 
0057 signals:
0058     /** @short Emitted when job finishes unsuccessful with error */
0059     void error(Plugins::AddressbookJob::Error error);
0060 
0061 protected:
0062     AddressbookJob(QObject *parent);
0063 };
0064 
0065 class PLUGINMANAGER_EXPORT AddressbookCompletionJob : public AddressbookJob
0066 {
0067     Q_OBJECT
0068 
0069 signals:
0070     /** @short Emitted when completion is available */
0071     void completionAvailable(const Plugins::NameEmailList &completion);
0072 
0073 protected:
0074     AddressbookCompletionJob(QObject *parent);
0075 };
0076 
0077 class PLUGINMANAGER_EXPORT AddressbookNamesJob : public AddressbookJob
0078 {
0079     Q_OBJECT
0080 
0081 signals:
0082     /** @short Emitted when pretty names for address is available */
0083     void prettyNamesForAddressAvailable(const QStringList &displayNames);
0084 
0085 protected:
0086     AddressbookNamesJob(QObject *parent);
0087 };
0088 
0089 class PLUGINMANAGER_EXPORT AddressbookPlugin : public QObject
0090 {
0091     Q_OBJECT
0092 
0093 public:
0094     /** @short Features returned by method features */
0095     enum Feature {
0096         FeatureAddressbookWindow = 1 << 0, /**< Plugin has support for opening addressbook window via openAddressbookWindow */
0097         FeatureContactWindow = 1 << 1, /**< Plugin has support for opening contact window via openContactWindow */
0098         FeatureAddContact = 1 << 2, /**< Plugin has support for adding new contact via openContactWindow */
0099         FeatureEditContact = 1 << 3, /**< Plugin has support for editing existing contact via openContactWindow */
0100         FeatureCompletion = 1 << 4, /**< Plugin has support for completion via requestCompletion */
0101         FeaturePrettyNames = 1 << 5 /**< Plugin has support for display names via requestPrettyNamesForAddress */
0102     };
0103 
0104     Q_DECLARE_FLAGS(Features, Feature)
0105 
0106     /** @short Return implementation features */
0107     virtual Features features() const = 0;
0108 
0109 public slots:
0110     /** @short Request a list of pairs (name, email) matching contacts and return AddressbookJob
0111      *  @p input is input string
0112      *  @p ignores is list of strings which are NOT included in result
0113      *  @p max is the demanded maximum reply length, negative value means "uncapped"
0114      */
0115     virtual AddressbookCompletionJob *requestCompletion(const QString &input, const QStringList &ignores = QStringList(), int max = -1) = 0;
0116 
0117     /** @short Request a list of display names matching the given e-mail address and return AddressbookJob
0118      *  @p email is e-mail address
0119      */
0120     virtual AddressbookNamesJob *requestPrettyNamesForAddress(const QString &email) = 0;
0121 
0122     /** @short Open window for addressbook manager */
0123     virtual void openAddressbookWindow() = 0;
0124 
0125     /** @short Open window for specified contact
0126      *  first try to match contact by email, then by name
0127      *  if contact not exist, open window for adding new contact and fill name and email strings
0128      */
0129     virtual void openContactWindow(const QString &email, const QString &displayName) = 0;
0130 
0131 protected:
0132     AddressbookPlugin(QObject *parent);
0133 };
0134 
0135 Q_DECLARE_OPERATORS_FOR_FLAGS(AddressbookPlugin::Features)
0136 
0137 }
0138 
0139 #endif //ADDRESSBOOK_INTERFACE
0140 
0141 // vim: set et ts=4 sts=4 sw=4