#include "upgradeapkdialog.h"
#include "ui_upgradeapkdialog.h"
#include <QAction>
#include <communication/network.h>
#include <QFileDialog>
#include <QMessageBox>
UpgradeApkDialog::UpgradeApkDialog(QWidget *parent,QString strProgramName,QString strProgramPath) :
    LoQDialog(parent),
    ui(new Ui::UpgradeApkDialog)
{
    ui->setupUi(this);
    setWindowState(Qt::WindowMaximized);

    m_strProgramName=strProgramName;
    m_strProgramPath=strProgramPath;
    QAction *search = new QAction(ui->txtSearch);
    search->setIcon(QIcon(":/res/ProgramManager/bnSearch.png"));
    ui->txtSearch->addAction(search, QLineEdit::LeadingPosition);
    ui->txtSearch->setClearButtonEnabled(true);
    ui->txtSearch->setProperty("ssType", "progManageTool");
    ui->txtSearch->setProperty("ssName", "searchProg");
    ui->wDevicePublishList->setProperty("ssType", "topList");
    ui->wDevicePublishList->setProperty("ssName", "publishTreeWidget1");
    ui->pushButtonClose->setProperty("ssType", "progManageTool");
    ui->pushButtonClose->setStyleSheet("QPushButton{background:rgba(28,154,210,255);}");
    ui->pushButtonRefresh->setProperty("ssType", "progManageTool");
    ui->pushButtonRefresh->setStyleSheet("QPushButton{background:rgba(28,154,210,255);}");
    ui->pushButtonPublish->setProperty("ssType", "progManageTool");
    ui->pushButtonPublish->setStyleSheet("QPushButton{background:rgba(28,154,210,255);}");

    ui->pushButtonSelectApk->setProperty("ssType", "progManageTool");
    ui->pushButtonSelectApk->setStyleSheet("QPushButton{background:rgba(28,154,210,255);}");
    ui->pushButtonSelectFpga->setProperty("ssType", "progManageTool");
    ui->pushButtonSelectFpga->setStyleSheet("QPushButton{background:rgba(28,154,210,255);}");
    ui->pushButtonUpgradeFpga->setProperty("ssType", "progManageTool");
    ui->pushButtonUpgradeFpga->setStyleSheet("QPushButton{background:rgba(28,154,210,255);}");

    ui->pushButtonUninstall->setProperty("ssType", "progManageTool");
    ui->pushButtonUninstall->setStyleSheet("QPushButton{background:rgba(28,154,210,255);}");
    ui->pushButtonCheckRuningState->setProperty("ssType", "progManageTool");
    ui->pushButtonCheckRuningState->setStyleSheet("QPushButton{background:rgba(28,154,210,255);}");

    ui->pushButtonCancel->setProperty("ssType", "progManageTool");
    ui->pushButtonCancel->setStyleSheet("QPushButton{background:rgba(28,154,210,255);}");

    ui->pushButtonMax->setProperty("ssType", "progManageTool");
    ui->pushButtonMax->setStyleSheet("QPushButton{background:rgba(28,154,210,255);}");

//    ui->wDevicePublishList->setStyleSheet("background-color: #f0f0f0;");

    m_headerItem = new QTreeWidgetItem();
    m_headerItem->setTextAlignment(1, Qt::AlignHCenter | Qt::AlignVCenter);

    for(int i=1; i<ENUM_DEVICE_PUBLISH_HEADE_END; i++) {
        m_headerItem->setTextAlignment(i, Qt::AlignCenter);
    }
    m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_CHECK, 0, "");
    m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_SCREEN_ID, 0, tr("Screen ID"));
    m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_REMARK_NAME, 0, tr("Remark Name"));
    m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_ONLINE, 0, tr("Online"));
    m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_SCREEN_IP, 0, tr("Screen IP"));
    m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_ENCRYPT,0,tr("Security"));
    m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_PROGRESS, 0, tr("Progress"));
    m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_XIXUNPLAYER_VERSION, 0, tr("xixunplayer"));
    m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_CARDSYSTEM_VERSION,0,tr("cardsystem"));
    m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_TAXIAPP_VERSION,0,tr("taxiapp"));
    m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_STARTER_VERSION,0,tr("starter"));
    m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_CONNECTION_VERSION,0,tr("connection"));
    m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_DISPLAYER_VERSION,0,tr("displayer"));
    m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_FPAG_VERSION,0,tr("FPGA"));

    m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_UPDATE_VERSION,0,tr("update"));
