2022-09-30 18:08:39 +08:00
|
|
|
|
#include "progitem.h"
|
2022-08-25 18:37:24 +08:00
|
|
|
|
#include "tools.h"
|
|
|
|
|
#include "progeditorwin.h"
|
2022-01-04 18:11:48 +08:00
|
|
|
|
#include "mconverter.h"
|
|
|
|
|
#include "LoUIClass/loemptydialog.h"
|
|
|
|
|
#include "usbdetectdialog.h"
|
|
|
|
|
#include <globaldefine.h>
|
|
|
|
|
#include "sendprogramdialog.h"
|
|
|
|
|
#include "mainwindow.h"
|
|
|
|
|
|
2022-09-30 18:08:39 +08:00
|
|
|
|
ProgItem::ProgItem(const QString &pRoot, const QString &name, int w, int h, const QString &remarks, LoQTreeWidget *parent,QWidget *pWnd) : QObject(parent), QTreeWidgetItem(UserType), m_parent(parent) {
|
2022-01-04 18:11:48 +08:00
|
|
|
|
m_name = name;
|
|
|
|
|
m_width = w;
|
|
|
|
|
m_height = h;
|
|
|
|
|
m_remarks = remarks;
|
|
|
|
|
m_fsize = 0;
|
|
|
|
|
m_last = QDateTime::currentDateTime();
|
|
|
|
|
m_strSavePath = pRoot;
|
2022-08-25 18:37:24 +08:00
|
|
|
|
mProgDir = pRoot + MACRO_FENGEFU + m_name;
|
2022-01-04 18:11:48 +08:00
|
|
|
|
m_orgName = m_name;
|
2022-08-25 18:37:24 +08:00
|
|
|
|
m_pWnd = pWnd;
|
2022-01-04 18:11:48 +08:00
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-30 18:08:39 +08:00
|
|
|
|
ProgItem::ProgItem(const QString &pRoot, const QJsonObject &json, LoQTreeWidget *parent,QWidget *pWnd) : QObject(parent), QTreeWidgetItem(UserType), m_parent(parent) {
|
2022-01-04 18:11:48 +08:00
|
|
|
|
m_name = json["name"].toString();
|
|
|
|
|
m_width = json["resolution"]["w"].toInt();
|
|
|
|
|
m_height = json["resolution"]["h"].toInt();
|
|
|
|
|
m_remarks = json["remarks"].toString();
|
|
|
|
|
m_fsize = json["file_size"].toDouble();
|
|
|
|
|
m_last = QDateTime::fromString(json["last_edit"].toString(), "yyyy-MM-dd hh:mm:ss");
|
|
|
|
|
m_strSavePath = pRoot;
|
2022-08-25 18:37:24 +08:00
|
|
|
|
mProgDir = pRoot + MACRO_FENGEFU + m_name;
|
2022-01-04 18:11:48 +08:00
|
|
|
|
m_orgName = m_name;
|
2022-08-25 18:37:24 +08:00
|
|
|
|
m_pWnd = pWnd;
|
2022-01-04 18:11:48 +08:00
|
|
|
|
init();
|
|
|
|
|
}
|
2022-09-30 18:08:39 +08:00
|
|
|
|
|
|
|
|
|
void ProgItem::init()
|
2022-01-04 18:11:48 +08:00
|
|
|
|
{
|
2022-08-25 18:37:24 +08:00
|
|
|
|
auto cfg = Tools::getInstance();
|
2022-01-04 18:11:48 +08:00
|
|
|
|
setData(ENUM_PROGRAMLISTHEADERITEM_NAME, 0,m_name);
|
|
|
|
|
setData(ENUM_PROGRAMLISTHEADERITEM_RESOLUTION, 0, QString("%1 x %2").arg(m_width).arg(m_height));
|
|
|
|
|
if(m_fsize<=0)
|
2022-08-25 18:37:24 +08:00
|
|
|
|
setData(ENUM_PROGRAMLISTHEADERITEM_SIZE, 0, cfg->convertFileSize((qint64)100));
|
2022-01-04 18:11:48 +08:00
|
|
|
|
else
|
|
|
|
|
setData(ENUM_PROGRAMLISTHEADERITEM_SIZE, 0, cfg->convertFileSize(m_fsize));
|
|
|
|
|
setData(ENUM_PROGRAMLISTHEADERITEM_LASTTIME, 0, m_last.toString("yyyy-MM-dd hh:mm:ss"));
|
|
|
|
|
setTextAlignment(ENUM_PROGRAMLISTHEADERITEM_NAME, Qt::AlignLeft | Qt::AlignVCenter);
|
|
|
|
|
for(int i=1; i<ENUM_PROGRAMLISTHEADERITEM_END; i++) {
|
|
|
|
|
setTextAlignment(i, Qt::AlignCenter);
|
|
|
|
|
}
|
|
|
|
|
setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
|
|
|
|
|
setCheckState(0, Qt::Unchecked);
|
|
|
|
|
m_parent->insertTopLevelItem(0,this);
|
|
|
|
|
|
|
|
|
|
m_bnName = new QPushButton(m_name);
|
2022-08-25 18:37:24 +08:00
|
|
|
|
m_bnName->setStyleSheet(R"delimiter(
|
|
|
|
|
QPushButton{border-radius: 4px;}
|
|
|
|
|
QPushButton:hover {
|
|
|
|
|
background-color: #cccccc;
|
|
|
|
|
text-decoration: underline;
|
|
|
|
|
}
|
|
|
|
|
)delimiter");
|
|
|
|
|
|
2022-01-04 18:11:48 +08:00
|
|
|
|
m_bnName->setCursor(QCursor(Qt::PointingHandCursor));
|
|
|
|
|
m_parent->setItemWidget(this, ENUM_PROGRAMLISTHEADERITEM_NAME, m_bnName);
|
|
|
|
|
connect(m_bnName, SIGNAL(clicked()), this, SLOT(onEditProgram()));
|
|
|
|
|
m_bnExport = new QPushButton();
|
|
|
|
|
m_bnExport->setCursor(QCursor(Qt::PointingHandCursor));
|
|
|
|
|
m_bnExport->setToolTip(tr("ExportButtonTip"));
|
2022-08-25 18:37:24 +08:00
|
|
|
|
m_bnExport->setStyleSheet(R"rrr(
|
|
|
|
|
QPushButton {
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
image: url(:/res/ProgramManager/bnExport_u.png);
|
|
|
|
|
}
|
|
|
|
|
QPushButton:pressed{image: url(:/res/ProgramManager/bnExport_s.png);}
|
|
|
|
|
QPushButton:hover{background-color: #cccccc;}
|
|
|
|
|
)rrr");
|
|
|
|
|
|
2022-01-04 18:11:48 +08:00
|
|
|
|
m_parent->setItemWidget(this, ENUM_PROGRAMLISTHEADERITEM_USB_EXPORT, m_bnExport);
|
|
|
|
|
connect(m_bnExport, SIGNAL(clicked()), this, SLOT(onUsbExportProgram()));
|
|
|
|
|
|
|
|
|
|
m_bnSend = new QPushButton();
|
|
|
|
|
m_bnSend->setCursor(QCursor(Qt::PointingHandCursor));
|
|
|
|
|
m_bnSend->setToolTip(tr("SendButtonTip"));
|
2022-08-25 18:37:24 +08:00
|
|
|
|
m_bnSend->setStyleSheet(R"rrr(
|
|
|
|
|
QPushButton{
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
image: url(:/res/ProgramManager/bnSend_u.png);
|
|
|
|
|
}
|
|
|
|
|
QPushButton:pressed{image: url(:/res/ProgramManager/bnSend_s.png);}
|
|
|
|
|
QPushButton:hover{background-color: #cccccc;}
|
|
|
|
|
)rrr");
|
|
|
|
|
|
2022-01-04 18:11:48 +08:00
|
|
|
|
m_parent->setItemWidget(this, ENUM_PROGRAMLISTHEADERITEM_SEND, m_bnSend);
|
|
|
|
|
connect(m_bnSend, SIGNAL(clicked()), this, SLOT(onSendProgram()));
|
|
|
|
|
}
|
2022-09-30 18:08:39 +08:00
|
|
|
|
void ProgItem::refreshLable()
|
2022-01-04 18:11:48 +08:00
|
|
|
|
{
|
|
|
|
|
m_bnExport->setToolTip(tr("ExportButtonTip"));
|
|
|
|
|
m_bnSend->setToolTip(tr("SendButtonTip"));
|
|
|
|
|
|
|
|
|
|
}
|
2022-09-30 18:08:39 +08:00
|
|
|
|
QJsonObject ProgItem::jRoot()
|
2022-01-04 18:11:48 +08:00
|
|
|
|
{
|
|
|
|
|
QJsonObject oRoot;
|
|
|
|
|
QJsonObject oSize;
|
|
|
|
|
oRoot["name"] = m_name;
|
|
|
|
|
oSize["w"] = m_width;
|
|
|
|
|
oSize["h"] = m_height;
|
|
|
|
|
oRoot["resolution"] = oSize;
|
|
|
|
|
oRoot["remarks"] = m_remarks;
|
|
|
|
|
oRoot["file_size"] = m_fsize;
|
|
|
|
|
oRoot["last_edit"] = m_last.toString("yyyy-MM-dd hh:mm:ss");
|
|
|
|
|
return oRoot;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-30 18:08:39 +08:00
|
|
|
|
void ProgItem::save() {
|
2022-08-25 18:37:24 +08:00
|
|
|
|
QDir dRoot(mProgDir);
|
2022-01-04 18:11:48 +08:00
|
|
|
|
QDir dParent(m_strSavePath);
|
|
|
|
|
if(!dRoot.exists()) {
|
|
|
|
|
dParent.mkdir(m_name);
|
|
|
|
|
} else if(m_name != m_orgName) {
|
|
|
|
|
dParent.rename(m_orgName, m_name);
|
|
|
|
|
m_orgName = m_name;
|
2022-08-25 18:37:24 +08:00
|
|
|
|
mProgDir = m_strSavePath + MACRO_FENGEFU + m_name;
|
2022-01-04 18:11:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-25 18:37:24 +08:00
|
|
|
|
dRoot = QDir(mProgDir);
|
2022-01-04 18:11:48 +08:00
|
|
|
|
if(dRoot.exists()) {
|
|
|
|
|
QJsonDocument json(jRoot());
|
2022-08-25 18:37:24 +08:00
|
|
|
|
QFile f(mProgDir + MACRO_FENGEFU+"pro.json");
|
2022-01-04 18:11:48 +08:00
|
|
|
|
f.open(QIODevice::WriteOnly);
|
|
|
|
|
f.write(json.toJson());
|
|
|
|
|
f.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-30 18:08:39 +08:00
|
|
|
|
void ProgItem::del()
|
2022-01-04 18:11:48 +08:00
|
|
|
|
{
|
2022-08-25 18:37:24 +08:00
|
|
|
|
QDir dRoot(mProgDir);
|
2022-01-04 18:11:48 +08:00
|
|
|
|
if(dRoot.exists()) {
|
|
|
|
|
dRoot.removeRecursively();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//设置列表项的值
|
2022-09-30 18:08:39 +08:00
|
|
|
|
void ProgItem::onSetProgram()
|
2022-01-04 18:11:48 +08:00
|
|
|
|
{
|
2022-08-25 18:37:24 +08:00
|
|
|
|
auto cfg = Tools::getInstance();
|
2022-01-04 18:11:48 +08:00
|
|
|
|
m_bnName->setText(m_name);
|
|
|
|
|
setData(ENUM_PROGRAMLISTHEADERITEM_RESOLUTION, 0, QString("%1 x %2").arg(m_width).arg(m_height));
|
|
|
|
|
if(m_fsize<=0)
|
|
|
|
|
setData(ENUM_PROGRAMLISTHEADERITEM_SIZE, 0, cfg->convertFileSize(100));
|
|
|
|
|
else
|
|
|
|
|
setData(ENUM_PROGRAMLISTHEADERITEM_SIZE, 0, cfg->convertFileSize(m_fsize));
|
|
|
|
|
setData(ENUM_PROGRAMLISTHEADERITEM_LASTTIME, 0, m_last.toString("yyyy-MM-dd hh:mm:ss"));
|
|
|
|
|
save();
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-30 18:08:39 +08:00
|
|
|
|
void ProgItem::onEditProgram() {
|
2022-08-25 18:37:24 +08:00
|
|
|
|
auto editor = new ProgEditorWin(m_name, m_width, m_height, m_remarks, mProgDir, m_strSavePath, gMainWin);
|
|
|
|
|
connect(editor, &ProgEditorWin::sProgramChanged, this, [this]{
|
|
|
|
|
m_last = QDateTime::currentDateTime();
|
|
|
|
|
m_fsize = dirFileSize(mProgDir);
|
|
|
|
|
onSetProgram();
|
|
|
|
|
});//编辑窗口发送节目变化信号到该ITEM响应属性变化槽函数
|
|
|
|
|
connect(editor, &ProgEditorWin::sProgramSaveAs, (ProgPanel*)m_pWnd, &ProgPanel::onCreateNewProgramOnOpenEditProgramWidget);//编辑窗口另存为按钮触发后发送信号到播放列表增加一行
|
|
|
|
|
editor->show();
|
2022-01-04 18:11:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-30 18:08:39 +08:00
|
|
|
|
void ProgItem::onUsbExportProgram(){
|
2022-08-25 18:37:24 +08:00
|
|
|
|
auto pDlg = new UsbDetectDialog(gMainWin);
|
2022-09-30 18:08:39 +08:00
|
|
|
|
connect(pDlg, &UsbDetectDialog::acceptData, this, &ProgItem::onUsbExportProgramPro);
|
2022-08-25 18:37:24 +08:00
|
|
|
|
pDlg->exec();
|
2022-01-04 18:11:48 +08:00
|
|
|
|
}
|
2022-09-30 18:08:39 +08:00
|
|
|
|
void ProgItem::onUsbExportProgramPro(QString strPath, QString strPassword){
|
2022-01-04 18:11:48 +08:00
|
|
|
|
LoEmptyDialog * msgbox = new LoEmptyDialog(m_pWnd);
|
2022-08-25 18:37:24 +08:00
|
|
|
|
QString strUsbProgramName = m_name;
|
|
|
|
|
auto converter = new mConverter(strUsbProgramName, strPath + (strPath.endsWith('/') ? "program.zip" : "/program.zip"), strPassword, this);
|
|
|
|
|
connect(converter, &QThread::finished, converter, &QThread::deleteLater);
|
2022-01-04 18:11:48 +08:00
|
|
|
|
//转换结束,发送信号触发converter释放内存
|
2022-08-25 18:37:24 +08:00
|
|
|
|
connect(converter, SIGNAL(finished()), msgbox, SLOT(unlock()));
|
|
|
|
|
connect(converter, SIGNAL(finished()), this, SLOT(UsbExportFinished()));
|
2022-01-04 18:11:48 +08:00
|
|
|
|
//链接转换进度信号到进度条槽函数
|
2022-08-25 18:37:24 +08:00
|
|
|
|
connect(converter, SIGNAL(sProgress(QString,int,bool)), msgbox->mIndicator, SLOT(onProgress(QString,int,bool)));
|
2022-01-04 18:11:48 +08:00
|
|
|
|
//链接进度对话框启动信号到转换开始槽函数
|
|
|
|
|
connect(msgbox, SIGNAL(startUp()), converter, SLOT(start()));
|
|
|
|
|
msgbox->lock(tr("Convertering")+"...",tr("USB Export Successed"),tr("USB Export TimeOut"));
|
|
|
|
|
msgbox->exec();
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-30 18:08:39 +08:00
|
|
|
|
void ProgItem::onSendProgram(){
|
2022-01-04 18:11:48 +08:00
|
|
|
|
LoEmptyDialog * msgbox = new LoEmptyDialog(m_pWnd);
|
|
|
|
|
//转换节目
|
2022-08-25 18:37:24 +08:00
|
|
|
|
auto converter = new mConverter(m_name, "", "", this);
|
|
|
|
|
connect(converter, &QThread::finished, converter, &QThread::deleteLater);
|
2022-01-04 18:11:48 +08:00
|
|
|
|
//转换结束,发送信号触发converter释放内存
|
|
|
|
|
connect(converter, SIGNAL(finished()), msgbox, SLOT(unlock()));
|
|
|
|
|
//链接转换进度信号到进度条槽函数
|
2022-08-25 18:37:24 +08:00
|
|
|
|
connect(converter, SIGNAL(sProgress(QString,int,bool)), msgbox->mIndicator, SLOT(onProgress(QString,int,bool)));
|
2022-01-04 18:11:48 +08:00
|
|
|
|
//链接进度对话框启动信号到转换开始槽函数
|
|
|
|
|
connect(msgbox, SIGNAL(startUp()), converter, SLOT(start()));
|
|
|
|
|
msgbox->lock(tr("Convertering")+"...",tr("Converter Successed"),tr("Converter TimeOut"));
|
|
|
|
|
msgbox->exec();
|
|
|
|
|
|
2022-08-25 18:37:24 +08:00
|
|
|
|
auto dlg = new SendProgramDialog(m_pWnd, m_name, programsDir());
|
|
|
|
|
dlg->show();
|
2022-01-04 18:11:48 +08:00
|
|
|
|
}
|