#include "systemmanagedialog.h"
#include "ui_systemmanagedialog.h"

SystemManageDialog::SystemManageDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::SystemManageDialog),
    m_itemPerPage(12)
{
    ui->setupUi(this);
    setWindowFlags (Qt::Window | Qt::FramelessWindowHint);
    setWindowModality(Qt::ApplicationModal);

    connect(g_pMachine, SIGNAL(siEXBInfoChange()), this, SLOT(slotEXBInfoChange()));

    this->move(0+g_mainWidgetPos.x(),0+g_mainWidgetPos.y());
    initDialog();
    initControl();
    initArabControlPos();

    m_logType = 0;

    m_curConnectWifi.clear();//当前连接的wifi
    m_curConnectWifiPass.clear();//当前连接的wifi密码
    m_curConnectMode = false;//当前连接的方式
    ui->labelCurIP->clear();

    ui->buttonSetAutoIP->setEnabled(false);
    ui->buttonSetStaticIP->setEnabled(false);
}

SystemManageDialog::~SystemManageDialog()
{
    delete ui;
}

//初始化窗体控件，包括位置、尺寸、样式
void SystemManageDialog::initControl()
{
    m_itemBtnList.clear();
    m_itemBtnList.append(ui->button1);
    m_itemBtnList.append(ui->button2);
    m_itemBtnList.append(ui->button3);
    m_itemBtnList.append(ui->button4);
    m_itemBtnList.append(ui->button5);
    ui->button6->setVisible(false);//隐藏
    ui->button7->setVisible(false);
    ui->button8->setVisible(false);
    ui->button9->setVisible(false);
    ui->button10->setVisible(false);
    ui->button11->setVisible(false);
    ui->button12->setVisible(false);

    if(g_emResolut == resolution1910)//1920x1080的分辨率每页显示12个条目
    {
        ui->button6->setVisible(true);//显示
        ui->button7->setVisible(true);
        ui->button8->setVisible(true);
        ui->button9->setVisible(true);
        ui->button10->setVisible(true);
        ui->button11->setVisible(true);
        ui->button12->setVisible(true);
        m_itemBtnList.append(ui->button6);
        m_itemBtnList.append(ui->button7);
        m_itemBtnList.append(ui->button8);
        m_itemBtnList.append(ui->button9);
        m_itemBtnList.append(ui->button10);
        m_itemBtnList.append(ui->button11);
        m_itemBtnList.append(ui->button12);
    }
    else if(g_emResolut == resolution1006)//1024x600的分辨率每页显示8个条目
    {
        ui->button6->setVisible(true);//显示
        ui->button7->setVisible(true);
        ui->button8->setVisible(true);
        m_itemBtnList.append(ui->button6);
        m_itemBtnList.append(ui->button7);
        m_itemBtnList.append(ui->button8);
    }

    //根据不同分辨率设置控件的位置和尺寸
    switch (g_emResolut)
    {
    case resolution1910:
        initResolution1910();
        break;
    case resolution1006:
        initResolution1006();
        break;
    default:
        this->resize(1920,1080);
        break;
    }

    initControlStyle();//初始化窗体控件样式
}

//初始化窗体控件为1920x1080分辨率
void SystemManageDialog::initResolution1910()
{
    this->resize(1920,1080);
    ui->frameBack->setGeometry(0,0,1920,1080);
    ui->buttonTypeLogo->setGeometry(128,66,78,78);
    ui->labelMainTitle->setGeometry(226,60,1000,48);
    ui->labelSubTitle->setGeometry(302,112,1000,36);

    ui->frameRightUp->setGeometry(1700,92,300,72);
    ui->buttonDelete->setGeometry(0,0,66,66);
    ui->buttonSelectAll->setGeometry(0,0,66,66);
    ui->buttonExport->setGeometry(80,0,66,66);

    ui->frameRightUpWIFI->setGeometry(1200,92,600,72);
    ui->buttonRefresh->setGeometry(500,0,66,66);
    ui->labelCurIP->setGeometry(0,0,500,66);

    ui->buttonChangeLog->setGeometry(10,0,66,66);

    for(int i = 0; i < m_itemPerPage; i++)
    {
        m_itemBtnList[i]->setGeometry(295,180 + i * 64,1330,58);
    }

    ui->framePageBtn->setGeometry(1120,990,800,70);
    ui->labelPage->setGeometry(32,1008,200,40);
    ui->labelExplain->setGeometry(240,960,660,110);
    ui->buttonPgUp->setGeometry(0,0,168,70);
    ui->buttonPgDn->setGeometry(200,0,168,70);
    ui->buttonOk->setGeometry(400,0,168,70);
    ui->buttonCancel->setGeometry(600,0,168,70);

    ui->framePageBtnWIFI->setGeometry(920,990,1000,70);
    ui->buttonPgUpWIFI->setGeometry(0,0,168,70);
    ui->buttonPgDnWIFI->setGeometry(200,0,168,70);
    ui->buttonSetAutoIP->setGeometry(400,0,168,70);
    ui->buttonSetStaticIP->setGeometry(600,0,168,70);
    ui->buttonCancelWIFI->setGeometry(800,0,168,70);
}

