#include "mconverter.h" #include "loappconfig.h" #include "wProgramManager/wEditProgram/wElement/etext.h" #include "wProgramManager/wEditProgram/wElement/ephoto.h" #include "wProgramManager/wEditProgram/wElement/emovie.h" #include "wProgramManager/wEditProgram/wElement/egif.h" #include "wProgramManager/wEditProgram/wElement/edclock.h" #include "wProgramManager/wEditProgram/wElement/eaclock.h" #include "wProgramManager/wEditProgram/wElement/etemp.h" #include "wProgramManager/wEditProgram/wElement/eweather.h" #include "wProgramManager/wEditProgram/wElement/etimer.h" #include #include //转换为控制卡播放的项目文件类 mConverter::mConverter(const QString &name,const QString &strPath,const QString &strPassword, QObject *parent) : QThread(parent), m_nProg(name) { m_nConv = m_nProg + "_tmp"; m_strProgramItemPath = LoAppConfig::getInstance()->NProgramsLocation(); //原始节目保存的路径 m_pProg = m_strProgramItemPath + MACRO_FENGEFU + m_nProg; m_pZipProg=strPath + MACRO_FENGEFU + "program"; //m_pConv = m_strProgramItemPath + MACRO_FENGEFU + m_nConv; //转换后的路径,转换设定路径+节目名称+_tmp m_pConv = m_strProgramItemPath + MACRO_FENGEFU + m_nConv; m_resId = 0; m_strPassword=strPassword; } void mConverter::run() { qDebug() << "CopyResource拷贝素材资源到控制卡需要的节目任务对应的目录下"; cpyResource(); qDebug() << "genPackage 生成控制卡需要的节目任务文件" ; genPackage(); if(m_usbZipFlag==1)//如果是usb更新则生成压缩包,网络发送则不需要 { qDebug() << "zipPackage" ; zipPackage(); } qDebug() << "mConverter end" ; } //拷贝资源 void mConverter::cpyResource() { emit sProgress(tr("Preparing ..."), 0); QDir dRoot(m_strProgramItemPath); QDir dConv(m_pConv); if(dConv.exists()) { if(dConv.removeRecursively()) { int iReTryCount=0; while(!dRoot.mkdir(m_nConv)) { QThread::sleep(1); iReTryCount++; if(iReTryCount>10) break; } } } else { int iReTryCount=0; while(!dRoot.mkdir(m_nConv)) { QThread::sleep(1); iReTryCount++; if(iReTryCount>10) break; } } QString conv = m_nConv + ".zip"; if(dRoot.exists(conv)) { if(dRoot.remove(conv)) { } } emit sProgress(tr("Organizing resources ..."), 10); qDebug() << "emit sProgress 10"; QDir dProg(m_pProg); QStringList pageList = dProg.entryList(QDir::Dirs | QDir::NoDotAndDotDot); foreach(QString page, pageList) { QString strtemp1=m_pProg + MACRO_FENGEFU + page; m_strCurPagePath=strtemp1.replace(MACRO_DANYINFANXIEGAN, MACRO_DANYINXIEGAN); QDir dPage(m_strCurPagePath); QStringList resList = dPage.entryList(QDir::Files); QDir dprogram(m_pConv + MACRO_FENGEFU + page ); if(dprogram.exists()) dprogram.removeRecursively(); foreach(QString res, resList) { if(!dConv.exists(res) && QFileInfo(res).suffix() != "json") { QString pSrc(m_strCurPagePath + MACRO_FENGEFU + res); QFileInfo fileinfo; fileinfo = QFileInfo(pSrc); QDir dConv(m_pConv); if(!dprogram.exists()) { int iReTryCount=0; while(!dConv.mkdir(page)) { QThread::sleep(1); iReTryCount++; if(iReTryCount>10) break; } } //QString pTar(m_pConv + MACRO_FENGEFU + page + MACRO_FENGEFU + calcFilePathNameStringCRC(pSrc.replace(MACRO_DANYINFANXIEGAN, MACRO_DANYINXIEGAN))+"."+fileinfo.suffix()); QString file_full=pSrc.replace(MACRO_DANYINFANXIEGAN, MACRO_DANYINXIEGAN); QString strFileMD5=getFileMd5(file_full); //QString pTar(m_pConv + MACRO_FENGEFU + page + MACRO_FENGEFU + strFileMD5+"."+fileinfo.suffix()); QString pTar(m_pConv + MACRO_FENGEFU + page + MACRO_FENGEFU + strFileMD5); if(pSrc.right(3)=="jpg"||pSrc.right(4)=="jpeg"||pSrc.right(3)=="bmp"||pSrc.right(3)=="png") { if(fileinfo.fileName().length()>8) { if(fileinfo.fileName().left(8)=="yuanshi_") { } else { QFile::copy(pSrc, pTar); } } else { QFile::copy(pSrc, pTar); } } else { QFile::copy(pSrc, pTar); } } } if(!dprogram.exists()) { int iReTryCount=0; while(!dConv.mkdir(page)) { QThread::sleep(1); iReTryCount++; if(iReTryCount>10) break; } } foreach(QString subDir, dPage.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) { //若存在子目录,则递归调用dirFileSize()函数 QString strSubFullPath=m_strCurPagePath + QDir::separator() + subDir; QString strDestFullPath=m_pConv + MACRO_FENGEFU + page + MACRO_FENGEFU; cpySubResource(strSubFullPath,strDestFullPath); } } } void mConverter::cpySubResource(QString strSourceDir,QString strDestDir) { QDir dPage(strSourceDir); QStringList resList = dPage.entryList(QDir::Files); foreach(QString res, resList) { QString pSrc(strSourceDir + MACRO_FENGEFU + res); QFileInfo fileinfo; fileinfo = QFileInfo(pSrc); QString file_full=pSrc.replace(MACRO_DANYINFANXIEGAN, MACRO_DANYINXIEGAN); QString strFileMD5=getFileMd5(file_full); //QString pTar(m_pConv + MACRO_FENGEFU + page + MACRO_FENGEFU + strFileMD5+"."+fileinfo.suffix()); QString pTar(strDestDir + MACRO_FENGEFU + strFileMD5); //QString pTar(strDestDir + MACRO_FENGEFU + strFileMD5+".png"); QFile::copy(pSrc, pTar); } } #include "QJsonValuePtr" //生产包 void mConverter::genPackage() { emit sProgress(tr("Create json ..."), 20); qDebug() << "emit sProgress 20"; QJsonObject oRoot; QJsonObject oCommand; oCommand["_type"] = "PlayXixunTask"; oCommand["id"] = newUuid(); oCommand["preDownloadURL"] = "http://192.168.8.202:23412/file/download?id="; oCommand["notificationURL"] = "http://192.168.8.202:23412/test"; QJsonObject oTask; oTask["_id"] = newUuid(); oTask["name"] = m_nProg; QString aa=nullptr; // QJsonValuePtr aa=nullptr; oTask["_department"] = QJsonValue::Null; // oTask["executeDate"] = QJsonValue::Null;; oTask["cmdId"] = newUuid(); oTask["items"] = scanProg(); oCommand["task"] = oTask; oRoot["command"] = oCommand; // m_jProg.setObject(oRoot); m_jProg.setObject(oCommand); //QFile f(m_pConv + "\\program.json"); QFile f(m_pConv + "\\program"); if(f.open(QIODevice::WriteOnly)) { f.write(m_jProg.toJson()); f.close(); } } //压缩为zip包 //void mConverter::zipPackage() //{ // auto p = new QProcess(); // QString cmd = QString("zip -r \"%1.zip\" \".\\*\"").arg(m_pProg); //#if defined(Q_OS_WIN32) // qDebug() << "cmd.replace('\\', '/':)"<setWorkingDirectory(m_pConv); // p->start(cmd); // qDebug() << cmd; // p->waitForFinished(-1); //// qDebug() << QString::fromLocal8Bit(p->readAllStandardOutput()); // delete p; // QDir dConv(m_pConv); // qDebug() << m_pConv; // // dConv.removeRecursively(); // emit sProgress(tr("Zipped program ..."), 40, true); // qDebug() << "zipPackage end"; //} void mConverter::zipPackage() { #if defined(Q_OS_WIN32) #endif //// qDebug() << QString::fromLocal8Bit(p->readAllStandardOutput()); // QDir dConv(m_pConv); // qDebug() << m_pConv; // // dConv.removeRecursively(); // emit sProgress(tr("Zipped program ..."), 40); // JlCompress::compressDir(m_pProg+".zip", m_pConv); // // compressDirByPassword(m_pProg+".zip",m_pConv,m_strPassword); // emit sProgress(tr("Zipped finished ..."), 50); // //转换并压缩完毕后,删除xxx_tmp的文件夹 // dConv.removeRecursively(); // emit sProgress(tr("delete tmp dir ..."), 100); // qDebug() << "zipPackage end"; compressDirByPassword(m_pZipProg+".zip",m_pConv,m_strPassword); } //压缩有问题,该函数仍未完成 void mConverter::compressDirByPassword(QString strZipFileName,QString strSrcDir,QString strPassword) { const QString& zipName=strZipFileName; QuaZip zip(zipName); if (!zip.open(QuaZip::mdCreate)) { qDebug("Could not create zip: %s", qPrintable(zipName)); return; } AddDirToZipFile(strSrcDir,&zip,strSrcDir,strPassword); zip.close(); } void mConverter::AddDirToZipFile(const QString &path,QuaZip *pZip,QString strRoot,QString strPassword) { QDir dir(path); //qint64 size = 0; //dir.entryInfoList(QDir::Files)返回文件信息 foreach(QFileInfo fileInfo, dir.entryInfoList(QDir::Files)) { //计算文件大小 //size += fileInfo.size(); QString strFilePath=fileInfo.filePath(); QString strNewInfoInZip=fileInfo.fileName();//strFilePath.right(strFilePath.length()-strRoot.length()-1); AddFileToZipFile(strFilePath,strNewInfoInZip,pZip,strPassword); } //dir.entryList(QDir::Dirs|QDir::NoDotAndDotDot)返回所有子目录,并进行过滤 foreach(QString subDir, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) { //若存在子目录,则递归调用dirFileSize()函数 AddDirToZipFile(path + QDir::separator() + subDir,pZip,strRoot,strPassword); } return ; } void mConverter::AddFileToZipFile(const QString &strFile,QString strNewInfoInZip,QuaZip *pZip,QString strPassword) { QuaZipNewInfo newInfo(strNewInfoInZip); QuaZipFile file(pZip); bool ret = file.open(QIODevice::WriteOnly, newInfo, // QuaZipNewInfo结构体引用 strPassword.toUtf8().constData(), // 密码 0, // CRC值(默认值是0) 0); // 写入方法(0为文件夹,8为普通文件) if (ret) { //QFile file2(m_pConv+"/pro.json"); QFile file2(strFile); bool isopen = file2.open(QIODevice::ReadOnly); if (isopen) { // 开始写入文件的数据了 file.write(file2.readAll()); } file2.close(); file.close(); } } //alahover扫描节目,返回多个节目数组QJsonArray QJsonArray mConverter::scanProg() { /////////////////////////////////// emit sProgress(tr("Scan program ..."), 30); qDebug() << "emit sProgress 30"; QJsonArray oItems; QDir dProg(m_pProg); QList jPageList; QStringList pageList = dProg.entryList(QDir::Dirs | QDir::NoDotAndDotDot); //需要 查询 order 属性, 将最上层的放在转换后layers 的 最前面 //一个page.json 对应节目任务中的一个 items里的program foreach(QString page, pageList) { QString pJson =m_pProg+MACRO_FENGEFU+ page + "\\page.json"; QFile fJson(pJson); if(fJson.open(QIODevice::ReadOnly)){ QJsonDocument jPage = QJsonDocument::fromJson(fJson.readAll()); fJson.close(); jPageList.append(jPage); } } //根据order排序,这里是对节目放在items中的排序 ,是节目的排序 std::sort(jPageList.begin(), jPageList.end(), [](const QJsonDocument &a, const QJsonDocument &b) { return a["order"].toInt() < b["order"].toInt(); }); QJsonArray oLayers; foreach(QJsonDocument jPage, jPageList) { QString strtemp1=m_pProg + MACRO_FENGEFU + jPage["name"].toString(); m_strCurPagePath=strtemp1.replace(MACRO_DANYINFANXIEGAN, MACRO_DANYINXIEGAN); oItems.append(genProgramJson(jPage)); } return oItems; ////////////////////////////// // emit sProgress(tr("Scan program ..."), 30); // qDebug() << "emit sProgress 30"; // QJsonArray oItems; // oItems.append(genProgJson(m_pProg)); // return oItems; } //alahover根据pro.json生成节目任务json QJsonObject mConverter::genProgramJson(const QJsonDocument &jPage) { QJsonObject oItem, oProgram; oItem["_id"] = newUuid(); oItem["priority"] = 0; // oItem["repeatTimes"] = 1; oItem["version"] = 0; /////////////////////////////////////////// QJsonArray oPlanArray; if(jPage["plans"].toArray().count()<=0) { QJsonObject oXixunSchedule; if(jPage["validDate"]["isValid"].toBool()) { oXixunSchedule["dateType"]="Range"; oXixunSchedule["startDate"]=jPage["validDate"]["start"].toString(); oXixunSchedule["endDate"]=jPage["validDate"]["end"].toString(); oXixunSchedule["timeType"]="All"; oXixunSchedule["startTime"]=QJsonValue::Null; oXixunSchedule["endTime"]=QJsonValue::Null; oXixunSchedule["filterType"]="None"; oXixunSchedule["monthFilter"]=QJsonArray(); oXixunSchedule["weekFilter"]=QJsonArray(); oPlanArray.append(oXixunSchedule); } else { // oXixunSchedule["dateType"]="All"; // oXixunSchedule["startDate"]=QJsonValue::Null;; // oXixunSchedule["endDate"]=QJsonValue::Null;; // oXixunSchedule["timeType"]="All"; // oXixunSchedule["filterType"]="None"; // oXixunSchedule["monthFilter"]=QJsonArray(); // oXixunSchedule["weekFilter"]=QJsonArray(); } } else { foreach(QJsonValue value, jPage["plans"].toArray()) { QJsonObject oPlan = value.toObject(); QJsonObject oXixunSchedule; if(jPage["validDate"]["isValid"].toBool()) { oXixunSchedule["dateType"]="Range"; oXixunSchedule["startDate"]=jPage["validDate"]["start"].toString(); oXixunSchedule["endDate"]=jPage["validDate"]["end"].toString(); oXixunSchedule["timeType"]="Range"; oXixunSchedule["startTime"]=oPlan["start"]; oXixunSchedule["endTime"]=oPlan["end"]; oXixunSchedule["weekFilter"]=oPlan["weekly"]; QJsonArray oWeekly=oPlan["weekly"].toArray(); if(oWeekly.count()<=0) oXixunSchedule["filterType"]="None"; else { oXixunSchedule["filterType"]="Week"; } oXixunSchedule["monthFilter"]=QJsonArray(); } else { oXixunSchedule["dateType"]="All"; oXixunSchedule["startDate"]=QJsonValue::Null; oXixunSchedule["endDate"]=QJsonValue::Null; oXixunSchedule["timeType"]="Range"; oXixunSchedule["startTime"]=oPlan["start"]; oXixunSchedule["endTime"]=oPlan["end"]; oXixunSchedule["weekFilter"]=oPlan["weekly"]; QJsonArray oWeekly=oPlan["weekly"].toArray(); if(oWeekly.count()<=0) oXixunSchedule["filterType"]="None"; else { oXixunSchedule["filterType"]="Week"; } oXixunSchedule["monthFilter"]=QJsonArray(); } oPlanArray.append(oXixunSchedule); } } oItem["schedules"] = oPlanArray; //////////////////////////// oProgram["_id"] = newUuid(); oProgram["totalSize"] = 0; oProgram["name"] = jPage["name"]; oProgram["width"] = jPage["resolution"]["w"]; oProgram["height"] = jPage["resolution"]["h"]; oProgram["_company"] = "alahover"; oProgram["_department"] = "alahover"; oProgram["_role"] = "alahover"; oProgram["_user"] = "alahover"; oProgram["__v"] = 0; // QString dateCreated = QDateTime::fromString(jProg["last_edit"].toString(), "yyyy-MM-dd hh:mm:ss").toString("yyyy-MM-ddThh:mm:ss"); QString dateCreated = jPage["last_edit"].toString(); oProgram["dateCreated"] = dateCreated; oProgram["layers"] = genLayerJson(jPage); oItem["_program"] = oProgram; oItem["repeatTimes"] = jPage["repeat"].toInt(); return oItem; } //alahover生成多节目页json,键值layers QJsonArray mConverter::genLayerJson(const QJsonDocument &jPage) { QJsonArray LayerArray; //此处需要把一个幻灯片中的元素 按层顺序进行一个排序, 排序后 再放入layers中,每个 元素对一个一个layer。 ewindow中的多个顺序元素为一个层上的时间轴上的素材, QList elementList; foreach(QJsonValue value, jPage["elements"].toArray()) { QJsonObject oElement = value.toObject(); elementList.append(oElement); } std::sort(elementList.begin(), elementList.end(), [](const QJsonObject &a, const QJsonObject &b) { return a["geometry"]["order"].toInt() > b["geometry"]["order"].toInt(); }); foreach(QJsonObject oElement, elementList) { QJsonArray oSourceArray; QJsonArray oSourceObjects; QJsonObject oSourceObject; QJsonObject oPage; oPage["repeat"] = false; switch (oElement["elementTypeId"].toInt()) { case eObject::Text : oSourceObject=convertText(oElement); oSourceObject["playTime"]=0; oSourceObjects.append(oSourceObject); oPage["sources"] = oSourceObjects; break; case eObject::Photo : oSourceObject=convertPhoto(oElement); if(!oSourceObject.isEmpty()) { oSourceObject["playTime"]=0; oSourceObjects.append(oSourceObject); oPage["sources"] = oSourceObjects; } break; case eObject::Movie : oSourceObject=convertMovie(oElement); if(!oSourceObject.isEmpty()) { oSourceObject["playTime"]=0; oSourceObjects.append(oSourceObject); oPage["sources"] = oSourceObjects; break; } case eObject::Gif : oSourceObject=convertGif(oElement); oSourceObject["playTime"]=0; oSourceObjects.append(oSourceObject); oPage["sources"] = oSourceObjects; break; case eObject::DClock : oSourceObject=convertDClockNew(oElement); oSourceObject["playTime"]=0; oSourceObjects.append(oSourceObject); oPage["sources"] = oSourceObjects; break; case eObject::AClock : oSourceObject=convertAClock(oElement); oSourceObject["playTime"]=0; oSourceObjects.append(oSourceObject); oPage["sources"] = oSourceObjects; break; case eObject::Office : oSourceObject=convertOffice(oElement); oSourceObject["playTime"]=0; oSourceObjects.append(oSourceObject); oPage["sources"] = oSourceObjects; break; case eObject::Temp : oSourceObject=convertTemp(oElement); oSourceObject["playTime"]=0; oSourceObjects.append(oSourceObject); oPage["sources"] = oSourceObjects; break; case eObject::Weather : oSourceObject=convertWeather(oElement); oSourceObject["playTime"]=0; oSourceObjects.append(oSourceObject); oPage["sources"] = oSourceObjects; break; case eObject::Rss : oSourceObject=convertRss(oElement); oSourceObject["playTime"]=0; oSourceObjects.append(oSourceObject); oPage["sources"] = oSourceObjects; break; case eObject::Timer : oSourceObject=convertTimer(oElement); oSourceObject["playTime"]=0; oSourceObjects.append(oSourceObject); oPage["sources"] = oSourceObjects; break; case eObject::ColorText : oSourceObject=convertColorText(oElement);oSourceObject["playTime"]=0; oSourceObjects.append(oSourceObject); oPage["sources"] = oSourceObjects; break; case eObject::Window : oSourceObject=convertWindow(oElement,oSourceArray); oPage["sources"] = oSourceArray; break; default: break; } if(!oSourceObject.isEmpty()) LayerArray.append(oPage); } return LayerArray; } //根据pro.json生成节目任务json QJsonObject mConverter::genProgJson(const QString &pProg) { QJsonObject oItem, oProgram; QString pJson = pProg + "\\pro.json"; QFile fJson(pJson); if(fJson.open(QIODevice::ReadOnly)){ QJsonDocument jProg = QJsonDocument::fromJson(fJson.readAll()); oItem["_id"] = newUuid(); oItem["priority"] = 0; // oItem["repeatTimes"] = jProg[""]; oItem["version"] = 0; oItem["schedules"] = QJsonArray(); //////////////////////////// oProgram["_id"] = newUuid(); oProgram["totalSize"] = 0; oProgram["name"] = jProg["name"]; oProgram["width"] = jProg["resolution"]["w"]; oProgram["height"] = jProg["resolution"]["h"]; oProgram["_company"] = "alahover"; oProgram["_department"] = "alahover"; oProgram["_role"] = "alahover"; oProgram["_user"] = "alahover"; oProgram["__v"] = 0; // QString dateCreated = QDateTime::fromString(jProg["last_edit"].toString(), "yyyy-MM-dd hh:mm:ss").toString("yyyy-MM-ddThh:mm:ss"); QString dateCreated = jProg["last_edit"].toString(); oProgram["dateCreated"] = dateCreated; oProgram["layers"] = genPagesJson(pProg); oItem["_program"] = oProgram; } return oItem; } //生成多节目页json,键值layers QJsonArray mConverter::genPagesJson(const QString &pProg) { QDir dProg(pProg); QList jPageList; QStringList pageList = dProg.entryList(QDir::Dirs | QDir::NoDotAndDotDot); //需要 查询 order 属性, 将最上层的放在转换后layers 的 最前面 //一个page.json 对应节目任务中的一个 items里的program foreach(QString page, pageList) { QString pJson = pProg + MACRO_FENGEFU + page + "\\page.json"; QFile fJson(pJson); if(fJson.open(QIODevice::ReadOnly)){ QJsonDocument jPage = QJsonDocument::fromJson(fJson.readAll()); fJson.close(); jPageList.append(jPage); } } //根据order排序,这里是对节目放在items中的排序 ,是节目的排序 std::sort(jPageList.begin(), jPageList.end(), [](const QJsonDocument &a, const QJsonDocument &b) { return a["order"].toInt() < b["order"].toInt(); }); QJsonArray oLayers; foreach(QJsonDocument jPage, jPageList) { QJsonObject temp=genPageJson(jPage); if(!temp.isEmpty()) oLayers.append(temp); } return oLayers; } //生成单节目页json QJsonObject mConverter::genPageJson (const QJsonDocument &jPage) { QJsonObject oPage; QJsonArray oSource; oPage["repeat"] = false; //此处需要把一个幻灯片中的元素 按层顺序进行一个排序, 排序后 再放入layers中,每个 元素对一个一个layer。 ewindow中的多个顺序元素为一个层上的时间轴上的素材, QList elementList; foreach(QJsonValue value, jPage["elements"].toArray()) { QJsonObject oElement = value.toObject(); elementList.append(oElement); } std::sort(elementList.begin(), elementList.end(), [](const QJsonObject &a, const QJsonObject &b) { return a["geometry"]["order"].toInt() < b["geometry"]["order"].toInt(); }); // foreach(QJsonValue value, jPage["elements"].toArray()) { // QJsonObject oElement = value.toObject(); foreach(QJsonObject oElement, elementList) { switch (oElement["elementTypeId"].toInt()) { case eObject::Text : oSource.append(convertText(oElement)); break; case eObject::Photo : oSource.append(convertPhoto(oElement));break; case eObject::Movie : oSource.append(convertMovie(oElement));break; case eObject::Gif : oSource.append(convertGif(oElement));break; case eObject::DClock : oSource.append(convertDClockNew(oElement));break; case eObject::AClock : oSource.append(convertAClock(oElement));break; case eObject::Office : oSource.append(convertOffice(oElement));break; case eObject::Temp : oSource.append(convertTemp(oElement));break; case eObject::Weather : oSource.append(convertWeather(oElement));break; case eObject::Rss : oSource.append(convertRss(oElement));break; case eObject::Timer : oSource.append(convertTimer(oElement));break; case eObject::ColorText : oSource.append(convertColorText(oElement)); break; case eObject::Window : convertWindow(oElement,oSource);break; default: break; } } if(!oSource.isEmpty()) oPage["sources"] = oSource; else { QJsonObject otemp; return otemp; } return oPage; } /* * 获取文件md5值 */ QString mConverter::getFileMd5(QString filePath) { QFile localFile(filePath); if (!localFile.open(QFile::ReadOnly)) { qDebug() << "file open error."; return ""; } QCryptographicHash ch(QCryptographicHash::Md5); quint64 totalBytes = 0; quint64 bytesWritten = 0; quint64 bytesToWrite = 0; quint64 loadSize = 1024 * 4; QByteArray buf; totalBytes = localFile.size(); bytesToWrite = totalBytes; while (1) { if(bytesToWrite > 0) { buf = localFile.read(qMin(bytesToWrite, loadSize)); ch.addData(buf); bytesWritten += buf.length(); bytesToWrite -= buf.length(); buf.resize(0); } else { break; } if(bytesWritten == totalBytes) { break; } } localFile.close(); QByteArray md5 = ch.result(); QString strRes=""; strRes.append(md5.toHex()); return strRes; } //转换文本 QJsonObject mConverter::convertText(const QJsonObject &json) { eText::Data attr; QJsonDocument jRoot(json); QJsonObject oRes; //auto at = LoAppTools::getInstance(); MACRO_CONVERT_WIN_RECT eText::setElement(json, attr); oRes["_type"] = "MultiPng"; oRes["name"] = "MultiPng"; oRes["id"] = newResId(); oRes["left"] = element_x; oRes["top"] = element_y; oRes["width"] = element_w; oRes["height"] = element_h; //把["widget"]["files"]字段的数组转成[{"text0.png","move up"}] QJsonArray fileArray; QJsonArray NewFileArray; fileArray=json["widget"]["files"].toArray(); oRes["iPicCount"] = fileArray.count(); QString strIdDir=json["widget"]["idDir"].toString(); for (int i=0;i=attr.stTurning.iEffectTime) attr.stTurning.iEffectSpeed=attr.stTurning.iEffectTime/2; jsonObject["effectSpeed"]=attr.stTurning.iEffectSpeed; jsonObject["picDuration"]=attr.stTurning.iEffectTime; break; case eText::Rolling: if(attr.stRolloing.rollingStyle==0) jsonObject["effect"]=MACRO_EFFECT_STR_RIGHT_TO_LEFT; else if(attr.stRolloing.rollingStyle==1) jsonObject["effect"]=MACRO_EFFECT_STR_BOTTOM_TO_TOP; else if(attr.stRolloing.rollingStyle==2) jsonObject["effect"]=MACRO_EFFECT_STR_LEFT_TO_RIGHT; else if(attr.stRolloing.rollingStyle==3) jsonObject["effect"]=MACRO_EFFECT_STR_TOP_TO_BOTTOM; oRes["timeSpan"] = attr.stRolloing.playDuration; jsonObject["effectSpeed"]=attr.stRolloing.rollingSpeed; jsonObject["picDuration"]=0; break; case eText::Static : jsonObject["effect"]="no"; oRes["timeSpan"] = attr.stStatic.playDuration; jsonObject["effectSpeed"]=0; jsonObject["picDuration"]=attr.stStatic.playDuration; break; //转换成plainText default: break; } jsonObject["mime"] = "image/png"; NewFileArray.append(jsonObject); } //随机,无,左移,右移,上移,下移,连续左移,连续右移,连续上移,连续下移,百叶窗,淡入淡出,左上角覆盖,右上角覆盖,左下角覆盖,右下角覆盖 // switch (attr.playStyle) { // //转换成多行文本 // case eText::Turning: // oRes["playStyle"] = "Turning"; // break; // case eText::Static : oRes["playStyle"] = "Static"; break; // //转换成plainText // case eText::Rolling: // oRes["playStyle"] = "Rolling"; // break; // default: break; // } oRes["arrayPics"]=NewFileArray; return oRes; } //转换图片 QJsonObject mConverter::convertPhoto (const QJsonObject &json) { ePhoto::Data attr; QJsonDocument jRoot(json); QJsonObject oRes; // auto at = LoAppTools::getInstance(); MACRO_CONVERT_WIN_RECT ePhoto::setElement(json, attr); oRes["timeSpan"] = attr.playDuration; oRes["left"] = element_x; oRes["top"] = element_y; oRes["width"] = element_w; oRes["height"] = element_h; oRes["_type"] = "Image"; //QString file_full=attr.path+MACRO_FENGEDANFU+attr.name; QString file_full=attr.path+MACRO_FENGEDANFU+"card_"+attr.name; QString strFileMD5=getFileMd5(file_full); if(strFileMD5.length()<1) { QJsonObject TEMP; return TEMP; } oRes["id"] = strFileMD5;//calcFilePathNameStringCRC(file_full); oRes["md5"] = strFileMD5;//getFileMd5(file_full); oRes["name"] = attr.name; QFileInfo fileinfo; fileinfo = QFileInfo(file_full); //文件名 //file_name = fileinfo.fileName(); //file_path = fileinfo.absolutePath(); QString QStrExt=fileinfo.suffix().toLower(); if(QStrExt=="jpeg"||QStrExt=="jpg") oRes["mime"] = "image/jpeg"; else oRes["mime"] = "image/"+QStrExt; oRes["size"] = fileinfo.size(); oRes["enabled"] = true; oRes["enabledBy"] = ""; oRes["useType"] = QJsonValue::Null;; oRes["mediaGroup"] = QJsonValue::Null;; oRes["deletedBy"] = QJsonValue::Null;; oRes["deleted"] = QJsonValue::Null;; oRes["newName"] = QJsonValue::Null;; oRes["oldFilePath"] = ""; oRes["fileExt"] = fileinfo.suffix(); int iArray[13]={0,1,3,4,5,6,7,9,10,11,12,17,18}; if(attr.enterStyle<13) oRes["entryEffect"] = iArray[attr.enterStyle]; else oRes["entryEffect"] = 0; oRes["exitEffect"] = 0; oRes["entryEffectTimeSpan"] = attr.enterDuration; oRes["exitEffectTimeSpan"] = 0; return oRes; } //转换视频 QJsonObject mConverter::convertMovie (const QJsonObject &json) { eMovie::Data attr; QJsonDocument jRoot(json); QJsonObject oRes; // auto at = LoAppTools::getInstance(); MACRO_CONVERT_WIN_RECT eMovie::setElement(json, attr); oRes["timeSpan"] = attr.playDuration*attr.playTimes; oRes["left"] = element_x; oRes["top"] = element_y; oRes["width"] = element_w; oRes["height"] = element_h; oRes["_type"] = "Video"; QString strMd5; QString file_full=attr.path+MACRO_FENGEDANFU+attr.name; QString strFileMD5=getFileMd5(file_full); if(strFileMD5.length()<1) { QJsonObject TEMP; return TEMP; } oRes["id"] = strFileMD5;//calcFilePathNameStringCRC(file_full); oRes["md5"] = strFileMD5;//getFileMd5(file_full); oRes["name"] = attr.name; QFileInfo fileinfo; fileinfo = QFileInfo(file_full); //文件名 //file_name = fileinfo.fileName(); //file_path = fileinfo.absolutePath(); QString QStrExt=fileinfo.suffix().toLower(); oRes["mime"] = "video/"+QStrExt; oRes["size"] = fileinfo.size(); oRes["enabled"] = true; oRes["enabledBy"] = ""; oRes["mediaGroup"] = QJsonValue::Null;; oRes["deletedBy"] = QJsonValue::Null;; oRes["deleted"] = QJsonValue::Null;; oRes["newName"] = QJsonValue::Null;; oRes["oldFilePath"] = ""; oRes["fileExt"] = fileinfo.suffix(); oRes["entryEffect"] = "None"; oRes["exitEffect"] = "None"; oRes["entryEffectTimeSpan"] = 0; oRes["exitEffectTimeSpan"] = 0; return oRes; } //转换图片 QJsonObject mConverter::convertGif (const QJsonObject &json) { eGif::Data attr; QJsonDocument jRoot(json); QJsonObject oRes; // auto at = LoAppTools::getInstance(); MACRO_CONVERT_WIN_RECT eGif::setElement(json, attr); oRes["timeSpan"] = attr.playDuration*attr.playTimes; oRes["left"] = element_x; oRes["top"] = element_y; oRes["width"] = element_w; oRes["height"] = element_h; oRes["_type"] = "Image"; QString file_full=attr.path+MACRO_FENGEDANFU+attr.name; QString strFileMD5=getFileMd5(file_full); if(strFileMD5.length()<1) { QJsonObject TEMP; return TEMP; } oRes["id"] = strFileMD5;//calcFilePathNameStringCRC(file_full); oRes["md5"] = strFileMD5;//getFileMd5(file_full); oRes["name"] = attr.name; QFileInfo fileinfo; fileinfo = QFileInfo(file_full); //文件名 //file_name = fileinfo.fileName(); //file_path = fileinfo.absolutePath(); QString QStrExt=fileinfo.suffix().toLower(); oRes["mime"] = "image/gif"; oRes["size"] = fileinfo.size(); oRes["enabled"] = true; oRes["enabledBy"] = ""; oRes["mediaGroup"] = QJsonValue::Null;; oRes["deletedBy"] = QJsonValue::Null;; oRes["deleted"] = QJsonValue::Null;; oRes["newName"] = QJsonValue::Null;; oRes["oldFilePath"] = ""; oRes["fileExt"] = fileinfo.suffix(); oRes["entryEffect"] = "None"; oRes["exitEffect"] = "None"; oRes["entryEffectTimeSpan"] = 0; oRes["exitEffectTimeSpan"] = 0; return oRes; } QJsonObject mConverter::convertDClock (const QJsonObject &json) { eDClock::Data attr; QJsonDocument jRoot(json); QJsonObject oRes; // auto at = LoAppTools::getInstance(); MACRO_CONVERT_WIN_RECT eDClock::setElement(json, attr); oRes["id"] = ""; oRes["timeSpan"] = attr.playDuration; oRes["left"] = element_x; oRes["top"] = element_y; oRes["width"] = element_w; oRes["height"] = element_h; oRes["name"] = "DigitalClock"; oRes["_type"] = "DigitalClock"; oRes["html"] = "%w, %Mw %d %y
%h:%m:%s %am"; oRes["lineHeight"] = 1.4; oRes["timezone"] = 8; oRes["language"] = "en"; oRes["entryEffect"] = "None"; oRes["exitEffect"] = "None"; oRes["entryEffectTimeSpan"] = 0; oRes["exitEffectTimeSpan"] = 0; return oRes; } QJsonObject mConverter::convertDClockNew (const QJsonObject &json) { eDClock::Data attr; QJsonDocument jRoot(json); QJsonObject oRes; // auto at = LoAppTools::getInstance(); MACRO_CONVERT_WIN_RECT eDClock::setElement(json, attr); oRes["id"] = ""; oRes["timeSpan"] = attr.playDuration; oRes["left"] = element_x; oRes["top"] = element_y; oRes["width"] = element_w; oRes["height"] = element_h; oRes["name"] = "DigitalClockNew"; oRes["_type"] = "DigitalClockNew"; oRes["timezone"] = 8; QByteArray timeZoneId; oRes["year"] = attr.year; oRes["month"] = attr.month; oRes["day"] = attr.day; oRes["hour"] = attr.hour; oRes["min"] = attr.min; oRes["sec"] = attr.sec; oRes["weekly"] = attr.weekly; oRes["fullYear"] = attr.fullYear; oRes["hour12"] = attr.hour12; oRes["AmPm"] = attr.AmPm; oRes["dateStyle"] = attr.dateStyle; oRes["timeStyle"] = attr.timeStyle; oRes["multiline"] = attr.multiline; oRes["fontSize"] =attr.fontSize; oRes["entryEffect"] = "None"; oRes["exitEffect"] = "None"; oRes["entryEffectTimeSpan"] = 0; oRes["exitEffectTimeSpan"] = 0; QJsonArray NewFileArray; QStringList strFileList; strFileList.append("0"); strFileList.append("1"); strFileList.append("2"); strFileList.append("3"); strFileList.append("4"); strFileList.append("5"); strFileList.append("6"); strFileList.append("7"); strFileList.append("8"); strFileList.append("9"); strFileList.append("MON"); strFileList.append("TUE"); strFileList.append("WED"); strFileList.append("THU"); strFileList.append("FRI"); strFileList.append("SAT"); strFileList.append("SUN"); strFileList.append("AM"); strFileList.append("PM"); strFileList.append("YEAR"); strFileList.append("MONTH"); strFileList.append("DAY"); strFileList.append("maohao"); strFileList.append("xiegang"); strFileList.append("hengxian"); oRes["iPicCount"] = strFileList.count(); QString strIdDir=json["widget"]["idDir"].toString(); for (int i=0;icolor2Int(attr.cBackground); oRes["bSingleScroll"]=json["widget"]["bPaomadeng"].toBool(); oRes["iScrollSpeed"]=json["widget"]["scrollSpeed"].toInt(); oRes["font_Name"]=attr.fontFamily; oRes["font_Size"]=attr.fontSize; oRes["font_Bold"]=attr.fontBold; oRes["font_Italics"]=attr.fontItalics; oRes["font_Underline"]=attr.fontUnderline; oRes["font_Color"]=apptool->color2Int(attr.textColor); QJsonArray NewFileArray; QStringList strFileList; strFileList.append("0"); strFileList.append("1"); strFileList.append("2"); strFileList.append("3"); strFileList.append("4"); strFileList.append("5"); strFileList.append("6"); strFileList.append("7"); strFileList.append("8"); strFileList.append("9"); strFileList.append("labeltitle"); strFileList.append("labeltemperature"); strFileList.append("labelhumidity"); strFileList.append("labelnoise"); strFileList.append("labelwindSpeed"); strFileList.append("labelwindDirection"); strFileList.append("labelpm10"); strFileList.append("labelpm25"); strFileList.append("unit_celsius"); strFileList.append("unit_fahrenheit"); strFileList.append("unit_humidity"); strFileList.append("unit_noise"); strFileList.append("unit_windspeed"); strFileList.append("unit_pm10"); strFileList.append("unit_pm25"); strFileList.append("minus_sign"); strFileList.append("N"); strFileList.append("NNE"); strFileList.append("NE"); strFileList.append("ENE"); strFileList.append("E"); strFileList.append("ESE"); strFileList.append("SE"); strFileList.append("SSE"); strFileList.append("S"); strFileList.append("SSW"); strFileList.append("SW"); strFileList.append("WSW"); strFileList.append("W"); strFileList.append("WNW"); strFileList.append("NW"); strFileList.append("NNW"); strFileList.append("previewTmp"); // strFileList.append("space"); oRes["iPicCount"] = strFileList.count(); QString strIdDir=json["widget"]["idDir"].toString(); for (int i=0;i elementList; foreach(QJsonValue value, json["elements"].toArray()) { QJsonObject oElement = value.toObject(); elementList.append(oElement); } std::sort(elementList.begin(), elementList.end(), [](const QJsonObject &a, const QJsonObject &b) { return a["geometry"]["order"].toInt() < b["geometry"]["order"].toInt(); }); foreach(QJsonObject oElement, elementList) { iPlayTime+=iLastSpanTime;; switch (oElement["elementTypeId"].toInt()) { case eObject::Text : otemp=convertText(oElement); break; case eObject::Photo : otemp=convertPhoto(oElement); break; case eObject::Movie : otemp=convertMovie(oElement); break; case eObject::Gif : otemp=convertGif(oElement); break; case eObject::DClock : otemp=convertDClockNew(oElement); break; case eObject::AClock : otemp=convertAClock(oElement); break; case eObject::Office : otemp=convertOffice(oElement); break; case eObject::Temp : otemp=convertTemp(oElement); break; case eObject::Weather : otemp=convertWeather(oElement); break; case eObject::Rss : otemp=convertRss(oElement); break; case eObject::Timer : otemp=convertTimer(oElement); break; case eObject::ColorText : otemp=convertOffice(oElement); break; default: break; } iLastSpanTime=otemp["timeSpan"].toInt(); otemp["left"]=json["geometry"]["x"]; otemp["top"]=json["geometry"]["y"]; otemp["playTime"]=iPlayTime; oSource.append(otemp); } return otemp; /* QJsonDocument jRoot(json); QJsonObject oReturn; QJsonObject rootObj = jRoot.object(); QStringList keys = rootObj.keys(); for(int i = 0; i < keys.size(); i++) { QString strKey=keys.at(i); //qDebug() << "key" << i << " is:" << strKey; if(rootObj.contains(strKey)) { QJsonObject oRes = rootObj.value(strKey).toObject(); //oPage["repeat"] = false; foreach(QJsonValue value, oRes["elements"].toArray()) { QJsonObject oElement = value.toObject(); switch (oElement["elementTypeId"].toInt()) { case eObject::Text : oSource.append(convertText(oElement)); break; case eObject::Photo : oSource.append(convertPhoto(oElement));break; case eObject::Movie : oSource.append(convertMovie(oElement));break; case eObject::Gif : oSource.append(convertGif(oElement));break; case eObject::DClock : oSource.append(convertDClockNew(oElement));break; case eObject::AClock : oSource.append(convertAClock(oElement));break; case eObject::Office : oSource.append(convertOffice(oElement));break; case eObject::Temp : oSource.append(convertTemp(oElement));break; case eObject::Weather : oSource.append(convertWeather(oElement));break; case eObject::Rss : oSource.append(convertRss(oElement));break; case eObject::Timer : oSource.append(convertTimer(oElement));break; case eObject::ColorText : oSource.append(convertOffice(oElement)); break; default: break; } } } }*/ } QJsonObject mConverter::convertRss(const QJsonObject &json) { QJsonDocument jRoot(json); QJsonObject oRes; return oRes; } QJsonObject mConverter::convertOffice(const QJsonObject &json) { QJsonDocument jRoot(json); QJsonObject oRes; return oRes; } QJsonObject mConverter::convertColorText(const QJsonObject &json) { QJsonDocument jRoot(json); QJsonObject oRes; return oRes; } QString mConverter::makeColorString(const QColor &color, const QString type) { if(type == "RGBA") { return QString("rgba(%1, %2, %3, %4)") .arg(color.red()) .arg(color.green()) .arg(color.blue()) .arg(color.alpha()); } else if(type == "RGB") { return QString("rgba(%1, %2, %3)") .arg(color.red()) .arg(color.green()) .arg(color.blue()); } else if(type == "HEX") { if(color.alpha() != 255) { return QString().sprintf("#%02X%02X%02X%02X", color.red() ,color.green() ,color.blue() ,color.alpha()); } else { return QString().sprintf("#%02X%02X%02X", color.red() ,color.green() ,color.blue()); } // return QString().sprintf("#%1%02X%02X%02X", // color.red(), // color.green(), // color.blue() // ).arg(color.alpha() != 255 ? QString().sprintf("%02X", color.alpha()) : QString()); } if(type == "HEXNOALPHA") { QByteArray byteArrayTempInfo; QString strR = QString::number(color.red()&0xff,16); if(strR.length()<2) strR.insert(0,"0"); QString strG = QString::number(color.green()&0xff,16); if(strG.length()<2) strG.insert(0,"0"); QString strB = QString::number(color.blue()&0xff,16); if(strB.length()<2) strB.insert(0,"0"); return "#"+strR+strG+strB; } return color.name(); }