/*
* Copyright (C) 2020 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/&gt;.
*
*/
#ifndef WIFIWIDGET_H
#define WIFIWIDGET_H

#include <QObject>
#include <QWidget>
#include <QPushButton>
#include <QProcess>
#include <QLabel>
#include <QVBoxLayout>
#include <QDBusInterface>
#include <QDBusReply>
#include <QDebug>
#include <QGSettings>
#include <QStyle>
#include "swichButtonOpenStatus.h"
#include "customstyle_switchNormalStatus.h"
#include <QPainter>
#include <QStyleOption>
#include <QPalette>
#include "../dbusmanager.h"

#define CONTROL_CENTER_WIFI "org.ukui.control-center.wifi.switch"
#define KYLIN_WIFI_GSETTING_VALUE "org.kylinnm.settings"

#define KYLIN_WIFI_PRESS_PATH          ":/image/arrow.svg"

#define KYLIN_WIFI_NORMAL_NAME          "pad_Wifi"
#define KYLIN_WIFI_PRESS_NAME           "pad_Wifi-open"
#define KYLIN_LINE_PRESS_NAME           "pb-network-online"
#define KYLIN_LINE_PRESS_PATH           ":/image/pb-network-online.png"

#define KYLIN_WIFI_100_PATH_NAME         "pad_Wifi-open"
#define KYLIN_WIFI_10_PATH_NAME          "wifi_10"
#define KYLIN_WIFI_30_PATH_NAME          "wifi_30"
#define KYLIN_WIFI_80_PATH_NAME          "wifi_80"
#define KYLIN_WIFI_no_PATH_NAME          "wifi_no"

#define KYLIN_WIFI_100_PATH         ":/image/pad_Wifi-open.svg"
#define KYLIN_WIFI_10_PATH          ":/image/wifi_10.svg"
#define KYLIN_WIFI_30_PATH          ":/image/wifi_30.svg"
#define KYLIN_WIFI_80_PATH          ":/image/wifi_80.svg"
#define KYLIN_WIFI_NO_PATH          ":/image/wifi_no.svg"

class WifiLabel;

class WifiWidget : public QWidget
{
    Q_OBJECT
public:
    explicit WifiWidget(QWidget *parent= nullptr);
    ~WifiWidget();

private:
    WifiLabel      *m_pWidgetButton;

    QLabel       *m_pWifiIconLabel; // 图标相关LABEL
    QLabel       *m_pWifihNameLabel; //名称相关LABEL
    QHBoxLayout  *m_pHboxButtonLayout;

    //wifi显示字段
    QString      m_wired_connection = QObject::tr("Wired connection");
    QString      m_not_Connected = QObject::tr("Not connected");
    QString      m_closed = QObject::tr("Closed");

    bool         m_bWifiIsEnable;
    bool         m_bLanStatus;

    void initMemberVariables();
    void initLayout();
    void initNetworkManagerConnect();

    void setwifi(QString wifiName, int wifisignal);
    void setLabelText(QString s);

    void getWifiSignal(const QString dBusPath, int& singalStrength);
    void updateIcon();
    bool checkWifiIsEnable();

    void paintEvent(QPaintEvent *event);
    void mousePressEvent(QMouseEvent *event);

private slots:
    void          WifiButtonClickSlot();
    void          onPropertiesChanged(QVariantMap qvm);
};

class WifiLabel : public QLabel
{
    Q_OBJECT
public:
    explicit WifiLabel(QWidget *parent = nullptr);

protected:
    virtual void mouseReleaseEvent(QMouseEvent *ev);

Q_SIGNALS:
    void LabelClicked();
};


#endif // WIFIWIDGET_H
