GlobalSetting.cpp 25.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766
#include "GlobalSetting.h"
#include "GlobalSettingDefine.h"
#include "sqliteutil.h"
#include <conio.h>
#include <QSettings>

#include <QNetworkInterface>
#include <QProcess>
#include <QDir>
#include <QTextCodec>

CGlobalSetting _GlobalSetting;

CGlobalSetting::CGlobalSetting()
{

    networkurl           = "http://test.ishowedu.com/";   //网络地址web通讯
//    networkurl           = "https://api.ishowedu.com/";   //网络地址web通讯
    cloud_id             = "viptalk@ishowedu.com";   //网络地址web通讯
//    cloud_id             = "http://viptalk.ishowedu.com/";   //网络地址web通讯

}

CGlobalSetting::~CGlobalSetting()
{

}


//
void CGlobalSetting::writeConfigValue(QString key, QString value)
{
    QString filename = QCoreApplication::applicationDirPath() + QString("/config/config.ini");
    QSettings settings(filename, QSettings::IniFormat);

    QDir my_dir;
    QFileInfo my_info(filename);
    if (!my_dir.exists(my_info.absoluteDir().path())) {
        my_dir.mkpath(my_info.absoluteDir().path());
    }
    settings.beginGroup("VALUES");
    settings.setValue(key, value);
    settings.endGroup();
}


//
QString CGlobalSetting::readConfigValue(QString key)
{/*
    static QMutex mutex;
    QMutexLocker locker(&mutex);*/

    QString filename = QCoreApplication::applicationDirPath()+QString("/config/config.ini");
    QDir my_dir;
    QFileInfo my_info(filename);
    if(!my_dir.exists(my_info.absoluteDir().path()))
    {
       my_dir.mkpath(my_info.absoluteDir().path());
    }
    QSettings settings(filename, QSettings::IniFormat); // 当前目录的INI文件

    QTextCodec *code = QTextCodec::codecForName("utf-8");
    if(code == NULL)
    {
        code = QTextCodec::codecForLocale();
    }

    settings.setIniCodec(code);

    settings.beginGroup("VALUES");
    QString value = settings.value(key).toString();
    settings.endGroup();
    return value;
}

/*
bool CGlobalSetting::getActiveMac(char *sMac)
{
    bool bRtn = FALSE;
    PIP_ADAPTER_INFO pAdapterInfo;
    PIP_ADAPTER_INFO pAdapter = NULL;
    DWORD dwRetVal = 0;
    pAdapterInfo = (IP_ADAPTER_INFO *) malloc( sizeof(IP_ADAPTER_INFO) );
    ULONG ulOutBufLen = sizeof(IP_ADAPTER_INFO);
    if (GetAdaptersInfo( pAdapterInfo, &ulOutBufLen) != ERROR_SUCCESS)
    {
        free (pAdapterInfo);
        pAdapterInfo = (IP_ADAPTER_INFO *) malloc (ulOutBufLen);
    }
    if ((dwRetVal = GetAdaptersInfo( pAdapterInfo, &ulOutBufLen)) == NO_ERROR)
    {
        pAdapter = pAdapterInfo;
        char szMac[20] = {0};
        char szAddress[4] = {0};


        while (pAdapter)
        {

            if ( strcmp( pAdapter->IpAddressList.IpAddress.String ,"0.0.0.0" ) != 0 )
            {
                bool hadMac = false;
                for (UINT i = 0; i < pAdapter->AddressLength; i++)
                {
                    sprintf_s( szAddress , "%02X", pAdapter->Address[i] );
                    strcat_s( szMac , szAddress );
                    if( i != pAdapter->AddressLength - 1 )
                    {
                        strcat_s( szMac , "-" );
                    }
                    hadMac = true;
                }
                if (hadMac)
                    break;
            }
            pAdapter = pAdapter->Next;
        }
        memcpy( sMac , szMac , strlen( szMac ) );

    }
    else
    {
        printf("Call to GetAdaptersInfo failed.\n");
    }
    return bRtn;
}
*/
int CGlobalSetting::OnAppUninit()
{
    return 0;
}




/**
 * @brief CGlobalSetting::getScreenPos
 * @param showWidget
 * @return
 */
