From 77e0555343ed71220233309d3eeafb3fe435586c Mon Sep 17 00:00:00 2001 From: Gangphon Date: Thu, 4 May 2023 14:38:17 +0800 Subject: [PATCH] ledok --- LedOK/LedOK.pro | 2 - LedOK/program/progitem.cpp | 67 ++++++++++++++++++++++++------- LedOK/program/progitem.h | 1 - LedOK/program/usbdetectdialog.cpp | 63 ----------------------------- LedOK/program/usbdetectdialog.h | 19 --------- 5 files changed, 53 insertions(+), 99 deletions(-) delete mode 100644 LedOK/program/usbdetectdialog.cpp delete mode 100644 LedOK/program/usbdetectdialog.h diff --git a/LedOK/LedOK.pro b/LedOK/LedOK.pro index 41c61a0..18e198a 100644 --- a/LedOK/LedOK.pro +++ b/LedOK/LedOK.pro @@ -136,7 +136,6 @@ SOURCES += \ program/progitem.cpp \ program/sendprogramdialog.cpp \ program/sendprogthread.cpp \ - program/usbdetectdialog.cpp \ program/videosplitthread.cpp \ program/wplanitem.cpp \ program/wplanlist.cpp \ @@ -225,7 +224,6 @@ HEADERS += \ program/progitem.h \ program/sendprogramdialog.h \ program/sendprogthread.h \ - program/usbdetectdialog.h \ program/videosplitthread.h \ program/wplanitem.h \ program/wplanlist.h \ diff --git a/LedOK/program/progitem.cpp b/LedOK/program/progitem.cpp index df28b02..9e5e097 100644 --- a/LedOK/program/progitem.cpp +++ b/LedOK/program/progitem.cpp @@ -1,15 +1,19 @@ #include "progitem.h" +#include "progpanel.h" +#include "QtWidgets/qdialogbuttonbox.h" +#include "QtWidgets/qlineedit.h" #include "gutil/qcore.h" +#include "gutil/qgui.h" +#include "base/waitingdlg.h" #include "tools.h" #include "progeditorwin.h" #include "base/waitingdlg.h" #include "gentmpthread.h" -#include "base/loemptydialog.h" -#include "usbdetectdialog.h" #include #include "sendprogramdialog.h" -#include "mainwindow.h" #include +#include +#include ProgItem::ProgItem(const QString &progsDir, const QString &name, int w, int h, const QString &remarks, QList &splitWidths, int maxWidth, LoQTreeWidget *tree, ProgPanel *progPanel) : QTreeWidgetItem(UserType), mName(name), mWidth(w), mHeight(h), mRemark(remarks), mSplitWidths(splitWidths), mMaxWidth(maxWidth), mProgsDir(progsDir), mProgPanel(progPanel), mTree(tree) { @@ -145,19 +149,54 @@ void ProgItem::onSetProgram() { save(); } -void ProgItem::onUsbExportProgram(){ - UsbDetectDialog dlg(gMainWin); - connect(&dlg, &UsbDetectDialog::acceptData, this, &ProgItem::onUsbExportProgramPro); +void ProgItem::onUsbExportProgram() { + QDialog dlg(gMainWin); + dlg.setWindowFlag(Qt::WindowContextHelpButtonHint, 0); + dlg.setWindowTitle(tr("Usb upgrade program")); + dlg.resize(300, 260); + + auto vBox = new VBox(&dlg); + auto hBox = new HBox(vBox); + + hBox->addWidget(new QLabel(tr("Password"))); + + auto fdPassword = new QLineEdit; + fdPassword->setEchoMode(QLineEdit::Password); + fdPassword->setPlaceholderText(tr("Input password")); + hBox->addWidget(fdPassword); + + auto fdDrives = new ListWgt; + fdDrives->setSelectionRectVisible(true); + vBox->addWidget(fdDrives); + + auto btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + connect(btnBox, &QDialogButtonBox::accepted, &dlg, [=, &dlg] { + auto selects = fdDrives->selectedItems(); + if(selects.count() > 0) { + foreach(auto select, selects) { + auto strPath = select->data(Qt::UserRole).toString(); + auto waitingDlg = new WaitingDlg(mProgPanel, tr("Convertering")+" ..."); + auto converter = new GenTmpThread(this, mName, strPath + (strPath.endsWith('/') ? "program.zip" : "/program.zip"), fdPassword->text(), this); + connect(converter, &QThread::finished, waitingDlg, &WaitingDlg::success); + connect(converter, &GenTmpThread::sProgress, waitingDlg->mIndicator, &CustomProgressIndicator::onProgress); + converter->start(); + waitingDlg->exec(); + } + dlg.accept(); + return; + } + if(fdDrives->count() <= 0) QMessageBox::warning(&dlg, tr("Tip"),tr("No checked USB device")); + else QMessageBox::warning(&dlg, tr("Tip"),tr("please select usb device in list")); + }); + connect(btnBox, &QDialogButtonBox::rejected, &dlg, &QDialog::reject); + vBox->addWidget(btnBox); + + fdDrives->clear(); + auto volumes = QStorageInfo::mountedVolumes(); + foreach(auto volume, volumes) fdDrives->addItem(volume.displayName(), volume.rootPath()); + dlg.exec(); } -void ProgItem::onUsbExportProgramPro(QString strPath, QString strPassword) { - auto waitingDlg = new WaitingDlg(mProgPanel, tr("Convertering")+" ..."); - auto converter = new GenTmpThread(this, mName, strPath + (strPath.endsWith('/') ? "program.zip" : "/program.zip"), strPassword, this); - connect(converter, &QThread::finished, waitingDlg, &WaitingDlg::success); - connect(converter, &GenTmpThread::sProgress, waitingDlg->mIndicator, &CustomProgressIndicator::onProgress); - converter->start(); - waitingDlg->exec(); -} void ProgItem::onSendProgram() { auto waitingDlg = new WaitingDlg(mProgPanel, tr("Convertering")+" ..."); diff --git a/LedOK/program/progitem.h b/LedOK/program/progitem.h index 62a9ff6..827dda7 100644 --- a/LedOK/program/progitem.h +++ b/LedOK/program/progitem.h @@ -37,7 +37,6 @@ public slots: void onSetProgram(); void onSendProgram(); void onUsbExportProgram(); - void onUsbExportProgramPro(QString strPath,QString strPassword); private: void init(); diff --git a/LedOK/program/usbdetectdialog.cpp b/LedOK/program/usbdetectdialog.cpp deleted file mode 100644 index 10b39c3..0000000 --- a/LedOK/program/usbdetectdialog.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "usbdetectdialog.h" -#include "gutil/qgui.h" -#include -#include -#include -#include -#include -#include -#include -#include - -UsbDetectDialog::UsbDetectDialog(QWidget *parent) : QDialog(parent) { - setWindowFlag(Qt::WindowContextHelpButtonHint, 0); - setWindowTitle(tr("Usb upgrade program")); - resize(300, 260); - - auto vBox = new VBox(this); - auto hBox = new HBox(vBox); - - hBox->addWidget(new QLabel(tr("Password"))); - - fdPassword = new QLineEdit(); - fdPassword->setEchoMode(QLineEdit::Password); - fdPassword->setPlaceholderText(tr("Input password")); - hBox->addWidget(fdPassword); - - fdDrives = new ListWgt; - fdDrives->setSelectionRectVisible(true); - vBox->addWidget(fdDrives); - - auto btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); - connect(btnBox, &QDialogButtonBox::accepted, this, [this] { - auto selects = fdDrives->selectedItems(); - if(selects.count() > 0) { - foreach(auto select, selects) emit acceptData(select->data(Qt::UserRole).toString(), fdPassword->text()); - accept(); - return; - } - if(fdDrives->count() <= 0) QMessageBox::warning(this, tr("Tip"),tr("No checked USB device")); - else QMessageBox::warning(this, tr("Tip"),tr("please select usb device in list")); - }); - connect(btnBox, &QDialogButtonBox::rejected, this, &QDialog::reject); - vBox->addWidget(btnBox); - - detectDriver(); -} -#include -void UsbDetectDialog::detectDriver() { - fdDrives->clear(); -//#ifdef Q_OS_WINDOWS - auto volumes = QStorageInfo::mountedVolumes(); - foreach(auto volume, volumes) fdDrives->addItem(volume.displayName(), volume.rootPath()); - foreach(auto volume, volumes) { - qDebug() << "rootPath" << volume.rootPath(); - qDebug() << "device" << volume.device(); - qDebug() << "name" << volume.name(); - qDebug() << "displayName" << volume.displayName(); - } -//#else -// auto drives = QDir("/Volumes").entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot); -//foreach(auto drive, drives) fdDrives->addItem(drive.fileName(), drive.filePath()); -//#endif -} diff --git a/LedOK/program/usbdetectdialog.h b/LedOK/program/usbdetectdialog.h deleted file mode 100644 index f421088..0000000 --- a/LedOK/program/usbdetectdialog.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef USBDETECTDIALOG_H -#define USBDETECTDIALOG_H - -#include "gutil/qgui.h" -#include - -class UsbDetectDialog : public QDialog { - Q_OBJECT -public: - explicit UsbDetectDialog(QWidget *parent = 0); -signals: - void acceptData(QString string1, QString string2); -private: - void detectDriver(); - ListWgt *fdDrives; - QLineEdit *fdPassword; -}; - -#endif // USBDETECTDIALOG_H