#ifndef POWERLISTWIDGET_H
#define POWERLISTWIDGET_H

#include <QDebug>
#include <QObject>
#include <QWidget>
#include <QString>
#include <QDBusReply>
#include <QScrollBar>
#include <QDBusInterface>

#include "mylistwidget.h"
#include "poweritemwidget.h"
#include "lock-dialog/lockdialogmodel.h"

class MyListWidget;
class PowerItemWidget;
class QListWidgetItem;
class LockDialogModel;
#define LISTSZIE(x) (sizeof(x)/sizeof(x[0]))
//电源管理界面
#define BTN_ITEM_SIZE_WIDTH     204
#define BTN_ITEM_SIZE_HEIGHT    200
#define BTN_ICON_SIZE_WIDTH     48
#define BTN_ICON_SIZE_HEIGHT    48

enum stateType {
    REBOOT,
    SHUTDOWN,
    SLEEP,
    HIBERNATE,
    NOTHING
};

class PowerListWidget : public MyListWidget
{
    Q_OBJECT
public:

    explicit PowerListWidget(LockDialogModel *model,QWidget *parent = nullptr);
    ~PowerListWidget();
    LockDialogModel * m_modelLockDialog;

    void updateWidgetSize();
    void setSystemSuspend1();

    struct Btn_Data_Struct {
        QString m_strName;
        QString m_strToolTip;
        QString m_strIcon;
        bool m_show_flag;

        int m_item_width;
        int m_item_height;
        int m_icon_width;
        int m_icon_height;
        QString canFuncName;
        QString setFuncName;
        int m_inhibitType;
//        void (*func)();
    } powerBtnList[4] = {
        //1.Hibernate
        {
            .m_strName      = tr("Hibernate"),
            .m_strToolTip   = tr("Turn off your computer, but the app stays open. When the computer is turned on, it can be restored to the state you left"),
            .m_strIcon      = ":/image/assets/hibernate.svg",
            .m_show_flag    = true,
            .m_item_width   = BTN_ITEM_SIZE_WIDTH,
            .m_item_height  = BTN_ITEM_SIZE_HEIGHT,
            .m_icon_width   = BTN_ICON_SIZE_WIDTH,
            .m_icon_height  = BTN_ICON_SIZE_HEIGHT,
            .canFuncName    = "CanHibernate",
            .setFuncName    = "Hibernate",
            .m_inhibitType  = HIBERNATE
        },
        //2.Suspend
        {
            .m_strName      = tr("Suspend"),
            .m_strToolTip   = tr("The computer stays on, but consumes less power. The app stays open and can quickly wake up and revert to where you left off"),
            .m_strIcon      = ":/image/assets/suspend.svg",
            .m_show_flag    = true,
            .m_item_width   = BTN_ITEM_SIZE_WIDTH,
            .m_item_height  = BTN_ITEM_SIZE_HEIGHT,
            .m_icon_width   = BTN_ICON_SIZE_WIDTH,
            .m_icon_height  = BTN_ICON_SIZE_HEIGHT,
            .canFuncName    = "CanSuspend",
            .setFuncName    = "Suspend",
            .m_inhibitType  = SLEEP
        },
        //3.reboot
        {
            .m_strName      = tr("Restart"),
            .m_strToolTip   = tr("The computer stays on, but consumes less power. The app stays open and can quickly wake up and revert to where you left off"),
            .m_strIcon      = ":/image/assets/reboot.svg",
            .m_show_flag    = true,
            .m_item_width   = BTN_ITEM_SIZE_WIDTH,
            .m_item_height  = BTN_ITEM_SIZE_HEIGHT,
            .m_icon_width   = BTN_ICON_SIZE_WIDTH,
            .m_icon_height  = BTN_ICON_SIZE_HEIGHT,
            .canFuncName       = "CanReboot",
            .setFuncName       = "Reboot",
            .m_inhibitType  = REBOOT
        },
        //4.Shut Down
        {
            .m_strName      = tr("Power Off"),
            .m_strToolTip   = tr("Close all apps, and then shut down your computer"),
            .m_strIcon      = ":/image/assets/shutdown.svg",
            .m_show_flag    = true,
            .m_item_width   = BTN_ITEM_SIZE_WIDTH,
            .m_item_height  = BTN_ITEM_SIZE_HEIGHT,
            .m_icon_width   = BTN_ICON_SIZE_WIDTH,
            .m_icon_height  = BTN_ICON_SIZE_HEIGHT,
            .canFuncName    = "CanPowerOff",
            .setFuncName    = "PowerOff",
            .m_inhibitType  = SHUTDOWN
        }
    };

    void setSystemPowerStatus(QString);

protected:
    bool eventFilter(QObject *obj, QEvent *event);

Q_SIGNALS:
    void mulUsersLogined(QString inhibitType);
    void showInhibitWarning(QStringList list, int type);

public Q_SLOTS:
    void onUpdateListInfo();
    void onListItemClicked(QListWidgetItem *item);

private:

//    QDBusInterface *sessionInterface;
//    QDBusInterface *loginInterface;

    bool    m_canSuspend;
    bool    m_canHibernate;
    bool    m_canReboot ;
    bool    m_canShutDown ;

    void initUI();
    void initBtnShowFlag();
    void initConnections();
//    void initDBusInterface();

};

#endif // POWERLISTWIDGET_H
