qt/LedOK/program/usbdetectdialog.cpp
2023-04-28 16:02:14 +08:00

66 lines
2.1 KiB
C++

#include "usbdetectdialog.h"
#include "gutil/qgui.h"
#include <QPushButton>
#include <QLabel>
#include <QLineEdit>
#include <QLabel>
#include <QDir>
#include <QMessageBox>
#include <QTimerEvent>
UsbDetectDialog::UsbDetectDialog(QWidget *parent) : QDialog(parent) {
setAttribute(Qt::WA_DeleteOnClose);
setWindowTitle(tr("Usb upgrade program"));
resize(240, 220);
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 QListWidget();
fdDrives->setSelectionRectVisible(true);
fdDrives->setProperty("ssType", "usbList");
fdDrives->setProperty("ssName", "usbListName");
vBox->addWidget(fdDrives);
hBox = new HBox(vBox);
hBox->addStretch();
auto bnOk = new QPushButton(tr("OK"));
bnOk->setProperty("ssType","progManageTool");
connect(bnOk, &QPushButton::clicked, this, [this] {
auto selects = fdDrives->selectedItems();
if(selects.count() > 0) {
foreach(auto select, selects) emit acceptData(select->text(), 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"));
});
hBox->addWidget(bnOk);
hBox->addStretch();
auto bnCancel = new QPushButton(tr("Cancel"));
bnCancel->setProperty("ssType","progManageTool");
connect(bnCancel, &QPushButton::clicked, this, &QDialog::reject);
hBox->addWidget(bnCancel);
hBox->addStretch();
detectDriver();
}
void UsbDetectDialog::detectDriver() {
#ifdef Q_OS_WINDOWS
auto drives = QDir::drives(); //获取当前系统的盘符
#else
auto drives = QDir("/Volumes").entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
#endif
fdDrives->clear();
foreach(auto drive, drives) fdDrives->addItem(drive.fileName());
}