/*
* Copyright (C) 2019 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 NOTIFICATION_PLUGIN_H
#define NOTIFICATION_PLUGIN_H

#include <QtWidgets>
#include <QDebug>
#include <QPainter>
#include "notification_interface.h"
#include "notificationDbus.h"
#include "appmsg.h"
#include "scrollareawidget.h"
#include "customstylePushbutton2.h"
#include "../dbusmanager.h"
#include "../gsettingmanager.h"
#include "../dataprocess.h"

#define NOTIFICATION_CLEAR_BUTTON     "Notification Clear Button "
#define CLEARALLMESSAGE               "ClearAllMessage"

#define NOTIFICATION_SETTING_BUTTON   "Notification Setting Button"
#define OPEN_SETTING                  "Open Setting"

#define SIDEBAR_AND_PANEL_DISTANCE 8

class AppMsg;
class ScrollAreaWidget;
class ExternalLabel;

class NotificationPlugin : public QObject, public NotificationInterface
{
    Q_OBJECT

    /* Q_INTERFACES宏用于告诉Qt该类实现的接口 */
    Q_INTERFACES(NotificationInterface)

    /* Q_PLUGIN_METADATA宏用于描述插件元数据 */
    Q_PLUGIN_METADATA(IID NotificationInterface_iid FILE "notificationPlugin.json")

    /* 申明该类有D-BUS服务接口 */
    //Q_CLASSINFO("D-Bus Interface", "com.scorpio.test.value")

public:
    NotificationPlugin();
    virtual QWidget* centerWidget() override;    // 消息通知插件接口
    virtual void showNotification() override;    // 展开时，将通知列表时间刷新
    virtual void hideNotification() override;    // 隐藏时，将通知列表折叠
    AppMsg* getAppMsgAndIndexByName(QString strAppName, int& nIndex);

private:
    void                    initTrans();         // 初始化翻译文件
    void                    initUI();            // 初始化界面
    void                    initAttribute();     // 初始化界面属性
    void                    initLayout();        // 初始化布局
    void                    initDbus();          // 初始化dbus
    void                    initGsetting();      // 消息通知的gsetting 初始化
    void                    initAnimation();     // 初始化动画

    QWidget*                m_pMainWidget;                      //主界面
    QVBoxLayout*            m_pMainWidgetVLayout;               //主界面自上而下布局器

    QWidget*                m_pTitleWidget;                     //通知顶部标签界面
    QHBoxLayout*            m_pTitleWidgetHLayout;              //通知顶部标签界面自左而右布局器，第一行左侧标签“最近消息”，右侧一个清空按钮，一个设置按钮

    QWidget*                m_pExternalNotifyWidget;            //外层消息列表界面
    QHBoxLayout*            m_pExternalNotifyWidgetHLayout;     //外层消息列表界面布局

    QList<AppMsg*>          m_listAppMsg;                       //对于SingleMsg类对象用list表记录

    ScrollAreaWidget*       m_pNotifyQScrollAreaWidget;         //通知列表
    QWidget*                m_pInsideNotifyWidget;              //内层通知列表部件
    QVBoxLayout*            m_pInsideNotifyWidgetVLayout;       //内层通知列表自上而下布局器

    QLabel*                 m_pNotificationLabel;               //标签-最近消息
    ExternalLabel*          m_pMessageCenterLabel;              //标签-暂无消息通知

    QPushButton*            m_pClearAllNotifyButton;            //清除按钮
    QPushButton*            m_pSettingNotifyButton;             //设置按钮

    NotificationDbus*       m_pNotifyDbus ;                     //调用消息通知dbus类

    QPropertyAnimation          *m_pAnimationHideSidebarNotifition;
signals:
    void Sig_onNewNotification();                               //更新侧边栏托盘图标提示信号

public slots:
    uint onAddSingleNotify(QString strAppName, QString strIconPath, QString strSummary, QString strBody, QString urlStr,
                           QString actions, QDateTime dateTime, int maxNum);    //处理新增单条通知

    void onClearAllMessage();                                   //清除所有消息
    void onClearAppMsg(AppMsg* pAppMsg);                        //处理删除通知应用消息槽函数
    void onCallControlPanel();                                  //调用控制面板
    void onCloseAppMsg(QString strAppName);                     //配置实时关闭通知消息
    void onUpdateAppMaxNum(QString strAppName, int maxNum);     //配置实时更新通知消息最大数
    void onUpdateAnimationData(QString arg);                    //更新动画数据
};


class ExternalLabel:public QLabel
{

public:
    ExternalLabel();
    void paintEvent(QPaintEvent *e);                //重绘事件
};

#endif // NOTIFICATION_PLUGIN_H