//    m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_BASICAPP_VERSION,0,tr("basicapp"));
    m_headerItem->setData(ENUM_DEVICE_PUBLISH_HEADE_REMARKS,0,tr("State"));

    ui->wDevicePublishList->setHeaderItem(m_headerItem);
    ui->wDevicePublishList->header()->setSectionResizeMode(ENUM_DEVICE_PUBLISH_HEADE_CHECK, QHeaderView::Fixed);
    ui->wDevicePublishList->header()->setSectionResizeMode(ENUM_DEVICE_PUBLISH_HEADE_ONLINE, QHeaderView::Fixed);
    ui->wDevicePublishList->header()->setSectionResizeMode(ENUM_DEVICE_PUBLISH_HEADE_SCREEN_ID, QHeaderView::Fixed);
    ui->wDevicePublishList->header()->setSectionResizeMode(ENUM_DEVICE_PUBLISH_HEADE_REMARK_NAME, QHeaderView::ResizeToContents);
    ui->wDevicePublishList->header()->setSectionResizeMode(ENUM_DEVICE_PUBLISH_HEADE_SCREEN_IP, QHeaderView::ResizeToContents);
    ui->wDevicePublishList->header()->setSectionResizeMode(ENUM_DEVICE_PUBLISH_HEADE_ENCRYPT, QHeaderView::Fixed);
    ui->wDevicePublishList->header()->setSectionResizeMode(ENUM_DEVICE_PUBLISH_HEADE_PROGRESS, QHeaderView::Fixed);
    ui->wDevicePublishList->header()->setSectionResizeMode(ENUM_DEVICE_PUBLISH_HEADE_XIXUNPLAYER_VERSION, QHeaderView::Stretch);
    ui->wDevicePublishList->header()->setSectionResizeMode(ENUM_DEVICE_PUBLISH_HEADE_CARDSYSTEM_VERSION, QHeaderView::Stretch);
    ui->wDevicePublishList->header()->setSectionResizeMode(ENUM_DEVICE_PUBLISH_HEADE_TAXIAPP_VERSION, QHeaderView::ResizeToContents);
    ui->wDevicePublishList->header()->setSectionResizeMode(ENUM_DEVICE_PUBLISH_HEADE_STARTER_VERSION, QHeaderView::ResizeToContents);
      ui->wDevicePublishList->header()->setSectionResizeMode(ENUM_DEVICE_PUBLISH_HEADE_CONNECTION_VERSION, QHeaderView::ResizeToContents);
      ui->wDevicePublishList->header()->setSectionResizeMode(ENUM_DEVICE_PUBLISH_HEADE_DISPLAYER_VERSION, QHeaderView::ResizeToContents);
      ui->wDevicePublishList->header()->setSectionResizeMode(ENUM_DEVICE_PUBLISH_HEADE_FPAG_VERSION, QHeaderView::ResizeToContents);

    ui->wDevicePublishList->header()->setSectionResizeMode(ENUM_DEVICE_PUBLISH_HEADE_UPDATE_VERSION, QHeaderView::ResizeToContents);
 //   ui->wDevicePublishList->header()->setSectionResizeMode(ENUM_DEVICE_PUBLISH_HEADE_BASICAPP_VERSION, QHeaderView::Stretch);
    ui->wDevicePublishList->header()->setSectionResizeMode(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, QHeaderView::Stretch);

     ui->wDevicePublishList->header()->setStretchLastSection(false);
     ui->wDevicePublishList->setColumnWidth(ENUM_DEVICE_PUBLISH_HEADE_CHECK, 50);
     ui->wDevicePublishList->setColumnWidth(ENUM_DEVICE_PUBLISH_HEADE_SCREEN_ID, 120);
//     ui->wDevicePublishList->setColumnWidth(ENUM_DEVICE_PUBLISH_HEADE_SCREEN_IP, 110);
     ui->wDevicePublishList->setColumnWidth(ENUM_DEVICE_PUBLISH_HEADE_ONLINE, 50);
    ui->wDevicePublishList->setColumnWidth(ENUM_DEVICE_PUBLISH_HEADE_ENCRYPT, 50);
    ui->wDevicePublishList->setColumnWidth(ENUM_DEVICE_PUBLISH_HEADE_PROGRESS, 100);
    //ui->wDevicePublishList->setColumnWidth(ENUM_DEVICE_PUBLISH_HEADE_REMARKS, 192);
    ui->lineEditPackageName->setVisible(false);
