/*
 * Project "Fingerprint GUI": Services for fingerprint authentication on Linux
 * Module: PolkitListener.cpp, PolkitListener.h
 * Purpose: Listens for polkit events
 *
 * @author  Wolfgang Ullrich
 * Copyright (C) 2008-2014  Wolfgang Ullrich
 */

/*
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef POLKITLISTENER_H
#define	POLKITLISTENER_H

#include <polkit-qt-1/PolkitQt1/Agent/Listener>
#include "PolkitDialogImpl.h"

using namespace PolkitQt1::Agent;

class PolkitListener : public Listener {
    Q_OBJECT
public:
    PolkitListener(QObject *parent=0);
    virtual ~PolkitListener();

public slots:
#ifdef LIBPOLKIT_QT_1_1
    void initiateAuthentication(
        const QString &actionId,
        const QString &message,
        const QString &iconName,
        const PolkitQt1::Details &details,
        const QString &cookie,
        const PolkitQt1::Identity::List &identities,
#else
    void initiateAuthentication(
        const QString &actionId,
        const QString &message,
        const QString &iconName,
        PolkitQt1::Details *details,
        const QString &cookie,
        QList<PolkitQt1::Identity *> identities,
#endif //LIBPOLKIT_QT_1_1
        PolkitQt1::Agent::AsyncResult* result);
    bool initiateAuthenticationFinish();
    void cancelAuthentication();
    void tryAgain();
    void finishObtainPrivilege();
    void request(const QString &request,bool echo);
    void completed(bool gainedAuthorization);
    void showError(const QString &text);

private:
    PolkitDialogImpl *dialog;
    bool inProgress;
    bool gainedAuthorization;
    bool wasCancelled;
    int numTries;
#ifdef LIBPOLKIT_QT_1_1
    QWeakPointer<Session> session;
    PolkitQt1::Identity::List identities;
    PolkitQt1::Identity selectedUser;
#else
    QPointer<Session> session;
    QList<PolkitQt1::Identity*>identities;
    PolkitQt1::Identity *selectedUser;
#endif //LIBPOLKIT_QT_1_1
    PolkitQt1::Agent::AsyncResult* result;
    QString cookie;
private slots:
    void dialogAccepted();
    void dialogCanceled();
#ifdef LIBPOLKIT_QT_1_1
    void userSelected(PolkitQt1::Identity identity);
#else
    void userSelected(PolkitQt1::Identity *identity);
#endif //LIBPOLKIT_QT_1_1
};
#endif	/* POLKITLISTENER_H */
