/*
 * Copyright (c) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
 * Copyright (c) 2010 Tobias Koenig <tokoe@kdab.com>
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifndef PIMCOMMON_ACLMANAGER_H
#define PIMCOMMON_ACLMANAGER_H

#include "pimcommonakonadi_private_export.h"

#include <Collection>

#include <QObject>

class QAbstractItemModel;
class QAction;
class QItemSelectionModel;

namespace PimCommon {
class PIMCOMMONAKONADI_TESTS_EXPORT AclManager : public QObject
{
    Q_OBJECT

    Q_PROPERTY(Akonadi::Collection collection READ collection WRITE setCollection NOTIFY collectionChanged)
    Q_PROPERTY(QAbstractItemModel *model READ model)
    Q_PROPERTY(QItemSelectionModel *selectionModel READ selectionModel)
    Q_PROPERTY(QAction *addAction READ addAction)
    Q_PROPERTY(QAction *editAction READ editAction)
    Q_PROPERTY(QAction *deleteAction READ deleteAction)

public:
    /**
     * Creates a new ACL manager.
     *
     * @param parent The parent object.
     */
    explicit AclManager(QObject *parent = nullptr);

    /**
     * Destroys the ACL manager.
     */
    ~AclManager();

    /**
     * Sets the @p collection whose ACL will be managed.
     */
    void setCollection(const Akonadi::Collection &collection);

    /**
     * Sets the @p collection whose ACL are managed.
     */
    Q_REQUIRED_RESULT Akonadi::Collection collection() const;

    /**
     * Returns the model that represents the ACL of the managed collection.
     */
    Q_REQUIRED_RESULT QAbstractItemModel *model() const;

    /**
     * Returns the selection model that is used by the manager to select the
     * ACL entry to work on.
     */
    Q_REQUIRED_RESULT QItemSelectionModel *selectionModel() const;

    /**
     * Returns the action that handles adding new ACL entries.
     */
    Q_REQUIRED_RESULT QAction *addAction() const;

    /**
     * Returns the action that handles editing the currently selected ACL entry.
     */
    Q_REQUIRED_RESULT QAction *editAction() const;

    /**
     * Returns the action that handles deleting the currently selected ACL entry.
     */
    Q_REQUIRED_RESULT QAction *deleteAction() const;

    void setChanged(bool b);
public Q_SLOTS:
    /**
     * Saves the changes of the ACL back to the collection.
     */
    void save(bool recursive);

Q_SIGNALS:
    /**
     * This signal is emitted whenever the collection whose ACL will
     * be managed has changed.
     */
    void collectionChanged(const Akonadi::Collection &collection);

    void collectionCanBeAdministrated(bool canAdmin);

private:
    //@cond PRIVATE
    class Private;
    Private *const d;
    //@endcond
};
}

#endif
