qt/LedOK/program/usbdetectdialog.cpp

66 lines
2.1 KiB
C++
Raw Normal View History

2023-04-18 14:14:46 +08:00
#include "usbdetectdialog.h"
2023-04-28 16:02:14 +08:00
#include "gutil/qgui.h"
2023-04-18 14:14:46 +08:00
#include <QPushButton>
#include <QLabel>
#include <QLineEdit>
#include <QLabel>
#include <QDir>
#include <QMessageBox>
#include <QTimerEvent>
2023-04-28 16:02:14 +08:00
UsbDetectDialog::UsbDetectDialog(QWidget *parent) : QDialog(parent) {
2023-04-18 14:14:46 +08:00
setAttribute(Qt::WA_DeleteOnClose);
setWindowTitle(tr("Usb upgrade program"));
resize(240, 220);
2023-04-28 16:02:14 +08:00
auto vBox = new VBox(this);
auto hBox = new HBox(vBox);
2023-04-18 14:14:46 +08:00
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);
2023-04-28 16:02:14 +08:00
hBox = new HBox(vBox);
2023-04-18 14:14:46 +08:00
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) {
2023-04-28 16:02:14 +08:00
foreach(auto select, selects) emit acceptData(select->text(), fdPassword->text());
2023-04-18 14:14:46 +08:00
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");
2023-04-28 16:02:14 +08:00
connect(bnCancel, &QPushButton::clicked, this, &QDialog::reject);
2023-04-18 14:14:46 +08:00
hBox->addWidget(bnCancel);
hBox->addStretch();
detectDriver();
}
2023-04-21 11:06:47 +08:00
2023-04-18 14:14:46 +08:00
void UsbDetectDialog::detectDriver() {
2023-04-28 16:02:14 +08:00
#ifdef Q_OS_WINDOWS
2023-04-18 14:14:46 +08:00
auto drives = QDir::drives(); //获取当前系统的盘符
2023-04-28 16:02:14 +08:00
#else
auto drives = QDir("/Volumes").entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
#endif
2023-04-21 11:06:47 +08:00
fdDrives->clear();
2023-04-28 16:02:14 +08:00
foreach(auto drive, drives) fdDrives->addItem(drive.fileName());
2023-04-18 14:14:46 +08:00
}