QPoint CGlobalSetting::getScreenPos(QWidget *showWidget)
{
    QPoint ScreenPos =  QPoint(this->MainWinRect.left()+(this->MainWinRect.width()-showWidget->geometry().width())/2
                               ,this->MainWinRect.top()+(this->MainWinRect.height()-showWidget->geometry().height())/2);
    qDebug() << "getScreenPos" << ScreenPos;
    if(ScreenPos.y() < QApplication::desktop()->geometry().top())
    {
        ScreenPos.setY(QApplication::desktop()->geometry().top());
    }

    if(ScreenPos.x() < QApplication::desktop()->geometry().left())
    {
        ScreenPos.setX(QApplication::desktop()->geometry().left());
    }
    return ScreenPos;
}

/**
 * @brief SetButtonColorStyle
 * @param button
 * 设置图片背景,通过颜色渐变
 */
void CGlobalSetting::SetButtonColorStyle(QPushButton *button)
{
    QString color_bg_1 = "93dbfe";
    QString color_bg_2 = "8ccff5";
    QString color_bg_3 = "50bdf9";
    QString color_bg_4 = "4db5f1";
    button->setStyleSheet(QString("QPushButton{background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #%1, stop: 1.0 #%2);")
      .append("border-style: outset;border-width: 0px;border-radius: 0px;color:white;}")
      .append("QPushButton::pressed{background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #%3, stop: 1.0 #%4);color:white;}")
      .append("QPushButton::checked{background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #%3, stop: 1.0 #%4);color:white;}")
      .arg(color_bg_1).arg(color_bg_2)
      .arg(color_bg_3).arg(color_bg_4));
}


/**
 * @brief SetButtonStyle 设置button图片分隔片 并且支持格外的qss
 * @param button
 * @param imgsrc
 * @param CutSec
 */
void CGlobalSetting::SetButtonStyle(QPushButton *button, QString imgsrc, int CutSec, QString appstr)
{
    int PicWidth = QPixmap(imgsrc).width()/CutSec;
    int width_2 = PicWidth*2;
    int width_3 = PicWidth*3;
    if(CutSec == 2)
    {
        width_2 = PicWidth;
        width_3 = PicWidth;
    }
    button->setStyleSheet(QString("QPushButton{border-width: 41px; border-image: url(%1)  0 0 0 %2 repeat  repeat;border-width: 0px; border-radius: 0px; %6}")
      .append("QPushButton::hover{border-image: url(%1) 0 0 0 %3  repeat  repeat;border-width: 0px; border-radius: 0px; %6}")
      .append("QPushButton::pressed{border-image: url(%1) 0  0 0 %4 repeat  repeat;border-width: 0px; border-radius: 0px; %6}")
      .append("QPushButton::checked{border-image: url(%1) 0  0 0 %4 repeat  repeat;border-width: 0px; border-radius: 0px; %6}")
      .append("QPushButton::disabled{border-image: url(%1) 0  0 0 %5 repeat  repeat;border-width: 0px; border-radius: 0px; %6}")
                          .arg(imgsrc).arg(0).arg(PicWidth*1).arg(width_2).arg(width_3).arg(appstr));
}

/**
 * @brief SetButtonStyle 设置button图片分隔片 并且支持格外的qss
 * @param button
 * @param imgsrc
 * @param CutSec
 */
void CGlobalSetting::SetButtonStyleC(QPushButton *button, QString imgsrc, int CutSec, QString appstr)
{
    int PicWidth = QPixmap(imgsrc).width()/CutSec;
    int width_2 = PicWidth*2;
    int width_3 = PicWidth*3;
    if(CutSec == 2)
    {
        width_2 = PicWidth;
        width_3 = PicWidth;
    }
    button->setStyleSheet(QString("QPushButton{border-width: 41px; border-image: url(%1)  0 0 0 %2 repeat  repeat;border-width: 0px; border-radius: 0px; %6}")
      .append("QPushButton::hover{border-image: url(%1) 0 0 0 %3  repeat  repeat;border-width: 0px; border-radius: 0px; %6}")
     /* .append("QPushButton::pressed{border-image: url(%1) 0  0 0 %4 repeat  repeat;border-width: 0px; border-radius: 0px; %6}")*/
      .append("QPushButton::checked{border-image: url(%1) 0  0 0 %4 repeat  repeat;border-width: 0px; border-radius: 0px; %6}")
      .append("QPushButton::disabled{border-image: url(%1) 0  0 0 %5 repeat  repeat;border-width: 0px; border-radius: 0px; %6}")
                          .arg(imgsrc).arg(0).arg(PicWidth*1).arg(width_2).arg(width_3).arg(appstr));
}

