Hello,

here is new version of interface. I added static function formatAddress from 
src/AbookAddressbook/AbookAddressbook.cpp as 
suggested Kevin, removed const from slot methods and complete() and 
prettyNamesForAddress() are now async (when done 
emitting signals). Because qt plugin interface can have only pure virtual 
functions (and no signal/slots) I added factory class 
which will be qt plugin interface.

#ifndef ADDRESSBOOK_INTERFACE
#define ADDRESSBOOK_INTERFACE

#include <QObject>
#include <QStringList>
#include <QtPlugin>

class AddressbookInterface : public QObject {

    Q_OBJECT

public:
    AddressbookInterface(QObject * parent) : QObject(parent) {}
    virtual ~AddressbookInterface() {}

public slots:
    /**
     * @short Search for a list of matching contacts in the form "[Name 
<]a...@mail.com[>]" and emit signal completeResult
     *
     * - Matches are case INsensitive
     * - The match aligns to either Name or a...@mail.com, ie. "ja" or "jkt" 
match
     *   "Jan Kundrát <j...@gentoo.org>" but "gentoo" does not
     * - Strings in the ignore list are NOT included in the return, despite 
they may match.
     * - The return can be empty.
     *
     * - @p max defines the demanded maximum reply length
     * It is intended to improve performance in the implementations
     * If you reimplement this, please notice that the return can be longer, 
but the client
     * will not make use of that. Negative values mean "uncapped"
     *
     * A maximum value is sufficient since typing "a" and getting a list with a 
hundred entries which
     * one will then navigate for the address unlikely a real use case - so 
there's no point in presenting
     * more than <place random number here> entries (or look them up, or 
transmit them)
     **/
    virtual void startComplete(const QString &input, const QStringList &ignores 
= QStringList(), int max = -1) = 0;

    /**
     * @short Search for a list of display names matching the given e-mail 
address and emit signal prettyNamesForAddressResult
     **/
    virtual void startPrettyNamesForAddress(const QString &email) = 0;

    /**
     * @short Open window for addressbook manager
     **/
    virtual void openAddressbookWindow() = 0;

    /**
     * @short Open window for edit contact
     * first try to match contact by email, then by name
     * if contact not exist, open window for adding new contact and fill name 
and email strings
     * empty email and name strings means opening window for adding new contact
     **/
    virtual void openEditContactWindow(const QString &email = QString(), const 
QString &name = QString()) = 0;

private:
    /**
     * @short Return name and email in format "[Name <]a...@mail.com[>]" needed 
by method startComplete()
     */
    static inline QString formatAddress(const QString &name, const QString 
&email) {
        if (name.isEmpty() || name == email) return email;
        else return name + " <" + email + '>';
    }

signals:
    /**
     * @short Emitted when method startComplete() finish
     **/
    void completeResult(const QString &input, const QStringList &list);

    /**
     * @short Emitted when method startPrettyNamesForAddress() finish
     */
    void prettyNamesForAddressResult(const QString &email, const QStringList 
&displayNames);

};

class AddressbookFactoryInterface {

public:
    /**
     * @short Return new AddressbookInterface instance implemented by plugin
     */
    virtual AddressbookInterface * create(QObject * parent) = 0;

};

Q_DECLARE_INTERFACE(AddressbookFactoryInterface, "AddressbookFactoryInterface");

#endif //ADDRESSBOOK_INTERFACE

-- 
Pali Rohár
pali.ro...@gmail.com

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to