#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QLabel>
#include <QSizeGrip>
#include <QProcess>
#include <tipdialog.h>
#include <LoUIClass/x_uimsgboxok.h>
#include "LoUIClass/x_uimsgboxokcancel.h"
#include <wDevicesManager/inputpassworddialog.h>
#include <QDesktopWidget>
#include "QTextCodec"
//主窗口
NetComm *p_globaNetComm=nullptr;
static const QString FILE_NAME_TRANSLATOR{ "\\qt_zh_CN.qm" };


MainWindow::MainWindow(QWidget *parent) :
    LoQMainWindow(parent),
    ui(new Ui::MainWindow),
    m_Translator(nullptr)
{
    LoAppConfig *cfg = LoAppConfig::getInstance();
    QCoreApplication::setOrganizationName(cfg->OrganizationName());
    QCoreApplication::setOrganizationDomain(cfg->OrganizationDomain());
    QCoreApplication::setApplicationName(cfg->ApplicationName());
    setStyleSheet(cfg->styleSheet());
    //窗口UI
    ui->setupUi(this);
    ui->wMainWnd->setProperty("ssBackground", "dark");
    ui->wStatus ->setProperty("ssBackground", "dark");
    ui->wMainWnd->setProperty("ssPrettify",   "fillet");
    ui->wStatus ->setProperty("ssPrettify",   "fillet");
    //为状态栏添加DHCP开关按钮
   // QHBoxLayout *pStatusHLayout = new QHBoxLayout();
    //m_LableDhcp = new QLabel(tr("DHCP Service"));
    m_LableDhcp = new QLabel(tr("RJ45 Cable directly connected"));

 //   QLabel *LableDhcp1 = new QLabel("  3223");
    m_LableDhcp->setStyleSheet("padding-left:5px");
    //pStatusHLayout->addWidget(LableDhcp);
    m_pSwitchDhcpControl = new SwitchControl();
    /*
    m_pSwitchDhcpControl->setSliderColor(QColor(145, 145, 145),QColor(0, 160, 230));
    m_pSwitchDhcpControl->setTextColor(QColor(145, 145, 145),QColor(0, 160, 230));
    m_pSwitchDhcpControl->setStyleSheet("margin-right:35px");
    m_pSwitchDhcpControl->setFixedSize(66,30);
    m_pSwitchDhcpControl->setText(tr("OFF"),tr("ON"));
    connect(m_pSwitchDhcpControl, SIGNAL(checkedChanged(bool)), this, SLOT(onDhcpSwitcherToggled(bool)));
    m_pSwitchDhcpControl->setButtonStyle(SwitchControl::ButtonStyle_CircleIn);
     //ui->wStatus->setLayout()
    ui->wStatus->addWidget(m_LableDhcp);
    ui->wStatus->addWidget(m_pSwitchDhcpControl);
    */
    m_pOneKeyCheckCard = new QPushButton(tr("Check card"));
    m_pOneKeyCheckCard->setCursor(Qt::PointingHandCursor);
    m_pOneKeyCheckCard->setProperty("ssType", "progManageTool");
    m_pOneKeyCheckCard->setStyleSheet("margin-left:5px");
    //m_pOneKeyCheckCard->setStyleSheet("bord-color:#008d8d ; bord-size:2px");
    ui->wStatus->addWidget(m_pOneKeyCheckCard);
    //ui->wStatus->setSizeGripEnabled(true);
    //QSizeGrip *grip =new QSizeGrip(ui->wStatus);
   // grip->setVisible(true);
  //  ui->wStatus->addWidget(LableDhcp1);

    //ui->wStatus->adjustSize();
//    ui->wStatus->addWidget(LableDhcp,2);
   // ui->wStatus->setLayout(pStatusHLayout);
 //   ui->wStatus->setSizeGripEnabled(true);
    //pSwitchDhcpControl->setToolTip(tr("1.This function is only used to connect to the termianl via Ethernet cable and the terminal is assignned with a dynamic IP address.\r\n2.Please turn off the firewall or turn on ICMP echo before you turn on DHCP.\r\n3.If the connection is unstable,set a static IP address for your PC."));
    //ui->wStatus->setToolTip(tr("DhcpTip"));
 //   ui->wStatus->setToolTip(tr("DhcpTip4")+".\r\n"+tr("DhcpTip5")+".\r\n"+tr("DhcpTip6")+".");


    //项目保存的文档路径
    QString doc_path = cfg->DocumentsLocation();
    if(!doc_path.isEmpty()) {
        QDir app_dir = QDir(doc_path + MACRO_FENGEFU + cfg->ApplicationName());
        if(!app_dir.exists()) {
            QDir doc_dir(doc_path);
            doc_dir.mkdir(cfg->ApplicationName());
        }
    }
    //创建软件logo图标
    QRect rect;
    QLabel *pIcon = new QLabel(this);
    pIcon->setObjectName(tr("MainWndIcon"));
    pIcon->setPixmap(QPixmap(":/res/Logo.png"));
    pIcon->adjustSize();
    rect = pIcon->geometry();
    rect.setX(50);
    rect.setY(30);
    rect.setWidth(pIcon->width());
    rect.setHeight(pIcon->height());
    pIcon->setGeometry(rect);


    //创建软件的标题
  // masked by alahover 20200203
    QLabel *pTitle = new QLabel(this);
//    QFont font;
//    font.setFamily("宋体");
//   // font.setBold(false);
//    font.setWeight(1);
//    //font.setItalic(true);
//    font.setPixelSize(18);
//    pTitle->setFont(font);


    //pTitle->setText("V1.0.0.1");
    pTitle->setStyleSheet("font-size:12px;font-weight:100;");
    pTitle->setText("LedOK Express");
    pTitle->setObjectName("MainWndTitle");
    pTitle->adjustSize();

    rect.setX(50);
    rect.setY(72);
    rect.setWidth(pTitle->width());
    rect.setHeight(pTitle->height());
    pTitle->setGeometry(rect);
    //自定义的标题上的工具栏创建（语言和设置选项）
    m_wTitle = new mTitleBar(ui->wMainWnd);
    installEventFilter(m_wTitle);
    connect(m_wTitle, SIGNAL(sigLanguageChanged(const QString&)), this, SLOT(onLanguageChanged(const QString&)));
    connect(m_wTitle, SIGNAL(sigGuangYingPinChanged()), this, SLOT(onGuangYingPinChanged()));

    //设备管理，节目管理，高级节目管理页创建
    m_wDeviceManager   = new mDeviceManager();
    m_wProgramManager  = new mProgramManager();
//    m_wProgramManagerA = new mProgramManagerA();
    m_wGuangYingPinWidget = new mGuangYingPinWidget();
    //m_wDeviceSetting = new mDeviceSetting();
    //QWidget *wWidget3  = new QWidget();
    //m_wTab = new mTabWidget(m_wDeviceManager, m_wProgramManager, m_wProgramManagerA,  this);
    //m_wTab = new mTabWidget(m_wDeviceManager, m_wProgramManager, m_wProgramManagerA, m_wDeviceSetting, this);
    m_wTab = new mTabWidget(m_wDeviceManager, m_wProgramManager, nullptr, m_wDeviceManager,m_wGuangYingPinWidget, this);
    connect(m_wTab,SIGNAL(sigOpenDeviceUdpTimer(bool)),m_wDeviceManager->pNetComm,SLOT(OnStartUdpTimer(bool)));
    connect(m_wTab,SIGNAL(sigOpenDeviceUdpTimer(bool)),m_wDeviceManager,SLOT(OnStopAllItemPostHeartBeat(bool)));
    //创建一个水平布局，水平布局里左右留12个0空格，中间放入页部件
    QHBoxLayout *pTabLayout = new QHBoxLayout();
    //pTabLayout->setSpacing(20);//MainWindow父类为QMainWindow，在QMainWindow及其子类中使用layout不起作用。
    pTabLayout->addSpacing(6);
    pTabLayout->addWidget(m_wTab);
    pTabLayout->addSpacing(6);
    pTabLayout->setContentsMargins(0, 0, 0, 0);
    //创建一个垂直布局
    QVBoxLayout *pLayout = new QVBoxLayout();
    pLayout->addWidget(m_wTitle, 0);
    pLayout->addLayout(pTabLayout, 1);
    pLayout->setSpacing(0);
    pLayout->setContentsMargins(0, 0, 0, 0);
    ui->wMainWnd->setLayout(pLayout);

    m_wTitle->setupLang();
    readSettings();
    connect(m_pOneKeyCheckCard, SIGNAL(clicked()), this, SLOT(RestoreLedCardIpByUdpCmd()));
    connect(this, SIGNAL(sigRestorLedCardIpByUdpCmd()), m_wDeviceManager->pNetComm, SLOT(RestoreLedCardIpByUdpCmd()));


    QSettings *settings = new QSettings(cfg->OrganizationName(), cfg->ApplicationName());
    if(settings->value("TextAntialiasing").isValid())
    {
        if(settings->value("TextAntialiasing").toBool())
        {
            m_globBoolFontantialiasing=true;
        }
        else {
            m_globBoolFontantialiasing=false;

        }
    }
    else {
        m_globBoolFontantialiasing=false;

    }

#ifdef MACRO_YUANHENG_VERSION
    timer = new QTimer(this);
    timer->setInterval(5);
    connect(timer, SIGNAL(timeout()), this, SLOT(InputPasswordDlg()));
    timer->start();


#endif

}
void MainWindow::RestoreLedCardIpByUdpCmd()
{
    X_UIMsgBoxOkCancel *dlg = new X_UIMsgBoxOkCancel(tr("Tip Info"),tr("RestoreLedCardIpByUdpTip"), this);
    if(dlg->exec() == QDialog::Accepted)
    {
        qDebug()<<"sigRestorLedCardIpByUdpCmd";
        emit sigRestorLedCardIpByUdpCmd();
    }
    else {
    }


}
MainWindow::~MainWindow()
{
    writeSettings();
    if(m_Translator!=nullptr)
        delete m_Translator;
    if(m_wTitle!=nullptr)
        delete m_wTitle;
    if(m_wTab!=nullptr)
        delete m_wTab;
    if(m_pSwitchDhcpControl!=nullptr)
        delete m_pSwitchDhcpControl;
    if(m_LableDhcp!=nullptr)
        delete m_LableDhcp;
    if(m_pOneKeyCheckCard!=nullptr)
        delete m_pOneKeyCheckCard;
    if(m_wStatus!=nullptr)
        delete m_wStatus;
    if(m_pTimerSendResoreIpOneKey!=nullptr)
    {
        if(m_pTimerSendResoreIpOneKey->isActive())
            m_pTimerSendResoreIpOneKey->stop();
        delete m_pTimerSendResoreIpOneKey;
    }

    delete ui;
}
void MainWindow::AddAppToFirewall()
{
    //添加exe到win防火墙例外
    QString strAppFilePathName=QCoreApplication::applicationFilePath();
    QString command = "netsh advfirewall firewall add rule name = \"allow LedOK\" dir=in program=";
    command = command   + "\"" + strAppFilePathName + "\"" + " security=authnoencap action=allow";
    command.replace('/','\\');
    //    qDebug() <<strAppFilePathName;
    //    qDebug() <<command;
    QProcess cmd(nullptr);
    cmd.start(command);
    cmd.waitForFinished();
    qDebug() <<"Set firewall finished";

    QString strAppPath=QApplication::applicationDirPath();
    QString strLedSetFile=strAppPath+"\\LedSet\\LedSet3.0.exe";
    QString command1 = "netsh advfirewall firewall add rule name = \"allow LedOK\" dir=in program=";
    command1 = command1   + "\"" + strLedSetFile + "\"" + " security=authnoencap action=allow";
    command1.replace('/','\\');
    QProcess cmd1(nullptr);
    cmd1.start(command1);
    cmd1.waitForFinished();
}
void MainWindow::refreshLable()
{

    if(m_wTab!=nullptr)
    {
       m_wTab->refreshLable();
    }
    if(m_wDeviceManager!=nullptr)
    {
       m_wDeviceManager->refreshLable();
    }
    if(m_wProgramManager!=nullptr)
    {
       m_wProgramManager->refreshLable();
    }
    if(m_wGuangYingPinWidget!=nullptr)
    {
       m_wGuangYingPinWidget->refreshLable();
    }

    if(m_wTitle!=nullptr)
    {
       m_wTitle->refreshLable();
    }
//    ui->wStatus->setToolTip(tr("DhcpTip4")+".\r\n"+tr("DhcpTip5")+".\r\n"+tr("DhcpTip6")+".");
//    m_LableDhcp->setText(tr("DHCP Service"));
    m_LableDhcp->setText(tr("RJ45 Cable directly connected"));
    m_pOneKeyCheckCard->setText(tr("Check card"));


}
/*
 语言切换响应函数
 */
