#include "GlobalSetting.h" #include "GlobalSettingDefine.h" #include "sqliteutil.h" #include #include #include #include #include #include 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 /** * @brief GetIPMAC * 获取主机IP 和 MAC * @return */ QString CGlobalSetting::GetIPMAC() { QString ipmac; QNetworkInterface localInterface; QList iterfaces = localInterface.allInterfaces(); qDebug() << "getip:mac" << iterfaces.size(); for(int i=0;i /** * @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"); 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; //}