/*
 * Copyright (C) 2018 Tianjin KYLIN Information Technology Co., Ltd.
 *
 * 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 3, 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, see <http://www.gnu.org/licenses/>.
 *
**/
#ifndef LOCKWIDGET_H
#define LOCKWIDGET_H

#ifndef QT_NO_KEYWORDS
#define QT_NO_KEYWORDS
#endif

#include <QWidget>
#include <QResizeEvent>
#include <QDBusArgument>
#include "surewindow.h"
#include "xeventmonitor.h"

namespace Ui {
class LockWidget;
}


struct userInfo {
    int userId;
    QString userName;
    QDBusObjectPath userPath;
};

QDBusArgument &operator <<(QDBusArgument &arg, const userInfo &usersInfo);
const QDBusArgument &operator >>(const QDBusArgument &arg, userInfo &usersInfo);

class VirtualKeyboard;
class PowerManager;
class AuthDialog;
class Users;
class UserItem;
class DisplayManager;
class QMenu;
class QScrollArea;
class KylinNM;

class LockWidget : public QWidget
{
    Q_OBJECT

public:
    explicit LockWidget(QWidget *parent = 0);
    ~LockWidget();
    void closeEvent(QCloseEvent *event);
    void startAuth();
    void stopAuth();
    void setX11Focus();
    bool exitSubWidget();
Q_SIGNALS:
    void closed();
//    void capsLockChanged();

private:
    void initUI();
    void initUserMenu();
    void setVirkeyboardPos();
    void updateNetIcon(int status);
    bool getLoadStatus(const QString &name);
    int getNetStatus();
    QPixmap PixmapToRound(const QPixmap &src, int radius);
    void keyBdRelease(QString key);
private Q_SLOTS:
    void onUserAdded(const UserItem &user);
    void onUserDeleted(const UserItem &user);
    void onUserMenuTrigged(QAction *action);
    void showVirtualKeyboard();
    void showPowerManager();
    void showNetManager();
    void switchToGreeter();
    void switchToSureDialog(int type);
    void hideSureDialog();
    void confirmClicked();
    void hideNetManager();
    void onGlobalKeyPress(const QString &key);
    void onGlobalkeyRelease(const QString &key);
protected:
     bool eventFilter(QObject *obj, QEvent *event);
     void resizeEvent(QResizeEvent *event);
     void keyReleaseEvent(QKeyEvent *e);

private:
     Ui::LockWidget      *ui;
     AuthDialog          *authDialog;
     VirtualKeyboard     *vKeyboard = nullptr;
     PowerManager        *powermanager = nullptr;
     SureWindow          *sureWidget = nullptr;
     QTimer              *timer;
     QMenu               *usersMenu = nullptr;
     QList<QWidget *>     list;
     Users               *users;
     DisplayManager      *displayManager;
     int                 timeType;
     QString             dateType;
     QScrollArea         *scrollArea;
     QWidget             *scrollContents;

     KylinNM             *m_kylinNM = nullptr;
     QWidget             *m_NetManagerWidget;
     QStringList         m_loginedUser;
     bool		 isNetFinished = false;
     int                 powermanagerType;
     XEventMonitor      *xEventMonitor;
     int                nowAt = -1;
};

#endif // LOCKWIDGET_H
