/*
* 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;.
*
*/

#include <QObject>
#include <QWidget>
#include <QPushButton>
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QtDBus>
#include <QStyleOption>
#include <QPainter>
#include <QIcon>
#include <QGSettings>
#include <QThread>
#include "swichButtonOpenStatus.h"
#include "customstyle_switchNormalStatus.h"

#define KYLIN_BLUETOOTH_NORMAL_NAME     "pad_bluetooth.svg"
#define KYLIN_BLUETOOTH_PRESS_NAME      "pad_bluetooth-open.svg"
#define KYLIN_BLUETOOTH_ARROW_NAME      "arrow"

#define KYLIN_BLUETOOTH_NORMAL_PATH     ":/image/pad_bluetooth.svg"
#define KYLIN_BLUETOOTH_PRESS_PATH      ":/image/pad_bluetooth-open.svg"
#define KYLIN_BLUETOOTH_ARROW_PATH      ":/image/arrow.svg"

#define KYLIN_BLUETOOTH_SERVER_NAME      "com.ukui.bluetooth"
#define KYLIN_BLUETOOTH_SERVER_PATH      "/com/ukui/bluetooth"
#define KYLIN_BLUETOOTH_SERVER_INTERFACE "com.ukui.bluetooth"

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

class bluetooththread;
class BlueToolsLabel;

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

    void initMemberVariables();
    void initLayout();
    bool initBluetoothDbus();
    void initBluetoothStatus();
    void setBluetoothStatus();

    enum TaskWidgetStatus{NORMAL, HOVER, PRESS};
    TaskWidgetStatus status = NORMAL;

private:
    QLabel          *m_pbluetoothIconLabel;
    QLabel          *m_pbluetoothNameLabel;
    BlueToolsLabel  *m_pbluetoothButton;
    QHBoxLayout     *m_pHboxButtonLayout;

    QStyle          *m_pStyleNormal;

    QDBusInterface*  m_pServiceInterface;
    bool             m_bbluetoothStatus = false;
    bool             m_constatus = false;        //是否连接蓝牙的状态值，默认未连接
    bluetooththread *m_bbluetooththread;

    QString      m_not_Connected;
    QString      m_closed;
    QString      m_connectDevice;

    QStringList  m_devAddress;
    QStringList  m_devName;

    void setLabelText(QString s);
    void handBlueToothData();

protected:
    void mouseReleaseEvent(QMouseEvent *event);
    void paintEvent(QPaintEvent *event);

private slots:
    void setButtonclickSlots();
    void bluetoothservice(bool status);
    void updateBluetoothStatus(QString arg, bool status);
    void removeBluetoothStatus(QString arg);
};

class bluetooththread : public QThread
{
    Q_OBJECT
signals:
    void result(bool bluestatus);
private:
    void run();
};

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

protected:
    virtual void mouseReleaseEvent(QMouseEvent *ev);

Q_SIGNALS:
    void LabelClicked();


};