void SystemManageDialog::initResolution1006()
{
    m_itemPerPage = m_itemPerPage - 4;
    this->resize(1024,600);
    ui->frameBack->setGeometry(0,0,1024,600);

    ui->buttonTypeLogo->setGeometry(25,30,60,60);
    ui->labelMainTitle->setGeometry(100,30,200,24);
    ui->labelSubTitle->setGeometry(130,64,240,21);

    ui->frameRightUp->setGeometry(800,40,800,61);
    ui->buttonDelete->setGeometry(150,0,50,50);
    ui->buttonSelectAll->setGeometry(150,0,50,50);
    ui->buttonExport->setGeometry(90,0,50,50);

    ui->frameRightUpWIFI->setGeometry(600,40,400,61);
    ui->buttonRefresh->setGeometry(300,0,50,50);
    ui->labelCurIP->setGeometry(0,0,300,50);

    ui->buttonChangeLog->setGeometry(20,0,50,50);

    for(int i = 0; i < m_itemPerPage; i++)
    {
        m_itemBtnList[i]->setGeometry(153,96 + i * 53,718,53);
    }

    ui->framePageBtn->setGeometry(595,545,600,45);
    ui->labelPage->setGeometry(20,550,102,45);
    ui->labelExplain->setGeometry(130,538,350,50);
    ui->buttonPgUp->setGeometry(0,0,96,40);
    ui->buttonPgDn->setGeometry(106,0,96,40);
    ui->buttonOk->setGeometry(212,0,96,40);
    ui->buttonCancel->setGeometry(318,0,96,40);

    ui->framePageBtnWIFI->setGeometry(489,545,600,45);
    ui->buttonPgUpWIFI->setGeometry(0,0,96,40);
    ui->buttonPgDnWIFI->setGeometry(106,0,96,40);
    ui->buttonSetAutoIP->setGeometry(212,0,96,40);
    ui->buttonSetStaticIP->setGeometry(318,0,96,40);
    ui->buttonCancelWIFI->setGeometry(424,0,96,40);
}

