/
mainwindow.cpp
210 lines (189 loc) · 8.72 KB
/
mainwindow.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent, Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint)
{
aWindowLocked = false;
}
MainWindow::~MainWindow()
{
}
void MainWindow::show()
{
QWidget::show();
aWindow = new QWidget(this);
QGridLayout* lGLayout = new QGridLayout(aWindow);
aWindow->setLayout(lGLayout);
setCentralWidget(aWindow);
//Èíôîðìàöèÿ îá óñòðîéñòâå
QGroupBox* lDeviceGroup = new QGroupBox(QString::fromLocal8Bit("Óñòðîéñòâî"),aWindow);
lGLayout->addWidget(lDeviceGroup,0,0);
aDeviceComboBox = new QComboBox(lDeviceGroup);
QObject::connect(aDeviceComboBox, SIGNAL(activated(int)), this, SLOT(updateDeviceProperty(int)));
QVBoxLayout* lDeviceLayout = new QVBoxLayout(lDeviceGroup);
lDeviceGroup->setLayout(lDeviceLayout);
lDeviceLayout->addWidget(aDeviceComboBox);
aDeviceLabel = new QLabel("",lDeviceGroup);
lDeviceLayout->addWidget(aDeviceLabel);
//Èíôîðìàöèÿ î ïàìÿòè
QGroupBox* lMemoryGroup = new QGroupBox(QString::fromLocal8Bit("Õàðàêòåðèñòèêè"),aWindow);
lGLayout->addWidget(lMemoryGroup,0,1);
QVBoxLayout* lMemoryLayout = new QVBoxLayout(lMemoryGroup);
lMemoryGroup->setLayout(lMemoryLayout);
aMemoryLabel = new QLabel(QString::fromLocal8Bit(getMemoryInfoString().c_str()));
lMemoryLayout->addWidget(aMemoryLabel);
//Ïàðàìåòðû òåñòèðîâàíèÿ
QGroupBox* lTestParamGroup = new QGroupBox(QString::fromLocal8Bit("Ïàðàìåòðû òåñòèðîâàíèÿ"),aWindow);
lGLayout->addWidget(lTestParamGroup,1,0,1,2);
QGridLayout* lTestParamLayout = new QGridLayout(lTestParamGroup);
lTestParamGroup->setLayout(lTestParamLayout);
aReadCheck = new QCheckBox(QString::fromLocal8Bit("×òåíèå"),lTestParamGroup);
aReadCheck->setChecked(true);
lTestParamLayout->addWidget(aReadCheck, 0, 0);
aWriteCheck = new QCheckBox(QString::fromLocal8Bit("Çàïèñü"),lTestParamGroup);
lTestParamLayout->addWidget(aWriteCheck, 1, 0);
aLinearRadio = new QRadioButton(QString::fromLocal8Bit("Ëèíåéíàÿ àäðåñàöèÿ"),lTestParamGroup);
aLinearRadio->setChecked(true);
lTestParamLayout->addWidget(aLinearRadio, 0, 1);
aButterflyRadio = new QRadioButton(QString::fromLocal8Bit("Àäðåñàöèÿ ìåòîäîì 'Butterfly'"),lTestParamGroup);
lTestParamLayout->addWidget(aButterflyRadio, 1, 1);
//aRandomRadio = new QRadioButton(QString::fromLocal8Bit("Àäðåñàöèÿ ìåòîäîì 'Random'"),lTestParamGroup);
//lTestParamLayout->addWidget(aRandomRadio, 2, 1);
QLabel* blockSizeLabel = new QLabel(QString::fromLocal8Bit("Ðàçìåð áëîêà:"),lTestParamGroup);
lTestParamLayout->addWidget(blockSizeLabel, 0, 3);
aBlockSizeEdit = new QSpinBox(lTestParamGroup);
aBlockSizeEdit->setMaximum(4096);
aBlockSizeEdit->setMinimum(1);
aBlockSizeEdit->setValue(512);
lTestParamLayout->addWidget(aBlockSizeEdit,0,4);
QLabel* startLabel = new QLabel(QString::fromLocal8Bit("Íà÷àëüíûé àäðåñ LBA:"),lTestParamGroup);
lTestParamLayout->addWidget(startLabel, 1, 3);
aStartEdit = new QSpinBox(lTestParamGroup);
aStartEdit->setMinimum(0);
lTestParamLayout->addWidget(aStartEdit,1,4);
QLabel* endLabel = new QLabel(QString::fromLocal8Bit("Êîíå÷íûé àäðåñ LBA:"),lTestParamGroup);
lTestParamLayout->addWidget(endLabel, 2, 3);
aEndEdit = new QSpinBox(lTestParamGroup);
aEndEdit->setMinimum(0);
lTestParamLayout->addWidget(aEndEdit,2,4);
lTestParamLayout->setColumnMinimumWidth(2,20);
QPushButton* testButton = new QPushButton(QString::fromLocal8Bit("Íà÷àòü òåñòèðîâàíèå"),lTestParamGroup);
lTestParamLayout->addWidget(testButton, 2, 0, 1, 2);
QObject::connect(testButton, SIGNAL(clicked()), this, SLOT(testButtonClick()));
CDeviceManager* lDevManager = CDeviceManager::getInstance();
QObject::connect(lDevManager,SIGNAL(testFinished()),this,SLOT(unlockWindow()));
pNameList nameList = lDevManager->getDeviceNameList();
for(std::vector<std::string>::iterator it=nameList->begin();it<nameList->end();it++)
aDeviceComboBox->addItem(QString::fromStdString(*it));
updateDeviceProperty(0);
aWindow->adjustSize();
aWindow->setWhatsThis(QString::fromLocal8Bit("Ïðîãðàììà ïðîâåðêè ðàáîòîñïîñîáíîñòè Flash-ïàìÿòè.\n\nÀâòîð: Ñîëîøåíêî Èðèíà"
"\n(ïðè ïîääåðæêå Êàëóãèíà Èâàíà, Áóëîâàöêîãî Àëåêñåÿ)"));
}
void MainWindow::unlockWindow()
{
aWindow->setEnabled(true);
aWindowLocked = false;
}
void MainWindow::closeEvent(QCloseEvent *iCloseEvent)
{
if(aWindowLocked)
iCloseEvent->ignore();
else
iCloseEvent->accept();
}
std::string MainWindow::getDeviceInfoString(std::string iModel, std::string iVendor, std::string iSerial, std::string iFileSystem)
{
return "\nÌîäåëü: "+iModel
+"\nÏðîèçâîäèòåëü: "+iVendor
//+"\nÑåðèéíûé íîìåð: "+iSerial
+"\nÔàéëîâàÿ ñèñòåìà: "+iFileSystem;
}
std::string MainWindow::getMemoryInfoString(long long iDevSize, long long iAvailableSpace, long long iFreeSpace, long long iCountLBA, int iSectorSize)
{
std::stringstream lMemoryInfoString;
lMemoryInfoString<<"\nÐàçìåð óñòðîéñòâà: ";
if(iDevSize)
lMemoryInfoString<<iDevSize<<" "<<convertBytes(iDevSize);
lMemoryInfoString<<"\nÄîñòóïíûé îáúåì ïàìÿòè: ";
if(iAvailableSpace)
lMemoryInfoString<<iAvailableSpace<<" "<<convertBytes(iAvailableSpace);
lMemoryInfoString<<"\nÎáúåì ñâîáîäíîé ïàìÿòè: ";
if(iFreeSpace)
lMemoryInfoString<<iFreeSpace<<" "<<convertBytes(iFreeSpace);
lMemoryInfoString<<"\n\nÊîëè÷åñòâî ñåêòîðîâ LBA: ";
if(iCountLBA)
lMemoryInfoString<<iCountLBA;
lMemoryInfoString<<"\nÐàçìåð ñåêòîðà: ";
if(iSectorSize)
lMemoryInfoString<<iSectorSize;
return lMemoryInfoString.str();
}
std::string MainWindow::convertBytes(long long iBytes)
{
std::stringstream convertStream;
if( (iBytes/1024) < 1)
return "";
if((iBytes/1024/1024) < 1)
convertStream<<"("<<((long)(iBytes/1024.0*100))/100.0<<" Êá)";
else
if((iBytes/1024/1024/1024) < 1)
convertStream<<"("<<((long)(iBytes/1024.0/1024*100))/100.0<<" Ìá)";
else
if((iBytes/1024/1024/1024/1024) < 1)
convertStream<<"("<<((long)(iBytes/1024.0/1024/1024*100))/100.0<<" Ãá)";
return convertStream.str();
}
void MainWindow::updateDiskNameList()
{
QMessageBox* testBox = new QMessageBox();
testBox->exec();
}
void MainWindow::updateDeviceProperty(int iIndex)
{
CDeviceManager* devManager = CDeviceManager::getInstance();
try
{
if(!devManager->updateDeviceInfo(iIndex))
throw "device not found";
aDeviceLabel->setText(QString::fromLocal8Bit(getDeviceInfoString(devManager->getDeviceModel(iIndex),
devManager->getDeviceVendor(iIndex),
devManager->getDeviceSerial(iIndex),
devManager->getDeviceFileSystem(iIndex)).c_str()));
aMemoryLabel->setText(QString::fromLocal8Bit(getMemoryInfoString(devManager->getDeviceSize(iIndex),
devManager->getDeviceFreeSpace(iIndex),
devManager->getAvailableSpace(iIndex),
devManager->getDeviceCountLBA(iIndex),
devManager->getDeviceSectorSize(iIndex)).c_str()));
aStartEdit->setMaximum(devManager->getDeviceCountLBA(iIndex)-1);
aEndEdit->setMaximum(devManager->getDeviceCountLBA(iIndex)-1);
aEndEdit->setValue(devManager->getDeviceCountLBA(iIndex)-1);
}
catch(...)
{
aDeviceLabel->setText(QString::fromLocal8Bit(getDeviceInfoString().c_str()));
aMemoryLabel->setText(QString::fromLocal8Bit(getMemoryInfoString().c_str()));
}
}
void MainWindow::testButtonClick()
{
aWindow->setEnabled(false);
aWindowLocked = true;
int iMode = 0;
if (aReadCheck->isChecked())
iMode+=1;
if (aWriteCheck->isChecked())
iMode+=2;
int iMethod = 0;
if(aLinearRadio->isChecked())
iMethod =1;
if(aButterflyRadio->isChecked())
iMethod =2;
if(aRandomRadio->isChecked())
iMethod =3;
(CDeviceManager::getInstance())->runTest(aDeviceComboBox->currentIndex(),
iMode,
iMethod,
aBlockSizeEdit->value(),
aStartEdit->value(),
aEndEdit->value());
}