//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
// RCS-ID:      $Id$
// Copyright (C) 2002 - 2010, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// ctlDefaultSecurityPanel.h - Panel with default security information
//
//////////////////////////////////////////////////////////////////////////


#ifndef CTL_DEFDEFSECPANEL_H
#define CTL_DEFDEFSECPANEL_H

#include <wx/wx.h>
#include <wx/notebook.h>

enum
{
    CTL_DEFPROPSQL=500,
    CTL_DEFMSG,
    CTL_DEFLBPRIV,
    CTL_DEFSTATICGROUP,
    CTL_DEFCBGROUP,
    CTL_DEFADDPRIV,
    CTL_DEFDELPRIV,
    CTL_DEFALLPRIV,
    CTL_DEFALLPRIVGRANT,
    CTL_DEFPRIVCB          // base for all privilege checkboxes, must be last
};

DECLARE_EVENT_TYPE(EVT_DEFAULTSECURITYPANEL_CHANGE, -1)

class pgConn;

class ctlDefaultSecurityPanel : public wxPanel
{

public:

    ctlDefaultSecurityPanel(wxNotebook *nb, const wxString &privList, const char *privChars, wxImageList *imgList);
    ~ctlDefaultSecurityPanel();

    ctlListView *lbPrivileges;
    ctlComboBox *cbGroups;
    wxStaticText *stGroup;
    ctlComboBox *cbSchemas;
    wxStaticText *stSchema;
    ctlComboBox *cbTypes;
    wxStaticText *stType;
    void SetConnection(pgConn *conn);

    /*
     *  Except column level privileges, column will be always an empty string in any case
     */
    wxString GetGrant(const wxString &allPattern, const wxString &grantObject, wxArrayString *currentAcl=0, wxString column = wxEmptyString);
    bool DisablePrivilege(const wxString &priv);
protected:
    wxNotebook *nbNotebook;
    pgConn *connection;

    wxButton *btnAddPriv, *btnDelPriv;
    int privilegeCount;
    const char *privilegeChars;
    wxCheckBox **privCheckboxes;
    wxCheckBox *allPrivileges, *allPrivilegesGrant;

    void OnPrivSelChange(wxListEvent &ev);
    void OnAddPriv(wxCommandEvent& ev);
    void OnGroupChange(wxCommandEvent &ev);
    void OnDelPriv(wxCommandEvent& ev);
    void OnPrivCheck(wxCommandEvent& ev);
    void OnPrivCheckAll(wxCommandEvent& ev);
    void OnPrivCheckAllGrant(wxCommandEvent& ev);

    void CheckGrantOpt(int index);
    bool GrantAllowed() const;


    DECLARE_EVENT_TABLE()
};

#endif