//初始化窗体控件样式
void SystemManageDialog::initControlStyle()
{
    SetControlStyle setControlStyle;
    setControlStyle.setUiName(this->objectName());

    //背景图
    QString frameBackImgPath = setControlStyle.getSharedStyleSheet();
    ui->frameBack->setStyleSheet(frameBackImgPath);
    ui->labelMainTitle->setFont(fontBold_1);
    ui->labelMainTitle->setStyleSheet(LABELWHITESTYLE);
    ui->labelSubTitle->setFont(fontNormal_1);
    ui->labelSubTitle->setStyleSheet(LABELWHITESTYLE);
    ui->labelPage->setFont(fontNormal_1);
    ui->labelPage->setStyleSheet(LABELWHITESTYLE);
    ui->labelExplain->setFont(fontNormal_1);
    ui->labelExplain->setStyleSheet(LABELWHITESTYLE);

    //右上方
    ui->frameRightUp->setStyleSheet(TRANSPARENTSTYLE);
    ui->buttonDelete->setGreenGradientBottomStyle(BORDER_RADIUS1);
    ui->buttonDelete->setTopImage(setControlStyle.getTopStyleSheet(ui->buttonDelete->objectName()));
    ui->buttonSelectAll->setGreenGradientBottomStyle(BORDER_RADIUS1);
    ui->buttonSelectAll->setTopImage(setControlStyle.getTopStyleSheet(ui->buttonSelectAll->objectName()));
    ui->buttonExport->setGreenGradientBottomStyle(BORDER_RADIUS1);
    ui->buttonExport->setTopImage(setControlStyle.getTopStyleSheet(ui->buttonExport->objectName()));
    ui->buttonChangeLog->setGreenGradientBottomStyle(BORDER_RADIUS1);
    ui->buttonChangeLog->setTopImage(setControlStyle.getTopStyleSheet(ui->buttonChangeLog->objectName()));

    //右上方
    ui->frameRightUpWIFI->setStyleSheet(TRANSPARENTSTYLE);
    ui->buttonRefresh->setGreenGradientBottomStyle(BORDER_RADIUS1);
    ui->buttonRefresh->setTopImage(setControlStyle.getTopStyleSheet(ui->buttonChangeLog->objectName()));
    ui->labelCurIP->setFont(fontNormal_1);
    ui->labelCurIP->setStyleSheet(LABELWHITESTYLE);

    QString style = "QPushButton{border:0px;text-align:left;border-radius:7px;background-color:rgba(255, 255, 255, 0);color: rgb(255, 255, 255);}";
    style += "QPushButton:checked{background-color: rgba(255, 255, 255, 50);}";

    for(int i = 0; i < m_itemBtnList.size(); i++)
    {
        m_itemBtnList[i]->setStyleSheet(style);//文本左对齐
        m_itemBtnList[i]->setFont(fontNormal_1);
    }

    //四个按钮样式表一样
    ui->buttonPgUp->setOrangeGradientBottomStyle(BORDER_RADIUS2);
    ui->buttonPgUp->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonPgUp->objectName()),12);

    ui->buttonPgDn->setOrangeGradientBottomStyle(BORDER_RADIUS2);
    ui->buttonPgDn->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonPgDn->objectName()),12);

    ui->buttonOk->setOrangeGradientBottomStyle(BORDER_RADIUS2);
    ui->buttonOk->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonOk->objectName()),12);

    ui->buttonCancel->setOrangeGradientBottomStyle(BORDER_RADIUS2);
    ui->buttonCancel->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonCancel->objectName()),12);

    //WIFI
    ui->framePageBtnWIFI->setStyleSheet(TRANSPARENTSTYLE);
    ui->buttonPgUpWIFI->setOrangeGradientBottomStyle(BORDER_RADIUS2);
    ui->buttonPgUpWIFI->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonPgUp->objectName()),12);

    ui->buttonPgDnWIFI->setOrangeGradientBottomStyle(BORDER_RADIUS2);
    ui->buttonPgDnWIFI->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonPgDn->objectName()),12);

    ui->buttonSetAutoIP->setOrangeGradientBottomStyle(BORDER_RADIUS2);
    ui->buttonSetAutoIP->setFont(fontNormal_6);

    ui->buttonSetStaticIP->setOrangeGradientBottomStyle(BORDER_RADIUS2);
    ui->buttonSetStaticIP->setFont(fontNormal_6);

    ui->buttonCancelWIFI->setOrangeGradientBottomStyle(BORDER_RADIUS2);
    ui->buttonCancelWIFI->setTopImage(setControlStyle.getSharedTopStyleSheet(ui->buttonCancel->objectName()),12);
}

void SystemManageDialog::initArabControlPos()
{
    int language = g_pSettings->readFromInHMIiFile("HMI/language").toInt();
    if(language != arabic)
    {
        return;
    }

    ui->labelMainTitle->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    ui->labelSubTitle->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    ui->labelCurIP->setAlignment(Qt::AlignRight | Qt::AlignVCenter);

    QString style = "QPushButton{border:0px;text-align:right;border-radius:7px;background-color:rgba(255, 255, 255, 0);color: rgb(255, 255, 255);}";
    style += "QPushButton:checked{background-color: rgba(255, 255, 255, 50);}";

    for(int i = 0; i < m_itemBtnList.size(); i++)
    {
        m_itemBtnList[i]->setStyleSheet(style);//文本右对齐
    }

    ui->labelPage->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    ui->labelExplain->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
}

