-
Notifications
You must be signed in to change notification settings - Fork 1
/
ManageDriveWindow.cpp
77 lines (60 loc) · 2.04 KB
/
ManageDriveWindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "ManageDriveWindow.h"
#include <QFileDialog>
#include <QMessageBox>
#include <QPushButton>
ManageDriveWindow::ManageDriveWindow(const TailDriveInfo& drive, QWidget* parent)
: QDialog(parent)
, ui(new Ui::ManageDriveWindow)
, originalDriveInfo(drive)
{
ui->setupUi(this);
setWindowTitle("Tail drive");
setWindowModality(Qt::WindowModality::ApplicationModal);
setModal(true);
driveToUi();
connect(ui->btnSelectFolder, &QPushButton::clicked,
this, &ManageDriveWindow::selectFolder);
connect(ui->btnOk, &QPushButton::clicked,
this, &ManageDriveWindow::acceptButtonClicked);
connect(ui->btnCancel, &QPushButton::clicked,
this, &ManageDriveWindow::close);
}
void ManageDriveWindow::driveToUi() {
ui->txtName->setText(originalDriveInfo.name);
ui->txtPath->setText(originalDriveInfo.path);
}
TailDriveInfo ManageDriveWindow::driveInfo() const {
TailDriveInfo retVal{};
retVal.name = ui->txtName->text();
retVal.path = ui->txtPath->text();
return retVal;
}
void ManageDriveWindow::selectFolder() {
QFileDialog dlg(this, "Select folder", ui->txtPath->text());
dlg.setFileMode(QFileDialog::FileMode::Directory);
dlg.setAcceptMode(QFileDialog::AcceptMode::AcceptOpen);
dlg.setOption(QFileDialog::Option::ShowDirsOnly, true);
auto result = dlg.exec();
if (result == QFileDialog::Accepted) {
const auto& selection = dlg.selectedFiles();
ui->txtPath->setText(selection.first());
}
}
void ManageDriveWindow::acceptButtonClicked() {
QString error;
if (ui->txtName->text().isEmpty()) {
error = "Name must be set";
setResult(QDialog::Rejected);
}
const QDir dir(ui->txtPath->text());
if (ui->txtPath->text().isEmpty() || !dir.exists()) {
error = "Path must be set and exist";
setResult(QDialog::Rejected);
}
if (!error.isEmpty()) {
QMessageBox::warning(this, "Error", error, QMessageBox::Ok);
return;
}
setResult(QDialog::Accepted);
accept();
}