//    ui->comboBoxApk->addItem("Player");
//    ui->comboBoxApk->addItem("Displayer");
//    ui->comboBoxApk->addItem("TaxiApp");
//    ui->comboBoxApk->addItem("Starter");
//    ui->comboBoxApk->addItem("Systemcore");
//    ui->comboBoxApk->addItem("CardSystem");
//    ui->comboBoxApk->addItem("Conn");
//    ui->comboBoxApk->addItem("Xwalk");
//    ui->comboBoxApk->addItem("Live");
    ui->comboBoxApk->addItem("com.xixun.xixunplayer");
    ui->comboBoxApk->addItem("com.xixun.joey.cardsystem");
    ui->comboBoxApk->addItem("com.xixun.joey.systemcore");
    ui->comboBoxApk->addItem("net.sysolution.taxiapp");
    ui->comboBoxApk->addItem("net.sysolution.starter");
    ui->comboBoxApk->addItem("com.xixun.display");
    ui->comboBoxApk->addItem("com.xixun.xy.conn");
    ui->comboBoxApk->addItem("com.xixun.xy.update");
    ui->comboBoxApk->addItem("net.sysolution.basicapp");
    ui->comboBoxApk->addItem("PackageName");

    ui->comboBoxApk->setCurrentIndex(0);
    ui->comboBoxApk->setFocus();
    ui->pushButtonPublish->setEnabled(false);
    ui->pushButtonUpgradeFpga->setEnabled(false);
    connect(ui->pushButtonRefresh,SIGNAL(clicked()),this,SLOT(onRefresh()));
    connect(ui->pushButtonPublish,SIGNAL(clicked()),this,SLOT(onUpgradeApk()));
    connect(ui->pushButtonUpgradeFpga,SIGNAL(clicked()),this,SLOT(onUpgradeFpga()));


    connect(ui->pushButtonMax,SIGNAL(clicked()),this,SLOT(onMaxWnd()));
    connect(ui->pushButtonSelectApk,SIGNAL(clicked()),this,SLOT(onSelectApk()));
    connect(ui->pushButtonSelectFpga,SIGNAL(clicked()),this,SLOT(onSelectFpga()));
    connect(ui->pushButtonUninstall,SIGNAL(clicked()),this,SLOT(onUninstall()));
    connect(ui->pushButtonCheckRuningState,SIGNAL(clicked()),this,SLOT(onCheckRuningState()));

    connect(ui->txtSearch,SIGNAL(textChanged(const QString &)),this,SLOT(FilterProgram(const QString &)));
    connect(ui->comboBoxApk, SIGNAL(currentIndexChanged(int)), this, SLOT(OnComboApkChanged(int)));

    onRefreshAuto();
    m_pTimer=new QTimer(this);
    connect(m_pTimer,SIGNAL(timeout()),this,SLOT(onRefreshAuto()));
    m_pTimer->start(500000);