void SystemManageDialog::refreshUi()
{
    int itemNum;
    if (m_itemList.size() <= 0)
    {
        itemNum = 0;

        for (int i = 0; i < m_itemPerPage; i++)
        {
            m_itemBtnList.at(i)->hide();
        }
        ui->labelPage->setText(tr("pageNum: 0/0"));//页数: 0/0
        ui->buttonPgUp->setEnabled(false);
        ui->buttonPgDn->setEnabled(false);
        ui->buttonOk->setEnabled(false);

        return;
    }
    else
    {
        itemNum = m_itemList.size();
    }

    m_pageNums = (itemNum + m_itemPerPage - 1)/m_itemPerPage;// 计算页数
    if (m_curPages > m_pageNums)// 当前页
    {
        m_curPages = m_pageNums;
    }
    if (m_curPages <= 1 && itemNum != 0)
    {
        m_curPages = 1;
    }

    int itemidx = (m_curPages - 1) * m_itemPerPage;

    for (int i = 0; i < m_itemPerPage; i++)
    {
        if (itemidx < itemNum)
        {
            //设置图标和文件夹名称
            m_itemBtnList[i]->setText(m_itemList.at(itemidx));
            m_itemBtnList.at(i)->show();

            itemidx++;
        }
        else
        {
            m_itemBtnList.at(i)->hide();
        }
    }

    // 翻页按钮
    if (m_curPages <= 1)
    {
        ui->buttonPgUp->setEnabled(false);
    }
    else
    {
        ui->buttonPgUp->setEnabled(true);
    }
    if (m_curPages >= m_pageNums)
    {
        ui->buttonPgDn->setEnabled(false);
    }
    else
    {
        ui->buttonPgDn->setEnabled(true);
    }

    // 页信息
    if(m_pageNums == 0)
    {
        m_curPages = 0;
    }

    QString str = tr("pageNum: ") + QString("%1/%2").arg(m_curPages).arg(m_pageNums);//页数:
    ui->labelPage->setText(str);

    refreshCheckedPage();
}

void SystemManageDialog::refreshCheckedPage()
{
    if(m_selectedIdx == SELECT_NONE)
    {
        ui->buttonOk->setEnabled(false);
    }
    else
    {
        ui->buttonOk->setEnabled(true);
    }

    if(m_selectedIdx == SELECT_ALL)
    {
        // 刷新页面中被选择的条目
        for(int var = 0; var < m_itemPerPage; var++)
        {
            // 条目被选中
            m_itemBtnList.at(var)->setCheckable(true);
            m_itemBtnList.at(var)->setChecked(true);
        }
        return;
    }

    // 刷新页面中被选择的条目
    for(int var = 0; var < m_itemPerPage; var++)
    {
        int idx = (m_curPages - 1) * m_itemPerPage + var;
        if(m_selectedIdx == idx)
        {
            // 条目被选中
            m_itemBtnList.at(var)->setCheckable(true);
            m_itemBtnList.at(var)->setChecked(true);
        }
        else
        {
            // 不被选中
            m_itemBtnList.at(var)->setChecked(false);
            m_itemBtnList.at(var)->setCheckable(false);
        }
    }
}

void SystemManageDialog::clickItem(int idx)
{
    m_selectedIdx = (m_curPages - 1) * m_itemPerPage + idx - 1;
    refreshCheckedPage();
    QString wifiName = m_itemList[m_selectedIdx];
    if(m_curConnectWifi != wifiName)
    {
        ui->buttonSetAutoIP->setEnabled(true);
        ui->buttonSetStaticIP->setEnabled(false);
    }
    else
    {
        ui->buttonSetAutoIP->setEnabled(false);
        ui->buttonSetStaticIP->setEnabled(true);
    }
}

void SystemManageDialog::initDialog(s16 type)
{
    m_setType = type;
    m_curPages = 1;//当前页数
    m_pageNums = 1;//总页数
    m_selectedIdx = SELECT_NONE;//被选中的条目
    m_itemList.clear();

    if(type != 0)
    {
        ui->frameRightUpWIFI->show();
        ui->framePageBtnWIFI->show();
        ui->frameRightUp->hide();
        ui->framePageBtn->hide();
        ui->labelExplain->show();
    }
    else
    {
        ui->frameRightUpWIFI->hide();
        ui->framePageBtnWIFI->hide();
        ui->frameRightUp->show();
        ui->framePageBtn->show();
        ui->labelExplain->hide();
    }
}

//设置类型图标
void SystemManageDialog::setTypeLogo(QString tStyle)
{
    ui->buttonTypeLogo->setUnPreBtnLogo(tStyle);
}

//设置主title
void SystemManageDialog::setMainTitle(QString str)
{
    ui->labelMainTitle->setText(str);
}

//设置副title
void SystemManageDialog::setSubTitle(QString str)
{
    ui->labelSubTitle->setText(str);
}

