/*

Shutdown dialog

Copyright (C) 1997, 1998 Steffen Hansen <hansen@kde.org>
Copyright (C) 2000-2003,2005 Oswald Buddenhagen <ossi@kde.org>


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 KDMSHUTDOWN_H
#define KDMSHUTDOWN_H

#include "kdmconfig.h" // for HAVE_VTS
#include "kgverify.h"

#include <QPushButton> //<kpushbutton.h>

#include <QRadioButton>

class QGroupBox;
class QComboBox;
class QCheckBox;
class QLineEdit;
//class KGuiItem;
class QMovie; //alex

struct DpySpec;

enum { Authed = QDialog::Accepted + 1, Schedule };

class KDMShutdownBase : public FDialog, public KGVerifyHandler {
    Q_OBJECT
    typedef FDialog inherited;

  public:
    KDMShutdownBase(int _uid, QWidget *_parent);
    virtual ~KDMShutdownBase();

    int isNeedRoot() { return needRoot; } //alex

  protected Q_SLOTS:
    void accept() override;

  protected:
    virtual void accepted();

  protected:
    void updateNeedRoot();
    void complete(QWidget *prevWidget);

    QVBoxLayout *box;
#ifdef HAVE_VTS
    bool willShut;
#else
    static const bool willShut = true;
#endif
    bool mayNuke, doesNuke, mayOk, maySched;
#ifdef WITH_POWER_MANAGEMENT /*alex*/
    bool  willSuspend;
#endif
  private Q_SLOTS:
    void slotSched();
    void slotActivatePlugMenu();

  private:
    QPushButton *okButton, *cancelButton;
    QLabel *rootlab;
    KGStdVerify *verify;
    int needRoot, uid;

    static int curPlugin;
    static PluginList pluginList;

  public: // from KGVerifyHandler
    void verifyPluginChanged(int id) override;
    void verifyOk() override;
    void verifyFailed() override;
    void verifyRetry() override;
    void verifySetUser(const QString &user) override;
};


class KDMShutdown : public KDMShutdownBase {
    Q_OBJECT
    typedef KDMShutdownBase inherited;

  public:
    KDMShutdown(int _uid, QWidget *_parent = nullptr);
    static void scheduleShutdown(QWidget *_parent = nullptr);

  protected Q_SLOTS:
    void accept() override;

  protected:
    void accepted() override;

  private Q_SLOTS:
    void slotTargetChanged();
    void slotWhenChanged();

  private:
    QGroupBox *howGroup;
    QGroupBox *schedGroup;
    QRadioButton *restart_rb;
    QLineEdit *le_start, *le_timeout;
    QCheckBox *cb_force;
    QComboBox *targets;
    int oldTarget;
    int sch_st, sch_to;

};

class KDMRadioButton : public QRadioButton {
    Q_OBJECT
    typedef QRadioButton inherited;

  public:
    KDMRadioButton(const QString &label, QWidget *parent);

  private:
    void mouseDoubleClickEvent(QMouseEvent *) override;

  Q_SIGNALS:
    void doubleClicked();

};

class FlyAnimPushButton : public QPushButton { //alex
	Q_OBJECT
	typedef QPushButton inherited;

  public:
	FlyAnimPushButton( const QString &item, QWidget *parent );
	void setAnimationInfo( QLabel *mLabel, int animFrame, QPixmap *pm );
	void startOwnAnimation();
	void stopOwnAnimation();

protected:
    void focusInEvent(QFocusEvent *) override;
    void focusOutEvent(QFocusEvent *) override;
    void enterEvent(QEvent *) override;
    void leaveEvent(QEvent *) override;
private:
	QLabel  *masterLabel;
	int		 animFrame;
	QMovie  *savedMovie;
	QPixmap *animPixmap;
};

class KDMDelayedPushButton : public FlyAnimPushButton {
    Q_OBJECT
    typedef FlyAnimPushButton inherited;

  public:
    KDMDelayedPushButton(const QString/*KGuiItem*/ &item, QWidget *parent);
    void setDelayedMenu(QMenu *pop);

  private:
    QTimer popt;
};

class KDMSlimShutdown : public FDialog {
    Q_OBJECT
    typedef FDialog inherited;

  public:
    KDMSlimShutdown(QWidget *_parent = nullptr);
    static void externShutdown(int type, const QString &os, int uid, bool ask);

  private Q_SLOTS:
    void slotHalt();
    void slotReboot();
    void slotReboot(QAction *);
    void slotSched();

#ifdef WITH_POWER_MANAGEMENT /*alex*/
    void slotSuspend();
    void slotSuspend( QAction * );
#endif
  private:
    bool checkShutdown(int type, const QString &os);
    QStringList targetList;

#ifdef WITH_POWER_MANAGEMENT /*alex*/
    bool suspend_disk, suspend_ram, standby;
    QAction *qa_suspend_disk, *qa_suspend_ram, *qa_standby;
#endif
};

class KDMConfShutdown : public KDMShutdownBase {
    Q_OBJECT
    typedef KDMShutdownBase inherited;

  public:
    KDMConfShutdown(int _uid, const QList<DpySpec> &sessions, int type,
                    const QString &os, QWidget *_parent = nullptr);
};

class KDMCancelShutdown : public KDMShutdownBase {
    Q_OBJECT
    typedef KDMShutdownBase inherited;

  public:
    KDMCancelShutdown(int how, int start, int timeout, int force, int uid,
                      const QString &os, QWidget *_parent);
};

#endif /* KDMSHUTDOWN_H */