/**
 * @brief SetButtonStyle 设置button图片分隔片 仅修改按钮背景图片
 * @param button
 * @param imgsrc
 * @param CutSec
 */
void CGlobalSetting::SetButtonStyleB(QPushButton *button, QString imgsrc, int CutSec)
{
    int PicWidth = QPixmap(imgsrc).width()/CutSec;
    int width_2 = PicWidth*2;
    int width_3 = PicWidth*3;
    if(CutSec == 2)
    {
        width_2 = PicWidth;
        width_3 = PicWidth;
    }
    button->setStyleSheet(QString("QPushButton{border-width: 41px; border-image: url(%1)  0 0 0 %2 repeat  repeat;border-width: 0px; border-radius: 0px;}")
      .append("QPushButton::hover{border-image: url(%1) 0 0 0 %3  repeat  repeat;border-width: 0px; border-radius: 0px;}")
      .append("QPushButton::pressed{border-image: url(%1) 0  0 0 %4 repeat  repeat;border-width: 0px; border-radius: 0px;}")
      .append("QPushButton::checked{border-image: url(%1) 0  0 0 %4 repeat  repeat;border-width: 0px; border-radius: 0px;}")
      .append("QPushButton::disabled{border-image: url(%1) 0  0 0 %5 repeat  repeat;border-width: 0px; border-radius: 0px;}")
                          .arg(imgsrc).arg(0).arg(PicWidth*1).arg(width_2).arg(width_3));
}

/**
 * @brief SetButtonStyle 设置button 渐变
 * @param button
 * @param imgsrc
 * @param CutSec
 */
void CGlobalSetting::SetButtonColorStyleB(QPushButton *button, QString imgsrc, int CutSec)
{
    Q_UNUSED(imgsrc)
    Q_UNUSED(CutSec)
    QString color_bg_1 = "";
    QString color_bg_2 = "";
    QString color_bg_3 = "";
    QString color_bg_border = "";
    QString color_hover_1 = "";
    QString color_hover_2 = "";
    QString color_hover_3 = "";
    QString color_hover_border = "";
    QString color_pressed_1 = "";
    QString color_pressed_2 = "";
    QString color_pressed_3 = "";
    QString color_pressed_border = "";
    QString color_disabled = "";
    QString color_disabled_border = "";
    button->setStyleSheet(QString("QPushButton{background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #%1, stop: 0.5 #%2,stop: 1.0 #%3);")
      .append("border-style: outset;border-width: 1px;border-radius: 5px;border-color: #%4;padding: 1px;}")
      .append("QPushButton::hover{background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #%5, stop: 0.5 #%6,stop: 1.0 #%7);border-color: #%8;}")
       .append("QPushButton::pressed{background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #%9, stop: 0.5 #%10,stop: 1.0 #%11);border-color: #%12;}")
      .append("QPushButton::checked{background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #%9, stop: 0.5 #%10,stop: 1.0 #%11);border-color: #%12;}")
      .append("QPushButton::disabled{background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #%13, stop: 0.5 #%13,stop: 1.0 #%13);border-color: #%16;}")
      .arg(color_bg_1).arg(color_bg_2).arg(color_bg_3).arg(color_bg_border)
      .arg(color_hover_1).arg(color_hover_2).arg(color_hover_3).arg(color_hover_border)
      .arg(color_pressed_1).arg(color_pressed_2).arg(color_pressed_3).arg(color_pressed_border)
      .arg(color_disabled).arg(color_disabled_border));
}


/**
 * @brief SetButtonStyle 设置button 渐变
 * @param button
 * @param imgsrc
 * @param CutSec
 */