void SystemManageDialog::addItem(QString str)
{
    m_itemList.append(str);
}

void SystemManageDialog::addListError()
{
    m_itemList = g_pSettings->readToCsv(TYPE_ERROR);//读取   QStringList
}
void SystemManageDialog::addListBreakage()
{
    m_itemList = g_pSettings->readToCsv(TYPE_BREAK);//读取   QStringList
}
void SystemManageDialog::addListDebug()
{
    m_itemList = g_pSettings->readToCsv(TYPE_DEBUGINFO);//读取   QStringList
}

int SystemManageDialog::exec(int type)//升级类型
{
    ui->buttonDelete->setVisible(false);
    ui->buttonSelectAll->setVisible(false);
    ui->buttonExport->setVisible(false);

    ui->buttonChangeLog->setVisible(false);

    m_updateType = type;

    //当为外围板版本查询时，列表按钮和确定按钮不可按
    if(m_updateType < 0)
    {
        ui->buttonOk->setEnabled(false);

        for(int i = 0; i < m_itemBtnList.size(); i++)
        {
            m_itemBtnList[i]->setEnabled(false);
        }
    }
    else
    {
        //板卡列表显示(连接多块主板时)
        if(m_updateType == BOARD_LIST)
        {
            ui->buttonSelectAll->setVisible(true);
        }

        if(m_updateType == PRODUCTSTATIS)
        {
            ui->buttonDelete->setVisible(true);
            ui->buttonOk->setEnabled(false);

            for(int i = 0; i < m_itemBtnList.size(); i++)
            {
                m_itemBtnList[i]->setEnabled(false);
            }
        }
        else if(m_updateType == JOURNAL)
        {
            ui->buttonDelete->setVisible(false);//不可见
            ui->buttonOk->setEnabled(false);
            ui->buttonExport->setVisible(true);

            ui->buttonChangeLog->setVisible(true);

            for(int i = 0; i < m_itemBtnList.size(); i++)
            {
                m_itemBtnList[i]->setEnabled(false);
            }
        }
        else
        {
            ui->buttonOk->setEnabled(true);

            for(int i = 0; i < m_itemBtnList.size(); i++)
            {
                m_itemBtnList[i]->setEnabled(true);
            }
        }
    }

    refreshUi();
    return QDialog::exec();
}

QString SystemManageDialog::getCurFile()
{
    QString fileName = m_itemList.at(m_selectedIdx);
    return fileName;
}

void SystemManageDialog::setWifiInfo(QString ip,QString ssid,QString psd,bool mode)
{
    ui->labelCurIP->setText(ip);
    m_curConnectWifi = ssid;
    m_curConnectWifiPass = psd;
    m_curConnectMode = mode;
}

void SystemManageDialog::setItemList(QStringList list)
{
    m_itemList.clear();
    m_itemList = list;
}

