-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselectcarddialog.cpp
More file actions
73 lines (63 loc) · 1.95 KB
/
selectcarddialog.cpp
File metadata and controls
73 lines (63 loc) · 1.95 KB
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
#include "selectcarddialog.h"
#include "externalDriveFetcher.h"
#include "ui_selectcarddialog.h"
SelectCardDialog::SelectCardDialog(QWidget *parent)
: QDialog(parent)
, ui(new Ui::SelectCardDialog)
{
ui->setupUi(this);
ui->listBox->setSelectionMode(QAbstractItemView::SingleSelection);
ui->listBox->setSelectionBehavior(QAbstractItemView::SelectItems);
}
void SelectCardDialog::setCards(QList<QStorageInfo> _cardList)
{
cardList = _cardList;
qDebug() << _cardList;
ui->listBox->clear();
if (cardList.isEmpty()) {
return;
}
foreach (const QStorageInfo &storage, cardList) {
QString text = storage.name()
+ tr(" (size: %1 GB, %2 GB Free )")
.arg(storage.bytesTotal() / (1024LL * 1024 * 1024))
.arg(storage.bytesFree() / (1024LL * 1024 * 1024));
#if defined(__APPLE__)
// macOS-specific code
QListWidgetItem *item = new QListWidgetItem(text);
item->setIcon(ExternalDriveIconFetcher::getExternalDriveIcon(storage.rootPath()));
#else
QListWidgetItem *item = new QListWidgetItem(text);
#endif
ui->listBox->addItem(item);
}
if (ui->listBox->count() > 0) {
ui->listBox->setCurrentRow(0);
}
}
QStorageInfo SelectCardDialog::getSelected()
{
int currentItem = ui->listBox->currentRow();
qDebug() << currentItem;
if (currentItem < 0 || currentItem >= cardList.size()) {
return QStorageInfo(); // safe empty value
}
return cardList.at(currentItem);
//QListWidgetItem *current = ui->listBox->currentItem();
//qDebug() << current->text();
//foreach (const QStorageInfo &storage, cardList) {
// if (current->text() == storage.rootPath()) {
// return storage;
// }
//}
//return QStorageInfo();
}
SelectCardDialog::~SelectCardDialog()
{
delete ui;
}
void SelectCardDialog::on_listBox_itemDoubleClicked(QListWidgetItem *item)
{
Q_UNUSED(item);
accept();
}