void CGlobalSetting::SetButtonColorStyleA(QPushButton *button, QString color_bg, QString color_h, QString color_press, QString color_check, QString appendstyle)
{
    QString stylestr="";

    button->setStyleSheet(stylestr);
}

/**
 * @brief SetWidgetColorStyle 设置 widget 渐变
 * @param widget
 * @param imgsrc
 * @param CutSec
 */
void CGlobalSetting::SetWidgetColorStyle(QPushButton *widget, QString colors)
{
    QString color_bg_1 = "ffffbb";
    QString color_bg_2 = "ffffbb";
    QString color_bg_3 = "ffffbb";
    QString color_bg_border = "444555";
    QString color_hover_1 = "555555";
    QString color_hover_2 = "666666";
    QString color_hover_3 = "777777";
    QString color_hover_border = "888888";
    QString color_pressed_1 = "999999";
    QString color_pressed_2 = "000000";
    QString color_pressed_3 = "aaaaaa";
    QString color_pressed_border = "bbbbbb";
    QString color_disabled = "cccccc";
    QString color_disabled_border = "dddddd";
    widget->setStyleSheet(QString("QPushButton#mybuttonlist{background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #%1, stop: 0.5 #%2,stop: 1.0 #%3);")
      .append("border-style: outset;border-width: 0px;border-radius: 0px;border-color: #%4;padding: 1px;}")
      .append("QPushButton#mybuttonlist::hover{background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #%5, stop: 0.5 #%6,stop: 1.0 #%7);border-color: #%8;}")
       .append("QPushButton#mybuttonlist::pressed{background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #%9, stop: 0.5 #%10,stop: 1.0 #%11);border-color: #%12;}")
      .append("QPushButton#mybuttonlist::checked{background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #%9, stop: 0.5 #%10,stop: 1.0 #%11);border-color: #%12;}")
      .append("QPushButton#mybuttonlist::disabled{background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,stop: 0 #%13, stop: 0.5 #%13,stop: 1.0 #%13);border-color: #%16;}")
      .arg(color_bg_1).arg(color_bg_2).arg(color_bg_3).arg(color_bg_border)
      .arg(color_hover_1).arg(color_hover_2).arg(color_hover_3).arg(color_hover_border)
      .arg(color_pressed_1).arg(color_pressed_2).arg(color_pressed_3).arg(color_pressed_border)
      .arg(color_disabled).arg(color_disabled_border));
}
#include <QDebug>
/**
 * @brief GetIPMAC
 * 获取主机IP 和 MAC
 * @return
 */
QString CGlobalSetting::GetIPMAC()
{
     QString ipmac;
     QNetworkInterface  localInterface;
     QList<QNetworkInterface>  iterfaces = localInterface.allInterfaces();
     qDebug() << "getip:mac" << iterfaces.size();
     for(int i=0;i<iterfaces.size(); i++)
     {
         QNetworkInterface iterface = (QNetworkInterface)iterfaces.at(i);
         int size = iterface.addressEntries().size();
         qDebug() << "iterface.addressEntries().size():" << size;
         for(int j=0;j<size;j++)
         {
             qDebug() << iterface.addressEntries().at(j).ip().toString();
             qDebug() << iterface.hardwareAddress();
             if(!iterface.addressEntries().at(j).ip().isNull() && iterface.addressEntries().at(j).ip().protocol() == QAbstractSocket::IPv4Protocol
                     && iterface.addressEntries().at(j).ip() != QHostAddress::LocalHost)
             {
                 ipmac.append(iterface.addressEntries().at(j).ip().toString());
                 ipmac.append("#");
                 ipmac.append(iterface.hardwareAddress());
                 if(iterface.hardwareAddress() != "" && iterface.addressEntries().at(j).ip().toString() != "")
                 {
                     qDebug() << "IP:" << iterface.addressEntries().at(j).ip().toString();
                     qDebug() << "MAC:" << iterface.hardwareAddress();
                     goto loop;
                 }
                 else
                 {
                     qDebug() << "CLEAR IP:" << iterface.addressEntries().at(j).ip().toString();
                     qDebug() << "CLEAR MAC:" << iterface.hardwareAddress();
                     ipmac.clear();
                 }
             }
         }
         loop:
            break;
     }
    qDebug() << "ip:mac" << ipmac;

    //拨号上网的时候获取IP,MAC失败,特殊处理
    if(ipmac == "" || !ipmac.contains("#"))
    {
        ipmac= "#";
    }
    return ipmac;
}


