Hello, here is new version of password interface which using Jobs

#ifndef PASSWORD_INTERFACE
#define PASSWORD_INTERFACE

#include <QObject>
#include <QString>
#include <QtPlugin>

class PasswordJob : public QObject {

    Q_OBJECT

public:
    enum Error {
        NoError = 0,
        NoPassword,
        Stopped,
        OtherError,
    };

    enum Type {
        Invalid = 0,
        Request,
        Store,
        Delete,
    };

    QString accountId() { return m_accountId; }
    QString accountType() { return m_accountType; }
    QString password() { return m_password; }
    PasswordJob::Type type() { return m_type; }
    PasswordJob::Error error() { return m_error; }

public slots:
    /**
     * @short Start job
     **/
    virtual void start() = 0;

    /**
     * @short Stop job
     **/
    virtual void stop() = 0;

signals:
    /**
     * @short Emitted when job successfull finish
     **/
    void finished();

    /**
     * @short Emitted when job finish unsuccessfull with error
     **/
    void error(PasswordJob::Error error);

protected:
    PasswordJob(QObject *parent, PasswordJob::Type t, const QString &aId, const 
QString &aT, const QString &p = QString()) : 
QObject(parent), m_type(t), m_accountId(aId), m_accountType(aT), m_password(p), 
m_error(PasswordJob::NoError) {}

    /**
     * @short Set password - this should be called only if PasswordJob::Type is 
PasswordJob::Requst
     **/
    void setPassword(const QString &str) { m_password = str; }

    /**
     * @short Set and emit error when job finish unsuccessfull
     **/
    void setError(PasswordJob::Error e) { m_error = e; emit error(e); }

private:
    QString m_accountId;
    QString m_accountType;
    QString m_password;
    PasswordJob::Type m_type;
    PasswordJob::Error m_error;

};

class PasswordInterface : public QObject {

    Q_OBJECT

public slots:
    /**
     * @short Request password associated with accountId and accountType and 
return PasswordJob
     **/
    virtual PasswordJob *requestPassword(const QString &accountId, const 
QString &accountType) = 0;

    /**
     * @short Save password for accountId and accountType and return PasswordJob
     **/
    virtual PasswordJob *storePassword(const QString &accountId, const QString 
&accountType, const QString &password) = 0;

    /**
     * @short Delete password for accountId and accountType and return 
PasswordJob
     **/
    virtual PasswordJob *deletePassword(const QString &accountId, const QString 
&accountType) = 0;

protected:
    PasswordInterface(QObject *parent) : QObject(parent) {}

};

class PasswordFactoryInterface {

public:
    /**
     * @short Return name of plugin
     **/
    virtual QString name() const = 0;

    /**
     * @short Return description of plugin
     **/
    virtual QString description() const = 0;

    /**
     * @short Return true if this plugin is valid and can be used (e.g this 
password storage is available)
     **/
    virtual bool isValid() const = 0;

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

};

Q_DECLARE_INTERFACE(PasswordFactoryInterface, "PasswordFactoryInterface");

#endif //PASSWORD_INTERFACE

-- 
Pali Rohár
[email protected]

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

Reply via email to