64 lines
2.3 KiB
C++
64 lines
2.3 KiB
C++
#include "usbdetectdialog.h"
|
|
#include "gutil/qgui.h"
|
|
#include <QPushButton>
|
|
#include <QDialogButtonBox>
|
|
#include <QLabel>
|
|
#include <QLineEdit>
|
|
#include <QLabel>
|
|
#include <QStorageInfo>
|
|
#include <QMessageBox>
|
|
#include <QTimerEvent>
|
|
|
|
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 <QDebug>
|
|
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
|
|
}
|