/**
 * @brief GetCpuId
 * 获取CPU的ID信息
 * @return CPUID
 */

QString CGlobalSetting::GetCpuId()
{
//     unsigned long s1,s2,s3,s4;
//     char szCpuId[1024];
//     char p1[128], p2[128];
//     unsigned int eax,ebx,ecx,edx;
     QString strCPUID;

//     __asm {
//         mov     ecx, ShiftCount
//         mov     eax, dword ptr [Value]
//         mov     edx, dword ptr [Value+4]
//         shld    edx, eax, cl
//         shl     eax, cl
//     }

//     asm volatile
//     (
//         "cpuid"
//         : "=a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx)
//         : "0"(0)
//     );
//     _snprintf(szCpuId, 5, "%s", (char *)&ebx);
//     _snprintf(szCpuId+4, 5, "%s", (char *)&edx);
//     _snprintf(szCpuId+8, 5, "%s", (char *)&ecx);

//     asm volatile
//     (
//         "movl $0x01 , %%eax ; \n\t"
//         "xorl %%edx , %%edx ;\n\t"
//         "cpuid ;\n\t"
//         "movl %%edx ,%0 ;\n\t"
//         "movl %%eax ,%1 ; \n\t"
//         :"=m"(s1),"=m"(s2)
//     );

//     char cpuID[20];
//     memset(cpuID,0,20);
//     sprintf((char *)p1, "%08X%08X", s1, s2);
//     _snprintf(szCpuId+12, 20, "%s", (char *)p1);
//     memcpy(cpuID,p1,17);
//     strCPUID = strCPUID.fromAscii(cpuID);
//     asm volatile
//     (
//         "movl $0x03,%%eax ;\n\t"
//         "xorl %%ecx,%%ecx ;\n\t"
//         "xorl %%edx,%%edx ;\n\t"
//         "cpuid ;\n\t"
//         "movl %%edx,%0 ;\n\t"
//         "movl %%ecx,%1 ;\n\t"
//         :"=m"(s3),"=m"(s4)
//     );

//     sprintf((char *)p2, "%08X-%08X\n", s3, s4);
//     _snprintf(szCpuId+31, 19, "%s", (char *)p2);
     return strCPUID;
}

#include <windows.h>
/**
 * @brief GetDiskNum
 * 获取硬盘编号
 * @return
 */
//QString CGlobalSetting::GetDiskNum()
//{
//    QString lpRootPathName = "C:\\";
//    TCHAR *tt = new TCHAR[12];//磁盘卷标
//    LPTSTR lpVolumeNameBuffer=(LPTSTR)(tt);
//    DWORD nVolumeNameSize=12;// 卷标的字符串长度
//    DWORD VolumeSerialNumber;//硬盘序列号
//    DWORD MaximumComponentLength;// 最大的文件长度
//    TCHAR *tt2 = new TCHAR[12];//存储所在盘符的分区类型的长指针变量
//    LPTSTR lpFileSystemNameBuffer=(LPTSTR)(tt2);// 存储所在盘符的分区类型的长指针变量
//    DWORD nFileSystemNameSize=10;// 分区类型的长指针变量所指向的字符串长度
//    DWORD FileSystemFlags;// 文件系统的一此标志

//    GetVolumeInformation((LPTSTR)lpRootPathName.utf16(),
//    lpVolumeNameBuffer, nVolumeNameSize,
//    &VolumeSerialNumber, &MaximumComponentLength,
//    &FileSystemFlags,
//    lpFileSystemNameBuffer, nFileSystemNameSize);
//    return QString("%1").arg(VolumeSerialNumber);
//}
/**
 * @brief GetItemImgPath 获取图片路径
 *
 * @return 图片路径
 */
