#ifndef TRAYICON_H
#define TRAYICON_H

#include <QQuickItem>
#include <QQuickPaintedItem>
#include <QIcon>
#include <QPainter>
#include <QGSettings/QGSettings>
#include <QGSettings>
#include <QProcess>
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
#include <QtQml/qqml.h>
#endif

class TrayIcon : public QQuickPaintedItem
{
    Q_OBJECT
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
    QML_ELEMENT
#endif
    Q_PROPERTY(QIcon icon READ icon)
    Q_PROPERTY(QString source READ source WRITE setSource NOTIFY sourceChanged)
    Q_PROPERTY(int type READ type WRITE setType NOTIFY typeChanged)
    Q_PROPERTY(QString timeformat READ timeformat WRITE settimeformat NOTIFY timeformatChanged)
    Q_PROPERTY(QString dateformat READ dateformat WRITE setdateformat NOTIFY dateformatChanged)

public:
    enum IconType {
        Sound,
        Power,
        Message,
        Wifi,
        Bluetooth,
    };
    Q_ENUMS(IconType)
    TrayIcon(QQuickPaintedItem *parent = nullptr);

    QIcon icon();

    QString source();
    void setSource(const QString &source);

    int type();
    void setType(const int &type);

    void paint(QPainter *painter);

    QString timeformat();
    void settimeformat(const QString &timeformat);

    QString dateformat();
    void setdateformat(const QString &dateformat);

    void getSoundValue();

    Q_INVOKABLE void initPowerDbusaddrest();


    void getBluetoothSwitch();
    void getTimeDateState();
    void setVolumeIcon(int value);
    void setPowerIcon(int value);
    void setPowerChargeIcon(int value);
    void setMessageIcon(bool value);
    void setNetIcon(int value, bool state);
    void setBluetoothIcon(bool state);

private:
    QIcon m_icon;
    QString m_source;
    int m_type;
    QString m_timeformat;
    QString m_dateformat;
    QGSettings *sound;
    QGSettings *messageSetting;
    QGSettings *bluetoothSetting;
    QGSettings *timeSetting;
    QString powerpath;
    int netconnectType = 0; //wire = 1, wifi = 2
    bool messageState;

signals:
    void sourceChanged();
    void typeChanged();
    void timeformatChanged();
    void dateformatChanged();

    void soundValueChanged();
    void wifiStateChanged();
    void messageStateChanged();
    void powerValueChanged();
    void powerChargeValueChanged(int powerValue);

public slots:
    void initPowerValue();
    void getWifiValue();
    void getMessageValue();
};

#endif // TRAYICON_H