void MainWindow::onLanguageChanged(const QString &lan)
{
    qDebug() << "MainWindow::onLanguageChanged:" << lan;
    if(m_Translator!= nullptr)
    {
         qApp->removeTranslator(m_Translator);
         delete m_Translator;
         m_Translator = nullptr;

    }
     m_Translator = new QTranslator(this);
     if(m_Translator->load(":/" + lan)) {
         qApp->installTranslator(m_Translator);
     }
     if(m_TranslatorCustom!= nullptr)
     {
          qApp->removeTranslator(m_TranslatorCustom);
          delete m_TranslatorCustom;
          m_TranslatorCustom = nullptr;

     }
     if(m_TranslatorQtSys!= nullptr)
     {
          qApp->removeTranslator(m_TranslatorQtSys);
          delete m_TranslatorQtSys;
          m_TranslatorQtSys = nullptr;

     }
     if(lan=="zhCN")
     {
         m_TranslatorCustom =  new QTranslator(this);
         if(m_TranslatorCustom->load(":/widgets_cn"))
             qApp->installTranslator(m_TranslatorCustom);


             m_TranslatorQtSys = new QTranslator(this);
             if (m_TranslatorQtSys->load(QApplication::applicationDirPath()+ FILE_NAME_TRANSLATOR))
             {
                 qApp->installTranslator(m_TranslatorQtSys);
             }
     }
     else if(lan=="zhTH")
     {
         m_TranslatorCustom =  new QTranslator(this);
         if(m_TranslatorCustom->load(":/widgets_th"))
             qApp->installTranslator(m_TranslatorCustom);


             m_TranslatorQtSys = new QTranslator(this);
             if (m_TranslatorQtSys->load(QApplication::applicationDirPath()+ FILE_NAME_TRANSLATOR))
             {
                 qApp->installTranslator(m_TranslatorQtSys);
             }
     }
     refreshLable();
/*#if 1
    if(m_Translator == nullptr) {
        m_Translator = new QTranslator(this);
    }
    qApp->removeTranslator(m_Translator);
    if(m_Translator->load(":/" + lan)) {
        qApp->installTranslator(m_Translator);
        ui->retranslateUi(this);
    } else {
        QMessageBox::critical(this, tr("Error"), tr("Load new language failed !"));
    }
#else
//    qApp->removeTranslator(m_Translator);
//    if(false == m_Translator->load(":/" + lan)) {
//        QMessageBox::critical(this, tr("Error"), tr("Load new language failed !"));
//        qApp->installTranslator(m_Translator);
//        ui->retranslateUi(this);
//    }
#endif
*/
}
QSize MainWindow::GetScreenSize()
   {
       QDesktopWidget* desktopWidget = QApplication::desktop();
       //获取可用桌面大小
       QRect deskRect = desktopWidget->availableGeometry();
       //获取设备屏幕大小
       QRect screenRect = desktopWidget->screenGeometry();
       qDebug()<<"*********分辨率********"<<screenRect.width();
       return QSize(screenRect.width(),screenRect.height());
       //g_nActScreenY = screenRect.height();
       //g_nActScreenX = deskRect.width();
       //g_nActScreenY = deskRect.height();

       //获取系统设置的屏幕个数（屏幕拷贝方式该值为1）
       //g_nScreenCount = desktopWidget->screenCount();
}
void MainWindow::readSettings()
{
    LoAppConfig *cfg = LoAppConfig::getInstance();
    QSettings *settings = new QSettings(cfg->OrganizationName(), cfg->ApplicationName());
    QVariant iMaxFlag=settings->value("MainWindowMaximized");
    QVariant iAddFirewallFlag=settings->value("AddFirewallFlag");
    if (iAddFirewallFlag.toString() =="1")//是加入防火墙
    {

    }
    else {
        AddAppToFirewall();
    }
    //QPoint pos = settings->value("posMainWindow", QPoint(-1, 0)).toPoint();
    QSize size = settings->value("sizeMainWindow", QSize(1024, 600)).toSize();
    setWindowState(Qt::WindowMaximized);
    qDebug()<<"Qt::WindowMaximized";
//    if (iMaxFlag.toString() =="1")//是最大化状态
//    {
//        setWindowState(Qt::WindowMaximized);
//    }
//    else
//    {
//        QSize itempDesktopSize=GetScreenSize();
//        this->setMaximumSize(itempDesktopSize);
//        this->setMinimumSize(QSize(1024,600));
//        if(size.width()>itempDesktopSize.width()||size.height()>itempDesktopSize.height())
//        {
//             resize(itempDesktopSize);
//        }
//        else {

//            resize(size);
//        }

//    }
    /*20201017 masked by alahover -s
    m_strSelectNetName=settings->value("DirectlyConnectNetWork").toString();
    if(m_strSelectNetName.isEmpty())
    {
        m_pOneKeyCheckCard->setEnabled(false);
    }
    else {
        m_pSwitchDhcpControl->setCheckedStatus(true);
        m_pSwitchDhcpControl->setEnabled(true);
        m_pOneKeyCheckCard->setEnabled(true);
        m_wDeviceManager->pNetComm->RestoreLedCardIpByUdpCmdBefore(m_strSelectNetName);
    }
    */

}