//外围板版本信息改变
void SystemManageDialog::slotEXBInfoChange()
{
    m_itemList.clear();
    ExBoardInfo exboardInfo;
    memset(&exboardInfo,0,sizeof(ExBoardInfo));        // 外围板信息

    //外围板用g_pMachine
    exboardInfo = g_pMachine->getEXBInfo();
    for(u16 i = 0; i < MAX_SUPPORT_N5; i++)
    {
        char verStr[BOARD_VER_LEN];
        memset(verStr,0,sizeof(verStr));        // 外围板信息
        memcpy(verStr,exboardInfo.headInfo[i].softwareVerStr,sizeof(verStr));

        QString info = QString::fromLocal8Bit(verStr,sizeof(verStr));

        char clearStr[BOARD_VER_LEN];
        memset(clearStr,0,sizeof(clearStr));        // 外围板信息
        int ret = memcmp(verStr, clearStr, sizeof(verStr)); // 比较两个缓存区内容是否相同(等于0相等)

        if(info.length() > 0 && ret != 0)
        {
            //过滤掉字符为0的字符，因为linux下会显示为x
            for(int j = 0; j < info.length(); j++)
            {
                if (info.at(j) == 0)
                {
                    info[j] = ' ';
                }
            }

            u8 nType;
            QString boardStr;
            memcpy(&nType, &exboardInfo.headInfo[i].nodeType,sizeof(nType));
            if(nType == FLATEMB)
            {
                boardStr = tr("FLATEMB");//平绣机头板
            }
            else if(nType == TOWEL)
            {
                boardStr = tr("CHENILLE");//毛巾机头板
            }
            else if(nType == TOWEL_DOWN_HEAD)
            {
                boardStr = tr("CHENILLE DOWN");//毛巾下机头板
            }
            else if(nType == COIL)
            {
                boardStr = tr("COIL");//缠绕机头板
            }
            QString str = QString::number(i + 1) + " " +boardStr + tr("Head board") + " " + info;
            m_itemList.append(str);//机头板
        }
    }

    if (g_emMacType == MACHINE_EMB )
    {
        // 读取D86程序版本    -rq
        for(u16 i = 0; i < MAX_SUPPORT_D86; i++)
        {
            char verStr[BOARD_VER_LEN];
            memset(verStr,0,sizeof(verStr));        // D86板信息
            memcpy(verStr,exboardInfo.d86Info[i].softwareVerStr,sizeof(verStr));

            QString info = QString::fromLocal8Bit(verStr,sizeof(verStr));

            char clearStr[BOARD_VER_LEN];
            memset(clearStr,0,sizeof(clearStr));        // D86板信息
            int ret = memcmp(verStr, clearStr, sizeof(verStr)); // 比较两个缓存区内容是否相同(等于0相等)

            if(info.length() > 0 && ret != 0)
            {
                //过滤掉字符为0的字符，因为linux下会显示为x
                for(int j = 0; j < info.length(); j++)
                {
                    if (info.at(j) == 0)
                    {
                        info[j] = ' ';
                    }
                }
                QString str = QString::number(i + 1) + " " + tr("D86 board") + " " + info;
                m_itemList.append(str);//D86板
            }
        }

        for(u16 i = 0; i < MAX_SUPPORT_N6; i++)
        {
            char verStr[BOARD_VER_LEN];
            memset(verStr,0,sizeof(verStr));        // 外围板信息
            memcpy(verStr,exboardInfo.hcpsInfo[i].softwareVerStr,sizeof(verStr));

            QString info = QString::fromLocal8Bit(verStr,sizeof(verStr));

            char clearStr[BOARD_VER_LEN];
            memset(clearStr,0,sizeof(clearStr));        // 外围板信息
            int ret = memcmp(verStr, clearStr, sizeof(verStr)); // 比较两个缓存区内容是否相同(等于0相等)

            if(info.length() > 0 && ret != 0)
            {
                //过滤掉字符为0的字符，因为linux下会显示为x
                for(int j = 0; j < info.length(); j++)
                {
                    if (info.at(j) == 0)
                    {
                        info[j] = ' ';
                    }
                }
                m_itemList.append(QString::number(i + 1) + " " + tr("N6 board") + " " + info);//N6板   -rq
            }
        }

    }
    refreshUi();
}

void SystemManageDialog::on_buttonCancel_clicked()
{
    //超级用户密码权限,单次有效
    g_emUser = operate;
    done(0);
}

void SystemManageDialog::on_buttonOk_clicked()
{
    if(m_updateType == HMI_UPDATA)//界面升级
    {
        //升级需要重新启动程序，是否重启进行升级？
        qDebug()<<"HMI_UPDATA";

        PromptDialog promptDlg(this);
        promptDlg.initDialog(PromptDialog::BTN_OK_CANCEL);
        promptDlg.setTitleStr(tr("Prompt"));

        QString str;
        str = tr("The upgrade needs to restart the program. Do you need to restart to upgrade?");//升级需要重新启动程序，是否重启进行升级？
        promptDlg.setContentStr(str);
        if(promptDlg.exec() != 1)
        {
           //done(0);
           return;
        }
    }
    done(1);
}

void SystemManageDialog::on_buttonPgUp_clicked()
{
    m_curPages--;
    refreshUi();
}

void SystemManageDialog::on_buttonPgDn_clicked()
{
    m_curPages++;
    refreshUi();
}

void SystemManageDialog::on_button1_clicked()
{
    clickItem(1);
}

void SystemManageDialog::on_button2_clicked()
{
    clickItem(2);
}

void SystemManageDialog::on_button3_clicked()
{
    clickItem(3);
}

void SystemManageDialog::on_button4_clicked()
{
    clickItem(4);
}

void SystemManageDialog::on_button5_clicked()
{
    clickItem(5);
}

void SystemManageDialog::on_button6_clicked()
{
    clickItem(6);
}

void SystemManageDialog::on_button7_clicked()
{
    clickItem(7);
}