QString CGlobalSetting::GetItemImgPath(QString dir_append, QString imgname)
{

   // QString path = QDesktopServices::storageLocation(QDesktopServices::ApplicationsLocation).append("/resources/").append(dir_append).append("/").append(imgname);
    QString path = QCoreApplication::applicationDirPath().append("/resources/").append(dir_append).append("/").append(imgname);

    while(path.contains("\\"))
    {
            path = path.replace("\\", "/");
    }
    while(path.contains("//"))
    {
            path = path.replace("//", "/");
    }
    return path;
}


void CGlobalSetting::Sleep(unsigned int msec)
{
    Q_UNUSED(msec)
    QTime dieTime = QTime::currentTime().addMSecs(100);

    while( QTime::currentTime() < dieTime )

    QCoreApplication::processEvents(QEventLoop::AllEvents, 100);

}

/**
 * @brief readConfigValueByFileName 读ini文件
 * @param filename
 * @param group
 * @param key
 * @return
 */
QString CGlobalSetting::readConfigValueByFileName(QString filename, QString group, QString key)
{
    QSettings settings(filename, QSettings::IniFormat); // 当前目录的INI文件
    settings.beginGroup(group);
    QString value = settings.value(key).toString();
    settings.endGroup();
    return value;
}

QString CGlobalSetting::readConfigValueByFileAndUser(QString filename, QString key, bool isGuest)
{
    QSettings settings(filename, QSettings::IniFormat); // 当前目录的INI文件
    settings.beginGroup("NETWORKS");
    QString value = settings.value(key).toString();
    settings.endGroup();




   // qDebug() << "readConfigValueByFileAndUser" << isGuest << value << key;
    return value;
}



/**
 * @brief JMainWindow::runExeProcess 开启更新进程
 * @param localVersion
 * @param isHidden
 */
void CGlobalSetting::runExeProcess(QString localVersion, int isHidden)
{
    QString  updateurl = readConfigValueByFileName(UPDATE_FILE,"version","UPDATEURL");
    if(QString(updateurl) == "")
    {
        updateurl = "http://122.226.95.28:8082/";
    }
    //updateurl = "http://127.0.0.1:8080/";

    QString upUrl1 = QString("%1/update.txt").arg(updateurl);
    QProcess *proc = new QProcess;
    QString strExe = "JUpdate.exe";
    QStringList arguments;
    arguments << localVersion;
    arguments << upUrl1;
    arguments << upUrl1;
    arguments << FileExeName;
    arguments << "";
    arguments << QString("%1").arg(isHidden);
    proc->start(strExe, arguments);
    qDebug() << arguments;
    // 等待进程启动
    if (!proc->waitForStarted())
    {
    }

}



/*删除文件夹内容,不删除该文件夹本身
//入口参数:const QString &dirName---------------------文件夹全路径
//出口参数:无
//返回值:true----删除成功;false----文件夹不存在
//备注:无*/
bool CGlobalSetting::DeleteDirectory(const QString &folderDir)
{
    QString folderDir2 = folderDir;
    folderDir2 = folderDir2.replace('\\',"/");

    if(folderDir2 == "" || folderDir2 == "." || folderDir2 == "./")
    {
        return false;
    }
    QDir dir(folderDir2);
    QFileInfoList fileList;
    QFileInfo curFile;
    if(!dir.exists())
    {
        return false;
    }
    fileList=dir.entryInfoList(QDir::Dirs|QDir::Files
                               |QDir::Readable|QDir::Writable
                               |QDir::Hidden|QDir::NoDotAndDotDot
                               ,QDir::Name);
    while(fileList.size()>0)
    {
        int infoNum=fileList.size();
        for(int i=infoNum-1;i>=0;i--)
        {
            curFile=fileList[i];
            if(curFile.isFile())//如果是文件,删除文件
            {
                QFile fileTemp(curFile.filePath());
                fileTemp.remove();
                fileList.removeAt(i);
            }
            if(curFile.isDir())//如果是文件夹
            {
                QDir dirTemp(curFile.filePath());
                QFileInfoList fileList1=dirTemp.entryInfoList(QDir::Dirs|QDir::Files
                                                              |QDir::Readable|QDir::Writable
                                                              |QDir::Hidden|QDir::NoDotAndDotDot
                                                              ,QDir::Name);
                if(fileList1.size()==0)//下层没有文件或文件夹
                {
                    dirTemp.rmdir(".");
                    fileList.removeAt(i);
                }
                else
                {
                    for(int j=0;j<fileList1.size();j++)
                    {
                        if(!(fileList.contains(fileList1[j])))
                            fileList.append(fileList1[j]);
                    }
                }
            }
        }
    }
   return true;
}


