1534 lines
53 KiB
C++
1534 lines
53 KiB
C++
#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 <JlCompress.h>
|
||
#include <QCryptographicHash>
|
||
//转换为控制卡播放的项目文件类
|
||
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('\\', '/':)"<<cmd;
|
||
// cmd.replace(MACRO_DANYINFANXIEGAN, MACRO_DANYINXIEGAN);
|
||
//#endif
|
||
// p->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<QJsonDocument> 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<QJsonObject> 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<QJsonDocument> 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<QJsonObject> 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<fileArray.count();i++)
|
||
{
|
||
QString strFileName=fileArray.at(i).toString();
|
||
QJsonObject jsonObject;
|
||
|
||
QString file_full= m_strCurPagePath+MACRO_FENGEDANFU+strIdDir+MACRO_FENGEDANFU+strFileName;
|
||
QString strFileMD5=getFileMd5(file_full);
|
||
jsonObject["id"]=strFileMD5;
|
||
|
||
switch (attr.playStyle)
|
||
{
|
||
//转换成多行文本
|
||
case eText::Turning:
|
||
jsonObject["effect"]=attr.stTurning.strEffect;
|
||
oRes["timeSpan"] = attr.stTurning.playDuration;
|
||
if(attr.stTurning.iEffectSpeed>=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<br />%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;i<strFileList.count();i++)
|
||
{
|
||
QString strFileName=strFileList.at(i);
|
||
QJsonObject jsonObject;
|
||
|
||
QString file_full= m_strCurPagePath+MACRO_FENGEDANFU+strIdDir+MACRO_FENGEDANFU+strFileName+".png";
|
||
QString strFileMD5=getFileMd5(file_full);
|
||
jsonObject["name"]=strFileName;
|
||
jsonObject["id"]=strFileMD5;
|
||
jsonObject["mime"] = "image/png";
|
||
QImage image(file_full);
|
||
jsonObject["picWidth"]=image.width();
|
||
jsonObject["picHeight"]=image.height();
|
||
NewFileArray.append(jsonObject);
|
||
}
|
||
oRes["arrayPics"]=NewFileArray;
|
||
|
||
|
||
/*
|
||
//年
|
||
{
|
||
"pos_x":100,
|
||
"pos_y":200,
|
||
"id":"342394803284",
|
||
}
|
||
//月
|
||
{
|
||
|
||
}
|
||
//日
|
||
{
|
||
|
||
}
|
||
//星期
|
||
{
|
||
|
||
}
|
||
//上午下午
|
||
{
|
||
|
||
}
|
||
//时
|
||
{
|
||
|
||
}
|
||
//分
|
||
{
|
||
|
||
}
|
||
//秒
|
||
{
|
||
|
||
}
|
||
*/
|
||
|
||
|
||
return oRes;
|
||
}
|
||
QJsonObject mConverter::convertAClock (const QJsonObject &json)
|
||
{
|
||
eAClock::Data attr;
|
||
QJsonDocument jRoot(json);
|
||
QJsonObject oRes;
|
||
// auto at = LoAppTools::getInstance();
|
||
|
||
MACRO_CONVERT_WIN_RECT
|
||
eAClock::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"] = "001";
|
||
oRes["_type"] ="AnalogClock";
|
||
//__TODO 待定
|
||
oRes["shade"] = 0;//表盘形状
|
||
oRes["opacity"] = 1;//透明度
|
||
oRes["showBg"] = false;//是否显示背景色
|
||
oRes["bgColor"] = 0;
|
||
oRes["showHourScale"] = false;//是否显示时针
|
||
|
||
oRes["scaleHourColor"] = makeColorString(attr.hourMarkColor,"HEXNOALPHA");//时标的颜色
|
||
oRes["showMinScale"] = false;
|
||
oRes["scaleMinColor"] = makeColorString(attr.minMarkColor,"HEXNOALPHA");//分标的颜色
|
||
oRes["scaleStyle"] = 0;
|
||
oRes["showScaleNum"] = false;
|
||
oRes["pinStyle"] = 1;
|
||
|
||
oRes["pinHourColor"] =makeColorString(attr.hourHandColor,"HEXNOALPHA");//时针
|
||
oRes["pinMinColor"] = makeColorString(attr.minHandColor,"HEXNOALPHA");//分针
|
||
oRes["pinSecColor"] = makeColorString(attr.secHandColor,"HEXNOALPHA");//秒针
|
||
oRes["showSecond"] = true;
|
||
QString file_full="";
|
||
file_full=m_strCurPagePath+MACRO_FENGEDANFU+attr.selfCreateDialName;
|
||
QString strFileMD5=getFileMd5(file_full);
|
||
|
||
oRes["id"] = strFileMD5;//calcFilePathNameStringCRC(file_full);
|
||
oRes["md5"] = strFileMD5;//getFileMd5(file_full);
|
||
oRes["mime"] = "image/png";
|
||
|
||
//下同Video
|
||
oRes["entryEffect"] = "None";
|
||
oRes["exitEffect"] = "None";
|
||
oRes["entryEffectTimeSpan"] = 0;
|
||
oRes["exitEffectTimeSpan"] = 0 ;
|
||
return oRes;
|
||
}
|
||
|
||
QJsonObject mConverter::convertTemp (const QJsonObject &json)
|
||
{
|
||
auto apptool = LoAppTools::getInstance();
|
||
eTemp::Data attr;
|
||
QJsonDocument jRoot(json);
|
||
QJsonObject oRes;
|
||
// auto at = LoAppTools::getInstance();
|
||
|
||
MACRO_CONVERT_WIN_RECT
|
||
eTemp::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"] = "EnvironmentalMonitoring";
|
||
oRes["_type"] = "EnvironmentalMonitoring";
|
||
|
||
QByteArray timeZoneId;
|
||
oRes["alignType"]=json["widget"]["alignType"].toInt();
|
||
oRes["bHumidity"]=json["widget"]["bHumidity"].toBool();
|
||
oRes["bNoise"]=json["widget"]["bNoise"].toBool();
|
||
oRes["bPM10"]=json["widget"]["bPM10"].toBool();
|
||
oRes["bPM25"]=json["widget"]["bPM25"].toBool();
|
||
oRes["bTemperature"]=json["widget"]["bTemperature"].toBool();
|
||
oRes["bTitle"]=json["widget"]["bTitle"].toBool();
|
||
oRes["bWindDirection"]=json["widget"]["bWindDirection"].toBool();
|
||
oRes["bWindSpeed"]=json["widget"]["bWindSpeed"].toBool();
|
||
oRes["temperatureCompensation"]=json["widget"]["temperatureCompensation"].toInt();
|
||
oRes["temperatureStyle"]=json["widget"]["temperatureStyle"].toInt();
|
||
oRes["bgColor"]=apptool->color2Int(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<strFileList.count();i++)
|
||
{
|
||
QString strFileName=strFileList.at(i);
|
||
QJsonObject jsonObject;
|
||
|
||
QString file_full= m_strCurPagePath+MACRO_FENGEDANFU+strIdDir+MACRO_FENGEDANFU+strFileName+".png";
|
||
QString strFileMD5=getFileMd5(file_full);
|
||
jsonObject["name"]=strFileName;
|
||
jsonObject["id"]=strFileMD5;
|
||
jsonObject["mime"] = "image/png";
|
||
QImage image(file_full);
|
||
jsonObject["picWidth"]=image.width();
|
||
jsonObject["picHeight"]=image.height();
|
||
NewFileArray.append(jsonObject);
|
||
}
|
||
oRes["arrayPics"]=NewFileArray;
|
||
|
||
|
||
return oRes;
|
||
}
|
||
|
||
QJsonObject mConverter::convertWeather(const QJsonObject &json)
|
||
{
|
||
eWeather::Data attr;
|
||
QJsonDocument jRoot(json);
|
||
QJsonObject oRes;
|
||
// auto at = LoAppTools::getInstance();
|
||
|
||
MACRO_CONVERT_WIN_RECT
|
||
eWeather::setElement(json, attr);
|
||
oRes["id"] = "";
|
||
oRes["name"] ="今天";
|
||
//素材为天气预报类型,必须为Weather,大小写敏感
|
||
oRes["_type"] ="Weather";
|
||
//城市名称,支持国内主要城市
|
||
oRes["city"] ="上海";
|
||
//文字行高
|
||
oRes["lineHeight"] =1;
|
||
//显示内容,html格式
|
||
//%{current}:当前温度
|
||
//%{aqi}:AQI(空气质量指数)
|
||
//%{arr.0.date}:当天日期(包含实时温度)
|
||
//%{arr.0.type}:当天天气
|
||
//%{arr.0.high}:当天最高温度
|
||
//%{arr.0.low}:当天最低温度
|
||
//%{arr.0.fx}:当天风向
|
||
//%{arr.0.fl}:当天风力
|
||
//%{arr.0.img-32-32}:当天天气图片,格式:img-宽度-高度(蓝色),img2-宽度-高度(灰色)
|
||
//以上{ }里的yesterday代表昨天,arr.0代表当天,1代表明天,2代表后天,3代表大后天,4代表大大后天
|
||
oRes["html"] ="今天:%{arr.0.date}<br />实时温度:%{current}℃<br />空气质量:%{aqi}<br />%{arr.0.img-32-32}%{arr.0.type}<br />最高:%{arr.0.high}℃ 最低:%{arr.0.low}℃<br />%{arr.0.fx} %{arr.0.fl}";
|
||
|
||
|
||
oRes["timeSpan"] = attr.playDuration;
|
||
oRes["left"] = element_x;
|
||
oRes["top"] = element_y;
|
||
oRes["width"] = element_w;
|
||
oRes["height"] = element_h;
|
||
return oRes;
|
||
|
||
}
|
||
|
||
QJsonObject mConverter::convertTimer (const QJsonObject &json)
|
||
{
|
||
eTimer::Data attr;
|
||
QJsonDocument jRoot(json);
|
||
QJsonObject oRes;
|
||
// auto at = LoAppTools::getInstance();
|
||
|
||
MACRO_CONVERT_WIN_RECT
|
||
eTimer::setElement(json, attr);
|
||
oRes["id"] = "";
|
||
|
||
oRes["name"] = "Countdown";
|
||
oRes["_type"] = "Countdown";
|
||
oRes["lineHeight"] = 1.4;
|
||
oRes["time"] = attr.targetDateTime.toString("yyyy-MM-dd hh:mm:ss");
|
||
oRes["html"] = "Remain<br />%dDay%hHours%mMins%sSecs";
|
||
|
||
|
||
oRes["timeSpan"] = attr.playDuration;
|
||
oRes["left"] = element_x;
|
||
oRes["top"] = element_y;
|
||
oRes["width"] = element_w;
|
||
oRes["height"] = element_h;
|
||
return oRes;
|
||
// int xWard;
|
||
// QDateTime targetDateTime;
|
||
// bool day;
|
||
// bool hour;
|
||
// bool min;
|
||
// bool sec;
|
||
// QString text;
|
||
// bool multiline;
|
||
// QString fontFamily;
|
||
// int fontSize;
|
||
// bool fontBold;
|
||
// bool fontItalics;
|
||
// bool fontUnderline;
|
||
// QColor textColor;
|
||
// QColor backgroundColor;
|
||
// int playDuration;
|
||
}
|
||
/*该函数的返回值只是用来供函数判断是否有内容,方便上一级函数genLayerJson判断是否需要添加oSource到layer内,实际该window多素材窗口的内容在oSource中*/
|
||
QJsonObject mConverter::convertWindow (const QJsonObject &json,QJsonArray &oSource)
|
||
{
|
||
//QJsonDocument jRoot(json);
|
||
QJsonObject otemp;
|
||
int iPlayTime=0;
|
||
int iLastSpanTime=0;
|
||
|
||
QList<QJsonObject> 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();
|
||
}
|
||
|