void SystemManageDialog::on_button8_clicked()
{
    clickItem(8);
}

void SystemManageDialog::on_button9_clicked()
{
    clickItem(9);
}

void SystemManageDialog::on_button10_clicked()
{
    clickItem(10);
}

void SystemManageDialog::on_button11_clicked()
{
    clickItem(11);
}

void SystemManageDialog::on_button12_clicked()
{
    clickItem(12);
}

void SystemManageDialog::on_buttonDelete_clicked()
{
    if(m_updateType == PRODUCTSTATIS)//等于生产统计
    {
        PromptDialog promptDlg(this);
        promptDlg.initDialog(PromptDialog::BTN_OK_CANCEL);
        promptDlg.setTitleStr(tr("Prompt"));

        QString str;
        str = tr("Do you want to clear the production statistics?");//是否清空生产统计？
        promptDlg.setContentStr(str);
        if(promptDlg.exec() == 1)
        {
            emit siClearProductStatis();
        }
    }
    else if(m_updateType == JOURNAL)
    {
        PromptDialog promptDlg(this);
        promptDlg.initDialog(PromptDialog::BTN_OK_CANCEL);
        promptDlg.setTitleStr(tr("Prompt"));

        QString str;
        str = tr("Do you want to clear the journal?");//是否清空日志文件？
        promptDlg.setContentStr(str);
        if(promptDlg.exec() == 1)
        {
            emit siClearJournal();
        }
    }
}

void SystemManageDialog::on_buttonSelectAll_clicked()
{
    if(m_selectedIdx == SELECT_ALL)
    {
        m_selectedIdx = SELECT_NONE;
    }
    else
    {
        m_selectedIdx = SELECT_ALL;
    }
    refreshCheckedPage();
}

//导出csv文件
void SystemManageDialog::on_buttonExport_clicked()
{
    if(m_updateType == JOURNAL)//等于日志文件
    {
        PromptDialog promptDlg(this);
        promptDlg.initDialog(PromptDialog::BTN_OK_CANCEL);
        promptDlg.setTitleStr(tr("Prompt"));

        QString str;
        str = tr("Do you want to export journal?");//是否导出日志文件？
        promptDlg.setContentStr(str);
        if(promptDlg.exec() == 1)
        {
            emit siCsvExport(m_logType);
        }
    }
}

void SystemManageDialog::on_buttonChangeLog_clicked()
{
    //done(0);
    //qDebug()<<"buttonChange_clicked" <<endl;
    m_logType++;
    if(m_logType > TYPE_DEBUGINFO)
    {
        m_logType = 0;
    }

     if(m_logType == TYPE_ERROR)
    {
         emit siCsvChangeErro();
    }
    else if(m_logType == TYPE_BREAK)
    {
         emit  siCsvChangeBrea();
    }
     else if(m_logType == TYPE_DEBUGINFO)
     {
          emit  siCsvChangeDebug();
     }

    refreshUi();
}

//刷新wifi
void SystemManageDialog::on_buttonRefresh_clicked()
{
    m_curPages = 1;//当前页数
    m_pageNums = 1;//总页数
    m_selectedIdx = SELECT_NONE;//被选中的条目
    emit siRefreshWifiList();
    refreshUi();
}

void SystemManageDialog::on_buttonPgUpWIFI_clicked()
{
    m_curPages--;
    refreshUi();
}

void SystemManageDialog::on_buttonPgDnWIFI_clicked()
{
    m_curPages++;
    refreshUi();
}

void SystemManageDialog::on_buttonSetAutoIP_clicked()
{
    if(m_selectedIdx < m_itemList.size() && m_selectedIdx >= 0)
    {
        QString ssid = m_itemList.at(m_selectedIdx);
        emit siSetDynamicIP(ssid);
    }
}

void SystemManageDialog::on_buttonSetStaticIP_clicked()
{
    QString ssid = m_curConnectWifi;
    QString psd = m_curConnectWifiPass;
    QStringList ipList = ui->labelCurIP->text().split(".", QString::SkipEmptyParts);
    QString ip;
    ip.clear();
    if(ipList.size() >= 3)
    {
        ip = ipList[0]+"."+ipList[1]+"."+ipList[2]+".";
    }

    emit siSetStaticIP(ssid,psd,ip);
}

void SystemManageDialog::on_buttonCancelWIFI_clicked()
{
    done(0);
}