//    ui->pushButtonSelectApk->setVisible(false);
//    ui->pushButtonPublish->setVisible(false);

}
void UpgradeApkDialog::onRefresh()
{

    if(p_globaNetComm!=nullptr)
    {
        ui->wDevicePublishList->clear();
        ui->wDevicePublishList->onCheckAll(false);
        int iCount=p_globaNetComm->LedCardList.count();
        for(int i=0;i<iCount;i++)
        {
            onAddLedCard(p_globaNetComm->LedCardList.at(i));
        }
        ui->label->setText(tr("All")+":"+QString::number(iCount));

    }

}
void UpgradeApkDialog::onRefreshAuto()
{

    if(p_globaNetComm!=nullptr)
    {
        int iCount=p_globaNetComm->LedCardList.count();
        for(int i=0;i<iCount;i++)
        {
            onAddLedCard(p_globaNetComm->LedCardList.at(i));
        }
        ui->label->setText(tr("All")+":"+QString::number(iCount));

    }

}
void UpgradeApkDialog::onMaxWnd()
{
    QWidget *pWindow = this;//window();
    if(pWindow->isMaximized()) {
        pWindow->showNormal();
        qDebug()<<"showNormal";
    } else {
        pWindow->showMaximized();
        qDebug()<<"showMaximized";
    }
}
void UpgradeApkDialog::onUpgradeApk()
{
    QString strApkName=ui->label_ApkPath->text();

    if(strApkName.length()<3)
        return;
    int cnt = ui->wDevicePublishList->topLevelItemCount();
    QStringList selectProgramlist;
    //int ii=0;
    for(int i=0; i<cnt; i++) {
        if(ui->wDevicePublishList->topLevelItem(i)->checkState(0) == Qt::Checked) {

            static_cast<wUpgradeApkItem *>(ui->wDevicePublishList->topLevelItem(i))->onUpgradeApk(strApkName);
           // ii++;
        }
        else {
           // ii++;
        }
    }

}
void UpgradeApkDialog::onUpgradeFpga()
{
    QString strFpgaName=ui->label_FpgaPath->text();

    if(strFpgaName.length()<3)
        return;
    int cnt = ui->wDevicePublishList->topLevelItemCount();
    QStringList selectProgramlist;
    //int ii=0;
    for(int i=0; i<cnt; i++) {
        if(ui->wDevicePublishList->topLevelItem(i)->checkState(0) == Qt::Checked) {

            static_cast<wUpgradeApkItem *>(ui->wDevicePublishList->topLevelItem(i))->onUpgradeFpga(strFpgaName);
           // ii++;
        }
        else {
           // ii++;
        }
    }

}
UpgradeApkDialog::~UpgradeApkDialog()
{
    if(m_pTimer!=nullptr)
    {
        if(m_pTimer->isActive())
            m_pTimer->stop();
        delete m_pTimer;
    }
    delete ui;
}
void UpgradeApkDialog::onAddLedCard(LedCard *p)
{
    // qDebug() << " SLOT onAddLedCard FUNC:" << p->m_strCardId;
     int iExistFlg=0;
     int cnt = ui->wDevicePublishList->topLevelItemCount();
     for(int i=0; i<cnt; i++) {
         QString strTempCardId=static_cast<wUpgradeApkItem*>(ui->wDevicePublishList->topLevelItem(i))->GetLedCardId();

         if(strTempCardId == p->m_strCardId) {
             iExistFlg=1;
             static_cast<wUpgradeApkItem*>(ui->wDevicePublishList->topLevelItem(i))->SetItemParam(p);
             break;
         }
     }
     if(iExistFlg==0)
     {
         m_pwDeviceItemList.append(new wUpgradeApkItem( p, ui->wDevicePublishList,this,m_strProgramName,m_strProgramPath));

     }
}

//void UpgradeApkDialog::mousePressEvent(QMouseEvent *event)
//{
//    if(event->button()==Qt::RightButton)
//   {
//        int cnt = ui->wDevicePublishList->topLevelItemCount();
//         for(int i=0; i<cnt; i++) {
//                static_cast<wUpgradeApkItem *>(ui->wDevicePublishList->topLevelItem(i))->SetLockFlagFalse();
//        }