/**
 * @brief isCheckLength
 * @param htmlContent html格式的内容
 * @return 返回验证后的字符长度
 */
int CGlobalSetting::isCheckLength(QString htmlContent)
{
    QString szAddress = htmlContent;
    int size = 0;
    int nLen = 0;
    int offset = 0;
    while (1) {
        size = szAddress.size();
        offset = szAddress.indexOf("<img");
        if (offset != -1) {
            szAddress = szAddress.mid(offset+4, size-offset);
            nLen++;
            continue;
        }

        break;
    }
    szAddress = htmlContent;
    QString strTmp = "";
    while (1) {
        size = szAddress.size();
        offset = szAddress.indexOf(">");
        if (offset != -1) {
            int n = szAddress.indexOf("<", offset);
            if (n != -1) {
                if (n - (offset+1) != 0) {
                    strTmp += szAddress.mid(offset+1, n-offset-1);
                }
                szAddress = szAddress.mid(n+1, size-n);
                continue;
            } else {
                szAddress = szAddress.mid(offset+1, size-offset);
            }
        }

        break;
    }

    nLen = nLen*2 + strTmp.trimmed().size();
   // qDebug() << "nLen 1111111111111111111111111111111111111111111111111111" << nLen << strTmp.trimmed() << strTmp.trimmed().size();
    return nLen;
}


/**
 * @brief wcharTochar
 * @param wchar
 * @param chr
 * @param length
 * @details wchat_t 转换char*
 */
void CGlobalSetting::wcharTochar(const wchar_t *wchar, char *chr, int length)
{
    WideCharToMultiByte( CP_ACP, 0, wchar, -1,
        chr, length, NULL, NULL );
}

/**
 * @brief GetProcessidFromName
 * @param szProcessName 程序名
 * @return 返回进程ID
 * @details  检查当前程序是否正在运行,0:没有进程运行
 */
//DWORD CGlobalSetting::GetProcessidFromName(const char *szProcessName)
//{
//    PROCESSENTRY32 pe;
//    DWORD id = 0;
//    HANDLE hSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
//    pe.dwSize=sizeof(PROCESSENTRY32);
//    if(!Process32First(hSnapshot,&pe))
//        return 0;
//    while(1)
//    {
//        pe.dwSize=sizeof(PROCESSENTRY32);
//        if(Process32Next(hSnapshot,&pe)==FALSE)
//            break;
//        char chr[256];
//        memset(chr, 256, 0);
//        wcharTochar(pe.szExeFile, chr, sizeof(chr));
//        if(strcmp(chr,szProcessName)== 0)
//        {
//            id=pe.th32ProcessID;
//            break;
//        }
//    }
//    CloseHandle(hSnapshot);
//    return id;
//}

/**
 * @brief GetProcessCountFromName
 * @param szProcessName
 * @return
 * @detials  当前进程个数
 */
//int CGlobalSetting::GetProcessCountFromName(const char *szProcessName)
//{
//    int nPorcessCount = 0;
//    PROCESSENTRY32 pe;
//    HANDLE hSnapshot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
//    pe.dwSize=sizeof(PROCESSENTRY32);
//    if(!Process32First(hSnapshot,&pe))
//        return 0;
//    while(1)
//    {
//        pe.dwSize=sizeof(PROCESSENTRY32);
//        if(Process32Next(hSnapshot,&pe)==FALSE)
//            break;
//        char chr[256];
//        memset(chr, 256, 0);
//        wcharTochar(pe.szExeFile, chr, sizeof(chr));
//        if(strcmp(chr,szProcessName)== 0)
//        {
//           nPorcessCount++;
//        }
//    }
//    CloseHandle(hSnapshot);
//    return nPorcessCount;
//}