void MainWindow::writeSettings()
{
    LoAppConfig *cfg = LoAppConfig::getInstance();
    QSettings *settings = new QSettings(cfg->OrganizationName(), cfg->ApplicationName());
    settings->setValue("AddFirewallFlag", "1");
    if (windowState() & Qt::WindowMaximized)//是最大化状态
    {
        settings->setValue("MainWindowMaximized", "1");
    }
    else {
        settings->setValue("posMainWindow", this->pos());
        settings->setValue("sizeMainWindow", QSize(this->width(), this->height()));
        settings->setValue("MainWindowMaximized", "0");

    }
    settings->setValue("DirectlyConnectNetWork", m_strSelectNetName);

}
void MainWindow::onDhcpSwitcherToggled(bool b)
{
    QList<QNetworkInterface> ifaceList = QNetworkInterface::allInterfaces();
    QStringList selectNetworklist;
    for (int i = 0; i < ifaceList.count(); i++)
    {
        QNetworkInterface var = ifaceList.at(i);
        if(var.type()==QNetworkInterface::Ethernet)
        {
            QString strTemp=var.humanReadableName();
            QString strtemplower=strTemp.toLower();
            if(strtemplower.contains("bluetooth")||strtemplower.contains("蓝牙"))
                break;
            selectNetworklist.append(strtemplower);
        }

    }
    int iCount=selectNetworklist.count();
    if(iCount<=0)
    {
        //没有检测到计算机网卡
       //m_pSwitchDhcpControl->setToggle(false);
        m_pSwitchDhcpControl->setEnabled(false);

        m_pOneKeyCheckCard->setEnabled(false);
        X_UIMsgBoxOk *pDlg=new X_UIMsgBoxOk(tr("Tip"),tr("No available network was detected"),this,0);
        pDlg->exec();
        return;
    }
    if(b)//直连，设置计算机IP地址为192.168.0.168,掩码255.255.255.0,网关192.168.0.1
    {

        if(iCount==1)
        {
            m_strSelectNetName=selectNetworklist.at(0);

        }
        else if(iCount>1){//人工选择和控制卡直连的网卡
            TipDialog *dlg = new TipDialog(this,ENUM_SELECT_NETWORK,&selectNetworklist,0);
            connect(dlg, SIGNAL(sigAcceptData(QString,QString)), this, SLOT(onCmdSetNetworkBySelect(QString,QString)));
            if(dlg->exec() == QDialog::Accepted)
            {
        //        QMessageBox::warning(this, "Title", "Text");
                qDebug() <<"选择的网卡是：" <<m_strSelectNetName;
            }
            else {

                    //m_pSwitchDhcpControl->setChecked(false);
                    //m_pSwitchDhcpControl->setCheckedStatus(false);
                    m_pSwitchDhcpControl->setEnabled(false);

                    m_pOneKeyCheckCard->setEnabled(false);
                    return;
            }
        }
            QString strCommand="netsh interface ip set address name=";
            strCommand=strCommand+"\""+m_strSelectNetName+"\" static 192.168.0.88 255.255.255.0 192.168.0.1";
            qDebug() <<strCommand;
            QProcess cmd(nullptr);
            cmd.start(strCommand);
            cmd.waitForFinished();
           // QThread::sleep(5000);
            m_wDeviceManager->pNetComm->RestoreLedCardIpByUdpCmdBefore(m_strSelectNetName);
            m_pOneKeyCheckCard->setEnabled(true);
 //          QThread::sleep(0.5);
  //          m_pOneKeyCheckCard->click();

        if(m_pTimerSendResoreIpOneKey==nullptr)
        {
            m_pTimerSendResoreIpOneKey = new QTimer();
            connect(m_pTimerSendResoreIpOneKey,SIGNAL(timeout()),this, SLOT(OnTimeoutSendResoreIpOneKey()));
        }
        m_pTimerSendResoreIpOneKey->start(2000);

    }
    else {//关闭直连，设置计算机为自动获取ip地址
        if(iCount==1)
        {
            m_strSelectNetName=selectNetworklist.at(0);

        }
        else if(iCount>1){//人工选择和控制卡直连的网卡
            TipDialog *dlg = new TipDialog(this,ENUM_SELECT_NETWORK,&selectNetworklist,1);
            connect(dlg, SIGNAL(sigAcceptData(QString,QString)), this, SLOT(onCmdSetNetworkBySelect(QString,QString)));
            if(dlg->exec() == QDialog::Accepted)
            {
        //        QMessageBox::warning(this, "Title", "Text");
                qDebug() <<"选择的网卡是：" <<m_strSelectNetName;
            }
            else {

                    //m_pSwitchDhcpControl->setToggle(false);
                    m_pSwitchDhcpControl->setEnabled(true);

                    m_pOneKeyCheckCard->setEnabled(false);
                    return;
            }
        }
       // m_wDeviceManager->pNetComm->RestoreLedCardIpToDhcpByUdpCmd(m_strSelectNetName);//屏蔽词句，在终端设置中通过post去修改ip，不再使用udp去配置控制卡的dhcp

            QString strCommand="netsh interface ip set address name=";
            strCommand=strCommand+"\""+m_strSelectNetName+"\" source=dhcp";
            qDebug() <<strCommand;
            QProcess cmd(nullptr);
            cmd.start(strCommand);
            cmd.waitForFinished();
            m_wDeviceManager->pNetComm->RestoreLedCardIpByUdpCmdBefore("");
            m_strSelectNetName="";
            m_pOneKeyCheckCard->setEnabled(false);

    }
    writeSettings();
}
void MainWindow::OnTimeoutSendResoreIpOneKey()
{
    m_pTimerSendResoreIpOneKey->stop();
    m_pOneKeyCheckCard->click();
}
void MainWindow::onCmdSetNetworkBySelect(QString strNetwork,QString strTip1)
{
    Q_UNUSED(strTip1);
    m_strSelectNetName=strNetwork;

}
void MainWindow::onGuangYingPinChanged()
{
    if(m_wTab!=nullptr)
    m_wTab->onGuangYingPinChanged();
}
QString MainWindow::GetPasswordPro()
{
    LoAppConfig *cfg = LoAppConfig::getInstance();
    QSettings *settings = new QSettings(cfg->OrganizationName(), cfg->ApplicationName());
#ifndef MACRO_YUANHENG_VERSION
    QString strMiWenPs=settings->value("advUiPs").toString();
#else
    QString strMiWenPs=settings->value("advUiPs_YuanHeng").toString();

#endif
    QString result = QTextCodec::codecForName("GBK")->toUnicode(QByteArray::fromBase64(strMiWenPs.toLocal8Bit()));

    QString strPs=result;

    if(strPs.isEmpty())
    {
#ifndef MACRO_YUANHENG_VERSION
        return "888";
#else
        return "Cargo10065!@#";

#endif


    }
    else {
        return strPs;
    }
}
void MainWindow::onInputPasswordPro(QString strPassword)
{
//#ifndef MACRO_YUANHENG_VERSION
//   if(strPassword=="888")
// #else
//  if(strPassword=="Cargo10065!@#")
// #endif
  if(strPassword==GetPasswordPro())
  {

   }
  else {

      InputPasswordDialog *pDlg1=new InputPasswordDialog(this,2);
      connect(pDlg1, SIGNAL(sigAcceptData(QString)), this, SLOT(onInputPasswordPro(QString)));
      connect(pDlg1, SIGNAL(rejected()), window(), SLOT(close()));
       pDlg1->setWindowModality(Qt::WindowModal);
      pDlg1->exec();
  }
}
void MainWindow::InputPasswordDlg()
{
    timer->stop();
    InputPasswordDialog *pDlg=new InputPasswordDialog(this,0);
    connect(pDlg, SIGNAL(sigAcceptData(QString)), this, SLOT(onInputPasswordPro(QString)));
    connect(pDlg, SIGNAL(rejected()), window(), SLOT(close()));
    pDlg->setWindowModality(Qt::WindowModal);
    pDlg->exec();
   // close();
}

