qt/LedOK/program/usbdetectdialog.cpp

64 lines
2.3 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>
2023-04-28 18:26:41 +08:00
#include <QDialogButtonBox>
2023-04-18 14:14:46 +08:00
#include <QLabel>
#include <QLineEdit>
#include <QLabel>
2023-04-28 18:26:41 +08:00
#include <QStorageInfo>
2023-04-18 14:14:46 +08:00
#include <QMessageBox>
#include <QTimerEvent>
2023-04-28 16:02:14 +08:00
UsbDetectDialog::UsbDetectDialog(QWidget *parent) : QDialog(parent) {
2023-04-28 18:26:41 +08:00
setWindowFlag(Qt::WindowContextHelpButtonHint, 0);
2023-04-18 14:14:46 +08:00
setWindowTitle(tr("Usb upgrade program"));
2023-04-28 18:26:41 +08:00
resize(300, 260);
2023-04-18 14:14:46 +08:00
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);
2023-04-28 18:26:41 +08:00
fdDrives = new ListWgt;
2023-04-18 14:14:46 +08:00
fdDrives->setSelectionRectVisible(true);
vBox->addWidget(fdDrives);
2023-04-28 18:26:41 +08:00
auto btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(btnBox, &QDialogButtonBox::accepted, this, [this] {
2023-04-18 14:14:46 +08:00
auto selects = fdDrives->selectedItems();
if(selects.count() > 0) {
2023-04-28 18:26:41 +08:00
foreach(auto select, selects) emit acceptData(select->data(Qt::UserRole).toString(), 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"));
});
2023-04-28 18:26:41 +08:00
connect(btnBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
vBox->addWidget(btnBox);
2023-04-18 14:14:46 +08:00
detectDriver();
}
2023-04-28 18:26:41 +08:00
#include <QDebug>
2023-04-18 14:14:46 +08:00
void UsbDetectDialog::detectDriver() {
2023-04-21 11:06:47 +08:00
fdDrives->clear();
2023-04-28 18:26:41 +08:00
//#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
2023-04-18 14:14:46 +08:00
}