//   }
//}
void UpgradeApkDialog::keyPressEvent(QKeyEvent *ev)
{
     if(ev->key() == Qt::Key_F3)
    {
         QMessageBox::warning(this, "Tip", tr("The encrypted control card can be upgraded directly"));
         int cnt = ui->wDevicePublishList->topLevelItemCount();
          for(int i=0; i<cnt; i++) {
                 static_cast<wUpgradeApkItem *>(ui->wDevicePublishList->topLevelItem(i))->SetLockFlagFalse();
         }
    }
}
void UpgradeApkDialog::FilterProgram(const QString &strtemp)
{
    if (strtemp.isEmpty())	//显示全部
    {
        for (int i = 0; i< ui->wDevicePublishList->topLevelItemCount(); ++i)
        {
            QTreeWidgetItem* topItem = ui->wDevicePublishList->topLevelItem(i);
            ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),false);
        }
    }
    else
    {
        QList<QTreeWidgetItem*> resultList = ui->wDevicePublishList->findItems(strtemp, Qt::MatchContains,ENUM_DEVICE_PUBLISH_HEADE_SCREEN_ID);	//搜索结果
        if (resultList.size() > 0)
        {
            //QMessageBox::warning(this, "Export", QString(resultList.size()));
            for (int i = 0; i< ui->wDevicePublishList->topLevelItemCount(); ++i)
            {
                QTreeWidgetItem* topItem = ui->wDevicePublishList->topLevelItem(i);
                if (resultList.contains(topItem))
                    ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),false);	//显示匹配的结果
                else
                    ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),true);	//隐藏不匹配的结果
            }
        }
        else {

            QList<QTreeWidgetItem*> resultList6 = ui->wDevicePublishList->findItems(strtemp, Qt::MatchContains,ENUM_DEVICE_PUBLISH_HEADE_REMARK_NAME);	//搜索结果
            if (resultList6.size() > 0)
            {
                //QMessageBox::warning(this, "Export", QString(resultList.size()));
                for (int i = 0; i< ui->wDevicePublishList->topLevelItemCount(); ++i)
                {
                    QTreeWidgetItem* topItem = ui->wDevicePublishList->topLevelItem(i);
                    if (resultList6.contains(topItem))
                        ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),false);	//显示匹配的结果
                    else
                        ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),true);	//隐藏不匹配的结果
                }
            }
            else {


                //QMessageBox::warning(this, "Export", "FilterProgram");
                QList<QTreeWidgetItem*> resultList1 = ui->wDevicePublishList->findItems(strtemp, Qt::MatchContains,ENUM_DEVICE_PUBLISH_HEADE_XIXUNPLAYER_VERSION);	//搜索结果
                if (resultList1.size() > 0)
                {
                    //QMessageBox::warning(this, "Export", QString(resultList.size()));
                    for (int i = 0; i< ui->wDevicePublishList->topLevelItemCount(); ++i)
                    {
                        QTreeWidgetItem* topItem = ui->wDevicePublishList->topLevelItem(i);
                        if (resultList1.contains(topItem))
                            ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),false);	//显示匹配的结果
                        else
                            ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),true);	//隐藏不匹配的结果
                    }
                }
                else {
                    QList<QTreeWidgetItem*> resultList2 = ui->wDevicePublishList->findItems(strtemp, Qt::MatchContains,ENUM_DEVICE_PUBLISH_HEADE_SCREEN_IP);	//搜索结果
                    if (resultList2.size() > 0)
                    {
                        //QMessageBox::warning(this, "Export", QString(resultList.size()));
                        for (int i = 0; i< ui->wDevicePublishList->topLevelItemCount(); ++i)
                        {
                            QTreeWidgetItem* topItem = ui->wDevicePublishList->topLevelItem(i);
                            if (resultList2.contains(topItem))
                                ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),false);	//显示匹配的结果
                            else
                                ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),true);	//隐藏不匹配的结果
                        }
                    }
                    else {
                        QList<QTreeWidgetItem*> resultList2 = ui->wDevicePublishList->findItems(strtemp, Qt::MatchContains,ENUM_DEVICE_PUBLISH_HEADE_XIXUNPLAYER_VERSION);	//搜索结果
                        if (resultList2.size() > 0)
                        {
                            //QMessageBox::warning(this, "Export", QString(resultList.size()));
                            for (int i = 0; i< ui->wDevicePublishList->topLevelItemCount(); ++i)
                            {
                                QTreeWidgetItem* topItem = ui->wDevicePublishList->topLevelItem(i);
                                if (resultList2.contains(topItem))
                                    ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),false);	//显示匹配的结果
                                else
                                    ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),true);	//隐藏不匹配的结果
                            }
                        }
                        else {
                            QList<QTreeWidgetItem*> resultList2 = ui->wDevicePublishList->findItems(strtemp, Qt::MatchContains,ENUM_DEVICE_PUBLISH_HEADE_CARDSYSTEM_VERSION);	//搜索结果
                            if (resultList2.size() > 0)
                            {
                                //QMessageBox::warning(this, "Export", QString(resultList.size()));
                                for (int i = 0; i< ui->wDevicePublishList->topLevelItemCount(); ++i)
                                {
                                    QTreeWidgetItem* topItem = ui->wDevicePublishList->topLevelItem(i);
                                    if (resultList2.contains(topItem))
                                        ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),false);	//显示匹配的结果
                                    else
                                        ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),true);	//隐藏不匹配的结果
                                }
                            }
                            else {
                                QList<QTreeWidgetItem*> resultList2 = ui->wDevicePublishList->findItems(strtemp, Qt::MatchContains,ENUM_DEVICE_PUBLISH_HEADE_TAXIAPP_VERSION);	//搜索结果
                                if (resultList2.size() > 0)
                                {
                                    //QMessageBox::warning(this, "Export", QString(resultList.size()));
                                    for (int i = 0; i< ui->wDevicePublishList->topLevelItemCount(); ++i)
                                    {
                                        QTreeWidgetItem* topItem = ui->wDevicePublishList->topLevelItem(i);
                                        if (resultList2.contains(topItem))
                                            ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),false);	//显示匹配的结果
                                        else
                                            ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),true);	//隐藏不匹配的结果
                                    }
                                }
                                else {
                                    QList<QTreeWidgetItem*> resultList2 = ui->wDevicePublishList->findItems(strtemp, Qt::MatchContains,ENUM_DEVICE_PUBLISH_HEADE_DISPLAYER_VERSION);	//搜索结果
                                    if (resultList2.size() > 0)
                                    {
                                        //QMessageBox::warning(this, "Export", QString(resultList.size()));
                                        for (int i = 0; i< ui->wDevicePublishList->topLevelItemCount(); ++i)
                                        {
                                            QTreeWidgetItem* topItem = ui->wDevicePublishList->topLevelItem(i);
                                            if (resultList2.contains(topItem))
                                                ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),false);	//显示匹配的结果
                                            else
                                                ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),true);	//隐藏不匹配的结果
                                        }
                                    }
                                    else {
                                        QList<QTreeWidgetItem*> resultList2 = ui->wDevicePublishList->findItems(strtemp, Qt::MatchContains,ENUM_DEVICE_PUBLISH_HEADE_STARTER_VERSION);	//搜索结果
                                        if (resultList2.size() > 0)
                                        {
                                            //QMessageBox::warning(this, "Export", QString(resultList.size()));
                                            for (int i = 0; i< ui->wDevicePublishList->topLevelItemCount(); ++i)
                                            {
                                                QTreeWidgetItem* topItem = ui->wDevicePublishList->topLevelItem(i);
                                                if (resultList2.contains(topItem))
                                                    ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),false);	//显示匹配的结果
                                                else
                                                    ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),true);	//隐藏不匹配的结果
                                            }
                                        }
                                        else {
                                            QList<QTreeWidgetItem*> resultList2 = ui->wDevicePublishList->findItems(strtemp, Qt::MatchContains,ENUM_DEVICE_PUBLISH_HEADE_CONNECTION_VERSION);	//搜索结果
                                            if (resultList2.size() > 0)
                                            {
                                                //QMessageBox::warning(this, "Export", QString(resultList.size()));
                                                for (int i = 0; i< ui->wDevicePublishList->topLevelItemCount(); ++i)
                                                {
                                                    QTreeWidgetItem* topItem = ui->wDevicePublishList->topLevelItem(i);
                                                    if (resultList2.contains(topItem))
                                                        ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),false);	//显示匹配的结果
                                                    else
                                                        ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),true);	//隐藏不匹配的结果
                                                }
                                            }
                                            else {
                                                QList<QTreeWidgetItem*> resultList2 = ui->wDevicePublishList->findItems(strtemp, Qt::MatchContains,ENUM_DEVICE_PUBLISH_HEADE_UPDATE_VERSION);	//搜索结果
                                                if (resultList2.size() > 0)
                                                {
                                                    //QMessageBox::warning(this, "Export", QString(resultList.size()));
                                                    for (int i = 0; i< ui->wDevicePublishList->topLevelItemCount(); ++i)
                                                    {
                                                        QTreeWidgetItem* topItem = ui->wDevicePublishList->topLevelItem(i);
                                                        if (resultList2.contains(topItem))
                                                            ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),false);	//显示匹配的结果
                                                        else
                                                            ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),true);	//隐藏不匹配的结果
                                                    }
                                                }
                                                else {
                                                    QList<QTreeWidgetItem*> resultList2 = ui->wDevicePublishList->findItems(strtemp, Qt::MatchContains,ENUM_DEVICE_PUBLISH_HEADE_FPAG_VERSION);	//搜索结果
                                                    if (resultList2.size() > 0)
                                                    {
                                                        //QMessageBox::warning(this, "Export", QString(resultList.size()));
                                                        for (int i = 0; i< ui->wDevicePublishList->topLevelItemCount(); ++i)
                                                        {
                                                            QTreeWidgetItem* topItem = ui->wDevicePublishList->topLevelItem(i);
                                                            if (resultList2.contains(topItem))
                                                                ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),false);	//显示匹配的结果
                                                            else
                                                                ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),true);	//隐藏不匹配的结果
                                                        }
                                                    }
                                                    else {
                                                        QList<QTreeWidgetItem*> resultList2 = ui->wDevicePublishList->findItems(strtemp, Qt::MatchContains,ENUM_DEVICE_PUBLISH_HEADE_REMARKS);	//搜索结果
                                                        if (resultList2.size() > 0)
                                                        {
                                                            //QMessageBox::warning(this, "Export", QString(resultList.size()));
                                                            for (int i = 0; i< ui->wDevicePublishList->topLevelItemCount(); ++i)
                                                            {
                                                                QTreeWidgetItem* topItem = ui->wDevicePublishList->topLevelItem(i);
                                                                if (resultList2.contains(topItem))
                                                                    ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),false);	//显示匹配的结果
                                                                else
                                                                    ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),true);	//隐藏不匹配的结果
                                                            }
                                                        }
                                                        else {
                                                            for (int i = 0; i< ui->wDevicePublishList->topLevelItemCount(); ++i)
                                                            {
                                                                QTreeWidgetItem* topItem = ui->wDevicePublishList->topLevelItem(i);
                                                                    ui->wDevicePublishList->setRowHidden(i,ui->wDevicePublishList->indexFromItem(topItem->parent()),true);	//隐藏不匹配的结果
                                                            }
                                                        }

                                                    }

                                                }

                                            }

                                        }

                                    }

                                }

                            }

                        }

                    }
                }
            }




        }
    }

}
void UpgradeApkDialog::onSelectFpga()
{
    QFileDialog dlg;

    QString m_strUpgradeFpgaFile = QFileDialog::getOpenFileName(this, "open file dialog",
                                             "",
                                             tr("apk package (*.rpd)"));
    ui->label_FpgaPath->setText(m_strUpgradeFpgaFile);

    QFileInfo file1(m_strUpgradeFpgaFile);
    if(file1.exists())
    {
        ui->pushButtonUpgradeFpga->setEnabled(true);
    }
    else {
        ui->pushButtonUpgradeFpga->setEnabled(false);
    }
}
void UpgradeApkDialog::onSelectApk()
{
    QFileDialog dlg;
    QString strUpgradeApkFile= QFileDialog::getOpenFileName(this, "open file dialog",
                                                       "",
                                                       tr("apk package (*.apk *.zip)"));
    ui->label_ApkPath->setText(strUpgradeApkFile);

    QFileInfo file1(strUpgradeApkFile);
    if(file1.exists())
    {
        ui->pushButtonPublish->setEnabled(true);
    }
    else {
        ui->pushButtonPublish->setEnabled(false);
    }

}
void UpgradeApkDialog::OnComboApkChanged(int index)
{

    if(ui->comboBoxApk->currentText()=="PackageName")
    {
        ui->lineEditPackageName->setVisible(true);
        ui->lineEditPackageName->setFocus();
    }
    else
    {
        ui->lineEditPackageName->setVisible(false);

    }
}
void UpgradeApkDialog::onUninstall()
{
    QString strApkName=ui->comboBoxApk->currentText();
    if(strApkName=="PackageName")
    {
        strApkName=ui->lineEditPackageName->text();
    }
    else
    {


    }
    int cnt = ui->wDevicePublishList->topLevelItemCount();
    QStringList selectProgramlist;
    //int ii=0;
    for(int i=0; i<cnt; i++) {
        if(ui->wDevicePublishList->topLevelItem(i)->checkState(0) == Qt::Checked) {
            static_cast<wUpgradeApkItem *>(ui->wDevicePublishList->topLevelItem(i))->onUninstallApk(strApkName);
           // ii++;
        }
        else {
           // ii++;
        }
    }
}
void UpgradeApkDialog::onCheckRuningState()
{
    QString strApkName=ui->comboBoxApk->currentText();
    if(strApkName=="PackageName")
    {
        strApkName=ui->lineEditPackageName->text();
    }
    else
    {


    }
    int cnt = ui->wDevicePublishList->topLevelItemCount();
    QStringList selectProgramlist;
    //int ii=0;
    for(int i=0; i<cnt; i++) {
        if(ui->wDevicePublishList->topLevelItem(i)->checkState(0) == Qt::Checked) {
            static_cast<wUpgradeApkItem *>(ui->wDevicePublishList->topLevelItem(i))->onCheckRuningState(strApkName);
           // ii++;
        }
        else {
           // ii++;
        }
    }
}
